Changeset 236 for pjproject/trunk/pjsip/src/pjsua/pjsua_opt.c
- Timestamp:
- Feb 26, 2006 9:23:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua/pjsua_opt.c
r223 r236 44 44 puts(" pjsua [options]"); 45 45 puts(""); 46 puts(" [sip-url] Default URL to invite.");47 puts("");48 46 puts("General options:"); 49 47 puts(" --help Display this help screen"); … … 56 54 puts(" --app-log-level=N Set log max level for stdout display to N"); 57 55 puts(""); 56 puts("SIP Account options:"); 57 puts(" --id=url Set the URL of local ID (used in From header)"); 58 puts(" --contact=url Override the Contact information"); 59 puts(" --proxy=url Set the URL of proxy server"); 60 puts(""); 61 puts("SIP Account Registration Options:"); 62 puts(" --registrar=url Set the URL of registrar server"); 63 puts(" --reg-timeout=secs Set registration interval to secs (default 3600)"); 64 puts(""); 65 puts("SIP Account Control:"); 66 puts(" --next-account Add more account"); 67 puts(""); 58 68 puts("Authentication options:"); 59 69 puts(" --realm=string Set realm"); 60 70 puts(" --username=string Set authentication username"); 61 71 puts(" --password=string Set authentication password"); 62 puts(""); 63 puts("SIP options:"); 64 puts(" --id=url Set the URL of local ID (used in From header)"); 65 puts(" --contact=url Override the Contact information"); 66 puts(" --proxy=url Set the URL of proxy server"); 67 //puts(" --outbound=url Set the URL of outbound proxy server"); 68 puts(""); 69 puts("Registration Options:"); 70 puts(" --registrar=url Set the URL of registrar server"); 71 puts(" --reg-timeout=secs Set registration interval to secs (default 3600)"); 72 puts(" --next-cred Add more credential"); 72 73 puts(""); 73 74 puts("Transport Options:"); 74 puts(" --local-port=port Set TCP/UDP port"); 75 puts(" --local-port=port Set TCP/UDP port"); 76 puts(" --outbound=url Set the URL of outbound proxy server"); 75 77 puts(" --use-stun1=host[:port]"); 76 puts(" --use-stun2=host[:port] Use STUN and set host name and port ofSTUN servers");78 puts(" --use-stun2=host[:port] Resolve local IP with the specified STUN servers"); 77 79 puts(""); 78 80 puts("Media Options:"); 79 81 puts(" --null-audio Use NULL audio device"); 80 //puts(" --wav-file=file Play WAV file in conference bridge"); 82 puts(" --play-file=file Play WAV file in conference bridge"); 83 puts(" --auto-play Automatically play the file (to incoming calls only)"); 84 puts(" --auto-loop Automatically loop incoming RTP to outgoing RTP"); 85 puts(" --auto-conf Automatically put incoming calls to conference"); 81 86 puts(""); 82 87 puts("Buddy List (can be more than one):"); … … 85 90 puts("User Agent options:"); 86 91 puts(" --auto-answer=code Automatically answer incoming calls with code (e.g. 200)"); 87 puts(" -- auto-play=file Automatically play WAVE file to incoming calls");92 puts(" --max-calls=N Maximum number of concurrent calls (default:4, max:255)"); 88 93 puts(""); 89 94 fflush(stdout); … … 200 205 OPT_USE_STUN1, OPT_USE_STUN2, 201 206 OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, 202 OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY}; 207 OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY, OPT_AUTO_LOOP, 208 OPT_AUTO_CONF, 209 OPT_PLAY_FILE, 210 OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 211 }; 203 212 struct option long_options[] = { 204 213 { "config-file",1, 0, OPT_CONFIG_FILE}, … … 226 235 { "auto-answer",1, 0, OPT_AUTO_ANSWER}, 227 236 { "auto-hangup",1, 0, OPT_AUTO_HANGUP}, 228 { "auto-play", 1, 0, OPT_AUTO_PLAY}, 237 { "auto-play", 0, 0, OPT_AUTO_PLAY}, 238 { "auto-loop", 0, 0, OPT_AUTO_LOOP}, 239 { "auto-conf", 0, 0, OPT_AUTO_CONF}, 240 { "play-file", 1, 0, OPT_PLAY_FILE}, 241 { "next-account",0,0, OPT_NEXT_ACCOUNT}, 242 { "next-cred", 0, 0, OPT_NEXT_CRED}, 243 { "max-calls", 1, 0, OPT_MAX_CALLS}, 229 244 { NULL, 0, 0, 0} 230 245 }; 231 246 pj_status_t status; 247 pjsua_acc *cur_acc; 248 pjsip_cred_info *cur_cred; 232 249 char *config_file = NULL; 233 250 … … 248 265 return status; 249 266 } 267 268 269 cur_acc = &pjsua.acc[0]; 270 cur_cred = &pjsua.cred_info[0]; 250 271 251 272 … … 308 329 return PJ_EINVAL; 309 330 } 310 pjsua.proxy = pj_str(optarg);331 cur_acc->proxy = pj_str(optarg); 311 332 break; 312 333 … … 324 345 return PJ_EINVAL; 325 346 } 326 pjsua.registrar_uri = pj_str(optarg);347 cur_acc->reg_uri = pj_str(optarg); 327 348 break; 328 349 329 350 case OPT_REG_TIMEOUT: /* reg-timeout */ 330 pjsua.reg_timeout = pj_strtoul(pj_cstr(&tmp,optarg));331 if ( pjsua.reg_timeout < 1 || pjsua.reg_timeout > 3600) {351 cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,optarg)); 352 if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) { 332 353 printf("Error: invalid value for --reg-timeout (expecting 1-3600)\n"); 333 354 return PJ_EINVAL; … … 340 361 return PJ_EINVAL; 341 362 } 342 pjsua.local_uri = pj_str(optarg);363 cur_acc->local_uri = pj_str(optarg); 343 364 break; 344 365 … … 348 369 return PJ_EINVAL; 349 370 } 350 pjsua.contact_uri = pj_str(optarg); 371 cur_acc->contact_uri = pj_str(optarg); 372 break; 373 374 case OPT_NEXT_ACCOUNT: /* Add more account. */ 375 pjsua.acc_cnt++; 376 cur_acc = &pjsua.acc[pjsua.acc_cnt - 1]; 351 377 break; 352 378 353 379 case OPT_USERNAME: /* Default authentication user */ 354 if ( !pjsua.cred_count) pjsua.cred_count =1;355 pjsua.cred_info[0].username = pj_str(optarg);380 if (pjsua.cred_count==0) pjsua.cred_count=1; 381 cur_cred->username = pj_str(optarg); 356 382 break; 357 383 358 384 case OPT_REALM: /* Default authentication realm. */ 359 if ( !pjsua.cred_count) pjsua.cred_count =1;360 pjsua.cred_info[0].realm = pj_str(optarg);385 if (pjsua.cred_count==0) pjsua.cred_count=1; 386 cur_cred->realm = pj_str(optarg); 361 387 break; 362 388 363 389 case OPT_PASSWORD: /* authentication password */ 364 if (!pjsua.cred_count) pjsua.cred_count = 1; 365 pjsua.cred_info[0].data_type = 0; 366 pjsua.cred_info[0].data = pj_str(optarg); 390 if (pjsua.cred_count==0) pjsua.cred_count=1; 391 cur_cred->data_type = 0; 392 cur_cred->data = pj_str(optarg); 393 break; 394 395 case OPT_NEXT_CRED: /* Next credential */ 396 pjsua.cred_count++; 397 cur_cred = &pjsua.cred_info[pjsua.cred_count - 1]; 367 398 break; 368 399 … … 412 443 413 444 case OPT_AUTO_PLAY: 445 pjsua.auto_play = 1; 446 break; 447 448 case OPT_AUTO_LOOP: 449 pjsua.auto_loop = 1; 450 break; 451 452 case OPT_AUTO_CONF: 453 pjsua.auto_conf = 1; 454 break; 455 456 case OPT_PLAY_FILE: 414 457 pjsua.wav_file = optarg; 415 458 break; … … 422 465 } 423 466 break; 467 468 case OPT_MAX_CALLS: 469 pjsua.max_calls = atoi(optarg); 470 if (pjsua.max_calls < 1 || pjsua.max_calls > 255) { 471 puts("Too many calls for max-calls (1-255)"); 472 return -1; 473 } 474 break; 424 475 } 425 476 } … … 430 481 } 431 482 432 if (pjsua.reg_timeout == 0)433 pjsua.reg_timeout = 3600;434 435 436 483 return PJ_SUCCESS; 437 484 } … … 439 486 440 487 441 static void print_ invite_session(const char *title,442 struct pjsua_inv_data *inv_data,443 488 static void print_call(const char *title, 489 int call_index, 490 char *buf, pj_size_t size) 444 491 { 445 492 int len; 446 pjsip_inv_session *inv = inv_data->inv;493 pjsip_inv_session *inv = pjsua.calls[call_index].inv; 447 494 pjsip_dialog *dlg = inv->dlg; 448 495 char userinfo[128]; … … 516 563 void pjsua_dump(void) 517 564 { 518 struct pjsua_inv_data *inv_data;519 565 char buf[128]; 520 566 unsigned old_decor; … … 534 580 PJ_LOG(3,(THIS_FILE, "Dumping invite sessions:")); 535 581 536 if (pj _list_empty(&pjsua.inv_list)) {582 if (pjsua.call_cnt == 0) { 537 583 538 584 PJ_LOG(3,(THIS_FILE, " - no sessions -")); 539 585 540 586 } else { 541 542 inv_data = pjsua.inv_list.next; 543 544 while (inv_data != &pjsua.inv_list) { 545 546 print_invite_session(" ", inv_data, buf, sizeof(buf)); 587 int i; 588 589 for (i=0; i<pjsua.max_calls; ++i) { 590 591 if (pjsua.calls[i].inv == NULL) 592 continue; 593 594 print_call(" ", i, buf, sizeof(buf)); 547 595 PJ_LOG(3,(THIS_FILE, "%s", buf)); 548 596 549 if (inv_data->session) 550 dump_media_session(inv_data->session); 551 552 inv_data = inv_data->next; 597 if (pjsua.calls[i].session) 598 dump_media_session(pjsua.calls[i].session); 553 599 } 554 600 } … … 576 622 577 623 /* 578 * Save settings.624 * Save account settings 579 625 */ 580 pj_status_t pjsua_save_settings(const char *filename) 581 { 582 unsigned i; 626 static void save_account_settings(int acc_index, pj_str_t *result) 627 { 628 char line[128]; 629 pjsua_acc *acc = &pjsua.acc[acc_index]; 630 631 632 pj_ansi_sprintf(line, "#\n# Account %d:\n#\n", acc_index); 633 pj_strcat2(result, line); 634 635 636 /* Identity */ 637 if (acc->local_uri.slen) { 638 pj_ansi_sprintf(line, "--id %.*s\n", 639 (int)acc->local_uri.slen, 640 acc->local_uri.ptr); 641 pj_strcat2(result, line); 642 } 643 644 /* Registrar server */ 645 if (acc->reg_uri.slen) { 646 pj_ansi_sprintf(line, "--registrar %.*s\n", 647 (int)acc->reg_uri.slen, 648 acc->reg_uri.ptr); 649 pj_strcat2(result, line); 650 651 pj_ansi_sprintf(line, "--reg-timeout %u\n", 652 acc->reg_timeout); 653 pj_strcat2(result, line); 654 } 655 656 657 /* Proxy */ 658 if (acc->proxy.slen) { 659 pj_ansi_sprintf(line, "--proxy %.*s\n", 660 (int)acc->proxy.slen, 661 acc->proxy.ptr); 662 pj_strcat2(result, line); 663 } 664 } 665 666 667 668 /* 669 * Dump settings. 670 */ 671 int pjsua_dump_settings(char *buf, pj_size_t max) 672 { 673 int acc_index; 674 int i; 583 675 pj_str_t cfg; 584 676 char line[128]; 585 pj_pool_t *pool; 586 FILE *fhnd; 587 588 /* Create pool for temporary buffer. */ 589 pool = pj_pool_create(&pjsua.cp.factory, "settings", 4000, 0, NULL); 590 if (!pool) 591 return PJ_ENOMEM; 592 593 594 cfg.ptr = pj_pool_alloc(pool, 3800); 595 if (!cfg.ptr) { 596 pj_pool_release(pool); 597 return PJ_EBUG; 598 } 677 678 cfg.ptr = buf; 599 679 cfg.slen = 0; 600 680 601 681 602 /* Identity */ 603 if (pjsua.local_uri.slen) { 604 pj_ansi_sprintf(line, "--id %.*s\n", 605 (int)pjsua.local_uri.slen, 606 pjsua.local_uri.ptr); 607 pj_strcat2(&cfg, line); 682 /* Logging. */ 683 pj_strcat2(&cfg, "#\n# Logging options:\n#\n"); 684 pj_ansi_sprintf(line, "--log-level %d\n", 685 pjsua.log_level); 686 pj_strcat2(&cfg, line); 687 688 pj_ansi_sprintf(line, "--app-log-level %d\n", 689 pjsua.app_log_level); 690 pj_strcat2(&cfg, line); 691 692 if (pjsua.log_filename) { 693 pj_ansi_sprintf(line, "--log-file %s\n", 694 pjsua.log_filename); 695 pj_strcat2(&cfg, line); 696 } 697 698 699 /* Save account settings. */ 700 for (acc_index=0; acc_index < pjsua.acc_cnt; ++acc_index) { 701 702 save_account_settings(acc_index, &cfg); 703 704 if (acc_index < pjsua.acc_cnt-1) 705 pj_strcat2(&cfg, "--next-account\n"); 608 706 } 609 707 610 708 /* Credentials. */ 611 709 for (i=0; i<pjsua.cred_count; ++i) { 710 711 pj_ansi_sprintf(line, "#\n# Credential %d:\n#\n", i); 712 pj_strcat2(&cfg, line); 713 612 714 if (pjsua.cred_info[i].realm.slen) { 613 715 pj_ansi_sprintf(line, "--realm %.*s\n", … … 626 728 pjsua.cred_info[i].data.ptr); 627 729 pj_strcat2(&cfg, line); 628 } 629 630 /* Registrar server */ 631 if (pjsua.registrar_uri.slen) { 632 pj_ansi_sprintf(line, "--registrar %.*s\n", 633 (int)pjsua.registrar_uri.slen, 634 pjsua.registrar_uri.ptr); 635 pj_strcat2(&cfg, line); 636 } 637 730 731 if (i < pjsua.cred_count-1) 732 pj_strcat2(&cfg, "--next-cred\n"); 733 } 734 735 736 pj_strcat2(&cfg, "#\n# Network settings:\n#\n"); 638 737 639 738 /* Outbound proxy */ … … 644 743 pj_strcat2(&cfg, line); 645 744 } 646 647 /* Media */648 if (pjsua.null_audio)649 pj_strcat2(&cfg, "--null-audio\n");650 745 651 746 … … 673 768 674 769 770 pj_strcat2(&cfg, "#\n# Media settings:\n#\n"); 771 772 773 /* Media */ 774 if (pjsua.null_audio) 775 pj_strcat2(&cfg, "--null-audio\n"); 776 if (pjsua.auto_play) 777 pj_strcat2(&cfg, "--auto-play\n"); 778 if (pjsua.auto_loop) 779 pj_strcat2(&cfg, "--auto-loop\n"); 780 if (pjsua.auto_conf) 781 pj_strcat2(&cfg, "--auto-conf\n"); 782 if (pjsua.wav_file) { 783 pj_ansi_sprintf(line, "--play-file %s\n", 784 pjsua.wav_file); 785 pj_strcat2(&cfg, line); 786 } 787 788 789 pj_strcat2(&cfg, "#\n# User agent:\n#\n"); 790 791 /* Auto-answer. */ 792 if (pjsua.auto_answer != 0) { 793 pj_ansi_sprintf(line, "--auto-answer %d\n", 794 pjsua.auto_answer); 795 pj_strcat2(&cfg, line); 796 } 797 798 /* Max calls. */ 799 pj_ansi_sprintf(line, "--max-calls %d\n", 800 pjsua.max_calls); 801 pj_strcat2(&cfg, line); 802 803 804 pj_strcat2(&cfg, "#\n# Buddies:\n#\n"); 805 675 806 /* Add buddies. */ 676 807 for (i=0; i<pjsua.buddy_cnt; ++i) { … … 682 813 683 814 815 *(cfg.ptr + cfg.slen) = '\0'; 816 return cfg.slen; 817 } 818 819 /* 820 * Save settings. 821 */ 822 pj_status_t pjsua_save_settings(const char *filename) 823 { 824 pj_str_t cfg; 825 pj_pool_t *pool; 826 FILE *fhnd; 827 828 /* Create pool for temporary buffer. */ 829 pool = pj_pool_create(&pjsua.cp.factory, "settings", 4000, 0, NULL); 830 if (!pool) 831 return PJ_ENOMEM; 832 833 834 cfg.ptr = pj_pool_alloc(pool, 3800); 835 if (!cfg.ptr) { 836 pj_pool_release(pool); 837 return PJ_EBUG; 838 } 839 840 841 cfg.slen = pjsua_dump_settings(cfg.ptr, 3800); 842 if (cfg.slen < 1) { 843 pj_pool_release(pool); 844 return PJ_ENOMEM; 845 } 846 847 684 848 /* Write to file. */ 685 849 fhnd = fopen(filename, "wt");
Note: See TracChangeset
for help on using the changeset viewer.