Commit ecad45db authored by Martti Mela's avatar Martti Mela

initial async stun, compiles not works.

darcs-hash:20051205214454-1b897-6564426174fdd1d3d69a042d3808b9dd91f4c3ca.gz
parent 050acb11
......@@ -19,9 +19,10 @@ INCLUDES = -I$(srcdir)/../ipt \
noinst_LTLIBRARIES = libnth.la
noinst_PROGRAMS = nth_test http-client http-server
# noinst_PROGRAMS = nth_test http-client http-server
TESTS = nth_test
# TESTS = nth_test
TESTS =
# ----------------------------------------------------------------------
# Rules for building the targets
......
/**@SIP
*
* @cfile sip_p_tag.c SIP Tags.
*
* This file is automatically generated from <sip_p_headers.h.in> by msg_parser.awk.
*
* @par Contributor(s):
* - Pekka Pessi <Pekka.Pessi@nokia.com>.
*
* @date Created: Wed Mar 30 21:00:09 EEST 2005 ppessi
*/
#include "config.h"
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <su.h>
#define TAG_NAMESPACE "sip"
#include "sip_parser.h"
#include <sip_p_headers.h>
#include <su_tag_class.h>
#include <su_tag_inline.h>
#include <sip_tag_class.h>
SIP_DLL extern tag_class_t siphdrtag_class[1];
SIP_DLL extern tag_class_t sipstrtag_class[1];
/**@ingroup sip_p_asserted_identity
* Tag for P-Asserted-Identity header object.
*/
tag_typedef_t siptag_p_asserted_identity = SIPHDRTAG_TYPEDEF(p_asserted_identity);
/**@ingroup sip_p_asserted_identity
* Tag for string with P-Asserted-Identity header value.
*/
tag_typedef_t siptag_p_asserted_identity_str = SIPSTRTAG_TYPEDEF(p_asserted_identity);
/**@ingroup sip_p_preferred_identity
* Tag for P-Preferred-Identity header object.
*/
tag_typedef_t siptag_p_preferred_identity = SIPHDRTAG_TYPEDEF(p_preferred_identity);
/**@ingroup sip_p_preferred_identity
* Tag for string with P-Preferred-Identity header value.
*/
tag_typedef_t siptag_p_preferred_identity_str = SIPSTRTAG_TYPEDEF(p_preferred_identity);
/**@ingroup sip_p_associated_uri
* Tag for P-Associated-URI header object.
*/
tag_typedef_t siptag_p_associated_uri = SIPHDRTAG_TYPEDEF(p_associated_uri);
/**@ingroup sip_p_associated_uri
* Tag for string with P-Associated-URI header value.
*/
tag_typedef_t siptag_p_associated_uri_str = SIPSTRTAG_TYPEDEF(p_associated_uri);
/**@ingroup sip_p_called_party_id
* Tag for P-Called-Party-ID header object.
*/
tag_typedef_t siptag_p_called_party_id = SIPHDRTAG_TYPEDEF(p_called_party_id);
/**@ingroup sip_p_called_party_id
* Tag for string with P-Called-Party-ID header value.
*/
tag_typedef_t siptag_p_called_party_id_str = SIPSTRTAG_TYPEDEF(p_called_party_id);
/**@ingroup sip_p_visited_network_id
* Tag for P-Visited-Network-ID header object.
*/
tag_typedef_t siptag_p_visited_network_id = SIPHDRTAG_TYPEDEF(p_visited_network_id);
/**@ingroup sip_p_visited_network_id
* Tag for string with P-Visited-Network-ID header value.
*/
tag_typedef_t siptag_p_visited_network_id_str = SIPSTRTAG_TYPEDEF(p_visited_network_id);
/**@ingroup sip_p_access_network_info
* Tag for P-Access-Network-Info header object.
*/
tag_typedef_t siptag_p_access_network_info = SIPHDRTAG_TYPEDEF(p_access_network_info);
/**@ingroup sip_p_access_network_info
* Tag for string with P-Access-Network-Info header value.
*/
tag_typedef_t siptag_p_access_network_info_str = SIPSTRTAG_TYPEDEF(p_access_network_info);
/**@ingroup sip_p_charging_addr
* Tag for P-Charging-Function-Addresses header object.
*/
tag_typedef_t siptag_p_charging_addr = SIPHDRTAG_TYPEDEF(p_charging_addr);
/**@ingroup sip_p_charging_addr
* Tag for string with P-Charging-Function-Addresses header value.
*/
tag_typedef_t siptag_p_charging_addr_str = SIPSTRTAG_TYPEDEF(p_charging_addr);
/**@ingroup sip_p_charging_vector
* Tag for P-Charging-Vector header object.
*/
tag_typedef_t siptag_p_charging_vector = SIPHDRTAG_TYPEDEF(p_charging_vector);
/**@ingroup sip_p_charging_vector
* Tag for string with P-Charging-Vector header value.
*/
tag_typedef_t siptag_p_charging_vector_str = SIPSTRTAG_TYPEDEF(p_charging_vector);
This diff is collapsed.
......@@ -39,20 +39,32 @@
#endif
#include "stun_common.h"
#define STUN_LIFETIME_EST 350 /**< 6 min? */
#define STUN_LIFETIME_MAX 1800 /**< 30 min? */
#define STUN_LIFETIME_CI 5 /**< 5 sec confidence interval */
typedef struct stun_engine_s stun_engine_t;
typedef struct stun_socket_s stun_socket_t;
#ifndef STUN_MAGIC_T
#define STUN_MAGIC_T struct stun_magic_t
#endif
/** STUN server context */
typedef STUN_MAGIC_T stun_magic_t;
extern char const stun_version[]; /**< Name and version of STUN software */
int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
stun_engine_t *stun_engine_tcreate(tag_type_t tag, tag_value_t value, ...);
typedef int (stun_event_f) (stun_magic_t *magic, stun_engine_t *se);
stun_engine_t *stun_engine_tcreate(stun_magic_t *context,
su_root_t *root,
stun_event_f *cb,
tag_type_t tag, tag_value_t value, ...);
stun_engine_t *stun_engine_create(char const *server, int use_msgint);
stun_engine_t *stun_engine_create(stun_magic_t *context,
su_root_t *root,
stun_event_f *cb,
char const *server,
int use_msgint);
void stun_engine_destroy(stun_engine_t *);
......@@ -68,7 +80,6 @@ int stun_bind(stun_socket_t *ss,
int stun_get_nattype(stun_socket_t *ss,
struct sockaddr *my_addr, int *addrlen);
int stun_poll(stun_socket_t *ss);
int stun_get_lifetime(stun_socket_t *ss,
struct sockaddr *my_addr, int *addrlen,
int *lifetime);
......@@ -77,22 +88,6 @@ int stun_get_lifetime(stun_socket_t *ss,
int stun_set_uname_pwd(stun_engine_t *se, const char *uname, int len_uname,
const char *pwd, int len_pwd);
/* internal functions declaration */
int stun_get_sharedsecret(stun_engine_t *se);
int stun_make_sharedsecret_req(stun_msg_t *msg);
int stun_bind_test(stun_socket_t *ss, struct sockaddr_in *srvr, struct sockaddr_in *cli,
int chg_ip, int chg_port);
int stun_send_message2(stun_socket_t *ss, struct sockaddr_in *srvr, stun_msg_t *msg); /* client version */
int stun_make_binding_req(stun_socket_t *ss, stun_msg_t *msg, int chg_ip, int chg_port);
int stun_process_response(stun_msg_t *msg);
int stun_process_binding_response(stun_msg_t *msg);
int stun_process_error_response(stun_msg_t *msg);
int stun_atoaddr(struct sockaddr_in *addr, char const *in);
char const *stun_nattype(stun_engine_t *se);
int stun_add_response_address(stun_msg_t *req, struct sockaddr_in *mapped_addr);
#endif /* !defined(STUN_H) */
......@@ -37,6 +37,10 @@
#include <string.h>
#include <stdlib.h>
typedef struct stunc_s stunc_t;
#define SU_ROOT_MAGIC stunc_t
#define STUN_MAGIC_T stunc_t
#include "stun.h"
char const *name = "stunc";
......@@ -47,21 +51,41 @@ void usage(int exitcode)
exit(exitcode);
}
struct stunc_s {
int kakka;
};
int stunc_callback(stunc_t *stunc, stun_engine_t *en);
int stunc_callback(stunc_t *stunc, stun_engine_t *en)
{
return 0;
}
int main(int argc, char *argv[])
{
int result;
int s, lifetime;
socklen_t addrlen;
su_sockaddr_t addr;
stunc_t stunc[1];
su_root_t *root = su_root_create(stunc);
stun_engine_t *se;
stun_socket_t *ss;
if (argc != 3)
usage(1);
/* Running this test requires a local STUN server on default port */
se = stun_engine_create(argv[1], argv[2] != NULL);
se = stun_engine_create(stunc,
root,
stunc_callback,
argv[1], argv[2] != NULL);
if (se == NULL) { perror("stun_engine_create"); exit(1); }
......
......@@ -43,14 +43,23 @@
#include <stdio.h>
#include <string.h>
typedef struct torture_s torture_t;
#define SU_ROOT_MAGIC_T torture_t
#define STUN_MAGIC_T torture_t
#include "stun.h"
#define TSTFLAGS tstflags
#include <tstdef.h>
struct torture_s {
int kakka;
};
char const *name = "torture_stun";
static int test_init(char *addr);
static int test_init(su_root_t *root, char *addr);
static int test_sync_stun(char *addr);
static int test_get_nattype(char *addr);
static int test_get_lifetime(char *addr);
......@@ -77,6 +86,9 @@ int bypass_msg_int=0;
int main(int argc, char *argv[])
{
torture_t torture[1];
su_root_t *root = su_root_create(torture);
int retval = 0;
int i;
char *clntaddr = "127.0.0.1", *srvraddr = "127.0.0.1";
......@@ -106,7 +118,7 @@ int main(int argc, char *argv[])
if(!test_bind && !test_nat && !test_lifetime) {usage(); return -1;}
if (!(retval |= test_init(srvraddr))) {
if (!(retval |= test_init(root, srvraddr))) {
if(test_bind) {
retval |= test_sync_stun(clntaddr);
}
......@@ -125,13 +137,26 @@ int main(int argc, char *argv[])
stun_engine_t *se;
int test_init(char *server)
int torture_callback(torture_t *torturer, stun_engine_t *en);
int torture_callback(torture_t *torturer, stun_engine_t *en)
{
return 0;
}
int test_init(su_root_t *root, char *server)
{
torture_t torturer[1];
BEGIN();
/* Running this test requires a local STUN server on default port */
se = stun_engine_create(server, !bypass_msg_int); TEST_1(se);
se = stun_engine_create(torturer,
root,
torture_callback,
server, !bypass_msg_int); TEST_1(se);
END();
}
......
......@@ -69,9 +69,11 @@ typedef struct tport_master tport_master_t;
typedef struct tport_nat_s tport_nat_t;
#define SU_WAKEUP_ARG_T struct tport_s
#define SU_TIMER_ARG_T struct tport_master
#define SU_TIMER_ARG_T struct tport_master
#define SU_ROOT_MAGIC_T struct tport_threadpool
#define SU_MSG_ARG_T union tport_su_msg_arg
#define SU_MSG_ARG_T union tport_su_msg_arg
#define STUN_MAGIC_T tport_master_t
#include <su_wait.h>
......@@ -6833,6 +6835,15 @@ void thrp_udp_send_report(su_root_magic_t *magic,
msg_ref_destroy(tpd->tpd_msg);
}
int tport_stun_cb(tport_t *tport, stun_engine_t *en)
{
/* xxx - mela: here events that can be sent to nua_events */
return 0;
}
static
struct tport_nat_s *
tport_nat_initialize_nat_traversal(tport_master_t *mr,
......@@ -6859,7 +6870,10 @@ tport_nat_initialize_nat_traversal(tport_master_t *mr,
strcasecmp(tpn->tpn_proto, stun_transports[i]) == 0)) {
SU_DEBUG_5(("%s(%p) starting STUN engine\n", __func__, mr));
nat->stun = stun_engine_tcreate(TAG_NEXT(tags));
nat->stun = stun_engine_tcreate(mr,
mr->mr_root,
tport_stun_cb,
TAG_NEXT(tags));
if (!nat->stun)
return NULL;
......
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