urlcontent *u;
void *U;
long HKLen;
- char *HKey;
+ const char *HKey;
HashPos *Cursor;
Cursor = GetNewHashPos ();
* Return the value of a variable supplied to the current web page (from the url or a form)
*/
-const char *XBstr(char *key, size_t keylen, size_t *len)
+const char *XBstr(const char *key, size_t keylen, size_t *len)
{
void *U;
}
}
-const char *XBSTR(char *key, size_t *len)
+const char *XBSTR(const char *key, size_t *len)
{
void *U;
}
-const char *BSTR(char *key)
+const char *BSTR(const char *key)
{
void *U;
return ("");
}
-const char *Bstr(char *key, size_t keylen)
+const char *Bstr(const char *key, size_t keylen)
{
void *U;
return NULL;
}
-long LBstr(char *key, size_t keylen)
+long LBstr(const char *key, size_t keylen)
{
void *U;
return (0);
}
-long LBSTR(char *key)
+long LBSTR(const char *key)
{
void *U;
return (0);
}
-int IBstr(char *key, size_t keylen)
+int IBstr(const char *key, size_t keylen)
{
void *U;
return (0);
}
-int IBSTR(char *key)
+int IBSTR(const char *key)
{
void *U;
return (0);
}
-int HaveBstr(char *key, size_t keylen)
+int HaveBstr(const char *key, size_t keylen)
{
void *U;
return (0);
}
-int HAVEBSTR(char *key)
+int HAVEBSTR(const char *key)
{
void *U;
}
-int YesBstr(char *key, size_t keylen)
+int YesBstr(const char *key, size_t keylen)
{
void *U;
return (0);
}
-int YESBSTR(char *key)
+int YESBSTR(const char *key)
{
void *U;
}
+
/*
* Copy a string, escaping characters which have meaning in HTML.
*
- * target target buffer
- * strbuf source buffer
- * nbsp If nonzero, spaces are converted to non-breaking spaces.
- * nolinebreaks if set, linebreaks are removed from the string.
+ * target target buffer
+ * strbuf source buffer
+ * nbsp If nonzero, spaces are converted to non-breaking spaces.
+ * nolinebreaks if set, linebreaks are removed from the string.
*/
long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
{
- char *aptr, *bptr, *eptr;
-
- *target = '\0';
- aptr = strbuf;
- bptr = target;
- eptr = target + tSize - 6; // our biggest unit to put in...
-
- while ((bptr < eptr) && !IsEmptyStr(aptr) ){
- if (*aptr == '<') {
- memcpy(bptr, "<", 4);
- bptr += 4;
- }
- else if (*aptr == '>') {
- memcpy(bptr, ">", 4);
- bptr += 4;
- }
- else if (*aptr == '&') {
- memcpy(bptr, "&", 5);
- bptr += 5;
- }
- else if (*aptr == '\"') {
- memcpy(bptr, """, 6);
- bptr += 6;
- }
- else if (*aptr == '\'') {
- memcpy(bptr, "'", 5);
- bptr += 5;
- }
- else if (*aptr == LB) {
- *bptr = '<';
- bptr ++;
- }
- else if (*aptr == RB) {
- *bptr = '>';
- bptr ++;
- }
- else if (*aptr == QU) {
- *bptr ='"';
- bptr ++;
- }
- else if ((*aptr == 32) && (nbsp == 1)) {
- memcpy(bptr, " ", 6);
- bptr += 6;
- }
- else if ((*aptr == '\n') && (nolinebreaks)) {
- *bptr='\0'; /* nothing */
- }
- else if ((*aptr == '\r') && (nolinebreaks)) {
- *bptr='\0'; /* nothing */
- }
- else{
- *bptr = *aptr;
- bptr++;
- }
- aptr ++;
- }
- *bptr = '\0';
- if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
- return -1;
- return (bptr - target);
+ char *aptr, *bptr, *eptr;
+
+ *target = '\0';
+ aptr = strbuf;
+ bptr = target;
+ eptr = target + tSize - 6; // our biggest unit to put in...
+
+
+ while ((bptr < eptr) && !IsEmptyStr(aptr) ){
+ if (*aptr == '<') {
+ memcpy(bptr, "<", 4);
+ bptr += 4;
+ }
+ else if (*aptr == '>') {
+ memcpy(bptr, ">", 4);
+ bptr += 4;
+ }
+ else if (*aptr == '&') {
+ memcpy(bptr, "&", 5);
+ bptr += 5;
+ }
+ else if (*aptr == '\"') {
+ memcpy(bptr, """, 6);
+ bptr += 6;
+ }
+ else if (*aptr == '\'') {
+ memcpy(bptr, "'", 5);
+ bptr += 5;
+ }
+ else if (*aptr == LB) {
+ *bptr = '<';
+ bptr ++;
+ }
+ else if (*aptr == RB) {
+ *bptr = '>';
+ bptr ++;
+ }
+ else if (*aptr == QU) {
+ *bptr ='"';
+ bptr ++;
+ }
+ else if ((*aptr == 32) && (nbsp == 1)) {
+ memcpy(bptr, " ", 6);
+ bptr += 6;
+ }
+ else if ((*aptr == '\n') && (nolinebreaks)) {
+ *bptr='\0'; /* nothing */
+ }
+ else if ((*aptr == '\r') && (nolinebreaks)) {
+ *bptr='\0'; /* nothing */
+ }
+ else{
+ *bptr = *aptr;
+ bptr++;
+ }
+ aptr ++;
+ }
+ *bptr = '\0';
+ if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
+ return -1;
+ return (bptr - target);
}
+
void escputs1(char *strbuf, int nbsp, int nolinebreaks)
{
- char *buf;
- long Siz;
+ StrEscAppend(WC->WBuf, NULL, strbuf, nbsp, nolinebreaks);
+}
- if (strbuf == NULL) return;
- Siz = (3 * strlen(strbuf)) + SIZ ;
- buf = malloc(Siz);
- stresc(buf, Siz, strbuf, nbsp, nolinebreaks);
- wprintf("%s", buf);
- free(buf);
+void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks)
+{
+ StrEscAppend(WC->WBuf, strbuf, NULL, nbsp, nolinebreaks);
}
/*
}
+/*
+ * static wrapper for ecsputs1
+ */
+void StrEscPuts(const StrBuf *strbuf)
+{
+ StrEscputs1(strbuf, 0, 0);
+}
+
+
/*
* urlescape buffer and print it to the client
*/
-void urlescputs(char *strbuf)
+void urlescputs(const char *strbuf)
{
- char outbuf[SIZ];
-
- urlesc(outbuf, SIZ, strbuf);
- wprintf("%s", outbuf);
+ StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
}
+
+/*
+ * urlescape buffer and print it to the client
+ */
+void UrlescPutStrBuf(const StrBuf *strbuf)
+{
+ StrBufUrlescAppend(WC->WBuf, strbuf, NULL);
+}
+
/**
* urlescape buffer and print it as header
*/
-void hurlescputs(char *strbuf) {
- char outbuf[SIZ];
-
- urlesc(outbuf, SIZ, strbuf);
- hprintf("%s", outbuf);
+void hurlescputs(const char *strbuf)
+{
+ StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
}
wprintf("%s", outbuf);
}
-/*
- * Copy a string, escaping characters for message text hold
- */
-void msgesc(char *target, size_t tlen, char *strbuf)
-{
- int len;
- char *tend;
- char *send;
- char *tptr;
- char *sptr;
-
- target[0]='\0';
- len = strlen (strbuf);
- send = strbuf + len;
- tend = target + tlen;
- sptr = strbuf;
- tptr = target;
-
- while (!IsEmptyStr(sptr) &&
- (sptr < send) &&
- (tptr < tend)) {
-
- if (*sptr == '\n')
- *tptr = ' ';
- else if (*sptr == '\r')
- *tptr = ' ';
- else if (*sptr == '\'') {
- if (tend - tptr < 8)
- return;
- *(tptr++) = '&';
- *(tptr++) = '#';
- *(tptr++) = '3';
- *(tptr++) = '9';
- *tptr = ';';
- } else {
- *tptr = *sptr;
- }
- tptr++; sptr++;
- }
- *tptr = '\0';
-}
-
/*
* print a string to the client after cleaning it with msgesc() and stresc()
*/
void msgescputs1( char *strbuf)
{
- char *outbuf;
- char *outbuf2;
- int buflen;
+ StrBuf *OutBuf = NewStrBuf();
- if (strbuf == NULL) return;
- buflen = 3 * strlen(strbuf) + SIZ;
- outbuf = malloc( buflen);
- outbuf2 = malloc( buflen);
- msgesc(outbuf, buflen, strbuf);
- stresc(outbuf2, buflen, outbuf, 0, 0);
- wprintf("%s", outbuf2);
- free(outbuf);
- free(outbuf2);
+ if ((strbuf == NULL) || IsEmptyStr(strbuf))
+ return;
+ StrMsgEscAppend(OutBuf, NULL, strbuf);
+ StrEscAppend(WC->WBuf, OutBuf, NULL, 0, 0);
+ FreeStrBuf(&OutBuf);
}
/*
* print a string to the client after cleaning it with msgesc()
*/
void msgescputs(char *strbuf) {
- char *outbuf;
- size_t len;
-
- if (strbuf == NULL) return;
- len = (3 * strlen(strbuf)) + SIZ;
- outbuf = malloc(len);
- msgesc(outbuf, len, strbuf);
- wprintf("%s", outbuf);
- free(outbuf);
+ if ((strbuf != NULL) && !IsEmptyStr(strbuf))
+ StrMsgEscAppend(WC->WBuf, NULL, strbuf);
}
/* ICONBAR */
if (do_htmlhead) {
-
+ begin_burst();
/* check for ImportantMessages (these display in a div overlaying the main screen) */
if (!IsEmptyStr(WC->ImportantMessage)) {
char buf[256];
off_t bytes;
char content_type[256];
- char *content = NULL;
serv_printf("OPNA %s|%s", msgnum, partnum);
serv_getln(buf, sizeof buf);
if (buf[0] == '2') {
bytes = extract_long(&buf[4], 0);
- content = malloc(bytes + 2);
if (force_download) {
strcpy(content_type, "application/octet-stream");
}
wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
end_burst();
}
-
}
else {
return(NULL);
}
-
}
* A template has been requested
*/
void url_do_template(void) {
- do_template(bstr("template"), NULL);
+ const StrBuf *Tmpl = sbstr("template");
+ begin_burst();
+ output_headers(1, 0, 0, 0, 1, 0);
+ DoTemplate(ChrPtr(Tmpl), StrLength(Tmpl), NULL, NULL);
+ end_burst();
}
* Convenience functions to wrap around asynchronous ajax responses
*/
void begin_ajax_response(void) {
+ struct wcsession *WCC = WC;
+
+ FlushStrBuf(WCC->HBuf);
output_headers(0, 0, 0, 0, 0, 0);
hprintf("Content-type: text/html; charset=UTF-8\r\n"
"Server: %s\r\n"
"Connection: close\r\n"
- "Pragma: no-cache\r\n"
- "Cache-Control: no-cache\r\n"
- "Expires: -1\r\n"
,
PACKAGE_STRING);
begin_burst();
{
char buf[256];
- begin_ajax_response();
if ( (time(NULL) - WC->last_pager_check) < 30) {
wprintf("NO\n");
}
wprintf("NO");
}
}
- end_ajax_response();
}
/**
content = malloc(BuffSize);
memset(content, 0, BuffSize);
snprintf(content, BuffSize, "Content-type: %s\n"
- "Content-length: %d\n\n",
- ContentType, ContentLength);
+ "Content-length: %d\n\n",
+ ContentType, ContentLength);
+/*
+ hprintf("Content-type: %s\n"
+ "Content-length: %d\n\n",
+ ContentType, ContentLength);
+*/
body_start = strlen(content);
/** Read the entire input data at once. */
- client_read(WCC->http_sock, &content[body_start], ContentLength);
+ client_read(&WCC->http_sock, &content[body_start], ContentLength);
if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
StrBuf *Content;
//cmd[len - a] = '\0';
Params = _NewConstStrBuf(&cmd[a + 1], len - a);
addurls(Params);
+ FreeStrBuf(&Params);
cmd[a] = 0;
len = a - 1;
}
output_headers(1, 1, 1, 0, 0, 0);
wprintf("Session: %d<hr />\n", WC->wc_session);
wprintf("Command: <br /><PRE>\n");
- escputs(WC->UrlFragment1);
+ StrEscPuts(WC->UrlFragment1);
wprintf("<br />\n");
- escputs(WC->UrlFragment2);
+ StrEscPuts(WC->UrlFragment2);
wprintf("</PRE><hr />\n");
wprintf("Variables: <br /><PRE>\n");
dump_vars();
1);
}
+
+int ConditionalImportantMesage(WCTemplateToken *Tokens, void *Context)
+{
+ struct wcsession *WCC = WC;
+ if (WCC != NULL)
+ return (!IsEmptyStr(WCC->ImportantMessage));
+ else
+ return 0;
+}
+
+void tmplput_importantmessage(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+{
+ struct wcsession *WCC = WC;
+
+ if (WCC != NULL) {
+ StrEscAppend(Target, NULL, WCC->ImportantMessage, 0, 0);
+ WCC->ImportantMessage[0] = '\0';
+ }
+}
+
+void tmplput_offer_start_page(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context)
+{
+ offer_start_page();
+}
+
void
InitModule_WEBCIT
(void)
WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
WebcitAddUrlHandler(HKEY("diagnostics"), diagnostics, NEED_URL);
+ RegisterConditional(HKEY("COND:IMPMSG"), 0, ConditionalImportantMesage);
+ RegisterNamespace("IMPORTANTMESSAGE", 0, 0, tmplput_importantmessage);
+ RegisterNamespace("OFFERSTARTPAGE", 0, 0, tmplput_offer_start_page);
}