|
|
1.1 root 1:
2: #ifndef lint
3: static char *rcsid = "$Header: /f/osi/others/quipu/uips/pod/RCS/filt.c,v 7.1 90/07/27 08:45:37 mrose Exp $";
4: #endif
5:
6: /*
7: * $Header: /f/osi/others/quipu/uips/pod/RCS/filt.c,v 7.1 90/07/27 08:45:37 mrose Exp $
8: */
9:
10: /*
11: * $Log: filt.c,v $
12: * Revision 7.1 90/07/27 08:45:37 mrose
13: * update
14: *
15: * Revision 7.0 90/06/12 13:15:49 mrose
16: * *** empty log message ***
17: *
18: * Revision 1.5 90/04/26 10:21:12 emsrdsm
19: * *** empty log message ***
20: *
21: * Revision 1.4 90/04/25 13:47:24 emsrdsm
22: * i) lint'ed
23: *
24: * Revision 1.3 90/04/20 10:28:16 emsrdsm
25: * (i) fixed form bug
26: *
27: * Revision 1.2 90/04/18 18:48:11 emsrdsm
28: * i) added logging
29: *
30: * Revision 1.1 90/04/10 16:43:44 emsrdsm
31: * Initial revision
32: *
33: */
34: #include <string.h>
35: #include <malloc.h>
36: #include <ctype.h>
37:
38: #include "quipu/util.h"
39: #include "quipu/common.h"
40: #include "quipu/entry.h"
41:
42: #include "filt.h"
43: #include "y.tab.h"
44: #include "symtab.h"
45:
46: extern unsigned int curr_filt;
47: extern unsigned int filt_num;
48: extern unsigned int typeindx;
49: extern filt_struct *filt_arr[];
50: extern char *filtvalue[];
51: extern char *filttype[];
52: extern char *default_arr[];
53:
54: extern char svalue[], mvalue[];
55:
56: make_type(name_val, filt)
57: char * name_val;
58: filt_struct * filt;
59: {
60: filttype[curr_filt] = (char *) malloc((unsigned int) (strlen(name_val) + 1));
61: (void) strcpy(filttype[curr_filt], name_val);
62:
63: /* if (default_val) {
64: default_arr[curr_filt] =
65: (char *) malloc((unsigned int) (strlen(default_val)+1));
66: (void) strcpy(default_arr[curr_filt], default_val);
67: } else {
68: default_arr[curr_filt] = (char *) malloc((unsigned int) 2);
69: *default_arr[curr_filt] = '\0';
70: }*/
71: filt_arr[curr_filt] = filt;
72: }
73:
74: filt_struct *
75: make_item_filter(oid, match, value)
76: char *oid;
77: int match;
78: char *value;
79: {
80: register filt_struct * filt = (filt_struct *) malloc(sizeof(filt_struct));
81:
82: filt->flt_type = ITEM;
83: filt->next = 0;
84:
85: filt->fu_cont.item.fi_type = match;
86: filt->fu_cont.item.stroid =
87: (char *) malloc((unsigned int) (strlen(oid) + 1));
88: (void) strcpy(filt->fu_cont.item.stroid, oid);
89:
90: if (*value == '*') filt->fu_cont.item.name = (char *) 0;
91: else {
92: filt->fu_cont.item.name =
93: (char *) malloc((unsigned int) (strlen(value) + 1));
94: (void) strcpy(filt->fu_cont.item.name, value);
95: }
96: return filt;
97: }
98:
99: filt_struct *
100: link_filters(filt1, filt2)
101: filt_struct *filt1;
102: filt_struct *filt2;
103: {
104: filt1->next = filt2;
105: return filt1;
106: }
107:
108: filt_struct *
109: make_parent_filter(filt_type, filt1, filt2, filt3)
110: int filt_type;
111: filt_struct * filt1;
112: filt_struct * filt2;
113: filt_struct * filt3;
114: {
115: filt_struct * parent = (filt_struct *) malloc(sizeof(filt_struct));
116:
117: switch (filt_type) {
118:
119: case NOT:
120: parent->flt_type = NOT;
121: parent->fu_cont.sub_filt = filt1;
122: parent->next = 0;
123: break;
124:
125: case AND:
126: parent->flt_type = AND;
127: parent->fu_cont.sub_filt = filt1;
128: filt1->next = filt2;
129: filt2->next = filt3;
130: parent->next = 0;
131: break;
132:
133: default:
134: parent->flt_type = OR;
135: parent->fu_cont.sub_filt = filt1;
136: filt1->next = filt2;
137: filt2->next = filt3;
138: parent->next = 0;
139: break;
140: }
141:
142: return parent;
143: }
144:
145: free_filt(filt)
146: filt_struct *filt;
147: {
148: if (filt) {
149: free_filt(filt->next);
150:
151: if (filt->flt_type = ITEM) {
152: free(filt->fu_cont.item.stroid);
153: if (filt->fu_cont.item.name) free(filt->fu_cont.item.name);
154: } else
155: free_filt(filt->fu_cont.sub_filt);
156:
157: free((char *) filt);
158: } else
159: return;
160: }
161:
162: Filter
163: make_filter(filt)
164: filt_struct *filt;
165: {
166: int type, count;
167: char *value;
168: Filter rfilt, sfilt = filter_alloc();
169:
170: if (!filt)
171: return (Filter) 0;
172:
173: switch(filt->flt_type) {
174:
175: case ITEM:
176: sfilt->flt_type = FILTER_ITEM;
177: sfilt->flt_next = make_filter(filt->next);
178:
179: if (strcmp(filt->fu_cont.item.stroid, "2.5.4.4"))
180: (void) strcpy(svalue, (filt->fu_cont.item.name?
181: filt->fu_cont.item.name:
182: mvalue));
183: else if (!filt->fu_cont.item.name) {
184: count = strlen(mvalue);
185: value = mvalue + count - 1;
186:
187: while(!isalpha(*value) && value > mvalue) value--;
188: while (!isspace(*value) && value > mvalue) value--;
189:
190: if (mvalue < value) (void) strcpy(svalue, ++value);
191: else (void) strcpy(svalue, mvalue);
192: } else (void) strcpy(svalue, filt->fu_cont.item.name);
193:
194: type = filt->fu_cont.item.fi_type;
195:
196: switch(type) {
197: case APPROX:
198: case EQUAL:
199: sfilt->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type =
200: AttrT_new(filt->fu_cont.item.stroid);
201:
202: if ((sfilt->flt_un.flt_un_item.fi_un.fi_un_ava.ava_value =
203: str2AttrV(svalue,
204: sfilt->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type->
205: oa_syntax)) == NULL) {
206:
207: rfilt = sfilt->flt_next;
208: sfilt->flt_next = NULLFILTER;
209: filter_free(sfilt);
210: return rfilt;
211: }
212:
213: if (type == EQUAL)
214: sfilt->flt_un.flt_un_item.fi_type = FILTERITEM_EQUALITY;
215: else
216: sfilt->flt_un.flt_un_item.fi_type = FILTERITEM_APPROX;
217:
218: break;
219:
220: case SUBSTRING:
221: sfilt->flt_un.flt_un_item.fi_type = FILTERITEM_SUBSTRINGS;
222: sfilt->flt_un.flt_un_item.fi_un.fi_un_substrings.fi_sub_type =
223: AttrT_new(filt->fu_cont.item.stroid);
224:
225: sfilt->flt_un.flt_un_item.fi_un.fi_un_substrings.fi_sub_initial =
226: NULLAV;
227: sfilt->flt_un.flt_un_item.fi_un.fi_un_substrings.fi_sub_final =
228: NULLAV;
229: sfilt->flt_un.flt_un_item.fi_un.fi_un_substrings.fi_sub_any =
230: avs_comp_new(str2AttrV(svalue,
231: sfilt->flt_un.flt_un_item.fi_un.
232: fi_un_substrings.fi_sub_type->
233: oa_syntax));
234: break;
235:
236: default:
237: sfilt->flt_un.flt_un_item.fi_type = FILTERITEM_APPROX;
238: break;
239: }
240: return sfilt;
241:
242: case AND:
243: sfilt->flt_type = FILTER_AND;
244: sfilt->flt_un.flt_un_filter = make_filter(filt->fu_cont.sub_filt);
245: sfilt->flt_next = make_filter(filt->next);
246: return sfilt;
247:
248: case OR:
249: sfilt->flt_type = FILTER_OR;
250: sfilt->flt_un.flt_un_filter = make_filter(filt->fu_cont.sub_filt);
251: sfilt->flt_next = make_filter(filt->next);
252: return sfilt;
253:
254: case NOT:
255: sfilt->flt_type = FILTER_NOT;
256: sfilt->flt_next = make_filter(filt->next);
257: sfilt->flt_un.flt_un_filter = make_filter(filt->fu_cont.sub_filt);
258: return sfilt;
259:
260: default:
261: return NULLFILTER;
262: }
263: }
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.