/** * Looks for the P-Asserted-Identity header and extracts its content * @param msg - the sip message * @returns the asserted identity */ str cscf_get_asserted_identity(struct sip_msg *msg, int is_shm) { int len; str uri = { 0, 0 }; if (!msg || !msg->pai) return uri; if ((parse_pai_header(msg) == 0) && (msg->pai) && (msg->pai->parsed)) { to_body_t *pai = get_pai(msg)->id; if (!is_shm) return pai->uri; //make a pkg malloc str to return to consuming function len = pai->uri.len + 1; uri.s = (char*) pkg_malloc(pai->uri.len + 1); if (!uri.s) { LM_ERR("no more pkg mem\n"); return uri; } memset(uri.s, 0, len); memcpy(uri.s, pai->uri.s, pai->uri.len); uri.len = pai->uri.len; p_id_body_t* ptr = (p_id_body_t*) msg->pai->parsed; msg->pai->parsed = 0; free_pai_ppi_body(ptr); } return uri; }
/* * Get user part from P-Asserted-Identity header * param msg SIP message * param user User part of P-Asserted-Identity header * param bufsize Size of fromuser buffer * return 0 success, 1 without PAI, -1 failure */ int ospGetPaiUserpart( struct sip_msg* msg, char* paiuser, int bufsize) { struct to_body* pai; struct sip_uri uri; int result = -1; if ((paiuser != NULL) && (bufsize > 0)) { paiuser[0] = '\0'; if (msg->pai != NULL) { if (parse_pai_header(msg) == 0) { pai = get_pai(msg); if (parse_uri(pai->uri.s, pai->uri.len, &uri) == 0) { ospCopyStrToBuffer(&uri.user, paiuser, bufsize); ospSkipUserParam(paiuser); result = 0; } else { LM_ERR("failed to parse PAI uri\n"); } } else { LM_ERR("failed to parse PAI uri\n"); } } else { LM_DBG("without PAI header\n"); result = 1; } } else { LM_ERR("bad parameters to parse user part from PAI\n"); } return result; }