From 72a1098e21f5b7d797655afe7ddb275969a192bd Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 28 Jun 2006 16:46:49 +0000 Subject: Major improvements in PJSIP to support TCP. The changes fall into these categories: (1) the TCP transport implementation itself (*.[hc]), (2) bug-fix in SIP transaction when using reliable transports, (3) support for TCP transport in PJSUA-LIB/PJSUA, and (4) changes in PJSIP-TEST to support TCP testing. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@563 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/pjsua_app.c | 74 +++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index caf6f8b7..5468d236 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -29,6 +29,8 @@ static struct app_config pjsua_config cfg; pjsua_logging_config log_cfg; pjsua_media_config media_cfg; + pj_bool_t no_tcp; + pj_bool_t no_udp; pjsua_transport_config udp_cfg; pjsua_transport_config rtp_cfg; @@ -95,7 +97,11 @@ static void usage(void) puts (" --next-account Add more account"); puts (""); puts ("Transport Options:"); - puts (" --local-port=port Set TCP/UDP port"); + puts (" --local-port=port Set TCP/UDP port. This implicitly enables both "); + puts (" TCP and UDP transports on the specified port, unless"); + puts (" if TCP or UDP is disabled."); + puts (" --no-tcp Disable TCP transport."); + puts (" --no-udp Disable UDP transport."); puts (" --outbound=url Set the URL of global outbound proxy server"); puts (" May be specified multiple times"); puts (" --use-stun1=host[:port]"); @@ -239,7 +245,7 @@ static pj_status_t parse_args(int argc, char *argv[], OPT_PLAY_FILE, OPT_RTP_PORT, OPT_ADD_CODEC, OPT_COMPLEXITY, OPT_QUALITY, OPT_PTIME, OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, - OPT_DURATION, + OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, }; struct pj_getopt_option long_options[] = { { "config-file",1, 0, OPT_CONFIG_FILE}, @@ -251,6 +257,8 @@ static pj_status_t parse_args(int argc, char *argv[], { "clock-rate", 1, 0, OPT_CLOCK_RATE}, { "null-audio", 0, 0, OPT_NULL_AUDIO}, { "local-port", 1, 0, OPT_LOCAL_PORT}, + { "no-tcp", 0, 0, OPT_NO_TCP}, + { "no-udp", 0, 0, OPT_NO_UDP}, { "proxy", 1, 0, OPT_PROXY}, { "outbound", 1, 0, OPT_OUTBOUND_PROXY}, { "registrar", 1, 0, OPT_REGISTRAR}, @@ -384,6 +392,24 @@ static pj_status_t parse_args(int argc, char *argv[], cfg->udp_cfg.port = (pj_uint16_t)lval; break; + case OPT_NO_UDP: /* no-udp */ + if (cfg->no_tcp) { + PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); + return PJ_EINVAL; + } + + cfg->no_udp = PJ_TRUE; + break; + + case OPT_NO_TCP: /* no-tcp */ + if (cfg->no_udp) { + PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); + return PJ_EINVAL; + } + + cfg->no_tcp = PJ_TRUE; + break; + case OPT_PROXY: /* proxy */ if (pjsua_verify_sip_url(pj_optarg) != 0) { PJ_LOG(1,(THIS_FILE, @@ -2046,7 +2072,7 @@ on_exit: pj_status_t app_init(int argc, char *argv[]) { - pjsua_transport_id transport_id; + pjsua_transport_id transport_id = -1; unsigned i; pj_status_t status; @@ -2096,16 +2122,40 @@ pj_status_t app_init(int argc, char *argv[]) app_config.wav_port = pjsua_player_get_conf_port(app_config.wav_id); } - /* Add UDP transport */ - status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, - &app_config.udp_cfg, - &transport_id); - if (status != PJ_SUCCESS) - goto on_error; - /* Add local account */ - pjsua_acc_add_local(transport_id, PJ_TRUE, ¤t_acc); - pjsua_acc_set_online_status(current_acc, PJ_TRUE); + /* Add TCP transport unless it's disabled */ + if (!app_config.no_tcp) { + status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, + &app_config.udp_cfg, + &transport_id); + if (status != PJ_SUCCESS) + goto on_error; + + /* Add local account */ + pjsua_acc_add_local(transport_id, PJ_TRUE, ¤t_acc); + pjsua_acc_set_online_status(current_acc, PJ_TRUE); + + } + + + /* Add UDP transport unless it's disabled. */ + if (!app_config.no_udp) { + status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, + &app_config.udp_cfg, + &transport_id); + if (status != PJ_SUCCESS) + goto on_error; + + /* Add local account */ + pjsua_acc_add_local(transport_id, PJ_TRUE, ¤t_acc); + pjsua_acc_set_online_status(current_acc, PJ_TRUE); + } + + if (transport_id == -1) { + PJ_LOG(3,(THIS_FILE, "Error: no transport is configured")); + status = -1; + goto on_error; + } /* Add accounts */ -- cgit v1.2.3