From 1cbd593259dcebba3f58c715f4389f60db27e275 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 11 Sep 2000 03:29:50 +0000 Subject: [PATCH] * Started working on a variable-substitution thing --- webcit/ChangeLog | 4 +- webcit/Makefile.in | 4 +- webcit/subst.c | 149 +++++++++++++++++++++++++++++++++++++++++++++ webcit/webcit.h | 25 +++++++- 4 files changed, 177 insertions(+), 5 deletions(-) create mode 100644 webcit/subst.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 942ae2fd1..8d5726cd2 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 212.7 2000/09/11 03:29:50 ajc +* Started working on a variable-substitution thing + Revision 212.6 2000/08/30 03:20:22 ajc * Put the wholist back into its own window. @@ -467,4 +470,3 @@ 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 7bd92c894..1be0c0305 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -26,11 +26,11 @@ 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 \ - mime_parser.o graphics.o netconf.o siteconfig.o $(LIBOBJS) + 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 \ - locate_host.o siteconfig.o \ + locate_host.o siteconfig.o subst.o \ mime_parser.o graphics.o netconf.o \ $(LIBOBJS) $(LIBS) -o webserver diff --git a/webcit/subst.c b/webcit/subst.c new file mode 100644 index 000000000..d3b6af925 --- /dev/null +++ b/webcit/subst.c @@ -0,0 +1,149 @@ +/* + * $Id$ + * + * Variable substitution type stuff + * + */ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" + +struct wcsubst *global_subst = NULL; + + +/* + * Clear out the list of substitution variables local to this session + */ +void clear_local_substs(void) { + struct wcsubst *ptr; + + while (WC->vars != NULL) { + ptr = WC->vars->next; + + if (WC->vars->wcs_type == WCS_STRING) { + free(WC->vars->wcs_value); + } + + free(WC->vars); + WC->vars = ptr; + } +} + + +/* + * Add a substitution variable (local to this session) + */ +void svprintf(char *keyname, const char *format,...) +{ + va_list arg_ptr; + char wbuf[1024]; + struct wcsubst *ptr; + + va_start(arg_ptr, format); + vsprintf(wbuf, format, arg_ptr); + va_end(arg_ptr); + + ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst)); + ptr->next = WC->vars; + ptr->wcs_type = WCS_STRING; + strcpy(ptr->wcs_key, keyname); + ptr->wcs_value = malloc(strlen(wbuf)+1); + strcpy(ptr->wcs_value, wbuf); + WC->vars = ptr; +} + + + +/* + * Print the value of a variable + */ +void print_value_of(char *keyname) { + struct wbsubst *ptr; + + for (ptr = WC->vars; ptr != NULL; ptr = ptr->next) { + if (!strcasecmp(ptr->wcs_key, keyname)) { + if (ptr->wcs_type == WCS_STRING) { + wprintf("%s", ptr->wcs_value); + } + } + } +} + + + +/* + * Display a variable-substituted template + */ +void do_template(void *templatename) { + char filename[PATH_MAX]; + FILE *fp; + char inbuf[1024]; + char outbuf[sizeof inbuf]; + char key[sizeof inbuf]; + int i, j, pos; + int olen; + + strcpy(filename, "static/"); + strcat(filename, templatename); + + fp = fopen(filename, "r"); + if (fp == NULL) { + wprintf("ERROR - could not open template "); + wprintf("'%s' - %s
\n", + templatename, strerror(errno)); + return; + } + + strcpy(inbuf, ""); + + while (fgets(inbuf, sizeof inbuf, fp) != NULL) { + strcpy(outbuf, ""); + olen = 0; + + for (i=0; i=i; --j) { + if (inbuf[j]=='>') pos = j; + } + if (pos > 0) { + strncpy(key, &inbuf[i+2], pos-i-2); + print_value_of(key); + olen = strlen(outbuf); + i = pos; + } + else { + i = i + 2; + } + } + } + wprintf("%s", outbuf); + } + + fclose(fp); +} diff --git a/webcit/webcit.h b/webcit/webcit.h index 84904bc03..8a4ffd2fa 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -89,9 +89,24 @@ struct roomlisting { +/* + * Dynamic content for variable substitution in templates + */ +struct wcsubst { + struct wcsubst *next; + int wcs_type; + char wcs_key[32]; + void *wcs_value; +}; - - +/* + * Values for wcs_type + */ +enum { + WCS_STRING, + WCS_FUNCTION +}; + /* * One of these is kept for each active Citadel session. @@ -126,6 +141,7 @@ struct wcsession { int fake_frames; struct urlcontent *urlstrings; int HaveExpressMessages; /* Nonzero if incoming msgs exist */ + struct wcsubst *vars; }; @@ -138,6 +154,8 @@ extern char floorlist[128][256]; extern char *axdefs[]; extern char *defaulthost, *defaultport; +extern struct wcsubst *global_subst; + void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room); @@ -260,3 +278,6 @@ void httpdate(char *buf, time_t thetime); 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 do_template(void *templatename); -- 2.39.2