Changeset 23fddadbb7a375688e9be9627f1f5ca39aaa54d0

Show
Ignore:
Timestamp:
10/23/09 23:01:30 (5 weeks ago)
Author:
Karl Ramm <kcr@1ts.org>
git-author:
Karl Ramm <kcr@1ts.org> / 2009-09-30T10:12:27Z-0400
Parents:
52761cc7346cb35d2d70160f25573df691427ef2
Children:
859077469433dd85e1c9ebff365cb2cc6d237c6a
git-committer:
Karl Ramm <kcr@1ts.org> / 2009-10-23T23:01:30Z-0400
Message:
refactor & rename filter creation & storage management

filter_init_fromstring -> filter_new_fromstring
filter_init -> filter_new
filter_free -> filter_delete

Every time owl_filter_init and owl_filter_init_fromstring were called,
there was a call to malloc right above them;  Conversely, after every
owl_filter_free there needed to be a call to owl_free (and sometimes
there wasn't).
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • commands.c

    r73faa26 r23fddad  
    24262426        f = owl_list_get_element(fl, i); 
    24272427        owl_list_remove_element(fl, i); 
    2428         owl_filter_free(f); 
     2428        owl_filter_delete(f); 
    24292429        return; 
    24302430      } else { 
  • filter.c

    r8bce750 r23fddad  
    22#include "owl.h" 
    33 
    4 int owl_filter_init_fromstring(owl_filter *f, const char *name, const char *string) 
    5 { 
     4owl_filter *owl_filter_new_fromstring(const char *name, const char *string) 
     5{ 
     6  owl_filter *f; 
    67  char **argv; 
    7   int argc, out; 
    8  
    9   argv=owl_parseline(string, &argc); 
    10   out=owl_filter_init(f, name, argc, strs(argv)); 
     8  int argc; 
     9 
     10  argv = owl_parseline(string, &argc); 
     11  f = owl_filter_new(name, argc, strs(argv)); 
    1112  owl_parsefree(argv, argc); 
    12   return(out); 
    13 } 
    14  
    15 int owl_filter_init(owl_filter *f, const char *name, int argc, const char *const *argv) 
    16 { 
     13 
     14  return f; 
     15} 
     16 
     17owl_filter *owl_filter_new(const char *name, int argc, const char *const *argv) 
     18{ 
     19  owl_filter *f; 
     20 
     21  f = owl_malloc(sizeof(owl_filter)); 
     22 
    1723  f->name=owl_strdup(name); 
    1824  f->fgcolor=OWL_COLOR_DEFAULT; 
     
    4046  } 
    4147 
    42   if(!(f->root = owl_filter_parse_expression(argc, argv, NULL))) 
    43     return(-1); 
     48  if (!(f->root = owl_filter_parse_expression(argc, argv, NULL))) { 
     49    owl_filter_delete(f); 
     50    return NULL; 
     51  } 
    4452 
    4553  /* Now check for recursion. */ 
    4654  if (owl_filter_is_toodeep(f)) { 
    4755    owl_function_error("Filter loop!"); 
    48     owl_filter_free(f); 
    49     return(-1); 
    50   } 
    51  
    52   return(0); 
     56    owl_filter_delete(f); 
     57    return NULL; 
     58  } 
     59 
     60  return f; 
    5361} 
    5462 
     
    255263} 
    256264 
    257 void owl_filter_free(owl_filter *f) 
    258 { 
    259   if(f->root) { 
     265void owl_filter_delete(owl_filter *f) 
     266{ 
     267  if (f == NULL) 
     268    return; 
     269  if (f->root) { 
    260270    owl_filterelement_free(f->root); 
    261271    owl_free(f->root); 
    262272  } 
    263   if (f->name) owl_free(f->name); 
    264 } 
     273  if (f->name) 
     274    owl_free(f->name); 
     275  owl_free(f); 
     276} 
  • functions.c

    r52761cc r23fddad  
    21332133  owl_filter *f; 
    21342134  const owl_view *v; 
    2135   int ret, inuse=0; 
     2135  int inuse = 0; 
    21362136 
    21372137  if (argc < 2) { 
     
    21832183 
    21842184  /* create the filter and check for errors */ 
    2185   f=owl_malloc(sizeof(owl_filter)); 
    2186   ret=owl_filter_init(f, argv[1], argc-2, argv+2); 
    2187   if (ret==-1) { 
    2188     owl_free(f); 
     2185  f = owl_filter_new(argv[1], argc-2, argv+2); 
     2186  if (f == NULL) { 
    21892187    owl_function_error("Invalid filter"); 
    21902188    return; 
     
    23822380  if (tmpinstance) owl_free(tmpinstance); 
    23832381 
    2384   f=owl_malloc(sizeof(owl_filter)); 
    2385   owl_filter_init_fromstring(f, filtname, argbuff); 
     2382  f = owl_filter_new_fromstring(filtname, argbuff); 
    23862383 
    23872384  /* add it to the global list */ 
     
    24212418 
    24222419  /* create the new-internal filter */ 
    2423   f=owl_malloc(sizeof(owl_filter)); 
    2424  
    24252420  esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 
    24262421 
     
    24302425      esclonguser); 
    24312426 
    2432   owl_filter_init_fromstring(f, filtname, argbuff); 
     2427  f = owl_filter_new_fromstring(filtname, argbuff); 
    24332428 
    24342429  /* add it to the global list */ 
     
    24652460 
    24662461  /* create the new-internal filter */ 
    2467   f=owl_malloc(sizeof(owl_filter)); 
    2468  
    24692462  escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 
    24702463 
     
    24742467      escuser, owl_global_get_aim_screenname_for_filters(&g)); 
    24752468 
    2476   owl_filter_init_fromstring(f, filtname, argbuff); 
     2469  f = owl_filter_new_fromstring(filtname, argbuff); 
    24772470 
    24782471  /* add it to the global list */ 
     
    25062499  argbuff = owl_sprintf("type ^%s$", esctype); 
    25072500 
    2508   owl_filter_init_fromstring(f, filtname, argbuff); 
     2501  f = owl_filter_new_fromstring(filtname, argbuff); 
    25092502 
    25102503  /* add it to the global list */ 
     
    28252818  owl_filter *f; 
    28262819  owl_list *fl; 
    2827   int ret, i, j; 
     2820  int i, j; 
    28282821  fl=owl_global_get_puntlist(&g); 
    28292822 
    28302823  /* first, create the filter */ 
    2831   f=owl_malloc(sizeof(owl_filter)); 
    2832  
    28332824  owl_function_debugmsg("About to filter %s", filter); 
    2834   ret=owl_filter_init_fromstring(f, "punt-filter", filter); 
    2835   if (ret) { 
     2825  f = owl_filter_new_fromstring("punt-filter", filter); 
     2826  if (f == NULL) { 
    28362827    owl_function_error("Error creating filter for zpunt"); 
    2837     owl_filter_free(f); 
    2838     owl_free(f); 
    28392828    return; 
    28402829  } 
     
    28472836      /* if we're punting, then just silently bow out on this duplicate */ 
    28482837      if (direction==0) { 
    2849         owl_filter_free(f); 
    2850         owl_free(f); 
     2838        owl_filter_delete(f); 
    28512839        return; 
    28522840      } 
     
    28542842      /* if we're unpunting, then remove this filter from the puntlist */ 
    28552843      if (direction==1) { 
    2856         owl_filter_free(owl_list_get_element(fl, i)); 
     2844        owl_filter_delete(owl_list_get_element(fl, i)); 
    28572845        owl_list_remove_element(fl, i); 
    2858         owl_filter_free(f); 
    2859         owl_free(f); 
     2846        owl_filter_delete(f); 
    28602847        return; 
    28612848      } 
  • global.c

    r52761cc r23fddad  
    635635    f=owl_list_get_element(&(g->filterlist), i); 
    636636    if (!strcmp(name, owl_filter_get_name(f))) { 
    637       owl_filter_free(f); 
     637      owl_filter_delete(f); 
    638638      owl_list_remove_element(&(g->filterlist), i); 
    639639      break; 
  • owl.c

    r84ea53c r23fddad  
    151151static void owl_setup_default_filters(void) 
    152152{ 
    153   owl_filter *f; 
    154153  int i; 
    155154  static const struct { 
     
    176175  owl_function_debugmsg("startup: creating default filters"); 
    177176 
    178   for (i = 0; filters[i].name != NULL; i++) { 
    179     f = owl_malloc(sizeof(owl_filter)); 
    180     owl_filter_init_fromstring(f, filters[i].name, filters[i].desc); 
    181     owl_list_append_element(owl_global_get_filterlist(&g), f); 
    182   } 
     177  for (i = 0; filters[i].name != NULL; i++) 
     178    owl_list_append_element(owl_global_get_filterlist(&g), 
     179                            owl_filter_new_fromstring(filters[i].name, 
     180                                                      filters[i].desc)); 
    183181} 
    184182 
  • tester.c

    rdd6af02 r23fddad  
    194194 
    195195int owl_filter_test_string(const char * filt, const owl_message *m, int shouldmatch) /* noproto */ { 
    196   owl_filter f; 
     196  owl_filter *f; 
    197197  int ok; 
    198198  int failed = 0; 
    199   if(owl_filter_init_fromstring(&f, "test-filter", filt)) { 
     199  if ((f = owl_filter_new_fromstring("test-filter", filt)) == NULL) { 
    200200    printf("not ok can't parse %s\n", filt); 
    201201    failed = 1; 
    202202    goto out; 
    203203  } 
    204   ok = owl_filter_message_match(&f, m); 
     204  ok = owl_filter_message_match(f, m); 
    205205  if((shouldmatch && !ok) || (!shouldmatch && ok)) { 
    206206    printf("not ok match %s (got %d, expected %d)\n", filt, ok, shouldmatch); 
     
    208208  } 
    209209 out: 
    210   owl_filter_free(&f); 
     210  owl_filter_delete(f); 
    211211  if(!failed) { 
    212212    printf("ok %s %s\n", shouldmatch ? "matches" : "doesn't match", filt); 
     
    218218  int numfailed=0; 
    219219  owl_message m; 
    220   owl_filter f1, f2, f3, f4, f5; 
     220  owl_filter *f1, *f2, *f3, *f4, *f5; 
    221221 
    222222  owl_list_create(&(g.filterlist)); 
     
    260260  TEST_FILTER("true and false or false", 0); 
    261261 
    262   owl_filter_init_fromstring(&f1, "f1", "class owl"); 
    263   owl_global_add_filter(&g, &f1); 
     262  f1 = owl_filter_new_fromstring("f1", "class owl"); 
     263  owl_global_add_filter(&g, f1); 
    264264  TEST_FILTER("filter f1", 1); 
     265  owl_global_remove_filter(&g, "f1"); 
    265266 
    266267  /* Test recursion prevention */ 
    267   FAIL_UNLESS("self reference", owl_filter_init_fromstring(&f2, "test", "filter test")); 
     268  FAIL_UNLESS("self reference", (f2 = owl_filter_new_fromstring("test", "filter test")) == NULL); 
     269  owl_filter_delete(f2); 
    268270 
    269271  /* mutual recursion */ 
    270   owl_filter_init_fromstring(&f3, "f3", "filter f4"); 
    271   owl_global_add_filter(&g, &f3); 
    272   FAIL_UNLESS("mutual recursion",   owl_filter_init_fromstring(&f4, "f4", "filter f3")); 
     272  f3 = owl_filter_new_fromstring("f3", "filter f4"); 
     273  owl_global_add_filter(&g, f3); 
     274  FAIL_UNLESS("mutual recursion", (f4 = owl_filter_new_fromstring("f4", "filter f3")) == NULL); 
     275  owl_global_remove_filter(&g, "f3"); 
     276  owl_filter_delete(f4); 
    273277 
    274278  /* support referencing a filter several times */ 
    275   FAIL_UNLESS("DAG", !owl_filter_init_fromstring(&f5, "dag", "filter f1 or filter f1")); 
     279  FAIL_UNLESS("DAG", (f5 = owl_filter_new_fromstring("dag", "filter f1 or filter f1")) != NULL); 
     280  owl_filter_delete(f5); 
    276281 
    277282  return 0;