Commit 4c8e1f40 authored by Youness Alaoui's avatar Youness Alaoui

Add full TURN support for the turn usage allocate request

parent 0c08c052
......@@ -50,16 +50,70 @@
#include <sys/time.h>
#include <fcntl.h>
/** Non-blocking mode STUN TURN usage */
size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg,
uint8_t *buffer, size_t buffer_len,
StunMessage *previous_request,
uint32_t request_ports,
uint32_t bandwidth, uint32_t lifetime,
uint8_t *username, size_t username_len,
uint8_t *password, size_t password_len,
uint8_t *buffer, size_t buffer_len)
StunUsageTurnCompatibility compatibility)
{
stun_agent_init_request (agent, msg, buffer, buffer_len, STUN_ALLOCATE);
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_TD9) {
if (bandwidth > 0) {
if (stun_message_append32 (msg, STUN_ATTRIBUTE_BANDWIDTH, bandwidth) != 0)
return 0;
}
if (lifetime > 0) {
if (stun_message_append32 (msg, STUN_ATTRIBUTE_LIFETIME, lifetime) != 0)
return 0;
}
} else {
if (stun_message_append32 (msg, STUN_ATTRIBUTE_MAGIC_COOKIE,
TURN_MAGIC_COOKIE) != 0)
return 0;
}
#if 0
if (request_ports != STUN_USAGE_TURN_REQUEST_PORT_NORMAL) {
uint32_t req = 0;
if (compatibility == STUN_USAGE_TURN_COMPATIBILITY_TD9) {
}
if (stun_message_append32 (msg, STUN_ATTRIBUTE_REQUESTED_PORT_PROPS,
req) != 0)
return 0;
}
#endif
if (previous_request) {
char realm[100];
char nonce[100];
uint64_t reservation;
if (stun_message_find_string (previous_request, STUN_ATTRIBUTE_REALM,
realm, sizeof(realm)) == 0) {
if (stun_message_append_string (msg, STUN_ATTRIBUTE_REALM, realm) != 0)
return 0;
}
if (stun_message_find_string (previous_request, STUN_ATTRIBUTE_NONCE,
nonce, sizeof(nonce)) == 0) {
if (stun_message_append_string (msg, STUN_ATTRIBUTE_NONCE, nonce) != 0)
return 0;
}
if (stun_message_find64 (previous_request, STUN_ATTRIBUTE_RESERVATION_TOKEN,
&reservation) == 0) {
if (stun_message_append64 (msg, STUN_ATTRIBUTE_RESERVATION_TOKEN,
reservation) != 0)
return 0;
}
}
if (username != NULL && username_len > 0) {
if (stun_message_append_bytes (msg, STUN_ATTRIBUTE_USERNAME,
username, username_len) != 0)
......
......@@ -33,8 +33,8 @@
* file under either the MPL or the LGPL.
*/
#ifndef STUN_BIND_H
# define STUN_BIND_H 1
#ifndef STUN_TURN_H
# define STUN_TURN_H 1
/**
* @file bind.h
......@@ -50,6 +50,19 @@
extern "C" {
# endif
#define STUN_USAGE_TURN_REQUEST_PORT_NORMAL 0
#define STUN_USAGE_TURN_REQUEST_PORT_ODD 1
#define STUN_USAGE_TURN_REQUEST_PORT_EVEN 2
#define STUN_USAGE_TURN_REQUEST_PORT_BOTH 4
#define STUN_USAGE_TURN_REQUEST_PORT_PRESERVING 8
typedef enum {
STUN_USAGE_TURN_COMPATIBILITY_TD9,
STUN_USAGE_TURN_COMPATIBILITY_GOOGLE,
STUN_USAGE_TURN_COMPATIBILITY_MSN,
} StunUsageTurnCompatibility;
typedef enum {
STUN_USAGE_TURN_RETURN_SUCCESS,
STUN_USAGE_TURN_RETURN_ERROR,
......@@ -59,9 +72,13 @@ typedef enum {
size_t stun_usage_turn_create (StunAgent *agent, StunMessage *msg,
uint8_t *buffer, size_t buffer_len,
StunMessage *previous_request,
uint32_t request_ports,
uint32_t bandwidth, uint32_t lifetime,
uint8_t *username, size_t username_len,
uint8_t *password, size_t password_len,
uint8_t *buffer, size_t buffer_len);
StunUsageTurnCompatibility compatibility);
StunUsageTurnReturn stun_usage_turn_process (StunMessage *msg,
struct sockaddr *addr, socklen_t *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