[srvx-commits] CVS: services/src conf.c,1.23,1.24 conf.h,1.11,1.12 main.c,1.116,1.117 proto_bahamut.
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-10-14 19:45:43
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv21276/src Modified Files: conf.c conf.h main.c proto_bahamut.c proto_ircu_p10.c service.c service.h Log Message: revise config file interface move ping_freq, ping_timeout to protocol modules implement module search path add some service config lookup code Index: conf.c =================================================================== RCS file: /cvsroot/srvx/services/src/conf.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -r1.23 -r1.24 *** conf.c 2001/10/02 16:04:36 1.23 --- conf.c 2001/10/14 19:45:40 1.24 *************** *** 15,20 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ */ --- 15,18 ---- *************** *** 32,37 **** #include "tools.h" ! static dict_t conf_db; ! static dict_t conf_server; static conf_reload_func *reload_funcs; --- 30,34 ---- #include "tools.h" ! dict_t conf_db; static conf_reload_func *reload_funcs; *************** *** 67,72 **** dict_t new_conf; ! if (!(new_conf = parse_database(conf_file_name)) ! || !(conf_server = database_get_data(new_conf, "server", RECDB_OBJECT))) { log(MAIN_LOG, LOG_ERROR, "Reverting to previous configuration\n"); return 0; --- 64,68 ---- dict_t new_conf; ! if (!(new_conf = parse_database(conf_file_name))) { log(MAIN_LOG, LOG_ERROR, "Reverting to previous configuration\n"); return 0; *************** *** 105,131 **** const char * conf_server_name(void) { ! return database_get_data(conf_server, "hostname", RECDB_QSTRING); } const char * conf_server_desc(void) { ! return database_get_data(conf_server, "description", RECDB_QSTRING); ! } ! ! int ! conf_server_num(void) { ! const char *text = database_get_data(conf_server, "numeric", RECDB_QSTRING); ! return text ? atoi(text) : -1; ! } ! ! int ! conf_server_ping_freq(void) { ! const unsigned char *text = database_get_data(conf_server, "ping_freq", RECDB_QSTRING); ! return text ? (signed)ParseInterval(text) : -1; ! } ! ! int ! conf_server_ping_timeout(void) { ! const unsigned char *text = database_get_data(conf_server, "ping_timeout", RECDB_QSTRING); ! return text ? (signed)ParseInterval(text) : -1; } --- 101,109 ---- const char * conf_server_name(void) { ! return database_get_data(conf_db, "server/hostname", RECDB_QSTRING); } const char * conf_server_desc(void) { ! return database_get_data(conf_db, "server/description", RECDB_QSTRING); } Index: conf.h =================================================================== RCS file: /cvsroot/srvx/services/src/conf.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** conf.h 2001/03/30 21:20:10 1.11 --- conf.h 2001/10/14 19:45:40 1.12 *************** *** 15,20 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ */ --- 15,18 ---- *************** *** 24,42 **** #include "dict.h" ! int conf_read(const char *conf_file_name); ! void conf_close(void); ! ! const char *conf_server_name(void); ! const char *conf_server_desc(void); ! int conf_server_num(void); ! int conf_server_ping_freq(void); ! int conf_server_ping_timeout(void); typedef void (*conf_reload_func)(void); void conf_register_reload(conf_reload_func crf); void conf_call_reload_funcs(void); - struct record_data *conf_get_node(const char *full_path); ! const char *conf_enum_root(dict_iterator_f it, void *extra); #endif --- 22,35 ---- #include "dict.h" ! extern dict_t conf_db; + int conf_read(const char *conf_file_name); typedef void (*conf_reload_func)(void); void conf_register_reload(conf_reload_func crf); void conf_call_reload_funcs(void); struct record_data *conf_get_node(const char *full_path); ! const char *conf_server_name(void); ! const char *conf_server_desc(void); ! void conf_close(void); #endif Index: main.c =================================================================== RCS file: /cvsroot/srvx/services/src/main.c,v retrieving revision 1.116 retrieving revision 1.117 diff -C2 -r1.116 -r1.117 *** main.c 2001/10/13 23:51:33 1.116 --- main.c 2001/10/14 19:45:40 1.117 *************** *** 71,75 **** time_t boot_time, burst_begin, now; - int ping_freq = 120, ping_timeout = 30; int silent, quit_services; --- 71,74 ---- *************** *** 329,333 **** int main(int argc, char *argv[]) { ! int tmp, daemon; pid_t pid = 0; FILE *file_out; --- 328,332 ---- int main(int argc, char *argv[]) { ! int daemon; pid_t pid = 0; FILE *file_out; *************** *** 457,462 **** reg_exit_func(conf_close); - if ((tmp = conf_server_ping_freq()) != -1) ping_freq = tmp; - if ((tmp = conf_server_ping_timeout()) != -1) ping_timeout = tmp; modules_init(); timeq_init(); --- 456,459 ---- Index: proto_bahamut.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_bahamut.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** proto_bahamut.c 2001/10/12 04:03:51 1.18 --- proto_bahamut.c 2001/10/14 19:45:40 1.19 *************** *** 35,38 **** --- 35,39 ---- #define PROTO_VARIABLE(type, name) extern type name; #include "proto.h" + #include "recdb.h" #include "timeq.h" #include "tools.h" *************** *** 48,53 **** typedef void (*foreach_nonuser) (char *name, void *data); ! extern int ping_freq, ping_timeout; ! static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); --- 49,54 ---- typedef void (*foreach_nonuser) (char *name, void *data); ! static int ping_freq = 60; ! static int ping_timeout = 150; static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); *************** *** 281,285 **** irc_introduce(const char *passwd) { - extern int ping_freq; extern time_t burst_begin; extern unsigned long burst_length; --- 282,285 ---- *************** *** 1374,1377 **** --- 1374,1378 ---- { extern time_t boot_time; + const char *conf_str; /* Register things with module registry */ *************** *** 1413,1418 **** dict_insert(irc_func_dict, CMD_SJOIN, cmd_sjoin); dict_insert(irc_func_dict, CMD_SVINFO, cmd_svinfo); - /* DESYNCH is just informational, so ignore it */ - dict_insert(irc_func_dict, CMD_DESYNCH, cmd_dummy); /* TODO: parse the cmd_dummy lines here */ dict_insert(irc_func_dict, CMD_VERSION, cmd_dummy); --- 1414,1417 ---- *************** *** 1441,1444 **** --- 1440,1451 ---- reg_del_user_func(bahamut_del_user); reg_exit_func(free_parse_misc); + + /* set other config data */ + if ((conf_str = database_get_data(conf_db, "server/ping_freq", RECDB_QSTRING))) { + ping_freq = ParseInterval(conf_str); + } + if ((conf_str = database_get_data(conf_db, "server/ping_timeout", RECDB_QSTRING))) { + ping_timeout = ParseInterval(conf_str); + } /* create self server */ Index: proto_ircu_p10.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_ircu_p10.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** proto_ircu_p10.c 2001/10/12 04:03:51 1.28 --- proto_ircu_p10.c 2001/10/14 19:45:40 1.29 *************** *** 34,37 **** --- 34,38 ---- #define PROTO_VARIABLE(type, name) extern type name; #include "proto.h" + #include "recdb.h" #include "timeq.h" #include "tools.h" *************** *** 47,56 **** #define USERARRAYSIZE (1 << (USER_NUMERIC_LEN * 6)) - extern int ping_freq, ping_timeout; - static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); static struct server *servers_num[64]; static unsigned int next_numeric; static unsigned int highest_numeric; --- 48,57 ---- #define USERARRAYSIZE (1 << (USER_NUMERIC_LEN * 6)) static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); static struct server *servers_num[64]; + static int ping_freq = 60; + static int ping_timeout = 150; static unsigned int next_numeric; static unsigned int highest_numeric; *************** *** 1659,1662 **** --- 1660,1664 ---- unsigned int i; char numer[COMBO_NUMERIC_LEN+1]; + const char *conf_str; /* Register things with module registry */ *************** *** 1670,1673 **** --- 1672,1683 ---- proto_max_channel_bans = 30; + /* set other config data */ + if ((conf_str = database_get_data(conf_db, "server/ping_freq", RECDB_QSTRING))) { + ping_freq = ParseInterval(conf_str); + } + if ((conf_str = database_get_data(conf_db, "server/ping_timeout", RECDB_QSTRING))) { + ping_timeout = ParseInterval(conf_str); + } + /* initialize data structures */ for (i=0; i<ArrayLength(servers_num); i++) { *************** *** 1678,1682 **** /* create self server */ ! inttobase64(numer, conf_server_num(), SERVER_NUMERIC_LEN); for (i=SERVER_NUMERIC_LEN; i<COMBO_NUMERIC_LEN+1; i++) numer[i] = ']'; numer[COMBO_NUMERIC_LEN] = 0; --- 1688,1697 ---- /* create self server */ ! conf_str = database_get_data(conf_db, "server/numeric", RECDB_QSTRING); ! if (!conf_str) { ! log(MAIN_LOG, LOG_ERROR, "Missing configuration entry server/numeric\n"); ! exit(1); ! } ! inttobase64(numer, strtoul(conf_str, NULL, 0), SERVER_NUMERIC_LEN); for (i=SERVER_NUMERIC_LEN; i<COMBO_NUMERIC_LEN+1; i++) numer[i] = ']'; numer[COMBO_NUMERIC_LEN] = 0; Index: service.c =================================================================== RCS file: /cvsroot/srvx/services/src/service.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** service.c 2001/10/12 02:03:34 1.5 --- service.c 2001/10/14 19:45:40 1.6 *************** *** 15,20 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ */ --- 15,18 ---- *************** *** 24,30 **** --- 22,31 ---- #include <stdlib.h> + #include "conf.h" #include "dict.h" + #include "log.h" #include "messages.h" #include "proto.h" + #include "recdb.h" #include "rules.h" #include "service.h" *************** *** 37,47 **** static struct module *service_module; ! static dict_t service_templates; void service_init(void) { service_module = module_register("service", MAKE_VERSION(SERVICE_MAJOR, SERVICE_MINOR, SERVICE_REVISION), NULL, NULL); ! service_templates = dict_new(); } --- 38,92 ---- static struct module *service_module; ! static dict_t services; /* (struct service*->user->nick)->struct service*) */ void + service_free_user(struct user *user) + { + struct service *svc; + if (!(svc = user->service)) return; + assert(user == svc->user); + free(svc->name); + free(svc); + } + + void service_init(void) { service_module = module_register("service", MAKE_VERSION(SERVICE_MAJOR, SERVICE_MINOR, SERVICE_REVISION), NULL, NULL); ! reg_del_user_func(service_free_user); ! } ! ! static struct service_command * ! service_find_command(struct service *sinst, const char *name) ! { ! struct service_command *cmd; ! while (sinst) { ! cmd = dict_find(sinst->commands, name, NULL); ! if (cmd) return cmd; ! sinst = sinst->extends; ! } ! return NULL; ! } ! ! static void * ! service_find_conf_by_name(const char *sname, const char *path, enum recdb_type type) ! { ! dict_t services, conf; ! void *res; ! ! services = database_get_data(conf_db, "services", RECDB_OBJECT); ! while (sname) { ! conf = database_get_data(services, sname, RECDB_OBJECT); ! if (!conf) return NULL; ! if ((res = database_get_data(conf, path, type))) return res; ! sname = database_get_data(conf_db, "extends", RECDB_QSTRING); ! } ! return NULL; ! } ! ! void * ! service_find_conf(struct service *sinst, const char *path, enum recdb_type type) ! { ! return service_find_conf_by_name(sinst->user->nick, path, type); } *************** *** 52,56 **** unsigned char *argv[MAXNUMPARAMS], *chan_name; unsigned int argc, shift; ! struct service_instance *sinst; struct service_command *cmd; struct expression_context rule_ctx; --- 97,101 ---- unsigned char *argv[MAXNUMPARAMS], *chan_name; unsigned int argc, shift; ! struct service *sinst; struct service_command *cmd; struct expression_context rule_ctx; *************** *** 61,65 **** sinst = bot->service; if ((argc > 0) && (argv[0][0] == '#')) { ! cmd = dict_find(sinst->templ->commands, argv[1], NULL); if (cmd->base->flags & (1 << TAKES_CHANNEL)) { shift = 1; --- 106,110 ---- sinst = bot->service; if ((argc > 0) && (argv[0][0] == '#')) { ! cmd = service_find_command(sinst, argv[1]); if (cmd->base->flags & (1 << TAKES_CHANNEL)) { shift = 1; *************** *** 70,74 **** } } else if ((argc > 1) && (argv[1][0] == '#')) { ! cmd = dict_find(sinst->templ->commands, argv[0], NULL); if (cmd->base->flags & (1 << TAKES_CHANNEL)) { shift = 1; --- 115,119 ---- } } else if ((argc > 1) && (argv[1][0] == '#')) { ! cmd = service_find_command(sinst, argv[0]); if (cmd->base->flags & (1 << TAKES_CHANNEL)) { shift = 1; *************** *** 81,85 **** } else { shift = 0; ! cmd = dict_find(sinst->templ->commands, argv[0], NULL); } if ((cmd->base->flags & (1 << TAKES_CHANNEL)) && shift) { --- 126,130 ---- } else { shift = 0; ! cmd = service_find_command(sinst, argv[0]); } if ((cmd->base->flags & (1 << TAKES_CHANNEL)) && shift) { *************** *** 107,134 **** } ! struct user * ! service_create(const char *name, dict_t params) { - struct user *user; const char *hostname, *userinfo, *trigger; ! struct service_template *templ; ! struct service_instance *sinst; ! /* Is the template defined? */ ! if (!(templ = dict_find(service_templates, name, NULL))) return NULL; /* Get the various parameters from the params dict */ ! hostname = dict_find(params, "hostname", NULL); ! userinfo = dict_find(params, "userinfo", NULL); ! trigger = dict_find(params, "trigger", NULL); /* Create the user and annotate it */ - user = add_local_user(name, name, hostname, "+oik", userinfo, now); sinst = calloc(1, sizeof(*sinst)); assert(sinst); ! sinst->templ = templ; ! user->service = sinst; ! /* Register callbacks */ ! if (trigger) reg_chanmsg_func(trigger[0], user, service_chanmsg); ! reg_privmsg_func(user, service_privmsg); ! /* TODO: finish service_create() */ ! return user; } --- 152,192 ---- } ! struct service * ! service_create(const char *name) { const char *hostname, *userinfo, *trigger; ! struct service *sinst; ! /* Check if we've already created it */ ! if ((sinst = dict_find(services, name, NULL))) return sinst; /* Get the various parameters from the params dict */ ! hostname = service_find_conf_by_name(name, "hostname", RECDB_QSTRING); ! if (!hostname) { ! log(MAIN_LOG, LOG_ERROR, "No 'hostname' entry defined for service '%s'\n", name); ! return NULL; ! } ! userinfo = service_find_conf_by_name(name, "userinfo", RECDB_QSTRING); ! if (!userinfo) { ! log(MAIN_LOG, LOG_ERROR, "No 'userinfo' entry defined for service '%s'\n", name); ! return NULL; ! } ! trigger = service_find_conf_by_name(name, "trigger", RECDB_QSTRING); /* Create the user and annotate it */ sinst = calloc(1, sizeof(*sinst)); assert(sinst); ! sinst->name = strdup(name); ! sinst->extends = service_create(service_find_conf_by_name(name, "extends", RECDB_QSTRING)); ! if (name[0] != '*') { ! struct user *user; ! user = sinst->user = add_local_user(name, name, hostname, "+oik", userinfo, now); ! user->service = sinst; ! /* Register callbacks */ ! if (trigger) reg_chanmsg_func(trigger[0], user, service_chanmsg); ! reg_privmsg_func(user, service_privmsg); ! } ! sinst->commands = dict_new(); ! /* Put into services dict */ ! dict_insert(services, sinst->name, sinst); ! /* TODO: finish service_create(): load commands, ?call callbacks? */ ! return sinst; } Index: service.h =================================================================== RCS file: /cvsroot/srvx/services/src/service.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** service.h 2001/10/10 04:51:23 1.4 --- service.h 2001/10/14 19:45:40 1.5 *************** *** 15,20 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ */ --- 15,18 ---- *************** *** 32,47 **** struct service_common; - struct service_template { - dict_t commands; /* string->struct service_command* */ - struct service_template_common *common; - }; - /* Attached as a "service" module note to "struct user" */ ! struct service_instance { ! struct service_template *templ; }; void service_init(); ! struct user *service_create(const char *templ_name, dict_t params); void service_chanmsg(struct user *bot, struct user *source, struct channel *chan, char *real_text); --- 30,45 ---- struct service_common; /* Attached as a "service" module note to "struct user" */ ! struct service { ! char *name; ! struct user *user; ! struct service *extends; ! dict_t commands; ! struct service_common *common; }; void service_init(); ! struct service *service_create(const char *name); ! void * service_find_conf(struct service *sinst, const char *path, enum recdb_type type); void service_chanmsg(struct user *bot, struct user *source, struct channel *chan, char *real_text); |