Hi, I am trying to use Kamailio specific function 'subst_str' for replacing
some media attributes in SDP in my module.
Finally I have resolved how to create 'subst_expr' structure so I can pass
it to 'subst_str' function. I am doing something like this:
struct subst_expr *seMedia;
char *pattern; asprintf(&pattern, "/m=audio
([0-9]{0,5})/m=audio %s/", _host_port.s);
str *subst;
subst = (str *) pkg_malloc(sizeof(str));
subst->s = pattern;
subst->len = strlen(pattern);
seMedia = subst_parser(subst);
int count = 0;
str *tmpBody;
char const *oldBody = (char const *) msg->body;
tmpBody = subst_str(oldBody, msg, seMedia, &count);
if (count > 0) {
// do other stuff
I am trying to replace all "m=audio {port number}" attributes with port
5060. I think that the regular expression is correct. But unfortunately in
Kamailio log I am getting something like this:
0(25049) DEBUG: <core> [re.c:329]: subst_parser(): subst_parser: ok, se is
0xb72941d8
0(25049) DEBUG: <core> [re.c:454]: subst_run(): subst_run: running. r=1
0(25049) DEBUG: <core> [re.c:523]: subst_str(): subst_str: no match
It seems like regex was not matched but after this I am printing out whole
message and I can see that in SDP 'm=audio' is present. I also noticed
another thing when I am printing out 'seMedia->replacement.s' in log I am
getting my replacement "m=audio 5060" but also at the end of the string I
can see some weird character:
[image: Inline image 1]
If someone came across this issue in the past and resolved it, it would be
great if he/she can share his/her knowledge with me because seriously this
issue is driving me crazy.
On Thu, Mar 12, 2015 at 9:17 PM, Cockhootec Yahrabee <cockootec(a)gmail.com>
wrote:
> Thanks a lot. I am sorry I didn't code with pointers quite a long time so
> I need to refresh my knowledge a bit :)
> But unfortunately it was not the main problem.
>
> In Kamailio log I am getting something like this:
>
> 0(17809) ERROR: <core> [re.c:181]: parse_repl(): subst_parser: bad
> specifier in replace part /$1 5060/gm
>
> I think, that problem is on this line
> https://gist.github.com/ivanbarlog/1b552b57e89bf4670872#file-test-c-L5
> where I am trying to use $1 as a placeholder for first matched group.
>
> I also tried it without it - just replace `m=audio` (not m=*) but it also
> didn't worked.
>
> I am also not sure if I am correctly re-transmitting updated SIP message.
> I looked at other modules which perform the same action and I tried to
> inspire with their code but unfortunately it's not working.
>
> Could you please review this code sample
> https://gist.github.com/ivanbarlog/4040ae5b735386a88ea0 ?
>
> Or maybe if you can point me to some resource where I can read more about
> it. Also it would be great if there was some tutorial for developing
> modules.
>
> Thanks for help
>
>
> On Wed, Mar 11, 2015 at 7:20 PM, Daniel-Constantin Mierla <
> miconda(a)gmail.com> wrote:
>
>> Hello,
>>
>> at least one problem is the next line in your code:
>>
>> subst->len = sizeof(pattern);
>>
>> should be:
>>
>> subst->len = strlen(pattern);
>>
>> Because patter is declared as 'char*', sizeof returns 4 or 8 (if 32b or
>> 64b architecture).
>>
>> Try with that change and see how far it goes.
>>
>> Cheers,
>> Daniel
>>
>>
>> On 11/03/15 00:43, Cockhootec Yahrabee wrote:
>>
>> Hi guys,
>> I am trying to 'search&replace' some patterns in message body but
>> unfortunately with no result (but bunch of errors).
>>
>> First of all I am trying to perform regex substitution as one that can
>> be seen at https://regex101.com/r/vF1kZ7/1
>>
>> Since I have regular expression I am trying to convert it so it will
>> work with `sub_str` function from re.h
>>
>> Here is my attempt:
>> https://gist.github.com/ivanbarlog/1b552b57e89bf4670872#file-test-c-L12
>>
>> I had quite lot of errors but last error I am getting is that
>> `subst_parser` cannot find separator
>> https://github.com/kamailio/kamailio/blob/master/re.c#L240
>>
>> Since the `struct subst_expr` is not parsed right the next error is
>> segfault in `subst_str` function.
>>
>>
>>
>> If someone can explain me how exactly I should use `subst_str` function
>> with my regex I'll be really grateful. Little example code would be also
>> great.
>>
>> Thanks in advance
>>
>>
>> _______________________________________________
>> sr-dev mailing listsr-dev@lists.sip-router.orghttp://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>
>>
>> --
>> Daniel-Constantin Mierlahttp://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
>> Kamailio World Conference, May 27-29, 2015
>> Berlin, Germany - http://www.kamailioworld.com
>>
>>
>
Query: insert into location (username,contact,expires,q,callid,cseq,flags,cflags,user_agent,received,socket,methods,last_modified,ruid,instance,reg_id,reg_id,reg_id,reg_id,domain )
---
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/117
Module: kamailio
Branch: master
Commit: 44fdfff6b407bc3d541cd43f249700a69f1e0eb8
URL: https://github.com/kamailio/kamailio/commit/44fdfff6b407bc3d541cd43f249700a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-03-28T08:57:15+01:00
usrloc: proper init column names
- reported and patch by Anthony Messina, GH#117
---
Modified: modules/usrloc/ul_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/44fdfff6b407bc3d541cd43f249700a…
Patch: https://github.com/kamailio/kamailio/commit/44fdfff6b407bc3d541cd43f249700a…
---
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index 99c8346..c5e95f8 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -140,9 +140,9 @@ str methods_col = str_init(METHODS_COL); /*!< Name of column containing the
str instance_col = str_init(INSTANCE_COL); /*!< Name of column containing the SIP instance value */
str reg_id_col = str_init(REG_ID_COL); /*!< Name of column containing the reg-id value */
str last_mod_col = str_init(LAST_MOD_COL); /*!< Name of column containing the last modified date */
-str srv_id_col = str_init(REG_ID_COL); /*!< Name of column containing the server id value */
-str con_id_col = str_init(REG_ID_COL); /*!< Name of column containing the connection id value */
-str keepalive_col = str_init(REG_ID_COL); /*!< Name of column containing the keepalive value */
+str srv_id_col = str_init(SRV_ID_COL); /*!< Name of column containing the server id value */
+str con_id_col = str_init(CON_ID_COL); /*!< Name of column containing the connection id value */
+str keepalive_col = str_init(KEEPALIVE_COL); /*!< Name of column containing the keepalive value */
str ulattrs_user_col = str_init(ULATTRS_USER_COL); /*!< Name of column containing username */
str ulattrs_domain_col = str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */