Commit e01cfe8a authored by Pekka Pessi's avatar Pekka Pessi

Added tagged call stun_engine_tcreate().

darcs-hash:20051018173012-65a35-3269ac17e8e1d73825707d13cb05dd8120b1af61.gz
parent 0f316418
......@@ -29,9 +29,12 @@ noinst_PROGRAMS = ${stun_prog_targets}
# ----------------------------------------------------------------------
# Rules for building the targets
include_HEADERS = stun.h stun_common.h
include_HEADERS = stun.h stun_common.h stun_tag.h
libstun_la_SOURCES = stun.c stun_common.c
libstun_la_SOURCES = stun.c stun_common.c \
stun_tag.c stun_tag_ref.c
BUILT_SOURCES = stun_tag_ref.c
COVERAGE_INPUT = $(libstun_la_SOURCES) $(include_HEADERS)
......@@ -55,12 +58,6 @@ torture_stun_SOURCES = torture_stun.c
include ../sofia.am
test: check
built_sources: $(BUILT_SOURCES)
libtarget: $(lib_LIBRARIES)
%.libtarget:
$(MAKE) -C $(*) $(MFLAGS) libtarget SUBTARGETS=
TAG_DLL_FLAGS = LIST=stun_tag_list
doc:
doxygen
built_sources: $(BUILT_SOURCES)
......@@ -40,8 +40,10 @@
#include <assert.h>
#include "stun.h"
#include "stun_tag.h"
#include <su_alloc.h>
#include <su_tagarg.h>
#include <su_log.h>
#include <su.h>
#include <su_localinfo.h>
......@@ -54,8 +56,6 @@ su_log_t stun_log[] = { SU_LOG_INIT("stun", "STUN_DEBUG", STUN_DEBUG) };
#include <su_debug.h>
#include <su.h>
char const stun_nat_unknown[] = "NAT type undetermined",
stun_open_internet[] = "Open Internet",
stun_udp_blocked[] = "UDP traffic is blocked, or Server unreachable",
......@@ -88,14 +88,49 @@ struct stun_socket_s
*
* @param stun server hostname or IPv4 address
* @param msg_integrity true if msg integr. should be used
**/
*
*
*/
stun_engine_t *stun_engine_create(char const *server,
int msg_integrity)
{
return stun_engine_tcreate(STUNTAG_SERVER(server),
STUNTAG_INTEGRITY(msg_integrity),
TAG_END());
}
/**
* Creates a STUN engine
*
* @param tag,value,... tag-value list
*
* @TAGS
* @TAG STUNTAG_SERVER() stun server hostname or dotted IPv4 address
* @TAG STUNTAG_INTEGRITY() true if msg integrity should be used
*
*/
stun_engine_t *stun_engine_tcreate(tag_type_t tag, tag_value_t value, ...)
{
stun_engine_t *stun;
char const *server = NULL;
int msg_integrity = 1;
ta_list ta;
SU_DEBUG_5(("%s(\"%s\"): called\n",
"stun_engine_create", server));
"stun_engine_tcreate", server));
ta_start(ta, tag, value);
tl_gets(ta_args(ta),
STUNTAG_SERVER_REF(server),
STUNTAG_INTEGRITY_REF(msg_integrity),
TAG_END());
/* Enviroment overrides */
if (getenv("STUN_SERVER")) {
server = getenv("STUN_SERVER");
SU_DEBUG_5(("stun: using STUN_SERVER=%s\n", server));
}
stun = su_home_clone(NULL, sizeof(*stun));
......@@ -276,7 +311,8 @@ int stun_bind(stun_socket_t *ss,
int stun_get_nattype(stun_socket_t *ss, struct sockaddr *my_addr, int *addrlen)
{
int nattype = STUN_NAT_UNKNOWN;
int retval, lifetime, sockfd, locallen, len;
int retval, lifetime, sockfd;
socklen_t locallen, len;
struct sockaddr_in local, mapped_addr1, mapped_addr2;
sockfd = ss->ss_sockfd;
......@@ -547,7 +583,7 @@ int stun_bind_test(stun_socket_t *ss, struct sockaddr_in *srvr_addr, struct sock
unsigned char dgram[512];
stun_attr_t *mapped_addr, *chg_addr;
struct sockaddr_in recv_addr;
int recv_addr_len;
socklen_t recv_addr_len;
/* for retransmission */
int num_retrx=0;
long retrx_int=100000;
......@@ -840,7 +876,8 @@ char const *stun_nattype(stun_engine_t *se)
int stun_get_lifetime(stun_socket_t *ss, struct sockaddr *my_addr, int *addrlen, int *lifetime)
{
int retval = -1, sockfdx, sockfdy, x_len, y_len, recv_addr_len, mapped_len;
int retval = -1, sockfdx, sockfdy;
socklen_t x_len, y_len, recv_addr_len, mapped_len;
struct sockaddr_in *clnt_addr=0, x_addr, y_addr, recv_addr, mapped_addr;
int lt_cur=0, lt=STUN_LIFETIME_EST, lt_max = STUN_LIFETIME_MAX;
stun_attr_t *mapped_addr_attr;
......
......@@ -31,7 +31,12 @@
* @author Kai Vehmanen <kai.vehmanen@nokia.com>
*/
#ifndef SU_WAIT_H
#include <su_wait.h>
#endif
#ifndef SU_TAG_H
#include <su_tag.h>
#endif
#include "stun_common.h"
#define STUN_LIFETIME_EST 350 /**< 6 min? */
......@@ -41,6 +46,8 @@
typedef struct stun_engine_s stun_engine_t;
typedef struct stun_socket_s stun_socket_t;
stun_engine_t *stun_engine_tcreate(tag_type_t tag, tag_value_t value, ...);
stun_engine_t *stun_engine_create(char const *server, int use_msgint);
void stun_engine_destroy(stun_engine_t *);
......
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@CFILE stun_tag.c Tags and tag lists for Offer/Answer Engine
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Wed Aug 3 20:28:17 EEST 2005
*/
#include "config.h"
#define TAG_NAMESPACE "stun"
#include <su_tag_class.h>
/**@def STUNTAG_SERVER(x)
*
* Pass media address.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_invite() \n
* nua_respond()
*
* @par Parameter type
* char const *
*
* @par Values
* NULL terminated character string containing a domain name,
* IPv4 address, or IPv6 address.
*
* Corresponding tag taking reference parameter is STUNTAG_SERVER_REF()
*/
tag_typedef_t stuntag_server = STRTAG_TYPEDEF(server);
/**@def STUNTAG_INTEGRITY(x)
*
* Enable integrity protection.
*
* @par Used with
* nua_create() \n
*
* @par Parameter type
* int (boolean)
*
* @par Values
* @c !=0 enable
* @c 0 disable
*
* Corresponding tag taking reference parameter is STUNTAG_INTEGRITY_REF()
*/
tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(srtp_integrity);
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef STUN_TAG_H
#define STUN_TAG_H
/**@file stun_tag.h Tags for STUN.
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Tue Oct 18 20:13:50 EEST 2005 ppessi
*/
#ifndef SU_TAG_H
#include <su_tag.h>
#endif
#define STUNTAG_SERVER(x) stuntag_server, tag_str_v(x)
extern tag_typedef_t stuntag_server;
#define STUNTAG_SERVER_REF(x) stuntag_server_ref, tag_str_vr(&(x))
extern tag_typedef_t stuntag_server_ref;
#define STUNTAG_INTEGRITY(x) stuntag_integrity, tag_int_v(x)
extern tag_typedef_t stuntag_integrity;
#define STUNTAG_INTEGRITY_REF(x) stuntag_integrity_ref, tag_int_vr(&(x))
extern tag_typedef_t stuntag_integrity_ref;
#endif /* STUN_TAG_H */
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