@@ -2348,7 +2348,7 @@ bool call::process_unexpected(const char* msg)
2348
2348
if (curmsg -> recv_request) {
2349
2349
desc += snprintf (desc, MAX_HEADER_LEN - (desc - buffer), " while expecting '%s' " , curmsg -> recv_request);
2350
2350
} else {
2351
- desc += snprintf (desc, MAX_HEADER_LEN - (desc - buffer), " while expecting '%d ' " , curmsg -> recv_response);
2351
+ desc += snprintf (desc, MAX_HEADER_LEN - (desc - buffer), " while expecting '%s ' " , curmsg -> recv_response);
2352
2352
}
2353
2353
} else if (curmsg -> M_type == MSG_TYPE_SEND) {
2354
2354
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,
4451
4451
} else {
4452
4452
return !strcmp (curmsg->recv_request , request);
4453
4453
}
4454
- } else if (curmsg->recv_response && (curmsg->recv_response == reply_code)) {
4455
- /* This is a potential candidate, we need to match transactions. */
4456
- if (curmsg->response_txn ) {
4457
- if (transactions[curmsg->response_txn - 1 ].txnID && !strcmp (transactions[curmsg->response_txn - 1 ].txnID , txn)) {
4458
- return true ;
4459
- } else {
4460
- return false ;
4454
+ } else if (curmsg->recv_response ) {
4455
+ if (curmsg->regexp_match ) { // Match response code using regex
4456
+ char reply_code_str[8 ];
4457
+ snprintf (reply_code_str,8 ," %u" ,reply_code); // Convert the response code to string
4458
+ if (curmsg->regexp_compile == nullptr ) {
4459
+ regex_t *re = new regex_t ;
4460
+ /* No regex match position needed (NOSUB), we're simply
4461
+ * looking for the <request method="INVITE|REGISTER"../>
4462
+ * regex. */
4463
+ if (regcomp (re, curmsg->recv_response , REGCOMP_PARAMS|REG_NOSUB)) {
4464
+ ERROR (" Invalid regular expression for index %d: %s" , index , curmsg->recv_response );
4465
+ }
4466
+ curmsg->regexp_compile = re;
4461
4467
}
4462
- } else if (index == 0 ) {
4463
- /* Always true for the first message. */
4464
- return true ;
4465
- } else if (curmsg->recv_response_for_cseq_method_list &&
4466
- strstr (curmsg->recv_response_for_cseq_method_list , responsecseqmethod)) {
4467
- /* If we do not have a transaction defined, we just check the CSEQ method. */
4468
- return true ;
4469
- } else {
4470
- return false ;
4471
- }
4468
+ if (regexec (curmsg->regexp_compile , reply_code_str, (size_t )0 , nullptr , REGEXEC_PARAMS)) {
4469
+ return false ;
4470
+ }
4471
+ } else { // Exact numerical match
4472
+ if (atoi (curmsg->recv_response )!=reply_code) {
4473
+ return false ;
4474
+ }
4475
+ }
4476
+ /* This is a potential candidate, we need to match transactions. */
4477
+ if (curmsg->response_txn ) {
4478
+ if (transactions[curmsg->response_txn - 1 ].txnID && !strcmp (transactions[curmsg->response_txn - 1 ].txnID , txn)) {
4479
+ return true ;
4480
+ } else {
4481
+ return false ;
4482
+ }
4483
+ } else if (index == 0 ) {
4484
+ /* Always true for the first message. */
4485
+ return true ;
4486
+ } else if (curmsg->recv_response_for_cseq_method_list &&
4487
+ strstr (curmsg->recv_response_for_cseq_method_list , responsecseqmethod)) {
4488
+ /* If we do not have a transaction defined, we just check the CSEQ method. */
4489
+ return true ;
4490
+ } else {
4491
+ return false ;
4492
+ }
4472
4493
}
4473
4494
4474
4495
return false ;
0 commit comments