hnimminh / libresbc

An open source Session Border Controller 🌟 The SBC you dream about 🗽 LibreSBC will help you save thousands of dollars.
https://github.com/hnimminh/libresbc
MIT License
357 stars 80 forks source link

[BUG] Translation rules not working when escaped + sign included #76

Closed WEBudoGT closed 1 year ago

WEBudoGT commented 1 year ago

Describe the bug When the number_pattern (caller or destination) includes a + sign (in E.164 format) it never matches.

To Reproduce Create a translation class like the following: { "name": "anyName", "desc": "Localize Caller ID", "caller_number_pattern": "^+?502([0-9]{8})$", "destination_number_pattern": "", "caller_number_replacement": "${1}", "destination_number_replacement": "", "caller_name": "_caller_number" } Make a call using inbound interconnection that has your "anyName" defined in "translation_classes" list with a device that has a caller ID that matches pattern.

Actual behavior The CallerID is not changed on the outcome, and logs show there are no translations for the call like in the following example:

2022-11-10T04:44:48.733597+00:00 ny3sbc program=libresbc, pid=784, module=callng, space=main, action=translate, seshid=f4544848-60fd-437b-b6f4-8050d3ea68ef, direction=inbound, uuid=c3943970-f9ed-450d-95de-ed17585f1dd5, tranrules=[], cidnumber=+50212345678, cidname=Name, dstnumber=50298765432

Expected behavior Translation rule being applied.

Log & Screenshots I guessed that the + sign must be escaped for the PCRE REGEX to match, but if trying to add it using "^\+?502([0-9]{8})$" on the API I get:

"msg": "Invalid \\escape: line 4 column 32 (char 121)",
"type": "value_error.jsondecode",

Trying to escape it twice "^\\+?502([0-9]{8})$" is accepted on the API request, but also stored as double\\

Also tried to add it directly to redis using redis-cli:

hset class:translation:anyName caller_number_pattern '^\+?502([0-9]{8})$'
(integer) 0
hget class:translation:anyName caller_number_pattern
"^\\+?502([0-9]{8})$"

It gets stored with double quotes

Additional context

hnimminh commented 1 year ago

@WEBudoGT Does translation work after adding double \\ ?

WEBudoGT commented 1 year ago

Hello Hnimminh

No, it doesn't

On Thu, Nov 10, 2022, 1:42 AM Minh @.***> wrote:

@WEBudoGT https://github.com/WEBudoGT Does translation work after adding double \ ?

— Reply to this email directly, view it on GitHub https://github.com/hnimminh/libresbc/issues/76#issuecomment-1309891943, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMPHOGRJ25OTJBMY5ODPVMTWHSRPXANCNFSM6AAAAAAR4E6YAY . You are receiving this because you were mentioned.Message ID: @.***>

hnimminh commented 1 year ago

Did you assign that translation profile to the interconnection? and try with % instead of $ "caller_number_replacement": "%{1}"

WEBudoGT commented 1 year ago

I'm very sorry @hnimminh Yes it works! No need to change the $ by % So using double backslash works just fine. Thanks!!! :D

hnimminh commented 1 year ago

@WEBudoGT I'm going to add the list of organization/company who are using LibreSBC into repo, and I really need your help to completed it. Can you tell me if you're using libresbc by commenting here or send email to me hnimminh [at] outlook [dot] com.

Appreciate for your help!