Changeset d09e5a1 for filter.c


Ignore:
Timestamp:
May 31, 2003, 3:33:42 PM (18 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
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
Message:
Added libfaim
Added basic AIM support, including the "aimlogin", "aimwrite" and
   "aimlogout" commands
File:
1 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r89426ab rd09e5a1  
    121121  char *field, *match;
    122122
    123   /* create the working list */
     123  /* create the working list of expression elements */
    124124  fes=&(f->fes);
    125125  owl_list_create(&work_fes);
     
    129129  }
    130130
    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 */
    132132  match="";
    133133  for (i=0; i<j; i++) {
     
    152152      if (owl_message_is_type_zephyr(m)) {
    153153        match="zephyr";
     154      } else if (owl_message_is_type_aim(m)) {
     155        match="aim";
    154156      } else if (owl_message_is_type_admin(m)) {
    155157        match="admin";
     
    177179  }
    178180
    179  
    180181  /* call the recrsive helper */
    181182  i=_owl_filter_message_match_recurse(f, m, &work_fes, 0, owl_list_get_size(&(f->fes))-1);
    182183
     184  /* now there will be only one TRUE / FALSE, find it among the NULL's */
    183185  tmp=0;
    184   /* now we should have one value */
    185186  for (i=0; i<j; i++) {
    186187    fe=owl_list_get_element(&work_fes, i);
     
    196197  } 
    197198
    198   if (f->polarity) {
    199     tmp=!tmp;
    200   }
     199  /* reverse the answer if negative polarity is in use */
     200  if (f->polarity) tmp=!tmp;
     201
    201202  owl_list_free_simple(&work_fes);
    202203  return(tmp);
     
    207208  owl_filterelement *fe, *tmpfe=NULL;
    208209
    209   /* deal with parens first */
     210  /* Deal with parens first. */
    210211  for (i=0; i<OWL_FILTER_MAX_DEPTH; i++) {
     212    /* Find first open paren and matching close paren, store in x, y */
    211213    score=x=y=0;
    212214    for (i=start; i<=end; i++) {
     
    231233    }
    232234
     235    /* Simply the parens by removing them and evaluating what was in between */
    233236    if (y>0) {
    234237      /* null out the parens */
     
    236239      owl_list_replace_element(fes, y, owl_global_get_filterelement_null(&g));
    237240
    238       /* simplify the part that was in between */
     241      /* evaluate expression in between */
    239242      ret=_owl_filter_message_match_recurse(f, m, fes, x+1, y-1);
    240243      if (ret<0) return(-1);
     
    248251  }
    249252  if (i==OWL_FILTER_MAX_DEPTH) {
     253    /* hit the saftey limit, consider it invalid */
    250254    return(-1);
    251255  }
    252256
    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   */
    254266  for (i=0; i<OWL_FILTER_MAX_DEPTH; i++) {
    255267    type=score=x=y=z=0;
     
    273285            y=i;
    274286          } else {
     287            /* it's not a valid binary expression */
    275288            x=y=z=score=0;
    276289          }
    277290        } else if (type==2) {
    278291          if (owl_filterelement_is_value(fe)) {
    279             /* it's a valid "NOT expr" */
     292            /* valid unary expression, we're done */
    280293            y=i;
    281294            break;
     
    284297      } else if (score==2) {
    285298        if (owl_filterelement_is_value(fe)) {
    286           /* yes, it's a good match */
     299          /* valid binary expression, we're done */
    287300          z=i;
    288301          break;
     
    293306    }
    294307
    295     /* process and / or */
     308    /* simplify AND / OR */
    296309    if ((type==1) && (z>0)) {
    297310      fe=owl_list_get_element(fes, x);
     
    326339      owl_list_replace_element(fes, y, tmpfe);
    327340      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 */
    329343      fe=owl_list_get_element(fes, y);
    330344      owl_list_replace_element(fes, x, owl_global_get_filterelement_null(&g));
Note: See TracChangeset for help on using the changeset viewer.