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 StrBuf_ServGetln(ReadBuf);
161 if ( (StrLength(ReadBuf)==3) &&
162 !strcmp(ChrPtr(ReadBuf), "000")) {
167 if ((ChrPtr(ReadBuf)[0] == ' ') &&
168 (LastData != NULL)) {
169 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
172 LastData = Data = malloc(sizeof(Preference));
173 memset(Data, 0, sizeof(Preference));
174 Data->Key = NewStrBuf();
175 Data->Val = NewStrBuf();
176 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
177 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
178 if (!IsEmptyStr(ChrPtr(Data->Key)))
188 lprintf(1, "ignoring spurious preference line: [%s]\n",
190 DestroyPreference(Data);
201 * display preferences dialog
203 void load_preferences(void)
211 memset(&Room, 0, sizeof(folder));
212 ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
213 if (goto_config_room(ReadBuf, &Room) != 0) {
214 FreeStrBuf(&ReadBuf);
217 return; /* oh well. */
220 serv_puts("MSGS ALL|0|1");
221 StrBuf_ServGetln(ReadBuf);
222 if (GetServerStatus(ReadBuf, NULL) == 8) {
223 serv_puts("subj|__ WebCit Preferences __");
227 StrBuf_ServGetln(ReadBuf)) {
228 if ( (StrLength(ReadBuf)==3) &&
229 !strcmp(ChrPtr(ReadBuf), "000")) {
233 msgnum = StrTol(ReadBuf);
237 serv_printf("MSG0 %ld", msgnum);
238 StrBuf_ServGetln(ReadBuf);
239 if (GetServerStatus(ReadBuf, NULL) == 1) {
240 while (StrBuf_ServGetln(ReadBuf),
241 (strcmp(ChrPtr(ReadBuf), "text") &&
242 strcmp(ChrPtr(ReadBuf), "000"))) {
244 if (!strcmp(ChrPtr(ReadBuf), "text")) {
245 ParsePref(&WCC->hash_prefs, ReadBuf);
250 /* Go back to the room we're supposed to be in */
251 if (StrLength(WCC->CurRoom.name) > 0) {
252 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
253 StrBuf_ServGetln(ReadBuf);
254 GetServerStatus(ReadBuf, NULL);
256 FreeStrBuf(&ReadBuf);
261 * Goto the user's configuration room, creating it if necessary.
262 * returns 0 on success or nonzero upon failure.
264 int goto_config_room(StrBuf *Buf, folder *Room)
266 serv_printf("GOTO %s", USERCONFIGROOM);
267 StrBuf_ServGetln(Buf);
268 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
269 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
270 StrBuf_ServGetln(Buf);
271 GetServerStatus(Buf, NULL);
273 serv_printf("GOTO %s", USERCONFIGROOM);
274 StrBuf_ServGetln(Buf);
275 if (GetServerStatus(Buf, NULL) != 2) {
279 ParseGoto(Room, Buf);
283 void WritePrefsToServer(HashList *Hash)
291 StrBuf *SubBuf = NULL;
293 Hash = WCC->hash_prefs;
294 #ifdef DBG_PREFS_HASH
295 dbg_PrintHash(Hash, PrintPref, NULL);
297 HashPos = GetNewHashPos(Hash, 0);
298 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
303 Pref = (Preference*) vPref;
304 nchars = StrLength(Pref->Val);
307 size_t offset, nchars;
309 SubBuf = NewStrBufPlain(NULL, SIZ);
318 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
321 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
323 serv_printf(" %s", ChrPtr(SubBuf));
326 nchars = StrLength(Pref->Val) - offset;
332 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
336 DeleteHashPos(&HashPos);
340 * \brief save the modifications
342 void save_preferences(void)
350 ReadBuf = NewStrBuf();
351 memset(&Room, 0, sizeof(folder));
352 if (goto_config_room(ReadBuf, &Room) != 0) {
353 FreeStrBuf(&ReadBuf);
356 return; /* oh well. */
359 /* make shure the config room has the right type, else it might reject our config */
360 if (Room.view != VIEW_BBS) {
361 serv_printf("VIEW %d", VIEW_BBS);
362 StrBuf_ServGetln(ReadBuf);
363 if (GetServerStatus(ReadBuf, NULL) != 2) {
366 else if (goto_config_room(ReadBuf, &Room) != 0) {
367 FreeStrBuf(&ReadBuf);
370 return; /* oh well. */
374 serv_puts("MSGS ALL|0|1");
375 StrBuf_ServGetln(ReadBuf);
376 if (GetServerStatus(ReadBuf, NULL) == 8) {
377 serv_puts("subj|__ WebCit Preferences __");
381 StrBuf_ServGetln(ReadBuf)) {
382 if ( (StrLength(ReadBuf)==3) &&
383 !strcmp(ChrPtr(ReadBuf), "000")) {
387 msgnum = StrTol(ReadBuf);
391 serv_printf("DELE %ld", msgnum);
392 StrBuf_ServGetln(ReadBuf);
393 GetServerStatus(ReadBuf, NULL);
396 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
397 StrBuf_ServGetln(ReadBuf);
398 if (GetServerStatus(ReadBuf, NULL) == 4) {
400 WritePrefsToServer(WCC->hash_prefs);
405 /** Go back to the room we're supposed to be in */
406 if (StrLength(WCC->CurRoom.name) > 0) {
407 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
408 StrBuf_ServGetln(ReadBuf);
409 GetServerStatus(ReadBuf, NULL);
411 FreeStrBuf(&ReadBuf);
416 * \brief query the actual setting of key in the citadel database
417 * \param key config key to query
418 * \param keylen length of the key string
419 * \param value StrBuf-value to the key to get
422 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
424 void *hash_value = NULL;
425 #ifdef DBG_PREFS_HASH
426 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
428 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
433 *Pref = (Preference*) hash_value;
438 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
443 Ret = get_pref_backend(key, keylen, &Pref);
452 * \brief Write a key into the webcit preferences database for this user
454 * \params key key whichs value is to be modified
455 * \param keylen length of the key string
456 * \param value value to set
457 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
459 long compare_preference(const Preference *PrefA,
460 const Preference *PrefB)
462 ePrefType TypeA, TypeB;
464 if (PrefA->Type != NULL)
465 TypeA = PrefA->Type->eType;
467 TypeA = PrefA->eFlatPrefType;
469 if (PrefB->Type != NULL)
470 TypeB = PrefB->Type->eType;
472 TypeB = PrefB->eFlatPrefType;
474 if ((TypeA != PRF_UNSET) &&
475 (TypeB != PRF_UNSET) &&
480 else /* (PrefA->Type < PrefB->Type) */
484 if (TypeB == PRF_UNSET)
492 return strcmp(ChrPtr(PrefA->Val),
496 if (PrefA->lval == PrefB->lval)
498 else if (PrefA->lval > PrefB->lval)
503 return strcmp(ChrPtr(PrefA->DeQPed),
504 ChrPtr(PrefB->DeQPed));
509 * \brief Write a key into the webcit preferences database for this user
511 * \params key key whichs value is to be modified
512 * \param keylen length of the key string
513 * \param value value to set
514 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
516 void set_preference_backend(const char *key, size_t keylen,
528 Pref = (Preference*) malloc(sizeof(Preference));
529 memset(Pref, 0, sizeof(Preference));
530 Pref->Key = NewStrBufPlain(key, keylen);
532 if ((PrefType == NULL) &&
533 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
535 PrefType = (PrefDef*) vPrefDef;
537 if (PrefType != NULL)
539 Pref->Type = PrefType;
540 Pref->eFlatPrefType = PrefType->eType;
541 if (Pref->Type->eType != lPrefType)
542 lprintf(1, "warning: saving preference with wrong type [%s] %ld != %ld \n",
543 key, Pref->Type->eType, lPrefType);
544 switch (Pref->Type->eType)
546 case PRF_UNSET: /* default to string... */
554 if (Pref->Val == NULL)
555 Pref->Val = NewStrBufPlain(NULL, 64);
556 StrBufPrintf(Pref->Val, "%ld", lvalue);
560 Pref->DeQPed = value;
561 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
562 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
568 Pref->Val = NewStrBufPlain(HKEY("yes"));
570 Pref->Val = NewStrBufPlain(HKEY("no"));
574 if (Pref->Type->OnLoad != NULL)
575 Pref->Type->OnLoad(Pref->Val, Pref->lval);
578 Pref->eFlatPrefType = lPrefType;
588 if (Pref->Val == NULL)
589 Pref->Val = NewStrBufPlain(NULL, 64);
590 StrBufPrintf(Pref->Val, "%ld", lvalue);
594 Pref->DeQPed = value;
595 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
596 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
602 Pref->Val = NewStrBufPlain(HKEY("yes"));
604 Pref->Val = NewStrBufPlain(HKEY("no"));
610 if ((save_to_server != 0) &&
611 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
613 (compare_preference (Pref, vPrefB) == 0))
616 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
618 if (save_to_server) WCC->SavePrefsToServer = 1;
621 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
623 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
626 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
631 Ret = get_pref_backend(key, keylen, &Pref);
640 *value = Pref->lval = atol(ChrPtr(Pref->Val));
647 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
649 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
652 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
657 Ret = get_pref_backend(key, keylen, &Pref);
666 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
672 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
674 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
677 int get_room_prefs_backend(const char *key, size_t keylen,
683 pref_name = NewStrBufPlain (HKEY("ROOM:"));
684 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
685 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
686 StrBufAppendBufPlain(pref_name, key, keylen, 0);
687 Ret = get_pref_backend(SKEY(pref_name), Pref);
688 FreeStrBuf(&pref_name);
693 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
694 const char *xkey, size_t xkeylen)
700 pref_name = NewStrBufPlain (HKEY("XPREF:"));
701 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
702 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
703 StrBufAppendBufPlain(pref_name, key, keylen, 0);
705 ret = get_pref_backend(SKEY(pref_name), &Prf);
706 FreeStrBuf(&pref_name);
713 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
717 pref_name = NewStrBufPlain (HKEY("XPREF:"));
718 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
719 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
720 StrBufAppendBufPlain(pref_name, key, keylen, 0);
722 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
723 FreeStrBuf(&pref_name);
727 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
732 Ret = get_room_prefs_backend(key, keylen, &Pref);
742 *value = Pref->lval = atol(ChrPtr(Pref->Val));
749 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
754 Ret = get_room_prefs_backend(key, keylen, &Pref);
763 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
767 pref_name = NewStrBufPlain (HKEY("ROOM:"));
768 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
769 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
770 StrBufAppendBufPlain(pref_name, key, keylen, 0);
771 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
772 FreeStrBuf(&pref_name);
776 void GetPreferences(HashList *Setting)
788 Tmp = WCC->hash_prefs;
789 WCC->hash_prefs = Setting;
791 It = GetNewHashPos(PreferenceHooks, 0);
792 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
793 PrefType = (PrefDef*) vSetting;
795 if (!HaveBstr(SKEY(PrefType->Setting)))
797 switch (PrefType->eType) {
800 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
801 set_preference_backend(SKEY(PrefType->Setting),
809 lval = LBstr(SKEY(PrefType->Setting));
810 set_preference_backend(SKEY(PrefType->Setting),
818 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
819 set_preference_backend(SKEY(PrefType->Setting),
827 lval = YesBstr(SKEY(PrefType->Setting));
828 set_preference_backend(SKEY(PrefType->Setting),
837 WCC->hash_prefs = Tmp;
843 * \brief Commit new preferences and settings
845 void set_preferences(void)
847 if (!havebstr("change_button")) {
848 safestrncpy(WC->ImportantMessage,
849 _("Cancelled. No settings were changed."),
850 sizeof WC->ImportantMessage);
854 GetPreferences(WC->hash_prefs);
859 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
862 if (get_pref_backend(TKEY(0), &Pref))
864 if (Pref->Type == NULL) {
865 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
867 switch (Pref->Type->eType)
869 case PRF_UNSET: /* default to string... */
871 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
874 if (Pref->decoded != 1) {
875 if (Pref->Val == NULL)
876 Pref->Val = NewStrBufPlain(NULL, 64);
877 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
880 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
883 if (Pref->decoded != 1) {
884 if (Pref->DeQPed == NULL)
885 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
887 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
890 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
893 if (Pref->decoded != 1) {
894 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
897 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
903 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
905 const char *SettingStr;
906 SettingStr = PrefGetLocalStr(TKEY(0));
907 if (SettingStr != NULL)
908 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
910 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
916 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
917 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
918 StrBufAppendPrintf(Target, "%ld", lvalue);
920 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
922 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
924 StrBufAppendBuf(Target, pref, 0);
926 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
928 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
929 TP->Tokens->Params[0]->len) != NULL)
935 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
939 if (!get_PREFERENCE(TKEY(2), &Pref))
942 if (!HAVE_PARAM(3)) {
945 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
947 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
954 GetTemplateTokenString(Target, TP, 3, &pch, &len);
956 return ((len == StrLength(Pref)) &&
957 (strcmp(pch, ChrPtr(Pref)) == 0));
961 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
965 if (!get_PREFERENCE(TKEY(2), &Pref) ||
973 /********************************************************************************
974 * preferences stored discrete in citserver
975 ********************************************************************************/
976 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
979 HashList *List = NULL;
986 StrBuf_ServGetln(Rcp);
987 if (GetServerStatus(Rcp, NULL) == 1) {
989 List = NewHash(1, NULL);
990 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
991 if ( (StrLength(Rcp)==3) &&
992 !strcmp(ChrPtr(Rcp), "000"))
997 i = snprintf(N, sizeof(N), "%d", n);
999 Put(List, N, i, Rcp, HFreeStrBuf);
1008 void DeleteGVEAHash(HashList **KillMe)
1013 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1016 HashList *List = NULL;
1023 StrBuf_ServGetln(Rcp);
1024 if (GetServerStatus(Rcp, NULL) == 1) {
1026 List = NewHash(1, NULL);
1027 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1028 if ( (StrLength(Rcp)==3) &&
1029 !strcmp(ChrPtr(Rcp), "000"))
1034 i = snprintf(N, sizeof(N), "%d", n);
1036 Put(List, N, i, Rcp, HFreeStrBuf);
1045 void DeleteGVSNHash(HashList **KillMe)
1054 * Offer to make any page the user's "start page."
1056 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1058 wc_printf("<a href=\"change_start_page?startpage=");
1059 urlescputs(ChrPtr(WC->Hdr->this_page));
1061 wc_printf(_("Make this my start page"));
1067 * Change the user's start page
1069 void change_start_page(void)
1071 wcsession *WCC = WC;
1074 int ProhibitSave = 0;
1075 const StrBuf *pStartPage = sbstr("startpage");
1077 if (pStartPage != NULL) {
1078 pch = strchr(ChrPtr(pStartPage), '?');
1080 if ((pch != NULL) && (
1081 GetHash(HandlerHash, ChrPtr(pStartPage), pch - ChrPtr(pStartPage), &vHandler),
1082 (vHandler != NULL) &&
1083 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0)))
1084 { /* OK, This handler doesn't want to be set as start page, prune it. */
1089 if ((pStartPage == NULL) ||
1090 (ProhibitSave == 1))
1092 set_preference_backend(HKEY("startpage"),
1094 NewStrBufPlain(HKEY("")),
1098 if (ProhibitSave == 1)
1099 StrBufAppendBufPlain(WCC->ImportantMsg,
1100 _("This isn't allowed to become the start page."),
1103 StrBufAppendBufPlain(WCC->ImportantMsg,
1104 _("You no longer have a start page selected."),
1106 display_main_menu();
1112 set_preference_backend(HKEY("startpage"),
1114 NewStrBufDup(pStartPage),
1119 output_headers(1, 1, 0, 0, 0, 0);
1120 do_template("newstartpage", NULL);
1125 void LoadStartpage(StrBuf *URL, long lvalue)
1129 pch = strchr(ChrPtr(URL), '?');
1131 /* purge the sins of the past... */
1132 pch = strchr(ChrPtr(URL), '&');
1134 StrBufPeek(URL, pch, -1, '?');
1135 WC->SavePrefsToServer = 1;
1138 else if (GetHash(HandlerHash, ChrPtr(URL), pch - ChrPtr(URL), &vHandler),
1139 (vHandler != NULL) &&
1140 ((((WebcitHandler*)vHandler)->Flags & PROHIBIT_STARTPAGE) != 0))
1141 { /* OK, This handler doesn't want to be set as start page, prune it. */
1143 WC->SavePrefsToServer = 1;
1149 InitModule_PREFERENCES
1152 WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0);
1153 WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0);
1155 RegisterPreference("startpage", _("Prefered startpage"), PRF_STRING, LoadStartpage);
1157 RegisterNamespace("OFFERSTARTPAGE", 0, 0, offer_start_page, NULL, CTX_NONE);
1158 RegisterNamespace("PREF:ROOM:VALUE", 1, 2, tmplput_CFG_RoomValue, NULL, CTX_NONE);
1159 RegisterNamespace("PREF:ROOM:VALUE:INT", 1, 2, tmplput_CFG_RoomValueLong, NULL, CTX_NONE);
1160 RegisterNamespace("PREF:VALUE", 1, 2, tmplput_CFG_Value, NULL, CTX_NONE);
1162 RegisterNamespace("PREF:DESCR", 1, 1, tmplput_CFG_Descr, NULL, CTX_NONE);
1164 RegisterConditional(HKEY("COND:PREF"), 4, ConditionalPreference, CTX_NONE);
1165 RegisterConditional(HKEY("COND:PREF:SET"), 4, ConditionalHasPreference, CTX_NONE);
1166 RegisterConditional(HKEY("COND:ROOM:SET"), 4, ConditionalHasRoomPreference, CTX_NONE);
1168 RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL,
1169 GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1170 RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL,
1171 GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
1177 ServerStartModule_PREFERENCES
1180 PreferenceHooks = NewHash(1, NULL);
1186 ServerShutdownModule_PREFERENCES
1189 DeleteHash(&PreferenceHooks);
1193 SessionDetachModule__PREFERENCES
1196 if (sess->SavePrefsToServer) {
1198 sess->SavePrefsToServer = 0;
1203 SessionNewModule_PREFERENCES
1206 sess->hash_prefs = NewHash(1,NULL);
1210 SessionDestroyModule_PREFERENCES
1213 DeleteHash(&sess->hash_prefs);