diff options
| author | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-02 23:50:53 +0000 |
|---|---|---|
| committer | Robin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-02 23:50:53 +0000 |
| commit | ec9dafb778cae465379f64bf0a0f997dbb4603ab (patch) | |
| tree | 2a908a3c4bcd4f1fa7e137766ff1349909b13f1c /src | |
| parent | 232d1b5e88c62ef3e2dae4a03353da817a3b89dc (diff) | |
Rip out SQL. It's utterly useless in current implementation.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1502 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 16 | ||||
| -rw-r--r-- | src/botserv.c | 34 | ||||
| -rw-r--r-- | src/chanserv.c | 94 | ||||
| -rw-r--r-- | src/config.c | 2 | ||||
| -rw-r--r-- | src/core/ns_group.c | 10 | ||||
| -rw-r--r-- | src/hostserv.c | 48 | ||||
| -rw-r--r-- | src/init.c | 116 | ||||
| -rw-r--r-- | src/main.c | 59 | ||||
| -rw-r--r-- | src/makefile.win32 | 4 | ||||
| -rw-r--r-- | src/mypasql.c | 122 | ||||
| -rw-r--r-- | src/mysql.c | 1890 | ||||
| -rw-r--r-- | src/news.c | 31 | ||||
| -rw-r--r-- | src/nickserv.c | 164 | ||||
| -rw-r--r-- | src/operserv.c | 65 | ||||
| -rw-r--r-- | src/rdb.c | 496 | ||||
| -rw-r--r-- | src/sessions.c | 29 |
16 files changed, 48 insertions, 3132 deletions
diff --git a/src/Makefile b/src/Makefile index 3d7122c5f..ccd6a3be2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,15 +1,11 @@ -MYSQL_OBJ = $(MYSQL:.c=.o) -RDB_OBJ = $(RDB:.c=.o) OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o commands.o compat.o \ config.o datafiles.o encrypt.o events.o hashcomp.o helpserv.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o news.o nickserv.o operserv.o \ - process.o send.o servers.o sessions.o slist.o sockutil.o timeout.o users.o \ - $(RDB_OBJ) $(MYSQL_OBJ) + process.o send.o servers.o sessions.o slist.o sockutil.o timeout.o users.o SRCS = actions.c base64.c bots.cpp botserv.c channels.c chanserv.c commands.c compat.c \ - config.c datafiles.c encrypt.c events.c hashcomp.c helpserv.c hostserv.c init.c ircd.c language.c log.c mail.c main.c \ + config.c datafiles.c encrypt.c events.c hashcomp.cpp helpserv.c hostserv.c init.c ircd.c language.c log.c mail.c main.c \ memory.c memoserv.c messages.c misc.c modules.c news.c nickserv.c operserv.c \ - process.c send.c servers.c sessions.c s sockutil.c timeout.c users.c \ - $(RDB) $(MYSQL) + process.c send.c servers.c sessions.c s sockutil.c timeout.c users.c INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ ../include/pseudo.h ../include/sysconf.h ../include/config.h \ @@ -21,8 +17,8 @@ MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ 'LDFLAGS=${LDFLAGS}' 'BINDEST=${BINDEST}' 'INSTALL=${INSTALL}' \ 'INCLUDEDIR=${INCLUDEDIR}' 'RM=${RM}' 'CP=${CP}' \ 'TOUCH=${TOUCH}' 'SHELL=${SHELL}' 'DATDEST=${DATDEST}' \ - 'RUNGROUP=${RUNGROUP}' 'MODULE_PATH=${MODULE_PATH}' 'MYSQL=${MYSQL}'\ - 'RDB=${RDB}' 'SHARED=${SHARED}' 'MODULEFLAGS=${MODULEFLAGS}' + 'RUNGROUP=${RUNGROUP}' 'MODULE_PATH=${MODULE_PATH}' \ + 'SHARED=${SHARED}' 'MODULEFLAGS=${MODULEFLAGS}' .c.o: @../run-cc.pl $(CC) $(CFLAGS) -I../include/ -c $< @@ -76,8 +72,6 @@ sockutil.o: sockutil.c $(INCLUDES) timeout.o: timeout.c $(INCLUDES) users.o: users.c $(INCLUDES) vsnprintf.o: vsnprintf.c $(INCLUDES) -mysql.o: mysql.c $(INCLUDES) -rdb.o: rdb.c $(INCLUDES) mod_version: mod_version.c $(INCLUDES) @../run-cc.pl $(CC) $(CDEFS) $(CFLAGS) $(MODULEFLAGS) -I../include/ -c mod_version.c diff --git a/src/botserv.c b/src/botserv.c index b1507b2e8..2aeca8249 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -531,40 +531,6 @@ void save_bs_dbase(void) /*************************************************************************/ -void save_bs_rdb_dbase(void) -{ -#ifdef USE_RDB - int i; - BotInfo *bi; - - if (!rdb_open()) - return; - - if (rdb_tag_table("anope_bs_core") == 0) { - alog("Unable to tag table 'anope_bs_core' - BotServ RDB save failed."); - rdb_close(); - return; - } - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - if (rdb_save_bs_core(bi) == 0) { - alog("Unable to save BotInfo for %s - BotServ RDB save failed.", bi->nick); - rdb_close(); - return; - } - } - } - - if (rdb_clean_table("anope_bs_core") == 0) - alog("Unable to clean table 'anope_bs_core' - BotServ RDB save failed."); - - rdb_close(); -#endif -} - -/*************************************************************************/ - /* Inserts a bot in the bot list. I can't be much explicit mh? */ void insert_bot(BotInfo * bi) diff --git a/src/chanserv.c b/src/chanserv.c index 598982cd9..c20c39265 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -756,100 +756,6 @@ void save_cs_dbase(void) /*************************************************************************/ -void save_cs_rdb_dbase(void) -{ -#ifdef USE_RDB - int i; - ChannelInfo *ci; - - if (!rdb_open()) - return; - - if (rdb_tag_table("anope_cs_info") == 0) { - alog("Unable to tag table 'anope_cs_info' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table("anope_cs_access") == 0) { - alog("Unable to tag table 'anope_cs_access' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table("anope_cs_levels") == 0) { - alog("Unable to tag table 'anope_cs_levels' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table("anope_cs_akicks") == 0) { - alog("Unable to tag table 'anope_cs_akicks' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table("anope_cs_badwords") == 0) { - alog("Unable to tag table 'anope_cs_badwords' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table("anope_cs_ttb") == 0) { - alog("Unable to tag table 'anope_cs_ttb' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_tag_table_where("anope_ms_info", "serv='CHAN'") == 0) { - alog("Unable to tag table 'anope_ms_info' - ChanServ RDB save failed."); - rdb_close(); - return; - } - - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = ci->next) { - if (rdb_save_cs_info(ci) == 0) { - alog("Unable to save ChanInfo for %s - ChanServ RDB save failed.", ci->name); - rdb_close(); - return; - } - } /* for (chanlists[i]) */ - } /* for (i) */ - - if (rdb_clean_table("anope_cs_info") == 0) { - alog("Unable to clean table 'anope_cs_info' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table("anope_cs_access") == 0) { - alog("Unable to clean table 'anope_cs_access' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table("anope_cs_levels") == 0) { - alog("Unable to clean table 'anope_cs_levels' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table("anope_cs_akicks") == 0) { - alog("Unable to clean table 'anope_cs_akicks' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table("anope_cs_badwords") == 0) { - alog("Unable to clean table 'anope_cs_badwords' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table("anope_cs_ttb") == 0) { - alog("Unable to clean table 'anope_cs_ttb' - ChanServ RDB save failed."); - rdb_close(); - return; - } - if (rdb_clean_table_where("anope_ms_info", "serv='CHAN'") == 0) - alog("Unable to clean table 'anope_ms_info' - ChanServ RDB save failed."); - - rdb_close(); -#endif -} - -/*************************************************************************/ - /* Check the current modes on a channel; if they conflict with a mode lock, * fix them. * diff --git a/src/config.c b/src/config.c index 73ac09cb3..bd76ffcb1 100644 --- a/src/config.c +++ b/src/config.c @@ -277,7 +277,6 @@ char *MysqlSecure; char *MysqlSock; int MysqlRetries = 0; int MysqlRetryGap = 0; -int UseRDB = 0; int DefConLevel; static std::string DefCon1; @@ -1316,7 +1315,6 @@ Directive directives[] = { {"MysqlSock", {{PARAM_STRING, PARAM_RELOAD, &MysqlSock}}}, {"MysqlRetries", {{PARAM_POSINT, PARAM_RELOAD, &MysqlRetries}}}, {"MysqlRetryGap", {{PARAM_POSINT, PARAM_RELOAD, &MysqlRetryGap}}}, - {"UseRDB", {{PARAM_SET, PARAM_RELOAD, &UseRDB}}}, {"ModuleAutoload", {{PARAM_STRING, PARAM_RELOAD, &Modules}}}, {"ModuleDelayedAutoload", {{PARAM_STRING, PARAM_RELOAD, &ModulesDelayed}}}, diff --git a/src/core/ns_group.c b/src/core/ns_group.c index 29e5d44f4..4a31eb988 100644 --- a/src/core/ns_group.c +++ b/src/core/ns_group.c @@ -213,16 +213,6 @@ int do_group(User * u) u->na = na; na->u = u; -#ifdef USE_RDB - /* Is this really needed? Since this is a new alias it will get - * its unique id on the next update, since it was previously - * deleted by delnick. Must observe... - */ - if (rdb_open()) { - rdb_save_ns_alias(na); - rdb_close(); - } -#endif send_event(EVENT_GROUP, 1, u->nick); alog("%s: %s!%s@%s makes %s join group of %s (%s) (e-mail: %s)", s_NickServ, u->nick, u->username, u->host, u->nick, target->nick, target->nc->display, (target->nc->email ? target->nc->email : "none")); notice_lang(s_NickServ, u, NICK_GROUP_JOINED, target->nick); diff --git a/src/hostserv.c b/src/hostserv.c index cdf43889c..52dfbc0d9 100644 --- a/src/hostserv.c +++ b/src/hostserv.c @@ -314,28 +314,11 @@ char *getvIdent(char *nick) /*************************************************************************/ void delHostCore(char *nick) { -#ifdef USE_RDB - static char clause[128]; - char *q_nick; -#endif HostCore *tmp; bool found = false; tmp = findHostCore(head, nick, &found); if (found) { head = deleteHostCore(head, tmp); - -#ifdef USE_RDB - /* Reflect this change in the database right away. */ - if (rdb_open()) { - q_nick = rdb_quote(nick); - snprintf(clause, sizeof(clause), "nick='%s'", q_nick); - if (rdb_scrub_table("anope_hs_core", clause) == 0) - alog("Unable to scrub table 'anope_hs_core' - HostServ RDB update failed."); - rdb_close(); - free(q_nick); - } -#endif - } } @@ -497,37 +480,6 @@ void save_hs_dbase(void) #undef SAFE -void save_hs_rdb_dbase(void) -{ -#ifdef USE_RDB - HostCore *current; - - if (!rdb_open()) - return; - - if (rdb_tag_table("anope_hs_core") == 0) { - alog("Unable to tag table 'anope_hs_core' - HostServ RDB save failed."); - rdb_close(); - return; - } - - current = head; - while (current != NULL) { - if (rdb_save_hs_core(current) == 0) { - alog("Unable to save HostCore for %s - HostServ RDB save failed.", current->nick); - rdb_close(); - return; - } - current = current->next; - } - - if (rdb_clean_table("anope_hs_core") == 0) - alog("Unable to clean table 'anope_hs_core' - HostServ RDB save failed."); - - rdb_close(); -#endif -} - /*************************************************************************/ /* End of Load/Save Functions */ /*************************************************************************/ diff --git a/src/init.c b/src/init.c index 38f7b0c7d..6ba89f052 100644 --- a/src/init.c +++ b/src/init.c @@ -528,20 +528,6 @@ int init_secondary(int ac, char **av) hostserv_init(); helpserv_init(); -#ifdef USE_RDB - if (!rdb_init()) { - if (UseRDB) { - UseRDB = 0; - alog("Error: Disabling UseRDB due to errors with SQL"); - } - } else { - if (MysqlSecure && UseRDB) { - UseRDB = 0; - alog("Error: MySQL password are encrypted using method in MysqlSecure disabling UseRDB"); - } - } -#endif - /* load any custom modules */ modules_init(); @@ -550,56 +536,47 @@ int init_secondary(int ac, char **av) add_entropy_userkeys(); /* Load up databases */ -#ifdef USE_RDB - if (UseRDB) - rdb_load_dbases(); - /* Need a better way to handle this -dane */ - if (!UseRDB) { -#endif - load_ns_dbase(); - if (debug) - alog("debug: Loaded %s database (1/%d)", s_NickServ, - (PreNickDBName ? 8 : 7)); - if (s_HostServ) { - load_hs_dbase(); - if (debug) - alog("debug: Loaded %s database (2/%d)", s_HostServ, - (PreNickDBName ? 8 : 7)); - } else if (debug) { - alog("debug: HostServ database (2/%d) not loaded because HostServ is disabled", (PreNickDBName ? 8 : 7)); - } - if (s_BotServ) { - load_bs_dbase(); - if (debug) - alog("debug: Loaded %s database (3/%d)", s_BotServ, - (PreNickDBName ? 8 : 7)); - } else if (debug) { - alog("debug: BotServ database (3/%d) not loaded because BotServ is disabled", (PreNickDBName ? 8 : 7)); - } - load_cs_dbase(); - if (debug) - alog("debug: Loaded %s database (4/%d)", s_ChanServ, - (PreNickDBName ? 8 : 7)); - load_os_dbase(); - if (debug) - alog("debug: Loaded %s database (5/%d)", s_OperServ, - (PreNickDBName ? 8 : 7)); - load_news(); - if (debug) - alog("debug: Loaded news database (6/%d)", - (PreNickDBName ? 8 : 7)); - load_exceptions(); - if (debug) - alog("debug: Loaded exception database (7/%d)", - (PreNickDBName ? 8 : 7)); - if (PreNickDBName) { - load_ns_req_db(); - if (debug) - alog("debug: Loaded PreNick database (8/8)"); - } -#ifdef USE_RDB - } -#endif + load_ns_dbase(); + if (debug) + alog("debug: Loaded %s database (1/%d)", s_NickServ, + (PreNickDBName ? 8 : 7)); + if (s_HostServ) { + load_hs_dbase(); + if (debug) + alog("debug: Loaded %s database (2/%d)", s_HostServ, + (PreNickDBName ? 8 : 7)); + } else if (debug) { + alog("debug: HostServ database (2/%d) not loaded because HostServ is disabled", (PreNickDBName ? 8 : 7)); + } + if (s_BotServ) { + load_bs_dbase(); + if (debug) + alog("debug: Loaded %s database (3/%d)", s_BotServ, + (PreNickDBName ? 8 : 7)); + } else if (debug) { + alog("debug: BotServ database (3/%d) not loaded because BotServ is disabled", (PreNickDBName ? 8 : 7)); + } + load_cs_dbase(); + if (debug) + alog("debug: Loaded %s database (4/%d)", s_ChanServ, + (PreNickDBName ? 8 : 7)); + load_os_dbase(); + if (debug) + alog("debug: Loaded %s database (5/%d)", s_OperServ, + (PreNickDBName ? 8 : 7)); + load_news(); + if (debug) + alog("debug: Loaded news database (6/%d)", + (PreNickDBName ? 8 : 7)); + load_exceptions(); + if (debug) + alog("debug: Loaded exception database (7/%d)", + (PreNickDBName ? 8 : 7)); + if (PreNickDBName) { + load_ns_req_db(); + if (debug) + alog("debug: Loaded PreNick database (8/8)"); + } alog("Databases loaded"); @@ -626,19 +603,8 @@ int init_secondary(int ac, char **av) } /* Save the databases back to file/mysql to reflect any changes */ -#ifdef USE_RDB - if (!UseRDB) { /* Only save if we are not using remote databases - * to avoid floods. As a side effects our nice - * FFF databases won't get overwritten if the - * mysql db is broken (empty etc.) */ -#endif alog("Info: Reflecting database records."); save_databases(); -#ifdef USE_RDB - } else { - alog("Info: Not reflecting database records."); - } -#endif send_event(EVENT_CONNECT, 1, EVENT_START); /* Connect to the remote server */ diff --git a/src/main.c b/src/main.c index d70e936ba..ab658e090 100644 --- a/src/main.c +++ b/src/main.c @@ -49,10 +49,6 @@ int protocoldebug = 0; /* -protocoldebug */ char *binary_dir; /* Used to store base path for win32 restart */ #endif -#ifdef USE_RDB -int do_mysql = 0; /* use mysql ? */ -#endif - /* Set to 1 if we are to quit */ int quitting = 0; @@ -165,61 +161,6 @@ void save_databases(void) save_news(); waiting = -18; save_exceptions(); - -#ifdef USE_RDB - if (do_mysql) { - if (debug) - alog("debug: Saving RDB databases"); - waiting = -10; - waiting = -11; - save_ns_rdb_dbase(); - /* We send these PONG's when we're not syncing to avoid timeouts. - * If we send them during the sync, we fuck something up there and - * break the syncing process, resulting in lost (literally lost) - * data. -GD - * This used is_sync(serv_uplink) to check for sync states. There's - * only a minor error with this: serv_uplink doesn't exist during - * the first save. So now we check for serv_uplink only; if it - * exists we're safe. -GD - */ - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - waiting = -12; - save_cs_rdb_dbase(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - if (PreNickDBName) { - save_ns_req_rdb_dbase(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - waiting = -13; - } - if (s_BotServ) { - waiting = -14; - save_bs_rdb_dbase(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - } - if (s_HostServ) { - waiting = -15; - save_hs_rdb_dbase(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - } - waiting = -16; - save_os_rdb_dbase(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - waiting = -17; - save_rdb_news(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - waiting = -18; - save_rdb_exceptions(); - if (serv_uplink) - ircdproto->SendPong(ServerName, ServerName); - } -#endif waiting = -20; send_event(EVENT_DB_SAVING, 1, EVENT_STOP); } diff --git a/src/makefile.win32 b/src/makefile.win32 index 09f05acbe..39799a25a 100644 --- a/src/makefile.win32 +++ b/src/makefile.win32 @@ -22,13 +22,13 @@ OBJS = actions.obj base64.obj bots.obj botserv.obj channels.obj chanserv.obj co init.obj ircd.obj language.obj list.obj log.obj mail.obj main.obj memory.obj \ memoserv.obj messages.obj misc.obj modules.obj mod_version.obj news.obj nickserv.obj operserv.obj \ process.obj send.obj servers.obj sessions.obj slist.obj sockutil.obj \ - timeout.obj users.obj $(RDB_O) $(MYSQL_O) + timeout.obj users.obj SRCS = actions.c base64.c botserv.c bots.cpp channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c events.c helpserv.c hostserv.c init.c ircd.c \ language.c list.c log.c mail.c main.c memory.c memoserv.c messages.c misc.c \ modules.c mod_version.c news.c nickserv.c operserv.c process.c send.c servers.obj sessions.c \ - slist.c sockutil.c timeout.c users.c $(RDB_C) $(MYSQL_C) + slist.c sockutil.c timeout.c users.c ########################################################################### diff --git a/src/mypasql.c b/src/mypasql.c deleted file mode 100644 index a66850c84..000000000 --- a/src/mypasql.c +++ /dev/null @@ -1,122 +0,0 @@ -#include <winsock.h> -#include <stdio.h> -#include <mysql.h> - -MYSQL *mysql; -MYSQL_RES *result = NULL; -MYSQL_ROW row; - -int __stdcall mysql_Connect(char *server, char *user, char *pass) -{ - mysql = mysql_init(NULL); - return (int) mysql_real_connect(mysql, server, user, pass, NULL, 0, - NULL, 0); -} - -int __stdcall mysql_SelectDb(char *db) -{ - return (int) mysql_select_db(mysql, db); -} - -const char *__stdcall mysql_Error() -{ - return mysql_error(mysql); -} - -int __stdcall mysql_Query(char *query) -{ - if (result) { - mysql_free_result(result); - result = NULL; - } - return (int) mysql_real_query(mysql, query, strlen(query)); -} - -int __stdcall mysql_NumRows() -{ - if (!result) - result = mysql_store_result(mysql); - return mysql_num_rows(result); -} - -char *strip(char *str) -{ - char *c; - if ((c = strrchr(str, '\n'))) - *c = 0; - if ((c = strrchr(str, '\r'))) - *c = 0; - return str; -} - -void add_line(char **buf, char *line) -{ - int oldlen; - char *tmp; - - if (*buf != NULL) { - oldlen = strlen(*buf); - tmp = malloc(oldlen + 1); - strcpy(tmp, *buf); - *buf = realloc(*buf, oldlen + strlen(line) + 1); - strcpy(*buf, tmp); - strcat(*buf, line); - free(tmp); - } else - *buf = strdup(line); -} - -int __stdcall mysql_LoadFromFile(char *file) -{ - FILE *fd = fopen(file, "r"); - char line[1024]; - char *query = NULL; - - - if (!fd) - return 0; - while (fgets(line, 1024, fd)) { - int len; - strip(line); - len = strlen(line); - if (!*line || (*line == '-' && *(line + 1) == '-')) - continue; - else if (line[len - 1] == ';') { /* End of a query */ - line[len - 1] = 0; - add_line(&query, line); - if (mysql_real_query(mysql, query, strlen(query))) { - free(query); - return 0; - } - free(query); - query = NULL; - } - - else - add_line(&query, line); - } - return 1; -} - -int __stdcall mysql_NumFields() -{ - if (!result) - result = mysql_store_result(mysql); - return mysql_num_fields(result); -} - -int __stdcall mysql_FetchRow() -{ - if (!result) - result = mysql_store_result(mysql); - row = mysql_fetch_row(result); - return (int) row; -} - -char *__stdcall mysql_FetchField(int i) -{ - if (i >= mysql_num_fields(result)) - return NULL; - else - return row[i]; -} diff --git a/src/mysql.c b/src/mysql.c deleted file mode 100644 index db67980f4..000000000 --- a/src/mysql.c +++ /dev/null @@ -1,1890 +0,0 @@ - -/* MySQL functions. - * - * (C) 2003-2008 Anope Team - * Contact us at info@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * $Id$ - * - */ -#include "services.h" - -/*************************************************************************/ - -/* Database Global Variables */ -MYSQL *mysql; /* MySQL Handler */ -MYSQL_RES *mysql_res; /* MySQL Result */ -MYSQL_FIELD *mysql_fields; /* MySQL Fields */ -MYSQL_ROW mysql_row; /* MySQL Row */ - -int mysql_is_connected = 0; /* Are we currently connected? */ - -/*************************************************************************/ - -/* Throw a mysql error into the logs. If severity is MYSQL_ERROR, we - * also exit Anope... - */ -void db_mysql_error(int severity, char *msg) -{ - static char buf[512]; - - if (mysql_error(mysql)) { - snprintf(buf, sizeof(buf), "MySQL %s %s: %s", msg, - severity == MYSQL_WARNING ? "warning" : "error", - mysql_error(mysql)); - } else { - snprintf(buf, sizeof(buf), "MySQL %s %s", msg, - severity == MYSQL_WARNING ? "warning" : "error"); - } - - log_perror(buf); - - if (severity == MYSQL_ERROR) { - log_perror("MySQL FATAL error... aborting."); - exit(0); - } - -} - -/*************************************************************************/ - -/* Initialize the MySQL code */ -int db_mysql_init() -{ - - /* If the host is not defined, assume we don't want MySQL */ - if (!MysqlHost) { - do_mysql = 0; - alog("MySQL: has been disabled."); - return 0; - } else { - do_mysql = 1; - alog("MySQL: has been enabled."); - alog("MySQL: client version %s.", mysql_get_client_info()); - } - - /* The following configuration options are required. - * If missing disable MySQL to avoid any problems. - */ - - if ((do_mysql) && (!MysqlName || !MysqlUser)) { - do_mysql = 0; - alog("MySQL Error: Set all required configuration options."); - return 0; - } - - if (!db_mysql_open()) { - do_mysql = 0; - return 0; - } - - return 1; -} - -/*************************************************************************/ - -/* Open a connection to the mysql database. Return 0 on failure, or - * 1 on success. If this succeeds, we're guaranteed of a working - * mysql connection (unless something unexpected happens ofcourse...) - */ -int db_mysql_open() -{ - /* If MySQL is disabled, return 0 */ - if (!do_mysql) - return 0; - - /* If we are reported to be connected, ping MySQL to see if we really are - * still connected. (yes mysql_ping() returns 0 on success) - */ - if (mysql_is_connected && !mysql_ping(mysql)) - return 1; - - mysql_is_connected = 0; - - mysql = mysql_init(NULL); - if (mysql == NULL) { - db_mysql_error(MYSQL_WARNING, "Unable to create mysql object"); - return 0; - } - - if (!MysqlPort) - MysqlPort = MYSQL_DEFAULT_PORT; - - if (!mysql_real_connect(mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, MysqlSock, 0)) { - log_perror("MySQL Error: Cant connect to MySQL: %s\n", mysql_error(mysql)); - return 0; - } - - mysql_is_connected = 1; - - return 1; - -} - - -/*************************************************************************/ - -/* Perform a MySQL query. Return 1 if the query succeeded and 0 if the - * query failed. Before returning failure, re-try the query a few times - * and die if it still fails. - */ -int db_mysql_query(char *sql) -{ - int lcv; - - if (!do_mysql) - return 0; - - if (debug) - alog("debug: MySQL: %s", sql); - - /* Try as many times as configured in MysqlRetries */ - for (lcv = 0; lcv < MysqlRetries; lcv++) { - if (db_mysql_open() && (mysql_query(mysql, sql) == 0)) - return 1; - - /* If we get here, we could not run the query */ - log_perror("Unable to run query: %s\n", mysql_error(mysql)); - - /* Wait for MysqlRetryGap seconds and try again */ - sleep(MysqlRetryGap); - } - - /* Unable to run the query even after MysqlRetries tries */ - db_mysql_error(MYSQL_WARNING, "query"); - - return 0; - -} - -/*************************************************************************/ - -/* Quote a string to be safely included in a query. The result of this - * function is allocated; it MUST be freed by the caller. - */ -char *db_mysql_quote(char *sql) -{ - int slen; - char *quoted; - - - if (!sql) - return sstrdup(""); - - slen = strlen(sql); - quoted = (char*)malloc((1 + (slen * 2)) * sizeof(char)); - - mysql_real_escape_string(mysql, quoted, sql, slen); - - return quoted; - -} - -/*************************************************************************/ - -/* Close the MySQL database connection. */ -int db_mysql_close() -{ - mysql_close(mysql); - - mysql_is_connected = 0; - - return 1; -} - -/*************************************************************************/ - -/* Try to execute a query and issue a warning when failed. Return 1 on - * success and 0 on failure. - */ -int db_mysql_try(const char *fmt, ...) -{ - va_list args; - static char sql[MAX_SQL_BUF]; - - va_start(args, fmt); - vsnprintf(sql, MAX_SQL_BUF, fmt, args); - va_end(args); - - if (!db_mysql_query(sql)) { - log_perror("Can't create sql query: %s", sql); - db_mysql_error(MYSQL_WARNING, "query"); - return 0; - } - - return 1; -} - -/*************************************************************************/ - -/* Return a string to insert into a SQL query. The string will, once - * evaluated by MySQL, result in a the given pass encoded in the encryption - * type selected for MysqlSecure - * - * This should be removed since Rob properly did encryption modules... -GD - */ -char *db_mysql_secure(char *pass) -{ - char epass[BUFSIZE]; - char tmp_pass[PASSMAX]; - - /* Initialize the buffer. Bug #86 */ - memset(epass, '\0', BUFSIZE); - memset(tmp_pass, '\0', PASSMAX); - - /* We couldnt decrypt the pass... */ - if (enc_decrypt(pass, tmp_pass, PASSMAX - 1) != 1) { - snprintf(epass, sizeof(epass), "'%s'", pass); - } else { /* if we could decrypt the pass */ - if (!pass) { - snprintf(epass, sizeof(epass), "''"); - } else if ((!MysqlSecure) || (strcmp(MysqlSecure, "") == 0)) { - snprintf(epass, sizeof(epass), "'%s'", tmp_pass); - } else if (strcmp(MysqlSecure, "des") == 0) { - snprintf(epass, sizeof(epass), "ENCRYPT('%s')", tmp_pass); - } else if (strcmp(MysqlSecure, "md5") == 0) { - snprintf(epass, sizeof(epass), "MD5('%s')", tmp_pass); - } else if (strcmp(MysqlSecure, "sha") == 0) { - snprintf(epass, sizeof(epass), "SHA('%s')", tmp_pass); - } else { - snprintf(epass, sizeof(epass), "ENCODE('%s','%s')", tmp_pass, - MysqlSecure); - } - } - return sstrdup(epass); -} - -/*************************************************************************/ - -/* - * NickServ Specific Secion - */ - -/*************************************************************************/ - -/* Save the given NickRequest into the database - * Return 1 on success, 0 on failure - * These tables are tagged and will be cleaned: - * - anope_ns_request - */ -int db_mysql_save_ns_req(NickRequest * nr) -{ - int ret; |
