2 * Manage user preferences with a little help from the Citadel server.
4 * Copyright (c) 1996-2012 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, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
19 HashList *PreferenceHooks;
20 extern HashList *HandlerHash;
22 typedef struct _PrefDef {
30 typedef struct _Preference {
32 ePrefType eFlatPrefType;
42 void DestroyPrefDef(void *vPrefDef)
44 PrefDef *Prefdef = (PrefDef*) vPrefDef;
45 FreeStrBuf(&Prefdef->Setting);
46 FreeStrBuf(&Prefdef->OnLoadName);
50 void DestroyPreference(void *vPref)
52 Preference *Pref = (Preference*) vPref;
53 FreeStrBuf(&Pref->Key);
54 FreeStrBuf(&Pref->Val);
55 FreeStrBuf(&Pref->DeQPed);
60 void _RegisterPreference(const char *Setting, long SettingLen,
64 const char *OnLoadName)
66 PrefDef *Newpref = (PrefDef*) malloc(sizeof(PrefDef));
67 Newpref->Setting = NewStrBufPlain(Setting, SettingLen);
68 Newpref->PrefStr = PrefStr;
69 Newpref->eType = Type;
70 Newpref->OnLoad = OnLoad;
71 if (Newpref->OnLoad != NULL) {
72 Newpref->OnLoadName = NewStrBufPlain(OnLoadName, -1);
75 Newpref->OnLoadName = NULL;
76 Put(PreferenceHooks, Setting, SettingLen, Newpref, DestroyPrefDef);
79 const char *PrefGetLocalStr(const char *Setting, long len)
82 if (GetHash(PreferenceHooks, Setting, len, &hash_value) != 0) {
83 PrefDef *Newpref = (PrefDef*) hash_value;
84 return _(Newpref->PrefStr);
91 inline const char *PrintPref(void *vPref)
93 Preference *Pref = (Preference*) vPref;
94 if (Pref->DeQPed != NULL)
95 return ChrPtr(Pref->DeQPed);
97 return ChrPtr(Pref->Val);
101 void GetPrefTypes(HashList *List)
111 It = GetNewHashPos(List, 0);
112 while (GetNextHashPos(List, It, &len, &Key, &vSetting))
114 Pref = (Preference*) vSetting;
115 if (GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
118 PrefType = (PrefDef*) vPrefDef;
119 Pref->Type = PrefType;
120 Pref->eFlatPrefType = Pref->Type->eType;
122 syslog(1, "Loading [%s]with type [%d] [\"%s\"]\n",
127 switch (Pref->Type->eType)
129 case PRF_UNSET: /* WHUT? */
134 Pref->lval = StrTol(Pref->Val);
138 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
139 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
143 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
148 if (PrefType->OnLoad != NULL){
150 syslog(1, "Loading with: -> %s(\"%s\", %ld)\n",
151 ChrPtr(PrefType->OnLoadName),
154 PrefType->OnLoad(Pref->Val, Pref->lval);
161 void ParsePref(HashList **List, StrBuf *ReadBuf)
164 Preference *Data = NULL;
165 Preference *LastData = NULL;
168 if (StrBuf_ServGetln(ReadBuf) < 0)
170 if ( (StrLength(ReadBuf)==3) &&
171 !strcmp(ChrPtr(ReadBuf), "000")) {
176 if ((ChrPtr(ReadBuf)[0] == ' ') &&
177 (LastData != NULL)) {
178 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
181 LastData = Data = malloc(sizeof(Preference));
182 memset(Data, 0, sizeof(Preference));
183 Data->Key = NewStrBuf();
184 Data->Val = NewStrBuf();
185 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
186 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
188 /***************** BEGIN VILE SLEAZY HACK ************************/
190 /* some users might still have this start page configured, which now breaks */
192 if ( (!strcasecmp(ChrPtr(Data->Key), "startpage"))
193 && (!strcasecmp(ChrPtr(Data->Val), "/do_template?template=summary_page"))
195 FreeStrBuf(&Data->Val);
196 Data->Val = NewStrBufPlain(HKEY("/summary"));
199 /******************* END VILE SLEAZY HACK ************************/
201 if (!IsEmptyStr(ChrPtr(Data->Key)))
211 syslog(1, "ignoring spurious preference line: [%s]\n",
213 DestroyPreference(Data);
224 * display preferences dialog
226 void load_preferences(void)
234 memset(&Room, 0, sizeof(folder));
235 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
236 if (goto_config_room(ReadBuf, &Room) != 0) {
237 FreeStrBuf(&ReadBuf);
240 return; /* oh well. */
243 serv_puts("MSGS ALL|0|1");
244 StrBuf_ServGetln(ReadBuf);
245 if (GetServerStatus(ReadBuf, NULL) == 8) {
246 serv_puts("subj|__ WebCit Preferences __");
249 while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
250 if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
254 msgnum = StrTol(ReadBuf);
258 serv_printf("MSG0 %ld", msgnum);
259 StrBuf_ServGetln(ReadBuf);
260 if (GetServerStatus(ReadBuf, NULL) == 1) {
261 while ( (StrBuf_ServGetln(ReadBuf) >= 0)
262 && (strcmp(ChrPtr(ReadBuf), "text")
263 && strcmp(ChrPtr(ReadBuf), "000"))
267 if (!strcmp(ChrPtr(ReadBuf), "text")) {
268 ParsePref(&WCC->hash_prefs, ReadBuf);
273 /* Go back to the room we're supposed to be in */
274 if (StrLength(WCC->CurRoom.name) > 0) {
275 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
276 StrBuf_ServGetln(ReadBuf);
277 GetServerStatus(ReadBuf, NULL);
279 FreeStrBuf(&ReadBuf);
285 * Go to the user's configuration room, creating it if necessary.
286 * returns 0 on success or nonzero upon failure.
288 int goto_config_room(StrBuf *Buf, folder *Room)
290 serv_printf("GOTO %s", USERCONFIGROOM);
291 StrBuf_ServGetln(Buf);
292 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
293 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
294 StrBuf_ServGetln(Buf);
295 GetServerStatus(Buf, NULL);
297 serv_printf("GOTO %s", USERCONFIGROOM);
298 StrBuf_ServGetln(Buf);
299 if (GetServerStatus(Buf, NULL) != 2) {
303 ParseGoto(Room, Buf);
307 void WritePrefsToServer(HashList *Hash)
315 StrBuf *SubBuf = NULL;
317 Hash = WCC->hash_prefs;
318 #ifdef DBG_PREFS_HASH
319 dbg_PrintHash(Hash, PrintPref, NULL);
321 HashPos = GetNewHashPos(Hash, 0);
322 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
327 Pref = (Preference*) vPref;
328 nchars = StrLength(Pref->Val);
331 size_t offset, nchars;
333 SubBuf = NewStrBufPlain(NULL, SIZ);
342 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
345 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
348 serv_printf(" %s", ChrPtr(SubBuf));
352 nchars = StrLength(Pref->Val) - offset;
358 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
363 DeleteHashPos(&HashPos);
367 * save the modifications
369 void save_preferences(void)
377 ReadBuf = NewStrBuf();
378 memset(&Room, 0, sizeof(folder));
379 if (goto_config_room(ReadBuf, &Room) != 0) {
380 FreeStrBuf(&ReadBuf);
383 return; /* oh well. */
386 /* make shure the config room has the right type, else it might reject our config */
387 if (Room.view != VIEW_BBS) {
388 serv_printf("VIEW %d", VIEW_BBS);
389 StrBuf_ServGetln(ReadBuf);
390 if (GetServerStatus(ReadBuf, NULL) != 2) {
393 else if (goto_config_room(ReadBuf, &Room) != 0) {
394 FreeStrBuf(&ReadBuf);
397 return; /* oh well. */
401 serv_puts("MSGS ALL|0|1");
402 StrBuf_ServGetln(ReadBuf);
403 if (GetServerStatus(ReadBuf, NULL) == 8) {
404 serv_puts("subj|__ WebCit Preferences __");
407 while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
408 if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
412 msgnum = StrTol(ReadBuf);
416 serv_printf("DELE %ld", msgnum);
417 StrBuf_ServGetln(ReadBuf);
418 GetServerStatus(ReadBuf, NULL);
421 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
422 StrBuf_ServGetln(ReadBuf);
423 if (GetServerStatus(ReadBuf, NULL) == 4) {
425 WritePrefsToServer(WCC->hash_prefs);
430 /** Go back to the room we're supposed to be in */
431 if (StrLength(WCC->CurRoom.name) > 0) {
432 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
433 StrBuf_ServGetln(ReadBuf);
434 GetServerStatus(ReadBuf, NULL);
436 FreeStrBuf(&ReadBuf);
441 * query the actual setting of key in the citadel database
443 * key config key to query
444 * keylen length of the key string
445 * value StrBuf-value to the key to get
448 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
450 void *hash_value = NULL;
451 #ifdef DBG_PREFS_HASH
452 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
454 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
459 *Pref = (Preference*) hash_value;
464 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
469 Ret = get_pref_backend(key, keylen, &Pref);
478 * Write a key into the webcit preferences database for this user
480 * key key whichs value is to be modified
481 * keylen length of the key string
483 * save_to_server 1 = flush all data to the server, 0 = cache it for now
485 long compare_preference(const Preference *PrefA, const Preference *PrefB)
487 ePrefType TypeA, TypeB;
489 if (PrefA->Type != NULL) {
490 TypeA = PrefA->Type->eType;
493 TypeA = PrefA->eFlatPrefType;
496 if (PrefB->Type != NULL) {
497 TypeB = PrefB->Type->eType;
500 TypeB = PrefB->eFlatPrefType;
503 if ( (TypeA != PRF_UNSET)
504 && (TypeB != PRF_UNSET)
510 else { /* (PrefA->Type < PrefB->Type) */
515 if (TypeB == PRF_UNSET) {
524 return strcmp(ChrPtr(PrefA->Val), ChrPtr(PrefB->Val));
527 if (PrefA->lval == PrefB->lval)
529 else if (PrefA->lval > PrefB->lval)
534 return strcmp(ChrPtr(PrefA->DeQPed),
535 ChrPtr(PrefB->DeQPed));
541 * Write a key into the webcit preferences database for this user
543 * key key which value is to be modified
544 * keylen length of the key string
546 * save_to_server 1 = flush all data to the server, 0 = cache it for now
548 void set_preference_backend(const char *key, size_t keylen,
560 Pref = (Preference*) malloc(sizeof(Preference));
561 memset(Pref, 0, sizeof(Preference));
562 Pref->Key = NewStrBufPlain(key, keylen);
564 if ((PrefType == NULL) &&
565 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
567 PrefType = (PrefDef*) vPrefDef;
569 if (PrefType != NULL)
571 Pref->Type = PrefType;
572 Pref->eFlatPrefType = PrefType->eType;
573 if (Pref->Type->eType != lPrefType)
574 syslog(1, "warning: saving preference with wrong type [%s] %d != %ld \n",
575 key, Pref->Type->eType, lPrefType);
576 switch (Pref->Type->eType)
578 case PRF_UNSET: /* default to string... */
586 if (Pref->Val == NULL)
587 Pref->Val = NewStrBufPlain(NULL, 64);
588 StrBufPrintf(Pref->Val, "%ld", lvalue);
592 Pref->DeQPed = value;
593 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
594 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
600 Pref->Val = NewStrBufPlain(HKEY("yes"));
602 Pref->Val = NewStrBufPlain(HKEY("no"));
606 if (Pref->Type->OnLoad != NULL)
607 Pref->Type->OnLoad(Pref->Val, Pref->lval);
610 Pref->eFlatPrefType = lPrefType;
620 if (Pref->Val == NULL)
621 Pref->Val = NewStrBufPlain(NULL, 64);
622 StrBufPrintf(Pref->Val, "%ld", lvalue);
626 Pref->DeQPed = value;
627 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
628 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
634 Pref->Val = NewStrBufPlain(HKEY("yes"));
636 Pref->Val = NewStrBufPlain(HKEY("no"));
642 if ((save_to_server != 0) &&
643 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
645 (compare_preference (Pref, vPrefB) == 0))
648 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
650 if (save_to_server) WCC->SavePrefsToServer = 1;
653 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
655 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
658 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
663 Ret = get_pref_backend(key, keylen, &Pref);
672 *value = Pref->lval = atol(ChrPtr(Pref->Val));
679 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
681 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
684 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
689 Ret = get_pref_backend(key, keylen, &Pref);
698 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
704 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
706 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
709 int get_room_prefs_backend(const char *key, size_t keylen,
715 pref_name = NewStrBufPlain (HKEY("ROOM:"));
716 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
717 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
718 StrBufAppendBufPlain(pref_name, key, keylen, 0);
719 Ret = get_pref_backend(SKEY(pref_name), Pref);
720 FreeStrBuf(&pref_name);
725 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
726 const char *xkey, size_t xkeylen)
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 ret = get_pref_backend(SKEY(pref_name), &Prf);
738 FreeStrBuf(&pref_name);
745 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
749 pref_name = NewStrBufPlain (HKEY("XPREF:"));
750 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
751 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
752 StrBufAppendBufPlain(pref_name, key, keylen, 0);
754 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
755 FreeStrBuf(&pref_name);
759 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
764 Ret = get_room_prefs_backend(key, keylen, &Pref);
774 *value = Pref->lval = atol(ChrPtr(Pref->Val));
781 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
786 Ret = get_room_prefs_backend(key, keylen, &Pref);
795 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
799 pref_name = NewStrBufPlain (HKEY("ROOM:"));
800 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
801 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
802 StrBufAppendBufPlain(pref_name, key, keylen, 0);
803 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
804 FreeStrBuf(&pref_name);
808 void GetPreferences(HashList *Setting)
820 Tmp = WCC->hash_prefs;
821 WCC->hash_prefs = Setting;
823 It = GetNewHashPos(PreferenceHooks, 0);
824 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
825 PrefType = (PrefDef*) vSetting;
827 if (!HaveBstr(SKEY(PrefType->Setting)))
829 switch (PrefType->eType) {
832 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
833 set_preference_backend(SKEY(PrefType->Setting),
841 lval = LBstr(SKEY(PrefType->Setting));
842 set_preference_backend(SKEY(PrefType->Setting),
850 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
851 set_preference_backend(SKEY(PrefType->Setting),
859 lval = YesBstr(SKEY(PrefType->Setting));
860 set_preference_backend(SKEY(PrefType->Setting),
869 WCC->hash_prefs = Tmp;
875 * Commit new preferences and settings
877 void set_preferences(void)
879 if (!havebstr("change_button")) {
880 AppendImportantMessage(_("Cancelled. No settings were changed."), -1);
884 GetPreferences(WC->hash_prefs);
889 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
892 if (get_pref_backend(TKEY(0), &Pref))
894 if (Pref->Type == NULL) {
895 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
897 switch (Pref->Type->eType)
899 case PRF_UNSET: /* default to string... */
901 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
904 if (Pref->decoded != 1) {
905 if (Pref->Val == NULL)
906 Pref->Val = NewStrBufPlain(NULL, 64);
907 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
910 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
913 if (Pref->decoded != 1) {
914 if (Pref->DeQPed == NULL)
915 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
917 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
920 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
923 if (Pref->decoded != 1) {
924 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
927 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
933 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
935 const char *SettingStr;
936 SettingStr = PrefGetLocalStr(TKEY(0));
937 if (SettingStr != NULL)
938 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
940 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
946 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
947 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
948 StrBufAppendPrintf(Target, "%ld", lvalue);
950 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
952 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
954 StrBufAppendBuf(Target, pref, 0);
956 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
958 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
959 TP->Tokens->Params[0]->len) != NULL)
965 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
969 if (!get_PREFERENCE(TKEY(2), &Pref))
972 if (!HAVE_PARAM(3)) {
975 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
977 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
984 GetTemplateTokenString(Target, TP, 3, &pch, &len);
986 return ((len == StrLength(Pref)) &&
987 (strcmp(pch, ChrPtr(Pref)) == 0));
991 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
995 if (!get_PREFERENCE(TKEY(2), &Pref) ||
1003 /********************************************************************************
1004 * preferences stored discrete in citserver
1005 ********************************************************************************/
1006 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
1009 HashList *List = NULL;
1016 StrBuf_ServGetln(Rcp);
1017 if (GetServerStatus(Rcp, NULL) == 1) {
1019 List = NewHash(1, NULL);
1020 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1021 if ( (StrLength(Rcp)==3) &&
1022 !strcmp(ChrPtr(Rcp), "000"))
1027 i = snprintf(N, sizeof(N), "%d", n);
1029 Put(List, N, i, Rcp, HFreeStrBuf);
1038 void DeleteGVEAHash(HashList **KillMe)
1043 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1046 HashList *List = NULL;
1053 StrBuf_ServGetln(Rcp);
1054 if (GetServerStatus(Rcp, NULL) == 1) {
1056 List = NewHash(1, NULL);
1057 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1058 if ( (StrLength(Rcp)==3) &&
1059 !strcmp(ChrPtr(Rcp), "000"))
1064 i = snprintf(N, sizeof(N), "%d", n);
1066 Put(List, N, i, Rcp, HFreeStrBuf);
1075 void DeleteGVSNHash(HashList **KillMe)
1084 * Offer to make any page the user's "start page" (only if logged in)
1086 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1088 if (WC->logged_in) {
1089 wc_printf("<a href=\"change_start_page?startpage=");
1090 urlescputs(ChrPtr(WC->Hdr->this_page));
1092 wc_printf(_("Make this my start page"));
1099 * Change the user's start page
1101 void change_start_page(void)
1105 int ProhibitSave = 0;
1106 const StrBuf *pStartPage = sbstr("startpage");
1108 if (pStartPage != NULL) {
1109 pch = strchr(ChrPtr(pStartPage), '?');
1111 if ((pch != NULL) && (
1112 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1113 (vHandler != NULL) &&
1114 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1115 { /* OK, This handler doesn't want to be set as start page, prune it. */
1120 if ((pStartPage == NULL) ||
1121 (ProhibitSave == 1))
1123 set_preference_backend(HKEY("startpage"),
1125 NewStrBufPlain(HKEY("")),
1129 if (ProhibitSave == 1)
1130 AppendImportantMessage(_("This isn't allowed to become the start page."), -1);
1132 AppendImportantMessage(_("You no longer have a start page selected."), -1);
1133 display_main_menu();
1139 set_preference_backend(HKEY("startpage"),
1141 NewStrBufDup(pStartPage),
1146 output_headers(1, 1, 0, 0, 0, 0);
1147 do_template("newstartpage");
1152 void LoadStartpage(StrBuf *URL, long lvalue)
1156 pch = strchr(ChrPtr(URL), '?');
1158 /* purge the sins of the past... */
1159 pch = strchr(ChrPtr(URL), '&');
1161 StrBufPeek(URL, pch, -1, '?');
1162 WC->SavePrefsToServer = 1;
1165 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1166 (vHandler != NULL) &&
1167 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1168 { /* OK, This handler doesn't want to be set as start page, prune it. */
1170 WC->SavePrefsToServer = 1;
1176 InitModule_PREFERENCES
1179 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1180 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1182 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1184 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1185 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1186 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1187 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1189 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1191 RegisterConditional("COND:PREF", 4, ConditionalPreference, CTX_NONE);
1192 RegisterConditional("COND:PREF:SET", 4, ConditionalHasPreference, CTX_NONE);
1193 RegisterConditional("COND:ROOM:SET", 4, ConditionalHasRoomPreference, CTX_NONE);
1195 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1196 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1197 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1198 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1204 ServerStartModule_PREFERENCES
1207 PreferenceHooks = NewHash(1, NULL);
1213 ServerShutdownModule_PREFERENCES
1216 DeleteHash(&PreferenceHooks);
1220 SessionDetachModule__PREFERENCES
1223 if (sess->SavePrefsToServer) {
1225 sess->SavePrefsToServer = 0;
1230 SessionNewModule_PREFERENCES
1233 sess->hash_prefs = NewHash(1,NULL);
1237 SessionDestroyModule_PREFERENCES
1240 DeleteHash(&sess->hash_prefs);