Changeset 5152 for pjproject


Ignore:
Timestamp:
Aug 7, 2015 9:00:52 AM (6 years ago)
Author:
ming
Message:

Fixed #1878: Compile time option for TCP/TLS transport to not create a listener

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_config.h

    r5090 r5152  
    671671 
    672672/** 
     673 * Specify whether TCP transport should skip creating the listener. 
     674 * Not having a listener means that application will not be able to 
     675 * function in server mode and accept incoming connections. 
     676 * 
     677 * When enabling this setting, if you use PJSUA, it is recommended to set  
     678 * pjsua_acc_config.contact_use_src_port to PJ_TRUE. 
     679 * Warning: If contact_use_src_port is disabled or failed (because it's 
     680 * unsupported in some platforms or automatically turned off due to 
     681 * DNS server resolution), Contact header will be generated from 
     682 * pj_getipinterface()/pj_gethostip(), but the address will not be 
     683 * able to accept connections.  
     684 * 
     685 * Default is FALSE (listener will be created). 
     686 */ 
     687#ifndef PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER 
     688#   define PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER 0 
     689#endif 
     690 
     691 
     692/** 
     693 * Specify whether TLS transport should skip creating the listener. 
     694 * Not having a listener means that application will not be able to 
     695 * function in server mode and accept incoming connections. 
     696 * 
     697 * When enabling this setting, if you use PJSUA, it is recommended to set  
     698 * pjsua_acc_config.contact_use_src_port to PJ_TRUE. 
     699 * Warning: If contact_use_src_port is disabled or failed (because it's 
     700 * unsupported in some platforms or automatically turned off due to 
     701 * DNS server resolution), Contact header will be generated from 
     702 * pj_getipinterface()/pj_gethostip(), but the address will not be 
     703 * able to accept connections. 
     704 * 
     705 * Default is FALSE (listener will be created). 
     706 */ 
     707#ifndef PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER 
     708#   define PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER 0 
     709#endif 
     710 
     711 
     712/** 
    673713 * Set the interval to send keep-alive packet for TCP transports. 
    674714 * If the value is zero, keep-alive will be disabled for TCP. 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c

    r5105 r5152  
    259259    pj_sockaddr *listener_addr; 
    260260    int addr_len; 
     261    pj_bool_t has_listener = PJ_FALSE; 
    261262    pj_status_t status; 
    262263 
     
    279280    } 
    280281 
    281     pool = pjsip_endpt_create_pool(endpt, "tcplis", POOL_LIS_INIT,  
     282    pool = pjsip_endpt_create_pool(endpt, "tcptp", POOL_LIS_INIT,  
    282283                                   POOL_LIS_INC); 
    283284    PJ_ASSERT_RETURN(pool, PJ_ENOMEM); 
     
    298299              sizeof(cfg->sockopt_params)); 
    299300 
    300     pj_ansi_strcpy(listener->factory.obj_name, "tcplis"); 
     301    pj_ansi_strcpy(listener->factory.obj_name, "tcptp"); 
    301302    if (listener->factory.type==PJSIP_TRANSPORT_TCP6) 
    302303        pj_ansi_strcat(listener->factory.obj_name, "6"); 
     
    307308        goto on_error; 
    308309 
     310#if !(defined(PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     311      PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER != 0) 
    309312 
    310313    /* Create socket */ 
     
    333336        status = pj_sock_setsockopt_params(sock, &cfg->sockopt_params); 
    334337 
     338#else 
     339    PJ_UNUSED_ARG(addr_len); 
     340#endif 
     341 
    335342    /* Bind address may be different than factory.local_addr because 
    336343     * factory.local_addr will be resolved below. 
     
    341348    listener_addr = &listener->factory.local_addr; 
    342349    pj_sockaddr_cp(listener_addr, &cfg->bind_addr); 
     350 
     351#if !(defined(PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     352      PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER != 0) 
    343353 
    344354    status = pj_sock_bind(sock, listener_addr,  
     
    352362    if (status != PJ_SUCCESS) 
    353363        goto on_error; 
     364 
     365#endif 
    354366 
    355367    /* If published host/IP is specified, then use that address as the 
     
    393405    pj_ansi_snprintf(listener->factory.obj_name,  
    394406                     sizeof(listener->factory.obj_name), 
    395                      "tcplis:%d",  listener->factory.addr_name.port); 
    396  
     407                     "tcptp:%d",  listener->factory.addr_name.port); 
     408 
     409 
     410#if !(defined(PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     411      PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER != 0) 
    397412 
    398413    /* Start listening to the address */ 
     
    409424        asock_cfg.async_cnt = cfg->async_cnt; 
    410425 
     426#endif 
     427 
    411428    /* Create group lock */ 
    412429    status = pj_grp_lock_create(pool, NULL, &listener->grp_lock); 
     
    422439    pj_bzero(&listener_cb, sizeof(listener_cb)); 
    423440    listener_cb.on_accept_complete = &on_accept_complete; 
     441 
     442#if !(defined(PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     443      PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER != 0) 
     444 
    424445    status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), &asock_cfg, 
    425446                                  pjsip_endpt_get_ioqueue(endpt),  
    426447                                  &listener_cb, listener, 
    427448                                  &listener->asock); 
     449 
     450#endif 
    428451 
    429452    /* Register to transport manager */ 
     
    440463    } 
    441464 
     465#if !(defined(PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     466      PJSIP_TCP_TRANSPORT_DONT_CREATE_LISTENER != 0) 
     467 
    442468    /* Start pending accept() operations */ 
    443469    status = pj_activesock_start_accept(listener->asock, pool); 
    444470    if (status != PJ_SUCCESS) 
    445471        goto on_error; 
    446  
    447     PJ_LOG(4,(listener->factory.obj_name,  
    448              "SIP TCP listener ready for incoming connections at %.*s:%d", 
    449              (int)listener->factory.addr_name.host.slen, 
    450              listener->factory.addr_name.host.ptr, 
    451              listener->factory.addr_name.port)); 
     472         
     473    has_listener = PJ_TRUE; 
     474 
     475#endif 
     476 
     477    if (has_listener) { 
     478        PJ_LOG(4,(listener->factory.obj_name,  
     479                 "SIP TCP listener ready for incoming connections at %.*s:%d", 
     480                 (int)listener->factory.addr_name.host.slen, 
     481                 listener->factory.addr_name.host.ptr, 
     482                 listener->factory.addr_name.port)); 
     483    } else { 
     484        PJ_LOG(4,(listener->factory.obj_name, "SIP TCP is ready " 
     485                  "(client only)"));     
     486    } 
    452487 
    453488    /* Return the pointer to user */ 
     
    519554        pj_pool_t *pool = listener->factory.pool; 
    520555 
    521         PJ_LOG(4,(listener->factory.obj_name,  "SIP TCP listener destroyed")); 
     556        PJ_LOG(4,(listener->factory.obj_name,  "SIP TCP transport destroyed")); 
    522557 
    523558        listener->factory.pool = NULL; 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c

    r5105 r5152  
    340340    } 
    341341 
    342     pool = pjsip_endpt_create_pool(endpt, "tlslis", POOL_LIS_INIT,  
     342    pool = pjsip_endpt_create_pool(endpt, "tlstp", POOL_LIS_INIT,  
    343343                                   POOL_LIS_INC); 
    344344    PJ_ASSERT_RETURN(pool, PJ_ENOMEM); 
     
    355355        pjsip_transport_get_flag_from_type(listener->factory.type); 
    356356 
    357     pj_ansi_strcpy(listener->factory.obj_name, "tlslis"); 
     357    pj_ansi_strcpy(listener->factory.obj_name, "tlstp"); 
    358358    if (is_ipv6) 
    359359        pj_ansi_strcat(listener->factory.obj_name, "6"); 
     
    420420                            &lis_on_destroy); 
    421421 
     422#if !(defined(PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     423      PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER != 0) 
     424 
    422425    ssock_param.grp_lock = listener->grp_lock; 
    423426 
     
    426429    if (status != PJ_SUCCESS) 
    427430        goto on_error; 
     431 
     432#endif 
    428433 
    429434    /* Bind address may be different than factory.local_addr because 
     
    439444        pj_sockaddr_init(af, &listener->bound_addr, NULL, 0); 
    440445    } 
     446 
     447#if !(defined(PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER) && \ 
     448      PJSIP_TLS_TRANSPORT_DONT_CREATE_LISTENER != 0) 
    441449 
    442450    /* Check if certificate/CA list for SSL socket is set */ 
     
    481489    } 
    482490 
     491#endif 
     492 
    483493    /* If published host/IP is specified, then use that address as the 
    484494     * listener advertised address. 
     
    519529    pj_ansi_snprintf(listener->factory.obj_name,  
    520530                     sizeof(listener->factory.obj_name), 
    521                      "tlslis:%d",  listener->factory.addr_name.port); 
     531                     "tlstp:%d",  listener->factory.addr_name.port); 
    522532 
    523533    /* Register to transport manager */ 
     
    570580        pj_pool_t *pool = listener->factory.pool; 
    571581 
    572         PJ_LOG(4,(listener->factory.obj_name,  "SIP TLS listener destroyed")); 
     582        PJ_LOG(4,(listener->factory.obj_name,  "SIP TLS transport destroyed")); 
    573583 
    574584        listener->factory.pool = NULL; 
Note: See TracChangeset for help on using the changeset viewer.