Commit 65a26d0a authored by Dafydd Harries's avatar Dafydd Harries

stun.c: make indentation consistent with other code

darcs-hash:20070107173235-c9803-b25f8bf1451b48140561f096532cda0b65e7b2b7.gz
parent 68648e89
...@@ -8,18 +8,18 @@ ...@@ -8,18 +8,18 @@
#include <stdio.h> #include <stdio.h>
static StunAttribute * static StunAttribute *
stun_attribute_new(guint type) stun_attribute_new (guint type)
{ {
StunAttribute *attr = g_slice_alloc(sizeof(StunAttribute)); StunAttribute *attr = g_slice_alloc (sizeof (StunAttribute));
attr->type = type; attr->type = type;
return attr; return attr;
} }
StunAttribute * StunAttribute *
stun_attribute_mapped_address_new(guint32 ip, guint16 port) stun_attribute_mapped_address_new (guint32 ip, guint16 port)
{ {
StunAttribute *attr = stun_attribute_new(STUN_ATTRIBUTE_MAPPED_ADDRESS); StunAttribute *attr = stun_attribute_new (STUN_ATTRIBUTE_MAPPED_ADDRESS);
attr->length = 8; attr->length = 8;
attr->address.padding = 0; attr->address.padding = 0;
...@@ -30,25 +30,25 @@ stun_attribute_mapped_address_new(guint32 ip, guint16 port) ...@@ -30,25 +30,25 @@ stun_attribute_mapped_address_new(guint32 ip, guint16 port)
} }
void void
stun_attribute_free(StunAttribute *attr) stun_attribute_free (StunAttribute *attr)
{ {
g_slice_free1(sizeof(StunAttribute), attr); g_slice_free1 (sizeof (StunAttribute), attr);
} }
StunAttribute * StunAttribute *
stun_attribute_unpack(guint length, const gchar *s) stun_attribute_unpack (guint length, const gchar *s)
{ {
StunAttribute *attr; StunAttribute *attr;
g_assert(length); g_assert (length);
attr = stun_attribute_new(ntohs(*(guint16 *)s)); attr = stun_attribute_new (ntohs (*(guint16 *)s));
switch (attr->type) { switch (attr->type) {
case STUN_ATTRIBUTE_MAPPED_ADDRESS: case STUN_ATTRIBUTE_MAPPED_ADDRESS:
attr->address.af = (guint8)s[5]; attr->address.af = (guint8) s[5];
g_assert(attr->address.af == 1); g_assert (attr->address.af == 1);
attr->address.port = ntohs(*(guint16 *)(s + 6)); attr->address.port = ntohs (*(guint16 *)(s + 6));
attr->address.ip = ntohl(*(guint32 *)(s + 8)); attr->address.ip = ntohl (*(guint32 *)(s + 8));
break; break;
default: default:
break; break;
...@@ -58,19 +58,19 @@ stun_attribute_unpack(guint length, const gchar *s) ...@@ -58,19 +58,19 @@ stun_attribute_unpack(guint length, const gchar *s)
} }
guint guint
stun_attribute_pack(StunAttribute *attr, gchar **packed) stun_attribute_pack (StunAttribute *attr, gchar **packed)
{ {
switch (attr->type) { switch (attr->type) {
case STUN_ATTRIBUTE_MAPPED_ADDRESS: case STUN_ATTRIBUTE_MAPPED_ADDRESS:
{ {
StunAttribute *ret = g_malloc0(sizeof(StunAttribute)); StunAttribute *ret = g_malloc0 (sizeof (StunAttribute));
ret->type = htons(attr->type); ret->type = htons (attr->type);
ret->length = htons(8); ret->length = htons (8);
ret->address.af = attr->address.af; ret->address.af = attr->address.af;
ret->address.port = htons(attr->address.port); ret->address.port = htons (attr->address.port);
ret->address.ip = htonl(attr->address.ip); ret->address.ip = htonl (attr->address.ip);
*packed = (gchar *)ret; *packed = (gchar *) ret;
return 12; return 12;
} }
default: default:
...@@ -79,11 +79,11 @@ stun_attribute_pack(StunAttribute *attr, gchar **packed) ...@@ -79,11 +79,11 @@ stun_attribute_pack(StunAttribute *attr, gchar **packed)
} }
gchar * gchar *
stun_attribute_dump(StunAttribute *attr) stun_attribute_dump (StunAttribute *attr)
{ {
switch (attr->type) { switch (attr->type) {
case STUN_ATTRIBUTE_MAPPED_ADDRESS: case STUN_ATTRIBUTE_MAPPED_ADDRESS:
return g_strdup_printf( return g_strdup_printf (
"MAPPED-ADDRESS %d.%d.%d.%d:%d", "MAPPED-ADDRESS %d.%d.%d.%d:%d",
(attr->address.ip & 0xff000000) >> 24, (attr->address.ip & 0xff000000) >> 24,
(attr->address.ip & 0x00ff0000) >> 16, (attr->address.ip & 0x00ff0000) >> 16,
...@@ -91,85 +91,85 @@ stun_attribute_dump(StunAttribute *attr) ...@@ -91,85 +91,85 @@ stun_attribute_dump(StunAttribute *attr)
(attr->address.ip & 0x000000ff) >> 0, (attr->address.ip & 0x000000ff) >> 0,
attr->address.port); attr->address.port);
default: default:
return g_strdup_printf("UNKNOWN (%d)", attr->type); return g_strdup_printf ("UNKNOWN (%d)", attr->type);
} }
} }
StunMessage * StunMessage *
stun_message_new(guint type) stun_message_new (guint type)
{ {
StunMessage *msg = g_slice_alloc0(sizeof(StunMessage)); StunMessage *msg = g_slice_alloc0 (sizeof (StunMessage));
msg->type = type; msg->type = type;
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);
} }
void void
stun_message_free(StunMessage *msg) stun_message_free (StunMessage *msg)
{ {
StunAttribute **attr; StunAttribute **attr;
if (msg->attributes) { if (msg->attributes) {
for (attr = msg->attributes; *attr; attr++) for (attr = msg->attributes; *attr; attr++)
stun_attribute_free(*attr); stun_attribute_free (*attr);
g_free(msg->attributes); g_free (msg->attributes);
} }
g_slice_free1(sizeof(StunMessage), msg); g_slice_free1 (sizeof (StunMessage), msg);
} }
StunMessage * StunMessage *
stun_message_unpack(guint length, gchar *s) stun_message_unpack (guint length, gchar *s)
{ {
gchar *t; gchar *t;
guint attr_length; guint attr_length;
guint n_attributes = 0; guint n_attributes = 0;
guint i; guint i;
StunAttribute *attr; StunAttribute *attr;
StunMessage *msg = stun_message_new(STUN_MESSAGE_BINDING_REQUEST); StunMessage *msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
/* message header is 20 bytes */ /* message header is 20 bytes */
g_assert(length >= 20); g_assert (length >= 20);
/* unpack the header */ /* unpack the header */
msg->type = ntohs(*(guint16 *)(s + 0)); msg->type = ntohs (*(guint16 *)(s + 0));
memcpy(msg->transaction_id, s + 4, 16); memcpy (msg->transaction_id, s + 4, 16);
/* count the number of attributes */ /* count the number of attributes */
for (t = s + 20; t - s < length; t += attr_length + 4) { for (t = s + 20; t - s < length; t += attr_length + 4) {
attr_length = ntohs(*(guint16 *)(t + 2)); attr_length = ntohs (*(guint16 *)(t + 2));
n_attributes++; n_attributes++;
} }
/* allocate memory for the attribute list and terminate it */ /* allocate memory for the attribute list and terminate it */
msg->attributes = g_malloc0((n_attributes + 1) * sizeof(StunAttribute *)); msg->attributes = g_malloc0 ((n_attributes + 1) * sizeof (StunAttribute *));
msg->attributes[n_attributes] = NULL; msg->attributes[n_attributes] = NULL;
/* unpack attributes */ /* unpack attributes */
for (i = 0, t = s + 20; i < n_attributes; i++, t += attr_length + 4) { for (i = 0, t = s + 20; i < n_attributes; i++, t += attr_length + 4) {
attr_length = ntohs(*(guint16 *)(t + 2)); attr_length = ntohs (*(guint16 *)(t + 2));
attr = msg->attributes[i] = stun_attribute_unpack(attr_length, t); attr = msg->attributes[i] = stun_attribute_unpack (attr_length, t);
} }
return msg; return msg;
} }
guint guint
stun_message_pack(StunMessage *msg, gchar **packed) stun_message_pack (StunMessage *msg, gchar **packed)
{ {
GString *tmp = g_string_new(""); GString *tmp = g_string_new ("");
unsigned int packed_type; unsigned int packed_type;
guint16 packed_length; guint16 packed_length;
guint length = 0; guint length = 0;
...@@ -181,28 +181,28 @@ stun_message_pack(StunMessage *msg, gchar **packed) ...@@ -181,28 +181,28 @@ stun_message_pack(StunMessage *msg, gchar **packed)
length += 4 + (*attr)->length; length += 4 + (*attr)->length;
} }
packed_type = htons(msg->type); packed_type = htons (msg->type);
packed_length = htons(length); packed_length = htons (length);
g_string_append_printf(tmp, "%c%c%c%c", g_string_append_printf (tmp, "%c%c%c%c",
((gchar *)&packed_type)[0], ((gchar *) &packed_type)[0],
((gchar *)&packed_type)[1], ((gchar *) &packed_type)[1],
((gchar *)&packed_length)[0], ((gchar *) &packed_length)[0],
((gchar *)&packed_length)[1]); ((gchar *) &packed_length)[1]);
g_string_append_len(tmp, msg->transaction_id, 16); g_string_append_len (tmp, msg->transaction_id, 16);
if (msg->attributes) { if (msg->attributes) {
StunAttribute **attr; StunAttribute **attr;
for (attr = msg->attributes; *attr; attr++) { for (attr = msg->attributes; *attr; attr++) {
gchar *attr_packed; gchar *attr_packed;
guint attr_length = stun_attribute_pack(*attr, &attr_packed); guint attr_length = stun_attribute_pack (*attr, &attr_packed);
g_string_append_len(tmp, attr_packed, attr_length); g_string_append_len (tmp, attr_packed, attr_length);
g_free(attr_packed); g_free (attr_packed);
} }
} }
*packed = g_string_free(tmp, FALSE); *packed = g_string_free (tmp, FALSE);
return length + 20; return length + 20;
} }
...@@ -210,7 +210,7 @@ gchar * ...@@ -210,7 +210,7 @@ gchar *
stun_message_dump (StunMessage *msg) stun_message_dump (StunMessage *msg)
{ {
StunAttribute **attr; StunAttribute **attr;
GString *tmp = g_string_new(""); GString *tmp = g_string_new ("");
const gchar *name; const gchar *name;
switch (msg->type) { switch (msg->type) {
...@@ -224,22 +224,22 @@ stun_message_dump (StunMessage *msg) ...@@ -224,22 +224,22 @@ stun_message_dump (StunMessage *msg)
return NULL; return NULL;
} }
g_string_printf(tmp, g_string_printf (tmp,
"%s %08x:%08x:%08x:%08x", "%s %08x:%08x:%08x:%08x",
name, name,
*(guint32*)(msg->transaction_id), *(guint32 *)(msg->transaction_id),
*(guint32*)(msg->transaction_id + 4), *(guint32 *)(msg->transaction_id + 4),
*(guint32*)(msg->transaction_id + 8), *(guint32 *)(msg->transaction_id + 8),
*(guint32*)(msg->transaction_id + 12)); *(guint32 *)(msg->transaction_id + 12));
if (msg->attributes) { if (msg->attributes) {
for (attr = msg->attributes; *attr; attr++) { for (attr = msg->attributes; *attr; attr++) {
gchar *dump = stun_attribute_dump(*attr); gchar *dump = stun_attribute_dump (*attr);
g_string_append_printf(tmp, "\n %s", dump); g_string_append_printf (tmp, "\n %s", dump);
g_free(dump); g_free (dump);
} }
} }
return g_string_free(tmp, FALSE); return g_string_free (tmp, FALSE);
} }
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