⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scenario.cpp

📁 sipp is sip protocal testing tool.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
          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 = get_long(ptr, "lost percentage");        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 = get_long(ptr, "next jump");         if ( 0 != ( ptr = xp_get_value((char *)"test") ) ) {           scenario[scenario_len] -> test = get_long(ptr, "test variable");         }         else {           scenario[scenario_len] -> test = -1;         }      } else {        scenario[scenario_len] -> next = 0;      }      if (0 != (ptr = xp_get_value((char *)"ontimeout")) ) {        if ((::scenario[scenario_len]->on_timeout = get_long(ptr, "timeout jump")) >= MAX_LABELS) {            ERROR_P1("Ontimeout label larger than max supported %d", MAX_LABELS-1);        }      }           if (++scenario_len >= SCEN_MAX_MESSAGES) {          ERROR("Too many items in xml scenario file");      }    } /** 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_PAUSE:        case MSG_TYPE_NOP:	  /* Allow pauses or nops to go first. */	  continue;        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, "&lt;", "<");            xp_replace(buffer, currentRegExp, "&gt;", ">");            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,                                     &currentTabVarId,                                     &currentNbVarId) == 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;              }            } 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++;#ifdef PCAPPLAY          } else if (ptr = xp_get_value((char *) "play_pcap_audio")) {            tmpAction.setPcapArgs(ptr);            tmpAction.setActionType(CAction::E_AT_PLAY_PCAP_AUDIO);            tmpActions.setAction(tmpAction);            tmpActionNumber++;            hasMedia = 1;          } else if (ptr = xp_get_value((char *) "play_pcap_video")) {            tmpAction.setPcapArgs(ptr);            tmpAction.setActionType(CAction::E_AT_PLAY_PCAP_VIDEO);            tmpActions.setAction(tmpAction);            tmpActionNumber++;            hasMedia = 1;#endif          } else {              ERROR("illegal <exec> in the scenario\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])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -