kemi_mock.py can now optionally consume documentation information generated by the vscode-kamailio-hover project
<!-- 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)
- [ ] 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)
- [ ] 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
- [ ] Tested changes locally
- [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description
<!-- Describe your changes in detail -->
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/3818
-- Commit Summary --
* tools/kemi: add dockstrings to the mocking
-- File Changes --
M misc/tools/kemi/python_mock/README.md (15)
M misc/tools/kemi/python_mock/kemi_mock.py (31)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/3818.patchhttps://github.com/kamailio/kamailio/pull/3818.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3818
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/3818(a)github.com>
Module: kamailio
Branch: master
Commit: 6b29df73115682424daf7b276d0138f004e274f7
URL: https://github.com/kamailio/kamailio/commit/6b29df73115682424daf7b276d0138f…
Author: tsearle <torrey.searle(a)wavecrest.com>
Committer: GitHub <noreply(a)github.com>
Date: 2024-04-22T12:53:48+02:00
tools/kemi: add dockstrings to the mocking (#3818)
kemi_mock.py can now optionally consume documentation information
generated by the vscode-kamailio-hover project
---
Modified: misc/tools/kemi/python_mock/README.md
Modified: misc/tools/kemi/python_mock/kemi_mock.py
---
Diff: https://github.com/kamailio/kamailio/commit/6b29df73115682424daf7b276d0138f…
Patch: https://github.com/kamailio/kamailio/commit/6b29df73115682424daf7b276d0138f…
---
diff --git a/misc/tools/kemi/python_mock/README.md b/misc/tools/kemi/python_mock/README.md
index 5e72e738c58..385cbd5656a 100644
--- a/misc/tools/kemi/python_mock/README.md
+++ b/misc/tools/kemi/python_mock/README.md
@@ -2,7 +2,7 @@
Generate a mocking framework base on the output of app_python.api_list
-Usage:
+### Usage:
```
/usr/sbin/kamctl rpc app_python.api_list > api.json
./kemi_mock.py api.json > KSR.py
@@ -15,6 +15,19 @@ the Union type add the --no-union flag
./kemi_mock.py api.json --no-union > KSR.py
```
+### Usage with Documentation:
+run the generate.py from the following project
+
+https://github.com/braams/vscode-kamailio-hover
+
+this creates a modules.json file in a tmp directory. This file can be used to generate the KSR.py file with documentation
+
+pass the modules.json as a 2nd parameter to kemi_mock.py
+```
+./kemi_mock.py api.json modules.json > KSR.py
+```
+
+## Mocking
Return values can be injected through the dictionary \_mock\_data
```python
diff --git a/misc/tools/kemi/python_mock/kemi_mock.py b/misc/tools/kemi/python_mock/kemi_mock.py
index 48a73efa232..145fcb34b3a 100755
--- a/misc/tools/kemi/python_mock/kemi_mock.py
+++ b/misc/tools/kemi/python_mock/kemi_mock.py
@@ -113,21 +113,41 @@ def printFunction(module_name, func, indent):
else:
print(prefix + "def " + func['name'] +"("+params+"):")
+ generate_function_doc(module_name, func, prefix)
+
print(prefix + "\tprint(\"Calling " + log_format_params + "\" % "+log_params+")")
printMocReturn(module_name, func, indent+1)
print("")
+def generate_function_doc(module_name, func, prefix):
+ if documentation is not None and module_name in documentation:
+ function_parts = func['name'].split("_")
+ for i in range(len(function_parts), 0, -1):
+ function_prefix = "_".join(function_parts[:i])
+ if function_prefix in documentation[module_name]["functions"]:
+ print(prefix + "\t\"\"\"")
+ documentation_lines = documentation[module_name]["functions"][function_prefix].split("\n")
+ for line in documentation_lines:
+ print(prefix + "\t" + line)
+ print(prefix + "\t\"\"\"")
+ break
+
+
classes = defaultdict(list)
if len(sys.argv) < 2:
print("Please specify the json file to parse")
sys.exit(-1)
+documentation = None
if len(sys.argv) > 2:
for i in range(2,len(sys.argv)):
if sys.argv[i] == "--no-union":
noUnion = True
+ else:
+ with open(sys.argv[i]) as f:
+ documentation = json.load(f)
if not noUnion:
print("from typing import Union")
@@ -193,12 +213,23 @@ def printFunction(module_name, func, indent):
print("")
printFunction('', func, 0)
+
+def document_module(module_name):
+ if documentation is not None and module_name in documentation:
+ print("\"\"\"")
+ documentation_lines = documentation[module_name]["overview"].split("\n")
+ for line in documentation_lines:
+ print("" + line)
+ print("\"\"\"")
+
+
for module_name in classes.keys():
if module_name != "":
if module_name in reserved_keywords:
print("setattr(sys.modules[__name__], '" + module_name + "', " + module_name.capitalize() + "())")
else:
print(module_name + " = "+module_name.capitalize()+"()")
+ document_module(module_name)
print("")
<!-- 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)
- [ ] 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 -->
When inserting into the database the AOR is split at the @ sign and if there is no @ sign in the AOR only the domain part is filled and the user part is left empty.
But for deleting this is not done and the query failed to be executed and the AOR is not deleted. This PR add this behaviour of only comparing against the domain part if the AOR doesn't contain a @ sign.
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/3815
-- Commit Summary --
* usrloc: check on db delete the return value of memchr
-- File Changes --
M src/modules/usrloc/urecord.c (14)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/3815.patchhttps://github.com/kamailio/kamailio/pull/3815.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3815
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/pull/3815(a)github.com>
Module: kamailio
Branch: master
Commit: 49276a1f43b1a3bf4a8d681888df964000360c79
URL: https://github.com/kamailio/kamailio/commit/49276a1f43b1a3bf4a8d681888df964…
Author: Rick Barenthin <rick(a)ng-voice.com>
Committer: Henning Westerholt <hw(a)gilawa.com>
Date: 2024-04-20T06:35:51+02:00
usrloc: check on db delete the return value of memchr
When inserting into the database the AOR is split at the @ sign and
if there is no @ sign in the AOR only the domain part is filled and the
user part is left empty.
But for deleting this is not done and the query failed to be executed
and the AOR is not deleted. This PR add this behaviour of only comparing against the
domain part if the AOR doesn't contain a @ sign.
---
Modified: src/modules/usrloc/urecord.c
---
Diff: https://github.com/kamailio/kamailio/commit/49276a1f43b1a3bf4a8d681888df964…
Patch: https://github.com/kamailio/kamailio/commit/49276a1f43b1a3bf4a8d681888df964…
---
diff --git a/src/modules/usrloc/urecord.c b/src/modules/usrloc/urecord.c
index e027affc8aa..3c394a24a10 100644
--- a/src/modules/usrloc/urecord.c
+++ b/src/modules/usrloc/urecord.c
@@ -491,13 +491,17 @@ int db_delete_urecord(urecord_t *_r)
vals[0].val.str_val.len = _r->aor.len;
if(ul_use_domain) {
- dom = memchr(_r->aor.s, '@', _r->aor.len);
- vals[0].val.str_val.len = dom - _r->aor.s;
-
vals[1].type = DB1_STR;
vals[1].nul = 0;
- vals[1].val.str_val.s = dom + 1;
- vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
+ dom = memchr(_r->aor.s, '@', _r->aor.len);
+ if(dom == 0) {
+ vals[0].val.str_val.len = 0;
+ vals[1].val.str_val = _r->aor;
+ } else {
+ vals[0].val.str_val.len = dom - _r->aor.s;
+ vals[1].val.str_val.s = dom + 1;
+ vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
+ }
}
if(ul_dbf.use_table(ul_dbh, _r->domain) < 0) {
when using sdp module to parse sdp I noticed that function called from sdp_get return -1 when no m-lines are present in sdp , normally we should accept sdp without m -line because it can be at a later time through a modified offer , how can we accept such sdp without changing source code for function "parse_sdp_session"
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3779
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/3779(a)github.com>
I want kamailio use User-Agent header, not Server head
My setup is as follows: kamailio.cfg
server_signature=no
user_agent_header="User-Agent: carrierroute-kam"
the result is :
SIP/2.0 100 trying -- your call is important to us
Via: SIP/2.0/UDP xxx
From: xxxxxxtag=N856ZmNXa4S6D
To: xxx
Call-ID: 5ab0
CSeq: 82194 INVITE
Content-Length: 0
**not have User-Agent header**
please help me,How to make it appear the User-Agent field? thank you
version: kamailio 5.7.0 (x86_64/linux) f1e91d
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3816
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/3816(a)github.com>
<!--
Kamailio Project uses GitHub Issues only for bugs in the code or feature requests. Please use this template only for bug reports.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists.kamailio…
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list:
* https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.kamailio.o…
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
Note that an issue report may be closed automatically after about 2 months
if there is no interest from developers or community users on pursuing it, being
considered expired. In such case, it can be reopened by writing a comment that includes
the token `/notexpired`. About two weeks before considered expired, the issue is
marked with the label `stale`, trying to notify the submitter and everyone else
that might be interested in it. To remove the label `stale`, write a comment that
includes the token `/notstale`. Also, any comment postpone the `expire` timeline,
being considered that there is interest in pursuing the issue.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment).
-->
### Description
The uri parser seems to fail in multiple ways on username-parameters. The ways it fails depends on the presence of user-params in the incoming request and on adjustments to $ru, $rd and $rU in the script.
My expectation is that the whole username, including user-params is *always* visible in $rU. In reality, the user-params are absent or present depending on manipulations to the uri in the script.
When setting $rU to a value with a user-param, that user-param is represented when reading $ru, but not in $rU.
<!--
Explain what you did, what you expected to happen, and what actually happened.
-->
### Troubleshooting
#### Reproduction
I used below config script to test various scenario's.
```
debug=2
memlog=4
#fork=no # This option should not be present to enable forking but disable daemonize, also -D commandline parameter is needed
log_stderror=yes
log_name="kamailio-test"
log_facility=LOG_LOCAL5
sip_warning=no
children=2
shm_mem_size=128
check_via=no # (cmd. line: -v)
dns=no # (cmd. line: -r)
rev_dns=no # (cmd. line: -R)
dns_use_search_list=no
use_dns_failover=yes
dns_srv_lb=yes
disable_tcp=yes
auto_aliases=no
listen=172.16.1.19:7060
loadmodule "sl.so"
loadmodule "pv.so"
loadmodule "xlog.so"
modparam("xlog", "prefix", "")
route {
xnotice("Incoming $rm to $rU\n");
xinfo("$$ru = $ru\n");
switch ($rU) {
case "100":
xnotice("Set $$rU = \"1234;first=yes\"\n");
$rU = "1234;first=yes";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
if ($rU != "1234;first=yes") {
xerr("Fail!\n");
} else {
xinfo("Success!\n");
}
break;
case "200":
xnotice("Set $$rd = \"example.com;transport=udp\"\n");
$rd = "example.com;transport=udp";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
xnotice("Set $$rU = \"1234;first=yes\"\n");
$rU = "1234;first=yes";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
if ($rU != "1234;first=yes") {
xerr("Fail!\n");
} else {
xinfo("Success!\n");
}
break;
case "300":
xnotice("Set $$ru = \"sip:1234@example.com;transport=udp\"\n");
$ru = "sip:1234@example.com;transport=udp";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
xnotice("Set $$rU = \"1234;first=yes\"\n");
$rU = "1234;first=yes";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
if ($rU != "1234;first=yes") {
xerr("Fail!\n");
} else {
xinfo("Success!\n");
}
break;
case "400":
xnotice("Set $$ru = \"sip:1234;first=yes@example.com;transport=udp\"\n");
$ru = "sip:1234;first=yes@example.com;transport=udp";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
if ($rU != "1234;first=yes") {
xerr("Fail!\n");
} else {
xinfo("Success!\n");
}
xnotice("Set $$rU = \"1234;second=yes\"\n");
$rU = "1234;second=yes";
xinfo("$$ru: $ru\n");
xinfo("$$rU: $rU\n");
if ($rU != "1234;second=yes") {
xerr("Fail!\n");
} else {
xinfo("Success!\n");
}
break;
}
sl_send_reply(500, "Done");
exit;
}
```
Outputs:
---
```
1(2206122) NOTICE: Incoming INVITE to 100
1(2206122) INFO: $ru = sip:100@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $rU = "1234;first=yes"
1(2206122) INFO: $ru: sip:1234;first=yes@172.16.1.19:7060;user=phone
1(2206122) INFO: $rU: 1234
1(2206122) ERROR: Fail!
```
Setting $rU with a user-param sets it correctly in $ru, but reading $rU back fails.
---
```
1(2206122) NOTICE: Incoming INVITE to 200
1(2206122) INFO: $ru = sip:200@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $rd = "example.com;transport=udp"
1(2206122) INFO: $ru: sip:200@example.com;transport=udp:7060;user=phone
1(2206122) INFO: $rU: 200
1(2206122) NOTICE: Set $rU = "1234;first=yes"
1(2206122) INFO: $ru: sip:1234;first=yes@example.com;transport=udp:7060;user=phone
1(2206122) INFO: $rU: 1234
1(2206122) ERROR: Fail!
```
Same when setting $rd in advance.
---
```
1(2206122) NOTICE: Incoming INVITE to 300
1(2206122) INFO: $ru = sip:300@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $ru = "sip:1234@example.com;transport=udp"
1(2206122) INFO: $ru: sip:1234@example.com;transport=udp
1(2206122) INFO: $rU: 1234
1(2206122) NOTICE: Set $rU = "1234;first=yes"
1(2206122) INFO: $ru: sip:1234;first=yes@example.com;transport=udp
1(2206122) INFO: $rU: 1234;first=yes
1(2206122) INFO: Success!
```
When setting $ru first with no user-param lets a later asssignment to $rU with user-param succeed.
---
```
1(2206122) NOTICE: Incoming INVITE to 400
1(2206122) INFO: $ru = sip:400@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $ru = "sip:1234;first=yes@example.com;transport=udp"
1(2206122) INFO: $ru: sip:1234;first=yes@example.com;transport=udp
1(2206122) INFO: $rU: 1234;first=yes
1(2206122) INFO: Success!
1(2206122) NOTICE: Set $rU = "1234;second=yes"
1(2206122) INFO: $ru: sip:1234;second=yes@example.com;transport=udp
1(2206122) INFO: $rU: 1234;second=yes
1(2206122) INFO: Success!
```
Setting $ru with a user-params succeeds. Subsequently overwriting the user part with $rU with a user-param also succeeds.
---
```
1(2206122) NOTICE: Incoming INVITE to 400
1(2206122) INFO: $ru = sip:400;existing=yes@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $ru = "sip:1234;first=yes@example.com;transport=udp"
1(2206122) INFO: $ru: sip:1234;first=yes@example.com;transport=udp
1(2206122) INFO: $rU: 1234;first=yes
1(2206122) INFO: Success!
1(2206122) NOTICE: Set $rU = "1234;second=yes"
1(2206122) INFO: $ru: sip:1234;second=yes@example.com;transport=udp
1(2206122) INFO: $rU: 1234;second=yes
1(2206122) INFO: Success!
```
Same as previous, but with incoming user-param.
---
```
1(2206122) NOTICE: Incoming INVITE to 100
1(2206122) INFO: $ru = sip:100;existing=yes@172.16.1.19:7060;user=phone
1(2206122) NOTICE: Set $rU = "1234;first=yes"
1(2206122) INFO: $ru: sip:1234;first=yes;existing=yes@172.16.1.19:7060;user=phone
1(2206122) INFO: $rU: 1234
1(2206122) ERROR: Fail!
```
This one fails in an interesting way. The incoming uri has a user-param. When overwriting $rU with a user-param, the user-param from the incoming request is kept in addition to the new one instead of being overwritten. $rU still misses (both) user-params.
#### Debugging Data
I have no build (yet) with EXTRA_DEBUG enabled.
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/3762
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/3762(a)github.com>