Here's a diff against 2007-01-08 snapshot that adds an optional 'regexp_match'
argument to the receive command which allows regexp style patterns to be
supplied for matching.
This allows a scenario to act as a 'universal' catcher. Meaning it can receive
multiple message types and respond to them all with the same 200 OK.
Particularly for presence testing, this would be useful for simulating a UAS
that OKs incoming publishes, subscribes, and IMs.
Example:
<recv request="MESSAGE|PUBLISH|SUBSCRIBE" crlf="true" regexp_match="true">
</recv>
If regexp_match is not supplied, the old behavior persists.
t
diff -bruN sipp.2007-01-08/call.cpp sipp.2007-01-08.new/call.cpp
--- sipp.2007-01-08/call.cpp 2006-12-21 05:24:42.000000000 -0500
+++ sipp.2007-01-08.new/call.cpp 2007-01-09 11:32:01.294682029 -0500
@@ -2601,6 +2601,38 @@
}
}
+bool call::matches_scenario(int index, int reply_code, char * request, char *
responsecseqmethod)
+{
+ int result;
+ regex_t re;
+
+ if ((reply_code) && ((scenario[index] -> recv_response) == reply_code) && \
+ (scenario[index]->recv_response_for_cseq_method_list) && \
+ (strstr(scenario[index]->recv_response_for_cseq_method_list,
responsecseqmethod))) {
+ return true;
+ }
+
+ if ((scenario[index] -> recv_request) && \
+ (!strcmp(scenario[index] -> recv_request, request))) {
+ return true;
+ }
+
+ if ((scenario[index] -> recv_request) && (scenario[index] -> regexp_match)) {
+
+ if (regcomp(&re, scenario[index] -> recv_request,
REG_EXTENDED|REG_NOSUB)) {
+ // regexp is not well formed
+ scenario[index] -> regexp_match = 0;
+ return false;
+ }
+
+ result = regexec(&re, request, (size_t)0, NULL, 0);
+ regfree(&re);
+ if (!result) return true;
+ }
+
+ return false;
+}
+
bool call::process_incoming(char * msg)
{
int reply_code;
@@ -2622,15 +2654,6 @@
/* Ignore the messages received during a pause if -pause_msg_ign is set */
if(scenario[msg_index] -> M_type == MSG_TYPE_PAUSE && pause_msg_ign)
return(true);
-#define MATCHES_SCENARIO(index) \
- (((reply_code) && \
- ((scenario[index] -> recv_response) == reply_code) && \
- (scenario[index]->recv_response_for_cseq_method_list) && \
- (strstr(scenario[index]->recv_response_for_cseq_method_list,
responsecseqmethod))) || \
- ((scenario[index] -> recv_request) && \
- (!strcmp(scenario[index] -> recv_request, \
- request))))
-
/* Authorize nop as a first command, even in server mode */
if((msg_index == 0) && (scenario[msg_index] -> M_type == MSG_TYPE_NOP)) {
actionResult = executeAction(NULL, msg_index);
@@ -2755,7 +2778,7 @@
for(search_index = msg_index;
search_index < scenario_len;
search_index++) {
- if(!MATCHES_SCENARIO(search_index)) {
+ if(!matches_scenario(search_index, reply_code, request,
responsecseqmethod)) {
if(scenario[search_index] -> optional) {
continue;
}
@@ -2778,7 +2801,7 @@
search_index >= 0;
search_index--) {
if (scenario[search_index]->optional == OPTIONAL_FALSE) contig = false;
- if(MATCHES_SCENARIO(search_index)) {
+ if(matches_scenario(search_index, reply_code, request,
responsecseqmethod)) {
if (contig || scenario[search_index]->optional == OPTIONAL_GLOBAL) {
found = true;
break;
diff -bruN sipp.2007-01-08/call.hpp sipp.2007-01-08.new/call.hpp
--- sipp.2007-01-08/call.hpp 2006-11-01 22:45:18.000000000 -0500
+++ sipp.2007-01-08.new/call.hpp 2007-01-09 11:32:11.053090282 -0500
@@ -209,6 +209,7 @@
bool run();
void formatNextReqUrl (char* next_req_url);
void computeRouteSetAndRemoteTargetUri (char* rrList, char* contact, bool
bRequestIncoming);
+ bool matches_scenario(int index, int reply_code, char * request, char *
responsecseqmethod);
bool process_incoming(char * msg);
T_ActionResult executeAction(char * msg, int scenarioIndex);
diff -bruN sipp.2007-01-08/scenario.cpp sipp.2007-01-08.new/scenario.cpp
--- sipp.2007-01-08/scenario.cpp 2006-12-20 07:57:58.000000000 -0500
+++ sipp.2007-01-08.new/scenario.cpp 2007-01-09 11:34:26.810944553 -0500
@@ -54,6 +54,7 @@
recv_response = 0;
recv_request = NULL;
optional = 0;
+ regexp_match = 0;
/* Anyway */
start_rtd = 0;
@@ -518,6 +519,12 @@
}
}
+ if (0 != (ptr = xp_get_value((char *)"regexp_match"))) {
+ if(!strcmp(ptr, "true")) {
+ scenario[scenario_len] -> regexp_match = 1;
+ }
+ }
+
if (0 != (ptr = xp_get_value((char *)"timeout"))) {
scenario[scenario_len]->retrans_delay = get_long(ptr, "message
timeout");
}
diff -bruN sipp.2007-01-08/scenario.hpp sipp.2007-01-08.new/scenario.hpp
--- sipp.2007-01-08/scenario.hpp 2006-12-20 07:57:58.000000000 -0500
+++ sipp.2007-01-08.new/scenario.hpp 2007-01-09 11:34:42.177437691 -0500
@@ -102,6 +102,7 @@
unsigned int recv_response;
char * recv_request;
int optional;
+ int regexp_match;
/* Anyway */
int start_rtd;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sipp-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sipp-users