[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[1aee7d9] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[7d4fbcd] | 5 | #define OWL_FILTERELEMENT_NULL 0 |
---|
| 6 | #define OWL_FILTERELEMENT_TRUE 1 |
---|
| 7 | #define OWL_FILTERELEMENT_FALSE 2 |
---|
| 8 | #define OWL_FILTERELEMENT_OPENBRACE 3 |
---|
| 9 | #define OWL_FILTERELEMENT_CLOSEBRACE 4 |
---|
| 10 | #define OWL_FILTERELEMENT_AND 5 |
---|
| 11 | #define OWL_FILTERELEMENT_OR 6 |
---|
| 12 | #define OWL_FILTERELEMENT_NOT 7 |
---|
| 13 | #define OWL_FILTERELEMENT_RE 8 |
---|
| 14 | |
---|
| 15 | |
---|
[e187445] | 16 | void owl_filterelement_create_null(owl_filterelement *fe) |
---|
| 17 | { |
---|
[7d4fbcd] | 18 | fe->type=OWL_FILTERELEMENT_NULL; |
---|
| 19 | fe->field=NULL; |
---|
| 20 | } |
---|
| 21 | |
---|
[e187445] | 22 | void owl_filterelement_create_openbrace(owl_filterelement *fe) |
---|
| 23 | { |
---|
[7d4fbcd] | 24 | fe->type=OWL_FILTERELEMENT_OPENBRACE; |
---|
| 25 | fe->field=NULL; |
---|
| 26 | } |
---|
| 27 | |
---|
[e187445] | 28 | void owl_filterelement_create_closebrace(owl_filterelement *fe) |
---|
| 29 | { |
---|
[7d4fbcd] | 30 | fe->type=OWL_FILTERELEMENT_CLOSEBRACE; |
---|
| 31 | fe->field=NULL; |
---|
| 32 | } |
---|
| 33 | |
---|
[e187445] | 34 | void owl_filterelement_create_and(owl_filterelement *fe) |
---|
| 35 | { |
---|
[7d4fbcd] | 36 | fe->type=OWL_FILTERELEMENT_AND; |
---|
| 37 | fe->field=NULL; |
---|
| 38 | } |
---|
| 39 | |
---|
[e187445] | 40 | void owl_filterelement_create_or(owl_filterelement *fe) |
---|
| 41 | { |
---|
[7d4fbcd] | 42 | fe->type=OWL_FILTERELEMENT_OR; |
---|
| 43 | fe->field=NULL; |
---|
| 44 | } |
---|
| 45 | |
---|
[e187445] | 46 | void owl_filterelement_create_not(owl_filterelement *fe) |
---|
| 47 | { |
---|
[7d4fbcd] | 48 | fe->type=OWL_FILTERELEMENT_NOT; |
---|
| 49 | fe->field=NULL; |
---|
| 50 | } |
---|
| 51 | |
---|
[e187445] | 52 | void owl_filterelement_create_true(owl_filterelement *fe) |
---|
| 53 | { |
---|
[7d4fbcd] | 54 | fe->type=OWL_FILTERELEMENT_TRUE; |
---|
| 55 | fe->field=NULL; |
---|
| 56 | } |
---|
| 57 | |
---|
[e187445] | 58 | void owl_filterelement_create_false(owl_filterelement *fe) |
---|
| 59 | { |
---|
[7d4fbcd] | 60 | fe->type=OWL_FILTERELEMENT_FALSE; |
---|
| 61 | fe->field=NULL; |
---|
| 62 | } |
---|
| 63 | |
---|
[e187445] | 64 | void owl_filterelement_create_re(owl_filterelement *fe, char *field, char *re) |
---|
| 65 | { |
---|
[7d4fbcd] | 66 | fe->type=OWL_FILTERELEMENT_RE; |
---|
| 67 | fe->field=owl_strdup(field); |
---|
| 68 | owl_regex_create(&(fe->re), re); |
---|
| 69 | } |
---|
| 70 | |
---|
[e187445] | 71 | void owl_filterelement_free(owl_filterelement *fe) |
---|
| 72 | { |
---|
[7d4fbcd] | 73 | if (fe->field) owl_free(fe->field); |
---|
| 74 | } |
---|
| 75 | |
---|
[e187445] | 76 | int owl_filterelement_is_null(owl_filterelement *fe) |
---|
| 77 | { |
---|
[7d4fbcd] | 78 | if (fe->type==OWL_FILTERELEMENT_NULL) return(1); |
---|
| 79 | return(0); |
---|
| 80 | } |
---|
| 81 | |
---|
[e187445] | 82 | int owl_filterelement_is_openbrace(owl_filterelement *fe) |
---|
| 83 | { |
---|
[7d4fbcd] | 84 | if (fe->type==OWL_FILTERELEMENT_OPENBRACE) return(1); |
---|
| 85 | return(0); |
---|
| 86 | } |
---|
| 87 | |
---|
[e187445] | 88 | int owl_filterelement_is_closebrace(owl_filterelement *fe) |
---|
| 89 | { |
---|
[7d4fbcd] | 90 | if (fe->type==OWL_FILTERELEMENT_CLOSEBRACE) return(1); |
---|
| 91 | return(0); |
---|
| 92 | } |
---|
| 93 | |
---|
[e187445] | 94 | int owl_filterelement_is_and(owl_filterelement *fe) |
---|
| 95 | { |
---|
[7d4fbcd] | 96 | if (fe->type==OWL_FILTERELEMENT_AND) return(1); |
---|
| 97 | return(0); |
---|
| 98 | } |
---|
| 99 | |
---|
[e187445] | 100 | int owl_filterelement_is_or(owl_filterelement *fe) |
---|
| 101 | { |
---|
[7d4fbcd] | 102 | if (fe->type==OWL_FILTERELEMENT_OR) return(1); |
---|
| 103 | return(0); |
---|
| 104 | } |
---|
| 105 | |
---|
[e187445] | 106 | int owl_filterelement_is_not(owl_filterelement *fe) |
---|
| 107 | { |
---|
[7d4fbcd] | 108 | if (fe->type==OWL_FILTERELEMENT_NOT) return(1); |
---|
| 109 | return(0); |
---|
| 110 | } |
---|
| 111 | |
---|
[e187445] | 112 | int owl_filterelement_is_true(owl_filterelement *fe) |
---|
| 113 | { |
---|
[7d4fbcd] | 114 | if (fe->type==OWL_FILTERELEMENT_TRUE) return(1); |
---|
| 115 | return(0); |
---|
| 116 | } |
---|
| 117 | |
---|
[e187445] | 118 | int owl_filterelement_is_false(owl_filterelement *fe) |
---|
| 119 | { |
---|
[7d4fbcd] | 120 | if (fe->type==OWL_FILTERELEMENT_FALSE) return(1); |
---|
| 121 | return(0); |
---|
| 122 | } |
---|
| 123 | |
---|
[e187445] | 124 | int owl_filterelement_is_re(owl_filterelement *fe) |
---|
| 125 | { |
---|
[7d4fbcd] | 126 | if (fe->type==OWL_FILTERELEMENT_RE) return(1); |
---|
| 127 | return(0); |
---|
| 128 | } |
---|
| 129 | |
---|
[e187445] | 130 | owl_regex *owl_filterelement_get_re(owl_filterelement *fe) |
---|
| 131 | { |
---|
[7d4fbcd] | 132 | return(&(fe->re)); |
---|
| 133 | } |
---|
| 134 | |
---|
[e187445] | 135 | char *owl_filterelement_get_field(owl_filterelement *fe) |
---|
| 136 | { |
---|
[7d4fbcd] | 137 | return(fe->field); |
---|
| 138 | } |
---|
| 139 | |
---|
[e187445] | 140 | int owl_filterelement_is_value(owl_filterelement *fe) |
---|
| 141 | { |
---|
[7d4fbcd] | 142 | if ( (fe->type==OWL_FILTERELEMENT_TRUE) || |
---|
| 143 | (fe->type==OWL_FILTERELEMENT_FALSE) || |
---|
| 144 | (fe->type==OWL_FILTERELEMENT_RE) ) { |
---|
| 145 | return(1); |
---|
| 146 | } |
---|
| 147 | return(0); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
[e187445] | 151 | char *owl_filterelement_to_string(owl_filterelement *fe) |
---|
| 152 | { |
---|
[7d4fbcd] | 153 | /* return must be freed by caller */ |
---|
| 154 | |
---|
| 155 | if (owl_filterelement_is_openbrace(fe)) { |
---|
| 156 | return(owl_strdup("( ")); |
---|
| 157 | } else if (owl_filterelement_is_closebrace(fe)) { |
---|
| 158 | return(owl_strdup(") ")); |
---|
| 159 | } else if (owl_filterelement_is_and(fe)) { |
---|
| 160 | return(owl_strdup("and ")); |
---|
| 161 | } else if (owl_filterelement_is_or(fe)) { |
---|
| 162 | return(owl_strdup("or ")); |
---|
| 163 | } else if (owl_filterelement_is_not(fe)) { |
---|
| 164 | return(owl_strdup("not ")); |
---|
| 165 | } else if (owl_filterelement_is_true(fe)) { |
---|
| 166 | return(owl_strdup("true ")); |
---|
| 167 | } else if (owl_filterelement_is_false(fe)) { |
---|
| 168 | return(owl_strdup("false ")); |
---|
| 169 | } else if (owl_filterelement_is_re(fe)) { |
---|
| 170 | char *buff; |
---|
| 171 | buff=owl_malloc(LINE); |
---|
| 172 | sprintf(buff, "%s %s ", fe->field, owl_regex_get_string(&(fe->re))); |
---|
| 173 | return(buff); |
---|
| 174 | } |
---|
| 175 | return(owl_strdup("")); |
---|
| 176 | } |
---|