Ignore:
Timestamp:
Sep 20, 2012 6:00:23 AM (12 years ago)
Author:
bennylp
Message:

Fixed #1585: IPv6 support for SIP TCP and TLS transports and PJSUA-LIB v2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r4218 r4262  
    171171static void stereo_demo(); 
    172172#endif 
    173 static pj_status_t create_ipv6_media_transports(void); 
    174173pj_status_t app_destroy(void); 
    175174 
     
    877876 
    878877        case OPT_NO_UDP: /* no-udp */ 
    879             if (cfg->no_tcp) { 
    880               PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); 
     878            if (cfg->no_tcp && !cfg->use_tls) { 
     879              PJ_LOG(1,(THIS_FILE,"Error: cannot disable both TCP and UDP")); 
    881880              return PJ_EINVAL; 
    882881            } 
     
    890889 
    891890        case OPT_NO_TCP: /* no-tcp */ 
    892             if (cfg->no_udp) { 
    893               PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); 
     891            if (cfg->no_udp && !cfg->use_tls) { 
     892              PJ_LOG(1,(THIS_FILE,"Error: cannot disable both TCP and UDP")); 
    894893              return PJ_EINVAL; 
    895894            } 
     
    59085907            pjsua_acc_get_config(aid, &acc_cfg); 
    59095908            app_config_init_video(&acc_cfg); 
     5909            if (app_config.ipv6) 
     5910                acc_cfg.ipv6_media_use = PJSUA_IPV6_ENABLED; 
    59105911            pjsua_acc_modify(aid, &acc_cfg); 
    59115912        } 
     
    59445945        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
    59455946 
     5947    } 
     5948 
     5949    /* Add TCP IPv6 transport unless it's disabled. */ 
     5950    if (!app_config.no_tcp && app_config.ipv6) { 
     5951        pjsua_acc_id aid; 
     5952        pjsip_transport_type_e type = PJSIP_TRANSPORT_TCP6; 
     5953 
     5954        tcp_cfg.port += 10; 
     5955 
     5956        status = pjsua_transport_create(type, 
     5957                                        &tcp_cfg, 
     5958                                        &transport_id); 
     5959        if (status != PJ_SUCCESS) 
     5960            goto on_error; 
     5961 
     5962        /* Add local account */ 
     5963        pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); 
     5964        if (PJMEDIA_HAS_VIDEO) { 
     5965            pjsua_acc_config acc_cfg; 
     5966            pjsua_acc_get_config(aid, &acc_cfg); 
     5967            app_config_init_video(&acc_cfg); 
     5968            if (app_config.ipv6) 
     5969                acc_cfg.ipv6_media_use = PJSUA_IPV6_ENABLED; 
     5970            pjsua_acc_modify(aid, &acc_cfg); 
     5971        } 
     5972        //pjsua_acc_set_transport(aid, transport_id); 
     5973        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
    59465974    } 
    59475975 
     
    59776005        pjsua_acc_set_online_status(acc_id, PJ_TRUE); 
    59786006    } 
     6007 
     6008    /* Add TLS IPv6 transport unless it's disabled. */ 
     6009    if (app_config.use_tls && app_config.ipv6) { 
     6010        pjsua_acc_id aid; 
     6011        pjsip_transport_type_e type = PJSIP_TRANSPORT_TLS6; 
     6012 
     6013        tcp_cfg.port += 10; 
     6014 
     6015        status = pjsua_transport_create(type, 
     6016                                        &tcp_cfg, 
     6017                                        &transport_id); 
     6018        if (status != PJ_SUCCESS) 
     6019            goto on_error; 
     6020 
     6021        /* Add local account */ 
     6022        pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); 
     6023        if (PJMEDIA_HAS_VIDEO) { 
     6024            pjsua_acc_config acc_cfg; 
     6025            pjsua_acc_get_config(aid, &acc_cfg); 
     6026            app_config_init_video(&acc_cfg); 
     6027            if (app_config.ipv6) 
     6028                acc_cfg.ipv6_media_use = PJSUA_IPV6_ENABLED; 
     6029            pjsua_acc_modify(aid, &acc_cfg); 
     6030        } 
     6031        //pjsua_acc_set_transport(aid, transport_id); 
     6032        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
     6033    } 
     6034 
    59796035#endif 
    59806036 
     
    60266082#endif 
    60276083    } 
    6028  
    6029     /* Add RTP transports */ 
    6030     if (app_config.ipv6) 
    6031         status = create_ipv6_media_transports(); 
    6032   #if DISABLED_FOR_TICKET_1185 
    6033     else 
    6034         status = pjsua_media_transports_create(&app_config.rtp_cfg); 
    6035   #endif 
    6036     if (status != PJ_SUCCESS) 
    6037         goto on_error; 
    60386084 
    60396085    /* Use null sound device? */ 
     
    62526298#endif 
    62536299 
    6254 static pj_status_t create_ipv6_media_transports(void) 
    6255 { 
    6256     pjsua_media_transport tp[PJSUA_MAX_CALLS]; 
    6257     pj_status_t status; 
    6258     int port = app_config.rtp_cfg.port; 
    6259     unsigned i; 
    6260  
    6261     for (i=0; i<app_config.cfg.max_calls; ++i) { 
    6262         enum { MAX_RETRY = 10 }; 
    6263         pj_sock_t sock[2]; 
    6264         pjmedia_sock_info si; 
    6265         unsigned j; 
    6266  
    6267         /* Get rid of uninitialized var compiler warning with MSVC */ 
    6268         status = PJ_SUCCESS; 
    6269  
    6270         for (j=0; j<MAX_RETRY; ++j) { 
    6271             unsigned k; 
    6272  
    6273             for (k=0; k<2; ++k) { 
    6274                 pj_sockaddr bound_addr; 
    6275  
    6276                 status = pj_sock_socket(pj_AF_INET6(), pj_SOCK_DGRAM(), 0, &sock[k]); 
    6277                 if (status != PJ_SUCCESS) 
    6278                     break; 
    6279  
    6280                 status = pj_sockaddr_init(pj_AF_INET6(), &bound_addr, 
    6281                                           &app_config.rtp_cfg.bound_addr,  
    6282                                           (unsigned short)(port+k)); 
    6283                 if (status != PJ_SUCCESS) 
    6284                     break; 
    6285  
    6286                 status = pj_sock_bind(sock[k], &bound_addr,  
    6287                                       pj_sockaddr_get_len(&bound_addr)); 
    6288                 if (status != PJ_SUCCESS) 
    6289                     break; 
    6290             } 
    6291             if (status != PJ_SUCCESS) { 
    6292                 if (k==1) 
    6293                     pj_sock_close(sock[0]); 
    6294  
    6295                 if (port != 0) 
    6296                     port += 10; 
    6297                 else 
    6298                     break; 
    6299  
    6300                 continue; 
    6301             } 
    6302  
    6303             pj_bzero(&si, sizeof(si)); 
    6304             si.rtp_sock = sock[0]; 
    6305             si.rtcp_sock = sock[1]; 
    6306          
    6307             pj_sockaddr_init(pj_AF_INET6(), &si.rtp_addr_name,  
    6308                              &app_config.rtp_cfg.public_addr,  
    6309                              (unsigned short)(port)); 
    6310             pj_sockaddr_init(pj_AF_INET6(), &si.rtcp_addr_name,  
    6311                              &app_config.rtp_cfg.public_addr,  
    6312                              (unsigned short)(port+1)); 
    6313  
    6314             status = pjmedia_transport_udp_attach(pjsua_get_pjmedia_endpt(), 
    6315                                                   NULL, 
    6316                                                   &si, 
    6317                                                   0, 
    6318                                                   &tp[i].transport); 
    6319             if (port != 0) 
    6320                 port += 10; 
    6321             else 
    6322                 break; 
    6323  
    6324             if (status == PJ_SUCCESS) 
    6325                 break; 
    6326         } 
    6327  
    6328         if (status != PJ_SUCCESS) { 
    6329             pjsua_perror(THIS_FILE, "Error creating IPv6 UDP media transport",  
    6330                          status); 
    6331             for (j=0; j<i; ++j) { 
    6332                 pjmedia_transport_close(tp[j].transport); 
    6333             } 
    6334             return status; 
    6335         } 
    6336     } 
    6337  
    6338 #if DISABLED_FOR_TICKET_1185 
    6339     return pjsua_media_transports_attach(tp, i, PJ_TRUE); 
    6340 #else 
    6341     return PJ_ENOTSUP; 
    6342 #endif 
    6343 } 
    6344  
Note: See TracChangeset for help on using the changeset viewer.