@@ -68,14 +68,15 @@ discard block |
||
| 68 | 68 | $start=$item; |
| 69 | 69 | $parenthesis_count=0; |
| 70 | 70 | while (($item < strlen($rule)) // Not end of string AND |
| 71 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 71 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 72 | + // Closing ')' or embeded () |
|
| 72 | 73 | { |
| 73 | 74 | if ($rule[$item] == '"' ) |
| 74 | 75 | { // pass through string |
| 75 | 76 | $item++; |
| 77 | + } |
|
| 76 | 78 | $item=$this->eval_getNext($rule,$item,'"'); |
| 77 | - } |
|
| 78 | - else{ |
|
| 79 | + } else{ |
|
| 79 | 80 | if ($rule[$item] == '(') |
| 80 | 81 | { |
| 81 | 82 | $parenthesis_count++; |
@@ -114,9 +115,11 @@ discard block |
||
| 114 | 115 | { |
| 115 | 116 | // function is : __function(param1,param2...) |
| 116 | 117 | $start=$item; |
| 117 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 118 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
| 119 | + // Not end of string AND not opening '(' |
|
| 118 | 120 | { |
| 119 | 121 | $item++; |
| 122 | + } |
|
| 120 | 123 | } |
| 121 | 124 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
| 122 | 125 | |
@@ -138,7 +141,9 @@ discard block |
||
| 138 | 141 | { |
| 139 | 142 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
| 140 | 143 | } |
| 141 | - while ($rule[$item]==' ') $item++; |
|
| 144 | + while ($rule[$item]==' ') { |
|
| 145 | + $item++; |
|
| 146 | + } |
|
| 142 | 147 | if (preg_match('/[\-0-9\.]/',$rule[$item])) |
| 143 | 148 | { // number |
| 144 | 149 | return $this->get_number($rule, $item); |
@@ -176,7 +181,9 @@ discard block |
||
| 176 | 181 | |
| 177 | 182 | protected function eval_getOper($rule,&$item) |
| 178 | 183 | { |
| 179 | - while ($rule[$item]==' ') $item++; |
|
| 184 | + while ($rule[$item]==' ') { |
|
| 185 | + $item++; |
|
| 186 | + } |
|
| 180 | 187 | switch ($rule[$item]) |
| 181 | 188 | { |
| 182 | 189 | case '<': |
@@ -203,12 +210,13 @@ discard block |
||
| 203 | 210 | |
| 204 | 211 | private function check_negate_first($rule,&$item) |
| 205 | 212 | { |
| 206 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 213 | + if ( $rule[$item] == '!') { |
|
| 214 | + // If '!' found, negate next expression. |
|
| 207 | 215 | { |
| 208 | 216 | $item++; |
| 209 | - return true; |
|
| 210 | 217 | } |
| 211 | - else |
|
| 218 | + return true; |
|
| 219 | + } else |
|
| 212 | 220 | { |
| 213 | 221 | return false; |
| 214 | 222 | } |
@@ -228,7 +236,10 @@ discard block |
||
| 228 | 236 | case '&': $retVal= ($val1 && $val2); break; |
| 229 | 237 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 230 | 238 | } |
| 231 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 239 | + if ($negate === true) { |
|
| 240 | + $retVal = ! $retVal; |
|
| 241 | + } |
|
| 242 | + // Inverse result if negate before expression |
|
| 232 | 243 | |
| 233 | 244 | return $retVal; |
| 234 | 245 | } |
@@ -249,10 +260,14 @@ discard block |
||
| 249 | 260 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 250 | 261 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 251 | 262 | |
| 252 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 263 | + if ($item==strlen($rule)) { |
|
| 264 | + // If only element, return value, but only boolean |
|
| 253 | 265 | { |
| 254 | 266 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 255 | - if ($negate === true) $val1= ! $val1; |
|
| 267 | + } |
|
| 268 | + if ($negate === true) { |
|
| 269 | + $val1= ! $val1; |
|
| 270 | + } |
|
| 256 | 271 | return $val1; |
| 257 | 272 | } |
| 258 | 273 | |
@@ -261,31 +276,41 @@ discard block |
||
| 261 | 276 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 262 | 277 | |
| 263 | 278 | // Third element : number, string or () |
| 264 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 279 | + if ( $rule[$item] == '!') { |
|
| 280 | + // starts with a ! so evaluate whats next |
|
| 265 | 281 | { |
| 266 | 282 | $item++; |
| 267 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 283 | + } |
|
| 284 | + if ($typec != 1) { |
|
| 285 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 286 | + } |
|
| 268 | 287 | $val2= ! $this->evaluation($rule,$item); |
| 269 | 288 | $type2=2; // result is a boolean |
| 270 | - } |
|
| 271 | - else |
|
| 289 | + } else |
|
| 272 | 290 | { |
| 273 | 291 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 274 | 292 | } |
| 275 | 293 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 276 | 294 | |
| 277 | - if ($type1!=$type2) // cannot compare different types |
|
| 295 | + if ($type1!=$type2) { |
|
| 296 | + // cannot compare different types |
|
| 278 | 297 | { |
| 279 | 298 | throw new Exception("Cannot compare string & number : ".$rule); |
| 280 | 299 | } |
| 281 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 300 | + } |
|
| 301 | + if ($typec==1 && $type1 !=2) { |
|
| 302 | + // cannot use & or | with string/number |
|
| 282 | 303 | { |
| 283 | 304 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 284 | 305 | } |
| 306 | + } |
|
| 285 | 307 | |
| 286 | 308 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 287 | 309 | |
| 288 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 310 | + if ($item==strlen($rule)) { |
|
| 311 | + return $retVal; |
|
| 312 | + } |
|
| 313 | + // End of string : return evaluation |
|
| 289 | 314 | // check for logical operator : |
| 290 | 315 | switch ($rule[$item]) |
| 291 | 316 | { |
@@ -313,7 +338,9 @@ discard block |
||
| 313 | 338 | $rule2.=$rule[$item]; |
| 314 | 339 | $item++; |
| 315 | 340 | } |
| 316 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 341 | + if ($item == strlen ($rule)) { |
|
| 342 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 343 | + } |
|
| 317 | 344 | $rule2.=$rule[$item]; |
| 318 | 345 | $item++; |
| 319 | 346 | continue; |
@@ -355,10 +382,12 @@ discard block |
||
| 355 | 382 | */ |
| 356 | 383 | public function eval_rule($rule,$oidList) |
| 357 | 384 | { |
| 358 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 385 | + if ($rule==null || $rule == '') { |
|
| 386 | + // Empty rule is always true |
|
| 359 | 387 | { |
| 360 | 388 | return true; |
| 361 | 389 | } |
| 390 | + } |
|
| 362 | 391 | $matches=array(); |
| 363 | 392 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 364 | 393 | { |