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) {
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>