Re: RTJson current selected route
Sergio Charrua via sr-users <[email protected]>
| Newsgroups | gmane.comp.voip.ser |
|---|---|
| Message-ID | <CALZWR5wRbOfXeciUenVYUCT+OfZG_EQtCN1NrE2X6Ts37M5=cQ@mail.gmail.com> |
Thanks for the suggestion, i will take a look at it.
Meanwhile, I thought doing something like adding following lines in the
route block where Kamailio gets a response from the REST API:
# Store the full JSON for later access
> $dlg_var(route_json) = $var(rtjson);
>
> # Initialize route index tracking
> $dlg_var(current_route_idx) = 0;
>
> # Parse and store route count
> jansson_get("routing.routes", $var(rtjson), "$var(routes_array)");
> if ($var(routes_array) != $null) {
> jansson_array_size("routes", $var(routes_array),
> "$var(total_routes)");
> $dlg_var(total_routes) = $var(total_routes);
> xlog("L_INFO", "Total routes available: $var(total_routes)\n");
> }
# Use rtjson to process the routes
> if (!rtjson_init_routes($var(rtjson))) {
> xlog("L_ERROR", "Failed to initialize routes from JSON\n");
> t_reply("500", "Routing Configuration Error");
> exit;
> }
> # Set failure route for handling failed attempts
> t_on_failure("ROUTE_FAILURE");
> t_on_reply("REPLY_HANDLER");
> t_on_branch("PER_BRANCH_ROUTE");
>
> # Extract current route info before relay
> # and do some voodoo ....
.....
>
# Try the first route
> if (!rtjson_push_routes()) {
> xlog("L_ERROR", "Failed to push routes\n");
> t_reply("500", "Routing Error");
> exit;
> }
>
> # Relay the INVITE
if (!t_relay()) {
> # First route failed immediately
> route(NOTIFY_ROUTE_FAILURE_ASYNC);
>
> # Increment route index
> $dlg_var(current_route_idx) = $dlg_var(current_route_idx) + 1;
>
> if (!rtjson_next_route()) {
> t_reply("503", "Service Unavailable");
> exit;
}
But honestly I would expect some fancy method that could simplify all the
above lines, like a RTJson variable returning current route index and (why
not?) a method returning the JSON part of the current route being
processed. Maybe this could be a nice feature for the next release ....
( my C/C++ experiences stopped +30 years ago..... Borland ruled back then!
.... Yeah, i'm that old :) )
Atenciosamente / Kind Regards / Cordialement / Un saludo,
*Sérgio Charrua*
On Tue, Jun 17, 2025 at 9:00 PM Daniel-Constantin Mierla <[email protected]>
wrote:
> Hello,
>
> probably you can leverage $T_branch_index in a branch_route (or
> falure_route).
>
> Cheers,
> Daniel
> On 17.06.25 17:08, Sergio Charrua via sr-users wrote:
>
> Just having a function that returns the current route from the RTJson
> object would be enough for me.... once I get it, I can parse the json
> object, modify/remove headers as needed and then relay the call.
>
> If there is no function/method/static variable available in the module,
> wouldn't that make sense to have it? just asking....
>
>
> Atenciosamente / Kind Regards / Cordialement / Un saludo,
>
>
> *Sérgio Charrua*
>
>
>
> On Tue, Jun 17, 2025 at 3:43 PM Alex Balashov via sr-users <
> [email protected]> wrote:
>
>> It sounds like your use-case might require going outside the boundaries
>> of the `rtjson` formula, and perhaps retrieving and consuming a JSON route
>> set manually.
>>
>> > On Jun 17, 2025, at 10:06 AM, Sergio Charrua via sr-users <
>> [email protected]> wrote:
>> >
>> > Hi all!
>> >
>> > doing some integrations with RTJson module for Kamailio 5.8.4, calling
>> a REST API to return the RTJson's JSON object with 1 or multiple route
>> elements.
>> > Kamailio converts the whole SIP headers to JSON using a Javascript
>> function, executed by APP_JDST module, and POSTing the resulting object to
>> the REST API via http_async module.
>> >
>> > I couldn't find a way to get the current selected route, from the
>> RTJson object, once Kamailio iterates through the JSON object (i.e: using
>> rtjson_push_routes or rtjson_next_route).
>> >
>> > When the RTJson module iterates through the different routes of the
>> JSON object, is there a way to get the JSON part that defines the route
>> currently being used by RTJson?
>> >
>> > The goal is to return some custom properties set in each route element
>> of the route array.
>> > Once those properties are returned, Kamailio should process them.
>> > For example, RTJson supports From and To headers modification and
>> appending new headers with the "extras" element, but there is no way that I
>> know of to modify other headers or remove headers depending on the route.
>> >
>> > Does anyone know how:
>> > 1 - to return current route element from the routes array of the RTJson
>> object ?
>> > 2 - to modify / remove headers other than the From and To headers,
>> according to the custom values set in the RTJson returned from a REST API ?
>> >
>> > Thanks in advance!
>> >
>> > Atenciosamente / Kind Regards / Cordialement / Un saludo,
>> >
>> > Sérgio Charrua
>> > __________________________________________________________
>> > Kamailio - Users Mailing List - Non Commercial Discussions --
>> [email protected]
>> > To unsubscribe send an email to [email protected]
>> > Important: keep the mailing list in the recipients, do not reply only
>> to the sender!
>>
>> --
>> Alex Balashov
>> Principal Consultant
>> Evariste Systems LLC
>> Web: https://evaristesys.com, https://www.csrpswitch.com
>> Tel: +1-706-510-6800
>>
>> __________________________________________________________
>> Kamailio - Users Mailing List - Non Commercial Discussions --
>> [email protected]
>> To unsubscribe send an email to [email protected]
>> Important: keep the mailing list in the recipients, do not reply only to
>> the sender!
>>
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions -- [email protected]
> To unsubscribe send an email to [email protected]
> Important: keep the mailing list in the recipients, do not reply only to the sender!
>
> --
> Daniel-Constantin Mierla (@ asipto.com)twitter.com/miconda -- linkedin.com/in/miconda
> Kamailio Consultancy, Training and Development Services -- asipto.com
> Kamailio Scalability Training - Online, June 16-19, 2025 -- asipto.com
>
>
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the sender!