From 13f214043d3697db7a3ca1c751cee41fd2fcf695 Mon Sep 17 00:00:00 2001 From: Dave West Date: Sun, 5 Aug 2007 19:16:00 +0000 Subject: [PATCH] Continue phase 2 of modules stuff. 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. --- citadel/include/ctdl_module.h | 2 + citadel/journaling.c | 8 +++ .../autocompletion/serv_autocompletion.c | 3 +- citadel/modules/fulltext/serv_fulltext.c | 12 +++++ .../{ => modules/fulltext}/serv_fulltext.h | 0 citadel/modules/imap/imap_search.c | 3 +- citadel/modules/vcard/serv_vcard.c | 2 + citadel/msgbase.c | 17 ++++--- citadel/serv_extensions.c | 49 +++++++++++++++++++ citadel/serv_extensions.h | 2 + citadel/server.h | 7 +++ 11 files changed, 94 insertions(+), 11 deletions(-) rename citadel/{ => modules/fulltext}/serv_fulltext.h (100%) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index a839ffbab..905446ee5 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -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 */ diff --git a/citadel/journaling.c b/citadel/journaling.c index 9a7088722..f0464a999 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -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; diff --git a/citadel/modules/autocompletion/serv_autocompletion.c b/citadel/modules/autocompletion/serv_autocompletion.c index ddea4f0dc..5d593e897 100644 --- a/citadel/modules/autocompletion/serv_autocompletion.c +++ b/citadel/modules/autocompletion/serv_autocompletion.c @@ -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 0) { for (j=0; j < IMAP->num_msgs; ++j) { if (IMAP->flags[j] & IMAP_SELECTED) { diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index d6a29a196..06b063718 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -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; diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 51bf426f1..34e11c15c 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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; diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 78d721704..3cbc5b906 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -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) { diff --git a/citadel/serv_extensions.h b/citadel/serv_extensions.h index f0e1cedb0..0d18582bc 100644 --- a/citadel/serv_extensions.h +++ b/citadel/serv_extensions.h @@ -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/server.h b/citadel/server.h index 11cd6319b..927abb6e8 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -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 { -- 2.30.2