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

📄 scenario.cpp

📁 学习sip协议的好工具
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            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(){  char *        actionElem;  CActions      tmpActions(100);  CAction       tmpAction;  int           tmpActionNumber;  char *        currentRegExp = NULL;  char *        buffer = NULL;  unsigned int* currentTabVarId = NULL;  int           currentNbVarId;  unsigned int  recvScenarioLen;  char * ptr;  if(actionElem = xp_open_element(0)) {    if(!strcmp(actionElem, "action")) {      tmpActionNumber = 0;      tmpActions.reset();      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) {                for(int i=0; i<currentNbVarId; i++) {                  if(currentTabVarId[i] <  SCEN_VARIABLE_SIZE) {                    tmpAction.setVarId(currentTabVarId[i]);                    /* the action is well formed, adding it in the */                    /* tmpActionTable */                    tmpActions.setAction(tmpAction);                    tmpActionNumber++;                    /* 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);                   }                }                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")        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)++;                }               break;            default:              return(0);            }        } // end for    }  return(1);}int createIntegerTable(char * P_listeStr,                        unsigned int ** listeInteger,                        int * sizeOfList){  int nb=0;  char * ptr = P_listeStr;  char * ptr_prev = P_listeStr;  unsigned int current_int;  int sizeOf;  bool isANumber;   if(isWellFormed(P_listeStr, sizeOfList) == 1)    {      (*listeInteger) = new unsigned int[(*sizeOfList)];      while((*ptr) != ('\0'))        {          if((*ptr) == ',')            {              sscanf(ptr_prev, "%u", &current_int);              if (nb<(*sizeOfList))                (*listeInteger)[nb] = current_int;              nb++;              ptr_prev = ptr+1;            }          ptr++;        }      // Read the last      sscanf(ptr_prev, "%u", &current_int);       if (nb<(*sizeOfList))        (*listeInteger)[nb] = current_int;      nb++;      return(1);    }  return(0);}// TIP: to integrate an existing XML scenario, use the following sed line:// cat ../3pcc-controller-B.xml | sed -e 's/\"/\\\"/g' -e 's/\(.*\)/\"\1\\n\"/'char * default_scenario [] = {  /************* Default_scenario[0] ***************/(char *)"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n""<!DOCTYPE scenario SYSTEM \"sipp.dtd\">\n""\n""<!-- This program is free software; you can redistribute it and/or      -->\n""<!-- modify it under the terms of the GNU General Public License as     -->\n""<!-- published by the Free Software Foundation; either version 2 of the -->\n""<!-- License, or (at your option) any later version.                    -->\n""<!--                                                                    -->\n""<!-- This program is distributed in the hope that it will be useful,    -->\n""<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of     -->\n""<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      -->\n""<!-- GNU General Public License for more details.                       -->\n""<!--                                                                    -->\n""<!-- You should have received a copy of the GNU General Public License  -->\n""<!-- along with this program; if not, write to the                      -->\n""<!-- Free Software Foundation, Inc.,                                    -->\n""<!-- 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA             -->\n""<!--                                                                    -->\n""<!--                 Sipp default 'uac' scenario.                       -->\n""<!--                                                                    -->\n""\n""<scenario name=\"Basic Sipstone UAC\">\n""  <!-- In client mode (sipp placing calls), the Call-ID MUST be         -->\n""  <!-- generated by sipp. To do so, use [call_id] token.                -->\n""  <send retrans=\"500\">\n""    <![CDATA[\n""\n""      INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n""      Via: SIP/2.0/[transport] [local_ip]:[local_port]\n""      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n""      To: sut <sip:[service]@[remote_ip]:[remote_port]>\n""      Call-ID: [call_id]\n""      CSeq: 1 INVITE\n""      Contact: sip:sipp@[local_ip]:[local_port]\n""      Max-Forwards: 70\n""      Subject: Performance Test\n""      Content-Type: application/sdp\n""      Content-Length: 136\n""\n""      v=0\n""      o=user1 53655765 2353687637 IN IP4 127.0.0.1\n""      s=-\n""      c=IN IP4 [media_ip]\n""      t=0 0\n""      m=audio [media_port] RTP/AVP 0\n""      a=rtpmap:0 PCMU/8000\n""\n""    ]]>\n""  </send>\n""\n""  <recv response=\"100\"\n""        optional=\"true\">\n""  </recv>\n""\n""  <recv response=\"180\" optional=\"true\">\n""  </recv>\n""\n""  <!-- By adding rrs=\"true\" (Record Route Sets), the route sets         -->\n""  <!-- are saved and used for following messages sent. Useful to test   -->\n""  <!-- against stateful SIP proxies/B2BUAs.                             -->\n""  <recv response=\"200\" rtd=\"true\">\n""  </recv>\n""\n""  <!-- Packet lost can be simulated in any send/recv message by         -->\n""  <!-- by adding the 'lost = \"10\"'. Value can be [1-100] percent.       -->\n""  <send>\n""    <![CDATA[\n""\n""      ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n""      Via: SIP/2.0/[transport] [local_ip]:[local_port]\n""      From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n""      To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n""      Call-ID: [call_id]\n""      CSeq: 1 ACK\n""      Contact: sip:sipp@[local_ip]:[local_port]\n""      Max-Forwards: 70\n""      Subject: Performance Test\n""      Content-Length: 0\n""\n""    ]]>\n""  </send>\n""\n""  <!-- This delay can be customized by the -d command-line option       -->\n""  <!-- or by adding a 'milliseconds = \"value\"' option here.             -->\n""  <pause/>\n""\n"

⌨️ 快捷键说明

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