📄 scenario.cpp
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author : Richard GAYRAUD - 04 Nov 2003 * From Hewlett Packard Company. * Shriram Natarajan [snatarajan@longboard.com] */#include "sipp.hpp"/************************ Class Constructor *************************/message::message(){ //ugly memset(this, 0, sizeof(message)); pause = 0; bShouldRecordRoutes = 0; send_scheme = NULL; retrans_delay = 0; recv_response = 0; recv_request = NULL; optional = 0; /* Anyway */ start_rtd = 0; stop_rtd = 0; lost = 0; crlf = 0; /* Statistics */ nb_sent = 0; nb_recv = 0; nb_sent_retrans = 0; nb_recv_retrans = 0; nb_timeout = 0; nb_unexp = 0; nb_lost = 0; M_actions = NULL; M_type = 0;#ifdef __3PCC__ M_sendCmdData = NULL; M_nbCmdSent = 0; M_nbCmdRecv = 0;#endif content_length_flag = ContentLengthNoPresent;}message::~message(){ if(M_actions != NULL) delete(M_actions); M_actions = NULL; if(send_scheme != NULL) free (send_scheme); send_scheme = NULL; if(recv_request != NULL) free (recv_request); recv_request = NULL;#ifdef __3PCC__ if(M_sendCmdData != NULL) delete(M_sendCmdData); M_sendCmdData = NULL;#endif}/******** Global variables which compose the scenario file **********/message* scenario[100];CVariable* scenVariableTable[SCEN_VARIABLE_SIZE];int scenario_len = 0;char scenario_name[255];int toolMode = MODE_CLIENT;unsigned long scenario_duration = 0;/********************** Scenario File analyser **********************/void load_scenario(char * filename, int deflt){ char * elem; unsigned int scenario_file_cursor = 0; int L_content_length = 0 ; if(filename) { if(!xp_set_xml_buffer_from_file(filename)) { ERROR_P1("Unable to load or parse '%s' xml scenario file", filename); } } else { if(!xp_set_xml_buffer_from_string(default_scenario[deflt])) { ERROR("Unable to load default xml scenario file"); } } // set all variable in scenVariable table to NULL for(int i=0; i<SCEN_VARIABLE_SIZE; i++) { scenVariableTable[i] = NULL; } elem = xp_open_element(0); if(strcmp("scenario", elem)) { ERROR("No 'scenario' section in xml scenario file"); } if(xp_get_value((char *)"name")) { strcpy(scenario_name, xp_get_value((char *)"name")); } else { scenario_name[0] = 0; } scenario_len = 0; scenario_file_cursor = 0; while(elem = xp_open_element(scenario_file_cursor)) { char * ptr; scenario_file_cursor ++; if(!strcmp(elem, "CallLengthRepartition")) { ptr = xp_get_value((char *)"value"); CStat::instance()->setRepartitionCallLength(ptr); } else if(!strcmp(elem, "ResponseTimeRepartition")) { ptr = xp_get_value((char *)"value"); CStat::instance()->setRepartitionResponseTime(ptr); } else { /** Message Case */ scenario[scenario_len] = new message(); scenario[scenario_len] -> content_length_flag = message::ContentLengthNoPresent; // Initialize to No present if(!strcmp(elem, "send")) { scenario[scenario_len]->M_type = MSG_TYPE_SEND; /* Sent messages descriptions */ if(ptr = xp_get_cdata()) { char * msg; int removed_clrf = 0; while((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n')) ptr++; msg = scenario[scenario_len] -> send_scheme = (char *) malloc(strlen(ptr) + 3); if(!msg) { ERROR("Memory Overflow"); } strcpy(msg, ptr); L_content_length = xp_get_content_length(msg); switch (L_content_length) { case -1 : // the msg does not contain content-length field break ; case 0 : scenario[scenario_len] -> content_length_flag = message::ContentLengthValueZero; // Initialize to No present break ; default : scenario[scenario_len] -> content_length_flag = message::ContentLengthValueNoZero; // Initialize to No present break ; } ptr = msg + strlen(msg); ptr --; while((ptr >= msg) && ((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n'))) { if(*ptr == '\n') { removed_clrf++; } *ptr-- = 0; } if(ptr == msg) { ERROR("Empty cdata in xml scenario file"); } if(!strstr(msg, "\n\n")) { strcat(msg, "\n\n"); } 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)); } if((msg[strlen(msg) - 1] != '\n') && (removed_clrf)) { strcat(msg, "\n"); } } else { ERROR("No CDATA in 'send' section of xml scenario file"); } if(ptr = xp_get_value((char *)"retrans")) { scenario[scenario_len] -> retrans_delay = atol(ptr); } if(ptr = xp_get_value((char *)"rtd")) { if(!strcmp(ptr, (char *)"true")) { scenario[scenario_len] -> stop_rtd = true; } } if(ptr = xp_get_value((char *)"start_rtd")) { if(!strcmp(ptr, (char *)"true")) { scenario[scenario_len] -> start_rtd = true; } } } else if(!strcmp(elem, (char *)"recv")) { scenario[scenario_len]->M_type = MSG_TYPE_RECV; /* Received messages descriptions */ if(ptr = xp_get_value((char *)"response")) { scenario[scenario_len] -> recv_response = atol(ptr); } if(ptr = xp_get_value((char *)"request")) { scenario[scenario_len] -> recv_request = strdup(ptr); } if(ptr = xp_get_value((char *)"rtd")) { if(!strcmp(ptr, "true")) { scenario[scenario_len] -> stop_rtd = true; } } if(ptr = xp_get_value((char *)"start_rtd")) { if(!strcmp(ptr, (char *)"true")) { scenario[scenario_len] -> start_rtd = true; } } if(ptr = xp_get_value((char *)"optional")) { if(!strcmp(ptr, "true")) { scenario[scenario_len] -> optional = true; } } /* record the route set */ /* TODO disallow optional and rrs to coexist? */ if(ptr = xp_get_value((char *)"rrs")) { if(!strcmp(ptr, "true")) { scenario[scenario_len] -> bShouldRecordRoutes = true; } } getActionForThisMessage(); } else if(!strcmp(elem, "pause")) { 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 { scenario[scenario_len] -> pause = -1; scenario_duration += duration; } } #ifdef __3PCC__ else if(!strcmp(elem, "recvCmd")) { scenario[scenario_len]->M_type = MSG_TYPE_RECVCMD; getActionForThisMessage(); } else if(!strcmp(elem, "sendCmd")) { 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; } 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -