Changeset 4729 for pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.c
- Timestamp:
- Feb 4, 2014 1:13:02 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_config.c
r4714 r4729 1 1 /* $Id$ */ 2 /* 2 /* 3 3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 4 4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> … … 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 #include "pjsua_app_common.h" … … 219 219 * Read command arguments from config file. 220 220 */ 221 static int read_config_file(pj_pool_t *pool, const char *filename, 221 static int read_config_file(pj_pool_t *pool, const char *filename, 222 222 int *app_argc, char ***app_argv) 223 223 { … … 249 249 pj_size_t len; 250 250 int token_len; 251 251 252 252 pj_bzero(line, sizeof(line)); 253 253 if (fgets(line, sizeof(line), fhnd) == NULL) break; 254 254 255 255 // Trim ending newlines 256 256 len = strlen(line); … … 268 268 if (*p == '\0') // are we done yet? 269 269 break; 270 270 271 271 if (*p == '"' || *p == '\'') { // is token a quoted string 272 272 cDelimiter = *p++; // save quote delimiter 273 273 token = p; 274 274 275 275 while (*p != '\0' && *p != cDelimiter) p++; 276 276 277 277 if (*p == '\0') // found end of the line, but, 278 278 cDelimiter = '\0'; // didn't find a matching quote … … 280 280 } else { // token's not a quoted string 281 281 token = p; 282 282 283 283 while (*p != '\0' && strchr(whitespace, *p) == NULL) p++; 284 284 285 285 cDelimiter = *p; 286 286 } 287 287 288 288 *p = '\0'; 289 289 token_len = (int)(p-token); 290 290 291 291 if (token_len > 0) { 292 292 if (*token == '#') 293 293 break; // ignore remainder of line 294 294 295 295 argv[argc] = pj_pool_alloc(pool, token_len + 1); 296 296 pj_memcpy(argv[argc], token, token_len + 1); 297 297 ++argc; 298 298 } 299 299 300 300 *p = cDelimiter; 301 301 } … … 307 307 308 308 if (argc == MAX_ARGS && (i!=*app_argc || !feof(fhnd))) { 309 PJ_LOG(1,(THIS_FILE, 309 PJ_LOG(1,(THIS_FILE, 310 310 "Too many arguments specified in cmd line/config file")); 311 311 fflush(stdout); … … 323 323 324 324 /* Parse arguments. */ 325 static pj_status_t parse_args(int argc, char *argv[], 325 static pj_status_t parse_args(int argc, char *argv[], 326 326 pj_str_t *uri_to_call) 327 327 { … … 329 329 int option_index; 330 330 pjsua_app_config *cfg = &app_config; 331 enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 331 enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 332 332 OPT_LOG_APPEND, OPT_COLOR, OPT_NO_COLOR, OPT_LIGHT_BG, OPT_NO_STDERR, 333 333 OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE, 334 OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 334 OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 335 335 OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT, 336 336 OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, OPT_CONTACT_URI_PARAMS, … … 342 342 OPT_AUTO_CONF, OPT_CLOCK_RATE, OPT_SND_CLOCK_RATE, OPT_STEREO, 343 343 OPT_USE_ICE, OPT_ICE_REGULAR, OPT_USE_SRTP, OPT_SRTP_SECURE, 344 OPT_USE_TURN, OPT_ICE_MAX_HOSTS, OPT_ICE_NO_RTCP, OPT_TURN_SRV, 344 OPT_USE_TURN, OPT_ICE_MAX_HOSTS, OPT_ICE_NO_RTCP, OPT_TURN_SRV, 345 345 OPT_TURN_TCP, OPT_TURN_USER, OPT_TURN_PASSWD, 346 OPT_PLAY_FILE, OPT_PLAY_TONE, OPT_RTP_PORT, OPT_ADD_CODEC, 346 OPT_PLAY_FILE, OPT_PLAY_TONE, OPT_RTP_PORT, OPT_ADD_CODEC, 347 347 OPT_ILBC_MODE, OPT_REC_FILE, OPT_AUTO_REC, 348 348 OPT_COMPLEXITY, OPT_QUALITY, OPT_PTIME, OPT_NO_VAD, 349 349 OPT_RX_DROP_PCT, OPT_TX_DROP_PCT, OPT_EC_TAIL, OPT_EC_OPT, 350 OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 350 OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 351 351 OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, OPT_THREAD_CNT, 352 352 OPT_NOREFERSUB, OPT_ACCEPT_REDIRECT, … … 458 458 { "thread-cnt", 1, 0, OPT_THREAD_CNT}, 459 459 #if defined(PJSIP_HAS_TLS_TRANSPORT) && (PJSIP_HAS_TLS_TRANSPORT != 0) 460 { "use-tls", 0, 0, OPT_USE_TLS}, 460 { "use-tls", 0, 0, OPT_USE_TLS}, 461 461 { "tls-ca-file",1, 0, OPT_TLS_CA_FILE}, 462 { "tls-cert-file",1,0, OPT_TLS_CERT_FILE}, 462 { "tls-cert-file",1,0, OPT_TLS_CERT_FILE}, 463 463 { "tls-privkey-file",1,0, OPT_TLS_PRIV_FILE}, 464 464 { "tls-password",1,0, OPT_TLS_PASSWORD}, … … 504 504 unsigned i; 505 505 506 /* Run pj_getopt once to see if user specifies config file to read. */ 506 /* Run pj_getopt once to see if user specifies config file to read. */ 507 507 pj_optind = 0; 508 while ((c=pj_getopt_long(argc, argv, "", long_options, 509 &option_index)) != -1) 508 while ((c=pj_getopt_long(argc, argv, "", long_options, 509 &option_index)) != -1) 510 510 { 511 511 switch (c) { … … 541 541 /* Ignore as this has been processed before */ 542 542 break; 543 543 544 544 case OPT_LOG_FILE: 545 545 cfg->log_cfg.log_filename = pj_str(pj_optarg); … … 549 549 c = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 550 550 if (c < 0 || c > 6) { 551 PJ_LOG(1,(THIS_FILE, 551 PJ_LOG(1,(THIS_FILE, 552 552 "Error: expecting integer value 0-6 " 553 553 "for --log-level")); … … 560 560 case OPT_APP_LOG_LEVEL: 561 561 cfg->log_cfg.console_level = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 562 if (cfg->log_cfg.console_level < 0 || cfg->log_cfg.console_level> 6) {563 PJ_LOG(1,(THIS_FILE, 562 if (cfg->log_cfg.console_level > 6) { 563 PJ_LOG(1,(THIS_FILE, 564 564 "Error: expecting integer value 0-6 " 565 565 "for --app-log-level")); … … 614 614 return PJ_EINVAL; 615 615 } 616 cfg->media_cfg.clock_rate = lval; 616 cfg->media_cfg.clock_rate = lval; 617 617 break; 618 618 … … 624 624 return PJ_EINVAL; 625 625 } 626 cfg->media_cfg.snd_clock_rate = lval; 626 cfg->media_cfg.snd_clock_rate = lval; 627 627 break; 628 628 … … 634 634 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 635 635 if (lval < 0 || lval > 65535) { 636 PJ_LOG(1,(THIS_FILE, 636 PJ_LOG(1,(THIS_FILE, 637 637 "Error: expecting integer value for " 638 638 "--local-port")); … … 676 676 case OPT_PROXY: /* proxy */ 677 677 if (pjsua_verify_sip_url(pj_optarg) != 0) { 678 PJ_LOG(1,(THIS_FILE, 678 PJ_LOG(1,(THIS_FILE, 679 679 "Error: invalid SIP URL '%s' " 680 680 "in proxy argument", pj_optarg)); … … 686 686 case OPT_OUTBOUND_PROXY: /* outbound proxy */ 687 687 if (pjsua_verify_sip_url(pj_optarg) != 0) { 688 PJ_LOG(1,(THIS_FILE, 688 PJ_LOG(1,(THIS_FILE, 689 689 "Error: invalid SIP URL '%s' " 690 690 "in outbound proxy argument", pj_optarg)); … … 696 696 case OPT_REGISTRAR: /* registrar */ 697 697 if (pjsua_verify_sip_url(pj_optarg) != 0) { 698 PJ_LOG(1,(THIS_FILE, 698 PJ_LOG(1,(THIS_FILE, 699 699 "Error: invalid SIP URL '%s' in " 700 700 "registrar argument", pj_optarg)); … … 707 707 cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,pj_optarg)); 708 708 if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) { 709 PJ_LOG(1,(THIS_FILE, 709 PJ_LOG(1,(THIS_FILE, 710 710 "Error: invalid value for --reg-timeout " 711 711 "(expecting 1-3600)")); … … 730 730 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 731 731 if (lval < 0 || lval > 3) { 732 PJ_LOG(1,(THIS_FILE, 732 PJ_LOG(1,(THIS_FILE, 733 733 "Error: expecting integer value 0-3 for --use-timer")); 734 734 return PJ_EINVAL; … … 741 741 cur_acc->timer_setting.sess_expires = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 742 742 if (cur_acc->timer_setting.sess_expires < 90) { 743 PJ_LOG(1,(THIS_FILE, 743 PJ_LOG(1,(THIS_FILE, 744 744 "Error: invalid value for --timer-se " 745 745 "(expecting higher than 90)")); … … 752 752 cur_acc->timer_setting.min_se = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 753 753 if (cur_acc->timer_setting.min_se < 90) { 754 PJ_LOG(1,(THIS_FILE, 754 PJ_LOG(1,(THIS_FILE, 755 755 "Error: invalid value for --timer-min-se " 756 756 "(expecting higher than 90)")); … … 770 770 case OPT_ID: /* id */ 771 771 if (pjsua_verify_url(pj_optarg) != 0) { 772 PJ_LOG(1,(THIS_FILE, 772 PJ_LOG(1,(THIS_FILE, 773 773 "Error: invalid SIP URL '%s' " 774 774 "in local id argument", pj_optarg)); … … 780 780 case OPT_CONTACT: /* contact */ 781 781 if (pjsua_verify_sip_url(pj_optarg) != 0) { 782 PJ_LOG(1,(THIS_FILE, 782 PJ_LOG(1,(THIS_FILE, 783 783 "Error: invalid SIP URL '%s' " 784 784 "in contact argument", pj_optarg)); … … 822 822 case OPT_ACCEPT_REDIRECT: 823 823 cfg->redir_op = my_atoi(pj_optarg); 824 if (cfg->redir_op <0 || cfg->redir_op>PJSIP_REDIRECT_STOP) {825 PJ_LOG(1,(THIS_FILE, 824 if (cfg->redir_op>PJSIP_REDIRECT_STOP) { 825 PJ_LOG(1,(THIS_FILE, 826 826 "Error: accept-redirect value '%s' ", pj_optarg)); 827 827 return PJ_EINVAL; … … 893 893 case OPT_ADD_BUDDY: /* Add to buddy list. */ 894 894 if (pjsua_verify_url(pj_optarg) != 0) { 895 PJ_LOG(1,(THIS_FILE, 895 PJ_LOG(1,(THIS_FILE, 896 896 "Error: invalid URL '%s' in " 897 897 "--add-buddy option", pj_optarg)); … … 899 899 } 900 900 if (cfg->buddy_cnt == PJ_ARRAY_SIZE(cfg->buddy_cfg)) { 901 PJ_LOG(1,(THIS_FILE, 901 PJ_LOG(1,(THIS_FILE, 902 902 "Error: too many buddies in buddy list.")); 903 903 return -1; … … 1022 1022 case OPT_SRTP_SECURE: 1023 1023 app_config.cfg.srtp_secure_signaling = my_atoi(pj_optarg); 1024 if (!pj_isdigit(*pj_optarg) || 1025 app_config.cfg.srtp_secure_signaling > 2) 1024 if (!pj_isdigit(*pj_optarg) || 1025 app_config.cfg.srtp_secure_signaling > 2) 1026 1026 { 1027 1027 PJ_LOG(1,(THIS_FILE, "Invalid value for --srtp-secure option")); … … 1039 1039 1040 1040 range = (65535-START_PORT-PJSUA_MAX_CALLS*2); 1041 cfg->rtp_cfg.port = START_PORT + 1041 cfg->rtp_cfg.port = START_PORT + 1042 1042 ((pj_rand() % range) & 0xFFFE); 1043 1043 } … … 1112 1112 case OPT_QUALITY: 1113 1113 cfg->media_cfg.quality = my_atoi(pj_optarg); 1114 if (cfg->media_cfg.quality < 0 || cfg->media_cfg.quality> 10) {1114 if (cfg->media_cfg.quality > 10) { 1115 1115 PJ_LOG(1,(THIS_FILE, 1116 1116 "Error: invalid --quality (expecting 0-10")); … … 1136 1136 } 1137 1137 break; 1138 1138 1139 1139 case OPT_TX_DROP_PCT: 1140 1140 cfg->media_cfg.tx_drop_pct = my_atoi(pj_optarg); … … 1170 1170 cfg->use_tls = PJ_TRUE; 1171 1171 break; 1172 1172 1173 1173 case OPT_TLS_CA_FILE: 1174 1174 cfg->udp_cfg.tls_setting.ca_list_file = pj_str(pj_optarg); 1175 1175 break; 1176 1176 1177 1177 case OPT_TLS_CERT_FILE: 1178 1178 cfg->udp_cfg.tls_setting.cert_file = pj_str(pj_optarg); 1179 1179 break; 1180 1180 1181 1181 case OPT_TLS_PRIV_FILE: 1182 1182 cfg->udp_cfg.tls_setting.privkey_file = pj_str(pj_optarg); … … 1222 1222 ciphers_cnt = PJ_ARRAY_SIZE(ciphers); 1223 1223 pj_ssl_cipher_get_availables(ciphers, &ciphers_cnt); 1224 1224 1225 1225 PJ_LOG(1,(THIS_FILE, "Cipher \"%s\" is not supported by " 1226 1226 "TLS/SSL backend.", pj_optarg)); … … 1286 1286 cfg->rtp_cfg.qos_type = PJ_QOS_TYPE_VOICE; 1287 1287 /* Directly apply DSCP value to SIP traffic. Say lets 1288 * set it to CS3 (DSCP 011000). Note that this will not 1288 * set it to CS3 (DSCP 011000). Note that this will not 1289 1289 * work on all platforms. 1290 1290 */ … … 1337 1337 1338 1338 default: 1339 PJ_LOG(1,(THIS_FILE, 1339 PJ_LOG(1,(THIS_FILE, 1340 1340 "Argument \"%s\" is not valid. Use --help to see help", 1341 1341 argv[pj_optind-1])); … … 1402 1402 /* Realm must point to the real domain */ 1403 1403 if (*acfg->cred_info[0].realm.ptr=='*') { 1404 PJ_LOG(1,(THIS_FILE, 1404 PJ_LOG(1,(THIS_FILE, 1405 1405 "Error: cannot use '*' as realm with IMS")); 1406 1406 return PJ_EINVAL; … … 1409 1409 /* Username for authentication must be in a@b format */ 1410 1410 if (strchr(acfg->cred_info[0].username.ptr, '@')==0) { 1411 PJ_LOG(1,(THIS_FILE, 1411 PJ_LOG(1,(THIS_FILE, 1412 1412 "Error: Username for authentication must " 1413 1413 "be in user@domain format with IMS")); … … 1456 1456 for (i=0; i<PJ_ARRAY_SIZE(cfg->buddy_cfg); ++i) 1457 1457 pjsua_buddy_config_default(&cfg->buddy_cfg[i]); 1458 1458 1459 1459 cfg->vid.vcapture_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; 1460 1460 cfg->vid.vrender_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV; … … 1500 1500 return status; 1501 1501 1502 if (app_running) { 1502 if (app_running) { 1503 1503 app_config.use_cli = use_cli; 1504 1504 app_config.cli_cfg.cli_fe = cli_fe;
Note: See TracChangeset
for help on using the changeset viewer.