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)
156 Preference *Data = NULL;
157 Preference *LastData = NULL;
160 if (StrBuf_ServGetln(ReadBuf) < 0)
162 if ( (StrLength(ReadBuf)==3) &&
163 !strcmp(ChrPtr(ReadBuf), "000")) {
168 if ((ChrPtr(ReadBuf)[0] == ' ') &&
169 (LastData != NULL)) {
170 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
173 LastData = Data = malloc(sizeof(Preference));
174 memset(Data, 0, sizeof(Preference));
175 Data->Key = NewStrBuf();
176 Data->Val = NewStrBuf();
177 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
178 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
179 if (!IsEmptyStr(ChrPtr(Data->Key)))
189 lprintf(1, "ignoring spurious preference line: [%s]\n",
191 DestroyPreference(Data);
202 * display preferences dialog
204 void load_preferences(void)
212 memset(&Room, 0, sizeof(folder));
213 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
214 if (goto_config_room(ReadBuf, &Room) != 0) {
215 FreeStrBuf(&ReadBuf);
218 return; /* oh well. */
221 serv_puts("MSGS ALL|0|1");
222 StrBuf_ServGetln(ReadBuf);
223 if (GetServerStatus(ReadBuf, NULL) == 8) {
224 serv_puts("subj|__ WebCit Preferences __");
228 (StrBuf_ServGetln(ReadBuf) >= 0)) {
229 if ( (StrLength(ReadBuf)==3) &&
230 !strcmp(ChrPtr(ReadBuf), "000")) {
234 msgnum = StrTol(ReadBuf);
238 serv_printf("MSG0 %ld", msgnum);
239 StrBuf_ServGetln(ReadBuf);
240 if (GetServerStatus(ReadBuf, NULL) == 1) {
241 while ((StrBuf_ServGetln(ReadBuf) >= 0) &&
242 (strcmp(ChrPtr(ReadBuf), "text") &&
243 strcmp(ChrPtr(ReadBuf), "000"))) {
245 if (!strcmp(ChrPtr(ReadBuf), "text")) {
246 ParsePref(&WCC->hash_prefs, ReadBuf);
251 /* Go back to the room we're supposed to be in */
252 if (StrLength(WCC->CurRoom.name) > 0) {
253 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
254 StrBuf_ServGetln(ReadBuf);
255 GetServerStatus(ReadBuf, NULL);
257 FreeStrBuf(&ReadBuf);
262 * Goto the user's configuration room, creating it if necessary.
263 * returns 0 on success or nonzero upon failure.
265 int goto_config_room(StrBuf *Buf, folder *Room)
267 serv_printf("GOTO %s", USERCONFIGROOM);
268 StrBuf_ServGetln(Buf);
269 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
270 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
271 StrBuf_ServGetln(Buf);
272 GetServerStatus(Buf, NULL);
274 serv_printf("GOTO %s", USERCONFIGROOM);
275 StrBuf_ServGetln(Buf);
276 if (GetServerStatus(Buf, NULL) != 2) {
280 ParseGoto(Room, Buf);
284 void WritePrefsToServer(HashList *Hash)
292 StrBuf *SubBuf = NULL;
294 Hash = WCC->hash_prefs;
295 #ifdef DBG_PREFS_HASH
296 dbg_PrintHash(Hash, PrintPref, NULL);
298 HashPos = GetNewHashPos(Hash, 0);
299 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
304 Pref = (Preference*) vPref;
305 nchars = StrLength(Pref->Val);
308 size_t offset, nchars;
310 SubBuf = NewStrBufPlain(NULL, SIZ);
319 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
322 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
324 serv_printf(" %s", ChrPtr(SubBuf));
327 nchars = StrLength(Pref->Val) - offset;
333 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
337 DeleteHashPos(&HashPos);
341 * \brief save the modifications
343 void save_preferences(void)
351 ReadBuf = NewStrBuf();
352 memset(&Room, 0, sizeof(folder));
353 if (goto_config_room(ReadBuf, &Room) != 0) {
354 FreeStrBuf(&ReadBuf);
357 return; /* oh well. */
360 /* make shure the config room has the right type, else it might reject our config */
361 if (Room.view != VIEW_BBS) {
362 serv_printf("VIEW %d", VIEW_BBS);
363 StrBuf_ServGetln(ReadBuf);
364 if (GetServerStatus(ReadBuf, NULL) != 2) {
367 else if (goto_config_room(ReadBuf, &Room) != 0) {
368 FreeStrBuf(&ReadBuf);
371 return; /* oh well. */
375 serv_puts("MSGS ALL|0|1");
376 StrBuf_ServGetln(ReadBuf);
377 if (GetServerStatus(ReadBuf, NULL) == 8) {
378 serv_puts("subj|__ WebCit Preferences __");
382 (StrBuf_ServGetln(ReadBuf) >= 0)) {
383 if ( (StrLength(ReadBuf)==3) &&
384 !strcmp(ChrPtr(ReadBuf), "000")) {
388 msgnum = StrTol(ReadBuf);
392 serv_printf("DELE %ld", msgnum);
393 StrBuf_ServGetln(ReadBuf);
394 GetServerStatus(ReadBuf, NULL);
397 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
398 StrBuf_ServGetln(ReadBuf);
399 if (GetServerStatus(ReadBuf, NULL) == 4) {
401 WritePrefsToServer(WCC->hash_prefs);
406 /** Go back to the room we're supposed to be in */
407 if (StrLength(WCC->CurRoom.name) > 0) {
408 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
409 StrBuf_ServGetln(ReadBuf);
410 GetServerStatus(ReadBuf, NULL);
412 FreeStrBuf(&ReadBuf);
417 * \brief query the actual setting of key in the citadel database
418 * \param key config key to query
419 * \param keylen length of the key string
420 * \param value StrBuf-value to the key to get
423 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
425 void *hash_value = NULL;
426 #ifdef DBG_PREFS_HASH
427 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
429 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
434 *Pref = (Preference*) hash_value;
439 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
444 Ret = get_pref_backend(key, keylen, &Pref);
453 * \brief Write a key into the webcit preferences database for this user
455 * \params key key whichs value is to be modified
456 * \param keylen length of the key string
457 * \param value value to set
458 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
460 long compare_preference(const Preference *PrefA,
461 const Preference *PrefB)
463 ePrefType TypeA, TypeB;
465 if (PrefA->Type != NULL)
466 TypeA = PrefA->Type->eType;
468 TypeA = PrefA->eFlatPrefType;
470 if (PrefB->Type != NULL)
471 TypeB = PrefB->Type->eType;
473 TypeB = PrefB->eFlatPrefType;
475 if ((TypeA != PRF_UNSET) &&
476 (TypeB != PRF_UNSET) &&
481 else /* (PrefA->Type < PrefB->Type) */
485 if (TypeB == PRF_UNSET)
493 return strcmp(ChrPtr(PrefA->Val),
497 if (PrefA->lval == PrefB->lval)
499 else if (PrefA->lval > PrefB->lval)
504 return strcmp(ChrPtr(PrefA->DeQPed),
505 ChrPtr(PrefB->DeQPed));
510 * \brief Write a key into the webcit preferences database for this user
512 * \params key key whichs value is to be modified
513 * \param keylen length of the key string
514 * \param value value to set
515 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
517 void set_preference_backend(const char *key, size_t keylen,
529 Pref = (Preference*) malloc(sizeof(Preference));
530 memset(Pref, 0, sizeof(Preference));
531 Pref->Key = NewStrBufPlain(key, keylen);
533 if ((PrefType == NULL) &&
534 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
536 PrefType = (PrefDef*) vPrefDef;
538 if (PrefType != NULL)
540 Pref->Type = PrefType;
541 Pref->eFlatPrefType = PrefType->eType;
542 if (Pref->Type->eType != lPrefType)
543 lprintf(1, "warning: saving preference with wrong type [%s] %ld != %ld \n",
544 key, Pref->Type->eType, lPrefType);
545 switch (Pref->Type->eType)
547 case PRF_UNSET: /* default to string... */
555 if (Pref->Val == NULL)
556 Pref->Val = NewStrBufPlain(NULL, 64);
557 StrBufPrintf(Pref->Val, "%ld", lvalue);
561 Pref->DeQPed = value;
562 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
563 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
569 Pref->Val = NewStrBufPlain(HKEY("yes"));
571 Pref->Val = NewStrBufPlain(HKEY("no"));
575 if (Pref->Type->OnLoad != NULL)
576 Pref->Type->OnLoad(Pref->Val, Pref->lval);
579 Pref->eFlatPrefType = lPrefType;
589 if (Pref->Val == NULL)
590 Pref->Val = NewStrBufPlain(NULL, 64);
591 StrBufPrintf(Pref->Val, "%ld", lvalue);
595 Pref->DeQPed = value;
596 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
597 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
603 Pref->Val = NewStrBufPlain(HKEY("yes"));
605 Pref->Val = NewStrBufPlain(HKEY("no"));
611 if ((save_to_server != 0) &&
612 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
614 (compare_preference (Pref, vPrefB) == 0))
617 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
619 if (save_to_server) WCC->SavePrefsToServer = 1;
622 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
624 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
627 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
632 Ret = get_pref_backend(key, keylen, &Pref);
641 *value = Pref->lval = atol(ChrPtr(Pref->Val));
648 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
650 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
653 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
658 Ret = get_pref_backend(key, keylen, &Pref);
667 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
673 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
675 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
678 int get_room_prefs_backend(const char *key, size_t keylen,
684 pref_name = NewStrBufPlain (HKEY("ROOM:"));
685 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
686 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
687 StrBufAppendBufPlain(pref_name, key, keylen, 0);
688 Ret = get_pref_backend(SKEY(pref_name), Pref);
689 FreeStrBuf(&pref_name);
694 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
695 const char *xkey, size_t xkeylen)
701 pref_name = NewStrBufPlain (HKEY("XPREF:"));
702 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
703 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
704 StrBufAppendBufPlain(pref_name, key, keylen, 0);
706 ret = get_pref_backend(SKEY(pref_name), &Prf);
707 FreeStrBuf(&pref_name);
714 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
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 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
724 FreeStrBuf(&pref_name);
728 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
733 Ret = get_room_prefs_backend(key, keylen, &Pref);
743 *value = Pref->lval = atol(ChrPtr(Pref->Val));
750 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
755 Ret = get_room_prefs_backend(key, keylen, &Pref);
764 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
768 pref_name = NewStrBufPlain (HKEY("ROOM:"));
769 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
770 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
771 StrBufAppendBufPlain(pref_name, key, keylen, 0);
772 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
773 FreeStrBuf(&pref_name);
777 void GetPreferences(HashList *Setting)
789 Tmp = WCC->hash_prefs;
790 WCC->hash_prefs = Setting;
792 It = GetNewHashPos(PreferenceHooks, 0);
793 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
794 PrefType = (PrefDef*) vSetting;
796 if (!HaveBstr(SKEY(PrefType->Setting)))
798 switch (PrefType->eType) {
801 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
802 set_preference_backend(SKEY(PrefType->Setting),
810 lval = LBstr(SKEY(PrefType->Setting));
811 set_preference_backend(SKEY(PrefType->Setting),
819 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
820 set_preference_backend(SKEY(PrefType->Setting),
828 lval = YesBstr(SKEY(PrefType->Setting));
829 set_preference_backend(SKEY(PrefType->Setting),
838 WCC->hash_prefs = Tmp;
844 * \brief Commit new preferences and settings
846 void set_preferences(void)
848 if (!havebstr("change_button")) {
849 safestrncpy(WC->ImportantMessage,
850 _("Cancelled. No settings were changed."),
851 sizeof WC->ImportantMessage);
855 GetPreferences(WC->hash_prefs);
860 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
863 if (get_pref_backend(TKEY(0), &Pref))
865 if (Pref->Type == NULL) {
866 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
868 switch (Pref->Type->eType)
870 case PRF_UNSET: /* default to string... */
872 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
875 if (Pref->decoded != 1) {
876 if (Pref->Val == NULL)
877 Pref->Val = NewStrBufPlain(NULL, 64);
878 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
881 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
884 if (Pref->decoded != 1) {
885 if (Pref->DeQPed == NULL)
886 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
888 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
891 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
894 if (Pref->decoded != 1) {
895 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
898 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
904 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
906 const char *SettingStr;
907 SettingStr = PrefGetLocalStr(TKEY(0));
908 if (SettingStr != NULL)
909 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
911 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
917 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
918 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
919 StrBufAppendPrintf(Target, "%ld", lvalue);
921 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
923 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
925 StrBufAppendBuf(Target, pref, 0);
927 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
929 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
930 TP->Tokens->Params[0]->len) != NULL)
936 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
940 if (!get_PREFERENCE(TKEY(2), &Pref))
943 if (!HAVE_PARAM(3)) {
946 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
948 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
955 GetTemplateTokenString(Target, TP, 3, &pch, &len);
957 return ((len == StrLength(Pref)) &&
958 (strcmp(pch, ChrPtr(Pref)) == 0));
962 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
966 if (!get_PREFERENCE(TKEY(2), &Pref) ||
974 /********************************************************************************
975 * preferences stored discrete in citserver
976 ********************************************************************************/
977 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
980 HashList *List = NULL;
987 StrBuf_ServGetln(Rcp);
988 if (GetServerStatus(Rcp, NULL) == 1) {
990 List = NewHash(1, NULL);
991 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
992 if ( (StrLength(Rcp)==3) &&
993 !strcmp(ChrPtr(Rcp), "000"))
998 i = snprintf(N, sizeof(N), "%d", n);
1000 Put(List, N, i, Rcp, HFreeStrBuf);
1009 void DeleteGVEAHash(HashList **KillMe)
1014 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1017 HashList *List = NULL;
1024 StrBuf_ServGetln(Rcp);
1025 if (GetServerStatus(Rcp, NULL) == 1) {
1027 List = NewHash(1, NULL);
1028 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1029 if ( (StrLength(Rcp)==3) &&
1030 !strcmp(ChrPtr(Rcp), "000"))
1035 i = snprintf(N, sizeof(N), "%d", n);
1037 Put(List, N, i, Rcp, HFreeStrBuf);
1046 void DeleteGVSNHash(HashList **KillMe)
1055 * Offer to make any page the user's "start page."
1057 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1059 wc_printf("<a href=\"change_start_page?startpage=");
1060 urlescputs(ChrPtr(WC->Hdr->this_page));
1062 wc_printf(_("Make this my start page"));
1068 * Change the user's start page
1070 void change_start_page(void)
1072 wcsession *WCC = WC;
1075 int ProhibitSave = 0;
1076 const StrBuf *pStartPage = sbstr("startpage");
1078 if (pStartPage != NULL) {
1079 pch = strchr(ChrPtr(pStartPage), '?');
1081 if ((pch != NULL) && (
1082 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1083 (vHandler != NULL) &&
1084 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1085 { /* OK, This handler doesn't want to be set as start page, prune it. */
1090 if ((pStartPage == NULL) ||
1091 (ProhibitSave == 1))
1093 set_preference_backend(HKEY("startpage"),
1095 NewStrBufPlain(HKEY("")),
1099 if (ProhibitSave == 1)
1100 StrBufAppendBufPlain(WCC->ImportantMsg,
1101 _("This isn't allowed to become the start page."),
1104 StrBufAppendBufPlain(WCC->ImportantMsg,
1105 _("You no longer have a start page selected."),
1107 display_main_menu();
1113 set_preference_backend(HKEY("startpage"),
1115 NewStrBufDup(pStartPage),
1120 output_headers(1, 1, 0, 0, 0, 0);
1121 do_template("newstartpage", NULL);
1126 void LoadStartpage(StrBuf *URL, long lvalue)
1130 pch = strchr(ChrPtr(URL), '?');
1132 /* purge the sins of the past... */
1133 pch = strchr(ChrPtr(URL), '&');
1135 StrBufPeek(URL, pch, -1, '?');
1136 WC->SavePrefsToServer = 1;
1139 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1140 (vHandler != NULL) &&
1141 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1142 { /* OK, This handler doesn't want to be set as start page, prune it. */
1144 WC->SavePrefsToServer = 1;
1150 InitModule_PREFERENCES
1153 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1154 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1156 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1158 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1159 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1160 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1161 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1163 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1165 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1166 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1167 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1169 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1170 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1171 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1172 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1178 ServerStartModule_PREFERENCES
1181 PreferenceHooks = NewHash(1, NULL);
1187 ServerShutdownModule_PREFERENCES
1190 DeleteHash(&PreferenceHooks);
1194 SessionDetachModule__PREFERENCES
1197 if (sess->SavePrefsToServer) {
1199 sess->SavePrefsToServer = 0;
1204 SessionNewModule_PREFERENCES
1207 sess->hash_prefs = NewHash(1,NULL);
1211 SessionDestroyModule_PREFERENCES
1214 DeleteHash(&sess->hash_prefs);