Ignore:
Timestamp:
Feb 26, 2006 9:23:45 PM (18 years ago)
Author:
bennylp
Message:

Major redesign in pjsua: call is indexed by number, multiple accounts, configurable max-calls, more auto-xxx features, fixed bugs in save_settings(), etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua/pjsua_reg.c

    r201 r236  
    3535static void regc_cb(struct pjsip_regc_cbparam *param) 
    3636{ 
     37 
     38    pjsua_acc *acc = param->token; 
     39 
    3740    /* 
    3841     * Print registration status. 
     
    4144        pjsua_perror(THIS_FILE, "SIP registration error",  
    4245                     param->status); 
    43         pjsua.regc = NULL; 
     46        pjsip_regc_destroy(acc->regc); 
     47        acc->regc = NULL; 
    4448         
    4549    } else if (param->code < 0 || param->code >= 300) { 
     
    4751                   param->code,  
    4852                   pjsip_get_status_text(param->code)->ptr)); 
    49         pjsua.regc = NULL; 
     53        pjsip_regc_destroy(acc->regc); 
     54        acc->regc = NULL; 
    5055 
    5156    } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) { 
    52         PJ_LOG(3, (THIS_FILE, "SIP registration success, status=%d (%s), " 
    53                               "will re-register in %d seconds",  
    54                               param->code, 
    55                               pjsip_get_status_text(param->code)->ptr, 
    56                               param->expiration)); 
     57 
     58        if (param->expiration < 1) { 
     59            pjsip_regc_destroy(acc->regc); 
     60            acc->regc = NULL; 
     61            PJ_LOG(3,(THIS_FILE, "%s: unregistration success", 
     62                      acc->local_uri.ptr)); 
     63        } else { 
     64            PJ_LOG(3, (THIS_FILE,  
     65                       "%s: registration success, status=%d (%s), " 
     66                       "will re-register in %d seconds",  
     67                       acc->local_uri.ptr, 
     68                       param->code, 
     69                       pjsip_get_status_text(param->code)->ptr, 
     70                       param->expiration)); 
     71        } 
    5772 
    5873    } else { 
     
    6075    } 
    6176 
    62     pjsua.regc_last_err = param->status; 
    63     pjsua.regc_last_code = param->code; 
     77    acc->reg_last_err = param->status; 
     78    acc->reg_last_code = param->code; 
    6479 
    65     pjsua_ui_regc_on_state_changed(pjsua.regc_last_code); 
     80    pjsua_ui_regc_on_state_changed(acc->index); 
    6681} 
    6782 
     
    7085 * Update registration. If renew is false, then unregistration will be performed. 
    7186 */ 
    72 void pjsua_regc_update(pj_bool_t renew) 
     87void pjsua_regc_update(int acc_index, pj_bool_t renew) 
    7388{ 
    7489    pj_status_t status; 
     
    7691 
    7792    if (renew) { 
    78         if (pjsua.regc == NULL) { 
    79             status = pjsua_regc_init(); 
     93        if (pjsua.acc[acc_index].regc == NULL) { 
     94            status = pjsua_regc_init(acc_index); 
    8095            if (status != PJ_SUCCESS) { 
    8196                pjsua_perror(THIS_FILE, "Unable to create registration",  
     
    8499            } 
    85100        } 
    86         status = pjsip_regc_register(pjsua.regc, 1, &tdata); 
     101        status = pjsip_regc_register(pjsua.acc[acc_index].regc, 1, &tdata); 
    87102    } else { 
    88         if (pjsua.regc == NULL) { 
     103        if (pjsua.acc[acc_index].regc == NULL) { 
    89104            PJ_LOG(3,(THIS_FILE, "Currently not registered")); 
    90105            return; 
    91106        } 
    92         status = pjsip_regc_unregister(pjsua.regc, &tdata); 
     107        status = pjsip_regc_unregister(pjsua.acc[acc_index].regc, &tdata); 
    93108    } 
    94109 
    95110    if (status == PJ_SUCCESS) 
    96         status = pjsip_regc_send( pjsua.regc, tdata ); 
     111        status = pjsip_regc_send( pjsua.acc[acc_index].regc, tdata ); 
    97112 
    98113    if (status != PJ_SUCCESS) { 
     
    108123 * Initialize client registration. 
    109124 */ 
    110 pj_status_t pjsua_regc_init(void) 
     125pj_status_t pjsua_regc_init(int acc_index) 
    111126{ 
    112127    pj_status_t status; 
    113128 
    114129    /* initialize SIP registration if registrar is configured */ 
    115     if (pjsua.registrar_uri.slen) { 
     130    if (pjsua.acc[acc_index].reg_uri.slen) { 
    116131 
    117         status = pjsip_regc_create( pjsua.endpt, NULL, &regc_cb, &pjsua.regc); 
     132        status = pjsip_regc_create( pjsua.endpt,  
     133                                    &pjsua.acc[acc_index],  
     134                                    &regc_cb,  
     135                                    &pjsua.acc[acc_index].regc); 
    118136 
    119137        if (status != PJ_SUCCESS) { 
     
    124142 
    125143 
    126         status = pjsip_regc_init( pjsua.regc, &pjsua.registrar_uri,  
    127                                   &pjsua.local_uri,  
    128                                   &pjsua.local_uri, 
    129                                   1, &pjsua.contact_uri,  
    130                                   pjsua.reg_timeout); 
     144        status = pjsip_regc_init( pjsua.acc[acc_index].regc,  
     145                                  &pjsua.acc[acc_index].reg_uri,  
     146                                  &pjsua.acc[acc_index].local_uri,  
     147                                  &pjsua.acc[acc_index].local_uri, 
     148                                  1, &pjsua.acc[acc_index].contact_uri,  
     149                                  pjsua.acc[acc_index].reg_timeout); 
    131150        if (status != PJ_SUCCESS) { 
    132151            pjsua_perror(THIS_FILE,  
     
    136155        } 
    137156 
    138         pjsip_regc_set_credentials( pjsua.regc, pjsua.cred_count,  
     157        pjsip_regc_set_credentials( pjsua.acc[acc_index].regc,  
     158                                    pjsua.cred_count,  
    139159                                    pjsua.cred_info ); 
    140160 
    141         pjsip_regc_set_route_set( pjsua.regc, &pjsua.route_set ); 
     161        pjsip_regc_set_route_set( pjsua.acc[acc_index].regc,  
     162                                  &pjsua.acc[acc_index].route_set ); 
    142163    } 
    143164 
Note: See TracChangeset for help on using the changeset viewer.