]> diplodocus.org Git - nmh/blob - uip/mhparam.c
Fix tests with oauth disabled.
[nmh] / uip / mhparam.c
1
2 /*
3 * mhparam.c -- print mh_profile values
4 *
5 * Originally contributed by
6 * Jeffrey C Honig <Jeffrey_C_Honig@cornell.edu>
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/mts.h>
15
16 #define MHPARAM_SWITCHES \
17 X("components", 0, COMPSW) \
18 X("nocomponents", 0, NCOMPSW) \
19 X("all", 0, ALLSW) \
20 X("version", 0, VERSIONSW) \
21 X("help", 0, HELPSW) \
22 X("debug", 5, DEBUGSW) \
23
24 #define X(sw, minchars, id) id,
25 DEFINE_SWITCH_ENUM(MHPARAM);
26 #undef X
27
28 #define X(sw, minchars, id) { sw, minchars, id },
29 DEFINE_SWITCH_ARRAY(MHPARAM, switches);
30 #undef X
31
32 extern char *mhbindir;
33 extern char *mhetcdir;
34 extern char *mhlibexecdir;
35
36 static char *sbackup = BACKUP_PREFIX;
37
38 static char *datalocking = "fcntl";
39 static char *localmbox = "";
40 static int localmbox_primed = 0;
41
42 extern char *spoollocking;
43
44 static char *sasl =
45 #ifdef CYRUS_SASL
46 "cyrus_sasl";
47 #else
48 "";
49 #endif
50
51 static char *tls =
52 #ifdef TLS_SUPPORT
53 "tls";
54 #else
55 "";
56 #endif
57
58 static char *mimetypeproc =
59 #ifdef MIMETYPEPROC
60 MIMETYPEPROC;
61 #else
62 "";
63 #endif
64
65 static char *mimeencodingproc =
66 #ifdef MIMEENCODINGPROC
67 MIMEENCODINGPROC;
68 #else
69 "";
70 #endif
71
72 static char *iconv =
73 #ifdef HAVE_ICONV
74 "iconv";
75 #else
76 "";
77 #endif
78
79 static char *oauth =
80 #ifdef OAUTH_SUPPORT
81 "oauth";
82 #else
83 "";
84 #endif
85
86 struct proc {
87 char *p_name;
88 char **p_field;
89 };
90
91 static struct proc procs [] = {
92 { "context", &context },
93 { "mh-sequences", &mh_seq },
94 { "buildmimeproc", &buildmimeproc },
95 { "fileproc", &fileproc },
96 { "foldprot", &foldprot },
97 { "formatproc", &formatproc },
98 { "incproc", &incproc },
99 { "lproc", &lproc },
100 { "mailproc", &mailproc },
101 { "mhlproc", &mhlproc },
102 { "mimetypeproc", &mimetypeproc },
103 { "mimeencodingproc", &mimeencodingproc },
104 { "moreproc", &moreproc },
105 { "msgprot", &msgprot },
106 { "packproc", &packproc },
107 { "postproc", &postproc },
108 { "rmmproc", &rmmproc },
109 { "sendproc", &sendproc },
110 { "showmimeproc", &showmimeproc },
111 { "showproc", &showproc },
112 { "version", &version_num },
113 { "whatnowproc", &whatnowproc },
114 { "whomproc", &whomproc },
115 { "bindir", &mhbindir },
116 { "etcdir", &mhetcdir },
117 { "libdir", &mhlibexecdir },
118 { "libexecdir", &mhlibexecdir },
119 { "localmbox", &localmbox },
120 { "sbackup", &sbackup },
121 { "datalocking", &datalocking },
122 { "spoollocking", &spoollocking },
123 { "iconv", &iconv },
124 { "oauth", &oauth },
125 { "sasl", &sasl },
126 { "tls", &tls },
127 { NULL, NULL },
128 };
129
130
131 /*
132 * static prototypes
133 */
134 static char *p_find(char *);
135
136
137 int
138 main(int argc, char **argv)
139 {
140 int i, compp = 0, missed = 0;
141 int all = 0, debug = 0;
142 int components = -1;
143 char *cp, buf[BUFSIZ], **argp;
144 char **arguments, *comps[MAXARGS];
145
146 if (nmh_init(argv[0], 1)) { return 1; }
147
148 arguments = getarguments (invo_name, argc, argv, 1);
149 argp = arguments;
150
151 while ((cp = *argp++)) {
152 if (*cp == '-') {
153 switch (smatch (++cp, switches)) {
154 case AMBIGSW:
155 ambigsw (cp, switches);
156 done (1);
157 case UNKWNSW:
158 adios (NULL, "-%s unknown", cp);
159
160 case HELPSW:
161 snprintf (buf, sizeof(buf), "%s [profile-components] [switches]",
162 invo_name);
163 print_help (buf, switches, 1);
164 done (0);
165 case VERSIONSW:
166 print_version(invo_name);
167 done (0);
168
169 case COMPSW:
170 components = 1;
171 break;
172 case NCOMPSW:
173 components = 0;
174 break;
175
176 case ALLSW:
177 all = 1;
178 break;
179
180 case DEBUGSW:
181 debug = 1;
182 break;
183 }
184 } else {
185 comps[compp++] = cp;
186 if (strcmp("localmbox", cp) == 0 && ! localmbox_primed) {
187 localmbox = getlocalmbox();
188 localmbox_primed = 1;
189 }
190 }
191 }
192
193 if (all) {
194 struct node *np;
195
196 if (compp)
197 advise(NULL, "profile-components ignored with -all");
198
199 if (components >= 0)
200 advise(NULL, "-%scomponents ignored with -all",
201 components ? "" : "no");
202
203 /* Print all entries in context/profile list. That does not
204 include entries in mts.conf, such as spoollocking. */
205 for (np = m_defs; np; np = np->n_next)
206 printf("%s: %s\n", np->n_name, np->n_field);
207
208 } else if (debug) {
209 struct proc *ps;
210
211 /* In case datalocking was set in profile. */
212 if ((cp = context_find("datalocking"))) { datalocking = cp; }
213
214 /* In case spoollocking was set in mts.conf. */
215 mts_init(invo_name);
216
217 /* Also set localmbox here */
218 if (! localmbox_primed) {
219 localmbox = getlocalmbox();
220 localmbox_primed = 1;
221 }
222
223 /*
224 * Print the current value of everything in
225 * procs array. This will show their current
226 * value (as determined after context is read).
227 */
228 for (ps = procs; ps->p_name; ps++)
229 printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : "");
230
231 } else {
232 if (components < 0)
233 components = compp > 1;
234
235 for (i = 0; i < compp; i++) {
236 register char *value;
237
238 if (! strcmp ("spoollocking", comps[i])) {
239 /* In case spoollocking was set in mts.conf. */
240 mts_init(invo_name);
241 }
242
243 value = context_find (comps[i]);
244 if (!value)
245 value = p_find (comps[i]);
246 if (value) {
247 if (components)
248 printf("%s: ", comps[i]);
249
250 printf("%s\n", value);
251 } else
252 missed++;
253 }
254 }
255
256 done (missed);
257 return 1;
258 }
259
260
261 static char *
262 p_find(char *str)
263 {
264 struct proc *ps;
265
266 for (ps = procs; ps->p_name; ps++)
267 if (!strcasecmp (ps->p_name, str ? str : ""))
268 return (*ps->p_field);
269
270 return NULL;
271 }