Commit dbdb7dec authored by Ghislain MARY's avatar Ghislain MARY

Handle TURN create permission requests.

parent aa734546
......@@ -129,21 +129,23 @@ typedef struct _IceSession {
bool_t turn_enabled; /**< TURN protocol enabled */
} IceSession;
typedef struct _IceStunServerCheckTransaction {
typedef struct _IceStunServerRequestTransaction {
UInt96 transactionID;
MSTimeSpec request_time;
MSTimeSpec response_time;
} IceStunServerCheckTransaction;
} IceStunServerRequestTransaction;
typedef struct _IceStunServerCheck {
typedef struct _IceStunServerRequest {
struct _IceCheckList *cl;
RtpTransport *rtptp;
MSTurnContext *turn_context;
int srcport;
MSList *transactions; /**< List of IceStunServerCheckTransaction structures. */
MSList *transactions; /**< List of IceStunServerRequestTransaction structures. */
MSTimeSpec next_transmission_time;
MSStunAddress peer_address;
uint16_t stun_method;
bool_t responded;
} IceStunServerCheck;
} IceStunServerRequest;
/**
* Structure representing an ICE transport address.
......@@ -221,7 +223,7 @@ typedef struct _IceCheckList {
RtpSession *rtp_session; /**< Pointer to the RTP session associated with this ICE check list */
char *remote_ufrag; /**< Remote username fragment for this check list (provided via SDP by the peer) */
char *remote_pwd; /**< Remote password for this check list (provided via SDP by the peer) */
MSList *stun_server_checks; /**< List of IceStunServerCheck structures */
MSList *stun_server_requests; /**< List of IceStunServerRequest structures */
MSList *local_candidates; /**< List of IceCandidate structures */
MSList *remote_candidates; /**< List of IceCandidate structures */
MSList *pairs; /**< List of IceCandidatePair structures */
......
......@@ -130,6 +130,7 @@ typedef struct {
MSStunErrorCode error_code;
MSStunAddress mapped_address;
MSStunAddress xor_mapped_address;
MSStunAddress xor_peer_address;
MSStunAddress xor_relayed_address;
uint32_t change_request;
uint32_t fingerprint;
......@@ -145,6 +146,7 @@ typedef struct {
bool_t has_fingerprint;
bool_t has_mapped_address;
bool_t has_xor_mapped_address;
bool_t has_xor_peer_address;
bool_t has_xor_relayed_address;
bool_t has_priority;
bool_t has_use_candidate;
......@@ -199,6 +201,7 @@ MS2_PUBLIC bool_t ms_stun_message_is_error_response(const MSStunMessage *msg);
MS2_PUBLIC bool_t ms_stun_message_is_indication(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_destroy(MSStunMessage *msg);
MS2_PUBLIC size_t ms_stun_message_encode(const MSStunMessage *msg, char **buf);
MS2_PUBLIC uint16_t ms_stun_message_get_method(const MSStunMessage *msg);
MS2_PUBLIC uint16_t ms_stun_message_get_length(const MSStunMessage *msg);
MS2_PUBLIC UInt96 ms_stun_message_get_tr_id(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_tr_id(MSStunMessage *msg, UInt96 tr_id);
......@@ -227,6 +230,8 @@ MS2_PUBLIC const MSStunAddress * ms_stun_message_get_mapped_address(const MSStun
MS2_PUBLIC void ms_stun_message_set_mapped_address(MSStunMessage *msg, MSStunAddress mapped_address);
MS2_PUBLIC const MSStunAddress * ms_stun_message_get_xor_mapped_address(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_xor_mapped_address(MSStunMessage *msg, MSStunAddress xor_mapped_address);
MS2_PUBLIC const MSStunAddress * ms_stun_message_get_xor_peer_address(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_xor_peer_address(MSStunMessage *msg, MSStunAddress xor_peer_address);
MS2_PUBLIC const MSStunAddress * ms_stun_message_get_xor_relayed_address(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_xor_relayed_address(MSStunMessage *msg, MSStunAddress xor_relayed_address);
MS2_PUBLIC void ms_stun_message_enable_change_ip(MSStunMessage *msg, bool_t enable);
......@@ -249,6 +254,7 @@ MS2_PUBLIC void ms_stun_message_enable_dummy_message_integrity(MSStunMessage *ms
MS2_PUBLIC MSStunMessage * ms_turn_allocate_request_create(void);
MS2_PUBLIC MSStunMessage * ms_turn_refresh_request_create(uint32_t lifetime);
MS2_PUBLIC MSStunMessage * ms_turn_create_permission_request_create(MSStunAddress peer_address);
MS2_PUBLIC bool_t ms_stun_message_has_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC uint8_t ms_stun_message_get_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC bool_t ms_stun_message_has_lifetime(const MSStunMessage *msg);
......
This diff is collapsed.
......@@ -719,6 +719,14 @@ MSStunMessage * ms_stun_message_create_from_buffer_parsing(const char *buf, size
case MS_ICE_ATTR_ICE_CONTROLLING:
ms_stun_message_set_ice_controlling(msg, decode_ice_control(&decoder, length));
break;
case MS_TURN_ATTR_XOR_PEER_ADDRESS:
{
MSStunAddress stun_addr = decode_addr(&decoder, length);
stun_addr.ipv4.addr ^= MS_STUN_MAGIC_COOKIE;
stun_addr.ipv4.port ^= MS_STUN_MAGIC_COOKIE >> 16;
ms_stun_message_set_xor_peer_address(msg, stun_addr);
}
break;
case MS_TURN_ATTR_XOR_RELAYED_ADDRESS:
{
MSStunAddress stun_addr = decode_addr(&decoder, length);
......@@ -835,6 +843,8 @@ size_t ms_stun_message_encode(const MSStunMessage *msg, char **buf) {
stun_addr = ms_stun_message_get_xor_mapped_address(msg);
if (stun_addr != NULL) encode_addr(&encoder, MS_STUN_ATTR_XOR_MAPPED_ADDRESS, stun_addr);
stun_addr = ms_stun_message_get_xor_peer_address(msg);
if (stun_addr != NULL) encode_addr(&encoder, MS_TURN_ATTR_XOR_PEER_ADDRESS, stun_addr);
stun_addr = ms_stun_message_get_xor_relayed_address(msg);
if (stun_addr != NULL) encode_addr(&encoder, MS_TURN_ATTR_XOR_RELAYED_ADDRESS, stun_addr);
if (ms_stun_message_has_requested_transport(msg)) encode_requested_transport(&encoder, ms_stun_message_get_requested_transport(msg));
......@@ -867,6 +877,10 @@ size_t ms_stun_message_encode(const MSStunMessage *msg, char **buf) {
return message_length;
}
uint16_t ms_stun_message_get_method(const MSStunMessage *msg) {
return msg->method;
}
uint16_t ms_stun_message_get_length(const MSStunMessage *msg) {
return msg->length;
}
......@@ -999,6 +1013,16 @@ void ms_stun_message_set_xor_mapped_address(MSStunMessage *msg, MSStunAddress xo
msg->has_xor_mapped_address = TRUE;
}
const MSStunAddress * ms_stun_message_get_xor_peer_address(const MSStunMessage *msg) {
if (msg->has_xor_peer_address) return &msg->xor_peer_address;
return NULL;
}
void ms_stun_message_set_xor_peer_address(MSStunMessage *msg, MSStunAddress xor_peer_address) {
msg->xor_peer_address = xor_peer_address;
msg->has_xor_peer_address = TRUE;
}
const MSStunAddress * ms_stun_message_get_xor_relayed_address(const MSStunMessage *msg) {
if (msg->has_xor_relayed_address) return &msg->xor_relayed_address;
return NULL;
......@@ -1093,6 +1117,14 @@ MSStunMessage * ms_turn_refresh_request_create(uint32_t lifetime) {
return msg;
}
MSStunMessage * ms_turn_create_permission_request_create(MSStunAddress peer_address) {
MSStunMessage *msg = ms_stun_message_create(MS_STUN_TYPE_REQUEST, MS_TURN_METHOD_CREATE_PERMISSION);
peer_address.ipv4.addr ^= MS_STUN_MAGIC_COOKIE;
peer_address.ipv4.port ^= MS_STUN_MAGIC_COOKIE >> 16;
ms_stun_message_set_xor_peer_address(msg, peer_address);
return msg;
}
bool_t ms_stun_message_has_requested_transport(const MSStunMessage *msg) {
return msg->has_requested_transport;
}
......
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