Commit b48f8e6c authored by Youness Alaoui's avatar Youness Alaoui

fix indentation issues

parent cb29f9e7
...@@ -114,9 +114,9 @@ typedef struct { ...@@ -114,9 +114,9 @@ typedef struct {
static void socket_close (NiceSocket *sock); static void socket_close (NiceSocket *sock);
static gint socket_recv (NiceSocket *sock, NiceAddress *from, static gint socket_recv (NiceSocket *sock, NiceAddress *from,
guint len, gchar *buf); guint len, gchar *buf);
static gboolean socket_send (NiceSocket *sock, const NiceAddress *to, static gboolean socket_send (NiceSocket *sock, const NiceAddress *to,
guint len, const gchar *buf); guint len, const gchar *buf);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static void priv_process_pending_bindings (TurnPriv *priv); static void priv_process_pending_bindings (TurnPriv *priv);
...@@ -125,14 +125,14 @@ static gboolean priv_retransmissions_tick (gpointer pointer); ...@@ -125,14 +125,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 *realm, gsize realm_len,
uint8_t *nonce, gsize nonce_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, uint16_t channel,
const NiceAddress *peer); const NiceAddress *peer);
static gboolean priv_add_channel_binding (TurnPriv *priv, static gboolean priv_add_channel_binding (TurnPriv *priv,
const NiceAddress *peer); const NiceAddress *peer);
static gboolean priv_forget_send_request (gpointer pointer); static gboolean priv_forget_send_request (gpointer pointer);
static void priv_clear_permissions (TurnPriv *priv); static void priv_clear_permissions (TurnPriv *priv);
...@@ -163,9 +163,9 @@ priv_send_data_queue_destroy (gpointer data) ...@@ -163,9 +163,9 @@ 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, gchar *username, gchar *password,
NiceTurnSocketCompatibility compatibility) 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);
...@@ -177,20 +177,20 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, ...@@ -177,20 +177,20 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 || if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) { compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC5389, STUN_COMPATIBILITY_RFC5389,
STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS); STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS);
} else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN) { } else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN) {
stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489, STUN_COMPATIBILITY_RFC3489,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS | STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_NO_INDICATION_AUTH); STUN_AGENT_USAGE_NO_INDICATION_AUTH);
} else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE) { } else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE) {
stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489, STUN_COMPATIBILITY_RFC3489,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS | STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_IGNORE_CREDENTIALS); STUN_AGENT_USAGE_IGNORE_CREDENTIALS);
} else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) { } else if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) {
stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&priv->agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_OC2007, STUN_COMPATIBILITY_OC2007,
STUN_AGENT_USAGE_NO_INDICATION_AUTH | STUN_AGENT_USAGE_NO_INDICATION_AUTH |
STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS | STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS |
...@@ -222,10 +222,10 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, ...@@ -222,10 +222,10 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
priv->send_requests = g_queue_new (); priv->send_requests = g_queue_new ();
priv->send_data_queues = priv->send_data_queues =
g_hash_table_new_full (priv_nice_address_hash, g_hash_table_new_full (priv_nice_address_hash,
(GEqualFunc) nice_address_equal, (GEqualFunc) nice_address_equal,
(GDestroyNotify) nice_address_free, (GDestroyNotify) nice_address_free,
priv_send_data_queue_destroy); priv_send_data_queue_destroy);
sock->addr = *addr; sock->addr = *addr;
sock->fileno = base_socket->fileno; sock->fileno = base_socket->fileno;
sock->send = socket_send; sock->send = socket_send;
...@@ -251,7 +251,7 @@ socket_close (NiceSocket *sock) ...@@ -251,7 +251,7 @@ socket_close (NiceSocket *sock)
g_list_free (priv->channels); g_list_free (priv->channels);
g_list_foreach (priv->pending_bindings, (GFunc) nice_address_free, g_list_foreach (priv->pending_bindings, (GFunc) nice_address_free,
NULL); NULL);
g_list_free (priv->pending_bindings); g_list_free (priv->pending_bindings);
if (priv->tick_source_channel_bind != NULL) { if (priv->tick_source_channel_bind != NULL) {
...@@ -297,12 +297,12 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -297,12 +297,12 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
nice_debug ("received message on TURN socket"); nice_debug ("received message on TURN socket");
recv_len = nice_socket_recv (priv->base_socket, &recv_from, recv_len = nice_socket_recv (priv->base_socket, &recv_from,
sizeof(recv_buf), (gchar *) recv_buf); sizeof(recv_buf), (gchar *) recv_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, &recv_from, (gchar *) recv_buf,
(guint) recv_len); (guint) recv_len);
else else
return recv_len; return recv_len;
} }
...@@ -316,7 +316,7 @@ stun_message_append_ms_connection_id(StunMessage *msg, ...@@ -316,7 +316,7 @@ stun_message_append_ms_connection_id(StunMessage *msg,
memcpy(buf, ms_connection_id, 20); memcpy(buf, ms_connection_id, 20);
*(uint32_t*)(buf + 20) = htonl(ms_sequence_num); *(uint32_t*)(buf + 20) = htonl(ms_sequence_num);
return stun_message_append_bytes (msg, STUN_ATTRIBUTE_MS_SEQUENCE_NUMBER, return stun_message_append_bytes (msg, STUN_ATTRIBUTE_MS_SEQUENCE_NUMBER,
buf, 24); buf, 24);
} }
static void static void
...@@ -330,7 +330,7 @@ stun_message_ensure_ms_realm(StunMessage *msg, uint8_t *realm) ...@@ -330,7 +330,7 @@ stun_message_ensure_ms_realm(StunMessage *msg, uint8_t *realm)
if (stun_message_get_method(msg) == STUN_SEND || if (stun_message_get_method(msg) == STUN_SEND ||
stun_message_get_method(msg) == STUN_OLD_SET_ACTIVE_DST) { stun_message_get_method(msg) == STUN_OLD_SET_ACTIVE_DST) {
stun_message_append_bytes (msg, STUN_ATTRIBUTE_REALM, realm, stun_message_append_bytes (msg, STUN_ATTRIBUTE_REALM, realm,
strlen((char *)realm)); strlen((char *)realm));
} }
} }
...@@ -371,7 +371,7 @@ static void ...@@ -371,7 +371,7 @@ static void
priv_add_sent_permission_for_peer (TurnPriv *priv, const NiceAddress *peer) priv_add_sent_permission_for_peer (TurnPriv *priv, const NiceAddress *peer)
{ {
priv->sent_permissions = priv->sent_permissions =
g_list_append (priv->sent_permissions, nice_address_dup (peer)); g_list_append (priv->sent_permissions, nice_address_dup (peer));
} }
static GList * static GList *
...@@ -395,7 +395,7 @@ static void ...@@ -395,7 +395,7 @@ static void
priv_remove_sent_permission_for_peer (TurnPriv *priv, const NiceAddress *peer) priv_remove_sent_permission_for_peer (TurnPriv *priv, const NiceAddress *peer)
{ {
priv->sent_permissions = priv->sent_permissions =
priv_remove_peer_from_list (priv->sent_permissions, peer); priv_remove_peer_from_list (priv->sent_permissions, peer);
} }
static void static void
...@@ -408,7 +408,7 @@ priv_clear_permissions (TurnPriv *priv) ...@@ -408,7 +408,7 @@ priv_clear_permissions (TurnPriv *priv)
static void static void
socket_enqueue_data(TurnPriv *priv, const NiceAddress *to, socket_enqueue_data(TurnPriv *priv, const NiceAddress *to,
guint len, const gchar *buf) guint len, const gchar *buf)
{ {
SendData *data = g_slice_new0 (SendData); SendData *data = g_slice_new0 (SendData);
GQueue *queue = g_hash_table_lookup (priv->send_data_queues, to); GQueue *queue = g_hash_table_lookup (priv->send_data_queues, to);
...@@ -416,7 +416,7 @@ socket_enqueue_data(TurnPriv *priv, const NiceAddress *to, ...@@ -416,7 +416,7 @@ socket_enqueue_data(TurnPriv *priv, const NiceAddress *to,
if (queue == NULL) { if (queue == NULL) {
queue = g_queue_new (); queue = g_queue_new ();
g_hash_table_insert (priv->send_data_queues, nice_address_dup (to), g_hash_table_insert (priv->send_data_queues, nice_address_dup (to),
queue); queue);
} }
data->data = g_memdup(buf, len); data->data = g_memdup(buf, len);
...@@ -432,7 +432,7 @@ socket_dequeue_all_data (TurnPriv *priv, const NiceAddress *to) ...@@ -432,7 +432,7 @@ socket_dequeue_all_data (TurnPriv *priv, const NiceAddress *to)
if (send_queue) { if (send_queue) {
while (!g_queue_is_empty (send_queue)) { while (!g_queue_is_empty (send_queue)) {
SendData *data = SendData *data =
(SendData *) g_queue_pop_head(send_queue); (SendData *) g_queue_pop_head(send_queue);
nice_debug ("dequeing data enqueued when installing permission or binding"); nice_debug ("dequeing data enqueued when installing permission or binding");
nice_socket_send (priv->base_socket, to, data->data_len, data->data); nice_socket_send (priv->base_socket, to, data->data_len, data->data);
...@@ -449,7 +449,7 @@ socket_dequeue_all_data (TurnPriv *priv, const NiceAddress *to) ...@@ -449,7 +449,7 @@ socket_dequeue_all_data (TurnPriv *priv, const NiceAddress *to)
static gboolean static gboolean
socket_send (NiceSocket *sock, const NiceAddress *to, socket_send (NiceSocket *sock, const NiceAddress *to,
guint len, const gchar *buf) guint len, const gchar *buf)
{ {
TurnPriv *priv = (TurnPriv *) sock->priv; TurnPriv *priv = (TurnPriv *) sock->priv;
StunMessage msg; StunMessage msg;
...@@ -489,30 +489,30 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -489,30 +489,30 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 || if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) { priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
if (!stun_agent_init_indication (&priv->agent, &msg, if (!stun_agent_init_indication (&priv->agent, &msg,
buffer, sizeof(buffer), STUN_IND_SEND)) buffer, sizeof(buffer), STUN_IND_SEND))
goto send; goto send;
if (stun_message_append_xor_addr (&msg, STUN_ATTRIBUTE_PEER_ADDRESS, if (stun_message_append_xor_addr (&msg, STUN_ATTRIBUTE_PEER_ADDRESS,
(struct sockaddr *)&sa, sizeof(sa)) != (struct sockaddr *)&sa, sizeof(sa)) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
} else { } else {
if (!stun_agent_init_request (&priv->agent, &msg, if (!stun_agent_init_request (&priv->agent, &msg,
buffer, sizeof(buffer), STUN_SEND)) buffer, sizeof(buffer), STUN_SEND))
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) != TURN_MAGIC_COOKIE) !=
STUN_MESSAGE_RETURN_SUCCESS) 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,
priv->username, priv->username_len) != priv->username, priv->username_len) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
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, (struct sockaddr *)&sa,
sizeof(sa)) != STUN_MESSAGE_RETURN_SUCCESS) 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 &&
...@@ -533,20 +533,20 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -533,20 +533,20 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
} }
if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_DATA, if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_DATA,
buf, len) != STUN_MESSAGE_RETURN_SUCCESS) buf, len) != STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
msg_len = stun_agent_finish_message (&priv->agent, &msg, msg_len = stun_agent_finish_message (&priv->agent, &msg,
priv->password, priv->password_len); priv->password, priv->password_len);
if (msg_len > 0 && stun_message_get_class (&msg) == STUN_REQUEST) { if (msg_len > 0 && stun_message_get_class (&msg) == STUN_REQUEST) {
SendRequest *req = g_slice_new0 (SendRequest); SendRequest *req = g_slice_new0 (SendRequest);
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, req->source = agent_timeout_add_with_context (priv->nice,
STUN_END_TIMEOUT, STUN_END_TIMEOUT,
priv_forget_send_request, priv_forget_send_request,
req); req);
g_queue_push_tail (priv->send_requests, req); g_queue_push_tail (priv->send_requests, req);
} }
} }
...@@ -569,7 +569,7 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -569,7 +569,7 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
return TRUE; return TRUE;
} else { } else {
return nice_socket_send (priv->base_socket, &priv->server_addr, return nice_socket_send (priv->base_socket, &priv->server_addr,
msg_len, (gchar *)buffer); msg_len, (gchar *)buffer);
} }
} }
send: send:
...@@ -592,7 +592,7 @@ priv_forget_send_request (gpointer pointer) ...@@ -592,7 +592,7 @@ priv_forget_send_request (gpointer pointer)
if (g_source_is_destroyed (g_main_current_source ())) { if (g_source_is_destroyed (g_main_current_source ())) {
nice_debug ("Source was destroyed. " nice_debug ("Source was destroyed. "
"Avoided race condition in turn.c:priv_forget_send_request"); "Avoided race condition in turn.c:priv_forget_send_request");
agent_unlock (); agent_unlock ();
return FALSE; return FALSE;
} }
...@@ -651,8 +651,8 @@ priv_binding_timeout (gpointer data) ...@@ -651,8 +651,8 @@ priv_binding_timeout (gpointer data)
gint gint
nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
NiceAddress *from, guint len, gchar *buf, NiceAddress *from, guint len, gchar *buf,
NiceAddress *recv_from, gchar *recv_buf, guint recv_len) NiceAddress *recv_from, gchar *recv_buf, guint recv_len)
{ {
TurnPriv *priv = (TurnPriv *) sock->priv; TurnPriv *priv = (TurnPriv *) sock->priv;
...@@ -665,15 +665,15 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -665,15 +665,15 @@ 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, (uint8_t *) recv_buf, (size_t) recv_len, NULL,
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 &&
priv->compatibility != NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) { priv->compatibility != NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
uint32_t cookie; uint32_t cookie;
if (stun_message_find32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE, if (stun_message_find32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE,
&cookie) != STUN_MESSAGE_RETURN_SUCCESS) &cookie) != STUN_MESSAGE_RETURN_SUCCESS)
goto recv; goto recv;
if (cookie != TURN_MAGIC_COOKIE) if (cookie != TURN_MAGIC_COOKIE)
goto recv; goto recv;
...@@ -720,13 +720,13 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -720,13 +720,13 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
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, if (memcmp (request_id, response_id,
sizeof(StunTransactionId)) == 0) { 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;
if (stun_message_get_class (&msg) == STUN_RESPONSE && if (stun_message_get_class (&msg) == STUN_RESPONSE &&
(priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN || (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007)) { priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007)) {
goto msn_google_lock; goto msn_google_lock;
} else { } else {
g_free (priv->current_binding); g_free (priv->current_binding);
...@@ -744,7 +744,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -744,7 +744,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
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, if (memcmp (request_id, response_id,
sizeof(StunTransactionId)) == 0) { 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;
...@@ -753,30 +753,30 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -753,30 +753,30 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
uint16_t recv_realm_len = 0; uint16_t recv_realm_len = 0;
sent_realm = sent_realm =
(uint8_t *) stun_message_find ( (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 = recv_realm =
(uint8_t *) stun_message_find (&msg, (uint8_t *) stun_message_find (&msg,
STUN_ATTRIBUTE_REALM, &recv_realm_len); STUN_ATTRIBUTE_REALM, &recv_realm_len);
/* check for unauthorized error response */ /* check for unauthorized error response */
if (stun_message_find_error (&msg, &code) == if (stun_message_find_error (&msg, &code) ==
STUN_MESSAGE_RETURN_SUCCESS && STUN_MESSAGE_RETURN_SUCCESS &&
(code == 438 || (code == 401 && (code == 438 || (code == 401 &&
!(recv_realm != NULL && !(recv_realm != NULL &&
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, memcmp (sent_realm, recv_realm,
sent_realm_len) == 0)))) { sent_realm_len) == 0)))) {
if (priv->current_binding) { if (priv->current_binding) {
g_free (priv->current_binding_msg); g_free (priv->current_binding_msg);
priv->current_binding_msg = NULL; priv->current_binding_msg = NULL;
priv_send_channel_bind (priv, &msg, priv_send_channel_bind (priv, &msg,
priv->current_binding->channel, priv->current_binding->channel,
&priv->current_binding->peer); &priv->current_binding->peer);
} else { } else {
/* look up binding associated with peer */ /* look up binding associated with peer */
GList *i = priv->channels; GList *i = priv->channels;
...@@ -786,8 +786,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -786,8 +786,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
NiceAddress to; NiceAddress to;
stun_message_find_xor_addr (&priv->current_binding_msg->message, stun_message_find_xor_addr (&priv->current_binding_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa,
&sa_len); &sa_len);
nice_address_set_from_sockaddr (&to, &sa); nice_address_set_from_sockaddr (&to, &sa);
for (; i; i = i->next) { for (; i; i = i->next) {
...@@ -818,7 +818,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -818,7 +818,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (priv->current_binding) { if (priv->current_binding) {
priv->current_binding->active = TRUE; priv->current_binding->active = TRUE;
priv->channels = g_list_append (priv->channels, priv->channels = g_list_append (priv->channels,
priv->current_binding); priv->current_binding);
priv->current_binding = NULL; priv->current_binding = NULL;
} }
priv_process_pending_bindings (priv); priv_process_pending_bindings (priv);
...@@ -826,8 +826,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -826,8 +826,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
/* install timer to schedule refresh of the permission */ /* install timer to schedule refresh of the permission */
if (!priv->binding_timeout_source) { if (!priv->binding_timeout_source) {
priv->binding_timeout_source = priv->binding_timeout_source =
g_timeout_add_seconds (STUN_BINDING_TIMEOUT, g_timeout_add_seconds (STUN_BINDING_TIMEOUT,
priv_binding_timeout, priv); priv_binding_timeout, priv);
} }
} }
} }
...@@ -840,7 +840,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -840,7 +840,7 @@ 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, stun_message_id (&priv->current_create_permission_msg->message,
request_id); 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;
...@@ -850,8 +850,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -850,8 +850,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
nice_debug ("got response for CreatePermission"); nice_debug ("got response for CreatePermission");
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, &peer, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &peer,
&peer_len); &peer_len);
nice_address_set_from_sockaddr (&to, &peer); nice_address_set_from_sockaddr (&to, &peer);
g_free (priv->current_create_permission_msg); g_free (priv->current_create_permission_msg);
...@@ -868,13 +868,13 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -868,13 +868,13 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
uint16_t recv_nonce_len = 0; uint16_t recv_nonce_len = 0;
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);
recv_nonce = (uint8_t *) stun_message_find (&msg, recv_nonce = (uint8_t *) stun_message_find (&msg,
STUN_ATTRIBUTE_NONCE, &recv_nonce_len); STUN_ATTRIBUTE_NONCE, &recv_nonce_len);
/* resend CreatePermission */ /* resend CreatePermission */
priv_send_create_permission (priv, recv_realm, recv_realm_len, priv_send_create_permission (priv, recv_realm, recv_realm_len,
recv_nonce, recv_nonce_len, &to); recv_nonce, recv_nonce_len, &to);
} else { } else {
/* we now have a permission installed for this peer */ /* we now have a permission installed for this peer */
priv_remove_sent_permission_for_peer (priv, &to); priv_remove_sent_permission_for_peer (priv, &to);
...@@ -885,8 +885,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -885,8 +885,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (stun_message_get_class (&msg) == STUN_RESPONSE && if (stun_message_get_class (&msg) == STUN_RESPONSE &&
!priv->permission_timeout_source) { !priv->permission_timeout_source) {
priv->permission_timeout_source = priv->permission_timeout_source =
g_timeout_add_seconds (STUN_PERMISSION_TIMEOUT, g_timeout_add_seconds (STUN_PERMISSION_TIMEOUT,
priv_permission_timeout, priv); priv_permission_timeout, priv);
} }
/* send enqued data */ /* send enqued data */
...@@ -897,25 +897,25 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -897,25 +897,25 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
return 0; return 0;
} else if (stun_message_get_class (&msg) == STUN_INDICATION && } else if (stun_message_get_class (&msg) == STUN_INDICATION &&
stun_message_get_method (&msg) == STUN_IND_DATA) { stun_message_get_method (&msg) == STUN_IND_DATA) {
uint16_t data_len; uint16_t data_len;
uint8_t *data; uint8_t *data;
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 || if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) { priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
if (stun_message_find_xor_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS, if (stun_message_find_xor_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS,
(struct sockaddr *)&sa, &from_len) != (struct sockaddr *)&sa, &from_len) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto recv; goto recv;
} else { } else {
if (stun_message_find_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS, if (stun_message_find_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS,
(struct sockaddr *)&sa, &from_len) != (struct sockaddr *)&sa, &from_len) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto recv; goto recv;
} }
data = (uint8_t *) stun_message_find (&msg, STUN_ATTRIBUTE_DATA, data = (uint8_t *) stun_message_find (&msg, STUN_ATTRIBUTE_DATA,
&data_len); &data_len);
if (data == NULL) if (data == NULL)
goto recv; goto recv;
...@@ -1001,31 +1001,31 @@ priv_retransmissions_tick_unlocked (TurnPriv *priv) ...@@ -1001,31 +1001,31 @@ priv_retransmissions_tick_unlocked (TurnPriv *priv)
{ {
if (priv->current_binding_msg) { if (priv->current_binding_msg) {
switch (stun_timer_refresh (&priv->current_binding_msg->timer)) { switch (stun_timer_refresh (&priv->current_binding_msg->timer)) {
case STUN_USAGE_TIMER_RETURN_TIMEOUT: case STUN_USAGE_TIMER_RETURN_TIMEOUT:
{ {
/* Time out */ /* Time out */
StunTransactionId id; StunTransactionId id;
stun_message_id (&priv->current_binding_msg->message, id); stun_message_id (&priv->current_binding_msg->message, id);
stun_agent_forget_transaction (&priv->agent, id); stun_agent_forget_transaction (&priv->agent, id);
g_free (priv->current_binding); g_free (priv->current_binding);
priv->current_binding = NULL; priv->current_binding = NULL;
g_free (priv->current_binding_msg); g_free (priv->current_binding_msg);
priv->current_binding_msg = NULL; priv->current_binding_msg = NULL;
priv_process_pending_bindings (priv); priv_process_pending_bindings (priv);
break;
}
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
/* Retransmit */
nice_socket_send (priv->base_socket, &priv->server_addr,
stun_message_length (&priv->current_binding_msg->message),
(gchar *)priv->current_binding_msg->buffer);
break;
case STUN_USAGE_TIMER_RETURN_SUCCESS:
break; break;
}
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
/* Retransmit */
nice_socket_send (priv->base_socket, &priv->server_addr,
stun_message_length (&priv->current_binding_msg->message),
(gchar *)priv->current_binding_msg->buffer);
break;
case STUN_USAGE_TIMER_RETURN_SUCCESS:
break;
} }
} }
...@@ -1038,43 +1038,43 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv) ...@@ -1038,43 +1038,43 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv)
{ {
if (priv->current_create_permission_msg) { if (priv->current_create_permission_msg) {
switch (stun_timer_refresh (&priv->current_create_permission_msg->timer)) { switch (stun_timer_refresh (&priv->current_create_permission_msg->timer)) {
case STUN_USAGE_TIMER_RETURN_TIMEOUT: case STUN_USAGE_TIMER_RETURN_TIMEOUT:
{ {
/* Time out */ /* Time out */
StunTransactionId id; StunTransactionId id;
NiceAddress to; NiceAddress to;
struct sockaddr addr; struct sockaddr addr;
socklen_t addr_len = sizeof(addr); socklen_t addr_len = sizeof(addr);
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, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr,
&addr_len); &addr_len);
nice_address_set_from_sockaddr (&to, &addr); nice_address_set_from_sockaddr (&to, &addr);
priv_remove_sent_permission_for_peer (priv, &to); priv_remove_sent_permission_for_peer (priv, &to);
g_free (priv->current_create_permission_msg); g_free (priv->current_create_permission_msg);
priv->current_create_permission_msg = NULL; priv->current_create_permission_msg = NULL;
/* we got a timeout when retransmitting a CreatePermission /* we got a timeout when retransmitting a CreatePermission
message, assume we can just send the data, the server message, assume we can just send the data, the server
might not support RFC TURN, or connectivity check will might not support RFC TURN, or connectivity check will
fail eventually anyway */ fail eventually anyway */
priv_add_permission_for_peer (priv, &to); priv_add_permission_for_peer (priv, &to);
socket_dequeue_all_data (priv, &to); socket_dequeue_all_data (priv, &to);
break;
}
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
/* Retransmit */
nice_socket_send (priv->base_socket, &priv->server_addr,
stun_message_length (&priv->current_create_permission_msg->message),
(gchar *)priv->current_create_permission_msg->buffer);
break;
case STUN_USAGE_TIMER_RETURN_SUCCESS:
break; break;
}
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
/* Retransmit */
nice_socket_send (priv->base_socket, &priv->server_addr,
stun_message_length (&priv->current_create_permission_msg->message),
(gchar *)priv->current_create_permission_msg->buffer);
break;
case STUN_USAGE_TIMER_RETURN_SUCCESS:
break;
} }
} }
...@@ -1091,7 +1091,7 @@ priv_retransmissions_tick (gpointer pointer) ...@@ -1091,7 +1091,7 @@ priv_retransmissions_tick (gpointer pointer)
agent_lock (); agent_lock ();
if (g_source_is_destroyed (g_main_current_source ())) { if (g_source_is_destroyed (g_main_current_source ())) {
nice_debug ("Source was destroyed. " nice_debug ("Source was destroyed. "
"Avoided race condition in turn.c:priv_retransmissions_tick"); "Avoided race condition in turn.c:priv_retransmissions_tick");
agent_unlock (); agent_unlock ();
return FALSE; return FALSE;
} }
...@@ -1118,7 +1118,7 @@ priv_retransmissions_create_permission_tick (gpointer pointer) ...@@ -1118,7 +1118,7 @@ priv_retransmissions_create_permission_tick (gpointer pointer)
agent_lock (); agent_lock ();
if (g_source_is_destroyed (g_main_current_source ())) { if (g_source_is_destroyed (g_main_current_source ())) {
nice_debug ("Source was destroyed. " nice_debug ("Source was destroyed. "
"Avoided race condition in turn.c:priv_retransmissions_create_permission_tick"); "Avoided race condition in turn.c:priv_retransmissions_create_permission_tick");
agent_unlock (); agent_unlock ();
return FALSE; return FALSE;
} }
...@@ -1160,10 +1160,10 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1160,10 +1160,10 @@ priv_schedule_tick (TurnPriv *priv)
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 = priv->tick_source_create_permission =
agent_timeout_add_with_context (priv->nice, agent_timeout_add_with_context (priv->nice,
timeout, timeout,
priv_retransmissions_create_permission_tick, priv_retransmissions_create_permission_tick,
priv); priv);
} else { } else {
priv_retransmissions_create_permission_tick_unlocked (priv); priv_retransmissions_create_permission_tick_unlocked (priv);
} }
...@@ -1181,7 +1181,7 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg) ...@@ -1181,7 +1181,7 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg)
} }
nice_socket_send (priv->base_socket, &priv->server_addr, nice_socket_send (priv->base_socket, &priv->server_addr,
stun_len, (gchar *)msg->buffer); stun_len, (gchar *)msg->buffer);
if (nice_socket_is_reliable (priv->base_socket)) { if (nice_socket_is_reliable (priv->base_socket)) {
stun_timer_start_reliable (&msg->timer, stun_timer_start_reliable (&msg->timer,
...@@ -1197,8 +1197,8 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg) ...@@ -1197,8 +1197,8 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg)
static gboolean static gboolean
priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len, priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len,
uint8_t *nonce, gsize nonce_len, uint8_t *nonce, gsize nonce_len,
const NiceAddress *peer) const NiceAddress *peer)
{ {
guint msg_buf_len; guint msg_buf_len;
gboolean res = FALSE; gboolean res = FALSE;
...@@ -1214,20 +1214,20 @@ priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len, ...@@ -1214,20 +1214,20 @@ 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, msg->buffer,
sizeof(msg->buffer), sizeof(msg->buffer),
priv->username, priv->username,
priv->username_len, priv->username_len,
priv->password, priv->password,
priv->password_len, priv->password_len,
realm, realm_len, realm, realm_len,
nonce, nonce_len, nonce, nonce_len,
&addr, &addr,
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766); NICE_TURN_SOCKET_COMPATIBILITY_RFC5766);
if (msg_buf_len > 0) { if (msg_buf_len > 0) {
res = nice_socket_send (priv->base_socket, &priv->server_addr, res = nice_socket_send (priv->base_socket, &priv->server_addr,
msg_buf_len, (gchar *) msg->buffer); msg_buf_len, (gchar *) msg->buffer);
if (nice_socket_is_reliable (priv->base_socket)) { if (nice_socket_is_reliable (priv->base_socket)) {
stun_timer_start_reliable (&msg->timer); stun_timer_start_reliable (&msg->timer);
...@@ -1246,7 +1246,7 @@ priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len, ...@@ -1246,7 +1246,7 @@ priv_send_create_permission(TurnPriv *priv, uint8_t *realm, gsize realm_len,
static gboolean static gboolean
priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
uint16_t channel, const NiceAddress *peer) uint16_t channel, const NiceAddress *peer)
{ {
uint32_t channel_attr = channel << 16; uint32_t channel_attr = channel << 16;
size_t stun_len; size_t stun_len;
...@@ -1256,21 +1256,21 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1256,21 +1256,21 @@ 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), msg->buffer, sizeof(msg->buffer),
STUN_CHANNELBIND)) { STUN_CHANNELBIND)) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
if (stun_message_append32 (&msg->message, STUN_ATTRIBUTE_CHANNEL_NUMBER, if (stun_message_append32 (&msg->message, STUN_ATTRIBUTE_CHANNEL_NUMBER,
channel_attr) != STUN_MESSAGE_RETURN_SUCCESS) { channel_attr) != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
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, (struct sockaddr *)&sa,
sizeof(sa)) sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
...@@ -1278,7 +1278,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1278,7 +1278,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
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) priv->username, priv->username_len)
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
...@@ -1293,7 +1293,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1293,7 +1293,7 @@ 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) realm, len)
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return 0; return 0;
...@@ -1302,7 +1302,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1302,7 +1302,7 @@ 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) nonce, len)
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return 0; return 0;
...@@ -1311,7 +1311,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1311,7 +1311,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
} }
stun_len = stun_agent_finish_message (&priv->agent, &msg->message, stun_len = stun_agent_finish_message (&priv->agent, &msg->message,
priv->password, priv->password_len); priv->password, priv->password_len);
if (stun_len > 0) { if (stun_len > 0) {
priv_send_turn_message (priv, msg); priv_send_turn_message (priv, msg);
...@@ -1361,17 +1361,17 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1361,17 +1361,17 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
} }
return FALSE; return FALSE;
} else if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN || } else if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN ||
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), msg->buffer, sizeof(msg->buffer),
STUN_OLD_SET_ACTIVE_DST)) { 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) TURN_MAGIC_COOKIE)
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
...@@ -1379,7 +1379,7 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1379,7 +1379,7 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
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) priv->username, priv->username_len)
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
...@@ -1388,22 +1388,22 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1388,22 +1388,22 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) { if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) {
if (priv->ms_connection_id_valid) if (priv->ms_connection_id_valid)
stun_message_append_ms_connection_id(&msg->message, stun_message_append_ms_connection_id(&msg->message,
priv->ms_connection_id, ++priv->ms_sequence_num); priv->ms_connection_id, ++priv->ms_sequence_num);
stun_message_ensure_ms_realm(&msg->message, priv->ms_realm); stun_message_ensure_ms_realm(&msg->message, priv->ms_realm);
} }
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)) (struct sockaddr *)&sa, sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
} }
stun_len = stun_agent_finish_message (&priv->agent, &msg->message, stun_len = stun_agent_finish_message (&priv->agent, &msg->message,
priv->password, priv->password_len); priv->password, priv->password_len);
if (stun_len > 0) { if (stun_len > 0) {
priv->current_binding = g_new0 (ChannelBinding, 1); priv->current_binding = g_new0 (ChannelBinding, 1);
...@@ -1448,8 +1448,8 @@ nice_turn_socket_set_ms_connection_id (NiceSocket *sock, StunMessage *msg) ...@@ -1448,8 +1448,8 @@ nice_turn_socket_set_ms_connection_id (NiceSocket *sock, StunMessage *msg)
STUN_ATTRIBUTE_MS_SEQUENCE_NUMBER, &alen); STUN_ATTRIBUTE_MS_SEQUENCE_NUMBER, &alen);
if (ms_seq_num && alen == 24) { if (ms_seq_num && alen == 24) {
memcpy (priv->ms_connection_id, ms_seq_num, 20); memcpy (priv->ms_connection_id, ms_seq_num, 20);
priv->ms_sequence_num = ntohl((uint32_t)*(ms_seq_num + 20)); priv->ms_sequence_num = ntohl((uint32_t)*(ms_seq_num + 20));
priv->ms_connection_id_valid = TRUE; priv->ms_connection_id_valid = TRUE;
} }
} }
...@@ -106,7 +106,7 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg, ...@@ -106,7 +106,7 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg,
} }
if ((compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 || if ((compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 ||
compatibility == STUN_USAGE_TURN_COMPATIBILITY_RFC5766) && compatibility == STUN_USAGE_TURN_COMPATIBILITY_RFC5766) &&
request_props != STUN_USAGE_TURN_REQUEST_PORT_NORMAL) { request_props != STUN_USAGE_TURN_REQUEST_PORT_NORMAL) {
uint32_t req = 0; uint32_t req = 0;
...@@ -223,40 +223,40 @@ size_t stun_usage_turn_create_permission (StunAgent *agent, StunMessage *msg, ...@@ -223,40 +223,40 @@ size_t stun_usage_turn_create_permission (StunAgent *agent, StunMessage *msg,
struct sockaddr *peer, struct sockaddr *peer,
StunUsageTurnCompatibility compatibility) StunUsageTurnCompatibility compatibility)
{ {
stun_agent_init_request (agent, msg, buffer, buffer_len, stun_agent_init_request (agent, msg, buffer, buffer_len,
STUN_CREATEPERMISSION); STUN_CREATEPERMISSION);
/* PEER address */ /* PEER address */
if (peer) { if (peer) {
if (stun_message_append_xor_addr (msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, if (stun_message_append_xor_addr (msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS,
peer, sizeof(*peer)) != STUN_MESSAGE_RETURN_SUCCESS) { peer, sizeof(*peer)) != STUN_MESSAGE_RETURN_SUCCESS) {
return 0; return 0;
} }
} }
/* nonce */ /* nonce */
if (nonce != NULL) { if (nonce != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_NONCE, if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_NONCE,
nonce, nonce_len) != STUN_MESSAGE_RETURN_SUCCESS) nonce, nonce_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0; return 0;
} }
/* realm */ /* realm */
if (realm != NULL) { if (realm != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_REALM, if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_REALM,
realm, realm_len) != STUN_MESSAGE_RETURN_SUCCESS) realm, realm_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0; return 0;
} }
/* username */ /* username */
if (username != NULL) { if (username != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_USERNAME, if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_USERNAME,
username, username_len) != STUN_MESSAGE_RETURN_SUCCESS) username, username_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0; return 0;
} }
stun_debug("before stun_agent_finish_message \n"); stun_debug("before stun_agent_finish_message \n");
return stun_agent_finish_message (agent, msg, password, password_len); return stun_agent_finish_message (agent, msg, password, password_len);
} }
...@@ -339,7 +339,7 @@ StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg, ...@@ -339,7 +339,7 @@ StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg,
return STUN_USAGE_TURN_RETURN_ERROR; return STUN_USAGE_TURN_RETURN_ERROR;
} }
} else if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_MSN || } else if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_MSN ||
compatibility == STUN_USAGE_TURN_COMPATIBILITY_OC2007) { compatibility == STUN_USAGE_TURN_COMPATIBILITY_OC2007) {
val = stun_message_find_addr (msg, val = stun_message_find_addr (msg,
STUN_ATTRIBUTE_MSN_MAPPED_ADDRESS, addr, addrlen); STUN_ATTRIBUTE_MSN_MAPPED_ADDRESS, addr, addrlen);
......
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