summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes1
-rw-r--r--modules.c221
-rw-r--r--modules.h9
-rw-r--r--services.h20
-rw-r--r--users.c19
-rw-r--r--version.log7
6 files changed, 274 insertions, 3 deletions
diff --git a/Changes b/Changes
index ce1ff5eeb..e22b9253d 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
Anope Version 1.7.x (will be renamed when next release is produced)
-------------------
Provided by Anope Dev. <dev@anope.org>
+2004/04/26 Added module data ability, currently only added to User struct
2004/04/23 Added new MemoServ command RSEND to send a memo requesting a receipt memo once the recipient reads it.
2004/04/22 Fixed ALIST bug when being invoked by systems admins (Bug #20)
2004/04/19 Added /bin/anoperc anope console control script
diff --git a/modules.c b/modules.c
index 6e57aea67..29c37e774 100644
--- a/modules.c
+++ b/modules.c
@@ -446,6 +446,9 @@ int prepForUnload(Module * m)
/* Kill any active callbacks this module has */
moduleCallBackPrepForUnload(m->name);
+ /* Remove any stored data this module has */
+ moduleDelAllDataMod(m);
+
/**
* ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :)
**/
@@ -981,7 +984,7 @@ int delCommand(CommandHash * cmdTable[], Command * c, char *mod_name)
/**
* Search the command table gieven for a command.
* @param cmdTable the name of the command table to search
- * @name the name of the command to look for
+ * @param name the name of the command to look for
* @return returns a pointer to the found command struct, or NULL
*/
Command *findCommand(CommandHash * cmdTable[], const char *name)
@@ -1581,5 +1584,221 @@ void moduleDisplayHelp(int service, User * u)
#endif
}
+/**
+ * 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[], char *key, char *value)
+{
+ char *mod_name = sstrdup(mod_current_module_name);
+
+ int index = 0;
+ index = CMD_HASH(mod_name);
+ ModuleData *current = NULL;
+ ModuleData *newHash = NULL;
+ ModuleData *lastHash = NULL;
+ ModuleDataItem *item = NULL;
+ ModuleDataItem *itemCurrent = NULL;
+ ModuleDataItem *lastItem = NULL;
+
+ for (current = md[index]; current; current = current->next) {
+ if (strcasecmp(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) {
+ alog("key: [%s] itemKey: [%s]", key, itemCurrent->key);
+ if (strcasecmp(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;
+
+}
+
+/**
+ * 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[], char *key)
+{
+ char *mod_name = sstrdup(mod_current_module_name);
+ int index = 0;
+ char *ret = NULL;
+ index = CMD_HASH(mod_name);
+ ModuleData *current = NULL;
+ ModuleData *lastHash = NULL;
+
+ ModuleDataItem *itemCurrent = NULL;
+
+ for (current = md[index]; current; current = current->next) {
+ if (strcasecmp(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);
+ }
+ }
+ }
+ free(mod_name);
+ return ret;
+}
+
+/**
+ * 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[], char *key)
+{
+ char *mod_name = sstrdup(mod_current_module_name);
+ int index = 0;
+ index = CMD_HASH(mod_name);
+ ModuleData *current = NULL;
+ ModuleData *lastHash = NULL;
+
+ ModuleDataItem *itemCurrent = NULL;
+ ModuleDataItem *prev = NULL;
+ ModuleDataItem *next = NULL;
+
+ for (current = md[index]; current; current = current->next) {
+ if (strcasecmp(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;
+ }
+ }
+ }
+ 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[])
+{
+ char *mod_name = sstrdup(mod_current_module_name);
+ int index = 0;
+ index = CMD_HASH(mod_name);
+ ModuleData *current = NULL;
+ ModuleData *lastHash = NULL;
+
+ ModuleDataItem *itemCurrent = NULL;
+ ModuleDataItem *prev = NULL;
+ ModuleDataItem *next = NULL;
+
+ for (current = md[index]; current; current = current->next) {
+ if (strcasecmp(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;
+ }
+ }
+ }
+ 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)
+{
+ boolean freeme = false;
+ int i;
+ User *user;
+ if (!mod_current_module_name) {
+ mod_current_module_name = sstrdup(m->name);
+ freeme = true;
+ }
+
+ for (i = 0; i < 1024; i++) {
+ for (user = userlist[i]; user; user = user->next) {
+ moduleDelAllData(user->moduleData);
+ }
+ }
+
+ if (freeme) {
+ free(mod_current_module_name);
+ mod_current_module_name = NULL;
+ }
+}
+
+
/* EOF */
diff --git a/modules.h b/modules.h
index 3568b55a7..59f99ab41 100644
--- a/modules.h
+++ b/modules.h
@@ -64,6 +64,7 @@ typedef struct Message_ Message;
typedef struct MessageHash_ MessageHash;
typedef struct ModuleCallBack_ ModuleCallBack;
+
extern CommandHash *HOSTSERV[MAX_CMD_HASH];
extern CommandHash *BOTSERV[MAX_CMD_HASH];
extern CommandHash *MEMOSERV[MAX_CMD_HASH];
@@ -218,6 +219,14 @@ Message *findMessage(MessageHash *msgTable[], const char *name);
int moduleAddCallback(char *name,time_t when,int (*func)(int argc, char *argv[]),int argc, char **argv);
void moduleDelCallback(char *name);
void moduleCallBackRun(void);
+
+char *moduleGetData(ModuleData *md[], char *key); /* Get the value for this key from this struct */
+int moduleAddData(ModuleData *md[], char *key, char *value); /* Set the value for this key for this struct */
+void moduleDelData(ModuleData *md[], char *key); /* Delete this key/value pair */
+void moduleDelAllData(ModuleData *md[]); /* Delete all key/value pairs for this module for this struct */
+
+void moduleDelAllDataMod(Module *m); /* remove all module data from all structs for this module */
+
/*************************************************************************/
#endif
diff --git a/services.h b/services.h
index cd00c7c15..18a505d7a 100644
--- a/services.h
+++ b/services.h
@@ -644,8 +644,24 @@ struct csmodeutil_ {
#endif
/*************************************************************************/
-/* Online user and channel data. */
+typedef struct ModuleData_ ModuleData; /* ModuleData struct */
+typedef struct ModuleDataItem_ ModuleDataItem; /* A Module Data Item struct */
+
+struct ModuleDataItem_ {
+ char *key; /* The key */
+ char *value; /* The Value */
+ ModuleDataItem *next; /* The next ModuleDataItem in this list */
+};
+
+struct ModuleData_ {
+ char *moduleName; /* Which module we belong to */
+ ModuleDataItem *di; /* The first Item they own */
+ ModuleData *next; /* The next ModuleData record */
+};
+
+
+/* Online user and channel data. */
struct user_ {
User *next, *prev;
@@ -669,6 +685,8 @@ struct user_ {
NickAlias *na;
+ ModuleData *moduleData[1024]; /* defined for it, it should allow the module Add/Get */
+
int isSuperAdmin; /* is SuperAdmin on or off? */
struct u_chanlist {
diff --git a/users.c b/users.c
index 8a464c021..978b70a40 100644
--- a/users.c
+++ b/users.c
@@ -362,6 +362,9 @@ static void delete_user(User * user)
{
struct u_chanlist *c, *c2;
struct u_chaninfolist *ci, *ci2;
+ int i;
+ ModuleData *md, *nextMd;
+ ModuleDataItem *item, *nextItem;
if (LogUsers) {
#ifdef HAS_VHOST
@@ -412,6 +415,22 @@ static void delete_user(User * user)
free(ci);
ci = ci2;
}
+
+ for (i = 0; i < 1024; i++) { /* Clear up any module data used be the User struct */
+ for (md = user->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);
+ }
+ }
+
if (debug >= 2)
alog("debug: delete_user(): delete from list");
if (user->prev)
diff --git a/version.log b/version.log
index 778768d99..a2c403c53 100644
--- a/version.log
+++ b/version.log
@@ -8,11 +8,16 @@
VERSION_MAJOR="1"
VERSION_MINOR="7"
VERSION_PATCH="2"
-VERSION_BUILD="73"
+VERSION_BUILD="74"
VERSION_EXTRA=""
# $Log$
#
+# BUILD : 1.7.2 (74)
+# BUGS : N/A
+# NOTES : Added moduleAddData() and moduleGetData() currently only added to the User struct as a test
+#
+#
# BUILD : 1.7.2 (73)
# BUGS :
# NOTES : Removed delay timer from RSEND notifications.