<p></p>
<p>First, I find the name of the parameter a bit confusing, because it does not control the "parser" mode , but logging, so can eventually be something like <code>sip_parser_log_oneline</code>, <code>log_msg_error_online</code> or something that reflect it is about logging in case of error.</p>
<p>Then, somehow I feel it's opening the door for troubles, as it replaces content inside the incoming buffer. Probably now the logging is like last action done with the buffer content, but the current paradigm is that incoming buffer is not changed.</p>
<p>I would propose to create a more generic solution that can be used even when an error occurs, but it is not last use of the buffer (e.g., processing error, but it is still ok to send a reply or do something else).</p>
<p>My idea right now would be to create a function like:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-k">char</span> *<span class="pl-en">ksr_buf_oneline</span>(<span class="pl-k">char</span> *inbuf, <span class="pl-k">int</span> inlen)
{
   <span class="pl-k">static</span> outbuf[BUF_SIZE];
   <span class="pl-k">int</span> outlen;
   <span class="pl-k">int</span> i = <span class="pl-c1">0</span>;

  <span class="pl-k">if</span> (<span class="pl-c1">cfg_get</span>(core, core_cfg, sip_parser_oneline) == <span class="pl-c1">0</span>) {
     <span class="pl-k">return</span> inbuf;
 }

  <span class="pl-k">if</span>(inbuf==<span class="pl-c1">NULL</span>) {
    outbuf[<span class="pl-c1">0</span>] = <span class="pl-s"><span class="pl-pds">'</span><span class="pl-cce">\0</span><span class="pl-pds">'</span></span>;
    <span class="pl-k">return</span> outbuf;
  }

  outlen = (inlen<BUF_SIZE)?inlen:BUF_SIZE-<span class="pl-c1">1</span>;
  <span class="pl-c1">memcpy</span>(outbuf, inbuf, outlen);
  outbuf[outlen] = <span class="pl-s"><span class="pl-pds">'</span><span class="pl-cce">\0</span><span class="pl-pds">'</span></span>;

  <span class="pl-k">for</span> (i = <span class="pl-c1">0</span>; i < outlen;  i++) {
        <span class="pl-k">if</span>(buf[i] == <span class="pl-s"><span class="pl-pds">'</span><span class="pl-cce">\r</span><span class="pl-pds">'</span></span>) ...
  }
  <span class="pl-k">return</span> outbuf;
}</pre></div>
<p>Then can be used like:</p>
<div class="highlight highlight-source-c"><pre>   <span class="pl-en">LOG</span>(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n",
                        (<span class="pl-k">int</span>)msg->len, ZSW(ksr_buf_oneline(msg->buf, (<span class="pl-k">int</span>)msg->len)));</pre></div>
<p>There is a memcpy, but this is expected to be used on error or troubleshooting.</p>
<p>Also, as a side note, you don't need to do <code>strlen(msg->buf)</code>, its length is in <code>msg->len</code> field.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/2904#issuecomment-952866009">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZIJLEXV4XFKBDFVTBDUI73YVANCNFSM5G2CZAXQ">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/ABO7UZPXJPZ6GIFBLVSHVV3UI73YVA5CNFSM5G2CZAX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHDFZJWI.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/2904#issuecomment-952866009",
"url": "https://github.com/kamailio/kamailio/pull/2904#issuecomment-952866009",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>