Skip to content

Commit 3a9f928

Browse files
committed
Support for last_XX:value, last_XX:uri, last_XX:param.tag
1 parent a7069b9 commit 3a9f928

File tree

5 files changed

+232
-10
lines changed

5 files changed

+232
-10
lines changed

include/call.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class call : virtual public task, virtual public listener, public virtual socket
291291

292292
char * get_header_field_code(const char * msg, const char * code);
293293
char * get_last_header(const char * name);
294-
char * get_last_request_uri();
294+
char * get_last_tag (const char *name);
295+
char * get_last_request_uri(const char *name);
295296
unsigned long hash(const char * msg);
296297

297298
typedef std::map <std::string, int> file_line_map;

regress/github-#0258/run

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# This regression test is a part of SIPp.
3+
# Author: Pietro Bertera, Snom Technology AG, 2016
4+
5+
. "`dirname "$0"`/../functions"; init
6+
7+
sippbg -m 1 -sf uas.xml -p 5070 -i 127.0.0.1 \
8+
-timeout 4 -timeout_error -trace_logs \
9+
-log_file log.log >/dev/null 2>&1
10+
11+
job=$!
12+
13+
sippfg -m 1 -sf uac.xml 127.0.0.1:5070 \
14+
-timeout 4 -timeout_error >/dev/null 2>&1
15+
16+
status=$?
17+
wait $job || status=1
18+
19+
if test $status -eq 0; then
20+
if grep -e ^LAST\ From:\ \"Tom\ Jones\"\ \<sip:[email protected]\>\;tag=SIPpTag001$ log.log > /dev/null; then
21+
if grep -e ^LAST\ To:uri:\ sip:[email protected]$ log.log > /dev/null; then
22+
if grep -e ^LAST\ From-tag:\ SIPpTag001$ log.log > /dev/null; then
23+
ok
24+
else
25+
fail "From:param.tag not found"
26+
fi
27+
else
28+
fail "To:uri not found"
29+
fi
30+
else
31+
fail "From header not found"
32+
fi
33+
else
34+
fail "process failure"
35+
fi

regress/github-#0258/uac.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<!DOCTYPE scenario SYSTEM "sipp.dtd">
3+
<scenario>
4+
<send retrans="500" start_txn="invite">
5+
<![CDATA[
6+
7+
INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
8+
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=justafake
9+
From: "Tom Jones" <sip:[email protected]>;tag=SIPpTag00[call_number]
10+
To: "Fromage" <sip:[email protected]>
11+
Call-ID: [call_id]
12+
CSeq: 1 INVITE
13+
Contact: <sip:sipp@[local_ip]:[local_port]>
14+
Content-Length: 0
15+
16+
]]>
17+
</send>
18+
19+
<recv response="200" response_txn="invite" rrs="true"/>
20+
21+
<send retrans="500" ack_txn="invite">
22+
<![CDATA[
23+
24+
ACK [next_url] SIP/2.0
25+
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=justafake
26+
From: "Tom Jones" <sip:[email protected]>;tag=SIPpTag00[call_number]
27+
To: "Fromage" <sip:[email protected]>[peer_tag_param]
28+
Call-ID: [call_id]
29+
CSeq: 1 ACK
30+
Contact: sip:sipp@[local_ip]:[local_port]
31+
Content-Length: 0
32+
33+
]]>
34+
</send>
35+
36+
<recv request="BYE"/>
37+
38+
<send>
39+
<![CDATA[
40+
41+
SIP/2.0 200 OK
42+
[last_Via:]
43+
[last_From:]
44+
[last_To:]
45+
[last_Call-ID:]
46+
[last_CSeq:]
47+
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
48+
Content-Length: 0
49+
50+
]]>
51+
</send>
52+
53+
<timewait milliseconds="500"/>
54+
</scenario>

regress/github-#0258/uas.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<!DOCTYPE scenario SYSTEM "sipp.dtd">
3+
<scenario>
4+
<recv request="INVITE"/>
5+
6+
<send retrans="500">
7+
<![CDATA[
8+
9+
SIP/2.0 200 OK
10+
Via: [last_Via:value]
11+
From: [last_From:value]
12+
To: [last_To:value];tag=[pid]SIPpTag00[call_number]
13+
Call-ID: [last_Call-ID:value]
14+
CSeq: [last_CSeq:value]
15+
Contact: sip:sipp@[local_ip]:[local_port]
16+
Content-Length: 0
17+
18+
]]>
19+
</send>
20+
21+
<recv request="ACK" rrs="true">
22+
<action>
23+
<log message="LAST Contact: [last_Contact]" />
24+
<log message="LAST Via: [last_Via:value]"/>
25+
<log message="LAST From: [last_From:value]"/>
26+
<log message="LAST To: [last_To:value]"/>
27+
<log message="LAST To:uri: [last_To:uri]"/>
28+
<log message="LAST Contact:uri: [last_Contact:uri]"/>
29+
<log message="LAST From-tag: [last_From:param.tag]"/>
30+
</action>
31+
</recv>
32+
33+
<send retrans="500">
34+
<![CDATA[
35+
36+
BYE [next_url] SIP/2.0
37+
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
38+
From: [last_To:value]
39+
To: [last_From:value]
40+
Call-ID: [call_id]
41+
CSeq: 2 BYE
42+
Contact: sip:sipp@[local_ip]:[local_port]
43+
Content-Length: 0
44+
45+
]]>
46+
</send>
47+
48+
<recv response="200"/>
49+
50+
<timewait milliseconds="500"/>
51+
</scenario>

src/call.cpp

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -923,33 +923,114 @@ char * call::get_last_header(const char * name)
923923
if (name[len - 1] == ':') {
924924
return get_header(last_recv_msg, name, false);
925925
} else {
926+
926927
char with_colon[MAX_HEADER_LEN];
927-
sprintf(with_colon, "%s:", name);
928-
return get_header(last_recv_msg, with_colon, false);
928+
const char *sep = strrchr(name, ':');
929+
930+
if (!sep){
931+
sprintf(with_colon, "%s:", name);
932+
return get_header(last_recv_msg, with_colon, false);
933+
} else {
934+
if (!strcmp(sep, ":value")) {
935+
snprintf(with_colon, len - 4, "%s", name);
936+
return get_header(last_recv_msg, with_colon, true);
937+
}
938+
if (!strcmp(sep, ":uri")) {
939+
snprintf(with_colon, len - 2, "%s", name);
940+
char * last_header_uri = get_last_request_uri(with_colon);
941+
char * ret;
942+
if (!(ret = (char *)malloc(strlen(last_header_uri + 1)))){
943+
ERROR("call::get_last_header: Cannot allocate uri !\n");
944+
}
945+
sprintf(ret, "%s", last_header_uri);
946+
free(last_header_uri);
947+
return ret;
948+
}
949+
if (!strcmp(sep, ":param.tag")) {
950+
snprintf(with_colon, len - 8, "%s", name);
951+
char * last_tag = get_last_tag(with_colon);
952+
char * ret;
953+
if (!(ret = (char *)malloc(strlen(last_tag + 1)))){
954+
ERROR("call::get_last_header: Cannot allocate param.tag !\n");
955+
}
956+
sprintf(ret, "%s", last_tag);
957+
free(last_tag);
958+
return ret;
959+
}
960+
ERROR("Token %s not valid in %s", sep, name);
961+
}
929962
}
930963
}
931964

932-
/* Return the last request URI from the To header. On any error returns the
965+
/* Return the last tag from the header line. On any error returns the
933966
* empty string. The caller must free the result. */
934-
char * call::get_last_request_uri()
967+
char * call::get_last_tag(const char *name)
935968
{
936969
char * tmp;
937970
char * tmp2;
938-
char * last_request_uri;
971+
char * result;
972+
char * last_To;
939973
int tmp_len;
940974

941-
char * last_To = get_last_header("To:");
975+
if (!name || !strlen(name)) {
976+
return strdup("");
977+
}
978+
979+
last_To = get_last_header(name);
942980
if (!last_To) {
943981
return strdup("");
944982
}
945983

946-
tmp = strchr(last_To, '<');
984+
tmp = strcasestr(last_To, "tag=");
985+
if (!tmp) {
986+
return strdup("");
987+
}
988+
989+
tmp += strlen("tag=");
990+
tmp2 = tmp;
991+
992+
while (*tmp2 && *tmp2 != ';' && *tmp2!='\r' && *tmp2!='\n') tmp2++;
993+
994+
tmp_len = strlen(tmp) - strlen(tmp2);
995+
if (tmp_len < 0) {
996+
return strdup("");
997+
}
998+
if(!(result = (char *) malloc(tmp_len+1))) ERROR("call::get_last_tag: Cannot allocate !\n");
999+
memset(result, 0, sizeof(&result));
1000+
if(tmp && (tmp_len > 0)){
1001+
strncpy(result, tmp, tmp_len);
1002+
}
1003+
result[tmp_len] = '\0';
1004+
return result;
1005+
}
1006+
1007+
/* Return the last request URI from the header. On any error returns the
1008+
* empty string. The caller must free the result. */
1009+
char * call::get_last_request_uri(const char *name)
1010+
{
1011+
char * tmp;
1012+
char * tmp2;
1013+
char * last_request_uri;
1014+
char * last_header;
1015+
int tmp_len;
1016+
1017+
if (!name || !strlen(name)) {
1018+
return strdup("");
1019+
}
1020+
1021+
last_header = get_last_header(name);
1022+
1023+
if (!last_header) {
1024+
return strdup("");
1025+
}
1026+
1027+
tmp = strchr(last_header, '<');
9471028
if (!tmp) {
9481029
return strdup("");
9491030
}
9501031
tmp++;
9511032

952-
tmp2 = strchr(last_To, '>');
1033+
tmp2 = strchr(last_header, '>');
9531034
if (!tmp2) {
9541035
return strdup("");
9551036
}
@@ -2201,7 +2282,7 @@ char* call::createSendingMessage(SendingMessage *src, int P_index, char *msg_buf
22012282
}
22022283
break;
22032284
case E_Message_Last_Request_URI: {
2204-
char * last_request_uri = get_last_request_uri();
2285+
char * last_request_uri = get_last_request_uri("To:");
22052286
dest += sprintf(dest, "%s", last_request_uri);
22062287
free(last_request_uri);
22072288
break;

0 commit comments

Comments
 (0)