Commit fe7473cc authored by Martti Mela's avatar Martti Mela

async stun bind in tport, callback to NTA

darcs-hash:20060320211451-1b897-0d82d388697e45ffe3da9b6d4db6acabbed06ac7.gz
parent f24b8c13
......@@ -610,11 +610,16 @@ sip_via_t *nta_agent_via(nta_agent_t const *agent)
return agent ? agent->sa_vias : NULL;
}
/** Return a list of public @b Via headers.
/** Return a list of public (UPnP, STUN) @b Via headers.
*
* Return @b Via headers for all public transports.
* The function nta_agent_public_via() returns public @b Via headers for all activated
* transports.
*
* @param agent NTA agent object
*
* @return The function nta_agent_public_via() returns a list of sip_via_t objects
* used by the @a agent.
*/
sip_via_t *nta_agent_public_via(nta_agent_t const *agent)
{
......@@ -1289,7 +1294,7 @@ char const *stateless_branch(nta_agent_t *sa,
/* Local prototypes */
static int agent_create_master_transport(nta_agent_t *self, tagi_t *tags);
static int agent_init_via(nta_agent_t *self, int use_maddr);
static int agent_init_via(nta_agent_t *self, tport_t *primaries, int use_maddr);
static int agent_init_contact(nta_agent_t *self);
static void agent_recv_message(nta_agent_t *agent,
tport_t *tport,
......@@ -1511,7 +1516,7 @@ int nta_agent_add_tport(nta_agent_t *self,
tpn->tpn_comp ? tpn->tpn_comp : ""));
/* XXX - when to use maddr? */
if ((agent_init_via(self, 0)) < 0) {
if ((agent_init_via(self, tport_primaries(self->sa_tports), 0)) < 0) {
error = su_errno();
SU_DEBUG_1(("nta: cannot create Via headers\n"));
goto error;
......@@ -1581,7 +1586,7 @@ int agent_create_master_transport(nta_agent_t *self, tagi_t *tags)
/** Initialize Via headers. */
static
int agent_init_via(nta_agent_t *self, int use_maddr)
int agent_init_via(nta_agent_t *self, tport_t *primaries, int use_maddr)
{
sip_via_t *via = NULL, *new_via, *dup_via, *v, **vv = &via;
tport_t *tp;
......@@ -1599,7 +1604,7 @@ int agent_init_via(nta_agent_t *self, int use_maddr)
self->sa_tport_tls = 0;
/* Set via fields for the tports */
for (tp = tport_primaries(self->sa_tports); tp; tp = tport_next(tp)) {
for (tp = primaries; tp; tp = tport_next(tp)) {
int maddr, first_via;
tp_name_t tpn[1];
char const *comp = NULL;
......@@ -1691,7 +1696,7 @@ int agent_init_via(nta_agent_t *self, int use_maddr)
msg_header_free(self->sa_home, (void *)v);
/* Set via field magic for the tports */
for (tp = tport_primaries(self->sa_tports); tp; tp = tport_next(tp)) {
for (tp = primaries; tp; tp = tport_next(tp)) {
assert(via->v_common->h_data == tp);
v = tport_magic(tp);
tport_set_magic(tp, new_via);
......@@ -1931,7 +1936,12 @@ void agent_tp_error(nta_agent_t *agent,
/** Handle updated transport addresses */
static void agent_update_tport(nta_agent_t *self, tport_t *tport)
{
agent_init_via(self, 0);
/* Initialize non-natted Vias first */
agent_init_via(self, tport_primaries(self->sa_tports), 0);
/* Initialize natted Vias */
agent_init_via(self, tport_public_primaries(self->sa_tports), 0);
if (self->sa_update_tport) {
self->sa_update_tport(self->sa_update_magic, self);
......
......@@ -54,6 +54,12 @@ typedef struct stun_discovery_s stun_discovery_t;
/** STUN server context */
typedef STUN_MAGIC_T stun_magic_t;
#ifndef STUN_DISCOVERY_MAGIC_T
#define STUN_DISCOVERY_MAGIC_T struct stun_discovery_magic_t
#endif
/** STUN discovery_ context */
typedef STUN_DISCOVERY_MAGIC_T stun_discovery_magic_t;
extern char const stun_version[]; /**< Name and version of STUN software */
/**
......@@ -115,6 +121,15 @@ typedef enum stun_state_e {
} stun_state_t;
/* Per discovery */
typedef void (*stun_discovery_f)(stun_discovery_magic_t *magic,
stun_handle_t *sh,
stun_request_t *req,
stun_discovery_t *sd,
stun_action_t action,
stun_state_t event);
/* Used if no stun_discovery_f specified for a discovery */
typedef void (*stun_event_f)(stun_magic_t *magic,
stun_handle_t *sh,
stun_request_t *req,
......@@ -155,17 +170,23 @@ int stun_handle_request_shared_secret(stun_handle_t *sh);
/** Bind a socket using STUN. */
int stun_handle_bind(stun_handle_t *sh,
stun_discovery_f,
stun_discovery_magic_t *magic,
/* su_localinfo_t *my_addr, */
tag_type_t tag, tag_value_t value,
...);
int stun_handle_get_nattype(stun_handle_t *sh,
stun_discovery_f,
stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value,
...);
char const *stun_nattype(stun_discovery_t *sd);
int stun_handle_get_lifetime(stun_handle_t *sh,
stun_discovery_f,
stun_discovery_magic_t *magic,
tag_type_t tag, tag_value_t value,
...);
......@@ -205,6 +226,9 @@ int stun_keepalive(stun_handle_t *sh,
int stun_keepalive_destroy(stun_handle_t *sh, su_socket_t s);
/* Return socket attached to discovery object */
su_socket_t stun_discovery_get_socket(stun_discovery_t *sd);
SOFIA_END_DECLS
#endif /* !defined(STUN_H) */
......@@ -71,6 +71,11 @@ extern tag_typedef_t stuntag_socket;
#define STUNTAG_SOCKET_REF(x) stuntag_socket_ref, tag_int_vr(&(x))
extern tag_typedef_t stuntag_socket_ref;
#define STUNTAG_REGISTER_SOCKET(x) stuntag_register_socket, tag_int_v(x)
extern tag_typedef_t stuntag_register_socket;
#define STUNTAG_REGISTER_SOCKET_REF(x) stuntag_register_socket_ref, tag_int_vr(&(x))
extern tag_typedef_t stuntag_register_socket_ref;
#define STUNTAG_ACTION(x) stuntag_action, tag_int_v(x)
extern tag_typedef_t stuntag_action;
#define STUNTAG_ACTION_REF(x) stuntag_action_ref, tag_int_vr(&(x))
......
This diff is collapsed.
......@@ -422,7 +422,6 @@ int stun_encode_message_integrity(stun_attr_t *attr,
/* zero padding */
if (len % 64 == 0) {
void *sha_hmac;
padded_len = len + (64 - (len % 64));
padded_text = (unsigned char *) malloc(padded_len);
......
......@@ -128,6 +128,25 @@ tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(integrity);
*/
tag_typedef_t stuntag_socket = INTTAG_TYPEDEF(socket);
/**@def STUNTAG_REGISTER_SOCKET(x)
*
* Register socket for eventloop owned by STUN.
*
* @par Used with
* stun_handle_bind() \n
* stun_handle_get_lifetime() \n
* stun_handle_get_nattype() \n
*
* @par Parameter type
* int (su_register_socket_t)
*
* @par Values
* IPv4 (AF_INET) register_socket
*
* Corresponding tag taking reference parameter is STUNTAG_REGISTER_SOCKET_REF()
*/
tag_typedef_t stuntag_register_socket = INTTAG_TYPEDEF(register_socket);
/**@def STUNTAG_ACTION(x)
*
* Command action for STUN request.
......
......@@ -85,7 +85,7 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *sh,
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) {
if (stun_handle_bind(sh, NULL, NULL, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_bind()"));
su_root_break(stun_handle_root(sh));
}
......@@ -112,12 +112,12 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *sh,
(unsigned) ntohs(sa->su_port)));
/* su_root_break(stun_handle_root(sh)); */
if (stun_handle_get_nattype(sh, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
if (stun_handle_get_nattype(sh, NULL, NULL, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_get_nattype()"));
su_root_break(stun_handle_root(sh));
}
if (stun_handle_get_lifetime(sh, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
if (stun_handle_get_lifetime(sh, NULL, NULL, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_get_lifetime()"));
su_root_break(stun_handle_root(sh));
}
......@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
}
/* If no TSL query, start bind here */
if (stun_handle_bind(sh, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
if (stun_handle_bind(sh, NULL, NULL, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_0(("%s: %s failed\n", __func__, "stun_handle_bind()"));
return -1;
}
......
......@@ -301,7 +301,7 @@ int torture_test_get_lifetime(char *localaddr)
atonetaddr(my_addr, localaddr);
addrlen = sizeof(*my_addr);
result = stun_handle_get_lifetime(se, &addr.li_addr, &addrlen, &lifetime); TEST(result, 0);
result = stun_handle_get_lifetime(se, NULL, &addr.li_addr, &addrlen, &lifetime); TEST(result, 0);
printf("Binding Lifetime determined to be: %d seconds\n", lifetime);
su_close(s);
......
This diff is collapsed.
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