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.
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
*/
/*
* 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;
#include "room_ops.h"
#include "database.h"
#include "vcard.h"
-#include "serv_fulltext.h"
#include "serv_autocompletion.h"
#include "ctdl_module.h"
* 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;
}
+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 */
--- /dev/null
+/*
+ * $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);
#include "imap_fetch.h"
#include "imap_search.h"
#include "genstamp.h"
-#include "serv_fulltext.h" /* Needed for ft_search */
/*
*/
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) {
int linelen;
if (msgnum <= 0L) return;
+
+ if (room == NULL) return;
if (strcasecmp(room, ADDRESS_BOOK_ROOM)) {
return;
#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"
* 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;
*/
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;
struct FixedOutputHook *FixedOutputTable = NULL;
struct RoomFunctionHook *RoomHookTable = NULL;
struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL;
+struct SearchFunctionHook *SearchFunctionHookTable = NULL;
struct ProtoFunctionHook {
void (*handler) (char *cmdbuf);
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)
{
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 */
+++ /dev/null
-/*
- * $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);
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 {