diff options
-rw-r--r-- | Changes | 2 | ||||
-rw-r--r-- | src/botserv.c | 7 | ||||
-rw-r--r-- | src/modules/hs_request.c | 244 | ||||
-rw-r--r-- | version.log | 6 |
4 files changed, 144 insertions, 115 deletions
@@ -51,6 +51,8 @@ Provided by Ricardo <ricardoltdb@gmail.com> - 2005 05/30 F Updated Portuguese language file. And bundled modules language. [ #00] Provided by Trystan <trystan@nomadirc.net> - 2005 +09/21 F Various fixes in hs_request. [ #00] +09/21 F NormalizeBuffer() strips CR/LF as well now. [ #00] 09/18 F Removed color codes for tools on win32. [ #00] 09/18 F MySQL detection for win32 in install.vbs had issues. [ #00] 09/18 F Memleak when AddAkiller was enabled. [ #00] diff --git a/src/botserv.c b/src/botserv.c index 3ba8cdb91..6570a75d5 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -1069,7 +1069,12 @@ char *normalizeBuffer(char *buf) } break; - + /* line feed char */ + case 10: + break; + /* carriage returns char */ + case 13: + break; /* Reverse ctrl char */ case 22: break; diff --git a/src/modules/hs_request.c b/src/modules/hs_request.c index d9dcaa28e..aff1ad5b8 100644 --- a/src/modules/hs_request.c +++ b/src/modules/hs_request.c @@ -85,8 +85,8 @@ HostCore *hs_request_head; int AnopeInit(int argc, char **argv) { Command *c; - EvtHook *hook; - + EvtHook *hook; + c = createCommand("request", hs_do_request, nick_identified, -1, -1, -1, -1, -1); moduleAddHelp(c, hs_help_request); @@ -113,35 +113,36 @@ int AnopeInit(int argc, char **argv) c = createCommand("drop", ns_do_drop, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_HEAD); - - hook = createEventHook(EVENT_DB_SAVING, hsreqevt_db_saving); - moduleAddEventHook(hook); + + hook = createEventHook(EVENT_DB_SAVING, hsreqevt_db_saving); + moduleAddEventHook(hook); moduleSetHostHelp(hs_help); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); - - my_load_config(); - my_add_languages(); + + my_load_config(); + my_add_languages(); hs_request_head = NULL; - - if (debug) - alog("[hs_request] Loading database..."); - hsreq_load_db(); + + if (debug) + alog("[hs_request] Loading database..."); + hsreq_load_db(); alog("hs_request loaded"); return MOD_CONT; } void AnopeFini(void) { - if (debug) - alog("[hs_request] Saving database..."); - hsreq_save_db(); - - /* Clean up all open host requests */ + if (debug) + alog("[hs_request] Saving database..."); + hsreq_save_db(); + + /* Clean up all open host requests */ while (hs_request_head) - hs_request_head = deleteHostCore(hs_request_head, NULL); - + hs_request_head = deleteHostCore(hs_request_head, NULL); + + free(HSRequestDBName); alog("hs_request un-loaded"); } @@ -580,113 +581,130 @@ void hs_help(User * u) } void hsreq_load_db(void) { - FILE *fp; - char *filename; - char buf[1024]; - char *nick, *vident, *vhost, *creator, *tmp; - int32 tmp_time; - - if (HSRequestDBName) - filename = HSRequestDBName; - else - filename = HSREQ_DEFAULT_DBNAME; - - fp = fopen(filename ,"r"); - if (!fp) { - alog("[hs_request] Unable to open database ('%s') for reading", filename); - return; - } - - while (fgets(buf, 1024, fp)) { - nick = myStrGetToken(buf, ':', 0); - vident = myStrGetToken(buf, ':', 1); - vhost = myStrGetToken(buf, ':', 2); - tmp = myStrGetToken(buf, ':', 3); - tmp_time = strtol(tmp, (char **)NULL, 16); - free(tmp); - creator = myStrGetToken(buf, ':', 4); - if (!nick || !vident || !vhost || !creator) { - alog("[hs_request] Error while reading database, skipping record"); - continue; - } - if (stricmp(vident, "(null)") == 0) { - free(vident); - vident = NULL; - } - my_add_host_request(nick, vident, vhost, creator, tmp_time); - free(nick); - free(vhost); - free(creator); - if (vident) - free(vident); - } - - fclose(fp); - - if (debug) - alog("[hs_request] Succesfully loaded database"); + FILE *fp; + char *filename; + char readbuf[1024]; + char *nick, *vident, *vhost, *creator, *tmp; + int32 tmp_time; + char *buf; + + if (HSRequestDBName) + filename = HSRequestDBName; + else + filename = HSREQ_DEFAULT_DBNAME; + + fp = fopen(filename, "r"); + if (!fp) { + alog("[hs_request] Unable to open database ('%s') for reading", + filename); + return; + } + + while (fgets(readbuf, 1024, fp)) { + buf = normalizeBuffer(readbuf); + if (buf || *buf) { + nick = myStrGetToken(buf, ':', 0); + vident = myStrGetToken(buf, ':', 1); + vhost = myStrGetToken(buf, ':', 2); + tmp = myStrGetToken(buf, ':', 3); + if (tmp) { + tmp_time = strtol(tmp, (char **) NULL, 16); + free(tmp); + } else { + tmp_time = 0; + } + creator = myStrGetToken(buf, ':', 4); + if (!nick || !vident || !vhost || !creator) { + alog("[hs_request] Error while reading database, skipping record"); + continue; + } + if (stricmp(vident, "(null)") == 0) { + free(vident); + vident = NULL; + } + my_add_host_request(nick, vident, vhost, creator, tmp_time); + free(nick); + free(vhost); + free(creator); + if (vident) + free(vident); + } + free(buf); + } + + fclose(fp); + + if (debug) + alog("[hs_request] Succesfully loaded database"); } void hsreq_save_db(void) { - FILE *fp; - char *filename; - char *vident; - HostCore *current; - - if (HSRequestDBName) - filename = HSRequestDBName; - else - filename = HSREQ_DEFAULT_DBNAME; - - fp = fopen(filename ,"w"); - if (!fp) { - alog("[hs_request] Unable to open database ('%s') for writing", filename); - return; - } - - current = hs_request_head; - while (current) { - vident = (current->vIdent ? current->vIdent : "(null)"); - fprintf(fp, "%s:%s:%s:%X:%s\n", current->nick, vident, current->vHost, (uint32)current->time, current->creator); - current = current->next; - } - - fclose(fp); - - if (debug) - alog("[hs_request] Succesfully saved database"); + FILE *fp; + char *filename; + char *vident; + HostCore *current; + + if (HSRequestDBName) + filename = HSRequestDBName; + else + filename = HSREQ_DEFAULT_DBNAME; + + fp = fopen(filename, "w"); + if (!fp) { + alog("[hs_request] Unable to open database ('%s') for writing", + filename); + return; + } + + current = hs_request_head; + while (current) { + vident = (current->vIdent ? current->vIdent : "(null)"); + fprintf(fp, "%s:%s:%s:%X:%s\n", current->nick, vident, + current->vHost, (uint32) current->time, current->creator); + current = current->next; + } + + fclose(fp); + + if (debug) + alog("[hs_request] Succesfully saved database"); } int hsreqevt_db_saving(int argc, char **argv) { - if ((argc >= 1) && (stricmp(argv[0], EVENT_START) == 0)) - hsreq_save_db(); - - return MOD_CONT; + if ((argc >= 1) && (stricmp(argv[0], EVENT_START) == 0)) + hsreq_save_db(); + + return MOD_CONT; } void my_load_config(void) { - int i; - char *tmp = NULL; - + int i; + char *tmp = NULL; + Directive confvalues[][1] = { - {{"HSRequestMemoUser", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoUser}}}}, - {{"HSRequestMemoOper", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoOper}}}}, - {{"HSRequestMemoSetters", {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoSetters}}}}, - {{"HSRequestDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}} + {{"HSRequestMemoUser", + {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoUser}}}}, + {{"HSRequestMemoOper", + {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoOper}}}}, + {{"HSRequestMemoSetters", + {{PARAM_SET, PARAM_RELOAD, &HSRequestMemoSetters}}}}, + {{"HSRequestDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}} }; - - for (i = 0; i < 4; i++) - moduleGetConfigDirective(confvalues[i]); - - if (tmp) { - if (HSRequestDBName) - free(HSRequestDBName); - HSRequestDBName = tmp; - } - + + for (i = 0; i < 4; i++) + moduleGetConfigDirective(confvalues[i]); + + if (tmp) { + if (HSRequestDBName) + free(HSRequestDBName); + HSRequestDBName = sstrdup(tmp); + } else { + HSRequestDBName = sstrdup(HSREQ_DEFAULT_DBNAME); + } + if (debug) alog("debug: [hs_request] Set config vars: MemoUser=%d MemoOper=%d MemoSetters=%d DBName='%s'", HSRequestMemoUser, HSRequestMemoOper, HSRequestMemoSetters, HSRequestDBName); } @@ -895,7 +913,7 @@ void my_add_languages(void) moduleInsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); moduleInsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); moduleInsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); - moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); + moduleInsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); } /* EOF */ diff --git a/version.log b/version.log index d4adf9790..9b504f3f2 100644 --- a/version.log +++ b/version.log @@ -9,10 +9,14 @@ VERSION_MAJOR="1" VERSION_MINOR="7" VERSION_PATCH="11" VERSION_EXTRA="-rc2" -VERSION_BUILD="891" +VERSION_BUILD="892" # $Log$ # +# BUILD : 1.7.11 (892) +# BUGS : +# NOTES : Applied patch by Trystan to [1] strip CR/LF as well with normalizeBuffer() [2] fix various issues with hs_request (makes use of #1 in hs_request so that lines that are \n only are not processed; Adds check of tmp before allowing strtol() to get its hands on it; HSRequestDBName is set during the config load, if not by the config its sstrdup() with the default value.. so that the message at the end of the load does not read (NULL); frees the HSRequestDBName on unload; ran indent again it) +# # BUILD : 1.7.11 (891) # BUGS : # NOTES : Fixed bot ident length checking and sending a reponse when loading a non-existing module |