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, '|');
187 if (!IsEmptyStr(ChrPtr(Data->Key)))
197 syslog(1, "ignoring spurious preference line: [%s]\n",
199 DestroyPreference(Data);
210 * display preferences dialog
212 void load_preferences(void)
220 memset(&Room, 0, sizeof(folder));
221 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
222 if (goto_config_room(ReadBuf, &Room) != 0) {
223 FreeStrBuf(&ReadBuf);
226 return; /* oh well. */
229 serv_puts("MSGS ALL|0|1");
230 StrBuf_ServGetln(ReadBuf);
231 if (GetServerStatus(ReadBuf, NULL) == 8) {
232 serv_puts("subj|__ WebCit Preferences __");
235 while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
236 if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
240 msgnum = StrTol(ReadBuf);
244 serv_printf("MSG0 %ld", msgnum);
245 StrBuf_ServGetln(ReadBuf);
246 if (GetServerStatus(ReadBuf, NULL) == 1) {
247 while ( (StrBuf_ServGetln(ReadBuf) >= 0)
248 && (strcmp(ChrPtr(ReadBuf), "text")
249 && strcmp(ChrPtr(ReadBuf), "000"))
253 if (!strcmp(ChrPtr(ReadBuf), "text")) {
254 ParsePref(&WCC->hash_prefs, ReadBuf);
259 /* Go back to the room we're supposed to be in */
260 if (StrLength(WCC->CurRoom.name) > 0) {
261 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
262 StrBuf_ServGetln(ReadBuf);
263 GetServerStatus(ReadBuf, NULL);
265 FreeStrBuf(&ReadBuf);
271 * Go to the user's configuration room, creating it if necessary.
272 * returns 0 on success or nonzero upon failure.
274 int goto_config_room(StrBuf *Buf, folder *Room)
276 serv_printf("GOTO %s", USERCONFIGROOM);
277 StrBuf_ServGetln(Buf);
278 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
279 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
280 StrBuf_ServGetln(Buf);
281 GetServerStatus(Buf, NULL);
283 serv_printf("GOTO %s", USERCONFIGROOM);
284 StrBuf_ServGetln(Buf);
285 if (GetServerStatus(Buf, NULL) != 2) {
289 ParseGoto(Room, Buf);
293 void WritePrefsToServer(HashList *Hash)
301 StrBuf *SubBuf = NULL;
303 Hash = WCC->hash_prefs;
304 #ifdef DBG_PREFS_HASH
305 dbg_PrintHash(Hash, PrintPref, NULL);
307 HashPos = GetNewHashPos(Hash, 0);
308 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
313 Pref = (Preference*) vPref;
314 nchars = StrLength(Pref->Val);
317 size_t offset, nchars;
319 SubBuf = NewStrBufPlain(NULL, SIZ);
328 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
331 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
334 serv_printf(" %s", ChrPtr(SubBuf));
338 nchars = StrLength(Pref->Val) - offset;
344 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
349 DeleteHashPos(&HashPos);
353 * save the modifications
355 void save_preferences(void)
363 ReadBuf = NewStrBuf();
364 memset(&Room, 0, sizeof(folder));
365 if (goto_config_room(ReadBuf, &Room) != 0) {
366 FreeStrBuf(&ReadBuf);
369 return; /* oh well. */
372 /* make shure the config room has the right type, else it might reject our config */
373 if (Room.view != VIEW_BBS) {
374 serv_printf("VIEW %d", VIEW_BBS);
375 StrBuf_ServGetln(ReadBuf);
376 if (GetServerStatus(ReadBuf, NULL) != 2) {
379 else if (goto_config_room(ReadBuf, &Room) != 0) {
380 FreeStrBuf(&ReadBuf);
383 return; /* oh well. */
387 serv_puts("MSGS ALL|0|1");
388 StrBuf_ServGetln(ReadBuf);
389 if (GetServerStatus(ReadBuf, NULL) == 8) {
390 serv_puts("subj|__ WebCit Preferences __");
393 while (!Done && (StrBuf_ServGetln(ReadBuf) >= 0)) {
394 if ( (StrLength(ReadBuf)==3) && !strcmp(ChrPtr(ReadBuf), "000")) {
398 msgnum = StrTol(ReadBuf);
402 serv_printf("DELE %ld", msgnum);
403 StrBuf_ServGetln(ReadBuf);
404 GetServerStatus(ReadBuf, NULL);
407 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
408 StrBuf_ServGetln(ReadBuf);
409 if (GetServerStatus(ReadBuf, NULL) == 4) {
411 WritePrefsToServer(WCC->hash_prefs);
416 /** Go back to the room we're supposed to be in */
417 if (StrLength(WCC->CurRoom.name) > 0) {
418 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
419 StrBuf_ServGetln(ReadBuf);
420 GetServerStatus(ReadBuf, NULL);
422 FreeStrBuf(&ReadBuf);
427 * query the actual setting of key in the citadel database
429 * key config key to query
430 * keylen length of the key string
431 * value StrBuf-value to the key to get
434 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
436 void *hash_value = NULL;
437 #ifdef DBG_PREFS_HASH
438 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
440 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
445 *Pref = (Preference*) hash_value;
450 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
455 Ret = get_pref_backend(key, keylen, &Pref);
464 * Write a key into the webcit preferences database for this user
466 * key key whichs value is to be modified
467 * keylen length of the key string
469 * save_to_server 1 = flush all data to the server, 0 = cache it for now
471 long compare_preference(const Preference *PrefA, const Preference *PrefB)
473 ePrefType TypeA, TypeB;
475 if (PrefA->Type != NULL) {
476 TypeA = PrefA->Type->eType;
479 TypeA = PrefA->eFlatPrefType;
482 if (PrefB->Type != NULL) {
483 TypeB = PrefB->Type->eType;
486 TypeB = PrefB->eFlatPrefType;
489 if ( (TypeA != PRF_UNSET)
490 && (TypeB != PRF_UNSET)
496 else { /* (PrefA->Type < PrefB->Type) */
501 if (TypeB == PRF_UNSET) {
510 return strcmp(ChrPtr(PrefA->Val), ChrPtr(PrefB->Val));
513 if (PrefA->lval == PrefB->lval)
515 else if (PrefA->lval > PrefB->lval)
520 return strcmp(ChrPtr(PrefA->DeQPed),
521 ChrPtr(PrefB->DeQPed));
527 * Write a key into the webcit preferences database for this user
529 * key key which value is to be modified
530 * keylen length of the key string
532 * save_to_server 1 = flush all data to the server, 0 = cache it for now
534 void set_preference_backend(const char *key, size_t keylen,
546 Pref = (Preference*) malloc(sizeof(Preference));
547 memset(Pref, 0, sizeof(Preference));
548 Pref->Key = NewStrBufPlain(key, keylen);
550 if ((PrefType == NULL) &&
551 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
553 PrefType = (PrefDef*) vPrefDef;
555 if (PrefType != NULL)
557 Pref->Type = PrefType;
558 Pref->eFlatPrefType = PrefType->eType;
559 if (Pref->Type->eType != lPrefType)
560 syslog(1, "warning: saving preference with wrong type [%s] %d != %ld \n",
561 key, Pref->Type->eType, lPrefType);
562 switch (Pref->Type->eType)
564 case PRF_UNSET: /* default to string... */
572 if (Pref->Val == NULL)
573 Pref->Val = NewStrBufPlain(NULL, 64);
574 StrBufPrintf(Pref->Val, "%ld", lvalue);
578 Pref->DeQPed = value;
579 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
580 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
586 Pref->Val = NewStrBufPlain(HKEY("yes"));
588 Pref->Val = NewStrBufPlain(HKEY("no"));
592 if (Pref->Type->OnLoad != NULL)
593 Pref->Type->OnLoad(Pref->Val, Pref->lval);
596 Pref->eFlatPrefType = lPrefType;
606 if (Pref->Val == NULL)
607 Pref->Val = NewStrBufPlain(NULL, 64);
608 StrBufPrintf(Pref->Val, "%ld", lvalue);
612 Pref->DeQPed = value;
613 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
614 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
620 Pref->Val = NewStrBufPlain(HKEY("yes"));
622 Pref->Val = NewStrBufPlain(HKEY("no"));
628 if ((save_to_server != 0) &&
629 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
631 (compare_preference (Pref, vPrefB) == 0))
634 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
636 if (save_to_server) WCC->SavePrefsToServer = 1;
639 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
641 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
644 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
649 Ret = get_pref_backend(key, keylen, &Pref);
658 *value = Pref->lval = atol(ChrPtr(Pref->Val));
665 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
667 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
670 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
675 Ret = get_pref_backend(key, keylen, &Pref);
684 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
690 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
692 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
695 int get_room_prefs_backend(const char *key, size_t keylen,
701 pref_name = NewStrBufPlain (HKEY("ROOM:"));
702 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
703 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
704 StrBufAppendBufPlain(pref_name, key, keylen, 0);
705 Ret = get_pref_backend(SKEY(pref_name), Pref);
706 FreeStrBuf(&pref_name);
711 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
712 const char *xkey, size_t xkeylen)
718 pref_name = NewStrBufPlain (HKEY("XPREF:"));
719 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
720 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
721 StrBufAppendBufPlain(pref_name, key, keylen, 0);
723 ret = get_pref_backend(SKEY(pref_name), &Prf);
724 FreeStrBuf(&pref_name);
731 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
735 pref_name = NewStrBufPlain (HKEY("XPREF:"));
736 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
737 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
738 StrBufAppendBufPlain(pref_name, key, keylen, 0);
740 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
741 FreeStrBuf(&pref_name);
745 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
750 Ret = get_room_prefs_backend(key, keylen, &Pref);
760 *value = Pref->lval = atol(ChrPtr(Pref->Val));
767 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
772 Ret = get_room_prefs_backend(key, keylen, &Pref);
781 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
785 pref_name = NewStrBufPlain (HKEY("ROOM:"));
786 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
787 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
788 StrBufAppendBufPlain(pref_name, key, keylen, 0);
789 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
790 FreeStrBuf(&pref_name);
794 void GetPreferences(HashList *Setting)
806 Tmp = WCC->hash_prefs;
807 WCC->hash_prefs = Setting;
809 It = GetNewHashPos(PreferenceHooks, 0);
810 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
811 PrefType = (PrefDef*) vSetting;
813 if (!HaveBstr(SKEY(PrefType->Setting)))
815 switch (PrefType->eType) {
818 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
819 set_preference_backend(SKEY(PrefType->Setting),
827 lval = LBstr(SKEY(PrefType->Setting));
828 set_preference_backend(SKEY(PrefType->Setting),
836 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
837 set_preference_backend(SKEY(PrefType->Setting),
845 lval = YesBstr(SKEY(PrefType->Setting));
846 set_preference_backend(SKEY(PrefType->Setting),
855 WCC->hash_prefs = Tmp;
861 * Commit new preferences and settings
863 void set_preferences(void)
865 if (!havebstr("change_button")) {
866 AppendImportantMessage(_("Cancelled. No settings were changed."), -1);
870 GetPreferences(WC->hash_prefs);
875 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
878 if (get_pref_backend(TKEY(0), &Pref))
880 if (Pref->Type == NULL) {
881 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
883 switch (Pref->Type->eType)
885 case PRF_UNSET: /* default to string... */
887 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
890 if (Pref->decoded != 1) {
891 if (Pref->Val == NULL)
892 Pref->Val = NewStrBufPlain(NULL, 64);
893 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
896 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
899 if (Pref->decoded != 1) {
900 if (Pref->DeQPed == NULL)
901 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
903 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
906 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
909 if (Pref->decoded != 1) {
910 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
913 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
919 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
921 const char *SettingStr;
922 SettingStr = PrefGetLocalStr(TKEY(0));
923 if (SettingStr != NULL)
924 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
926 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
932 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
933 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
934 StrBufAppendPrintf(Target, "%ld", lvalue);
936 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
938 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
940 StrBufAppendBuf(Target, pref, 0);
942 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
944 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
945 TP->Tokens->Params[0]->len) != NULL)
951 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
955 if (!get_PREFERENCE(TKEY(2), &Pref))
958 if (!HAVE_PARAM(3)) {
961 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
963 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
970 GetTemplateTokenString(Target, TP, 3, &pch, &len);
972 return ((len == StrLength(Pref)) &&
973 (strcmp(pch, ChrPtr(Pref)) == 0));
977 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
981 if (!get_PREFERENCE(TKEY(2), &Pref) ||
989 /********************************************************************************
990 * preferences stored discrete in citserver
991 ********************************************************************************/
992 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
995 HashList *List = NULL;
1002 StrBuf_ServGetln(Rcp);
1003 if (GetServerStatus(Rcp, NULL) == 1) {
1005 List = NewHash(1, NULL);
1006 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1007 if ( (StrLength(Rcp)==3) &&
1008 !strcmp(ChrPtr(Rcp), "000"))
1013 i = snprintf(N, sizeof(N), "%d", n);
1015 Put(List, N, i, Rcp, HFreeStrBuf);
1024 void DeleteGVEAHash(HashList **KillMe)
1029 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1032 HashList *List = NULL;
1039 StrBuf_ServGetln(Rcp);
1040 if (GetServerStatus(Rcp, NULL) == 1) {
1042 List = NewHash(1, NULL);
1043 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1044 if ( (StrLength(Rcp)==3) &&
1045 !strcmp(ChrPtr(Rcp), "000"))
1050 i = snprintf(N, sizeof(N), "%d", n);
1052 Put(List, N, i, Rcp, HFreeStrBuf);
1061 void DeleteGVSNHash(HashList **KillMe)
1070 * Offer to make any page the user's "start page" (only if logged in)
1072 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1074 if (WC->logged_in) {
1075 wc_printf("<a href=\"change_start_page?startpage=");
1076 urlescputs(ChrPtr(WC->Hdr->this_page));
1078 wc_printf(_("Make this my start page"));
1085 * Change the user's start page
1087 void change_start_page(void)
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 AppendImportantMessage(_("This isn't allowed to become the start page."), -1);
1118 AppendImportantMessage(_("You no longer have a start page selected."), -1);
1119 display_main_menu();
1125 set_preference_backend(HKEY("startpage"),
1127 NewStrBufDup(pStartPage),
1132 output_headers(1, 1, 0, 0, 0, 0);
1133 do_template("newstartpage");
1138 void LoadStartpage(StrBuf *URL, long lvalue)
1142 pch = strchr(ChrPtr(URL), '?');
1144 /* purge the sins of the past... */
1145 pch = strchr(ChrPtr(URL), '&');
1147 StrBufPeek(URL, pch, -1, '?');
1148 WC->SavePrefsToServer = 1;
1151 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1152 (vHandler != NULL) &&
1153 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1154 { /* OK, This handler doesn't want to be set as start page, prune it. */
1156 WC->SavePrefsToServer = 1;
1162 InitModule_PREFERENCES
1165 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1166 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1168 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1170 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1171 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1172 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1173 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1175 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1177 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1178 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1179 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1181 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1182 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1183 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1184 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1190 ServerStartModule_PREFERENCES
1193 PreferenceHooks = NewHash(1, NULL);
1199 ServerShutdownModule_PREFERENCES
1202 DeleteHash(&PreferenceHooks);
1206 SessionDetachModule__PREFERENCES
1209 if (sess->SavePrefsToServer) {
1211 sess->SavePrefsToServer = 0;
1216 SessionNewModule_PREFERENCES
1219 sess->hash_prefs = NewHash(1,NULL);
1223 SessionDestroyModule_PREFERENCES
1226 DeleteHash(&sess->hash_prefs);