1 /* tree.h -- abstract syntax tree 2 * Larry Greenfield 3 * 4 * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * 3. The name "Carnegie Mellon University" must not be used to 19 * endorse or promote products derived from this software without 20 * prior written permission. For permission or any legal 21 * details, please contact 22 * Carnegie Mellon University 23 * Center for Technology Transfer and Enterprise Creation 24 * 4615 Forbes Avenue 25 * Suite 302 26 * Pittsburgh, PA 15213 27 * (412) 268-7393, fax: (412) 268-7395 28 * innovation@andrew.cmu.edu 29 * 30 * 4. Redistributions of any form whatsoever must retain the following 31 * acknowledgment: 32 * "This product includes software developed by Computing Services 33 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 34 * 35 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 36 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 37 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 38 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 39 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 40 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 41 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 42 */ 43 44 #ifndef TREE_H 45 #define TREE_H 46 47 #include "comparator.h" 48 #include "strarray.h" 49 50 /* abstract syntax tree for sieve */ 51 typedef struct Commandlist commandlist_t; 52 typedef struct Test test_t; 53 typedef struct Testlist testlist_t; 54 typedef struct Tag tag_t; 55 typedef struct Taglist taglist_t; 56 57 struct Tag { 58 int type; 59 char *arg; 60 }; 61 62 struct Taglist { 63 tag_t *t; 64 taglist_t *next; 65 }; 66 67 struct Test { 68 int type; 69 union { 70 testlist_t *tl; /* anyof, allof */ 71 strarray_t *sl; /* exists */ 72 struct { /* it's a header or hasflag or string test */ 73 int index; 74 int comptag; 75 char * comparator; 76 int relation; 77 void *comprock; 78 strarray_t *sl; 79 strarray_t *pl; 80 } h; 81 struct { /* it's an address or envelope test */ 82 int index; 83 int comptag; 84 char * comparator; 85 int relation; 86 void *comprock; 87 strarray_t *sl; 88 strarray_t *pl; 89 int addrpart; 90 } ae; 91 struct { /* it's a body test */ 92 int comptag; 93 int relation; 94 char * comparator; 95 void *comprock; 96 int transform; 97 int offset; 98 strarray_t *content_types; 99 strarray_t *pl; 100 } b; 101 test_t *t; /* not */ 102 struct { /* size */ 103 int t; /* tag */ 104 int n; /* param */ 105 } sz; 106 struct { /* it's a date test */ 107 int index; 108 int zonetag; 109 char *zone; 110 int comptag; 111 int relation; 112 char *comparator; 113 int date_part; 114 char *header_name; 115 strarray_t *kl; 116 } dt; 117 struct { /* it's one of the mailbox type tests */ 118 char *extname; 119 char *keyname; 120 strarray_t *keylist; 121 int comptag; 122 int relation; 123 char *comparator; 124 } mbx; 125 } u; 126 }; 127 128 struct Testlist { 129 test_t *t; 130 testlist_t *next; 131 }; 132 133 struct Commandlist { 134 int type; 135 union { 136 char *reject; /* its a reject action */ 137 struct { /* it's an if statement */ 138 test_t *t; 139 commandlist_t *do_then; 140 commandlist_t *do_else; 141 } i; 142 struct { /* it's an include action */ 143 int location; 144 int once; 145 int optional; 146 char *script; 147 } inc; 148 struct { /* it's a set action */ 149 int mod40; /* :lower or :upper */ 150 int mod30; /* :lowerfirst or :upperfirst */ 151 int mod20; /* :quotewildcard */ 152 int mod10; /* :length */ 153 char *variable; 154 char *value; 155 } s; 156 struct { /* it's a keep action */ 157 int copy; 158 strarray_t *flags; 159 } k; 160 struct { /* it's a fileinto action */ 161 char *folder; 162 int copy; 163 int create; 164 strarray_t *flags; 165 } f; 166 struct { /* it's a flag action */ 167 char *variable; 168 strarray_t *flags; 169 } fl; 170 struct { /* it's a redirect action */ 171 char *address; 172 int copy; 173 } r; 174 struct { /* it's a vacation action */ 175 char *subject; 176 int seconds; 177 strarray_t *addresses; 178 char *message; 179 char *from; 180 char *handle; 181 int mime; 182 } v; 183 struct { /* it's a notify action */ 184 char *method; 185 char *id; 186 strarray_t *options; 187 int priority; 188 char *message; 189 } n; 190 struct { /* it's a denotify action */ 191 int comptag; 192 int relation; 193 void *comprock; 194 void *pattern; 195 int priority; 196 } d; 197 } u; 198 struct Commandlist *next; 199 }; 200 201 tag_t *new_tag(int type, char *s); 202 taglist_t *new_taglist(tag_t *t, taglist_t *n); 203 test_t *new_test(int type); 204 testlist_t *new_testlist(test_t *t, testlist_t *n); 205 commandlist_t *new_command(int type); 206 commandlist_t *new_if(test_t *t, commandlist_t *y, commandlist_t *n); 207 208 void free_test(test_t *t); 209 void free_tree(commandlist_t *cl); 210 211 #endif 212