Parent Directory
|
Revision Log
Package all media, etc. needed for Public demo system into one tree
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 24 #include "sipp.hpp" 25 26 /* 27 __________________________________________________________________________ 28 29 C L A S S C C a l l V a r i a b l e 30 __________________________________________________________________________ 31 */ 32 33 bool CCallVariable::isSet() 34 { 35 if (M_type == E_VT_REGEXP) { 36 if(M_nbOfMatchingValue >= 1) 37 return(true); 38 else 39 return(false); 40 } else if (M_type == E_VT_BOOL) { 41 return M_bool; 42 } 43 return (M_type != E_VT_UNDEFINED); 44 } 45 46 bool CCallVariable::isDouble() 47 { 48 return (M_type == E_VT_DOUBLE); 49 } 50 51 bool CCallVariable::isBool() 52 { 53 return (M_type == E_VT_BOOL); 54 } 55 56 bool CCallVariable::isRegExp() 57 { 58 return (M_type == E_VT_REGEXP); 59 } 60 61 bool CCallVariable::isString() 62 { 63 return (M_type == E_VT_STRING); 64 } 65 66 // WARNING : setMatchingValue does't allocate the memory for the matching value 67 // but the destructor free the memory 68 void CCallVariable::setMatchingValue(char* P_matchingVal) 69 { 70 M_type = E_VT_REGEXP; 71 if(M_matchingValue != NULL) { 72 delete [] M_matchingValue; 73 } 74 M_matchingValue = P_matchingVal; 75 M_nbOfMatchingValue++; 76 } 77 78 char* CCallVariable::getMatchingValue() 79 { 80 if (M_type != E_VT_REGEXP) { 81 return NULL; 82 } 83 return(M_matchingValue); 84 } 85 86 void CCallVariable::setDouble(double val) 87 { 88 M_type = E_VT_DOUBLE; 89 M_double = val; 90 } 91 92 double CCallVariable::getDouble() 93 { 94 if (M_type != E_VT_DOUBLE) { 95 return 0.0; 96 } 97 return(M_double); 98 } 99 100 void CCallVariable::setString(char *P_val) 101 { 102 M_type = E_VT_STRING; 103 if(M_stringValue != NULL) { 104 delete [] M_stringValue; 105 } 106 M_stringValue = P_val; 107 } 108 109 char *CCallVariable::getString() 110 { 111 if (M_type == E_VT_STRING) { 112 return(M_stringValue); 113 } else if (M_type == E_VT_REGEXP && M_matchingValue) { 114 return(M_matchingValue); 115 } else { 116 return ""; 117 } 118 } 119 120 /* Convert this variable to a double. Returns true on success, false on failure. */ 121 bool CCallVariable::toDouble(double *newValue) 122 { 123 char *p; 124 125 switch(M_type) { 126 case E_VT_REGEXP: 127 if(M_nbOfMatchingValue < 1) { 128 return false; 129 } 130 *newValue = strtod(M_matchingValue, &p); 131 if (*p) { 132 return false; 133 } 134 break; 135 case E_VT_STRING: 136 *newValue = strtod(M_stringValue, &p); 137 if (*p) { 138 return false; 139 } 140 break; 141 case E_VT_DOUBLE: 142 *newValue = getDouble(); 143 break; 144 case E_VT_BOOL: 145 *newValue = (double)getBool(); 146 break; 147 default: 148 return false; 149 } 150 return true; 151 } 152 153 void CCallVariable::setBool(bool val) 154 { 155 M_type = E_VT_BOOL; 156 M_bool = val; 157 } 158 159 bool CCallVariable::getBool() 160 { 161 if (M_type != E_VT_BOOL) { 162 return false; 163 } 164 return(M_bool); 165 } 166 167 // Constuctor and destructor 168 CCallVariable::CCallVariable() 169 { 170 M_matchingValue = NULL; 171 M_stringValue = NULL; 172 M_nbOfMatchingValue = 0; 173 M_type = E_VT_UNDEFINED; 174 } 175 176 CCallVariable::~CCallVariable() 177 { 178 if(M_matchingValue != NULL) { 179 delete [] M_matchingValue; 180 } 181 M_matchingValue = NULL; 182 if(M_stringValue != NULL) { 183 delete [] M_stringValue; 184 } 185 } 186 187 /* 188 __________________________________________________________________________ 189 190 C L A S S C V a r i a b l e 191 __________________________________________________________________________ 192 */ 193 194 bool CVariable::matchRegularExpression(char* P_string) 195 { 196 if(M_regExpWellFormed) { 197 if(regexec(&(M_internalRegExp), P_string, 0, NULL, 0) == 0) { 198 return(true); 199 } else { 200 return(false); 201 } 202 } else { 203 return(false); 204 } 205 } 206 207 void CVariable::setSubString(char** P_target, char* P_source, int P_start, int P_stop) 208 { 209 int sizeOf; 210 int sourceLength; 211 size_t L_size = 0; 212 213 if(P_source != NULL) { 214 sizeOf = P_stop - P_start; 215 if(sizeOf > 0) { 216 L_size = (size_t) sizeOf; 217 L_size += 1; 218 (*P_target) = new char[L_size]; 219 sourceLength = strlen(P_source); 220 221 memcpy((*P_target), &(P_source[P_start]), sizeOf); 222 223 (*P_target)[sizeOf] = '\0'; 224 } 225 } else { 226 *P_target = NULL ; 227 } 228 } 229 230 231 int CVariable::executeRegExp(char* P_string, 232 CCallVariable** P_callVarTable, 233 int P_varId, 234 int P_nbSubVar, 235 int * P_subVarIdTable) 236 { 237 regmatch_t pmatch[10]; 238 int error; 239 int nbOfMatch = 0; 240 int L_i ; 241 CCallVariable* L_callVar ; 242 char* result = NULL ; 243 int L_currentSubIdx = 0 ; 244 245 246 memset((void*)pmatch, 0, sizeof(regmatch_t)*10); 247 248 if(M_regExpWellFormed) { 249 error = regexec(&(M_internalRegExp), P_string, 10, pmatch, REGEXP_PARAMS); 250 if ( error == 0) { 251 L_callVar = P_callVarTable[P_varId] ; 252 for(L_i=0; L_i < 10; L_i++) { 253 if(pmatch[L_i].rm_eo == -1) break ; 254 setSubString(&result, P_string, 255 pmatch[L_i].rm_so, pmatch[L_i].rm_eo); 256 L_callVar->setMatchingValue(result); 257 if (L_currentSubIdx == P_nbSubVar) break ; 258 L_callVar = P_callVarTable[P_subVarIdTable[L_currentSubIdx]] ; 259 L_currentSubIdx ++ ; 260 261 /* 262 printf(" the pmatch %d %d \n", L_i, pmatch[L_i].rm_eo); 263 printf(" the pmatch %d %d \n", L_i, pmatch[L_i].rm_so); 264 int L_k ; 265 266 for(L_k = pmatch[L_i].rm_so; L_k <= pmatch[L_i].rm_eo; L_k++) { 267 printf("%c", P_string[L_k]); 268 } 269 printf("\n"); 270 */ 271 272 } 273 } 274 } 275 return(nbOfMatch); 276 277 } 278 279 bool CVariable::extractAllMatchedExpression(char* P_string, 280 char *** P_result, 281 int* P_number) 282 { 283 regmatch_t pmatch; 284 int error; 285 char tmpTab[MAX_MATCHING_EXPR][BUFFER_SIZE]; 286 char* strBuff; 287 int currentStop; 288 int maxLength; 289 290 if(M_regExpWellFormed) { 291 292 currentStop = 0; 293 maxLength = strlen(P_string); 294 error = regexec(&(M_internalRegExp), P_string, 1, &pmatch, REGEXP_PARAMS); 295 (*P_number) = 0; 296 297 while(error == 0) { 298 setSubString(&strBuff, P_string+currentStop, 299 pmatch.rm_so, pmatch.rm_eo); 300 if (strlen(strBuff) > BUFFER_SIZE) { 301 ERROR_P2("Regular expression match size (%zu) is bigger than buffer size (%d). Change BUFFER_SIZE in call.hpp and recompile SIPp.", strlen(strBuff), BUFFER_SIZE); 302 } 303 strcpy(tmpTab[(*P_number)], strBuff); 304 delete(strBuff); 305 (*P_number)++; 306 currentStop += pmatch.rm_eo; 307 if((currentStop >= maxLength) || ((*P_number) >= MAX_MATCHING_EXPR)) 308 break; 309 error = regexec(&(M_internalRegExp), 310 P_string+currentStop, 1, 311 &pmatch, REGEXP_PARAMS); 312 if(pmatch.rm_eo == pmatch.rm_so) 313 break; 314 } 315 if((*P_number) > 0) { 316 (*P_result) = (char**) malloc(sizeof(char*)*(*P_number)); 317 for(int i=0; i<(*P_number); i++) 318 { 319 (*P_result)[i] = (char*) malloc(sizeof(char)*(maxLength+1)); 320 strcpy((*P_result)[i], tmpTab[i]); 321 } 322 return(true); 323 } else { 324 return(false); 325 } 326 } else { 327 return(false); 328 } 329 } 330 331 // selecteur et accesseur 332 bool CVariable::isRegExpWellFormed() 333 { 334 return(M_regExpWellFormed); 335 } 336 337 char* CVariable::getRegularExpression() 338 { 339 return(M_regularExpression); 340 } 341 342 343 // Constuctor and destructor 344 CVariable::CVariable(char* P_regularExpression) 345 { 346 int sizeOf; 347 int errorCode; 348 349 if(P_regularExpression != NULL) 350 { 351 sizeOf = strlen(P_regularExpression); 352 M_regularExpression = new char[sizeOf+1]; 353 strcpy(M_regularExpression, P_regularExpression); 354 } 355 356 // we must call regcomp to avoid a coredump on the regfree. Even if the char* P_regularExpression is null 357 errorCode = regcomp(&(M_internalRegExp), M_regularExpression, REGEXP_PARAMS); 358 if(errorCode != 0) 359 { 360 /* regerror(errorCode, &M_internalRegExp, buffer, sizeof(buffer)); 361 printf("recomp error : regular expression '%s' - error '%s'\n", 362 M_regularExpression, 363 buffer); */ 364 M_regExpWellFormed = false; 365 } 366 else 367 { 368 M_regExpWellFormed = true; 369 } 370 } 371 372 CVariable::~CVariable() 373 { 374 if(M_regularExpression != NULL) 375 delete [] M_regularExpression; 376 M_regularExpression = NULL; 377 378 regfree(&(M_internalRegExp)); 379 }
| No admin address has been configured | ViewVC Help |
| Powered by ViewVC 1.0.8 |