<div dir="ltr">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<div><br></div><div>Of course the problem was in my function. This would be correct one:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="monospace, monospace" size="1">int shm_copy_string(const char *original_string, int original_length, char **new_string) {</font></div></div><div><div><font face="monospace, monospace" size="1">    // allocate shared memory for new string</font></div></div><div><div><font face="monospace, monospace" size="1">    *new_string = (char *) shm_malloc(sizeof(char) * (original_length + 1));</font></div></div><div><div><font face="monospace, monospace" size="1"><br></font></div></div><div><div><font face="monospace, monospace" size="1">    if (*new_string == NULL) {</font></div></div><div><div><font face="monospace, monospace" size="1">        ERR("cannot allocate shm memory");</font></div></div><div><div><font face="monospace, monospace" size="1">        return -1;</font></div></div><div><div><font face="monospace, monospace" size="1">    }</font></div></div><div><div><font face="monospace, monospace" size="1"><br></font></div></div><div><div><font face="monospace, monospace" size="1">    // copy original string to new string</font></div></div><div><div><font face="monospace, monospace" size="1">    memcpy(*new_string, original_string, original_length);</font></div></div><div><div><font face="monospace, monospace" size="1">    // end new string with null character</font></div></div><div><div><font face="monospace, monospace" size="1">    (*new_string)[original_length] = '\0';</font></div></div><div><div><font face="monospace, monospace" size="1"><br></font></div></div><div><div><font face="monospace, monospace" size="1">    return 0;</font></div></div><div><div><font face="monospace, monospace" size="1">}</font></div></div><div><font face="monospace, monospace" size="1"><br></font></div></blockquote>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 ;-)<br><div><br></div><div>I am not sure if this will help somebody in the future but still I hope that anyone do the same error as me.</div><div><br></div><div><br></div><div>Have a nice day folks</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 7, 2016 at 9:28 PM, Cockhootec Yahrabee <span dir="ltr"><<a href="mailto:cockootec@gmail.com" target="_blank">cockootec@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi guys!<div><br></div><div>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`</div><div><br></div><div>So it seems that kamailio adds `CR` byte to Call-ID which I am parsing.</div><div><br></div><div><br></div><div>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):</div><div><br></div><div>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.</div><div><br></div><div>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:</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">int shm_copy_string(const char *original_string, int original_length, char **new_string) {</font></div><div><font face="monospace, monospace" size="1">    // allocate shared memory for new string</font></div><div><font face="monospace, monospace" size="1">    *new_string = (char *) shm_malloc(sizeof(char) * (original_length + 1));</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">    if (*new_string == NULL) {</font></div><div><font face="monospace, monospace" size="1">        ERR("cannot allocate shm memory");</font></div><div><font face="monospace, monospace" size="1">        return -1;</font></div><div><font face="monospace, monospace" size="1">    }</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">    // copy original string to new string</font></div><div><font face="monospace, monospace" size="1">    memcpy(new_string, &original_string, original_length);</font></div><div><font face="monospace, monospace" size="1">    // end new string with null character</font></div><div><font face="monospace, monospace" size="1">    (*new_string)[original_length] = '\0';</font></div><div><font face="monospace, monospace" size="1"><br></font></div><div><font face="monospace, monospace" size="1">    return 0;</font></div><div><font face="monospace, monospace" size="1">}</font></div><div><br></div></blockquote>I am calling this function within my module like this:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace" size="1">shm_copy_string(call_id_str.s, call_id_str.len, &call_id);</font></div><div><font face="monospace, monospace" size="1"><br></font></div></blockquote>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.<br><div><br></div><div>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.<br></div><div><br></div><div>Messages where I don't parse Call-ID are OK so the problem must be in this function.<br></div><div><br></div><div><br></div><div>Has anyone came across this issue? How-come response SIP message is affected when I didn't add anything to the message?</div><div><br></div><div><br></div><div>Thanks in advance for any help </div></div>
</blockquote></div><br></div>