From: Peter H. <pet...@ne...> - 2005-08-26 09:06:58
|
Some changes we have made in our local copy to meet this requirement are to add the following functionality to regexp for the "hdr" matching case: 1) case_indep="true" to look for a header ignoring case 2) occurrence="n" to find the nth occurrence of a header 3) start_line="true" to look only at start of line The occurrence option will allow you to set different variables to each of the headers you are looking for. I have also fixed a bug which might crash SIPp for packets longer than 1024 bytes (this may be already incorporated). Note that the current hdr match looks anywhere in the message and I have left this as the default (with start of line as the option). The code changes are below (I've done them based on the version we use, but I think they match up with the current versions): In scenario.cpp, change this section of code: tmpAction.setVarType(CAction::E_VT_REGEXP); tmpAction.setActionType(CAction::E_AT_ASSIGN_FROM_REGEXP); if(ptr = xp_get_value((char *)"search_in")){ if(!strcmp(ptr, (char *)"msg")) { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } else if (!strcmp(ptr, (char *)"hdr")) { if(ptr = xp_get_value((char *)"header")) { if(strlen(ptr) > 0) { tmpAction.setLookingPlace(CAction::E_LP_HDR); tmpAction.setLookingChar(ptr); } else { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } To: tmpAction.setVarType(CAction::E_VT_REGEXP); tmpAction.setActionType(CAction::E_AT_ASSIGN_FROM_REGEXP); // warning - although these are detected for both msg and hdr // they are only implemented for search_in="hdr" if ( 0 != ( ptr = xp_get_value((char *)"case_indep") ) && 0 == strcmp(ptr, "true")) tmpAction.setCaseIndep(true); else tmpAction.setCaseIndep(false); if ( 0 != ( ptr = xp_get_value((char *)"start_line") ) && 0 == strcmp(ptr, "true")) tmpAction.setHeadersOnly(true); else tmpAction.setHeadersOnly(false); if ( 0 != ( ptr = xp_get_value((char *)"search_in") ) ) { tmpAction.setOccurrence(1); if ( 0 == strcmp(ptr, (char *)"msg") ) { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } else if (!strcmp(ptr, (char *)"hdr")) { if ( 0 != ( ptr = xp_get_value((char *)"header") ) ) { if ( 0 < strlen(ptr) ) { tmpAction.setLookingPlace(CAction::E_LP_HDR); tmpAction.setLookingChar(ptr); if (0 != (ptr = xp_get_value((char *)"occurrence"))) { tmpAction.setOccurrence(atol(ptr)); } } else { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } In actions.hpp, after char* getLookingChar(); Add: bool getCaseIndep(); int getOccurrence(); bool getHeadersOnly(); After: void setAction (CAction P_action); Add: void setCaseIndep (bool P_value); void setOccurrence (int P_value); void setHeadersOnly (bool P_value); and after: int M_varId; Add: bool M_caseIndep; int M_occurrence; bool M_headersOnly; In actions.cpp, after: char* CAction::getLookingChar() { return(M_lookingChar); } Add: bool CAction::getCaseIndep() { return(M_caseIndep); } int CAction::getOccurrence() { return(M_occurrence); } bool CAction::getHeadersOnly() { return(M_headersOnly); } After: void CAction::setVarId (int P_value) { M_varId = P_value; } Add: void CAction::setCaseIndep (bool P_value) { M_caseIndep = P_value; } void CAction::setOccurrence (int P_value) { M_occurrence = P_value; } void CAction::setHeadersOnly (bool P_value) { M_headersOnly = P_value; } After: setCheckIt ( P_action.getCheckIt() ); Add: setCaseIndep ( P_action.getCaseIndep() ); setOccurrence ( P_action.getOccurrence() ); setHeadersOnly ( P_action.getHeadersOnly() ); After: M_lookingChar = NULL; Add: M_caseIndep = false; M_occurrence = 1; M_headersOnly = true; After: setCheckIt ( P_action.M_checkIt ); Add: setCaseIndep ( P_action.M_caseIndep ); setOccurrence ( P_action.M_occurrence ); setHeadersOnly ( P_action.M_headersOnly ); In call.hpp, change: void extractSubMessage(char * msg, char * matchingString, char* result); To: void extractSubMessage(char * msg, char * matchingString, char* result, bool case_indep, int occurrence, bool headers); In call.cpp, change the call to extractSubMessage to become: extractSubMessage (msg, currentAction->getLookingChar(), msgPart, currentAction->getCaseIndep(), currentAction->getOccurrence(), currentAction->getHeadersOnly()); and then replace the existing routine extractSubMessage with this: void CallContext::extractSubMessage(char * msg, char * matchingString, char* result, bool case_indep, int occurrence, bool headers) { char *ptr, *ptr1; int sizeOf; int i = 0; int len = strlen(matchingString); char mat1 = tolower(*matchingString); char mat2 = toupper(*matchingString); ptr = msg; while (*ptr) { if (!case_indep) { ptr = strstr(ptr, matchingString); if (ptr == NULL) break; if (headers == true && ptr != msg && *(ptr-1) != '\n') { ++ptr; continue; } } else { if (headers) { if (ptr != msg) { ptr = strchr(ptr, '\n'); if (ptr == NULL) break; ++ptr; if (*ptr == 0) break; } } else { ptr1 = strchr(ptr, mat1); ptr = strchr(ptr, mat2); if (ptr == NULL) { if (ptr1 == NULL) break; ptr = ptr1; } else { if (ptr1 != NULL && ptr1 < ptr) ptr = ptr1; } } if (strncasecmp(ptr, matchingString, len) != 0) { ++ptr; continue; } } // here with ptr pointing to a matching string if (occurrence <= 1) break; --occurrence; ++ptr; } if(ptr != NULL && *ptr != 0) { strncpy(result, ptr+len, MAX_SUB_MESSAGE_LENGTH); sizeOf = strlen(result); if(sizeOf >= MAX_SUB_MESSAGE_LENGTH) sizeOf = MAX_SUB_MESSAGE_LENGTH-1; while((i<sizeOf) && (result[i] != '\n') && (result[i] != '\r')) i++; result[i] = '\0'; } else { result[0] = '\0'; } } Hopefully Olivier will add this to the main version. Let me know of any issues or problems. Regards, Peter Peter Higginson Newport Networks Ltd, Direct line 01494 470694 http://www.newport-networks.com/ _____ From: sip...@li... [mailto:sip...@li...] On Behalf Of Siddharth Angrish Sent: 26 August 2005 06:48 To: sip...@li... Subject: [Sipp-users] Query regarding sipp regexp hi I have a query regarding regexp usage in a sipp (uas/uac) xml files. The situation is I am receiving a Response having more than 2 ( actually 3) Record-Route headers. I have to extract them and put them as Route headers in my subsequent outgoing Request. Currently I know how to extract one, put it in a variable and then use it. But how to extract more than one, as (I feel) the syntax of regexp identifying one or more headers is same. For example, The incoming message has : Record-Route: <sip:siddh@192.168.12.29:5070;lr> Record-Route: <sip:192.168.12.44:5060;lr;asasrr> Record-Route: <sip:192.168.12.44@192.168.12.51:5080;lr> The outgoing request should have : Route: <sip:siddh@192.168.12.29:5070;lr> Route: <sip:192.168.12.44:5060;lr;asasrr> Route: <sip:192.168.12.44@192.168.12.51:5080;lr> regards Siddharth |