📄 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 * Olivier Jacques * From Hewlett Packard Company. * Shriram Natarajan * Peter Higginson * Venkatesh * Lee Ballard * Guillaume TEISSIER from FTR&D * Wolfgang Beck */#include "sipp.hpp"/************************ Class Constructor *************************/message::message(){ //ugly memset(this, 0, sizeof(message)); pause = 0; pause_min = 0; pause_max = 0; sessions = 0; bShouldRecordRoutes = 0;#ifdef _USE_OPENSSL bShouldAuthenticate = 0;#endif 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; test = 0; next = 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[SCEN_MAX_MESSAGES];CVariable* scenVariableTable[SCEN_VARIABLE_SIZE][SCEN_MAX_MESSAGES];int scenario_len = 0;char scenario_name[255];int toolMode = MODE_CLIENT;unsigned long scenario_duration = 0;unsigned int labelArray[20];/********************** Scenario File analyser **********************/void load_scenario(char * filename, int deflt){ char * elem; char method_list[METHOD_LIST_LENGTH]; // hopefully the method list wont be longer than this char method_list_length = 0; // Enforce length, in case... unsigned int scenario_file_cursor = 0; int L_content_length = 0 ; unsigned int recv_count = 0; unsigned int recv_opt_count = 0; memset (method_list, 0, sizeof (method_list)); 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++) { for (int j=0; j<SCEN_MAX_MESSAGES; j++) { scenVariableTable[i][j] = 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 if(!strcmp(elem, "label")) { ptr = xp_get_value((char *)"id"); unsigned int labelNumber = atoi(ptr); if (labelNumber < (sizeof(labelArray)/sizeof(labelArray[0]))) { labelArray[labelNumber] = ::scenario_len; } } else { /** Message Case */ scenario[scenario_len] = new message(); scenario[scenario_len] -> content_length_flag = message::ContentLengthNoPresent; // Initialize to No present if(!strcmp(elem, "send")) { 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_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); // // If this is a request we are sending, then copy over the method so that we can associate // responses to the request // if (0 != strncmp (ptr, "SIP/2.0", 7) ) { char *methodEnd = ptr; int bytesToCopy = 0; while (*methodEnd != ' ') { methodEnd++; bytesToCopy++; } if (method_list_length + bytesToCopy + 1 > METHOD_LIST_LENGTH) { ERROR_P2("METHOD_LIST_LENGTH in scenario.hpp is too small (currently %d, need at least %d). Please modify and recompile.", METHOD_LIST_LENGTH, method_list_length + bytesToCopy + 1); } strncat (method_list, ptr, bytesToCopy); method_list_length += bytesToCopy; method_list[method_list_length+1] = '\0'; } 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; } }#ifdef PCAPPLAY getActionForThisMessage();#endif } else if(!strcmp(elem, (char *)"recv")) { recv_count++; 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); strcpy (scenario[scenario_len]->recv_response_for_cseq_method_list, method_list); } 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; recv_opt_count++; } } /* 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; } } #ifdef _USE_OPENSSL /* record the authentication credentials */ if(ptr = xp_get_value((char *)"auth")) { if(!strcmp(ptr, "true")) { scenario[scenario_len] -> bShouldAuthenticate = true; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -