- Timestamp:
- May 31, 2003, 3:33:42 PM (20 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 5e53c4a
- Parents:
- c86a35c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
filter.c
r89426ab rd09e5a1 121 121 char *field, *match; 122 122 123 /* create the working list */123 /* create the working list of expression elements */ 124 124 fes=&(f->fes); 125 125 owl_list_create(&work_fes); … … 129 129 } 130 130 131 /* first go thru and turn all RE elements into true or false */131 /* first go thru and evaluate all RE elements to true or false */ 132 132 match=""; 133 133 for (i=0; i<j; i++) { … … 152 152 if (owl_message_is_type_zephyr(m)) { 153 153 match="zephyr"; 154 } else if (owl_message_is_type_aim(m)) { 155 match="aim"; 154 156 } else if (owl_message_is_type_admin(m)) { 155 157 match="admin"; … … 177 179 } 178 180 179 180 181 /* call the recrsive helper */ 181 182 i=_owl_filter_message_match_recurse(f, m, &work_fes, 0, owl_list_get_size(&(f->fes))-1); 182 183 184 /* now there will be only one TRUE / FALSE, find it among the NULL's */ 183 185 tmp=0; 184 /* now we should have one value */185 186 for (i=0; i<j; i++) { 186 187 fe=owl_list_get_element(&work_fes, i); … … 196 197 } 197 198 198 if (f->polarity) {199 200 } 199 /* reverse the answer if negative polarity is in use */ 200 if (f->polarity) tmp=!tmp; 201 201 202 owl_list_free_simple(&work_fes); 202 203 return(tmp); … … 207 208 owl_filterelement *fe, *tmpfe=NULL; 208 209 209 /* deal with parens first*/210 /* Deal with parens first. */ 210 211 for (i=0; i<OWL_FILTER_MAX_DEPTH; i++) { 212 /* Find first open paren and matching close paren, store in x, y */ 211 213 score=x=y=0; 212 214 for (i=start; i<=end; i++) { … … 231 233 } 232 234 235 /* Simply the parens by removing them and evaluating what was in between */ 233 236 if (y>0) { 234 237 /* null out the parens */ … … 236 239 owl_list_replace_element(fes, y, owl_global_get_filterelement_null(&g)); 237 240 238 /* simplify the part that wasin between */241 /* evaluate expression in between */ 239 242 ret=_owl_filter_message_match_recurse(f, m, fes, x+1, y-1); 240 243 if (ret<0) return(-1); … … 248 251 } 249 252 if (i==OWL_FILTER_MAX_DEPTH) { 253 /* hit the saftey limit, consider it invalid */ 250 254 return(-1); 251 255 } 252 256 253 /* and / or / not */ 257 /* Find AND / OR / NOT. 258 * For binary expressions (AND/OR): 259 * "type" is 1 260 * "x" will index first val, "y" the operator and "z" the second val 261 * For unary expressions (NOT): 262 * "type" is 2 263 * "x" will index the operator, "y" the value 264 * "score" tallys how many expression elements have been found so far 265 */ 254 266 for (i=0; i<OWL_FILTER_MAX_DEPTH; i++) { 255 267 type=score=x=y=z=0; … … 273 285 y=i; 274 286 } else { 287 /* it's not a valid binary expression */ 275 288 x=y=z=score=0; 276 289 } 277 290 } else if (type==2) { 278 291 if (owl_filterelement_is_value(fe)) { 279 /* it's a valid "NOT expr"*/292 /* valid unary expression, we're done */ 280 293 y=i; 281 294 break; … … 284 297 } else if (score==2) { 285 298 if (owl_filterelement_is_value(fe)) { 286 /* yes, it's a good match*/299 /* valid binary expression, we're done */ 287 300 z=i; 288 301 break; … … 293 306 } 294 307 295 /* process and / or*/308 /* simplify AND / OR */ 296 309 if ((type==1) && (z>0)) { 297 310 fe=owl_list_get_element(fes, x); … … 326 339 owl_list_replace_element(fes, y, tmpfe); 327 340 owl_list_replace_element(fes, z, owl_global_get_filterelement_null(&g)); 328 } else if ((type==2) && (y>0)) { /* process NOT */ 341 } else if ((type==2) && (y>0)) { 342 /* simplify NOT */ 329 343 fe=owl_list_get_element(fes, y); 330 344 owl_list_replace_element(fes, x, owl_global_get_filterelement_null(&g));
Note: See TracChangeset
for help on using the changeset viewer.