2 * Manage user preferences with a little help from the Citadel server.
9 HashList *PreferenceHooks;
10 extern HashList *HandlerHash;
12 typedef struct _PrefDef {
20 typedef struct _Preference {
22 ePrefType eFlatPrefType;
32 void DestroyPrefDef(void *vPrefDef)
34 PrefDef *Prefdef = (PrefDef*) vPrefDef;
35 FreeStrBuf(&Prefdef->Setting);
36 FreeStrBuf(&Prefdef->OnLoadName);
40 void DestroyPreference(void *vPref)
42 Preference *Pref = (Preference*) vPref;
43 FreeStrBuf(&Pref->Key);
44 FreeStrBuf(&Pref->Val);
45 FreeStrBuf(&Pref->DeQPed);
49 void _RegisterPreference(const char *Setting, long SettingLen,
53 const char *OnLoadName)
55 PrefDef *Newpref = (PrefDef*) malloc(sizeof(PrefDef));
56 Newpref->Setting = NewStrBufPlain(Setting, SettingLen);
57 Newpref->PrefStr = PrefStr;
58 Newpref->eType = Type;
59 Newpref->OnLoad = OnLoad;
60 if (Newpref->OnLoad != NULL) {
61 Newpref->OnLoadName = NewStrBufPlain(OnLoadName, -1);
64 Newpref->OnLoadName = NULL;
65 Put(PreferenceHooks, Setting, SettingLen, Newpref, DestroyPrefDef);
68 const char *PrefGetLocalStr(const char *Setting, long len)
71 if (GetHash(PreferenceHooks, Setting, len, &hash_value) != 0) {
72 PrefDef *Newpref = (PrefDef*) hash_value;
73 return _(Newpref->PrefStr);
80 inline const char *PrintPref(void *vPref)
82 Preference *Pref = (Preference*) vPref;
83 if (Pref->DeQPed != NULL)
84 return ChrPtr(Pref->DeQPed);
86 return ChrPtr(Pref->Val);
90 void GetPrefTypes(HashList *List)
100 It = GetNewHashPos(List, 0);
101 while (GetNextHashPos(List, It, &len, &Key, &vSetting))
103 Pref = (Preference*) vSetting;
104 if (GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
107 PrefType = (PrefDef*) vPrefDef;
108 Pref->Type = PrefType;
109 Pref->eFlatPrefType = Pref->Type->eType;
111 syslog(1, "Loading [%s]with type [%ld] [\"%s\"]\n",
116 switch (Pref->Type->eType)
118 case PRF_UNSET: /* WHUT? */
123 Pref->lval = StrTol(Pref->Val);
127 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
128 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
132 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
137 if (PrefType->OnLoad != NULL){
139 syslog(1, "Loading with: -> %s(\"%s\", %ld)\n",
140 ChrPtr(PrefType->OnLoadName),
143 PrefType->OnLoad(Pref->Val, Pref->lval);
150 void ParsePref(HashList **List, StrBuf *ReadBuf)
153 Preference *Data = NULL;
154 Preference *LastData = NULL;
157 StrBuf_ServGetln(ReadBuf);
158 if ( (StrLength(ReadBuf)==3) &&
159 !strcmp(ChrPtr(ReadBuf), "000")) {
164 if ((ChrPtr(ReadBuf)[0] == ' ') &&
165 (LastData != NULL)) {
166 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
169 LastData = Data = malloc(sizeof(Preference));
170 memset(Data, 0, sizeof(Preference));
171 Data->Key = NewStrBuf();
172 Data->Val = NewStrBuf();
173 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
174 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
175 if (!IsEmptyStr(ChrPtr(Data->Key)))
185 syslog(1, "ignoring spurious preference line: [%s]\n",
187 DestroyPreference(Data);
198 * display preferences dialog
200 void load_preferences(void)
208 memset(&Room, 0, sizeof(folder));
209 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
210 if (goto_config_room(ReadBuf, &Room) != 0) {
211 FreeStrBuf(&ReadBuf);
214 return; /* oh well. */
217 serv_puts("MSGS ALL|0|1");
218 StrBuf_ServGetln(ReadBuf);
219 if (GetServerStatus(ReadBuf, NULL) == 8) {
220 serv_puts("subj|__ WebCit Preferences __");
224 StrBuf_ServGetln(ReadBuf)) {
225 if ( (StrLength(ReadBuf)==3) &&
226 !strcmp(ChrPtr(ReadBuf), "000")) {
230 msgnum = StrTol(ReadBuf);
234 serv_printf("MSG0 %ld", msgnum);
235 StrBuf_ServGetln(ReadBuf);
236 if (GetServerStatus(ReadBuf, NULL) == 1) {
237 while (StrBuf_ServGetln(ReadBuf),
238 (strcmp(ChrPtr(ReadBuf), "text") &&
239 strcmp(ChrPtr(ReadBuf), "000"))) {
241 if (!strcmp(ChrPtr(ReadBuf), "text")) {
242 ParsePref(&WCC->hash_prefs, ReadBuf);
247 /* Go back to the room we're supposed to be in */
248 if (StrLength(WCC->CurRoom.name) > 0) {
249 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
250 StrBuf_ServGetln(ReadBuf);
251 GetServerStatus(ReadBuf, NULL);
253 FreeStrBuf(&ReadBuf);
258 * Goto the user's configuration room, creating it if necessary.
259 * returns 0 on success or nonzero upon failure.
261 int goto_config_room(StrBuf *Buf, folder *Room)
263 serv_printf("GOTO %s", USERCONFIGROOM);
264 StrBuf_ServGetln(Buf);
265 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
266 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
267 StrBuf_ServGetln(Buf);
268 GetServerStatus(Buf, NULL);
270 serv_printf("GOTO %s", USERCONFIGROOM);
271 StrBuf_ServGetln(Buf);
272 if (GetServerStatus(Buf, NULL) != 2) {
276 ParseGoto(Room, Buf);
280 void WritePrefsToServer(HashList *Hash)
288 StrBuf *SubBuf = NULL;
290 Hash = WCC->hash_prefs;
291 #ifdef DBG_PREFS_HASH
292 dbg_PrintHash(Hash, PrintPref, NULL);
294 HashPos = GetNewHashPos(Hash, 0);
295 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
300 Pref = (Preference*) vPref;
301 nchars = StrLength(Pref->Val);
304 size_t offset, nchars;
306 SubBuf = NewStrBufPlain(NULL, SIZ);
315 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
318 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
320 serv_printf(" %s", ChrPtr(SubBuf));
323 nchars = StrLength(Pref->Val) - offset;
329 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
333 DeleteHashPos(&HashPos);
337 * \brief save the modifications
339 void save_preferences(void)
347 ReadBuf = NewStrBuf();
348 memset(&Room, 0, sizeof(folder));
349 if (goto_config_room(ReadBuf, &Room) != 0) {
350 FreeStrBuf(&ReadBuf);
353 return; /* oh well. */
356 /* make shure the config room has the right type, else it might reject our config */
357 if (Room.view != VIEW_BBS) {
358 serv_printf("VIEW %d", VIEW_BBS);
359 StrBuf_ServGetln(ReadBuf);
360 if (GetServerStatus(ReadBuf, NULL) != 2) {
363 else if (goto_config_room(ReadBuf, &Room) != 0) {
364 FreeStrBuf(&ReadBuf);
367 return; /* oh well. */
371 serv_puts("MSGS ALL|0|1");
372 StrBuf_ServGetln(ReadBuf);
373 if (GetServerStatus(ReadBuf, NULL) == 8) {
374 serv_puts("subj|__ WebCit Preferences __");
378 StrBuf_ServGetln(ReadBuf)) {
379 if ( (StrLength(ReadBuf)==3) &&
380 !strcmp(ChrPtr(ReadBuf), "000")) {
384 msgnum = StrTol(ReadBuf);
388 serv_printf("DELE %ld", msgnum);
389 StrBuf_ServGetln(ReadBuf);
390 GetServerStatus(ReadBuf, NULL);
393 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
394 StrBuf_ServGetln(ReadBuf);
395 if (GetServerStatus(ReadBuf, NULL) == 4) {
397 WritePrefsToServer(WCC->hash_prefs);
402 /** Go back to the room we're supposed to be in */
403 if (StrLength(WCC->CurRoom.name) > 0) {
404 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
405 StrBuf_ServGetln(ReadBuf);
406 GetServerStatus(ReadBuf, NULL);
408 FreeStrBuf(&ReadBuf);
413 * \brief query the actual setting of key in the citadel database
414 * \param key config key to query
415 * \param keylen length of the key string
416 * \param value StrBuf-value to the key to get
419 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
421 void *hash_value = NULL;
422 #ifdef DBG_PREFS_HASH
423 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
425 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
430 *Pref = (Preference*) hash_value;
435 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
440 Ret = get_pref_backend(key, keylen, &Pref);
449 * \brief Write a key into the webcit preferences database for this user
451 * \params key key whichs value is to be modified
452 * \param keylen length of the key string
453 * \param value value to set
454 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
456 long compare_preference(const Preference *PrefA,
457 const Preference *PrefB)
459 ePrefType TypeA, TypeB;
461 if (PrefA->Type != NULL)
462 TypeA = PrefA->Type->eType;
464 TypeA = PrefA->eFlatPrefType;
466 if (PrefB->Type != NULL)
467 TypeB = PrefB->Type->eType;
469 TypeB = PrefB->eFlatPrefType;
471 if ((TypeA != PRF_UNSET) &&
472 (TypeB != PRF_UNSET) &&
477 else /* (PrefA->Type < PrefB->Type) */
481 if (TypeB == PRF_UNSET)
489 return strcmp(ChrPtr(PrefA->Val),
493 if (PrefA->lval == PrefB->lval)
495 else if (PrefA->lval > PrefB->lval)
500 return strcmp(ChrPtr(PrefA->DeQPed),
501 ChrPtr(PrefB->DeQPed));
506 * \brief Write a key into the webcit preferences database for this user
508 * \params key key whichs value is to be modified
509 * \param keylen length of the key string
510 * \param value value to set
511 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
513 void set_preference_backend(const char *key, size_t keylen,
525 Pref = (Preference*) malloc(sizeof(Preference));
526 memset(Pref, 0, sizeof(Preference));
527 Pref->Key = NewStrBufPlain(key, keylen);
529 if ((PrefType == NULL) &&
530 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
532 PrefType = (PrefDef*) vPrefDef;
534 if (PrefType != NULL)
536 Pref->Type = PrefType;
537 Pref->eFlatPrefType = PrefType->eType;
538 if (Pref->Type->eType != lPrefType)
539 syslog(1, "warning: saving preference with wrong type [%s] %ld != %ld \n",
540 key, Pref->Type->eType, lPrefType);
541 switch (Pref->Type->eType)
543 case PRF_UNSET: /* default to string... */
551 if (Pref->Val == NULL)
552 Pref->Val = NewStrBufPlain(NULL, 64);
553 StrBufPrintf(Pref->Val, "%ld", lvalue);
557 Pref->DeQPed = value;
558 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
559 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
565 Pref->Val = NewStrBufPlain(HKEY("yes"));
567 Pref->Val = NewStrBufPlain(HKEY("no"));
571 if (Pref->Type->OnLoad != NULL)
572 Pref->Type->OnLoad(Pref->Val, Pref->lval);
575 Pref->eFlatPrefType = lPrefType;
585 if (Pref->Val == NULL)
586 Pref->Val = NewStrBufPlain(NULL, 64);
587 StrBufPrintf(Pref->Val, "%ld", lvalue);
591 Pref->DeQPed = value;
592 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
593 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
599 Pref->Val = NewStrBufPlain(HKEY("yes"));
601 Pref->Val = NewStrBufPlain(HKEY("no"));
607 if ((save_to_server != 0) &&
608 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
610 (compare_preference (Pref, vPrefB) == 0))
613 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
615 if (save_to_server) WCC->SavePrefsToServer = 1;
618 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
620 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
623 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
628 Ret = get_pref_backend(key, keylen, &Pref);
637 *value = Pref->lval = atol(ChrPtr(Pref->Val));
644 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
646 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
649 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
654 Ret = get_pref_backend(key, keylen, &Pref);
663 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
669 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
671 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
674 int get_room_prefs_backend(const char *key, size_t keylen,
680 pref_name = NewStrBufPlain (HKEY("ROOM:"));
681 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
682 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
683 StrBufAppendBufPlain(pref_name, key, keylen, 0);
684 Ret = get_pref_backend(SKEY(pref_name), Pref);
685 FreeStrBuf(&pref_name);
690 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
691 const char *xkey, size_t xkeylen)
697 pref_name = NewStrBufPlain (HKEY("XPREF:"));
698 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
699 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
700 StrBufAppendBufPlain(pref_name, key, keylen, 0);
702 ret = get_pref_backend(SKEY(pref_name), &Prf);
703 FreeStrBuf(&pref_name);
710 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
714 pref_name = NewStrBufPlain (HKEY("XPREF:"));
715 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
716 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
717 StrBufAppendBufPlain(pref_name, key, keylen, 0);
719 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
720 FreeStrBuf(&pref_name);
724 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
729 Ret = get_room_prefs_backend(key, keylen, &Pref);
739 *value = Pref->lval = atol(ChrPtr(Pref->Val));
746 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
751 Ret = get_room_prefs_backend(key, keylen, &Pref);
760 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
764 pref_name = NewStrBufPlain (HKEY("ROOM:"));
765 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
766 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
767 StrBufAppendBufPlain(pref_name, key, keylen, 0);
768 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
769 FreeStrBuf(&pref_name);
773 void GetPreferences(HashList *Setting)
785 Tmp = WCC->hash_prefs;
786 WCC->hash_prefs = Setting;
788 It = GetNewHashPos(PreferenceHooks, 0);
789 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
790 PrefType = (PrefDef*) vSetting;
792 if (!HaveBstr(SKEY(PrefType->Setting)))
794 switch (PrefType->eType) {
797 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
798 set_preference_backend(SKEY(PrefType->Setting),
806 lval = LBstr(SKEY(PrefType->Setting));
807 set_preference_backend(SKEY(PrefType->Setting),
815 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
816 set_preference_backend(SKEY(PrefType->Setting),
824 lval = YesBstr(SKEY(PrefType->Setting));
825 set_preference_backend(SKEY(PrefType->Setting),
834 WCC->hash_prefs = Tmp;
840 * \brief Commit new preferences and settings
842 void set_preferences(void)
844 if (!havebstr("change_button")) {
845 safestrncpy(WC->ImportantMessage,
846 _("Cancelled. No settings were changed."),
847 sizeof WC->ImportantMessage);
851 GetPreferences(WC->hash_prefs);
856 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
859 if (get_pref_backend(TKEY(0), &Pref))
861 if (Pref->Type == NULL) {
862 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
864 switch (Pref->Type->eType)
866 case PRF_UNSET: /* default to string... */
868 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
871 if (Pref->decoded != 1) {
872 if (Pref->Val == NULL)
873 Pref->Val = NewStrBufPlain(NULL, 64);
874 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
877 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
880 if (Pref->decoded != 1) {
881 if (Pref->DeQPed == NULL)
882 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
884 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
887 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
890 if (Pref->decoded != 1) {
891 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
894 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
900 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
902 const char *SettingStr;
903 SettingStr = PrefGetLocalStr(TKEY(0));
904 if (SettingStr != NULL)
905 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
907 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
913 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
914 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
915 StrBufAppendPrintf(Target, "%ld", lvalue);
917 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
919 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
921 StrBufAppendBuf(Target, pref, 0);
923 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
925 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
926 TP->Tokens->Params[0]->len) != NULL)
932 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
936 if (!get_PREFERENCE(TKEY(2), &Pref))
939 if (!HAVE_PARAM(3)) {
942 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
944 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
951 GetTemplateTokenString(Target, TP, 3, &pch, &len);
953 return ((len == StrLength(Pref)) &&
954 (strcmp(pch, ChrPtr(Pref)) == 0));
958 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
962 if (!get_PREFERENCE(TKEY(2), &Pref) ||
970 /********************************************************************************
971 * preferences stored discrete in citserver
972 ********************************************************************************/
973 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
976 HashList *List = NULL;
983 StrBuf_ServGetln(Rcp);
984 if (GetServerStatus(Rcp, NULL) == 1) {
986 List = NewHash(1, NULL);
987 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
988 if ( (StrLength(Rcp)==3) &&
989 !strcmp(ChrPtr(Rcp), "000"))
994 i = snprintf(N, sizeof(N), "%d", n);
996 Put(List, N, i, Rcp, HFreeStrBuf);
1005 void DeleteGVEAHash(HashList **KillMe)
1010 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1013 HashList *List = NULL;
1020 StrBuf_ServGetln(Rcp);
1021 if (GetServerStatus(Rcp, NULL) == 1) {
1023 List = NewHash(1, NULL);
1024 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1025 if ( (StrLength(Rcp)==3) &&
1026 !strcmp(ChrPtr(Rcp), "000"))
1031 i = snprintf(N, sizeof(N), "%d", n);
1033 Put(List, N, i, Rcp, HFreeStrBuf);
1042 void DeleteGVSNHash(HashList **KillMe)
1051 * Offer to make any page the user's "start page" (only if logged in)
1053 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1055 if (WC->logged_in) {
1056 wc_printf("<a href=\"change_start_page?startpage=");
1057 urlescputs(ChrPtr(WC->Hdr->this_page));
1059 wc_printf(_("Make this my start page"));
1066 * Change the user's start page
1068 void change_start_page(void)
1070 wcsession *WCC = WC;
1073 int ProhibitSave = 0;
1074 const StrBuf *pStartPage = sbstr("startpage");
1076 if (pStartPage != NULL) {
1077 pch = strchr(ChrPtr(pStartPage), '?');
1079 if ((pch != NULL) && (
1080 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1081 (vHandler != NULL) &&
1082 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1083 { /* OK, This handler doesn't want to be set as start page, prune it. */
1088 if ((pStartPage == NULL) ||
1089 (ProhibitSave == 1))
1091 set_preference_backend(HKEY("startpage"),
1093 NewStrBufPlain(HKEY("")),
1097 if (ProhibitSave == 1)
1098 StrBufAppendBufPlain(WCC->ImportantMsg,
1099 _("This isn't allowed to become the start page."),
1102 StrBufAppendBufPlain(WCC->ImportantMsg,
1103 _("You no longer have a start page selected."),
1105 display_main_menu();
1111 set_preference_backend(HKEY("startpage"),
1113 NewStrBufDup(pStartPage),
1118 output_headers(1, 1, 0, 0, 0, 0);
1119 do_template("newstartpage", NULL);
1124 void LoadStartpage(StrBuf *URL, long lvalue)
1128 pch = strchr(ChrPtr(URL), '?');
1130 /* purge the sins of the past... */
1131 pch = strchr(ChrPtr(URL), '&');
1133 StrBufPeek(URL, pch, -1, '?');
1134 WC->SavePrefsToServer = 1;
1137 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1138 (vHandler != NULL) &&
1139 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1140 { /* OK, This handler doesn't want to be set as start page, prune it. */
1142 WC->SavePrefsToServer = 1;
1148 InitModule_PREFERENCES
1151 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1152 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1154 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1156 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1157 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1158 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1159 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1161 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1163 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1164 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1165 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1167 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1168 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1169 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1170 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1176 ServerStartModule_PREFERENCES
1179 PreferenceHooks = NewHash(1, NULL);
1185 ServerShutdownModule_PREFERENCES
1188 DeleteHash(&PreferenceHooks);
1192 SessionDetachModule__PREFERENCES
1195 if (sess->SavePrefsToServer) {
1197 sess->SavePrefsToServer = 0;
1202 SessionNewModule_PREFERENCES
1205 sess->hash_prefs = NewHash(1,NULL);
1209 SessionDestroyModule_PREFERENCES
1212 DeleteHash(&sess->hash_prefs);