diff options
Diffstat (limited to 'pjsip/src/pjsua/pjsua_reg.c')
-rw-r--r-- | pjsip/src/pjsua/pjsua_reg.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/pjsip/src/pjsua/pjsua_reg.c b/pjsip/src/pjsua/pjsua_reg.c index 972791b1..f11ff3fd 100644 --- a/pjsip/src/pjsua/pjsua_reg.c +++ b/pjsip/src/pjsua/pjsua_reg.c @@ -37,9 +37,15 @@ static void regc_cb(struct pjsip_regc_cbparam *param) /* * Print registration status. */ - if (param->code < 0 || param->code >= 300) { + if (param->status!=PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "SIP registration error", + param->status); + pjsua.regc = NULL; + + } else if (param->code < 0 || param->code >= 300) { PJ_LOG(2, (THIS_FILE, "SIP registration failed, status=%d (%s)", - param->code, pjsip_get_status_text(param->code)->ptr)); + param->code, + pjsip_get_status_text(param->code)->ptr)); pjsua.regc = NULL; } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) { @@ -53,6 +59,7 @@ static void regc_cb(struct pjsip_regc_cbparam *param) PJ_LOG(4, (THIS_FILE, "SIP registration updated status=%d", param->code)); } + pjsua.regc_last_err = param->status; pjsua.regc_last_code = param->code; pjsua_ui_regc_on_state_changed(pjsua.regc_last_code); @@ -68,19 +75,33 @@ void pjsua_regc_update(pj_bool_t renew) pjsip_tx_data *tdata; if (renew) { - PJ_LOG(3,(THIS_FILE, "Performing SIP registration...")); + if (pjsua.regc == NULL) { + status = pjsua_regc_init(); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Unable to create registration", + status); + return; + } + } status = pjsip_regc_register(pjsua.regc, 1, &tdata); } else { - PJ_LOG(3,(THIS_FILE, "Performing SIP unregistration...")); + if (pjsua.regc == NULL) { + PJ_LOG(3,(THIS_FILE, "Currently not registered")); + return; + } status = pjsip_regc_unregister(pjsua.regc, &tdata); } + if (status == PJ_SUCCESS) + status = pjsip_regc_send( pjsua.regc, tdata ); + if (status != PJ_SUCCESS) { - pjsua_perror("Unable to create REGISTER request", status); - return; + pjsua_perror(THIS_FILE, "Unable to create/send REGISTER", + status); + } else { + PJ_LOG(3,(THIS_FILE, "%s sent", + (renew? "Registration" : "Unregistration"))); } - - pjsip_regc_send( pjsua.regc, tdata ); } /* @@ -96,7 +117,8 @@ pj_status_t pjsua_regc_init(void) status = pjsip_regc_create( pjsua.endpt, NULL, ®c_cb, &pjsua.regc); if (status != PJ_SUCCESS) { - pjsua_perror("Unable to create client registration", status); + pjsua_perror(THIS_FILE, "Unable to create client registration", + status); return status; } @@ -107,7 +129,9 @@ pj_status_t pjsua_regc_init(void) 1, &pjsua.contact_uri, pjsua.reg_timeout); if (status != PJ_SUCCESS) { - pjsua_perror("Client registration initialization error", status); + pjsua_perror(THIS_FILE, + "Client registration initialization error", + status); return status; } |