2005-01-19 20:16:09 +03:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is SniffURI.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Erik van der Poel <erik@vanderpoel.org>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-01 21:24:20 +03:00
|
|
|
|
2005-01-19 20:16:09 +03:00
|
|
|
#include "all.h"
|
2000-02-01 21:24:20 +03:00
|
|
|
|
2005-02-05 19:30:04 +03:00
|
|
|
#define CONTROL_START "<s>"
|
2000-02-01 21:24:20 +03:00
|
|
|
#define CONTROL(str) CONTROL_START str CONTROL_END
|
2005-02-05 19:30:04 +03:00
|
|
|
#define CONTROL_END "</s>"
|
2005-01-21 23:11:50 +03:00
|
|
|
#define NL "\n"
|
2000-02-01 21:24:20 +03:00
|
|
|
|
|
|
|
static int verbose = 0;
|
|
|
|
|
|
|
|
static void
|
2005-01-25 11:22:29 +03:00
|
|
|
print(View *view, Buf *b)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char *hex;
|
|
|
|
char hexBuf[4];
|
|
|
|
int i;
|
|
|
|
unsigned long inLen;
|
|
|
|
unsigned long j;
|
|
|
|
int len;
|
|
|
|
char *p;
|
|
|
|
char *replacement;
|
|
|
|
char *result;
|
|
|
|
unsigned char *str;
|
|
|
|
|
|
|
|
hex = "0123456789ABCDEF";
|
2005-01-25 11:22:29 +03:00
|
|
|
str = bufCopyMemory(b, &inLen);
|
2000-02-01 21:24:20 +03:00
|
|
|
|
|
|
|
buf[1] = 0;
|
|
|
|
len = 0;
|
|
|
|
p = NULL;
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < inLen; j++)
|
|
|
|
{
|
|
|
|
switch (str[j])
|
|
|
|
{
|
|
|
|
case '\r':
|
2005-01-25 11:22:29 +03:00
|
|
|
if (((j + 1) < inLen) && (str[j + 1] == '\n'))
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
|
|
|
j++;
|
|
|
|
replacement = CONTROL("CRLF") NL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
replacement = CONTROL("CR") NL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
replacement = CONTROL("LF") NL;
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
replacement = CONTROL("TAB");
|
|
|
|
break;
|
|
|
|
case 0x1b:
|
|
|
|
replacement = CONTROL("ESC");
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
replacement = "<";
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
replacement = ">";
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
replacement = "&";
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
case '"':
|
|
|
|
if (view->backslash)
|
|
|
|
{
|
|
|
|
buf[0] = '\\';
|
|
|
|
buf[1] = str[j];
|
|
|
|
buf[2] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[0] = str[j];
|
|
|
|
buf[1] = 0;
|
|
|
|
}
|
|
|
|
replacement = buf;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ((str[j] <= 0x1f) || (str[j] >= 0x7f))
|
|
|
|
{
|
|
|
|
replacement = buf;
|
|
|
|
strcpy(buf, CONTROL_START);
|
|
|
|
hexBuf[0] = 'x';
|
|
|
|
hexBuf[1] = hex[str[j] >> 4];
|
|
|
|
hexBuf[2] = hex[str[j] & 0x0f];
|
|
|
|
hexBuf[3] = 0;
|
|
|
|
strcat(buf, hexBuf);
|
|
|
|
strcat(buf, CONTROL_END);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
replacement = buf;
|
|
|
|
buf[0] = str[j];
|
|
|
|
buf[1] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
strcpy(p, replacement);
|
|
|
|
p += strlen(replacement);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len += strlen(replacement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
result = calloc(len + 1, 1);
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"cannot calloc toHTML string\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
p = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(view->out, "%s", result);
|
|
|
|
|
|
|
|
free(result);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTML(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<em>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</em>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTMLAttributeName(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<u>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</u>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTMLAttributeValue(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<i>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</i>");
|
2005-02-03 04:06:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
viewHTMLDeclaration(App *app, Buf *buf)
|
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<tt>");
|
2005-02-03 04:06:24 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</tt>");
|
2005-02-03 04:06:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
viewHTMLProcessingInstruction(App *app, Buf *buf)
|
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<var>");
|
2005-02-03 04:06:24 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</var>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTMLTag(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<b>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</b>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTMLText(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTTP(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTTPHeaderName(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<u>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</u>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-25 11:22:29 +03:00
|
|
|
viewHTTPHeaderValue(App *app, Buf *buf)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "<i>");
|
2005-01-25 11:22:29 +03:00
|
|
|
print(&app->view, buf);
|
2005-02-05 19:30:04 +03:00
|
|
|
fprintf(app->view.out, "</i>");
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
viewVerbose(void)
|
|
|
|
{
|
|
|
|
verbose = 1;
|
|
|
|
}
|
|
|
|
|
2005-02-04 23:11:34 +03:00
|
|
|
void
|
|
|
|
viewPrintHTML(App *app, char *str)
|
|
|
|
{
|
|
|
|
fprintf(app->view.out, "%s", str);
|
|
|
|
fflush(app->view.out);
|
|
|
|
}
|
|
|
|
|
2000-02-01 21:24:20 +03:00
|
|
|
void
|
2005-01-21 00:09:40 +03:00
|
|
|
viewReport(App *app, char *str)
|
2000-02-01 21:24:20 +03:00
|
|
|
{
|
2005-01-25 11:22:29 +03:00
|
|
|
unsigned char *esc;
|
|
|
|
|
2000-02-01 21:24:20 +03:00
|
|
|
if (verbose)
|
|
|
|
{
|
2005-02-04 23:11:34 +03:00
|
|
|
esc = escapeHTML((unsigned char *) str);
|
|
|
|
fprintf(app->view.out, "%s\n", (char *) esc);
|
2005-01-25 11:22:29 +03:00
|
|
|
free(esc);
|
2005-01-21 00:09:40 +03:00
|
|
|
fflush(app->view.out);
|
2000-02-01 21:24:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 21:03:44 +03:00
|
|
|
void
|
2005-01-21 00:09:40 +03:00
|
|
|
viewReportHTML(App *app, char *str)
|
2005-01-19 21:03:44 +03:00
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
{
|
2005-02-04 23:11:34 +03:00
|
|
|
fprintf(app->view.out, "%s\n", str);
|
2005-01-21 00:09:40 +03:00
|
|
|
fflush(app->view.out);
|
2005-01-19 21:03:44 +03:00
|
|
|
}
|
|
|
|
}
|