<!-- 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
#### Description
This change introduces a new type of variable $xavi - eXtended Attribute Value Insensitive case. It's like a $xavp but keys are case insensitive:
``` $xavi(WhatEver=>fOo) = 1;
if($xavi(whatever[0]=>foo) == 1) { .... } ``` You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2337
-- Commit Summary --
* core: xavi api - like xavp but with insensitive case names * core: pv - define xavi types * core: receive - reset xavi list after message processing * tm: process xavi list in transaction contexts * pv: $xavi(...) config variables implementation
-- File Changes --
M src/core/pvar.h (4) M src/core/receive.c (1) M src/core/xavp.c (987) M src/core/xavp.h (43) M src/modules/pv/pv.c (539) M src/modules/pv/pv_xavp.c (416) M src/modules/pv/pv_xavp.h (7) M src/modules/tm/h_table.c (12) M src/modules/tm/h_table.h (3) M src/modules/tm/t_hooks.c (6) M src/modules/tm/t_reply.c (7)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2337.patch https://github.com/kamailio/kamailio/pull/2337.diff
@linuxmaniac pushed 1 commit.
5a7e2314a6cd2f157327ba781e9ffe06043fc7e5 pv: $xavi(...) config variables implementation
I could not spot anything on a quick look over the patch. If nobody else wants to still keep it here for review, I am fine to merge it.
@henningw commented on this pull request.
The code looks all fine, but i noticed that several of the functions are more or less identical to the existing xavp code. This is of course to be expected, as the value works differs only in the case handling. I think it is worthwhile to try if it could be generalized.
What do you think about just using a generic function that gets a function pointer to a comparison or hash function? E.g. like this (pseudo-code to the relevant parts); - static sr_xavp_t *xavi_new_value(str *name, sr_xval_t *val, void * hash_func) { id = hash_func(name->s, name->len); } - int xavi_add(sr_xavp_t *xavi, sr_xavp_t **list, sr_avp_t* core_list) { *core_list = xavi; } - static sr_xavp_t *xavi_get_internal(str *name, sr_xavp_t **list, int idx, sr_xavp_t **prv, void *hash_func, void* comp_func) { id = hash_func(..); if (.. && comp_func(...)) }
Using void* function pointers is of course not perfect, but this is what C gives us. In e.g. the DB1 API they are used in different functions in a similar way to prevent a lot of code duplication.
I prefer to have separate functions, instead of going to some generic void* callbacks. Those are hard to track and prone to introduce bugs in existing functional code. The duplicated code should not be really big in size and having new dedicated functions for comparison, etc ... will result also in extra size of the overall code.
I actually looked at reusing the xavp code when I implementing xavu recently and the code got a lot of messy IF-ELSE conditions everywhere, functions with extra parameters to indicate what type of variable, etc ... so I reverted and just made dedicated functions, everything afterwards being easier to follow.
I don't think the usage of function pointers is a big problem, but it was just an idea. If you need to pass to many "switch" type of variables, it gets hard to follow, sure. The two functions xavi_add_value, xavi_add_value_after just operate on a global static list. This could be implemented type safe by just passing the list to it, without the need of void pointers.
In the case of the two functions you mention, then `_xavi_list_crt` is hidden in the c file (being declared static, since it is controlled in very special cases related transaction states, ...), so if those functions are used outside of the file, then they still need wrappers to call a common function (for xavp and xavi) with the adequate list.
And my remark was targeting exactly this case, because the functions have like 10 effective lines of code. A wrapper function is like 3 lines of code, with a jump on the stack. So overall it is not a significant gain.
It makes sense to have a function for a small number of lines of code, if the function is used in a lot of places, but if it going to be used in 2-3 places, then it has to be a significant number of codes of lines to really worth it.
Of course, it can be seen as a personal preference, but I prefer code easier to follow/search/maintain instead of modularising every snippet of code.
Merged #2337 into master.