summaryrefslogtreecommitdiff
path: root/src/mysql.c
diff options
context:
space:
mode:
authorRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-02 23:50:53 +0000
committerRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-02 23:50:53 +0000
commitec9dafb778cae465379f64bf0a0f997dbb4603ab (patch)
tree2a908a3c4bcd4f1fa7e137766ff1349909b13f1c /src/mysql.c
parent232d1b5e88c62ef3e2dae4a03353da817a3b89dc (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/mysql.c')
-rw-r--r--src/mysql.c1890
1 files changed, 0 insertions, 1890 deletions
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;
- char *q_nick, *q_passcode, *q_password, *q_email;
-
- q_nick = db_mysql_quote(nr->nick);
- q_passcode = db_mysql_quote(nr->passcode);
- q_password = db_mysql_quote(nr->password);
- q_email = db_mysql_quote(nr->email);
-
- ret = db_mysql_try("UPDATE anope_ns_request "
- "SET passcode = '%s', password = '%s', email = '%s', requested = %d, active = 1 "
- "WHERE nick = '%s'",
- q_passcode, q_password, q_email, (int) nr->requested,
- q_nick);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_ns_request "
- "(nick, passcode, password, email, requested, active) "
- "VALUES ('%s', '%s', '%s', '%s', %d, 1)",
- q_nick, q_passcode, q_password, q_email,
- (int) nr->requested);
- }
-
- free(q_nick);
- free(q_passcode);
- free(q_password);
- free(q_email);
-
- return ret;
-}
-
-/*************************************************************************/
-
-/* Save the given NickCore into the database
- * Also save the access list and memo's for this user
- * Return 1 on success, 0 on failure
- * These tables are tagged and will be cleaned:
- * - anope_ns_core
- * - anope_ns_alias
- * - anope_ns_access
- * - anope_ms_info (serv='NICK')
- */
-int db_mysql_save_ns_core(NickCore * nc)
-{
- int ret;
- int i;
- char *q_display, *q_pass, *epass, *q_email, *q_greet, *q_url,
- *q_access, *q_sender, *q_text;
-
- q_display = db_mysql_quote(nc->display);
- q_pass = db_mysql_quote(nc->pass);
- q_email = db_mysql_quote(nc->email);
- q_greet = db_mysql_quote(nc->greet);
- q_url = db_mysql_quote(nc->url);
-
- epass = db_mysql_secure(q_pass);
- free(q_pass);
-
- /* Let's take care of the core itself */
- /* Update the existing records */
- ret = db_mysql_try("UPDATE anope_ns_core "
- "SET pass = %s, email = '%s', greet = '%s', icq = %d, url = '%s', flags = %d, language = %d, accesscount = %d, memocount = %d, "
- " memomax = %d, channelcount = %d, active = 1 "
- "WHERE display = '%s'",
- epass, q_email, q_greet, nc->icq, q_url, nc->flags,
- nc->language, nc->accesscount, nc->memos.memocount,
- nc->memos.memomax, nc->channelcount,
- q_display);
-
- /* Our previous UPDATE affected no rows, therefore this is a new record */
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_ns_core "
- "(display, pass, email, greet, icq, url, flags, language, accesscount, memocount, memomax, channelcount, active) "
- "VALUES ('%s', %s, '%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, %d, 1)",
- q_display, epass, q_email, q_greet, nc->icq, q_url,
- nc->flags, nc->language, nc->accesscount,
- nc->memos.memocount, nc->memos.memomax,
- nc->channelcount);
- }
-
- /* Now let's do the access */
- for (i = 0; ret && (i < nc->accesscount); i++) {
- q_access = db_mysql_quote(nc->access[i]);
-
- ret = db_mysql_try("UPDATE anope_ns_access "
- "SET access = '%s' "
- "WHERE display = '%s'",
- q_access, q_display);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_ns_access "
- "(display, access) "
- "VALUES ('%s','%s')",
- q_display, q_access);
- }
-
- free(q_access);
- }
-
- /* Memos */
- for (i = 0; ret && (i < nc->memos.memocount); i++) {
- q_sender = db_mysql_quote(nc->memos.memos[i].sender);
- q_text = db_mysql_quote(nc->memos.memos[i].text);
-
- ret = db_mysql_try("UPDATE anope_ms_info "
- "SET receiver = '%s', number = %d, flags = %d, time = %d, sender = '%s', text = '%s', active = 1 "
- "WHERE nm_id = %d AND serv = 'NICK'",
- q_display, nc->memos.memos[i].number,
- nc->memos.memos[i].flags,
- (int) nc->memos.memos[i].time, q_sender, q_text,
- nc->memos.memos[i].id);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT INTO anope_ms_info "
- "(receiver, number, flags, time, sender, text, serv, active) "
- "VALUES ('%s', %d, %d, %d, '%s', '%s', 'NICK', 1)",
- q_display, nc->memos.memos[i].number,
- nc->memos.memos[i].flags,
- (int) nc->memos.memos[i].time, q_sender,
- q_text);
-
- /* This is to make sure we can UPDATE memos instead of TRUNCATE
- * the table each time and then INSERT them all again. Ideally
- * everything in core would have it's dbase-id stored, but that's
- * something for phase 3. -GD
- */
- if (ret)
- nc->memos.memos[i].id = mysql_insert_id(mysql);
- }
-
- free(q_sender);
- free(q_text);
- }
-
- free(q_display);
- free(epass);
- free(q_email);
- free(q_greet);
- free(q_url);
-
- return ret;
-}
-
-
-/*************************************************************************/
-
-/* Save the given NickAlias into the database
- * Return 1 on success, 0 on failure
- * These tables are tagged and will be cleaned:
- * - anope_ns_core
- * - anope_ns_alias
- * - anope_ns_access
- * - anope_ms_info (serv='NICK')
- */
-int db_mysql_save_ns_alias(NickAlias * na)
-{
- int ret;
- char *q_nick, *q_lastmask, *q_lastrname, *q_lastquit, *q_display;
-
- q_nick = db_mysql_quote(na->nick);
- q_lastmask = db_mysql_quote(na->last_usermask);
- q_lastrname = db_mysql_quote(na->last_realname);
- q_lastquit = db_mysql_quote(na->last_quit);
- q_display = db_mysql_quote(na->nc->display);
-
- ret = db_mysql_try("UPDATE anope_ns_alias "
- "SET last_usermask = '%s', last_realname = '%s', last_quit = '%s', time_registered = %d, last_seen = %d, status = %d, "
- " display = '%s', active = 1 "
- "WHERE nick = '%s'",
- q_lastmask, q_lastrname, q_lastquit,
- (int) na->time_registered, (int) na->last_seen,
- (int) na->status, q_display, q_nick);
-
- /* Our previous UPDATE affected no rows, therefore this is a new record */
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_ns_alias "
- "(nick, last_usermask, last_realname, last_quit, time_registered, last_seen, status, display, active) "
- "VALUES ('%s', '%s', '%s', '%s', %d, %d, %d, '%s', 1)",
- q_nick, q_lastmask, q_lastrname, q_lastquit,
- (int) na->time_registered, (int) na->last_seen,
- (int) na->status, q_display);
- }
-
- free(q_nick);
- free(q_lastmask);
- free(q_lastrname);
- free(q_lastquit);
- free(q_display);
-
- return ret;
-}
-
-/*************************************************************************/
-
-/*
- * ChanServ Specific Secion
- */
-
-/*************************************************************************/
-
-/* Save the given ChannelInfo into the database
- * Also save the access list, levels, akicks, badwords, ttb, and memo's for this channel
- * Return 1 on success, 0 on failure
- * These tables are tagged and will be cleaned:
- * - anope_cs_info
- * - anope_cs_access
- * - anope_cs_levels
- * - anope_cs_akicks
- * - anope_cs_badwords
- * - anope_cs_ttb
- * - anope_ms_info (serv='CHAN')
- */
-int db_mysql_save_cs_info(ChannelInfo * ci)
-{
- int ret;
- int i;
- char *q_name;
- char *q_founder;
- char *q_successor;
- char *q_pass;
- char *e_pass;
- char *q_desc;
- char *q_url;
- char *q_email;
- char *q_lasttopic;
- char *q_lasttopicsetter;
- char *q_forbidby;
- char *q_forbidreason;
- char *q_mlock_key;
- char *q_mlock_flood;
- char *q_mlock_redirect;
- char *q_entrymsg;
- char *q_botnick;
- char *q_sender;
- char *q_text;
- char *q_accessdisp;
- char *q_akickdisp;
- char *q_akickreason;
- char *q_akickcreator;
- char *q_badwords;
-
- q_name = db_mysql_quote(ci->name);
- if (ci->founder) {
- q_founder = db_mysql_quote(ci->founder->display);
- } else {
- q_founder = db_mysql_quote("");
- }
- if (ci->successor) {
- q_successor = db_mysql_quote(ci->successor->display);
- } else {
- q_successor = db_mysql_quote("");
- }
- q_pass = db_mysql_quote(ci->founderpass);
- q_desc = db_mysql_quote(ci->desc);
- q_url = db_mysql_quote(ci->url);
- q_email = db_mysql_quote(ci->email);
- q_lasttopic = db_mysql_quote(ci->last_topic);
- q_lasttopicsetter = db_mysql_quote(ci->last_topic_setter);
- q_forbidby = db_mysql_quote(ci->forbidby);
- q_forbidreason = db_mysql_quote(ci->forbidreason);
- q_mlock_key = db_mysql_quote(ci->mlock_key);
- q_mlock_flood = db_mysql_quote(ci->mlock_flood);
- q_mlock_redirect = db_mysql_quote(ci->mlock_redirect);
- q_entrymsg = db_mysql_quote(ci->entry_message);
- if (ci->bi) {
- q_botnick = db_mysql_quote(ci->bi->nick);
- } else {
- q_botnick = db_mysql_quote("");
- }
-
- e_pass = db_mysql_secure(q_pass);
- free(q_pass);
-
- /* Let's take care of the core itself */
- ret = db_mysql_try("UPDATE anope_cs_info "
- "SET founder = '%s', successor = '%s', founderpass = %s, descr = '%s', url = '%s', email = '%s', time_registered = %d, "
- " last_used = %d, last_topic = '%s', last_topic_setter = '%s', last_topic_time = %d, flags = %d, forbidby = '%s', "
- " forbidreason = '%s', bantype = %d, accesscount = %d, akickcount = %d, mlock_on = %d, mlock_off = %d, mlock_limit = %d, "
- " mlock_key = '%s', mlock_flood = '%s', mlock_redirect = '%s', entry_message = '%s', memomax = %d, botnick = '%s', botflags = %d, "
- " bwcount = %d, capsmin = %d, capspercent = %d, floodlines = %d, floodsecs = %d, repeattimes = %d, active = 1 "
- "WHERE name = '%s'",
- q_founder, q_successor, e_pass, q_desc, q_url, q_email,
- (int) ci->time_registered, (int) ci->last_used,
- q_lasttopic, q_lasttopicsetter,
- (int) ci->last_topic_time, (int) ci->flags, q_forbidby,
- q_forbidreason, (int) ci->bantype,
- (int) ci->accesscount, (int) ci->akickcount,
- (int) ci->mlock_on, (int) ci->mlock_off,
- (int) ci->mlock_limit, q_mlock_key, q_mlock_flood,
- q_mlock_redirect, q_entrymsg, (int) ci->memos.memomax,
- q_botnick, (int) ci->botflags, (int) ci->bwcount,
- (int) ci->capsmin, (int) ci->capspercent,
- (int) ci->floodlines, (int) ci->floodsecs,
- (int) ci->repeattimes, q_name);
-
- /* Our previous UPDATE affected no rows, therefore this is a new record */
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_info "
- "(name, founder, successor, founderpass, descr, url, email, time_registered, last_used, last_topic, last_topic_setter, "
- " last_topic_time, flags, forbidby, forbidreason, bantype, accesscount, akickcount, mlock_on, mlock_off, mlock_limit, "
- " mlock_key, mlock_flood, mlock_redirect, entry_message, botnick, botflags, bwcount, capsmin, capspercent, floodlines, "
- " floodsecs, repeattimes, active) "
- "VALUES ('%s', '%s', '%s', %s, '%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', %d, %d, %d, %d, %d, %d, '%s', '%s', "
- " '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d, 1)",
- q_name, q_founder, q_successor, e_pass, q_desc,
- q_url, q_email, (int) ci->time_registered,
- (int) ci->last_used, q_lasttopic,
- q_lasttopicsetter, (int) ci->last_topic_time,
- (int) ci->flags, q_forbidby, q_forbidreason,
- (int) ci->bantype, (int) ci->accesscount,
- (int) ci->akickcount, (int) ci->mlock_on,
- (int) ci->mlock_off, (int) ci->mlock_limit,
- q_mlock_key, q_mlock_flood, q_mlock_redirect,
- q_entrymsg, q_botnick, (int) ci->botflags,
- (int) ci->bwcount, (int) ci->capsmin,
- (int) ci->capspercent, (int) ci->floodlines,
- (int) ci->floodsecs, (int) ci->repeattimes);
- }
-
- /* Memos */
- for (i = 0; ret && (i < ci->memos.memocount); i++) {
- q_sender = db_mysql_quote(ci->memos.memos[i].sender);
- q_text = db_mysql_quote(ci->memos.memos[i].text);
-
- ret = db_mysql_try("UPDATE anope_ms_info "
- "SET receiver = '%s', number = %d, flags = %d, time = %d, sender = '%s', text = '%s', active = 1 "
- "WHERE nm_id = %d AND serv = 'CHAN'",
- q_name, ci->memos.memos[i].number,
- ci->memos.memos[i].flags,
- (int) ci->memos.memos[i].time, q_sender, q_text,
- ci->memos.memos[i].id);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT INTO anope_ms_info "
- "(receiver, number,flags, time, sender, text, serv, active) "
- "VALUES ('%s', %d, %d, %d, '%s', '%s', 'CHAN', 1)",
- q_name, ci->memos.memos[i].number,
- ci->memos.memos[i].flags,
- (int) ci->memos.memos[i].time, q_sender,
- q_text);
-
- /* See comment at db_mysql_save_ns_core */
- if (ret)
- ci->memos.memos[i].id = mysql_insert_id(mysql);
- }
-
- free(q_sender);
- free(q_text);
- }
-
- /* Access */
- for (i = 0; ret && (i < ci->accesscount); i++) {
- if (ci->access[i].in_use) {
- q_accessdisp = db_mysql_quote(ci->access[i].nc->display);
-
- ret = db_mysql_try("UPDATE anope_cs_access "
- "SET in_use = %d, level = %d, last_seen = %d, active = 1 "
- "WHERE channel = '%s' AND display = '%s'",
- (int) ci->access[i].in_use,
- (int) ci->access[i].level,
- (int) ci->access[i].last_seen,
- q_name, q_accessdisp);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_access "
- "(channel, display, in_use, level, last_seen, active) "
- "VALUES ('%s', '%s', %d, %d, %d, 1)",
- q_name, q_accessdisp,
- (int) ci->access[i].in_use,
- (int) ci->access[i].level,
- (int) ci->access[i].last_seen);
- }
-
- free(q_accessdisp);
- }
- }
-
- /* Levels */
- for (i = 0; ret && (i < CA_SIZE); i++) {
- ret = db_mysql_try("UPDATE anope_cs_levels "
- "SET level = %d, active = 1 "
- "WHERE channel = '%s' AND position = %d",
- (int) ci->levels[i], q_name, i);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_levels "
- "(channel, position, level, active) "
- "VALUES ('%s', %d, %d, 1)",
- q_name, i, (int) ci->levels[i]);
- }
- }
-
- /* Akicks */
- for (i = 0; ret && (i < ci->akickcount); i++) {
- if (ci->akick[i].flags & AK_USED) {
- if (ci->akick[i].flags & AK_ISNICK)
- q_akickdisp = db_mysql_quote(ci->akick[i].u.nc->display);
- else
- q_akickdisp = db_mysql_quote(ci->akick[i].u.mask);
-
- q_akickreason = db_mysql_quote(ci->akick[i].reason);
- q_akickcreator = db_mysql_quote(ci->akick[i].creator);
- } else {
- q_akickdisp = "";
- q_akickreason = "";
- q_akickcreator = "";
- }
-
- ret = db_mysql_try("UPDATE anope_cs_akicks "
- "SET flags = %d, reason = '%s', creator = '%s', addtime = %d, active = 1 "
- "WHERE channel = '%s' AND dmask = '%s'",
- (int) ci->akick[i].flags, q_akickreason,
- q_akickcreator, (ci->akick[i].flags & AK_USED ?
- (int) ci->akick[i].addtime : 0),
- q_name, q_akickdisp);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_akicks "
- "(channel, dmask, flags, reason, creator, addtime, active) "
- "VALUES ('%s', '%s', %d, '%s', '%s', %d, 1)",
- q_name, q_akickdisp, (int) ci->akick[i].flags,
- q_akickreason, q_akickcreator,
- (ci->akick[i].flags & AK_USED ?
- (int) ci->akick[i].addtime : 0));
- }
-
- if (ci->akick[i].flags & AK_USED) {
- free(q_akickdisp);
- free(q_akickreason);
- free(q_akickcreator);
- }
- }
-
- /* Bad Words */
- for (i = 0; ret && (i < ci->bwcount); i++) {
- if (ci->badwords[i].in_use) {
- q_badwords = db_mysql_quote(ci->badwords[i].word);
-
- ret = db_mysql_try("UPDATE anope_cs_badwords "
- "SET type = %d, active = 1 "
- "WHERE channel = '%s' AND word = '%s'",
- (int) ci->badwords[i].type, q_name,
- q_badwords);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_badwords "
- "(channel, word, type, active) "
- "VALUES ('%s', '%s', %d, 1)",
- q_name, q_badwords,
- (int) ci->badwords[i].type);
- }
-
- free(q_badwords);
- }
- }
-
- /* TTB's */
- for (i = 0; ret && (i < TTB_SIZE); i++) {
- ret = db_mysql_try("UPDATE anope_cs_ttb "
- "SET value = %d, active = 1 "
- "WHERE channel = '%s' AND ttb_id = %d",
- ci->ttb[i], q_name, i);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_cs_ttb "
- "(channel, ttb_id, value, active) "
- "VALUES ('%s', %d, %d, 1)",
- q_name, i, ci->ttb[i]);
- }
- }
-
- free(q_name);
- free(q_founder);
- free(q_successor);
- free(e_pass);
- free(q_desc);
- free(q_url);
- free(q_email);
- free(q_lasttopic);
- free(q_lasttopicsetter);
- free(q_mlock_key);
- free(q_mlock_flood);
- free(q_mlock_redirect);
- free(q_entrymsg);
- free(q_botnick);
- free(q_forbidby);
- free(q_forbidreason);
-
- return ret;
-}
-
-/*************************************************************************/
-
-
-/*
- * OperServ Specific Section
- */
-
-/*************************************************************************/
-
-/* Save the OperServ database into MySQL
- * Return 1 on success, 0 on failure
- * These tables are tagged and will be cleaned:
- * - anope_os_akills
- * - anope_os_sglines
- * - anope_os_sqlines
- * - anope_os_szlines
- * These tables are emptied:
- * - anope_os_core
- */
-
-int db_mysql_save_os_db(unsigned int maxucnt, unsigned int maxutime,
- SList * ak, SList * sgl, SList * sql, SList * szl)
-{
- int ret;
- int i;
- Akill *akl;
- SXLine *sl;
- char *q_user;
- char *q_host;
- char *q_mask;
- char *q_by;
- char *q_reason;
-
-
- /* First save the core info */
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_core "
- "(maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) "
- "VALUES (%d, %d, %d, %d, %d, %d)",
- maxucnt, maxutime, ak->count, sgl->count, sql->count,
- szl->count);
-
- /* Next save all AKILLs */
- for (i = 0; ret && (i < ak->count); i++) {
- akl = (Akill*)ak->list[i];
- q_user = db_mysql_quote(akl->user);
- q_host = db_mysql_quote(akl->host);
- q_by = db_mysql_quote(akl->by);
- q_reason = db_mysql_quote(akl->reason);
-
- ret = db_mysql_try("UPDATE anope_os_akills "
- "SET xby = '%s', reason = '%s', seton = %d, expire = %d, active = 1 "
- "WHERE user = '%s' AND host = '%s'",
- q_by, q_reason, (int) akl->seton,
- (int) akl->expires, q_user, q_host);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_akills "
- "(user, host, xby, reason, seton, expire, active) "
- "VALUES ('%s', '%s', '%s', '%s', %d, %d, 1)",
- q_user, q_host, q_by, q_reason,
- (int) akl->seton, (int) akl->expires);
- }
-
- free(q_user);
- free(q_host);
- free(q_by);
- free(q_reason);
- }
-
- /* Time to save the SGLINEs */
- for (i = 0; ret && (i < sgl->count); i++) {
- sl = (SXLine*)sgl->list[i];
- q_mask = db_mysql_quote(sl->mask);
- q_by = db_mysql_quote(sl->by);
- q_reason = db_mysql_quote(sl->reason);
-
- ret = db_mysql_try("UPDATE anope_os_sglines "
- "SET xby = '%s', reason = '%s', seton = %d, expire = %d, active = 1 "
- "WHERE mask = '%s'",
- q_by, q_reason, (int) sl->seton, (int) sl->expires,
- q_mask);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_sglines "
- "(mask, xby, reason, seton, expire, active) "
- "VALUES ('%s', '%s', '%s', %d, %d, 1)",
- q_mask, q_by, q_reason, (int) sl->seton,
- (int) sl->expires);
- }
-
- free(q_mask);
- free(q_by);
- free(q_reason);
- }
-
- /* Save the SQLINEs */
- for (i = 0; ret && (i < sql->count); i++) {
- sl = (SXLine*)sql->list[i];
-
- q_mask = db_mysql_quote(sl->mask);
- q_by = db_mysql_quote(sl->by);
- q_reason = db_mysql_quote(sl->reason);
-
- ret = db_mysql_try("UPDATE anope_os_sqlines "
- "SET xby = '%s', reason = '%s', seton = %d, expire = %d, active = 1 "
- "WHERE mask = '%s'",
- q_by, q_reason, (int) sl->seton, (int) sl->expires,
- q_mask);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_sqlines "
- "(mask, xby, reason, seton, expire, active) "
- "VALUES ('%s', '%s', '%s', %d, %d, 1)",
- q_mask, q_by, q_reason, (int) sl->seton,
- (int) sl->expires);
- }
-
- free(q_mask);
- free(q_by);
- free(q_reason);
- }
-
- /* Now save the SZLINEs */
- for (i = 0; ret && (i < szl->count); i++) {
- sl = (SXLine*)szl->list[i];
-
- q_mask = db_mysql_quote(sl->mask);
- q_by = db_mysql_quote(sl->by);
- q_reason = db_mysql_quote(sl->reason);
-
- ret = db_mysql_try("UPDATE anope_os_szlines "
- "SET xby = '%s', reason = '%s', seton = %d, expire = %d, active = 1 "
- "WHERE mask = '%s'",
- q_by, q_reason, (int) sl->seton, (int) sl->expires,
- q_mask);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_szlines "
- "(mask, xby, reason, seton, expire, active) "
- "VALUES ('%s', '%s', '%s', %d, %d, 1)",
- q_mask, q_by, q_reason, (int) sl->seton,
- (int) sl->expires);
- }
-
- free(q_mask);
- free(q_by);
- free(q_reason);
- }
-
- return ret;
-}
-
-/*************************************************************************/
-
-/* Save the given NewsItem
- * These tables are tagged and will be cleaned:
- * - anope_os_news
- */
-int db_mysql_save_news(NewsItem * ni)
-{
- int ret;
- char *q_text;
- char *q_who;
-
- q_text = db_mysql_quote(ni->text);
- q_who = db_mysql_quote(ni->who);
-
- ret = db_mysql_try("UPDATE anope_os_news "
- "SET ntext = '%s', who = '%s', active = 1 "
- "WHERE type = %d AND num = %d AND `time` = %d",
- q_text, q_who, ni->type, ni->num, (int) ni->time);
-
- if (ret && (mysql_affected_rows(mysql) == 0)) {
- ret = db_mysql_try("INSERT DELAYED INTO anope_os_news "
- "(type, num, ntext, who, `time`, active) "
- "VALUES (%d, %d, '%s', '%s', %d, 1)",
- ni->type, ni->num, q_text, q_who, (int) ni->time);
- }
-
- free(q_text);
- free(q_who);
-
- return ret;
-}
-
-/*************************************************************************/
-
-/* Save the given Exception
- * These tables are tagged and will be cleaned:
- * - anope_os_exceptions
- */
-
-int db_mysql_save_exceptions(Exception * e)
-{
- int ret;
- char *q_mask;
- char *q_who;
- char *q_reason;
-
- q_mask = db_mysql_quote(e->mask);
- q_who = db_mysql_quote(e->who);
- q_reason = db_mysql_quote(e->reason);
-
- ret = db_mysql_try("UPDATE anope_os_exceptions "
- "SET lim = %d, who = '%s', reason = '%s', `time` = %d, expires = %d, active = 1 "
-