Continue phase 2 of modules stuff.
authorDave West <davew@uncensored.citadel.org>
Sun, 5 Aug 2007 19:16:00 +0000 (19:16 +0000)
committerDave West <davew@uncensored.citadel.org>
Sun, 5 Aug 2007 19:16:00 +0000 (19:16 +0000)
Moved some more stuff into the relevant modules/* directories.
modified Makefile.in to build them.
Created a new Hook to register a search function. This allowed serv_fulltext.c to become independant of two files.
New suite of functions to support this hook mechanism are:
CtdlRegisterSearchFunction
CtdlUnregisterSearchFunction
CtdlModuleDoSearch
Remind me to document that mechanism too 8-)
Altered the DeleteHook mechanism slightly.
A registered DeleteHook will be called with a room name of NULL when the message no longer has a refcount and
has realy been deleted from the system. This allowed fulltext to be fully disconected from the msgbase.

12 files changed:
citadel/include/ctdl_module.h
citadel/journaling.c
citadel/modules/autocompletion/serv_autocompletion.c
citadel/modules/fulltext/serv_fulltext.c
citadel/modules/fulltext/serv_fulltext.h [new file with mode: 0644]
citadel/modules/imap/imap_search.c
citadel/modules/vcard/serv_vcard.c
citadel/msgbase.c
citadel/serv_extensions.c
citadel/serv_extensions.h
citadel/serv_fulltext.h [deleted file]
citadel/server.h

index a839ffbabc7cdeafdab05a6db17f64f9e8f4c5ae..905446ee55aa8d0a7e387cdce09c9e9c128f6a17 100644 (file)
@@ -64,6 +64,8 @@ void CtdlUnRegisterFixedOutputHook(char *content_type);
 
 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
 
+void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name);
+
 /* TODODRW: This needs to be changed into a hook type interface
  * for now we have this horrible hack
  */
index 9a708872273f57d29dd04baf439cb06ebdadf6df..f0464a999adca9124bd9673c396e8bc8523048b7 100644 (file)
@@ -92,6 +92,14 @@ void JournalBackgroundSubmit(struct CtdlMessage *msg,
 /*
  * Convert a local user name to an internet email address for the journal
  */
+/*
+ * TODODRW: change this into a CtdlModuleDo type function that returns alternative address info
+ * for this local user. Something like CtdlModuleGoGetAddr(char *localuser, int type, char *alt_addr, size_t alt_addr_len)
+ * where type can be ADDR_EMAIL, ADDR_FIDO, ADDR_UUCP, ADDR_WEB, ADDR_POSTAL etc etc.
+ * This then begs the question of what should be returned. Is it wise to return a single char* using a comma as a
+ * delimiter? Or would it be better to return a linked list of some kind?
+ */
 void local_to_inetemail(char *inetemail, char *localuser, size_t inetemail_len) {
        struct ctdluser us;
        struct vCard *v;
index ddea4f0dcc0077b015eeb7424b23fe62d2087ef4..5d593e897864accbf65dbb986ddb25bd2ff7f846 100644 (file)
@@ -40,7 +40,6 @@
 #include "room_ops.h"
 #include "database.h"
 #include "vcard.h"
-#include "serv_fulltext.h"
 #include "serv_autocompletion.h"
 
 #include "ctdl_module.h"
@@ -205,7 +204,7 @@ void cmd_auto(char *argbuf) {
         * Search-reduce the results if we have the full text index available
         */
        if (config.c_enable_fulltext) {
-               ft_search(&fts_num_msgs, &fts_msgs, search_string);
+               CtdlModuleDoSearch(&fts_num_msgs, &fts_msgs, search_string, "fulltext");
                if (fts_msgs) {
                        for (i=0; i<num_msgs; ++i) {
                                search_match = 0;
index b5753fbf63c95e4e156082f36da568d6d8ea9485..ba3f948a01af4885838f2918864738f11e2914eb 100644 (file)
@@ -467,12 +467,24 @@ void initialize_ft_cache(void) {
 }
 
 
+void ft_delete_remove(char *room, long msgnum)
+{
+       if (room) return;
+       
+       /* Remove from fulltext index */
+       if (config.c_enable_fulltext) {
+               ft_index_message(msgnum, 0);
+       }
+}
+
 /*****************************************************************************/
 
 CTDL_MODULE_INIT(fulltext)
 {
        initialize_ft_cache();
        CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
+       CtdlRegisterDeleteHook(ft_delete_remove);
+       CtdlRegisterSearchFuncHook(ft_search, "fulltext");
        CtdlRegisterMaintenanceThread ("indexer", indexer_thread);
 
        /* return our Subversion id for the Log */
diff --git a/citadel/modules/fulltext/serv_fulltext.h b/citadel/modules/fulltext/serv_fulltext.h
new file mode 100644 (file)
index 0000000..5a106f7
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * $Id$
+ *
+ */
+
+void ft_index_message(long msgnum, int op);
+void ft_search(int *fts_num_msgs, long **fts_msgs, char *search_string);
+void *indexer_thread(void *arg);
index 64f26f648870cfc45cee8e2d3367a0bd36e25ad9..b22e74280c8cba2a6227c8e591b37891297d9324 100644 (file)
@@ -48,7 +48,6 @@
 #include "imap_fetch.h"
 #include "imap_search.h"
 #include "genstamp.h"
-#include "serv_fulltext.h"     /* Needed for ft_search */
 
 
 /*
@@ -545,7 +544,7 @@ void imap_do_search(int num_items, char **itemlist, int is_uid) {
         */
        if (config.c_enable_fulltext) for (i=0; i<(num_items-1); ++i) {
                if (!strcasecmp(itemlist[i], "BODY")) {
-                       ft_search(&fts_num_msgs, &fts_msgs, itemlist[i+1]);
+                       CtdlModuleDoSearch(&fts_num_msgs, &fts_msgs, itemlist[i+1], "fulltext");
                        if (fts_num_msgs > 0) {
                                for (j=0; j < IMAP->num_msgs; ++j) {
                                        if (IMAP->flags[j] & IMAP_SELECTED) {
index d6a29a196b9f81fc490279b33510156a8eeecc8f..06b06371871da1eeaae74635dc32e53c17030f36 100644 (file)
@@ -881,6 +881,8 @@ void vcard_delete_remove(char *room, long msgnum) {
        int linelen;
 
        if (msgnum <= 0L) return;
+       
+       if (room == NULL) return;
 
        if (strcasecmp(room, ADDRESS_BOOK_ROOM)) {
                return;
index 51bf426f110b89a4c22bc57ebe3831317c2cdf8e..34e11c15c6d0e715a13144db53c9ddc611dfebcc 100644 (file)
@@ -49,7 +49,6 @@
 #include "html.h"
 #include "genstamp.h"
 #include "internet_addressing.h"
-#include "serv_fulltext.h"     /* Needed for ft_search and ft_index_message */
 #include "vcard.h"
 #include "euidindex.h"
 #include "journaling.h"
@@ -610,7 +609,13 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
         * over again.
         */
        if ( (num_msgs > 0) && (mode == MSGS_SEARCH) && (search_string) ) {
-               ft_search(&num_search_msgs, &search_msgs, search_string);
+
+               /* Call search module via hook mechanism.
+                * NULL means use any search function available.
+                * otherwise replace with a char * to name of search routine
+                */
+               CtdlModuleDoSearch(&num_search_msgs, &search_msgs, search_string, "fulltext");
+
                if (num_search_msgs > 0) {
        
                        int orig_num_msgs;
@@ -4079,11 +4084,9 @@ void TDAP_AdjRefCount(long msgnum, int incr)
         */
        if (smi.meta_refcount == 0) {
                lprintf(CTDL_DEBUG, "Deleting message <%ld>\n", msgnum);
-
-               /* Remove from fulltext index */
-               if (config.c_enable_fulltext) {
-                       ft_index_message(msgnum, 0);
-               }
+               
+               /* Call delete hooks with NULL room to show it has gone altogether */
+               PerformDeleteHooks(NULL, msgnum);
 
                /* Remove from message base */
                delnum = msgnum;
index 78d721704eba60274550f2f73d60415db67ea2f8..3cbc5b9069d01469a50ace56f7f30ae87b90f35e 100644 (file)
@@ -41,6 +41,7 @@ struct ServiceFunctionHook *ServiceHookTable = NULL;
 struct FixedOutputHook *FixedOutputTable = NULL;
 struct RoomFunctionHook *RoomHookTable = NULL;
 struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL;
+struct SearchFunctionHook *SearchFunctionHookTable = NULL;
 
 struct ProtoFunctionHook {
        void (*handler) (char *cmdbuf);
@@ -891,6 +892,54 @@ void CtdlDestroyServiceHook(void)
        ServiceHookTable = NULL;
 }
 
+void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
+{
+       struct SearchFunctionHook *newfcn;
+
+       if (!name || !fcn_ptr) {
+               return;
+       }
+       
+       newfcn = (struct SearchFunctionHook *)
+           malloc(sizeof(struct SearchFunctionHook));
+       newfcn->next = SearchFunctionHookTable;
+       newfcn->name = name;
+       newfcn->fcn_ptr = fcn_ptr;
+       SearchFunctionHookTable = newfcn;
+
+       lprintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
+}
+
+void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
+{
+       struct SearchFunctionHook *cur, *p;
+       
+       for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
+               while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
+                       lprintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
+                       p = cur->next;
+                       if (cur == SearchFunctionHookTable) {
+                               SearchFunctionHookTable = p;
+                       }
+                       free (cur);
+                       cur = p;
+               }
+       }
+}
+
+void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
+{
+       struct SearchFunctionHook *fcn = NULL;
+
+       for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
+               if (!func_name || !strcmp(func_name, fcn->name)) {
+                       (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
+                       return;
+               }
+       }
+       *num_msgs = 0;
+}
+
 
 void PerformSessionHooks(int EventType)
 {
index f0e1cedb097baf6d5fe58670ee0bef406048d488..0d18582bca5240f17345d5cdc85c4efa5dee72af 100644 (file)
@@ -55,4 +55,6 @@ void CtdlDestroyServiceHook(void);
 void CtdlDestroyFixedOutputHooks(void);
 int PerformFixedOutputHooks(char *, char *, int);
 
+void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name);
+
 #endif /* SERV_EXTENSIONS_H */
diff --git a/citadel/serv_fulltext.h b/citadel/serv_fulltext.h
deleted file mode 100644 (file)
index 5a106f7..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * $Id$
- *
- */
-
-void ft_index_message(long msgnum, int op);
-void ft_search(int *fts_num_msgs, long **fts_msgs, char *search_string);
-void *indexer_thread(void *arg);
index 11cd6319b8a982bc28c4b10159e16df7005d5b75..927abb6e867ace165e62846b6ab8f6c253cd146d 100644 (file)
@@ -460,6 +460,13 @@ struct MaintenanceThreadHook {
 extern struct MaintenanceThreadHook *MaintenanceThreadHookTable;
 
 
+struct SearchFunctionHook {
+       struct SearchFunctionHook *next;
+       void (*fcn_ptr) (int *, long **, char *);
+       char *name;
+};
+extern struct SearchFunctionHook *SearchFunctionHookTable;
+
 
 /* Defines the relationship of a user to a particular room */
 struct visit {