Added an elastic string buffer class to libcitadel. Why do I have a feeling I'm...
authorArt Cancro <ajc@citadel.org>
Tue, 9 Feb 2021 00:06:55 +0000 (19:06 -0500)
committerArt Cancro <ajc@citadel.org>
Tue, 9 Feb 2021 00:06:55 +0000 (19:06 -0500)
citadel/euidindex.c
citadel/modules/listdeliver/serv_listdeliver.c
citadel/room_ops.c
libcitadel/Makefile.in
libcitadel/lib/array.c [new file with mode: 0644]
libcitadel/lib/libcitadel.h

index bfef39b4c900634967d0a45696625f6441662997..247a998a83d86cf99ba35371555322cb74c458e1 100644 (file)
@@ -167,8 +167,7 @@ void rebuild_euid_index_for_room(struct ctdlroom *qrbuf, void *data) {
                                        "euidindex: rebuilding EUID index for <%s>",
                                        rplist->name);
                                CtdlUserGoto(rplist->name, 0, 0, NULL, NULL, NULL, NULL);
-                               CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
-                                       rebuild_euid_index_for_msg, NULL);
+                               CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, rebuild_euid_index_for_msg, NULL);
                        }
                }
                ptr = rplist;
index 39006a0b70f235a0af6ea1fae5c99db7ab6e1e09..7dd34630a0750c5fc5977fcf4f663163a50d18b9 100644 (file)
@@ -83,7 +83,11 @@ void listdeliver_do_msg(long msgnum, void *userdata) {
                        }
                }
                syslog(LOG_DEBUG, "\033[33m%s\033[0m", recipients);
-               free(recipients);
+               struct recptypes *valid = validate_recipients(recipients, NULL, 0);
+               if (valid) {
+                       long new_msgnum = CtdlSubmitMsg(TheMessage, valid, "");
+                       free_recipients(valid);
+               }
        }
        CM_Free(TheMessage);
 }
@@ -174,7 +178,7 @@ void listdeliver_sweep(void) {
        last_run = time(NULL);
        doing_listdeliver = 0;
 
-       //exit(0);
+       exit(0);
 }
 
 
index 1e3f787fe33dc955203edc2443fad89bcc53dd0f..44573dae34d985470c823f491b9005dba760efb8 100644 (file)
@@ -333,13 +333,14 @@ void room_sanity_check(struct ctdlroom *qrbuf) {
                qrbuf->QRfloor = 0;
        }
        /* Listing order of 0 is illegal except for base rooms */
-       if (qrbuf->QRorder == 0)
+       if (qrbuf->QRorder == 0) {
                if (    !(qrbuf->QRflags & QR_MAILBOX)
                        && strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)
                        && strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)
                ) {
                        qrbuf->QRorder = 64;
                }
+       }
 }
 
 
index e4f4ec476c7e38b96519965ce8becef5d8157188..ae5d4d664c4c824911d5805d75d8be31e9e0020d 100755 (executable)
@@ -132,7 +132,8 @@ LIB_OBJS = lib/libcitadel.lo \
        lib/xdgmime/xdgmimealias.lo \
        lib/xdgmime/xdgmimeparent.lo \
        lib/xdgmime/xdgmimecache.lo \
-       lib/html_to_ascii.lo
+       lib/html_to_ascii.lo \
+       lib/array.lo
 
 $(LIBRARY): $(LIB_OBJS)
        $(LINK_LIB) $(LIB_OBJS)
@@ -156,6 +157,7 @@ lib/xdgmime/xdgmimealias.lo:  lib/xdgmime/xdgmimealias.c
 lib/xdgmime/xdgmimeparent.lo:  lib/xdgmime/xdgmimeparent.c 
 lib/xdgmime/xdgmimecache.lo: lib/xdgmime/xdgmimecache.c
 lib/html_to_ascii.lo: lib/html_to_ascii.c
+lib/tools.lo: lib/tools.c
 
 .SUFFIXES: .c .cpp .lo .o
 
diff --git a/libcitadel/lib/array.c b/libcitadel/lib/array.c
new file mode 100644 (file)
index 0000000..444a347
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * This is a quickly-hacked-together implementation of an elastic array class.  It includes constructor and destructor
+ * methods, append and access methods, and that's about it.  The memory allocation is very naive: whenever we are about
+ * to append beyond the size of the buffer, we double its size.
+ *
+ * Copyright (c) 2021 by Art Cancro
+ *
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "libcitadel.h"
+
+/*
+ * Constructor for elastic array
+ */
+Array *array_new(size_t element_size) {
+       Array *newarr = malloc(sizeof(Array));
+       if (newarr) {
+               memset(newarr, 0, sizeof(Array));
+       }
+       newarr->element_size = element_size;
+       return newarr;
+}
+
+
+/*
+ * Destructor for elastic array
+ */
+void array_free(Array *arr) {
+       free(arr->the_elements);
+       free(arr);
+}
+
+
+/*
+ * Append an element to an array (we already know the element size because it's in the data type)
+ */
+void array_append(Array *arr, void *new_element) {
+
+       if (!arr) {                                             // silently fail if they gave us a null array
+               return;
+       }
+
+       if ( (arr->the_elements == NULL) || (arr->num_alloc == 0)) {
+               arr->num_alloc = 1;
+               arr->num_elements = 0;
+               arr->the_elements = malloc(arr->element_size * arr->num_alloc);
+       }
+
+       ++arr->num_elements;
+       if (arr->num_elements > arr->num_alloc) {
+               arr->num_alloc = arr->num_alloc * 2;
+               arr->the_elements = realloc(arr->the_elements, (arr->element_size * arr->num_alloc));
+       }
+
+       memcpy((arr->the_elements + ( (arr->num_elements-1) * arr->element_size )), new_element, arr->element_size);
+}
+
+
+/*
+ * Return the element in an array at the specified index
+ */
+void *array_get_element_at(Array *arr, int index) {
+       return (arr->the_elements + ( index * arr->element_size ));
+}
+
+
+/*
+ * Return the number of elements in an array
+ */
+int array_len(Array *arr) {
+       return arr->num_elements;
+}
index 9d015a9378927dd1afbe86505f384656c061e1c1..54bf8d99285f28e1ac822f3298caca582e8bb51f 100644 (file)
@@ -26,7 +26,7 @@
 #include <sys/types.h>
 #include <netinet/in.h>
 
-#define LIBCITADEL_VERSION_NUMBER      925
+#define LIBCITADEL_VERSION_NUMBER      926
 
 /*
  * Here's a bunch of stupid magic to make the MIME parser portable.
@@ -440,6 +440,19 @@ char *html_to_ascii(const char *inputmsg, int msglen, int screenwidth);
 void LoadEntityList(char *FileName);
 
 
+typedef struct {
+       void *the_elements;
+       size_t element_size;
+       int num_elements;
+       int num_alloc;
+} Array;
+
+Array *array_new(size_t element_size);
+void array_free(Array *arr);
+void array_append(Array *arr, void *new_element);
+void *array_get_element_at(Array *arr, int index);
+int array_len(Array *arr);
+
 
 /* vCard stuff */