[sr-dev] Parse value from SIP message within custom module without affecting the SIP message
Cockhootec Yahrabee
cockootec at gmail.com
Fri Apr 8 11:41:17 CEST 2016
I am sorry, once again I've proved myself that it's a good thing that I am
not a C developer and my skills are still not good enough to become one -
thanks God for the high level languages :D
Of course the problem was in my function. This would be correct one:
int shm_copy_string(const char *original_string, int original_length, char
**new_string) {
// allocate shared memory for new string
*new_string = (char *) shm_malloc(sizeof(char) * (original_length + 1));
if (*new_string == NULL) {
ERR("cannot allocate shm memory");
return -1;
}
// copy original string to new string
memcpy(*new_string, original_string, original_length);
// end new string with null character
(*new_string)[original_length] = '\0';
return 0;
}
First of all I was trying to copy more than I need (original_length + 1
instead of just original_length) and once again I was little confused with
the pointers - double de-referencing always scares me ;-)
I am not sure if this will help somebody in the future but still I hope
that anyone do the same error as me.
Have a nice day folks
On Thu, Apr 7, 2016 at 9:28 PM, Cockhootec Yahrabee <cockootec at gmail.com>
wrote:
> Hi guys!
>
> I am trying to parse Call-ID from received message within my custom
> kamailio module but every time I parse it and persist it within shared
> memory of my module the kamailio sends back (to UA) SIP message with
> `{Call-ID-hex-stream}0d` instead of `{Call-ID-hex-stream}00`
>
> So it seems that kamailio adds `CR` byte to Call-ID which I am parsing.
>
>
> This is how I am parsing and persisting the Call-ID (in my opinion it's
> without affecting the original message but yet it seems that I am wrong):
>
> First of all I parse Call-ID so I have `str` structure where the
> `call_id_str.s` is pointing to the begining of Call-ID within `sip_msg_t`
> structure and `call_id_str.len` has the length of that Call-ID.
>
> Secondly I am trying to copy the string from received SIP message into my
> own structure (I mean copy not just point to it since I need it also when
> the message is gone). I've prepared this function:
>
>
> int shm_copy_string(const char *original_string, int original_length, char
> **new_string) {
> // allocate shared memory for new string
> *new_string = (char *) shm_malloc(sizeof(char) * (original_length +
> 1));
>
> if (*new_string == NULL) {
> ERR("cannot allocate shm memory");
> return -1;
> }
>
> // copy original string to new string
> memcpy(new_string, &original_string, original_length);
> // end new string with null character
> (*new_string)[original_length] = '\0';
>
> return 0;
> }
>
> I am calling this function within my module like this:
>
> shm_copy_string(call_id_str.s, call_id_str.len, &call_id);
>
> I don't manipulate with the pointer to original message in any way but
> still the message which kamailio sends back to my UA has that `CR` and it
> causes me big problems since UA cannot match the Call-ID.
>
> Also weird is that when I skip copying of the Call-ID on Registration
> message it is not affected so UA can register but then when I am trying to
> call from UA to UA I am getting as a response for my INVITE the `407 Proxy
> Authentication Required` with malformed Call-ID.
>
> Messages where I don't parse Call-ID are OK so the problem must be in this
> function.
>
>
> Has anyone came across this issue? How-come response SIP message is
> affected when I didn't add anything to the message?
>
>
> Thanks in advance for any help
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20160408/d199ddaa/attachment.html>
More information about the sr-dev
mailing list