* Completed the initial hack of the variable substitution template thingy.
authorArt Cancro <ajc@citadel.org>
Wed, 13 Sep 2000 04:13:59 +0000 (04:13 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 13 Sep 2000 04:13:59 +0000 (04:13 +0000)
  Check out static/login.html to see the first template.

webcit/ChangeLog
webcit/auth.c
webcit/subst.c
webcit/webcit.c
webcit/webcit.h

index ddf143a73533f1199de9c48bb700d4ae5467ede3..28c30b57cdeb2ca1891bc56bce5f6af078567740 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 212.9  2000/09/13 04:13:59  ajc
+* Completed the initial hack of the variable substitution template thingy.
+  Check out static/login.html to see the first template.
+
 Revision 212.8  2000/09/11 17:08:16  ajc
 * Started templatizing the login screen.  Not finished yet.
 
@@ -473,4 +477,3 @@ 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 bb30fe160e3e0c5b27ce8b9e7c6dda2f0a79099d..5ec9b829ee8c876ebec95a028d4892a1c2621dee 100644 (file)
@@ -45,16 +45,23 @@ char *axdefs[] =
  */
 void display_login(char *mesg)
 {
+       char buf[256];
+
        output_headers(3);
 
-       /*
-       mesg = mesg
-       hello = "mesg hello"
-       humannode = config.c_humannode
-       */
+       if (mesg != NULL) if (strlen(mesg) > 0) {
+               stresc(buf, mesg, 0);
+               svprintf("mesg", WCS_STRING, "%s", buf);
+       }
+
+       stresc(buf, serv_info.serv_humannode, 1);
+       svprintf("humannode", WCS_STRING, "%s", buf);
+
+       svprintf("hello", WCS_SERVCMD, "MESG hello");
 
        do_template("login.html");
 
+       clear_local_substs();
        wDumpContent(0);        /* No menu here; not logged in yet! */
 }
 
index e9a5c25e0fb402ba25cbb040d7d47d57de403a95..9753c580516007d64a8e570c12266a9b2794ff9c 100644 (file)
@@ -41,7 +41,8 @@ void clear_local_substs(void) {
        while (WC->vars != NULL) {
                ptr = WC->vars->next;
 
-               if (WC->vars->wcs_type == WCS_STRING) {
+               if ((WC->vars->wcs_type == WCS_STRING)
+                  || (WC->vars->wcs_type == WCS_SERVCMD)) {
                        free(WC->vars->wcs_value);
                }
 
@@ -54,7 +55,7 @@ void clear_local_substs(void) {
 /*
  * Add a substitution variable (local to this session)
  */
-void svprintf(char *keyname, const char *format,...)
+void svprintf(char *keyname, int keytype, const char *format,...)
 {
        va_list arg_ptr;
        char wbuf[1024];
@@ -66,7 +67,7 @@ void svprintf(char *keyname, const char *format,...)
 
        ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
        ptr->next = WC->vars;
-       ptr->wcs_type = WCS_STRING;
+       ptr->wcs_type = keytype;
        strcpy(ptr->wcs_key, keyname);
        ptr->wcs_value = malloc(strlen(wbuf)+1);
        strcpy(ptr->wcs_value, wbuf);
@@ -75,6 +76,33 @@ void svprintf(char *keyname, const char *format,...)
 
 
 
+/*
+ * back end for print_value_of() ... does a server command
+ */
+void pvo_do_cmd(char *servcmd) {
+       char buf[256];
+
+       serv_puts(servcmd);
+       serv_gets(buf);
+
+       switch(buf[0]) {
+               case '2':
+               case '3':
+               case '5':
+                       wprintf("%s\n", &buf[4]);
+                       break;
+               case '1':
+                       fmout(NULL);
+                       break;
+               case '4':
+                       wprintf("%s\n", &buf[4]);
+                       serv_puts("000");
+                       break;
+       }
+}
+
+
+
 /*
  * Print the value of a variable
  */
@@ -86,6 +114,9 @@ void print_value_of(char *keyname) {
                        if (ptr->wcs_type == WCS_STRING) {
                                wprintf("%s", ptr->wcs_value);
                        }
+                       else if (ptr->wcs_type == WCS_SERVCMD) {
+                               pvo_do_cmd(ptr->wcs_value);
+                       }
                }
        }
 }
@@ -132,9 +163,11 @@ void do_template(void *templatename) {
                                        if (inbuf[j]=='>') pos = j;
                                }
                                if (pos > 0) {
+                                       wprintf("%s", outbuf);
+                                       strcpy(outbuf, "");
+                                       olen = 0;
                                        strncpy(key, &inbuf[i+2], pos-i-2);
                                        print_value_of(key);
-                                       olen = strlen(outbuf);
                                        i = pos;
                                }
                                else {
index cfa488814602f2ff15d513504199dc67c8cd7393..9751dd47d078bea0ebf4e7abad587ed43dc2bcef 100644 (file)
@@ -204,47 +204,61 @@ void wDumpContent(int print_standard_html_footer)
 }
 
 
-void escputs1(char *strbuf, int nbsp)
+/*
+ * Copy a string, escaping characters which have meaning in HTML.  If
+ * nbsp is nonzero, spaces are converted to non-breaking spaces.
+ */
+void stresc(char *target, char *strbuf, int nbsp)
 {
        int a;
+       strcpy(target, "");
 
        for (a = 0; a < strlen(strbuf); ++a) {
                if (strbuf[a] == '<')
-                       wprintf("&lt;");
+                       strcat(target, "&lt;");
                else if (strbuf[a] == '>')
-                       wprintf("&gt;");
+                       strcat(target, "&gt;");
                else if (strbuf[a] == '&')
-                       wprintf("&amp;");
+                       strcat(target, "&amp;");
                else if (strbuf[a] == '\"')
-                       wprintf("&quot;");
+                       strcat(target, "&quot;");
                else if (strbuf[a] == '\'') 
-                       wprintf("&#39;");
+                       strcat(target, "&#39;");
                else if (strbuf[a] == LB)
-                       wprintf("<");
+                       strcat(target, "<");
                else if (strbuf[a] == RB)
-                       wprintf(">");
+                       strcat(target, ">");
                else if (strbuf[a] == QU)
-                       wprintf("\"");
+                       strcat(target, "\"");
                else if ((strbuf[a] == 32) && (nbsp == 1)) {
-                       wprintf("&nbsp;");
+                       strcat(target, "&nbsp;");
                } else {
-                       wprintf("%c", strbuf[a]);
+                       strncat(target, &strbuf[a], 1);
                }
        }
 }
 
+void escputs1(char *strbuf, int nbsp)
+{
+       char buf[1024];
+       stresc(buf, strbuf, nbsp);
+       wprintf("%s", buf);
+}
+
 void escputs(char *strbuf)
 {
        escputs1(strbuf, 0);
 }
 
-
-
+/*
+ * Escape a string for feeding out as a URL.
+ * FIXME this is not threadsafe!
+ */
 char *urlesc(char *strbuf)
 {
        int a, b, c;
        char *ec = " #&;`'|*?-~<>^()[]{}$\\";
-       static char outbuf[512];
+       static char outbuf[1024];
 
        strcpy(outbuf, "");
 
index 8a4ffd2fae66970530f37c3613dd1a563b16c0df..917db44b71e29545d59ba286c491aacbb09ed718 100644 (file)
@@ -104,7 +104,8 @@ struct wcsubst {
  */
 enum {
        WCS_STRING,
-       WCS_FUNCTION
+       WCS_FUNCTION,
+       WCS_SERVCMD
 };
        
 
@@ -190,6 +191,7 @@ void wprintf(const char *format,...);
 void extract(char *dest, char *source, int parmnum);
 int extract_int(char *source, int parmnum);
 void output_static(char *what);
+void stresc(char *target, char *strbuf, int nbsp);
 void escputs(char *strbuf);
 void url(char *buf);
 void escputs1(char *strbuf, int nbsp);
@@ -279,5 +281,5 @@ void end_webcit_session(void);
 void page_popup(void);
 void http_redirect(char *);
 void clear_local_substs(void);
-void svprintf(char *keyname, const char *format,...);
+void svprintf(char *keyname, int keytype, const char *format,...);
 void do_template(void *templatename);