Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
6e731d62
Commit
6e731d62
authored
Aug 04, 2008
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding initial TURN usage to libstun
parent
dae09b56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
215 additions
and
0 deletions
+215
-0
stun/Makefile.am
stun/Makefile.am
+1
-0
stun/usages/turn.c
stun/usages/turn.c
+139
-0
stun/usages/turn.h
stun/usages/turn.h
+75
-0
No files found.
stun/Makefile.am
View file @
6e731d62
...
@@ -24,6 +24,7 @@ libstun_la_SOURCES = stun.h constants.h \
...
@@ -24,6 +24,7 @@ libstun_la_SOURCES = stun.h constants.h \
utils.c utils.h
\
utils.c utils.h
\
usages/ice.c usages/ice.h
\
usages/ice.c usages/ice.h
\
usages/bind.c usages/bind.h
\
usages/bind.c usages/bind.h
\
usages/turn.c usages/turn.h
\
usages/timer.c usages/timer.h
\
usages/timer.c usages/timer.h
\
usages/trans.c usages/trans.h
usages/trans.c usages/trans.h
...
...
stun/usages/turn.c
0 → 100644
View file @
6e731d62
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "stun/stunagent.h"
#include "turn.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#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
*
username
,
size_t
username_len
,
uint8_t
*
password
,
size_t
password_len
,
uint8_t
*
buffer
,
size_t
buffer_len
)
{
stun_agent_init_request
(
agent
,
msg
,
buffer
,
buffer_len
,
STUN_ALLOCATE
);
if
(
username
!=
NULL
&&
username_len
>
0
)
{
if
(
stun_message_append_bytes
(
msg
,
STUN_ATTRIBUTE_USERNAME
,
username
,
username_len
)
!=
0
)
return
0
;
}
return
stun_agent_finish_message
(
agent
,
msg
,
password
,
password_len
);
}
StunUsageTurnReturn
stun_usage_turn_process
(
StunMessage
*
msg
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
struct
sockaddr
*
alternate_server
,
socklen_t
*
alternate_server_len
,
uint32_t
*
bandwidth
,
uint32_t
*
lifetime
)
{
int
val
,
code
=
-
1
;
switch
(
stun_message_get_class
(
msg
))
{
case
STUN_REQUEST
:
case
STUN_INDICATION
:
return
STUN_USAGE_TURN_RETURN_RETRY
;
case
STUN_RESPONSE
:
break
;
case
STUN_ERROR
:
if
(
stun_message_find_error
(
msg
,
&
code
)
!=
0
)
{
/* missing ERROR-CODE: ignore message */
return
STUN_USAGE_TURN_RETURN_RETRY
;
}
/* NOTE: currently we ignore unauthenticated messages if the context
* is authenticated, for security reasons. */
stun_debug
(
" STUN error message received (code: %d)
\n
"
,
code
);
/* ALTERNATE-SERVER mechanism */
if
((
code
/
100
)
==
3
)
{
if
(
alternate_server
&&
alternate_server_len
)
{
if
(
stun_message_find_addr
(
msg
,
STUN_ATTRIBUTE_ALTERNATE_SERVER
,
alternate_server
,
alternate_server_len
))
{
stun_debug
(
" Unexpectedly missing ALTERNATE-SERVER attribute
\n
"
);
return
STUN_USAGE_TURN_RETURN_ERROR
;
}
}
else
{
if
(
!
stun_message_has_attribute
(
msg
,
STUN_ATTRIBUTE_ALTERNATE_SERVER
))
{
stun_debug
(
" Unexpectedly missing ALTERNATE-SERVER attribute
\n
"
);
return
STUN_USAGE_TURN_RETURN_ERROR
;
}
}
stun_debug
(
"Found alternate server
\n
"
);
return
STUN_USAGE_TURN_RETURN_ALTERNATE_SERVER
;
}
return
STUN_USAGE_TURN_RETURN_ERROR
;
}
stun_debug
(
"Received %u-bytes STUN message
\n
"
,
stun_message_length
(
msg
));
val
=
stun_message_find_xor_addr
(
msg
,
STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS
,
addr
,
addrlen
);
if
(
val
)
{
stun_debug
(
" No XOR-MAPPED-ADDRESS: %s
\n
"
,
strerror
(
val
));
val
=
stun_message_find_addr
(
msg
,
STUN_ATTRIBUTE_MAPPED_ADDRESS
,
addr
,
addrlen
);
if
(
val
)
{
stun_debug
(
" No MAPPED-ADDRESS: %s
\n
"
,
strerror
(
val
));
return
STUN_USAGE_TURN_RETURN_ERROR
;
}
}
stun_debug
(
" Mapped address found!
\n
"
);
return
STUN_USAGE_TURN_RETURN_SUCCESS
;
}
stun/usages/turn.h
0 → 100644
View file @
6e731d62
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Rémi Denis-Courmont
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Rémi Denis-Courmont, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifndef STUN_BIND_H
# define STUN_BIND_H 1
/**
* @file bind.h
* @brief STUN binding discovery
*/
# include <stdbool.h>
# include <stdint.h>
# include "stun/stunagent.h"
# ifdef __cplusplus
extern
"C"
{
# endif
typedef
enum
{
STUN_USAGE_TURN_RETURN_SUCCESS
,
STUN_USAGE_TURN_RETURN_ERROR
,
STUN_USAGE_TURN_RETURN_RETRY
,
STUN_USAGE_TURN_RETURN_ALTERNATE_SERVER
,
}
StunUsageTurnReturn
;
size_t
stun_usage_turn_create
(
StunAgent
*
agent
,
StunMessage
*
msg
,
uint8_t
*
username
,
size_t
username_len
,
uint8_t
*
password
,
size_t
password_len
,
uint8_t
*
buffer
,
size_t
buffer_len
);
StunUsageTurnReturn
stun_usage_turn_process
(
StunMessage
*
msg
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
struct
sockaddr
*
alternate_server
,
socklen_t
*
alternate_server_len
,
uint32_t
*
bandwidth
,
uint32_t
*
lifetime
);
# ifdef __cplusplus
}
# endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment