4 * Manage user preferences with a little help from the Citadel server.
12 HashList *PreferenceHooks;
13 extern HashList *HandlerHash;
15 typedef struct _PrefDef {
23 typedef struct _Preference {
25 ePrefType eFlatPrefType;
35 void DestroyPrefDef(void *vPrefDef)
37 PrefDef *Prefdef = (PrefDef*) vPrefDef;
38 FreeStrBuf(&Prefdef->Setting);
39 FreeStrBuf(&Prefdef->OnLoadName);
43 void DestroyPreference(void *vPref)
45 Preference *Pref = (Preference*) vPref;
46 FreeStrBuf(&Pref->Key);
47 FreeStrBuf(&Pref->Val);
48 FreeStrBuf(&Pref->DeQPed);
52 void _RegisterPreference(const char *Setting, long SettingLen,
56 const char *OnLoadName)
58 PrefDef *Newpref = (PrefDef*) malloc(sizeof(PrefDef));
59 Newpref->Setting = NewStrBufPlain(Setting, SettingLen);
60 Newpref->PrefStr = PrefStr;
61 Newpref->eType = Type;
62 Newpref->OnLoad = OnLoad;
63 if (Newpref->OnLoad != NULL) {
64 Newpref->OnLoadName = NewStrBufPlain(OnLoadName, -1);
67 Newpref->OnLoadName = NULL;
68 Put(PreferenceHooks, Setting, SettingLen, Newpref, DestroyPrefDef);
71 const char *PrefGetLocalStr(const char *Setting, long len)
74 if (GetHash(PreferenceHooks, Setting, len, &hash_value) != 0) {
75 PrefDef *Newpref = (PrefDef*) hash_value;
76 return _(Newpref->PrefStr);
83 inline const char *PrintPref(void *vPref)
85 Preference *Pref = (Preference*) vPref;
86 if (Pref->DeQPed != NULL)
87 return ChrPtr(Pref->DeQPed);
89 return ChrPtr(Pref->Val);
93 void GetPrefTypes(HashList *List)
103 It = GetNewHashPos(List, 0);
104 while (GetNextHashPos(List, It, &len, &Key, &vSetting))
106 Pref = (Preference*) vSetting;
107 if (GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
110 PrefType = (PrefDef*) vPrefDef;
111 Pref->Type = PrefType;
112 Pref->eFlatPrefType = Pref->Type->eType;
114 lprintf(1, "Loading [%s]with type [%ld] [\"%s\"]\n",
119 switch (Pref->Type->eType)
121 case PRF_UNSET: /* WHUT? */
126 Pref->lval = StrTol(Pref->Val);
130 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
131 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
135 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
140 if (PrefType->OnLoad != NULL){
142 lprintf(1, "Loading with: -> %s(\"%s\", %ld)\n",
143 ChrPtr(PrefType->OnLoadName),
146 PrefType->OnLoad(Pref->Val, Pref->lval);
153 void ParsePref(HashList **List, StrBuf *ReadBuf)
155 Preference *Data = NULL;
156 Preference *LastData = NULL;
159 if (StrBuf_ServGetln(ReadBuf) < 0)
161 if ( (StrLength(ReadBuf)==3) &&
162 !strcmp(ChrPtr(ReadBuf), "000")) {
166 if ((ChrPtr(ReadBuf)[0] == ' ') &&
167 (LastData != NULL)) {
168 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
171 LastData = Data = malloc(sizeof(Preference));
172 memset(Data, 0, sizeof(Preference));
173 Data->Key = NewStrBuf();
174 Data->Val = NewStrBuf();
175 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
176 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
177 if (!IsEmptyStr(ChrPtr(Data->Key)))
187 lprintf(1, "ignoring spurious preference line: [%s]\n",
189 DestroyPreference(Data);
200 * display preferences dialog
202 void load_preferences(void)
209 memset(&Room, 0, sizeof(folder));
210 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
211 if (goto_config_room(ReadBuf, &Room) != 0) {
212 FreeStrBuf(&ReadBuf);
215 return; /* oh well. */
218 serv_puts("MSGS ALL|0|1");
219 StrBuf_ServGetln(ReadBuf);
220 if (GetServerStatus(ReadBuf, NULL) == 8) {
221 serv_puts("subj|__ WebCit Preferences __");
224 while (StrBuf_ServGetln(ReadBuf) >= 0) {
225 if ( (StrLength(ReadBuf)==3) &&
226 !strcmp(ChrPtr(ReadBuf), "000")) {
229 msgnum = StrTol(ReadBuf);
233 serv_printf("MSG0 %ld", msgnum);
234 StrBuf_ServGetln(ReadBuf);
235 if (GetServerStatus(ReadBuf, NULL) == 1) {
236 while ((StrBuf_ServGetln(ReadBuf) >= 0) &&
237 (strcmp(ChrPtr(ReadBuf), "text") &&
238 strcmp(ChrPtr(ReadBuf), "000"))) {
240 if (!strcmp(ChrPtr(ReadBuf), "text")) {
241 ParsePref(&WCC->hash_prefs, ReadBuf);
246 /* Go back to the room we're supposed to be in */
247 if (StrLength(WCC->CurRoom.name) > 0) {
248 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
249 StrBuf_ServGetln(ReadBuf);
250 GetServerStatus(ReadBuf, NULL);
252 FreeStrBuf(&ReadBuf);
257 * Goto the user's configuration room, creating it if necessary.
258 * returns 0 on success or nonzero upon failure.
260 int goto_config_room(StrBuf *Buf, folder *Room)
262 serv_printf("GOTO %s", USERCONFIGROOM);
263 StrBuf_ServGetln(Buf);
264 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
265 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
266 StrBuf_ServGetln(Buf);
267 GetServerStatus(Buf, NULL);
269 serv_printf("GOTO %s", USERCONFIGROOM);
270 StrBuf_ServGetln(Buf);
271 if (GetServerStatus(Buf, NULL) != 2) {
275 ParseGoto(Room, Buf);
279 void WritePrefsToServer(HashList *Hash)
287 StrBuf *SubBuf = NULL;
289 Hash = WCC->hash_prefs;
290 #ifdef DBG_PREFS_HASH
291 dbg_PrintHash(Hash, PrintPref, NULL);
293 HashPos = GetNewHashPos(Hash, 0);
294 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
299 Pref = (Preference*) vPref;
300 nchars = StrLength(Pref->Val);
303 size_t offset, nchars;
305 SubBuf = NewStrBufPlain(NULL, SIZ);
314 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
317 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
319 serv_printf(" %s", ChrPtr(SubBuf));
322 nchars = StrLength(Pref->Val) - offset;
328 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
332 DeleteHashPos(&HashPos);
336 * \brief save the modifications
338 void save_preferences(void)
345 ReadBuf = NewStrBuf();
346 memset(&Room, 0, sizeof(folder));
347 if (goto_config_room(ReadBuf, &Room) != 0) {
348 FreeStrBuf(&ReadBuf);
351 return; /* oh well. */
354 /* make shure the config room has the right type, else it might reject our config */
355 if (Room.view != VIEW_BBS) {
356 serv_printf("VIEW %d", VIEW_BBS);
357 StrBuf_ServGetln(ReadBuf);
358 if (GetServerStatus(ReadBuf, NULL) != 2) {
361 else if (goto_config_room(ReadBuf, &Room) != 0) {
362 FreeStrBuf(&ReadBuf);
365 return; /* oh well. */
369 serv_puts("MSGS ALL|0|1");
370 StrBuf_ServGetln(ReadBuf);
371 if (GetServerStatus(ReadBuf, NULL) == 8) {
372 serv_puts("subj|__ WebCit Preferences __");
375 while (StrBuf_ServGetln(ReadBuf) >= 0) {
376 if ( (StrLength(ReadBuf)==3) &&
377 !strcmp(ChrPtr(ReadBuf), "000")) {
380 msgnum = StrTol(ReadBuf);
384 serv_printf("DELE %ld", msgnum);
385 StrBuf_ServGetln(ReadBuf);
386 GetServerStatus(ReadBuf, NULL);
389 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
390 StrBuf_ServGetln(ReadBuf);
391 if (GetServerStatus(ReadBuf, NULL) == 4) {
393 WritePrefsToServer(WCC->hash_prefs);
398 /** Go back to the room we're supposed to be in */
399 if (StrLength(WCC->CurRoom.name) > 0) {
400 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
401 StrBuf_ServGetln(ReadBuf);
402 GetServerStatus(ReadBuf, NULL);
404 FreeStrBuf(&ReadBuf);
409 * \brief query the actual setting of key in the citadel database
410 * \param key config key to query
411 * \param keylen length of the key string
412 * \param value StrBuf-value to the key to get
415 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
417 void *hash_value = NULL;
418 #ifdef DBG_PREFS_HASH
419 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
421 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
426 *Pref = (Preference*) hash_value;
431 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
436 Ret = get_pref_backend(key, keylen, &Pref);
445 * \brief Write a key into the webcit preferences database for this user
447 * \params key key whichs value is to be modified
448 * \param keylen length of the key string
449 * \param value value to set
450 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
452 long compare_preference(const Preference *PrefA,
453 const Preference *PrefB)
455 ePrefType TypeA, TypeB;
457 if (PrefA->Type != NULL)
458 TypeA = PrefA->Type->eType;
460 TypeA = PrefA->eFlatPrefType;
462 if (PrefB->Type != NULL)
463 TypeB = PrefB->Type->eType;
465 TypeB = PrefB->eFlatPrefType;
467 if ((TypeA != PRF_UNSET) &&
468 (TypeB != PRF_UNSET) &&
473 else /* (PrefA->Type < PrefB->Type) */
477 if (TypeB == PRF_UNSET)
485 return strcmp(ChrPtr(PrefA->Val),
489 if (PrefA->lval == PrefB->lval)
491 else if (PrefA->lval > PrefB->lval)
496 return strcmp(ChrPtr(PrefA->DeQPed),
497 ChrPtr(PrefB->DeQPed));
502 * \brief Write a key into the webcit preferences database for this user
504 * \params key key whichs value is to be modified
505 * \param keylen length of the key string
506 * \param value value to set
507 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
509 void set_preference_backend(const char *key, size_t keylen,
521 Pref = (Preference*) malloc(sizeof(Preference));
522 memset(Pref, 0, sizeof(Preference));
523 Pref->Key = NewStrBufPlain(key, keylen);
525 if ((PrefType == NULL) &&
526 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
528 PrefType = (PrefDef*) vPrefDef;
530 if (PrefType != NULL)
532 Pref->Type = PrefType;
533 Pref->eFlatPrefType = PrefType->eType;
534 if (Pref->Type->eType != lPrefType)
535 lprintf(1, "warning: saving preference with wrong type [%s] %ld != %ld \n",
536 key, Pref->Type->eType, lPrefType);
537 switch (Pref->Type->eType)
539 case PRF_UNSET: /* default to string... */
547 if (Pref->Val == NULL)
548 Pref->Val = NewStrBufPlain(NULL, 64);
549 StrBufPrintf(Pref->Val, "%ld", lvalue);
553 Pref->DeQPed = value;
554 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
555 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
561 Pref->Val = NewStrBufPlain(HKEY("yes"));
563 Pref->Val = NewStrBufPlain(HKEY("no"));
567 if (Pref->Type->OnLoad != NULL)
568 Pref->Type->OnLoad(Pref->Val, Pref->lval);
571 Pref->eFlatPrefType = lPrefType;
581 if (Pref->Val == NULL)
582 Pref->Val = NewStrBufPlain(NULL, 64);
583 StrBufPrintf(Pref->Val, "%ld", lvalue);
587 Pref->DeQPed = value;
588 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
589 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
595 Pref->Val = NewStrBufPlain(HKEY("yes"));
597 Pref->Val = NewStrBufPlain(HKEY("no"));
603 if ((save_to_server != 0) &&
604 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
606 (compare_preference (Pref, vPrefB) == 0))
609 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
611 if (save_to_server) WCC->SavePrefsToServer = 1;
614 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
616 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
619 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
624 Ret = get_pref_backend(key, keylen, &Pref);
633 *value = Pref->lval = atol(ChrPtr(Pref->Val));
640 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
642 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
645 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
650 Ret = get_pref_backend(key, keylen, &Pref);
659 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
665 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
667 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
670 int get_room_prefs_backend(const char *key, size_t keylen,
676 pref_name = NewStrBufPlain (HKEY("ROOM:"));
677 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
678 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
679 StrBufAppendBufPlain(pref_name, key, keylen, 0);
680 Ret = get_pref_backend(SKEY(pref_name), Pref);
681 FreeStrBuf(&pref_name);
686 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
687 const char *xkey, size_t xkeylen)
693 pref_name = NewStrBufPlain (HKEY("XPREF:"));
694 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
695 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
696 StrBufAppendBufPlain(pref_name, key, keylen, 0);
698 ret = get_pref_backend(SKEY(pref_name), &Prf);
699 FreeStrBuf(&pref_name);
706 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
710 pref_name = NewStrBufPlain (HKEY("XPREF:"));
711 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
712 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
713 StrBufAppendBufPlain(pref_name, key, keylen, 0);
715 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
716 FreeStrBuf(&pref_name);
720 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
725 Ret = get_room_prefs_backend(key, keylen, &Pref);
735 *value = Pref->lval = atol(ChrPtr(Pref->Val));
742 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
747 Ret = get_room_prefs_backend(key, keylen, &Pref);
756 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
760 pref_name = NewStrBufPlain (HKEY("ROOM:"));
761 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
762 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
763 StrBufAppendBufPlain(pref_name, key, keylen, 0);
764 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
765 FreeStrBuf(&pref_name);
769 void GetPreferences(HashList *Setting)
781 Tmp = WCC->hash_prefs;
782 WCC->hash_prefs = Setting;
784 It = GetNewHashPos(PreferenceHooks, 0);
785 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
786 PrefType = (PrefDef*) vSetting;
788 if (!HaveBstr(SKEY(PrefType->Setting)))
790 switch (PrefType->eType) {
793 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
794 set_preference_backend(SKEY(PrefType->Setting),
802 lval = LBstr(SKEY(PrefType->Setting));
803 set_preference_backend(SKEY(PrefType->Setting),
811 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
812 set_preference_backend(SKEY(PrefType->Setting),
820 lval = YesBstr(SKEY(PrefType->Setting));
821 set_preference_backend(SKEY(PrefType->Setting),
830 WCC->hash_prefs = Tmp;
836 * \brief Commit new preferences and settings
838 void set_preferences(void)
840 if (!havebstr("change_button")) {
841 safestrncpy(WC->ImportantMessage,
842 _("Cancelled. No settings were changed."),
843 sizeof WC->ImportantMessage);
847 GetPreferences(WC->hash_prefs);
852 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
855 if (get_pref_backend(TKEY(0), &Pref))
857 if (Pref->Type == NULL) {
858 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
860 else switch (Pref->Type->eType)
862 case PRF_UNSET: /* default to string... */
864 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
867 if (Pref->decoded != 1) {
868 if (Pref->Val == NULL)
869 Pref->Val = NewStrBufPlain(NULL, 64);
870 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
873 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
876 if (Pref->decoded != 1) {
877 if (Pref->DeQPed == NULL)
878 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
880 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
883 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
886 if (Pref->decoded != 1) {
887 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
890 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
896 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
898 const char *SettingStr;
899 SettingStr = PrefGetLocalStr(TKEY(0));
900 if (SettingStr != NULL)
901 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
903 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
909 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
910 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
911 StrBufAppendPrintf(Target, "%ld", lvalue);
913 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
915 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
917 StrBufAppendBuf(Target, pref, 0);
919 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
921 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
922 TP->Tokens->Params[0]->len) != NULL)
928 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
932 if (!get_PREFERENCE(TKEY(2), &Pref))
935 if (!HAVE_PARAM(3)) {
938 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
940 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
947 GetTemplateTokenString(Target, TP, 3, &pch, &len);
949 return ((len == StrLength(Pref)) &&
950 (strcmp(pch, ChrPtr(Pref)) == 0));
954 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
958 if (!get_PREFERENCE(TKEY(2), &Pref) ||
966 /********************************************************************************
967 * preferences stored discrete in citserver
968 ********************************************************************************/
969 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
972 HashList *List = NULL;
979 StrBuf_ServGetln(Rcp);
980 if (GetServerStatus(Rcp, NULL) == 1) {
982 List = NewHash(1, NULL);
983 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
984 if ( (StrLength(Rcp)==3) &&
985 !strcmp(ChrPtr(Rcp), "000"))
990 i = snprintf(N, sizeof(N), "%d", n);
992 Put(List, N, i, Rcp, HFreeStrBuf);
1001 void DeleteGVEAHash(HashList **KillMe)
1006 HashList *GetGVSNHash(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 DeleteGVSNHash(HashList **KillMe)
1047 * Offer to make any page the user's "start page."
1049 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1051 wc_printf("<a href=\"change_start_page?startpage=");
1052 urlescputs(ChrPtr(WC->Hdr->this_page));
1054 wc_printf(_("Make this my start page"));
1060 * Change the user's start page
1062 void change_start_page(void)
1064 wcsession *WCC = WC;
1067 int ProhibitSave = 0;
1068 const StrBuf *pStartPage = sbstr("startpage");
1070 if (pStartPage != NULL) {
1071 pch = strchr(ChrPtr(pStartPage), '?');
1073 if ((pch != NULL) && (
1074 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1075 (vHandler != NULL) &&
1076 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1077 { /* OK, This handler doesn't want to be set as start page, prune it. */
1082 if ((pStartPage == NULL) ||
1083 (ProhibitSave == 1))
1085 set_preference_backend(HKEY("startpage"),
1087 NewStrBufPlain(HKEY("")),
1091 if (ProhibitSave == 1)
1092 StrBufAppendBufPlain(WCC->ImportantMsg,
1093 _("This isn't allowed to become the start page."),
1096 StrBufAppendBufPlain(WCC->ImportantMsg,
1097 _("You no longer have a start page selected."),
1099 display_main_menu();
1105 set_preference_backend(HKEY("startpage"),
1107 NewStrBufDup(pStartPage),
1112 output_headers(1, 1, 0, 0, 0, 0);
1113 do_template("newstartpage", NULL);
1118 void LoadStartpage(StrBuf *URL, long lvalue)
1122 pch = strchr(ChrPtr(URL), '?');
1124 /* purge the sins of the past... */
1125 pch = strchr(ChrPtr(URL), '&');
1127 StrBufPeek(URL, pch, -1, '?');
1128 WC->SavePrefsToServer = 1;
1131 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1132 (vHandler != NULL) &&
1133 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1134 { /* OK, This handler doesn't want to be set as start page, prune it. */
1136 WC->SavePrefsToServer = 1;
1142 InitModule_PREFERENCES
1145 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1146 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1148 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1150 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1151 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1152 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1153 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1155 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1157 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1158 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1159 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1161 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1162 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1163 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1164 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1170 ServerStartModule_PREFERENCES
1173 PreferenceHooks = NewHash(1, NULL);
1179 ServerShutdownModule_PREFERENCES
1182 DeleteHash(&PreferenceHooks);
1186 SessionDetachModule__PREFERENCES
1189 if (sess->SavePrefsToServer) {
1191 sess->SavePrefsToServer = 0;
1196 SessionNewModule_PREFERENCES
1199 sess->hash_prefs = NewHash(1,NULL);
1203 SessionDestroyModule_PREFERENCES
1206 DeleteHash(&sess->hash_prefs);