From: Art Cancro Date: Wed, 8 May 2002 03:38:58 +0000 (+0000) Subject: * Preferences framework X-Git-Tag: v7.86~6413 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=de360cd8c3ef2510b584e7a756f2b2c56a2fbc30;p=citadel.git * Preferences framework --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 58dceeb65..c41e280c2 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 323.30 2002/05/08 03:38:58 ajc +* Preferences framework + Revision 323.29 2002/05/07 03:57:29 ajc * In message summary, replace 'Del' links with checkboxes @@ -803,3 +806,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/Makefile.in b/webcit/Makefile.in index aef57a3f7..beb446a2b 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -26,13 +26,13 @@ webserver: webserver.o context_loop.o tools.o \ cookie_conversion.o locate_host.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ - vcard.o vcard_edit.o \ + vcard.o vcard_edit.o preferences.o \ mime_parser.o graphics.o netconf.o siteconfig.o subst.o $(LIBOBJS) $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ locate_host.o siteconfig.o subst.o vcard.o vcard_edit.o \ - mime_parser.o graphics.o netconf.o \ + mime_parser.o graphics.o netconf.o preferences.o \ $(LIBOBJS) $(LIBS) -o webserver strip webserver diff --git a/webcit/auth.c b/webcit/auth.c index ac7acc8e2..3871d938c 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -68,7 +68,11 @@ void display_login(char *mesg) /* - * This function needs to get called whenever a PASS or NEWU succeeds. + * This function needs to get called whenever the session changes from + * not-logged-in to logged-in, either by an explicit login by the user or + * by a timed-out session automatically re-establishing with a little help + * from the browser cookie. Either way, we need to load access controls and + * preferences from the server. */ void become_logged_in(char *user, char *pass, char *serv_response) { @@ -76,8 +80,10 @@ void become_logged_in(char *user, char *pass, char *serv_response) extract(WC->wc_username, &serv_response[4], 0); strcpy(WC->wc_password, pass); WC->axlevel = extract_int(&serv_response[4], 1); - if (WC->axlevel >= 6) + if (WC->axlevel >= 6) { WC->is_aide = 1; + } + load_preferences(); } diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 99de823e7..30a41e41b 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -82,6 +82,9 @@ BREAKOUT: pthread_mutex_unlock(&SessionListMutex); if (session_to_kill != NULL) { pthread_mutex_lock(&session_to_kill->SessionMutex); close(session_to_kill->serv_sock); + if (session_to_kill->preferences != NULL) { + free(session_to_kill->preferences); + } pthread_mutex_unlock(&session_to_kill->SessionMutex); free(session_to_kill); } diff --git a/webcit/preferences.c b/webcit/preferences.c new file mode 100644 index 000000000..71d61cc77 --- /dev/null +++ b/webcit/preferences.c @@ -0,0 +1,173 @@ +/* + * preferences.c + * + * Manage user preferences with a little help from the Citadel server. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" + + + +void load_preferences(void) { + char buf[SIZ]; + long msgnum = 0L; + + serv_printf("GOTO My Citadel Config"); + serv_gets(buf); + if (buf[0] != '2') return; + + serv_puts("MSGS ALL|0|1"); + serv_gets(buf); + if (buf[0] == '8') { + serv_puts("subj|__ WebCit Preferences __"); + serv_puts("000"); + } + while (serv_gets(buf), strcmp(buf, "000")) { + msgnum = atol(buf); + } + + if (msgnum > 0L) { + serv_printf("MSG0 %ld", msgnum); + serv_gets(buf); + if (buf[0] == '1') { + while (serv_gets(buf), + (strcmp(buf, "text") && strcmp(buf, "000"))) { + } + if (!strcmp(buf, "text")) { + while (serv_gets(buf), strcmp(buf, "000")) { + if (WC->preferences == NULL) { + WC->preferences = malloc(SIZ); + strcpy(WC->preferences, ""); + } + else { + WC->preferences = realloc( + WC->preferences, + strlen(WC->preferences) + +SIZ + ); + } + strcat(WC->preferences, buf); + strcat(WC->preferences, "\n"); + } + } + } + } + + /* Go back to the room we're supposed to be in */ + serv_printf("GOTO %s", WC->wc_roomname); + serv_gets(buf); +} + +void save_preferences(void) { + char buf[SIZ]; + long msgnum = 0L; + + serv_printf("GOTO My Citadel Config"); + serv_gets(buf); + if (buf[0] != '2') { /* try to create the config room if not there */ + serv_printf("CRE8 1|My Citadel Config|4|0"); + serv_gets(buf); + serv_printf("GOTO My Citadel Config"); + serv_gets(buf); + if (buf[0] != '2') return; /* oh well. */ + } + + serv_puts("MSGS ALL|0|1"); + serv_gets(buf); + if (buf[0] == '8') { + serv_puts("subj|__ WebCit Preferences __"); + serv_puts("000"); + } + while (serv_gets(buf), strcmp(buf, "000")) { + msgnum = atol(buf); + } + + if (msgnum > 0L) { + serv_printf("DELE %ld", msgnum); + serv_gets(buf); + } + + serv_printf("ENT0 1||0|1|__ WebCit Preferences __|"); + serv_gets(buf); + if (buf[0] == '4') { + serv_puts(WC->preferences); + serv_puts(""); + serv_puts("000"); + } + + /* Go back to the room we're supposed to be in */ + serv_printf("GOTO %s", WC->wc_roomname); + serv_gets(buf); +} + +void get_preference(char *key, char *value) { + int num_prefs; + int i; + char buf[SIZ]; + char thiskey[SIZ]; + + strcpy(value, ""); + + num_prefs = num_tokens(WC->preferences, '\n'); + for (i=0; ipreferences, i, '\n'); + extract_token(thiskey, buf, 0, '|'); + if (!strcasecmp(thiskey, key)) { + extract_token(value, buf, 1, '|'); + } + } +} + +void set_preference(char *key, char *value) { + int num_prefs; + int i; + char buf[SIZ]; + char thiskey[SIZ]; + char *newprefs = NULL; + + num_prefs = num_tokens(WC->preferences, '\n'); + for (i=0; ipreferences, i, '\n'); + extract_token(thiskey, buf, 0, '|'); + if (strcasecmp(thiskey, key)) { + if (newprefs == NULL) newprefs = strdup(""); + else { + newprefs = realloc(newprefs, + strlen(newprefs) + SIZ ); + } + strcat(newprefs, buf); + strcat(newprefs, "\n"); + } + } + + + if (newprefs == NULL) newprefs = strdup(""); + else { + newprefs = realloc(newprefs, + strlen(newprefs) + SIZ ); + } + sprintf(&newprefs[strlen(newprefs)], "%s|%s\n", key, value); + + save_preferences(); +} diff --git a/webcit/webcit.h b/webcit/webcit.h index e0c2556e5..1e4e2d00b 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -150,6 +150,7 @@ struct wcsession { struct urlcontent *urlstrings; int HaveExpressMessages; /* Nonzero if incoming msgs exist */ struct wcsubst *vars; + char *preferences; }; #define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|') @@ -300,3 +301,7 @@ void edituser(void); void change_view(void); void folders(void); void do_stuff_to_msgs(void); +void load_preferences(void); +void save_preferences(void); +void get_preference(char *key, char *value); +void set_preference(char *key, char *value);