static pjsip_fromto_hdr *get_diversion_header(pjsip_rx_data *rdata) { static const pj_str_t from_name = { "From", 4 }; pjsip_generic_string_hdr *hdr; pj_str_t value; int size; if (!(hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &diversion_name, NULL))) { return NULL; } pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue); /* parse as a fromto header */ return pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr, pj_strlen(&value), &size); }
/*! \brief Helper function which validates a permanent contact */ static int permanent_contact_validate(void *data) { const char *value = data; pj_pool_t *pool; pj_str_t contact_uri; static const pj_str_t HCONTACT = { "Contact", 7 }; pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Permanent Contact Validation", 256, 256); if (!pool) { return -1; } pj_strdup2_with_null(pool, &contact_uri, value); if (!pjsip_parse_hdr(pool, &HCONTACT, contact_uri.ptr, contact_uri.slen, NULL)) { pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); return -1; } pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); return 0; }
/*! * \internal * \brief Get a P-Asserted-Identity or Remote-Party-ID header from an incoming message * * This function will parse the header as if it were a From header. This allows for us * to easily manipulate the URI, as well as add, modify, or remove parameters from the * header * * \param rdata The incoming message * \param header_name The name of the ID header to find * \retval NULL No ID header present or unable to parse ID header * \retval non-NULL The parsed ID header */ static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *header_name) { static const pj_str_t from = { "From", 4 }; pj_str_t header_content; pjsip_fromto_hdr *parsed_hdr; pjsip_generic_string_hdr *ident = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, header_name, NULL); int parsed_len; if (!ident) { return NULL; } pj_strdup_with_null(rdata->tp_info.pool, &header_content, &ident->hvalue); parsed_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from, header_content.ptr, pj_strlen(&header_content), &parsed_len); if (!parsed_hdr) { return NULL; } return parsed_hdr; }
static pj_status_t set_contact( pjsip_regc *regc, int contact_cnt, const pj_str_t contact[] ) { const pj_str_t CONTACT = { "Contact", 7 }; pjsip_contact_hdr *h; int i; /* Save existing contact list to removed_contact_hdr_list and * clear contact_hdr_list. */ pj_list_merge_last(®c->removed_contact_hdr_list, ®c->contact_hdr_list); /* Set the expiration of Contacts in to removed_contact_hdr_list * zero. */ h = regc->removed_contact_hdr_list.next; while (h != ®c->removed_contact_hdr_list) { h->expires = 0; h = h->next; } /* Process new contacts */ for (i=0; i<contact_cnt; ++i) { pjsip_contact_hdr *hdr; pj_str_t tmp; pj_strdup_with_null(regc->pool, &tmp, &contact[i]); hdr = (pjsip_contact_hdr*) pjsip_parse_hdr(regc->pool, &CONTACT, tmp.ptr, tmp.slen, NULL); if (hdr == NULL) { PJ_LOG(4,(THIS_FILE, "Invalid Contact: \"%.*s\"", (int)tmp.slen, tmp.ptr)); return PJSIP_EINVALIDURI; } /* Find the new contact in old contact list. If found, remove * the old header from the old header list. */ h = regc->removed_contact_hdr_list.next; while (h != ®c->removed_contact_hdr_list) { int rc; rc = pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, h->uri, hdr->uri); if (rc == 0) { /* Match */ pj_list_erase(h); break; } h = h->next; } /* If add_xuid_param option is enabled and Contact URI is sip/sips, * add xuid parameter to assist matching the Contact URI in the * REGISTER response later. */ if (regc->add_xuid_param && (PJSIP_URI_SCHEME_IS_SIP(hdr->uri) || PJSIP_URI_SCHEME_IS_SIPS(hdr->uri))) { pjsip_param *xuid_param; pjsip_sip_uri *sip_uri; xuid_param = PJ_POOL_ZALLOC_T(regc->pool, pjsip_param); xuid_param->name = XUID_PARAM_NAME; pj_create_unique_string(regc->pool, &xuid_param->value); sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(hdr->uri); pj_list_push_back(&sip_uri->other_param, xuid_param); } pj_list_push_back(®c->contact_hdr_list, hdr); } return PJ_SUCCESS; }
/* * Initialize a new account (after configuration is set). */ static pj_status_t initialize_acc(unsigned acc_id) { pjsua_acc_config *acc_cfg = &pjsua_var.acc[acc_id].cfg; pjsua_acc *acc = &pjsua_var.acc[acc_id]; pjsip_name_addr *name_addr; pjsip_sip_uri *sip_uri, *sip_reg_uri; pj_status_t status; unsigned i; /* Need to parse local_uri to get the elements: */ name_addr = (pjsip_name_addr*) pjsip_parse_uri(acc->pool, acc_cfg->id.ptr, acc_cfg->id.slen, PJSIP_PARSE_URI_AS_NAMEADDR); if (name_addr == NULL) { pjsua_perror(THIS_FILE, "Invalid local URI", PJSIP_EINVALIDURI); return PJSIP_EINVALIDURI; } /* Local URI MUST be a SIP or SIPS: */ if (!PJSIP_URI_SCHEME_IS_SIP(name_addr) && !PJSIP_URI_SCHEME_IS_SIPS(name_addr)) { pjsua_perror(THIS_FILE, "Invalid local URI", PJSIP_EINVALIDSCHEME); return PJSIP_EINVALIDSCHEME; } /* Get the SIP URI object: */ sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(name_addr); /* Parse registrar URI, if any */ if (acc_cfg->reg_uri.slen) { pjsip_uri *reg_uri; reg_uri = pjsip_parse_uri(acc->pool, acc_cfg->reg_uri.ptr, acc_cfg->reg_uri.slen, 0); if (reg_uri == NULL) { pjsua_perror(THIS_FILE, "Invalid registrar URI", PJSIP_EINVALIDURI); return PJSIP_EINVALIDURI; } /* Registrar URI MUST be a SIP or SIPS: */ if (!PJSIP_URI_SCHEME_IS_SIP(reg_uri) && !PJSIP_URI_SCHEME_IS_SIPS(reg_uri)) { pjsua_perror(THIS_FILE, "Invalid registar URI", PJSIP_EINVALIDSCHEME); return PJSIP_EINVALIDSCHEME; } sip_reg_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(reg_uri); } else { sip_reg_uri = NULL; } /* Save the user and domain part. These will be used when finding an * account for incoming requests. */ acc->display = name_addr->display; acc->user_part = sip_uri->user; acc->srv_domain = sip_uri->host; acc->srv_port = 0; if (sip_reg_uri) { acc->srv_port = sip_reg_uri->port; } /* Create Contact header if not present. */ //if (acc_cfg->contact.slen == 0) { // acc_cfg->contact = acc_cfg->id; //} /* Build account route-set from outbound proxies and route set from * account configuration. */ pj_list_init(&acc->route_set); for (i=0; i<pjsua_var.ua_cfg.outbound_proxy_cnt; ++i) { pj_str_t hname = { "Route", 5}; pjsip_route_hdr *r; pj_str_t tmp; pj_strdup_with_null(acc->pool, &tmp, &pjsua_var.ua_cfg.outbound_proxy[i]); r = (pjsip_route_hdr*) pjsip_parse_hdr(acc->pool, &hname, tmp.ptr, tmp.slen, NULL); if (r == NULL) { pjsua_perror(THIS_FILE, "Invalid outbound proxy URI", PJSIP_EINVALIDURI); return PJSIP_EINVALIDURI; } pj_list_push_back(&acc->route_set, r); } for (i=0; i<acc_cfg->proxy_cnt; ++i) { pj_str_t hname = { "Route", 5}; pjsip_route_hdr *r; pj_str_t tmp; pj_strdup_with_null(acc->pool, &tmp, &acc_cfg->proxy[i]); r = (pjsip_route_hdr*) pjsip_parse_hdr(acc->pool, &hname, tmp.ptr, tmp.slen, NULL); if (r == NULL) { pjsua_perror(THIS_FILE, "Invalid URI in account route set", PJ_EINVAL); return PJ_EINVAL; } pj_list_push_back(&acc->route_set, r); } /* Concatenate credentials from account config and global config */ acc->cred_cnt = 0; for (i=0; i<acc_cfg->cred_count; ++i) { acc->cred[acc->cred_cnt++] = acc_cfg->cred_info[i]; } for (i=0; i<pjsua_var.ua_cfg.cred_count && acc->cred_cnt < PJ_ARRAY_SIZE(acc->cred); ++i) { acc->cred[acc->cred_cnt++] = pjsua_var.ua_cfg.cred_info[i]; } status = pjsua_pres_init_acc(acc_id); if (status != PJ_SUCCESS) return status; /* Mark account as valid */ pjsua_var.acc[acc_id].valid = PJ_TRUE; /* Insert account ID into account ID array, sorted by priority */ for (i=0; i<pjsua_var.acc_cnt; ++i) { if ( pjsua_var.acc[pjsua_var.acc_ids[i]].cfg.priority < pjsua_var.acc[acc_id].cfg.priority) { break; } } pj_array_insert(pjsua_var.acc_ids, sizeof(pjsua_var.acc_ids[0]), pjsua_var.acc_cnt, i, &acc_id); return PJ_SUCCESS; }