📄 scenario.cpp
字号:
#endif getActionForThisMessage(); } else if(!strcmp(elem, "pause")) { if (recv_count) { if (recv_count != recv_opt_count) { recv_count = 0; recv_opt_count = 0; } else { ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor); } } scenario[scenario_len]->M_type = MSG_TYPE_PAUSE; if(ptr = xp_get_value((char *)"milliseconds")) { scenario[scenario_len] -> pause = atol(ptr); scenario_duration += scenario[scenario_len] -> pause; } else if(ptr = xp_get_value((char *)"min")) { scenario[scenario_len] -> pause_min = atol(ptr); if(ptr = xp_get_value((char *)"max")) { scenario[scenario_len] -> pause_max = atol(ptr); if (scenario[scenario_len] -> pause_max < scenario[scenario_len] -> pause_min) { ERROR("Min is greater than max in variable pause!"); } /* Update scenario duration with max duration */ scenario_duration += scenario[scenario_len] -> pause_max; } else { ERROR("Min without max for a variable pause"); } } else if(ptr = xp_get_value((char *)"max")) { scenario[scenario_len] -> pause_max = atol(ptr); /* Update scenario duration with max duration */ scenario_duration += scenario[scenario_len] -> pause_max; if(ptr = xp_get_value((char *)"min")) { scenario[scenario_len] -> pause_min = atol(ptr); if (scenario[scenario_len] -> pause_max < scenario[scenario_len] -> pause_min) { ERROR("Min is greater than max in variable pause!"); } } else { ERROR("Max without min for a variable pause"); } } else { scenario[scenario_len] -> pause = -1; scenario_duration += duration; } getActionForThisMessage(); } else if(!strcmp(elem, "nop")) { /* Does nothing at SIP level, only meant to handle actions */ scenario[scenario_len]->M_type = MSG_TYPE_NOP; getActionForThisMessage(); }#ifdef __3PCC__ else if(!strcmp(elem, "recvCmd")) { if (recv_count) { if (recv_count != recv_opt_count) { recv_count = 0; recv_opt_count = 0; } else { ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor); } } scenario[scenario_len]->M_type = MSG_TYPE_RECVCMD; getActionForThisMessage(); } else if(!strcmp(elem, "sendCmd")) { if (recv_count) { if (recv_count != recv_opt_count) { recv_count = 0; recv_opt_count = 0; } else { ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor); } } scenario[scenario_len]->M_type = MSG_TYPE_SENDCMD; /* Sent messages descriptions */ if(ptr = xp_get_cdata()) { char * msg; while((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n')) ptr++; msg = scenario[scenario_len] -> M_sendCmdData = (char *) malloc(strlen(ptr) + 3); if(!msg) { ERROR("Memory Overflow"); } strcpy(msg, ptr); ptr = msg + strlen(msg); ptr --; while((ptr >= msg) && ((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n'))) { *ptr-- = 0; } if(ptr != msg) { while(ptr = strstr(msg, "\n ")) { memmove(((char *)(ptr + 1)), ((char *)(ptr + 2)), strlen(ptr) - 1); } while(ptr = strstr(msg, " \n")) { memmove(((char *)(ptr)), ((char *)(ptr + 1)), strlen(ptr)); } } } } #endif else { ERROR_P1("Unknown element '%s' in xml scenario file", elem); } if(ptr = xp_get_value((char *)"lost")) { scenario[scenario_len] -> lost = atol(ptr); lose_packets = 1; } if(ptr = xp_get_value((char *)"crlf")) { scenario[scenario_len] -> crlf = 1; } if ( 0 != ( ptr = xp_get_value((char *)"next") ) ) { scenario[scenario_len] -> next = atol(ptr); if ( 0 != ( ptr = xp_get_value((char *)"test") ) ) { scenario[scenario_len] -> test = atol(ptr); } else { scenario[scenario_len] -> test = -1; } } else { scenario[scenario_len] -> next = 0; } scenario_len++; } /** end * Message case */ xp_close_element(); } // end while}// Determine in which mode the sipp tool has been // launched (client, server, 3pcc client, 3pcc server)void computeSippMode(){ bool isRecvCmdFound = false; bool isSendCmdFound = false; bool isFirstMessageFound = true; toolMode = -1; for(int i=0; i<scenario_len; i++) { switch(scenario[i] -> M_type) { case MSG_TYPE_SEND: if(isFirstMessageFound) toolMode = MODE_CLIENT; isFirstMessageFound = false; break; case MSG_TYPE_RECV: if(isFirstMessageFound) toolMode = MODE_SERVER; isFirstMessageFound = false; break;#ifdef __3PCC__ case MSG_TYPE_SENDCMD: isSendCmdFound = true; if(!isRecvCmdFound) { if (false == isFirstMessageFound && toolMode == MODE_SERVER) { /* * If it is a server already, then start it in * 3PCC A passive mode */ toolMode = MODE_3PCC_A_PASSIVE; } else { toolMode = MODE_3PCC_CONTROLLER_A; } if(!twinSippMode) ERROR("sendCmd message found in scenario but no twin sipp" " address has been passed! Use -3pcc option.\n"); return; } isFirstMessageFound = false; break; case MSG_TYPE_RECVCMD: isRecvCmdFound = true; if(!isSendCmdFound) { toolMode = MODE_3PCC_CONTROLLER_B; if(!twinSippMode) ERROR("sendCmd message found in scenario but no " "twin sipp address has been passed! Use " "-3pcc option\n"); return; } isFirstMessageFound = false; break;#endif // __3PCC__ default: break; } if(toolMode == -1) ERROR("Unable to determine mode of the tool (server, " "client, 3PCC controller A, 3PCC controller B).\n"); }}// Action list for the message indexed by message_index in // the scenariovoid getActionForThisMessage(){ const int MAX_ACTIONS(100); char * actionElem; CActions tmpActions(MAX_ACTIONS); CAction tmpAction; int tmpActionNumber(0); char * currentRegExp = NULL; char * buffer = NULL; unsigned int* currentTabVarId = NULL; int currentNbVarId; unsigned int recvScenarioLen; char * ptr; int sub_currentNbVarId; tmpActions.reset(); if(actionElem = xp_open_element(0)) { if(!strcmp(actionElem, "action")) { tmpActionNumber = 0; recvScenarioLen = 0; while(actionElem = xp_open_element(recvScenarioLen)) { if(!strcmp(actionElem, "ereg")) { if(ptr = xp_get_value((char *)"regexp")) { // keeping regexp expression in memory if(currentRegExp != NULL) delete[] currentRegExp; currentRegExp = new char[strlen(ptr)+1]; buffer = new char[strlen(ptr)+1]; xp_replace(ptr, buffer, "<", "<"); xp_replace(buffer, currentRegExp, ">", ">"); if(buffer != NULL) delete[] buffer; 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); } } else { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } } else { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } } else { tmpAction.setLookingPlace(CAction::E_LP_MSG); tmpAction.setLookingChar(NULL); } // end if-else search_in if(ptr = xp_get_value((char *)"check_it")) { if(!strcmp(ptr, (char *)"true")) { tmpAction.setCheckIt(true); } else { tmpAction.setCheckIt(false); } } else { tmpAction.setCheckIt(false); } if(ptr = xp_get_value((char *)"assign_to")) { if(createIntegerTable(ptr, ¤tTabVarId, ¤tNbVarId) == 1) { if(currentTabVarId[0] < SCEN_VARIABLE_SIZE) { tmpAction.setVarId(currentTabVarId[0]); /* and creating the associated variable */ if (scenVariableTable[currentTabVarId[0]][scenario_len] != NULL) { delete(scenVariableTable[currentTabVarId[0]][scenario_len]); scenVariableTable[currentTabVarId[0]][scenario_len] = NULL; } scenVariableTable[currentTabVarId[0]][scenario_len] = new CVariable(currentRegExp); if(!(scenVariableTable[currentTabVarId[0]][scenario_len] ->isRegExpWellFormed())) ERROR_P1("Regexp '%s' is not valid in xml " "scenario file", currentRegExp); } else { ERROR("Too many call variables in the scenario. Please change '#define SCEN_VARIABLE_SIZE' in scenario.hpp and recompile SIPp"); } if (currentNbVarId > 1 ) { sub_currentNbVarId = currentNbVarId - 1 ; tmpAction.setNbSubVarId(sub_currentNbVarId); for(int i=1; i<= sub_currentNbVarId; i++) { if(currentTabVarId[i] < SCEN_VARIABLE_SIZE) { tmpAction.setSubVarId(currentTabVarId[i]); /* and creating the associated variable */ if (scenVariableTable[currentTabVarId[i]][scenario_len] != NULL) { delete(scenVariableTable[currentTabVarId[i]][scenario_len]); scenVariableTable[currentTabVarId[i]][scenario_len] = NULL; } scenVariableTable[currentTabVarId[i]][scenario_len] = new CVariable(currentRegExp); if(!(scenVariableTable[currentTabVarId[i]][scenario_len] ->isRegExpWellFormed())) ERROR_P1("Regexp '%s' is not valid in xml " "scenario file", currentRegExp); } } } /* the action is well formed, adding it in the */ /* tmpActionTable */ tmpActions.setAction(tmpAction); tmpActionNumber++; delete[] currentTabVarId; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -