@@ -64,14 +64,15 @@ discard block |
||
| 64 | 64 | $start=$item; |
| 65 | 65 | $parenthesis_count=0; |
| 66 | 66 | while (($item < strlen($rule)) // Not end of string AND |
| 67 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 67 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 68 | + // Closing ')' or embeded () |
|
| 68 | 69 | { |
| 69 | 70 | if ($rule[$item] == '"' ) |
| 70 | 71 | { // pass through string |
| 71 | 72 | $item++; |
| 73 | + } |
|
| 72 | 74 | $item=$this->eval_getNext($rule,$item,'"'); |
| 73 | - } |
|
| 74 | - else{ |
|
| 75 | + } else{ |
|
| 75 | 76 | if ($rule[$item] == '(') |
| 76 | 77 | { |
| 77 | 78 | $parenthesis_count++; |
@@ -110,9 +111,11 @@ discard block |
||
| 110 | 111 | { |
| 111 | 112 | // function is : __function(param1,param2...) |
| 112 | 113 | $start=$item; |
| 113 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 114 | + while (($item < strlen($rule)) && ($rule[$item] != '(' )) { |
|
| 115 | + // Not end of string AND not opening '(' |
|
| 114 | 116 | { |
| 115 | 117 | $item++; |
| 118 | + } |
|
| 116 | 119 | } |
| 117 | 120 | if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
| 118 | 121 | |
@@ -134,7 +137,9 @@ discard block |
||
| 134 | 137 | { |
| 135 | 138 | throw new Exception("Early end of string ".$rule ." at " .$item ); |
| 136 | 139 | } |
| 137 | - while ($rule[$item]==' ') $item++; |
|
| 140 | + while ($rule[$item]==' ') { |
|
| 141 | + $item++; |
|
| 142 | + } |
|
| 138 | 143 | if (preg_match('/[\-0-9\.]/',$rule[$item])) |
| 139 | 144 | { // number |
| 140 | 145 | return $this->get_number($rule, $item); |
@@ -172,7 +177,9 @@ discard block |
||
| 172 | 177 | |
| 173 | 178 | protected function eval_getOper($rule,&$item) |
| 174 | 179 | { |
| 175 | - while ($rule[$item]==' ') $item++; |
|
| 180 | + while ($rule[$item]==' ') { |
|
| 181 | + $item++; |
|
| 182 | + } |
|
| 176 | 183 | switch ($rule[$item]) |
| 177 | 184 | { |
| 178 | 185 | case '<': |
@@ -199,12 +206,13 @@ discard block |
||
| 199 | 206 | |
| 200 | 207 | private function check_negate_first($rule,&$item) |
| 201 | 208 | { |
| 202 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 209 | + if ( $rule[$item] == '!') { |
|
| 210 | + // If '!' found, negate next expression. |
|
| 203 | 211 | { |
| 204 | 212 | $item++; |
| 205 | - return true; |
|
| 206 | 213 | } |
| 207 | - else |
|
| 214 | + return true; |
|
| 215 | + } else |
|
| 208 | 216 | { |
| 209 | 217 | return false; |
| 210 | 218 | } |
@@ -224,7 +232,10 @@ discard block |
||
| 224 | 232 | case '&': $retVal= ($val1 && $val2); break; |
| 225 | 233 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 226 | 234 | } |
| 227 | - if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 235 | + if ($negate === true) { |
|
| 236 | + $retVal = ! $retVal; |
|
| 237 | + } |
|
| 238 | + // Inverse result if negate before expression |
|
| 228 | 239 | |
| 229 | 240 | return $retVal; |
| 230 | 241 | } |
@@ -245,10 +256,14 @@ discard block |
||
| 245 | 256 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 246 | 257 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 247 | 258 | |
| 248 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 259 | + if ($item==strlen($rule)) { |
|
| 260 | + // If only element, return value, but only boolean |
|
| 249 | 261 | { |
| 250 | 262 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 251 | - if ($negate === true) $val1= ! $val1; |
|
| 263 | + } |
|
| 264 | + if ($negate === true) { |
|
| 265 | + $val1= ! $val1; |
|
| 266 | + } |
|
| 252 | 267 | return $val1; |
| 253 | 268 | } |
| 254 | 269 | |
@@ -257,31 +272,41 @@ discard block |
||
| 257 | 272 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 258 | 273 | |
| 259 | 274 | // Third element : number, string or () |
| 260 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 275 | + if ( $rule[$item] == '!') { |
|
| 276 | + // starts with a ! so evaluate whats next |
|
| 261 | 277 | { |
| 262 | 278 | $item++; |
| 263 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 279 | + } |
|
| 280 | + if ($typec != 1) { |
|
| 281 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 282 | + } |
|
| 264 | 283 | $val2= ! $this->evaluation($rule,$item); |
| 265 | 284 | $type2=2; // result is a boolean |
| 266 | - } |
|
| 267 | - else |
|
| 285 | + } else |
|
| 268 | 286 | { |
| 269 | 287 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 270 | 288 | } |
| 271 | 289 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 272 | 290 | |
| 273 | - if ($type1!=$type2) // cannot compare different types |
|
| 291 | + if ($type1!=$type2) { |
|
| 292 | + // cannot compare different types |
|
| 274 | 293 | { |
| 275 | 294 | throw new Exception("Cannot compare string & number : ".$rule); |
| 276 | 295 | } |
| 277 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 296 | + } |
|
| 297 | + if ($typec==1 && $type1 !=2) { |
|
| 298 | + // cannot use & or | with string/number |
|
| 278 | 299 | { |
| 279 | 300 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 280 | 301 | } |
| 302 | + } |
|
| 281 | 303 | |
| 282 | 304 | $retVal = $this->do_compare($val1, $val2, $comp, $negate); |
| 283 | 305 | |
| 284 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 306 | + if ($item==strlen($rule)) { |
|
| 307 | + return $retVal; |
|
| 308 | + } |
|
| 309 | + // End of string : return evaluation |
|
| 285 | 310 | // check for logical operator : |
| 286 | 311 | switch ($rule[$item]) |
| 287 | 312 | { |
@@ -309,7 +334,9 @@ discard block |
||
| 309 | 334 | $rule2.=$rule[$item]; |
| 310 | 335 | $item++; |
| 311 | 336 | } |
| 312 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 337 | + if ($item == strlen ($rule)) { |
|
| 338 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 339 | + } |
|
| 313 | 340 | $rule2.=$rule[$item]; |
| 314 | 341 | $item++; |
| 315 | 342 | continue; |
@@ -330,10 +357,12 @@ discard block |
||
| 330 | 357 | |
| 331 | 358 | public function eval_rule($rule,$oidList) |
| 332 | 359 | { |
| 333 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 360 | + if ($rule==null || $rule == '') { |
|
| 361 | + // Empty rule is always true |
|
| 334 | 362 | { |
| 335 | 363 | return true; |
| 336 | 364 | } |
| 365 | + } |
|
| 337 | 366 | $matches=array(); |
| 338 | 367 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 339 | 368 | { |