Ignore:
Timestamp:
Jun 6, 2006 6:40:40 PM (18 years ago)
Author:
bennylp
Message:

Another huge chunks of modifications in PJSUA API, too many things to mention!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r487 r492  
    5656    cfg->udp_port = 5060; 
    5757    cfg->start_rtp_port = 4000; 
     58    cfg->msg_logging = PJ_TRUE; 
    5859    cfg->max_calls = 4; 
    5960    cfg->conf_ports = 0; 
     
    722723    unsigned j; 
    723724 
     725    pj_memcpy(dst_acc, src_acc, sizeof(pjsua_acc_config)); 
     726 
    724727    pj_strdup_with_null(pool, &dst_acc->id, &src_acc->id); 
    725728    pj_strdup_with_null(pool, &dst_acc->reg_uri, &src_acc->reg_uri); 
     
    743746 * Copy configuration. 
    744747 */ 
    745 static void copy_config(pj_pool_t *pool, pjsua_config *dst,  
     748void pjsua_copy_config( pj_pool_t *pool, pjsua_config *dst,  
    746749                        const pjsua_config *src) 
    747750{ 
     
    762765 
    763766    pj_strdup_with_null(pool, &dst->outbound_proxy, &src->outbound_proxy); 
    764     pj_strdup_with_null(pool, &dst->uri_to_call, &src->uri_to_call); 
     767    //pj_strdup_with_null(pool, &dst->uri_to_call, &src->uri_to_call); 
    765768 
    766769    for (i=0; i<src->acc_cnt; ++i) { 
     
    814817    } 
    815818 
     819    /* Enable SIP message logging */ 
     820    if (pjsua.config.msg_logging) 
     821        pjsip_endpt_register_module(pjsua.endpt, &pjsua_msg_logger); 
     822 
    816823    return PJ_SUCCESS; 
    817824} 
     
    864871 
    865872    /* Copy configuration */ 
    866     copy_config(pjsua.pool, &pjsua.config, cfg); 
     873    pjsua_copy_config(pjsua.pool, &pjsua.config, cfg); 
    867874 
    868875    /* Copy callback */ 
     
    10271034 * Find account for incoming request. 
    10281035 */ 
    1029 int pjsua_find_account_for_incoming(pjsip_rx_data *rdata) 
     1036PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata) 
    10301037{ 
    10311038    pjsip_uri *uri; 
     
    10351042    uri = rdata->msg_info.to->uri; 
    10361043 
    1037     /* Just return last account if To URI is not SIP: */ 
     1044    /* Just return default account if To URI is not SIP: */ 
    10381045    if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&  
    10391046        !PJSIP_URI_SCHEME_IS_SIPS(uri))  
    10401047    { 
    1041         return pjsua.config.acc_cnt; 
     1048        return pjsua.default_acc; 
    10421049    } 
    10431050 
     
    10691076    } 
    10701077 
    1071     /* Still no match, just return last account */ 
    1072     return pjsua.config.acc_cnt; 
     1078    /* Still no match, use default account */ 
     1079    return pjsua.default_acc; 
    10731080} 
    10741081 
     
    10771084 * Find account for outgoing request. 
    10781085 */ 
    1079 int pjsua_find_account_for_outgoing(const pj_str_t *url) 
    1080 { 
    1081     PJ_UNUSED_ARG(url); 
    1082  
    1083     /* Just use account #0 */ 
    1084     return 0; 
     1086PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *str_url) 
     1087{ 
     1088    pj_str_t tmp; 
     1089    pjsip_uri *uri; 
     1090    pjsip_sip_uri *sip_uri; 
     1091    unsigned i; 
     1092 
     1093    pj_strdup_with_null(pjsua.pool, &tmp, str_url); 
     1094 
     1095    uri = pjsip_parse_uri(pjsua.pool, tmp.ptr, tmp.slen, 0); 
     1096    if (!uri) 
     1097        return pjsua.config.acc_cnt-1; 
     1098 
     1099    if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&  
     1100        !PJSIP_URI_SCHEME_IS_SIPS(uri))  
     1101    { 
     1102        /* Return the first account with proxy */ 
     1103        for (i=0; i<PJ_ARRAY_SIZE(pjsua.acc); ++i) { 
     1104            if (!pjsua.acc[i].valid) 
     1105                continue; 
     1106            if (pjsua.config.acc_config[i].proxy.slen) 
     1107                break; 
     1108        } 
     1109 
     1110        if (i != PJ_ARRAY_SIZE(pjsua.acc)) 
     1111            return i; 
     1112 
     1113        /* Not found, use default account */ 
     1114        return pjsua.default_acc; 
     1115    } 
     1116 
     1117    sip_uri = pjsip_uri_get_uri(uri); 
     1118 
     1119    /* Find matching domain */ 
     1120    for (i=0; i<PJ_ARRAY_SIZE(pjsua.acc); ++i) { 
     1121        if (!pjsua.acc[i].valid) 
     1122            continue; 
     1123        if (pj_stricmp(&pjsua.acc[i].host_part, &sip_uri->host)==0) 
     1124            break; 
     1125    } 
     1126 
     1127    if (i != PJ_ARRAY_SIZE(pjsua.acc)) 
     1128        return i; 
     1129 
     1130    /* Just use default account */ 
     1131    return pjsua.default_acc; 
    10851132} 
    10861133 
     
    11931240    } 
    11941241 
     1242    /* Mark account as valid */ 
     1243    pjsua.acc[acc_index].valid = PJ_TRUE; 
     1244 
     1245 
    11951246    return PJ_SUCCESS; 
    11961247} 
     
    12001251 */ 
    12011252PJ_DEF(pj_status_t) pjsua_acc_add( const pjsua_acc_config *cfg, 
    1202                                    int *acc_index) 
    1203 { 
     1253                                   pjsua_acc_id *acc_index) 
     1254{ 
     1255    unsigned index; 
    12041256    pj_status_t status; 
    12051257 
    1206     PJ_ASSERT_RETURN(pjsua.config.acc_cnt<PJ_ARRAY_SIZE(pjsua.config.acc_config), 
     1258    PJ_ASSERT_RETURN(pjsua.config.acc_cnt <  
     1259                        PJ_ARRAY_SIZE(pjsua.config.acc_config), 
    12071260                     PJ_ETOOMANY); 
    12081261 
    1209     copy_acc_config(pjsua.pool, &pjsua.config.acc_config[pjsua.config.acc_cnt], cfg); 
     1262    /* Find empty account index. */ 
     1263    for (index=0; index < PJ_ARRAY_SIZE(pjsua.acc); ++index) { 
     1264        if (pjsua.acc[index].valid == PJ_FALSE) 
     1265            break; 
     1266    } 
     1267 
     1268    /* Expect to find a slot */ 
     1269    PJ_ASSERT_RETURN(index < PJ_ARRAY_SIZE(pjsua.acc), PJ_EBUG); 
     1270 
     1271    copy_acc_config(pjsua.pool, &pjsua.config.acc_config[index], cfg); 
    12101272     
    1211     status = init_acc(pjsua.config.acc_cnt); 
     1273    status = init_acc(index); 
    12121274    if (status != PJ_SUCCESS) { 
    12131275        pjsua_perror(THIS_FILE, "Error adding account", status); 
     
    12161278 
    12171279    if (acc_index) 
    1218         *acc_index = pjsua.config.acc_cnt; 
     1280        *acc_index = index; 
    12191281 
    12201282    pjsua.config.acc_cnt++; 
     
    12231285} 
    12241286 
     1287 
     1288/* 
     1289 * Delete account. 
     1290 */ 
     1291PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_index) 
     1292{ 
     1293    PJ_ASSERT_RETURN(acc_index < (int)pjsua.config.acc_cnt,  
     1294                     PJ_EINVAL); 
     1295    PJ_ASSERT_RETURN(pjsua.acc[acc_index].valid, PJ_EINVALIDOP); 
     1296 
     1297    /* Delete registration */ 
     1298    if (pjsua.acc[acc_index].regc != NULL)  
     1299        pjsua_acc_set_registration(acc_index, PJ_FALSE); 
     1300 
     1301    /* Invalidate */ 
     1302    pjsua.acc[acc_index].valid = PJ_FALSE; 
     1303 
     1304    return PJ_SUCCESS; 
     1305} 
    12251306 
    12261307 
     
    12671348 
    12681349        tmp.ptr = buf; 
    1269         tmp.slen = pj_ansi_sprintf(tmp.ptr, "<sip:%s:%d>",  
     1350        tmp.slen = pj_ansi_sprintf(tmp.ptr, "Local <sip:%s:%d>",  
    12701351                                   pjsua.config.sip_host.ptr, 
    12711352                                   pjsua.config.sip_port); 
     
    12831364    } 
    12841365     
     1366 
     1367    /* Add another account as the last one.  
     1368     * This account corresponds to local endpoint, and is user-less. 
     1369     * This is also the default account. 
     1370     */ 
     1371    if (pjsua.config.acc_cnt < PJ_ARRAY_SIZE(pjsua.config.acc_config)) { 
     1372        pjsua.default_acc = pjsua.config.acc_cnt; 
     1373        pjsua.acc[pjsua.default_acc].auto_gen = 1; 
     1374        pjsua.config.acc_cnt++; 
     1375    } 
     1376 
    12851377 
    12861378    /* Initialize accounts: */ 
     
    12921384        } 
    12931385    } 
    1294  
    12951386 
    12961387 
     
    13341425 
    13351426 
     1427    /* Refresh presence */ 
     1428    pjsua_pres_refresh(); 
     1429 
    13361430 
    13371431    PJ_LOG(3,(THIS_FILE, "PJSUA version %s started", PJ_VERSION)); 
     
    13691463 
    13701464/** 
    1371  * Enum all conference ports. 
    1372  */ 
    1373 PJ_DEF(pj_status_t) pjsua_conf_enum_ports( unsigned *count, 
    1374                                            pjmedia_conf_port_info info[]) 
    1375 { 
    1376     return pjmedia_conf_get_ports_info(pjsua.mconf, count, info); 
    1377 } 
    1378  
    1379  
     1465 * Enum all conference port ID. 
     1466 */ 
     1467PJ_DEF(pj_status_t) pjsua_conf_enum_port_ids( pjsua_conf_port_id id[], 
     1468                                              unsigned *count) 
     1469{ 
     1470    return pjmedia_conf_enum_ports( pjsua.mconf, (unsigned*)id, count); 
     1471} 
     1472 
     1473 
     1474 
     1475/** 
     1476 * Get information about the specified conference port 
     1477 */ 
     1478PJ_DEF(pj_status_t) pjsua_conf_get_port_info( pjsua_conf_port_id id, 
     1479                                              pjsua_conf_port_info *info) 
     1480{ 
     1481    pjmedia_conf_port_info cinfo; 
     1482    unsigned i, count; 
     1483    pj_status_t status; 
     1484 
     1485    status = pjmedia_conf_get_port_info( pjsua.mconf, id, &cinfo); 
     1486    if (status != PJ_SUCCESS) 
     1487        return status; 
     1488 
     1489    pj_memset(info, 0, sizeof(*info)); 
     1490    info->slot_id = id; 
     1491    info->name = cinfo.name; 
     1492    info->clock_rate = cinfo.clock_rate; 
     1493    info->channel_count = cinfo.channel_count; 
     1494    info->samples_per_frame = cinfo.samples_per_frame; 
     1495    info->bits_per_sample = cinfo.bits_per_sample; 
     1496 
     1497    /* Build array of listeners */ 
     1498    count = pjsua.config.conf_ports; 
     1499    for (i=0; i<count; ++i) { 
     1500        if (cinfo.listener[i]) { 
     1501            info->listeners[info->listener_cnt++] = i; 
     1502        } 
     1503    } 
     1504 
     1505    return PJ_SUCCESS; 
     1506} 
    13801507 
    13811508 
     
    13831510 * Connect conference port. 
    13841511 */ 
    1385 PJ_DEF(pj_status_t) pjsua_conf_connect( unsigned src_port, 
    1386                                         unsigned dst_port) 
     1512PJ_DEF(pj_status_t) pjsua_conf_connect( pjsua_conf_port_id src_port, 
     1513                                        pjsua_conf_port_id dst_port) 
    13871514{ 
    13881515    return pjmedia_conf_connect_port(pjsua.mconf, src_port, dst_port, 0); 
     
    13931520 * Connect conference port connection. 
    13941521 */ 
    1395 PJ_DEF(pj_status_t) pjsua_conf_disconnect( unsigned src_port, 
    1396                                            unsigned dst_port) 
     1522PJ_DEF(pj_status_t) pjsua_conf_disconnect( pjsua_conf_port_id src_port, 
     1523                                           pjsua_conf_port_id dst_port) 
    13971524{ 
    13981525    return pjmedia_conf_disconnect_port(pjsua.mconf, src_port, dst_port); 
     
    14351562    pjsua.player[pjsua.player_cnt].slot = slot; 
    14361563 
    1437     if (*id) 
     1564    if (id) 
    14381565        *id = pjsua.player_cnt; 
    14391566 
     
    14471574 * Get conference port associated with player. 
    14481575 */ 
    1449 PJ_DEF(int) pjsua_player_get_conf_port(pjsua_player_id id) 
     1576PJ_DEF(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id) 
    14501577{ 
    14511578    PJ_ASSERT_RETURN(id>=0 && id < PJ_ARRAY_SIZE(pjsua.player), PJ_EINVAL); 
     
    15311658 * Get conference port associated with recorder. 
    15321659 */ 
    1533 PJ_DEF(int) pjsua_recorder_get_conf_port(pjsua_recorder_id id) 
     1660PJ_DEF(pjsua_conf_port_id) pjsua_recorder_get_conf_port(pjsua_recorder_id id) 
    15341661{ 
    15351662    PJ_ASSERT_RETURN(id>=0 && id < PJ_ARRAY_SIZE(pjsua.recorder), PJ_EINVAL); 
Note: See TracChangeset for help on using the changeset viewer.