Changeset 32eed98 for filter.c


Ignore:
Timestamp:
Dec 26, 2003, 2:49:54 PM (17 years ago)
Author:
Erik Nygren <nygren@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:
5f82eb3
Parents:
4357be8
Message:
2.1.3-pre-2
	Added perl filter elements.  Similar to having "filter <subfilter>"
	  in a filter, you may also have "perl <functionname>"
	  where <functionname> is passed an owl::Message object and
	  returns 0 or 1 depending on whether the message matches
	  that element of the filter.
	  [Note: currently this overloads the filtername element
	  of the filterelement structure to store the function name.
	  Perhaps we should change the name of this element to something
	  more general to avoid confusion?]
File:
1 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    rbf73bdd r32eed98  
    8484        owl_filterelement_create_filter(fe, argv[i+1]);
    8585        i++;
     86      } else if (!strcasecmp(argv[i], "perl")) {
     87        owl_filterelement_create_perl(fe, argv[i+1]);
     88        i++;
    8689      } else {
    8790        error=1;
     
    224227  }
    225228
    226   /* now subfilters */
     229  /* now subfilters and perl functions */
    227230  for (i=0; i<j; i++) {
    228231    owl_filter *subfilter;
    229232                           
    230233    fe=owl_list_get_element(&work_fes, i);
    231     if (!owl_filterelement_is_filter(fe)) continue;
    232 
    233     subfilter=owl_global_get_filter(&g, owl_filterelement_get_filtername(fe));
    234     if (!subfilter) {
    235       /* the filter does not exist, maybe because it was deleted.
    236        * Default to not matching
    237        */
    238       owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
    239     } else if (owl_filter_message_match(subfilter, m)) {
    240       owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_true(&g));
    241     } else {
    242       owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
     234
     235    if (owl_filterelement_is_filter(fe)) {
     236
     237      subfilter=owl_global_get_filter(&g, owl_filterelement_get_filtername(fe));
     238      if (!subfilter) {
     239        /* the filter does not exist, maybe because it was deleted.
     240         * Default to not matching
     241         */
     242        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
     243      } else if (owl_filter_message_match(subfilter, m)) {
     244        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_true(&g));
     245      } else {
     246        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
     247      }
     248
     249    } else if (owl_filterelement_is_perl(fe)) {
     250      char *subname, *perlrv;
     251      int   tf=0;
     252
     253      subname = owl_filterelement_get_filtername(fe);
     254      if (!owl_perlconfig_is_function(subname)) {
     255        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
     256        continue;
     257      }
     258      perlrv = owl_perlconfig_call_with_message(subname, m);
     259      if (perlrv) {
     260        if (0 == strcmp(perlrv, "1")) {
     261          tf=1;
     262        }
     263        owl_free(perlrv);
     264      }
     265      if (tf) {
     266        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_true(&g));
     267      } else {
     268        owl_list_replace_element(&work_fes, i, owl_global_get_filterelement_false(&g));
     269      }
    243270    }
    244271  }
Note: See TracChangeset for help on using the changeset viewer.