Updated the CtdlUserGoto() API call to also return the oldest and newest message...
[citadel.git] / citadel / euidindex.c
index a1d5ec960c69424968bb80098197cfd1e7079bd8..aa41d50dcc8c0149a16e810683a56e4ae3dbd9b0 100644 (file)
@@ -3,45 +3,11 @@
  */
 
 #include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
 #include <stdio.h>
-#include <fcntl.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-
-#include <ctype.h>
-#include <string.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <sys/stat.h>
 #include <libcitadel.h>
-#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:
@@ -74,6 +40,8 @@ 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);
@@ -161,10 +129,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);
 }
 
 
@@ -194,7 +162,7 @@ void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) {
                                syslog(LOG_DEBUG,
                                        "Rebuilding EUID index for <%s>\n",
                                        rplist->name);
-                               CtdlUserGoto(rplist->name, 0, 0, NULL, NULL);
+                               CtdlUserGoto(rplist->name, 0, 0, NULL, NULL, NULL, NULL);
                                CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
                                        rebuild_euid_index_for_msg, NULL);
                        }
@@ -217,28 +185,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 +205,27 @@ 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";