Commit 62932069 authored by Kai Vehmanen's avatar Kai Vehmanen

Added initial DNS-SRV lookup support to stun.

darcs-hash:20060322195701-7659e-941bf1d0e955951b61b57de3020d0f6c981fadfb.gz
parent 9259f476
......@@ -42,6 +42,7 @@ LDADD = libnth.la \
../sresolv/libsresolv.la \
../tport/libtport.la \
../stun/libstun.la \
../sresolv/libsresolv.la \
../url/liburl.la \
../msg/libmsg.la \
../bnf/libbnf.la \
......
......@@ -36,6 +36,7 @@ BUILT_SOURCES = stun_tag_ref.c
COVERAGE_INPUT = $(libstun_la_SOURCES) $(include_sofia_HEADERS)
LDADD = libstun.la \
../sresolv/libsresolv.la \
../su/libsu.la
torture_stun_LDFLAGS = -static
......
......@@ -66,14 +66,15 @@ extern char const stun_version[]; /**< Name and version of STUN software */
/**
* STUN Action types. These define the current discovery process.
* Defined as a bitmap.
*/
typedef enum stun_action_s {
stun_action_no_action,
stun_action_tls_query,
stun_action_binding_request,
stun_action_keepalive,
stun_action_get_nattype,
stun_action_get_lifetime,
stun_action_no_action = 1,
stun_action_tls_query = 2,
stun_action_binding_request = 4,
stun_action_keepalive = 8,
stun_action_get_nattype = 16,
stun_action_get_lifetime = 32,
} stun_action_t;
/**
......@@ -84,6 +85,9 @@ typedef enum stun_state_e {
stun_no_assigned_event,
stun_dispose_me,
/* DNS-SRV lookups */
stun_dns_lookup_pending,
/* TLS events */
stun_tls_connecting,
stun_tls_ssl_connecting,
......@@ -170,14 +174,13 @@ su_root_t *stun_root(stun_handle_t *sh);
int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
/* -------------------------------------------------------------------
* Functions for 'Binding Discovery' usage (RFC3489bis) */
* Functions for 'Binding Discovery' usage (RFC3489/3489bis) */
int stun_request_shared_secret(stun_handle_t *sh);
/** Bind a socket using STUN. */
int stun_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,
...);
......@@ -201,7 +204,6 @@ int stun_lifetime(stun_discovery_t *sd);
/* -------------------------------------------------------------------
* Functions for 'Connectivity Check' and 'NAT Keepalives' usages (RFC3489bis) */
/* other functions */
int stun_set_uname_pwd(stun_handle_t *sh,
const char *uname,
int len_uname,
......@@ -211,7 +213,8 @@ int stun_set_uname_pwd(stun_handle_t *sh,
int stun_msg_is_keepalive(uint16_t data);
int stun_message_length(void *data, int len, int end_of_message);
/** Process incoming message */
/* Process incoming message */
int stun_process_message(stun_handle_t *sh, su_socket_t s,
su_sockaddr_t *sa, socklen_t salen,
void *data, int len);
......@@ -236,9 +239,9 @@ su_socket_t stun_discovery_get_socket(stun_discovery_t *sd);
/*********************************************************/
/* Deprecated functions. These are supported with limited
compatibility. */
/* --------------------------------------------------------------------
* Deprecated functions. These are supported with limited
* compatibility. */
su_root_t *stun_handle_root(stun_handle_t *sh);
int stun_handle_request_shared_secret(stun_handle_t *sh);
......
This diff is collapsed.
......@@ -55,6 +55,8 @@ struct stun_dns_lookup_s {
su_root_t *stun_root;
stun_magic_t *stun_magic;
sres_resolver_t *stun_sres;
sres_record_t **stun_answers;
int stun_socket;
stun_dns_lookup_f stun_cb;
char *stun_tls_target;
char *stun_udp_target;
......@@ -109,6 +111,9 @@ static void priv_sres_cb(stun_dns_lookup_t *self,
if (self->stun_state == stun_dns_done) {
self->stun_cb(self, self->stun_magic);
if (self->stun_socket >= 0)
sres_resolver_timer(self->stun_sres, self->stun_socket);
}
sres_free_answers(self->stun_sres, answer);
......@@ -143,12 +148,15 @@ stun_dns_lookup_t *stun_dns_lookup(stun_magic_t *magic,
char *query_udp = su_sprintf(self->stun_home, "%s.%s", STUN_SRV_SERVICE_UDP, domain);
char *query_tcp = su_sprintf(self->stun_home, "%s.%s", STUN_SRV_SERVICE_TLS, domain);
self->stun_socket = socket;
query = sres_query_make(self->stun_sres, priv_sres_cb, self, socket, sres_type_srv, query_udp);
query = sres_query_make(self->stun_sres, priv_sres_cb, self, socket, sres_type_srv, query_tcp);
}
else {
sres_resolver_destroy(self->stun_sres);
su_free(NULL, self), self = NULL;
self->stun_socket = -1;
}
}
else {
......@@ -196,6 +204,7 @@ void stun_dns_lookup_destroy(stun_dns_lookup_t *self)
{
if (self->stun_sres)
sres_resolver_destroy(self->stun_sres);
su_home_destroy(self->stun_home);
su_free(NULL, self);
}
......
......@@ -46,6 +46,7 @@ COVERAGE_INPUT = $(libtport_la_SOURCES) $(include_sofia_HEADERS)
LDADD = libtport.la \
../stun/libstun.la \
../sresolv/libsresolv.la \
../ipt/libipt.la \
../msg/libtest_msg.a ../msg/libmsg.la \
../url/liburl.la \
......
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