From 1e656d277fe91b7c4f5d73eab4a0dd0b7a173145 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 16 Nov 2007 05:52:26 +0000 Subject: [PATCH] HUGE PATCH. This moves all of mime_parser.c and all 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. --- citadel/Makefile.in | 40 +- citadel/citadel.c | 3 +- citadel/citadel_ipc.c | 2 +- citadel/citmail.c | 2 +- citadel/citserver.c | 2 +- citadel/client_chat.c | 2 +- citadel/client_passwords.c | 6 +- citadel/clientsocket.c | 2 +- citadel/commands.c | 2 +- citadel/configure.ac | 20 + citadel/control.c | 2 +- citadel/domain.c | 3 +- citadel/euidindex.c | 2 +- citadel/file_ops.c | 2 +- citadel/getmail.c | 2 +- citadel/housekeeping.c | 2 +- citadel/html.c | 2 +- citadel/internet_addressing.c | 2 +- citadel/ipc_c_tcp.c | 2 +- citadel/journaling.c | 3 +- citadel/locate_host.c | 2 +- citadel/messages.c | 2 +- citadel/mime_parser.c | 611 -------------- citadel/mime_parser.h | 57 -- .../autocompletion/serv_autocompletion.c | 2 +- citadel/modules/bio/serv_bio.c | 2 +- citadel/modules/calendar/serv_calendar.c | 3 +- citadel/modules/chat/serv_chat.c | 2 +- citadel/modules/expire/serv_expire.c | 2 +- citadel/modules/fulltext/ft_wordbreaker.c | 2 +- citadel/modules/fulltext/serv_fulltext.c | 2 +- citadel/modules/funambol/serv_funambol.c | 2 +- citadel/modules/imap/imap_acl.c | 2 +- citadel/modules/imap/imap_fetch.c | 3 +- citadel/modules/imap/imap_list.c | 2 +- citadel/modules/imap/imap_metadata.c | 2 +- citadel/modules/imap/imap_misc.c | 2 +- citadel/modules/imap/imap_search.c | 2 +- citadel/modules/imap/imap_store.c | 2 +- citadel/modules/imap/imap_tools.c | 2 +- citadel/modules/imap/serv_imap.c | 8 +- citadel/modules/inetcfg/serv_inetcfg.c | 2 +- citadel/modules/ldap/serv_ldap.c | 2 +- citadel/modules/listsub/serv_listsub.c | 4 +- .../modules/managesieve/serv_managesieve.c | 4 +- citadel/modules/mrtg/serv_mrtg.c | 2 +- citadel/modules/netfilter/serv_netfilter.c | 2 +- citadel/modules/network/serv_network.c | 2 +- citadel/modules/notes/serv_notes.c | 2 +- citadel/modules/pager/serv_pager.c | 2 +- citadel/modules/pas2/serv_pas2.c | 2 +- citadel/modules/pop3/serv_pop3.c | 2 +- citadel/modules/pop3client/serv_pop3client.c | 2 +- citadel/modules/rssclient/serv_rssclient.c | 2 +- citadel/modules/rwho/serv_rwho.c | 2 +- citadel/modules/sieve/serv_sieve.c | 2 +- citadel/modules/smtp/serv_smtp.c | 8 +- citadel/modules/spam/serv_spam.c | 2 +- citadel/modules/upgrade/serv_upgrade.c | 2 +- citadel/modules/vandelay/serv_vandelay.c | 2 +- citadel/modules/vcard/serv_vcard.c | 3 +- citadel/msgbase.c | 6 +- citadel/msgform.c | 3 +- citadel/policy.c | 2 +- citadel/room_ops.c | 2 +- citadel/rooms.c | 2 +- citadel/routines.c | 4 +- citadel/routines.h | 1 - citadel/routines2.c | 2 +- citadel/sendcommand.c | 2 +- citadel/serv_extensions.c | 2 +- citadel/server_main.c | 3 +- citadel/setup.c | 3 +- citadel/stress.c | 2 +- citadel/support.c | 15 +- citadel/support.h | 1 - citadel/sysdep.c | 2 +- citadel/tools.h | 42 - citadel/tuiconfig.c | 2 +- citadel/user_ops.c | 2 +- citadel/userlist.c | 2 +- citadel/vcard.c | 3 +- citadel/whobbs.c | 2 +- libcitadel/Makefile.in | 4 +- libcitadel/lib/libcitadel.h | 129 +++ {citadel => libcitadel/lib}/tools.c | 274 ++++--- webcit/Makefile.in | 12 +- webcit/calendar.c | 4 +- webcit/calendar_view.c | 14 +- webcit/configure.ac | 19 + webcit/fmt_date.c | 2 +- webcit/groupdav_get.c | 1 - webcit/messages.c | 14 +- webcit/mime_parser.c | 598 -------------- webcit/mime_parser.h | 57 -- webcit/sieve.c | 8 +- webcit/smtpqueue.c | 4 +- webcit/tools.c | 762 ------------------ webcit/webcit.c | 14 +- webcit/webcit.h | 14 +- 100 files changed, 493 insertions(+), 2410 deletions(-) delete mode 100644 citadel/mime_parser.c delete mode 100644 citadel/mime_parser.h delete mode 100644 citadel/tools.h rename {citadel => libcitadel/lib}/tools.c (80%) delete mode 100644 webcit/mime_parser.c delete mode 100644 webcit/mime_parser.h delete mode 100644 webcit/tools.c diff --git a/citadel/Makefile.in b/citadel/Makefile.in index e689e3ad9..79d40df39 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -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 diff --git a/citadel/citadel.c b/citadel/citadel.c index 8fe6b3a47..5f7420b07 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -32,7 +32,7 @@ #include #include #include - +#include #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" diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index b679de7e3..96d5f1e79 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -29,10 +29,10 @@ #ifdef THREADED_CLIENT #include #endif +#include #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; diff --git a/citadel/citmail.c b/citadel/citmail.c index 524140734..f47d8f2ab 100644 --- a/citadel/citmail.c +++ b/citadel/citmail.c @@ -22,8 +22,8 @@ #include #include #include +#include #include "citadel.h" -#include "tools.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif diff --git a/citadel/citserver.c b/citadel/citserver.c index 966bbbe8d..6a85744a5 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -40,6 +40,7 @@ #include #include #include +#include #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 diff --git a/citadel/client_chat.c b/citadel/client_chat.c index a1ad06ce1..d2dd9cf44 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -32,13 +32,13 @@ #include #endif #include +#include #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 diff --git a/citadel/client_passwords.c b/citadel/client_passwords.c index 2087f1b7a..f764626d1 100644 --- a/citadel/client_passwords.c +++ b/citadel/client_passwords.c @@ -16,9 +16,9 @@ #include #include #include +#include #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); diff --git a/citadel/clientsocket.c b/citadel/clientsocket.c index 5b5bb90b2..1d65e2ca8 100644 --- a/citadel/clientsocket.c +++ b/citadel/clientsocket.c @@ -23,6 +23,7 @@ #include #include #include +#include #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 diff --git a/citadel/commands.c b/citadel/commands.c index 9e2af9991..82db34c9e 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -43,6 +43,7 @@ #include #include #include +#include #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" diff --git a/citadel/configure.ac b/citadel/configure.ac index a5eb62499..74e707208 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -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" diff --git a/citadel/control.c b/citadel/control.c index fe625d051..e142504c6 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/domain.c b/citadel/domain.c index d7bd402de..da1c9bf95 100644 --- a/citadel/domain.c +++ b/citadel/domain.c @@ -19,12 +19,11 @@ #endif #include #endif - +#include #include "sysdep_decls.h" #include "citadel.h" #include "domain.h" #include "server.h" -#include "tools.h" #include "internet_addressing.h" diff --git a/citadel/euidindex.c b/citadel/euidindex.c index 5f25615f9..1e87e25d2 100644 --- a/citadel/euidindex.c +++ b/citadel/euidindex.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" /* diff --git a/citadel/file_ops.c b/citadel/file_ops.c index 30c65067b..b5db77743 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -28,6 +28,7 @@ #endif #include +#include #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 diff --git a/citadel/getmail.c b/citadel/getmail.c index 6ed3405be..664c81e08 100644 --- a/citadel/getmail.c +++ b/citadel/getmail.c @@ -29,8 +29,8 @@ #include #include #include +#include #include "citadel.h" -#include "tools.h" #include "citadel_ipc.h" #include "server.h" #include "config.h" diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 38995277c..3a02ef569 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -30,7 +30,7 @@ #ifdef HAVE_SYS_SELECT_H #include #endif -#include "tools.h" +#include #include "citadel.h" #include "server.h" #include "serv_extensions.h" diff --git a/citadel/html.c b/citadel/html.c index ad22efdf2..bc9006a3b 100644 --- a/citadel/html.c +++ b/citadel/html.c @@ -28,6 +28,7 @@ #include #include #include +#include #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" diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index ae8a6ceed..1b414be7d 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -30,13 +30,13 @@ #include #include #include +#include #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" diff --git a/citadel/ipc_c_tcp.c b/citadel/ipc_c_tcp.c index b0e8ea07e..bc68721c6 100644 --- a/citadel/ipc_c_tcp.c +++ b/citadel/ipc_c_tcp.c @@ -23,10 +23,10 @@ #include #include #include +#include #include "citadel.h" #include "citadel_ipc.h" #include "citadel_decls.h" -#include "tools.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif diff --git a/citadel/journaling.c b/citadel/journaling.c index f0464a999..9ea772860 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/locate_host.c b/citadel/locate_host.c index 744bc7e3c..4df8e19e7 100644 --- a/citadel/locate_host.c +++ b/citadel/locate_host.c @@ -17,12 +17,12 @@ #include #include #include +#include #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 diff --git a/citadel/messages.c b/citadel/messages.c index 0d822804c..ee067bd5a 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -35,13 +35,13 @@ #endif #include +#include #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 index a1a4965e9..000000000 --- a/citadel/mime_parser.c +++ /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 -#include -#include -#include -#include -#include -#include -#include -#include - -#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 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 index b82cd6884..000000000 --- a/citadel/mime_parser.h +++ /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 - ); diff --git a/citadel/modules/autocompletion/serv_autocompletion.c b/citadel/modules/autocompletion/serv_autocompletion.c index 5aaedd8cb..9ca03240c 100644 --- a/citadel/modules/autocompletion/serv_autocompletion.c +++ b/citadel/modules/autocompletion/serv_autocompletion.c @@ -29,12 +29,12 @@ #include #include #include +#include #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" diff --git a/citadel/modules/bio/serv_bio.c b/citadel/modules/bio/serv_bio.c index 9f5589b3b..8f875a435 100644 --- a/citadel/modules/bio/serv_bio.c +++ b/citadel/modules/bio/serv_bio.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 1f47e72d7..cd55a1339 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -19,6 +19,7 @@ #ifdef HAVE_STRINGS_H #include #endif +#include #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" diff --git a/citadel/modules/chat/serv_chat.c b/citadel/modules/chat/serv_chat.c index fff6640fe..b62f48524 100644 --- a/citadel/modules/chat/serv_chat.c +++ b/citadel/modules/chat/serv_chat.c @@ -29,13 +29,13 @@ #include #include #include +#include #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" diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index ee41a5f84..254ee5a10 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -49,6 +49,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/fulltext/ft_wordbreaker.c b/citadel/modules/fulltext/ft_wordbreaker.c index 12b0f667c..4a03e1b77 100644 --- a/citadel/modules/fulltext/ft_wordbreaker.c +++ b/citadel/modules/fulltext/ft_wordbreaker.c @@ -31,6 +31,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/fulltext/serv_fulltext.c b/citadel/modules/fulltext/serv_fulltext.c index 4e12ead4a..5ba8b5a37 100644 --- a/citadel/modules/fulltext/serv_fulltext.c +++ b/citadel/modules/fulltext/serv_fulltext.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/funambol/serv_funambol.c b/citadel/modules/funambol/serv_funambol.c index 33aecdf5b..23b17b470 100644 --- a/citadel/modules/funambol/serv_funambol.c +++ b/citadel/modules/funambol/serv_funambol.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_acl.c b/citadel/modules/imap/imap_acl.c index 369afce88..55a010982 100644 --- a/citadel/modules/imap/imap_acl.c +++ b/citadel/modules/imap/imap_acl.c @@ -31,6 +31,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_fetch.c b/citadel/modules/imap/imap_fetch.c index 6a8104b96..3cd92cb32 100644 --- a/citadel/modules/imap/imap_fetch.c +++ b/citadel/modules/imap/imap_fetch.c @@ -32,6 +32,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_list.c b/citadel/modules/imap/imap_list.c index 87ff58549..023a0dca9 100644 --- a/citadel/modules/imap/imap_list.c +++ b/citadel/modules/imap/imap_list.c @@ -33,6 +33,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_metadata.c b/citadel/modules/imap/imap_metadata.c index 4dde983f9..fef885071 100644 --- a/citadel/modules/imap/imap_metadata.c +++ b/citadel/modules/imap/imap_metadata.c @@ -33,6 +33,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_misc.c b/citadel/modules/imap/imap_misc.c index 8525216b8..3b7d95834 100644 --- a/citadel/modules/imap/imap_misc.c +++ b/citadel/modules/imap/imap_misc.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_search.c b/citadel/modules/imap/imap_search.c index 7cbf9e320..7efc71ed6 100644 --- a/citadel/modules/imap/imap_search.c +++ b/citadel/modules/imap/imap_search.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_store.c b/citadel/modules/imap/imap_store.c index b564380aa..80167ab49 100644 --- a/citadel/modules/imap/imap_store.c +++ b/citadel/modules/imap/imap_store.c @@ -31,6 +31,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/imap/imap_tools.c b/citadel/modules/imap/imap_tools.c index 080f9db7c..0e62a407c 100644 --- a/citadel/modules/imap/imap_tools.c +++ b/citadel/modules/imap/imap_tools.c @@ -12,9 +12,9 @@ #include #include #include +#include #include "citadel.h" #include "sysdep_decls.h" -#include "tools.h" #include "room_ops.h" #include "internet_addressing.h" #include "imap_tools.h" diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index 098ce942f..c86518fb8 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -35,6 +35,7 @@ #include #include #include +#include #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; diff --git a/citadel/modules/inetcfg/serv_inetcfg.c b/citadel/modules/inetcfg/serv_inetcfg.c index 90f4431fd..8fb48f19a 100644 --- a/citadel/modules/inetcfg/serv_inetcfg.c +++ b/citadel/modules/inetcfg/serv_inetcfg.c @@ -32,6 +32,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/ldap/serv_ldap.c b/citadel/modules/ldap/serv_ldap.c index f684344c4..c2b786529 100644 --- a/citadel/modules/ldap/serv_ldap.c +++ b/citadel/modules/ldap/serv_ldap.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/listsub/serv_listsub.c b/citadel/modules/listsub/serv_listsub.c index 8b1db7788..0eb2300f2 100644 --- a/citadel/modules/listsub/serv_listsub.c +++ b/citadel/modules/listsub/serv_listsub.c @@ -33,6 +33,7 @@ #include #include #include +#include #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); } diff --git a/citadel/modules/managesieve/serv_managesieve.c b/citadel/modules/managesieve/serv_managesieve.c index dacc789f9..065702fa1 100644 --- a/citadel/modules/managesieve/serv_managesieve.c +++ b/citadel/modules/managesieve/serv_managesieve.c @@ -38,6 +38,7 @@ #include #include #include +#include #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; diff --git a/citadel/modules/mrtg/serv_mrtg.c b/citadel/modules/mrtg/serv_mrtg.c index 12e09f0f0..dab0ab7b8 100644 --- a/citadel/modules/mrtg/serv_mrtg.c +++ b/citadel/modules/mrtg/serv_mrtg.c @@ -33,6 +33,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/netfilter/serv_netfilter.c b/citadel/modules/netfilter/serv_netfilter.c index edaf01d4f..09fe8c0f9 100644 --- a/citadel/modules/netfilter/serv_netfilter.c +++ b/citadel/modules/netfilter/serv_netfilter.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index d84fe2f70..06363b92d 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -48,6 +48,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/notes/serv_notes.c b/citadel/modules/notes/serv_notes.c index 18494fde6..0dedda9e3 100644 --- a/citadel/modules/notes/serv_notes.c +++ b/citadel/modules/notes/serv_notes.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/pager/serv_pager.c b/citadel/modules/pager/serv_pager.c index 5e6b0d25d..bdafbc85f 100644 --- a/citadel/modules/pager/serv_pager.c +++ b/citadel/modules/pager/serv_pager.c @@ -33,6 +33,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/pas2/serv_pas2.c b/citadel/modules/pas2/serv_pas2.c index fd7fbf246..7df51d60d 100644 --- a/citadel/modules/pas2/serv_pas2.c +++ b/citadel/modules/pas2/serv_pas2.c @@ -21,13 +21,13 @@ #include #include #include +#include #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" diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index e8f975c4d..6aaa628a4 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -41,6 +41,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index 89546015c..5046a985d 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -25,12 +25,12 @@ #include #include #include +#include #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" diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index a7093efa3..868516907 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -25,12 +25,12 @@ #include #include #include +#include #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" diff --git a/citadel/modules/rwho/serv_rwho.c b/citadel/modules/rwho/serv_rwho.c index d8a1285ba..1c9f7a7a4 100644 --- a/citadel/modules/rwho/serv_rwho.c +++ b/citadel/modules/rwho/serv_rwho.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/sieve/serv_sieve.c b/citadel/modules/sieve/serv_sieve.c index aeb977bbb..e92ebdc8f 100644 --- a/citadel/modules/sieve/serv_sieve.c +++ b/citadel/modules/sieve/serv_sieve.c @@ -31,6 +31,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index ac60e79d7..b444ab4fe 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -55,6 +55,7 @@ #include #include #include +#include #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)); diff --git a/citadel/modules/spam/serv_spam.c b/citadel/modules/spam/serv_spam.c index cdf81557a..415f03cae 100644 --- a/citadel/modules/spam/serv_spam.c +++ b/citadel/modules/spam/serv_spam.c @@ -34,6 +34,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/upgrade/serv_upgrade.c b/citadel/modules/upgrade/serv_upgrade.c index 2956e79a0..8676ab9ae 100644 --- a/citadel/modules/upgrade/serv_upgrade.c +++ b/citadel/modules/upgrade/serv_upgrade.c @@ -29,6 +29,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/vandelay/serv_vandelay.c b/citadel/modules/vandelay/serv_vandelay.c index c79e1eeee..576089f3c 100644 --- a/citadel/modules/vandelay/serv_vandelay.c +++ b/citadel/modules/vandelay/serv_vandelay.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index 8925228e6..0e3d264f8 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -47,6 +47,7 @@ #include #include #include +#include #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" diff --git a/citadel/msgbase.c b/citadel/msgbase.c index ac2e54d2d..48f2eb727 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -31,6 +31,7 @@ #include #include #include +#include #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 { diff --git a/citadel/msgform.c b/citadel/msgform.c index 3c0a6d0fa..c17a25779 100644 --- a/citadel/msgform.c +++ b/citadel/msgform.c @@ -31,8 +31,7 @@ #endif #include -#include "tools.h" - +#include int qwk = 0; diff --git a/citadel/policy.c b/citadel/policy.c index 804416e71..226e985dc 100644 --- a/citadel/policy.c +++ b/citadel/policy.c @@ -23,6 +23,7 @@ #endif #include +#include #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" /* diff --git a/citadel/room_ops.c b/citadel/room_ops.c index af6cb2149..4a5ed25da 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -28,6 +28,7 @@ #include #include #include "citadel.h" +#include #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]; diff --git a/citadel/rooms.c b/citadel/rooms.c index 649b21a99..87d46f8bb 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -19,12 +19,12 @@ #include #include #include +#include #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" diff --git a/citadel/routines.c b/citadel/routines.c index 30db9a5ce..08f89540a 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -29,6 +29,7 @@ # include # endif #endif + #ifdef HAVE_LIMITS_H #include #endif @@ -38,6 +39,8 @@ #ifdef HAVE_UTMPX_H #include #endif + +#include #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" diff --git a/citadel/routines.h b/citadel/routines.h index 9d8e50976..6bb516a2c 100644 --- a/citadel/routines.h +++ b/citadel/routines.h @@ -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); diff --git a/citadel/routines2.c b/citadel/routines2.c index 9896697a6..b414b4731 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -30,6 +30,7 @@ #include #include #include +#include #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" diff --git a/citadel/sendcommand.c b/citadel/sendcommand.c index 4254d7213..225b23a4c 100644 --- a/citadel/sendcommand.c +++ b/citadel/sendcommand.c @@ -29,8 +29,8 @@ #include #include #include +#include #include "citadel.h" -#include "tools.h" #include "citadel_ipc.h" #include "server.h" #include "config.h" diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index c090e3c78..e248d50a1 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -15,12 +15,12 @@ #include #include #include +#include #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 */ diff --git a/citadel/server_main.c b/citadel/server_main.c index f8b95019d..7edc6ad16 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -44,6 +44,7 @@ #ifdef HAVE_SYS_PRCTL_H #include #endif +#include #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"); diff --git a/citadel/setup.c b/citadel/setup.c index 845a3408d..f0ad438a3 100644 --- a/citadel/setup.c +++ b/citadel/setup.c @@ -21,12 +21,11 @@ #include #include #include - +#include #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 */ diff --git a/citadel/stress.c b/citadel/stress.c index 038c6feb5..dfb98052c 100644 --- a/citadel/stress.c +++ b/citadel/stress.c @@ -67,6 +67,7 @@ char* const message = #include #include #include +#include #include "sysdep.h" #if TIME_WITH_SYS_TIME # include @@ -78,7 +79,6 @@ char* const message = # include # endif #endif -#include "tools.h" #include "citadel_ipc.h" #ifndef HAVE_PTHREAD_H diff --git a/citadel/support.c b/citadel/support.c index 8a56d8544..b650c7ee8 100644 --- a/citadel/support.c +++ b/citadel/support.c @@ -13,10 +13,10 @@ #include #include #include +#include #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); - } /* diff --git a/citadel/support.h b/citadel/support.h index a63f8723c..0b4aa3dce 100644 --- a/citadel/support.h +++ b/citadel/support.h @@ -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); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 182c0df7d..14676acfb 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -52,6 +52,7 @@ #ifdef HAVE_PTHREAD_H #include #endif +#include #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.h b/citadel/tools.h deleted file mode 100644 index 7c9f5c017..000000000 --- a/citadel/tools.h +++ /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); diff --git a/citadel/tuiconfig.c b/citadel/tuiconfig.c index ed1fdfb20..9cacb68b0 100644 --- a/citadel/tuiconfig.c +++ b/citadel/tuiconfig.c @@ -29,6 +29,7 @@ #include #include #include +#include #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 diff --git a/citadel/user_ops.c b/citadel/user_ops.c index f457c6089..f9ac7c843 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -33,6 +33,7 @@ #include #include +#include #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" diff --git a/citadel/userlist.c b/citadel/userlist.c index c8b070318..0e7e3fbfd 100644 --- a/citadel/userlist.c +++ b/citadel/userlist.c @@ -21,10 +21,10 @@ # endif #endif +#include #include "citadel.h" #include #include "citadel_ipc.h" -#include "tools.h" #include "citadel_dirs.h" void logoff(int code) diff --git a/citadel/vcard.c b/citadel/vcard.c index a44117747..75a2c9f7c 100644 --- a/citadel/vcard.c +++ b/citadel/vcard.c @@ -31,12 +31,11 @@ #include #include #include - +#include #include "citadel.h" #include "server.h" #include "support.h" #include "vcard.h" -#include "tools.h" diff --git a/citadel/whobbs.c b/citadel/whobbs.c index be5dbe05e..9c0db8216 100644 --- a/citadel/whobbs.c +++ b/citadel/whobbs.c @@ -11,10 +11,10 @@ #include #include #include +#include #include "citadel.h" #include "citadel_ipc.h" #include "citadel_dirs.h" -#include "tools.h" void logoff(int code) { diff --git a/libcitadel/Makefile.in b/libcitadel/Makefile.in index 3c6d57b4a..a95cf2128 100755 --- a/libcitadel/Makefile.in +++ b/libcitadel/Makefile.in @@ -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 diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 6eb9a8949..99a3a27fb 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -10,6 +10,10 @@ #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/citadel/tools.c b/libcitadel/lib/tools.c similarity index 80% rename from citadel/tools.c rename to libcitadel/lib/tools.c index b86464259..e3882c7bb 100644 --- a/citadel/tools.c +++ b/libcitadel/lib/tools.c @@ -1,18 +1,18 @@ /* - * $Id$ - * - * Utility functions that are used by both the client and server. * */ -#include "sysdep.h" + #include #include #include -#include +#include +#include #include #include -#include +#include +#include +#include #if TIME_WITH_SYS_TIME # include @@ -25,9 +25,8 @@ # endif #endif -#include "tools.h" -#include "citadel.h" -#include "sysdep_decls.h" +#include "libcitadel.h" + #define TRUE 1 #define FALSE 0 @@ -62,25 +61,6 @@ char *safestrncpy(char *dest, const char *src, size_t n) -#ifndef HAVE_STRNCASECMP -int strncasecmp(char *lstr, char *rstr, int len) -{ - int pos = 0; - char lc,rc; - while (posrc) return(1); - pos=pos+1; - } - return(0); -} -#endif - - - /* * num_tokens() - discover number of parameters/tokens in a string */ @@ -316,57 +296,90 @@ void CtdlInitBase64Table(void) 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. + * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by John Walker. */ -void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen) +size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks) { - int i, hiteof = FALSE; - int spos = 0; - int dpos = 0; + int i, hiteof = FALSE; + int spos = 0; + int dpos = 0; + int thisline = 0; - while (!hiteof) { - byte igroup[3], ogroup[4]; - int c, n; + /** Fill dtable with character encodings. */ - 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 < 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; } - } - for (i = 0; i < 4; i++) { - dest[dpos++] = ogroup[i]; + 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. @@ -416,42 +429,6 @@ int CtdlDecodeBase64(char *dest, const char *source, size_t length) } } -/* - * 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. @@ -474,7 +451,7 @@ char *rfc2047encode(char *line, long length) result = (char*) malloc(strlen(UTF8_HEADER) + 4 + length * 2); strncpy (result, UTF8_HEADER, strlen (UTF8_HEADER)); - CtdlEncodeBase64(result + strlen(UTF8_HEADER), line, length); + CtdlEncodeBase64(result + strlen(UTF8_HEADER), line, length, 0); end = strlen (result); result[end]='?'; result[end+1]='='; @@ -766,9 +743,9 @@ char *strcpy(char *dest, const char *src) { void generate_uuid(char *buf) { static int seq = 0; - sprintf(buf, "%lx-"F_XPID_T"-%x", + sprintf(buf, "%lx-%lx-%x", time(NULL), - getpid(), + (long)getpid(), (seq++) ); } @@ -843,8 +820,8 @@ void CtdlMakeTempFileName(char *name, int len) { int i = 0; while (i++, i < 100) { - snprintf(name, len, "/tmp/ctdl."F_XPID_T".%04x", - getpid(), + snprintf(name, len, "/tmp/ctdl.%4lx.%04x", + (long)getpid(), rand() ); if (!access(name, F_OK)) { @@ -852,3 +829,84 @@ void CtdlMakeTempFileName(char *name, int len) { } } } + + + +/* + * 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= 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'; + } +} + diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 44871bf2f..2c024f9d6 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -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 \ diff --git a/webcit/calendar.c b/webcit/calendar.c index 6ea3cd7ff..3ced19b1d 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -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("
"); wprintf(_("Starting date/time:")); wprintf("
%s
", 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("
"); wprintf(_("Ending date/time:")); wprintf("
%s
", buf); diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index addfe9cac..b5525b1be 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -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("%s %s
", _("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("%s %s
", _("Ending date/time:"), buf); } @@ -932,9 +932,9 @@ void calendar_day_view_display_events(time_t thetime, escputs((char *)icalproperty_get_comment(q)); wprintf("
"); } - fmt_date(buf, event_tt, 1); + webcit_fmt_date(buf, event_tt, 1); wprintf("%s %s
", _("Starting date/time:"), buf); - fmt_date(buf, event_tte, 1); + webcit_fmt_date(buf, event_tte, 1); wprintf("%s %s
", _("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("
"); } - fmt_date(buf, event_tt, 1); + webcit_fmt_date(buf, event_tt, 1); wprintf("%s %s
", _("Starting date/time:"), buf); - fmt_date(buf, event_tte, 1); + webcit_fmt_date(buf, event_tte, 1); wprintf("%s %s
", _("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("\n"); due = get_task_due_date(WC->disp_cal[i].cal); - fmt_date(buf, due, 0); + webcit_fmt_date(buf, due, 0); wprintf(""); wprintf("%s ", now); wprintf(""); @@ -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(""); wprintf("", 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(""); @@ -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(""); 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 index c41fb26ad..000000000 --- a/webcit/mime_parser.c +++ /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 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 index b82cd6884..000000000 --- a/webcit/mime_parser.h +++ /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 - ); diff --git a/webcit/sieve.c b/webcit/sieve.c index 3dde76a60..831151045 100644 --- a/webcit/sieve.c +++ b/webcit/sieve.c @@ -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); } diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 664e5eff6..9b9e5726f 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -144,7 +144,7 @@ void display_queue_msg(long msgnum) wprintf(""); 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(""); 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 index 591af0d97..000000000 --- a/webcit/tools.c +++ /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 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= 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); -} - - - - - -/*@}*/ diff --git a/webcit/webcit.c b/webcit/webcit.c index 371a2d570..e5b064934 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -11,7 +11,6 @@ #include "webcit.h" #include "groupdav.h" #include "webserver.h" -#include "mime_parser.h" #include #include @@ -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); +} + /*@}*/ diff --git a/webcit/webcit.h b/webcit/webcit.h index 35d9087cd..d918d71b3 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -38,6 +38,8 @@ #include #include +#include + #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); -- 2.30.2