From 76f23da782e9e80dad0a8ae1336230da5a6fa124 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 13 Jul 2008 22:33:01 +0000 Subject: [PATCH] * copy daves great handler script and modify it to fit the simpler needs of webcit. * add init functions to all handler containing .c files; Register these calls in the init function * replace strcmp URL to handler dispatcher by hashlist * wrap calls that had more than one call in simple functions --- webcit/Makefile.in | 3 +- webcit/addressbook_popup.c | 11 + webcit/auth.c | 19 +- webcit/autocompletion.c | 15 ++ webcit/calendar.c | 15 ++ webcit/configure.ac | 1 + webcit/downloads.c | 14 +- webcit/floors.c | 10 + webcit/graphics.c | 63 +++++ webcit/iconbar.c | 10 + webcit/inetconf.c | 8 + webcit/mainmenu.c | 14 + webcit/messages.c | 40 ++- webcit/mk_module_init.sh | 123 +++++++++ webcit/netconf.c | 11 + webcit/notes.c | 8 + webcit/openid.c | 9 + webcit/paging.c | 11 + webcit/preferences.c | 7 + webcit/pushemail.c | 8 + webcit/roomops.c | 51 +++- webcit/setup_wizard.c | 7 +- webcit/sieve.c | 13 + webcit/siteconfig.c | 8 +- webcit/smtpqueue.c | 9 +- webcit/summary.c | 11 + webcit/sysmsgs.c | 19 ++ webcit/useredit.c | 12 + webcit/userlist.c | 8 +- webcit/vcard_edit.c | 8 + webcit/webcit.c | 520 ++++++++----------------------------- webcit/webcit.h | 19 +- webcit/webserver.c | 9 +- webcit/who.c | 16 ++ webcit/wiki.c | 8 + 35 files changed, 672 insertions(+), 446 deletions(-) create mode 100755 webcit/mk_module_init.sh diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 28bbde07f..32401434b 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -52,6 +52,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ groupdav_options.o autocompletion.o gettext.o tabs.o sieve.o \ groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \ downloads.o addressbook_popup.o pushemail.o sysdep.o openid.o \ + modules_init.o \ $(LIBOBJS) $(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 \ @@ -62,7 +63,7 @@ webcit: webserver.o context_loop.o ical_dezonify.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 \ groupdav_options.o autocompletion.o tabs.o smtpqueue.o sieve.o \ - groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o \ + groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o modules_init.o \ gettext.o downloads.o addressbook_popup.o pushemail.o sysdep.o \ $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webcit diff --git a/webcit/addressbook_popup.c b/webcit/addressbook_popup.c index fe4ca703b..230e09dc3 100644 --- a/webcit/addressbook_popup.c +++ b/webcit/addressbook_popup.c @@ -182,3 +182,14 @@ void display_address_book_inner_div() { end_ajax_response(); } + + + + +void +InitModule_ADDRBOOK_POPUP +(void) +{ + WebcitAddUrlHandler(HKEY("display_address_book_middle_div"), display_address_book_middle_div, 0); + WebcitAddUrlHandler(HKEY("display_address_book_inner_div"), display_address_book_inner_div, 0); +} diff --git a/webcit/auth.c b/webcit/auth.c index d85ad0cb2..c431c0055 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -875,10 +875,25 @@ void changepw(void) } } +void _display_openid_login(void) {display_openid_login(NULL);} +void _display_reg(void) {display_reg(0);} -void InitModule_AUTH(void) +void +InitModule_AUTH +(void) { - WebcitAddUrlHandler(HKEY("do_welcome"), do_welcome, 0); + WebcitAddUrlHandler(HKEY("do_welcome"), do_welcome, ANONYMOUS); + WebcitAddUrlHandler(HKEY("login"), do_login, ANONYMOUS); + WebcitAddUrlHandler(HKEY("display_openid_login"), _display_openid_login, ANONYMOUS); + WebcitAddUrlHandler(HKEY("openid_login"), do_openid_login, ANONYMOUS); + WebcitAddUrlHandler(HKEY("finalize_openid_login"), finalize_openid_login, ANONYMOUS); + WebcitAddUrlHandler(HKEY("openid_manual_create"), openid_manual_create, ANONYMOUS); + WebcitAddUrlHandler(HKEY("do_logout"), do_logout, 0); + WebcitAddUrlHandler(HKEY("validate"), validate, 0); + WebcitAddUrlHandler(HKEY("display_reg"), _display_reg, 0); + WebcitAddUrlHandler(HKEY("display_changepw"), display_changepw, 0); + WebcitAddUrlHandler(HKEY("changepw"), changepw, 0); + WebcitAddUrlHandler(HKEY("termquit"), do_logout, 0); return ; } diff --git a/webcit/autocompletion.c b/webcit/autocompletion.c index 327b98c6d..69564e812 100644 --- a/webcit/autocompletion.c +++ b/webcit/autocompletion.c @@ -43,3 +43,18 @@ void recp_autocomplete(char *partial) { wprintf("\r\n\r\n"); wDumpContent(0); } + + +void _recp_autocomplete(void) {recp_autocomplete(bstr("recp"));} +void _cc_autocomplete(void) {recp_autocomplete(bstr("cc"));} +void _bcc_autocomplete(void) {recp_autocomplete(bstr("bcc"));} + + +void +InitModule_AUTO_COMPLETE +(void) +{ + WebcitAddUrlHandler(HKEY("recp_autocomplete"), _recp_autocomplete, 0); + WebcitAddUrlHandler(HKEY("cc_autocomplete"), _cc_autocomplete, 0); + WebcitAddUrlHandler(HKEY("bcc_autocomplete"), _bcc_autocomplete, 0); +} diff --git a/webcit/calendar.c b/webcit/calendar.c index 41395ef11..e91012eef 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -1057,3 +1057,18 @@ void do_freebusy(char *req) { free(fb); } + + + + +void +InitModule_CALENDAR +(void) +{ + WebcitAddUrlHandler(HKEY("display_edit_task"), display_edit_task, 0); + WebcitAddUrlHandler(HKEY("save_task"), save_task, 0); + WebcitAddUrlHandler(HKEY("display_edit_event"), display_edit_event, 0); + WebcitAddUrlHandler(HKEY("save_event"), save_event, 0); + WebcitAddUrlHandler(HKEY("respond_to_request"), respond_to_request, 0); + WebcitAddUrlHandler(HKEY("handle_rsvp"), handle_rsvp, 0); +} diff --git a/webcit/configure.ac b/webcit/configure.ac index 6601635f4..bb7663429 100644 --- a/webcit/configure.ac +++ b/webcit/configure.ac @@ -453,6 +453,7 @@ AC_ARG_WITH(editordir, ) AC_DEFINE_UNQUOTED(EDITORDIR, "$editordir", [where to find our mail editor]) +./mk_module_init.sh AC_CONFIG_HEADER(sysdep.h) AC_OUTPUT(Makefile po/Makefile ) diff --git a/webcit/downloads.c b/webcit/downloads.c index 86c5108ab..f2653746a 100644 --- a/webcit/downloads.c +++ b/webcit/downloads.c @@ -381,7 +381,7 @@ void display_mime_icon(void) } -void download_file(char *filename) +void download_file(void) { char buf[256]; off_t bytes; @@ -391,7 +391,7 @@ void download_file(char *filename) /* Setting to nonzero forces a MIME type of application/octet-stream */ int force_download = 1; - safestrncpy(buf, filename, sizeof buf); + safestrncpy(buf, ChrPtr(WC->UrlFragment1), sizeof buf); unescape_input(buf); serv_printf("OPEN %s", buf); serv_getln(buf, sizeof buf); @@ -462,3 +462,13 @@ void upload_file(void) strcpy(WCC->ImportantMessage, &buf[4]); display_room_directory(); } + +void +InitModule_DOWNLOAD +(void) +{ + WebcitAddUrlHandler(HKEY("display_room_directory"), display_room_directory, 0); + WebcitAddUrlHandler(HKEY("display_pictureview"), display_pictureview, 0); + WebcitAddUrlHandler(HKEY("download_file"), download_file, NEED_URL); + WebcitAddUrlHandler(HKEY("upload_file"), upload_file, 0); +} diff --git a/webcit/floors.c b/webcit/floors.c index e06dfaa8d..b5ee4028e 100644 --- a/webcit/floors.c +++ b/webcit/floors.c @@ -196,5 +196,15 @@ void rename_floor(void) { display_floorconfig(message); } +void _display_floorconfig(void) {display_floorconfig(NULL);} +void +InitModule_FLOORS +(void) +{ + WebcitAddUrlHandler(HKEY("delete_floor"), delete_floor, 0); + WebcitAddUrlHandler(HKEY("rename_floor"), rename_floor, 0); + WebcitAddUrlHandler(HKEY("create_floor"), create_floor, 0); + WebcitAddUrlHandler(HKEY("display_floorconfig"), _display_floorconfig, 0); +} /*@}*/ diff --git a/webcit/graphics.c b/webcit/graphics.c index 6949e09fd..9cc0d4145 100644 --- a/webcit/graphics.c +++ b/webcit/graphics.c @@ -114,3 +114,66 @@ void do_graphics_upload(char *filename) return; } } + + +void edithellopic(void) { do_graphics_upload("hello"); } +void editpic(void) { do_graphics_upload("_userpic_"); } +void editgoodbuyepic(void) { do_graphics_upload("UIMG 1|%s|goodbuye"); } + +/* The users photo display / upload facility */ +void display_editpic(void) { + display_graphics_upload(_("your photo"), + "_userpic_", + "editpic"); +} +/* room picture dispay / upload facility */ +void display_editroompic(void) { + display_graphics_upload(_("the icon for this room"), + "_roompic_", + "editroompic"); +} + +/* the greetingpage hello pic */ +void display_edithello(void) { + display_graphics_upload(_("the Greetingpicture for the login prompt"), + "hello", + "edithellopic"); +} + +/* the logoff banner */ +void display_editgoodbyepic(void) { + display_graphics_upload(_("the Logoff banner picture"), + "UIMG 0|%s|goodbuye", + "editgoodbuyepic"); +} + +void display_editfloorpic(void) { + char buf[SIZ]; + snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s", + bstr("which_floor")); + display_graphics_upload(_("the icon for this floor"), + buf, + "editfloorpic"); +} + +void editfloorpic(void){ + char buf[SIZ]; + snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s", + bstr("which_floor")); + do_graphics_upload(buf); +} + +void +InitModule_GRAPHICS +(void) +{ + WebcitAddUrlHandler(HKEY("display_editpic"), display_editpic, 0); + WebcitAddUrlHandler(HKEY("editpic"), editpic, 0); + WebcitAddUrlHandler(HKEY("display_editroompic"), display_editroompic, 0); + WebcitAddUrlHandler(HKEY("display_edithello"), display_edithello, 0); + WebcitAddUrlHandler(HKEY("edithellopic"), edithellopic, 0); + WebcitAddUrlHandler(HKEY("display_editgoodbyepic"), display_editgoodbyepic, 0); + WebcitAddUrlHandler(HKEY("editgoodbuyepic"), editgoodbuyepic, 0); + WebcitAddUrlHandler(HKEY("display_editfloorpic"), display_editfloorpic, 0); + WebcitAddUrlHandler(HKEY("editfloorpic"), editfloorpic, 0); +} diff --git a/webcit/iconbar.c b/webcit/iconbar.c index 981e2c928..4b76d6bbf 100644 --- a/webcit/iconbar.c +++ b/webcit/iconbar.c @@ -795,5 +795,15 @@ void commit_iconbar(void) { } +void +InitModule_ICONBAR +(void) +{ + WebcitAddUrlHandler(HKEY("iconbar_ajax_menu"), do_iconbar, AJAX); + WebcitAddUrlHandler(HKEY("iconbar_ajax_rooms"), do_iconbar_roomlist, AJAX); + WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0); + WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0); +} + /*@}*/ diff --git a/webcit/inetconf.c b/webcit/inetconf.c index b483dd1aa..ad27d97b5 100644 --- a/webcit/inetconf.c +++ b/webcit/inetconf.c @@ -207,3 +207,11 @@ void save_inetconf(void) { free(etype); free(newconfig); } + +void +InitModule_INETCONF +(void) +{ + WebcitAddUrlHandler(HKEY("display_inetconf"), display_inetconf, 0); + WebcitAddUrlHandler(HKEY("save_inetconf"), save_inetconf, AJAX); +} diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 14b3cedc3..1ec145374 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -415,3 +415,17 @@ void display_shutdown(void) } } } + +void _display_menubar(void) { display_menubar(0); } + +void +InitModule_MAINMENU +(void) +{ + WebcitAddUrlHandler(HKEY("display_aide_menu"), display_aide_menu, 0); + WebcitAddUrlHandler(HKEY("server_shutdown"), display_shutdown, 0); + WebcitAddUrlHandler(HKEY("display_main_menu"), display_main_menu, 0); + WebcitAddUrlHandler(HKEY("display_generic"), display_generic, 0); + WebcitAddUrlHandler(HKEY("do_generic"), do_generic, 0); + WebcitAddUrlHandler(HKEY("display_menubar"), _display_menubar, 0); +} diff --git a/webcit/messages.c b/webcit/messages.c index 4d2724c11..7676c9dd8 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1390,13 +1390,11 @@ ENDBODY: /* If there are attached submessages, display them now... */ * * msgnum_as_string == Message number, as a string instead of as a long int */ -void embed_message(char *msgnum_as_string) { +void embed_message(void) { long msgnum = 0L; - msgnum = atol(msgnum_as_string); - begin_ajax_response(); + msgnum = StrTol(WC->UrlFragment1); read_message(msgnum, 0, ""); - end_ajax_response(); } @@ -1405,10 +1403,10 @@ void embed_message(char *msgnum_as_string) { * * msgnum_as_string == Message number, as a string instead of as a long int */ -void print_message(char *msgnum_as_string) { +void print_message(void) { long msgnum = 0L; - msgnum = atol(msgnum_as_string); + msgnum = StrTol(WC->UrlFragment1); output_headers(0, 0, 0, 0, 0, 0); wprintf("Content-type: text/html\r\n" @@ -1436,11 +1434,11 @@ void print_message(char *msgnum_as_string) { * * \param msgnum_as_string Message number, as a string instead of as a long int */ -void display_headers(char *msgnum_as_string) { +void display_headers(void) { long msgnum = 0L; char buf[1024]; - msgnum = atol(msgnum_as_string); + msgnum = StrTol(WC->UrlFragment1); output_headers(0, 0, 0, 0, 0, 0); wprintf("Content-type: text/plain\r\n" @@ -3800,3 +3798,29 @@ void confirm_move_msg(void) wprintf("\n"); wDumpContent(1); } + +void readnew(void) { readloop("readnew");} +void readold(void) { readloop("readold");} +void readfwd(void) { readloop("readfwd");} +void headers(void) { readloop("headers");} +void do_search(void) { readloop("do_search");} + +void +InitModule_MSG +(void) +{ + WebcitAddUrlHandler(HKEY("readnew"), readnew, 0); + WebcitAddUrlHandler(HKEY("readold"), readold, 0); + WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0); + WebcitAddUrlHandler(HKEY("headers"), headers, 0); + WebcitAddUrlHandler(HKEY("do_search"), do_search, 0); + WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0); + WebcitAddUrlHandler(HKEY("post"), post_message, 0); + WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0); + WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0); + WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0); + WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX); + WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL); + WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL); + return ; +} diff --git a/webcit/mk_module_init.sh b/webcit/mk_module_init.sh new file mode 100755 index 000000000..bf38637b3 --- /dev/null +++ b/webcit/mk_module_init.sh @@ -0,0 +1,123 @@ +#!/bin/sh +# +# Script to generate $C_FILE +# + +ECHO=/usr/bin/printf + +#MINUS_e=X`$ECHO -n -e` +#if [ $MINUS_e != "X" ] ; then +# MINUS_e="" +#else +# MINUS_e="-e" +#fi + +#MINUS_E=X`$ECHO -n -E` +#if [ $MINUS_E != "X" ] ; then +# MINUS_E="" +#else +# MINUS_E="-E" +#fi + + +CUR_DIR=`pwd` +C_FILE="$CUR_DIR/modules_init.c" +H_FILE="$CUR_DIR/modules_init.h" +MOD_FILE="$CUR_DIR/Make_modules" +SRC_FILE="$CUR_DIR/Make_sources" +U_FILE="$CUR_DIR/modules_upgrade.c" + +/usr/bin/printf "Scanning extension modules for entry points.\n" + + +#start of the files which inturn removes any existing file +# + +# start the Makefile included file for $SERV_MODULES +cat <$MOD_FILE +# +# Make_modules +# This file is to be included by Makefile to dynamically add modules to the build process +# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE +# + +EOF + +# start the Makefile included file for $SOURCES +cat <$SRC_FILE +# +# Make_sources +# This file is to be included by Makefile to dynamically add modules to the build process +# THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE +# + +EOF + +# start the c file +cat <$C_FILE +/* + * $C_FILE + * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE + */ + + + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" +#include "modules_init.h" +#include "webserver.h" + +void LogPrintMessages(long err); +extern long DetailErrorFlags; + + + +void initialise_modules (void) +{ + +EOF + + +#start the header file +cat < $H_FILE +/* + * $H_FILE + * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE + */ + + +#ifndef MODULES_INIT_H +#define MODULES_INIT_H +extern size_t nSizErrmsg; +void initialise_modules (void); + + +EOF + + +INIT_FUNCS=`grep InitModule_ *.c |sed "s;.*:;;"` + +for HOOK in $INIT_FUNCS; do +HOOKNAME=`echo $HOOK |sed "s;InitModule_;;"` +# Add this entry point to the .c file +cat <> $C_FILE + lprintf (CTDL_INFO, "Initializing $HOOKNAME\n"); + $HOOK(); +EOF +# Add this entry point to the .h file +cat <> $H_FILE + extern void $HOOK(void); +EOF +done + + +/usr/bin/printf "}\n" >> $C_FILE + +/usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE diff --git a/webcit/netconf.c b/webcit/netconf.c index 79130b8db..beb7e095f 100644 --- a/webcit/netconf.c +++ b/webcit/netconf.c @@ -294,5 +294,16 @@ void delete_node(void) display_netconf(); } +void +InitModule_NETCONF +(void) +{ + WebcitAddUrlHandler(HKEY("display_edit_node"), display_edit_node, 0); + WebcitAddUrlHandler(HKEY("edit_node"), edit_node, 0); + WebcitAddUrlHandler(HKEY("display_netconf"), display_netconf, 0); + WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0); + WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0); + WebcitAddUrlHandler(HKEY("display_add_node"), display_add_node, 0); +} /*@}*/ diff --git a/webcit/notes.c b/webcit/notes.c index 7478813d9..497251d39 100644 --- a/webcit/notes.c +++ b/webcit/notes.c @@ -379,3 +379,11 @@ void add_new_note(void) { readloop("readfwd"); } + +void +InitModule_NOTES +(void) +{ + WebcitAddUrlHandler(HKEY("add_new_note"), add_new_note, 0); + WebcitAddUrlHandler(HKEY("ajax_update_note"), ajax_update_note, 0); +} diff --git a/webcit/openid.c b/webcit/openid.c index cae9de053..58c3503ab 100644 --- a/webcit/openid.c +++ b/webcit/openid.c @@ -106,3 +106,12 @@ void openid_detach(void) { display_openids(); } + +void +InitModule_OPENID +(void) +{ + WebcitAddUrlHandler(HKEY("display_openids"), display_openids, 0); + WebcitAddUrlHandler(HKEY("openid_attach"), openid_attach, 0); + WebcitAddUrlHandler(HKEY("openid_detach"), openid_detach, 0); +} diff --git a/webcit/paging.c b/webcit/paging.c index 93c402501..1d79cddf5 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -498,4 +498,15 @@ void chat_send(void) { wDumpContent(0); } +void +InitModule_PAGING +(void) +{ + WebcitAddUrlHandler(HKEY("display_page"), display_page, 0); + WebcitAddUrlHandler(HKEY("page_user"), page_user, 0); + WebcitAddUrlHandler(HKEY("chat"), do_chat, 0); + WebcitAddUrlHandler(HKEY("chat_recv"), chat_recv, 0); + WebcitAddUrlHandler(HKEY("chat_send"), chat_send, 0); +} + /*@}*/ diff --git a/webcit/preferences.c b/webcit/preferences.c index db35cedae..5b47e1659 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -604,4 +604,11 @@ void set_preferences(void) } +void +InitModule_PREFERENCES +(void) +{ + WebcitAddUrlHandler(HKEY("display_preferences"), display_preferences, 0); + WebcitAddUrlHandler(HKEY("set_preferences"), set_preferences, 0); +} /*@}*/ diff --git a/webcit/pushemail.c b/webcit/pushemail.c index e67c04b47..4b2e753d4 100644 --- a/webcit/pushemail.c +++ b/webcit/pushemail.c @@ -111,3 +111,11 @@ void save_pushemail(void) { serv_getln(buf, sizeof buf); http_redirect("display_pushemail"); } + +void +InitModule_PUSHMAIL +(void) +{ + WebcitAddUrlHandler(HKEY("display_pushemail"), display_pushemail, 0); + WebcitAddUrlHandler(HKEY("save_pushemail"), save_pushemail, 0); +} diff --git a/webcit/roomops.c b/webcit/roomops.c index da33b279c..05a7feef4 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -3187,10 +3187,14 @@ void do_rooms_view(struct folder *fold, int max_folders, int num_floors) { * \brief print a floor div??? * \param which_floordiv name of the floordiv??? */ -void set_floordiv_expanded(char *which_floordiv) { - begin_ajax_response(); - StrBufPrintf(WC->floordiv_expanded, "%s", which_floordiv); - end_ajax_response(); +void set_floordiv_expanded(void) { + struct wcsession *WCC = WC; + + if (WCC->floordiv_expanded == NULL) + WCC->floordiv_expanded = NewStrBuf(); + else + FlushStrBuf(WC->floordiv_expanded); + StrBufAppendBuf(WC->floordiv_expanded, WC->UrlFragment1, 0); } /** @@ -3640,4 +3644,43 @@ void set_room_policy(void) { display_editroom(); } + +void _gotonext(void) { slrp_highest(); gotonext(); } +void dotskip(void) {smart_goto(bstr("room"));} +void _display_private(void) { display_private("", 0); } +void dotgoto(void) { + if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */ + slrp_highest(); + } + smart_goto(bstr("room")); +} + + +void +InitModule_ROOMOPS +(void) +{ + WebcitAddUrlHandler(HKEY("knrooms"), knrooms, 0); + WebcitAddUrlHandler(HKEY("gotonext"), _gotonext, 0); + WebcitAddUrlHandler(HKEY("skip"), gotonext, 0); + WebcitAddUrlHandler(HKEY("ungoto"), ungoto, 0); + WebcitAddUrlHandler(HKEY("dotgoto"), dotgoto, 0); + WebcitAddUrlHandler(HKEY("dotskip"), dotskip, 0); + WebcitAddUrlHandler(HKEY("display_private"), _display_private, 0); + WebcitAddUrlHandler(HKEY("goto_private"), goto_private, 0); + WebcitAddUrlHandler(HKEY("zapped_list"), zapped_list, 0); + WebcitAddUrlHandler(HKEY("display_zap"), display_zap, 0); + WebcitAddUrlHandler(HKEY("zap"), zap, 0); + WebcitAddUrlHandler(HKEY("display_entroom"), display_entroom, 0); + WebcitAddUrlHandler(HKEY("entroom"), entroom, 0); + WebcitAddUrlHandler(HKEY("display_whok"), display_whok, 0); + WebcitAddUrlHandler(HKEY("do_invt_kick"), do_invt_kick, 0); + WebcitAddUrlHandler(HKEY("display_editroom"), display_editroom, 0); + WebcitAddUrlHandler(HKEY("netedit"), netedit, 0); + WebcitAddUrlHandler(HKEY("editroom"), editroom, 0); + WebcitAddUrlHandler(HKEY("delete_room"), delete_room, 0); + WebcitAddUrlHandler(HKEY("set_room_policy"), set_room_policy, 0); + WebcitAddUrlHandler(HKEY("set_floordiv_expanded"), set_floordiv_expanded, NEED_URL|AJAX); +} + /*@}*/ diff --git a/webcit/setup_wizard.c b/webcit/setup_wizard.c index d2d177a2b..8b52e0616 100644 --- a/webcit/setup_wizard.c +++ b/webcit/setup_wizard.c @@ -52,4 +52,9 @@ void do_setup_wizard(void) wDumpContent(1); } - +void +InitModule_SETUP_WIZARD +(void) +{ + WebcitAddUrlHandler(HKEY("setup_wizard"), do_setup_wizard, 0); +} diff --git a/webcit/sieve.c b/webcit/sieve.c index cf68af89a..d4d00dab7 100644 --- a/webcit/sieve.c +++ b/webcit/sieve.c @@ -1155,3 +1155,16 @@ void display_rules_editor_inner_div(void) { free(rooms); } + +void _display_add_remove_scripts(void) {display_add_remove_scripts(NULL);} + +void +InitModule_SIEVE +(void) +{ + WebcitAddUrlHandler(HKEY("display_sieve"), display_sieve, 0); + WebcitAddUrlHandler(HKEY("save_sieve"), save_sieve, 0); + WebcitAddUrlHandler(HKEY("display_add_remove_scripts"), _display_add_remove_scripts, 0); + WebcitAddUrlHandler(HKEY("create_script"), create_script, 0); + WebcitAddUrlHandler(HKEY("delete_script"), delete_script, 0); +} diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index 7a7288dee..5a2ee2e6f 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -845,5 +845,11 @@ void siteconfig(void) display_aide_menu(); } - +void +InitModule_SITECONFIG +(void) +{ + WebcitAddUrlHandler(HKEY("display_siteconfig"), display_siteconfig, 0); + WebcitAddUrlHandler(HKEY("siteconfig"), siteconfig, 0); +} /*@}*/ diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 3a1b29f2d..16a2491ff 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -265,7 +265,12 @@ void display_smtpqueue(void) } - - +void +InitModule_SMTP_QUEUE +(void) +{ + WebcitAddUrlHandler(HKEY("display_smtpqueue"), display_smtpqueue, 0); + WebcitAddUrlHandler(HKEY("display_smtpqueue_inner_div"), display_smtpqueue_inner_div, 0); +} /*@}*/ diff --git a/webcit/summary.c b/webcit/summary.c index f71a43b08..f7230e6b6 100644 --- a/webcit/summary.c +++ b/webcit/summary.c @@ -288,5 +288,16 @@ void summary(void) { wDumpContent(1); } +void +InitModule_SUMMARY +(void) +{ + WebcitAddUrlHandler(HKEY("new_messages_html"), new_messages_section, AJAX); + WebcitAddUrlHandler(HKEY("tasks_inner_html"), tasks_section, AJAX); + WebcitAddUrlHandler(HKEY("calendar_inner_html"), calendar_section, AJAX); + WebcitAddUrlHandler(HKEY("mini_calendar"), ajax_mini_calendar, AJAX); + WebcitAddUrlHandler(HKEY("summary"), summary, 0); + WebcitAddUrlHandler(HKEY("summary_inner_div"), summary_inner_div, AJAX); +} /*@}*/ diff --git a/webcit/sysmsgs.c b/webcit/sysmsgs.c index 00abb6cc5..b734e16f0 100644 --- a/webcit/sysmsgs.c +++ b/webcit/sysmsgs.c @@ -101,4 +101,23 @@ void save_edit(char *description, char *enter_cmd, int regoto) } +void display_editinfo(void){ display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);} +void editinfo(void) {save_edit(_("Room info"), "EINF 1", 1);} +void display_editbio(void) { + char buf[SIZ]; + + snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname); + display_edit(_("Your bio"), "NOOP", buf, "editbio", 3); +} +void editbio(void) { save_edit(_("Your bio"), "EBIO", 0); } + +void +InitModule_SYSMSG +(void) +{ + WebcitAddUrlHandler(HKEY("display_editinfo"), display_editinfo, 0); + WebcitAddUrlHandler(HKEY("editinfo"), editinfo, 0); + WebcitAddUrlHandler(HKEY("display_editbio"), display_editbio, 0); + WebcitAddUrlHandler(HKEY("editbio"), editbio, 0); +} /*@}*/ diff --git a/webcit/useredit.c b/webcit/useredit.c index e7ac53bd2..d5b9f44e0 100644 --- a/webcit/useredit.c +++ b/webcit/useredit.c @@ -529,5 +529,17 @@ void create_user(void) { } +void _select_user_to_edit(void){select_user_to_edit(NULL, NULL);} +void _display_edituser(void) {display_edituser(NULL, 0);} +void +InitModule_USEREDIT +(void) +{ + WebcitAddUrlHandler(HKEY("select_user_to_edit"), _select_user_to_edit, 0); + WebcitAddUrlHandler(HKEY("display_edituser"), _display_edituser, 0); + WebcitAddUrlHandler(HKEY("edituser"), edituser, 0); + WebcitAddUrlHandler(HKEY("create_user"), create_user, 0); + WebcitAddUrlHandler(HKEY("changeview"), change_view, 0); +} /*@}*/ diff --git a/webcit/userlist.c b/webcit/userlist.c index 20450d928..0733851d2 100644 --- a/webcit/userlist.c +++ b/webcit/userlist.c @@ -170,5 +170,11 @@ void showuser(void) wDumpContent(1); } - +void +InitModule_USERLIST +(void) +{ + WebcitAddUrlHandler(HKEY("userlist"), userlist, 0); + WebcitAddUrlHandler(HKEY("showuser"), showuser, 0); +} /*@}*/ diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 17b781778..d0e3ef7a0 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -485,4 +485,12 @@ void submit_vcard(void) { +void +InitModule_VCARD +(void) +{ + WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0); + WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0); +} + /*@}*/ diff --git a/webcit/webcit.c b/webcit/webcit.c index 8892ece71..2660b3d2f 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -22,8 +22,10 @@ static char *unset = "; expires=28-May-1971 18:10:00 GMT"; HashList *HandlerHash = NULL; - -void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc F, int IsAjax) +void WebcitAddUrlHandler(const char * UrlString, + long UrlSLen, + WebcitHandlerFunc F, + long Flags) { WebcitHandler *NewHandler; @@ -32,8 +34,7 @@ void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc NewHandler = (WebcitHandler*) malloc(sizeof(WebcitHandler)); NewHandler->F = F; - NewHandler->IsAjax = IsAjax; - + NewHandler->Flags = Flags; Put(HandlerHash, UrlString, UrlSLen, NewHandler, NULL); } @@ -935,7 +936,7 @@ void output_image() /* * Extract an embedded photo from a vCard for display on the client */ -void display_vcard_photo_img(char *msgnum_as_string) +void display_vcard_photo_img(void) { long msgnum = 0L; char *vcard; @@ -945,7 +946,7 @@ void display_vcard_photo_img(char *msgnum_as_string) int decoded; const char *contentType; - msgnum = atol(msgnum_as_string); + msgnum = StrTol(WC->UrlFragment1); vcard = load_mimepart(msgnum,"1"); v = vcard_load(vcard); @@ -976,7 +977,7 @@ void display_vcard_photo_img(char *msgnum_as_string) * partnum The MIME part to be output * force_download Nonzero to force set the Content-Type: header to "application/octet-stream" */ -void mimepart(char *msgnum, char *partnum, int force_download) +void mimepart(const char *msgnum, const char *partnum, int force_download) { char buf[256]; off_t bytes; @@ -1366,6 +1367,7 @@ void session_loop(struct httprequest *req) char c_httpauth_user[SIZ]; char c_httpauth_pass[SIZ]; char cookie[SIZ]; + struct wcsession *WCC = WC; safestrncpy(c_username, "", sizeof c_username); safestrncpy(c_password, "", sizeof c_password); @@ -1375,9 +1377,9 @@ void session_loop(struct httprequest *req) safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass); strcpy(browser_host, ""); - WC->upload_length = 0; - WC->upload = NULL; - WC->is_mobile = 0; + WCC->upload_length = 0; + WCC->upload = NULL; + WCC->is_mobile = 0; hptr = req; if (hptr == NULL) return; @@ -1436,17 +1438,17 @@ void session_loop(struct httprequest *req) else if (!strncasecmp(buf, "User-agent: ", 12)) { safestrncpy(user_agent, &buf[12], sizeof user_agent); if (is_mobile_ua(&buf[12])) { - WC->is_mobile = 1; + WCC->is_mobile = 1; } } else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) { if (follow_xff) { - safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host); + safestrncpy(WCC->http_host, &buf[18], sizeof WCC->http_host); } } else if (!strncasecmp(buf, "Host: ", 6)) { - if (IsEmptyStr(WC->http_host)) { - safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host); + if (IsEmptyStr(WCC->http_host)) { + safestrncpy(WCC->http_host, &buf[6], sizeof WCC->http_host); } } else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) { @@ -1470,7 +1472,7 @@ void session_loop(struct httprequest *req) body_start = strlen(content); /** Read the entire input data at once. */ - client_read(WC->http_sock, &content[body_start], ContentLength); + client_read(WCC->http_sock, &content[body_start], ContentLength); if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) { addurls(&content[body_start], ContentLength); @@ -1483,9 +1485,9 @@ void session_loop(struct httprequest *req) } /* make a note of where we are in case the user wants to save it */ - safestrncpy(WC->this_page, cmd, sizeof(WC->this_page)); - remove_token(WC->this_page, 2, ' '); - remove_token(WC->this_page, 0, ' '); + safestrncpy(WCC->this_page, cmd, sizeof(WCC->this_page)); + remove_token(WCC->this_page, 2, ' '); + remove_token(WCC->this_page, 0, ' '); /* If there are variables in the URL, we must grab them now */ len = strlen(cmd); @@ -1552,8 +1554,8 @@ void session_loop(struct httprequest *req) /* If the client sent a nonce that is incorrect, kill the request. */ if (strlen(bstr("nonce")) > 0) { lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n", - bstr("nonce"), WC->nonce); - if (ibstr("nonce") != WC->nonce) { + bstr("nonce"), WCC->nonce); + if (ibstr("nonce") != WCC->nonce) { lprintf(9, "Ignoring request with mismatched nonce.\n"); wprintf("HTTP/1.1 404 Security check failed\r\n"); wprintf("Content-Type: text/plain\r\n"); @@ -1567,23 +1569,23 @@ void session_loop(struct httprequest *req) * If we're not connected to a Citadel server, try to hook up the * connection now. */ - if (!WC->connected) { + if (!WCC->connected) { if (!strcasecmp(ctdlhost, "uds")) { /* unix domain socket */ snprintf(buf, SIZ, "%s/citadel.socket", ctdlport); - WC->serv_sock = uds_connectsock(buf); + WCC->serv_sock = uds_connectsock(buf); } else { /* tcp socket */ - WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport); + WCC->serv_sock = tcp_connectsock(ctdlhost, ctdlport); } - if (WC->serv_sock < 0) { + if (WCC->serv_sock < 0) { do_logout(); goto SKIP_ALL_THIS_CRAP; } else { - WC->connected = 1; + WCC->connected = 1; serv_getln(buf, sizeof buf); /** get the server welcome message */ /** @@ -1593,7 +1595,7 @@ void session_loop(struct httprequest *req) * and such a header has already turned up something. */ if ( (!follow_xff) || (strlen(browser_host) == 0) ) { - locate_host(browser_host, WC->http_sock); + locate_host(browser_host, WCC->http_sock); } get_serv_info(browser_host, user_agent); @@ -1630,7 +1632,7 @@ void session_loop(struct httprequest *req) * If we're not logged in, but we have HTTP Authentication data, * try logging in to Citadel using that. */ - if ((!WC->logged_in) + if ((!WCC->logged_in) && (strlen(c_httpauth_user) > 0) && (strlen(c_httpauth_pass) > 0)) { serv_printf("USER %s", c_httpauth_user); @@ -1641,8 +1643,8 @@ void session_loop(struct httprequest *req) if (buf[0] == '2') { become_logged_in(c_httpauth_user, c_httpauth_pass, buf); - safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user); - safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass); + safestrncpy(WCC->httpauth_user, c_httpauth_user, sizeof WCC->httpauth_user); + safestrncpy(WCC->httpauth_pass, c_httpauth_pass, sizeof WCC->httpauth_pass); } else { /* Should only display when password is wrong */ authorization_required(&buf[4]); @@ -1666,8 +1668,8 @@ void session_loop(struct httprequest *req) if (!strncasecmp(action, "groupdav", 8)) { groupdav_main(req, ContentType, /* do GroupDAV methods */ ContentLength, content+body_start); - if (!WC->logged_in) { - WC->killthis = 1; /* If not logged in, don't */ + if (!WCC->logged_in) { + WCC->killthis = 1; /* If not logged in, don't */ } /* keep the session active */ goto SKIP_ALL_THIS_CRAP; } @@ -1680,8 +1682,8 @@ void session_loop(struct httprequest *req) if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) { groupdav_main(req, ContentType, /** do GroupDAV methods */ ContentLength, content+body_start); - if (!WC->logged_in) { - WC->killthis = 1; /** If not logged in, don't */ + if (!WCC->logged_in) { + WCC->killthis = 1; /** If not logged in, don't */ } /** keep the session active */ goto SKIP_ALL_THIS_CRAP; } @@ -1690,7 +1692,7 @@ void session_loop(struct httprequest *req) * If we're not logged in, but we have username and password cookies * supplied by the browser, try using them to log in. */ - if ((!WC->logged_in) + if ((!WCC->logged_in) && (!IsEmptyStr(c_username)) && (!IsEmptyStr(c_password))) { serv_printf("USER %s", c_username); @@ -1707,11 +1709,11 @@ void session_loop(struct httprequest *req) * If we don't have a current room, but a cookie specifying the * current room is supplied, make an effort to go there. */ - if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) { + if ((IsEmptyStr(WCC->wc_roomname)) && (!IsEmptyStr(c_roomname))) { serv_printf("GOTO %s", c_roomname); serv_getln(buf, sizeof buf); if (buf[0] == '2') { - safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname); + safestrncpy(WCC->wc_roomname, c_roomname, sizeof WCC->wc_roomname); } } @@ -1719,392 +1721,39 @@ void session_loop(struct httprequest *req) output_image(); } else if (!strcasecmp(action, "display_mime_icon")) { display_mime_icon(); - - /* - * All functions handled below this point ... make sure we log in - * before doing anything else! - */ - } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) { - do_login(); - } else if ((!WC->logged_in) && (!strcasecmp(action, "display_openid_login"))) { - display_openid_login(NULL); - } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) { - do_openid_login(); - } else if (!strcasecmp(action, "finalize_openid_login")) { - finalize_openid_login(); - } else if (!strcasecmp(action, "openid_manual_create")) { - openid_manual_create(); - } else if (!WC->logged_in) { - display_login(NULL); } - - /* - * Various commands... - */ - else { void *vHandler; WebcitHandler *Handler; - + GetHash(HandlerHash, action, strlen(action) /* TODO*/, &vHandler), Handler = (WebcitHandler*) vHandler; if (Handler != NULL) { - if (Handler->IsAjax) - begin_ajax_response(); - Handler->F(); - if (Handler->IsAjax) - end_ajax_response(); - } - - - else if (!strcasecmp(action, "do_welcome")) { - do_welcome(); - } else if (!strcasecmp(action, "blank")) { - blank_page(); - } else if (!strcasecmp(action, "do_template")) { - url_do_template(); - } else if (!strcasecmp(action, "display_aide_menu")) { - display_aide_menu(); - } else if (!strcasecmp(action, "server_shutdown")) { - display_shutdown(); - } else if (!strcasecmp(action, "display_main_menu")) { - display_main_menu(); - } else if (!strcasecmp(action, "who")) { - who(); - } else if (!strcasecmp(action, "sslg")) { - seconds_since_last_gexp(); - } else if (!strcasecmp(action, "who_inner_html")) { - begin_ajax_response(); - who_inner_div(); - end_ajax_response(); - } else if (!strcasecmp(action, "wholist_section")) { - begin_ajax_response(); - wholist_section(); - end_ajax_response(); - } else if (!strcasecmp(action, "new_messages_html")) { - begin_ajax_response(); - new_messages_section(); - end_ajax_response(); - } else if (!strcasecmp(action, "tasks_inner_html")) { - begin_ajax_response(); - tasks_section(); - end_ajax_response(); - } else if (!strcasecmp(action, "calendar_inner_html")) { - begin_ajax_response(); - calendar_section(); - end_ajax_response(); - } else if (!strcasecmp(action, "mini_calendar")) { - begin_ajax_response(); - ajax_mini_calendar(); - end_ajax_response(); - } else if (!strcasecmp(action, "iconbar_ajax_menu")) { - begin_ajax_response(); - do_iconbar(); - end_ajax_response(); - } else if (!strcasecmp(action, "iconbar_ajax_rooms")) { - begin_ajax_response(); - do_iconbar_roomlist(); - end_ajax_response(); - } else if (!strcasecmp(action, "knrooms")) { - knrooms(); - } else if (!strcasecmp(action, "gotonext")) { - slrp_highest(); - gotonext(); - } else if (!strcasecmp(action, "skip")) { - gotonext(); - } else if (!strcasecmp(action, "ungoto")) { - ungoto(); - } else if (!strcasecmp(action, "dotgoto")) { - if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */ - slrp_highest(); + if (!WCC->logged_in && ((Handler->Flags & ANONYMOUS) == 0)) { + display_login(NULL); + } + else { + if((Handler->Flags & NEED_URL)) { + if (WCC->UrlFragment1 == NULL) + WCC->UrlFragment1 = NewStrBuf(); + if (WCC->UrlFragment2 == NULL) + WCC->UrlFragment2 = NewStrBuf(); + StrBufPrintf(WCC->UrlFragment1, "%s", index[1]); + StrBufPrintf(WCC->UrlFragment2, "%s", index[2]); + } + if ((Handler->Flags & AJAX) != 0) + begin_ajax_response(); + Handler->F(); + if ((Handler->Flags & AJAX) != 0) + end_ajax_response(); + } } - smart_goto(bstr("room")); - } else if (!strcasecmp(action, "dotskip")) { - smart_goto(bstr("room")); - } else if (!strcasecmp(action, "termquit")) { - do_logout(); - } else if (!strcasecmp(action, "readnew")) { - readloop("readnew"); - } else if (!strcasecmp(action, "readold")) { - readloop("readold"); - } else if (!strcasecmp(action, "readfwd")) { - readloop("readfwd"); - } else if (!strcasecmp(action, "headers")) { - readloop("headers"); - } else if (!strcasecmp(action, "do_search")) { - readloop("do_search"); - } else if (!strcasecmp(action, "msg")) { - embed_message(index[1]); - } else if (!strcasecmp(action, "printmsg")) { - print_message(index[1]); - } else if (!strcasecmp(action, "msgheaders")) { - display_headers(index[1]); - } else if (!strcasecmp(action, "vcardphoto")) { - display_vcard_photo_img(index[1]); - } else if (!strcasecmp(action, "wiki")) { - display_wiki_page(); - } else if (!strcasecmp(action, "display_enter")) { - display_enter(); - } else if (!strcasecmp(action, "post")) { - post_message(); - } else if (!strcasecmp(action, "move_msg")) { - move_msg(); - } else if (!strcasecmp(action, "delete_msg")) { - delete_msg(); - } else if (!strcasecmp(action, "userlist")) { - userlist(); - } else if (!strcasecmp(action, "showuser")) { - showuser(); - } else if (!strcasecmp(action, "display_page")) { - display_page(); - } else if (!strcasecmp(action, "page_user")) { - page_user(); - } else if (!strcasecmp(action, "chat")) { - do_chat(); - } else if (!strcasecmp(action, "display_private")) { - display_private("", 0); - } else if (!strcasecmp(action, "goto_private")) { - goto_private(); - } else if (!strcasecmp(action, "zapped_list")) { - zapped_list(); - } else if (!strcasecmp(action, "display_zap")) { - display_zap(); - } else if (!strcasecmp(action, "zap")) { - zap(); - } else if (!strcasecmp(action, "display_entroom")) { - display_entroom(); - } else if (!strcasecmp(action, "entroom")) { - entroom(); - } else if (!strcasecmp(action, "display_whok")) { - display_whok(); - } else if (!strcasecmp(action, "do_invt_kick")) { - do_invt_kick(); - } else if (!strcasecmp(action, "display_editroom")) { - display_editroom(); - } else if (!strcasecmp(action, "netedit")) { - netedit(); - } else if (!strcasecmp(action, "editroom")) { - editroom(); - } else if (!strcasecmp(action, "display_editinfo")) { - display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1); - } else if (!strcasecmp(action, "editinfo")) { - save_edit(_("Room info"), "EINF 1", 1); - } else if (!strcasecmp(action, "display_editbio")) { - snprintf(buf, SIZ, "RBIO %s", WC->wc_fullname); - display_edit(_("Your bio"), "NOOP", buf, "editbio", 3); - } else if (!strcasecmp(action, "editbio")) { - save_edit(_("Your bio"), "EBIO", 0); - } else if (!strcasecmp(action, "confirm_move_msg")) { - confirm_move_msg(); - } else if (!strcasecmp(action, "delete_room")) { - delete_room(); - } else if (!strcasecmp(action, "validate")) { - validate(); - /* The users photo display / upload facility */ - } else if (!strcasecmp(action, "display_editpic")) { - display_graphics_upload(_("your photo"), - "_userpic_", - "editpic"); - } else if (!strcasecmp(action, "editpic")) { - do_graphics_upload("_userpic_"); - /* room picture dispay / upload facility */ - } else if (!strcasecmp(action, "display_editroompic")) { - display_graphics_upload(_("the icon for this room"), - "_roompic_", - "editroompic"); - } else if (!strcasecmp(action, "editroompic")) { - do_graphics_upload("_roompic_"); - /* the greetingpage hello pic */ - } else if (!strcasecmp(action, "display_edithello")) { - display_graphics_upload(_("the Greetingpicture for the login prompt"), - "hello", - "edithellopic"); - } else if (!strcasecmp(action, "edithellopic")) { - do_graphics_upload("hello"); - /* the logoff banner */ - } else if (!strcasecmp(action, "display_editgoodbyepic")) { - display_graphics_upload(_("the Logoff banner picture"), - "UIMG 0|%s|goodbuye", - "editgoodbuyepic"); - } else if (!strcasecmp(action, "editgoodbuyepic")) { - do_graphics_upload("UIMG 1|%s|goodbuye"); - - } else if (!strcasecmp(action, "delete_floor")) { - delete_floor(); - } else if (!strcasecmp(action, "rename_floor")) { - rename_floor(); - } else if (!strcasecmp(action, "create_floor")) { - create_floor(); - } else if (!strcasecmp(action, "display_editfloorpic")) { - snprintf(buf, SIZ, "UIMG 0|_floorpic_|%s", - bstr("which_floor")); - display_graphics_upload(_("the icon for this floor"), - buf, - "editfloorpic"); - } else if (!strcasecmp(action, "editfloorpic")) { - snprintf(buf, SIZ, "UIMG 1|_floorpic_|%s", - bstr("which_floor")); - do_graphics_upload(buf); - } else if (!strcasecmp(action, "display_reg")) { - display_reg(0); - } else if (!strcasecmp(action, "display_changepw")) { - display_changepw(); - } else if (!strcasecmp(action, "changepw")) { - changepw(); - } else if (!strcasecmp(action, "display_edit_node")) { - display_edit_node(); - } else if (!strcasecmp(action, "edit_node")) { - edit_node(); - } else if (!strcasecmp(action, "display_netconf")) { - display_netconf(); - } else if (!strcasecmp(action, "display_confirm_delete_node")) { - display_confirm_delete_node(); - } else if (!strcasecmp(action, "delete_node")) { - delete_node(); - } else if (!strcasecmp(action, "display_add_node")) { - display_add_node(); - } else if (!strcasecmp(action, "terminate_session")) { - slrp_highest(); - terminate_session(); - } else if (!strcasecmp(action, "edit_me")) { - edit_me(); - } else if (!strcasecmp(action, "display_siteconfig")) { - display_siteconfig(); - } else if (!strcasecmp(action, "chat_recv")) { - chat_recv(); - } else if (!strcasecmp(action, "chat_send")) { - chat_send(); - } else if (!strcasecmp(action, "siteconfig")) { - siteconfig(); - } else if (!strcasecmp(action, "display_generic")) { - display_generic(); - } else if (!strcasecmp(action, "do_generic")) { - do_generic(); - } else if (!strcasecmp(action, "ajax_servcmd")) { - ajax_servcmd(); - } else if (!strcasecmp(action, "display_menubar")) { - display_menubar(1); - } else if (!strcasecmp(action, "mimepart")) { - mimepart(index[1], index[2], 0); - } else if (!strcasecmp(action, "mimepart_download")) { - mimepart(index[1], index[2], 1); - } else if (!strcasecmp(action, "edit_vcard")) { - edit_vcard(); - } else if (!strcasecmp(action, "submit_vcard")) { - submit_vcard(); - } else if (!strcasecmp(action, "select_user_to_edit")) { - select_user_to_edit(NULL, NULL); - } else if (!strcasecmp(action, "display_edituser")) { - display_edituser(NULL, 0); - } else if (!strcasecmp(action, "edituser")) { - edituser(); - } else if (!strcasecmp(action, "create_user")) { - create_user(); - } else if (!strcasecmp(action, "changeview")) { - change_view(); - } else if (!strcasecmp(action, "change_start_page")) { - change_start_page(); - } else if (!strcasecmp(action, "display_floorconfig")) { - display_floorconfig(NULL); - } else if (!strcasecmp(action, "toggle_self_service")) { - toggle_self_service(); - } else if (!strcasecmp(action, "display_edit_task")) { - display_edit_task(); - } else if (!strcasecmp(action, "save_task")) { - save_task(); - } else if (!strcasecmp(action, "display_edit_event")) { - display_edit_event(); - } else if (!strcasecmp(action, "save_event")) { - save_event(); - } else if (!strcasecmp(action, "respond_to_request")) { - respond_to_request(); - } else if (!strcasecmp(action, "handle_rsvp")) { - handle_rsvp(); - } else if (!strcasecmp(action, "summary")) { - summary(); - } else if (!strcasecmp(action, "summary_inner_div")) { - begin_ajax_response(); - summary_inner_div(); - end_ajax_response(); - } else if (!strcasecmp(action, "display_customize_iconbar")) { - display_customize_iconbar(); - } else if (!strcasecmp(action, "commit_iconbar")) { - commit_iconbar(); - } else if (!strcasecmp(action, "set_room_policy")) { - set_room_policy(); - } else if (!strcasecmp(action, "display_inetconf")) { - display_inetconf(); - } else if (!strcasecmp(action, "save_inetconf")) { - save_inetconf(); - } else if (!strcasecmp(action, "display_smtpqueue")) { - display_smtpqueue(); - } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) { - display_smtpqueue_inner_div(); - } else if (!strcasecmp(action, "display_sieve")) { - display_sieve(); - } else if (!strcasecmp(action, "save_sieve")) { - save_sieve(); - } else if (!strcasecmp(action, "display_pushemail")) { - display_pushemail(); - } else if (!strcasecmp(action, "save_pushemail")) { - save_pushemail(); - } else if (!strcasecmp(action, "display_add_remove_scripts")) { - display_add_remove_scripts(NULL); - } else if (!strcasecmp(action, "create_script")) { - create_script(); - } else if (!strcasecmp(action, "delete_script")) { - delete_script(); - } else if (!strcasecmp(action, "setup_wizard")) { - do_setup_wizard(); - } else if (!strcasecmp(action, "display_preferences")) { - display_preferences(); - } else if (!strcasecmp(action, "set_preferences")) { - set_preferences(); - } else if (!strcasecmp(action, "recp_autocomplete")) { - recp_autocomplete(bstr("recp")); - } else if (!strcasecmp(action, "cc_autocomplete")) { - recp_autocomplete(bstr("cc")); - } else if (!strcasecmp(action, "bcc_autocomplete")) { - recp_autocomplete(bstr("bcc")); - } else if (!strcasecmp(action, "display_address_book_middle_div")) { - display_address_book_middle_div(); - } else if (!strcasecmp(action, "display_address_book_inner_div")) { - display_address_book_inner_div(); - } else if (!strcasecmp(action, "set_floordiv_expanded")) { - set_floordiv_expanded(index[1]); - } else if (!strcasecmp(action, "diagnostics")) { - output_headers(1, 1, 1, 0, 0, 0); - wprintf("Session: %d
\n", WC->wc_session); - wprintf("Command:
\n");
-		escputs(cmd);
-		wprintf("

\n"); - wprintf("Variables:
\n");
-		dump_vars();
-		wprintf("

\n"); - wDumpContent(1); - } else if (!strcasecmp(action, "add_new_note")) { - add_new_note(); - } else if (!strcasecmp(action, "ajax_update_note")) { - ajax_update_note(); - } else if (!strcasecmp(action, "display_room_directory")) { - display_room_directory(); - } else if (!strcasecmp(action, "display_pictureview")) { - display_pictureview(); - } else if (!strcasecmp(action, "download_file")) { - download_file(index[1]); - } else if (!strcasecmp(action, "upload_file")) { - upload_file(); - } else if (!strcasecmp(action, "display_openids")) { - display_openids(); - } else if (!strcasecmp(action, "openid_attach")) { - openid_attach(); - } else if (!strcasecmp(action, "openid_detach")) { - openid_detach(); - } - /* When all else fais, display the main menu. */ else { - display_main_menu(); + if (!WCC->logged_in) + display_login(NULL); + else + display_main_menu(); } } SKIP_ALL_THIS_CRAP: @@ -2114,9 +1763,9 @@ SKIP_ALL_THIS_CRAP: content = NULL; } free_urls(); - if (WC->upload_length > 0) { - free(WC->upload); - WC->upload_length = 0; + if (WCC->upload_length > 0) { + free(WCC->upload); + WCC->upload_length = 0; } } @@ -2133,4 +1782,45 @@ void sleeeeeeeeeep(int seconds) select(0, NULL, NULL, NULL, &tv); } +void diagnostics(void) +{ + output_headers(1, 1, 1, 0, 0, 0); + wprintf("Session: %d
\n", WC->wc_session); + wprintf("Command:
\n");
+	escputs(WC->UrlFragment1);
+	wprintf("
\n"); + escputs(WC->UrlFragment2); + wprintf("

\n"); + wprintf("Variables:
\n");
+	dump_vars();
+	wprintf("

\n"); + wDumpContent(1); +} + +void view_mimepart(void) { + mimepart(ChrPtr(WC->UrlFragment1), + ChrPtr(WC->UrlFragment2), + 0); +} +void download_mimepart(void) { + mimepart(ChrPtr(WC->UrlFragment1), + ChrPtr(WC->UrlFragment2), + 1); +} + +void +InitModule_WEBCIT +(void) +{ + WebcitAddUrlHandler(HKEY("blank"), blank_page, ANONYMOUS); + WebcitAddUrlHandler(HKEY("do_template"), url_do_template, ANONYMOUS); + WebcitAddUrlHandler(HKEY("sslg"), seconds_since_last_gexp, AJAX); + WebcitAddUrlHandler(HKEY("ajax_servcmd"), ajax_servcmd, 0); + WebcitAddUrlHandler(HKEY("change_start_page"), change_start_page, 0); + WebcitAddUrlHandler(HKEY("toggle_self_service"), toggle_self_service, 0); + WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL); + WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL); + WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL); + WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL); +} diff --git a/webcit/webcit.h b/webcit/webcit.h index 337063f5b..1a8cd774f 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -426,6 +426,8 @@ struct wcsession { time_t last_pager_check; /**< last time we polled for instant msgs */ int nonce; /**< session nonce (to prevent session riding) */ int time_format_cache; /**< which timeformat does our user like? */ + StrBuf *UrlFragment1; /**< first urlfragment, if NEED_URL is specified by the handler*/ + StrBuf *UrlFragment2; /**< second urlfragment, if NEED_URL is specified by the handler*/ }; /** values for WC->current_iconbar */ @@ -572,9 +574,9 @@ void embed_main_menu(void); void serv_read(char *buf, int bytes); void readloop(char *oper); void read_message(long msgnum, int printable_view, char *section); -void embed_message(char *msgnum_as_string); -void print_message(char *msgnum_as_string); -void display_headers(char *msgnum_as_string); +void embed_message(void); +void print_message(void); +void display_headers(void); void text_to_server(char *ptr); void text_to_server_qp(char *ptr); void display_enter(void); @@ -769,7 +771,7 @@ void list_all_rooms_by_floor(const char *viewpref); void display_room_directory(void); void display_picture(void); void display_pictureview(void); -void download_file(char *); +void download_file(void); void upload_file(void); void display_edit_task(void); @@ -818,7 +820,7 @@ void commit_iconbar(void); int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen); void spawn_another_worker_thread(void); void display_rss(char *roomname, char *request_method); -void set_floordiv_expanded(char *which_floordiv); +void set_floordiv_expanded(void); void offer_languages(void); void set_selected_language(char *); void go_selected_language(void); @@ -879,10 +881,13 @@ void http_datestring(char *buf, size_t n, time_t xtime); typedef void (*WebcitHandlerFunc)(void); typedef struct _WebcitHandler{ WebcitHandlerFunc F; - int IsAjax; + long Flags; } WebcitHandler; -void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc F, int IsAjax); +void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, WebcitHandlerFunc F, long Flags); +#define AJAX (1<<0) +#define ANONYMOUS (1<<1) +#define NEED_URL (1<<2) /* These should be empty, but we have them for testing */ diff --git a/webcit/webserver.c b/webcit/webserver.c index 7ff612a69..3bb95099b 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -13,7 +13,7 @@ #if HAVE_BACKTRACE #include #endif - +#include "modules_init.h" #ifndef HAVE_SNPRINTF int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp); #endif @@ -663,6 +663,8 @@ void spawn_another_worker_thread() pthread_attr_destroy(&attr); } +const char foobuf[32]; +const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;} /* * \brief Here's where it all begins. * \param argc number of commandline args @@ -690,7 +692,10 @@ int main(int argc, char **argv) #endif /* ENABLE_NLS */ char uds_listen_path[PATH_MAX]; /*< listen on a unix domain socket? */ - HandlerHash = NewHash (1, NULL); + HandlerHash = NewHash(1, NULL); + initialise_modules(); + dbg_PrintHash(HandlerHash, nix, NULL); + /* Ensure that we are linked to the correct version of libcitadel */ if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) { fprintf(stderr, " You are running libcitadel version %d.%02d\n", diff --git a/webcit/who.c b/webcit/who.c index 834eb4817..d37105c2b 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -434,3 +434,19 @@ void wholist_section(void) { } DeleteHash(&List); } + +void _terminate_session(void) { + slrp_highest(); + terminate_session(); +} + +void +InitModule_WHO +(void) +{ + WebcitAddUrlHandler(HKEY("who"), who, 0); + WebcitAddUrlHandler(HKEY("who_inner_html"), who_inner_div, AJAX); + WebcitAddUrlHandler(HKEY("wholist_section"), wholist_section, AJAX); + WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0); + WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0); +} diff --git a/webcit/wiki.c b/webcit/wiki.c index 6efa60471..7a9a66c9d 100644 --- a/webcit/wiki.c +++ b/webcit/wiki.c @@ -97,3 +97,11 @@ void display_wiki_page(void) wprintf("\n"); wDumpContent(1); } + +void +InitModule_WIKI +(void) +{ + WebcitAddUrlHandler(HKEY("wiki"), display_wiki_page, 0); + return ; +} -- 2.30.2