1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License as published by 4 * the Free Software Foundation; either version 2 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * 16 * Authors : Benjamin GAUTHIER - 24 Mar 2004 17 * Joseph BANINO 18 * Olivier JACQUES 19 * Richard GAYRAUD 20 * From Hewlett Packard Company. 21 */ 22 23 #ifndef _CACTIONS 24 #define _CACTIONS 25 26 #include "variables.hpp" 27 #include "message.hpp" 28 class CSample; 29 30 #ifdef PCAPPLAY 31 #include "prepare_pcap.h" 32 #endif 33 #ifdef RTP_STREAM 34 #include "rtpstream.hpp" 35 #endif 36 37 #define MAX_ACTION_MESSAGE 3 38 39 class CAction 40 { 41 public: 42 enum T_ActionType { 43 E_AT_NO_ACTION = 0, 44 E_AT_ASSIGN_FROM_REGEXP, 45 E_AT_CHECK, 46 E_AT_ASSIGN_FROM_VALUE, 47 E_AT_ASSIGN_FROM_SAMPLE, 48 E_AT_ASSIGN_FROM_STRING, 49 E_AT_ASSIGN_FROM_INDEX, 50 E_AT_ASSIGN_FROM_GETTIMEOFDAY, 51 E_AT_JUMP, 52 E_AT_LOOKUP, 53 E_AT_INSERT, 54 E_AT_REPLACE, 55 E_AT_PAUSE_RESTORE, 56 E_AT_LOG_TO_FILE, 57 E_AT_LOG_WARNING, 58 E_AT_LOG_ERROR, 59 E_AT_EXECUTE_CMD, 60 E_AT_EXEC_INTCMD, 61 E_AT_VAR_ADD, 62 E_AT_VAR_SUBTRACT, 63 E_AT_VAR_MULTIPLY, 64 E_AT_VAR_DIVIDE, 65 E_AT_VAR_TEST, 66 E_AT_VAR_TO_DOUBLE, 67 E_AT_VAR_STRCMP, 68 E_AT_VAR_TRIM, 69 E_AT_VERIFY_AUTH, 70 E_AT_SET_DEST, 71 E_AT_CLOSE_CON, 72 #ifdef PCAPPLAY 73 E_AT_PLAY_PCAP_AUDIO, 74 E_AT_PLAY_PCAP_IMAGE, 75 E_AT_PLAY_PCAP_VIDEO, 76 #endif 77 #ifdef RTP_STREAM 78 E_AT_RTP_STREAM_PAUSE, 79 E_AT_RTP_STREAM_RESUME, 80 E_AT_RTP_STREAM_PLAY, 81 #endif 82 E_AT_NB_ACTION 83 }; 84 85 enum T_LookingPlace { 86 E_LP_MSG = 0, 87 E_LP_HDR, 88 E_LP_BODY, 89 E_LP_VAR, 90 E_LP_NB_LOOKING_PLACE 91 }; 92 93 enum T_Comparator { 94 E_C_EQ, 95 E_C_NE, 96 E_C_GT, 97 E_C_LT, 98 E_C_GEQ, 99 E_C_LEQ, 100 E_C_NB_COMPARATOR 101 }; 102 103 enum T_IntCmdType { 104 E_INTCMD_INVALID = 0, 105 E_INTCMD_STOPCALL, 106 E_INTCMD_STOP_ALL, 107 E_INTCMD_STOP_NOW 108 }; 109 110 typedef struct _T_Action { 111 } T_Action; 112 113 void afficheInfo(); 114 const char *comparatorToString(T_Comparator comp); 115 bool compare(VariableTable *variableTable); 116 117 T_ActionType getActionType(); 118 T_VarType getVarType(); 119 T_LookingPlace getLookingPlace(); 120 T_Comparator getComparator(); 121 bool getCheckIt(); 122 bool getCheckItInverse(); 123 bool getCaseIndep(); 124 bool getHeadersOnly(); 125 int getVarId(); 126 int getVarInId(); 127 int getVarIn2Id(); 128 int getOccurrence(); 129 char* getLookingChar(); 130 char* getRegularExpression(); 131 SendingMessage *getMessage(int n = 0); /* log specific function */ 132 T_IntCmdType getIntCmd(); /* exec specific function */ 133 #ifdef PCAPPLAY 134 pcap_pkts *getPcapPkts(); /* send_packets specific function */ 135 #endif 136 #ifdef RTP_STREAM 137 rtpstream_actinfo_t *getRTPStreamActInfo(); /* return stored rtp stream playback params */ 138 #endif 139 140 void setActionType (T_ActionType P_value); 141 void setLookingPlace (T_LookingPlace P_value); 142 void setComparator (T_Comparator P_value); 143 void setCheckIt (bool P_value); 144 void setCheckItInverse (bool P_value); 145 void setVarId (int P_value); 146 void setVarInId (int P_value); 147 void setVarIn2Id (int P_value); 148 void setLookingChar(const char* P_value); 149 void setAction (CAction P_action); 150 void setCaseIndep (bool P_action); 151 void setOccurrence (int P_value); 152 void setHeadersOnly (bool P_value); 153 void setScenario (scenario * P_scenario); 154 void setRegExp (const char* P_value); /* ereg specific function. */ 155 int executeRegExp (const char* P_string, VariableTable *P_callVarTable); 156 void setMessage (char* P_value, int n = 0); /* log specific function */ 157 void setIntCmd (T_IntCmdType P_type ); /* exec specific function */ 158 void setDistribution (CSample * P_value); /* sample specific function */ 159 void setDoubleValue (double P_value); /* assign value specific function */ 160 void setStringValue (char * P_value); /* strcmp value specific function */ 161 #ifdef PCAPPLAY 162 void setPcapArgs(const char* P_value); /* send_packets specific function */ 163 void setPcapArgs (pcap_pkts * P_value); /* send_packets specific function */ 164 #endif 165 #ifdef RTP_STREAM 166 void setRTPStreamActInfo(const char* P_value); /* parse rtp stream playback values from string */ 167 void setRTPStreamActInfo (rtpstream_actinfo_t *P_value); /* copy stored rtp stream playback params */ 168 #endif 169 170 void setSubVarId (int P_value); 171 int getSubVarId (int P_index); 172 void setNbSubVarId (int P_value); 173 int getNbSubVarId (); 174 int* getSubVarId() ; 175 CSample *getDistribution (); /* sample specific function */ 176 double getDoubleValue (); /* assign value specific function */ 177 char * getStringValue (); /* strcmp specific function */ 178 179 CAction(scenario *scenario); 180 ~CAction(); 181 182 private: 183 T_ActionType M_action; 184 T_LookingPlace M_lookingPlace; 185 T_Comparator M_comp; 186 bool M_checkIt; 187 bool M_checkItInverse; 188 bool M_caseIndep; 189 bool M_headersOnly; 190 int M_varId; 191 int M_varInId; 192 int M_varIn2Id; 193 int M_occurrence; 194 int M_nbSubVarId; 195 int M_maxNbSubVarId; 196 int * M_subVarId; 197 198 char * M_lookingChar; 199 /* log specific member */ 200 SendingMessage * M_message[MAX_ACTION_MESSAGE]; 201 char * M_message_str[MAX_ACTION_MESSAGE]; 202 /* exec specific member */ 203 T_IntCmdType M_IntCmd; 204 /* sample specific member. */ 205 CSample * M_distribution; 206 /* assign value specific member. */ 207 double M_doubleValue; 208 /* strcmp specific member. */ 209 char * M_stringValue; 210 /* what scenario we belong to. */ 211 scenario * M_scenario; 212 /* Our regular expression. */ 213 bool M_regExpSet; 214 regex_t M_internalRegExp; 215 char * M_regularExpression; 216 #ifdef PCAPPLAY 217 /* pcap specific member */ 218 pcap_pkts * M_pcapArgs; 219 #endif 220 #ifdef RTP_STREAM 221 rtpstream_actinfo_t M_rtpstream_actinfo; 222 #endif 223 void setSubString(char** P_target, const char* P_source, int P_start, int P_stop); 224 }; 225 226 class CActions 227 { 228 public: 229 void afficheInfo(); 230 void setAction(CAction *P_action); 231 void reset(); 232 int getActionSize(); 233 CAction* getAction(int i); 234 CActions(); 235 ~CActions(); 236 237 private: 238 CAction ** M_actionList; 239 int M_nbAction; 240 }; 241 242 #endif 243