2 * Manage user preferences with a little help from the Citadel server.
4 * Copyright (c) 1996-2011 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "webserver.h"
26 HashList *PreferenceHooks;
27 extern HashList *HandlerHash;
29 typedef struct _PrefDef {
37 typedef struct _Preference {
39 ePrefType eFlatPrefType;
49 void DestroyPrefDef(void *vPrefDef)
51 PrefDef *Prefdef = (PrefDef*) vPrefDef;
52 FreeStrBuf(&Prefdef->Setting);
53 FreeStrBuf(&Prefdef->OnLoadName);
57 void DestroyPreference(void *vPref)
59 Preference *Pref = (Preference*) vPref;
60 FreeStrBuf(&Pref->Key);
61 FreeStrBuf(&Pref->Val);
62 FreeStrBuf(&Pref->DeQPed);
66 void _RegisterPreference(const char *Setting, long SettingLen,
70 const char *OnLoadName)
72 PrefDef *Newpref = (PrefDef*) malloc(sizeof(PrefDef));
73 Newpref->Setting = NewStrBufPlain(Setting, SettingLen);
74 Newpref->PrefStr = PrefStr;
75 Newpref->eType = Type;
76 Newpref->OnLoad = OnLoad;
77 if (Newpref->OnLoad != NULL) {
78 Newpref->OnLoadName = NewStrBufPlain(OnLoadName, -1);
81 Newpref->OnLoadName = NULL;
82 Put(PreferenceHooks, Setting, SettingLen, Newpref, DestroyPrefDef);
85 const char *PrefGetLocalStr(const char *Setting, long len)
88 if (GetHash(PreferenceHooks, Setting, len, &hash_value) != 0) {
89 PrefDef *Newpref = (PrefDef*) hash_value;
90 return _(Newpref->PrefStr);
97 inline const char *PrintPref(void *vPref)
99 Preference *Pref = (Preference*) vPref;
100 if (Pref->DeQPed != NULL)
101 return ChrPtr(Pref->DeQPed);
103 return ChrPtr(Pref->Val);
107 void GetPrefTypes(HashList *List)
117 It = GetNewHashPos(List, 0);
118 while (GetNextHashPos(List, It, &len, &Key, &vSetting))
120 Pref = (Preference*) vSetting;
121 if (GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
124 PrefType = (PrefDef*) vPrefDef;
125 Pref->Type = PrefType;
126 Pref->eFlatPrefType = Pref->Type->eType;
128 syslog(1, "Loading [%s]with type [%d] [\"%s\"]\n",
133 switch (Pref->Type->eType)
135 case PRF_UNSET: /* WHUT? */
140 Pref->lval = StrTol(Pref->Val);
144 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
145 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
149 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
154 if (PrefType->OnLoad != NULL){
156 syslog(1, "Loading with: -> %s(\"%s\", %ld)\n",
157 ChrPtr(PrefType->OnLoadName),
160 PrefType->OnLoad(Pref->Val, Pref->lval);
167 void ParsePref(HashList **List, StrBuf *ReadBuf)
170 Preference *Data = NULL;
171 Preference *LastData = NULL;
174 if (StrBuf_ServGetln(ReadBuf) < 0)
176 if ( (StrLength(ReadBuf)==3) &&
177 !strcmp(ChrPtr(ReadBuf), "000")) {
182 if ((ChrPtr(ReadBuf)[0] == ' ') &&
183 (LastData != NULL)) {
184 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
187 LastData = Data = malloc(sizeof(Preference));
188 memset(Data, 0, sizeof(Preference));
189 Data->Key = NewStrBuf();
190 Data->Val = NewStrBuf();
191 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
192 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
193 if (!IsEmptyStr(ChrPtr(Data->Key)))
203 syslog(1, "ignoring spurious preference line: [%s]\n",
205 DestroyPreference(Data);
216 * display preferences dialog
218 void load_preferences(void)
226 memset(&Room, 0, sizeof(folder));
227 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
228 if (goto_config_room(ReadBuf, &Room) != 0) {
229 FreeStrBuf(&ReadBuf);
232 return; /* oh well. */
235 serv_puts("MSGS ALL|0|1");
236 StrBuf_ServGetln(ReadBuf);
237 if (GetServerStatus(ReadBuf, NULL) == 8) {
238 serv_puts("subj|__ WebCit Preferences __");
242 (StrBuf_ServGetln(ReadBuf) >= 0)) {
243 if ( (StrLength(ReadBuf)==3) &&
244 !strcmp(ChrPtr(ReadBuf), "000")) {
248 msgnum = StrTol(ReadBuf);
252 serv_printf("MSG0 %ld", msgnum);
253 StrBuf_ServGetln(ReadBuf);
254 if (GetServerStatus(ReadBuf, NULL) == 1) {
255 while ((StrBuf_ServGetln(ReadBuf) >= 0) &&
256 (strcmp(ChrPtr(ReadBuf), "text") &&
257 strcmp(ChrPtr(ReadBuf), "000"))) {
259 if (!strcmp(ChrPtr(ReadBuf), "text")) {
260 ParsePref(&WCC->hash_prefs, ReadBuf);
265 /* Go back to the room we're supposed to be in */
266 if (StrLength(WCC->CurRoom.name) > 0) {
267 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
268 StrBuf_ServGetln(ReadBuf);
269 GetServerStatus(ReadBuf, NULL);
271 FreeStrBuf(&ReadBuf);
276 * Goto the user's configuration room, creating it if necessary.
277 * returns 0 on success or nonzero upon failure.
279 int goto_config_room(StrBuf *Buf, folder *Room)
281 serv_printf("GOTO %s", USERCONFIGROOM);
282 StrBuf_ServGetln(Buf);
283 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
284 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
285 StrBuf_ServGetln(Buf);
286 GetServerStatus(Buf, NULL);
288 serv_printf("GOTO %s", USERCONFIGROOM);
289 StrBuf_ServGetln(Buf);
290 if (GetServerStatus(Buf, NULL) != 2) {
294 ParseGoto(Room, Buf);
298 void WritePrefsToServer(HashList *Hash)
306 StrBuf *SubBuf = NULL;
308 Hash = WCC->hash_prefs;
309 #ifdef DBG_PREFS_HASH
310 dbg_PrintHash(Hash, PrintPref, NULL);
312 HashPos = GetNewHashPos(Hash, 0);
313 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
318 Pref = (Preference*) vPref;
319 nchars = StrLength(Pref->Val);
322 size_t offset, nchars;
324 SubBuf = NewStrBufPlain(NULL, SIZ);
333 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
336 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
338 serv_printf(" %s", ChrPtr(SubBuf));
341 nchars = StrLength(Pref->Val) - offset;
347 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
351 DeleteHashPos(&HashPos);
355 * \brief save the modifications
357 void save_preferences(void)
365 ReadBuf = NewStrBuf();
366 memset(&Room, 0, sizeof(folder));
367 if (goto_config_room(ReadBuf, &Room) != 0) {
368 FreeStrBuf(&ReadBuf);
371 return; /* oh well. */
374 /* make shure the config room has the right type, else it might reject our config */
375 if (Room.view != VIEW_BBS) {
376 serv_printf("VIEW %d", VIEW_BBS);
377 StrBuf_ServGetln(ReadBuf);
378 if (GetServerStatus(ReadBuf, NULL) != 2) {
381 else if (goto_config_room(ReadBuf, &Room) != 0) {
382 FreeStrBuf(&ReadBuf);
385 return; /* oh well. */
389 serv_puts("MSGS ALL|0|1");
390 StrBuf_ServGetln(ReadBuf);
391 if (GetServerStatus(ReadBuf, NULL) == 8) {
392 serv_puts("subj|__ WebCit Preferences __");
396 (StrBuf_ServGetln(ReadBuf) >= 0)) {
397 if ( (StrLength(ReadBuf)==3) &&
398 !strcmp(ChrPtr(ReadBuf), "000")) {
402 msgnum = StrTol(ReadBuf);
406 serv_printf("DELE %ld", msgnum);
407 StrBuf_ServGetln(ReadBuf);
408 GetServerStatus(ReadBuf, NULL);
411 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
412 StrBuf_ServGetln(ReadBuf);
413 if (GetServerStatus(ReadBuf, NULL) == 4) {
415 WritePrefsToServer(WCC->hash_prefs);
420 /** Go back to the room we're supposed to be in */
421 if (StrLength(WCC->CurRoom.name) > 0) {
422 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
423 StrBuf_ServGetln(ReadBuf);
424 GetServerStatus(ReadBuf, NULL);
426 FreeStrBuf(&ReadBuf);
431 * \brief query the actual setting of key in the citadel database
432 * \param key config key to query
433 * \param keylen length of the key string
434 * \param value StrBuf-value to the key to get
437 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
439 void *hash_value = NULL;
440 #ifdef DBG_PREFS_HASH
441 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
443 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
448 *Pref = (Preference*) hash_value;
453 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
458 Ret = get_pref_backend(key, keylen, &Pref);
467 * \brief Write a key into the webcit preferences database for this user
469 * \params key key whichs value is to be modified
470 * \param keylen length of the key string
471 * \param value value to set
472 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
474 long compare_preference(const Preference *PrefA,
475 const Preference *PrefB)
477 ePrefType TypeA, TypeB;
479 if (PrefA->Type != NULL)
480 TypeA = PrefA->Type->eType;
482 TypeA = PrefA->eFlatPrefType;
484 if (PrefB->Type != NULL)
485 TypeB = PrefB->Type->eType;
487 TypeB = PrefB->eFlatPrefType;
489 if ((TypeA != PRF_UNSET) &&
490 (TypeB != PRF_UNSET) &&
495 else /* (PrefA->Type < PrefB->Type) */
499 if (TypeB == PRF_UNSET)
507 return strcmp(ChrPtr(PrefA->Val),
511 if (PrefA->lval == PrefB->lval)
513 else if (PrefA->lval > PrefB->lval)
518 return strcmp(ChrPtr(PrefA->DeQPed),
519 ChrPtr(PrefB->DeQPed));
524 * \brief Write a key into the webcit preferences database for this user
526 * \params key key whichs value is to be modified
527 * \param keylen length of the key string
528 * \param value value to set
529 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
531 void set_preference_backend(const char *key, size_t keylen,
543 Pref = (Preference*) malloc(sizeof(Preference));
544 memset(Pref, 0, sizeof(Preference));
545 Pref->Key = NewStrBufPlain(key, keylen);
547 if ((PrefType == NULL) &&
548 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
550 PrefType = (PrefDef*) vPrefDef;
552 if (PrefType != NULL)
554 Pref->Type = PrefType;
555 Pref->eFlatPrefType = PrefType->eType;
556 if (Pref->Type->eType != lPrefType)
557 syslog(1, "warning: saving preference with wrong type [%s] %d != %ld \n",
558 key, Pref->Type->eType, lPrefType);
559 switch (Pref->Type->eType)
561 case PRF_UNSET: /* default to string... */
569 if (Pref->Val == NULL)
570 Pref->Val = NewStrBufPlain(NULL, 64);
571 StrBufPrintf(Pref->Val, "%ld", lvalue);
575 Pref->DeQPed = value;
576 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
577 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
583 Pref->Val = NewStrBufPlain(HKEY("yes"));
585 Pref->Val = NewStrBufPlain(HKEY("no"));
589 if (Pref->Type->OnLoad != NULL)
590 Pref->Type->OnLoad(Pref->Val, Pref->lval);
593 Pref->eFlatPrefType = lPrefType;
603 if (Pref->Val == NULL)
604 Pref->Val = NewStrBufPlain(NULL, 64);
605 StrBufPrintf(Pref->Val, "%ld", lvalue);
609 Pref->DeQPed = value;
610 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
611 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
617 Pref->Val = NewStrBufPlain(HKEY("yes"));
619 Pref->Val = NewStrBufPlain(HKEY("no"));
625 if ((save_to_server != 0) &&
626 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
628 (compare_preference (Pref, vPrefB) == 0))
631 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
633 if (save_to_server) WCC->SavePrefsToServer = 1;
636 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
638 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
641 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
646 Ret = get_pref_backend(key, keylen, &Pref);
655 *value = Pref->lval = atol(ChrPtr(Pref->Val));
662 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
664 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
667 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
672 Ret = get_pref_backend(key, keylen, &Pref);
681 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
687 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
689 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
692 int get_room_prefs_backend(const char *key, size_t keylen,
698 pref_name = NewStrBufPlain (HKEY("ROOM:"));
699 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
700 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
701 StrBufAppendBufPlain(pref_name, key, keylen, 0);
702 Ret = get_pref_backend(SKEY(pref_name), Pref);
703 FreeStrBuf(&pref_name);
708 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
709 const char *xkey, size_t xkeylen)
715 pref_name = NewStrBufPlain (HKEY("XPREF:"));
716 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
717 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
718 StrBufAppendBufPlain(pref_name, key, keylen, 0);
720 ret = get_pref_backend(SKEY(pref_name), &Prf);
721 FreeStrBuf(&pref_name);
728 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
732 pref_name = NewStrBufPlain (HKEY("XPREF:"));
733 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
734 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
735 StrBufAppendBufPlain(pref_name, key, keylen, 0);
737 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
738 FreeStrBuf(&pref_name);
742 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
747 Ret = get_room_prefs_backend(key, keylen, &Pref);
757 *value = Pref->lval = atol(ChrPtr(Pref->Val));
764 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
769 Ret = get_room_prefs_backend(key, keylen, &Pref);
778 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
782 pref_name = NewStrBufPlain (HKEY("ROOM:"));
783 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
784 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
785 StrBufAppendBufPlain(pref_name, key, keylen, 0);
786 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
787 FreeStrBuf(&pref_name);
791 void GetPreferences(HashList *Setting)
803 Tmp = WCC->hash_prefs;
804 WCC->hash_prefs = Setting;
806 It = GetNewHashPos(PreferenceHooks, 0);
807 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
808 PrefType = (PrefDef*) vSetting;
810 if (!HaveBstr(SKEY(PrefType->Setting)))
812 switch (PrefType->eType) {
815 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
816 set_preference_backend(SKEY(PrefType->Setting),
824 lval = LBstr(SKEY(PrefType->Setting));
825 set_preference_backend(SKEY(PrefType->Setting),
833 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
834 set_preference_backend(SKEY(PrefType->Setting),
842 lval = YesBstr(SKEY(PrefType->Setting));
843 set_preference_backend(SKEY(PrefType->Setting),
852 WCC->hash_prefs = Tmp;
858 * \brief Commit new preferences and settings
860 void set_preferences(void)
862 if (!havebstr("change_button")) {
863 safestrncpy(WC->ImportantMessage,
864 _("Cancelled. No settings were changed."),
865 sizeof WC->ImportantMessage);
869 GetPreferences(WC->hash_prefs);
874 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
877 if (get_pref_backend(TKEY(0), &Pref))
879 if (Pref->Type == NULL) {
880 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
882 switch (Pref->Type->eType)
884 case PRF_UNSET: /* default to string... */
886 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
889 if (Pref->decoded != 1) {
890 if (Pref->Val == NULL)
891 Pref->Val = NewStrBufPlain(NULL, 64);
892 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
895 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
898 if (Pref->decoded != 1) {
899 if (Pref->DeQPed == NULL)
900 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
902 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
905 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
908 if (Pref->decoded != 1) {
909 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
912 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
918 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
920 const char *SettingStr;
921 SettingStr = PrefGetLocalStr(TKEY(0));
922 if (SettingStr != NULL)
923 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
925 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
931 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
932 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
933 StrBufAppendPrintf(Target, "%ld", lvalue);
935 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
937 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
939 StrBufAppendBuf(Target, pref, 0);
941 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
943 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
944 TP->Tokens->Params[0]->len) != NULL)
950 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
954 if (!get_PREFERENCE(TKEY(2), &Pref))
957 if (!HAVE_PARAM(3)) {
960 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
962 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
969 GetTemplateTokenString(Target, TP, 3, &pch, &len);
971 return ((len == StrLength(Pref)) &&
972 (strcmp(pch, ChrPtr(Pref)) == 0));
976 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
980 if (!get_PREFERENCE(TKEY(2), &Pref) ||
988 /********************************************************************************
989 * preferences stored discrete in citserver
990 ********************************************************************************/
991 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
994 HashList *List = NULL;
1001 StrBuf_ServGetln(Rcp);
1002 if (GetServerStatus(Rcp, NULL) == 1) {
1004 List = NewHash(1, NULL);
1005 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1006 if ( (StrLength(Rcp)==3) &&
1007 !strcmp(ChrPtr(Rcp), "000"))
1012 i = snprintf(N, sizeof(N), "%d", n);
1014 Put(List, N, i, Rcp, HFreeStrBuf);
1023 void DeleteGVEAHash(HashList **KillMe)
1028 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1031 HashList *List = NULL;
1038 StrBuf_ServGetln(Rcp);
1039 if (GetServerStatus(Rcp, NULL) == 1) {
1041 List = NewHash(1, NULL);
1042 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1043 if ( (StrLength(Rcp)==3) &&
1044 !strcmp(ChrPtr(Rcp), "000"))
1049 i = snprintf(N, sizeof(N), "%d", n);
1051 Put(List, N, i, Rcp, HFreeStrBuf);
1060 void DeleteGVSNHash(HashList **KillMe)
1069 * Offer to make any page the user's "start page" (only if logged in)
1071 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1073 if (WC->logged_in) {
1074 wc_printf("<a href=\"change_start_page?startpage=");
1075 urlescputs(ChrPtr(WC->Hdr->this_page));
1077 wc_printf(_("Make this my start page"));
1084 * Change the user's start page
1086 void change_start_page(void)
1088 wcsession *WCC = WC;
1091 int ProhibitSave = 0;
1092 const StrBuf *pStartPage = sbstr("startpage");
1094 if (pStartPage != NULL) {
1095 pch = strchr(ChrPtr(pStartPage), '?');
1097 if ((pch != NULL) && (
1098 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1099 (vHandler != NULL) &&
1100 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1101 { /* OK, This handler doesn't want to be set as start page, prune it. */
1106 if ((pStartPage == NULL) ||
1107 (ProhibitSave == 1))
1109 set_preference_backend(HKEY("startpage"),
1111 NewStrBufPlain(HKEY("")),
1115 if (ProhibitSave == 1)
1116 StrBufAppendBufPlain(WCC->ImportantMsg,
1117 _("This isn't allowed to become the start page."),
1120 StrBufAppendBufPlain(WCC->ImportantMsg,
1121 _("You no longer have a start page selected."),
1123 display_main_menu();
1129 set_preference_backend(HKEY("startpage"),
1131 NewStrBufDup(pStartPage),
1136 output_headers(1, 1, 0, 0, 0, 0);
1137 do_template("newstartpage");
1142 void LoadStartpage(StrBuf *URL, long lvalue)
1146 pch = strchr(ChrPtr(URL), '?');
1148 /* purge the sins of the past... */
1149 pch = strchr(ChrPtr(URL), '&');
1151 StrBufPeek(URL, pch, -1, '?');
1152 WC->SavePrefsToServer = 1;
1155 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1156 (vHandler != NULL) &&
1157 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1158 { /* OK, This handler doesn't want to be set as start page, prune it. */
1160 WC->SavePrefsToServer = 1;
1166 InitModule_PREFERENCES
1169 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1170 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1172 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1174 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1175 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1176 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1177 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1179 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1181 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1182 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1183 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1185 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1186 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1187 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1188 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1194 ServerStartModule_PREFERENCES
1197 PreferenceHooks = NewHash(1, NULL);
1203 ServerShutdownModule_PREFERENCES
1206 DeleteHash(&PreferenceHooks);
1210 SessionDetachModule__PREFERENCES
1213 if (sess->SavePrefsToServer) {
1215 sess->SavePrefsToServer = 0;
1220 SessionNewModule_PREFERENCES
1223 sess->hash_prefs = NewHash(1,NULL);
1227 SessionDestroyModule_PREFERENCES
1230 DeleteHash(&sess->hash_prefs);