/*! \brief the term_impu_registered() function * Return true if the AOR in the Request-URI for the terminating user is registered */ int term_impu_registered(struct sip_msg* _m, char* _t, char* _s) { //str uri, aor; struct sip_msg *req; int i; str uri; impurecord_t* r; int res; // if (_m->new_uri.s) uri = _m->new_uri; // else uri = _m->first_line.u.request.uri; // // if (extract_aor(&uri, &aor) < 0) { // LM_ERR("failed to extract address of record\n"); // return -1; // } req = _m; if (!req){ LM_ERR(":term_impu_registered: NULL message!!!\n"); return -1; } if (req->first_line.type!=SIP_REQUEST){ req = get_request_from_reply(req); } if (_m->new_uri.s) uri = _m->new_uri; else uri = _m->first_line.u.request.uri; for(i=0;i<uri.len;i++) if (uri.s[i]==';' || uri.s[i]=='?') { uri.len = i; break; } LM_DBG("term_impu_registered: Looking for <%.*s>\n",uri.len,uri.s); ul.lock_udomain((udomain_t*)_t, &uri); res = ul.get_impurecord((udomain_t*)_t, &uri, &r); if (res < 0) { ul.unlock_udomain((udomain_t*)_t, &uri); LM_ERR("failed to query for terminating IMPU <%.*s>\n", uri.len, uri.s); return -1; } if (res == 0) { //ul.release_impurecord(r); ul.unlock_udomain((udomain_t*) _t, &uri); LM_DBG("'%.*s' found in usrloc\n", uri.len, ZSW(uri.s)); return 1; } ul.unlock_udomain((udomain_t*)_t, &uri); LM_DBG("'%.*s' not found in usrloc\n", uri.len, ZSW(uri.s)); return -1; }
int assert_called_identity(struct sip_msg* _m, udomain_t* _d) { int ret=CSCF_RETURN_FALSE; str called_party_id={0,0},x={0,0}; struct sip_msg* req; struct hdr_field *h=0; //get request from reply req = get_request_from_reply(_m); if (!req) { LM_ERR("Unable to get request from reply for REGISTER. No transaction\n"); goto error; } called_party_id = cscf_get_public_identity_from_called_party_id(req, &h); if (!called_party_id.len){ goto error; }else{ LM_DBG("Called Party ID from request: %.*s\n", called_party_id.len, called_party_id.s); x.len = p_asserted_identity_s.len+p_asserted_identity_m.len+called_party_id.len+p_asserted_identity_e.len; x.s = pkg_malloc(x.len); if (!x.s){ LM_ERR("P_assert_called_identity: Error allocating %d bytes\n", x.len); x.len=0; goto error; } x.len=0; STR_APPEND(x,p_asserted_identity_s); STR_APPEND(x,p_asserted_identity_m); STR_APPEND(x,called_party_id); STR_APPEND(x,p_asserted_identity_e); if (cscf_add_header(_m,&x,HDR_OTHER_T)) ret = CSCF_RETURN_TRUE; else goto error; } return ret; error: ret=CSCF_RETURN_FALSE; return ret; }
/** * Save the contacts and their associated public ids. * @param rpl - the SIP Register 200 OK response that contains the Expire and Contact and P-associated-uri headers * @param _d - domain * @param _cflags - flags * @returns #CSCF_RETURN_TRUE if OK, #CSCF_RETURN_ERROR on error */ int save(struct sip_msg* _m, udomain_t* _d, int _cflags) { struct sip_msg* req; int expires_hdr = 0; contact_body_t* cb = 0; str *public_ids=0; int num_public_ids = 0; str *service_routes=0; int num_service_routes = 0; pv_elem_t *presentity_uri_pv; //get request from reply req = get_request_from_reply(_m); if (!req) { LM_ERR("Unable to get request from reply for REGISTER. No transaction\n"); goto error; } expires_hdr = cscf_get_expires_hdr(_m, 0); cb = cscf_parse_contacts(_m); if (!cb || (!cb->contacts && !cb->star)) { LM_DBG("No contact headers and not *\n"); goto error; } cscf_get_p_associated_uri(_m, &public_ids, &num_public_ids, 1); service_routes = cscf_get_service_route(_m, &num_service_routes, 1); //update contacts if (!update_contacts(req, _m, _d, cb->star, expires_hdr, public_ids, num_public_ids, service_routes, num_service_routes, 0)) { LM_ERR("failed to update pcontact\n"); goto error; } if(subscribe_to_reginfo == 1){ //use the first p_associated_uri - i.e. the default IMPU LM_DBG("Subscribe to reg event for primary p_associated_uri"); if(num_public_ids > 0){ //find the first routable (not a tel: URI and use that that presentity) //if you can not find one then exit int i = 0; int found_presentity_uri=0; while (i < num_public_ids && found_presentity_uri == 0) { //check if public_id[i] is NOT a tel URI - if it isn't then concert to pv format and set found presentity_uri to 1 if (strncasecmp(public_ids[i].s,"tel:",4)==0) { LM_DBG("This is a tel URI - it is not routable so we don't use it to subscribe"); i++; } else { //convert primary p_associated_uri to pv_elem_t if(pv_parse_format(&public_ids[i], &presentity_uri_pv)<0) { LM_ERR("wrong format[%.*s]\n",public_ids[i].len, public_ids[i].s); goto error; } found_presentity_uri=1; } } if(found_presentity_uri!=1){ LM_ERR("Could not find routable URI in p_assoiated_uri list - failed to subscribe"); goto error; } }else{ //Now some how check if there is a pua record and what the presentity uri is from there - if nothing there LM_DBG("No p_associated_uri in 200 OK this must be a de-register - we ignore this - will unsubscribe when the notify is received"); goto done; } reginfo_subscribe_real(_m, presentity_uri_pv, service_routes, subscription_expires); pv_elem_free_all(presentity_uri_pv); } done: if (public_ids && public_ids->s) pkg_free(public_ids); if (service_routes && service_routes->s) pkg_free(service_routes); return 1; error: if (public_ids && public_ids->s) pkg_free(public_ids); if (service_routes && service_routes->s) pkg_free(service_routes); return -1; }