From 0c03f9d1a434ca591f40980eff388daff653ce0d Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 4 Feb 2014 10:13:56 +0000 Subject: Misc (re #1630): Fixing warnings about variable set but not used with recent gcc git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4728 74dad513-b988-da41-8d7b-12977e46ad98 --- pjnath/src/pjnath-test/ice_test.c | 94 +++++++++---------- pjnath/src/pjnath-test/test.c | 15 +-- pjnath/src/pjnath/ice_strans.c | 186 ++++++++++++++++++------------------- pjnath/src/pjturn-srv/allocation.c | 163 ++++++++++++++++---------------- pjnath/src/pjturn-srv/server.c | 74 +++++++-------- 5 files changed, 266 insertions(+), 266 deletions(-) (limited to 'pjnath') diff --git a/pjnath/src/pjnath-test/ice_test.c b/pjnath/src/pjnath-test/ice_test.c index 66d48314..4317cc7a 100644 --- a/pjnath/src/pjnath-test/ice_test.c +++ b/pjnath/src/pjnath-test/ice_test.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "test.h" #include "server.h" @@ -112,11 +112,11 @@ struct test_sess static void ice_on_rx_data(pj_ice_strans *ice_st, - unsigned comp_id, + unsigned comp_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, unsigned src_addr_len); -static void ice_on_ice_complete(pj_ice_strans *ice_st, +static void ice_on_ice_complete(pj_ice_strans *ice_st, pj_ice_strans_op op, pj_status_t status); static void destroy_sess(struct test_sess *sess, unsigned wait_msec); @@ -201,7 +201,7 @@ static int create_ice_strans(struct test_sess *test_sess, *p_ice = ice; return PJ_SUCCESS; } - + /* Create test session */ static int create_sess(pj_stun_config *stun_cfg, unsigned server_flag, @@ -238,7 +238,7 @@ static int create_sess(pj_stun_config *stun_cfg, destroy_sess(sess, 500); return -10; } - sess->server->turn_respond_allocate = + sess->server->turn_respond_allocate = sess->server->turn_respond_refresh = PJ_TRUE; /* Create resolver */ @@ -318,7 +318,7 @@ static void destroy_sess(struct test_sess *sess, unsigned wait_msec) } static void ice_on_rx_data(pj_ice_strans *ice_st, - unsigned comp_id, + unsigned comp_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, unsigned src_addr_len) @@ -335,7 +335,7 @@ static void ice_on_rx_data(pj_ice_strans *ice_st, } -static void ice_on_ice_complete(pj_ice_strans *ice_st, +static void ice_on_ice_complete(pj_ice_strans *ice_st, pj_ice_strans_op op, pj_status_t status) { @@ -436,14 +436,14 @@ static int check_pair(const struct ice_ept *ept1, const struct ice_ept *ept2, /* Extra components must not have valid pair */ for (; icfg.comp_cnt>i && - pj_ice_strans_get_valid_pair(ept1->ice, i+1) != NULL) + pj_ice_strans_get_valid_pair(ept1->ice, i+1) != NULL) { PJ_LOG(3,(THIS_FILE, INDENT "err: ice1 shouldn't have valid pair " "for component %d", i+1)); return start_err - 8; } if (ept2->cfg.comp_cnt>i && - pj_ice_strans_get_valid_pair(ept2->ice, i+1) != NULL) + pj_ice_strans_get_valid_pair(ept2->ice, i+1) != NULL) { PJ_LOG(3,(THIS_FILE, INDENT "err: ice2 shouldn't have valid pair " "for component %d", i+1)); @@ -463,7 +463,7 @@ static int check_pair(const struct ice_ept *ept1, const struct ice_ept *ept2, poll_events(stun_cfg, 10, PJ_FALSE); \ pj_gettimeofday(&t); \ if (expr) { \ - rc = PJ_SUCCESS; \ + RC = PJ_SUCCESS; \ break; \ } \ PJ_TIME_VAL_SUB(t, t0); \ @@ -477,13 +477,13 @@ int worker_thread_proc(void *data) pj_status_t rc; struct test_sess *sess = (struct test_sess *) data; pj_stun_config *stun_cfg = sess->stun_cfg; - + /* Wait until negotiation is complete on both endpoints */ #define ALL_DONE (sess->param->worker_quit || \ (sess->caller.result.nego_status!=PJ_EPENDING && \ sess->callee.result.nego_status!=PJ_EPENDING)) WAIT_UNTIL(sess->param->worker_timeout, ALL_DONE, rc); - + PJ_UNUSED_ARG(rc); return 0; } @@ -538,7 +538,7 @@ static int perform_test2(const char *title, goto on_return; } /* Init ICE on caller */ - rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role, + rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role, &sess->caller.ufrag, &sess->caller.pass); if (rc != PJ_SUCCESS) { app_perror(INDENT "err: caller pj_ice_strans_init_ice()", rc); @@ -547,7 +547,7 @@ static int perform_test2(const char *title, } /* Init ICE on callee */ - rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role, + rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role, &sess->callee.ufrag, &sess->callee.pass); if (rc != PJ_SUCCESS) { app_perror(INDENT "err: callee pj_ice_strans_init_ice()", rc); @@ -596,7 +596,7 @@ static int perform_test2(const char *title, } goto on_destroy; } - + WAIT_UNTIL(30000, ALL_DONE, rc); if (!ALL_DONE) { PJ_LOG(3,(THIS_FILE, INDENT "err: negotiation timed-out")); @@ -690,7 +690,7 @@ int ice_test(void) unsigned server_flag; struct test_cfg ua1; struct test_cfg ua2; - } sess_cfg[] = + } sess_cfg[] = { /* Role comp# host? stun? turn? flag? ans_del snd_del des_del */ { @@ -740,7 +740,7 @@ int ice_test(void) /* Simple test first with host candidate */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "Basic with host candidates", 0x0, @@ -749,23 +749,23 @@ int ice_test(void) {ROLE2, 1, YES, NO, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; - rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, + rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; - rc = perform_test("Basic with host candidates, 2 components", - &stun_cfg, cfg.server_flag, + rc = perform_test("Basic with host candidates, 2 components", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; } - + /* Simple test first with srflx candidate */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "Basic with srflx candidates", 0xFFFF, @@ -774,7 +774,7 @@ int ice_test(void) {ROLE2, 1, YES, YES, NO, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; - rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, + rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -782,8 +782,8 @@ int ice_test(void) cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; - rc = perform_test("Basic with srflx candidates, 2 components", - &stun_cfg, cfg.server_flag, + rc = perform_test("Basic with srflx candidates, 2 components", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -791,7 +791,7 @@ int ice_test(void) /* Simple test with relay candidate */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "Basic with relay candidates", 0xFFFF, @@ -800,7 +800,7 @@ int ice_test(void) {ROLE2, 1, NO, NO, YES, 0, 0, 0, 0, {PJ_SUCCESS, PJ_SUCCESS}} }; - rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, + rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -808,8 +808,8 @@ int ice_test(void) cfg.ua1.comp_cnt = 2; cfg.ua2.comp_cnt = 2; - rc = perform_test("Basic with relay candidates, 2 components", - &stun_cfg, cfg.server_flag, + rc = perform_test("Basic with relay candidates, 2 components", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -817,7 +817,7 @@ int ice_test(void) /* Failure test with STUN resolution */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "STUN resolution failure", 0x0, @@ -834,8 +834,8 @@ int ice_test(void) cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; - rc = perform_test("STUN resolution failure with destroy on callback", - &stun_cfg, cfg.server_flag, + rc = perform_test("STUN resolution failure with destroy on callback", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -843,7 +843,7 @@ int ice_test(void) /* Failure test with TURN resolution */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "TURN allocation failure", 0xFFFF, @@ -852,7 +852,7 @@ int ice_test(void) {ROLE2, 2, NO, NO, YES, WRONG_TURN, 0, 0, 0, {PJ_STATUS_FROM_STUN_CODE(401), -1}} }; - rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, + rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -860,8 +860,8 @@ int ice_test(void) cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; - rc = perform_test("TURN allocation failure with destroy on callback", - &stun_cfg, cfg.server_flag, + rc = perform_test("TURN allocation failure with destroy on callback", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -870,7 +870,7 @@ int ice_test(void) /* STUN failure, testing TURN deallocation */ if (1) { - struct sess_cfg_t cfg = + struct sess_cfg_t cfg = { "STUN failure, testing TURN deallocation", 0xFFFF & (~(CREATE_STUN_SERVER)), @@ -887,8 +887,8 @@ int ice_test(void) cfg.ua1.client_flag |= DEL_ON_ERR; cfg.ua2.client_flag |= DEL_ON_ERR; - rc = perform_test("STUN failure, testing TURN deallocation (cb)", - &stun_cfg, cfg.server_flag, + rc = perform_test("STUN failure, testing TURN deallocation (cb)", + &stun_cfg, cfg.server_flag, &cfg.ua1, &cfg.ua2); if (rc != 0) goto on_return; @@ -908,7 +908,7 @@ int ice_test(void) struct role_t { pj_ice_sess_role ua1; pj_ice_sess_role ua2; - } role[] = + } role[] = { { ROLE1, ROLE2}, { ROLE2, ROLE1}, @@ -936,14 +936,14 @@ int ice_test(void) for (k2=1; k2<=2; ++k2) { char title[120]; - sprintf(title, - "%s/%s, %dms answer delay, %d vs %d components", + sprintf(title, + "%s/%s, %dms answer delay, %d vs %d components", pj_ice_sess_role_name(role[j].ua1), pj_ice_sess_role_name(role[j].ua2), delay[d], k1, k2); cfg->ua2.comp_cnt = k2; - rc = perform_test(title, &stun_cfg, cfg->server_flag, + rc = perform_test(title, &stun_cfg, cfg->server_flag, &cfg->ua1, &cfg->ua2); if (rc != 0) goto on_return; @@ -1021,14 +1021,14 @@ int ice_conc_test(void) pj_stun_config stun_cfg; unsigned i; int rc; - + pool = pj_pool_create(mem, NULL, 512, 512, NULL); rc = create_stun_config(pool, &stun_cfg); if (rc != PJ_SUCCESS) { pj_pool_release(pool); return -7; } - + for (i = 0; i < LOOP; i++) { PJ_LOG(3,(THIS_FILE, INDENT "Test %d of %d", i+1, LOOP)); rc = ice_one_conc_test(&stun_cfg, PJ_TRUE); @@ -1038,7 +1038,7 @@ int ice_conc_test(void) /* Avoid compiler warning */ goto on_return; - + on_return: destroy_stun_config(&stun_cfg); pj_pool_release(pool); diff --git a/pjnath/src/pjnath-test/test.c b/pjnath/src/pjnath-test/test.c index e8f93080..dd3e192d 100644 --- a/pjnath/src/pjnath-test/test.c +++ b/pjnath/src/pjnath-test/test.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "test.h" #include @@ -108,12 +108,12 @@ void capture_pjlib_state(pj_stun_config *cfg, struct pjlib_state *st) pj_caching_pool *cp; st->timer_cnt = (unsigned)pj_timer_heap_count(cfg->timer_heap); - + cp = (pj_caching_pool*)cfg->pf; st->pool_used_cnt = (unsigned)cp->used_count; } -int check_pjlib_state(pj_stun_config *cfg, +int check_pjlib_state(pj_stun_config *cfg, const struct pjlib_state *initial_st) { struct pjlib_state current_state; @@ -153,7 +153,7 @@ int check_pjlib_state(pj_stun_config *cfg, pj_pool_factory *mem; -int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | +int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC; pj_log_func *orig_log_func; @@ -178,6 +178,7 @@ static int test_inner(void) #if 1 pj_log_set_level(3); pj_log_set_decor(param_log_decor); + PJ_UNUSED_ARG(test_log_func); #elif 1 log_file = fopen("pjnath-test.log", "wt"); pj_log_set_level(5); @@ -190,7 +191,7 @@ static int test_inner(void) app_perror("pj_init() error!!", rc); return rc; } - + pj_dump_config(); pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); @@ -233,7 +234,7 @@ int test_main(void) } PJ_CATCH_ANY { int id = PJ_GET_EXCEPTION(); - PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)", + PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)", id, pj_exception_id_name(id))); } PJ_END; diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c index bd817272..b016e8f1 100644 --- a/pjnath/src/pjnath/ice_strans.c +++ b/pjnath/src/pjnath/ice_strans.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include @@ -65,7 +65,7 @@ enum tp_type /* The candidate type preference when STUN candidate is used */ -static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] = +static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] = { #if PJNATH_ICE_PRIO_STD 100, /**< PJ_ICE_HOST_PREF */ @@ -84,14 +84,14 @@ static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] = /* ICE callbacks */ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status); -static pj_status_t ice_tx_pkt(pj_ice_sess *ice, +static pj_status_t ice_tx_pkt(pj_ice_sess *ice, unsigned comp_id, unsigned transport_id, const void *pkt, pj_size_t size, const pj_sockaddr_t *dst_addr, unsigned dst_addr_len); -static void ice_rx_data(pj_ice_sess *ice, - unsigned comp_id, +static void ice_rx_data(pj_ice_sess *ice, + unsigned comp_id, unsigned transport_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, @@ -110,7 +110,7 @@ static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock, pj_ioqueue_op_key_t *send_key, pj_ssize_t sent); /* Notification when the status of the STUN transport has changed. */ -static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, +static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status); @@ -136,7 +136,7 @@ static void sess_init_update(pj_ice_strans *ice_st); * This structure describes an ICE stream transport component. A component * in ICE stream transport typically corresponds to a single socket created * for this component, and bound to a specific transport address. This - * component may have multiple alias addresses, for example one alias + * component may have multiple alias addresses, for example one alias * address for each interfaces in multi-homed host, another for server * reflexive alias, and another for relayed alias. For each transport * address alias, an ICE stream transport candidate (#pj_ice_sess_cand) will @@ -298,11 +298,11 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st, /* Override with component specific socket buffer size settings, if any */ if (ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size > 0) { - ice_st->cfg.turn.cfg.so_rcvbuf_size = + ice_st->cfg.turn.cfg.so_rcvbuf_size = ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size; } if (ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size > 0) { - ice_st->cfg.turn.cfg.so_sndbuf_size = + ice_st->cfg.turn.cfg.so_sndbuf_size = ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size; } @@ -381,10 +381,10 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) stun_sock_cb.on_rx_data = &stun_on_rx_data; stun_sock_cb.on_status = &stun_on_status; stun_sock_cb.on_data_sent = &stun_on_data_sent; - + /* Override component specific QoS settings, if any */ if (ice_st->cfg.comp[comp_id-1].qos_type) { - ice_st->cfg.stun.cfg.qos_type = + ice_st->cfg.stun.cfg.qos_type = ice_st->cfg.comp[comp_id-1].qos_type; } if (ice_st->cfg.comp[comp_id-1].qos_params.flags) { @@ -395,11 +395,11 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) /* Override component specific socket buffer size settings, if any */ if (ice_st->cfg.comp[comp_id-1].so_rcvbuf_size > 0) { - ice_st->cfg.stun.cfg.so_rcvbuf_size = + ice_st->cfg.stun.cfg.so_rcvbuf_size = ice_st->cfg.comp[comp_id-1].so_rcvbuf_size; } if (ice_st->cfg.comp[comp_id-1].so_sndbuf_size > 0) { - ice_st->cfg.stun.cfg.so_sndbuf_size = + ice_st->cfg.stun.cfg.so_sndbuf_size = ice_st->cfg.comp[comp_id-1].so_sndbuf_size; } @@ -411,8 +411,8 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) if (status != PJ_SUCCESS) return status; - /* Start STUN Binding resolution and add srflx candidate - * only if server is set + /* Start STUN Binding resolution and add srflx candidate + * only if server is set */ if (ice_st->cfg.stun.server.slen) { pj_stun_sock_info stun_sock_info; @@ -420,16 +420,16 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) /* Add pending job */ ///sess_add_ref(ice_st); - PJ_LOG(4,(ice_st->obj_name, + PJ_LOG(4,(ice_st->obj_name, "Comp %d: srflx candidate starts Binding discovery", comp_id)); pj_log_push_indent(); /* Start Binding resolution */ - status = pj_stun_sock_start(comp->stun_sock, + status = pj_stun_sock_start(comp->stun_sock, &ice_st->cfg.stun.server, - ice_st->cfg.stun.port, + ice_st->cfg.stun.port, ice_st->cfg.resolver); if (status != PJ_SUCCESS) { ///sess_dec_ref(ice_st); @@ -475,8 +475,8 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) if (status != PJ_SUCCESS) return status; - for (i=0; icfg.stun.max_host_cands; ++i) + for (i=0; icfg.stun.max_host_cands; ++i) { char addrinfo[PJ_INET6_ADDRSTRLEN+10]; const pj_sockaddr *addr = &stun_sock_info.aliases[i]; @@ -487,8 +487,8 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) break; } - /* Ignore loopback addresses unless cfg->stun.loop_addr - * is set + /* Ignore loopback addresses unless cfg->stun.loop_addr + * is set */ if ((pj_ntohl(addr->ipv4.sin_addr.s_addr)>>24)==127) { if (ice_st->cfg.stun.loop_addr==PJ_FALSE) @@ -508,7 +508,7 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) pj_ice_calc_foundation(ice_st->pool, &cand->foundation, cand->type, &cand->base_addr); - PJ_LOG(4,(ice_st->obj_name, + PJ_LOG(4,(ice_st->obj_name, "Comp %d: host candidate %s added", comp_id, pj_sockaddr_print(&cand->addr, addrinfo, sizeof(addrinfo), 3))); @@ -532,8 +532,8 @@ static pj_status_t create_comp(pj_ice_strans *ice_st, unsigned comp_id) } -/* - * Create ICE stream transport +/* + * Create ICE stream transport */ PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name, const pj_ice_strans_cfg *cfg, @@ -564,7 +564,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name, ice_st->obj_name = pool->obj_name; ice_st->user_data = user_data; - PJ_LOG(4,(ice_st->obj_name, + PJ_LOG(4,(ice_st->obj_name, "Creating ICE stream transport with %d component(s)", comp_cnt)); pj_log_push_indent(); @@ -586,13 +586,13 @@ PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name, pj_memcpy(&ice_st->cb, cb, sizeof(*cb)); ice_st->comp_cnt = comp_cnt; - ice_st->comp = (pj_ice_strans_comp**) + ice_st->comp = (pj_ice_strans_comp**) pj_pool_calloc(pool, comp_cnt, sizeof(pj_ice_strans_comp*)); /* Move state to candidate gathering */ ice_st->state = PJ_ICE_STRANS_STATE_INIT; - /* Acquire initialization mutex to prevent callback to be + /* Acquire initialization mutex to prevent callback to be * called before we finish initialization. */ pj_grp_lock_acquire(ice_st->grp_lock); @@ -749,7 +749,7 @@ static void sess_init_update(pj_ice_strans *ice_st) ice_st->cb_called = PJ_TRUE; ice_st->state = PJ_ICE_STRANS_STATE_READY; if (ice_st->cb.on_ice_complete) - (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT, + (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT, PJ_SUCCESS); } @@ -785,7 +785,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_get_options( pj_ice_strans *ice_st, } /* - * Specify various options for this ICE stream transport. + * Specify various options for this ICE stream transport. */ PJ_DEF(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st, const pj_ice_sess_options *opt) @@ -834,7 +834,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, /* Create! */ status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role, - ice_st->comp_cnt, &ice_cb, + ice_st->comp_cnt, &ice_cb, local_ufrag, local_passwd, ice_st->grp_lock, &ice_st->ice); @@ -852,7 +852,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, * checked first. */ if (ice_st->comp[0]->default_cand >= 0 && - ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type + ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type == PJ_ICE_CAND_TYPE_SRFLX) { pj_ice_sess_set_prefs(ice_st->ice, srflx_pref_table); @@ -865,7 +865,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, /* Re-enable logging for Send/Data indications */ if (comp->turn_sock) { - PJ_LOG(5,(ice_st->obj_name, + PJ_LOG(5,(ice_st->obj_name, "Disabling STUN Indication logging for " "component %d", i+1)); pj_turn_sock_set_log(comp->turn_sock, 0xFFFF); @@ -878,7 +878,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, /* Skip if candidate is not ready */ if (cand->status != PJ_SUCCESS) { - PJ_LOG(5,(ice_st->obj_name, + PJ_LOG(5,(ice_st->obj_name, "Candidate %d of comp %d is not added (pending)", j, i)); continue; @@ -888,10 +888,10 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st, pj_assert(pj_sockaddr_has_addr(&cand->addr)); /* Add the candidate */ - status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id, - cand->transport_id, cand->type, - cand->local_pref, - &cand->foundation, &cand->addr, + status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id, + cand->transport_id, cand->type, + cand->local_pref, + &cand->foundation, &cand->addr, &cand->base_addr, &cand->rel_addr, pj_sockaddr_get_len(&cand->addr), (unsigned*)&ice_cand_id); @@ -911,7 +911,7 @@ on_error: } /* - * Check if the ICE stream transport has the ICE session created. + * Check if the ICE stream transport has the ICE session created. */ PJ_DEF(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st) { @@ -984,7 +984,7 @@ PJ_DEF(unsigned) pj_ice_strans_get_cands_count(pj_ice_strans *ice_st, { unsigned i, cnt; - PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && + PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && comp_id <= ice_st->comp_cnt, 0); cnt = 0; @@ -1007,7 +1007,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_enum_cands(pj_ice_strans *ice_st, { unsigned i, cnt; - PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && + PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && comp_id <= ice_st->comp_cnt && count && cand, PJ_EINVAL); cnt = 0; @@ -1041,7 +1041,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_get_def_cand( pj_ice_strans *ice_st, } else { pj_ice_strans_comp *comp = ice_st->comp[comp_id - 1]; pj_assert(comp->default_cand>=0 && comp->default_candcand_cnt); - pj_memcpy(cand, &comp->cand_list[comp->default_cand], + pj_memcpy(cand, &comp->cand_list[comp->default_cand], sizeof(pj_ice_sess_cand)); } return PJ_SUCCESS; @@ -1107,7 +1107,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_start_ice( pj_ice_strans *ice_st, } if (count) { - status = pj_turn_sock_set_perm(comp->turn_sock, count, + status = pj_turn_sock_set_perm(comp->turn_sock, count, addrs, 0); if (status != PJ_SUCCESS) { pj_ice_strans_stop_ice(ice_st); @@ -1131,16 +1131,16 @@ PJ_DEF(pj_status_t) pj_ice_strans_start_ice( pj_ice_strans *ice_st, /* * Get valid pair. */ -PJ_DEF(const pj_ice_sess_check*) +PJ_DEF(const pj_ice_sess_check*) pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st, unsigned comp_id) { PJ_ASSERT_RETURN(ice_st && comp_id && comp_id <= ice_st->comp_cnt, NULL); - + if (ice_st->ice == NULL) return NULL; - + return ice_st->ice->comp[comp_id-1].valid_check; } @@ -1170,7 +1170,6 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st, const pj_sockaddr_t *dst_addr, int dst_addr_len) { - pj_ssize_t pkt_size; pj_ice_strans_comp *comp; unsigned def_cand; pj_status_t status; @@ -1219,25 +1218,24 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st, if (!comp->turn_log_off) { /* Disable logging for Send/Data indications */ - PJ_LOG(5,(ice_st->obj_name, + PJ_LOG(5,(ice_st->obj_name, "Disabling STUN Indication logging for " "component %d", comp->comp_id)); pj_turn_sock_set_log(comp->turn_sock, msg_disable_ind); comp->turn_log_off = PJ_TRUE; } - status = pj_turn_sock_sendto(comp->turn_sock, - (const pj_uint8_t*)data, + status = pj_turn_sock_sendto(comp->turn_sock, + (const pj_uint8_t*)data, (unsigned)data_len, dst_addr, dst_addr_len); - return (status==PJ_SUCCESS||status==PJ_EPENDING) ? + return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; } else { - pkt_size = data_len; - status = pj_stun_sock_sendto(comp->stun_sock, NULL, data, - (unsigned)data_len, 0, dst_addr, + status = pj_stun_sock_sendto(comp->stun_sock, NULL, data, + (unsigned)data_len, 0, dst_addr, dst_addr_len); - return (status==PJ_SUCCESS||status==PJ_EPENDING) ? + return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; } @@ -1265,8 +1263,8 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; pj_strerror(status, errmsg, sizeof(errmsg)); - PJ_LOG(4,(ice_st->obj_name, - "ICE negotiation failed after %ds:%03d: %s", + PJ_LOG(4,(ice_st->obj_name, + "ICE negotiation failed after %ds:%03d: %s", msec/1000, msec%1000, errmsg)); } else { unsigned i; @@ -1276,7 +1274,7 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) PJ_STUN_SESS_LOG_RX_IND) }; - PJ_LOG(4,(ice_st->obj_name, + PJ_LOG(4,(ice_st->obj_name, "ICE negotiation success after %ds:%03d", msec/1000, msec%1000)); @@ -1288,9 +1286,9 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) char lip[PJ_INET6_ADDRSTRLEN+10]; char rip[PJ_INET6_ADDRSTRLEN+10]; - pj_sockaddr_print(&check->lcand->addr, lip, + pj_sockaddr_print(&check->lcand->addr, lip, sizeof(lip), 3); - pj_sockaddr_print(&check->rcand->addr, rip, + pj_sockaddr_print(&check->rcand->addr, rip, sizeof(rip), 3); if (check->lcand->transport_id == TP_TURN) { @@ -1303,7 +1301,7 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) sizeof(check->rcand->addr)); /* Disable logging for Send/Data indications */ - PJ_LOG(5,(ice_st->obj_name, + PJ_LOG(5,(ice_st->obj_name, "Disabling STUN Indication logging for " "component %d", i+1)); pj_turn_sock_set_log(ice_st->comp[i]->turn_sock, @@ -1314,14 +1312,14 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) PJ_LOG(4,(ice_st->obj_name, " Comp %d: " "sending from %s candidate %s to " "%s candidate %s", - i+1, + i+1, pj_ice_get_cand_type_name(check->lcand->type), lip, pj_ice_get_cand_type_name(check->rcand->type), rip)); - + } else { - PJ_LOG(4,(ice_st->obj_name, + PJ_LOG(4,(ice_st->obj_name, "Comp %d: disabled", i+1)); } } @@ -1331,10 +1329,10 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) PJ_ICE_STRANS_STATE_FAILED; pj_log_push_indent(); - (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION, + (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION, status); pj_log_pop_indent(); - + } pj_grp_lock_dec_ref(ice_st->grp_lock); @@ -1343,8 +1341,8 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) /* * Callback called by ICE session when it wants to send outgoing packet. */ -static pj_status_t ice_tx_pkt(pj_ice_sess *ice, - unsigned comp_id, +static pj_status_t ice_tx_pkt(pj_ice_sess *ice, + unsigned comp_id, unsigned transport_id, const void *pkt, pj_size_t size, const pj_sockaddr_t *dst_addr, @@ -1361,39 +1359,39 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice, comp = ice_st->comp[comp_id-1]; - TRACE_PKT((comp->ice_st->obj_name, + TRACE_PKT((comp->ice_st->obj_name, "Component %d TX packet to %s:%d with transport %d", - comp_id, + comp_id, pj_sockaddr_print(dst_addr, daddr, sizeof(addr), 0), pj_sockaddr_get_port(dst_addr), transport_id)); if (transport_id == TP_TURN) { if (comp->turn_sock) { - status = pj_turn_sock_sendto(comp->turn_sock, - (const pj_uint8_t*)pkt, + status = pj_turn_sock_sendto(comp->turn_sock, + (const pj_uint8_t*)pkt, (unsigned)size, dst_addr, dst_addr_len); } else { status = PJ_EINVALIDOP; } } else if (transport_id == TP_STUN) { - status = pj_stun_sock_sendto(comp->stun_sock, NULL, + status = pj_stun_sock_sendto(comp->stun_sock, NULL, pkt, (unsigned)size, 0, dst_addr, dst_addr_len); } else { pj_assert(!"Invalid transport ID"); status = PJ_EINVALIDOP; } - + return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; } /* * Callback called by ICE session when it receives application data. */ -static void ice_rx_data(pj_ice_sess *ice, - unsigned comp_id, +static void ice_rx_data(pj_ice_sess *ice, + unsigned comp_id, unsigned transport_id, void *pkt, pj_size_t size, const pj_sockaddr_t *src_addr, @@ -1404,13 +1402,13 @@ static void ice_rx_data(pj_ice_sess *ice, PJ_UNUSED_ARG(transport_id); if (ice_st->cb.on_rx_data) { - (*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size, + (*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size, src_addr, src_addr_len); } } /* Notification when incoming packet has been received from - * the STUN socket. + * the STUN socket. */ static pj_bool_t stun_on_rx_data(pj_stun_sock *stun_sock, void *pkt, @@ -1438,19 +1436,19 @@ static pj_bool_t stun_on_rx_data(pj_stun_sock *stun_sock, * report this to application. */ if (ice_st->cb.on_rx_data) { - (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len, + (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len, src_addr, addr_len); } } else { /* Hand over the packet to ICE session */ - status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id, + status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id, TP_STUN, pkt, pkt_len, src_addr, addr_len); if (status != PJ_SUCCESS) { - ice_st_perror(comp->ice_st, "Error processing packet", + ice_st_perror(comp->ice_st, "Error processing packet", status); } } @@ -1459,7 +1457,7 @@ static pj_bool_t stun_on_rx_data(pj_stun_sock *stun_sock, } /* Notifification when asynchronous send operation to the STUN socket - * has completed. + * has completed. */ static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock, pj_ioqueue_op_key_t *send_key, @@ -1472,7 +1470,7 @@ static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock, } /* Notification when the status of the STUN transport has changed. */ -static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, +static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status) { @@ -1572,11 +1570,11 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, cand->status = PJ_SUCCESS; } - PJ_LOG(4,(comp->ice_st->obj_name, + PJ_LOG(4,(comp->ice_st->obj_name, "Comp %d: %s, " "srflx address is %s", - comp->comp_id, op_name, - pj_sockaddr_print(&info.mapped_addr, ipaddr, + comp->comp_id, op_name, + pj_sockaddr_print(&info.mapped_addr, ipaddr, sizeof(ipaddr), 3))); sess_init_update(ice_st); @@ -1662,8 +1660,8 @@ static void turn_on_rx_data(pj_turn_sock *turn_sock, peer_addr, addr_len); if (status != PJ_SUCCESS) { - ice_st_perror(comp->ice_st, - "Error processing packet from TURN relay", + ice_st_perror(comp->ice_st, + "Error processing packet from TURN relay", status); } } @@ -1721,18 +1719,18 @@ static void turn_on_state(pj_turn_sock *turn_sock, pj_turn_state_t old_state, pj_sockaddr_cp(&cand->addr, &rel_info.relay_addr); pj_sockaddr_cp(&cand->base_addr, &rel_info.relay_addr); pj_sockaddr_cp(&cand->rel_addr, &rel_info.mapped_addr); - pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation, - PJ_ICE_CAND_TYPE_RELAYED, + pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation, + PJ_ICE_CAND_TYPE_RELAYED, &rel_info.relay_addr); cand->status = PJ_SUCCESS; /* Set default candidate to relay */ comp->default_cand = (unsigned)(cand - comp->cand_list); - PJ_LOG(4,(comp->ice_st->obj_name, + PJ_LOG(4,(comp->ice_st->obj_name, "Comp %d: TURN allocation complete, relay address is %s", - comp->comp_id, - pj_sockaddr_print(&rel_info.relay_addr, ipaddr, + comp->comp_id, + pj_sockaddr_print(&rel_info.relay_addr, ipaddr, sizeof(ipaddr), 3))); sess_init_update(comp->ice_st); diff --git a/pjnath/src/pjturn-srv/allocation.c b/pjnath/src/pjturn-srv/allocation.c index b13f02f1..5310ea5f 100644 --- a/pjnath/src/pjturn-srv/allocation.c +++ b/pjnath/src/pjturn-srv/allocation.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "turn.h" #include "auth.h" @@ -62,8 +62,8 @@ static pj_status_t create_relay(pj_turn_srv *srv, const alloc_request *req, pj_turn_relay_res *relay); static void destroy_relay(pj_turn_relay_res *relay); -static void on_rx_from_peer(pj_ioqueue_key_t *key, - pj_ioqueue_op_key_t *op_key, +static void on_rx_from_peer(pj_ioqueue_key_t *key, + pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_read); static pj_status_t stun_on_send_msg(pj_stun_session *sess, void *token, @@ -124,7 +124,7 @@ static pj_status_t parse_allocate_req(alloc_request *cfg, /* Check if we can satisfy the bandwidth */ if (cfg->bandwidth > MAX_CLIENT_BANDWIDTH) { - pj_stun_session_respond(sess, rdata, + pj_stun_session_respond(sess, rdata, PJ_STUN_SC_ALLOCATION_QUOTA_REACHED, "Invalid bandwidth", NULL, PJ_TRUE, src_addr, src_addr_len); @@ -136,7 +136,7 @@ static pj_status_t parse_allocate_req(alloc_request *cfg, pj_stun_msg_find_attr(req, PJ_STUN_ATTR_REQ_TRANSPORT, 0); if (attr_req_tp == NULL) { pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, - "Missing REQUESTED-TRANSPORT attribute", + "Missing REQUESTED-TRANSPORT attribute", NULL, PJ_TRUE, src_addr, src_addr_len); return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); } @@ -156,9 +156,9 @@ static pj_status_t parse_allocate_req(alloc_request *cfg, 0); if (attr_res_token) { /* We don't support RESERVATION-TOKEN for now */ - pj_stun_session_respond(sess, rdata, + pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, - "RESERVATION-TOKEN is not supported", NULL, + "RESERVATION-TOKEN is not supported", NULL, PJ_TRUE, src_addr, src_addr_len); return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); } @@ -170,7 +170,7 @@ static pj_status_t parse_allocate_req(alloc_request *cfg, cfg->lifetime = attr_lifetime->value; if (cfg->lifetime < MIN_LIFETIME) { pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, - "LIFETIME too short", NULL, + "LIFETIME too short", NULL, PJ_TRUE, src_addr, src_addr_len); return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); } @@ -206,7 +206,7 @@ static pj_status_t send_allocate_response(pj_turn_allocation *alloc, /* Add LIFETIME. */ pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, - PJ_STUN_ATTR_LIFETIME, + PJ_STUN_ATTR_LIFETIME, (unsigned)alloc->relay.lifetime); /* Add BANDWIDTH */ @@ -222,10 +222,10 @@ static pj_status_t send_allocate_response(pj_turn_allocation *alloc, PJ_STUN_ATTR_XOR_MAPPED_ADDR, PJ_TRUE, &alloc->hkey.clt_addr, pj_sockaddr_get_len(&alloc->hkey.clt_addr)); - + /* Send the response */ return pj_stun_session_send_msg(srv_sess, transport, PJ_TRUE, - PJ_FALSE, &alloc->hkey.clt_addr, + PJ_FALSE, &alloc->hkey.clt_addr, pj_sockaddr_get_len(&alloc->hkey.clt_addr), tdata); } @@ -255,9 +255,9 @@ static pj_status_t init_cred(pj_turn_allocation *alloc, const pj_stun_msg *req) PJ_ASSERT_RETURN(nonce != NULL, PJ_EBUG); /* Lookup the password */ - status = pj_turn_get_password(NULL, NULL, &realm->value, - &user->value, alloc->pool, - &alloc->cred.data.static_cred.data_type, + status = pj_turn_get_password(NULL, NULL, &realm->value, + &user->value, alloc->pool, + &alloc->cred.data.static_cred.data_type, &alloc->cred.data.static_cred.data); if (status != PJ_SUCCESS) return status; @@ -314,7 +314,7 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport, alloc->hkey.tp_type = transport->listener->tp_type; pj_memcpy(&alloc->hkey.clt_addr, src_addr, src_addr_len); - status = pj_lock_create_recursive_mutex(pool, alloc->obj_name, + status = pj_lock_create_recursive_mutex(pool, alloc->obj_name, &alloc->lock); if (status != PJ_SUCCESS) { goto on_error; @@ -327,7 +327,7 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport, alloc->ch_table = pj_hash_create(pool, PEER_TABLE_SIZE); /* Print info */ - pj_ansi_strcpy(alloc->info, + pj_ansi_strcpy(alloc->info, pj_turn_tp_type_name(transport->listener->tp_type)); alloc->info[3] = ':'; pj_sockaddr_print(src_addr, alloc->info+4, sizeof(alloc->info)-4, 3); @@ -371,9 +371,9 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport, goto on_error; /* Done */ - pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp, + pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp, sizeof(str_tmp), 3); - PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s", + PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s", alloc->info, pj_turn_tp_type_name(req.tp_type), str_tmp)); /* Success */ @@ -383,7 +383,7 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport, on_error: /* Send reply to the ALLOCATE request */ pj_strerror(status, str_tmp, sizeof(str_tmp)); - pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, + pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, transport, PJ_TRUE, src_addr, src_addr_len); /* Cleanup */ @@ -396,7 +396,7 @@ on_error: static void destroy_relay(pj_turn_relay_res *relay) { if (relay->timer.id) { - pj_timer_heap_cancel(relay->allocation->server->core.timer_heap, + pj_timer_heap_cancel(relay->allocation->server->core.timer_heap, &relay->timer); relay->timer.id = PJ_FALSE; } @@ -482,8 +482,8 @@ PJ_DEF(void) pj_turn_allocation_on_transport_closed( pj_turn_allocation *alloc, /* Initiate shutdown sequence for this allocation and start destroy timer. - * Once allocation is marked as shutting down, any packets will be - * rejected/discarded + * Once allocation is marked as shutting down, any packets will be + * rejected/discarded */ static void alloc_shutdown(pj_turn_allocation *alloc) { @@ -501,7 +501,7 @@ static void alloc_shutdown(pj_turn_allocation *alloc) * shutdown request. */ return; - } + } pj_assert(alloc->relay.timer.id == TIMER_ID_NONE); @@ -530,7 +530,7 @@ static pj_status_t resched_timeout(pj_turn_allocation *alloc) pj_assert(alloc->relay.timer.id != TIMER_ID_DESTROY); if (alloc->relay.timer.id != 0) { - pj_timer_heap_cancel(alloc->server->core.timer_heap, + pj_timer_heap_cancel(alloc->server->core.timer_heap, &alloc->relay.timer); alloc->relay.timer.id = TIMER_ID_NONE; } @@ -539,7 +539,7 @@ static pj_status_t resched_timeout(pj_turn_allocation *alloc) delay.msec = 0; alloc->relay.timer.id = TIMER_ID_TIMEOUT; - status = pj_timer_heap_schedule(alloc->server->core.timer_heap, + status = pj_timer_heap_schedule(alloc->server->core.timer_heap, &alloc->relay.timer, &delay); if (status != PJ_SUCCESS) { alloc->relay.timer.id = TIMER_ID_NONE; @@ -565,8 +565,8 @@ static void relay_timeout_cb(pj_timer_heap_t *heap, pj_timer_entry *e) e->id = TIMER_ID_NONE; - PJ_LOG(4,(alloc->obj_name, - "Client %s refresh timed-out, shutting down..", + PJ_LOG(4,(alloc->obj_name, + "Client %s refresh timed-out, shutting down..", alloc->info)); alloc_shutdown(alloc); @@ -574,7 +574,7 @@ static void relay_timeout_cb(pj_timer_heap_t *heap, pj_timer_entry *e) } else if (e->id == TIMER_ID_DESTROY) { e->id = TIMER_ID_NONE; - PJ_LOG(4,(alloc->obj_name, "Client %s destroying..", + PJ_LOG(4,(alloc->obj_name, "Client %s destroying..", alloc->info)); destroy_allocation(alloc); @@ -600,10 +600,10 @@ static pj_status_t create_relay(pj_turn_srv *srv, pj_status_t status; pj_bzero(relay, sizeof(*relay)); - + relay->allocation = alloc; relay->tp.sock = PJ_INVALID_SOCKET; - + /* TODO: get the requested address family from somewhere */ af = alloc->transport->listener->addr.addr.sa_family; @@ -621,10 +621,10 @@ static pj_status_t create_relay(pj_turn_srv *srv, /* Lifetime and timeout */ relay->lifetime = req->lifetime; - pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay, + pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay, &relay_timeout_cb); resched_timeout(alloc); - + /* Transport type */ relay->hkey.tp_type = req->tp_type; @@ -676,7 +676,7 @@ static pj_status_t create_relay(pj_turn_srv *srv, pj_sockaddr_init(af, &bound_addr, NULL, port); - status = pj_sock_bind(relay->tp.sock, &bound_addr, + status = pj_sock_bind(relay->tp.sock, &bound_addr, pj_sockaddr_get_len(&bound_addr)); if (status == PJ_SUCCESS) break; @@ -684,7 +684,7 @@ static pj_status_t create_relay(pj_turn_srv *srv, if (status != PJ_SUCCESS) { /* Unable to allocate port */ - PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d", + PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d", status)); pj_sock_close(relay->tp.sock); relay->tp.sock = PJ_INVALID_SOCKET; @@ -695,14 +695,14 @@ static pj_status_t create_relay(pj_turn_srv *srv, namelen = sizeof(relay->hkey.addr); status = pj_sock_getsockname(relay->tp.sock, &relay->hkey.addr, &namelen); if (status != PJ_SUCCESS) { - PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d", + PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d", status)); pj_sock_close(relay->tp.sock); relay->tp.sock = PJ_INVALID_SOCKET; return status; } if (!pj_sockaddr_has_addr(&relay->hkey.addr)) { - pj_sockaddr_copy_addr(&relay->hkey.addr, + pj_sockaddr_copy_addr(&relay->hkey.addr, &alloc->transport->listener->addr); } if (!pj_sockaddr_has_addr(&relay->hkey.addr)) { @@ -718,7 +718,7 @@ static pj_status_t create_relay(pj_turn_srv *srv, status = pj_ioqueue_register_sock(pool, srv->core.ioqueue, relay->tp.sock, relay, &icb, &relay->tp.key); if (status != PJ_SUCCESS) { - PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d", + PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d", status)); pj_sock_close(relay->tp.sock); relay->tp.sock = PJ_INVALID_SOCKET; @@ -736,12 +736,12 @@ static pj_status_t create_relay(pj_turn_srv *srv, /* Create and send error response */ static void send_reply_err(pj_turn_allocation *alloc, const pj_stun_rx_data *rdata, - pj_bool_t cache, + pj_bool_t cache, int code, const char *errmsg) { pj_status_t status; - status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL, + status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL, cache, &alloc->hkey.clt_addr, pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr)); if (status != PJ_SUCCESS) { @@ -786,9 +786,9 @@ static void send_reply_ok(pj_turn_allocation *alloc, } } - status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE, - PJ_FALSE, &alloc->hkey.clt_addr, - pj_sockaddr_get_len(&alloc->hkey.clt_addr), + status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE, + PJ_FALSE, &alloc->hkey.clt_addr, + pj_sockaddr_get_len(&alloc->hkey.clt_addr), tdata); if (status != PJ_SUCCESS) { alloc_err(alloc, "Error sending STUN success response", status); @@ -806,7 +806,7 @@ static pj_turn_permission *create_permission(pj_turn_allocation *alloc, perm = PJ_POOL_ZALLOC_T(alloc->pool, pj_turn_permission); pj_memcpy(&perm->hkey.peer_addr, peer_addr, addr_len); - + perm->allocation = alloc; perm->channel = PJ_TURN_INVALID_CHANNEL; @@ -814,8 +814,8 @@ static pj_turn_permission *create_permission(pj_turn_allocation *alloc, perm->expiry.sec += PJ_TURN_PERM_TIMEOUT; /* Register to hash table (only the address part!) */ - pj_hash_set(alloc->pool, alloc->peer_table, - pj_sockaddr_get_addr(&perm->hkey.peer_addr), + pj_hash_set(alloc->pool, alloc->peer_table, + pj_sockaddr_get_addr(&perm->hkey.peer_addr), pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, perm); return perm; @@ -834,13 +834,13 @@ static pj_turn_permission *check_permission_expiry(pj_turn_permission *perm) } /* Remove from permission hash table */ - pj_hash_set(NULL, alloc->peer_table, - pj_sockaddr_get_addr(&perm->hkey.peer_addr), + pj_hash_set(NULL, alloc->peer_table, + pj_sockaddr_get_addr(&perm->hkey.peer_addr), pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, NULL); /* Remove from channel hash table, if assigned a channel number */ if (perm->channel != PJ_TURN_INVALID_CHANNEL) { - pj_hash_set(NULL, alloc->ch_table, &perm->channel, + pj_hash_set(NULL, alloc->ch_table, &perm->channel, sizeof(perm->channel), 0, NULL); } @@ -858,10 +858,10 @@ lookup_permission_by_addr(pj_turn_allocation *alloc, PJ_UNUSED_ARG(addr_len); /* Lookup in peer hash table */ - perm = (pj_turn_permission*) - pj_hash_get(alloc->peer_table, + perm = (pj_turn_permission*) + pj_hash_get(alloc->peer_table, pj_sockaddr_get_addr(peer_addr), - pj_sockaddr_get_addr_len(peer_addr), + pj_sockaddr_get_addr_len(peer_addr), NULL); return perm ? check_permission_expiry(perm) : NULL; } @@ -880,7 +880,7 @@ lookup_permission_by_chnum(pj_turn_allocation *alloc, return perm ? check_permission_expiry(perm) : NULL; } -/* Update permission because of data from client to peer. +/* Update permission because of data from client to peer. * Return PJ_TRUE is permission is found. */ static pj_bool_t refresh_permission(pj_turn_permission *perm) @@ -916,7 +916,7 @@ PJ_DEF(void) pj_turn_allocation_on_rx_client_pkt(pj_turn_allocation *alloc, * our stun_on_rx_request() or stun_on_rx_indication() * callbacks. * - * Note: currently it is necessary to specify the + * Note: currently it is necessary to specify the * PJ_STUN_NO_FINGERPRINT_CHECK otherwise the FINGERPRINT * attribute inside STUN Send Indication message will mess up * with fingerprint checking. @@ -929,7 +929,7 @@ PJ_DEF(void) pj_turn_allocation_on_rx_client_pkt(pj_turn_allocation *alloc, status = pj_stun_session_on_rx_pkt(alloc->sess, pkt->pkt, pkt->len, options, NULL, &parsed_len, - &pkt->src.clt_addr, + &pkt->src.clt_addr, pkt->src_addr_len); if (pkt->transport->listener->tp_type == PJ_TURN_TP_UDP) { @@ -962,7 +962,7 @@ PJ_DEF(void) pj_turn_allocation_on_rx_client_pkt(pj_turn_allocation *alloc, /* For UDP check the packet length */ if (alloc->transport->listener->tp_type == PJ_TURN_TP_UDP) { if (pkt->len < pj_ntohs(cd->length)+sizeof(*cd)) { - PJ_LOG(4,(alloc->obj_name, + PJ_LOG(4,(alloc->obj_name, "ChannelData from %s discarded: UDP size error", alloc->info)); goto on_return; @@ -975,7 +975,7 @@ PJ_DEF(void) pj_turn_allocation_on_rx_client_pkt(pj_turn_allocation *alloc, perm = lookup_permission_by_chnum(alloc, pj_ntohs(cd->ch_number)); if (!perm) { /* Discard */ - PJ_LOG(4,(alloc->obj_name, + PJ_LOG(4,(alloc->obj_name, "ChannelData from %s discarded: ch#0x%x not found", alloc->info, pj_ntohs(cd->ch_number))); goto on_return; @@ -998,7 +998,7 @@ on_return: /* - * Handle incoming packet from peer. This function is called by + * Handle incoming packet from peer. This function is called by * on_rx_from_peer(). */ static void handle_peer_pkt(pj_turn_allocation *alloc, @@ -1009,7 +1009,7 @@ static void handle_peer_pkt(pj_turn_allocation *alloc, pj_turn_permission *perm; /* Lookup permission */ - perm = lookup_permission_by_addr(alloc, src_addr, + perm = lookup_permission_by_addr(alloc, src_addr, pj_sockaddr_get_len(src_addr)); if (perm == NULL) { /* No permission, discard data */ @@ -1049,23 +1049,23 @@ static void handle_peer_pkt(pj_turn_allocation *alloc, pj_stun_tx_data *tdata; pj_status_t status; - status = pj_stun_session_create_ind(alloc->sess, + status = pj_stun_session_create_ind(alloc->sess, PJ_STUN_DATA_INDICATION, &tdata); if (status != PJ_SUCCESS) { alloc_err(alloc, "Error creating Data indication", status); return; } - pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, + pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, PJ_STUN_ATTR_XOR_PEER_ADDR, PJ_TRUE, src_addr, pj_sockaddr_get_len(src_addr)); pj_stun_msg_add_binary_attr(tdata->pool, tdata->msg, - PJ_STUN_ATTR_DATA, + PJ_STUN_ATTR_DATA, (const pj_uint8_t*)pkt, len); - pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE, - PJ_FALSE, &alloc->hkey.clt_addr, - pj_sockaddr_get_len(&alloc->hkey.clt_addr), + pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE, + PJ_FALSE, &alloc->hkey.clt_addr, + pj_sockaddr_get_len(&alloc->hkey.clt_addr), tdata); } } @@ -1073,8 +1073,8 @@ static void handle_peer_pkt(pj_turn_allocation *alloc, /* * ioqueue notification on RX packets from the relay socket. */ -static void on_rx_from_peer(pj_ioqueue_key_t *key, - pj_ioqueue_op_key_t *op_key, +static void on_rx_from_peer(pj_ioqueue_key_t *key, + pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_read) { pj_turn_relay_res *rel; @@ -1096,7 +1096,7 @@ static void on_rx_from_peer(pj_ioqueue_key_t *key, rel->tp.src_addr_len = sizeof(rel->tp.src_addr); status = pj_ioqueue_recvfrom(key, op_key, rel->tp.rx_pkt, &bytes_read, 0, - &rel->tp.src_addr, + &rel->tp.src_addr, &rel->tp.src_addr_len); if (status != PJ_EPENDING && status != PJ_SUCCESS) @@ -1156,14 +1156,14 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, /* Refuse to serve any request if we've been shutdown */ if (alloc->relay.lifetime == 0) { /* Reject with 437 if we're shutting down */ - send_reply_err(alloc, rdata, PJ_TRUE, + send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_ALLOCATION_MISMATCH, NULL); return PJ_SUCCESS; } if (msg->hdr.type == PJ_STUN_REFRESH_REQUEST) { - /* - * Handle REFRESH request + /* + * Handle REFRESH request */ pj_stun_lifetime_attr *lifetime; pj_stun_bandwidth_attr *bandwidth; @@ -1176,6 +1176,9 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, bandwidth = (pj_stun_bandwidth_attr*) pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_BANDWIDTH, 0); + /* TODO: process bandwidth */ + PJ_UNUSED_ARG(bandwidth); + if (lifetime && lifetime->value==0) { /* * This is deallocation request. @@ -1186,7 +1189,7 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, send_reply_ok(alloc, rdata); /* Shutdown allocation */ - PJ_LOG(4,(alloc->obj_name, + PJ_LOG(4,(alloc->obj_name, "Client %s request to dealloc, shutting down", alloc->info)); @@ -1196,7 +1199,7 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, /* * This is a refresh request. */ - + /* Update lifetime */ if (lifetime) { alloc->relay.lifetime = lifetime->value; @@ -1226,7 +1229,7 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_XOR_PEER_ADDR, 0); if (!ch_attr || !peer_attr) { - send_reply_err(alloc, rdata, PJ_TRUE, + send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL); return PJ_SUCCESS; } @@ -1234,14 +1237,14 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, /* Find permission with the channel number */ p1 = lookup_permission_by_chnum(alloc, PJ_STUN_GET_CH_NB(ch_attr->value)); - /* If permission is found, this is supposed to be a channel bind + /* If permission is found, this is supposed to be a channel bind * refresh. Make sure it's for the same peer. */ if (p1) { if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) { /* Address mismatch. Send 400 */ - send_reply_err(alloc, rdata, PJ_TRUE, - PJ_STUN_SC_BAD_REQUEST, + send_reply_err(alloc, rdata, PJ_TRUE, + PJ_STUN_SC_BAD_REQUEST, "Peer address mismatch"); return PJ_SUCCESS; } @@ -1262,7 +1265,7 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, p2 = lookup_permission_by_addr(alloc, &peer_attr->sockaddr, pj_sockaddr_get_len(&peer_attr->sockaddr)); if (p2 && p2->channel != PJ_TURN_INVALID_CHANNEL) { - send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, + send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, "Peer address already assigned a channel number"); return PJ_SUCCESS; } @@ -1280,7 +1283,7 @@ static pj_status_t stun_on_rx_request(pj_stun_session *sess, /* Register to hash table */ pj_assert(sizeof(p2->channel==2)); - pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel, + pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel, sizeof(p2->channel), 0, p2); /* Update */ @@ -1367,7 +1370,7 @@ static pj_status_t stun_on_rx_indication(pj_stun_session *sess, /* Relay the data to peer */ len = data_attr->length; - pj_sock_sendto(alloc->relay.tp.sock, data_attr->data, + pj_sock_sendto(alloc->relay.tp.sock, data_attr->data, &len, 0, &peer_attr->sockaddr, pj_sockaddr_get_len(&peer_attr->sockaddr)); diff --git a/pjnath/src/pjturn-srv/server.c b/pjnath/src/pjturn-srv/server.c index f53243d5..94dda29a 100644 --- a/pjnath/src/pjturn-srv/server.c +++ b/pjnath/src/pjturn-srv/server.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* +/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "turn.h" #include "auth.h" @@ -76,7 +76,7 @@ PJ_DEF(const char*) pj_turn_tp_type_name(int tp_type) /* * Create server. */ -PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, +PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, pj_turn_srv **p_srv) { pj_pool_t *pool; @@ -94,14 +94,14 @@ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, srv->core.pf = pf; srv->core.pool = pool; srv->core.tls_key = srv->core.tls_data = -1; - + /* Create ioqueue */ status = pj_ioqueue_create(pool, MAX_HANDLES, &srv->core.ioqueue); if (status != PJ_SUCCESS) goto on_error; /* Server mutex */ - status = pj_lock_create_recursive_mutex(pool, srv->obj_name, + status = pj_lock_create_recursive_mutex(pool, srv->obj_name, &srv->core.lock); if (status != PJ_SUCCESS) goto on_error; @@ -114,7 +114,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, status = pj_thread_local_alloc(&srv->core.tls_data); if (status != PJ_SUCCESS) goto on_error; - + /* Create timer heap */ status = pj_timer_heap_create(pool, MAX_TIMER, &srv->core.timer_heap); if (status != PJ_SUCCESS) @@ -125,7 +125,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, /* Array of listeners */ srv->core.listener = (pj_turn_listener**) - pj_pool_calloc(pool, MAX_LISTENERS, + pj_pool_calloc(pool, MAX_LISTENERS, sizeof(srv->core.listener[0])); /* Create hash tables */ @@ -169,19 +169,19 @@ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, /* Array of worker threads */ srv->core.thread_cnt = MAX_THREADS; srv->core.thread = (pj_thread_t**) - pj_pool_calloc(pool, srv->core.thread_cnt, + pj_pool_calloc(pool, srv->core.thread_cnt, sizeof(pj_thread_t*)); /* Start the worker threads */ for (i=0; icore.thread_cnt; ++i) { - status = pj_thread_create(pool, srv->obj_name, &server_thread_proc, + status = pj_thread_create(pool, srv->obj_name, &server_thread_proc, srv, 0, 0, &srv->core.thread[i]); if (status != PJ_SUCCESS) goto on_error; } /* We're done. Application should add listeners now */ - PJ_LOG(4,(srv->obj_name, "TURN server v%s is running", + PJ_LOG(4,(srv->obj_name, "TURN server v%s is running", pj_get_version())); *p_srv = srv; @@ -193,8 +193,8 @@ on_error: } -/* - * Handle timer and network events +/* + * Handle timer and network events */ static void srv_handle_events(pj_turn_srv *srv, const pj_time_val *max_timeout) { @@ -203,8 +203,8 @@ static void srv_handle_events(pj_turn_srv *srv, const pj_time_val *max_timeout) unsigned net_event_count = 0; int c; - /* Poll the timer. The timer heap has its own mutex for better - * granularity, so we don't need to lock the server. + /* Poll the timer. The timer heap has its own mutex for better + * granularity, so we don't need to lock the server. */ timeout.sec = timeout.msec = 0; c = pj_timer_heap_poll( srv->core.timer_heap, &timeout ); @@ -222,7 +222,7 @@ static void srv_handle_events(pj_turn_srv *srv, const pj_time_val *max_timeout) timeout = *max_timeout; } - /* Poll ioqueue. + /* Poll ioqueue. * Repeat polling the ioqueue while we have immediate events, because * timer heap may process more than one events, so if we only process * one network events at a time (such as when IOCP backend is used), @@ -292,7 +292,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_destroy(pj_turn_srv *srv) it = next; } } - + /* Destroy all listeners. */ for (i=0; icore.lis_cnt; ++i) { if (srv->core.listener[i]) { @@ -312,7 +312,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_destroy(pj_turn_srv *srv) srv->tables.alloc = NULL; srv->tables.res = NULL; } - + /* Destroy timer heap */ if (srv->core.timer_heap) { pj_timer_heap_destroy(srv->core.timer_heap); @@ -460,7 +460,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_unregister_allocation(pj_turn_srv *srv, } -/* Callback from our own STUN session whenever it needs to send +/* Callback from our own STUN session whenever it needs to send * outgoing STUN packet. */ static pj_status_t on_tx_stun_msg( pj_stun_session *sess, @@ -471,24 +471,24 @@ static pj_status_t on_tx_stun_msg( pj_stun_session *sess, unsigned addr_len) { pj_turn_transport *transport = (pj_turn_transport*) token; - + PJ_ASSERT_RETURN(transport!=NULL, PJ_EINVALIDOP); PJ_UNUSED_ARG(sess); - return transport->sendto(transport, pdu, pdu_size, 0, + return transport->sendto(transport, pdu, pdu_size, 0, dst_addr, addr_len); } /* Respond to STUN request */ -static pj_status_t stun_respond(pj_stun_session *sess, +static pj_status_t stun_respond(pj_stun_session *sess, pj_turn_transport *transport, const pj_stun_rx_data *rdata, - unsigned code, + unsigned code, const char *errmsg, - pj_bool_t cache, - const pj_sockaddr_t *dst_addr, + pj_bool_t cache, + const pj_sockaddr_t *dst_addr, unsigned addr_len) { pj_status_t status; @@ -496,14 +496,14 @@ static pj_status_t stun_respond(pj_stun_session *sess, pj_stun_tx_data *tdata; /* Create response */ - status = pj_stun_session_create_res(sess, rdata, code, + status = pj_stun_session_create_res(sess, rdata, code, (errmsg?pj_cstr(&reason,errmsg):NULL), &tdata); if (status != PJ_SUCCESS) return status; /* Send the response */ - return pj_stun_session_send_msg(sess, transport, cache, PJ_FALSE, + return pj_stun_session_send_msg(sess, transport, cache, PJ_FALSE, dst_addr, addr_len, tdata); } @@ -522,7 +522,6 @@ static pj_status_t on_rx_stun_request(pj_stun_session *sess, { pj_turn_transport *transport; const pj_stun_msg *msg = rdata->msg; - pj_turn_srv *srv; pj_turn_allocation *alloc; pj_status_t status; @@ -530,7 +529,6 @@ static pj_status_t on_rx_stun_request(pj_stun_session *sess, PJ_UNUSED_ARG(pdu_len); transport = (pj_turn_transport*) token; - srv = transport->listener->server; /* Respond any requests other than ALLOCATE with 437 response */ if (msg->hdr.type != PJ_STUN_ALLOCATE_REQUEST) { @@ -569,13 +567,13 @@ static void handle_binding_request(pj_turn_pkt *pkt, return; /* Create response */ - status = pj_stun_msg_create_response(pkt->pool, request, 0, NULL, + status = pj_stun_msg_create_response(pkt->pool, request, 0, NULL, &response); if (status != PJ_SUCCESS) return; /* Add XOR-MAPPED-ADDRESS */ - pj_stun_msg_add_sockaddr_attr(pkt->pool, response, + pj_stun_msg_add_sockaddr_attr(pkt->pool, response, PJ_STUN_ATTR_XOR_MAPPED_ADDR, PJ_TRUE, &pkt->src.clt_addr, @@ -587,7 +585,7 @@ static void handle_binding_request(pj_turn_pkt *pkt, return; /* Send response */ - pkt->transport->sendto(pkt->transport, pdu, len, 0, + pkt->transport->sendto(pkt->transport, pdu, len, 0, &pkt->src.clt_addr, pkt->src_addr_len); } @@ -598,7 +596,7 @@ static void handle_binding_request(pj_turn_pkt *pkt, * is found for the client address, or handed over to owned STUN session * if an allocation is not found. */ -PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, +PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, pj_turn_pkt *pkt) { pj_turn_allocation *alloc; @@ -638,7 +636,7 @@ PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, */ if ((*pkt->pkt != 0x00 && *pkt->pkt != 0x01) || pkt->len > 1600 || - (options & PJ_STUN_IS_DATAGRAM)) + (options & PJ_STUN_IS_DATAGRAM)) { char errmsg[PJ_ERR_MSG_SIZE]; char ip[PJ_INET6_ADDRSTRLEN+10]; @@ -646,7 +644,7 @@ PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, pkt->len = 0; pj_strerror(status, errmsg, sizeof(errmsg)); - PJ_LOG(5,(srv->obj_name, + PJ_LOG(5,(srv->obj_name, "Non-STUN packet from %s is dropped: %s", pj_sockaddr_print(&pkt->src.clt_addr, ip, sizeof(ip), 3), errmsg)); @@ -654,7 +652,7 @@ PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, return; } - /* Special handling for Binding Request. We won't give it to the + /* Special handling for Binding Request. We won't give it to the * STUN session since this request is not authenticated. */ if (pkt->pkt[1] == 1) { @@ -668,16 +666,16 @@ PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, */ options &= ~PJ_STUN_CHECK_PACKET; parsed_len = 0; - status = pj_stun_session_on_rx_pkt(srv->core.stun_sess, pkt->pkt, + status = pj_stun_session_on_rx_pkt(srv->core.stun_sess, pkt->pkt, pkt->len, options, pkt->transport, - &parsed_len, &pkt->src.clt_addr, + &parsed_len, &pkt->src.clt_addr, pkt->src_addr_len); if (status != PJ_SUCCESS) { char errmsg[PJ_ERR_MSG_SIZE]; char ip[PJ_INET6_ADDRSTRLEN+10]; pj_strerror(status, errmsg, sizeof(errmsg)); - PJ_LOG(5,(srv->obj_name, + PJ_LOG(5,(srv->obj_name, "Error processing STUN packet from %s: %s", pj_sockaddr_print(&pkt->src.clt_addr, ip, sizeof(ip), 3), errmsg)); -- cgit v1.2.3