Hey all,
Back with more questions.
I'm using Kamailio to make an HTTP call to my API to perform authentication and message routing. Currently, I'm trying to build up the post body that I send to my API to make those decisions.
I've cherry picked a few of the headers that are important in my routing decisions. But, ideally, I'd like to just iterate over all the SIP message headers and append them as request parameters to my API call. Is this possible with Kamailio? I've been looking through the docs and can't seem to find a function to iterate the full list of headers.
Thanks in advance.
Best, Colin
Colin,
I don't see a way to do that, either, but you could just pass in the whole SIP message ($mb) to the API and decode the headers on the API backend side.
Example:
if(is_method("OPTIONS")) { xlog("L_ERR", "Message buffer = $mb\n"); ... }
sasha@peacock:~$ sipsak -T -s sip:s@10.150.20.6 warning: IP extract from warning activated to be more informational 0: ?? (4.852 ms) SIP/2.0 483 Too Many Hops (10) 1: ?? (7.730 ms) SIP/2.0 200 OK without Contact header
Jun 26 16:41:52 allegro-4 /usr/local/sbin/kamailio[29268]: [1361911286@127.0.1.1 1] ERROR: Message buffer = OPTIONS sip:s@10.150.20.6 SIP/2.0#015#012Via: SIP/2.0/UDP 127.0.1.1:43150;branch=z9hG4bK.6c27cf6b;rport;alias#015#012From: sip:sipsak@127.0.1.1:43150;tag=512d1df6#015#012To: sip:s@10.150.20.6#015#012Call-ID: 1361911286@127.0.1.1#015#012CSeq: 2 OPTIONS#015#012Contact: sip:sipsak@127.0.1.1:43150#015#012Content-Length: 0#015#012Max-Forwards: 0#015#012User-Agent: sipsak 0.9.6#015#012Accept: text/plain
-- Alex
On 26 Jun 2016, at 22:29, Colin Morelli colin.morelli@gmail.com wrote:
Hey all,
Back with more questions.
I'm using Kamailio to make an HTTP call to my API to perform authentication and message routing. Currently, I'm trying to build up the post body that I send to my API to make those decisions.
I've cherry picked a few of the headers that are important in my routing decisions. But, ideally, I'd like to just iterate over all the SIP message headers and append them as request parameters to my API call. Is this possible with Kamailio? I've been looking through the docs and can't seem to find a function to iterate the full list of headers.
Thanks in advance.
$mb
will give you the full SIP message.
/O
Yeah, I saw $mb as I was browsing through things. I was hoping to not have to re-parse the SIP message in the API since Kamailio has already done that work, and it would require some form of a SIP parser in my API.
As a future feature request, I'll say that I think this would be a helpful addition (possibly even just a function that exports all headers names to an AVP which you can then iterate as you choose). Especially as applications continue to become more dynamic in nature.
For now, I'll probably go the current route of just cherry-picking the headers that I need in my API and pushing those up.
Thanks all!
Best, Colin
On Mon, Jun 27, 2016 at 7:49 AM Olle E. Johansson oej@edvina.net wrote:
On 26 Jun 2016, at 22:29, Colin Morelli colin.morelli@gmail.com wrote:
Hey all,
Back with more questions.
I'm using Kamailio to make an HTTP call to my API to perform
authentication and message routing. Currently, I'm trying to build up the post body that I send to my API to make those decisions.
I've cherry picked a few of the headers that are important in my routing
decisions. But, ideally, I'd like to just iterate over all the SIP message headers and append them as request parameters to my API call. Is this possible with Kamailio? I've been looking through the docs and can't seem to find a function to iterate the full list of headers.
Thanks in advance.
$mb
will give you the full SIP message.
/O
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
FWIW, I think that from a security and software quality perspective, explicitly defining which headers you want to feed to the API is the much better approach anyway.
-- Alex
-- Principal, Evariste Systems LLC (www.evaristesys.com)
Sent from my Google Nexus.
I suppose there's a lot of subjectivity here - and it greatly depends on your configuration - but at least for my use case I don't quite agree with that statement. My API is already the component performing authentication and making routing decisions anyway, which means Kamailio is going to send the SIP traffic to wherever it says. Pushing a full list of headers to that endpoint doesn't compromise security any more than it already is by allowing the API to decide where that SIP message goes next. (In other words: my API is controlling SIP credentials, and if it really wanted access to the value of another header, it could simply redirect the SIP request to a server it controls).
Additionally, this means that if I need to change the routing decisions that my API makes, I have to redeploy Kamailio with configuration changes to send the new header values. This leaks implementation details of my API into a layer that really doesn't need (or want) to concern itself with that work.
Again - I fully understand that everyone's solutions here are different and this is just how it applies in my particular scenario. So I'm not intending to argue here, rather just suggesting that there are some valid use cases for it.
In any case, thanks for the response! I'm sure I'll be back with more questions as I continue to work through this.
Best, Colin
On Mon, Jun 27, 2016 at 8:00 AM Alex Balashov abalashov@evaristesys.com wrote:
FWIW, I think that from a security and software quality perspective, explicitly defining which headers you want to feed to the API is the much better approach anyway.
-- Alex
-- Principal, Evariste Systems LLC (www.evaristesys.com)
Sent from my Google Nexus.
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hello,
you can get the only the headers from sip message in the following way:
- compute the length of the sip message without the body (there are variables for message buffer len and body size, or use the s.len transformation) - use substring transformation over $mb to get only its first part of length size computed at the previous step
If you want to skip the first line and have only pure headers, then use {line.at,0) transformation over the above result to get the first line, then compute its length and again substring to skip it.
For convenience, in the devel master branch I added a new variable $msg(hdrs) which returns only the headers.
I am also considering to add an iterator to be able to walk through headers. That is even possible now by using {line.at,pos} and {s.select,...}, but with a bit more scripting inside the config file.
Cheers, Daniel
On 27/06/16 14:10, Colin Morelli wrote:
I suppose there's a lot of subjectivity here - and it greatly depends on your configuration - but at least for my use case I don't quite agree with that statement. My API is already the component performing authentication and making routing decisions anyway, which means Kamailio is going to send the SIP traffic to wherever it says. Pushing a full list of headers to that endpoint doesn't compromise security any more than it already is by allowing the API to decide where that SIP message goes next. (In other words: my API is controlling SIP credentials, and if it really wanted access to the value of another header, it could simply redirect the SIP request to a server it controls).
Additionally, this means that if I need to change the routing decisions that my API makes, I have to redeploy Kamailio with configuration changes to send the new header values. This leaks implementation details of my API into a layer that really doesn't need (or want) to concern itself with that work.
Again - I fully understand that everyone's solutions here are different and this is just how it applies in my particular scenario. So I'm not intending to argue here, rather just suggesting that there are some valid use cases for it.
In any case, thanks for the response! I'm sure I'll be back with more questions as I continue to work through this.
Best, Colin
On Mon, Jun 27, 2016 at 8:00 AM Alex Balashov <abalashov@evaristesys.com mailto:abalashov@evaristesys.com> wrote:
FWIW, I think that from a security and software quality perspective, explicitly defining which headers you want to feed to the API is the much better approach anyway. -- Alex -- Principal, Evariste Systems LLC (www.evaristesys.com <http://www.evaristesys.com>) Sent from my Google Nexus. _______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org <mailto:sr-users@lists.sip-router.org> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users