Commit 6e91f5b9 authored by Marcus Lundblad's avatar Marcus Lundblad Committed by Youness Alaoui

Fixing tabs, trailing whitespaces and indentation

parent 29f97e9e
...@@ -93,7 +93,8 @@ typedef struct { ...@@ -93,7 +93,8 @@ typedef struct {
there is an installed permission */ there is an installed permission */
GList *sent_permissions; /* ongoing permission installed */ GList *sent_permissions; /* ongoing permission installed */
GHashTable *send_data_queues; /* stores a send data queue for per peer */ GHashTable *send_data_queues; /* stores a send data queue for per peer */
guint permission_timeout_source; /* timer used to invalidate permissions */ guint permission_timeout_source; /* timer used to invalidate
permissions */
gboolean has_binding; gboolean has_binding;
gboolean sent_binding; gboolean sent_binding;
guint binding_timeout_source; guint binding_timeout_source;
...@@ -125,11 +126,14 @@ static gboolean priv_retransmissions_tick (gpointer pointer); ...@@ -125,11 +126,14 @@ static gboolean priv_retransmissions_tick (gpointer pointer);
static void priv_schedule_tick (TurnPriv *priv); static void priv_schedule_tick (TurnPriv *priv);
static void priv_send_turn_message (TurnPriv *priv, TURNMessage *msg); static void priv_send_turn_message (TurnPriv *priv, TURNMessage *msg);
static gboolean priv_send_create_permission (TurnPriv *priv, static gboolean priv_send_create_permission (TurnPriv *priv,
uint8_t *realm, gsize realm_len, uint8_t *nonce, gsize nonce_len, uint8_t *realm, gsize realm_len,
uint8_t *nonce, gsize nonce_len,
const NiceAddress *peer); const NiceAddress *peer);
static gboolean priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, static gboolean priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
uint16_t channel, const NiceAddress *peer); uint16_t channel,
static gboolean priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer); const NiceAddress *peer);
static gboolean priv_add_channel_binding (TurnPriv *priv,
const NiceAddress *peer);
static gboolean priv_forget_send_request (gpointer pointer); static gboolean priv_forget_send_request (gpointer pointer);
static guint static guint
...@@ -160,7 +164,8 @@ priv_send_data_queue_destroy (gpointer data) ...@@ -160,7 +164,8 @@ priv_send_data_queue_destroy (gpointer data)
NiceSocket * NiceSocket *
nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
NiceSocket *base_socket, NiceAddress *server_addr, NiceSocket *base_socket, NiceAddress *server_addr,
gchar *username, gchar *password, NiceTurnSocketCompatibility compatibility) gchar *username, gchar *password,
NiceTurnSocketCompatibility compatibility)
{ {
TurnPriv *priv = g_new0 (TurnPriv, 1); TurnPriv *priv = g_new0 (TurnPriv, 1);
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock = g_slice_new0 (NiceSocket);
...@@ -297,7 +302,8 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -297,7 +302,8 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
if (recv_len > 0) if (recv_len > 0)
return nice_turn_socket_parse_recv (sock, &dummy, from, len, buf, return nice_turn_socket_parse_recv (sock, &dummy, from, len, buf,
&recv_from, (gchar *) recv_buf, (guint) recv_len); &recv_from, (gchar *) recv_buf,
(guint) recv_len);
else else
return recv_len; return recv_len;
} }
...@@ -441,7 +447,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -441,7 +447,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
goto send; goto send;
if (stun_message_append32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE, if (stun_message_append32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE,
TURN_MAGIC_COOKIE) != STUN_MESSAGE_RETURN_SUCCESS) TURN_MAGIC_COOKIE) !=
STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
if (priv->username != NULL && priv->username_len > 0) { if (priv->username != NULL && priv->username_len > 0) {
if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_USERNAME, if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_USERNAME,
...@@ -450,7 +457,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -450,7 +457,8 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
goto send; goto send;
} }
if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS, if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS,
(struct sockaddr *)&sa, sizeof(sa)) != STUN_MESSAGE_RETURN_SUCCESS) (struct sockaddr *)&sa,
sizeof(sa)) != STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE && if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE &&
...@@ -481,8 +489,10 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -481,8 +489,10 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
req->priv = priv; req->priv = priv;
stun_message_id (&msg, req->id); stun_message_id (&msg, req->id);
req->source = agent_timeout_add_with_context (priv->nice, STUN_END_TIMEOUT, req->source = agent_timeout_add_with_context (priv->nice,
priv_forget_send_request, req); STUN_END_TIMEOUT,
priv_forget_send_request,
req);
g_queue_push_tail (priv->send_requests, req); g_queue_push_tail (priv->send_requests, req);
} }
} }
...@@ -600,7 +610,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -600,7 +610,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (nice_address_equal (&priv->server_addr, recv_from)) { if (nice_address_equal (&priv->server_addr, recv_from)) {
valid = stun_agent_validate (&priv->agent, &msg, valid = stun_agent_validate (&priv->agent, &msg,
(uint8_t *) recv_buf, (size_t) recv_len, NULL, NULL); (uint8_t *) recv_buf, (size_t) recv_len, NULL,
NULL);
if (valid == STUN_VALIDATION_SUCCESS) { if (valid == STUN_VALIDATION_SUCCESS) {
if (priv->compatibility != NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 && if (priv->compatibility != NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 &&
...@@ -653,7 +664,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -653,7 +664,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (priv->current_binding && priv->current_binding_msg) { if (priv->current_binding && priv->current_binding_msg) {
stun_message_id (&msg, response_id); stun_message_id (&msg, response_id);
stun_message_id (&priv->current_binding_msg->message, request_id); stun_message_id (&priv->current_binding_msg->message, request_id);
if (memcmp (request_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (request_id, response_id,
sizeof(StunTransactionId)) == 0) {
g_free (priv->current_binding_msg); g_free (priv->current_binding_msg);
priv->current_binding_msg = NULL; priv->current_binding_msg = NULL;
...@@ -676,7 +688,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -676,7 +688,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (priv->current_binding_msg) { if (priv->current_binding_msg) {
stun_message_id (&msg, response_id); stun_message_id (&msg, response_id);
stun_message_id (&priv->current_binding_msg->message, request_id); stun_message_id (&priv->current_binding_msg->message, request_id);
if (memcmp (request_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (request_id, response_id,
sizeof(StunTransactionId)) == 0) {
if (stun_message_get_class (&msg) == STUN_ERROR) { if (stun_message_get_class (&msg) == STUN_ERROR) {
int code = -1; int code = -1;
uint8_t *sent_realm = NULL; uint8_t *sent_realm = NULL;
...@@ -684,10 +697,12 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -684,10 +697,12 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
uint16_t sent_realm_len = 0; uint16_t sent_realm_len = 0;
uint16_t recv_realm_len = 0; uint16_t recv_realm_len = 0;
sent_realm = (uint8_t *) stun_message_find ( sent_realm =
(uint8_t *) stun_message_find (
&priv->current_binding_msg->message, &priv->current_binding_msg->message,
STUN_ATTRIBUTE_REALM, &sent_realm_len); STUN_ATTRIBUTE_REALM, &sent_realm_len);
recv_realm = (uint8_t *) stun_message_find (&msg, recv_realm =
(uint8_t *) stun_message_find (&msg,
STUN_ATTRIBUTE_REALM, &recv_realm_len); STUN_ATTRIBUTE_REALM, &recv_realm_len);
if (!priv->has_binding) { if (!priv->has_binding) {
...@@ -703,7 +718,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -703,7 +718,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
recv_realm_len > 0 && recv_realm_len > 0 &&
recv_realm_len == sent_realm_len && recv_realm_len == sent_realm_len &&
sent_realm != NULL && sent_realm != NULL &&
memcmp (sent_realm, recv_realm, sent_realm_len) == 0)))) { memcmp (sent_realm, recv_realm,
sent_realm_len) == 0)))) {
if (priv->current_binding) { if (priv->current_binding) {
g_free (priv->current_binding_msg); g_free (priv->current_binding_msg);
...@@ -773,7 +789,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -773,7 +789,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (priv->current_create_permission_msg) { if (priv->current_create_permission_msg) {
stun_message_id (&msg, response_id); stun_message_id (&msg, response_id);
stun_message_id (&priv->current_create_permission_msg->message, request_id); stun_message_id (&priv->current_create_permission_msg->message,
request_id);
if (memcmp (request_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (request_id, response_id, sizeof(StunTransactionId)) == 0) {
struct sockaddr peer; struct sockaddr peer;
...@@ -998,9 +1015,11 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv) ...@@ -998,9 +1015,11 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv)
stun_message_id (&priv->current_create_permission_msg->message, id); stun_message_id (&priv->current_create_permission_msg->message, id);
stun_agent_forget_transaction (&priv->agent, id); stun_agent_forget_transaction (&priv->agent, id);
stun_message_find_xor_addr (&priv->current_create_permission_msg->message, stun_message_find_xor_addr (&priv->current_create_permission_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr, &addr_len); STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr,
&addr_len);
nice_address_set_from_sockaddr (to, &addr); nice_address_set_from_sockaddr (to, &addr);
sent_permission = g_list_find_custom (priv->sent_permissions, to, sent_permission =
g_list_find_custom (priv->sent_permissions, to,
(GCompareFunc) nice_address_equal); (GCompareFunc) nice_address_equal);
g_free (priv->current_create_permission_msg); g_free (priv->current_create_permission_msg);
...@@ -1114,8 +1133,11 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1114,8 +1133,11 @@ priv_schedule_tick (TurnPriv *priv)
if (priv->current_create_permission_msg) { if (priv->current_create_permission_msg) {
guint timeout = stun_timer_remainder (&priv->current_create_permission_msg->timer); guint timeout = stun_timer_remainder (&priv->current_create_permission_msg->timer);
if (timeout > 0) { if (timeout > 0) {
priv->tick_source_create_permission = agent_timeout_add_with_context (priv->nice, timeout, priv->tick_source_create_permission =
priv_retransmissions_create_permission_tick, priv); agent_timeout_add_with_context (priv->nice,
timeout,
priv_retransmissions_create_permission_tick,
priv);
} else { } else {
priv_retransmissions_create_permission_tick_unlocked (priv); priv_retransmissions_create_permission_tick_unlocked (priv);
} }
...@@ -1165,8 +1187,14 @@ priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len, ...@@ -1165,8 +1187,14 @@ priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len,
/* send CreatePermission */ /* send CreatePermission */
msg_buf_len = stun_usage_turn_create_permission(&priv->agent, &msg->message, msg_buf_len = stun_usage_turn_create_permission(&priv->agent, &msg->message,
msg->buffer, sizeof(msg->buffer), priv->username, priv->username_len, msg->buffer,
priv->password, priv->password_len, realm, realm_len, nonce, nonce_len, sizeof(msg->buffer),
priv->username,
priv->username_len,
priv->password,
priv->password_len,
realm, realm_len,
nonce, nonce_len,
&addr, &addr,
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766); NICE_TURN_SOCKET_COMPATIBILITY_RFC5766);
...@@ -1205,7 +1233,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1205,7 +1233,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
nice_address_copy_to_sockaddr (peer, (struct sockaddr *)&sa); nice_address_copy_to_sockaddr (peer, (struct sockaddr *)&sa);
if (!stun_agent_init_request (&priv->agent, &msg->message, if (!stun_agent_init_request (&priv->agent, &msg->message,
msg->buffer, sizeof(msg->buffer), STUN_CHANNELBIND)) { msg->buffer, sizeof(msg->buffer),
STUN_CHANNELBIND)) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
...@@ -1217,14 +1246,17 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1217,14 +1246,17 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
} }
if (stun_message_append_xor_addr (&msg->message, STUN_ATTRIBUTE_PEER_ADDRESS, if (stun_message_append_xor_addr (&msg->message, STUN_ATTRIBUTE_PEER_ADDRESS,
(struct sockaddr *)&sa, sizeof(sa)) != STUN_MESSAGE_RETURN_SUCCESS) { (struct sockaddr *)&sa,
sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
if (priv->username != NULL && priv->username_len > 0) { if (priv->username != NULL && priv->username_len > 0) {
if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_USERNAME, if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_USERNAME,
priv->username, priv->username_len) != STUN_MESSAGE_RETURN_SUCCESS) { priv->username, priv->username_len)
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
...@@ -1238,7 +1270,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1238,7 +1270,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
realm = (uint8_t *) stun_message_find (resp, STUN_ATTRIBUTE_REALM, &len); realm = (uint8_t *) stun_message_find (resp, STUN_ATTRIBUTE_REALM, &len);
if (realm != NULL) { if (realm != NULL) {
if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_REALM, if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_REALM,
realm, len) != STUN_MESSAGE_RETURN_SUCCESS) { realm, len)
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return 0; return 0;
} }
...@@ -1246,7 +1279,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1246,7 +1279,8 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
nonce = (uint8_t *) stun_message_find (resp, STUN_ATTRIBUTE_NONCE, &len); nonce = (uint8_t *) stun_message_find (resp, STUN_ATTRIBUTE_NONCE, &len);
if (nonce != NULL) { if (nonce != NULL) {
if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_NONCE, if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_NONCE,
nonce, len) != STUN_MESSAGE_RETURN_SUCCESS) { nonce, len)
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return 0; return 0;
} }
...@@ -1308,20 +1342,23 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1308,20 +1342,23 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) { priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) {
TURNMessage *msg = g_new0 (TURNMessage, 1); TURNMessage *msg = g_new0 (TURNMessage, 1);
if (!stun_agent_init_request (&priv->agent, &msg->message, if (!stun_agent_init_request (&priv->agent, &msg->message,
msg->buffer, sizeof(msg->buffer), STUN_OLD_SET_ACTIVE_DST)) { msg->buffer, sizeof(msg->buffer),
STUN_OLD_SET_ACTIVE_DST)) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
if (stun_message_append32 (&msg->message, STUN_ATTRIBUTE_MAGIC_COOKIE, if (stun_message_append32 (&msg->message, STUN_ATTRIBUTE_MAGIC_COOKIE,
TURN_MAGIC_COOKIE) != STUN_MESSAGE_RETURN_SUCCESS) { TURN_MAGIC_COOKIE)
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
if (priv->username != NULL && priv->username_len > 0) { if (priv->username != NULL && priv->username_len > 0) {
if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_USERNAME, if (stun_message_append_bytes (&msg->message, STUN_ATTRIBUTE_USERNAME,
priv->username, priv->username_len) != STUN_MESSAGE_RETURN_SUCCESS) { priv->username, priv->username_len)
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
...@@ -1337,7 +1374,8 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1337,7 +1374,8 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
if (stun_message_append_addr (&msg->message, if (stun_message_append_addr (&msg->message,
STUN_ATTRIBUTE_DESTINATION_ADDRESS, STUN_ATTRIBUTE_DESTINATION_ADDRESS,
(struct sockaddr *)&sa, sizeof(sa)) != STUN_MESSAGE_RETURN_SUCCESS) { (struct sockaddr *)&sa, sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
bool stun_message_init (StunMessage *msg, StunClass c, StunMethod m, bool stun_message_init (StunMessage *msg, StunClass c, StunMethod m,
const StunTransactionId id) const StunTransactionId id)
{ {
if (msg->buffer_len < STUN_MESSAGE_HEADER_LENGTH) if (msg->buffer_len < STUN_MESSAGE_HEADER_LENGTH)
return FALSE; return 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