1
0
mirror of https://github.com/anope/anope.git synced 2026-07-03 09:13:12 +02:00

Remove moduleAddData|GetData|DelData and all associated mess. Extensible base replaces all this in a much cleaner and more transparent fashion.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1706 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
rburchell
2008-11-15 17:56:39 +00:00
parent b2b0e1d235
commit 8784fa995e
11 changed files with 0 additions and 268 deletions
-230
View File
@@ -1127,236 +1127,6 @@ void moduleDisplayHelp(int service, User * u)
mod_current_module_name = calling_module_name;
}
/**
* 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
* @param key The Key for the key/value pair
* @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, const char *key, char *value)
{
ModuleData *newData = NULL;
if (mod_current_module_name == NULL) {
alog("moduleAddData() called with mod_current_module_name being NULL");
if (debug)
do_backtrace(0);
}
if (!key || !value) {
alog("A module (%s) tried to use ModuleAddData() with one or more NULL arguments... returning", mod_current_module_name);
return MOD_ERR_PARAMS;
}
moduleDelData(md, key); /* Remove any existing module data for this module with the same key */
newData = (ModuleData *)malloc(sizeof(ModuleData));
if (!newData) {
return MOD_ERR_MEMORY;
}
newData->moduleName = sstrdup(mod_current_module_name);
newData->key = sstrdup(key);
newData->value = sstrdup(value);
newData->next = *md;
*md = newData;
return MOD_ERR_OK;
}
/**
* Returns the value from a key/value pair set.
* This allows module coders to retrive any data they have previuosly stored in any given struct
* @param md The module data for the struct to be used
* @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, const char *key)
{
/* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
if (mod_current_module_name == NULL) {
alog("moduleGetData() called with mod_current_module_name being NULL");
if (debug)
do_backtrace(0);
}
if (debug) {
alog("debug: moduleGetData %p : key %s", (void *) md, key);
alog("debug: Current Module %s", mod_name);
}
while (current) {
if ((stricmp(current->moduleName, mod_name) == 0)
&& (stricmp(current->key, key) == 0)) {
free(mod_name);
return sstrdup(current->value);
}
current = current->next;
}
free(mod_name);
return NULL;
}
/**
* Delete the key/value pair indicated by "key" for the current module.
* This allows module coders to remove a previously stored key/value pair.
* @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, const char *key)
{
/* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
ModuleData *prev = NULL;
ModuleData *next = NULL;
if (mod_current_module_name == NULL) {
alog("moduleDelData() called with mod_current_module_name being NULL");
if (debug)
do_backtrace(0);
}
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);
} else {
prev = current;
}
current = next;
}
}
free(mod_name);
}
/**
* This will remove all data for a particular module from existing structs.
* Its primary use is modulePrepForUnload() however, based on past expericance with module coders wanting to
* 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)
{
/* See comment in moduleAddData... -GD */
char *mod_name = sstrdup(mod_current_module_name);
ModuleData *current = *md;
ModuleData *prev = NULL;
ModuleData *next = NULL;
if (mod_current_module_name == NULL) {
alog("moduleDelAllData() called with mod_current_module_name being NULL");
if (debug)
do_backtrace(0);
}
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);
} else {
prev = current;
}
current = next;
}
free(mod_name);
}
/**
* 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)
{
bool freeme = false;
int i, j;
User *user;
NickAlias *na;
NickCore *nc;
ChannelInfo *ci;
if (!mod_current_module_name) {
mod_current_module_name = sstrdup(m->name.c_str());
freeme = true;
}
for (i = 0; i < 1024; i++) {
/* Remove the users */
for (user = userlist[i]; user; user = user->next) {
moduleDelAllData(&user->moduleData);
}
/* Remove the nick Cores */
for (nc = nclists[i]; nc; nc = nc->next) {
/* Remove any memo data for this nick core */
for (j = 0; j < nc->memos.memocount; j++) {
moduleCleanStruct(&nc->memos.memos[j].moduleData);
}
}
}
for (i = 0; i < 256; i++) {
/* Remove any chan info data */
for (ci = chanlists[i]; ci; ci = ci->next) {
/* Remove any memo data for this nick core */
for (j = 0; j < ci->memos.memocount; j++) {
moduleCleanStruct(&ci->memos.memos[j].moduleData);
}
}
}
if (freeme) {
free((void *)mod_current_module_name);
mod_current_module_name = NULL;
}
}
/**
* 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 *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;
}
/**
* Check the current version of anope against a given version number
* Specifiying -1 for minor,patch or build