… | |
… | |
3 | * Rights to this code are documented in doc/pod/license.pod. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 | */ |
6 | */ |
7 | |
7 | |
8 | static char const rcsid[] = "$Id: conf.C,v 1.5 2007/08/28 22:18:31 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: conf.C,v 1.6 2007/08/29 21:01:18 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
11 | #include <ermyth/crypto.h> |
11 | #include <ermyth/crypto.h> |
12 | #include <ermyth/database.h> |
12 | #include <ermyth/database.h> |
13 | #include <ermyth/module.h> |
13 | #include <ermyth/module.h> |
… | |
… | |
33 | int param_error (config_entry_t *ce, char const * const msg = NULL); |
33 | int param_error (config_entry_t *ce, char const * const msg = NULL); |
34 | |
34 | |
35 | template<> |
35 | template<> |
36 | int param_error<config::no_param> (config_entry_t *ce, char const * const msg) |
36 | int param_error<config::no_param> (config_entry_t *ce, char const * const msg) |
37 | { |
37 | { |
38 | slog (LG_INFO, "%s:%i: no parameter for " |
38 | slog (LG_INFO, "%s:%i: %s: %s", |
39 | "configuration option: %s %s", |
|
|
40 | ce->ce_fileptr->cf_filename, |
39 | ce->ce_fileptr->cf_filename, |
41 | ce->ce_varlinenum, ce->ce_varname, |
40 | ce->ce_varlinenum, msg ? msg : "no parameter for option", |
42 | msg ? msg : ""); |
41 | ce->ce_varname); |
43 | return 1; |
42 | return 1; |
44 | } |
43 | } |
45 | |
44 | |
46 | template<> |
45 | template<> |
47 | int param_error<config::wrong_param> (config_entry_t *ce, char const * const msg) |
46 | int param_error<config::wrong_param> (config_entry_t *ce, char const * const msg) |
48 | { |
47 | { |
49 | slog (LG_INFO, "%s:%i: wrong parameter for " |
48 | slog (LG_INFO, "%s:%i: %s: %s", |
50 | "configuration option: %s %s", |
|
|
51 | ce->ce_fileptr->cf_filename, |
49 | ce->ce_fileptr->cf_filename, |
52 | ce->ce_varlinenum, ce->ce_varname, msg ? msg : ""); |
50 | ce->ce_varlinenum, msg ? msg : "wrong parameter for option", |
|
|
51 | ce->ce_varname); |
53 | return 1; |
52 | return 1; |
54 | } |
53 | } |
55 | |
54 | |
56 | static int c_serverinfo (config_entry_t *); |
55 | static int c_serverinfo (config_entry_t *); |
57 | static int c_general (config_entry_t *); |
56 | static int c_general (config_entry_t *); |
… | |
… | |
385 | conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname); |
384 | conf_report_error (ce, "invalid configuration option: %s", ce->ce_varname); |
386 | } |
385 | } |
387 | return 0; |
386 | return 0; |
388 | } |
387 | } |
389 | |
388 | |
390 | struct ConfTable * |
389 | ConfTable * |
391 | find_top_conf (char const * const name) |
390 | find_top_conf (char const * const name) |
392 | { |
391 | { |
393 | node_t *n; |
392 | node_t *n; |
394 | ConfTable *ct; |
393 | ConfTable *ct; |
395 | |
394 | |
… | |
… | |
402 | } |
401 | } |
403 | |
402 | |
404 | return NULL; |
403 | return NULL; |
405 | } |
404 | } |
406 | |
405 | |
407 | struct ConfTable * |
406 | ConfTable * |
408 | find_conf_item (char const * const name, list_t *conflist) |
407 | find_conf_item (char const * const name, list_t *conflist) |
409 | { |
408 | { |
410 | node_t *n; |
409 | node_t *n; |
411 | ConfTable *ct; |
410 | ConfTable *ct; |
412 | |
411 | |
… | |
… | |
492 | /* stolen from Sentinel */ |
491 | /* stolen from Sentinel */ |
493 | #define TOKEN_UNMATCHED -1 |
492 | #define TOKEN_UNMATCHED -1 |
494 | #define TOKEN_ERROR -2 |
493 | #define TOKEN_ERROR -2 |
495 | |
494 | |
496 | static int |
495 | static int |
497 | token_to_value (struct Token token_table[], char *token) |
496 | token_to_value (Token token_table[], char *token) |
498 | { |
497 | { |
499 | int i; |
498 | int i; |
500 | |
499 | |
501 | if ((token_table != NULL) && (token != NULL)) |
500 | if ((token_table != NULL) && (token != NULL)) |
502 | { |
501 | { |
503 | for (i = 0; token_table[i].text != NULL; i++) |
502 | for (i = 0; token_table[i].text != NULL; i++) |
504 | { |
|
|
505 | if (strcasecmp (token_table[i].text, token) == 0) |
503 | if (strcasecmp (token_table[i].text, token) == 0) |
506 | { |
|
|
507 | return token_table[i].value; |
504 | return token_table[i].value; |
508 | } |
|
|
509 | } |
|
|
510 | /* If no match... */ |
505 | /* If no match... */ |
511 | return TOKEN_UNMATCHED; |
506 | return TOKEN_UNMATCHED; |
512 | } |
507 | } |
513 | |
508 | |
514 | /* Otherwise... */ |
509 | /* Otherwise... */ |
515 | return TOKEN_ERROR; |
510 | return TOKEN_ERROR; |
516 | } |
511 | } |
517 | |
512 | |
518 | void |
513 | void |
519 | init_newconf (void) |
514 | init_newconf (void) |
520 | { |
515 | { |
521 | #if 0 |
516 | #if 0 |
522 | conftable_heap = BlockHeapCreate (sizeof (struct ConfTable), 32); |
517 | conftable_heap = BlockHeapCreate (sizeof (ConfTable), 32); |
523 | #endif |
518 | #endif |
524 | |
519 | |
525 | /* First we set up the blocks. */ |
520 | /* First we set up the blocks. */ |
526 | add_top_conf ("SERVERINFO", c_serverinfo); |
521 | add_top_conf ("SERVERINFO", c_serverinfo); |
527 | add_top_conf ("CHANSERV", c_chanserv); |
522 | add_top_conf ("CHANSERV", c_chanserv); |
… | |
… | |
716 | |
711 | |
717 | typedef factory::factory_mgr<protocol::handler> protocol_factory; |
712 | typedef factory::factory_mgr<protocol::handler> protocol_factory; |
718 | protocol_factory &f = protocol_factory::instance (); |
713 | protocol_factory &f = protocol_factory::instance (); |
719 | |
714 | |
720 | if (!f.provides (name)) |
715 | if (!f.provides (name)) |
721 | return param_error<config::wrong_param> (ce, "(no such protocol handler)"); |
716 | return param_error<config::wrong_param> (ce, "no such protocol handler"); |
722 | |
717 | |
723 | phandler = f.create (name); |
718 | phandler = f.create (name); |
724 | |
719 | |
725 | return 0; |
720 | return 0; |
726 | } |
721 | } |
… | |
… | |
737 | return param_error<config::no_param> (ce); |
732 | return param_error<config::no_param> (ce); |
738 | |
733 | |
739 | name = ce->vardata<char *> (); |
734 | name = ce->vardata<char *> (); |
740 | |
735 | |
741 | if (!modules::provides (name)) |
736 | if (!modules::provides (name)) |
742 | return param_error<config::wrong_param> (ce, "(no such module)"); |
737 | return param_error<config::wrong_param> (ce, "no such module"); |
743 | |
738 | |
744 | modules::enable (name); |
739 | modules::enable (name); |
745 | |
740 | |
746 | return 0; |
741 | return 0; |
747 | } |
742 | } |
… | |
… | |
761 | |
756 | |
762 | typedef factory::factory_mgr<crypto::handler> crypto_factory; |
757 | typedef factory::factory_mgr<crypto::handler> crypto_factory; |
763 | crypto_factory &f = crypto_factory::instance (); |
758 | crypto_factory &f = crypto_factory::instance (); |
764 | |
759 | |
765 | if (!f.provides (name)) |
760 | if (!f.provides (name)) |
766 | return param_error<config::wrong_param> (ce, "(no such crypto handler)"); |
761 | return param_error<config::wrong_param> (ce, "no such crypto handler"); |
767 | |
762 | |
768 | crypter = f.create (name); |
763 | crypter = f.create (name); |
769 | |
764 | |
770 | return 0; |
765 | return 0; |
771 | } |
766 | } |
… | |
… | |
785 | |
780 | |
786 | typedef factory::factory_mgr<database::handler> backend_factory; |
781 | typedef factory::factory_mgr<database::handler> backend_factory; |
787 | backend_factory &f = backend_factory::instance (); |
782 | backend_factory &f = backend_factory::instance (); |
788 | |
783 | |
789 | if (!f.provides (name)) |
784 | if (!f.provides (name)) |
790 | return param_error<config::wrong_param> (ce, "(no such database backend)"); |
785 | return param_error<config::wrong_param> (ce, "no such database backend"); |
791 | |
786 | |
792 | backend = f.create (name); |
787 | backend = f.create (name); |
793 | |
788 | |
794 | return 0; |
789 | return 0; |
795 | } |
790 | } |
… | |
… | |
1132 | val = token_to_value (logflags, ce->vardata<char *> ()); |
1127 | val = token_to_value (logflags, ce->vardata<char *> ()); |
1133 | |
1128 | |
1134 | if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR)) |
1129 | if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR)) |
1135 | mask |= val; |
1130 | mask |= val; |
1136 | else |
1131 | else |
1137 | { |
|
|
1138 | slog (LG_INFO, "%s:%d: unknown flag: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ()); |
1132 | slog (LG_INFO, "%s:%d: unknown flag: %s", ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->vardata<char *> ()); |
1139 | } |
|
|
1140 | } |
1133 | } |
1141 | for (flce = ce->ce_entries; flce; flce = flce->ce_next) |
1134 | for (flce = ce->ce_entries; flce; flce = flce->ce_next) |
1142 | { |
1135 | { |
1143 | val = token_to_value (logflags, flce->ce_varname); |
1136 | val = token_to_value (logflags, flce->ce_varname); |
1144 | |
1137 | |
1145 | if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR)) |
1138 | if ((val != TOKEN_UNMATCHED) && (val != TOKEN_ERROR)) |
1146 | mask |= val; |
1139 | mask |= val; |
1147 | else |
1140 | else |
1148 | { |
|
|
1149 | slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname); |
1141 | slog (LG_INFO, "%s:%d: unknown flag: %s", flce->ce_fileptr->cf_filename, flce->ce_varlinenum, flce->ce_varname); |
1150 | } |
|
|
1151 | } |
1142 | } |
1152 | log_master_set_mask (mask); |
1143 | log_master_set_mask (mask); |
1153 | |
1144 | |
1154 | return 0; |
1145 | return 0; |
1155 | } |
1146 | } |