Commit 22073fec authored by Dafydd Harries's avatar Dafydd Harries
Browse files

make stun_message_{new,init} take transaction ID

darcs-hash:20070201114851-c9803-4f8d67c0afcd66fbbf0f961c9c741fdd12ad7285.gz
parent ce95c071
......@@ -490,8 +490,8 @@ RESPOND:
gchar *packed;
/* XXX: add username to response */
response = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
memcpy (response->transaction_id, msg->transaction_id, 16);
response = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE,
msg->transaction_id);
response->attributes = g_malloc0 (2 * sizeof (StunAttribute));
response->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from.sin_addr.s_addr), ntohs (from.sin_port));
......
......@@ -39,8 +39,8 @@ test_stun_no_password (
gchar *packed;
/* send binding request without username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
memcpy (breq->transaction_id, "0123456789abcdef", 16);
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
packed_len = stun_message_pack (breq, &packed);
udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed);
......@@ -78,10 +78,10 @@ test_stun_invalid_password (
gchar *packed;
/* send binding request with incorrect username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
breq->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
breq->attributes[0] = stun_attribute_username_new ("lala");
memcpy (breq->transaction_id, "0123456789abcdef", 16);
packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0);
udp_fake_socket_push_recv (sock, &from, packed_len, packed);
......@@ -123,7 +123,8 @@ test_stun_valid_password (
gchar *username;
/* send binding request with correct username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
breq->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
username = g_strconcat (
"username",
......@@ -131,7 +132,6 @@ test_stun_valid_password (
NULL);
breq->attributes[0] = stun_attribute_username_new (username);
g_free (username);
memcpy (breq->transaction_id, "0123456789abcdef", 16);
packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0);
udp_fake_socket_push_recv (sock, &from, packed_len, packed);
......@@ -143,8 +143,8 @@ test_stun_valid_password (
StunMessage *bres;
/* construct expected response packet */
bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
memcpy (bres->transaction_id, "0123456789abcdef", 16);
bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE,
"0123456789abcdef");
bres->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
bres->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from.sin_addr.s_addr), 5678);
......
......@@ -16,7 +16,7 @@ send_stun (UDPSocket *udpsock, struct sockaddr_in sin)
gchar buf[1024];
StunMessage *msg;
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL);
msg->attributes = g_malloc0 (2 * sizeof (StunAttribute));
msg->attributes[0] = stun_attribute_username_new ("lala");
......
......@@ -37,7 +37,7 @@ handle_packet (
}
stun_message_free (msg);
msg = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
msg = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE, NULL);
msg->attributes = g_malloc0 (2 * sizeof (StunAttribute));
msg->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from->sin_addr.s_addr), ntohs (from->sin_port));
......
......@@ -180,24 +180,27 @@ stun_attribute_dump (StunAttribute *attr)
}
void
stun_message_init (StunMessage *msg, guint type)
stun_message_init (StunMessage *msg, guint type, gchar *id)
{
msg->type = type;
if (id != NULL)
memcpy (msg->transaction_id, id, 16);
}
StunMessage *
stun_message_new (guint type)
stun_message_new (guint type, gchar *id)
{
StunMessage *msg = g_slice_new0 (StunMessage);
stun_message_init (msg, type);
stun_message_init (msg, type, id);
return msg;
}
StunMessage *
stun_message_binding_request_new ()
{
return stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
return stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL);
}
void
......@@ -224,7 +227,7 @@ stun_message_unpack (guint length, gchar *s)
guint i;
guint offset;
StunAttribute *attr;
StunMessage *msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
StunMessage *msg;
/* message header is 20 bytes */
......@@ -232,8 +235,7 @@ stun_message_unpack (guint length, gchar *s)
/* unpack the header */
msg->type = ntohs (*(guint16 *)(s + 0));
memcpy (msg->transaction_id, s + 4, 16);
msg = stun_message_new (ntohs (*(guint16 *) s), s + 4);
/* count the number of attributes */
......
......@@ -95,10 +95,10 @@ StunAttribute *
stun_attribute_unpack (guint length, const gchar *s);
void
stun_message_init (StunMessage *msg, guint type);
stun_message_init (StunMessage *msg, guint type, gchar *id);
G_GNUC_WARN_UNUSED_RESULT
StunMessage *
stun_message_new (guint type);
stun_message_new (guint type, gchar *id);
G_GNUC_WARN_UNUSED_RESULT
StunMessage *
stun_message_binding_request_new (void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment