Module: sip-router Branch: jason.penton/ims_ro_interface Commit: 9e7dd6ffd0467e7c1f8f60ea20204e87b472bd14 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9e7dd6ff...
Author: Jason Penton jason.penton@smilecoms.com Committer: Jason Penton jason.penton@smilecoms.com Date: Tue Mar 12 13:20:34 2013 +0200
lib/ims: added function to get p-charging-vector
---
lib/ims/ims_getters.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/ims/ims_getters.h | 16 +++++++ 2 files changed, 135 insertions(+), 0 deletions(-)
diff --git a/lib/ims/ims_getters.c b/lib/ims/ims_getters.c index d1c84c7..94efe20 100644 --- a/lib/ims/ims_getters.c +++ b/lib/ims/ims_getters.c @@ -1399,3 +1399,122 @@ int cscf_get_cseq(struct sip_msg *msg,struct hdr_field **hr) return nr; }
+/** + * Returns the first header structure for a given header name. + * @param msg - the SIP message to look into + * @param header_name - the name of the header to search for + * @returns the hdr_field on success or NULL if not found + */ +struct hdr_field* cscf_get_header(struct sip_msg * msg, str header_name) { + struct hdr_field *h; + if (parse_headers(msg, HDR_EOH_F, 0) < 0) { + LM_ERR("cscf_get_path: error parsing headers\n"); + return NULL ; + } + h = msg->headers; + while (h) { + if (h->name.len == header_name.len + && strncasecmp(h->name.s, header_name.s, header_name.len) == 0) + break; + h = h->next; + } + return h; +} + + +static str p_charging_vector = {"P-Charging-Vector", 17}; + +int cscf_get_p_charging_vector(struct sip_msg *msg, str * icid, str * orig_ioi, + str * term_ioi) { + struct hdr_field* header = 0; + str header_body = { 0, 0 }; + char * p; + int index; + str temp = { 0, 0 }; + + LM_DBG("get_p_charging_vector\n"); + header = cscf_get_header(msg, p_charging_vector); + if (!header) { + LM_DBG("no header %.*s was found\n", p_charging_vector.len, p_charging_vector.s); + return 0; + } + if (!header->body.s || !header->body.len) + return 0; + + str_dup(header_body, header->body, pkg); + + LM_DBG("p_charging_vector body is %.*s\n", header_body.len, header_body.s); + + p = strtok(header_body.s, " ;:\r\t\n"="); + loop: if (p > (header_body.s + header_body.len)) + return 1; + + if (strncmp(p, "icid-value", 10) == 0) { + p = strtok(NULL, " ;:\r\t\n"="); + if (p > (header_body.s + header_body.len)) { + LM_ERR("cscf_get_p_charging_vector: no value for icid\n"); + return 0; + } + temp.s = p; + temp.len = 0; + while (*p != '"') { + temp.len = temp.len + 1; + p++; + } + icid->len = temp.len; + index = temp.s - header_body.s; + LM_DBG("icid len %i, index %i\n", temp.len, index); + icid->s = header->body.s + index; + LM_DBG("icid is %.*s\n", icid->len, icid->s); + p = strtok(NULL, " ;:\r\t\n"="); + goto loop; + } else if (strncmp(p, "orig-ioi", 8) == 0) { + + p = strtok(NULL, " ;:\r\t\n"="); + if (p > (header_body.s + header_body.len)) { + LM_ERR("cscf_get_p_charging_vector: no value for icid\n"); + return 0; + } + temp.s = p; + temp.len = 0; + while (*p != '"') { + temp.len = temp.len + 1; + p++; + } + orig_ioi->len = temp.len; + index = temp.s - header_body.s; + LM_DBG("orig ioi len %i, index %i\n", temp.len, index); + orig_ioi->s = header->body.s + index; + LM_DBG("orig_ioi is %.*s\n", orig_ioi->len, orig_ioi->s); + p = strtok(NULL, " ;:\r\t\n"="); + goto loop; + } else if (strncmp(p, "term-ioi", 8) == 0) { + + p = strtok(NULL, " ;:\r\t\n"="); + if (p > (header_body.s + header_body.len)) { + LM_ERR("cscf_get_p_charging_vector: no value for icid\n"); + return 0; + } + temp.s = p; + temp.len = 0; + while (*p != '"') { + temp.len = temp.len + 1; + p++; + } + term_ioi->len = temp.len; + term_ioi->s = header->body.s + (temp.s - header_body.s); + p = strtok(NULL, " ;:\r\t\n"="); + goto loop; + } else { + p = strtok(NULL, " ;:\r\t\n"="); + goto loop; + } + + LM_DBG("end\n"); + str_free(header_body, pkg); + return 1; + out_of_memory: + LM_ERR("cscf_get_p_charging_vector:out of pkg memory\n"); + return 0; +} + diff --git a/lib/ims/ims_getters.h b/lib/ims/ims_getters.h index a36e0f3..38c0dd9 100644 --- a/lib/ims/ims_getters.h +++ b/lib/ims/ims_getters.h @@ -410,5 +410,21 @@ int cscf_add_header_rpl(struct sip_msg *msg, str *hdr); */ int cscf_get_cseq(struct sip_msg *msg,struct hdr_field **hr);
+/** + * Returns the first header structure for a given header name. + * @param msg - the SIP message to look into + * @param header_name - the name of the header to search for + * @returns the hdr_field on success or NULL if not found + */ +struct hdr_field* cscf_get_header(struct sip_msg * msg, str header_name); + +/** + * Retrieves the P-Charging-Vector header information + * P-Charging-Vector: + * @param msg - the SIP message to retrieve from + * @returns #CSCF_RETURN_TRUE if ok or #CSCF_RETURN_FALSE on error + */ +int cscf_get_p_charging_vector(struct sip_msg *msg, str * icid, str * orig_ioi, str * term_ioi); + #endif