diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c index e3cf32db10d35aee0fde9c640ff9df5b595db838..13a86f93a9dcf8d85fcce51187b76495bbb3290f 100644 --- a/res/res_pjsip_outbound_registration.c +++ b/res/res_pjsip_outbound_registration.c @@ -1369,6 +1369,26 @@ static int handle_registration_response(void *data) return 0; } +/*! \brief The function validates the expiration period set when 200 OK is received for REGISTER */ +static void sip_outbound_registration_get_expiration(struct pjsip_regc_cbparam *param, pjsip_contact_hdr *register_contact, int *expiration) +{ + if (!param || !register_contact || !expiration) + return; + + pjsip_sip_uri *register_contact_uri = pjsip_uri_get_uri(register_contact->uri); + if (register_contact_uri) { + for (int i = 0; i < param->contact_cnt; i++) { + pjsip_sip_uri *response_contact_uri = pjsip_uri_get_uri(param->contact[i]->uri); + + if (pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, register_contact_uri, response_contact_uri) == PJ_SUCCESS) { + *expiration = (int)param->contact[i]->expires; + return; + } + } + } + +} + /*! \brief Callback function for outbound registration client */ static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *param) { @@ -1390,6 +1410,12 @@ static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *par } response->code = param->code; response->expiration = param->expiration; + + if (param->code == 200 && client_state->last_tdata) { + pjsip_contact_hdr *register_contact = pjsip_msg_find_hdr(client_state->last_tdata->msg, PJSIP_H_CONTACT, NULL); + sip_outbound_registration_get_expiration(param, register_contact, &response->expiration); + } + /* * Transfer client_state reference to response so the * nominal path will not dec the client_state ref in this