Commit 842d8848 authored by Dafydd Harries's avatar Dafydd Harries
Browse files

add n_attributes paramenter to stun_message_new

darcs-hash:20070201125530-c9803-b048be80885d9d82f7e1a2fcdd24f1675b85b345.gz
parent 0f798e75
......@@ -494,8 +494,7 @@ RESPOND:
/* XXX: add username to response */
response = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE,
msg->transaction_id);
response->attributes = g_malloc0 (2 * sizeof (StunAttribute));
msg->transaction_id, 1);
response->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from.sin_addr.s_addr), ntohs (from.sin_port));
len = stun_message_pack (response, &packed);
......
......@@ -40,7 +40,7 @@ test_stun_no_password (
/* send binding request without username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
"0123456789abcdef", 0);
packed_len = stun_message_pack (breq, &packed);
udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed);
......@@ -79,8 +79,7 @@ test_stun_invalid_password (
/* send binding request with incorrect username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
breq->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
"0123456789abcdef", 1);
breq->attributes[0] = stun_attribute_username_new ("lala");
packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0);
......@@ -124,8 +123,7 @@ test_stun_valid_password (
/* send binding request with correct username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef");
breq->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
"0123456789abcdef", 1);
username = g_strconcat (
"username",
((NiceCandidate *) agent->local_candidates->data)->username,
......@@ -144,8 +142,7 @@ test_stun_valid_password (
/* construct expected response packet */
bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE,
"0123456789abcdef");
bres->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
"0123456789abcdef", 1);
bres->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from.sin_addr.s_addr), 5678);
packed_len = stun_message_pack (bres, &packed);
......
......@@ -16,8 +16,7 @@ send_stun (UDPSocket *udpsock, struct sockaddr_in sin)
gchar buf[1024];
StunMessage *msg;
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL);
msg->attributes = g_malloc0 (2 * sizeof (StunAttribute));
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL, 1);
msg->attributes[0] = stun_attribute_username_new ("lala");
{
......
......@@ -37,8 +37,8 @@ handle_packet (
}
stun_message_free (msg);
msg = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE, msg->transaction_id);
msg->attributes = g_malloc0 (2 * sizeof (StunAttribute));
msg = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE, msg->transaction_id,
1);
msg->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from->sin_addr.s_addr), ntohs (from->sin_port));
length = stun_message_pack (msg, &packed);
......
......@@ -189,18 +189,23 @@ stun_message_init (StunMessage *msg, guint type, gchar *id)
}
StunMessage *
stun_message_new (guint type, gchar *id)
stun_message_new (guint type, gchar *id, guint n_attributes)
{
StunMessage *msg = g_slice_new0 (StunMessage);
stun_message_init (msg, type, id);
if (n_attributes != 0)
msg->attributes = g_malloc0 (
(n_attributes + 1) * sizeof (StunAttribute *));
return msg;
}
StunMessage *
stun_message_binding_request_new ()
{
return stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL);
return stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL, 0);
}
void
......@@ -233,10 +238,6 @@ stun_message_unpack (guint length, gchar *s)
g_assert (length >= 20);
/* unpack the header */
msg = stun_message_new (ntohs (*(guint16 *) s), s + 4);
/* count the number of attributes */
for (offset = 20; offset < length; offset += attr_length)
......@@ -245,10 +246,9 @@ stun_message_unpack (guint length, gchar *s)
n_attributes++;
}
/* allocate memory for the attribute list and terminate it */
/* create message structure */
msg->attributes = g_malloc0 ((n_attributes + 1) * sizeof (StunAttribute *));
msg->attributes[n_attributes] = NULL;
msg = stun_message_new (ntohs (*(guint16 *) s), s + 4, n_attributes);
/* unpack attributes */
......
......@@ -104,7 +104,7 @@ stun_message_init (StunMessage *msg, guint type, gchar *id);
G_GNUC_WARN_UNUSED_RESULT
StunMessage *
stun_message_new (guint type, gchar *id);
stun_message_new (guint type, gchar *id, guint n_attributes);
G_GNUC_WARN_UNUSED_RESULT
StunMessage *
......
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