Commit bbd1d93e authored by Marcus Lundblad's avatar Marcus Lundblad Committed by Youness Alaoui

Remaining changes for RFC 5766

parent a58b6e00
...@@ -172,7 +172,7 @@ nice_interfaces_get_local_ips (gboolean include_loopback) ...@@ -172,7 +172,7 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
GList *ips = NULL; GList *ips = NULL;
struct ifaddrs *ifa, *results; struct ifaddrs *ifa, *results;
GList *loopbacks = NULL; GList *loopbacks = NULL;
int ret;
if (getifaddrs (&results) < 0) if (getifaddrs (&results) < 0)
return NULL; return NULL;
......
This diff is collapsed.
...@@ -43,6 +43,7 @@ typedef enum { ...@@ -43,6 +43,7 @@ typedef enum {
NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE, NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE,
NICE_TURN_SOCKET_COMPATIBILITY_MSN, NICE_TURN_SOCKET_COMPATIBILITY_MSN,
NICE_TURN_SOCKET_COMPATIBILITY_OC2007, NICE_TURN_SOCKET_COMPATIBILITY_OC2007,
NICE_TURN_SOCKET_COMPATIBILITY_RFC5766,
} NiceTurnSocketCompatibility; } NiceTurnSocketCompatibility;
#include "socket.h" #include "socket.h"
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "stunhmac.h" #include "stunhmac.h"
#include "stun5389.h" #include "stun5389.h"
#include "utils.h" #include "utils.h"
#include "debug.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -548,6 +549,7 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg, ...@@ -548,6 +549,7 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
STUN_ATTRIBUTE_REALM, &realm_len); STUN_ATTRIBUTE_REALM, &realm_len);
username = (uint8_t *) stun_message_find (msg, username = (uint8_t *) stun_message_find (msg,
STUN_ATTRIBUTE_USERNAME, &username_len); STUN_ATTRIBUTE_USERNAME, &username_len);
if (username == NULL || realm == NULL) { if (username == NULL || realm == NULL) {
skip = TRUE; skip = TRUE;
} else { } else {
...@@ -640,6 +642,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg, ...@@ -640,6 +642,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
msg->key = (uint8_t *) key; msg->key = (uint8_t *) key;
msg->key_len = key_len; msg->key_len = key_len;
stun_debug("stun_agent_finish_message, returning lenght: %d\n",
stun_message_length(msg));
return stun_message_length (msg); return stun_message_length (msg);
} }
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
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;
......
...@@ -238,7 +238,7 @@ static void test_turn (char *username, char *password, char *hostname, int port) ...@@ -238,7 +238,7 @@ static void test_turn (char *username, char *password, char *hostname, int port)
static void turnserver (void) static void turnserver (void)
{ {
test_turn ("toto", "password", "127.0.0.1", "3478"); test_turn ("anonymous", "anonymous", "91.121.109.155", "3480");
} }
static void numb (void) static void numb (void)
......
...@@ -79,7 +79,8 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg, ...@@ -79,7 +79,8 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg,
{ {
stun_agent_init_request (agent, msg, buffer, buffer_len, STUN_ALLOCATE); stun_agent_init_request (agent, msg, buffer, buffer_len, STUN_ALLOCATE);
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9) { if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 ||
compatibility == STUN_USAGE_TURN_COMPATIBILITY_RFC5766) {
if (stun_message_append32 (msg, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, if (stun_message_append32 (msg, STUN_ATTRIBUTE_REQUESTED_TRANSPORT,
TURN_REQUESTED_TRANSPORT_UDP) != STUN_MESSAGE_RETURN_SUCCESS) TURN_REQUESTED_TRANSPORT_UDP) != STUN_MESSAGE_RETURN_SUCCESS)
return 0; return 0;
...@@ -104,7 +105,8 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg, ...@@ -104,7 +105,8 @@ size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg,
return 0; return 0;
} }
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 && if ((compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 ||
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;
...@@ -166,7 +168,8 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg, ...@@ -166,7 +168,8 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg,
StunUsageTurnCompatibility compatibility) StunUsageTurnCompatibility compatibility)
{ {
if (compatibility != STUN_USAGE_TURN_COMPATIBILITY_DRAFT9) { if (compatibility != STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 &&
compatibility != STUN_USAGE_TURN_COMPATIBILITY_RFC5766) {
return stun_usage_turn_create (agent, msg, buffer, buffer_len, return stun_usage_turn_create (agent, msg, buffer, buffer_len,
previous_response, STUN_USAGE_TURN_REQUEST_PORT_NORMAL, 0, lifetime, previous_response, STUN_USAGE_TURN_REQUEST_PORT_NORMAL, 0, lifetime,
username, username_len, password, password_len, compatibility); username, username_len, password, password_len, compatibility);
...@@ -211,6 +214,52 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg, ...@@ -211,6 +214,52 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg,
return stun_agent_finish_message (agent, msg, password, password_len); return stun_agent_finish_message (agent, msg, password, password_len);
} }
size_t stun_usage_turn_create_permission (StunAgent *agent, StunMessage *msg,
uint8_t *buffer, size_t buffer_len,
uint8_t *username, size_t username_len,
uint8_t *password, size_t password_len,
uint8_t *realm, size_t realm_len,
uint8_t *nonce, size_t nonce_len,
struct sockaddr *peer,
StunUsageTurnCompatibility compatibility)
{
stun_agent_init_request (agent, msg, buffer, buffer_len,
STUN_CREATEPERMISSION);
/* PEER address */
if (peer) {
if (stun_message_append_xor_addr (msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS,
peer, sizeof(*peer)) != STUN_MESSAGE_RETURN_SUCCESS) {
return 0;
}
}
/* nonce */
if (nonce != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_NONCE,
nonce, nonce_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0;
}
/* realm */
if (realm != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_REALM,
realm, realm_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0;
}
/* username */
if (username != NULL) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_USERNAME,
username, username_len) != STUN_MESSAGE_RETURN_SUCCESS)
return 0;
}
stun_debug("before stun_agent_finish_message \n");
return stun_agent_finish_message (agent, msg, password, password_len);
}
StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg, StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg,
struct sockaddr *relay_addr, socklen_t *relay_addrlen, struct sockaddr *relay_addr, socklen_t *relay_addrlen,
struct sockaddr *addr, socklen_t *addrlen, struct sockaddr *addr, socklen_t *addrlen,
...@@ -269,7 +318,8 @@ StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg, ...@@ -269,7 +318,8 @@ StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg,
stun_debug ("Received %u-bytes STUN message\n", stun_message_length (msg)); stun_debug ("Received %u-bytes STUN message\n", stun_message_length (msg));
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9) { if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 ||
compatibility == STUN_USAGE_TURN_COMPATIBILITY_RFC5766) {
val = stun_message_find_xor_addr (msg, val = stun_message_find_xor_addr (msg,
STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, addr, addrlen); STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, addr, addrlen);
...@@ -320,7 +370,8 @@ StunUsageTurnReturn stun_usage_turn_refresh_process (StunMessage *msg, ...@@ -320,7 +370,8 @@ StunUsageTurnReturn stun_usage_turn_refresh_process (StunMessage *msg,
int code = -1; int code = -1;
StunUsageTurnReturn ret = STUN_USAGE_TURN_RETURN_RELAY_SUCCESS; StunUsageTurnReturn ret = STUN_USAGE_TURN_RETURN_RELAY_SUCCESS;
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9) { if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_DRAFT9 ||
compatibility == STUN_USAGE_TURN_COMPATIBILITY_RFC5766) {
if (stun_message_get_method (msg) != STUN_REFRESH) if (stun_message_get_method (msg) != STUN_REFRESH)
return STUN_USAGE_TURN_RETURN_INVALID; return STUN_USAGE_TURN_RETURN_INVALID;
} else { } else {
......
...@@ -59,8 +59,14 @@ ...@@ -59,8 +59,14 @@
# include <stdint.h> # include <stdint.h>
#endif #endif
# include "stun/stunagent.h" #ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#endif
# include "stun/stunagent.h"
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
# endif # endif
...@@ -97,6 +103,7 @@ typedef enum { ...@@ -97,6 +103,7 @@ typedef enum {
STUN_USAGE_TURN_COMPATIBILITY_GOOGLE, STUN_USAGE_TURN_COMPATIBILITY_GOOGLE,
STUN_USAGE_TURN_COMPATIBILITY_MSN, STUN_USAGE_TURN_COMPATIBILITY_MSN,
STUN_USAGE_TURN_COMPATIBILITY_OC2007 STUN_USAGE_TURN_COMPATIBILITY_OC2007
STUN_USAGE_TURN_COMPATIBILITY_RFC5766,
} StunUsageTurnCompatibility; } StunUsageTurnCompatibility;
/** /**
...@@ -197,6 +204,16 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg, ...@@ -197,6 +204,16 @@ size_t stun_usage_turn_create_refresh (StunAgent *agent, StunMessage *msg,
uint8_t *password, size_t password_len, uint8_t *password, size_t password_len,
StunUsageTurnCompatibility compatibility); StunUsageTurnCompatibility compatibility);
size_t stun_usage_turn_create_permission (StunAgent *agent, StunMessage *msg,
uint8_t *buffer, size_t buffer_len,
uint8_t *username, size_t username_len,
uint8_t *password, size_t password_len,
uint8_t *realm, size_t realm_len,
uint8_t *nonce, size_t nonce_len,
struct sockaddr *peer,
StunUsageTurnCompatibility compatibility);
/** /**
* stun_usage_turn_process: * stun_usage_turn_process:
* @msg: The message containing the response * @msg: The message containing the response
......
...@@ -44,9 +44,10 @@ ...@@ -44,9 +44,10 @@
#include <string.h> #include <string.h>
#define USE_TURN 0 #define USE_TURN 1
#define USE_LOOPBACK 1 #define USE_LOOPBACK 1
#define TEST_GOOGLE 0 #define TEST_GOOGLE 0
#define USE_TURN_SERVER_ORG 1
#define PROXY_IP "127.0.0.1" #define PROXY_IP "127.0.0.1"
#define PROXY_PORT 1080 #define PROXY_PORT 1080
...@@ -85,10 +86,10 @@ ...@@ -85,10 +86,10 @@
#define NUMB_USER "youness.alaoui@collabora.co.uk" #define NUMB_USER "youness.alaoui@collabora.co.uk"
#define NUMB_PASS "badger" #define NUMB_PASS "badger"
#define TSORG_IP "127.0.0.1" #define TSORG_IP "91.121.109.155"
#define TSORG_PORT 3478 #define TSORG_PORT 3480
#define TSORG_USER "toto" #define TSORG_USER "anonymous"
#define TSORG_PASS "password" #define TSORG_PASS "anonymous"
#if USE_TURN_SERVER_ORG #if USE_TURN_SERVER_ORG
...@@ -348,6 +349,7 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas ...@@ -348,6 +349,7 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
g_assert (ls_id > 0); g_assert (ls_id > 0);
g_assert (rs_id > 0); g_assert (rs_id > 0);
#if USE_TURN #if USE_TURN
nice_debug("TURN_IP: %s\n", TURN_IP);
nice_agent_set_relay_info(lagent, ls_id, 1, nice_agent_set_relay_info(lagent, ls_id, 1,
TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE); TURN_IP, TURN_PORT, TURN_USER, TURN_PASS, TURN_TYPE);
nice_agent_set_relay_info(lagent, ls_id, 2, nice_agent_set_relay_info(lagent, ls_id, 2,
......
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