Changeset 6137


Ignore:
Timestamp:
Jan 28, 2020 1:47:56 AM (4 years ago)
Author:
riza
Message:

Close #2262: Notify when IP change handling is completed.

Location:
pjproject/trunk
Files:
7 edited

Legend:

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

    r6112 r6137  
    10241024                               &app_config.auto_hangup_timer,  
    10251025                               &delay); 
     1026} 
     1027 
     1028/* IP change progress callback. */ 
     1029void on_ip_change_progress(pjsua_ip_change_op op, 
     1030                           pj_status_t status, 
     1031                           const pjsua_ip_change_op_info *info) 
     1032{ 
     1033    char info_str[128]; 
     1034    pjsua_acc_info acc_info; 
     1035    pjsua_transport_info tp_info; 
     1036 
     1037    if (status == PJ_SUCCESS) { 
     1038        switch (op) { 
     1039        case PJSUA_IP_CHANGE_OP_RESTART_LIS: 
     1040            pjsua_transport_get_info(info->lis_restart.transport_id, &tp_info); 
     1041            pj_ansi_snprintf(info_str, sizeof(info_str), 
     1042                             "restart transport %.*s", 
     1043                             tp_info.info.slen, tp_info.info.ptr); 
     1044            break; 
     1045        case PJSUA_IP_CHANGE_OP_ACC_SHUTDOWN_TP: 
     1046            pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 
     1047 
     1048            pj_ansi_snprintf(info_str, sizeof(info_str), 
     1049                             "transport shutdown for account %.*s", 
     1050                             acc_info.acc_uri.slen, acc_info.acc_uri.ptr); 
     1051            break; 
     1052        case PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT: 
     1053            pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 
     1054            if (info->acc_update_contact.code) { 
     1055                pj_ansi_snprintf(info_str, sizeof(info_str), 
     1056                                 "update contact for account %.*s, code[%d]", 
     1057                                 acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 
     1058                                 info->acc_update_contact.code); 
     1059            } else { 
     1060                pj_ansi_snprintf(info_str, sizeof(info_str), 
     1061                                 "update contact for account %.*s", 
     1062                                 acc_info.acc_uri.slen, acc_info.acc_uri.ptr); 
     1063            } 
     1064            break; 
     1065        case PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS: 
     1066            pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 
     1067            pj_ansi_snprintf(info_str, sizeof(info_str), 
     1068                             "hangup call for account %.*s, call_id[%d]", 
     1069                             acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 
     1070                             info->acc_hangup_calls.call_id); 
     1071            break; 
     1072        case PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS: 
     1073            pjsua_acc_get_info(info->acc_shutdown_tp.acc_id, &acc_info); 
     1074            pj_ansi_snprintf(info_str, sizeof(info_str), 
     1075                             "reinvite call for account %.*s, call_id[%d]", 
     1076                             acc_info.acc_uri.slen, acc_info.acc_uri.ptr, 
     1077                             info->acc_reinvite_calls.call_id); 
     1078            break; 
     1079        case PJSUA_IP_CHANGE_OP_COMPLETED: 
     1080            pj_ansi_snprintf(info_str, sizeof(info_str), 
     1081                             "done"); 
     1082            break; 
     1083        } 
     1084        PJ_LOG(3,(THIS_FILE, "IP change progress report : %s", info_str)); 
     1085 
     1086    } else { 
     1087        PJ_PERROR(3,(THIS_FILE, status, "IP change progress fail")); 
     1088    } 
    10261089} 
    10271090 
     
    13011364    app_config.cfg.cb.on_snd_dev_operation = &on_snd_dev_operation; 
    13021365    app_config.cfg.cb.on_call_media_event = &on_call_media_event; 
     1366    app_config.cfg.cb.on_ip_change_progress = &on_ip_change_progress; 
    13031367#ifdef TRANSPORT_ADAPTER_SAMPLE 
    13041368    app_config.cfg.cb.on_create_media_transport = &on_create_media_transport; 
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app_legacy.c

    r6123 r6137  
    17561756} 
    17571757 
     1758static void ui_handle_ip_change() 
     1759{ 
     1760    pjsua_ip_change_param param; 
     1761    pjsua_ip_change_param_default(&param); 
     1762    pjsua_handle_ip_change(&param); 
     1763} 
    17581764 
    17591765/* 
     
    20072013            break; 
    20082014 
     2015        case 'I': /* Handle IP change. */ 
     2016            ui_handle_ip_change(); 
     2017            break; 
     2018 
    20092019        default: 
    20102020            if (menuin[0] != '\n' && menuin[0] != '\r') { 
  • pjproject/trunk/pjsip-apps/src/swig/symbols.i

    r6075 r6137  
    848848  PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT, 
    849849  PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS, 
    850   PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS 
     850  PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS, 
     851  PJSUA_IP_CHANGE_OP_COMPLETED 
    851852} pjsua_ip_change_op; 
    852853 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r6117 r6137  
    749749     * The re-INVITE call process. 
    750750     */ 
    751     PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS 
     751    PJSUA_IP_CHANGE_OP_ACC_REINVITE_CALLS, 
     752 
     753    /** 
     754     * The ip change process has completed. 
     755     */ 
     756    PJSUA_IP_CHANGE_OP_COMPLETED 
    752757 
    753758} pjsua_ip_change_op; 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r6035 r6137  
    898898pj_status_t pjsua_acc_handle_call_on_ip_change(pjsua_acc *acc); 
    899899 
     900/* 
     901 * End IP change process per account. 
     902 */ 
     903void pjsua_acc_end_ip_change(pjsua_acc *acc); 
     904 
    900905PJ_END_DECL 
    901906 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r6035 r6137  
    693693    acc->via_tp = NULL; 
    694694    acc->next_rtp_port = 0; 
    695     acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL;     
     695    acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 
    696696 
    697697    /* Remove from array */ 
     
    24232423 
    24242424            pj_bzero(&ip_chg_info, sizeof(ip_chg_info)); 
    2425             pjsip_regc_get_info(param->regc, &rinfo);        
     2425            pjsip_regc_get_info(param->regc, &rinfo); 
    24262426            ip_chg_info.acc_update_contact.acc_id = acc->index; 
    24272427            ip_chg_info.acc_update_contact.code = param->code; 
    24282428            ip_chg_info.acc_update_contact.is_register = !param->is_unreg; 
    2429             (*pjsua_var.ua_cfg.cb.on_ip_change_progress)(acc->ip_change_op,  
    2430                                                          param->status,  
     2429            (*pjsua_var.ua_cfg.cb.on_ip_change_progress)(acc->ip_change_op, 
     2430                                                         param->status, 
    24312431                                                         &ip_chg_info); 
    24322432        } 
     
    24412441 
    24422442                status = pjsua_acc_set_registration(acc->index, PJ_TRUE); 
    2443                 if ((status != PJ_SUCCESS) &&  
    2444                     pjsua_var.ua_cfg.cb.on_ip_change_progress)  
     2443                if ((status != PJ_SUCCESS) && 
     2444                    pjsua_var.ua_cfg.cb.on_ip_change_progress) 
    24452445                { 
    24462446                    pjsua_ip_change_op_info ip_chg_info; 
     
    24502450                    ip_chg_info.acc_update_contact.is_register = PJ_TRUE; 
    24512451                    (*pjsua_var.ua_cfg.cb.on_ip_change_progress)( 
    2452                                                             acc->ip_change_op,  
    2453                                                             status,  
     2452                                                            acc->ip_change_op, 
     2453                                                            status, 
    24542454                                                            &ip_chg_info); 
     2455 
     2456                    pjsua_acc_end_ip_change(acc); 
    24552457                } 
    24562458            } else { 
    24572459                /* Avoid deadlock issue when sending BYE or Re-INVITE.  */ 
    2458                 pjsua_schedule_timer2(&handle_call_on_ip_change_cb,  
     2460                pjsua_schedule_timer2(&handle_call_on_ip_change_cb, 
    24592461                                      (void*)acc, 0); 
    24602462            } 
    2461         }  
    2462     } 
    2463      
     2463        } else { 
     2464            pjsua_acc_end_ip_change(acc); 
     2465        } 
     2466    } 
     2467 
    24642468    PJSUA_UNLOCK(); 
    24652469    pj_log_pop_indent(); 
     
    39033907            pjsip_regc_release_transport(pjsua_var.acc[i].regc); 
    39043908 
    3905             if (pjsua_var.acc[i].ip_change_op ==  
     3909            if (pjsua_var.acc[i].ip_change_op == 
    39063910                                            PJSUA_IP_CHANGE_OP_ACC_SHUTDOWN_TP) 
    39073911            { 
     3912                /* Before progressing to next step, report here. */ 
     3913                if (pjsua_var.ua_cfg.cb.on_ip_change_progress) { 
     3914                    pjsua_ip_change_op_info ch_info; 
     3915 
     3916                    pj_bzero(&ch_info, sizeof(ch_info)); 
     3917                    ch_info.acc_shutdown_tp.acc_id = acc->index; 
     3918 
     3919                    pjsua_var.ua_cfg.cb.on_ip_change_progress( 
     3920                                                         acc->ip_change_op, 
     3921                                                         PJ_SUCCESS, 
     3922                                                         &ch_info); 
     3923                } 
     3924 
    39083925                if (acc->cfg.allow_contact_rewrite) { 
    39093926                    pjsua_acc_update_contact_on_ip_change(acc); 
     
    39403957    status = pjsua_acc_set_registration(acc->index, !need_unreg); 
    39413958 
    3942     if ((status != PJ_SUCCESS) && (pjsua_var.ua_cfg.cb.on_ip_change_progress))  
     3959    if ((status != PJ_SUCCESS) && (pjsua_var.ua_cfg.cb.on_ip_change_progress) 
     3960        && (acc->ip_change_op == PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT)) 
    39433961    { 
     3962        /* If update contact fails, notification might already been triggered 
     3963         * from registration callback. 
     3964         */ 
    39443965        pjsua_ip_change_op_info info; 
    3945          
     3966 
    39463967        pj_bzero(&info, sizeof(info)); 
    39473968        info.acc_update_contact.acc_id = acc->index; 
    3948         info.acc_update_contact.is_register = !need_unreg;       
     3969        info.acc_update_contact.is_register = !need_unreg; 
    39493970 
    39503971        pjsua_var.ua_cfg.cb.on_ip_change_progress(acc->ip_change_op, 
    39513972                                                  status, 
    39523973                                                  &info); 
     3974 
     3975        pjsua_acc_end_ip_change(acc); 
    39533976    } 
    39543977    return status; 
     
    39653988 
    39663989    PJSUA_LOCK(); 
    3967     if (acc->cfg.ip_change_cfg.hangup_calls ||  
     3990    if (acc->cfg.ip_change_cfg.hangup_calls || 
    39683991        acc->cfg.ip_change_cfg.reinvite_flags) 
    39693992    { 
     
    39774000            } 
    39784001 
    3979             if (acc->cfg.ip_change_cfg.hangup_calls) { 
     4002            if ((acc->cfg.ip_change_cfg.hangup_calls) && 
     4003                (call_info.state >= PJSIP_INV_STATE_EARLY)) 
     4004            { 
    39804005                acc->ip_change_op = PJSUA_IP_CHANGE_OP_ACC_HANGUP_CALLS; 
    39814006                PJ_LOG(3, (THIS_FILE, "call to %.*s: hangup " 
     
    40324057            } 
    40334058        } 
    4034     }     
    4035     acc->ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 
     4059    } 
     4060    pjsua_acc_end_ip_change(acc); 
    40364061    PJSUA_UNLOCK(); 
    40374062    return status; 
    40384063} 
     4064 
     4065void pjsua_acc_end_ip_change(pjsua_acc *acc) 
     4066{ 
     4067    int i = 0; 
     4068    pj_bool_t all_done = PJ_TRUE; 
     4069 
     4070    PJSUA_LOCK(); 
     4071    if (acc && acc->ip_change_op < PJSUA_IP_CHANGE_OP_COMPLETED) { 
     4072        PJ_LOG(3, (THIS_FILE, "IP address change handling for acc %d " 
     4073                   "completed", acc->index)); 
     4074        acc->ip_change_op = PJSUA_IP_CHANGE_OP_COMPLETED; 
     4075        if (pjsua_var.acc_cnt) { 
     4076            for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     4077                if (pjsua_var.acc[i].valid && 
     4078                    pjsua_var.acc[i].ip_change_op != 
     4079                                                  PJSUA_IP_CHANGE_OP_COMPLETED) 
     4080                { 
     4081                    all_done = PJ_FALSE; 
     4082                    break; 
     4083                } 
     4084            } 
     4085        } 
     4086    } 
     4087    if (all_done && pjsua_var.ua_cfg.cb.on_ip_change_progress) { 
     4088        PJ_LOG(3, (THIS_FILE, "IP address change handling completed")); 
     4089        pjsua_var.ua_cfg.cb.on_ip_change_progress( 
     4090                                            PJSUA_IP_CHANGE_OP_COMPLETED, 
     4091                                            PJ_SUCCESS, 
     4092                                            NULL); 
     4093    } 
     4094    PJSUA_UNLOCK(); 
     4095} 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r6015 r6137  
    35723572 
    35733573    PJSUA_LOCK(); 
     3574 
     3575    if (pjsua_var.acc_cnt == 0) { 
     3576        PJ_LOG(3, (THIS_FILE, 
     3577                   "No account is set, IP change handling will stop")); 
     3578        pjsua_acc_end_ip_change(NULL); 
     3579        PJSUA_UNLOCK(); 
     3580        return status; 
     3581    } 
     3582 
    35743583    /* Reset ip_change_active flag. */ 
    35753584    for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
    35763585        pjsua_var.acc[i].ip_change_op = PJSUA_IP_CHANGE_OP_NULL; 
    35773586        acc_done[i] = PJ_FALSE; 
    3578     }     
    3579      
     3587    } 
     3588 
    35803589    for (i = 0; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
    35813590        pj_bool_t shutdown_transport = PJ_FALSE; 
     
    35953604 
    35963605            pjsip_regc_get_info(acc->regc, &regc_info); 
    3597              
     3606 
    35983607            /* Check if transport restart listener succeed. */ 
    35993608            for (; j < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++j) { 
    3600                 if (pjsua_var.tpdata[j].data.ptr != NULL &&  
     3609                if (pjsua_var.tpdata[j].data.ptr != NULL && 
    36013610                  pjsua_var.tpdata[j].restart_status != PJ_SUCCESS && 
    36023611                  pjsua_var.tpdata[j].type == regc_info.transport->key.type) 
     
    36053614                                           == regc_info.transport->factory) || 
    36063615                        (pjsua_var.tpdata[j].data.tp 
    3607                                                == regc_info.transport))  
     3616                                               == regc_info.transport)) 
    36083617                    { 
    36093618                        found_restart_tp_fail = PJ_TRUE; 
     
    36233632                    } 
    36243633                } 
    3625                      
     3634                pjsua_acc_end_ip_change(acc); 
    36263635                continue; 
    36273636            } 
     
    36333642                shutdown_transport = acc->cfg.ip_change_cfg.shutdown_tp; 
    36343643                shut_acc_ids[shut_acc_cnt++] = acc->index; 
    3635             }    
     3644            } 
    36363645        } else if (acc->cfg.reg_uri.slen && 
    3637                    acc->reg_last_code != PJSIP_SC_BAD_GATEWAY && 
     3646                   acc->reg_last_code != PJSIP_SC_OK && 
    36383647                   acc->reg_last_code != PJSIP_SC_REQUEST_TIMEOUT && 
    36393648                   acc->reg_last_code != PJSIP_SC_INTERNAL_SERVER_ERROR && 
     
    36413650                   acc->reg_last_code != PJSIP_SC_SERVICE_UNAVAILABLE && 
    36423651                   acc->reg_last_code != PJSIP_SC_SERVER_TIMEOUT && 
    3643                    acc->reg_last_code != PJSIP_SC_TEMPORARILY_UNAVAILABLE)  
     3652                   acc->reg_last_code != PJSIP_SC_TEMPORARILY_UNAVAILABLE) 
    36443653        { 
     3654            PJ_LOG(3, (THIS_FILE, "Permanent registration failure, " 
     3655                       "IP change handling will stop for acc %d", acc->index)); 
     3656 
     3657            pjsua_acc_end_ip_change(acc); 
    36453658            continue; 
    3646         }  
    3647         pj_ansi_snprintf(acc_id, sizeof(acc_id), "#%d", i);      
     3659        } 
     3660        pj_ansi_snprintf(acc_id, sizeof(acc_id), "#%d", i); 
    36483661 
    36493662        if (transport) { 
     
    36563669 
    36573670                if (!next_acc->valid || !next_acc->regc || 
    3658                     (next_acc->ip_change_op > PJSUA_IP_CHANGE_OP_NULL))  
     3671                    (next_acc->ip_change_op > PJSUA_IP_CHANGE_OP_NULL)) 
    36593672                { 
    36603673                    continue; 
     
    36833696        if (shutdown_transport) { 
    36843697            unsigned j; 
    3685             /* Shutdown the transport. */            
     3698            /* Shutdown the transport. */ 
    36863699            PJ_LOG(3, (THIS_FILE, "Shutdown transport %s used by account %s " 
    36873700                       "triggered by IP change", transport->obj_name, acc_id)); 
     
    36943707 
    36953708            status = pjsip_transport_shutdown2(transport, PJ_TRUE); 
    3696  
    3697             /* Report progress to each acc which uses the same transport. */ 
    3698             for (j = 0; j < shut_acc_cnt; ++j) { 
    3699                 pjsua_acc *tmp_acc = &pjsua_var.acc[shut_acc_ids[j]]; 
    3700  
    3701                 if (pjsua_var.ua_cfg.cb.on_ip_change_progress) { 
    3702                     pjsua_ip_change_op_info info; 
    3703  
    3704                     pj_bzero(&info, sizeof(info)); 
    3705                     info.acc_shutdown_tp.acc_id = tmp_acc->index; 
    3706  
    3707                     pjsua_var.ua_cfg.cb.on_ip_change_progress( 
    3708                                                          tmp_acc->ip_change_op, 
    3709                                                          status, 
    3710                                                          &info); 
    3711                 } 
    3712  
    3713             } 
    37143709        } else { 
    37153710            acc_done[i] = PJ_TRUE; 
     
    37263721 
    37273722 
    3728 static pj_status_t restart_listener(pjsua_transport_id id,  
     3723static pj_status_t restart_listener(pjsua_transport_id id, 
    37293724                                    unsigned restart_lis_delay) 
    37303725{ 
    37313726    pj_sockaddr bind_addr; 
    37323727    pjsua_transport_info tp_info; 
    3733     pj_status_t status;     
    3734  
    3735     pjsua_transport_get_info(id, &tp_info);         
     3728    pj_status_t status; 
     3729 
     3730    pjsua_transport_get_info(id, &tp_info); 
    37363731    pj_sockaddr_init(pjsip_transport_type_get_af(tp_info.type), 
    37373732                     &bind_addr, 
    37383733                     NULL, 
    37393734                     pj_sockaddr_get_port(&tp_info.local_addr)); 
    3740      
     3735 
    37413736    switch (tp_info.type) { 
    37423737    case PJSIP_TRANSPORT_UDP: 
     
    37713766    } 
    37723767 
    3773     PJ_PERROR(3,(THIS_FILE, status, "Listener %s restart", 
    3774                  pjsip_transport_get_type_name(tp_info.type))); 
     3768    PJ_PERROR(3,(THIS_FILE, status, "Listener %.*s restart", 
     3769                 tp_info.info.slen, tp_info.info.ptr)); 
    37753770 
    37763771    if (status != PJ_SUCCESS && (restart_lis_delay > 0)) { 
    37773772        /* Try restarting again, with delay. */ 
    3778         pjsua_schedule_timer2(&restart_listener_cb,  
    3779                               (void*)(pj_size_t)id,  
     3773        pjsua_schedule_timer2(&restart_listener_cb, 
     3774                              (void*)(pj_size_t)id, 
    37803775                              restart_lis_delay); 
    37813776 
    3782         PJ_LOG(3,(THIS_FILE, "Retry listener %s restart in %d ms", 
    3783                      pjsip_transport_get_type_name(tp_info.type), 
    3784                      restart_lis_delay)); 
     3777        PJ_LOG(3,(THIS_FILE, "Retry listener %.*s restart in %d ms", 
     3778                  tp_info.info.slen, tp_info.info.ptr, restart_lis_delay)); 
    37853779 
    37863780        status = PJ_SUCCESS; 
     
    37973791            info.lis_restart.transport_id = id; 
    37983792            pjsua_var.ua_cfg.cb.on_ip_change_progress( 
    3799                                                 PJSUA_IP_CHANGE_OP_RESTART_LIS,  
    3800                                                 status,  
     3793                                                PJSUA_IP_CHANGE_OP_RESTART_LIS, 
     3794                                                status, 
    38013795                                                &info); 
    38023796        } 
     
    38043798        /* Move forward if all listener has been restarted. */ 
    38053799        for (; i < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++i) { 
    3806             if (pjsua_var.tpdata[i].data.ptr != NULL &&  
    3807                 pjsua_var.tpdata[i].is_restarting)  
     3800            if (pjsua_var.tpdata[i].data.ptr != NULL && 
     3801                pjsua_var.tpdata[i].is_restarting) 
    38083802            { 
    38093803                all_done = PJ_FALSE; 
     
    38323826    PJ_ASSERT_RETURN(param, PJ_EINVAL); 
    38333827 
     3828    for (; i < (int)PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     3829        if (pjsua_var.acc[i].valid && 
     3830            pjsua_var.acc[i].ip_change_op != PJSUA_IP_CHANGE_OP_NULL && 
     3831            pjsua_var.acc[i].ip_change_op != PJSUA_IP_CHANGE_OP_COMPLETED) 
     3832        { 
     3833            PJ_LOG(2, (THIS_FILE, 
     3834                     "Previous IP address change handling still in progress")); 
     3835        } 
     3836    } 
     3837 
    38343838    PJ_LOG(3, (THIS_FILE, "Start handling IP address change")); 
    3835      
    38363839    if (param->restart_listener) { 
    38373840        PJSUA_LOCK(); 
     
    38463849        } 
    38473850        for (i = 0; i < PJ_ARRAY_SIZE(pjsua_var.tpdata); ++i) { 
    3848             if (pjsua_var.tpdata[i].data.ptr != NULL) {          
     3851            if (pjsua_var.tpdata[i].data.ptr != NULL) { 
    38493852                status = restart_listener(i, param->restart_lis_delay); 
    38503853            } 
Note: See TracChangeset for help on using the changeset viewer.