LCOV - code coverage report
Current view: top level - src - Rule.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 21 51 41.2 %
Date: 2010-12-13 Functions: 5 10 50.0 %
Branches: 2 58 3.4 %

           Branch data     Line data    Source code
       1                 :            : // $Id: Rule.cc 6914 2009-09-22 00:35:24Z vern $
       2                 :            : 
       3                 :            : #include "config.h"
       4                 :            : 
       5                 :            : #include "Rule.h"
       6                 :            : #include "RuleMatcher.h"
       7                 :            : 
       8                 :            : // Start at one as we want search for this within a list,
       9                 :            : // and List's is_member returns zero for non-membership ...
      10                 :            : unsigned int Rule::rule_counter = 1;
      11                 :            : unsigned int Rule::pattern_counter = 0;
      12                 :          6 : rule_list Rule::rule_table;
      13                 :            : 
      14                 :          0 : Rule::~Rule()
      15                 :            :         {
      16 [ #  # ][ #  # ]:          0 :         delete [] id;
      17                 :            : 
      18 [ #  # ][ #  # ]:          0 :         loop_over_list(patterns, i)
      19                 :            :                 {
      20 [ #  # ][ #  # ]:          0 :                 delete [] patterns[i]->pattern;
      21                 :          0 :                 delete patterns[i];
      22                 :            :                 }
      23                 :            : 
      24 [ #  # ][ #  # ]:          0 :         loop_over_list(hdr_tests, j)
      25 [ #  # ][ #  # ]:          0 :                 delete hdr_tests[j];
      26                 :            : 
      27 [ #  # ][ #  # ]:          0 :         loop_over_list(conditions, k)
      28 [ #  # ][ #  # ]:          0 :                 delete conditions[k];
      29                 :            : 
      30 [ #  # ][ #  # ]:          0 :         loop_over_list(actions, l)
      31 [ #  # ][ #  # ]:          0 :                 delete actions[l];
      32                 :            : 
      33 [ #  # ][ #  # ]:          0 :         loop_over_list(preconds, m)
      34                 :            :                 {
      35 [ #  # ][ #  # ]:          0 :                 delete [] preconds[m]->id;
      36                 :          0 :                 delete preconds[m];
      37                 :            :                 }
      38                 :          0 :         }
      39                 :            : 
      40                 :          0 : const char* Rule::TypeToString(Rule::PatternType type)
      41                 :            :         {
      42                 :            :         static const char* labels[] = {
      43                 :            :                 "Payload", "HTTP-REQUEST", "HTTP-REQUEST-BODY",
      44                 :            :                 "HTTP-REQUEST-HEADER", "HTTP-REPLY-BODY",
      45                 :            :                 "HTTP-REPLY-HEADER", "FTP", "Finger",
      46                 :            :         };
      47                 :          0 :         return labels[type];
      48                 :            :         }
      49                 :            : 
      50                 :          0 : void Rule::PrintDebug()
      51                 :            :         {
      52         [ #  # ]:          0 :         fprintf(stderr, "Rule %s (%d) %s\n", id, idx, active ? "[active]" : "[disabled]");
      53                 :            : 
      54         [ #  # ]:          0 :         loop_over_list(patterns, i)
      55                 :            :                 {
      56                 :            :                 fprintf(stderr, "  %-8s |%s| (%d) \n",
      57                 :            :                         TypeToString(patterns[i]->type), patterns[i]->pattern,
      58                 :          0 :                         patterns[i]->id);
      59                 :            :                 }
      60                 :            : 
      61         [ #  # ]:          0 :         loop_over_list(hdr_tests, j)
      62                 :          0 :                 hdr_tests[j]->PrintDebug();
      63                 :            : 
      64         [ #  # ]:          0 :         loop_over_list(conditions, k)
      65                 :          0 :                 conditions[k]->PrintDebug();
      66                 :            : 
      67         [ #  # ]:          0 :         loop_over_list(actions, l)
      68                 :          0 :                 actions[l]->PrintDebug();
      69                 :            : 
      70                 :          0 :         fputs("\n", stderr);
      71                 :          0 :         }
      72                 :            : 
      73                 :            : void Rule::AddPattern(const char* str, Rule::PatternType type,
      74                 :         21 :                         uint32 offset, uint32 depth)
      75                 :            :         {
      76                 :         21 :         Pattern* p = new Pattern;
      77                 :         21 :         p->pattern = copy_string(str);
      78                 :         21 :         p->type = type;
      79                 :         21 :         p->id = ++pattern_counter;
      80                 :         21 :         p->offset = offset;
      81                 :         21 :         p->depth = depth;
      82                 :         21 :         patterns.append(p);
      83                 :            : 
      84                 :         21 :         rule_table.append(this);
      85                 :         21 :         }
      86                 :            : 
      87                 :         11 : void Rule::AddRequires(const char* id, bool opposite_direction, bool negate)
      88                 :            :         {
      89                 :         11 :         Precond* p = new Precond;
      90                 :         11 :         p->id = copy_string(id);
      91                 :         11 :         p->rule = 0;
      92                 :         11 :         p->opposite_dir = opposite_direction;
      93                 :         11 :         p->negate = negate;
      94                 :            : 
      95                 :         11 :         preconds.append(p);
      96                 :         11 :         }
      97                 :            : 
      98                 :          0 : void Rule::SortHdrTests()
      99                 :            :         {
     100                 :            :         // FIXME: Do nothing for now - we may want to come up with
     101                 :            :         // something clever here.
     102 [ +  - ][ +  - ]:          6 :         }

Generated by: LCOV version 1.8