HUGE PATCH. This moves all of mime_parser.c and all
authorArt Cancro <ajc@citadel.org>
Fri, 16 Nov 2007 05:52:26 +0000 (05:52 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 16 Nov 2007 05:52:26 +0000 (05:52 +0000)
of tools.c into libcitadel.  It compiles cleanly, and seems to work, but I'm sure
I broke *something* so let's give this lots of testing.

101 files changed:
citadel/Makefile.in
citadel/citadel.c
citadel/citadel_ipc.c
citadel/citmail.c
citadel/citserver.c
citadel/client_chat.c
citadel/client_passwords.c
citadel/clientsocket.c
citadel/commands.c
citadel/configure.ac
citadel/control.c
citadel/domain.c
citadel/euidindex.c
citadel/file_ops.c
citadel/getmail.c
citadel/housekeeping.c
citadel/html.c
citadel/internet_addressing.c
citadel/ipc_c_tcp.c
citadel/journaling.c
citadel/locate_host.c
citadel/messages.c
citadel/mime_parser.c [deleted file]
citadel/mime_parser.h [deleted file]
citadel/modules/autocompletion/serv_autocompletion.c
citadel/modules/bio/serv_bio.c
citadel/modules/calendar/serv_calendar.c
citadel/modules/chat/serv_chat.c
citadel/modules/expire/serv_expire.c
citadel/modules/fulltext/ft_wordbreaker.c
citadel/modules/fulltext/serv_fulltext.c
citadel/modules/funambol/serv_funambol.c
citadel/modules/imap/imap_acl.c
citadel/modules/imap/imap_fetch.c
citadel/modules/imap/imap_list.c
citadel/modules/imap/imap_metadata.c
citadel/modules/imap/imap_misc.c
citadel/modules/imap/imap_search.c
citadel/modules/imap/imap_store.c
citadel/modules/imap/imap_tools.c
citadel/modules/imap/serv_imap.c
citadel/modules/inetcfg/serv_inetcfg.c
citadel/modules/ldap/serv_ldap.c
citadel/modules/listsub/serv_listsub.c
citadel/modules/managesieve/serv_managesieve.c
citadel/modules/mrtg/serv_mrtg.c
citadel/modules/netfilter/serv_netfilter.c
citadel/modules/network/serv_network.c
citadel/modules/notes/serv_notes.c
citadel/modules/pager/serv_pager.c
citadel/modules/pas2/serv_pas2.c
citadel/modules/pop3/serv_pop3.c
citadel/modules/pop3client/serv_pop3client.c
citadel/modules/rssclient/serv_rssclient.c
citadel/modules/rwho/serv_rwho.c
citadel/modules/sieve/serv_sieve.c
citadel/modules/smtp/serv_smtp.c
citadel/modules/spam/serv_spam.c
citadel/modules/upgrade/serv_upgrade.c
citadel/modules/vandelay/serv_vandelay.c
citadel/modules/vcard/serv_vcard.c
citadel/msgbase.c
citadel/msgform.c
citadel/policy.c
citadel/room_ops.c
citadel/rooms.c
citadel/routines.c
citadel/routines.h
citadel/routines2.c
citadel/sendcommand.c
citadel/serv_extensions.c
citadel/server_main.c
citadel/setup.c
citadel/stress.c
citadel/support.c
citadel/support.h
citadel/sysdep.c
citadel/tools.c [deleted file]
citadel/tools.h [deleted file]
citadel/tuiconfig.c
citadel/user_ops.c
citadel/userlist.c
citadel/vcard.c
citadel/whobbs.c
libcitadel/Makefile.in
libcitadel/lib/libcitadel.h
libcitadel/lib/tools.c [new file with mode: 0644]
webcit/Makefile.in
webcit/calendar.c
webcit/calendar_view.c
webcit/configure.ac
webcit/fmt_date.c
webcit/groupdav_get.c
webcit/messages.c
webcit/mime_parser.c [deleted file]
webcit/mime_parser.h [deleted file]
webcit/sieve.c
webcit/smtpqueue.c
webcit/tools.c [deleted file]
webcit/webcit.c
webcit/webcit.h

index e689e3ad95040def238dd5ec3b5d5db3025c8251..79d40df395fc6ea5604fd618e3277a1f4eb61997 100644 (file)
@@ -76,12 +76,12 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c chkpw.c citadel.c citadel_ipc.c \
        housekeeping.c html.c ical_dezonify.c \
        internet_addressing.c ecrash.c \
        ipc_c_tcp.c locate_host.c md5.c messages.c  \
-       mime_parser.c msgbase.c msgform.c parsedate.c policy.c \
+       msgbase.c msgform.c parsedate.c policy.c \
        room_ops.c rooms.c routines.c routines2.c tuiconfig.c euidindex.c \
        screen.c sendcommand.c getmail.c \
        server_main.c \
        setup.c snprintf.c \
-       stress.c support.c sysdep.c tools.c user_ops.c userlist.c \
+       stress.c support.c sysdep.c user_ops.c userlist.c \
        whobbs.c vcard.c \
        crc16.c journaling.c citadel_dirs.c
 
@@ -97,10 +97,10 @@ utils: $(UTIL_TARGETS) $(UTILBIN_TARGETS)
 
 citadel$(EXEEXT): citadel.o citadel_ipc.o client_chat.o client_passwords.o \
        commands.o html.o ipc_c_tcp.o md5.o messages.o rooms.o routines.o \
-       routines2.o tuiconfig.o screen.o tools.o citadel_dirs.o ecrash.o $(LIBOBJS)
+       routines2.o tuiconfig.o screen.o citadel_dirs.o ecrash.o $(LIBOBJS)
        $(CC) citadel.o citadel_ipc.o client_chat.o client_passwords.o \
        commands.o html.o ipc_c_tcp.o md5.o messages.o rooms.o routines.o \
-       routines2.o tuiconfig.o screen.o tools.o citadel_dirs.o ecrash.o $(LIBOBJS) \
+       routines2.o tuiconfig.o screen.o citadel_dirs.o ecrash.o $(LIBOBJS) \
        $(LDFLAGS) -o citadel $(LIBS)
 
 .y.c:
@@ -121,10 +121,10 @@ modules_init.c: mk_module_init.sh $(SOURCES)
 
 SERV_OBJS = server_main.o \
        user_ops.o citserver.o sysdep.o serv_extensions.o \
-       tools.o $(DATABASE:.c=.o) domain.o \
+       $(DATABASE:.c=.o) domain.o \
        control.o policy.o config.o support.o room_ops.o \
        file_ops.o msgbase.o euidindex.o \
-       locate_host.o housekeeping.o mime_parser.o html.o \
+       locate_host.o housekeeping.o html.o \
        internet_addressing.o journaling.o \
        parsedate.o genstamp.o ecrash.o \
        clientsocket.o modules_init.o $(AUTH) $(SERV_MODULES)
@@ -138,12 +138,12 @@ citserver: $(SERV_OBJS)
 aidepost: aidepost.o config.o
        $(CC) aidepost.o config.o citadel_dirs.o $(LDFLAGS) -o aidepost $(LIBS)
 
-citmail: citmail.o citadel_dirs.o tools.o
-       $(CC) citmail.o citadel_dirs.o tools.o $(LDFLAGS) -o citmail $(LIBS)
+citmail: citmail.o citadel_dirs.o
+       $(CC) citmail.o citadel_dirs.o $(LDFLAGS) -o citmail $(LIBS)
 
 # setup does need LIBS defined, because it uses network functions which are in -lsocket -lnsl on Solaris.
-setup: setup.o tools.o citadel_dirs.o
-       $(CC) setup.o tools.o citadel_dirs.o $(LDFLAGS) -o setup $(LIBS) $(SETUP_LIBS)
+setup: setup.o citadel_dirs.o
+       $(CC) setup.o citadel_dirs.o $(LDFLAGS) -o setup $(LIBS) $(SETUP_LIBS)
 
 chkpwd: chkpwd.o auth.o
        $(CC) chkpwd.o auth.o $(LDFLAGS) -o chkpwd $(chkpwd_LIBS)
@@ -151,25 +151,25 @@ chkpwd: chkpwd.o auth.o
 chkpw: chkpw.o auth.o citadel_dirs.o
        $(CC) chkpw.o auth.o citadel_dirs.o $(LDFLAGS) -o chkpw $(chkpwd_LIBS)
 
-whobbs$(EXEEXT): whobbs.o ipc_c_tcp.o tools.o citadel_ipc.o citadel_dirs.o $(LIBOBJS)
-       $(CC) whobbs.o ipc_c_tcp.o tools.o citadel_ipc.o  citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o whobbs $(LIBS)
+whobbs$(EXEEXT): whobbs.o ipc_c_tcp.o citadel_ipc.o citadel_dirs.o $(LIBOBJS)
+       $(CC) whobbs.o ipc_c_tcp.o citadel_ipc.o  citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o whobbs $(LIBS)
 
-stress$(EXEEXT): stress.o ipc_c_tcp.o tools.o citadel_ipc.o citadel_dirs.o $(LIBOBJS)
-       $(CC) stress.o ipc_c_tcp.o tools.o citadel_ipc.o citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o stress $(LIBS)
+stress$(EXEEXT): stress.o ipc_c_tcp.o citadel_ipc.o citadel_dirs.o $(LIBOBJS)
+       $(CC) stress.o ipc_c_tcp.o citadel_ipc.o citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o stress $(LIBS)
 
-sendcommand: sendcommand.o ipc_c_tcp.o citadel_ipc.o tools.o config.o  $(LIBOBJS)
-       $(CC) sendcommand.o ipc_c_tcp.o citadel_ipc.o tools.o config.o  \
+sendcommand: sendcommand.o ipc_c_tcp.o citadel_ipc.o config.o  $(LIBOBJS)
+       $(CC) sendcommand.o ipc_c_tcp.o citadel_ipc.o config.o  \
         citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o sendcommand $(LIBS)
 
-getmail: getmail.o ipc_c_tcp.o citadel_ipc.o tools.o config.o  $(LIBOBJS)
-       $(CC) getmail.o ipc_c_tcp.o citadel_ipc.o tools.o config.o  \
+getmail: getmail.o ipc_c_tcp.o citadel_ipc.o config.o  $(LIBOBJS)
+       $(CC) getmail.o ipc_c_tcp.o citadel_ipc.o config.o  \
         citadel_dirs.o $(LIBOBJS) $(LDFLAGS) -o getmail $(LIBS)
 
 base64: base64.o
        $(CC) base64.o $(LDFLAGS) -o base64
 
-userlist: userlist.o ipc_c_tcp.o citadel_ipc.o tools.o citadel_dirs.o $(LIBOBJS)
-       $(CC) userlist.o ipc_c_tcp.o citadel_ipc.o tools.o citadel_dirs.o \
+userlist: userlist.o ipc_c_tcp.o citadel_ipc.o citadel_dirs.o $(LIBOBJS)
+       $(CC) userlist.o ipc_c_tcp.o citadel_ipc.o citadel_dirs.o \
        $(LIBOBJS) $(LDFLAGS) -o userlist $(LIBS)
 
 msgform: msgform.o
index 8fe6b3a476bcceebe5c80fb9dd1b1599b2afe5c8..5f7420b0770551e9e223c49f39f4daf5e1dec4c2 100644 (file)
@@ -32,7 +32,7 @@
 #include <pwd.h>
 #include <stdarg.h>
 #include <errno.h>
-
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "axdefs.h"
@@ -45,7 +45,6 @@
 #include "client_chat.h"
 #include "client_passwords.h"
 #include "citadel_decls.h"
-#include "tools.h"
 #include "sysdep.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
index b679de7e34982eff75ed20540598be5a4eb70dd0..96d5f1e7917e9b5a70567aa107d1282d9a0185a3 100644 (file)
 #ifdef THREADED_CLIENT
 #include <pthread.h>
 #endif
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
-#include "tools.h"
 #include "citadel_dirs.h"
 #ifdef THREADED_CLIENT
 pthread_mutex_t rwlock;
index 5241407343bc3cb5167a917b5da323353b5ce449..f47d8f2ab3f43de5def3748793f3984b72acbf62 100644 (file)
@@ -22,8 +22,8 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
-#include "tools.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
index 966bbbe8dedc10bbdd865067689295e618ef3911..6a85744a55ce04d0a653223c7af813b2d0bc07f4 100644 (file)
@@ -40,6 +40,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -55,7 +56,6 @@
 #include "file_ops.h"
 #include "policy.h"
 #include "control.h"
-#include "tools.h"
 #include "euidindex.h"
 
 #ifndef HAVE_SNPRINTF
index a1ad06ce101ea34b9094d062055431bb221adf98..d2dd9cf44309855c728eadc4e4d6725387426205 100644 (file)
 #include <sys/select.h>
 #endif
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "client_chat.h"
 #include "commands.h"
 #include "routines.h"
 #include "citadel_decls.h"
-#include "tools.h"
 #include "rooms.h"
 #include "messages.h"
 #ifndef HAVE_SNPRINTF
index 2087f1b7a722e661b111b6a43a4573026b333adf..f764626d1d4e9616e951f48bb2bcb368aef306b5 100644 (file)
@@ -16,9 +16,9 @@
 #include <sys/stat.h>
 #include <limits.h>
 #include <stdio.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
-#include "tools.h"
 #include "commands.h"
 #include "client_passwords.h"
 
@@ -109,14 +109,14 @@ void set_stored_password(
                   || (strcasecmp(portbuf, port)) ) {
                        snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
                                hostbuf, portbuf, ubuf, pbuf);
-                       CtdlEncodeBase64(buf64, buf, strlen(buf));
+                       CtdlEncodeBase64(buf64, buf, strlen(buf), 0);
                        fprintf(fp, "%s\n", buf64);
                }
        }
        if (!IsEmptyStr(username)) {
                snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
                        host, port, username, password);
-               CtdlEncodeBase64(buf64, buf, strlen(buf));
+               CtdlEncodeBase64(buf64, buf, strlen(buf), 0);
                fprintf(fp, "%s\n", buf64);
        }
        fclose(oldfp);
index 5b5bb90b276e501d060a94da4291e4dff96358d9..1d65e2ca8bf58084b23d3d03a8c5cb2b167a8c95 100644 (file)
@@ -23,6 +23,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #ifndef HAVE_SNPRINTF
@@ -31,7 +32,6 @@
 #include "sysdep_decls.h"
 #include "config.h"
 #include "clientsocket.h"
-#include "tools.h"
 
 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff
index 9e2af999138aef30dd88e860e2f22023fa2c02de..82db34c9e7311647c97e0b2d4181ba9146a931f1 100644 (file)
@@ -43,6 +43,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "commands.h"
@@ -50,7 +51,6 @@
 #include "citadel_decls.h"
 #include "routines.h"
 #include "routines2.h"
-#include "tools.h"
 #include "rooms.h"
 #include "client_chat.h"
 #include "citadel_dirs.h"
index a5eb62499aa24f53340035943508c24df139c7ec..74e707208efad53ded8cc3b96064d192e6dcd1de 100644 (file)
@@ -393,6 +393,26 @@ fi
 
 test -d /usr/kerberos/include && CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
 
+
+dnl Check for libcitadel
+AC_CHECK_HEADER(libcitadel.h,
+       [AC_CHECK_LIB(citadel, libcitadel_version_string,
+               [
+                       AC_MSG_RESULT(OK)
+                       LIBS="-lcitadel $LIBS"
+               ],
+               [
+                       AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
+               ]
+       ,
+       )],
+       [
+               AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
+       ]
+)
+
+
+
 # The big search for OpenSSL
 if test "$with_ssl" != "no"; then
        saved_LIBS="$LIBS"
index fe625d0512cf2570cdbb1ef4e0bb446fc9f75411..e142504c661d847784be09ae1f616149aa4dea01 100644 (file)
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <sys/types.h>
 #include <sys/file.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "control.h"
@@ -37,7 +38,6 @@
 #include "config.h"
 #include "msgbase.h"
 #include "citserver.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "database.h"
index d7bd402de868f2352e71b8ba91331c43c868da91..da1c9bf9544020d10f4d0314435b31f55bc8222b 100644 (file)
 #endif
 #include <resolv.h>
 #endif
-
+#include <libcitadel.h>
 #include "sysdep_decls.h"
 #include "citadel.h"
 #include "domain.h"
 #include "server.h"
-#include "tools.h"
 #include "internet_addressing.h"
 
 
index 5f25615f98f9d0b6baa8709e75f0ef6edaa21368..1e87e25d226cf9134d6a141afa7dd80b4ca7c390 100644 (file)
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <sys/stat.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -41,7 +42,6 @@
 #include "file_ops.h"
 #include "config.h"
 #include "control.h"
-#include "tools.h"
 #include "euidindex.h"
 
 /*
index 30c65067b8df26a23e33dcdd0c938afdb2ddbe07..b5db777432b70ba9cb467b5d165086d52f69000c 100644 (file)
@@ -28,6 +28,7 @@
 #endif
 
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "config.h"
@@ -37,7 +38,6 @@
 #include "support.h"
 #include "room_ops.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "citserver.h"
 
 #ifndef HAVE_SNPRINTF
index 6ed3405be5f5468ee3f26357dc6f4e6d3a1082b2..664c81e08e20e8f9b37cf6145d0fa613ef951c5a 100644 (file)
@@ -29,8 +29,8 @@
 #include <signal.h>
 #include <errno.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
-#include "tools.h"
 #include "citadel_ipc.h"
 #include "server.h"
 #include "config.h"
index 38995277cb306c74a6fe0ed5cc0d1982db999ebd..3a02ef569a028d66c007e7aa115e4cb8dbaf8174 100644 (file)
@@ -30,7 +30,7 @@
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
-#include "tools.h"
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
index ad22efdf25da00fc25dfc1a23584019d91fe619e..bc9006a3bbff4c0f54ac4a0f3494534f60068d45 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "control.h"
@@ -35,7 +36,6 @@
 #include "support.h"
 #include "config.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "html.h"
  
index ae8a6ceed7c0c31f1d170bff6492c4eadad2208c..1b414be7de8e8d19f6cb6b820a19b59825175db0 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "tools.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
 #include "user_ops.h"
index b0e8ea07ef68d29e8daeec6024f8673664bfc400..bc68721c6aa9e768199ef70027fe8dce2843abe3 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
-#include "tools.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
index f0464a999adca9124bd9673c396e8bc8523048b7..9ea77286034bc616b87819cbde036828aded467e 100644 (file)
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <sys/stat.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -41,8 +42,6 @@
 #include "file_ops.h"
 #include "config.h"
 #include "control.h"
-#include "tools.h"
-#include "mime_parser.h"
 #include "html.h"
 #include "genstamp.h"
 #include "internet_addressing.h"
index 744bc7e3c76e2296b694616e3695659f43fe791a..4df8e19e72b29c8aae6d1aec44ef75e301c9860d 100644 (file)
 #include <limits.h>
 #include <netdb.h>
 #include <string.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "locate_host.h"
 #include "sysdep_decls.h"
 #include "config.h"
-#include "tools.h"
 #include "domain.h"
 
 #ifdef HAVE_RESOLV_H
index 0d822804c346bdc13f37340976cd0753aac35354..ee067bd5a091639463f6a8490be1f8038bb1e787 100644 (file)
 #endif
 
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
 #include "messages.h"
 #include "commands.h"
 #include "rooms.h"
-#include "tools.h"
 #include "html.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
diff --git a/citadel/mime_parser.c b/citadel/mime_parser.c
deleted file mode 100644 (file)
index a1a4965..0000000
+++ /dev/null
@@ -1,611 +0,0 @@
-/*
- * $Id$
- *
- * This is the MIME parser for Citadel.
- *
- * Copyright (c) 1998-2006 by Art Cancro
- * This code is distributed under the GNU General Public License v2.
- *
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-#include "citadel.h"
-#include "server.h"
-#include "sysdep_decls.h"
-#include "tools.h"
-
-#include "mime_parser.h"
-
-
-void extract_key(char *target, char *source, char *key)
-{
-       char *ptr;
-       char looking_for[256];
-       int double_quotes = 0;
-
-       snprintf(looking_for, sizeof looking_for, "%s=", key);
-
-       ptr = bmstrcasestr(source, looking_for);
-       if (ptr == NULL) {
-               strcpy(target, "");
-               return;
-       }
-       strcpy(target, (ptr + strlen(looking_for)));
-
-       for (ptr=target; (*ptr != 0); ++ptr) {
-
-               /* A semicolon means we've hit the end of the key, unless we're inside double quotes */
-               if ( (double_quotes != 1) && (*ptr == ';')) {
-                       *ptr = 0;
-               }
-
-               /* if we find double quotes, we've got a great set of string boundaries */
-               if (*ptr == '\"') {
-                       ++double_quotes;
-                       if (double_quotes == 1) {
-                               strcpy(ptr, ptr+1);
-                       }
-                       else {
-                               *ptr = 0;
-                       }
-               }
-       }
-}
-
-
-/*
- * For non-multipart messages, we need to generate a quickie partnum of "1"
- * to return to callback functions.  Some callbacks demand it.
- */
-char *fixed_partnum(char *supplied_partnum) {
-       if (supplied_partnum == NULL) return "1";
-       if (strlen(supplied_partnum)==0) return "1";
-       return supplied_partnum;
-}
-
-
-
-/*
- * Given a message or message-part body and a length, handle any necessary
- * decoding and pass the request up the stack.
- */
-void mime_decode(char *partnum,
-                char *part_start, size_t length,
-                char *content_type, char *charset, char *encoding,
-                char *disposition,
-                char *name, char *filename,
-                void (*CallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                void (*PreMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                void (*PostMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                 void *userdata,
-                 int dont_decode
-)
-{
-
-       char *decoded;
-       size_t bytes_decoded = 0;
-
-       /* Some encodings aren't really encodings */
-       if (!strcasecmp(encoding, "7bit"))
-               strcpy(encoding, "");
-       if (!strcasecmp(encoding, "8bit"))
-               strcpy(encoding, "");
-       if (!strcasecmp(encoding, "binary"))
-               strcpy(encoding, "");
-
-       /* If this part is not encoded, send as-is */
-       if ( (strlen(encoding) == 0) || (dont_decode)) {
-               if (CallBack != NULL) {
-                       CallBack(name, filename, fixed_partnum(partnum),
-                               disposition, part_start,
-                               content_type, charset, length, encoding, userdata);
-                       }
-               return;
-       }
-       
-       /* Fail silently if we hit an unknown encoding. */
-       if ((strcasecmp(encoding, "base64"))
-           && (strcasecmp(encoding, "quoted-printable"))) {
-               return;
-       }
-
-       /*
-        * Allocate a buffer for the decoded data.  The output buffer is slightly
-        * larger than the input buffer; this assumes that the decoded data
-        * will never be significantly larger than the encoded data.  This is a
-        * safe assumption with base64, uuencode, and quoted-printable.
-        */
-       decoded = malloc(length + 32768);
-       if (decoded == NULL) {
-               return;
-       }
-
-       if (!strcasecmp(encoding, "base64")) {
-               bytes_decoded = CtdlDecodeBase64(decoded, part_start, length);
-       }
-       else if (!strcasecmp(encoding, "quoted-printable")) {
-               bytes_decoded = CtdlDecodeQuotedPrintable(decoded, part_start, length);
-       }
-
-       if (bytes_decoded > 0) if (CallBack != NULL) {
-               CallBack(name, filename, fixed_partnum(partnum),
-                       disposition, decoded,
-                       content_type, charset, bytes_decoded, "binary", userdata);
-       }
-
-       free(decoded);
-}
-
-/*
- * Break out the components of a multipart message
- * (This function expects to be fed HEADERS + CONTENT)
- * Note: NULL can be supplied as content_end; in this case, the message is
- * considered to have ended when the parser encounters a 0x00 byte.
- */
-void the_mime_parser(char *partnum,
-                    char *content_start, char *content_end,
-                    void (*CallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                    void (*PreMultiPartCallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                    void (*PostMultiPartCallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                     void *userdata,
-                     int dont_decode
-)
-{
-
-       char *ptr;
-       char *srch = NULL;
-       char *part_start, *part_end = NULL;
-       char buf[SIZ];
-       char *header;
-       char *boundary;
-       char *startary;
-       size_t startary_len = 0;
-       char *endary;
-       char *next_boundary;
-       char *content_type;
-       char *charset;
-       size_t content_length;
-       char *encoding;
-       char *disposition;
-       char *name = NULL;
-       char *content_type_name;
-       char *content_disposition_name;
-       char *filename;
-       int is_multipart;
-       int part_seq = 0;
-       int i;
-       size_t length;
-       char nested_partnum[256];
-       int crlf_in_use = 0;
-       char *evaluate_crlf_ptr = NULL;
-       int buflen = 0;
-       int headerlen = 0;
-
-       ptr = content_start;
-       content_length = 0;
-
-       boundary = malloc(SIZ);
-       memset(boundary, 0, SIZ);
-
-       startary = malloc(SIZ);
-       memset(startary, 0, SIZ);
-
-       endary = malloc(SIZ);
-       memset(endary, 0, SIZ);
-
-       header = malloc(SIZ);
-       memset(header, 0, SIZ);
-
-       content_type = malloc(SIZ);
-       memset(content_type, 0, SIZ);
-
-       charset = malloc(SIZ);
-       memset(charset, 0, SIZ);
-
-       encoding = malloc(SIZ);
-       memset(encoding, 0, SIZ);
-
-       content_type_name = malloc(SIZ);
-       memset(content_type_name, 0, SIZ);
-
-       content_disposition_name = malloc(SIZ);
-       memset(content_disposition_name, 0, SIZ);
-
-       filename = malloc(SIZ);
-       memset(filename, 0, SIZ);
-
-       disposition = malloc(SIZ);
-       memset(disposition, 0, SIZ);
-
-       /* If the caller didn't supply an endpointer, generate one by measure */
-       if (content_end == NULL) {
-               content_end = &content_start[strlen(content_start)];
-       }
-
-       /* Learn interesting things from the headers */
-       strcpy(header, "");
-       headerlen = 0;
-       do {
-               ptr = memreadlinelen(ptr, buf, SIZ, &buflen);
-               if (ptr >= content_end) {
-                       goto end_parser;
-               }
-
-               for (i = 0; i < buflen; ++i) {
-                       if (isspace(buf[i])) {
-                               buf[i] = ' ';
-                       }
-               }
-
-               if (!isspace(buf[0])) {
-                       if (!strncasecmp(header, "Content-type:", 13)) {
-                               strcpy(content_type, &header[13]);
-                               striplt(content_type);
-                               extract_key(content_type_name, content_type, "name");
-                               extract_key(charset, content_type, "charset");
-                               extract_key(boundary, header, "boundary");
-                               /* Deal with weird headers */
-                               if (strchr(content_type, ' '))
-                                       *(strchr(content_type, ' ')) = '\0';
-                               if (strchr(content_type, ';'))
-                                       *(strchr(content_type, ';')) = '\0';
-                       }
-                       if (!strncasecmp(header, "Content-Disposition:", 20)) {
-                               strcpy(disposition, &header[20]);
-                               striplt(disposition);
-                               extract_key(content_disposition_name, disposition, "name");
-                               extract_key(filename, disposition, "filename");
-                       }
-                       if (!strncasecmp(header, "Content-length: ", 15)) {
-                               char clbuf[10];
-                               safestrncpy(clbuf, &header[15], sizeof clbuf);
-                               striplt(clbuf);
-                               content_length = (size_t) atol(clbuf);
-                       }
-                       if (!strncasecmp(header, "Content-transfer-encoding: ", 26)) {
-                               strcpy(encoding, &header[26]);
-                               striplt(encoding);
-                       }
-                       strcpy(header, "");
-                       headerlen = 0;
-               }
-               if ((headerlen + buflen + 2) < SIZ) {
-                       memcpy(&header[headerlen], buf, buflen);
-                       headerlen += buflen;
-                       header[headerlen] = '\0';
-               }
-       } while ((!IsEmptyStr(buf)) && (*ptr != 0));
-
-       if (strchr(disposition, ';'))
-               *(strchr(disposition, ';')) = '\0';
-       striplt(disposition);
-       if (strchr(content_type, ';'))
-               *(strchr(content_type, ';')) = '\0';
-       striplt(content_type);
-
-       if (!IsEmptyStr(boundary)) {
-               is_multipart = 1;
-       } else {
-               is_multipart = 0;
-       }
-
-       /* If this is a multipart message, then recursively process it */
-       part_start = NULL;
-       if (is_multipart) {
-
-               /* Tell the client about this message's multipartedness */
-               if (PreMultiPartCallBack != NULL) {
-                       PreMultiPartCallBack("", "", partnum, "",
-                               NULL, content_type, charset,
-                               0, encoding, userdata);
-               }
-
-               /* Figure out where the boundaries are */
-               snprintf(startary, SIZ, "--%s", boundary);
-               snprintf(endary, SIZ, "--%s--", boundary);
-               startary_len = strlen(startary);
-
-               part_start = NULL;
-               do {
-                       next_boundary = NULL;
-                       for (srch=ptr; srch<content_end; ++srch) {
-                               if (!memcmp(srch, startary, startary_len)) {
-                                       next_boundary = srch;
-                                       srch = content_end;
-                               }
-                       }
-
-                       if ( (part_start != NULL) && (next_boundary != NULL) ) {
-                               part_end = next_boundary;
-                               --part_end;             /* omit the trailing LF */
-                               if (crlf_in_use) {
-                                       --part_end;     /* omit the trailing CR */
-                               }
-
-                               if (!IsEmptyStr(partnum)) {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%s.%d", partnum,
-                                                ++part_seq);
-                               }
-                               else {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%d", ++part_seq);
-                               }
-                               the_mime_parser(nested_partnum,
-                                           part_start, part_end,
-                                               CallBack,
-                                               PreMultiPartCallBack,
-                                               PostMultiPartCallBack,
-                                               userdata,
-                                               dont_decode);
-                       }
-
-                       if (next_boundary != NULL) {
-                               /* If we pass out of scope, don't attempt to
-                                * read past the end boundary. */
-                               if (!strcmp(next_boundary, endary)) {
-                                       ptr = content_end;
-                               }
-                               else {
-                                       /* Set up for the next part. */
-                                       part_start = strstr(next_boundary, "\n");
-                                       
-                                       /* Determine whether newlines are LF or CRLF */
-                                       evaluate_crlf_ptr = part_start;
-                                       --evaluate_crlf_ptr;
-                                       if (!memcmp(evaluate_crlf_ptr, "\r\n", 2)) {
-                                               crlf_in_use = 1;
-                                       }
-                                       else {
-                                               crlf_in_use = 0;
-                                       }
-
-                                       /* Advance past the LF ... now we're in the next part */
-                                       ++part_start;
-                                       ptr = part_start;
-                               }
-                       }
-                       else {
-                               /* Invalid end of multipart.  Bail out! */
-                               ptr = content_end;
-                       }
-               } while ( (ptr < content_end) && (next_boundary != NULL) );
-
-               if (PostMultiPartCallBack != NULL) {
-                       PostMultiPartCallBack("", "", partnum, "", NULL,
-                               content_type, charset, 0, encoding, userdata);
-               }
-               goto end_parser;
-       }
-
-       /* If it's not a multipart message, then do something with it */
-       if (!is_multipart) {
-               part_start = ptr;
-               length = 0;
-               while (ptr < content_end) {
-                       ++ptr;
-                       ++length;
-               }
-               part_end = content_end;
-
-               /******
-                * I thought there was an off-by-one error here, but there isn't.
-                * This probably means that there's an off-by-one error somewhere
-                * else ... or maybe only in certain messages?
-               --part_end;
-               --length;
-               ******/
-               
-               /* Truncate if the header told us to */
-               if ( (content_length > 0) && (length > content_length) ) {
-                       length = content_length;
-               }
-
-               /* Sometimes the "name" field is tacked on to Content-type,
-                * and sometimes it's tacked on to Content-disposition.  Use
-                * whichever one we have.
-                */
-               if (strlen(content_disposition_name) > strlen(content_type_name)) {
-                       name = content_disposition_name;
-               }
-               else {
-                       name = content_type_name;
-               }
-       
-               /* lprintf(CTDL_DEBUG, "mime_decode part=%s, len=%d, type=%s, charset=%s, encoding=%s\n",
-                       partnum, length, content_type, charset, encoding); */
-
-               /* Ok, we've got a non-multipart part here, so do something with it.
-                */
-               mime_decode(partnum,
-                       part_start, length,
-                       content_type, charset, encoding, disposition,
-                       name, filename,
-                       CallBack, NULL, NULL,
-                       userdata, dont_decode
-               );
-
-               /*
-                * Now if it's an encapsulated message/rfc822 then we have to recurse into it
-                */
-               if (!strcasecmp(content_type, "message/rfc822")) {
-
-                       if (PreMultiPartCallBack != NULL) {
-                               PreMultiPartCallBack("", "", partnum, "",
-                                       NULL, content_type, charset,
-                                       0, encoding, userdata);
-                       }
-                       if (CallBack != NULL) {
-                               if (strlen(partnum) > 0) {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%s.%d", partnum,
-                                                ++part_seq);
-                               }
-                               else {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%d", ++part_seq);
-                               }
-                               the_mime_parser(nested_partnum,
-                                       part_start, part_end,
-                                       CallBack,
-                                       PreMultiPartCallBack,
-                                       PostMultiPartCallBack,
-                                       userdata,
-                                       dont_decode
-                               );
-                       }
-                       if (PostMultiPartCallBack != NULL) {
-                               PostMultiPartCallBack("", "", partnum, "", NULL,
-                                       content_type, charset, 0, encoding, userdata);
-                       }
-
-
-               }
-
-       }
-
-end_parser:    /* free the buffers!  end the oppression!! */
-       free(boundary);
-       free(startary);
-       free(endary);   
-       free(header);
-       free(content_type);
-       free(charset);
-       free(encoding);
-       free(content_type_name);
-       free(content_disposition_name);
-       free(filename);
-       free(disposition);
-}
-
-
-
-/*
- * Entry point for the MIME parser.
- * (This function expects to be fed HEADERS + CONTENT)
- * Note: NULL can be supplied as content_end; in this case, the message is
- * considered to have ended when the parser encounters a 0x00 byte.
- */
-void mime_parser(char *content_start,
-               char *content_end,
-
-                void (*CallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                void (*PreMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                void (*PostMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                 void *userdata,
-                 int dont_decode
-)
-{
-
-       the_mime_parser("", content_start, content_end,
-                       CallBack,
-                       PreMultiPartCallBack,
-                       PostMultiPartCallBack,
-                       userdata, dont_decode);
-}
diff --git a/citadel/mime_parser.h b/citadel/mime_parser.h
deleted file mode 100644 (file)
index b82cd68..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * $Id$
- *
- */
-
-/*
- * Here's a bunch of stupid magic to make the MIME parser portable between
- * Citadel and WebCit.
- */
-#ifndef SIZ
-#define SIZ    4096
-#endif
-
-
-/* 
- * Declarations for functions in the parser
- */
-
-void extract_key(char *target, char *source, char *key);
-
-void mime_parser(char *content_start, char *content_end,
-               void (*CallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void (*PreMultiPartCallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void (*PostMultiPartCallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void *userdata,
-               int dont_decode
-               );
index 5aaedd8cbfa875caed9616f9941759bca84c8959..9ca03240c342d26236479e6a9c6214c461bb17a2 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "tools.h"
 #include "msgbase.h"
 #include "user_ops.h"
 #include "room_ops.h"
index 9f5589b3b2434af55248a65e177375a58a8c5931..8f875a43520fba1df0577404404ddd43b8f8d147 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -41,7 +42,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "citadel_dirs.h"
 
 #include "ctdl_module.h"
index 1f47e72d76e8a5266f9543c00fbcaf3e8ac14dd7..cd55a1339789224d74c61397c130d15f474d5e67 100644 (file)
@@ -19,6 +19,7 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -26,9 +27,7 @@
 #include "config.h"
 #include "user_ops.h"
 #include "room_ops.h"
-#include "tools.h"
 #include "msgbase.h"
-#include "mime_parser.h"
 #include "internet_addressing.h"
 #include "serv_calendar.h"
 #include "euidindex.h"
index fff6640fe55f9156af8f546238e2c0202ec48adf..b62f48524c626538b712a09d7521e7291a20618e 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_chat.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "tools.h"
 #include "msgbase.h"
 #include "user_ops.h"
 #include "room_ops.h"
index ee41a5f84f4546a19745ff799875732024db988d..254ee5a10fbdd97d1e3ad17dd47b5874a114abab 100644 (file)
@@ -49,6 +49,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -61,7 +62,6 @@
 #include "user_ops.h"
 #include "control.h"
 #include "serv_network.h"      /* Needed for defenition of UseTable */
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index 12b0f667c00d1b111073cfe86da475adeaf0fe12..4a03e1b77c6289877ba42815a439bd0e925d4b11 100644 (file)
@@ -31,6 +31,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -40,7 +41,6 @@
 #include "database.h"
 #include "msgbase.h"
 #include "control.h"
-#include "tools.h"
 #include "ft_wordbreaker.h"
 #include "crc16.h"
 
index 4e12ead4ae7c6513378e66a9c90eddc1f116c11e..5ba8b5a37c74d21fee67fa7b2885b54ede4ff208 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "msgbase.h"
 #include "control.h"
 #include "room_ops.h"
-#include "tools.h"
 #include "serv_fulltext.h"
 #include "ft_wordbreaker.h"
 
index 33aecdf5b22022a3c874f6dd656ec1f0ad6812a7..23b17b47099e3933be1d7831943270ec6003dbe2 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <limits.h>
 #include <sys/socket.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "user_ops.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "domain.h"
 #include "clientsocket.h"
index 369afce88e896a53d7d693075bcdb6ae73150c0d..55a010982ec870d2851a8c753800fed8badf6f68 100644 (file)
@@ -31,6 +31,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -42,7 +43,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 6a8104b969cf8f927c1a09c4636d91f360b3fa9a..3cd92cb32717722bd7f9e0ca19fad11d651a7137 100644 (file)
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -43,9 +44,7 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
-#include "mime_parser.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
 #include "imap_fetch.h"
index 87ff5854921dbf3ac9da229be2fd59e8431b0c6b..023a0dca9f61c92f87629fcbb264a0d94c055707 100644 (file)
@@ -33,6 +33,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -44,7 +45,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 4dde983f9792799d650984badac55d8006417b9d..fef885071bb7e2a73afbc64048b17ef1695703d0 100644 (file)
@@ -33,6 +33,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -44,7 +45,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 8525216b8d5b259c21ce2f7ba73085e05e2d389d..3b7d95834314ddbb8d60596ab4373e36b1eb0702 100644 (file)
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -41,7 +42,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 7cbf9e320a30d64201622fffcdb4ae1283204d88..7efc71ed6cd5db87d4f9aaddfd79fcfc9cbf687b 100644 (file)
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -41,7 +42,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index b564380aaed335c3639f4fea5f78c44cace0955e..80167ab49bd18802e0bc8f1756430a7f2576c75d 100644 (file)
@@ -31,6 +31,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -42,7 +43,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 080f9db7c0da74855888c081c1a321708207d763..0e62a407c34900af08df5453813cad6d4c96c2ac 100644 (file)
@@ -12,9 +12,9 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "sysdep_decls.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "internet_addressing.h"
 #include "imap_tools.h"
index 098ce942f5c520b402bac201ebb1a4fed42de264..c86518fb8f08b7a890939b05debd6af1805a52ad 100644 (file)
@@ -35,6 +35,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -45,7 +46,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
@@ -557,7 +557,7 @@ void imap_authenticate(int num_parms, char *parms[])
        }
 
        if (!strcasecmp(parms[2], "LOGIN")) {
-               CtdlEncodeBase64(buf, "Username:", 9);
+               CtdlEncodeBase64(buf, "Username:", 9, 0);
                cprintf("+ %s\r\n", buf);
                IMAP->authstate = imap_as_expecting_username;
                strcpy(IMAP->authseq, parms[0]);
@@ -565,7 +565,7 @@ void imap_authenticate(int num_parms, char *parms[])
        }
 
        if (!strcasecmp(parms[2], "PLAIN")) {
-               // CtdlEncodeBase64(buf, "Username:", 9);
+               // CtdlEncodeBase64(buf, "Username:", 9, 0);
                // cprintf("+ %s\r\n", buf);
                cprintf("+ \r\n");
                IMAP->authstate = imap_as_expecting_plainauth;
@@ -616,7 +616,7 @@ void imap_auth_login_user(char *cmd)
 
        CtdlDecodeBase64(buf, cmd, SIZ);
        CtdlLoginExistingUser(NULL, buf);
-       CtdlEncodeBase64(buf, "Password:", 9);
+       CtdlEncodeBase64(buf, "Password:", 9, 0);
        cprintf("+ %s\r\n", buf);
        IMAP->authstate = imap_as_expecting_password;
        return;
index 90f4431fd2613701274b810a661fa27673424359..8fb48f19aec40551a50a82944dd4e6f18c56515e 100644 (file)
@@ -32,6 +32,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -42,7 +43,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "genstamp.h"
 #include "domain.h"
index f684344c459bf497ec7150ba5e25a50e7901dccf..c2b786529fbb40b65025325f2b4497bb7a5d6fdb 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -38,7 +39,6 @@
 #include "policy.h"
 #include "database.h"
 #include "serv_ldap.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index 8b1db778896e7f6efd5dceb5c6d5025aba1e6e0d..0eb2300f2247c241f327a0990d556ac7b28588f0 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -43,7 +44,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "clientsocket.h"
 #include "file_ops.h"
@@ -74,7 +74,7 @@ void listsub_generate_token(char *buf) {
        );
 
        /* Convert it to base64 so it looks cool */     
-       CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf));
+       CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf), 0);
 }
 
 
index dacc789f9c298d1158c91a9aa3b6cd847771f318..065702fa1ef8631d03533092f731e68e5e3862bd 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -49,7 +50,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "imap_tools.h"        /* Needed for imap_parameterize */
 #include "genstamp.h"
@@ -444,7 +444,7 @@ void mgsve_auth(char *argbuf) {
                if (strlen(argbuf) >= 7) {
                }
                else {
-                       CtdlEncodeBase64(username_prompt, "Username:", 9);
+                       CtdlEncodeBase64(username_prompt, "Username:", 9, 0);
                        cprintf("334 %s\r\n", username_prompt);
                }
                return;
index 12e09f0f0ec89c96c93b5b005ae21c4ae37627d4..dab0ab7b809ad90f33eaba51e503b37d08d85af6 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -44,7 +45,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index edaf01d4f86a2b2c5091bca452167f4b14403be4..09fe8c0f990ab9d33b38c8baded797d78018c4da 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -42,7 +43,6 @@
 #include "database.h"
 #include "msgbase.h"
 #include "serv_network.h"      /* Needed for defenition of FilterList */
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index d84fe2f70b115a34e0d3c0ec111d63f246b8e76c..06363b92d3d8565fadfdd40923005f1e48f179e6 100644 (file)
@@ -48,6 +48,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -58,7 +59,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_network.h"
 #include "clientsocket.h"
index 18494fde67468d4189c12338681a6c4b58337a96..0dedda9e323c13d026377f8e0ea541620dea0728 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 
 #include "ctdl_module.h"
 
index 5e6b0d25d08d1194c83b0bb8baf6ce38cb305727..bdafbc85f3dee67a1804fe3e4d78798b58ecead2 100644 (file)
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <limits.h>
 #include <sys/socket.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -44,7 +45,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "domain.h"
 #include "clientsocket.h"
index fd7fbf246dc94513c684bffe5a28ca3264ccfa9b..7df51d60dfcd19786d91a53e871b85b59a0f1c98 100644 (file)
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "support.h"
 #include "user_ops.h"
 #include "md5.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index e8f975c4dc5999508a6db56ed31aea114f86a0c6..6aaa628a4cdd236eb535787b327c3e3d8ddc124e 100644 (file)
@@ -41,6 +41,7 @@
 #include <string.h>
 #include <limits.h>
 #include <ctype.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -51,7 +52,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_pop3.h"
 #include "md5.h"
index 89546015cd600b13e165fd525fb22d06a3039910..5046a985d4ff0aa4790b335c466bb6be2a52883d 100644 (file)
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "ctdl_module.h"
 #include "clientsocket.h"
index a7093efa32fd4bf019a0e27d8e26145d8685d660..868516907a7bbefa6dab1a9c3d1f86b4bb225fdf 100644 (file)
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "tools.h"
 #include "room_ops.h"
 #include "ctdl_module.h"
 #include "clientsocket.h"
index d8a1285babaf72f612b672d2896d3fe81a161e36..1c9f7a7a48e9fb59db3974287d2a14535fcf9484 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -41,7 +42,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index aeb977bbb9d15c1eff647c6245bdc4c15c66301d..e92ebdc8f24b1e36622c81daf5ad632dd6632f5d 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -41,7 +42,6 @@
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
-#include "tools.h"
 
 
 #include "ctdl_module.h"
index ac60e79d7311cfaa73eea5233bfe67ced6c47a66..b444ab4fed46e89b6748fc7b12207c91fcddbb49 100644 (file)
@@ -55,6 +55,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -66,7 +67,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "genstamp.h"
 #include "domain.h"
@@ -316,7 +316,7 @@ void smtp_get_user(char *argbuf) {
        CtdlDecodeBase64(username, argbuf, SIZ);
        /* lprintf(CTDL_DEBUG, "Trying <%s>\n", username); */
        if (CtdlLoginExistingUser(NULL, username) == login_ok) {
-               CtdlEncodeBase64(buf, "Password:", 9);
+               CtdlEncodeBase64(buf, "Password:", 9, 0);
                cprintf("334 %s\r\n", buf);
                SMTP->command_state = smtp_password;
        }
@@ -399,7 +399,7 @@ void smtp_auth(char *argbuf) {
                        smtp_get_user(&argbuf[6]);
                }
                else {
-                       CtdlEncodeBase64(username_prompt, "Username:", 9);
+                       CtdlEncodeBase64(username_prompt, "Username:", 9, 0);
                        cprintf("334 %s\r\n", username_prompt);
                        SMTP->command_state = smtp_user;
                }
@@ -1111,7 +1111,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        if (!IsEmptyStr(mx_user)) {
                char encoded[1024];
                sprintf(buf, "%s%c%s%c%s", mx_user, '\0', mx_user, '\0', mx_pass);
-               CtdlEncodeBase64(encoded, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 2);
+               CtdlEncodeBase64(encoded, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 2, 0);
                snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", encoded);
                lprintf(CTDL_DEBUG, ">%s", buf);
                sock_write(sock, buf, strlen(buf));
index cdf81557af86511a10eafab7d5ae49dc25bb00b2..415f03cae768a71752953298fab621998b304c80 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <limits.h>
 #include <sys/socket.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -45,7 +46,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "domain.h"
 #include "clientsocket.h"
index 2956e79a088382d9f1ed178b6374b011a348d552..8676ab9ae6146b9b27241c0b22a40f92755bc018 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "room_ops.h"
 #include "user_ops.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "serv_upgrade.h"
 #include "euidindex.h"
 
index c79e1eeee6b2c5ed1a468fb2adf85e3fc5215995..576089f3ccd9492fb2bacd760cf80e3505411813 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -37,7 +38,6 @@
 #include "config.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "user_ops.h"
 #include "room_ops.h"
 #include "control.h"
index 8925228e6b38140b063a87beaaeff84ab212640c..0e3d264f82b5b7d3454102a504f2f6366c156cfb 100644 (file)
@@ -47,6 +47,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -59,8 +60,6 @@
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
-#include "tools.h"
-#include "mime_parser.h"
 #include "vcard.h"
 #include "serv_vcard.h"
 
index ac2e54d2d2ad33ccc10ae33dbbaf02db34659429..48f2eb727afe8a06ee17c44a50d77ba6b8083cbb 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <regex.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
@@ -44,8 +45,6 @@
 #include "file_ops.h"
 #include "config.h"
 #include "control.h"
-#include "tools.h"
-#include "mime_parser.h"
 #include "html.h"
 #include "genstamp.h"
 #include "internet_addressing.h"
@@ -4234,7 +4233,8 @@ void CtdlWriteObject(char *req_room,              /* Room to stuff it in */
                CtdlEncodeBase64(
                        &encoded_message[strlen(encoded_message)],
                        raw_message,
-                       (int)raw_length
+                       (int)raw_length,
+                       0
                );
        }
        else {
index 3c0a6d0fa58b53bd83dc94dbac9abd349bb708c3..c17a2577904aabcc255fb70648039d3b5225ba69 100644 (file)
@@ -31,8 +31,7 @@
 #endif
 
 #include <errno.h>
-#include "tools.h"
-
+#include <libcitadel.h>
 
 int qwk = 0;
 
index 804416e71df443932841ac0627b12041445c7ff9..226e985dc58e0eb61516af618a380c457f369062 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -33,7 +34,6 @@
 #include "user_ops.h"
 #include "msgbase.h"
 #include "citserver.h"
-#include "tools.h"
 
 
 /*
index af6cb2149babc141aafbc0394f8191aae5eaf43a..4a5ed25da095a2e066b080d9ec0afc6aecb5b01a 100644 (file)
@@ -28,6 +28,7 @@
 #include <limits.h>
 #include <errno.h>
 #include "citadel.h"
+#include <libcitadel.h>
 #include "server.h"
 #include "database.h"
 #include "config.h"
@@ -38,7 +39,6 @@
 #include "msgbase.h"
 #include "citserver.h"
 #include "control.h"
-#include "tools.h"
 #include "citadel_dirs.h"
 
 struct floor *floorcache[MAXFLOORS];
index 649b21a9909479b86d210feb2c5030b49c7fac87..87d46f8bb61a387614300496f5696671227f8378 100644 (file)
 #include <sys/wait.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_decls.h"
 #include "rooms.h"
 #include "commands.h"
-#include "tools.h"
 #include "messages.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
index 30db9a5ce161671d2e6bc7cb987d78d1c8d531ce..08f89540a5c714ce4743a72615c8834971501aa3 100644 (file)
@@ -29,6 +29,7 @@
 #  include <time.h>
 # endif
 #endif
+
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
 #endif
@@ -38,6 +39,8 @@
 #ifdef HAVE_UTMPX_H
 #include <utmpx.h>
 #endif
+
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "screen.h"
@@ -51,7 +54,6 @@ struct utmp *getutline(struct utmp *ut);
 #include "citadel.h"
 #include "routines.h"
 #include "commands.h"
-#include "tools.h"
 #include "citadel_decls.h"
 #include "routines2.h"
 
index 9d8e50976627142d65731aae40476e2a3971ab3b..6bb516a2cd848a7378e716e2bdb1d7187c7d86d5 100644 (file)
@@ -7,7 +7,6 @@ void enter_config(CtdlIPC* ipc, int mode);
 void locate_host(CtdlIPC* ipc, char *hbuf);
 void misc_server_cmd(CtdlIPC *ipc, char *cmd);
 int nukedir(char *dirname);
-int num_parms(char *source);
 void strproc(char *string);
 void back(int spaces);
 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
index 9896697a6d1647bf192addc5d3cbb6c4b169b120..b414b47315af0d21e67df9361cb1c29940cb156b 100644 (file)
@@ -30,6 +30,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "sysdep.h"
 #include "citadel.h"
 #include "citadel_ipc.h"
@@ -37,7 +38,6 @@
 #include "routines2.h"
 #include "routines.h"
 #include "commands.h"
-#include "tools.h"
 #include "messages.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
index 4254d72133b10a40f7391ff41c8c936b1bbf0b2d..225b23a4c7a99ec989db0adf44e1428ba4dfbe95 100644 (file)
@@ -29,8 +29,8 @@
 #include <signal.h>
 #include <errno.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
-#include "tools.h"
 #include "citadel_ipc.h"
 #include "server.h"
 #include "config.h"
index c090e3c7877aa88b91dff97c678304af54697d15..e248d50a1ecb5edd677314a24ee35d444777859e 100644 (file)
 #include <string.h>
 #include <limits.h>
 #include <ctype.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
 #include "sysdep_decls.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "config.h"
 
 #include "modules/crypto/serv_crypto.h"        /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
index f8b95019d2f96991213c0bd9ef1db8b661b0b705..7edc6ad16e78134f34e33153dcfd8197cd545a6d 100644 (file)
@@ -44,6 +44,7 @@
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
@@ -55,7 +56,6 @@
 #include "database.h"
 #include "user_ops.h"
 #include "housekeeping.h"
-#include "tools.h"
 #include "citadel_dirs.c"
 
 #include "modules_init.h"
@@ -215,6 +215,7 @@ int main(int argc, char **argv)
                "General Public License.\n");
        lprintf(CTDL_NOTICE, "\n");
        lprintf(CTDL_DEBUG, "Called as: %s\n", argv[0]);
+       lprintf(CTDL_INFO, "%s\n", libcitadel_version_string());
 
        /* Load site-specific parameters, and set the ipgm secret */
        lprintf(CTDL_INFO, "Loading citadel.config\n");
index 845a3408dff7630c54d09d290a9dd3f26193d68f..f0ad438a376009f5248b489c1c49a28966bb19d0 100644 (file)
 #include <limits.h>
 #include <pwd.h>
 #include <time.h>
-
+#include <libcitadel.h>
 #include "citadel.h"
 #include "axdefs.h"
 #include "sysdep.h"
 #include "config.h"
-#include "tools.h"
 #include "citadel_dirs.h"
 
 #define MAXSETUP 5     /* How many setup questions to ask */
index 038c6feb58c9c275bb0c6cd21535f7377f030aaa..dfb98052ccf05a4101d29f4b470f3515257f83e5 100644 (file)
@@ -67,6 +67,7 @@ char* const message =
 #include <stdio.h>
 #include <sys/types.h>
 #include <string.h>
+#include <libcitadel.h>
 #include "sysdep.h"
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -78,7 +79,6 @@ char* const message =
 #  include <time.h>
 # endif
 #endif
-#include "tools.h"
 #include "citadel_ipc.h"
 
 #ifndef HAVE_PTHREAD_H
index 8a56d85445cf7d3e517f46aae6ff3f7db6ede610..b650c7ee8c2cfcbb5bbac65b999e08dee7fbcd88 100644 (file)
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "support.h"
-#include "tools.h"
 
 /*
  * strproc()  -  make a string 'nice'
@@ -90,19 +90,6 @@ int getstring(FILE *fp, char *string)
 }
 
 
-/*
- * pattern2()  -  searches for patn within search string, returns pos 
- */ 
-int pattern2(char *search, char *patn)
-{
-       int a, len;
-       
-       len = strlen(patn);
-       for (a=0; !IsEmptyStr(&search[a]); ++a) {
-               if (!strncasecmp(&search[a],patn, len)) return(a);
-               }
-       return(-1);
-       }
 
 
 /*
index a63f8723c6884d5ace0573abb8c4ffc2bc5afdf3..0b4aa3dce20ac7ae07197e1499985898461fe51f 100644 (file)
@@ -1,6 +1,5 @@
 /* $Id$ */
 void strproc (char *string);
 int getstring (FILE *fp, char *string);
-int pattern2 (char *search, char *patn);
 void mesg_locate (char *targ, size_t n, const char *searchfor,
                  int numdirs, const char * const *dirs);
index 182c0df7d1b0795b098eb566d092025ca9d95f53..14676acfb552e038528181142399497c25121de7 100644 (file)
@@ -52,6 +52,7 @@
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
@@ -60,7 +61,6 @@
 #include "config.h"
 #include "database.h"
 #include "housekeeping.h"
-#include "tools.h"
 #include "modules/crypto/serv_crypto.h"        /* Needed for init_ssl, client_write_ssl, client_read_ssl, destruct_ssl */
 #include "ecrash.h"
 
diff --git a/citadel/tools.c b/citadel/tools.c
deleted file mode 100644 (file)
index b864642..0000000
+++ /dev/null
@@ -1,854 +0,0 @@
-/*
- * $Id$
- *
- * Utility functions that are used by both the client and server.
- *
- */
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.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 "tools.h"
-#include "citadel.h"
-#include "sysdep_decls.h"
-
-#define TRUE  1
-#define FALSE 0
-
-typedef unsigned char byte;          /* Byte type */
-static byte dtable[256] = "\0";              /* base64 decode table */
-static byte etable[256] = "\0";              /* base64 encode table */
-
-/* Month strings for date conversions */
-char *ascmonths[12] = {
-       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-char *safestrncpy(char *dest, const char *src, size_t n)
-{
-       int i = 0;
-
-       if (dest == NULL || src == NULL) {
-               fprintf(stderr, "safestrncpy: NULL argument\n");
-               abort();
-       }
-
-       do {
-               dest[i] = src[i];
-               if (dest[i] == 0) return(dest);
-               ++i;
-       } while (i<n);
-       dest[n - 1] = 0;
-       return dest;
-}
-
-
-
-#ifndef HAVE_STRNCASECMP
-int strncasecmp(char *lstr, char *rstr, int len)
-{
-       int pos = 0;
-       char lc,rc;
-       while (pos<len) {
-               lc=tolower(lstr[pos]);
-               rc=tolower(rstr[pos]);
-               if ((lc==0)&&(rc==0)) return(0);
-               if (lc<rc) return(-1);
-               if (lc>rc) return(1);
-               pos=pos+1;
-       }
-       return(0);
-}
-#endif
-
-
-
-/*
- * num_tokens()  -  discover number of parameters/tokens in a string
- */
-int num_tokens(const char *source, char tok)
-{
-       int count = 1;
-       const char *ptr = source;
-
-       if (source == NULL) {
-               return (0);
-       }
-
-       while (*ptr != '\0') {
-               if (*ptr++ == tok) {
-                       ++count;
-               }
-       }
-       
-       return (count);
-}
-
-//extern void cit_backtrace(void);
-
-
-/*
- * extract_token() - a string tokenizer
- * returns -1 if not found, or length of token.
- */
-long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
-{
-       const char *s;                  //* source * /
-       int len = 0;                    //* running total length of extracted string * /
-       int current_token = 0;          //* token currently being processed * /
-
-       s = source;
-
-       if (dest == NULL) {
-               return(-1);
-       }
-
-//     cit_backtrace();
-//     lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
-       dest[0] = 0;
-
-       if (s == NULL) {
-               return(-1);
-       }
-       
-       maxlen--;
-
-       while (*s) {
-               if (*s == separator) {
-                       ++current_token;
-               }
-               if ( (current_token == parmnum) && 
-                    (*s != separator) && 
-                    (len < maxlen) ) {
-                       dest[len] = *s;
-                       ++len;
-               }
-               else if ((current_token > parmnum) || (len >= maxlen)) {
-                       break;
-               }
-               ++s;
-       }
-
-       dest[len] = '\0';
-       if (current_token < parmnum) {
-//             lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
-               return(-1);
-       }
-//     lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
-       return(len);
-}
-//*/
-
-
-/*
- * extract_token() - a string tokenizer
- * /
-long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
-{
-       char *d;                // dest
-       const char *s;          // source
-       int count = 0;
-       int len = 0;
-
-       
-//     cit_backtrace();
-       lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
-       strcpy(dest, "");
-
-       //  Locate desired parameter 
-       s = source;
-       while (count < parmnum) {
-               //  End of string, bail!
-               if (!*s) {
-                       s = NULL;
-                       break;
-               }
-               if (*s == separator) {
-                       count++;
-               }
-               s++;
-       }
-       if (!s) {
-               lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
-               return -1;              // Parameter not found
-       }
-       
-       for (d = dest; *s && *s != separator && ++len<maxlen; s++, d++) {
-               *d = *s;
-       }
-       *d = 0;
-       lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
-       return 0;
-}
-*/
-
-
-/*
- * remove_token() - a tokenizer that kills, maims, and destroys
- */
-void remove_token(char *source, int parmnum, char separator)
-{
-       char *d, *s;            /* dest, source */
-       int count = 0;
-
-       /* Find desired parameter */
-       d = source;
-       while (count < parmnum) {
-               /* End of string, bail! */
-               if (!*d) {
-                       d = NULL;
-                       break;
-               }
-               if (*d == separator) {
-                       count++;
-               }
-               d++;
-       }
-       if (!d) return;         /* Parameter not found */
-
-       /* Find next parameter */
-       s = d;
-       while (*s && *s != separator) {
-               s++;
-       }
-
-       /* Hack and slash */
-       if (*s)
-               strcpy(d, ++s);
-       else if (d == source)
-               *d = 0;
-       else
-               *--d = 0;
-       /*
-       while (*s) {
-               *d++ = *s++;
-       }
-       *d = 0;
-       */
-}
-
-
-/*
- * extract_int()  -  extract an int parm w/o supplying a buffer
- */
-int extract_int(const char *source, int parmnum)
-{
-       char buf[32];
-       
-       extract_token(buf, source, parmnum, '|', sizeof buf);
-       return(atoi(buf));
-}
-
-/*
- * extract_long()  -  extract an long parm w/o supplying a buffer
- */
-long extract_long(const char *source, int parmnum)
-{
-       char buf[32];
-       
-       extract_token(buf, source, parmnum, '|', sizeof buf);
-       return(atol(buf));
-}
-
-
-/*
- * extract_unsigned_long() - extract an unsigned long parm
- */
-unsigned long extract_unsigned_long(const char *source, int parmnum)
-{
-       char buf[32];
-
-       extract_token(buf, source, parmnum, '|', sizeof buf);
-       return strtoul(buf, NULL, 10);
-}
-
-
-
-void CtdlInitBase64Table(void)
-{
-       int i;
-       /*      Fill dtable with character encodings.  */
-       
-       /* Encoder Table */
-       for (i = 0; i < 26; i++) {
-               etable[i] = 'A' + i;
-               etable[26 + i] = 'a' + i;
-       }
-       for (i = 0; i < 10; i++) {
-               etable[52 + i] = '0' + i;
-       }
-       etable[62] = '+';
-       etable[63] = '/';
-       
-       /* Decoder Table */
-       for (i = 0; i < 255; i++) {
-               dtable[i] = 0x80;
-       }
-       for (i = 'A'; i <= 'Z'; i++) {
-               dtable[i] = 0 + (i - 'A');
-       }
-       for (i = 'a'; i <= 'z'; i++) {
-               dtable[i] = 26 + (i - 'a');
-       }
-       for (i = '0'; i <= '9'; i++) {
-               dtable[i] = 52 + (i - '0');
-       }
-       dtable['+'] = 62;
-       dtable['/'] = 63;
-       dtable['='] = 0;
-}
-
-/*
- * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by
- * John Walker, found in full in the file "base64.c" included with this
- * distribution.  We are moving in the direction of eventually discarding
- * the separate executables, and using the ones in our code exclusively.
- */
-
-void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen)
-{
-    int i, hiteof = FALSE;
-    int spos = 0;
-    int dpos = 0;
-
-    while (!hiteof) {
-       byte igroup[3], ogroup[4];
-       int c, n;
-
-       igroup[0] = igroup[1] = igroup[2] = 0;
-       for (n = 0; n < 3; n++) {
-           if (spos >= sourcelen) {
-               hiteof = TRUE;
-               break;
-           }
-           c = source[spos++];
-           igroup[n] = (byte) c;
-       }
-       if (n > 0) {
-           ogroup[0] = etable[igroup[0] >> 2];
-           ogroup[1] = etable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
-           ogroup[2] = etable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
-           ogroup[3] = etable[igroup[2] & 0x3F];
-
-            /* Replace characters in output stream with "=" pad
-              characters if fewer than three characters were
-              read from the end of the input stream. */
-
-           if (n < 3) {
-                ogroup[3] = '=';
-               if (n < 2) {
-                    ogroup[2] = '=';
-               }
-           }
-           for (i = 0; i < 4; i++) {
-               dest[dpos++] = ogroup[i];
-               dest[dpos] = 0;
-           }
-       }
-    }
-}
-
-
-/* 
- * Convert base64-encoded to binary.  Returns the length of the decoded data.
- * It will stop after reading 'length' bytes.
- */
-int CtdlDecodeBase64(char *dest, const char *source, size_t length)
-{
-    int i, c;
-    int dpos = 0;
-    int spos = 0;
-
-
-    /*CONSTANTCONDITION*/
-    while (TRUE) {
-       byte a[4], b[4], o[3];
-
-       for (i = 0; i < 4; i++) {
-           if (spos >= length) {
-               return(dpos);
-           }
-           c = source[spos++];
-
-           if (c == 0) {
-               if (i > 0) {
-                   return(dpos);
-               }
-               return(dpos);
-           }
-           if (dtable[c] & 0x80) {
-               /* Ignoring errors: discard invalid character. */
-               i--;
-               continue;
-           }
-           a[i] = (byte) c;
-           b[i] = (byte) dtable[c];
-       }
-       o[0] = (b[0] << 2) | (b[1] >> 4);
-       o[1] = (b[1] << 4) | (b[2] >> 2);
-       o[2] = (b[2] << 6) | b[3];
-        i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3);
-       if (i>=1) dest[dpos++] = o[0];
-       if (i>=2) dest[dpos++] = o[1];
-       if (i>=3) dest[dpos++] = o[2];
-       dest[dpos] = 0;
-       if (i < 3) {
-           return(dpos);
-       }
-    }
-}
-
-/*
- * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
- * according to RFC2045 section 6.7
- */
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
-       unsigned int ch;
-       int decoded_length = 0;
-       int pos = 0;
-
-       while (pos < sourcelen)
-       {
-               if (!strncmp(&encoded[pos], "=\r\n", 3))
-               {
-                       pos += 3;
-               }
-               else if (!strncmp(&encoded[pos], "=\n", 2))
-               {
-                       pos += 2;
-               }
-               else if (encoded[pos] == '=')
-               {
-                       ch = 0;
-                       sscanf(&encoded[pos+1], "%02x", &ch);
-                       pos += 3;
-                       decoded[decoded_length++] = ch;
-               }
-               else
-               {
-                       decoded[decoded_length++] = encoded[pos];
-                       pos += 1;
-               }
-       }
-       decoded[decoded_length] = 0;
-       return(decoded_length);
-}
-
-
-/*
- * if we send out non ascii subjects, we encode it this way.
- */
-char *rfc2047encode(char *line, long length)
-{
-       char *AlreadyEncoded;
-       char *result;
-       long end;
-#define UTF8_HEADER "=?UTF-8?B?"
-
-       /* check if we're already done */
-       AlreadyEncoded = strstr(line, "=?");
-       if ((AlreadyEncoded != NULL) &&
-           ((strstr(AlreadyEncoded, "?B?") != NULL)||
-            (strstr(AlreadyEncoded, "?Q?") != NULL)))
-       {
-               return strdup(line);
-       }
-
-       result = (char*) malloc(strlen(UTF8_HEADER) + 4 + length * 2);
-       strncpy (result, UTF8_HEADER, strlen (UTF8_HEADER));
-       CtdlEncodeBase64(result + strlen(UTF8_HEADER), line, length);
-       end = strlen (result);
-        result[end]='?';
-       result[end+1]='=';
-       result[end+2]='\0';
-       return result;
-}
-
-
-/*
- * Strip leading and trailing spaces from a string
- */
-void striplt(char *buf)
-{
-       size_t len;
-       int a;
-
-       if (buf==NULL) return;
-       if (IsEmptyStr(buf)) return;
-       len = strlen(buf);
-        while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
-                buf[--len] = 0;
-       if (IsEmptyStr(buf)) return;
-       a = 0;
-        while ((!IsEmptyStr(buf)) && (isspace(buf[a])))
-               a++;
-       if (a > 0)
-                memmove(buf, &buf[a], len - a + 1);
-}
-
-
-
-
-
-/**
- * \brief check for the presence of a character within a string (returns count)
- * \param st the string to examine
- * \param ch the char to search
- * \return the position inside of st
- */
-int haschar(const char *st,int ch)
-{
-       const char *ptr;
-       int b;
-       b = 0;
-       ptr = st;
-       while (!IsEmptyStr(ptr))
-       {
-               if (*ptr == ch)
-                       ++b;
-               ptr ++;
-       }
-       return (b);
-}
-
-
-
-
-
-/*
- * Format a date/time stamp for output 
- * seconds is whether to print the seconds
- */
-void fmt_date(char *buf, size_t n, time_t thetime, int seconds) {
-       struct tm tm;
-       int hour;
-
-       strcpy(buf, "");
-       localtime_r(&thetime, &tm);
-
-       hour = tm.tm_hour;
-       if (hour == 0)  hour = 12;
-       else if (hour > 12) hour = hour - 12;
-
-       if (seconds) {
-               snprintf(buf, n, "%s %d %4d %d:%02d:%02d%s",
-                       ascmonths[tm.tm_mon],
-                       tm.tm_mday,
-                       tm.tm_year + 1900,
-                       hour,
-                       tm.tm_min,
-                       tm.tm_sec,
-                       ( (tm.tm_hour >= 12) ? "pm" : "am" )
-               );
-       } else {
-               snprintf(buf, n, "%s %d %4d %d:%02d%s",
-                       ascmonths[tm.tm_mon],
-                       tm.tm_mday,
-                       tm.tm_year + 1900,
-                       hour,
-                       tm.tm_min,
-                       ( (tm.tm_hour >= 12) ? "pm" : "am" )
-               );
-       }
-}
-
-
-
-/*
- * Determine whether the specified message number is contained within the
- * specified sequence set.
- */
-int is_msg_in_sequence_set(char *mset, long msgnum) {
-       int num_sets;
-       int s;
-       char setstr[128], lostr[128], histr[128];
-       long lo, hi;
-
-       num_sets = num_tokens(mset, ',');
-       for (s=0; s<num_sets; ++s) {
-               extract_token(setstr, mset, s, ',', sizeof setstr);
-
-               extract_token(lostr, setstr, 0, ':', sizeof lostr);
-               if (num_tokens(setstr, ':') >= 2) {
-                       extract_token(histr, setstr, 1, ':', sizeof histr);
-                       if (!strcmp(histr, "*")) {
-                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
-                       }
-               } 
-               else {
-                       strcpy(histr, lostr);
-               }
-               lo = atol(lostr);
-               hi = atol(histr);
-
-               if ((msgnum >= lo) && (msgnum <= hi)) return(1);
-       }
-
-       return(0);
-}
-
-/** 
- * \brief Utility function to "readline" from memory
- * \param start Location in memory from which we are reading.
- * \param buf the buffer to place the string in.
- * \param maxlen Size of string buffer
- * \return Pointer to the source memory right after we stopped reading.
- */
-char *memreadline(char *start, char *buf, int maxlen)
-{
-       char ch;
-       char *ptr;
-       int len = 0;            /**< tally our own length to avoid strlen() delays */
-
-       ptr = start;
-
-       while (1) {
-               ch = *ptr++;
-               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
-                       buf[len++] = ch;
-               }
-               if ((ch == 10) || (ch == 0)) {
-                       buf[len] = 0;
-                       return ptr;
-               }
-       }
-}
-
-
-/** 
- * \brief Utility function to "readline" from memory
- * \param start Location in memory from which we are reading.
- * \param buf the buffer to place the string in.
- * \param maxlen Size of string buffer
- * \param retlen the length of the returned string
- * \return Pointer to the source memory right after we stopped reading.
- */
-char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen)
-{
-       char ch;
-       char *ptr;
-       int len = 0;            /**< tally our own length to avoid strlen() delays */
-
-       ptr = start;
-
-       while (1) {
-               ch = *ptr++;
-               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
-                       buf[len++] = ch;
-               }
-               if ((ch == 10) || (ch == 0)) {
-                       buf[len] = 0;
-                       *retlen = len;
-                       return ptr;
-               }
-       }
-}
-
-
-
-
-/*
- * Strip a boundarized substring out of a string (for example, remove
- * parentheses and anything inside them).
- */
-void stripout(char *str, char leftboundary, char rightboundary) {
-       int a;
-        int lb = (-1);
-        int rb = (-1);
-
-        for (a = 0; a < strlen(str); ++a) {
-                if (str[a] == leftboundary) lb = a;
-                if (str[a] == rightboundary) rb = a;
-        }
-
-        if ( (lb > 0) && (rb > lb) ) {
-                strcpy(&str[lb - 1], &str[rb + 1]);
-        }
-
-        else if ( (lb == 0) && (rb > lb) ) {
-                strcpy(str, &str[rb + 1]);
-        }
-
-}
-
-
-/*
- * Reduce a string down to a boundarized substring (for example, remove
- * parentheses and anything outside them).
- */
-void stripallbut(char *str, char leftboundary, char rightboundary) {
-       int a;
-
-       for (a = 0; a < strlen(str); ++ a) {
-               if (str[a] == leftboundary) strcpy(str, &str[a+1]);
-       }
-
-       for (a = 0; a < strlen(str); ++ a) {
-               if (str[a] == rightboundary) str[a] = 0;
-       }
-
-}
-
-char *myfgets(char *s, int size, FILE *stream) {
-       char *ret = fgets(s, size, stream);
-       char *nl;
-
-       if (ret != NULL) {
-               nl = strchr(s, '\n');
-
-               if (nl != NULL)
-                       *nl = 0;
-       }
-
-       return ret;
-}
-
-/*
- * Escape a string for feeding out as a URL.
- * Output buffer must be big enough to handle escape expansion!
- */
-void urlesc(char *outbuf, char *strbuf)
-{
-       int a, b, c;
-       char *ec = " #&;`'|*?-~<>^()[]{}$\\";
-
-       strcpy(outbuf, "");
-
-       for (a = 0; a < (int)strlen(strbuf); ++a) {
-               c = 0;
-               for (b = 0; b < strlen(ec); ++b) {
-                       if (strbuf[a] == ec[b])
-                               c = 1;
-               }
-               b = strlen(outbuf);
-               if (c == 1)
-                       sprintf(&outbuf[b], "%%%02x", strbuf[a]);
-               else
-                       sprintf(&outbuf[b], "%c", strbuf[a]);
-       }
-}
-
-
-
-/*
- * In our world, we want strcpy() to be able to work with overlapping strings.
- */
-#ifdef strcpy
-#undef strcpy
-#endif
-char *strcpy(char *dest, const char *src) {
-       memmove(dest, src, (strlen(src) + 1) );
-       return(dest);
-}
-
-
-/*
- * Generate a new, globally unique UID parameter for a calendar etc. object
- */
-void generate_uuid(char *buf) {
-       static int seq = 0;
-
-       sprintf(buf, "%lx-"F_XPID_T"-%x",
-               time(NULL),
-               getpid(),
-               (seq++)
-       );
-}
-
-/*
- * bmstrcasestr() -- case-insensitive substring search
- *
- * This uses the Boyer-Moore search algorithm and is therefore quite fast.
- * The code is roughly based on the strstr() replacement from 'tin' written
- * by Urs Jannsen.
- */
-char *bmstrcasestr(char *text, char *pattern) {
-
-       register unsigned char *p, *t;
-       register int i, j, *delta;
-       register size_t p1;
-       int deltaspace[256];
-       size_t textlen;
-       size_t patlen;
-
-       textlen = strlen (text);
-       patlen = strlen (pattern);
-
-       /* algorithm fails if pattern is empty */
-       if ((p1 = patlen) == 0)
-               return (text);
-
-       /* code below fails (whenever i is unsigned) if pattern too long */
-       if (p1 > textlen)
-               return (NULL);
-
-       /* set up deltas */
-       delta = deltaspace;
-       for (i = 0; i <= 255; i++)
-               delta[i] = p1;
-       for (p = (unsigned char *) pattern, i = p1; --i > 0;)
-               delta[tolower(*p++)] = i;
-
-       /*
-        * From now on, we want patlen - 1.
-        * In the loop below, p points to the end of the pattern,
-        * t points to the end of the text to be tested against the
-        * pattern, and i counts the amount of text remaining, not
-        * including the part to be tested.
-        */
-       p1--;
-       p = (unsigned char *) pattern + p1;
-       t = (unsigned char *) text + p1;
-       i = textlen - patlen;
-       while(1) {
-               if (tolower(p[0]) == tolower(t[0])) {
-                       if (strncasecmp ((const char *)(p - p1), (const char *)(t - p1), p1) == 0) {
-                               return ((char *)t - p1);
-                       }
-               }
-               j = delta[tolower(t[0])];
-               if (i < j)
-                       break;
-               i -= j;
-               t += j;
-       }
-       return (NULL);
-}
-
-
-
-/*
- * Local replacement for controversial C library function that generates
- * names for temporary files.  Included to shut up compiler warnings.
- */
-void CtdlMakeTempFileName(char *name, int len) {
-       int i = 0;
-
-       while (i++, i < 100) {
-               snprintf(name, len, "/tmp/ctdl."F_XPID_T".%04x",
-                       getpid(),
-                       rand()
-               );
-               if (!access(name, F_OK)) {
-                       return;
-               }
-       }
-}
diff --git a/citadel/tools.h b/citadel/tools.h
deleted file mode 100644 (file)
index 7c9f5c0..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* $Id$ */
-char *safestrncpy(char *dest, const char *src, size_t n);
-int num_tokens (const char *source, char tok);
-long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
-long grab_token(char **dest, const char *source, int parmnum, char separator);
-int extract_int (const char *source, int parmnum);
-long extract_long (const char *source, int parmnum);
-unsigned long extract_unsigned_long(const char *source, int parmnum);
-void CtdlInitBase64Table(void);
-void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
-int CtdlDecodeBase64(char *dest, const char *source, size_t length);
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
-void striplt(char *);
-int haschar(const char *st, int ch);
-void remove_token(char *source, int parmnum, char separator);
-void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
-int is_msg_in_sequence_set(char *mset, long msgnum);
-char *memreadline(char *start, char *buf, int maxlen);
-char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
-
-#ifndef HAVE_STRNCASECMP
-int strncasecmp(char *, char *, int);
-#endif
-#ifndef HAVE_STRCASECMP
-#define strcasecmp(x,y) strncasecmp(x,y,INT_MAX);
-#endif
-
-#define IsEmptyStr(a) ((a)[0] == '\0')
-
-#define num_parms(source)              num_tokens(source,(char)'|')
-void stripout(char *str, char leftboundary, char rightboundary);
-void stripallbut(char *str, char leftboundary, char rightboundary);
-
-char *myfgets(char *s, int size, FILE *stream);
-void urlesc(char *outbuf, char *strbuf);
-char *CtdlTempFileName(char *prefix1, int prefix2);
-FILE *CtdlTempFile(void);
-char *ascmonths[12];
-void generate_uuid(char *buf);
-char *bmstrcasestr(char *text, char *pattern);
-void CtdlMakeTempFileName(char *name, int len);
-char *rfc2047encode(char *line, long length);
index ed1fdfb202c7004cff6b5d5681ebbba621a77f31..9cacb68b05e8567703003f361e38d1a019d9d76a 100644 (file)
@@ -29,6 +29,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libcitadel.h>
 #include "sysdep.h"
 #include "citadel.h"
 #include "citadel_ipc.h"
@@ -37,7 +38,6 @@
 #include "messages.h"
 #include "routines.h"
 #include "commands.h"
-#include "tools.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
index f457c60894f7795e1a40fef116a81ce957dd5e98..f9ac7c843c8333a90b612ca52ef5c7767ffcd7dc 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "auth.h"
 #include "citadel.h"
 #include "server.h"
@@ -45,7 +46,6 @@
 #include "control.h"
 #include "msgbase.h"
 #include "config.h"
-#include "tools.h"
 #include "citserver.h"
 #include "citadel_dirs.h"
 #include "genstamp.h"
index c8b070318d3e129aad7f7ccaa216600af79b1acf..0e7e3fbfd92cf651eaf78f4d12302d25bee5b43d 100644 (file)
 # endif
 #endif
 
+#include <libcitadel.h>
 #include "citadel.h"
 #include <unistd.h>
 #include "citadel_ipc.h"
-#include "tools.h"
 #include "citadel_dirs.h"
 
 void logoff(int code)
index a44117747a3b73da5bb637a5fbfa6592f5e9698e..75a2c9f7c6c975f98f8c74fd0d920febdbec0675 100644 (file)
 #include <errno.h>
 #include <limits.h>
 #include <string.h>
-
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "support.h"
 #include "vcard.h"
-#include "tools.h"
 
 
 
index be5dbe05eaca1714563a87f17b8f47bf5ef65afb..9c0db8216e9383b22c8594b500fd23d46c297284 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_dirs.h"
-#include "tools.h"
 
 void logoff(int code)
 {
index 3c6d57b4afe8d27cefeb212324e97b11ff41226c..a95cf2128104f842b3944f97bc3408ace6fbbb0d 100755 (executable)
@@ -83,11 +83,13 @@ LINK_LIB = $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) -no-undefined $(VSNFLAG)
 LINK_EXE = $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) $(LDFLAGS) -o $@
 LINK_CXX_EXE = $(LIBTOOL) $(LTFLAGS) --mode=link $(CXXCOMPILE) $(LDFLAGS) -o $@
 
-LIB_OBJS = lib/libcitadel.lo
+LIB_OBJS = lib/libcitadel.lo lib/mime_parser.lo lib/tools.lo
 $(LIBRARY): $(LIB_OBJS)
        $(LINK_LIB) $(LIB_OBJS)
 
 lib/libcitadel.lo: lib/libcitadel.c lib/libcitadel.h
+lib/mime_parser.lo: lib/mime_parser.c lib/libcitadel.h
+lib/tools.lo: lib/tools.c lib/libcitadel.h
 
 .SUFFIXES: .c .cpp .lo .o
 
index 6eb9a89498b02e9ff80fcbad75ad294676b77af9..99a3a27fb39f6adf3234a02fa88a2d04a62193ec 100644 (file)
 #define SIZ    4096
 #endif
 
+#ifndef IsEmptyStr
+#define IsEmptyStr(a) ((a)[0] == '\0')
+#endif
+
 /*
  * Misc declarations
  */
@@ -60,3 +64,128 @@ void mime_parser(char *content_start, char *content_end,
                void *userdata,
                int dont_decode
                );
+
+
+
+char *fixed_partnum(char *);
+void mime_decode(char *partnum,
+                char *part_start, size_t length,
+                char *content_type, char *charset, char *encoding,
+                char *disposition,
+                char *name, char *filename,
+                void (*CallBack)
+                 (char *cbname,
+                  char *cbfilename,
+                  char *cbpartnum,
+                  char *cbdisp,
+                  void *cbcontent,
+                  char *cbtype,
+                  char *cbcharset,
+                  size_t cblength,
+                  char *cbencoding,
+                  void *cbuserdata),
+                void (*PreMultiPartCallBack)
+                 (char *cbname,
+                  char *cbfilename,
+                  char *cbpartnum,
+                  char *cbdisp,
+                  void *cbcontent,
+                  char *cbtype,
+                  char *cbcharset,
+                  size_t cblength,
+                  char *cbencoding,
+                  void *cbuserdata),
+                void (*PostMultiPartCallBack)
+                 (char *cbname,
+                  char *cbfilename,
+                  char *cbpartnum,
+                  char *cbdisp,
+                  void *cbcontent,
+                  char *cbtype,
+                  char *cbcharset,
+                  size_t cblength,
+                  char *cbencoding,
+                  void *cbuserdata),
+                 void *userdata,
+                 int dont_decode
+);
+void the_mime_parser(char *partnum,
+                    char *content_start, char *content_end,
+                    void (*CallBack)
+                     (char *cbname,
+                      char *cbfilename,
+                      char *cbpartnum,
+                      char *cbdisp,
+                      void *cbcontent,
+                      char *cbtype,
+                      char *cbcharset,
+                      size_t cblength,
+                      char *cbencoding,
+                      void *cbuserdata),
+                    void (*PreMultiPartCallBack)
+                     (char *cbname,
+                      char *cbfilename,
+                      char *cbpartnum,
+                      char *cbdisp,
+                      void *cbcontent,
+                      char *cbtype,
+                      char *cbcharset,
+                      size_t cblength,
+                      char *cbencoding,
+                      void *cbuserdata),
+                    void (*PostMultiPartCallBack)
+                     (char *cbname,
+                      char *cbfilename,
+                      char *cbpartnum,
+                      char *cbdisp,
+                      void *cbcontent,
+                      char *cbtype,
+                      char *cbcharset,
+                      size_t cblength,
+                      char *cbencoding,
+                      void *cbuserdata),
+                     void *userdata,
+                     int dont_decode
+);
+
+
+
+/* tools */
+
+
+
+char *safestrncpy(char *dest, const char *src, size_t n);
+int num_tokens (const char *source, char tok);
+long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
+long grab_token(char **dest, const char *source, int parmnum, char separator);
+int extract_int (const char *source, int parmnum);
+long extract_long (const char *source, int parmnum);
+unsigned long extract_unsigned_long(const char *source, int parmnum);
+void CtdlInitBase64Table(void);
+size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
+int CtdlDecodeBase64(char *dest, const char *source, size_t length);
+int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
+void striplt(char *);
+int haschar(const char *st, int ch);
+void remove_token(char *source, int parmnum, char separator);
+void fmt_date(char *buf, size_t n, time_t thetime, int seconds);
+int is_msg_in_sequence_set(char *mset, long msgnum);
+char *memreadline(char *start, char *buf, int maxlen);
+char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
+#define IsEmptyStr(a) ((a)[0] == '\0')
+#define num_parms(source)              num_tokens(source,(char)'|')
+void stripout(char *str, char leftboundary, char rightboundary);
+void stripallbut(char *str, char leftboundary, char rightboundary);
+char *myfgets(char *s, int size, FILE *stream);
+void urlesc(char *outbuf, char *strbuf);
+char *CtdlTempFileName(char *prefix1, int prefix2);
+FILE *CtdlTempFile(void);
+char *ascmonths[12];
+void generate_uuid(char *buf);
+char *bmstrcasestr(char *text, char *pattern);
+void CtdlMakeTempFileName(char *name, int len);
+char *rfc2047encode(char *line, long length);
+int is_msg_in_mset(char *mset, long msgnum);
+int pattern2(char *search, char *patn);
+void stripltlen(char *, int *);
+
diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c
new file mode 100644 (file)
index 0000000..e3882c7
--- /dev/null
@@ -0,0 +1,912 @@
+/*
+ *
+ */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <limits.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 "libcitadel.h"
+
+
+#define TRUE  1
+#define FALSE 0
+
+typedef unsigned char byte;          /* Byte type */
+static byte dtable[256] = "\0";              /* base64 decode table */
+static byte etable[256] = "\0";              /* base64 encode table */
+
+/* Month strings for date conversions */
+char *ascmonths[12] = {
+       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+char *safestrncpy(char *dest, const char *src, size_t n)
+{
+       int i = 0;
+
+       if (dest == NULL || src == NULL) {
+               fprintf(stderr, "safestrncpy: NULL argument\n");
+               abort();
+       }
+
+       do {
+               dest[i] = src[i];
+               if (dest[i] == 0) return(dest);
+               ++i;
+       } while (i<n);
+       dest[n - 1] = 0;
+       return dest;
+}
+
+
+
+/*
+ * num_tokens()  -  discover number of parameters/tokens in a string
+ */
+int num_tokens(const char *source, char tok)
+{
+       int count = 1;
+       const char *ptr = source;
+
+       if (source == NULL) {
+               return (0);
+       }
+
+       while (*ptr != '\0') {
+               if (*ptr++ == tok) {
+                       ++count;
+               }
+       }
+       
+       return (count);
+}
+
+//extern void cit_backtrace(void);
+
+
+/*
+ * extract_token() - a string tokenizer
+ * returns -1 if not found, or length of token.
+ */
+long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
+{
+       const char *s;                  //* source * /
+       int len = 0;                    //* running total length of extracted string * /
+       int current_token = 0;          //* token currently being processed * /
+
+       s = source;
+
+       if (dest == NULL) {
+               return(-1);
+       }
+
+//     cit_backtrace();
+//     lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
+       dest[0] = 0;
+
+       if (s == NULL) {
+               return(-1);
+       }
+       
+       maxlen--;
+
+       while (*s) {
+               if (*s == separator) {
+                       ++current_token;
+               }
+               if ( (current_token == parmnum) && 
+                    (*s != separator) && 
+                    (len < maxlen) ) {
+                       dest[len] = *s;
+                       ++len;
+               }
+               else if ((current_token > parmnum) || (len >= maxlen)) {
+                       break;
+               }
+               ++s;
+       }
+
+       dest[len] = '\0';
+       if (current_token < parmnum) {
+//             lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
+               return(-1);
+       }
+//     lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
+       return(len);
+}
+//*/
+
+
+/*
+ * extract_token() - a string tokenizer
+ * /
+long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
+{
+       char *d;                // dest
+       const char *s;          // source
+       int count = 0;
+       int len = 0;
+
+       
+//     cit_backtrace();
+       lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
+       strcpy(dest, "");
+
+       //  Locate desired parameter 
+       s = source;
+       while (count < parmnum) {
+               //  End of string, bail!
+               if (!*s) {
+                       s = NULL;
+                       break;
+               }
+               if (*s == separator) {
+                       count++;
+               }
+               s++;
+       }
+       if (!s) {
+               lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
+               return -1;              // Parameter not found
+       }
+       
+       for (d = dest; *s && *s != separator && ++len<maxlen; s++, d++) {
+               *d = *s;
+       }
+       *d = 0;
+       lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
+       return 0;
+}
+*/
+
+
+/*
+ * remove_token() - a tokenizer that kills, maims, and destroys
+ */
+void remove_token(char *source, int parmnum, char separator)
+{
+       char *d, *s;            /* dest, source */
+       int count = 0;
+
+       /* Find desired parameter */
+       d = source;
+       while (count < parmnum) {
+               /* End of string, bail! */
+               if (!*d) {
+                       d = NULL;
+                       break;
+               }
+               if (*d == separator) {
+                       count++;
+               }
+               d++;
+       }
+       if (!d) return;         /* Parameter not found */
+
+       /* Find next parameter */
+       s = d;
+       while (*s && *s != separator) {
+               s++;
+       }
+
+       /* Hack and slash */
+       if (*s)
+               strcpy(d, ++s);
+       else if (d == source)
+               *d = 0;
+       else
+               *--d = 0;
+       /*
+       while (*s) {
+               *d++ = *s++;
+       }
+       *d = 0;
+       */
+}
+
+
+/*
+ * extract_int()  -  extract an int parm w/o supplying a buffer
+ */
+int extract_int(const char *source, int parmnum)
+{
+       char buf[32];
+       
+       extract_token(buf, source, parmnum, '|', sizeof buf);
+       return(atoi(buf));
+}
+
+/*
+ * extract_long()  -  extract an long parm w/o supplying a buffer
+ */
+long extract_long(const char *source, int parmnum)
+{
+       char buf[32];
+       
+       extract_token(buf, source, parmnum, '|', sizeof buf);
+       return(atol(buf));
+}
+
+
+/*
+ * extract_unsigned_long() - extract an unsigned long parm
+ */
+unsigned long extract_unsigned_long(const char *source, int parmnum)
+{
+       char buf[32];
+
+       extract_token(buf, source, parmnum, '|', sizeof buf);
+       return strtoul(buf, NULL, 10);
+}
+
+
+
+void CtdlInitBase64Table(void)
+{
+       int i;
+       /*      Fill dtable with character encodings.  */
+       
+       /* Encoder Table */
+       for (i = 0; i < 26; i++) {
+               etable[i] = 'A' + i;
+               etable[26 + i] = 'a' + i;
+       }
+       for (i = 0; i < 10; i++) {
+               etable[52 + i] = '0' + i;
+       }
+       etable[62] = '+';
+       etable[63] = '/';
+       
+       /* Decoder Table */
+       for (i = 0; i < 255; i++) {
+               dtable[i] = 0x80;
+       }
+       for (i = 'A'; i <= 'Z'; i++) {
+               dtable[i] = 0 + (i - 'A');
+       }
+       for (i = 'a'; i <= 'z'; i++) {
+               dtable[i] = 26 + (i - 'a');
+       }
+       for (i = '0'; i <= '9'; i++) {
+               dtable[i] = 52 + (i - '0');
+       }
+       dtable['+'] = 62;
+       dtable['/'] = 63;
+       dtable['='] = 0;
+}
+
+
+/*
+ * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by John Walker.
+ */
+
+size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks)
+{
+       int i, hiteof = FALSE;
+       int spos = 0;
+       int dpos = 0;
+       int thisline = 0;
+
+       /**  Fill dtable with character encodings.  */
+
+       for (i = 0; i < 26; i++) {
+               dtable[i] = 'A' + i;
+               dtable[26 + i] = 'a' + i;
+       }
+       for (i = 0; i < 10; i++) {
+               dtable[52 + i] = '0' + i;
+       }
+       dtable[62] = '+';
+       dtable[63] = '/';
+
+       while (!hiteof) {
+               byte igroup[3], ogroup[4];
+               int c, n;
+
+               igroup[0] = igroup[1] = igroup[2] = 0;
+               for (n = 0; n < 3; n++) {
+                       if (spos >= sourcelen) {
+                               hiteof = TRUE;
+                               break;
+                       }
+                       c = source[spos++];
+                       igroup[n] = (byte) c;
+               }
+               if (n > 0) {
+                       ogroup[0] = dtable[igroup[0] >> 2];
+                       ogroup[1] =
+                           dtable[((igroup[0] & 3) << 4) |
+                                  (igroup[1] >> 4)];
+                       ogroup[2] =
+                           dtable[((igroup[1] & 0xF) << 2) |
+                                  (igroup[2] >> 6)];
+                       ogroup[3] = dtable[igroup[2] & 0x3F];
+
+                       /**
+                        * Replace characters in output stream with "=" pad
+                        * characters if fewer than three characters were
+                        * read from the end of the input stream. 
+                        */
+
+                       if (n < 3) {
+                               ogroup[3] = '=';
+                               if (n < 2) {
+                                       ogroup[2] = '=';
+                               }
+                       }
+                       for (i = 0; i < 4; i++) {
+                               dest[dpos++] = ogroup[i];
+                               dest[dpos] = 0;
+                       }
+                       thisline += 4;
+                       if ( (linebreaks) && (thisline > 70) ) {
+                               dest[dpos++] = '\r';
+                               dest[dpos++] = '\n';
+                               dest[dpos] = 0;
+                               thisline = 0;
+                       }
+               }
+       }
+       if ( (linebreaks) && (thisline > 70) ) {
+               dest[dpos++] = '\r';
+               dest[dpos++] = '\n';
+               dest[dpos] = 0;
+               thisline = 0;
+       }
+
+       return(dpos);
+}
+
+
+
+/* 
+ * Convert base64-encoded to binary.  Returns the length of the decoded data.
+ * It will stop after reading 'length' bytes.
+ */
+int CtdlDecodeBase64(char *dest, const char *source, size_t length)
+{
+    int i, c;
+    int dpos = 0;
+    int spos = 0;
+
+
+    /*CONSTANTCONDITION*/
+    while (TRUE) {
+       byte a[4], b[4], o[3];
+
+       for (i = 0; i < 4; i++) {
+           if (spos >= length) {
+               return(dpos);
+           }
+           c = source[spos++];
+
+           if (c == 0) {
+               if (i > 0) {
+                   return(dpos);
+               }
+               return(dpos);
+           }
+           if (dtable[c] & 0x80) {
+               /* Ignoring errors: discard invalid character. */
+               i--;
+               continue;
+           }
+           a[i] = (byte) c;
+           b[i] = (byte) dtable[c];
+       }
+       o[0] = (b[0] << 2) | (b[1] >> 4);
+       o[1] = (b[1] << 4) | (b[2] >> 2);
+       o[2] = (b[2] << 6) | b[3];
+        i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3);
+       if (i>=1) dest[dpos++] = o[0];
+       if (i>=2) dest[dpos++] = o[1];
+       if (i>=3) dest[dpos++] = o[2];
+       dest[dpos] = 0;
+       if (i < 3) {
+           return(dpos);
+       }
+    }
+}
+
+
+/*
+ * if we send out non ascii subjects, we encode it this way.
+ */
+char *rfc2047encode(char *line, long length)
+{
+       char *AlreadyEncoded;
+       char *result;
+       long end;
+#define UTF8_HEADER "=?UTF-8?B?"
+
+       /* check if we're already done */
+       AlreadyEncoded = strstr(line, "=?");
+       if ((AlreadyEncoded != NULL) &&
+           ((strstr(AlreadyEncoded, "?B?") != NULL)||
+            (strstr(AlreadyEncoded, "?Q?") != NULL)))
+       {
+               return strdup(line);
+       }
+
+       result = (char*) malloc(strlen(UTF8_HEADER) + 4 + length * 2);
+       strncpy (result, UTF8_HEADER, strlen (UTF8_HEADER));
+       CtdlEncodeBase64(result + strlen(UTF8_HEADER), line, length, 0);
+       end = strlen (result);
+        result[end]='?';
+       result[end+1]='=';
+       result[end+2]='\0';
+       return result;
+}
+
+
+/*
+ * Strip leading and trailing spaces from a string
+ */
+void striplt(char *buf)
+{
+       size_t len;
+       int a;
+
+       if (buf==NULL) return;
+       if (IsEmptyStr(buf)) return;
+       len = strlen(buf);
+        while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
+                buf[--len] = 0;
+       if (IsEmptyStr(buf)) return;
+       a = 0;
+        while ((!IsEmptyStr(buf)) && (isspace(buf[a])))
+               a++;
+       if (a > 0)
+                memmove(buf, &buf[a], len - a + 1);
+}
+
+
+
+
+
+/**
+ * \brief check for the presence of a character within a string (returns count)
+ * \param st the string to examine
+ * \param ch the char to search
+ * \return the position inside of st
+ */
+int haschar(const char *st,int ch)
+{
+       const char *ptr;
+       int b;
+       b = 0;
+       ptr = st;
+       while (!IsEmptyStr(ptr))
+       {
+               if (*ptr == ch)
+                       ++b;
+               ptr ++;
+       }
+       return (b);
+}
+
+
+
+
+
+/*
+ * Format a date/time stamp for output 
+ * seconds is whether to print the seconds
+ */
+void fmt_date(char *buf, size_t n, time_t thetime, int seconds) {
+       struct tm tm;
+       int hour;
+
+       strcpy(buf, "");
+       localtime_r(&thetime, &tm);
+
+       hour = tm.tm_hour;
+       if (hour == 0)  hour = 12;
+       else if (hour > 12) hour = hour - 12;
+
+       if (seconds) {
+               snprintf(buf, n, "%s %d %4d %d:%02d:%02d%s",
+                       ascmonths[tm.tm_mon],
+                       tm.tm_mday,
+                       tm.tm_year + 1900,
+                       hour,
+                       tm.tm_min,
+                       tm.tm_sec,
+                       ( (tm.tm_hour >= 12) ? "pm" : "am" )
+               );
+       } else {
+               snprintf(buf, n, "%s %d %4d %d:%02d%s",
+                       ascmonths[tm.tm_mon],
+                       tm.tm_mday,
+                       tm.tm_year + 1900,
+                       hour,
+                       tm.tm_min,
+                       ( (tm.tm_hour >= 12) ? "pm" : "am" )
+               );
+       }
+}
+
+
+
+/*
+ * Determine whether the specified message number is contained within the
+ * specified sequence set.
+ */
+int is_msg_in_sequence_set(char *mset, long msgnum) {
+       int num_sets;
+       int s;
+       char setstr[128], lostr[128], histr[128];
+       long lo, hi;
+
+       num_sets = num_tokens(mset, ',');
+       for (s=0; s<num_sets; ++s) {
+               extract_token(setstr, mset, s, ',', sizeof setstr);
+
+               extract_token(lostr, setstr, 0, ':', sizeof lostr);
+               if (num_tokens(setstr, ':') >= 2) {
+                       extract_token(histr, setstr, 1, ':', sizeof histr);
+                       if (!strcmp(histr, "*")) {
+                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
+                       }
+               } 
+               else {
+                       strcpy(histr, lostr);
+               }
+               lo = atol(lostr);
+               hi = atol(histr);
+
+               if ((msgnum >= lo) && (msgnum <= hi)) return(1);
+       }
+
+       return(0);
+}
+
+/** 
+ * \brief Utility function to "readline" from memory
+ * \param start Location in memory from which we are reading.
+ * \param buf the buffer to place the string in.
+ * \param maxlen Size of string buffer
+ * \return Pointer to the source memory right after we stopped reading.
+ */
+char *memreadline(char *start, char *buf, int maxlen)
+{
+       char ch;
+       char *ptr;
+       int len = 0;            /**< tally our own length to avoid strlen() delays */
+
+       ptr = start;
+
+       while (1) {
+               ch = *ptr++;
+               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
+                       buf[len++] = ch;
+               }
+               if ((ch == 10) || (ch == 0)) {
+                       buf[len] = 0;
+                       return ptr;
+               }
+       }
+}
+
+
+/** 
+ * \brief Utility function to "readline" from memory
+ * \param start Location in memory from which we are reading.
+ * \param buf the buffer to place the string in.
+ * \param maxlen Size of string buffer
+ * \param retlen the length of the returned string
+ * \return Pointer to the source memory right after we stopped reading.
+ */
+char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen)
+{
+       char ch;
+       char *ptr;
+       int len = 0;            /**< tally our own length to avoid strlen() delays */
+
+       ptr = start;
+
+       while (1) {
+               ch = *ptr++;
+               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
+                       buf[len++] = ch;
+               }
+               if ((ch == 10) || (ch == 0)) {
+                       buf[len] = 0;
+                       *retlen = len;
+                       return ptr;
+               }
+       }
+}
+
+
+
+
+/*
+ * Strip a boundarized substring out of a string (for example, remove
+ * parentheses and anything inside them).
+ */
+void stripout(char *str, char leftboundary, char rightboundary) {
+       int a;
+        int lb = (-1);
+        int rb = (-1);
+
+        for (a = 0; a < strlen(str); ++a) {
+                if (str[a] == leftboundary) lb = a;
+                if (str[a] == rightboundary) rb = a;
+        }
+
+        if ( (lb > 0) && (rb > lb) ) {
+                strcpy(&str[lb - 1], &str[rb + 1]);
+        }
+
+        else if ( (lb == 0) && (rb > lb) ) {
+                strcpy(str, &str[rb + 1]);
+        }
+
+}
+
+
+/*
+ * Reduce a string down to a boundarized substring (for example, remove
+ * parentheses and anything outside them).
+ */
+void stripallbut(char *str, char leftboundary, char rightboundary) {
+       int a;
+
+       for (a = 0; a < strlen(str); ++ a) {
+               if (str[a] == leftboundary) strcpy(str, &str[a+1]);
+       }
+
+       for (a = 0; a < strlen(str); ++ a) {
+               if (str[a] == rightboundary) str[a] = 0;
+       }
+
+}
+
+char *myfgets(char *s, int size, FILE *stream) {
+       char *ret = fgets(s, size, stream);
+       char *nl;
+
+       if (ret != NULL) {
+               nl = strchr(s, '\n');
+
+               if (nl != NULL)
+                       *nl = 0;
+       }
+
+       return ret;
+}
+
+/*
+ * Escape a string for feeding out as a URL.
+ * Output buffer must be big enough to handle escape expansion!
+ */
+void urlesc(char *outbuf, char *strbuf)
+{
+       int a, b, c;
+       char *ec = " #&;`'|*?-~<>^()[]{}$\\";
+
+       strcpy(outbuf, "");
+
+       for (a = 0; a < (int)strlen(strbuf); ++a) {
+               c = 0;
+               for (b = 0; b < strlen(ec); ++b) {
+                       if (strbuf[a] == ec[b])
+                               c = 1;
+               }
+               b = strlen(outbuf);
+               if (c == 1)
+                       sprintf(&outbuf[b], "%%%02x", strbuf[a]);
+               else
+                       sprintf(&outbuf[b], "%c", strbuf[a]);
+       }
+}
+
+
+
+/*
+ * In our world, we want strcpy() to be able to work with overlapping strings.
+ */
+#ifdef strcpy
+#undef strcpy
+#endif
+char *strcpy(char *dest, const char *src) {
+       memmove(dest, src, (strlen(src) + 1) );
+       return(dest);
+}
+
+
+/*
+ * Generate a new, globally unique UID parameter for a calendar etc. object
+ */
+void generate_uuid(char *buf) {
+       static int seq = 0;
+
+       sprintf(buf, "%lx-%lx-%x",
+               time(NULL),
+               (long)getpid(),
+               (seq++)
+       );
+}
+
+/*
+ * bmstrcasestr() -- case-insensitive substring search
+ *
+ * This uses the Boyer-Moore search algorithm and is therefore quite fast.
+ * The code is roughly based on the strstr() replacement from 'tin' written
+ * by Urs Jannsen.
+ */
+char *bmstrcasestr(char *text, char *pattern) {
+
+       register unsigned char *p, *t;
+       register int i, j, *delta;
+       register size_t p1;
+       int deltaspace[256];
+       size_t textlen;
+       size_t patlen;
+
+       textlen = strlen (text);
+       patlen = strlen (pattern);
+
+       /* algorithm fails if pattern is empty */
+       if ((p1 = patlen) == 0)
+               return (text);
+
+       /* code below fails (whenever i is unsigned) if pattern too long */
+       if (p1 > textlen)
+               return (NULL);
+
+       /* set up deltas */
+       delta = deltaspace;
+       for (i = 0; i <= 255; i++)
+               delta[i] = p1;
+       for (p = (unsigned char *) pattern, i = p1; --i > 0;)
+               delta[tolower(*p++)] = i;
+
+       /*
+        * From now on, we want patlen - 1.
+        * In the loop below, p points to the end of the pattern,
+        * t points to the end of the text to be tested against the
+        * pattern, and i counts the amount of text remaining, not
+        * including the part to be tested.
+        */
+       p1--;
+       p = (unsigned char *) pattern + p1;
+       t = (unsigned char *) text + p1;
+       i = textlen - patlen;
+       while(1) {
+               if (tolower(p[0]) == tolower(t[0])) {
+                       if (strncasecmp ((const char *)(p - p1), (const char *)(t - p1), p1) == 0) {
+                               return ((char *)t - p1);
+                       }
+               }
+               j = delta[tolower(t[0])];
+               if (i < j)
+                       break;
+               i -= j;
+               t += j;
+       }
+       return (NULL);
+}
+
+
+
+/*
+ * Local replacement for controversial C library function that generates
+ * names for temporary files.  Included to shut up compiler warnings.
+ */
+void CtdlMakeTempFileName(char *name, int len) {
+       int i = 0;
+
+       while (i++, i < 100) {
+               snprintf(name, len, "/tmp/ctdl.%4lx.%04x",
+                       (long)getpid(),
+                       rand()
+               );
+               if (!access(name, F_OK)) {
+                       return;
+               }
+       }
+}
+
+
+
+/*
+ * Determine whether the specified message number is contained within the specified set.
+ * Returns nonzero if the specified message number is in the specified message set string.
+ */
+int is_msg_in_mset(char *mset, long msgnum) {
+       int num_sets;
+       int s;
+       char setstr[SIZ], lostr[SIZ], histr[SIZ];       /* was 1024 */
+       long lo, hi;
+
+       /*
+        * Now set it for all specified messages.
+        */
+       num_sets = num_tokens(mset, ',');
+       for (s=0; s<num_sets; ++s) {
+               extract_token(setstr, mset, s, ',', sizeof setstr);
+
+               extract_token(lostr, setstr, 0, ':', sizeof lostr);
+               if (num_tokens(setstr, ':') >= 2) {
+                       extract_token(histr, setstr, 1, ':', sizeof histr);
+                       if (!strcmp(histr, "*")) {
+                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
+                       }
+               }
+               else {
+                       strcpy(histr, lostr);
+               }
+               lo = atol(lostr);
+               hi = atol(histr);
+
+               if ((msgnum >= lo) && (msgnum <= hi)) return(1);
+       }
+
+       return(0);
+}
+
+
+/**
+ * \brief searches for a  paternn within asearch string
+ * \param search the string to search 
+ * \param patn the pattern to find in string
+ * \returns position in string
+ */
+int pattern2(char *search, char *patn)
+{
+       int a;
+       int len, plen;
+       len = strlen (search);
+       plen = strlen (patn);
+       for (a = 0; a < len; ++a) {
+               if (!strncasecmp(&search[a], patn, plen))
+                       return (a);
+       }
+       return (-1);
+}
+
+
+/**
+ * \brief Strip leading and trailing spaces from a string; with premeasured and adjusted length.
+ * \param buf the string to modify
+ * \param len length of the string. 
+ */
+void stripltlen(char *buf, int *len)
+{
+       int delta = 0;
+       if (*len == 0) return;
+       while ((*len > delta) && (isspace(buf[delta]))){
+               delta ++;
+       }
+       memmove (buf, &buf[delta], *len - delta + 1);
+       (*len) -=delta;
+
+       if (*len == 0) return;
+       while (isspace(buf[(*len) - 1])){
+               buf[--(*len)] = '\0';
+       }
+}
+
index 44871bf2fbb2216aea571fd1f769fc49ae68700e..2c024f9d6ee0779f0817816664356e5f6bf98d19 100644 (file)
@@ -36,16 +36,16 @@ distclean: clean
                po/Makefile \
                $(srcdir)/TAGS
 
-setup: setup.o tools.o
-       $(CC) setup.o tools.o \
+setup: setup.o
+       $(CC) setup.o \
        $(LIBOBJS) $(LIBS) $(LDFLAGS) $(SETUP_LIBS) -o setup
 
-webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
+webserver: webserver.o context_loop.o ical_dezonify.o \
        cookie_conversion.o locate_host.o floors.o summary.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \
        roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \
        vcard.o vcard_edit.o preferences.o html2html.o listsub.o \
-       mime_parser.o graphics.o netconf.o siteconfig.o subst.o rss.o \
+       graphics.o netconf.o siteconfig.o subst.o rss.o \
        calendar.o calendar_tools.o calendar_view.o event.o smtpqueue.o \
        availability.o iconbar.o crypto.o inetconf.o notes.o wiki.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \
@@ -53,11 +53,11 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \
        groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \
        downloads.o  addressbook_popup.o pushemail.o sysdep.o \
        $(LIBOBJS)
-       $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \
+       $(CC) webserver.o context_loop.o cookie_conversion.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \
        roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \
        locate_host.o siteconfig.o subst.o vcard.o vcard_edit.o floors.o \
-       mime_parser.o graphics.o netconf.o preferences.o html2html.o rss.o \
+       graphics.o netconf.o preferences.o html2html.o rss.o \
        summary.o calendar.o calendar_tools.o calendar_view.o event.o wiki.o \
        availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \
        groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \
index 6ea3cd7ffce570da8d96bdf8cfc6ddeb5e8b70a9..3ced19b1d177605966ae6a6630a3836d18bcb918 100644 (file)
@@ -170,7 +170,7 @@ void cal_process_object(icalcomponent *cal,
                        }
                        else {
                                tt = icaltime_as_timet(t);
-                               fmt_date(buf, tt, 0);
+                               webcit_fmt_date(buf, tt, 0);
                                wprintf("<dt>");
                                wprintf(_("Starting date/time:"));
                                wprintf("</dt><dd>%s</dd>", buf);
@@ -181,7 +181,7 @@ void cal_process_object(icalcomponent *cal,
                if (p != NULL) {
                        t = icalproperty_get_dtend(p);
                        tt = icaltime_as_timet(t);
-                       fmt_date(buf, tt, 0);
+                       webcit_fmt_date(buf, tt, 0);
                        wprintf("<dt>");
                        wprintf(_("Ending date/time:"));
                        wprintf("</dt><dd>%s</dd>", buf);
index addfe9cac583b0316c24c8fa95ad061ad7dd151a..b5525b1beb5274d461db2a0b257f008fa628005d 100644 (file)
@@ -302,7 +302,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                }
                                                else {
                                                        tt = icaltime_as_timet(t);
-                                                       fmt_date(buf, tt, 1);
+                                                       webcit_fmt_date(buf, tt, 1);
                                                        wprintf("<i>%s</i> %s<br>",
                                                                _("Starting date/time:"), buf);
                                                        
@@ -313,7 +313,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                        if (q != NULL) {
                                                                t = icalproperty_get_dtend(q);
                                                                tt = icaltime_as_timet(t);
-                                                               fmt_date(buf, tt, 1);
+                                                               webcit_fmt_date(buf, tt, 1);
                                                                wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                                        }
                                                        
@@ -932,9 +932,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                         }
-                                fmt_date(buf, event_tt, 1);
+                                webcit_fmt_date(buf, event_tt, 1);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                fmt_date(buf, event_tte, 1);
+                                webcit_fmt_date(buf, event_tte, 1);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -1009,9 +1009,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                         }
-                                fmt_date(buf, event_tt, 1);
+                                webcit_fmt_date(buf, event_tt, 1);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                fmt_date(buf, event_tte, 1);
+                                webcit_fmt_date(buf, event_tte, 1);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -1480,7 +1480,7 @@ void do_tasks_view(void) {
                wprintf("</td>\n");
 
                due = get_task_due_date(WC->disp_cal[i].cal);
-               fmt_date(buf, due, 0);
+               webcit_fmt_date(buf, due, 0);
                wprintf("<td><font");
                if (due < time(NULL)) {
                        wprintf(" color=\"#FF0000\"");
index 5f1b9a02ebf380d7731dcb9fd8d00d8fb5ab6ba0..d8c30e82d586008e26d8b4aab3a8a9ece4e5bc70 100644 (file)
@@ -100,6 +100,25 @@ AC_TYPE_SIGNAL
 dnl AC_FUNC_VPRINTF
 AC_REPLACE_FUNCS(snprintf)
 
+
+dnl Check for libcitadel
+AC_CHECK_HEADER(libcitadel.h,
+       [AC_CHECK_LIB(citadel, libcitadel_version_string,
+               [
+                       AC_MSG_RESULT(OK)
+                       LIBS="-lcitadel $LIBS"
+               ],
+               [
+                       AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
+               ]
+       ,
+       )],
+       [
+               AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
+       ]
+)
+
+
 webcit_with_calendar_service=no
 dnl Checks for the libical calendaring library.
 if test "x$with_libical" != xno ; then
index a93e75f827883860e32e5462733b45774e7d03ba..3289fac0ae4f2af719cfdf6aa4626c6cef49caad 100644 (file)
@@ -44,7 +44,7 @@ size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm)
  * \param thetime time to convert to string 
  * \param brief do we want compact view?????
  */
-void fmt_date(char *buf, time_t thetime, int brief)
+void webcit_fmt_date(char *buf, time_t thetime, int brief)
 {
        struct tm tm;
        struct tm today_tm;
index 2cf1885235aca9c7468d0c9c533917b372e2eeda..124d44988108cf79f171f4f27d76e1f6b5575159 100644 (file)
@@ -8,7 +8,6 @@
 #include "webcit.h"
 #include "webserver.h"
 #include "groupdav.h"
-#include "mime_parser.h"
 
 
 /*
index a2e8168efbe49a45032d55ae2f2550c204d5bb9f..935e9a367feaa6b115203437a42448da33aa5b65 100644 (file)
@@ -210,7 +210,7 @@ void utf8ify_rfc822_string(char *buf) {
  * \param      maxlen          Maximum size of target buffer.
  * \param      source          Source string to be encoded.
  */
-void rfc2047encode(char *target, int maxlen, char *source)
+void webcit_rfc2047encode(char *target, int maxlen, char *source)
 {
        int need_to_encode = 0;
        int i, len;
@@ -813,7 +813,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                        wprintf(" ");
                }
                if (!strncasecmp(buf, "time=", 5)) {
-                       fmt_date(now, atol(&buf[5]), 0);
+                       webcit_fmt_date(now, atol(&buf[5]), 0);
                        wprintf("<span>");
                        wprintf("%s ", now);
                        wprintf("</span>");
@@ -1418,7 +1418,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                                wprintf("%s ", &buf[5]);
                        }
                        if (!strncasecmp(buf, "time=", 5)) {
-                               fmt_date(now, atol(&buf[5]), 0);
+                               webcit_fmt_date(now, atol(&buf[5]), 0);
                                wprintf("%s ", now);
                        }
                }
@@ -1659,7 +1659,7 @@ void display_summarized(int num) {
        wprintf("</td>");
 
        wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
-       fmt_date(datebuf, WC->summ[num].date, 1);       /* brief */
+       webcit_fmt_date(datebuf, WC->summ[num].date, 1);        /* brief */
        escputs(datebuf);
        wprintf("</td>");
 
@@ -2834,7 +2834,7 @@ void post_mime_to_server(void) {
                        encoded_length = ((att->length * 150) / 100);
                        encoded = malloc(encoded_length);
                        if (encoded == NULL) break;
-                       encoded_strlen = CtdlEncodeBase64(&encoded, att->data, att->length, &encoded_length, 1);
+                       encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
 
                        serv_printf("--%s", boundary);
                        serv_printf("Content-type: %s", att->content_type);
@@ -2939,7 +2939,7 @@ void post_message(void)
                        _("Automatically cancelled because you have already "
                        "saved this message."));
        } else {
-               rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
+               webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
                sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
                        bstr("recp"),
                        is_anonymous,
@@ -3145,7 +3145,7 @@ void display_enter(void)
 
        wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
        wprintf("  ");  /** header bar */
-       fmt_date(buf, now, 0);
+       webcit_fmt_date(buf, now, 0);
        wprintf("%s", buf);
        wprintf("\n");  /** header bar */
 
diff --git a/webcit/mime_parser.c b/webcit/mime_parser.c
deleted file mode 100644 (file)
index c41fb26..0000000
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * $Id$
- */
-/**
- * \defgroup MIME This is the MIME parser for Citadel.
- *
- * Copyright (c) 1998-2005 by Art Cancro
- * This code is distributed under the terms of the GNU General Public License.
- * \ingroup WebcitHttpServer
- */
-/*@{*/
-#include "webcit.h"
-#include "webserver.h"
-#include "mime_parser.h"
-
-void extract_key(char *target, char *source, char *key)
-{
-       char *ptr;
-       char looking_for[256];
-       int double_quotes = 0;
-
-       snprintf(looking_for, sizeof looking_for, "%s=", key);
-
-       ptr = bmstrcasestr(source, looking_for);
-       if (ptr == NULL) {
-               strcpy(target, "");
-               return;
-       }
-       strcpy(target, (ptr + strlen(looking_for)));
-
-       for (ptr=target; (*ptr != 0); ++ptr) {
-
-               /* A semicolon means we've hit the end of the key, unless we're inside double quotes */
-               if ( (double_quotes != 1) && (*ptr == ';')) {
-                       *ptr = 0;
-               }
-
-               /* if we find double quotes, we've got a great set of string boundaries */
-               if (*ptr == '\"') {
-                       ++double_quotes;
-                       if (double_quotes == 1) {
-                               strcpy(ptr, ptr+1);
-                       }
-                       else {
-                               *ptr = 0;
-                       }
-               }
-       }
-}
-
-
-/*
- * For non-multipart messages, we need to generate a quickie partnum of "1"
- * to return to callback functions.  Some callbacks demand it.
- */
-char *fixed_partnum(char *supplied_partnum) {
-       if (supplied_partnum == NULL) return "1";
-       if (strlen(supplied_partnum)==0) return "1";
-       return supplied_partnum;
-}
-
-
-
-/*
- * Given a message or message-part body and a length, handle any necessary
- * decoding and pass the request up the stack.
- */
-void mime_decode(char *partnum,
-                char *part_start, size_t length,
-                char *content_type, char *charset, char *encoding,
-                char *disposition,
-                char *name, char *filename,
-                void (*CallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                void (*PreMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                void (*PostMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-                 void *userdata,
-                 int dont_decode
-)
-{
-
-       char *decoded;
-       size_t bytes_decoded = 0;
-
-       /* Some encodings aren't really encodings */
-       if (!strcasecmp(encoding, "7bit"))
-               strcpy(encoding, "");
-       if (!strcasecmp(encoding, "8bit"))
-               strcpy(encoding, "");
-       if (!strcasecmp(encoding, "binary"))
-               strcpy(encoding, "");
-
-       /* If this part is not encoded, send as-is */
-       if ( (strlen(encoding) == 0) || (dont_decode)) {
-               if (CallBack != NULL) {
-                       CallBack(name, filename, fixed_partnum(partnum),
-                               disposition, part_start,
-                               content_type, charset, length, encoding, userdata);
-                       }
-               return;
-       }
-       
-       /* Fail silently if we hit an unknown encoding. */
-       if ((strcasecmp(encoding, "base64"))
-           && (strcasecmp(encoding, "quoted-printable"))) {
-               return;
-       }
-
-       /*
-        * Allocate a buffer for the decoded data.  The output buffer is slightly
-        * larger than the input buffer; this assumes that the decoded data
-        * will never be significantly larger than the encoded data.  This is a
-        * safe assumption with base64, uuencode, and quoted-printable.
-        */
-       decoded = malloc(length + 32768);
-       if (decoded == NULL) {
-               return;
-       }
-
-       if (!strcasecmp(encoding, "base64")) {
-               bytes_decoded = CtdlDecodeBase64(decoded, part_start, length);
-       }
-       else if (!strcasecmp(encoding, "quoted-printable")) {
-               bytes_decoded = CtdlDecodeQuotedPrintable(decoded, part_start, length);
-       }
-
-       if (bytes_decoded > 0) if (CallBack != NULL) {
-               CallBack(name, filename, fixed_partnum(partnum),
-                       disposition, decoded,
-                       content_type, charset, bytes_decoded, "binary", userdata);
-       }
-
-       free(decoded);
-}
-
-/*
- * Break out the components of a multipart message
- * (This function expects to be fed HEADERS + CONTENT)
- * Note: NULL can be supplied as content_end; in this case, the message is
- * considered to have ended when the parser encounters a 0x00 byte.
- */
-void the_mime_parser(char *partnum,
-                    char *content_start, char *content_end,
-                    void (*CallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                    void (*PreMultiPartCallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                    void (*PostMultiPartCallBack)
-                     (char *cbname,
-                      char *cbfilename,
-                      char *cbpartnum,
-                      char *cbdisp,
-                      void *cbcontent,
-                      char *cbtype,
-                      char *cbcharset,
-                      size_t cblength,
-                      char *cbencoding,
-                      void *cbuserdata),
-                     void *userdata,
-                     int dont_decode
-)
-{
-
-       char *ptr;
-       char *srch = NULL;
-       char *part_start, *part_end = NULL;
-       char buf[SIZ];
-       char *header;
-       char *boundary;
-       char *startary;
-       size_t startary_len = 0;
-       char *endary;
-       char *next_boundary;
-       char *content_type;
-       char *charset;
-       size_t content_length;
-       char *encoding;
-       char *disposition;
-       char *name = NULL;
-       char *content_type_name;
-       char *content_disposition_name;
-       char *filename;
-       int is_multipart;
-       int part_seq = 0;
-       int i;
-       size_t length;
-       char nested_partnum[256];
-       int crlf_in_use = 0;
-       char *evaluate_crlf_ptr = NULL;
-       int buflen = 0;
-       int headerlen = 0;
-
-       ptr = content_start;
-       content_length = 0;
-
-       boundary = malloc(SIZ);
-       memset(boundary, 0, SIZ);
-
-       startary = malloc(SIZ);
-       memset(startary, 0, SIZ);
-
-       endary = malloc(SIZ);
-       memset(endary, 0, SIZ);
-
-       header = malloc(SIZ);
-       memset(header, 0, SIZ);
-
-       content_type = malloc(SIZ);
-       memset(content_type, 0, SIZ);
-
-       charset = malloc(SIZ);
-       memset(charset, 0, SIZ);
-
-       encoding = malloc(SIZ);
-       memset(encoding, 0, SIZ);
-
-       content_type_name = malloc(SIZ);
-       memset(content_type_name, 0, SIZ);
-
-       content_disposition_name = malloc(SIZ);
-       memset(content_disposition_name, 0, SIZ);
-
-       filename = malloc(SIZ);
-       memset(filename, 0, SIZ);
-
-       disposition = malloc(SIZ);
-       memset(disposition, 0, SIZ);
-
-       /* If the caller didn't supply an endpointer, generate one by measure */
-       if (content_end == NULL) {
-               content_end = &content_start[strlen(content_start)];
-       }
-
-       /* Learn interesting things from the headers */
-       strcpy(header, "");
-       headerlen = 0;
-       do {
-               ptr = memreadlinelen(ptr, buf, SIZ, &buflen);
-               if (ptr >= content_end) {
-                       goto end_parser;
-               }
-
-               for (i = 0; i < buflen; ++i) {
-                       if (isspace(buf[i])) {
-                               buf[i] = ' ';
-                       }
-               }
-
-               if (!isspace(buf[0])) {
-                       if (!strncasecmp(header, "Content-type:", 13)) {
-                               strcpy(content_type, &header[13]);
-                               striplt(content_type);
-                               extract_key(content_type_name, content_type, "name");
-                               extract_key(charset, content_type, "charset");
-                               extract_key(boundary, header, "boundary");
-                               /* Deal with weird headers */
-                               if (strchr(content_type, ' '))
-                                       *(strchr(content_type, ' ')) = '\0';
-                               if (strchr(content_type, ';'))
-                                       *(strchr(content_type, ';')) = '\0';
-                       }
-                       if (!strncasecmp(header, "Content-Disposition:", 20)) {
-                               strcpy(disposition, &header[20]);
-                               striplt(disposition);
-                               extract_key(content_disposition_name, disposition, "name");
-                               extract_key(filename, disposition, "filename");
-                       }
-                       if (!strncasecmp(header, "Content-length: ", 15)) {
-                               char clbuf[10];
-                               safestrncpy(clbuf, &header[15], sizeof clbuf);
-                               striplt(clbuf);
-                               content_length = (size_t) atol(clbuf);
-                       }
-                       if (!strncasecmp(header, "Content-transfer-encoding: ", 26)) {
-                               strcpy(encoding, &header[26]);
-                               striplt(encoding);
-                       }
-                       strcpy(header, "");
-                       headerlen = 0;
-               }
-               if ((headerlen + buflen + 2) < SIZ) {
-                       memcpy(&header[headerlen], buf, buflen);
-                       headerlen += buflen;
-                       header[headerlen] = '\0';
-               }
-       } while ((!IsEmptyStr(buf)) && (*ptr != 0));
-
-       if (strchr(disposition, ';'))
-               *(strchr(disposition, ';')) = '\0';
-       striplt(disposition);
-       if (strchr(content_type, ';'))
-               *(strchr(content_type, ';')) = '\0';
-       striplt(content_type);
-
-       if (!IsEmptyStr(boundary)) {
-               is_multipart = 1;
-       } else {
-               is_multipart = 0;
-       }
-
-       /* If this is a multipart message, then recursively process it */
-       part_start = NULL;
-       if (is_multipart) {
-
-               /* Tell the client about this message's multipartedness */
-               if (PreMultiPartCallBack != NULL) {
-                       PreMultiPartCallBack("", "", partnum, "",
-                               NULL, content_type, charset,
-                               0, encoding, userdata);
-               }
-
-               /* Figure out where the boundaries are */
-               snprintf(startary, SIZ, "--%s", boundary);
-               snprintf(endary, SIZ, "--%s--", boundary);
-               startary_len = strlen(startary);
-
-               part_start = NULL;
-               do {
-                       next_boundary = NULL;
-                       for (srch=ptr; srch<content_end; ++srch) {
-                               if (!memcmp(srch, startary, startary_len)) {
-                                       next_boundary = srch;
-                                       srch = content_end;
-                               }
-                       }
-
-                       if ( (part_start != NULL) && (next_boundary != NULL) ) {
-                               part_end = next_boundary;
-                               --part_end;             /* omit the trailing LF */
-                               if (crlf_in_use) {
-                                       --part_end;     /* omit the trailing CR */
-                               }
-
-                               if (!IsEmptyStr(partnum)) {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%s.%d", partnum,
-                                                ++part_seq);
-                               }
-                               else {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%d", ++part_seq);
-                               }
-                               the_mime_parser(nested_partnum,
-                                           part_start, part_end,
-                                               CallBack,
-                                               PreMultiPartCallBack,
-                                               PostMultiPartCallBack,
-                                               userdata,
-                                               dont_decode);
-                       }
-
-                       if (next_boundary != NULL) {
-                               /* If we pass out of scope, don't attempt to
-                                * read past the end boundary. */
-                               if (!strcmp(next_boundary, endary)) {
-                                       ptr = content_end;
-                               }
-                               else {
-                                       /* Set up for the next part. */
-                                       part_start = strstr(next_boundary, "\n");
-                                       
-                                       /* Determine whether newlines are LF or CRLF */
-                                       evaluate_crlf_ptr = part_start;
-                                       --evaluate_crlf_ptr;
-                                       if (!memcmp(evaluate_crlf_ptr, "\r\n", 2)) {
-                                               crlf_in_use = 1;
-                                       }
-                                       else {
-                                               crlf_in_use = 0;
-                                       }
-
-                                       /* Advance past the LF ... now we're in the next part */
-                                       ++part_start;
-                                       ptr = part_start;
-                               }
-                       }
-                       else {
-                               /* Invalid end of multipart.  Bail out! */
-                               ptr = content_end;
-                       }
-               } while ( (ptr < content_end) && (next_boundary != NULL) );
-
-               if (PostMultiPartCallBack != NULL) {
-                       PostMultiPartCallBack("", "", partnum, "", NULL,
-                               content_type, charset, 0, encoding, userdata);
-               }
-               goto end_parser;
-       }
-
-       /* If it's not a multipart message, then do something with it */
-       if (!is_multipart) {
-               part_start = ptr;
-               length = 0;
-               while (ptr < content_end) {
-                       ++ptr;
-                       ++length;
-               }
-               part_end = content_end;
-
-               /******
-                * I thought there was an off-by-one error here, but there isn't.
-                * This probably means that there's an off-by-one error somewhere
-                * else ... or maybe only in certain messages?
-               --part_end;
-               --length;
-               ******/
-               
-               /* Truncate if the header told us to */
-               if ( (content_length > 0) && (length > content_length) ) {
-                       length = content_length;
-               }
-
-               /* Sometimes the "name" field is tacked on to Content-type,
-                * and sometimes it's tacked on to Content-disposition.  Use
-                * whichever one we have.
-                */
-               if (strlen(content_disposition_name) > strlen(content_type_name)) {
-                       name = content_disposition_name;
-               }
-               else {
-                       name = content_type_name;
-               }
-       
-               /* lprintf(CTDL_DEBUG, "mime_decode part=%s, len=%d, type=%s, charset=%s, encoding=%s\n",
-                       partnum, length, content_type, charset, encoding); */
-
-               /* Ok, we've got a non-multipart part here, so do something with it.
-                */
-               mime_decode(partnum,
-                       part_start, length,
-                       content_type, charset, encoding, disposition,
-                       name, filename,
-                       CallBack, NULL, NULL,
-                       userdata, dont_decode
-               );
-
-               /*
-                * Now if it's an encapsulated message/rfc822 then we have to recurse into it
-                */
-               if (!strcasecmp(content_type, "message/rfc822")) {
-
-                       if (PreMultiPartCallBack != NULL) {
-                               PreMultiPartCallBack("", "", partnum, "",
-                                       NULL, content_type, charset,
-                                       0, encoding, userdata);
-                       }
-                       if (CallBack != NULL) {
-                               if (strlen(partnum) > 0) {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%s.%d", partnum,
-                                                ++part_seq);
-                               }
-                               else {
-                                       snprintf(nested_partnum,
-                                                sizeof nested_partnum,
-                                                "%d", ++part_seq);
-                               }
-                               the_mime_parser(nested_partnum,
-                                       part_start, part_end,
-                                       CallBack,
-                                       PreMultiPartCallBack,
-                                       PostMultiPartCallBack,
-                                       userdata,
-                                       dont_decode
-                               );
-                       }
-                       if (PostMultiPartCallBack != NULL) {
-                               PostMultiPartCallBack("", "", partnum, "", NULL,
-                                       content_type, charset, 0, encoding, userdata);
-                       }
-
-
-               }
-
-       }
-
-end_parser:    /* free the buffers!  end the oppression!! */
-       free(boundary);
-       free(startary);
-       free(endary);   
-       free(header);
-       free(content_type);
-       free(charset);
-       free(encoding);
-       free(content_type_name);
-       free(content_disposition_name);
-       free(filename);
-       free(disposition);
-}
-
-
-
-/*
- * Entry point for the MIME parser.
- * (This function expects to be fed HEADERS + CONTENT)
- * Note: NULL can be supplied as content_end; in this case, the message is
- * considered to have ended when the parser encounters a 0x00 byte.
- */
-void mime_parser(char *content_start,
-               char *content_end,
-
-                void (*CallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                void (*PreMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                void (*PostMultiPartCallBack)
-                 (char *cbname,
-                  char *cbfilename,
-                  char *cbpartnum,
-                  char *cbdisp,
-                  void *cbcontent,
-                  char *cbtype,
-                  char *cbcharset,
-                  size_t cblength,
-                  char *cbencoding,
-                  void *cbuserdata),
-
-                 void *userdata,
-                 int dont_decode
-)
-{
-
-       the_mime_parser("", content_start, content_end,
-                       CallBack,
-                       PreMultiPartCallBack,
-                       PostMultiPartCallBack,
-                       userdata, dont_decode);
-}
diff --git a/webcit/mime_parser.h b/webcit/mime_parser.h
deleted file mode 100644 (file)
index b82cd68..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * $Id$
- *
- */
-
-/*
- * Here's a bunch of stupid magic to make the MIME parser portable between
- * Citadel and WebCit.
- */
-#ifndef SIZ
-#define SIZ    4096
-#endif
-
-
-/* 
- * Declarations for functions in the parser
- */
-
-void extract_key(char *target, char *source, char *key);
-
-void mime_parser(char *content_start, char *content_end,
-               void (*CallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void (*PreMultiPartCallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void (*PostMultiPartCallBack)
-                       (char *cbname,
-                       char *cbfilename,
-                       char *cbpartnum,
-                       char *cbdisp,
-                       void *cbcontent,
-                       char *cbtype,
-                       char *cbcharset,
-                       size_t cblength,
-                       char *cbencoding,
-                       void *cbuserdata),
-               void *userdata,
-               int dont_decode
-               );
index 3dde76a609fa029e0c17e8910b53fe1757892db5..831151045c0a9ddd4e8c224fd49e5fc26d65ba57 100644 (file)
@@ -425,12 +425,9 @@ void parse_fields_from_rule_editor(void) {
        char buf[256];
        char fname[256];
        char rule[2048];
-       char *encoded_rule;
+       char encoded_rule[4096];
        char my_addresses[4096];
-       size_t encoded_len;
        
-       encoded_len = 4096;
-       encoded_rule = (char*) malloc (encoded_len);
        /* Enumerate my email addresses in case they are needed for a vacation rule */
        my_addresses[0] = 0;
        serv_puts("GVEA");
@@ -509,7 +506,7 @@ void parse_fields_from_rule_editor(void) {
                                redirect, automsg, final
                        );
        
-                       CtdlEncodeBase64(&encoded_rule, rule, strlen(rule)+1, &encoded_len, 0);
+                       CtdlEncodeBase64(encoded_rule, rule, strlen(rule)+1, 0);
                        serv_printf("# WEBCIT_RULE|%d|%s|", i, encoded_rule);
                        output_sieve_rule(hfield, compare, htext, sizecomp, sizeval,
                                        action, fileinto, redirect, automsg, final, my_addresses);
@@ -521,7 +518,6 @@ void parse_fields_from_rule_editor(void) {
 
        serv_puts("stop;");
        serv_puts("000");
-       free(encoded_rule);
 }
 
 
index 664e5eff6f087736512a0cde2f5e6f7ecfc930cc..9b9e5726fc7ae4d6308c27ef093d5875a4e17877 100644 (file)
@@ -144,7 +144,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (submitted > 0) {
-               fmt_date(buf, submitted, 1);
+               webcit_fmt_date(buf, submitted, 1);
                wprintf("%s", buf);
        }
        else {
@@ -153,7 +153,7 @@ void display_queue_msg(long msgnum)
 
        wprintf("</td><td>");
        if (last_attempt > 0) {
-               fmt_date(buf, last_attempt, 1);
+               webcit_fmt_date(buf, last_attempt, 1);
                wprintf("%s", buf);
        }
        else {
diff --git a/webcit/tools.c b/webcit/tools.c
deleted file mode 100644 (file)
index 591af0d..0000000
+++ /dev/null
@@ -1,762 +0,0 @@
-/*
- * $Id$
- */
-/**
- * \defgroup MiscRout Miscellaneous routines 
- * \ingroup tools
- */
-
-/*@{*/
-#include "webcit.h"
-#include "webserver.h"
-
-
-typedef unsigned char byte; /**< byte data type */
-
-#define FALSE 0 /**< no. */
-#define TRUE 1  /**< yes. */
-
-static byte dtable[256];       /**< base64 encode / decode table */
-
-/**
- * \brief sanitize strncopy.
- * \param dest destination string
- * \param src source string
- * \param n length of source to copy 
- * \return result string
- */
-char *safestrncpy(char *dest, const char *src, size_t n)
-{
-       if (dest == NULL || src == NULL) {
-               abort();
-       }
-       strncpy(dest, src, n);
-       dest[n - 1] = 0;
-       return dest;
-}
-
-
-
-/**
- * \brief discover number of parameters/tokens in a string
- * \param source string to inspect
- * \param tok seperation token
- * \return number of tokenized parts found
- */
-int num_tokens(char *source, char tok)
-{
-       int count = 1;
-       char *ptr = source;
-
-       if (source == NULL) {
-               return (0);
-       }
-
-       while (*ptr != '\0') {
-               if (*ptr++ == tok) {
-                       ++count;
-               }
-       }
-       
-       return (count);
-}
-
-/*
- * extract_token() - a string tokenizer
- * returns -1 if not found, or length of token.
- */
-long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen)
-{
-       const char *s;                  //* source * /
-       int len = 0;                    //* running total length of extracted string * /
-       int current_token = 0;          //* token currently being processed * /
-
-       s = source;
-
-       if (dest == NULL) {
-               return(-1);
-       }
-
-//     cit_backtrace();
-//     lprintf (CTDL_DEBUG, "test >: n: %d sep: %c source: %s \n willi \n", parmnum, separator, source);
-       dest[0] = 0;
-
-       if (s == NULL) {
-               return(-1);
-       }
-
-       maxlen--;
-       
-       while (*s) {
-               if (*s == separator) {
-                       ++current_token;
-               }
-               if ( (current_token == parmnum) && 
-                    (*s != separator) && 
-                    (len < maxlen) ) {
-                       dest[len] = *s;
-                       ++len;
-               }
-               else if ((current_token > parmnum) || (len >= maxlen)) {
-                       break;
-               }
-               ++s;
-       }
-
-       dest[len] = '\0';
-       if (current_token < parmnum) {
-//             lprintf (CTDL_DEBUG,"test <!: %s\n", dest);
-               return(-1);
-       }
-//     lprintf (CTDL_DEBUG,"test <: %d; %s\n", len, dest);
-       return(len);
-}
-//*/
-
-
-/**
- * \brief a tokenizer that kills, maims, and destroys
- * \param source the string to process
- * \param parmnum which token to kill
- * \param separator the tokenizer string
- */
-void remove_token(char *source, int parmnum, char separator)
-{
-       int i;
-       int len, slen;
-       int curr_parm;
-       int start, end;
-
-       len = 0;
-       curr_parm = 0;
-       start = (-1);
-       end = (-1);
-
-       slen = strlen(source);
-       if (slen == 0) {
-               return;
-       }
-
-       for (i = 0; 
-            ( (i < slen)  && (end == -1) ); 
-            ++i) {
-               if ((start < 0) && (curr_parm == parmnum)) {
-                       start = i;
-               }
-
-               if ((end < 0) && (curr_parm == (parmnum + 1))) {
-                       end = i;
-               }
-
-               if (source[i] == separator) {
-                       ++curr_parm;
-               }
-       }
-
-       if (end < 0)
-               end = slen;
-
-       memmove(&source[start], &source[end], slen - end + 1);
-}
-
-
-
-
-/**
- * \brief extract an int parm w/o supplying a buffer
- * \param source the string to locate the int in
- * \param parmnum the n'th token to grab the int from
- * \return the integer
- */
-int extract_int(const char *source, int parmnum)
-{
-       char buf[32];
-       
-       extract_token(buf, source, parmnum, '|', sizeof buf);
-       return(atoi(buf));
-}
-
-/**
- * \brief extract an long parm w/o supplying a buffer
- * \param source string to examine
- * \param parmnum n'th token to search long in
- * \return the found long value
- */
-long extract_long(const char *source, int parmnum)
-{
-       char buf[32];
-       
-       extract_token(buf, source, parmnum, '|', sizeof buf);
-       return(atol(buf));
-}
-
-
-
-
-
-
-/**
- * \brief check for the presence of a character within a string (returns count)
- * \param st the string to examine
- * \param ch the char to search
- * \return the position inside of st
- */
-int haschar(const char *st,char ch)
-{
-       const char *ptr;
-       int b;
-       b = 0;
-       ptr = st;
-       while (!IsEmptyStr(ptr))
-               if (*ptr == ch)
-                       ++b;
-       return (b);
-}
-
-
-/** 
- * \brief Utility function to "readline" from memory
- * \param start Location in memory from which we are reading.
- * \param buf the buffer to place the string in.
- * \param maxlen Size of string buffer
- * \return Pointer to the source memory right after we stopped reading.
- */
-char *memreadline(char *start, char *buf, int maxlen)
-{
-       char ch;
-       char *ptr;
-       int len = 0;            /**< tally our own length to avoid strlen() delays */
-
-       ptr = start;
-       while (1) {
-               ch = *ptr++;
-               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
-                       buf[len++] = ch;
-               }
-               if ((ch == 10) || (ch == 0)) {
-                       buf[len] = 0;
-                       return ptr;
-               }
-       }
-}
-
-
-/** 
- * \brief Utility function to "readline" from memory
- * \param start Location in memory from which we are reading.
- * \param buf the buffer to place the string in.
- * \param maxlen Size of string buffer
- * \param retlen the length of the returned string
- * \return Pointer to the source memory right after we stopped reading.
- */
-char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen)
-{
-       char ch;
-       char *ptr;
-       int len = 0;            /**< tally our own length to avoid strlen() delays */
-
-       ptr = start;
-
-       while (1) {
-               ch = *ptr++;
-               if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
-                       buf[len++] = ch;
-               }
-               if ((ch == 10) || (ch == 0)) {
-                       buf[len] = 0;
-                       *retlen = len;
-                       return ptr;
-               }
-       }
-}
-
-
-
-/**
- * \brief searches for a  paternn within asearch string
- * \param search the string to search 
- * \param patn the pattern to find in string
- * \returns position in string
- */
-int pattern2(char *search, char *patn)
-{
-       int a;
-       int len, plen;
-       len = strlen (search);
-       plen = strlen (patn);
-       for (a = 0; a < len; ++a) {
-               if (!strncasecmp(&search[a], patn, plen))
-                       return (a);
-       }
-       return (-1);
-}
-
-
-/**
- * \brief Strip leading and trailing spaces from a string; with premeasured and adjusted length.
- * \param buf the string to modify
- * \param len length of the string. 
- */
-void stripltlen(char *buf, int *len)
-{
-       int delta = 0;
-       if (*len == 0) return;
-       while ((*len > delta) && (isspace(buf[delta]))){
-               delta ++;
-       }
-       memmove (buf, &buf[delta], *len - delta + 1);
-       (*len) -=delta;
-
-       if (*len == 0) return;
-       while (isspace(buf[(*len) - 1])){
-               buf[--(*len)] = '\0';
-       }
-}
-
-/**
- * \brief Strip leading and trailing spaces from a string
- * \param buf the string to modify
- */
-void striplt(char *buf)
-{
-       int len;
-       len = strlen(buf);
-       stripltlen(buf, &len);
-}
-
-
-/**
- * \brief Determine whether the specified message number is contained within the
- * specified set.
- *
- * \param mset Message set string
- * \param msgnum Message number we are looking for
- *
- * \return Nonzero if the specified message number is in the specified message set string.
- */
-int is_msg_in_mset(char *mset, long msgnum) {
-       int num_sets;
-       int s;
-       char setstr[SIZ], lostr[SIZ], histr[SIZ];       /* was 1024 */
-       long lo, hi;
-
-       /*
-        * Now set it for all specified messages.
-        */
-       num_sets = num_tokens(mset, ',');
-       for (s=0; s<num_sets; ++s) {
-               extract_token(setstr, mset, s, ',', sizeof setstr);
-
-               extract_token(lostr, setstr, 0, ':', sizeof lostr);
-               if (num_tokens(setstr, ':') >= 2) {
-                       extract_token(histr, setstr, 1, ':', sizeof histr);
-                       if (!strcmp(histr, "*")) {
-                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
-                       }
-               } 
-               else {
-                       strcpy(histr, lostr);
-               }
-               lo = atol(lostr);
-               hi = atol(histr);
-
-               if ((msgnum >= lo) && (msgnum <= hi)) return(1);
-       }
-
-       return(0);
-}
-
-
-
-/**
- * \brief Strip a boundarized substring out of a string
- * (for example, remove
- * parentheses and anything inside them).
- *
- * This improved version can strip out *multiple* boundarized substrings.
- * \param str the string to process
- * \param leftboundary the boundary character on the left side of the target string 
- * \param rightboundary the boundary character on the right side of the target string
- */
-void stripout(char *str, char leftboundary, char rightboundary)
-{
-       int a;
-       int lb = (-1);
-       int rb = (-1);
-       int len = strlen(str);
-
-       do {
-               lb = (-1);
-               rb = (-1);
-
-               for (a = 0; a < len; ++a) {
-                       if (str[a] == leftboundary)
-                               lb = a;
-                       if (str[a] == rightboundary)
-                               rb = a;
-               }
-
-               if ((lb > 0) && (rb > lb)) {
-                       memmove(&str[lb - 1], &str[rb + 1], len - rb);
-                       len -= (rb - lb + 2);
-               }
-
-       } while ((lb > 0) && (rb > lb));
-
-}
-
-
-
-/**
- * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
- * \param seconds how many seconds should we sleep?
- */
-void sleeeeeeeeeep(int seconds)
-{
-       struct timeval tv;
-
-       tv.tv_sec = seconds;
-       tv.tv_usec = 0;
-       select(0, NULL, NULL, NULL, &tv);
-}
-
-
-
-/**
- * \brief encode a string into base64 to for example tunnel it through mail transport
- * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by
- * John Walker, copied over from the Citadel server.
- * \param dest encrypted string
- * \param source the string to encrypt
- * \param sourcelen the length of the source data (may contain string terminators)
- * \return the length of the encoded string.
- */
-
-size_t CtdlEncodeBase64(char **pdest, const char *source, size_t sourcelen, size_t *destlen, int linebreaks)
-{
-       int i, hiteof = FALSE;
-       int spos = 0;
-       int dpos = 0;
-       int thisline = 0;
-       char *dest;
-
-       dest = *pdest;
-
-       /**  Fill dtable with character encodings.  */
-
-       for (i = 0; i < 26; i++) {
-               dtable[i] = 'A' + i;
-               dtable[26 + i] = 'a' + i;
-       }
-       for (i = 0; i < 10; i++) {
-               dtable[52 + i] = '0' + i;
-       }
-       dtable[62] = '+';
-       dtable[63] = '/';
-
-       while (!hiteof) {
-               byte igroup[3], ogroup[4];
-               int c, n;
-
-               igroup[0] = igroup[1] = igroup[2] = 0;
-               for (n = 0; n < 3; n++) {
-                       if (spos >= sourcelen) {
-                               hiteof = TRUE;
-                               break;
-                       }
-                       c = source[spos++];
-                       igroup[n] = (byte) c;
-               }
-               if (n > 0) {
-                       ogroup[0] = dtable[igroup[0] >> 2];
-                       ogroup[1] =
-                           dtable[((igroup[0] & 3) << 4) |
-                                  (igroup[1] >> 4)];
-                       ogroup[2] =
-                           dtable[((igroup[1] & 0xF) << 2) |
-                                  (igroup[2] >> 6)];
-                       ogroup[3] = dtable[igroup[2] & 0x3F];
-
-                       /**
-                        * Replace characters in output stream with "=" pad
-                        * characters if fewer than three characters were
-                        * read from the end of the input stream. 
-                        */
-
-                       if (n < 3) {
-                               ogroup[3] = '=';
-                               if (n < 2) {
-                                       ogroup[2] = '=';
-                               }
-                       }
-                       for (i = 0; i < 4; i++) {
-                               if (dpos > *destlen)
-                               {
-                                       int newlen;
-                                       char *newbuf;
-                                       newlen = *destlen + *destlen / 2;
-                                       newbuf = (char*) malloc(newlen);
-                                       memcpy(newbuf, dest, *destlen);
-                                       *pdest = dest = newbuf;
-                                       *destlen = newlen;
-                               }
-                               dest[dpos++] = ogroup[i];
-                               dest[dpos] = 0;
-                       }
-                       thisline += 4;
-                       if ( (linebreaks) && (thisline > 70) ) {
-                               if (dpos + 3 > *destlen)
-                               {
-                                       int newlen;
-                                       char *newbuf;
-                                       newlen = *destlen + *destlen / 2;
-                                       newbuf = (char*) malloc(newlen);
-                                       memcpy(newbuf, dest, *destlen);
-                                       *pdest = dest = newbuf;
-                                       *destlen = newlen;
-                               }
-                               dest[dpos++] = '\r';
-                               dest[dpos++] = '\n';
-                               dest[dpos] = 0;
-                               thisline = 0;
-                       }
-               }
-       }
-       if ( (linebreaks) && (thisline > 70) ) {
-               if (dpos + 3 > *destlen)
-               {
-                       int newlen;
-                       char *newbuf;
-                       newlen = *destlen + 5;
-                       newbuf = (char*) malloc(newlen);
-                       memcpy(newbuf, dest, *destlen);
-                       *pdest = dest = newbuf;
-                       *destlen = newlen;
-               }
-               dest[dpos++] = '\r';
-               dest[dpos++] = '\n';
-               dest[dpos] = 0;
-               thisline = 0;
-       }
-       return dpos;
-}
-
-
-/**
- * \brief Convert base64-encoded to binary.  
- * It will stop after reading 'length' bytes.
- *
- * \param dest The destination buffer 
- * \param source The base64 data to be decoded.
- * \param length The number of bytes to decode.
- * \return The actual length of the decoded data.
- */
-int CtdlDecodeBase64(char *dest, const char *source, size_t length)
-{
-       int i, c;
-       int dpos = 0;
-       int spos = 0;
-
-       for (i = 0; i < 255; i++) {
-               dtable[i] = 0x80;
-       }
-       for (i = 'A'; i <= 'Z'; i++) {
-               dtable[i] = 0 + (i - 'A');
-       }
-       for (i = 'a'; i <= 'z'; i++) {
-               dtable[i] = 26 + (i - 'a');
-       }
-       for (i = '0'; i <= '9'; i++) {
-               dtable[i] = 52 + (i - '0');
-       }
-       dtable['+'] = 62;
-       dtable['/'] = 63;
-       dtable['='] = 0;
-
-       /**CONSTANTCONDITION*/ while (TRUE) {
-               byte a[4], b[4], o[3];
-
-               for (i = 0; i < 4; i++) {
-                       if (spos >= length) {
-                               return (dpos);
-                       }
-                       c = source[spos++];
-
-                       if (c == 0) {
-                               if (i > 0) {
-                                       return (dpos);
-                               }
-                               return (dpos);
-                       }
-                       if (dtable[c] & 0x80) {
-                               /** Ignoring errors: discard invalid character */
-                               i--;
-                               continue;
-                       }
-                       a[i] = (byte) c;
-                       b[i] = (byte) dtable[c];
-               }
-               o[0] = (b[0] << 2) | (b[1] >> 4);
-               o[1] = (b[1] << 4) | (b[2] >> 2);
-               o[2] = (b[2] << 6) | b[3];
-               i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3);
-               if (i >= 1)
-                       dest[dpos++] = o[0];
-               if (i >= 2)
-                       dest[dpos++] = o[1];
-               if (i >= 3)
-                       dest[dpos++] = o[2];
-               dest[dpos] = 0;
-               if (i < 3) {
-                       return (dpos);
-               }
-       }
-}
-
-
-
-/**
- * \brief Generate a new, globally unique UID parameter for a calendar etc. object
- *
- * \param buf String buffer into which our newly created UUID should be placed
- */
-void generate_uuid(char *buf) {
-       static int seq = 0;
-
-       sprintf(buf, "%s-%lx-%lx-%x",
-               serv_info.serv_nodename,
-               (long)time(NULL),
-               (long)getpid(),
-               (seq++)
-       );
-}
-
-
-/*
- * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
- * according to RFC2045 section 6.7
- */
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
-       unsigned int ch;
-       int decoded_length = 0;
-       int pos = 0;
-
-       while (pos < sourcelen)
-       {
-               if (!strncmp(&encoded[pos], "=\r\n", 3))
-               {
-                       pos += 3;
-               }
-               else if (!strncmp(&encoded[pos], "=\n", 2))
-               {
-                       pos += 2;
-               }
-               else if (encoded[pos] == '=')
-               {
-                       ch = 0;
-                       sscanf(&encoded[pos+1], "%02x", &ch);
-                       pos += 3;
-                       decoded[decoded_length++] = ch;
-               }
-               else
-               {
-                       decoded[decoded_length++] = encoded[pos];
-                       pos += 1;
-               }
-       }
-       decoded[decoded_length] = 0;
-       return(decoded_length);
-}
-
-
-/**
- * \brief Local replacement for controversial C library function that generates
- * names for temporary files.  Included to shut up compiler warnings.
- * \todo return a fd to the file instead of the name for security reasons
- * \param name the created filename
- * \param len the length of the filename
- */
-void CtdlMakeTempFileName(char *name, int len) {
-       int i = 0;
-
-       while (i++, i < 100) {
-               snprintf(name, len, "/tmp/ctdl.%04x.%04x",
-                       getpid(),
-                       rand()
-               );
-               if (!access(name, F_OK)) {
-                       return;
-               }
-       }
-}
-
-
-
-/*
- * \brief      case-insensitive substring search
- *
- *             This uses the Boyer-Moore search algorithm and is therefore quite fast.
- *             The code is roughly based on the strstr() replacement from 'tin' written
- *             by Urs Jannsen.
- *
- * \param      text    String to be searched
- * \param      pattern String to search for
- */
-char *bmstrcasestr(char *text, char *pattern) {
-
-       register unsigned char *p, *t;
-       register int i, j, *delta;
-       register size_t p1;
-       int deltaspace[256];
-       size_t textlen;
-       size_t patlen;
-
-       textlen = strlen (text);
-       patlen = strlen (pattern);
-
-       /* algorithm fails if pattern is empty */
-       if ((p1 = patlen) == 0)
-               return (text);
-
-       /* code below fails (whenever i is unsigned) if pattern too long */
-       if (p1 > textlen)
-               return (NULL);
-
-       /* set up deltas */
-       delta = deltaspace;
-       for (i = 0; i <= 255; i++)
-               delta[i] = p1;
-       for (p = (unsigned char *) pattern, i = p1; --i > 0;)
-               delta[tolower(*p++)] = i;
-
-       /*
-        * From now on, we want patlen - 1.
-        * In the loop below, p points to the end of the pattern,
-        * t points to the end of the text to be tested against the
-        * pattern, and i counts the amount of text remaining, not
-        * including the part to be tested.
-        */
-       p1--;
-       p = (unsigned char *) pattern + p1;
-       t = (unsigned char *) text + p1;
-       i = textlen - patlen;
-       while(1) {
-               if (tolower(p[0]) == tolower(t[0])) {
-                       if (strncasecmp ((const char *)(p - p1), (const char *)(t - p1), p1) == 0) {
-                               return ((char *)t - p1);
-                       }
-               }
-               j = delta[tolower(t[0])];
-               if (i < j)
-                       break;
-               i -= j;
-               t += j;
-       }
-       return (NULL);
-}
-
-
-
-
-
-/*@}*/
index 371a2d57050be7c79ae72fea2e2a2652fd10cfd7..e5b064934d1f9e4f3fbfccb65330a0fcea0ba6eb 100644 (file)
@@ -11,7 +11,6 @@
 #include "webcit.h"
 #include "groupdav.h"
 #include "webserver.h"
-#include "mime_parser.h"
 
 #include <stdio.h>
 #include <stdarg.h>
@@ -1833,5 +1832,18 @@ SKIP_ALL_THIS_CRAP:
        }
 }
 
+/**
+ * \brief Replacement for sleep() that uses select() in order to avoid SIGALRM
+ * \param seconds how many seconds should we sleep?
+ */
+void sleeeeeeeeeep(int seconds)
+{
+       struct timeval tv;
+
+       tv.tv_sec = seconds;
+       tv.tv_usec = 0;
+       select(0, NULL, NULL, NULL, &tv);
+}
+
 
 /*@}*/
index 35d9087cdd5ab0b5d2afa06bd6af4076440e861e..d918d71b3e7dda49b29192b11d23e712b293d312 100644 (file)
@@ -38,6 +38,8 @@
 #include <signal.h>
 #include <sys/utsname.h>
 
+#include <libcitadel.h>
+
 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff
 #endif
@@ -413,7 +415,9 @@ enum {
        MAX_SEMAPHORES
 };
 
+#ifndef num_parms
 #define num_parms(source)              num_tokens(source, '|') 
+#endif
 
 /* Per-session data */
 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
@@ -504,13 +508,10 @@ void escputs1(char *strbuf, int nbsp, int nolinebreaks);
 void msgesc(char *target, char *strbuf);
 void msgescputs(char *strbuf);
 void msgescputs1(char *strbuf);
-int extract_int(const char *source, int parmnum);
-long extract_long(const char *source, int parmnum);
 void stripout(char *str, char leftboundary, char rightboundary);
 void dump_vars(void);
 void embed_main_menu(void);
 void serv_read(char *buf, int bytes);
-int haschar(const char *, char);
 void readloop(char *oper);
 void read_message(long msgnum, int printable_view, char *section);
 void embed_message(char *msgnum_as_string);
@@ -582,7 +583,6 @@ void smart_goto(char *);
 void worker_entry(void);
 void session_loop(struct httprequest *);
 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
-void fmt_date(char *buf, time_t thetime, int brief);
 void fmt_time(char *buf, time_t thetime);
 void httpdate(char *buf, time_t thetime);
 time_t httpdate_to_timestamp(char *buf);
@@ -599,7 +599,6 @@ void do_template(void *templatename);
 int lingering_close(int fd);
 char *memreadline(char *start, char *buf, int maxlen);
 char *memreadlinelen(char *start, char *buf, int maxlen, int *retlen);
-int num_tokens (char *source, char tok);
 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
 void remove_token(char *source, int parmnum, char separator);
 char *load_mimepart(long msgnum, char *partnum);
@@ -648,9 +647,6 @@ void do_tasks_view(void);
 void free_calendar_buffer(void);
 void calendar_summary_view(void);
 int load_msg_ptrs(char *servcmd, int with_headers);
-size_t CtdlEncodeBase64(char **dest, const char *source, size_t sourcelen, size_t *destlen, int linebreaks);
-int CtdlDecodeBase64(char *dest, const char *source, size_t length);
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void free_attachments(struct wcsession *sess);
 void free_march_list(struct wcsession *wcf);
 void set_room_policy(void);
@@ -741,9 +737,9 @@ void begin_tab(int tabnum, int num_tabs);
 void end_tab(int tabnum, int num_tabs);
 void str_wiki_index(char *s);
 void display_wiki_page(void);
-char *bmstrcasestr(char *text, char *pattern);
 int get_time_format_cached (void);
 int xtoi(char *in, size_t len);
+void webcit_fmt_date(char *buf, time_t thetime, int brief);
 
 #ifdef HAVE_ICONV
 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode);