4 * Index messages by EUID per room.
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
19 # include <sys/time.h>
34 #include "serv_extensions.h"
38 #include "sysdep_decls.h"
39 #include "citserver.h"
46 #include "euidindex.h"
49 long locate_message_by_euid(char *euid, struct ctdlroom *qrbuf) {
53 void index_message_by_euid(char *euid, struct ctdlroom *qrbuf, long msgnum) {
57 lprintf(CTDL_DEBUG, "Indexing message #%ld <%s> in <%s>\n", msgnum, euid, qrbuf->QRname);
59 key_len = strlen(euid) + sizeof(long) + 1;
60 key = malloc(key_len);
61 memcpy(key, &qrbuf->QRnumber, sizeof(long));
62 strcpy(&key[sizeof(long)], euid);
64 cdb_store(CDB_EUIDINDEX, key, key_len, &msgnum, sizeof(long));
70 * Called by rebuild_euid_index_for_room() to index one message.
72 void rebuild_euid_index_for_msg(long msgnum, void *userdata) {
73 struct CtdlMessage *msg;
75 msg = CtdlFetchMessage(msgnum, 0);
76 if (msg == NULL) return;
77 if (msg->cm_fields['E'] != NULL) {
78 index_message_by_euid(msg->cm_fields['E'], &CC->room, msgnum);
84 void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) {
85 static struct RoomProcList *rplist = NULL;
86 struct RoomProcList *ptr;
89 /* Lazy programming here. Call this function as a ForEachRoom backend
90 * in order to queue up the room names, or call it with a null room
91 * to make it do the processing.
94 ptr = (struct RoomProcList *)
95 malloc(sizeof (struct RoomProcList));
96 if (ptr == NULL) return;
98 safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name);
104 while (rplist != NULL) {
105 if (getroom(&qr, rplist->name) == 0) {
106 lprintf(CTDL_DEBUG, "Rebuilding EUID index for <%s>\n", rplist->name);
107 usergoto(rplist->name, 0, 0, NULL, NULL);
108 CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, rebuild_euid_index_for_msg, NULL);
111 rplist = rplist->next;
118 * Globally rebuild the EUID indices in every room.
120 void rebuild_euid_index(void) {
121 cdb_trunc(CDB_EUIDINDEX);
123 ForEachRoom(rebuild_euid_index_for_room, NULL);
124 rebuild_euid_index_for_room(NULL, NULL);