]> code.citadel.org Git - citadel.git/commitdiff
* Templatized the room banner.
authorArt Cancro <ajc@citadel.org>
Sun, 24 Sep 2000 04:17:19 +0000 (04:17 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 24 Sep 2000 04:17:19 +0000 (04:17 +0000)
webcit/ChangeLog
webcit/roomops.c
webcit/static/roombanner.html [new file with mode: 0644]
webcit/subst.c
webcit/webcit.h

index b820f8766810db6f80873cb9fc6b83b6db9efb69..bda86fe767a82e5d28dfd6e7cbfc621300623427 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 212.12  2000/09/24 04:17:16  ajc
+* Templatized the room banner.
+
 Revision 212.11  2000/09/17 03:29:45  ajc
 * Templatized the "<BODY BACKGROUND=...>" type stuff that starts each page.
 
@@ -484,3 +487,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 008b75d338abde25e24106abf74da533a3743687..80714c61ca0d7dafbe11adbe6eb1eb261ad49299 100644 (file)
@@ -285,7 +285,7 @@ void zapped_list(void)
 /*
  * read this room's info file (set v to 1 for verbose mode)
  */
-void readinfo(int v)
+void readinfo(void)
 {
        char buf[256];
 
@@ -296,50 +296,19 @@ void readinfo(int v)
                fmout(NULL);
                wprintf("</FONT>");
        }
-       else {
-               if (v == 1)
-                       wprintf("<EM>%s</EM><BR>\n", &buf[4]);
-       }
 }
 
 
 
-void embed_room_banner(char *got) {
-       char buf[256];
-       char fakegot[256];
-       static int remember_new_mail = (-1);
 
-       /* We need to have the information returned by a GOTO server command.
-        * If it isn't supplied, we fake it by issuing our own GOTO.
-        */
-       if (got == NULL) {
-               serv_printf("GOTO %s", WC->wc_roomname);
-               serv_gets(fakegot);
-               got = fakegot;
-       }
-
-       /* Check for new mail. */
-       WC->new_mail = extract_int(&got[4], 9);
-
-       /* Now start spewing HTML. */
-       wprintf("<CENTER><TABLE width=100%% border=0 cellpadding=5><TR>");
+/* Display room graphic.  The server doesn't actually
+ * need the room name, but we supply it in order to
+ * keep the browser from using a cached graphic from 
+ * another room.
+ */
+void embed_room_graphic(void) {
+       char buf[256];
 
-       if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
-               wprintf("<TD VALIGN=TOP><A HREF=\"/ungoto\">");
-               wprintf("<IMG SRC=\"/static/back.gif\" BORDER=0>");
-               wprintf("<BR><FONT SIZE=-2>Previous room</FONT></A></TD>");
-       }
-       wprintf("<TD VALIGN=TOP BGCOLOR=444455>");
-       wprintf("<FONT SIZE=+2 COLOR=FFFFEE>%s</FONT><BR>", WC->wc_roomname);
-       wprintf("<FONT COLOR=DDDDCC>%d new of %d messages</FONT></TD>\n",
-               extract_int(&got[4], 1),
-               extract_int(&got[4], 2));
-
-       /* Display room graphic.  The server doesn't actually
-        * need the room name, but we supply it in order to
-        * keep the browser from using a cached graphic from 
-        * another room.
-        */
        serv_puts("OIMG _roompic_");
        serv_gets(buf);
        if (buf[0] == '2') {
@@ -350,24 +319,50 @@ void embed_room_banner(char *got) {
                serv_puts("CLOS");
                serv_gets(buf);
        }
-       wprintf("<TD VALIGN=TOP>");
-       readinfo(0);
-       wprintf("</TD>");
 
-       /* Let the user know if new mail has arrived */
-       if ( (WC->new_mail > remember_new_mail) && (WC->new_mail>0) ) {
+}
+
+
+/* Let the user know if new mail has arrived 
+ */
+void embed_newmail_button(void) {
+       if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
                wprintf("<TD VALIGN=TOP>"
                        "<IMG SRC=\"/static/mail.gif\" border=0 "
                        "ALT=\"You have new mail\">"
                        "<BR><BLINK>%d</BLINK>", WC->new_mail);
                wprintf("<FONT SIZE=-2> new mail messages</FONT></TD>");
-               remember_new_mail = WC->new_mail;
+               WC->remember_new_mail = WC->new_mail;
+       }
+}
+
+
+
+void embed_room_banner(char *got) {
+       char fakegot[256];
+
+       /* We need to have the information returned by a GOTO server command.
+        * If it isn't supplied, we fake it by issuing our own GOTO.
+        */
+       if (got == NULL) {
+               serv_printf("GOTO %s", WC->wc_roomname);
+               serv_gets(fakegot);
+               got = fakegot;
        }
 
-       wprintf("<TD VALIGN=TOP><A HREF=\"/gotonext\">");
-       wprintf("<IMG SRC=\"/static/forward.gif\" border=0>");
-       wprintf("<BR><FONT SIZE=-2>Next room</FONT></A></TD>");
-       wprintf("</TR></TABLE></CENTER>\n");
+       /* Check for new mail. */
+       WC->new_mail = extract_int(&got[4], 9);
+
+       svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
+       svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
+       svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
+       svcallback("ROOMPIC", embed_room_graphic);
+       svcallback("ROOMINFO", readinfo);
+       svcallback("YOUHAVEMAIL", embed_newmail_button);
+
+
+       do_template("roombanner.html");
+       clear_local_substs();
 }
 
 
diff --git a/webcit/static/roombanner.html b/webcit/static/roombanner.html
new file mode 100644 (file)
index 0000000..4a7c1fe
--- /dev/null
@@ -0,0 +1,32 @@
+<CENTER>
+<TABLE width=100% border=0 cellpadding=5>
+<TR>
+
+<TD VALIGN=TOP><A HREF="/ungoto">
+<IMG SRC="/static/back.gif" BORDER=0>
+<BR><FONT SIZE=-2>Previous room</FONT></A>
+</TD>
+
+<TD VALIGN=TOP BGCOLOR=444455>
+<FONT SIZE=+2 COLOR=FFFFEE><?ROOMNAME></FONT><BR>
+<FONT COLOR=DDDDCC><?NEWMSGS> new of <?TOTALMSGS> messages</FONT>
+</TD>
+
+<TD>
+<?ROOMPIC>
+</TD>
+
+<TD VALIGN=TOP>
+<?ROOMINFO>
+</TD>
+
+<TD VALIGN=TOP>
+<?YOUHAVEMAIL>
+</TD>
+
+<TD VALIGN=TOP><A HREF="/gotonext">
+<IMG SRC="/static/forward.gif" border=0>
+<BR><FONT SIZE=-2>Next room</FONT></A>
+</TD>
+
+</TR></TABLE></CENTER>
index 9753c580516007d64a8e570c12266a9b2794ff9c..6e348dae33e41c1c522a514522d10fec72ba470e 100644 (file)
@@ -74,6 +74,21 @@ void svprintf(char *keyname, int keytype, const char *format,...)
        WC->vars = ptr;
 }
 
+/*
+ * Add a substitution variable (local to this session) that does a callback
+ */
+void svcallback(char *keyname, void (*fcn_ptr)() )
+{
+       struct wcsubst *ptr;
+
+       ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
+       ptr->next = WC->vars;
+       ptr->wcs_type = WCS_FUNCTION;
+       strcpy(ptr->wcs_key, keyname);
+       ptr->wcs_function = fcn_ptr;
+       WC->vars = ptr;
+}
+
 
 
 /*
@@ -108,6 +123,7 @@ void pvo_do_cmd(char *servcmd) {
  */
 void print_value_of(char *keyname) {
        struct wcsubst *ptr;
+       void *fcn();
 
        for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) {
                if (!strcasecmp(ptr->wcs_key, keyname)) {
@@ -117,6 +133,9 @@ void print_value_of(char *keyname) {
                        else if (ptr->wcs_type == WCS_SERVCMD) {
                                pvo_do_cmd(ptr->wcs_value);
                        }
+                       else if (ptr->wcs_type == WCS_FUNCTION) {
+                               (*ptr->wcs_function) ();
+                       }
                }
        }
 }
@@ -132,8 +151,7 @@ void do_template(void *templatename) {
        char inbuf[1024];
        char outbuf[sizeof inbuf];
        char key[sizeof inbuf];
-       int i, j, pos;
-       int olen;
+       int i, pos;
 
        strcpy(filename, "static/");
        strcat(filename, templatename);
@@ -150,32 +168,31 @@ void do_template(void *templatename) {
 
        while (fgets(inbuf, sizeof inbuf, fp) != NULL) {
                strcpy(outbuf, "");
-               olen = 0;
 
-               for (i=0; i<strlen(inbuf); ++i) {
-                       if (strncmp(&inbuf[i], "<?", 2)) {
-                               outbuf[olen] = inbuf[i];
-                               outbuf[++olen] = 0;
+               while (strlen(inbuf) > 0) {
+                       pos = (-1);
+                       for (i=strlen(inbuf); i>=0; --i) {
+                               if ((inbuf[i]=='<')&&(inbuf[i+1]=='?')) pos = i;
+                       }
+                       if (pos < 0) {
+                               wprintf("%s", inbuf);
+                               strcpy(inbuf, "");
                        }
                        else {
-                               pos = (-1);
-                               for (j=strlen(inbuf); j>=i;  --j)  {
-                                       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);
-                                       i = pos;
-                               }
-                               else {
-                                       i = i + 2;
+                               strncpy(outbuf, inbuf, pos);
+                               outbuf[pos] = 0;
+                               wprintf("%s", outbuf);
+                               strcpy(inbuf, &inbuf[pos]);
+                               pos = 1;
+                               for (i=strlen(inbuf); i>=0; --i) {
+                                       if (inbuf[i]=='>') pos = i;
                                }
+                               strncpy(key, &inbuf[2], pos-2);
+                               key[pos-2] = 0;
+                               print_value_of(key);
+                               strcpy(inbuf, &inbuf[pos+1]);
                        }
                }
-               wprintf("%s", outbuf);
        }
 
        fclose(fp);
index 917db44b71e29545d59ba286c491aacbb09ed718..7c7d0b033be4c2fb540f7b38480a30db3d0a4a8b 100644 (file)
@@ -97,6 +97,7 @@ struct wcsubst {
        int wcs_type;
        char wcs_key[32];
        void *wcs_value;
+       void (*wcs_function)(void);
 };
 
 /*
@@ -132,6 +133,7 @@ struct wcsession {
        int upload_length;
        char *upload;
        int new_mail;
+       int remember_new_mail;
        int need_vali;
         pthread_mutex_t SessionMutex;  /* mutex for exclusive access */
         time_t lastreq;                        /* Timestamp of most recent HTTP */
@@ -282,4 +284,5 @@ void page_popup(void);
 void http_redirect(char *);
 void clear_local_substs(void);
 void svprintf(char *keyname, int keytype, const char *format,...);
+void svcallback(char *keyname, void (*fcn_ptr)() );
 void do_template(void *templatename);