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 [%d] [\"%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 if (StrBuf_ServGetln(ReadBuf) < 0)
159 if ( (StrLength(ReadBuf)==3) &&
160 !strcmp(ChrPtr(ReadBuf), "000")) {
165 if ((ChrPtr(ReadBuf)[0] == ' ') &&
166 (LastData != NULL)) {
167 StrBufAppendBuf(LastData->Val, ReadBuf, 1);
170 LastData = Data = malloc(sizeof(Preference));
171 memset(Data, 0, sizeof(Preference));
172 Data->Key = NewStrBuf();
173 Data->Val = NewStrBuf();
174 StrBufExtract_token(Data->Key, ReadBuf, 0, '|');
175 StrBufExtract_token(Data->Val, ReadBuf, 1, '|');
176 if (!IsEmptyStr(ChrPtr(Data->Key)))
186 syslog(1, "ignoring spurious preference line: [%s]\n",
188 DestroyPreference(Data);
199 * display preferences dialog
201 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 __");
225 (StrBuf_ServGetln(ReadBuf) >= 0)) {
226 if ( (StrLength(ReadBuf)==3) &&
227 !strcmp(ChrPtr(ReadBuf), "000")) {
231 msgnum = StrTol(ReadBuf);
235 serv_printf("MSG0 %ld", msgnum);
236 StrBuf_ServGetln(ReadBuf);
237 if (GetServerStatus(ReadBuf, NULL) == 1) {
238 while ((StrBuf_ServGetln(ReadBuf) >= 0) &&
239 (strcmp(ChrPtr(ReadBuf), "text") &&
240 strcmp(ChrPtr(ReadBuf), "000"))) {
242 if (!strcmp(ChrPtr(ReadBuf), "text")) {
243 ParsePref(&WCC->hash_prefs, ReadBuf);
248 /* Go back to the room we're supposed to be in */
249 if (StrLength(WCC->CurRoom.name) > 0) {
250 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
251 StrBuf_ServGetln(ReadBuf);
252 GetServerStatus(ReadBuf, NULL);
254 FreeStrBuf(&ReadBuf);
259 * Goto the user's configuration room, creating it if necessary.
260 * returns 0 on success or nonzero upon failure.
262 int goto_config_room(StrBuf *Buf, folder *Room)
264 serv_printf("GOTO %s", USERCONFIGROOM);
265 StrBuf_ServGetln(Buf);
266 if (GetServerStatus(Buf, NULL) != 2) { /* try to create the config room if not there */
267 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
268 StrBuf_ServGetln(Buf);
269 GetServerStatus(Buf, NULL);
271 serv_printf("GOTO %s", USERCONFIGROOM);
272 StrBuf_ServGetln(Buf);
273 if (GetServerStatus(Buf, NULL) != 2) {
277 ParseGoto(Room, Buf);
281 void WritePrefsToServer(HashList *Hash)
289 StrBuf *SubBuf = NULL;
291 Hash = WCC->hash_prefs;
292 #ifdef DBG_PREFS_HASH
293 dbg_PrintHash(Hash, PrintPref, NULL);
295 HashPos = GetNewHashPos(Hash, 0);
296 while (GetNextHashPos(Hash, HashPos, &len, &Key, &vPref)!=0)
301 Pref = (Preference*) vPref;
302 nchars = StrLength(Pref->Val);
305 size_t offset, nchars;
307 SubBuf = NewStrBufPlain(NULL, SIZ);
316 nchars = StrBufSub(SubBuf, Pref->Val, offset, nchars);
319 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(SubBuf));
321 serv_printf(" %s", ChrPtr(SubBuf));
324 nchars = StrLength(Pref->Val) - offset;
330 serv_printf("%s|%s", ChrPtr(Pref->Key), ChrPtr(Pref->Val));
334 DeleteHashPos(&HashPos);
338 * \brief save the modifications
340 void save_preferences(void)
348 ReadBuf = NewStrBuf();
349 memset(&Room, 0, sizeof(folder));
350 if (goto_config_room(ReadBuf, &Room) != 0) {
351 FreeStrBuf(&ReadBuf);
354 return; /* oh well. */
357 /* make shure the config room has the right type, else it might reject our config */
358 if (Room.view != VIEW_BBS) {
359 serv_printf("VIEW %d", VIEW_BBS);
360 StrBuf_ServGetln(ReadBuf);
361 if (GetServerStatus(ReadBuf, NULL) != 2) {
364 else if (goto_config_room(ReadBuf, &Room) != 0) {
365 FreeStrBuf(&ReadBuf);
368 return; /* oh well. */
372 serv_puts("MSGS ALL|0|1");
373 StrBuf_ServGetln(ReadBuf);
374 if (GetServerStatus(ReadBuf, NULL) == 8) {
375 serv_puts("subj|__ WebCit Preferences __");
379 (StrBuf_ServGetln(ReadBuf) >= 0)) {
380 if ( (StrLength(ReadBuf)==3) &&
381 !strcmp(ChrPtr(ReadBuf), "000")) {
385 msgnum = StrTol(ReadBuf);
389 serv_printf("DELE %ld", msgnum);
390 StrBuf_ServGetln(ReadBuf);
391 GetServerStatus(ReadBuf, NULL);
394 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
395 StrBuf_ServGetln(ReadBuf);
396 if (GetServerStatus(ReadBuf, NULL) == 4) {
398 WritePrefsToServer(WCC->hash_prefs);
403 /** Go back to the room we're supposed to be in */
404 if (StrLength(WCC->CurRoom.name) > 0) {
405 serv_printf("GOTO %s", ChrPtr(WCC->CurRoom.name));
406 StrBuf_ServGetln(ReadBuf);
407 GetServerStatus(ReadBuf, NULL);
409 FreeStrBuf(&ReadBuf);
414 * \brief query the actual setting of key in the citadel database
415 * \param key config key to query
416 * \param keylen length of the key string
417 * \param value StrBuf-value to the key to get
420 int get_pref_backend(const char *key, size_t keylen, Preference **Pref)
422 void *hash_value = NULL;
423 #ifdef DBG_PREFS_HASH
424 dbg_PrintHash(WC->hash_prefs, PrintPref, NULL);
426 if (GetHash(WC->hash_prefs, key, keylen, &hash_value) == 0) {
431 *Pref = (Preference*) hash_value;
436 int get_PREFERENCE(const char *key, size_t keylen, StrBuf **value)
441 Ret = get_pref_backend(key, keylen, &Pref);
450 * \brief Write a key into the webcit preferences database for this user
452 * \params key key whichs value is to be modified
453 * \param keylen length of the key string
454 * \param value value to set
455 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
457 long compare_preference(const Preference *PrefA,
458 const Preference *PrefB)
460 ePrefType TypeA, TypeB;
462 if (PrefA->Type != NULL)
463 TypeA = PrefA->Type->eType;
465 TypeA = PrefA->eFlatPrefType;
467 if (PrefB->Type != NULL)
468 TypeB = PrefB->Type->eType;
470 TypeB = PrefB->eFlatPrefType;
472 if ((TypeA != PRF_UNSET) &&
473 (TypeB != PRF_UNSET) &&
478 else /* (PrefA->Type < PrefB->Type) */
482 if (TypeB == PRF_UNSET)
490 return strcmp(ChrPtr(PrefA->Val),
494 if (PrefA->lval == PrefB->lval)
496 else if (PrefA->lval > PrefB->lval)
501 return strcmp(ChrPtr(PrefA->DeQPed),
502 ChrPtr(PrefB->DeQPed));
507 * \brief Write a key into the webcit preferences database for this user
509 * \params key key whichs value is to be modified
510 * \param keylen length of the key string
511 * \param value value to set
512 * \param save_to_server 1 = flush all data to the server, 0 = cache it for now
514 void set_preference_backend(const char *key, size_t keylen,
526 Pref = (Preference*) malloc(sizeof(Preference));
527 memset(Pref, 0, sizeof(Preference));
528 Pref->Key = NewStrBufPlain(key, keylen);
530 if ((PrefType == NULL) &&
531 GetHash(PreferenceHooks, SKEY(Pref->Key), &vPrefDef) &&
533 PrefType = (PrefDef*) vPrefDef;
535 if (PrefType != NULL)
537 Pref->Type = PrefType;
538 Pref->eFlatPrefType = PrefType->eType;
539 if (Pref->Type->eType != lPrefType)
540 syslog(1, "warning: saving preference with wrong type [%s] %d != %ld \n",
541 key, Pref->Type->eType, lPrefType);
542 switch (Pref->Type->eType)
544 case PRF_UNSET: /* default to string... */
552 if (Pref->Val == NULL)
553 Pref->Val = NewStrBufPlain(NULL, 64);
554 StrBufPrintf(Pref->Val, "%ld", lvalue);
558 Pref->DeQPed = value;
559 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
560 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
566 Pref->Val = NewStrBufPlain(HKEY("yes"));
568 Pref->Val = NewStrBufPlain(HKEY("no"));
572 if (Pref->Type->OnLoad != NULL)
573 Pref->Type->OnLoad(Pref->Val, Pref->lval);
576 Pref->eFlatPrefType = lPrefType;
586 if (Pref->Val == NULL)
587 Pref->Val = NewStrBufPlain(NULL, 64);
588 StrBufPrintf(Pref->Val, "%ld", lvalue);
592 Pref->DeQPed = value;
593 Pref->Val = NewStrBufPlain(NULL, StrLength(Pref->DeQPed) * 3);
594 StrBufEUid_escapize(Pref->Val, Pref->DeQPed);
600 Pref->Val = NewStrBufPlain(HKEY("yes"));
602 Pref->Val = NewStrBufPlain(HKEY("no"));
608 if ((save_to_server != 0) &&
609 GetHash(WCC->hash_prefs, key, keylen, &vPrefB) &&
611 (compare_preference (Pref, vPrefB) == 0))
614 Put(WCC->hash_prefs, key, keylen, Pref, DestroyPreference);
616 if (save_to_server) WCC->SavePrefsToServer = 1;
619 void set_PREFERENCE(const char *key, size_t keylen, StrBuf *value, int save_to_server)
621 set_preference_backend(key, keylen, 0, value, PRF_STRING, save_to_server, NULL);
624 int get_PREF_LONG(const char *key, size_t keylen, long *value, long Default)
629 Ret = get_pref_backend(key, keylen, &Pref);
638 *value = Pref->lval = atol(ChrPtr(Pref->Val));
645 void set_PREF_LONG(const char *key, size_t keylen, long value, int save_to_server)
647 set_preference_backend(key, keylen, value, NULL, PRF_INT, save_to_server, NULL);
650 int get_PREF_YESNO(const char *key, size_t keylen, int *value, int Default)
655 Ret = get_pref_backend(key, keylen, &Pref);
664 *value = Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
670 void set_PREF_YESNO(const char *key, size_t keylen, long value, int save_to_server)
672 set_preference_backend(key, keylen, value, NULL, PRF_YESNO, save_to_server, NULL);
675 int get_room_prefs_backend(const char *key, size_t keylen,
681 pref_name = NewStrBufPlain (HKEY("ROOM:"));
682 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
683 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
684 StrBufAppendBufPlain(pref_name, key, keylen, 0);
685 Ret = get_pref_backend(SKEY(pref_name), Pref);
686 FreeStrBuf(&pref_name);
691 const StrBuf *get_X_PREFS(const char *key, size_t keylen,
692 const char *xkey, size_t xkeylen)
698 pref_name = NewStrBufPlain (HKEY("XPREF:"));
699 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
700 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
701 StrBufAppendBufPlain(pref_name, key, keylen, 0);
703 ret = get_pref_backend(SKEY(pref_name), &Prf);
704 FreeStrBuf(&pref_name);
711 void set_X_PREFS(const char *key, size_t keylen, const char *xkey, size_t xkeylen, StrBuf *value, int save_to_server)
715 pref_name = NewStrBufPlain (HKEY("XPREF:"));
716 StrBufAppendBufPlain(pref_name, xkey, xkeylen, 0);
717 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
718 StrBufAppendBufPlain(pref_name, key, keylen, 0);
720 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
721 FreeStrBuf(&pref_name);
725 long get_ROOM_PREFS_LONG(const char *key, size_t keylen, long *value, long Default)
730 Ret = get_room_prefs_backend(key, keylen, &Pref);
740 *value = Pref->lval = atol(ChrPtr(Pref->Val));
747 StrBuf *get_ROOM_PREFS(const char *key, size_t keylen)
752 Ret = get_room_prefs_backend(key, keylen, &Pref);
761 void set_ROOM_PREFS(const char *key, size_t keylen, StrBuf *value, int save_to_server)
765 pref_name = NewStrBufPlain (HKEY("ROOM:"));
766 StrBufAppendBuf(pref_name, WC->CurRoom.name, 0);
767 StrBufAppendBufPlain(pref_name, HKEY(":"), 0);
768 StrBufAppendBufPlain(pref_name, key, keylen, 0);
769 set_preference_backend(SKEY(pref_name), 0, value, PRF_STRING, save_to_server, NULL);
770 FreeStrBuf(&pref_name);
774 void GetPreferences(HashList *Setting)
786 Tmp = WCC->hash_prefs;
787 WCC->hash_prefs = Setting;
789 It = GetNewHashPos(PreferenceHooks, 0);
790 while (GetNextHashPos(PreferenceHooks, It, &len, &Key, &vSetting)) {
791 PrefType = (PrefDef*) vSetting;
793 if (!HaveBstr(SKEY(PrefType->Setting)))
795 switch (PrefType->eType) {
798 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
799 set_preference_backend(SKEY(PrefType->Setting),
807 lval = LBstr(SKEY(PrefType->Setting));
808 set_preference_backend(SKEY(PrefType->Setting),
816 Buf = NewStrBufDup(SBstr(SKEY(PrefType->Setting)));
817 set_preference_backend(SKEY(PrefType->Setting),
825 lval = YesBstr(SKEY(PrefType->Setting));
826 set_preference_backend(SKEY(PrefType->Setting),
835 WCC->hash_prefs = Tmp;
841 * \brief Commit new preferences and settings
843 void set_preferences(void)
845 if (!havebstr("change_button")) {
846 safestrncpy(WC->ImportantMessage,
847 _("Cancelled. No settings were changed."),
848 sizeof WC->ImportantMessage);
852 GetPreferences(WC->hash_prefs);
857 void tmplput_CFG_Value(StrBuf *Target, WCTemplputParams *TP)
860 if (get_pref_backend(TKEY(0), &Pref))
862 if (Pref->Type == NULL) {
863 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
865 switch (Pref->Type->eType)
867 case PRF_UNSET: /* default to string... */
869 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
872 if (Pref->decoded != 1) {
873 if (Pref->Val == NULL)
874 Pref->Val = NewStrBufPlain(NULL, 64);
875 StrBufPrintf(Pref->Val, "%ld", Pref->lval);
878 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
881 if (Pref->decoded != 1) {
882 if (Pref->DeQPed == NULL)
883 Pref->DeQPed = NewStrBufPlain(NULL, StrLength(Pref->Val));
885 StrBufEUid_unescapize(Pref->DeQPed, Pref->Val);
888 StrBufAppendTemplate(Target, TP, Pref->DeQPed, 1);
891 if (Pref->decoded != 1) {
892 Pref->lval = strcmp(ChrPtr(Pref->Val), "yes") == 0;
895 StrBufAppendTemplate(Target, TP, Pref->Val, 1);
901 void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
903 const char *SettingStr;
904 SettingStr = PrefGetLocalStr(TKEY(0));
905 if (SettingStr != NULL)
906 StrBufAppendBufPlain(Target, SettingStr, -1, 0);
908 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
914 defval = GetTemplateTokenNumber(Target, TP, 1, 0);
915 get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
916 StrBufAppendPrintf(Target, "%ld", lvalue);
918 void tmplput_CFG_RoomValue(StrBuf *Target, WCTemplputParams *TP)
920 StrBuf *pref = get_ROOM_PREFS(TKEY(0));
922 StrBufAppendBuf(Target, pref, 0);
924 int ConditionalHasRoomPreference(StrBuf *Target, WCTemplputParams *TP)
926 if (get_ROOM_PREFS(TP->Tokens->Params[0]->Start,
927 TP->Tokens->Params[0]->len) != NULL)
933 int ConditionalPreference(StrBuf *Target, WCTemplputParams *TP)
937 if (!get_PREFERENCE(TKEY(2), &Pref))
940 if (!HAVE_PARAM(3)) {
943 else if (IS_NUMBER(TP->Tokens->Params[3]->Type))
945 return StrTol(Pref) == GetTemplateTokenNumber (Target, TP, 3, 0);
952 GetTemplateTokenString(Target, TP, 3, &pch, &len);
954 return ((len == StrLength(Pref)) &&
955 (strcmp(pch, ChrPtr(Pref)) == 0));
959 int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP)
963 if (!get_PREFERENCE(TKEY(2), &Pref) ||
971 /********************************************************************************
972 * preferences stored discrete in citserver
973 ********************************************************************************/
974 HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP)
977 HashList *List = NULL;
984 StrBuf_ServGetln(Rcp);
985 if (GetServerStatus(Rcp, NULL) == 1) {
987 List = NewHash(1, NULL);
988 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
989 if ( (StrLength(Rcp)==3) &&
990 !strcmp(ChrPtr(Rcp), "000"))
995 i = snprintf(N, sizeof(N), "%d", n);
997 Put(List, N, i, Rcp, HFreeStrBuf);
1006 void DeleteGVEAHash(HashList **KillMe)
1011 HashList *GetGVSNHash(StrBuf *Target, WCTemplputParams *TP)
1014 HashList *List = NULL;
1021 StrBuf_ServGetln(Rcp);
1022 if (GetServerStatus(Rcp, NULL) == 1) {
1024 List = NewHash(1, NULL);
1025 while (!Done && (StrBuf_ServGetln(Rcp)>=0)) {
1026 if ( (StrLength(Rcp)==3) &&
1027 !strcmp(ChrPtr(Rcp), "000"))
1032 i = snprintf(N, sizeof(N), "%d", n);
1034 Put(List, N, i, Rcp, HFreeStrBuf);
1043 void DeleteGVSNHash(HashList **KillMe)
1052 * Offer to make any page the user's "start page" (only if logged in)
1054 void offer_start_page(StrBuf *Target, WCTemplputParams *TP)
1056 if (WC->logged_in) {
1057 wc_printf("<a href=\"change_start_page?startpage=");
1058 urlescputs(ChrPtr(WC->Hdr->this_page));
1060 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);