[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Alex Balashov via sr-users
EVAPI is quite low-overhead.—Sent from mobile, apologies for brevity and errors.On Apr 8, 2024, at 12:34 PM, Sergio Charrua  wrote:@Alex Balashov I thought about EVAPI but I'm afraid it will bring a lot of unnecessary CPU overload, and in my case I need to have maximum CPS on this server (used for as STIR/SHAKEN with a REST API...)-Will have a try with EVAPI.Sérgio CharruaOn Mon, Apr 8, 2024 at 6:14 PM Alex Balashov via sr-users  wrote:

> On Apr 8, 2024, at 11:12 AM, Sergio Charrua via sr-users  wrote:
> 
> Also, as this is a stateless script, is there another way of using async http or making http requests to a REST API without having to use TM Module? 

You can always use an outside service, which communicates with Kamailio asynchronously via a variety of channels. See the various message brokers, EVAPI, etc.

-- 
Alex Balashov
Principal Consultant
Evariste Systems LLC
Web: https://evaristesys.com
Tel: +1-706-510-6800

__
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:

__
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:


[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Sergio Charrua via sr-users
@Alex Balashov 

I thought about EVAPI but I'm afraid it will bring a lot of unnecessary CPU
overload, and in my case I need to have maximum CPS on this server (used
for as STIR/SHAKEN with a REST API...)-
Will have a try with EVAPI.

*Sérgio Charrua*

On Mon, Apr 8, 2024 at 6:14 PM Alex Balashov via sr-users <
sr-users@lists.kamailio.org> wrote:

>
>
> > On Apr 8, 2024, at 11:12 AM, Sergio Charrua via sr-users <
> sr-users@lists.kamailio.org> wrote:
> >
> > Also, as this is a stateless script, is there another way of using async
> http or making http requests to a REST API without having to use TM Module?
>
> You can always use an outside service, which communicates with Kamailio
> asynchronously via a variety of channels. See the various message brokers,
> EVAPI, etc.
>
> --
> Alex Balashov
> Principal Consultant
> Evariste Systems LLC
> Web: https://evaristesys.com
> Tel: +1-706-510-6800
>
> __
> Kamailio - Users Mailing List - Non Commercial Discussions
> To unsubscribe send an email to sr-users-le...@lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to
> the sender!
> Edit mailing list options or unsubscribe:
>
__
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:


[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Sergio Charrua via sr-users
@Ben Kaufman :  thanks, I will try that!

@Nick Digalaks : isn't that necessary to have a correct http async
transaction? the async_http module does make/need the TM module to be
loadedand all examples I got for the async_http module had t_newtran()
method added prior to executing http request

*Sérgio Charrua*



On Mon, Apr 8, 2024 at 6:20 PM Nick Digalakis  wrote:

> I didn't test this, but why are you calling t_newtran(); if you only want
> to send the 300 response?
>
> On Apr 8, 2024 18:12, Sergio Charrua via sr-users <
> sr-users@lists.kamailio.org> wrote:
>
> Hi all!
>
>
> For testing purposes, while I am waiting for the ST/SH REST API to be
> available from other teams, I developed a small python REST API that
> returns a mockup of a JSON object with some of the required values.
> The kamailio script, completely stateless as I do not need to keep track
> of the sessions, iterates through one of the JSON branches and adds the
> destination URLs to the Contact header and replies a SIP 300 Multiple
> Choices.
> This works: the UAC does receive the SIP response with the Contacts , but
> it also receives a SIP 500 error message right after, and I can't figure
> out why. And i bet this is simple to solve
> Any clue? I'm aware I'm not processing ACK messages, but the sl_send_reply
> 403 should do the trick right? ... at least while testing
>
> Also, as this is a stateless script, is there another way of using async
> http or making http requests to a REST API without having to use TM Module?
>
> Thanks in advance.
>
> The kamailio script is has follows:
>
> #!KAMAILIO
> /* add API http timeout */
> #!define HTTP_API_TIMEOUT 5000
> #!define HTTP_API_ROUTING_ENDPOINT "http://some_python_rest_api/get_route;
> ### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
> debug=4
> log_stderror=no
> memdbg=5
> memlog=5
> log_facility=LOG_LOCAL0
> log_prefix="{$mt $hdr(CSeq) $ci} "
> /* number of SIP routing processes */
> children=2
> /* set paths to location of modules */
> loadmodule "tm.so"
> loadmodule "jsonrpcs.so"
> loadmodule "kex.so"
> loadmodule "corex.so"
> loadmodule "sl.so"
> loadmodule "db_mysql.so"
> loadmodule "rr.so"
> loadmodule "pv.so"
> loadmodule "maxfwd.so"
> loadmodule "ipops.so"
> loadmodule "textops.so"
> loadmodule "siputils.so"
> loadmodule "xlog.so"
> loadmodule "sanity.so"
> loadmodule "ctl.so"
> loadmodule "cfg_rpc.so"
> loadmodule "uac.so"
> loadmodule "counters.so"
> loadmodule "http_async_client.so"
> loadmodule "jansson.so"
> loadmodule "usrloc.so"
> /* listen addresses */
> listen=udp:10.20.0.2:5060
> listen=udp:10.20.0.2:5062
> advertised_address="10.20.0.2";
> # - http_async_client params -
> modparam("http_async_client", "workers", HTTP_ASYNC_CLIENT_WORKERS)
> modparam("http_async_client", "connection_timeout", 2000)
> request_route {
>   #route(HANDLE_DMQ);
>   route(HANDLE_OPTIONS);
>   if (is_method("INVITE"))
>   {
> xlog("L_INFO","MAIN - calling TO_CARRIER");
> route(TO_CARRIER);
> exit;
>   }
>   else{
> sl_send_reply("401","UNAUTHORIZED");
>   }
> }
> route[TO_CARRIER]{
> xlog("L_INFO","TO_CARRIER - calling RELAY_API");
> route(RELAY_API);   #Route relay
> xlog("L_INFO","TO_CARRIER - return");
> return;
> }
> # Relay request using the API (response)
> route[RELAY_API_RESPONSE] {
> xlog("L_INFO","RELAY_API_RESPONSE - got response from REST API");
> if ($http_ok==1 && $http_rs==200)
> {
> xlog("L_INFO","RELAY_API_RESPONSE - HTTP RESPONSE:
> $http_rb\n");
> if (jansson_get("json", $http_rb, "$var(json)")) {
> xlog("L_INFO","RELAY_API_RESPONSE - JSON =
> $var(json)");
> $var(count) = 0;
> jansson_array_size("routes", $var(json),
> "$var(size)");
> xlog("L_INFO","RELAY_API_RESPONSE -
> jansson_array_size");
>
>
> while ( $var(count) < $var(size) ){
>
>
> jansson_get("routes[$var(count)].headers.to.uri", $var(rtjson), "$var(v)");
>
> xlog("L_INFO","JSON - routes[$var(count)]
> - $var(v)");
>
> #$(avp(mycontacts)[$var(count)]) =
> $avp(mycontacts) + $var(v) + "\r\n";
>
> $avp(mycontacts) = $avp(mycontacts) +
> $var(v) + ";";
>
>
>
> *append_to_reply("Contact: <" + $var(v)
> +">"+ "\r\n"); /*     IS THERE A BETTER ?? . */*
>
>
>
> $var(count) = $var(count) + 1;
>
> }
>
>
> xlog("L_INFO","RELAY_API_RESPONSE - RELAY");
> xlog("L_INFO","MAIN - calling REPLY_302");
> route(REPLY_302);
> return;
> }
> }
> send_reply(500, "API Not Available - http response = $http_rs
> $http_ok");
> exit;
> }
> 

[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Nick Digalakis via sr-users
I didn't test this, but why are you calling t_newtran(); if you only want to send the 300 response? On Apr 8, 2024 18:12, Sergio Charrua via sr-users  wrote:Hi all!For testing purposes, while I am waiting for the ST/SH REST API to be available from other teams, I developed a small python REST API that returns a mockup of a JSON object with some of the required values. The kamailio script, completely stateless as I do not need to keep track of the sessions, iterates through one of the JSON branches and adds the destination URLs to the Contact header and replies a SIP 300 Multiple Choices.This works: the UAC does receive the SIP response with the Contacts , but it also receives a SIP 500 error message right after, and I can't figure out why. And i bet this is simple to solve Any clue? I'm aware I'm not processing ACK messages, but the sl_send_reply 403 should do the trick right? ... at least while testingAlso, as this is a stateless script, is there another way of using async http or making http requests to a REST API without having to use TM Module? Thanks in advance.The kamailio script is has follows:#!KAMAILIO/* add API http timeout */#!define HTTP_API_TIMEOUT 5000#!define HTTP_API_ROUTING_ENDPOINT "http://some_python_rest_api/get_route"### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERRdebug=4log_stderror=nomemdbg=5memlog=5log_facility=LOG_LOCAL0log_prefix="{$mt $hdr(CSeq) $ci} "/* number of SIP routing processes */children=2/* set paths to location of modules */loadmodule "tm.so"loadmodule "jsonrpcs.so"loadmodule "kex.so"loadmodule "corex.so"loadmodule "sl.so"loadmodule "db_mysql.so"loadmodule "rr.so"loadmodule "pv.so"loadmodule "maxfwd.so"loadmodule "ipops.so"loadmodule "textops.so"loadmodule "siputils.so"loadmodule "xlog.so"loadmodule "sanity.so"loadmodule "ctl.so"loadmodule "cfg_rpc.so"loadmodule "uac.so"loadmodule "counters.so"loadmodule "http_async_client.so"loadmodule "jansson.so"loadmodule "usrloc.so"/* listen addresses */listen=udp:10.20.0.2:5060listen=udp:10.20.0.2:5062advertised_address="10.20.0.2";# - http_async_client params -modparam("http_async_client", "workers", HTTP_ASYNC_CLIENT_WORKERS)modparam("http_async_client", "connection_timeout", 2000)request_route {  #route(HANDLE_DMQ);  route(HANDLE_OPTIONS);  if (is_method("INVITE"))  {    xlog("L_INFO","MAIN - calling TO_CARRIER");    route(TO_CARRIER);    exit;  }  else{        sl_send_reply("401","UNAUTHORIZED");  }}route[TO_CARRIER]{        xlog("L_INFO","TO_CARRIER - calling RELAY_API");        route(RELAY_API);                   #Route relay        xlog("L_INFO","TO_CARRIER - return");        return;}# Relay request using the API (response)route[RELAY_API_RESPONSE] {    xlog("L_INFO","RELAY_API_RESPONSE - got response from REST API");        if ($http_ok==1 && $http_rs==200)        {                xlog("L_INFO","RELAY_API_RESPONSE - HTTP RESPONSE: $http_rb\n");                if (jansson_get("json", $http_rb, "$var(json)")) {                        xlog("L_INFO","RELAY_API_RESPONSE - JSON = $var(json)");                        $var(count) = 0;                        jansson_array_size("routes", $var(json), "$var(size)");                        xlog("L_INFO","RELAY_API_RESPONSE - jansson_array_size");                                            while ( $var(count) < $var(size) ){                                jansson_get("routes[$var(count)].headers.to.uri", $var(rtjson), "$var(v)");                                xlog("L_INFO","JSON - routes[$var(count)] - $var(v)");                                #$(avp(mycontacts)[$var(count)]) = $avp(mycontacts) + $var(v) + "\r\n";                                $avp(mycontacts) = $avp(mycontacts) + $var(v) + ";";                                 append_to_reply("Contact: <" + $var(v)  +">"+ "\r\n"); /*     IS THERE A BETTER ?? . */                                 $var(count) = $var(count) + 1;                        }                                                xlog("L_INFO","RELAY_API_RESPONSE - RELAY");                        xlog("L_INFO","MAIN - calling REPLY_302");                        route(REPLY_302);                        return;                }        }        send_reply(500, "API Not Available - http response = $http_rs $http_ok");        exit;}route[RELAY_API] {        xlog("L_INFO","RELAY_API - from_ip $si:$sp from_number $fU to_number $ru");        $http_req(all) = $null;        $http_req(suspend) = 1;        $http_req(timeout) = HTTP_API_TIMEOUT;        $http_req(method) = "POST";        $http_req(hdr) = "Content-Type: application/json";        jansson_set("string","from_ip",$si, "$var(http_routing_query)");        jansson_set("string","from_port",$sp, "$var(http_routing_query)");        jansson_set("string","from_number",$fU, "$var(http_routing_query)");        jansson_set("string","to_number",$ru , "$var(http_routing_query)");        xlog("L_INFO","RELAY_API - API ASYNC ROUTING REQUEST: $var(http_routing_query)\n");        $http_req(body) = 

[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Ben Kaufman via sr-users
> The kamailio script, completely stateless as I do not need to keep track of 
> the sessions, iterates through one of the JSON branches and adds the 
> destination URLs to the Contact header and replies a SIP 300 Multiple Choices.


The term 'stateless' in the scope of a SIP proxy doesn't mean to keep track of 
the session (or the dialog).  It means tracking the state of the transaction.  
In order to pause the current transaction and resume it (using 
http_async_query()), a stateful transaction must be created within Kamailio - 
and you've done this when you call `t_newtran()`.  As a recommendation, rather 
than using `sl_send_reply()`, `t_reply()`, or `t_send_reply()`, just  use 
`send_reply()`, which will send the reply statelessly if there's no 
transaction, and statefully if there is a transaction.


If you want to make your replies LOOK stateless to request source, disable 
automatic 100 Trying from the TM module.



Kaufman
Senior Voice Engineer



E: bkauf...@bcmone.com




SIP.US Client Support: 800.566.9810  |  SIPTRUNK Client Support: 800.250.6510  
|  Flowroute Client Support: 855.356.9768
[img]
[img]
[img]


From: Sergio Charrua via sr-users 
Sent: Monday, April 8, 2024 10:13 AM
To: Kamailio (SER) - Users Mailing List 
Cc: Sergio Charrua 
Subject: [SR-Users] making HTTP requests in stateless redirects


CAUTION: This email originated from outside the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.

Hi all!


For testing purposes, while I am waiting for the ST/SH REST API to be available 
from other teams, I developed a small python REST API that returns a mockup of 
a JSON object with some of the required values.
The kamailio script, completely stateless as I do not need to keep track of the 
sessions, iterates through one of the JSON branches and adds the destination 
URLs to the Contact header and replies a SIP 300 Multiple Choices.
This works: the UAC does receive the SIP response with the Contacts , but it 
also receives a SIP 500 error message right after, and I can't figure out why. 
And i bet this is simple to solve
Any clue? I'm aware I'm not processing ACK messages, but the sl_send_reply 403 
should do the trick right? ... at least while testing

Also, as this is a stateless script, is there another way of using async http 
or making http requests to a REST API without having to use TM Module?

Thanks in advance.

The kamailio script is has follows:

#!KAMAILIO
/* add API http timeout */
#!define HTTP_API_TIMEOUT 5000
#!define HTTP_API_ROUTING_ENDPOINT "http://some_python_rest_api/get_route;
### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
debug=4
log_stderror=no
memdbg=5
memlog=5
log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "
/* number of SIP routing processes */
children=2
/* set paths to location of modules */
loadmodule "tm.so"
loadmodule "jsonrpcs.so"
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "sl.so"
loadmodule "db_mysql.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "ipops.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "uac.so"
loadmodule "counters.so"
loadmodule "http_async_client.so"
loadmodule "jansson.so"
loadmodule "usrloc.so"
/* listen addresses */
listen=udp:10.20.0.2:5060
listen=udp:10.20.0.2:5062
advertised_address="10.20.0.2";
# - http_async_client params -
modparam("http_async_client", "workers", HTTP_ASYNC_CLIENT_WORKERS)
modparam("http_async_client", "connection_timeout", 2000)
request_route {
  #route(HANDLE_DMQ);
  route(HANDLE_OPTIONS);
  if (is_method("INVITE"))
  {
xlog("L_INFO","MAIN - calling TO_CARRIER");
route(TO_CARRIER);
exit;
  }
  else{
sl_send_reply("401","UNAUTHORIZED");
  }
}
route[TO_CARRIER]{
xlog("L_INFO","TO_CARRIER - calling RELAY_API");
route(RELAY_API);   #Route relay
xlog("L_INFO","TO_CARRIER - return");
return;
}
# Relay request using the API (response)
route[RELAY_API_RESPONSE] {
xlog("L_INFO","RELAY_API_RESPONSE - got response from REST API");
if ($http_ok==1 && $http_rs==200)
{
xlog("L_INFO","RELAY_API_RESPONSE - HTTP RESPONSE: $http_rb\n");
if (jansson_get("json", $http_rb, "$var(json)")) {
xlog("L_INFO","RELAY_API_RESPONSE - JSON = $var(json)");
$var(count) = 0;
jansson_array_size("routes", $var(json), "$var(size)");
xlog("L_INFO","RELAY_API_RESPONSE - 
jansson_array_size");

while ( $var(count) < $var(size) ){

jansson_get("routes[$var(count)].headers.to.uri", $var(rtjson), "$var(v)");

[SR-Users] Re: making HTTP requests in stateless redirects

2024-04-08 Thread Alex Balashov via sr-users


> On Apr 8, 2024, at 11:12 AM, Sergio Charrua via sr-users 
>  wrote:
> 
> Also, as this is a stateless script, is there another way of using async http 
> or making http requests to a REST API without having to use TM Module? 

You can always use an outside service, which communicates with Kamailio 
asynchronously via a variety of channels. See the various message brokers, 
EVAPI, etc.

-- 
Alex Balashov
Principal Consultant
Evariste Systems LLC
Web: https://evaristesys.com
Tel: +1-706-510-6800

__
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe: