Ignore:
Timestamp:
Nov 27, 2008 12:06:46 AM (15 years ago)
Author:
bennylp
Message:

Ticket #10: handle redirection response in the invite session

File:
1 edited

Legend:

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

    r2316 r2370  
    6363    pjsua_transport_config  udp_cfg; 
    6464    pjsua_transport_config  rtp_cfg; 
     65    pjsip_redirect_op       redir_op; 
    6566 
    6667    unsigned                acc_cnt; 
     
    279280    puts  ("  --use-compact-form  Minimize SIP message size"); 
    280281    puts  ("  --no-force-lr       Allow strict-route to be used (i.e. do not force lr)"); 
     282    puts  ("  --accept-redirect=N Specify how to handle call redirect (3xx) response."); 
     283    puts  ("                      0: reject, 1: follow automatically (default), 2: ask"); 
    281284 
    282285    puts  (""); 
     
    304307    pjsua_transport_config_default(&cfg->rtp_cfg); 
    305308    cfg->rtp_cfg.port = 4000; 
     309    cfg->redir_op = PJSIP_REDIRECT_ACCEPT; 
    306310    cfg->duration = NO_LIMIT; 
    307311    cfg->wav_id = PJSUA_INVALID_ID; 
     
    473477           OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS,  
    474478           OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, OPT_THREAD_CNT, 
    475            OPT_NOREFERSUB, 
     479           OPT_NOREFERSUB, OPT_ACCEPT_REDIRECT, 
    476480           OPT_USE_TLS, OPT_TLS_CA_FILE, OPT_TLS_CERT_FILE, OPT_TLS_PRIV_FILE, 
    477481           OPT_TLS_PASSWORD, OPT_TLS_VERIFY_SERVER, OPT_TLS_VERIFY_CLIENT, 
     
    516520        { "auto-update-nat",    1, 0, OPT_AUTO_UPDATE_NAT}, 
    517521        { "use-compact-form",   0, 0, OPT_USE_COMPACT_FORM}, 
     522        { "accept-redirect", 1, 0, OPT_ACCEPT_REDIRECT}, 
    518523        { "no-force-lr",0, 0, OPT_NO_FORCE_LR}, 
    519524        { "realm",      1, 0, OPT_REALM}, 
     
    841846            break; 
    842847 
     848        case OPT_ACCEPT_REDIRECT: 
     849            cfg->redir_op = my_atoi(pj_optarg); 
     850            if (cfg->redir_op<0 || cfg->redir_op>PJSIP_REDIRECT_STOP) { 
     851                PJ_LOG(1,(THIS_FILE,  
     852                          "Error: accept-redirect value '%s' ", pj_optarg)); 
     853                return PJ_EINVAL; 
     854            } 
     855            break; 
     856 
    843857        case OPT_NO_FORCE_LR: 
    844858            cfg->cfg.force_lr = PJ_FALSE; 
     
    17861800    } 
    17871801 
     1802    /* accept-redirect */ 
     1803    if (config->redir_op != PJSIP_REDIRECT_ACCEPT) { 
     1804        pj_ansi_sprintf(line, "--accept-redirect %d\n", 
     1805                        config->redir_op); 
     1806        pj_strcat2(&cfg, line); 
     1807    } 
     1808 
    17881809    /* Max calls. */ 
    17891810    pj_ansi_sprintf(line, "--max-calls %d\n", 
     
    18411862 * as the logger can accept. 
    18421863 */ 
    1843 static void log_call_dump(int call_id) { 
     1864static void log_call_dump(int call_id)  
     1865{ 
    18441866    unsigned call_dump_len; 
    18451867    unsigned part_len; 
     
    23672389{ 
    23682390    PJ_LOG(3,(THIS_FILE, "Incoming DTMF on call %d: %c", call_id, dtmf)); 
     2391} 
     2392 
     2393/* 
     2394 * Redirection handler. 
     2395 */ 
     2396static void call_on_redirected(pjsua_call_id call_id, const pjsip_uri *target, 
     2397                               pjsip_redirect_op *cmd, const pjsip_event *e) 
     2398{ 
     2399    *cmd = app_config.redir_op; 
     2400 
     2401    PJ_UNUSED_ARG(e); 
     2402 
     2403    if (*cmd == PJSIP_REDIRECT_PENDING) { 
     2404        char uristr[PJSIP_MAX_URL_SIZE]; 
     2405        int len; 
     2406 
     2407        len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr,  
     2408                              sizeof(uristr)); 
     2409        if (len < 1) { 
     2410            pj_ansi_strcpy(uristr, "--URI too long--"); 
     2411        } 
     2412 
     2413        PJ_LOG(3,(THIS_FILE, "Call %d is being redirected to %.*s. " 
     2414                  "Press 'Ra' to accept, 'Rr' to reject, or 'Rd' to " 
     2415                  "disconnect.", 
     2416                  call_id, len, uristr)); 
     2417    } 
    23692418} 
    23702419 
     
    39163965 
    39173966 
     3967        case 'R': 
     3968            if (!pjsua_call_is_active(current_call)) { 
     3969                PJ_LOG(1,(THIS_FILE, "Call %d has gone", current_call)); 
     3970            } else if (menuin[1] == 'a') { 
     3971                pjsua_call_process_redirect(current_call,  
     3972                                            PJSIP_REDIRECT_ACCEPT); 
     3973            } else if (menuin[1] == 'r') { 
     3974                pjsua_call_process_redirect(current_call, 
     3975                                            PJSIP_REDIRECT_REJECT); 
     3976            } else { 
     3977                pjsua_call_process_redirect(current_call, 
     3978                                            PJSIP_REDIRECT_STOP); 
     3979            } 
     3980            break; 
     3981 
    39183982        default: 
    39193983            if (menuin[0] != '\n' && menuin[0] != '\r') { 
     
    39634027    app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; 
    39644028    app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; 
     4029    app_config.cfg.cb.on_call_redirected = &call_on_redirected; 
    39654030    app_config.cfg.cb.on_reg_state = &on_reg_state; 
    39664031    app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe; 
Note: See TracChangeset for help on using the changeset viewer.