<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [X] Commit message has the format required by CONTRIBUTING guide - [X] Commits are split per component (core, individual modules, libs, utils, ...) - [X] Each component has a single commit (if not, squash them into one commit) - [X] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [X] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail -->
If this param is enabled, will log SIP headers with comma instead of \r\n, when some error happens. Default is disabled. You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2904
-- Commit Summary --
* <a href="https://github.com/kamailio/kamailio/pull/2904/commits/901ddcf7c1eef3e7e2eb2310ce82dffb848e4d4f">core: add new param sip_parser_oneline</a>
-- File Changes --
M src/core/cfg.lex (2) M src/core/cfg.y (3) M src/core/cfg_core.c (3) M src/core/cfg_core.h (1) M src/core/parser/msg_parser.c (28) M src/core/parser/msg_parser.h (5) M src/core/parser/parse_via.c (5)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2904.patch https://github.com/kamailio/kamailio/pull/2904.diff
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 `sip_parser_log_oneline`, `log_msg_error_online` or something that reflect it is about logging in case of error.
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.
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).
My idea right now would be to create a function like:
```c char *ksr_buf_oneline(char *inbuf, int inlen) { static outbuf[BUF_SIZE]; int outlen; int i = 0;
if (cfg_get(core, core_cfg, sip_parser_oneline) == 0) { return inbuf; }
if(inbuf==NULL) { outbuf[0] = '\0'; return outbuf; }
outlen = (inlen<BUF_SIZE)?inlen:BUF_SIZE-1; memcpy(outbuf, inbuf, outlen); outbuf[outlen] = '\0';
for (i = 0; i < outlen; i++) { if(buf[i] == '\r') ... } return outbuf; } ```
Then can be used like:
```c LOG(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, ZSW(ksr_buf_oneline(msg->buf, (int)msg->len))); ```
There is a memcpy, but this is expected to be used on error or troubleshooting.
Also, as a side note, you don't need to do `strlen(msg->buf)`, its length is in `msg->len` field.
One more remark, the comma is used for separating values in the same header and can be hard to spot EOH. Maybe this character should be made configurable. `ngrep` prints `.` (dot) instead of `\r` or '\n`, but can be set via `-F` iirc.
@smititelu pushed 1 commit.
663ab8c375b4620407e62047b391321bf08d1351 core: add new param sip_parser_log_oneline
Hello, thanks again for the feedback! I've update the pull request accordingly. For now, I used the ". " as delimiter.
@miconda commented on this pull request.
@@ -2703,11 +2703,11 @@ char *parse_via(
error: if(end > buffer) { - LM_ERR("parsing via on: <%.*s>\n", (int)(end - buffer), ZSW(buffer)); + LM_ERR("parsing via on: <%.*s>\n", (int)(end - buffer), ZSW(ksr_buf_oneline(buffer, (int)strlen(buffer))));
Instead of `(int)strlen(buffer)` should be `(int)(end - buffer)` -- that's the size to be printed, being the first parameter that is provided for `%.*s`.
@miconda commented on this pull request.
}
if((tmp > buffer) && (tmp < end)) { LM_ERR("parse error, parsed so far:<%.*s>\n", (int)(tmp - buffer), - ZSW(buffer)); + ZSW(ksr_buf_oneline(buffer, (int)strlen(buffer))));
Similar, `(int)(tmp - buffer)` instead of `(int)strlen(buffer)`.
@smititelu pushed 1 commit.
060a09377d3ab5f8ab62ec408a1fc2b87bf91c81 core: add new param sip_parser_log_oneline
Thanks, merging!
Merged #2904 into master.