Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added regexp support for response codes
Browse files Browse the repository at this point in the history
Petr Cisar committed Nov 4, 2024
1 parent 0240350 commit d6c0288
Showing 5 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/scenario.hpp
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ class message
char * peer_src;

/* If this is a recv */
int recv_response;
char * recv_response;
char * recv_request;
int optional;
bool advance_state;
57 changes: 39 additions & 18 deletions src/call.cpp
Original file line number Diff line number Diff line change
@@ -2348,7 +2348,7 @@ bool call::process_unexpected(const char* msg)
if (curmsg -> recv_request) {
desc += snprintf(desc, MAX_HEADER_LEN - (desc - buffer), "while expecting '%s' ", curmsg -> recv_request);
} else {
desc += snprintf(desc, MAX_HEADER_LEN - (desc - buffer), "while expecting '%d' ", curmsg -> recv_response);
desc += snprintf(desc, MAX_HEADER_LEN - (desc - buffer), "while expecting '%s' ", curmsg -> recv_response);
}
} else if (curmsg -> M_type == MSG_TYPE_SEND) {
desc += snprintf(desc, MAX_HEADER_LEN - (desc - buffer), "while sending ");
@@ -4451,24 +4451,45 @@ bool call::matches_scenario(unsigned int index, int reply_code, char * request,
} else {
return !strcmp(curmsg->recv_request, request);
}
} else if (curmsg->recv_response && (curmsg->recv_response == reply_code)) {
/* This is a potential candidate, we need to match transactions. */
if (curmsg->response_txn) {
if (transactions[curmsg->response_txn - 1].txnID && !strcmp(transactions[curmsg->response_txn - 1].txnID, txn)) {
return true;
} else {
return false;
} else if (curmsg->recv_response) {
if (curmsg->regexp_match) { // Match response code using regex
char reply_code_str[8];
snprintf(reply_code_str,8,"%u",reply_code); // Convert the response code to string
if (curmsg->regexp_compile == nullptr) {
regex_t *re = new regex_t;
/* No regex match position needed (NOSUB), we're simply
* looking for the <request method="INVITE|REGISTER"../>
* regex. */
if (regcomp(re, curmsg->recv_response, REGCOMP_PARAMS|REG_NOSUB)) {
ERROR("Invalid regular expression for index %d: %s", index, curmsg->recv_response);
}
curmsg->regexp_compile = re;
}
} else if (index == 0) {
/* Always true for the first message. */
return true;
} else if (curmsg->recv_response_for_cseq_method_list &&
strstr(curmsg->recv_response_for_cseq_method_list, responsecseqmethod)) {
/* If we do not have a transaction defined, we just check the CSEQ method. */
return true;
} else {
return false;
}
if (regexec(curmsg->regexp_compile, reply_code_str, (size_t)0, nullptr, REGEXEC_PARAMS)) {
return false;
}
} else { // Exact numerical match
if (atoi(curmsg->recv_response)!=reply_code) {
return false;
}
}
/* This is a potential candidate, we need to match transactions. */
if (curmsg->response_txn) {
if (transactions[curmsg->response_txn - 1].txnID && !strcmp(transactions[curmsg->response_txn - 1].txnID, txn)) {
return true;
} else {
return false;
}
} else if (index == 0) {
/* Always true for the first message. */
return true;
} else if (curmsg->recv_response_for_cseq_method_list &&
strstr(curmsg->recv_response_for_cseq_method_list, responsecseqmethod)) {
/* If we do not have a transaction defined, we just check the CSEQ method. */
return true;
} else {
return false;
}
}

return false;
2 changes: 1 addition & 1 deletion src/logger.cpp
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ void print_count_file(FILE* f, int header)
}
} else if (curmsg->recv_response) {
if (header) {
sprintf(temp_str, "%u_%d_", index, curmsg->recv_response);
sprintf(temp_str, "%u_%s_", index, curmsg->recv_response);

fprintf(f, "%sRecv%s", temp_str, stat_delimiter);
fprintf(f, "%sRetrans%s", temp_str, stat_delimiter);
5 changes: 3 additions & 2 deletions src/scenario.cpp
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ message::message(int index, const char *desc)
retrans_delay = 0;
timeout = 0;

recv_response = 0;
recv_response = nullptr; // free on exit
recv_request = nullptr; // free on exit
optional = 0;
advance_state = true;
@@ -116,6 +116,7 @@ message::~message()
free(pause_desc);
delete(send_scheme);
free(recv_request);
free(recv_response);
if (regexp_compile != nullptr) {
regfree(regexp_compile);
}
@@ -891,7 +892,7 @@ scenario::scenario(char * filename, int deflt)
curmsg->M_type = MSG_TYPE_RECV;
/* Received messages descriptions */
if((cptr = xp_get_value("response"))) {
curmsg ->recv_response = get_long(cptr, "response code");
curmsg ->recv_response = strdup(cptr);
if (method_list) {
curmsg->recv_response_for_cseq_method_list = strdup(method_list);
}
4 changes: 2 additions & 2 deletions src/screen.cpp
Original file line number Diff line number Diff line change
@@ -529,10 +529,10 @@ void ScreenPrinter::draw_scenario_screen()
} else if (curmsg->recv_response) {
if (creationMode == MODE_SERVER) {
buf_len += snprintf(buf + buf_len, bufsiz - buf_len,
" ----------> %-10d ", curmsg->recv_response);
" ----------> %-10s ", curmsg->recv_response);
} else {
buf_len += snprintf(buf + buf_len, bufsiz - buf_len,
" %10d <---------- ", curmsg->recv_response);
" %10s <---------- ", curmsg->recv_response);
}

if (curmsg->start_rtd) {

0 comments on commit d6c0288

Please sign in to comment.