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
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O
Hi
Agreed on this - historically large parts of the IMS module code comes from the FOKUS Open Source IMS Core which I think started as an IMS specific SER branch.
The purpose of these new modules is to enable this same IMS functionality but take advantage of Kamailio's proven reliability and core functionality. Some functions, like the one you mentioned, still need to be reworked.
Regards Richard.
On 12 March 2013 14:18, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
This email is subject to the disclaimer of Smile Communications (PTY) Ltd. at http://www.smilecoms.com/disclaimer
Thanks for volunteering to clean out for us Olle ;)
On Tue, Mar 12, 2013 at 2:39 PM, Richard Good richard.good@smilecoms.comwrote:
Hi
Agreed on this - historically large parts of the IMS module code comes from the FOKUS Open Source IMS Core which I think started as an IMS specific SER branch.
The purpose of these new modules is to enable this same IMS functionality but take advantage of Kamailio's proven reliability and core functionality. Some functions, like the one you mentioned, still need to be reworked.
Regards Richard.
On 12 March 2013 14:18, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
This email is subject to the disclaimer of Smile Communications (PTY) Ltd. at http://www.smilecoms.com/disclaimer
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
12 mar 2013 kl. 14:16 skrev Jason Penton jason.penton@gmail.com:
Thanks for volunteering to clean out for us Olle ;)
You wish ;-) In this case you added a function that must exist somewhere else, since I can find headers in the config scripts... That should definitely be avoided...
/O
On Tue, Mar 12, 2013 at 2:39 PM, Richard Good richard.good@smilecoms.com wrote: Hi
Agreed on this - historically large parts of the IMS module code comes from the FOKUS Open Source IMS Core which I think started as an IMS specific SER branch.
The purpose of these new modules is to enable this same IMS functionality but take advantage of Kamailio's proven reliability and core functionality. Some functions, like the one you mentioned, still need to be reworked.
Regards Richard.
On 12 March 2013 14:18, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
This email is subject to the disclaimer of Smile Communications (PTY) Ltd. at http://www.smilecoms.com/disclaimer
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Thanks Olle,
It's one of the things we know about. The IMS library can be de-duped in a few areas but right now we are still concentrating on bug fixes and new features. Will clean when and as we have time. Of course the community is welcome to help out too when these things are spotted. For example this change probably would have been quicker to do than for the two of us to waste time on emails ;-)
cheers Jason
On Tue, Mar 12, 2013 at 3:18 PM, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 14:16 skrev Jason Penton jason.penton@gmail.com:
Thanks for volunteering to clean out for us Olle ;)
You wish ;-) In this case you added a function that must exist somewhere else, since I can find headers in the config scripts... That should definitely be avoided...
/O
On Tue, Mar 12, 2013 at 2:39 PM, Richard Good richard.good@smilecoms.comwrote:
Hi
Agreed on this - historically large parts of the IMS module code comes from the FOKUS Open Source IMS Core which I think started as an IMS specific SER branch.
The purpose of these new modules is to enable this same IMS functionality but take advantage of Kamailio's proven reliability and core functionality. Some functions, like the one you mentioned, still need to be reworked.
Regards Richard.
On 12 March 2013 14:18, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
This email is subject to the disclaimer of Smile Communications (PTY) Ltd. at http://www.smilecoms.com/disclaimer
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Hi Olle,
I just checked and this code is not in master branch (I assumed you were referring to master). You are obv. looking at my Ro branch. You can be sure that the duplication won't end up in master ;) - my private branch will be totally clean before merging. Right now however, my Ro branch is still new and incorporates code I wrote almost 2 years ago - so cleaning will come - but thanks for the heads-up
Cheers Jason
Cheers Jason
On Tue, Mar 12, 2013 at 3:25 PM, Jason Penton jason.penton@gmail.comwrote:
Thanks Olle,
It's one of the things we know about. The IMS library can be de-duped in a few areas but right now we are still concentrating on bug fixes and new features. Will clean when and as we have time. Of course the community is welcome to help out too when these things are spotted. For example this change probably would have been quicker to do than for the two of us to waste time on emails ;-)
cheers Jason
On Tue, Mar 12, 2013 at 3:18 PM, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 14:16 skrev Jason Penton jason.penton@gmail.com:
Thanks for volunteering to clean out for us Olle ;)
You wish ;-) In this case you added a function that must exist somewhere else, since I can find headers in the config scripts... That should definitely be avoided...
/O
On Tue, Mar 12, 2013 at 2:39 PM, Richard Good <richard.good@smilecoms.com
wrote:
Hi
Agreed on this - historically large parts of the IMS module code comes from the FOKUS Open Source IMS Core which I think started as an IMS specific SER branch.
The purpose of these new modules is to enable this same IMS functionality but take advantage of Kamailio's proven reliability and core functionality. Some functions, like the one you mentioned, still need to be reworked.
Regards Richard.
On 12 March 2013 14:18, Olle E. Johansson oej@edvina.net wrote:
12 mar 2013 kl. 12:31 skrev Jason Penton jason.penton@gmail.com:
+/**
- 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;
+}
Just a small philosophical note. I think we should be careful not to rebuild Kamailio in a specific "IMS" version.
Generic functions like this one doesn't belong in the IMS library, it should exist (and maybe does) in the core libraries.
Let's try to merge functionality where we can and not complicate things.
/O _______________________________________________ sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
This email is subject to the disclaimer of Smile Communications (PTY) Ltd. at http://www.smilecoms.com/disclaimer
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev