summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-09-19 10:28:02 +0000
committerrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2004-09-19 10:28:02 +0000
commitfe0992a6aba0a7a95b666ecb52df8ce1a6d5a723 (patch)
tree5d45b54d05662b624b86a12bf94bd586bf77e68a /src
parentaa896a87ac4705a5a8a26cbf5ddae2db3fc54c62 (diff)
BUILD : 1.7.5 (351) BUGS : N/A NOTES : Rewrote the internals of moduleData, this will save _lots_ of memory especially on larger networks. The downside is modules using it need to make a tiny, tiny change... :/
git-svn-id: svn://svn.anope.org/anope/trunk@351 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@227 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/chanserv.c8
-rw-r--r--src/main.c9
-rw-r--r--src/memoserv.c7
-rw-r--r--src/modules.c329
-rw-r--r--src/mysql.c8
-rw-r--r--src/nickserv.c14
-rw-r--r--src/operserv.c2
-rw-r--r--src/users.c2
9 files changed, 181 insertions, 200 deletions
diff --git a/src/Makefile b/src/Makefile
index 3465c8e47..7db726aa3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,7 @@ INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \
../include/pseudo.h ../include/sysconf.h ../include/config.h \
../include/encrypt.h ../include/messages.h ../include/services.h \
../include/timeout.h ../include/datafiles.h ../include/extern.h \
- ../include/modules.h ../include/slist.h ../include/version.h \
+ ../include/modules.h ../include/slist.h \
../include/dreamforge.h ../include/bahamut.h ../include/ultimate2.h \
../include/ultimate3.h ../include/hybrid.h ../include/ptlink.h ../include/unreal31.h \
../include/viagra.h ../include/rageircd.h ../include/unreal32.h
diff --git a/src/chanserv.c b/src/chanserv.c
index 4a1ad524b..e210ac5ac 100644
--- a/src/chanserv.c
+++ b/src/chanserv.c
@@ -912,9 +912,7 @@ void load_cs_dbase(void)
memos->time = tmp32;
SAFE(read_buffer(memos->sender, f));
SAFE(read_string(&memos->text, f));
- for (m = 0; m < MAX_CMD_HASH; m++) {
- memos->moduleData[m] = NULL;
- }
+ memos->moduleData = NULL;
}
}
@@ -2097,7 +2095,7 @@ int delchan(ChannelInfo * ci)
for (i = 0; i < ci->memos.memocount; i++) {
if (ci->memos.memos[i].text)
free(ci->memos.memos[i].text);
- moduleCleanStruct(ci->memos.memos[i].moduleData);
+ moduleCleanStruct(&ci->memos.memos[i].moduleData);
}
free(ci->memos.memos);
}
@@ -2110,7 +2108,7 @@ int delchan(ChannelInfo * ci)
if (ci->badwords)
free(ci->badwords);
- moduleCleanStruct(ci->moduleData);
+ moduleCleanStruct(&ci->moduleData);
free(ci);
if (nc)
diff --git a/src/main.c b/src/main.c
index bc7bb6672..15660e2fc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -75,6 +75,15 @@ time_t start_time;
/* Parameters and environment */
char **my_av, **my_envp;
+/* Moved here from version.h */
+const char version_number[] = VERSION_STRING;
+const char version_build[] =
+ "build #" BUILD ", compiled " __DATE__ " " __TIME__;
+/* the space is needed cause if you build with nothing it will complain */
+const char version_flags[] =
+ " " VER_DEBUG VER_ENCRYPTION VER_THREAD VER_OS VER_GHBNR VER_MYSQL
+ VER_MODULE;
+
/******** Local variables! ********/
/* Set to 1 if we are waiting for input */
diff --git a/src/memoserv.c b/src/memoserv.c
index e182f0535..716f1a1bc 100644
--- a/src/memoserv.c
+++ b/src/memoserv.c
@@ -192,7 +192,7 @@ static int delmemo(MemoInfo * mi, int num)
break;
}
if (i < mi->memocount) {
- moduleCleanStruct(mi->memos[i].moduleData);
+ moduleCleanStruct(&mi->memos[i].moduleData);
free(mi->memos[i].text); /* Deallocate memo text memory */
mi->memocount--; /* One less memo now */
if (i < mi->memocount) /* Move remaining memos down a slot */
@@ -315,8 +315,7 @@ void memo_send(User * u, char *name, char *text, int z)
mi->memos = srealloc(mi->memos, sizeof(Memo) * mi->memocount);
m = &mi->memos[mi->memocount - 1];
strscpy(m->sender, source, NICKMAX);
- for (j = 0; j < MAX_CMD_HASH; j++)
- m->moduleData[j] = NULL;
+ m->moduleData = NULL;
if (mi->memocount > 1) {
m->number = m[-1].number + 1;
if (m->number < 1) {
@@ -786,7 +785,7 @@ static int do_del(User * u)
/* Delete all memos. */
for (i = 0; i < mi->memocount; i++) {
free(mi->memos[i].text);
- moduleCleanStruct(mi->memos[i].moduleData);
+ moduleCleanStruct(&mi->memos[i].moduleData);
}
free(mi->memos);
mi->memos = NULL;
diff --git a/src/modules.c b/src/modules.c
index 7ddf164b6..eca88077f 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -14,6 +14,7 @@
*/
#include "modules.h"
#include "language.h"
+#include "version.h"
#ifdef USE_MODULES
#include <dlfcn.h>
@@ -1749,6 +1750,24 @@ void moduleDisplayHelp(int service, User * u)
}
/**
+ * Output module data information into the log file.
+ * This is a vwey "debug only" function to dump the whole contents
+ * of a moduleData struct into the log files.
+ * @param md The module data for the struct to be used
+ * @return 0 is always returned;
+ **/
+int moduleDataDebug(ModuleData **md) {
+ ModuleData *current = NULL;
+ alog("Dumping module data....");
+ for (current = *md; current; current = current->next) {
+ alog("Module: [%s]",current->moduleName);
+ alog(" Key [%s]\tValue [%s]",current->key, current->value);
+ }
+ alog("End of module data dump");
+ return 0;
+}
+
+/**
* Add module data to a struct.
* This allows module coders to add data to an existing struct
* @param md The module data for the struct to be used
@@ -1756,72 +1775,40 @@ void moduleDisplayHelp(int service, User * u)
* @param value The value for the key/value pair, this is what will be stored for you
* @return MOD_ERR_OK will be returned on success
**/
-int moduleAddData(ModuleData * md[], char *key, char *value)
+int moduleAddData(ModuleData **md, char *key, char *value)
{
- char *mod_name = sstrdup(mod_current_module_name);
-
- int index = 0;
- ModuleData *current = NULL;
- ModuleData *newHash = NULL;
- ModuleData *lastHash = NULL;
- ModuleDataItem *item = NULL;
- ModuleDataItem *itemCurrent = NULL;
- ModuleDataItem *lastItem = NULL;
- index = CMD_HASH(mod_name);
-
- if (!key || !value) {
- alog("A module tried to use ModuleAddData() with one ore more NULL arguments... returning");
- return MOD_ERR_PARAMS;
- }
-
- for (current = md[index]; current; current = current->next) {
- if (stricmp(current->moduleName, mod_name) == 0)
- lastHash = current;
- }
-
- if (!lastHash) {
- newHash = malloc(sizeof(ModuleData));
- if (!newHash) {
- return MOD_ERR_MEMORY;
- }
- newHash->next = NULL;
- newHash->di = NULL;
- newHash->moduleName = strdup(mod_name);
- md[index] = newHash;
- lastHash = newHash;
- }
-
- /**
- * Ok, at this point lastHash will always be a valid ModuleData struct, and will always be "our" module Data Struct
- **/
- for (itemCurrent = lastHash->di; itemCurrent;
- itemCurrent = itemCurrent->next) {
- if (stricmp(itemCurrent->key, key) == 0) {
- item = itemCurrent;
- }
- lastItem = itemCurrent;
- }
- if (!item) {
- item = malloc(sizeof(ModuleDataItem));
- if (!item) {
- return MOD_ERR_MEMORY;
- }
- item->next = NULL;
- item->key = strdup(key);
- item->value = strdup(value);
- if (lastItem)
- lastItem->next = item;
- else
- lastHash->di = item;
- } else {
- free(item->key);
- free(item->value);
- item->key = strdup(key);
- item->value = strdup(value);
- }
- free(mod_name);
- return MOD_ERR_OK;
-
+ char *mod_name = sstrdup(mod_current_module_name);
+ ModuleData *newData=NULL;
+ ModuleData *tmp = *md;
+
+ if ( !key || !value ) {
+ alog("A module tried to use ModuleAddData() with one ore more NULL arguments... returning");
+ return MOD_ERR_PARAMS;
+ }
+
+ moduleDelData(md,key); /* Remove any existing module data for this module with the same key */
+
+ newData = malloc(sizeof(ModuleData));
+ if(!newData) {
+ return MOD_ERR_MEMORY;
+ }
+
+ newData->moduleName = sstrdup(mod_name);
+ newData->key = sstrdup(key);
+ newData->value = sstrdup(value);
+ if(tmp) {
+ newData->next = tmp->next;
+ } else {
+ newData->next = NULL;
+ }
+ *md = newData;
+
+ free(mod_name);
+
+ if(debug) {
+ moduleDataDebug(md);
+ }
+ return MOD_ERR_OK;
}
/**
@@ -1831,33 +1818,17 @@ int moduleAddData(ModuleData * md[], char *key, char *value)
* @param key The key to find the data for
* @return the value paired to the given key will be returned, or NULL
**/
-char *moduleGetData(ModuleData * md[], char *key)
+char *moduleGetData(ModuleData **md, char *key)
{
char *mod_name = sstrdup(mod_current_module_name);
- int index = 0;
- char *ret = NULL;
- ModuleData *current = NULL;
- ModuleData *lastHash = NULL;
- ModuleDataItem *itemCurrent = NULL;
- index = CMD_HASH(mod_name);
- if (!md) {
- return NULL;
- }
- for (current = md[index]; current; current = current->next) {
- if (stricmp(current->moduleName, mod_name) == 0)
- lastHash = current;
- }
-
- if (lastHash) {
- for (itemCurrent = lastHash->di; itemCurrent;
- itemCurrent = itemCurrent->next) {
- if (strcmp(itemCurrent->key, key) == 0) {
- ret = strdup(itemCurrent->value);
- }
- }
+ ModuleData *current = *md;
+ while(current) {
+ if((stricmp(current->moduleName,mod_name)==0) && (stricmp(current->key,key)==0)) {
+ return sstrdup(current->value);
+ }
}
free(mod_name);
- return ret;
+ return NULL;
}
/**
@@ -1866,39 +1837,31 @@ char *moduleGetData(ModuleData * md[], char *key)
* @param md The module data for the struct to be used
* @param key The key to delete the key/value pair for
**/
-void moduleDelData(ModuleData * md[], char *key)
+void moduleDelData(ModuleData **md, char *key)
{
char *mod_name = sstrdup(mod_current_module_name);
- int index = 0;
- ModuleData *current = NULL;
- ModuleData *lastHash = NULL;
-
- ModuleDataItem *itemCurrent = NULL;
- ModuleDataItem *prev = NULL;
- ModuleDataItem *next = NULL;
- index = CMD_HASH(mod_name);
-
- for (current = md[index]; current; current = current->next) {
- if (stricmp(current->moduleName, mod_name) == 0)
- lastHash = current;
- }
- if (lastHash) {
- for (itemCurrent = lastHash->di; itemCurrent; itemCurrent = next) {
- next = itemCurrent->next;
- if (strcmp(key, itemCurrent->key) == 0) {
- free(itemCurrent->key);
- free(itemCurrent->value);
- itemCurrent->next = NULL;
- free(itemCurrent);
- if (prev) {
- prev->next = next;
- } else {
- lastHash->di = next;
- }
- } else {
- prev = itemCurrent;
- }
- }
+ ModuleData *current = *md;
+ ModuleData *prev = NULL;
+ ModuleData *next = NULL;
+
+ if(key) {
+ while(current) {
+ next = current->next;
+ if((stricmp(current->moduleName,mod_name)==0) && (stricmp(current->key,key)==0)) {
+ if(prev) {
+ prev->next = current->next;
+ } else {
+ *md = current->next;
+ }
+ free(current->moduleName);
+ free(current->key);
+ free(current->value);
+ current->next = NULL;
+ free(current);
+ }
+ prev = current;;
+ current = next;
+ }
}
free(mod_name);
}
@@ -1909,35 +1872,29 @@ void moduleDelData(ModuleData * md[], char *key)
* do just about anything and everything, its safe to use from inside the module.
* @param md The module data for the struct to be used
**/
-void moduleDelAllData(ModuleData * md[])
+void moduleDelAllData(ModuleData **md)
{
char *mod_name = sstrdup(mod_current_module_name);
- int index = 0;
- ModuleData *current = NULL;
- ModuleData *lastHash = NULL;
-
- ModuleDataItem *itemCurrent = NULL;
- ModuleDataItem *prev = NULL;
- ModuleDataItem *next = NULL;
- index = CMD_HASH(mod_name);
-
- for (current = md[index]; current; current = current->next) {
- if (stricmp(current->moduleName, mod_name) == 0)
- lastHash = current;
- }
- if (lastHash) {
- for (itemCurrent = lastHash->di; itemCurrent; itemCurrent = next) {
- next = itemCurrent->next;
- free(itemCurrent->key);
- free(itemCurrent->value);
- itemCurrent->next = NULL;
- free(itemCurrent);
- if (prev) {
- prev->next = next;
- } else {
- lastHash->di = next;
- }
- }
+ ModuleData *current = *md;
+ ModuleData *prev = NULL;
+ ModuleData *next = NULL;
+
+ while(current) {
+ next = current->next;
+ if((stricmp(current->moduleName,mod_name)==0)) {
+ if(prev) {
+ prev->next = current->next;
+ } else {
+ *md = current->next;
+ }
+ free(current->moduleName);
+ free(current->key);
+ free(current->value);
+ current->next = NULL;
+ free(current);
+ }
+ prev = current;;
+ current = next;
}
free(mod_name);
}
@@ -1946,7 +1903,7 @@ void moduleDelAllData(ModuleData * md[])
* This will delete all module data used in any struct by module m.
* @param m The module to clear all data for
**/
-void moduleDelAllDataMod(Module * m)
+void moduleDelAllDataMod(Module *m)
{
boolean freeme = false;
int i, j;
@@ -1963,29 +1920,29 @@ void moduleDelAllDataMod(Module * m)
for (i = 0; i < 1024; i++) {
/* Remove the users */
for (user = userlist[i]; user; user = user->next) {
- moduleDelAllData(user->moduleData);
+ moduleDelAllData(&user->moduleData);
}
/* Remove the nick Cores */
for (nc = nclists[i]; nc; nc = nc->next) {
- moduleDelAllData(nc->moduleData);
+ moduleDelAllData(&nc->moduleData);
/* Remove any memo data for this nick core */
for (j = 0; j < nc->memos.memocount; j++) {
- moduleCleanStruct(nc->memos.memos[j].moduleData);
+ moduleCleanStruct(&nc->memos.memos[j].moduleData);
}
}
/* Remove the nick Aliases */
for (na = nalists[i]; na; na = na->next) {
- moduleDelAllData(na->moduleData);
+ moduleDelAllData(&na->moduleData);
}
}
for (i = 0; i < 256; i++) {
/* Remove any chan info data */
for (ci = chanlists[i]; ci; ci = ci->next) {
- moduleDelAllData(ci->moduleData);
+ moduleDelAllData(&ci->moduleData);
/* Remove any memo data for this nick core */
for (j = 0; j < ci->memos.memocount; j++) {
- moduleCleanStruct(ci->memos.memos[j].moduleData);
+ moduleCleanStruct(&ci->memos.memos[j].moduleData);
}
}
}
@@ -1997,30 +1954,56 @@ void moduleDelAllDataMod(Module * m)
}
/**
- * Remove any data fro many module used in the given struct.
+ * Remove any data from any module used in the given struct.
* Useful for cleaning up when a User leave's the net, a NickCore is deleted, etc...
* @param moduleData the moduleData struct to "clean"
**/
-void moduleCleanStruct(ModuleData * moduleData[])
-{
- ModuleData *md = NULL, *nextMd = NULL;
- ModuleDataItem *item = NULL, *nextItem = NULL;
- int i;
+void moduleCleanStruct(ModuleData **moduleData) {
+ ModuleData *current = *moduleData;;
+ ModuleData *next = NULL;
+
+ while(current) {
+ next = current->next;
+ free(current->moduleName);
+ free(current->key);
+ free(current->value);
+ current->next = NULL;
+ free(current);
+ current = next;
+ }
+ *moduleData = NULL;
+}
- for (i = 0; i < 1024; i++) {
- for (md = moduleData[i]; md; md = nextMd) {
- nextMd = md->next;
- for (item = md->di; item; item = nextItem) {
- nextItem = item->next;
- free(item->key);
- free(item->value);
- item->next = NULL;
- free(item);
- }
- free(md->moduleName);
- free(md);
- }
- }
+/**
+ * Check the current version of anope against a given version number
+ * Specifiying -1 for minor,patch or build
+ * @param major The major version of anope, the first part of the verison number
+ * @param minor The minor version of anope, the second part of the version number
+ * @param patch The patch version of anope, the third part of the version number
+ * @param build The build revision of anope from SVN
+ * @return True if the version newer than the version specified.
+ **/
+boolean moduleMinVersion(int major,int minor,int patch,int build) {
+ boolean ret=false;
+ if(VERSION_MAJOR>major) { // Def. new
+ ret = true;
+ } else if(VERSION_MAJOR == major) { // Might be newer
+ if(minor == -1) { return true; } // They dont care about minor
+ if(VERSION_MINOR > minor) { // Def. newer
+ ret = true;
+ } else if(VERSION_MINOR == minor) { // Might be newer
+ if(patch == -1) { return true; } // They dont care about patch
+ if(VERSION_PATCH > patch) {
+ ret = true;
+ } else if(VERSION_PATCH == patch) {
+ if(build == -1) { return true; } // They dont care about build
+ if(VERSION_BUILD >= build) {
+ ret = true;
+ }
+ }
+ }
+ }
+ return ret;
}
/* EOF */
diff --git a/src/mysql.c b/src/mysql.c
index 896eb9216..d0771faa0 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -1331,9 +1331,7 @@ void db_mysql_load_cs_dbase(void)
memos->time = atoi(row[2]);
snprintf(memos->sender, NICKMAX, "%s", row[3]);
memos->text = sstrdup(row[4]);
- for (m = 0; m < MAX_CMD_HASH; m++) {
- memos->moduleData[m] = NULL;
- }
+ memos->moduleData = NULL;
memos++;
}
}
@@ -1545,9 +1543,7 @@ void db_mysql_load_ns_dbase(void)
memos->time = atoi(row[2]);
snprintf(memos->sender, NICKMAX, "%s", row[3]);
memos->text = sstrdup(row[4]);
- for (m = 0; m < MAX_CMD_HASH; m++) {
- memos->moduleData[m] = NULL;
- }
+ memos->moduleData = NULL;
memos++;
}
mysql_free_result(res);
diff --git a/src/nickserv.c b/src/nickserv.c
index a654cf65a..1ca4a90e7 100644
--- a/src/nickserv.c
+++ b/src/nickserv.c
@@ -558,9 +558,7 @@ void load_old_ns_dbase(void)
memos->time = tmp32;
SAFE(read_buffer(memos->sender, f));
SAFE(read_string(&memos->text, f));
- for (m = 0; m < MAX_CMD_HASH; m++) {
- memos->moduleData[m] = NULL;
- }
+ memos->moduleData = NULL;
}
}
@@ -757,9 +755,7 @@ void load_ns_dbase(void)
memos->time = tmp32;
SAFE(read_buffer(memos->sender, f));
SAFE(read_string(&memos->text, f));
- for (m = 0; m < MAX_CMD_HASH; m++) {
- memos->moduleData[m] = NULL;
- }
+ memos->moduleData = NULL;
}
}
@@ -1562,13 +1558,13 @@ static int delcore(NickCore * nc)
if (nc->memos.memos) {
for (i = 0; i < nc->memos.memocount; i++) {
if (nc->memos.memos[i].text)
- moduleCleanStruct(nc->memos.memos[i].moduleData);
+ moduleCleanStruct(&nc->memos.memos[i].moduleData);
free(nc->memos.memos[i].text);
}
free(nc->memos.memos);
}
- moduleCleanStruct(nc->moduleData);
+ moduleCleanStruct(&nc->moduleData);
free(nc);
@@ -1666,7 +1662,7 @@ int delnick(NickAlias * na)
if (na->last_quit)
free(na->last_quit);
- moduleCleanStruct(na->moduleData);
+ moduleCleanStruct(&na->moduleData);
free(na);
diff --git a/src/operserv.c b/src/operserv.c
index 2d643aa01..92130c790 100644
--- a/src/operserv.c
+++ b/src/operserv.c
@@ -3096,7 +3096,7 @@ static int do_sqline(User * u)
if (mask && (reason = strtok(NULL, ""))) {
/* We first do some sanity check on the proposed mask. */
- if (strspn(mask, "*?") == strlen(mask)) {
+ if (strspn(mask, "*") == strlen(mask)) {
notice_lang(s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask);
return MOD_CONT;
}
diff --git a/src/users.c b/src/users.c
index 723cf65da..a3b4fa8fe 100644
--- a/src/users.c
+++ b/src/users.c
@@ -242,7 +242,7 @@ void delete_user(User * user)
if (user->nickTrack)
free(user->nickTrack);
- moduleCleanStruct(user->moduleData);
+ moduleCleanStruct(&user->moduleData);
if (debug >= 2)
alog("debug: delete_user(): delete from list");