* Preferences framework
authorArt Cancro <ajc@citadel.org>
Wed, 8 May 2002 03:38:58 +0000 (03:38 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 8 May 2002 03:38:58 +0000 (03:38 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/auth.c
webcit/context_loop.c
webcit/preferences.c [new file with mode: 0644]
webcit/webcit.h

index 58dceeb6591fb8920d594bfbaaae4f75481173ff..c41e280c2a4a49a2eb47ef45509d335cde7859a2 100644 (file)
@@ -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 <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index aef57a3f788ff8123fd0547ce6bbbdffa1791fee..beb446a2b34c6a2cc4f9476ce361e9ba247fd83c 100644 (file)
@@ -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
 
index ac7acc8e2e6f84e8e6dcfb76213161d19bd17944..3871d938ce0633bbff556c00cf76f9d9b86e719d 100644 (file)
@@ -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();
 }
 
 
index 99de823e712317c72b7a2f8f254e22078a6f0f20..30a41e41b250652b83461b2c2b5d5401ae116cb0 100644 (file)
@@ -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 (file)
index 0000000..71d61cc
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * preferences.c
+ *
+ * Manage user preferences with a little help from the Citadel server.
+ *
+ * $Id$
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <limits.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
+#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; i<num_prefs; ++i) {
+               extract_token(buf, WC->preferences, 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; i<num_prefs; ++i) {
+               extract_token(buf, WC->preferences, 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();
+}
index e0c2556e5ea1909af865c38b5ab0d6e86615c0e3..1e4e2d00b4ba4a4925288908757c5343595e8405 100644 (file)
@@ -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);