]> diplodocus.org Git - nmh/blob - sbr/readconfig.c
Cope with sasl_decode64() returning SASL_CONTINUE as well as SASL_OK.
[nmh] / sbr / readconfig.c
1
2 /*
3 * readconfig.c -- base routine to read nmh configuration files
4 * -- such as nmh profile, context file, or mhn.defaults.
5 *
6 * $Id$
7 *
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
11 */
12
13 #include <h/mh.h>
14 #include <h/utils.h>
15
16 struct procstr {
17 char *procname;
18 char **procnaddr;
19 };
20
21 static struct procstr procs[] = {
22 { "context", &context },
23 { "mh-sequences", &mh_seq },
24 { "buildmimeproc", &buildmimeproc },
25 { "faceproc", &faceproc },
26 { "fileproc", &fileproc },
27 { "incproc", &incproc },
28 { "installproc", &installproc },
29 { "lproc", &lproc },
30 { "mailproc", &mailproc },
31 { "mhlproc", &mhlproc },
32 { "moreproc", &moreproc },
33 { "mshproc", &mshproc },
34 { "packproc", &packproc },
35 { "postproc", &postproc },
36 { "rmfproc", &rmfproc },
37 { "rmmproc", &rmmproc },
38 { "sendproc", &sendproc },
39 { "showmimeproc", &showmimeproc },
40 { "showproc", &showproc },
41 { "vmhproc", &vmhproc },
42 { "whatnowproc", &whatnowproc },
43 { "whomproc", &whomproc },
44 { NULL, NULL }
45 };
46
47 static struct node **opp = NULL;
48
49
50 void
51 readconfig (struct node **npp, FILE *ib, char *file, int ctx)
52 {
53 register int state;
54 register char *cp;
55 char name[NAMESZ], field[BUFSIZ];
56 register struct node *np;
57 register struct procstr *ps;
58
59 if (npp == NULL && (npp = opp) == NULL) {
60 admonish (NULL, "bug: readconfig called but pump not primed");
61 return;
62 }
63
64 for (state = FLD;;) {
65 switch (state = m_getfld (state, name, field, sizeof(field), ib)) {
66 case FLD:
67 case FLDPLUS:
68 case FLDEOF:
69 np = (struct node *) mh_xmalloc (sizeof(*np));
70 *npp = np;
71 *(npp = &np->n_next) = NULL;
72 np->n_name = getcpy (name);
73 if (state == FLDPLUS) {
74 cp = getcpy (field);
75 while (state == FLDPLUS) {
76 state = m_getfld (state, name, field, sizeof(field), ib);
77 cp = add (field, cp);
78 }
79 np->n_field = trimcpy (cp);
80 free (cp);
81 } else {
82 np->n_field = trimcpy (field);
83 }
84 np->n_context = ctx;
85
86 /*
87 * Now scan the list of `procs' and link in the
88 * field value to the global variable.
89 */
90 for (ps = procs; ps->procname; ps++)
91 if (strcmp (np->n_name, ps->procname) == 0) {
92 *ps->procnaddr = np->n_field;
93 break;
94 }
95 if (state == FLDEOF)
96 break;
97 continue;
98
99 case BODY:
100 case BODYEOF:
101 adios (NULL, "no blank lines are permitted in %s", file);
102
103 case FILEEOF:
104 break;
105
106 default:
107 adios (NULL, "%s is poorly formatted", file);
108 }
109 break;
110 }
111
112 opp = npp;
113 }