Check out static/login.html to see the first template.
$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.
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
*/
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! */
}
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);
}
/*
* 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];
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);
+/*
+ * 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
*/
if (ptr->wcs_type == WCS_STRING) {
wprintf("%s", ptr->wcs_value);
}
+ else if (ptr->wcs_type == WCS_SERVCMD) {
+ pvo_do_cmd(ptr->wcs_value);
+ }
}
}
}
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 {
}
-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("<");
+ strcat(target, "<");
else if (strbuf[a] == '>')
- wprintf(">");
+ strcat(target, ">");
else if (strbuf[a] == '&')
- wprintf("&");
+ strcat(target, "&");
else if (strbuf[a] == '\"')
- wprintf(""");
+ strcat(target, """);
else if (strbuf[a] == '\'')
- wprintf("'");
+ strcat(target, "'");
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(" ");
+ strcat(target, " ");
} 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, "");
*/
enum {
WCS_STRING,
- WCS_FUNCTION
+ WCS_FUNCTION,
+ WCS_SERVCMD
};
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);
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);