-
Notifications
You must be signed in to change notification settings - Fork 422
Snom patch: Last_ keywords extension #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
This is not the way to move forward. If you look at the syntax suggested in #132, I would envision these to be called like:
See https://www.opensips.org/Documentation/Script-Tran-2-2 for ideas. I don't mind if only ".value", ".uri" and ".param.tag" are implemented, but at least it would provide a solid syntax to build more features on, instead of of adding |
|
Yes, you are right, I agree with this more general approach instead of adding more Here: master...Snomio:last_extensions I'm working on a solution for this, the patch implements:
So should cover this and #258, your feedback are appreciated, Thanks, |
18697fe to
3a9f928
Compare
324cf71 to
060d7ca
Compare
pbertera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you look at the code ?
If is sufficiently clean / correct I'll work on the documentation.
Thanks
060d7ca to
909cae7
Compare
| fi | ||
| else | ||
| fail "process failure" | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done without so much nesting with negative tests instead:
if test $status -ne 0; then
fail "process failure"
elif ! grep -q '^LAST From: "Tom Jones" <sip:tom\[email protected]>;tag=SIPpTag001$' log.log; then
fail "From header not found"
...
regress/github-#0260/uas.xml
Outdated
| <log message="LAST To: [last_To:value]"/> | ||
| <log message="LAST To:uri: [last_To:uri]"/> | ||
| <log message="LAST Contact:uri: [last_Contact:uri]"/> | ||
| <log message="LAST From-tag: [last_From:param.tag]"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your "key names" don't correspond to the lookups:
Suggest:
LAST Contact|[last_Contact]
LAST Via:value|[last_Via:value]
etc..
src/call.cpp
Outdated
| return ret; | ||
| } | ||
| ERROR("Token %s not valid in %s", sep, name); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is too big. The code in the if(strcmp..){...} blocks should be delegated to helper methods and duplicate code should be avoided.
For example:
if (!sep) { /* [last_Header] */
sprintf(with_colon, "%s:", name);
return get_header(last_recv_msg, with_colon, false);
}
/* [last_Header:...] */
sprintf(with_colon, "%.*s", (sep - name + 1), name);
if (!strcmp(sep, ":")) {
return get_header(last_recv_msg, with_colon, false);
}
char *value = get_header(last_recv_msg, with_colon, true);
if (!strcmp(sep, ":value")) {
; /* done */
} else if (!strcmp(sep, ":uri")) {
extract_header_uri(value); /* reuse mem in value (memmove?) */
} else if (....) {
...
} else {
ERROR("Token %s not valid in %s", sep, name);
}
return value;
include/call.hpp
Outdated
| char * get_last_header(const char * name); | ||
| char * get_last_request_uri(); | ||
| char * get_last_tag (const char *name); | ||
| char * get_last_request_uri(const char *name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be called get_last_request_uri but get_last_uri_from or something.
src/call.cpp
Outdated
| snprintf(with_colon, len - 2, "%s", name); | ||
| char * last_header_uri = get_last_request_uri(with_colon); | ||
| char * ret; | ||
| if (!(ret = (char *)malloc(strlen(last_header_uri + 1)))){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_header() returns a static buffer (yuck, I know).
You can't start returning malloc'ed memory all of a sudden: memory leaks.
src/call.cpp
Outdated
|
|
||
| /* Return the last tag from the header line. On any error returns the | ||
| * empty string. The caller must free the result. */ | ||
| char * call::get_last_tag(const char *name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be implemented in sip_parser.cpp instead. See get_peer_tag.
|
Thanks for all the hints, can you give me your feedback ? |
wdoekes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for being picky. But if we're changing the source, it should be for the better.
regress/github-#0260/run
Outdated
|
|
||
| if test $status -ne 0; then | ||
| fail "process failure" | ||
| elif ! grep -e ^LAST\ Contact\|Contact:\ \<sip:[email protected]:5060\> log.log > /dev/null; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single-quotes instead. And -q so you don't have to redirect to /dev/null. (And with -F you can do regular string comparisons without worrying about special regex tokens.)
grep -qF 'LAST Contact|Contact: <sip:[email protected]:5060>' log.log
src/sip_parser.cpp
Outdated
|
|
||
| char * get_peer_tag(const char *msg) | ||
| { | ||
| return get_param_tag(msg, "To", "t"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be:
get_param(msg, "tag", "To", "t");
That'd be even more generic.
src/call.cpp
Outdated
| char * last_request_uri = get_last_request_uri(); | ||
| char * last_request_uri = get_last_header_uri("To:"); | ||
| dest += sprintf(dest, "%s", last_request_uri); | ||
| free(last_request_uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not this?
dest += sprintf(dest, "%s", get_last_header("To:uri"));
And drop the entire get_last_header_uri() method.
The get_uri-code could be implemented in sip_parser.cpp instead as get_first_uri(const char *msg, const char *name, const char *shortname) or something, with the same semantics as the other get_* functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you wrote get_first_uri ? maybe you are thinking about multiple URI in the header ?
src/call.cpp
Outdated
| char * last_tag = get_param_tag(last_recv_msg, header_name, ""); | ||
| int last_tag_len = strlen(last_tag); | ||
| memmove(value, last_tag, last_tag_len); | ||
| value[last_tag_len] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memmove(value, last_tag, strlen(last_tag) + 1);
.. copies the NUL along.
src/call.cpp
Outdated
| if (name[len - 1] == ':') { | ||
| return get_header(last_recv_msg, name, false); | ||
| } | ||
| char *value = get_header(last_recv_msg, header_name, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently you're not using value get_header(last_recv_msg, header_name, true); here, move it to the ; /* done */ instead.
It would be only useful here if we used functions that operate on that single header directly later on, e.g.:
get_param(value, "tag");orextract_param(value, "tag");get_first_uri(value);orextract_first_uri(value);
They could certainly be implemented and would clean up things some more.
src/call.cpp
Outdated
| int uri_len = strlen(uri); | ||
| memmove(value, uri, uri_len); | ||
| value[uri_len] = '\0'; | ||
| free(uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If get_last_header_uri is dropped, we get rid of this unusual free() here (because of the different semantics of get_last_header_uri).
|
@wdoekes no pickiness, unfortunately my programming skills are very weak. Your fine grained review is a warranty for the quality of SIPp, thanks a lot. |
|
Sorry for the delay. I've been busy. I'll try to get to this in the coming week. |
|
Note to self: this fails: |
This patch add the support for the following new scenario keywords:
All the attribution for this patch should go to Snom Technology AG