2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.2 1995-11-01 13:54:49 quinn
10 * Revision 1.1 1995/11/01 11:56:09 quinn
11 * Added Retrieval (data management) functions en masse.
27 * We'll probably want to add some sort of hashed index to these lookup-
28 * functions eventually.
31 data1_datatype data1_maptype(char *t)
39 {"structured", DATA1K_structured},
40 {"string", DATA1K_string},
41 {"numeric", DATA1K_numeric},
43 {"bool", DATA1K_bool},
44 {"generalizedtime", DATA1K_generalizedtime},
45 {"intunit", DATA1K_intunit},
47 {"octetstring", DATA1K_octetstring},
52 for (i = 0; types[i].tname; i++)
53 if (!data1_matchstr(types[i].tname, t))
58 data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value)
62 for (; s; s = s->next)
66 for (r = s->tags; r; r = r->next)
67 if (r->which == DATA1T_numeric && r->value.numeric == value)
69 /* scan included sets */
70 if (s->children && (r = data1_gettagbynum(s->children, type, value)))
76 data1_tag *data1_gettagbyname(data1_tagset *s, char *name)
80 for (; s; s = s->next)
83 for (r = s->tags; r; r = r->next)
87 for (np = r->names; np; np = np->next)
88 if (!data1_matchstr(np->name, name))
91 /* scan included sets */
92 if (s->children && (r = data1_gettagbyname(s->children, name)))
98 data1_tagset *data1_read_tagset(char *file)
100 char line[512], *r, cmd[512], args[512];
101 data1_tagset *res = 0, **childp;
105 if (!(f = fopen(file, "r")))
107 logf(LOG_WARN|LOG_ERRNO, "%s", file);
111 if (!(res = xmalloc(sizeof(*res))))
118 childp = &res->children;
123 while ((r = fgets(line, 512, f)))
125 while (*r && isspace(*r))
135 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
137 if (!strcmp(cmd, "tag"))
140 char names[512], type[512], *nm;
144 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
146 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
151 if (!(rr = *tagp = xmalloc(sizeof(*rr))))
156 rr->which = DATA1T_numeric;
157 rr->value.numeric = value;
159 * how to deal with local numeric tags?
162 if (!(rr->kind = data1_maptype(type)))
164 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
176 if (!(*npp = xmalloc(sizeof(**npp))))
178 if ((e = strchr(nm, '/')))
180 if (!((*npp)->name = xmalloc(strlen(nm)+1)))
182 strcpy((*npp)->name, nm);
190 else if (!strcmp(cmd, "name"))
194 if (!sscanf(args, "%s", name))
196 logf(LOG_WARN, "%s malformed name directive in %s", file);
200 if (!(res->name = xmalloc(strlen(args)+1)))
202 strcpy(res->name, name);
204 else if (!strcmp(cmd, "reference"))
208 if (!sscanf(args, "%s", name))
210 logf(LOG_WARN, "%s malformed reference directive in %s", file);
214 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
216 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
221 else if (!strcmp(cmd, "type"))
223 if (!sscanf(args, "%d", &res->type))
225 logf(LOG_WARN, "%s malformed type directive in %s", file);
230 else if (!strcmp(cmd, "include"))
234 if (!sscanf(args, "%s", name))
236 logf(LOG_WARN, "%s malformed reference directive in %s", file);
240 if (!(*childp = data1_read_tagset(name)))
242 logf(LOG_WARN, "Inclusion failed in %s", file);
246 childp = &(*childp)->next;
250 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);