📄 scenario.cpp
字号:
} } } } #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; } } 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 not twin sipp" " address have been passed ! used -3pcc option\n"); } 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 not " "twin sipp address have been passed ! used " "-3pcc option\n"); } 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]] != NULL) { delete(scenVariableTable[currentTabVarId[0]]); scenVariableTable[currentTabVarId[0]] = NULL; } scenVariableTable[currentTabVarId[0]] = new CVariable(currentRegExp); if(!(scenVariableTable[currentTabVarId[0]] ->isRegExpWellFormed())) ERROR_P1("Regexp '%s' is not valid in xml " "scenario file", currentRegExp); } 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]] != NULL) { delete(scenVariableTable[currentTabVarId[i]]); scenVariableTable[currentTabVarId[i]] = NULL; } scenVariableTable[currentTabVarId[i]] = new CVariable(currentRegExp); if(!(scenVariableTable[currentTabVarId[i]] ->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; } } else { // end "assign_to" ERROR("'ereg' action without 'assign_to' " "argument (mandatory)"); } if(currentRegExp != NULL) { delete[] currentRegExp; } currentRegExp = NULL; } else { // end if regexp ERROR("'ereg' action without 'regexp' argument (mandatory)"); } } /* end !strcmp(actionElem, "ereg") */ else if(!strcmp(actionElem, "log")) { if(ptr = xp_get_value((char *)"message")) { tmpAction.setActionType(CAction::E_AT_LOG_TO_FILE); tmpAction.setMessage(ptr); /* the action is well formed, adding it in the */ /* tmpActionTable */ tmpActions.setAction(tmpAction); tmpActionNumber++; } } /* end !strcmp(actionElem, "log") */ else if(!strcmp(actionElem, "exec")) { if(ptr = xp_get_value((char *)"command")) { tmpAction.setActionType(CAction::E_AT_EXECUTE_CMD); tmpAction.setCmdLine(ptr); /* the action is well formed, adding it in the */ /* tmpActionTable */ tmpActions.setAction(tmpAction); tmpActionNumber++; } /* end (ptr = xp_get_value("command") */ else if(ptr = xp_get_value((char *)"int_cmd")) { CAction::T_IntCmdType type(CAction::E_INTCMD_STOPCALL); /* assume the default */ if (!strcmp(ptr, "stop_now")) { type = CAction::E_INTCMD_STOP_NOW; } else if (!strcmp(ptr, "stop_gracefully")) { type = CAction::E_INTCMD_STOP_ALL; } else if (!strcmp(ptr, "stop_call")) { type = CAction::E_INTCMD_STOPCALL; } /* the action is well formed, adding it in the */ /* tmpActionTable */ tmpAction.setActionType(CAction::E_AT_EXEC_INTCMD); tmpAction.setIntCmd(type); tmpActions.setAction(tmpAction); tmpActionNumber++; } else { ERROR("illegal exec line\n"); } } xp_close_element(); recvScenarioLen++; } // end while // creation the action list for this message if(tmpActionNumber != 0) { if(scenario[scenario_len] != NULL) { if(scenario[scenario_len]->M_actions != NULL) delete(scenario[scenario_len]->M_actions); scenario[scenario_len]->M_actions = new CActions(tmpActions); } } } // end if "action" xp_close_element(); }// end open element}// char* manipulation : create a int[] from a char*// test first is the char* is formed by int separeted by coma// and then create the tableint isWellFormed(char * P_listeStr, int * nombre){ char * ptr = P_listeStr; int sizeOf; bool isANumber; (*nombre) = 0; sizeOf = strlen(P_listeStr); // getting the number if(sizeOf > 0) { // is the string well formed ? [0-9] [,] isANumber = false; for(int i=0; i<=sizeOf; i++) { switch(ptr[i]) { case ',': if(isANumber == false) { return(0); } else { (*nombre)++; } isANumber = false; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': isANumber = true; break; case '\t': case ' ' : break; case '\0': if(isANumber == false) { return(0); } else { (*nombre)++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -