Changeset 32eed98


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?]
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4357be8 r32eed98  
    11$Id$
    22
     32.1.3-pre-2
     4        Added perl filter elements.  Similar to having "filter <subfilter>"
     5          in a filter, you may also have "perl <functionname>"
     6          where <functionname> is passed an owl::Message object and
     7          returns 0 or 1 depending on whether the message matches
     8          that element of the filter.
     9          [Note: currently this overloads the filtername element
     10          of the filterelement structure to store the function name.
     11          Perhaps we should change the name of this element to something
     12          more general to avoid confusion?]
     13       
    3142.1.3-pre-1
    415        Don't print an error about loading subs if there is no
  • commands.c

    r3895e23 r32eed98  
    526526              "Also you may match on the validity of another filter:\n"
    527527              "    filter <filtername>\n"
     528              "Also you may pass the message to a perl function returning 0 or 1,\n"
     529              "where 1 indicates that the function matches the filter:\n"
     530              "    perl <subname>\n"
    528531              "Valid operators are:\n"
    529532              "    and\n"
  • 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  }
  • filterelement.c

    r40458b9 r32eed98  
    1313#define OWL_FILTERELEMENT_RE          8
    1414#define OWL_FILTERELEMENT_FILTER      9
     15#define OWL_FILTERELEMENT_PERL       10
    1516
    1617void owl_filterelement_create_null(owl_filterelement *fe)
     
    7879}
    7980
     81void owl_filterelement_create_perl(owl_filterelement *fe, char *name)
     82{
     83  owl_filterelement_create_null(fe);
     84  fe->type=OWL_FILTERELEMENT_PERL;
     85  fe->filtername=owl_strdup(name);
     86}
     87
    8088void owl_filterelement_free(owl_filterelement *fe)
    8189{
     
    135143{
    136144  if (fe->type==OWL_FILTERELEMENT_RE) return(1);
     145  return(0);
     146}
     147
     148int owl_filterelement_is_perl(owl_filterelement *fe)
     149{
     150  if (fe->type==OWL_FILTERELEMENT_PERL) return(1);
    137151  return(0);
    138152}
     
    166180       (fe->type==OWL_FILTERELEMENT_FALSE) ||
    167181       (fe->type==OWL_FILTERELEMENT_RE) ||
     182       (fe->type==OWL_FILTERELEMENT_PERL) ||
    168183       (fe->type==OWL_FILTERELEMENT_FILTER)) {
    169184    return(1);
     
    193208  } else if (owl_filterelement_is_filter(fe)) {
    194209    return(owl_sprintf("filter %s ", fe->filtername));
     210  } else if (owl_filterelement_is_perl(fe)) {
     211    return(owl_sprintf("perl %s ", fe->filtername));
    195212  }
    196213
  • owl.h

    r4357be8 r32eed98  
    2020static const char owl_h_fileIdent[] = "$Id$";
    2121
    22 #define OWL_VERSION         2.1.3-pre-1
    23 #define OWL_VERSION_STRING "2.1.3-pre-1"
     22#define OWL_VERSION         2.1.3-pre-2
     23#define OWL_VERSION_STRING "2.1.3-pre-2"
    2424
    2525/* Feature that is being tested to redirect stderr through a pipe.
Note: See TracChangeset for help on using the changeset viewer.