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

make stun_message_{new,init} take transaction ID

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