ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/conf.C
Revision: 1.5
Committed: Tue Aug 28 22:18:31 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +298 -277 lines
Log Message:
added type traits

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * conf.C: Configuration processing.
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 pippijn 1.1 */
7    
8 pippijn 1.5 static char const rcsid[] = "$Id: conf.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
9 pippijn 1.1
10     #include "atheme.h"
11 pippijn 1.4 #include <ermyth/crypto.h>
12     #include <ermyth/database.h>
13     #include <ermyth/module.h>
14 pippijn 1.1 #include <account/myuser.h>
15     #include <account/mychan.h>
16     #include <account/chanacs.h>
17     #include "uplink.h"
18     #include "pmodule.h"
19     #include "privs.h"
20    
21 pippijn 1.4 ConfTable::callbacks ConfTable::callback;
22    
23 pippijn 1.5 namespace config
24     {
25     enum error
26     {
27     no_param,
28     wrong_param
29     };
30     }
31    
32     template<config::error e>
33     int param_error (config_entry_t *ce, char const * const msg = NULL);
34    
35     template<>
36     int param_error<config::no_param> (config_entry_t *ce, char const * const msg)
37     {
38     slog (LG_INFO, "%s:%i: no parameter for "
39     "configuration option: %s %s",
40     ce->ce_fileptr->cf_filename,
41     ce->ce_varlinenum, ce->ce_varname,
42     msg ? msg : "");
43     return 1;
44     }
45    
46     template<>
47     int param_error<config::wrong_param> (config_entry_t *ce, char const * const msg)
48     {
49     slog (LG_INFO, "%s:%i: wrong parameter for "
50     "configuration option: %s %s",
51     ce->ce_fileptr->cf_filename,
52     ce->ce_varlinenum, ce->ce_varname, msg ? msg : "");
53     return 1;
54 pippijn 1.1 }
55    
56 pippijn 1.4 static int c_serverinfo (config_entry_t *);
57     static int c_general (config_entry_t *);
58     static int c_database (config_entry_t *);
59     static int c_uplink (config_entry_t *);
60     static int c_chanserv (config_entry_t *);
61     static int c_globserv (config_entry_t *);
62     static int c_operserv (config_entry_t *);
63     static int c_memoserv (config_entry_t *);
64     static int c_gameserv (config_entry_t *);
65     static int c_nickserv (config_entry_t *);
66     static int c_saslserv (config_entry_t *);
67     static int c_loadmodule (config_entry_t *);
68     static int c_backend (config_entry_t *);
69     static int c_crypto (config_entry_t *);
70     static int c_protocol (config_entry_t *);
71     static int c_operclass (config_entry_t *);
72     static int c_operator (config_entry_t *);
73     static int c_logfile (config_entry_t *);
74    
75     static int c_si_name (config_entry_t *);
76     static int c_si_desc (config_entry_t *);
77     static int c_si_numeric (config_entry_t *);
78     static int c_si_vhost (config_entry_t *);
79     static int c_si_recontime (config_entry_t *);
80     static int c_si_restarttime (config_entry_t *);
81     static int c_si_netname (config_entry_t *);
82     static int c_si_hidehostsuffix (config_entry_t *);
83     static int c_si_adminname (config_entry_t *);
84     static int c_si_adminemail (config_entry_t *);
85     static int c_si_mta (config_entry_t *);
86     static int c_si_loglevel (config_entry_t *);
87     static int c_si_maxlogins (config_entry_t *);
88     static int c_si_maxusers (config_entry_t *);
89     static int c_si_maxnicks (config_entry_t *);
90     static int c_si_maxchans (config_entry_t *);
91     static int c_si_emaillimit (config_entry_t *);
92     static int c_si_emailtime (config_entry_t *);
93     static int c_si_auth (config_entry_t *);
94     static int c_si_mdlimit (config_entry_t *);
95     static int c_si_casemapping (config_entry_t *);
96    
97     /* ChanServ client information. */
98     static int c_ci_nick (config_entry_t *);
99     static int c_ci_user (config_entry_t *);
100     static int c_ci_host (config_entry_t *);
101     static int c_ci_real (config_entry_t *);
102     static int c_ci_fantasy (config_entry_t *);
103     static int c_ci_vop (config_entry_t *);
104     static int c_ci_hop (config_entry_t *);
105     static int c_ci_aop (config_entry_t *);
106     static int c_ci_sop (config_entry_t *);
107     static int c_ci_changets (config_entry_t *);
108     static int c_ci_trigger (config_entry_t *);
109     static int c_ci_expire (config_entry_t *);
110     static int c_ci_maxchanacs (config_entry_t *);
111     static int c_ci_maxfounders (config_entry_t *);
112    
113     /* GlobServ client information. */
114     static int c_gl_nick (config_entry_t *);
115     static int c_gl_user (config_entry_t *);
116     static int c_gl_host (config_entry_t *);
117     static int c_gl_real (config_entry_t *);
118    
119     /* OperServ client information. */
120     static int c_oi_nick (config_entry_t *);
121     static int c_oi_user (config_entry_t *);
122     static int c_oi_host (config_entry_t *);
123     static int c_oi_real (config_entry_t *);
124 pippijn 1.1
125     /* NickServ client information. */
126 pippijn 1.4 static int c_ni_nick (config_entry_t *);
127     static int c_ni_user (config_entry_t *);
128     static int c_ni_host (config_entry_t *);
129     static int c_ni_real (config_entry_t *);
130     static int c_ni_spam (config_entry_t *);
131     static int c_ni_no_nick_ownership (config_entry_t *);
132     static int c_ni_expire (config_entry_t *);
133 pippijn 1.1
134     /* SaslServ client information. */
135 pippijn 1.4 static int c_ss_nick (config_entry_t *);
136     static int c_ss_user (config_entry_t *);
137     static int c_ss_host (config_entry_t *);
138     static int c_ss_real (config_entry_t *);
139 pippijn 1.1
140     /* MemoServ client information. */
141 pippijn 1.4 static int c_ms_nick (config_entry_t *);
142     static int c_ms_user (config_entry_t *);
143     static int c_ms_host (config_entry_t *);
144     static int c_ms_real (config_entry_t *);
145 pippijn 1.1
146     /* GameServ client information. */
147 pippijn 1.4 static int c_gs_nick (config_entry_t *);
148     static int c_gs_user (config_entry_t *);
149     static int c_gs_host (config_entry_t *);
150     static int c_gs_real (config_entry_t *);
151 pippijn 1.1
152     /* Database information. */
153 pippijn 1.4 static int c_db_user (config_entry_t *);
154     static int c_db_host (config_entry_t *);
155     static int c_db_password (config_entry_t *);
156     static int c_db_database (config_entry_t *);
157     static int c_db_port (config_entry_t *);
158    
159     static int c_gi_chan (config_entry_t *);
160     static int c_gi_silent (config_entry_t *);
161     static int c_gi_verbose_wallops (config_entry_t *);
162     static int c_gi_use_privmsg (config_entry_t *);
163     static int c_gi_join_chans (config_entry_t *);
164     static int c_gi_leave_chans (config_entry_t *);
165     static int c_gi_uflags (config_entry_t *);
166     static int c_gi_cflags (config_entry_t *);
167     static int c_gi_raw (config_entry_t *);
168     static int c_gi_flood_msgs (config_entry_t *);
169     static int c_gi_flood_time (config_entry_t *);
170     static int c_gi_kline_time (config_entry_t *);
171     static int c_gi_commit_interval (config_entry_t *);
172     static int c_gi_expire (config_entry_t *);
173     static int c_gi_secure (config_entry_t *);
174     static int c_gi_default_clone_limit (config_entry_t *);
175 pippijn 1.1
176     /* *INDENT-OFF* */
177    
178     static Token uflags[] = {
179     { "HOLD", MU_HOLD },
180     { "NEVEROP", MU_NEVEROP },
181     { "NOOP", MU_NOOP },
182     { "HIDEMAIL", MU_HIDEMAIL },
183     { "NONE", 0 },
184     { NULL, 0 }
185     };
186    
187     static Token cflags[] = {
188     { "HOLD", MC_HOLD },
189     { "SECURE", MC_SECURE },
190     { "VERBOSE", MC_VERBOSE },
191     { "KEEPTOPIC", MC_KEEPTOPIC },
192     { "VERBOSE_OPS", MC_VERBOSE_OPS },
193     { "TOPICLOCK", MC_TOPICLOCK },
194 pippijn 1.4 { "GUARD", MC_GUARD },
195 pippijn 1.1 { "NONE", 0 },
196     { NULL, 0 }
197     };
198    
199     static Token logflags[] = {
200 pippijn 1.4 { "DEBUG", LG_ALL },
201     { "TRACE", LG_INFO | LG_ERROR | LG_CMD_ALL | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
202 pippijn 1.1 { "MISC", LG_INFO | LG_ERROR | LG_CMD_ADMIN | LG_CMD_REGISTER | LG_CMD_SET | LG_NETWORK | LG_WALLOPS | LG_REGISTER },
203 pippijn 1.4 { "NOTICE", LG_INFO | LG_ERROR | LG_CMD_ADMIN | LG_CMD_REGISTER | LG_NETWORK | LG_REGISTER },
204     { "ALL", LG_ALL },
205     { "INFO", LG_INFO },
206     { "ERROR", LG_ERROR },
207     { "COMMANDS", LG_CMD_ALL },
208     { "ADMIN", LG_CMD_ADMIN },
209     { "REGISTER", LG_CMD_REGISTER | LG_REGISTER },
210     { "SET", LG_CMD_SET },
211     { "NETWORK", LG_NETWORK },
212     { "WALLOPS", LG_WALLOPS },
213     { "RAWDATA", LG_RAWDATA },
214     { NULL, 0 }
215 pippijn 1.1 };
216    
217 pippijn 1.4 static list_t confblocks;
218     static list_t conf_si_table;
219     static list_t conf_ci_table;
220     static list_t conf_gl_table;
221     static list_t conf_oi_table;
222     static list_t conf_ni_table;
223     static list_t conf_db_table;
224     static list_t conf_gi_table;
225     static list_t conf_ms_table;
226     static list_t conf_la_table;
227     static list_t conf_ss_table;
228     static list_t conf_gs_table;
229 pippijn 1.1
230     /* *INDENT-ON* */
231    
232     static void
233 pippijn 1.4 conf_report_error (config_entry_t *ce, char const * const fmt, ...)
234 pippijn 1.1 {
235     va_list va;
236     char buf[BUFSIZE];
237    
238     return_if_fail (ce != NULL);
239     return_if_fail (fmt != NULL);
240    
241     va_start (va, fmt);
242     vsnprintf (buf, BUFSIZE, fmt, va);
243     va_end (va);
244    
245     slog (LG_INFO, "%s:%d: configuration error - %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, buf);
246     }
247    
248     static void
249     conf_process (config_file_t *cfp)
250     {
251     config_file_t *cfptr;
252     config_entry_t *ce;
253     node_t *tn;
254     ConfTable *ct = NULL;
255    
256     for (cfptr = cfp; cfptr; cfptr = cfptr->cf_next)
257     {
258     for (ce = cfptr->cf_entries; ce; ce = ce->ce_next)
259 pippijn 1.4 {
260     LIST_FOREACH (tn, confblocks.head)
261     {
262     ct = static_cast<ConfTable *> (tn->data);
263    
264     if (!strcasecmp (ct->name, ce->ce_varname))
265     {
266     ct->handler (ce);
267     break;
268     }
269     }
270    
271     if (ct == NULL)
272     conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
273     }
274 pippijn 1.1 }
275     }
276    
277     bool
278     conf_parse (char *file)
279     {
280     config_file_t *cfp;
281    
282     cfp = config_load (file);
283     if (cfp == NULL)
284     {
285     slog (LG_ERROR, "conf_parse(): unable to load configuration file: %s", strerror (errno));
286    
287     return false;
288     }
289    
290     conf_process (cfp);
291     config_free (cfp);
292    
293 pippijn 1.4 if (!protocol::handler::loaded)
294 pippijn 1.1 {
295     slog (LG_ERROR, "No protocol module loaded, aborting");
296     exit (EXIT_FAILURE);
297     }
298    
299 pippijn 1.4 ConfTable::callback.ready ();
300 pippijn 1.1 return true;
301     }
302    
303     void
304     conf_init (void)
305     {
306 pippijn 1.4 me.init ();
307 pippijn 1.1 if (chansvs.nick)
308 pippijn 1.4 sfree (chansvs.nick);
309 pippijn 1.1 if (config_options.chan)
310 pippijn 1.4 sfree (config_options.chan);
311 pippijn 1.1 if (config_options.global)
312 pippijn 1.4 sfree (config_options.global);
313 pippijn 1.1 if (config_options.languagefile)
314 pippijn 1.4 sfree (config_options.languagefile);
315 pippijn 1.1
316 pippijn 1.4 chansvs.nick = config_options.chan = config_options.global = config_options.languagefile = NULL;
317 pippijn 1.1
318 pippijn 1.4 config_options.flood_msgs = config_options.flood_time = config_options.kline_time = config_options.commit_interval = 0;
319 pippijn 1.1
320     nicksvs.expiry = chansvs.expiry = 0;
321    
322     config_options.defuflags = config_options.defcflags = 0x00000000;
323    
324     config_options.silent = config_options.join_chans = config_options.leave_chans = config_options.raw = false;
325    
326     me.auth = AUTH_NONE;
327    
328     me.mdlimit = 30;
329    
330     chansvs.fantasy = false;
331     if (chansvs.me != NULL && fcmd_agent == chansvs.me)
332     fcmd_agent = NULL;
333     chansvs.ca_vop = CA_VOP_DEF & ca_all;
334     chansvs.ca_hop = CA_HOP_DEF & ca_all;
335     chansvs.ca_aop = CA_AOP_DEF & ca_all;
336     chansvs.ca_sop = CA_SOP_DEF & ca_all;
337     chansvs.changets = false;
338     if (chansvs.trigger != NULL)
339 pippijn 1.4 sfree (chansvs.trigger);
340 pippijn 1.1 chansvs.trigger = sstrdup ("!");
341     chansvs.maxchanacs = 0;
342 pippijn 1.4 chansvs.maxfounders = 4;
343 pippijn 1.1
344     if (!(runflags & RF_REHASHING))
345     {
346     if (me.name)
347 pippijn 1.4 sfree (me.name);
348 pippijn 1.1 if (me.desc)
349 pippijn 1.4 sfree (me.desc);
350 pippijn 1.1 if (me.vhost)
351 pippijn 1.4 sfree (me.vhost);
352 pippijn 1.1 if (chansvs.user)
353 pippijn 1.4 sfree (chansvs.user);
354 pippijn 1.1 if (chansvs.host)
355 pippijn 1.4 sfree (chansvs.host);
356 pippijn 1.1 if (chansvs.real)
357 pippijn 1.4 sfree (chansvs.real);
358 pippijn 1.1
359     me.name = me.desc = me.vhost = chansvs.user = chansvs.host = chansvs.real = NULL;
360    
361 pippijn 1.4 set_match_mapping (MATCH_RFC1459); /* default to RFC compliancy */
362 pippijn 1.1 }
363     }
364    
365     int
366     subblock_handler (config_entry_t *ce, list_t *entries)
367     {
368     node_t *tn;
369     ConfTable *ct = NULL;
370    
371     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
372     {
373     LIST_FOREACH (tn, entries->head)
374     {
375 pippijn 1.4 ct = static_cast<ConfTable *> (tn->data);
376 pippijn 1.1
377 pippijn 1.4 if (!strcasecmp (ct->name, ce->ce_varname))
378     {
379     ct->handler (ce);
380     break;
381     }
382 pippijn 1.1 }
383    
384     if (ct == NULL)
385 pippijn 1.4 conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname);
386 pippijn 1.1 }
387     return 0;
388     }
389    
390     struct ConfTable *
391 pippijn 1.4 find_top_conf (char const * const name)
392 pippijn 1.1 {
393     node_t *n;
394     ConfTable *ct;
395    
396     LIST_FOREACH (n, confblocks.head)
397     {
398     ct = static_cast<ConfTable *> (n->data);
399    
400     if (!strcasecmp (ct->name, name))
401     return ct;
402     }
403    
404     return NULL;
405     }
406    
407     struct ConfTable *
408 pippijn 1.4 find_conf_item (char const * const name, list_t *conflist)
409 pippijn 1.1 {
410     node_t *n;
411     ConfTable *ct;
412    
413     LIST_FOREACH (n, conflist->head)
414     {
415     ct = static_cast<ConfTable *> (n->data);
416    
417     if (!strcasecmp (ct->name, name))
418     return ct;
419     }
420    
421     return NULL;
422     }
423    
424     void
425 pippijn 1.4 add_top_conf (char const * const name, int (*handler) (config_entry_t *ce))
426 pippijn 1.1 {
427     ConfTable *ct;
428    
429     if ((ct = find_top_conf (name)))
430     {
431     slog (LG_DEBUG, "add_top_conf(): duplicate config block '%s'.", name);
432     return;
433     }
434    
435 pippijn 1.4 ct = new ConfTable (name, 1, handler);
436 pippijn 1.1
437     node_add (ct, node_create (), &confblocks);
438     }
439    
440     void
441 pippijn 1.4 add_conf_item (char const * const name, list_t *conflist, int (*handler) (config_entry_t *ce))
442 pippijn 1.1 {
443     ConfTable *ct;
444    
445     if ((ct = find_conf_item (name, conflist)))
446     {
447     slog (LG_DEBUG, "add_conf_item(): duplicate item %s", name);
448     return;
449     }
450    
451 pippijn 1.4 ct = new ConfTable (name, 1, handler);
452 pippijn 1.1
453     node_add (ct, node_create (), conflist);
454     }
455    
456     void
457 pippijn 1.4 del_top_conf (char const * const name)
458 pippijn 1.1 {
459     node_t *n;
460     ConfTable *ct;
461    
462     if (!(ct = find_top_conf (name)))
463     {
464     slog (LG_DEBUG, "del_top_conf(): cannot delete nonexistant block %s", name);
465     return;
466     }
467    
468     n = node_find (ct, &confblocks);
469     node_del (n, &confblocks);
470    
471 pippijn 1.4 delete ct;
472 pippijn 1.1 }
473    
474     void
475 pippijn 1.4 del_conf_item (char const * const name, list_t *conflist)
476 pippijn 1.1 {
477     node_t *n;
478     ConfTable *ct;
479    
480     if (!(ct = find_conf_item (name, conflist)))
481     {
482     slog (LG_DEBUG, "del_conf_item(): cannot delete nonexistant item %s", name);
483     return;
484     }
485    
486     n = node_find (ct, conflist);
487     node_del (n, conflist);
488    
489 pippijn 1.4 delete ct;
490 pippijn 1.1 }
491    
492     /* stolen from Sentinel */
493 pippijn 1.4 #define TOKEN_UNMATCHED -1
494     #define TOKEN_ERROR -2
495    
496     static int
497 pippijn 1.1 token_to_value (struct Token token_table[], char *token)
498     {
499     int i;
500    
501     if ((token_table != NULL) && (token != NULL))
502     {
503     for (i = 0; token_table[i].text != NULL; i++)
504 pippijn 1.4 {
505     if (strcasecmp (token_table[i].text, token) == 0)
506     {
507     return token_table[i].value;
508     }
509     }
510 pippijn 1.1 /* If no match... */
511     return TOKEN_UNMATCHED;
512     }
513    
514     /* Otherwise... */
515     return TOKEN_ERROR;
516     }
517    
518     void
519     init_newconf (void)
520     {
521 pippijn 1.4 #if 0
522 pippijn 1.1 conftable_heap = BlockHeapCreate (sizeof (struct ConfTable), 32);
523 pippijn 1.4 #endif
524 pippijn 1.1
525     /* First we set up the blocks. */
526     add_top_conf ("SERVERINFO", c_serverinfo);
527 pippijn 1.4 add_top_conf ("CHANSERV", c_chanserv);
528     add_top_conf ("GLOBAL", c_globserv);
529     add_top_conf ("OPERSERV", c_operserv);
530 pippijn 1.1 add_top_conf ("NICKSERV", c_nickserv);
531     add_top_conf ("SASLSERV", c_saslserv);
532     add_top_conf ("MEMOSERV", c_memoserv);
533     add_top_conf ("GAMESERV", c_gameserv);
534     add_top_conf ("UPLINK", c_uplink);
535     add_top_conf ("GENERAL", c_general);
536     add_top_conf ("DATABASE", c_database);
537     add_top_conf ("LOADMODULE", c_loadmodule);
538 pippijn 1.4 add_top_conf ("BACKEND", c_backend);
539     add_top_conf ("CRYPTO", c_crypto);
540     add_top_conf ("PROTOCOL", c_protocol);
541 pippijn 1.1 add_top_conf ("OPERCLASS", c_operclass);
542     add_top_conf ("OPERATOR", c_operator);
543     add_top_conf ("LOGFILE", c_logfile);
544    
545     /* Now we fill in the information */
546     add_conf_item ("NAME", &conf_si_table, c_si_name);
547     add_conf_item ("DESC", &conf_si_table, c_si_desc);
548     add_conf_item ("NUMERIC", &conf_si_table, c_si_numeric);
549     add_conf_item ("VHOST", &conf_si_table, c_si_vhost);
550     add_conf_item ("RECONTIME", &conf_si_table, c_si_recontime);
551     add_conf_item ("RESTARTTIME", &conf_si_table, c_si_restarttime);
552     add_conf_item ("EXPIRE", &conf_si_table, c_gi_expire);
553     add_conf_item ("NETNAME", &conf_si_table, c_si_netname);
554     add_conf_item ("HIDEHOSTSUFFIX", &conf_si_table, c_si_hidehostsuffix);
555     add_conf_item ("ADMINNAME", &conf_si_table, c_si_adminname);
556     add_conf_item ("ADMINEMAIL", &conf_si_table, c_si_adminemail);
557     add_conf_item ("MTA", &conf_si_table, c_si_mta);
558     add_conf_item ("LOGLEVEL", &conf_si_table, c_si_loglevel);
559     add_conf_item ("MAXLOGINS", &conf_si_table, c_si_maxlogins);
560     add_conf_item ("MAXUSERS", &conf_si_table, c_si_maxusers);
561     add_conf_item ("MAXNICKS", &conf_si_table, c_si_maxnicks);
562     add_conf_item ("MAXCHANS", &conf_si_table, c_si_maxchans);
563     add_conf_item ("EMAILLIMIT", &conf_si_table, c_si_emaillimit);
564     add_conf_item ("EMAILTIME", &conf_si_table, c_si_emailtime);
565     add_conf_item ("AUTH", &conf_si_table, c_si_auth);
566     add_conf_item ("MDLIMIT", &conf_si_table, c_si_mdlimit);
567     add_conf_item ("CASEMAPPING", &conf_si_table, c_si_casemapping);
568    
569     /* general{} block. */
570     add_conf_item ("CHAN", &conf_gi_table, c_gi_chan);
571     add_conf_item ("VERBOSE_WALLOPS", &conf_gi_table, c_gi_verbose_wallops);
572     add_conf_item ("USE_PRIVMSG", &conf_gi_table, c_gi_use_privmsg);
573     add_conf_item ("SILENT", &conf_gi_table, c_gi_silent);
574     add_conf_item ("JOIN_CHANS", &conf_gi_table, c_gi_join_chans);
575     add_conf_item ("LEAVE_CHANS", &conf_gi_table, c_gi_leave_chans);
576     add_conf_item ("UFLAGS", &conf_gi_table, c_gi_uflags);
577     add_conf_item ("CFLAGS", &conf_gi_table, c_gi_cflags);
578     add_conf_item ("RAW", &conf_gi_table, c_gi_raw);
579     add_conf_item ("SECURE", &conf_gi_table, c_gi_secure);
580     add_conf_item ("FLOOD_MSGS", &conf_gi_table, c_gi_flood_msgs);
581     add_conf_item ("FLOOD_TIME", &conf_gi_table, c_gi_flood_time);
582     add_conf_item ("KLINE_TIME", &conf_gi_table, c_gi_kline_time);
583     add_conf_item ("COMMIT_INTERVAL", &conf_gi_table, c_gi_commit_interval);
584     add_conf_item ("EXPIRE", &conf_gi_table, c_gi_expire);
585 pippijn 1.4 add_conf_item ("DEFAULT_CLONE_LIMIT", &conf_gi_table, c_gi_default_clone_limit);
586 pippijn 1.1
587     /* chanserv{} block */
588     add_conf_item ("NICK", &conf_ci_table, c_ci_nick);
589     add_conf_item ("USER", &conf_ci_table, c_ci_user);
590     add_conf_item ("HOST", &conf_ci_table, c_ci_host);
591     add_conf_item ("REAL", &conf_ci_table, c_ci_real);
592     add_conf_item ("FANTASY", &conf_ci_table, c_ci_fantasy);
593     add_conf_item ("VOP", &conf_ci_table, c_ci_vop);
594     add_conf_item ("HOP", &conf_ci_table, c_ci_hop);
595     add_conf_item ("AOP", &conf_ci_table, c_ci_aop);
596     add_conf_item ("SOP", &conf_ci_table, c_ci_sop);
597     add_conf_item ("CHANGETS", &conf_ci_table, c_ci_changets);
598     add_conf_item ("TRIGGER", &conf_ci_table, c_ci_trigger);
599     add_conf_item ("EXPIRE", &conf_ci_table, c_ci_expire);
600     add_conf_item ("MAXCHANACS", &conf_ci_table, c_ci_maxchanacs);
601 pippijn 1.4 add_conf_item ("MAXFOUNDERS", &conf_ci_table, c_ci_maxfounders);
602 pippijn 1.1
603     /* global{} block */
604     add_conf_item ("NICK", &conf_gl_table, c_gl_nick);
605     add_conf_item ("USER", &conf_gl_table, c_gl_user);
606     add_conf_item ("HOST", &conf_gl_table, c_gl_host);
607     add_conf_item ("REAL", &conf_gl_table, c_gl_real);
608    
609     /* operserv{} block */
610     add_conf_item ("NICK", &conf_oi_table, c_oi_nick);
611     add_conf_item ("USER", &conf_oi_table, c_oi_user);
612     add_conf_item ("HOST", &conf_oi_table, c_oi_host);
613     add_conf_item ("REAL", &conf_oi_table, c_oi_real);
614    
615     /* nickserv{} block */
616     add_conf_item ("NICK", &conf_ni_table, c_ni_nick);
617     add_conf_item ("USER", &conf_ni_table, c_ni_user);
618     add_conf_item ("HOST", &conf_ni_table, c_ni_host);
619     add_conf_item ("REAL", &conf_ni_table, c_ni_real);
620     add_conf_item ("SPAM", &conf_ni_table, c_ni_spam);
621     add_conf_item ("NO_NICK_OWNERSHIP", &conf_ni_table, c_ni_no_nick_ownership);
622     add_conf_item ("EXPIRE", &conf_ni_table, c_ni_expire);
623    
624     /* saslserv{} block */
625     add_conf_item ("NICK", &conf_ss_table, c_ss_nick);
626     add_conf_item ("USER", &conf_ss_table, c_ss_user);
627     add_conf_item ("HOST", &conf_ss_table, c_ss_host);
628     add_conf_item ("REAL", &conf_ss_table, c_ss_real);
629    
630     /* memoserv{} block */
631     add_conf_item ("NICK", &conf_ms_table, c_ms_nick);
632     add_conf_item ("USER", &conf_ms_table, c_ms_user);
633     add_conf_item ("HOST", &conf_ms_table, c_ms_host);
634     add_conf_item ("REAL", &conf_ms_table, c_ms_real);
635    
636     /* memoserv{} block */
637     add_conf_item ("NICK", &conf_gs_table, c_gs_nick);
638     add_conf_item ("USER", &conf_gs_table, c_gs_user);
639     add_conf_item ("HOST", &conf_gs_table, c_gs_host);
640     add_conf_item ("REAL", &conf_gs_table, c_gs_real);
641    
642     /* database{} block */
643     add_conf_item ("USER", &conf_db_table, c_db_user);
644     add_conf_item ("HOST", &conf_db_table, c_db_host);
645     add_conf_item ("PASSWORD", &conf_db_table, c_db_password);
646     add_conf_item ("DATABASE", &conf_db_table, c_db_database);
647     add_conf_item ("PORT", &conf_db_table, c_db_port);
648     }
649    
650     static int
651     c_serverinfo (config_entry_t *ce)
652     {
653 pippijn 1.4 return subblock_handler (ce, &conf_si_table);
654 pippijn 1.1 }
655    
656     static int
657 pippijn 1.4 c_chanserv (config_entry_t *ce)
658 pippijn 1.1 {
659 pippijn 1.4 return subblock_handler (ce, &conf_ci_table);
660 pippijn 1.1 }
661    
662     static int
663 pippijn 1.4 c_globserv (config_entry_t *ce)
664 pippijn 1.1 {
665 pippijn 1.4 return subblock_handler (ce, &conf_gl_table);
666 pippijn 1.1 }
667    
668     static int
669 pippijn 1.4 c_operserv (config_entry_t *ce)
670 pippijn 1.1 {
671 pippijn 1.4 return subblock_handler (ce, &conf_oi_table);
672 pippijn 1.1 }
673    
674     static int
675     c_nickserv (config_entry_t *ce)
676     {
677 pippijn 1.4 return subblock_handler (ce, &conf_ni_table);
678 pippijn 1.1 }
679    
680     static int
681     c_saslserv (config_entry_t *ce)
682     {
683 pippijn 1.4 return subblock_handler (ce, &conf_ss_table);
684 pippijn 1.1 }
685    
686     static int
687     c_memoserv (config_entry_t *ce)
688     {
689 pippijn 1.4 return subblock_handler (ce, &conf_ms_table);
690 pippijn 1.1 }
691    
692     static int
693     c_gameserv (config_entry_t *ce)
694     {
695 pippijn 1.4 return subblock_handler (ce, &conf_gs_table);
696 pippijn 1.1 }
697    
698     static int
699     c_database (config_entry_t *ce)
700     {
701 pippijn 1.4 return subblock_handler (ce, &conf_db_table);
702     }
703    
704     static int
705     c_protocol (config_entry_t *ce)
706     {
707     char *name;
708    
709     if (cold_start == false)
710     return 0;
711    
712 pippijn 1.5 if (ce->vardata<char *> () == NULL)
713     return param_error<config::no_param> (ce);
714 pippijn 1.4
715 pippijn 1.5 name = ce->vardata<char *> ();
716 pippijn 1.4
717     typedef factory::factory_mgr<protocol::handler> protocol_factory;
718     protocol_factory &f = protocol_factory::instance ();
719    
720     if (!f.provides (name))
721 pippijn 1.5 return param_error<config::wrong_param> (ce, "(no such protocol handler)");
722 pippijn 1.4
723     phandler = f.create (name);
724    
725 pippijn 1.1 return 0;
726     }
727    
728     static int
729     c_loadmodule (config_entry_t *ce)
730     {
731     char *name;
732    
733     if (cold_start == false)
734     return 0;
735    
736 pippijn 1.5 if (ce->vardata<char *> () == NULL)
737     return param_error<config::no_param> (ce);
738 pippijn 1.1
739 pippijn 1.5 name = ce->vardata<char *> ();
740 pippijn 1.1
741 pippijn 1.4 if (!modules::provides (name))
742 pippijn 1.5 return param_error<config::wrong_param> (ce, "(no such module)");
743 pippijn 1.4
744     modules::enable (name);
745    
746     return 0;
747     }
748    
749     static int
750     c_crypto (config_entry_t *ce)
751     {
752     char *name;
753    
754     if (cold_start == false)
755     return 0;
756    
757 pippijn 1.5 if (ce->vardata<char *> () == NULL)
758     return param_error<config::no_param> (ce);
759 pippijn 1.4
760 pippijn 1.5 name = ce->vardata<char *> ();
761 pippijn 1.4
762     typedef factory::factory_mgr<crypto::handler> crypto_factory;
763     crypto_factory &f = crypto_factory::instance ();
764    
765     if (!f.provides (name))
766 pippijn 1.5 return param_error<config::wrong_param> (ce, "(no such crypto handler)");
767 pippijn 1.4
768     crypter = f.create (name);
769    
770     return 0;
771     }
772    
773     static int
774     c_backend (config_entry_t *ce)
775     {
776     char *name;
777    
778     if (cold_start == false)
779     return 0;
780    
781 pippijn 1.5 if (ce->vardata<char *> () == NULL)
782     return param_error<config::no_param> (ce);
783 pippijn 1.4
784 pippijn 1.5 name = ce->vardata<char *> ();
785 pippijn 1.4
786     typedef factory::factory_mgr<database::handler> backend_factory;
787     backend_factory &f = backend_factory::instance ();
788    
789     if (!f.provides (name))
790 pippijn 1.5 return param_error<config::wrong_param> (ce, "(no such database backend)");
791 pippijn 1.4
792     backend = f.create (name);
793    
794     return 0;
795 pippijn 1.1 }
796    
797     static int
798     c_uplink (config_entry_t *ce)
799     {
800     char *name;
801     char *host = NULL, *vhost = NULL, *password = NULL;
802     unsigned int port = 0;
803    
804 pippijn 1.5 if (ce->vardata<char *> () == NULL)
805     return param_error<config::no_param> (ce);
806 pippijn 1.1
807 pippijn 1.5 if (me.name != NULL && !irccasecmp (ce->vardata<char *> (), me.name))
808     slog (LG_ERROR, "%s:%d: uplink's server name %s should not be the same as our server name, continuing anyway", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
809     else if (!strchr (ce->vardata<char *> (), '.'))
810     slog (LG_ERROR, "%s:%d: uplink's server name %s is invalid, continuing anyway", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
811     else if (isdigit (ce->vardata<char *> ()[0]))
812     slog (LG_ERROR, "%s:%d: uplink's server name %s starts with a digit, probably invalid (continuing anyway)", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
813 pippijn 1.1
814 pippijn 1.5 name = sstrdup (ce->vardata<char *> ());
815 pippijn 1.1
816     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
817     {
818     if (!strcasecmp ("HOST", ce->ce_varname))
819 pippijn 1.4 {
820 pippijn 1.5 if (ce->vardata<char *> () == NULL)
821     return param_error<config::no_param> (ce);
822 pippijn 1.1
823 pippijn 1.5 host = sstrdup (ce->vardata<char *> ());
824 pippijn 1.4 }
825 pippijn 1.1 else if (!strcasecmp ("VHOST", ce->ce_varname))
826 pippijn 1.4 {
827 pippijn 1.5 if (ce->vardata<char *> () == NULL)
828     return param_error<config::no_param> (ce);
829 pippijn 1.1
830 pippijn 1.5 vhost = sstrdup (ce->vardata<char *> ());
831 pippijn 1.4 }
832 pippijn 1.1 else if (!strcasecmp ("PASSWORD", ce->ce_varname))
833 pippijn 1.4 {
834 pippijn 1.5 if (ce->vardata<char *> () == NULL)
835     return param_error<config::no_param> (ce);
836 pippijn 1.1
837 pippijn 1.5 password = sstrdup (ce->vardata<char *> ());
838 pippijn 1.4 }
839 pippijn 1.1 else if (!strcasecmp ("PORT", ce->ce_varname))
840 pippijn 1.4 {
841 pippijn 1.5 if (ce->vardata<char *> () == NULL)
842     return param_error<config::no_param> (ce);
843 pippijn 1.1
844 pippijn 1.5 port = ce->vardata<int> ();
845 pippijn 1.4 }
846 pippijn 1.1 else
847 pippijn 1.4 {
848     slog (LG_ERROR, "%s:%d: Invalid configuration option uplink::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
849     continue;
850     }
851 pippijn 1.1 }
852    
853     uplink_add (name, host, password, vhost, port);
854    
855 pippijn 1.4 sfree (name);
856     sfree (host);
857     sfree (password);
858     sfree (vhost);
859 pippijn 1.1
860     return 0;
861     }
862    
863     static int
864     c_operclass (config_entry_t *ce)
865     {
866     operclass_t *operclass;
867     char *name;
868     char *privs = NULL, *newprivs;
869     int flags = 0;
870    
871 pippijn 1.5 if (ce->vardata<char *> () == NULL)
872     return param_error<config::no_param> (ce);
873 pippijn 1.1
874 pippijn 1.5 name = ce->vardata<char *> ();
875 pippijn 1.1
876     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
877     {
878     if (!strcasecmp ("PRIVS", ce->ce_varname))
879 pippijn 1.4 {
880 pippijn 1.5 if (ce->vardata<char *> () == NULL && ce->ce_entries == NULL)
881     return param_error<config::no_param> (ce);
882 pippijn 1.4
883     if (ce->ce_entries == NULL)
884     {
885     if (privs == NULL)
886 pippijn 1.5 privs = sstrdup (ce->vardata<char *> ());
887 pippijn 1.4 else
888     {
889 pippijn 1.5 newprivs = alloc<char> (strlen (privs) + 1 + strlen (ce->vardata<char *> ()) + 1);
890 pippijn 1.4 strcpy (newprivs, privs);
891     strcat (newprivs, " ");
892 pippijn 1.5 strcat (newprivs, ce->vardata<char *> ());
893 pippijn 1.4 sfree (privs);
894     privs = newprivs;
895     }
896     }
897     else
898     {
899     config_entry_t *conf_p;
900     /*
901     * New definition format for operclasses.
902     *
903     * operclass "sra" {
904     * privs = {
905     * special:ircop;
906     * };
907     * };
908     *
909     * - nenolod
910     */
911     for (conf_p = ce->ce_entries; conf_p; conf_p = conf_p->ce_next)
912     {
913     if (privs == NULL)
914     privs = sstrdup (conf_p->ce_varname);
915     else
916     {
917     newprivs = alloc<char> (strlen (privs) + 1 + strlen (conf_p->ce_varname) + 1);
918     strcpy (newprivs, privs);
919     strcat (newprivs, " ");
920     strcat (newprivs, conf_p->ce_varname);
921     sfree (privs);
922     privs = newprivs;
923     }
924     }
925     }
926     }
927 pippijn 1.1 else if (!strcasecmp ("NEEDOPER", ce->ce_varname))
928 pippijn 1.4 flags |= OPERCLASS_NEEDOPER;
929 pippijn 1.1 else
930 pippijn 1.4 {
931     slog (LG_ERROR, "%s:%d: Invalid configuration option operclass::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
932     continue;
933     }
934 pippijn 1.1 }
935    
936     operclass = operclass_add (name, privs ? privs : "");
937     if (operclass != NULL)
938     operclass->flags |= flags;
939 pippijn 1.4 sfree (privs);
940 pippijn 1.1 return 0;
941     }
942    
943     static int
944     c_operator (config_entry_t *ce)
945     {
946     char *name;
947     operclass_t *operclass = NULL;
948     config_entry_t *topce;
949    
950 pippijn 1.5 if (ce->vardata<char *> () == NULL)
951     return param_error<config::no_param> (ce);
952 pippijn 1.1
953     topce = ce;
954 pippijn 1.5 name = ce->vardata<char *> ();
955 pippijn 1.1
956     for (ce = ce->ce_entries; ce; ce = ce->ce_next)
957     {
958     if (!strcasecmp ("OPERCLASS", ce->ce_varname))
959 pippijn 1.4 {
960 pippijn 1.5 if (ce->vardata<char *> () == NULL)
961     return param_error<config::no_param> (ce);
962 pippijn 1.4
963 pippijn 1.5 operclass = operclass_find (ce->vardata<char *> ());
964 pippijn 1.4 if (operclass == NULL)
965 pippijn 1.5 slog (LG_ERROR, "%s:%d: invalid operclass %s for operator %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> (), name);
966 pippijn 1.4 }
967 pippijn 1.1 else
968 pippijn 1.4 {
969     slog (LG_ERROR, "%s:%d: Invalid configuration option operator::%s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_varname);
970     continue;
971     }
972 pippijn 1.1 }
973    
974     if (operclass != NULL)
975     soper_add (name, operclass->name, SOPER_CONF);
976     else
977     slog (LG_ERROR, "%s:%d: skipping operator %s because of bad/missing parameters", topce->ce_fileptr->cf_filename, topce->ce_varlinenum, name);
978     return 0;
979     }
980    
981     static int
982     c_general (config_entry_t *ce)
983     {
984 pippijn 1.4 return subblock_handler (ce, &conf_gi_table);
985 pippijn 1.1 }
986    
987     static int
988     c_si_name (config_entry_t *ce)
989     {
990 pippijn 1.5 if (ce->vardata<char *> () == NULL)
991     return param_error<config::no_param> (ce);
992 pippijn 1.1
993     if (!(runflags & RF_REHASHING))
994 pippijn 1.5 me.name = sstrdup (ce->vardata<char *> ());
995 pippijn 1.1
996     return 0;
997     }
998    
999     static int
1000     c_si_desc (config_entry_t *ce)
1001     {
1002 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1003     return param_error<config::no_param> (ce);
1004 pippijn 1.1
1005     if (me.desc != NULL)
1006 pippijn 1.4 sfree (me.desc);
1007 pippijn 1.5 me.desc = sstrdup (ce->vardata<char *> ());
1008 pippijn 1.1
1009     return 0;
1010     }
1011    
1012     static int
1013     c_si_numeric (config_entry_t *ce)
1014     {
1015 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1016     return param_error<config::no_param> (ce);
1017 pippijn 1.1
1018     if (!(runflags & RF_REHASHING))
1019 pippijn 1.5 me.numeric = sstrdup (ce->vardata<char *> ());
1020 pippijn 1.1
1021     return 0;
1022     }
1023    
1024     static int
1025     c_si_mdlimit (config_entry_t *ce)
1026     {
1027 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1028     return param_error<config::no_param> (ce);
1029 pippijn 1.1
1030 pippijn 1.5 me.mdlimit = ce->vardata<int> ();
1031 pippijn 1.1
1032     return 0;
1033     }
1034    
1035     static int
1036     c_si_vhost (config_entry_t *ce)
1037     {
1038 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1039     return param_error<config::no_param> (ce);
1040 pippijn 1.1
1041 pippijn 1.5 me.vhost = sstrdup (ce->vardata<char *> ());
1042 pippijn 1.1
1043     return 0;
1044     }
1045    
1046     static int
1047     c_si_recontime (config_entry_t *ce)
1048     {
1049 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1050     return param_error<config::no_param> (ce);
1051 pippijn 1.1
1052 pippijn 1.5 me.recontime = ce->vardata<int> ();
1053 pippijn 1.1
1054     return 0;
1055     }
1056    
1057     static int
1058     c_si_restarttime (config_entry_t *ce)
1059     {
1060 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1061     return param_error<config::no_param> (ce);
1062 pippijn 1.1
1063 pippijn 1.5 me.restarttime = ce->vardata<int> ();
1064 pippijn 1.1
1065     return 0;
1066     }
1067    
1068     static int
1069     c_si_netname (config_entry_t *ce)
1070     {
1071 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1072     return param_error<config::no_param> (ce);
1073 pippijn 1.1
1074 pippijn 1.5 me.netname = sstrdup (ce->vardata<char *> ());
1075 pippijn 1.1
1076     return 0;
1077     }
1078    
1079     static int
1080     c_si_hidehostsuffix (config_entry_t *ce)
1081     {
1082 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1083     return param_error<config::no_param> (ce);
1084 pippijn 1.1
1085 pippijn 1.5 me.hidehostsuffix = sstrdup (ce->vardata<char *> ());
1086 pippijn 1.1
1087     return 0;
1088     }
1089    
1090     static int
1091     c_si_adminname (config_entry_t *ce)
1092     {
1093 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1094     return param_error<config::no_param> (ce);
1095 pippijn 1.1
1096 pippijn 1.5 me.adminname = sstrdup (ce->vardata<char *> ());
1097 pippijn 1.1
1098     return 0;
1099     }
1100    
1101     static int
1102     c_si_adminemail (config_entry_t *ce)
1103     {
1104 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1105     return param_error<config::no_param> (ce);
1106 pippijn 1.1
1107 pippijn 1.5 me.adminemail = sstrdup (ce->vardata<char *> ());
1108 pippijn 1.1
1109     return 0;
1110     }
1111    
1112     static int
1113     c_si_mta (config_entry_t *ce)
1114     {
1115 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1116     return param_error<config::no_param> (ce);
1117 pippijn 1.1
1118 pippijn 1.5 me.mta = sstrdup (ce->vardata<char *> ());
1119 pippijn 1.1
1120     return 0;
1121     }
1122    
1123     static int
1124     c_si_loglevel (config_entry_t *ce)
1125     {
1126     config_entry_t *flce;
1127     int val;
1128     int mask = 0;
1129    
1130 pippijn 1.5 if (ce->vardata<char *> () != NULL)
1131 pippijn 1.1 {
1132 pippijn 1.5 val = token_to_value (logflags, ce->vardata<char *> ());
1133 pippijn 1.1
1134     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1135 pippijn 1.4 mask |= val;
1136 pippijn 1.1 else
1137 pippijn 1.4 {
1138 pippijn 1.5 slog (LG_INFO, "%s:%d: unknown flag: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ());
1139 pippijn 1.4 }
1140 pippijn 1.1 }
1141     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1142     {
1143     val = token_to_value (logflags, flce->ce_varname);
1144    
1145     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1146 pippijn 1.4 mask |= val;
1147 pippijn 1.1 else
1148 pippijn 1.4 {
1149     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1150     }
1151 pippijn 1.1 }
1152     log_master_set_mask (mask);
1153    
1154     return 0;
1155     }
1156    
1157     static int
1158     c_si_maxlogins (config_entry_t *ce)
1159     {
1160 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1161     return param_error<config::no_param> (ce);
1162 pippijn 1.1
1163 pippijn 1.5 me.maxlogins = ce->vardata<int> ();
1164 pippijn 1.1
1165     return 0;
1166    
1167     }
1168    
1169     static int
1170     c_si_maxusers (config_entry_t *ce)
1171     {
1172 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1173     return param_error<config::no_param> (ce);
1174 pippijn 1.1
1175 pippijn 1.5 me.maxusers = ce->vardata<int> ();
1176 pippijn 1.1
1177     return 0;
1178    
1179     }
1180    
1181     static int
1182     c_si_maxnicks (config_entry_t *ce)
1183     {
1184 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1185     return param_error<config::no_param> (ce);
1186 pippijn 1.1
1187 pippijn 1.5 me.maxnicks = ce->vardata<int> ();
1188 pippijn 1.1
1189     return 0;
1190     }
1191    
1192     static int
1193     c_si_maxchans (config_entry_t *ce)
1194     {
1195 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1196     return param_error<config::no_param> (ce);
1197 pippijn 1.1
1198 pippijn 1.5 me.maxchans = ce->vardata<int> ();
1199 pippijn 1.1
1200     return 0;
1201     }
1202    
1203     static int
1204     c_si_emaillimit (config_entry_t *ce)
1205     {
1206 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1207     return param_error<config::no_param> (ce);
1208 pippijn 1.1
1209 pippijn 1.5 me.emaillimit = ce->vardata<int> ();
1210 pippijn 1.1
1211     return 0;
1212     }
1213    
1214     static int
1215     c_si_emailtime (config_entry_t *ce)
1216     {
1217 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1218     return param_error<config::no_param> (ce);
1219 pippijn 1.1
1220 pippijn 1.5 me.emailtime = ce->vardata<int> ();
1221 pippijn 1.1
1222     return 0;
1223     }
1224    
1225     static int
1226     c_si_auth (config_entry_t *ce)
1227     {
1228 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1229     return param_error<config::no_param> (ce);
1230 pippijn 1.1
1231 pippijn 1.5 if (!strcasecmp ("EMAIL", ce->vardata<char *> ()))
1232 pippijn 1.1 me.auth = AUTH_EMAIL;
1233    
1234     else
1235     me.auth = AUTH_NONE;
1236    
1237     return 0;
1238     }
1239    
1240     static int
1241     c_si_casemapping (config_entry_t *ce)
1242     {
1243 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1244     return param_error<config::no_param> (ce);
1245 pippijn 1.1
1246 pippijn 1.5 if (!strcasecmp ("ASCII", ce->vardata<char *> ()))
1247 pippijn 1.1 set_match_mapping (MATCH_ASCII);
1248    
1249     else
1250     set_match_mapping (MATCH_RFC1459);
1251    
1252     return 0;
1253     }
1254    
1255     static int
1256     c_ci_nick (config_entry_t *ce)
1257     {
1258 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1259     return param_error<config::no_param> (ce);
1260 pippijn 1.1
1261     if (chansvs.nick != NULL)
1262 pippijn 1.4 sfree (chansvs.nick);
1263 pippijn 1.5 chansvs.nick = sstrdup (ce->vardata<char *> ());
1264 pippijn 1.1
1265     return 0;
1266     }
1267    
1268     static int
1269     c_ci_user (config_entry_t *ce)
1270     {
1271 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1272     return param_error<config::no_param> (ce);
1273 pippijn 1.1
1274     if (chansvs.user != NULL)
1275 pippijn 1.4 sfree (chansvs.user);
1276 pippijn 1.5 chansvs.user = sstrdup (ce->vardata<char *> ());
1277 pippijn 1.1
1278     return 0;
1279     }
1280    
1281     static int
1282     c_ci_host (config_entry_t *ce)
1283     {
1284 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1285     return param_error<config::no_param> (ce);
1286 pippijn 1.1
1287     if (chansvs.host != NULL)
1288 pippijn 1.4 sfree (chansvs.host);
1289 pippijn 1.5 chansvs.host = sstrdup (ce->vardata<char *> ());
1290 pippijn 1.1
1291     return 0;
1292     }
1293    
1294     static int
1295     c_ci_real (config_entry_t *ce)
1296     {
1297 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1298     return param_error<config::no_param> (ce);
1299 pippijn 1.1
1300     if (chansvs.real != NULL)
1301 pippijn 1.4 sfree (chansvs.real);
1302 pippijn 1.5 chansvs.real = sstrdup (ce->vardata<char *> ());
1303 pippijn 1.1
1304     return 0;
1305     }
1306    
1307     static int
1308     c_ci_fantasy (config_entry_t *ce)
1309     {
1310     chansvs.fantasy = true;
1311    
1312     if (chansvs.me != NULL)
1313     fcmd_agent = chansvs.me;
1314    
1315     return 0;
1316     }
1317    
1318     static int
1319     c_ci_vop (config_entry_t *ce)
1320     {
1321 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1322     return param_error<config::no_param> (ce);
1323 pippijn 1.1
1324 pippijn 1.5 chansvs.ca_vop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1325 pippijn 1.1
1326     return 0;
1327     }
1328    
1329     static int
1330     c_ci_hop (config_entry_t *ce)
1331     {
1332 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1333     return param_error<config::no_param> (ce);
1334 pippijn 1.1
1335 pippijn 1.5 chansvs.ca_hop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1336 pippijn 1.1
1337     return 0;
1338     }
1339    
1340     static int
1341     c_ci_aop (config_entry_t *ce)
1342     {
1343 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1344     return param_error<config::no_param> (ce);
1345 pippijn 1.1
1346 pippijn 1.5 chansvs.ca_aop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1347 pippijn 1.1
1348     return 0;
1349     }
1350    
1351     static int
1352     c_ci_sop (config_entry_t *ce)
1353     {
1354 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1355     return param_error<config::no_param> (ce);
1356 pippijn 1.1
1357 pippijn 1.5 chansvs.ca_sop = flags_to_bitmask (ce->vardata<char *> (), chanacs_flags, 0);
1358 pippijn 1.1
1359     return 0;
1360     }
1361    
1362     static int
1363     c_ci_changets (config_entry_t *ce)
1364     {
1365     chansvs.changets = true;
1366     return 0;
1367     }
1368    
1369     static int
1370     c_ci_trigger (config_entry_t *ce)
1371     {
1372 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1373     return param_error<config::no_param> (ce);
1374 pippijn 1.1
1375     if (chansvs.trigger != NULL)
1376 pippijn 1.4 sfree (chansvs.trigger);
1377 pippijn 1.5 chansvs.trigger = sstrdup (ce->vardata<char *> ());
1378 pippijn 1.1
1379     return 0;
1380     }
1381    
1382     static int
1383     c_ci_expire (config_entry_t *ce)
1384     {
1385 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1386     return param_error<config::no_param> (ce);
1387 pippijn 1.1
1388 pippijn 1.5 chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1389 pippijn 1.1
1390     return 0;
1391     }
1392    
1393     static int
1394     c_ci_maxchanacs (config_entry_t *ce)
1395     {
1396 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1397     return param_error<config::no_param> (ce);
1398 pippijn 1.1
1399 pippijn 1.5 chansvs.maxchanacs = ce->vardata<int> ();
1400 pippijn 1.1
1401     return 0;
1402     }
1403    
1404     static int
1405 pippijn 1.4 c_ci_maxfounders (config_entry_t *ce)
1406     {
1407 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1408     return param_error<config::no_param> (ce);
1409 pippijn 1.4
1410 pippijn 1.5 chansvs.maxfounders = ce->vardata<int> ();
1411 pippijn 1.4
1412     return 0;
1413     }
1414    
1415     static int
1416 pippijn 1.1 c_gi_chan (config_entry_t *ce)
1417     {
1418 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1419     return param_error<config::no_param> (ce);
1420 pippijn 1.1
1421 pippijn 1.5 config_options.chan = sstrdup (ce->vardata<char *> ());
1422 pippijn 1.1
1423     return 0;
1424     }
1425    
1426     static int
1427     c_gi_silent (config_entry_t *ce)
1428     {
1429     config_options.silent = true;
1430     return 0;
1431     }
1432    
1433     static int
1434     c_gi_verbose_wallops (config_entry_t *ce)
1435     {
1436     config_options.verbose_wallops = true;
1437     return 0;
1438     }
1439    
1440     static int
1441     c_gi_use_privmsg (config_entry_t *ce)
1442     {
1443     config_options.use_privmsg = true;
1444     return 0;
1445     }
1446    
1447     static int
1448     c_gi_secure (config_entry_t *ce)
1449     {
1450     config_options.secure = true;
1451     return 0;
1452     }
1453    
1454     static int
1455     c_gi_join_chans (config_entry_t *ce)
1456     {
1457     config_options.join_chans = true;
1458     return 0;
1459     }
1460    
1461     static int
1462     c_gi_leave_chans (config_entry_t *ce)
1463     {
1464     config_options.leave_chans = true;
1465     return 0;
1466     }
1467    
1468     static int
1469     c_gi_uflags (config_entry_t *ce)
1470     {
1471     config_entry_t *flce;
1472    
1473     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1474     {
1475     int val;
1476    
1477     val = token_to_value (uflags, flce->ce_varname);
1478    
1479     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1480 pippijn 1.4 config_options.defuflags |= val;
1481 pippijn 1.1
1482     else
1483 pippijn 1.4 {
1484     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1485     }
1486 pippijn 1.1 }
1487    
1488     return 0;
1489     }
1490    
1491     static int
1492     c_gi_cflags (config_entry_t *ce)
1493     {
1494     config_entry_t *flce;
1495    
1496     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
1497     {
1498     int val;
1499    
1500     val = token_to_value (cflags, flce->ce_varname);
1501    
1502     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
1503 pippijn 1.4 config_options.defcflags |= val;
1504 pippijn 1.1
1505     else
1506 pippijn 1.4 {
1507     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
1508     }
1509 pippijn 1.1 }
1510    
1511     if (config_options.defcflags & MC_TOPICLOCK)
1512     config_options.defcflags |= MC_KEEPTOPIC;
1513    
1514     return 0;
1515     }
1516    
1517     static int
1518     c_gi_raw (config_entry_t *ce)
1519     {
1520     config_options.raw = true;
1521     return 0;
1522     }
1523    
1524     static int
1525     c_gi_flood_msgs (config_entry_t *ce)
1526     {
1527 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1528     return param_error<config::no_param> (ce);
1529 pippijn 1.1
1530 pippijn 1.5 config_options.flood_msgs = ce->vardata<int> ();
1531 pippijn 1.1
1532     return 0;
1533     }
1534    
1535     static int
1536     c_gi_flood_time (config_entry_t *ce)
1537     {
1538 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1539     return param_error<config::no_param> (ce);
1540 pippijn 1.1
1541 pippijn 1.5 config_options.flood_time = ce->vardata<int> ();
1542 pippijn 1.1
1543     return 0;
1544     }
1545    
1546     static int
1547     c_gi_kline_time (config_entry_t *ce)
1548     {
1549 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1550     return param_error<config::no_param> (ce);
1551 pippijn 1.1
1552 pippijn 1.5 config_options.kline_time = (ce->vardata<int> () * 60 * 60 * 24);
1553 pippijn 1.1
1554     return 0;
1555     }
1556    
1557     static int
1558     c_gi_commit_interval (config_entry_t *ce)
1559     {
1560 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1561     return param_error<config::no_param> (ce);
1562 pippijn 1.1
1563 pippijn 1.5 config_options.commit_interval = (ce->vardata<int> () * 60);
1564 pippijn 1.1
1565     return 0;
1566     }
1567    
1568     static int
1569     c_gi_expire (config_entry_t *ce)
1570     {
1571 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1572     return param_error<config::no_param> (ce);
1573 pippijn 1.1
1574     slog (LG_INFO, "warning: general::expire has been deprecated. please use nickserv::expire and chanserv::expire respectively.");
1575    
1576 pippijn 1.5 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1577     chansvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1578 pippijn 1.1
1579     return 0;
1580     }
1581    
1582     static int
1583 pippijn 1.4 c_gi_default_clone_limit (config_entry_t *ce)
1584     {
1585 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1586     return param_error<config::no_param> (ce);
1587 pippijn 1.4
1588 pippijn 1.5 config_options.default_clone_limit = ce->vardata<int> ();
1589 pippijn 1.4
1590     return 0;
1591     }
1592    
1593     static int
1594 pippijn 1.1 c_oi_nick (config_entry_t *ce)
1595     {
1596 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1597     return param_error<config::no_param> (ce);
1598 pippijn 1.1
1599     if (opersvs.nick != NULL)
1600 pippijn 1.4 sfree (opersvs.nick);
1601 pippijn 1.5 opersvs.nick = sstrdup (ce->vardata<char *> ());
1602 pippijn 1.1
1603     return 0;
1604     }
1605    
1606     static int
1607     c_oi_user (config_entry_t *ce)
1608     {
1609 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1610     return param_error<config::no_param> (ce);
1611 pippijn 1.1
1612     if (opersvs.user != NULL)
1613 pippijn 1.4 sfree (opersvs.user);
1614 pippijn 1.5 opersvs.user = sstrdup (ce->vardata<char *> ());
1615 pippijn 1.1
1616     return 0;
1617     }
1618    
1619     static int
1620     c_oi_host (config_entry_t *ce)
1621     {
1622 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1623     return param_error<config::no_param> (ce);
1624 pippijn 1.1
1625     if (opersvs.host != NULL)
1626 pippijn 1.4 sfree (opersvs.host);
1627 pippijn 1.5 opersvs.host = sstrdup (ce->vardata<char *> ());
1628 pippijn 1.1
1629     return 0;
1630     }
1631    
1632     static int
1633     c_oi_real (config_entry_t *ce)
1634     {
1635 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1636     return param_error<config::no_param> (ce);
1637 pippijn 1.1
1638     if (opersvs.real != NULL)
1639 pippijn 1.4 sfree (opersvs.real);
1640 pippijn 1.5 opersvs.real = sstrdup (ce->vardata<char *> ());
1641 pippijn 1.1
1642     return 0;
1643     }
1644    
1645     static int
1646     c_ni_nick (config_entry_t *ce)
1647     {
1648 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1649     return param_error<config::no_param> (ce);
1650 pippijn 1.1
1651     if (nicksvs.nick != NULL)
1652 pippijn 1.4 sfree (nicksvs.nick);
1653 pippijn 1.5 nicksvs.nick = sstrdup (ce->vardata<char *> ());
1654 pippijn 1.1
1655     return 0;
1656     }
1657    
1658     static int
1659     c_ni_user (config_entry_t *ce)
1660     {
1661 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1662     return param_error<config::no_param> (ce);
1663 pippijn 1.1
1664     if (nicksvs.user != NULL)
1665 pippijn 1.4 sfree (nicksvs.user);
1666 pippijn 1.5 nicksvs.user = sstrdup (ce->vardata<char *> ());
1667 pippijn 1.1
1668     return 0;
1669     }
1670    
1671     static int
1672     c_ni_host (config_entry_t *ce)
1673     {
1674 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1675     return param_error<config::no_param> (ce);
1676 pippijn 1.1
1677     if (nicksvs.host != NULL)
1678 pippijn 1.4 sfree (nicksvs.host);
1679 pippijn 1.5 nicksvs.host = sstrdup (ce->vardata<char *> ());
1680 pippijn 1.1
1681     return 0;
1682     }
1683    
1684     static int
1685     c_ni_real (config_entry_t *ce)
1686     {
1687 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1688     return param_error<config::no_param> (ce);
1689 pippijn 1.1
1690     if (nicksvs.real != NULL)
1691 pippijn 1.4 sfree (nicksvs.real);
1692 pippijn 1.5 nicksvs.real = sstrdup (ce->vardata<char *> ());
1693 pippijn 1.1
1694     return 0;
1695     }
1696    
1697     static int
1698     c_ni_spam (config_entry_t *ce)
1699     {
1700     nicksvs.spam = true;
1701     return 0;
1702     }
1703    
1704     static int
1705     c_ni_no_nick_ownership (config_entry_t *ce)
1706     {
1707     nicksvs.no_nick_ownership = true;
1708     return 0;
1709     }
1710    
1711     static int
1712     c_ni_expire (config_entry_t *ce)
1713     {
1714 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1715     return param_error<config::no_param> (ce);
1716 pippijn 1.1
1717 pippijn 1.5 nicksvs.expiry = (ce->vardata<int> () * 60 * 60 * 24);
1718 pippijn 1.1
1719     return 0;
1720     }
1721    
1722     static int
1723     c_ss_nick (config_entry_t *ce)
1724     {
1725 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1726     return param_error<config::no_param> (ce);
1727 pippijn 1.1
1728     if (saslsvs.nick != NULL)
1729 pippijn 1.4 sfree (saslsvs.nick);
1730 pippijn 1.5 saslsvs.nick = sstrdup (ce->vardata<char *> ());
1731 pippijn 1.1
1732     return 0;
1733     }
1734    
1735     static int
1736     c_ss_user (config_entry_t *ce)
1737     {
1738 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1739     return param_error<config::no_param> (ce);
1740 pippijn 1.1
1741     if (saslsvs.user != NULL)
1742 pippijn 1.4 sfree (saslsvs.user);
1743 pippijn 1.5 saslsvs.user = sstrdup (ce->vardata<char *> ());
1744 pippijn 1.1
1745     return 0;
1746     }
1747    
1748     static int
1749     c_ss_host (config_entry_t *ce)
1750     {
1751 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1752     return param_error<config::no_param> (ce);
1753 pippijn 1.1
1754     if (saslsvs.host != NULL)
1755 pippijn 1.4 sfree (saslsvs.host);
1756 pippijn 1.5 saslsvs.host = sstrdup (ce->vardata<char *> ());
1757 pippijn 1.1
1758     return 0;
1759     }
1760    
1761     static int
1762     c_ss_real (config_entry_t *ce)
1763     {
1764 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1765     return param_error<config::no_param> (ce);
1766 pippijn 1.1
1767     if (saslsvs.real != NULL)
1768 pippijn 1.4 sfree (saslsvs.real);
1769 pippijn 1.5 saslsvs.real = sstrdup (ce->vardata<char *> ());
1770 pippijn 1.1
1771     return 0;
1772     }
1773    
1774     static int
1775     c_ms_nick (config_entry_t *ce)
1776     {
1777 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1778     return param_error<config::no_param> (ce);
1779 pippijn 1.1
1780     if (memosvs.nick != NULL)
1781 pippijn 1.4 sfree (memosvs.nick);
1782 pippijn 1.5 memosvs.nick = sstrdup (ce->vardata<char *> ());
1783 pippijn 1.1
1784     return 0;
1785     }
1786    
1787     static int
1788     c_ms_user (config_entry_t *ce)
1789     {
1790 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1791     return param_error<config::no_param> (ce);
1792 pippijn 1.1
1793     if (memosvs.user != NULL)
1794 pippijn 1.4 sfree (memosvs.user);
1795 pippijn 1.5 memosvs.user = sstrdup (ce->vardata<char *> ());
1796 pippijn 1.1
1797     return 0;
1798     }
1799    
1800     static int
1801     c_ms_host (config_entry_t *ce)
1802     {
1803 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1804     return param_error<config::no_param> (ce);
1805 pippijn 1.1
1806     if (memosvs.host != NULL)
1807 pippijn 1.4 sfree (memosvs.host);
1808 pippijn 1.5 memosvs.host = sstrdup (ce->vardata<char *> ());
1809 pippijn 1.1
1810     return 0;
1811     }
1812    
1813     static int
1814     c_ms_real (config_entry_t *ce)
1815     {
1816 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1817     return param_error<config::no_param> (ce);
1818 pippijn 1.1
1819     if (memosvs.real != NULL)
1820 pippijn 1.4 sfree (memosvs.real);
1821 pippijn 1.5 memosvs.real = sstrdup (ce->vardata<char *> ());
1822 pippijn 1.1
1823     return 0;
1824     }
1825    
1826     static int
1827     c_gs_nick (config_entry_t *ce)
1828     {
1829 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1830     return param_error<config::no_param> (ce);
1831 pippijn 1.1
1832     if (gamesvs.nick != NULL)
1833 pippijn 1.4 sfree (gamesvs.nick);
1834 pippijn 1.5 gamesvs.nick = sstrdup (ce->vardata<char *> ());
1835 pippijn 1.1
1836     return 0;
1837     }
1838    
1839     static int
1840     c_gs_user (config_entry_t *ce)
1841     {
1842 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1843     return param_error<config::no_param> (ce);
1844 pippijn 1.1
1845     if (gamesvs.user != NULL)
1846 pippijn 1.4 sfree (gamesvs.user);
1847 pippijn 1.5 gamesvs.user = sstrdup (ce->vardata<char *> ());
1848 pippijn 1.1
1849     return 0;
1850     }
1851    
1852     static int
1853     c_gs_host (config_entry_t *ce)
1854     {
1855 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1856     return param_error<config::no_param> (ce);
1857 pippijn 1.1
1858     if (gamesvs.host != NULL)
1859 pippijn 1.4 sfree (gamesvs.host);
1860 pippijn 1.5 gamesvs.host = sstrdup (ce->vardata<char *> ());
1861 pippijn 1.1
1862     return 0;
1863     }
1864    
1865     static int
1866     c_gs_real (config_entry_t *ce)
1867     {
1868 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1869     return param_error<config::no_param> (ce);
1870 pippijn 1.1
1871     if (gamesvs.real != NULL)
1872 pippijn 1.4 sfree (gamesvs.real);
1873 pippijn 1.5 gamesvs.real = sstrdup (ce->vardata<char *> ());
1874 pippijn 1.1
1875     return 0;
1876     }
1877    
1878     static int
1879     c_gl_nick (config_entry_t *ce)
1880     {
1881 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1882     return param_error<config::no_param> (ce);
1883 pippijn 1.1
1884     if (globsvs.nick != NULL)
1885 pippijn 1.4 sfree (globsvs.nick);
1886 pippijn 1.5 globsvs.nick = sstrdup (ce->vardata<char *> ());
1887 pippijn 1.1
1888     return 0;
1889     }
1890    
1891     static int
1892     c_gl_user (config_entry_t *ce)
1893     {
1894 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1895     return param_error<config::no_param> (ce);
1896 pippijn 1.1
1897     if (globsvs.user != NULL)
1898 pippijn 1.4 sfree (globsvs.user);
1899 pippijn 1.5 globsvs.user = sstrdup (ce->vardata<char *> ());
1900 pippijn 1.1
1901     return 0;
1902     }
1903    
1904     static int
1905     c_gl_host (config_entry_t *ce)
1906     {
1907 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1908     return param_error<config::no_param> (ce);
1909 pippijn 1.1
1910     if (globsvs.host != NULL)
1911 pippijn 1.4 sfree (globsvs.host);
1912 pippijn 1.5 globsvs.host = sstrdup (ce->vardata<char *> ());
1913 pippijn 1.1
1914     return 0;
1915     }
1916    
1917     static int
1918     c_gl_real (config_entry_t *ce)
1919     {
1920 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1921     return param_error<config::no_param> (ce);
1922 pippijn 1.1
1923     if (globsvs.real != NULL)
1924 pippijn 1.4 sfree (globsvs.real);
1925 pippijn 1.5 globsvs.real = sstrdup (ce->vardata<char *> ());
1926 pippijn 1.1
1927     return 0;
1928     }
1929    
1930     static int
1931     c_db_user (config_entry_t *ce)
1932     {
1933 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1934     return param_error<config::no_param> (ce);
1935 pippijn 1.1
1936     if (database_options.user != NULL)
1937 pippijn 1.4 sfree (database_options.user);
1938 pippijn 1.5 database_options.user = sstrdup (ce->vardata<char *> ());
1939 pippijn 1.1
1940     return 0;
1941     }
1942    
1943     static int
1944     c_db_host (config_entry_t *ce)
1945     {
1946 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1947     return param_error<config::no_param> (ce);
1948 pippijn 1.1
1949     if (database_options.host != NULL)
1950 pippijn 1.4 sfree (database_options.host);
1951 pippijn 1.5 database_options.host = sstrdup (ce->vardata<char *> ());
1952 pippijn 1.1
1953     return 0;
1954     }
1955    
1956     static int
1957     c_db_password (config_entry_t *ce)
1958     {
1959 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1960     return param_error<config::no_param> (ce);
1961 pippijn 1.1
1962     if (database_options.pass != NULL)
1963 pippijn 1.4 sfree (database_options.pass);
1964 pippijn 1.5 database_options.pass = sstrdup (ce->vardata<char *> ());
1965 pippijn 1.1
1966     return 0;
1967     }
1968    
1969     static int
1970     c_db_database (config_entry_t *ce)
1971     {
1972 pippijn 1.5 if (ce->vardata<char *> () == NULL)
1973     return param_error<config::no_param> (ce);
1974 pippijn 1.1
1975     if (database_options.database != NULL)
1976 pippijn 1.4 sfree (database_options.database);
1977 pippijn 1.5 database_options.database = sstrdup (ce->vardata<char *> ());
1978 pippijn 1.1
1979     return 0;
1980     }
1981    
1982     static int
1983     c_db_port (config_entry_t *ce)
1984     {
1985 pippijn 1.5 if (ce->vardata<int> () == 0)
1986     return param_error<config::no_param> (ce);
1987 pippijn 1.1
1988 pippijn 1.5 database_options.port = ce->vardata<int> ();
1989 pippijn 1.1
1990     return 0;
1991     }
1992    
1993     static int
1994     c_logfile (config_entry_t *ce)
1995     {
1996     config_entry_t *flce;
1997     unsigned int logval = 0;
1998    
1999 pippijn 1.5 if (ce->vardata<char *> () == NULL)
2000     return param_error<config::no_param> (ce);
2001 pippijn 1.1
2002     for (flce = ce->ce_entries; flce; flce = flce->ce_next)
2003     {
2004     int val;
2005    
2006     val = token_to_value (logflags, flce->ce_varname);
2007    
2008     if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR))
2009 pippijn 1.4 logval |= val;
2010 pippijn 1.1 else
2011 pippijn 1.4 {
2012     slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname);
2013     }
2014 pippijn 1.1 }
2015    
2016 pippijn 1.5 logfile_new (ce->vardata<char *> (), logval);
2017 pippijn 1.1
2018     return 0;
2019     }
2020    
2021     bool
2022     conf_rehash (void)
2023     {
2024     me_t hold_me;
2025     char *oldsnoop;
2026     config_file_t *cfp;
2027    
2028     /* we're rehashing */
2029     slog (LG_INFO, "conf_rehash(): rehashing");
2030     runflags |= RF_REHASHING;
2031    
2032     errno = 0;
2033     cfp = config_load (config_file);
2034     if (cfp == NULL)
2035     {
2036     slog (LG_ERROR, "conf_rehash(): unable to load configuration file: %s, aborting rehash", strerror (errno));
2037     runflags &= ~RF_REHASHING;
2038     return false;
2039     }
2040    
2041     hold_me = me;
2042    
2043     oldsnoop = config_options.chan != NULL ? sstrdup (config_options.chan) : NULL;
2044    
2045     /* reset everything */
2046     conf_init ();
2047     mark_all_illegal ();
2048     log_shutdown ();
2049    
2050     /* now reload */
2051     log_open ();
2052     conf_process (cfp);
2053     config_free (cfp);
2054 pippijn 1.4 ConfTable::callback.ready ();
2055 pippijn 1.1
2056     /* now recheck */
2057     if (!conf_check ())
2058     {
2059     slog (LG_ERROR, "conf_rehash(): conf file was malformed, aborting rehash");
2060    
2061     /* freeing the new conf strings */
2062 pippijn 1.4 sfree (chansvs.nick);
2063     me.fini ();
2064 pippijn 1.1
2065     /* return everything to the way it was before */
2066     me = hold_me;
2067    
2068     /* not fully ok, oh well */
2069     unmark_all_illegal ();
2070    
2071 pippijn 1.4 sfree (oldsnoop);
2072 pippijn 1.1
2073     runflags &= ~RF_REHASHING;
2074     return false;
2075     }
2076    
2077     if (oldsnoop != NULL || config_options.chan != NULL)
2078     {
2079     if (config_options.chan == NULL)
2080 pippijn 1.4 partall (oldsnoop);
2081 pippijn 1.1 else if (oldsnoop == NULL)
2082 pippijn 1.4 joinall (config_options.chan);
2083 pippijn 1.1 else if (strcmp (oldsnoop, config_options.chan))
2084 pippijn 1.4 {
2085     partall (oldsnoop);
2086     joinall (config_options.chan);
2087     }
2088 pippijn 1.1 }
2089    
2090     remove_illegals ();
2091    
2092 pippijn 1.4 sfree (oldsnoop);
2093 pippijn 1.1
2094     runflags &= ~RF_REHASHING;
2095     return true;
2096     }
2097    
2098     bool
2099     conf_check (void)
2100     {
2101     if (!me.name)
2102     {
2103     slog (LG_ERROR, "conf_check(): no `name' set in %s", config_file);
2104     return false;
2105     }
2106    
2107     /* The following checks could perhaps be stricter */
2108     if (!strchr (me.name, '.') || strchr ("!\"#$%&+,-./:@", me.name[0]) || strchr (me.name, ' '))
2109     {
2110     slog (LG_ERROR, "conf_check(): bogus `name' in %s (did you specify a valid server name?)", config_file);
2111     return false;
2112     }
2113    
2114     if (isdigit (me.name[0]))
2115     slog (LG_ERROR, "conf_check(): `name' in %s starts with a digit, probably invalid (continuing anyway)", config_file);
2116    
2117     if (!me.desc)
2118     me.desc = sstrdup ("Ermyth IRC Services");
2119    
2120     if ((!me.recontime) || (me.recontime < 10))
2121     {
2122     slog (LG_INFO, "conf_check(): invalid `recontime' set in %s; " "defaulting to 10", config_file);
2123     me.recontime = 10;
2124     }
2125    
2126     if (!me.netname)
2127     {
2128     slog (LG_INFO, "conf_check(): no `netname' set in %s", config_file);
2129     return false;
2130     }
2131    
2132     if (!me.adminname)
2133     {
2134     slog (LG_INFO, "conf_check(): no `adminname' set in %s", config_file);
2135     return false;
2136     }
2137    
2138     if (!me.adminemail)
2139     {
2140     slog (LG_INFO, "conf_check(): no `adminemail' set in %s", config_file);
2141     return false;
2142     }
2143    
2144     if (!me.mta && me.auth == AUTH_EMAIL)
2145     {
2146     slog (LG_INFO, "conf_check(): no `mta' set in %s (but `auth' is email)", config_file);
2147     return false;
2148     }
2149    
2150     if (!me.maxlogins)
2151     {
2152     slog (LG_INFO, "conf_check(): no `maxlogins' set in %s; " "defaulting to 5", config_file);
2153     me.maxlogins = 5;
2154     }
2155    
2156     if (!me.maxusers)
2157     {
2158     slog (LG_INFO, "conf_check(): no `maxusers' set in %s; " "defaulting to 5", config_file);
2159     me.maxusers = 5;
2160     }
2161    
2162     if (!me.maxnicks)
2163     {
2164     if (!nicksvs.no_nick_ownership)
2165 pippijn 1.4 slog (LG_INFO, "conf_check(): no `maxnicks' set in %s; " "defaulting to 5", config_file);
2166 pippijn 1.1 me.maxnicks = 5;
2167     }
2168    
2169     if (!me.maxchans)
2170     {
2171     slog (LG_INFO, "conf_check(): no `maxchans' set in %s; " "defaulting to 5", config_file);
2172     me.maxchans = 5;
2173     }
2174    
2175     if (!me.emaillimit)
2176     {
2177     slog (LG_INFO, "conf_check(): no `emaillimit' set in %s; " "defaulting to 10", config_file);
2178     me.emaillimit = 10;
2179     }
2180    
2181     if (!me.emailtime)
2182     {
2183     slog (LG_INFO, "conf_check(): no `emailtime' set in %s; " "defaulting to 300", config_file);
2184     me.emailtime = 300;
2185     }
2186    
2187     if (me.auth != 0 && me.auth != 1)
2188     {
2189     slog (LG_INFO, "conf_check(): no `auth' set in %s; " "defaulting to NONE", config_file);
2190     me.auth = AUTH_NONE;
2191     }
2192    
2193     if (!chansvs.nick || !chansvs.user || !chansvs.host || !chansvs.real)
2194     {
2195     slog (LG_ERROR, "conf_check(): invalid chanserv{} block in %s", config_file);
2196     return false;
2197     }
2198    
2199     if ((strchr (chansvs.user, ' ')) || (strlen (chansvs.user) > 10))
2200     {
2201     slog (LG_ERROR, "conf_check(): invalid `chanserv::user' in %s", config_file);
2202     return false;
2203     }
2204    
2205     /* we know ca_all now */
2206     chansvs.ca_vop &= ca_all;
2207     chansvs.ca_hop &= ca_all;
2208     chansvs.ca_aop &= ca_all;
2209     chansvs.ca_sop &= ca_all;
2210     /* chansvs.ca_hop may be equal to chansvs.ca_vop to disable HOP */
2211     if (!chansvs.ca_vop || !chansvs.ca_hop || !chansvs.ca_aop || !chansvs.ca_sop || chansvs.ca_vop == chansvs.ca_aop || chansvs.ca_vop == chansvs.ca_sop || chansvs.ca_hop == chansvs.ca_aop || chansvs.ca_hop == chansvs.ca_sop || chansvs.ca_aop == chansvs.ca_sop)
2212     {
2213     slog (LG_INFO, "conf_check(): invalid xop levels in %s, using defaults", config_file);
2214     chansvs.ca_vop = CA_VOP_DEF & ca_all;
2215     chansvs.ca_hop = CA_HOP_DEF & ca_all;
2216     chansvs.ca_aop = CA_AOP_DEF & ca_all;
2217     chansvs.ca_sop = CA_SOP_DEF & ca_all;
2218     }
2219    
2220     if (config_options.flood_msgs && !config_options.flood_time)
2221     config_options.flood_time = 10;
2222 pippijn 1.4
2223     if (!config_options.default_clone_limit)
2224     config_options.default_clone_limit = 6;
2225    
2226 pippijn 1.1 /* recall that commit_interval is in seconds */
2227     if ((!config_options.commit_interval) || (config_options.commit_interval < 60) || (config_options.commit_interval > 3600))
2228     {
2229     slog (LG_INFO, "conf_check(): invalid `commit_interval' set in %s; " "defaulting to 5 minutes", config_file);
2230     config_options.commit_interval = 300;
2231     }
2232    
2233     return true;
2234     }