From 277aee1c5194bca8cff1bd77f33821eaa021b5cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 8 Apr 2010 21:04:13 +0000 Subject: [PATCH] * change_start_page(), LoadStartpage(): check whether the startpage is allowed by rule * InitModule_MSG() disallow postpart_download, postpart, confirm_move_msg, delete_msg, move_msg, post to become the startpage; they don't do usefull things there. --- webcit/messages.c | 12 ++++++------ webcit/preferences.c | 46 +++++++++++++++++++++++++++++++++++++++----- webcit/webcit.h | 1 + 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/webcit/messages.c b/webcit/messages.c index 33f3a8f01..1ff718905 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1729,10 +1729,10 @@ InitModule_MSG WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, NEED_URL); WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0); WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0); - WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, 0); - WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, 0); - WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, 0); - WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, 0); + WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, PROHIBIT_STARTPAGE); + WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, PROHIBIT_STARTPAGE); + WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, PROHIBIT_STARTPAGE); + WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, PROHIBIT_STARTPAGE); WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL); WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE); WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL); @@ -1741,8 +1741,8 @@ InitModule_MSG WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL); WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL); - WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL); - WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL); + WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL|PROHIBIT_STARTPAGE); + WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL|PROHIBIT_STARTPAGE); /* json */ WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0); diff --git a/webcit/preferences.c b/webcit/preferences.c index a00c73293..1891beae4 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -10,6 +10,7 @@ #include "groupdav.h" HashList *PreferenceHooks; +extern HashList *HandlerHash; typedef struct _PrefDef { long Type; @@ -984,23 +985,50 @@ void offer_start_page(StrBuf *Target, WCTemplputParams *TP) */ void change_start_page(void) { - if (!havebstr("startpage")) { + wcsession *WCC = WC; + const char *pch; + void *vHandler; + int ProhibitSave = 0; + const StrBuf *pStartPage = sbstr("startpage"); + + if (pStartPage != NULL) { + pch = strchr(ChrPtr(pStartPage), '?'); + + if ((pch != NULL) && ( + GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler), + (vHandler != NULL) && + ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))) + { /* OK, This handler doesn't want to be set as start page, prune it. */ + ProhibitSave = 1; + } + } + + if ((pStartPage == NULL) || + (ProhibitSave == 1)) + { set_preference_backend(HKEY("startpage"), 0, NewStrBufPlain(HKEY("")), PRF_STRING, 1, NULL); - safestrncpy(WC->ImportantMessage, - _("You no longer have a start page selected."), - sizeof( WC->ImportantMessage)); + if (ProhibitSave == 1) + StrBufAppendBufPlain(WCC->ImportantMsg, + _("This isn't allowed to become the start page."), + -1, 0); + else + StrBufAppendBufPlain(WCC->ImportantMsg, + _("You no longer have a start page selected."), + -1, 0); display_main_menu(); return; } + + set_preference_backend(HKEY("startpage"), 0, - NewStrBufDup(sbstr("startpage")), + NewStrBufDup(pStartPage), PRF_STRING, 1, NULL); @@ -1014,6 +1042,7 @@ void change_start_page(void) void LoadStartpage(StrBuf *URL, long lvalue) { const char *pch; + void *vHandler; pch = strchr(ChrPtr(URL), '?'); if (pch == NULL) { /* purge the sins of the past... */ @@ -1023,6 +1052,13 @@ void LoadStartpage(StrBuf *URL, long lvalue) WC->SavePrefsToServer = 1; } } + else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler), + (vHandler != NULL) && + ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)) + { /* OK, This handler doesn't want to be set as start page, prune it. */ + FlushStrBuf(URL); + WC->SavePrefsToServer = 1; + } } diff --git a/webcit/webcit.h b/webcit/webcit.h index b65683c9c..385f9f573 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -346,6 +346,7 @@ typedef struct _addrbookent { #define ISSTATIC (1<<7) #define FORCE_SESSIONCLOSE (1<<8) #define PARSE_REST_URL (1<<9) +#define PROHIBIT_STARTPAGE (1<<10) typedef void (*WebcitHandlerFunc)(void); typedef struct _WebcitHandler{ -- 2.30.2