Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sofia-sip
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
external
sofia-sip
Commits
94b52348
Commit
94b52348
authored
Jan 13, 2006
by
Martti Mela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stun cleanup contd.
darcs-hash:20060113160657-1b897-39c4961efde1da00acf54414e0bae325e7ab96de.gz
parent
2d9f4294
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
93 deletions
+95
-93
stun.c
libsofia-sip-ua/stun/stun.c
+94
-93
stunc.c
libsofia-sip-ua/stun/stunc.c
+1
-0
No files found.
libsofia-sip-ua/stun/stun.c
View file @
94b52348
...
...
@@ -175,11 +175,6 @@ struct stun_handle_s
int
sh_use_msgint
;
/**< use message integrity? */
int
sh_state
;
/**< Progress states */
#if 0
int sh_bind_socket;
int ss_root_index; /**< object index of su_root_register() */
#endif
};
...
...
@@ -246,6 +241,7 @@ char const stun_version[] =
"sofia-sip-stun using "
OPENSSL_VERSION_TEXT
;
int
do_action
(
stun_handle_t
*
sh
,
stun_msg_t
*
binding_response
);
int
stun_tls_callback
(
su_root_magic_t
*
m
,
su_wait_t
*
w
,
stun_handle_t
*
self
);
int
process_binding_request
(
stun_request_t
*
req
,
stun_msg_t
*
binding_response
);
stun_discovery_t
*
stun_discovery_create
(
stun_handle_t
*
sh
,
stun_action_t
action
);
...
...
@@ -396,6 +392,99 @@ stun_handle_t *stun_handle_create(stun_magic_t *context,
return
stun
;
}
/** Shared secret request/response processing */
int
stun_handle_request_shared_secret
(
stun_handle_t
*
sh
)
{
int
events
=
-
1
;
int
one
,
err
=
-
1
;
su_wait_t
wait
[
1
]
=
{
SU_WAIT_INIT
};
su_socket_t
s
=
SOCKET_ERROR
;
int
family
;
su_addrinfo_t
*
ai
=
NULL
;
su_timer_t
*
connect_timer
=
NULL
;
assert
(
sh
);
ai
=
&
sh
->
sh_pri_info
;
if
(
sh
->
sh_use_msgint
==
1
)
{
SU_DEBUG_3
((
"Contacting Server to obtain shared secret. "
\
"Please wait.
\n
"
));
}
else
{
SU_DEBUG_3
((
"No message integrity enabled.
\n
"
));
return
errno
=
EFAULT
,
-
1
;
}
/* open tcp connection to server */
s
=
su_socket
(
family
=
AF_INET
,
SOCK_STREAM
,
0
);
if
(
s
==
-
1
)
{
STUN_ERROR
(
errno
,
socket
);
return
-
1
;
}
/* asynchronous connect() */
if
(
su_setblocking
(
s
,
0
)
<
0
)
{
STUN_ERROR
(
errno
,
su_setblocking
);
return
-
1
;
}
if
(
setsockopt
(
s
,
SOL_TCP
,
TCP_NODELAY
,
(
void
*
)
&
one
,
sizeof
one
)
==
-
1
)
{
STUN_ERROR
(
errno
,
setsockopt
);
return
-
1
;
}
SU_DEBUG_7
((
"%s: %s: %s
\n
"
,
__func__
,
"setsockopt"
,
su_strerror
(
errno
)));
/* Do an asynchronous connect(). Three error codes are ok,
* others cause return -1. */
if
(
connect
(
s
,
(
struct
sockaddr
*
)
&
sh
->
sh_pri_addr
,
ai
->
ai_addrlen
)
==
SOCKET_ERROR
)
{
err
=
su_errno
();
if
(
err
!=
EINPROGRESS
&&
err
!=
EAGAIN
&&
err
!=
EWOULDBLOCK
)
{
STUN_ERROR
(
err
,
connect
);
return
-
1
;
}
}
SU_DEBUG_9
((
"%s: %s: %s
\n
"
,
__func__
,
"connect"
,
su_strerror
(
err
)));
sd
=
stun_discovery_create
(
sh
,
stun_action_tls_query
);
sd
->
sd_socket
=
s
;
req
=
stun_request_create
(
sd
);
sh
->
sh_tls_socket
=
s
;
if
(
su_wait_create
(
wait
,
s
,
events
)
==
-
1
)
STUN_ERROR
(
errno
,
su_wait_create
);
events
=
SU_WAIT_CONNECT
|
SU_WAIT_ERR
;
su_root_eventmask
(
sh
->
sh_root
,
sh
->
sh_root_index
,
s
,
events
);
if
((
sh
->
sh_root_index
=
su_root_register
(
sh
->
sh_root
,
wait
,
stun_tls_callback
,
sh
,
0
))
==
-
1
)
{
STUN_ERROR
(
errno
,
su_root_register
);
return
-
1
;
}
sh
->
sh_state
=
stun_tls_connecting
;
/* Create and start timer for connect() timeout */
SU_DEBUG_3
((
"%s: creating timeout timer for connect()
\n
"
,
__func__
));
connect_timer
=
su_timer_create
(
su_root_task
(
sh
->
sh_root
),
STUN_TLS_CONNECT_TIMEOUT
);
sh
->
sh_connect_timer
=
connect_timer
;
su_timer_set
(
connect_timer
,
stun_tls_connect_timer_cb
,
(
su_wakeup_arg_t
*
)
sh
);
return
0
;
}
stun_request_t
*
stun_request_create
(
stun_discovery_t
*
sd
)
{
stun_handle_t
*
sh
=
sd
->
sd_handle
;
...
...
@@ -850,8 +939,6 @@ int stun_handle_get_nattype(stun_handle_t *sh,
* Internal functions
*******************************************************************/
static
int
stun_tls_callback
(
su_root_magic_t
*
m
,
su_wait_t
*
w
,
stun_handle_t
*
self
)
{
stun_msg_t
*
req
,
*
resp
;
...
...
@@ -1106,92 +1193,6 @@ void stun_tls_connect_timer_cb(su_root_magic_t *magic,
}
/** Shared secret request/response processing */
int
stun_handle_request_shared_secret
(
stun_handle_t
*
sh
)
{
int
events
=
-
1
;
int
one
,
err
=
-
1
;
su_wait_t
wait
[
1
]
=
{
SU_WAIT_INIT
};
su_socket_t
s
=
SOCKET_ERROR
;
int
family
;
su_addrinfo_t
*
ai
=
NULL
;
su_timer_t
*
connect_timer
=
NULL
;
assert
(
sh
);
ai
=
&
sh
->
sh_pri_info
;
if
(
sh
->
sh_use_msgint
==
1
)
{
SU_DEBUG_3
((
"Contacting Server to obtain shared secret. "
\
"Please wait.
\n
"
));
}
else
{
SU_DEBUG_3
((
"No message integrity enabled.
\n
"
));
return
errno
=
EFAULT
,
-
1
;
}
/* open tcp connection to server */
s
=
su_socket
(
family
=
AF_INET
,
SOCK_STREAM
,
0
);
if
(
s
==
-
1
)
{
STUN_ERROR
(
errno
,
socket
);
return
-
1
;
}
/* asynchronous connect() */
if
(
su_setblocking
(
s
,
0
)
<
0
)
{
STUN_ERROR
(
errno
,
su_setblocking
);
return
-
1
;
}
if
(
setsockopt
(
s
,
SOL_TCP
,
TCP_NODELAY
,
(
void
*
)
&
one
,
sizeof
one
)
==
-
1
)
{
STUN_ERROR
(
errno
,
setsockopt
);
return
-
1
;
}
SU_DEBUG_7
((
"%s: %s: %s
\n
"
,
__func__
,
"setsockopt"
,
su_strerror
(
errno
)));
/* Do an asynchronous connect(). Three error codes are ok,
* others cause return -1. */
if
(
connect
(
s
,
(
struct
sockaddr
*
)
&
sh
->
sh_pri_addr
,
ai
->
ai_addrlen
)
==
SOCKET_ERROR
)
{
err
=
su_errno
();
if
(
err
!=
EINPROGRESS
&&
err
!=
EAGAIN
&&
err
!=
EWOULDBLOCK
)
{
STUN_ERROR
(
err
,
connect
);
return
-
1
;
}
}
SU_DEBUG_9
((
"%s: %s: %s
\n
"
,
__func__
,
"connect"
,
su_strerror
(
err
)));
sh
->
sh_tls_socket
=
s
;
if
(
su_wait_create
(
wait
,
s
,
events
)
==
-
1
)
STUN_ERROR
(
errno
,
su_wait_create
);
events
=
SU_WAIT_CONNECT
|
SU_WAIT_ERR
;
su_root_eventmask
(
sh
->
sh_root
,
sh
->
sh_root_index
,
s
,
events
);
if
((
sh
->
sh_root_index
=
su_root_register
(
sh
->
sh_root
,
wait
,
stun_tls_callback
,
sh
,
0
))
==
-
1
)
{
STUN_ERROR
(
errno
,
su_root_register
);
return
-
1
;
}
sh
->
sh_state
=
stun_tls_connecting
;
/* Create and start timer for connect() timeout */
SU_DEBUG_3
((
"%s: creating timeout timer for connect()
\n
"
,
__func__
));
connect_timer
=
su_timer_create
(
su_root_task
(
sh
->
sh_root
),
STUN_TLS_CONNECT_TIMEOUT
);
sh
->
sh_connect_timer
=
connect_timer
;
su_timer_set
(
connect_timer
,
stun_tls_connect_timer_cb
,
(
su_wakeup_arg_t
*
)
sh
);
return
0
;
}
/** Compose a STUN message of the format defined by stun_msg_t
* result encoded in enc_buf ready for sending as well.
*/
...
...
libsofia-sip-ua/stun/stunc.c
View file @
94b52348
...
...
@@ -82,6 +82,7 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *sh,
switch
(
event
)
{
case
stun_tls_done
:
case
stun_tls_connection_failed
:
case
stun_tls_connection_timeout
:
SU_DEBUG_0
((
"%s: TLS query done, start binding process.
\n
"
,
__func__
));
if
(
stun_handle_bind
(
sh
,
STUNTAG_SOCKET
(
s
),
TAG_NULL
())
<
0
)
{
SU_DEBUG_0
((
"%s: %s failed
\n
"
,
__func__
,
"stun_handle_bind()"
));
...
...
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