[OpenSIPS-Devel] Weirs param parsing - MI

Daniel Zanutti daniel.zanutti at gmail.com
Mon Jul 11 18:35:48 CEST 2016


Voila!

atoi was messing things:
Jul 11 13:29:14 plat1 /sbin/opensips[30500]: ERROR:custom_check
:mi_custom_check:
XXX value: '65'
Jul 11 13:29:14 plat1 /sbin/opensips[30500]: ERROR:custom_check
:mi_custom_check:
XXX value: '5000'
Jul 11 13:29:14 plat1 /sbin/opensips[30500]: ERROR:custom_check
:mi_custom_check:
XXX value: '100000'

I didn't consider the pointer may not have a null at the end, you're
absolutely correct.

Thanks Liviu

On Mon, Jul 11, 2016 at 5:46 AM, Liviu Chircu <liviu at opensips.org> wrote:

> Hi Daniel!
>
> The majority of OpenSIPS's codebase relies on "str"-based strings, which
> are basically both a memory and performance optimization, but they make
> programming/debugging more difficult, since most of them will not be
> NULL-terminated anymore, making you unable to use half (if not more) of
> glibc's string processing functions.
>
> atoi() may very well be one of the above cases. In order to confirm this,
> could you print each of your 3 values before feeding it to atoi()?
>
> ...
> LM_INFO("XXX value: '%.*s'\n", node->value.len, node->value.s);
> ...
>
> Liviu Chircu
> OpenSIPS Developerhttp://www.opensips-solutions.com
>
> On 09.07.2016 23:26, Daniel Zanutti wrote:
>
> I'm trying to read 3 integers parameters from MI, but Opensips is for some
> reason combining 2 values.
>
> This is the command: opensipsctl fifo custom_check 10 2000 50000
>
> For some reason, I'm getting these values on the nodes:
> val1 = 10
> val2 = 200050000
> val3 = 50000
>
> This is the summarized code:
>
> struct mi_root * custom_check(struct mi_root *cmd_tree, void *param )
> {
> struct mi_node* node;
>         int val1, val2, val3;
>
> node = cmd_tree->node.kids;
> if (!node->value.s || !node->value.len)
> return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM));
> val1 = atoi(node->value.s);
>
> node = node->next;
> if ( !node->value.s || !node->value.len)
> return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM));
> val2 = atoi(node->value.s);
>
> node = node->next;
> if ( !node->value.s || !node->value.len)
> return init_mi_tree( 400, MI_SSTR(MI_BAD_PARM));
> val3 = atoi(node->value.s);
>         .....
> }
>
> Am I doing something wrong?
>
> Thanks in advance
>
>
> _______________________________________________
> Devel mailing listDevel at lists.opensips.orghttp://lists.opensips.org/cgi-bin/mailman/listinfo/devel
>
>
>
> _______________________________________________
> Devel mailing list
> Devel at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/devel/attachments/20160711/e0137857/attachment.htm>


More information about the Devel mailing list