X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Feuidindex.c;h=247a998a83d86cf99ba35371555322cb74c458e1;hb=2d108c1f33c86b501a2540ba48eaedded8894f20;hp=a1d5ec960c69424968bb80098197cfd1e7079bd8;hpb=4583cc48c475fe3a2a24a72c1c9a54fe5598ca01;p=citadel.git diff --git a/citadel/euidindex.c b/citadel/euidindex.c index a1d5ec960..247a998a8 100644 --- a/citadel/euidindex.c +++ b/citadel/euidindex.c @@ -1,47 +1,23 @@ -/* +/* * Index messages by EUID per room. + * + * Copyright (c) 1987-2020 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "sysdep.h" -#include -#include #include -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - - -#include -#include -#include -#include -#include -#include #include -#include "citadel.h" -#include "server.h" -#include "database.h" -#include "msgbase.h" -#include "support.h" -#include "sysdep_decls.h" + #include "citserver.h" #include "room_ops.h" -#include "user_ops.h" -#include "file_ops.h" -#include "config.h" -#include "control.h" -#include "euidindex.h" - -#include "ctdl_module.h" /* * The structure of an euidindex record *key* is: @@ -57,8 +33,6 @@ * */ - - /* * Return nonzero if the supplied room is one which should have * an EUID index. @@ -74,16 +48,14 @@ int DoesThisRoomNeedEuidIndexing(struct ctdlroom *qrbuf) { case VIEW_TASKS: return(1); case VIEW_NOTES: return(1); case VIEW_WIKI: return(1); + case VIEW_WIKIMD: return(1); + case VIEW_BLOG: return(1); } return(0); } - - - - /* * Locate a message in a given room with a given euid, and return * its message number. @@ -92,13 +64,14 @@ long locate_message_by_euid(char *euid, struct ctdlroom *qrbuf) { return CtdlLocateMessageByEuid (euid, qrbuf); } + long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf) { char *key; int key_len; struct cdbdata *cdb_euid; long msgnum = (-1L); - syslog(LOG_DEBUG, "Searching for EUID <%s> in <%s>\n", euid, qrbuf->QRname); + syslog(LOG_DEBUG, "euidindex: searching for EUID <%s> in <%s>", euid, qrbuf->QRname); key_len = strlen(euid) + sizeof(long) + 1; key = malloc(key_len); @@ -118,7 +91,7 @@ long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf) { memcpy(&msgnum, cdb_euid->ptr, sizeof(long)); cdb_free(cdb_euid); } - syslog(LOG_DEBUG, "returning msgnum = %ld\n", msgnum); + syslog(LOG_DEBUG, "euidindex: returning msgnum = %ld", msgnum); return(msgnum); } @@ -133,7 +106,7 @@ void index_message_by_euid(char *euid, struct ctdlroom *qrbuf, long msgnum) { char *data; int data_len; - syslog(LOG_DEBUG, "Indexing message #%ld <%s> in <%s>\n", msgnum, euid, qrbuf->QRname); + syslog(LOG_DEBUG, "euidindex: indexing message #%ld <%s> in <%s>", msgnum, euid, qrbuf->QRname); key_len = strlen(euid) + sizeof(long) + 1; key = malloc(key_len); @@ -152,7 +125,6 @@ void index_message_by_euid(char *euid, struct ctdlroom *qrbuf, long msgnum) { } - /* * Called by rebuild_euid_index_for_room() to index one message. */ @@ -161,10 +133,10 @@ void rebuild_euid_index_for_msg(long msgnum, void *userdata) { msg = CtdlFetchMessage(msgnum, 0); if (msg == NULL) return; - if (msg->cm_fields['E'] != NULL) { - index_message_by_euid(msg->cm_fields['E'], &CC->room, msgnum); + if (!CM_IsEmpty(msg, eExclusiveID)) { + index_message_by_euid(msg->cm_fields[eExclusiveID], &CC->room, msgnum); } - CtdlFreeMessage(msg); + CM_Free(msg); } @@ -192,11 +164,10 @@ void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) { if (CtdlGetRoom(&qr, rplist->name) == 0) { if (DoesThisRoomNeedEuidIndexing(&qr)) { syslog(LOG_DEBUG, - "Rebuilding EUID index for <%s>\n", + "euidindex: rebuilding EUID index for <%s>", rplist->name); - CtdlUserGoto(rplist->name, 0, 0, NULL, NULL); - CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, - rebuild_euid_index_for_msg, NULL); + CtdlUserGoto(rplist->name, 0, 0, NULL, NULL, NULL, NULL); + CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, rebuild_euid_index_for_msg, NULL); } } ptr = rplist; @@ -216,29 +187,16 @@ void rebuild_euid_index(void) { } - -struct euid_callback { - long msgnum; - int found_it; -}; - -/* - * callback for cmd_euid - */ -void euid_is_msg_in_room(long msgnum, void *userdata) { - struct euid_callback *ec = (struct euid_callback *) userdata; - - if (msgnum == ec->msgnum) ec->found_it = 1; -} - - /* * Server command to fetch a message number given an euid. */ void cmd_euid(char *cmdbuf) { char euid[256]; long msgnum; - struct euid_callback ec; + struct cdbdata *cdbfr; + long *msglist = NULL; + int num_msgs = 0; + int i; if (CtdlAccessCheck(ac_logged_in_or_guest)) return; @@ -249,21 +207,28 @@ void cmd_euid(char *cmdbuf) { return; } - ec.msgnum = msgnum; - ec.found_it = 0; - CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, euid_is_msg_in_room, (void *)&ec); - - if (ec.found_it) { - cprintf("%d %ld\n", CIT_OK, msgnum); - return; + cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long)); + if (cdbfr != NULL) { + num_msgs = cdbfr->len / sizeof(long); + msglist = (long *) cdbfr->ptr; + for (i = 0; i < num_msgs; ++i) { + if (msglist[i] == msgnum) { + cdb_free(cdbfr); + cprintf("%d %ld\n", CIT_OK, msgnum); + return; + } + } + cdb_free(cdbfr); } + cprintf("%d not found\n", ERROR + MESSAGE_NOT_FOUND); } + CTDL_MODULE_INIT(euidindex) { if (!threading) { - CtdlRegisterProtoHook(cmd_euid, "EUID", "Fetch the msgnum associated with an EUID"); + CtdlRegisterProtoHook(cmd_euid, "EUID", "Perform operations on Extended IDs for messages"); } /* return our Subversion id for the Log */ return "euidindex";