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
71c36875
Commit
71c36875
authored
Jun 13, 2008
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing useless usages
parent
03590520
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
629 deletions
+0
-629
stun/Makefile.am
stun/Makefile.am
+0
-1
stun/usages/relay.c
stun/usages/relay.c
+0
-181
stun/usages/relay.h
stun/usages/relay.h
+0
-88
stun/usages/stun-ice.c
stun/usages/stun-ice.c
+0
-233
stun/usages/stun-ice.h
stun/usages/stun-ice.h
+0
-126
No files found.
stun/Makefile.am
View file @
71c36875
...
...
@@ -22,7 +22,6 @@ libstun_la_SOURCES = stun.h constants.h \
stuncrc32.c stuncrc32.h
\
stunhmac.c stunhmac.h
\
utils.c utils.h
# usages/stun-ice.c usages/stun-ice.h
libstun_la_LIBADD
=
$(OPENSSL_LIBS)
$(LIBRT)
stun/usages/relay.c
deleted
100644 → 0
View file @
03590520
/*
* 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 "relay.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "stun-msg.h"
#include "trans.h"
struct
turn_s
{
stun_trans_t
trans
;
};
/**
* @file relay.c
* @brief STUN relay usage (TURN) implementation
*/
turn_t
*
turn_socket
(
int
fd
,
int
family
,
turn_proto_t
proto
,
const
struct
sockaddr
*
restrict
srv
,
socklen_t
srvlen
)
{
turn_t
*
ctx
;
int
val
;
if
(
family
!=
AF_INET
)
{
errno
=
EAFNOSUPPORT
;
return
NULL
;
}
if
(
proto
!=
TURN_PROTO_UDP
)
{
errno
=
EPROTONOSUPPORT
;
return
NULL
;
}
ctx
=
malloc
(
sizeof
(
*
ctx
));
if
(
ctx
==
NULL
)
return
NULL
;
memset
(
ctx
,
0
,
sizeof
(
*
ctx
));
val
=
(
fd
!=
-
1
)
?
stun_trans_init
(
&
ctx
->
trans
,
fd
,
srv
,
srvlen
)
:
stun_trans_create
(
&
ctx
->
trans
,
SOCK_DGRAM
,
0
,
srv
,
srvlen
);
if
(
val
)
{
free
(
ctx
);
errno
=
val
;
return
NULL
;
}
stun_init_request
(
ctx
->
trans
.
msg
.
buf
,
STUN_ALLOCATE
);
return
ctx
;
}
int
turn_connect
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
dst
,
socklen_t
len
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
dst
;
(
void
)
len
;
errno
=
ENOSYS
;
return
-
1
;
}
ssize_t
turn_sendto
(
turn_t
*
restrict
ctx
,
const
void
*
data
,
size_t
datalen
,
int
flags
,
const
struct
sockaddr
*
restrict
dst
,
socklen_t
dstlen
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
data
;
(
void
)
datalen
;
(
void
)
flags
;
(
void
)
dst
;
(
void
)
dstlen
;
errno
=
ENOSYS
;
return
-
1
;
}
ssize_t
turn_send
(
turn_t
*
restrict
ctx
,
const
void
*
data
,
size_t
len
,
int
flags
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
data
;
(
void
)
len
;
(
void
)
flags
;
errno
=
ENOSYS
;
return
-
1
;
}
ssize_t
turn_recvfrom
(
turn_t
*
restrict
ctx
,
void
*
data
,
size_t
len
,
int
flags
,
const
struct
sockaddr
*
restrict
src
,
socklen_t
*
srclen
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
data
;
(
void
)
len
;
(
void
)
flags
;
(
void
)
src
;
(
void
)
srclen
;
errno
=
ENOSYS
;
return
-
1
;
}
ssize_t
turn_recv
(
turn_t
*
restrict
ctx
,
void
*
data
,
size_t
len
,
int
flags
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
data
;
(
void
)
len
;
(
void
)
flags
;
errno
=
ENOSYS
;
return
-
1
;
}
int
turn_getsockname
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
name
,
socklen_t
*
len
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
name
;
(
void
)
len
;
errno
=
ENOSYS
;
return
-
1
;
}
int
turn_getpeername
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
name
,
socklen_t
*
len
)
{
assert
(
ctx
!=
NULL
);
(
void
)
ctx
;
(
void
)
name
;
(
void
)
len
;
errno
=
ENOSYS
;
return
-
1
;
}
int
turn_close
(
turn_t
*
restrict
ctx
)
{
assert
(
ctx
!=
NULL
);
stun_trans_deinit
(
&
ctx
->
trans
);
free
(
ctx
);
return
0
;
}
stun/usages/relay.h
deleted
100644 → 0
View file @
03590520
/*
* 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_RELAY_H
# define STUN_RELAY_H 1
/**
* @file relay.h
* @brief STUN relay usage (TURN)
*/
typedef
struct
turn_s
turn_t
;
typedef
enum
{
TURN_PROTO_TCP
=
6
,
TURN_PROTO_UDP
=
17
}
turn_proto_t
;
# ifdef __cplusplus
extern
"C"
{
# endif
turn_t
*
turn_socket
(
int
fd
,
int
family
,
turn_proto_t
proto
,
const
struct
sockaddr
*
restrict
srv
,
socklen_t
srvlen
);
int
turn_setbandwidth
(
turn_t
*
ctx
,
unsigned
kbits
);
int
turn_setrealm
(
turn_t
*
restrict
ctx
,
const
char
*
realm
);
int
turn_setusername
(
turn_t
*
restrict
ctx
,
const
char
*
username
);
int
turn_setpassword
(
turn_t
*
restrict
ctx
,
const
char
*
password
);
int
turn_connect
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
dst
,
socklen_t
len
);
ssize_t
turn_sendto
(
turn_t
*
restrict
ctx
,
const
void
*
data
,
size_t
datalen
,
int
flags
,
const
struct
sockaddr
*
restrict
dst
,
socklen_t
dstlen
);
ssize_t
turn_send
(
turn_t
*
restrict
ctx
,
const
void
*
data
,
size_t
len
,
int
flags
);
ssize_t
turn_recvfrom
(
turn_t
*
restrict
ctx
,
void
*
data
,
size_t
len
,
int
flags
,
const
struct
sockaddr
*
restrict
src
,
socklen_t
*
srclen
);
ssize_t
turn_recv
(
turn_t
*
restrict
ctx
,
void
*
data
,
size_t
len
,
int
flags
);
int
turn_getsockname
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
name
,
socklen_t
*
len
);
int
turn_getpeername
(
turn_t
*
restrict
ctx
,
const
struct
sockaddr
*
restrict
name
,
socklen_t
*
len
);
int
turn_close
(
turn_t
*
ctx
);
# ifdef __cplusplus
}
# endif
#endif
stun/usages/stun-ice.c
deleted
100644 → 0
View file @
03590520
/*
* 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 <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "bind.h"
#include "stun-msg.h"
#include <errno.h>
/** ICE connectivity checks **/
#include "stun-ice.h"
static
int
stun_bind_error
(
uint8_t
*
buf
,
size_t
*
plen
,
const
uint8_t
*
req
,
stun_error_t
code
,
const
char
*
pass
,
int
compat
)
{
size_t
len
=
*
plen
;
int
val
;
*
plen
=
0
;
DBG
(
"STUN Error Reply (buffer size: %u)...
\n
"
,
(
unsigned
)
len
);
val
=
stun_init_error
(
buf
,
len
,
req
,
code
,
compat
);
if
(
val
)
return
val
;
val
=
stun_finish_short
(
buf
,
&
len
,
NULL
,
pass
,
NULL
,
compat
);
if
(
val
)
return
val
;
*
plen
=
len
;
DBG
(
" Error response (%u) of %u bytes
\n
"
,
(
unsigned
)
code
,
(
unsigned
)
*
plen
);
return
0
;
}
int
stun_conncheck_reply
(
uint8_t
*
restrict
buf
,
size_t
*
restrict
plen
,
const
uint8_t
*
msg
,
const
struct
sockaddr
*
restrict
src
,
socklen_t
srclen
,
const
char
*
local_ufrag
,
const
char
*
pass
,
bool
*
restrict
control
,
uint64_t
tie
,
uint32_t
compat
)
{
const
char
*
username
=
NULL
;
uint16_t
username_len
;
size_t
len
=
*
plen
;
uint64_t
q
;
int
val
,
ret
=
0
;
#define err( code ) \
stun_bind_error (buf, &len, msg, code, pass, compat); \
*plen = len
*
plen
=
0
;
DBG
(
"STUN Reply (buffer size = %u)...
\n
"
,
(
unsigned
)
len
);
if
(
stun_get_class
(
msg
)
!=
STUN_REQUEST
)
{
DBG
(
" Unhandled non-request (class %u) message.
\n
"
,
stun_get_class
(
msg
));
return
EINVAL
;
}
if
(
compat
!=
1
&&
!
stun_demux
(
msg
))
{
DBG
(
" Incorrectly multiplexed STUN message ignored.
\n
"
);
return
EINVAL
;
}
if
(
stun_has_unknown
(
msg
))
{
DBG
(
" Unknown mandatory attributes in message.
\n
"
);
val
=
stun_init_error_unknown
(
buf
,
len
,
msg
,
compat
);
if
(
!
val
)
val
=
stun_finish_short
(
buf
,
&
len
,
NULL
,
pass
,
NULL
,
compat
);
if
(
val
)
goto
failure
;
*
plen
=
len
;
return
EPROTO
;
}
DBG
(
"compat = %d - username %d - pass %d
\n
"
,
compat
,
stun_present
(
msg
,
STUN_USERNAME
),
stun_present
(
msg
,
STUN_MESSAGE_INTEGRITY
));
/* Short term credentials checking */
val
=
0
;
if
(
!
stun_present
(
msg
,
STUN_USERNAME
)
||
(
compat
!=
1
&&
!
stun_present
(
msg
,
STUN_MESSAGE_INTEGRITY
)))
{
DBG
(
" Missing USERNAME or MESSAGE-INTEGRITY.
\n
"
);
val
=
STUN_BAD_REQUEST
;
}
else
if
(
stun_verify_username
(
msg
,
local_ufrag
,
compat
)
||
(
compat
!=
1
&&
stun_verify_password
(
msg
,
pass
)))
{
DBG
(
" Integrity check failed.
\n
"
);
val
=
STUN_UNAUTHORIZED
;
}
username
=
(
const
char
*
)
stun_find
(
msg
,
STUN_USERNAME
,
&
username_len
);
if
(
val
)
{
stun_bind_error
(
buf
,
&
len
,
msg
,
val
,
NULL
,
compat
);
*
plen
=
len
;
return
EPERM
;
}
if
(
stun_get_method
(
msg
)
!=
STUN_BINDING
)
{
DBG
(
" Bad request (method %u) message.
\n
"
,
stun_get_method
(
msg
));
err
(
STUN_BAD_REQUEST
);
return
EPROTO
;
}
/* Role conflict handling */
assert
(
control
!=
NULL
);
if
(
!
stun_find64
(
msg
,
*
control
?
STUN_ICE_CONTROLLING
:
STUN_ICE_CONTROLLED
,
&
q
))
{
DBG
(
"STUN Role Conflict detected:
\n
"
);
if
(
tie
<
q
)
{
DBG
(
" switching role from
\"
controll%s
\"
to
\"
controll%s
\"\n
"
,
*
control
?
"ing"
:
"ed"
,
*
control
?
"ed"
:
"ing"
);
*
control
=
!*
control
;
ret
=
EACCES
;
}
else
{
DBG
(
" staying
\"
controll%s
\"
(sending error)
\n
"
,
*
control
?
"ing"
:
"ed"
);
*
plen
=
len
;
err
(
STUN_ROLE_CONFLICT
);
return
0
;
}
}
#ifndef NDEBUG
else
if
(
stun_find64
(
msg
,
*
control
?
STUN_ICE_CONTROLLED
:
STUN_ICE_CONTROLLING
,
&
q
))
DBG
(
"STUN Role not specified by peer!
\n
"
);
#endif
stun_init_response
(
buf
,
len
,
msg
,
compat
);
if
(
compat
==
1
)
{
val
=
stun_append_addr
(
buf
,
len
,
STUN_MAPPED_ADDRESS
,
src
,
srclen
);
}
else
{
val
=
stun_append_xor_addr
(
buf
,
len
,
STUN_XOR_MAPPED_ADDRESS
,
src
,
srclen
);
}
if
(
val
)
{
DBG
(
" Mapped address problem: %s
\n
"
,
strerror
(
val
));
goto
failure
;
}
val
=
stun_finish_short
(
buf
,
&
len
,
compat
==
1
?
username
:
NULL
,
compat
==
1
?
NULL
:
pass
,
NULL
,
compat
);
if
(
val
)
goto
failure
;
*
plen
=
len
;
DBG
(
" All done (response size: %u)
\n
"
,
(
unsigned
)
len
);
return
ret
;
failure:
assert
(
*
plen
==
0
);
DBG
(
" Fatal error formatting Response: %s
\n
"
,
strerror
(
val
));
return
val
;
}
#undef err
uint32_t
stun_conncheck_priority
(
const
uint8_t
*
msg
)
{
uint32_t
value
;
if
(
stun_find32
(
msg
,
STUN_PRIORITY
,
&
value
))
return
0
;
return
value
;
}
bool
stun_conncheck_use_candidate
(
const
uint8_t
*
msg
)
{
return
!
stun_find_flag
(
msg
,
STUN_USE_CANDIDATE
);
}
stun/usages/stun-ice.h
deleted
100644 → 0
View file @
03590520
/*
* 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_CONNCHECK_H
# define STUN_CONNCHECK_H 1
/**
* @file stun-ice.h
* @brief STUN/ICE connectivity checks
*/
# include "stun/usages/bind.h"
# ifdef __cplusplus
extern
"C"
{
# endif
/**
* Starts a connectivity check using STUN Binding discovery.
*
* @param context pointer to an opaque pointer that will be passed to
* stun_bind_resume() afterward
* @param fd socket to use for discovery, or -1 to create one
* @param srv STUN server socket address
* @param srvlen STUN server socket address length
* @param username nul-terminated username for authentication
* (need not be kept valid after return)
* @param password nul-terminated shared secret (ICE password)
* (need not be kept valid after return)
* @param cand_use whether to include a USE-CANDIDATE flag
* @param priority host-byte order PRIORITY value
* @param controlling whether we are in controlling (true) or
* controlled (false) state
* @param tie control tie breaker value (host-byte order)
*
* @return 0 on success, a standard error value otherwise.
*/
int
stun_conncheck_start
(
stun_bind_t
**
restrict
context
,
int
fd
,
const
struct
sockaddr
*
restrict
srv
,
socklen_t
srvlen
,
const
char
*
username
,
const
char
*
password
,
bool
cand_use
,
bool
controlling
,
uint32_t
priority
,
uint64_t
tie
,
uint32_t
compat
);
/**
* Tries to parse a STUN connectivity check (Binding request) and format a
* response accordingly.
*
* @param buf [OUT] output buffer to write a Binding response to. May refer
* to the same buffer space as the request message.
* @param plen [IN/OUT] output buffer size on entry, response length on exit
* @param msg pointer to the first byte of the binding request
* @param src socket address the message was received from
* @param srclen byte length of the socket address
* @param username STUN username
* @param password HMAC secret password
* @param control [IN/OUT] whether we are controlling ICE or not
* @param tie tie breaker value for ICE role determination
*
* @return 0 if successful (@a rbuf contains a <b>non-error</b> response),
* EINVAL: malformatted request message or socket address,
* EAFNOSUPPORT: unsupported socket address family,
* EPROTO: unsupported request message type or parameter,
* ENOBUFS: insufficient response buffer space.
* EACCES: ICE role conflict occurred, please recheck the flag at @a control
*
* In case of error, the value at @a plen is set to the size of an error
* response, or 0 if no error response should be sent.
*/
int
stun_conncheck_reply
(
uint8_t
*
restrict
buf
,
size_t
*
restrict
plen
,
const
uint8_t
*
msg
,
const
struct
sockaddr
*
restrict
src
,
socklen_t
srclen
,
const
char
*
local_ufrag
,
const
char
*
pass
,
bool
*
restrict
control
,
uint64_t
tie
,
uint32_t
compat
);
/**
* Extracts the priority from a STUN message.
* @param msg valid STUN message.
* @return host byte order priority, or 0 if not specified.
*/
uint32_t
stun_conncheck_priority
(
const
uint8_t
*
msg
);
/**
* Extracts the "use candidate" flag from a STUN message.
* @param msg valid STUN message.
* @return true if the flag is set, false if not.
*/
bool
stun_conncheck_use_candidate
(
const
uint8_t
*
msg
);
# 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