diff options
| author | geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2006-12-23 13:25:01 +0000 |
|---|---|---|
| committer | geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2006-12-23 13:25:01 +0000 |
| commit | 6e7add309dd9d985666e1107bd5c840faa881137 (patch) | |
| tree | 8d8313bcb0d1ca4e7b2ffe8cdc4597d88498cd38 | |
| parent | ee5559be07a5c5de2d870f3bc27cd2fb95b9f30b (diff) | |
BUILD : 1.7.17 (1209) BUGS : NOTES : Another batch of changes regarding RDB/MySQL; all functions are now doing proper error reporting; errors are not yet handled properly
git-svn-id: svn://svn.anope.org/anope/trunk@1209 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@928 5417fbe8-f217-4b02-8779-1006273d7864
| -rw-r--r-- | include/extern.h | 63 | ||||
| -rw-r--r-- | src/botserv.c | 4 | ||||
| -rw-r--r-- | src/mysql.c | 1207 | ||||
| -rw-r--r-- | src/nickserv.c | 6 | ||||
| -rw-r--r-- | src/rdb.c | 262 | ||||
| -rw-r--r-- | version.log | 6 |
6 files changed, 864 insertions, 684 deletions
diff --git a/include/extern.h b/include/extern.h index a064e3678..0c82d7b10 100644 --- a/include/extern.h +++ b/include/extern.h @@ -502,21 +502,21 @@ E int rdb_clean_table_where(char *table, char *clause); E int rdb_scrub_table(char *table, char *clause); E int rdb_direct_query(char *query); E int rdb_ns_set_display(char *newnick, char *oldnick); -E void rdb_save_ns_core(NickCore * nc); -E void rdb_save_ns_alias(NickAlias * na); -E void rdb_save_ns_req(NickRequest * nr); -E void rdb_save_cs_info(ChannelInfo * ci); -E void rdb_save_bs_core(BotInfo * bi); -E void rdb_save_bs_rdb_core(BotInfo * bi); -E void rdb_save_hs_core(HostCore * hc); -E void rdb_save_os_db(unsigned int maxucnt, unsigned int maxutime, +E int rdb_save_ns_core(NickCore * nc); +E int rdb_save_ns_alias(NickAlias * na); +E int rdb_save_ns_req(NickRequest * nr); +E int rdb_save_cs_info(ChannelInfo * ci); +E int rdb_save_bs_core(BotInfo * bi); +E int rdb_save_bs_rdb_core(BotInfo * bi); +E int rdb_save_hs_core(HostCore * hc); +E int rdb_save_os_db(unsigned int maxucnt, unsigned int maxutime, SList * ak, SList * sgl, SList * sql, SList * szl); -E void rdb_save_news(NewsItem * ni); -E void rdb_save_exceptions(Exception * e); -E void rdb_load_bs_dbase(void); -E void rdb_load_hs_dbase(void); -E void rdb_load_ns_dbase(void); -E void rdb_load_dbases(void); +E int rdb_save_news(NewsItem * ni); +E int rdb_save_exceptions(Exception * e); +E int rdb_load_bs_dbase(void); +E int rdb_load_hs_dbase(void); +E int rdb_load_ns_dbase(void); +E int rdb_load_dbases(void); #endif #ifdef USE_MYSQL @@ -1149,25 +1149,26 @@ E int db_mysql_open(); E int db_mysql_close(); E int db_mysql_query(char *sql); E char *db_mysql_quote(char *sql); -E void db_mysql_save_ns_core(NickCore * nc); -E void db_mysql_save_ns_alias(NickAlias * na); -E void db_mysql_save_ns_req(NickRequest * nr); -E void db_mysql_save_cs_info(ChannelInfo * ci); -E void db_mysql_save_os_db(unsigned int maxucnt, unsigned int maxutime, +E int db_mysql_try(const char *fmt, ...); +E int db_mysql_save_ns_core(NickCore * nc); +E int db_mysql_save_ns_alias(NickAlias * na); +E int db_mysql_save_ns_req(NickRequest * nr); +E int db_mysql_save_cs_info(ChannelInfo * ci); +E int db_mysql_save_os_db(unsigned int maxucnt, unsigned int maxutime, SList * ak, SList * sgl, SList * sql, SList * szl); -E void db_mysql_save_news(NewsItem * ni); -E void db_mysql_save_exceptions(Exception * e); -E void db_mysql_save_hs_core(HostCore * hc); -E void db_mysql_save_bs_core(BotInfo * bi); -E void db_mysql_load_bs_dbase(void); -E void db_mysql_load_hs_dbase(void); -E void db_mysql_load_ns_dbase(void); -E void db_mysql_load_ns_req_dbase(void); -E void db_mysql_load_cs_dbase(void); -E void db_mysql_load_os_dbase(void); -E void db_mysql_load_exceptions(void); -E void db_mysql_load_news(void); +E int db_mysql_save_news(NewsItem * ni); +E int db_mysql_save_exceptions(Exception * e); +E int db_mysql_save_hs_core(HostCore * hc); +E int db_mysql_save_bs_core(BotInfo * bi); +E int db_mysql_load_bs_dbase(void); +E int db_mysql_load_hs_dbase(void); +E int db_mysql_load_ns_dbase(void); +E int db_mysql_load_ns_req_dbase(void); +E int db_mysql_load_cs_dbase(void); +E int db_mysql_load_os_dbase(void); +E int db_mysql_load_exceptions(void); +E int db_mysql_load_news(void); E unsigned int mysql_rand(void); #endif diff --git a/src/botserv.c b/src/botserv.c index 7997d866d..e416be46f 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -831,7 +831,7 @@ static void check_ban(ChannelInfo * ci, User * u, int ttbtype) av[2] = mask; anope_cmd_mode(ci->bi->nick, av[0], "+b %s", av[2]); do_cmode(ci->bi->nick, 3, av); - send_event(EVENT_BOT_BAN,3,u->nick, ci->name, mask); + send_event(EVENT_BOT_BAN, 3, u->nick, ci->name, mask); free(av[1]); } } @@ -862,7 +862,7 @@ static void bot_kick(ChannelInfo * ci, User * u, int message, ...) av[2] = buf; anope_cmd_kick(ci->bi->nick, av[0], av[1], "%s", av[2]); do_kick(ci->bi->nick, 3, av); - send_event(EVENT_BOT_KICK,3,u->nick,ci->name,buf); + send_event(EVENT_BOT_KICK, 3, u->nick, ci->name, buf); } /*************************************************************************/ diff --git a/src/mysql.c b/src/mysql.c index c5016aa2a..99f147bff 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -89,7 +89,7 @@ int db_mysql_init() /*************************************************************************/ /* Open a connection to the mysql database. Return 0 on failure, or - * 0 on success. If this succeeds, we're guaranteed of a working + * 1 on success. If this succeeds, we're guaranteed of a working * mysql connection (unless something unexpected happens ofcourse...) */ int db_mysql_open() @@ -98,10 +98,14 @@ int db_mysql_open() if (!do_mysql) return 0; - /* If we're already connected, return 1 */ - if (mysql_is_connected) + /* 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"); @@ -110,23 +114,10 @@ int db_mysql_open() if (!MysqlPort) MysqlPort = MYSQL_DEFAULT_PORT; - - if (MysqlSock) { - 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; - } - } else { - if ((!mysql_real_connect - (mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, - NULL, 0))) { - log_perror("MySQL Error: Cant connect to MySQL: %s\n", - mysql_error(mysql)); - return 0; - } + + 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; @@ -135,48 +126,39 @@ int db_mysql_open() } + /*************************************************************************/ -/* Perform a MySQL query. Return 0 if the query succeeded, or something - * else, like 1, if it failed. Before returning failure, re-try the - * query a few times and die if it fails after a few tries. +/* 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) { - /* Error is 1 */ - return 1; - } + if (!do_mysql) + return 0; - if (debug) { + 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))) { - - /* Success is 0 */ - return 0; - - } + 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 */ - db_mysql_error(MYSQL_ERROR, "query"); + /* Unable to run the query even after MysqlRetries tries */ + db_mysql_error(MYSQL_WARNING, "query"); - /* Error is 1 */ - return 1; + return 0; } @@ -198,6 +180,7 @@ char *db_mysql_quote(char *sql) quoted = malloc((1 + (slen * 2)) * sizeof(char)); mysql_real_escape_string(mysql, quoted, sql, slen); + return quoted; } @@ -216,8 +199,10 @@ int db_mysql_close() /*************************************************************************/ -/* Try to execute a query and issue a warning when failed */ -void db_mysql_try(const char *fmt, ...) +/* 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]; @@ -226,10 +211,13 @@ void db_mysql_try(const char *fmt, ...) vsnprintf(sql, MAX_SQL_BUF, fmt, args); va_end(args); - if (db_mysql_query(sql)) { + if (!db_mysql_query(sql)) { log_perror("Can't create sql query: %s", sql); - db_mysql_error(MYSQL_ERROR, "query"); + db_mysql_error(MYSQL_WARNING, "query"); + return 0; } + + return 1; } /*************************************************************************/ @@ -237,6 +225,8 @@ void db_mysql_try(const char *fmt, ...) /* 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) { @@ -278,11 +268,13 @@ char *db_mysql_secure(char *pass) /*************************************************************************/ /* 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 */ -void db_mysql_save_ns_req(NickRequest * nr) +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); @@ -290,36 +282,42 @@ void db_mysql_save_ns_req(NickRequest * nr) q_password = db_mysql_quote(nr->password); q_email = db_mysql_quote(nr->email); - 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); + 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 (mysql_affected_rows(mysql) == 0) { - 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); - } + 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') */ -void db_mysql_save_ns_core(NickCore * nc) +int db_mysql_save_ns_core(NickCore * nc) { + int ret; int i; char **access; Memo *memos; @@ -337,70 +335,74 @@ void db_mysql_save_ns_core(NickCore * nc) /* Let's take care of the core itself */ /* Update the existing records */ - 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, channelmax = %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, - nc->channelmax, q_display); + 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, channelmax = %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, nc->channelmax, + q_display); /* Our previous UPDATE affected no rows, therefore this is a new record */ - if (mysql_affected_rows(mysql) == 0) { - db_mysql_try - ("INSERT DELAYED INTO anope_ns_core (display, pass, email, greet, icq, " - "url, flags, language, accesscount, memocount, memomax, " - "channelcount, channelmax, 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, nc->channelmax); + 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, channelmax, 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, nc->channelmax); } /* Now let's do the access */ - for (i = 0; i < nc->accesscount; i++) { + for (i = 0; ret && (i < nc->accesscount); i++) { q_access = db_mysql_quote(nc->access[i]); - db_mysql_try - ("UPDATE anope_ns_access SET access = '%s' WHERE display = '%s'", - q_access, q_display); + ret = db_mysql_try("UPDATE anope_ns_access " + "SET access = '%s' " + "WHERE display = '%s'", + q_access, q_display); - if (mysql_affected_rows(mysql) == 0) { - db_mysql_try - ("INSERT DELAYED INTO anope_ns_access (display, access) " - "VALUES ('%s','%s')", q_display, q_access); + 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; i < nc->memos.memocount; i++) { + 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); - 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 (mysql_affected_rows(mysql) == 0) { - 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); + 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 */ - nc->memos.memos[i].id = mysql_insert_id(mysql); + if (ret) + nc->memos.memos[i].id = mysql_insert_id(mysql); } free(q_sender); @@ -412,20 +414,24 @@ void db_mysql_save_ns_core(NickCore * nc) 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') */ -void db_mysql_save_ns_alias(NickAlias * na) +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); @@ -434,22 +440,22 @@ void db_mysql_save_ns_alias(NickAlias * na) q_lastquit = db_mysql_quote(na->last_quit); q_display = db_mysql_quote(na->nc->display); - 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); + 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 (mysql_affected_rows(mysql) == 0) { - 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); + 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); @@ -457,6 +463,8 @@ void db_mysql_save_ns_alias(NickAlias * na) free(q_lastrname); free(q_lastquit); free(q_display); + + return ret; } /*************************************************************************/ @@ -469,6 +477,7 @@ void db_mysql_save_ns_alias(NickAlias * na) /* 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 @@ -478,8 +487,9 @@ void db_mysql_save_ns_alias(NickAlias * na) * - anope_cs_ttb * - anope_ms_info (serv='CHAN') */ -void db_mysql_save_cs_info(ChannelInfo * ci) +int db_mysql_save_cs_info(ChannelInfo * ci) { + int ret; int i; Memo *memos; char *q_name; @@ -540,78 +550,76 @@ void db_mysql_save_cs_info(ChannelInfo * ci) free(q_pass); /* Let's take care of the core itself */ - 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); + 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 (mysql_affected_rows(mysql) == 0) { - 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); + 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; i < ci->memos.memocount; i++) { + 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); - 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 (mysql_affected_rows(mysql) == 0) { - 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); + 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 */ - ci->memos.memos[i].id = mysql_insert_id(mysql); + if (ret) + ci->memos.memos[i].id = mysql_insert_id(mysql); } free(q_sender); @@ -619,41 +627,49 @@ void db_mysql_save_cs_info(ChannelInfo * ci) } /* Access */ - for (i = 0; i < ci->accesscount; i++) { + for (i = 0; ret && (i < ci->accesscount); i++) { if (ci->access[i].in_use) { q_accessdisp = db_mysql_quote(ci->access[i].nc->display); - 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 (mysql_affected_rows(mysql) == 0) { - 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); + + 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; i < CA_SIZE; i++) { - 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 (mysql_affected_rows(mysql) == 0) { - 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]); + 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; i < ci->akickcount; i++) { + 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); @@ -668,22 +684,22 @@ void db_mysql_save_cs_info(ChannelInfo * ci) q_akickcreator = ""; } - 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 (mysql_affected_rows(mysql) == 0) { - 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)); + 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) { @@ -694,19 +710,22 @@ void db_mysql_save_cs_info(ChannelInfo * ci) } /* Bad Words */ - for (i = 0; i < ci->bwcount; i++) { + for (i = 0; ret && (i < ci->bwcount); i++) { if (ci->badwords[i].in_use) { q_badwords = db_mysql_quote(ci->badwords[i].word); - 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 (mysql_affected_rows(mysql) == 0) { - 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); + ret = db_mysql_try("UPDATE anope_cs_badwords " + "SET type = %d, active = 1 " |
