зеркало из https://github.com/mozilla/gecko-dev.git
app callbacks are now overrideable function pointers instead of global funcs
this reduces the number of empty functions in the apps
This commit is contained in:
Родитель
68ce35dcd2
Коммит
fdd2d4eec6
|
@ -46,6 +46,7 @@ PURIFY =
|
|||
|
||||
OBJS = \
|
||||
addurl.$(OBJ) \
|
||||
app.$(OBJ) \
|
||||
file.$(OBJ) \
|
||||
hash.$(OBJ) \
|
||||
html.$(OBJ) \
|
||||
|
|
|
@ -46,6 +46,7 @@ PURIFY =
|
|||
|
||||
OBJS = \
|
||||
addurl.$(OBJ) \
|
||||
app.$(OBJ) \
|
||||
file.$(OBJ) \
|
||||
hash.$(OBJ) \
|
||||
html.$(OBJ) \
|
||||
|
|
|
@ -33,7 +33,7 @@ static HashTable *rejectedURLTable = NULL;
|
|||
static HashTable *urlTable = NULL;
|
||||
|
||||
static void
|
||||
addThisURL(void *a, unsigned char *str)
|
||||
addThisURL(App *app, unsigned char *str)
|
||||
{
|
||||
int addIt;
|
||||
/*
|
||||
|
@ -126,7 +126,7 @@ addThisURL(void *a, unsigned char *str)
|
|||
printf("%s\n", fragless);
|
||||
*/
|
||||
hashAdd(urlTable, fragless, NULL);
|
||||
(*addURLFunc)(a, url);
|
||||
(*addURLFunc)(app, url);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -144,7 +144,7 @@ addThisURL(void *a, unsigned char *str)
|
|||
}
|
||||
|
||||
void
|
||||
addURL(void *a, unsigned char *str)
|
||||
addURL(App *app, unsigned char *str)
|
||||
{
|
||||
int len;
|
||||
unsigned char *s;
|
||||
|
@ -152,7 +152,7 @@ addURL(void *a, unsigned char *str)
|
|||
unsigned char *u;
|
||||
URL *url;
|
||||
|
||||
addThisURL(a, str);
|
||||
addThisURL(app, str);
|
||||
|
||||
url = urlParse(str);
|
||||
if (!url)
|
||||
|
@ -198,7 +198,7 @@ addURL(void *a, unsigned char *str)
|
|||
slash[1] = 0;
|
||||
u[len] = 0;
|
||||
strcat((char *) u, (char *) s);
|
||||
addThisURL(a, u);
|
||||
addThisURL(app, u);
|
||||
slash[0] = 0;
|
||||
}
|
||||
else
|
||||
|
@ -213,7 +213,7 @@ addURL(void *a, unsigned char *str)
|
|||
}
|
||||
|
||||
static void
|
||||
urlHandler(void *a, HTML *html)
|
||||
urlHandler(App *app, HTML *html)
|
||||
{
|
||||
URL *url;
|
||||
|
||||
|
@ -227,7 +227,7 @@ urlHandler(void *a, HTML *html)
|
|||
printf("%s\n", url->url);
|
||||
printf("--------------------------------\n");
|
||||
*/
|
||||
addURL(a, url->url);
|
||||
addURL(app, url->url);
|
||||
urlFree(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
#include "url.h"
|
||||
|
||||
typedef void (*AddURLFunc)(void *a, URL *url);
|
||||
typedef void (*AddURLFunc)(App *app, URL *url);
|
||||
|
||||
void addURL(void *a, unsigned char *str);
|
||||
void addURL(App *app, unsigned char *str);
|
||||
void addURLInit(AddURLFunc addURLFunc, char **limitURLs, char **limitDomains);
|
||||
|
||||
#endif /* _ADDURL_H_ */
|
||||
|
|
|
@ -66,13 +66,15 @@
|
|||
typedef int socklen_t;
|
||||
#endif
|
||||
|
||||
typedef struct App App;
|
||||
|
||||
#include "addurl.h"
|
||||
#include "app.h"
|
||||
#include "file.h"
|
||||
#include "hash.h"
|
||||
#include "html.h"
|
||||
#include "http.h"
|
||||
#include "io.h"
|
||||
#include "main.h"
|
||||
#include "mime.h"
|
||||
#include "net.h"
|
||||
#include "thread.h"
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
/* ***** 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 ***** */
|
||||
|
||||
#include "all.h"
|
||||
|
||||
static void
|
||||
appContentType(App *app, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTML(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTMLAttributeName(App *app, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTMLAttributeValue(App *app, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTMLTag(App *app, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTMLText(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTTP(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTTPBody(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTTPCharSet(App *app, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTTPHeaderName(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appHTTPHeaderValue(App *app, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appStatus(App *app, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
appTime(App *app, int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
App appDefault =
|
||||
{
|
||||
appContentType,
|
||||
appHTML,
|
||||
appHTMLAttributeName,
|
||||
appHTMLAttributeValue,
|
||||
appHTMLTag,
|
||||
appHTMLText,
|
||||
appHTTP,
|
||||
appHTTPBody,
|
||||
appHTTPCharSet,
|
||||
appHTTPHeaderName,
|
||||
appHTTPHeaderValue,
|
||||
appStatus,
|
||||
appTime
|
||||
};
|
||||
|
||||
App *
|
||||
appAlloc(void)
|
||||
{
|
||||
App *app;
|
||||
|
||||
app = calloc(1, sizeof(App));
|
||||
if (!app)
|
||||
{
|
||||
fprintf(stderr, "cannot calloc app\n");
|
||||
exit(0);
|
||||
}
|
||||
*app = appDefault;
|
||||
|
||||
return app;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/* ***** 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 ***** */
|
||||
|
||||
#include "html.h"
|
||||
#include "io.h"
|
||||
#include "view.h"
|
||||
|
||||
enum {
|
||||
appTimeConnectSuccess,
|
||||
appTimeConnectFailure,
|
||||
appTimeGetHostByNameSuccess,
|
||||
appTimeGetHostByNameFailure,
|
||||
appTimeReadStream,
|
||||
appTimeTotal,
|
||||
|
||||
appTimeMax /* must be last */
|
||||
};
|
||||
|
||||
struct App
|
||||
{
|
||||
void (*contentType)(App *app, unsigned char *contentType);
|
||||
void (*html)(App *app, Input *input);
|
||||
void (*htmlAttributeName)(App *app, HTML *html, Input *input);
|
||||
void (*htmlAttributeValue)(App *app, HTML *html, Input *input);
|
||||
void (*htmlTag)(App *app, HTML *html, Input *input);
|
||||
void (*htmlText)(App *app, Input *input);
|
||||
void (*http)(App *app, Input *input);
|
||||
void (*httpBody)(App *app, Input *input);
|
||||
void (*httpCharSet)(App *app, unsigned char *charset);
|
||||
void (*httpHeaderName)(App *app, Input *input);
|
||||
void (*httpHeaderValue)(App *app, Input *input, unsigned char *url);
|
||||
void (*status)(App *app, char *message, char *file, int line);
|
||||
void (*time)(App *app, int task, struct timeval *theTime);
|
||||
|
||||
View view;
|
||||
void *data;
|
||||
};
|
||||
|
||||
extern App appDefault;
|
||||
|
||||
App *appAlloc(void);
|
|
@ -35,44 +35,26 @@ static char *passThese[] =
|
|||
NULL
|
||||
};
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
static void
|
||||
cgiviewHTML(App *app, Input *input)
|
||||
{
|
||||
viewHTML(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
static void
|
||||
cgiviewHTMLAttributeName(App *app, HTML *html, Input *input)
|
||||
{
|
||||
viewHTMLAttributeName(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTML(view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTMLAttributeName(view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
cgiviewHTMLAttributeValue(App *app, HTML *html, Input *input)
|
||||
{
|
||||
URL *url;
|
||||
View *view;
|
||||
unsigned char *urlstring;
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
view = &app->view;
|
||||
|
||||
if (html->currentAttributeIsURL)
|
||||
{
|
||||
|
@ -82,70 +64,50 @@ reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
|||
free(urlstring);
|
||||
urlFree(url);
|
||||
}
|
||||
viewHTMLAttributeValue(view, input);
|
||||
viewHTMLAttributeValue(app, input);
|
||||
if (html->currentAttributeIsURL)
|
||||
{
|
||||
fprintf(view->out, "</a>");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
cgiviewHTMLTag(App *app, HTML *html, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTMLTag(view, input);
|
||||
viewHTMLTag(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
static void
|
||||
cgiviewHTMLText(App *app, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTMLText(view, input);
|
||||
viewHTMLText(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
static void
|
||||
cgiviewHTTP(App *app, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTTP(view, input);
|
||||
viewHTTP(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
static void
|
||||
cgiviewHTTPBody(App *app, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTTP(view, input);
|
||||
viewHTTP(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
static void
|
||||
cgiviewHTTPHeaderName(App *app, Input *input)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
|
||||
viewHTTPHeaderName(view, input);
|
||||
viewHTTPHeaderName(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
static void
|
||||
cgiviewHTTPHeaderValue(App *app, Input *input, unsigned char *url)
|
||||
{
|
||||
View *view;
|
||||
unsigned char *urlstring;
|
||||
View *view;
|
||||
|
||||
view = a;
|
||||
view = &app->view;
|
||||
|
||||
if (url)
|
||||
{
|
||||
|
@ -153,25 +115,15 @@ reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
|||
fprintf(view->out, "<a href=\"%s%s\">", me, urlstring);
|
||||
free(urlstring);
|
||||
}
|
||||
viewHTTPHeaderValue(view, input);
|
||||
viewHTTPHeaderValue(app, input);
|
||||
if (url)
|
||||
{
|
||||
fprintf(view->out, "</a>");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned char **
|
||||
getHTTPRequestHeaders(View *view, char *host, char *verbose)
|
||||
getHTTPRequestHeaders(App *app, char *host, char *verbose)
|
||||
{
|
||||
char **e;
|
||||
extern char **environ;
|
||||
|
@ -205,7 +157,7 @@ getHTTPRequestHeaders(View *view, char *host, char *verbose)
|
|||
|
||||
e = environ;
|
||||
r = ret;
|
||||
viewReport(view, "will send these HTTP Request headers:");
|
||||
viewReport(app, "will send these HTTP Request headers:");
|
||||
while (*e)
|
||||
{
|
||||
h = passThese;
|
||||
|
@ -259,7 +211,7 @@ getHTTPRequestHeaders(View *view, char *host, char *verbose)
|
|||
}
|
||||
*q = 0;
|
||||
*r++ = str;
|
||||
viewReport(view, str);
|
||||
viewReport(app, str);
|
||||
}
|
||||
}
|
||||
e++;
|
||||
|
@ -270,9 +222,9 @@ getHTTPRequestHeaders(View *view, char *host, char *verbose)
|
|||
strcpy(str, "Host: ");
|
||||
strcat(str, host);
|
||||
*r++ = str;
|
||||
viewReport(view, str);
|
||||
viewReport(app, str);
|
||||
}
|
||||
viewReportHTML(view, "<hr>");
|
||||
viewReportHTML(app, "<hr>");
|
||||
*r = NULL;
|
||||
|
||||
return (unsigned char **) ret;
|
||||
|
@ -282,6 +234,7 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
char *ampersand;
|
||||
App *app;
|
||||
unsigned char *equals;
|
||||
char *name;
|
||||
unsigned char *newURL;
|
||||
|
@ -306,7 +259,17 @@ main(int argc, char *argv[])
|
|||
verbose = "?url=";
|
||||
|
||||
query = getenv("QUERY_STRING");
|
||||
view = viewAlloc();
|
||||
app = appAlloc();
|
||||
app->html = cgiviewHTML;
|
||||
app->htmlAttributeName = cgiviewHTMLAttributeName;
|
||||
app->htmlAttributeValue = cgiviewHTMLAttributeValue;
|
||||
app->htmlTag = cgiviewHTMLTag;
|
||||
app->htmlText = cgiviewHTMLText;
|
||||
app->http = cgiviewHTTP;
|
||||
app->httpBody = cgiviewHTTPBody;
|
||||
app->httpHeaderName = cgiviewHTTPHeaderName;
|
||||
app->httpHeaderValue = cgiviewHTTPHeaderValue;
|
||||
view = &app->view;
|
||||
view->out = stdout;
|
||||
freopen("/dev/null", "w", stderr);
|
||||
fprintf(view->out, "Content-Type: text/html\n");
|
||||
|
@ -359,9 +322,9 @@ main(int argc, char *argv[])
|
|||
"<body><tt><b>\n",
|
||||
url
|
||||
);
|
||||
viewReport(view, "input url:");
|
||||
viewReport(view, (char *) url);
|
||||
viewReportHTML(view, "<hr>");
|
||||
viewReport(app, "input url:");
|
||||
viewReport(app, (char *) url);
|
||||
viewReportHTML(app, "<hr>");
|
||||
u = urlParse(url);
|
||||
if
|
||||
(
|
||||
|
@ -373,7 +336,7 @@ main(int argc, char *argv[])
|
|||
newURL = calloc(strlen((char *) url) + 3, 1);
|
||||
if (!newURL)
|
||||
{
|
||||
viewReport(view, "calloc failed");
|
||||
viewReport(app, "calloc failed");
|
||||
return 1;
|
||||
}
|
||||
strcpy((char *) newURL, "//");
|
||||
|
@ -398,7 +361,7 @@ main(int argc, char *argv[])
|
|||
newURL = calloc(strlen((char *) url) + 2, 1);
|
||||
if (!newURL)
|
||||
{
|
||||
viewReport(view, "calloc failed");
|
||||
viewReport(app, "calloc failed");
|
||||
return 1;
|
||||
}
|
||||
strcpy((char *) newURL, (char *) url);
|
||||
|
@ -410,14 +373,14 @@ main(int argc, char *argv[])
|
|||
(unsigned char *) "http://www.mozilla.org/index.html",
|
||||
newURL);
|
||||
free(newURL);
|
||||
viewReport(view, "fully qualified url:");
|
||||
viewReport(view, (char *) u->url);
|
||||
viewReportHTML(view, "<hr>");
|
||||
viewReport(app, "fully qualified url:");
|
||||
viewReport(app, (char *) u->url);
|
||||
viewReportHTML(app, "<hr>");
|
||||
fflush(view->out);
|
||||
if (!strcmp((char *) u->scheme, "http"))
|
||||
{
|
||||
httpProcess(view, u,
|
||||
getHTTPRequestHeaders(view, (char *) u->host,
|
||||
httpProcess(app, u,
|
||||
getHTTPRequestHeaders(app, (char *) u->host,
|
||||
verbose));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -38,71 +38,6 @@
|
|||
|
||||
static unsigned short ID = 0xbeef;
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
static unsigned char *
|
||||
putDomainName(unsigned char *p, char *name)
|
||||
{
|
||||
|
|
|
@ -148,71 +148,6 @@ ftpProcess(void *a, URL *url)
|
|||
printf("buf %s", buf);
|
||||
}
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
|
|
@ -24,11 +24,6 @@
|
|||
|
||||
#include "all.h"
|
||||
|
||||
typedef struct Arg
|
||||
{
|
||||
URL *url;
|
||||
} Arg;
|
||||
|
||||
static char *limitURLs[] =
|
||||
{
|
||||
"http://www.w3.org/TR/REC-CSS2/",
|
||||
|
@ -38,73 +33,8 @@ static char *limitURLs[] =
|
|||
static URL *lastURL = NULL;
|
||||
static URL *urls = NULL;
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
addURLFunc(void *a, URL *url)
|
||||
addURLFunc(App *app, URL *url)
|
||||
{
|
||||
lastURL->next = url;
|
||||
lastURL = url;
|
||||
|
@ -186,7 +116,6 @@ grab(unsigned char *url, HTTP *http)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
Arg arg;
|
||||
HTTP *http;
|
||||
char *prog;
|
||||
URL *url;
|
||||
|
@ -230,8 +159,8 @@ main(int argc, char *argv[])
|
|||
lastURL = url;
|
||||
while (url)
|
||||
{
|
||||
arg.url = url;
|
||||
http = httpProcess(&arg, url, NULL);
|
||||
appDefault.data = url;
|
||||
http = httpProcess(&appDefault, url, NULL);
|
||||
if (http)
|
||||
{
|
||||
switch (http->status)
|
||||
|
|
|
@ -304,7 +304,7 @@ htmlRegisterURLHandler(HTMLHandler handler)
|
|||
}
|
||||
|
||||
static void
|
||||
callHandler(void *a, HTML *html)
|
||||
callHandler(App *app, HTML *html)
|
||||
{
|
||||
HashEntry *attrEntry;
|
||||
HashEntry *tagEntry;
|
||||
|
@ -320,7 +320,7 @@ callHandler(void *a, HTML *html)
|
|||
html->currentAttribute->name);
|
||||
if (attrEntry)
|
||||
{
|
||||
(*((HTMLHandler) attrEntry->value))(a, html);
|
||||
(*((HTMLHandler) attrEntry->value))(app, html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -458,13 +458,13 @@ htmlFreeAttributes(HTMLState *state)
|
|||
}
|
||||
|
||||
static unsigned short
|
||||
readAttribute(void *a, Input *input, HTMLState *state, unsigned short c)
|
||||
readAttribute(App *app, Input *input, HTMLState *state, unsigned short c)
|
||||
{
|
||||
HTMLAttribute *attr;
|
||||
unsigned short quote;
|
||||
|
||||
mark(input, -1);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
while
|
||||
(
|
||||
(c != 256) &&
|
||||
|
@ -499,7 +499,7 @@ readAttribute(void *a, Input *input, HTMLState *state, unsigned short c)
|
|||
}
|
||||
state->html->currentAttribute = attr;
|
||||
attr->name = copyLower(input);
|
||||
reportHTMLAttributeName(a, state->html, input);
|
||||
app->htmlAttributeName(app, state->html, input);
|
||||
if ((c == 256) || (c == '>'))
|
||||
{
|
||||
return c;
|
||||
|
@ -519,7 +519,7 @@ readAttribute(void *a, Input *input, HTMLState *state, unsigned short c)
|
|||
{
|
||||
quote = c;
|
||||
mark(input, 0);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
do
|
||||
{
|
||||
c = htmlGetByte(input, state);
|
||||
|
@ -531,13 +531,13 @@ readAttribute(void *a, Input *input, HTMLState *state, unsigned short c)
|
|||
mark(input, -1);
|
||||
attr->value = copy(input);
|
||||
htmlCheckAttribute(state->html);
|
||||
reportHTMLAttributeValue(a, state->html, input);
|
||||
app->htmlAttributeValue(app, state->html, input);
|
||||
c = htmlGetByte(input, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
mark(input, -1);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
while
|
||||
(
|
||||
(c != 256) &&
|
||||
|
@ -557,9 +557,9 @@ readAttribute(void *a, Input *input, HTMLState *state, unsigned short c)
|
|||
mark(input, -1);
|
||||
attr->value = copy(input);
|
||||
htmlCheckAttribute(state->html);
|
||||
reportHTMLAttributeValue(a, state->html, input);
|
||||
app->htmlAttributeValue(app, state->html, input);
|
||||
}
|
||||
callHandler(a, state->html);
|
||||
callHandler(app, state->html);
|
||||
if (c == '>')
|
||||
{
|
||||
return c;
|
||||
|
@ -589,7 +589,7 @@ caseCompare(char *str, Input *input, HTMLState *state, unsigned short *ret)
|
|||
}
|
||||
|
||||
static unsigned short
|
||||
endTag(void *a, Input *input, HTMLState *state)
|
||||
endTag(App *app, Input *input, HTMLState *state)
|
||||
{
|
||||
unsigned short c;
|
||||
|
||||
|
@ -597,19 +597,19 @@ endTag(void *a, Input *input, HTMLState *state)
|
|||
if (c == 256)
|
||||
{
|
||||
mark(input, -1);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static unsigned short
|
||||
readTag(void *a, Input *input, HTMLState *state)
|
||||
readTag(App *app, Input *input, HTMLState *state)
|
||||
{
|
||||
unsigned short c;
|
||||
|
||||
mark(input, -1);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
|
||||
c = htmlGetByte(input, state);
|
||||
if (c == '!')
|
||||
|
@ -634,7 +634,7 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
state);
|
||||
if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
else if (c == '-')
|
||||
{
|
||||
|
@ -644,7 +644,7 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
} while (c == '-');
|
||||
if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
c = htmlGetByte(input, state);
|
||||
if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
else if (c == 256)
|
||||
{
|
||||
|
@ -669,7 +669,7 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
copyString((unsigned
|
||||
char *) "!--");
|
||||
state->html->tagIsKnown = 1;
|
||||
reportHTMLTag(a,
|
||||
app->htmlTag(app,
|
||||
state->html, input);
|
||||
return c;
|
||||
}
|
||||
|
@ -717,14 +717,14 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
{
|
||||
state->html->tagIsKnown = 0;
|
||||
}
|
||||
reportHTMLTag(a, state->html, input);
|
||||
app->htmlTag(app, state->html, input);
|
||||
if (c == 256)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
else if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
c = eatWhiteSpace(input, state, c);
|
||||
if (c == 256)
|
||||
|
@ -733,38 +733,38 @@ readTag(void *a, Input *input, HTMLState *state)
|
|||
}
|
||||
else if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
do
|
||||
{
|
||||
c = readAttribute(a, input, state, c);
|
||||
c = readAttribute(app, input, state, c);
|
||||
} while ((c != 256) && (c != '>'));
|
||||
state->html->currentAttribute = NULL;
|
||||
if (tagHandler)
|
||||
{
|
||||
(*tagHandler)(a, state->html);
|
||||
(*tagHandler)(app, state->html);
|
||||
}
|
||||
if (c == '>')
|
||||
{
|
||||
return endTag(a, input, state);
|
||||
return endTag(app, input, state);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static unsigned short
|
||||
readText(void *a, Input *input, HTMLState *state)
|
||||
readText(App *app, Input *input, HTMLState *state)
|
||||
{
|
||||
unsigned short c;
|
||||
|
||||
mark(input, -1);
|
||||
reportHTML(a, input);
|
||||
app->html(app, input);
|
||||
do
|
||||
{
|
||||
c = htmlGetByte(input, state);
|
||||
} while ((c != 256) && (c != '<'));
|
||||
mark(input, -1);
|
||||
reportHTMLText(a, input);
|
||||
app->htmlText(app, input);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -797,7 +797,7 @@ dealWithScript(Input *input, HTMLState *state, unsigned short c)
|
|||
}
|
||||
|
||||
void
|
||||
htmlRead(void *a, Input *input, unsigned char *base)
|
||||
htmlRead(App *app, Input *input, unsigned char *base)
|
||||
{
|
||||
unsigned short c;
|
||||
HTML html;
|
||||
|
@ -834,18 +834,18 @@ htmlRead(void *a, Input *input, unsigned char *base)
|
|||
(c == '!')
|
||||
)
|
||||
{
|
||||
c = readTag(a, input, &state);
|
||||
c = readTag(app, input, &state);
|
||||
c = dealWithScript(input, &state, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
diag(__LINE__, &state, c);
|
||||
c = readText(a, input, &state);
|
||||
c = readText(app, input, &state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = readText(a, input, &state);
|
||||
c = readText(app, input, &state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ typedef struct HTML
|
|||
int currentAttributeIsURL;
|
||||
} HTML;
|
||||
|
||||
typedef void (*HTMLHandler)(void *a, HTML *html);
|
||||
typedef void (*HTMLHandler)(App *app, HTML *html);
|
||||
|
||||
void htmlRead(void *a, Input *input, unsigned char *base);
|
||||
void htmlRead(App *app, Input *input, unsigned char *base);
|
||||
void htmlRegister(char *tag, char *attributeName, HTMLHandler handler);
|
||||
void htmlRegisterTagHandler(HTMLHandler handler);
|
||||
void htmlRegisterURLHandler(HTMLHandler handler);
|
||||
|
|
|
@ -85,7 +85,7 @@ readNonWhiteSpace(Input *input, unsigned short c)
|
|||
}
|
||||
|
||||
static unsigned char *
|
||||
httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
|
||||
httpReadHeaders(HTTP *http, App *app, Input *input, unsigned char *url)
|
||||
{
|
||||
unsigned short c;
|
||||
unsigned char *charset;
|
||||
|
@ -120,17 +120,17 @@ httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
|
|||
if (c == 256)
|
||||
{
|
||||
mark(input, 0);
|
||||
reportHTTP(a, input);
|
||||
app->http(app, input);
|
||||
break;
|
||||
}
|
||||
mark(input, -1);
|
||||
reportHTTP(a, input);
|
||||
app->http(app, input);
|
||||
if ((c == '\r') || (c == '\n'))
|
||||
{
|
||||
readLine(input, c);
|
||||
unGetByte(input);
|
||||
mark(input, 0);
|
||||
reportHTTP(a, input);
|
||||
app->http(app, input);
|
||||
break;
|
||||
}
|
||||
while
|
||||
|
@ -151,11 +151,11 @@ httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
|
|||
return NULL;
|
||||
}
|
||||
mark(input, -1);
|
||||
reportHTTPHeaderName(a, input);
|
||||
app->httpHeaderName(app, input);
|
||||
name = copyLower(input);
|
||||
c = readSpaceTab(input, getByte(input));
|
||||
mark(input, -1);
|
||||
reportHTTP(a, input);
|
||||
app->http(app, input);
|
||||
c = readLine(input, c);
|
||||
if ((c == ' ') || (c == '\t'))
|
||||
{
|
||||
|
@ -169,34 +169,34 @@ httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
|
|||
value = copy(input);
|
||||
if (!strcasecmp((char *) name, "content-type"))
|
||||
{
|
||||
reportHTTPHeaderValue(a, input, NULL);
|
||||
app->httpHeaderValue(app, input, NULL);
|
||||
type = mimeParseContentType(value);
|
||||
contentType = mimeGetContentType(type);
|
||||
charset = mimeGetContentTypeParameter(type, "charset");
|
||||
if (charset)
|
||||
{
|
||||
reportHTTPCharSet(a, charset);
|
||||
app->httpCharSet(app, charset);
|
||||
}
|
||||
mimeFreeContentType(type);
|
||||
}
|
||||
else if (!strcasecmp((char *) name, "location"))
|
||||
{
|
||||
reportHTTPHeaderValue(a, input, value);
|
||||
app->httpHeaderValue(app, input, value);
|
||||
/* XXX supposed to be absolute URL */
|
||||
rel = urlRelative(url, value);
|
||||
addURL(a, rel->url);
|
||||
addURL(app, rel->url);
|
||||
urlFree(rel);
|
||||
locationFound = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
reportHTTPHeaderValue(a, input, NULL);
|
||||
app->httpHeaderValue(app, input, NULL);
|
||||
}
|
||||
free(name);
|
||||
free(value);
|
||||
c = readLine(input, c);
|
||||
mark(input, -1);
|
||||
reportHTTP(a, input);
|
||||
app->http(app, input);
|
||||
}
|
||||
|
||||
if (!contentType)
|
||||
|
@ -211,7 +211,7 @@ httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
|
|||
}
|
||||
|
||||
void
|
||||
httpParseRequest(HTTP *http, void *a, char *url)
|
||||
httpParseRequest(HTTP *http, App *app, char *url)
|
||||
{
|
||||
unsigned short c;
|
||||
|
||||
|
@ -221,18 +221,18 @@ httpParseRequest(HTTP *http, void *a, char *url)
|
|||
c = getByte(http->input);
|
||||
} while (c != 256);
|
||||
mark(http->input, -1);
|
||||
reportHTTP(a, http->input);
|
||||
app->http(app, http->input);
|
||||
}
|
||||
|
||||
void
|
||||
httpParseStream(HTTP *http, void *a, unsigned char *url)
|
||||
httpParseStream(HTTP *http, App *app, unsigned char *url)
|
||||
{
|
||||
const unsigned char *begin;
|
||||
unsigned short c;
|
||||
unsigned char *contentType;
|
||||
|
||||
begin = current(http->input);
|
||||
contentType = httpReadHeaders(http, a, http->input, url);
|
||||
contentType = httpReadHeaders(http, app, http->input, url);
|
||||
http->body = current(http->input);
|
||||
http->bodyLen = inputLength(http->input) - (http->body - begin);
|
||||
if (contentType)
|
||||
|
@ -244,10 +244,10 @@ httpParseStream(HTTP *http, void *a, unsigned char *url)
|
|||
(contentType != locationURLWasAdded)
|
||||
)
|
||||
{
|
||||
reportContentType(a, contentType);
|
||||
app->contentType(app, contentType);
|
||||
if (!strcasecmp((char *) contentType, "text/html"))
|
||||
{
|
||||
htmlRead(a, http->input, url);
|
||||
htmlRead(app, http->input, url);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -257,7 +257,7 @@ httpParseStream(HTTP *http, void *a, unsigned char *url)
|
|||
}
|
||||
while (c != 256);
|
||||
mark(http->input, -1);
|
||||
reportHTTPBody(a, http->input);
|
||||
app->httpBody(app, http->input);
|
||||
}
|
||||
free(contentType);
|
||||
}
|
||||
|
@ -269,20 +269,20 @@ httpParseStream(HTTP *http, void *a, unsigned char *url)
|
|||
}
|
||||
|
||||
void
|
||||
httpRead(HTTP *http, void *a, int sock, unsigned char *url)
|
||||
httpRead(HTTP *http, App *app, int sock, unsigned char *url)
|
||||
{
|
||||
struct timeval theTime;
|
||||
|
||||
reportStatus(a, "readStream", __FILE__, __LINE__);
|
||||
app->status(app, "readStream", __FILE__, __LINE__);
|
||||
gettimeofday(&theTime, NULL);
|
||||
http->input = readStream(sock, url);
|
||||
reportTime(REPORT_TIME_READSTREAM, &theTime);
|
||||
reportStatus(a, "readStream done", __FILE__, __LINE__);
|
||||
httpParseStream(http, a, url);
|
||||
app->time(app, appTimeReadStream, &theTime);
|
||||
app->status(app, "readStream done", __FILE__, __LINE__);
|
||||
httpParseStream(http, app, url);
|
||||
}
|
||||
|
||||
static void
|
||||
httpGetObject(HTTP *http, void *a, int sock, URL *url, unsigned char **headers)
|
||||
httpGetObject(HTTP *http, App *app, int sock, URL *url, unsigned char **headers)
|
||||
{
|
||||
char *get;
|
||||
unsigned char **h;
|
||||
|
@ -317,7 +317,7 @@ httpGetObject(HTTP *http, void *a, int sock, URL *url, unsigned char **headers)
|
|||
}
|
||||
send(sock, "\n", 1, 0);
|
||||
|
||||
httpRead(http, a, sock, url->url);
|
||||
httpRead(http, app, sock, url->url);
|
||||
}
|
||||
|
||||
HTTP *
|
||||
|
@ -346,7 +346,7 @@ httpFree(HTTP *http)
|
|||
}
|
||||
|
||||
HTTP *
|
||||
httpProcess(void *a, URL *url, unsigned char **headers)
|
||||
httpProcess(App *app, URL *url, unsigned char **headers)
|
||||
{
|
||||
HTTP *http;
|
||||
int port;
|
||||
|
@ -367,7 +367,7 @@ httpProcess(void *a, URL *url, unsigned char **headers)
|
|||
url->url ? (char *) url->url : "<NULL>");
|
||||
return NULL;
|
||||
}
|
||||
sock = netConnect(a, url->host, port);
|
||||
sock = netConnect(app, url->host, port);
|
||||
if (sock == -1)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -375,7 +375,7 @@ httpProcess(void *a, URL *url, unsigned char **headers)
|
|||
|
||||
http = httpAlloc();
|
||||
|
||||
httpGetObject(http, a, sock, url, headers);
|
||||
httpGetObject(http, app, sock, url, headers);
|
||||
|
||||
close(sock);
|
||||
|
||||
|
|
|
@ -40,9 +40,9 @@ HTTP *httpAlloc(void);
|
|||
void httpFree(HTTP *http);
|
||||
int httpGetHTTP10OrGreaterCount(void);
|
||||
int httpGetNonEmptyHTTPResponseCount(void);
|
||||
void httpParseRequest(HTTP *http, void *a, char *url);
|
||||
void httpParseStream(HTTP *http, void *a, unsigned char *url);
|
||||
HTTP *httpProcess(void *a, URL *url, unsigned char **headers);
|
||||
void httpRead(HTTP *http, void *a, int fd, unsigned char *url);
|
||||
void httpParseRequest(HTTP *http, App *app, char *url);
|
||||
void httpParseStream(HTTP *http, App *app, unsigned char *url);
|
||||
HTTP *httpProcess(App *app, URL *url, unsigned char **headers);
|
||||
void httpRead(HTTP *http, App *app, int fd, unsigned char *url);
|
||||
|
||||
#endif /* _HTTP_H_ */
|
||||
|
|
|
@ -24,11 +24,6 @@
|
|||
|
||||
#include "all.h"
|
||||
|
||||
typedef struct Arg
|
||||
{
|
||||
URL *url;
|
||||
} Arg;
|
||||
|
||||
static char *limitURLs[] =
|
||||
{
|
||||
"http://sniffuri.org/test/",
|
||||
|
@ -38,73 +33,8 @@ static char *limitURLs[] =
|
|||
static URL *lastURL = NULL;
|
||||
static URL *urls = NULL;
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
addURLFunc(void *a, URL *url)
|
||||
addURLFunc(App *app, URL *url)
|
||||
{
|
||||
lastURL->next = url;
|
||||
lastURL = url;
|
||||
|
@ -113,7 +43,6 @@ addURLFunc(void *a, URL *url)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
Arg arg;
|
||||
HTTP *http;
|
||||
URL *url;
|
||||
|
||||
|
@ -138,8 +67,8 @@ main(int argc, char *argv[])
|
|||
lastURL = url;
|
||||
while (url)
|
||||
{
|
||||
arg.url = url;
|
||||
http = httpProcess(&arg, url, NULL);
|
||||
appDefault.data = url;
|
||||
http = httpProcess(&appDefault, url, NULL);
|
||||
if (http)
|
||||
{
|
||||
switch (http->status)
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/* ***** 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):
|
||||
* Bruce Robson <bns_robson@hotmail.com>
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
#include "html.h"
|
||||
|
||||
#define REPORT_TIME_CONNECT_SUCCESS 0
|
||||
#define REPORT_TIME_CONNECT_FAILURE 1
|
||||
#define REPORT_TIME_GETHOSTBYNAME_SUCCESS 2
|
||||
#define REPORT_TIME_GETHOSTBYNAME_FAILURE 3
|
||||
#define REPORT_TIME_READSTREAM 4
|
||||
#define REPORT_TIME_TOTAL 5
|
||||
|
||||
#define REPORT_TIME_MAX 6 /* highest + 1 */
|
||||
|
||||
void reportContentType(void *a, unsigned char *contentType);
|
||||
void reportHTML(void *a, Input *input);
|
||||
void reportHTMLAttributeName(void *a, HTML *html, Input *input);
|
||||
void reportHTMLAttributeValue(void *a, HTML *html, Input *input);
|
||||
void reportHTMLTag(void *a, HTML *html, Input *input);
|
||||
void reportHTMLText(void *a, Input *input);
|
||||
void reportHTTP(void *a, Input *input);
|
||||
void reportHTTPBody(void *a, Input *input);
|
||||
void reportHTTPCharSet(void *a, unsigned char *charset);
|
||||
void reportHTTPHeaderName(void *a, Input *input);
|
||||
void reportHTTPHeaderValue(void *a, Input *input, unsigned char *url);
|
||||
void reportStatus(void *a, char *message, char *file, int line);
|
||||
void reportTime(int task, struct timeval *theTime);
|
||||
|
||||
#endif /* _MAIN_H_ */
|
|
@ -81,7 +81,7 @@ getHostName(void)
|
|||
}
|
||||
|
||||
static int
|
||||
getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
||||
getSocketAndIPAddress(App *app, unsigned char *hostName, int port,
|
||||
struct sockaddr_in *addr)
|
||||
{
|
||||
#if HAVE_GETHOSTBYNAME_R
|
||||
|
@ -99,8 +99,8 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
|||
if (!proto)
|
||||
{
|
||||
perror("getprotobyname");
|
||||
viewReport(a, "getprotobyname failed");
|
||||
viewReport(a, strerror(errno) ? strerror(errno) : "NULL");
|
||||
viewReport(app, "getprotobyname failed");
|
||||
viewReport(app, strerror(errno) ? strerror(errno) : "NULL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -108,15 +108,15 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
|||
if (sock < 0)
|
||||
{
|
||||
perror("socket");
|
||||
viewReport(a, "socket failed");
|
||||
viewReport(a, strerror(errno) ? strerror(errno) : "NULL");
|
||||
viewReport(app, "socket failed");
|
||||
viewReport(app, strerror(errno) ? strerror(errno) : "NULL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
viewReport(a, "calling gethostbyname_r() on");
|
||||
viewReport(a, (char *) hostName);
|
||||
viewReport(app, "calling gethostbyname_r() on");
|
||||
viewReport(app, (char *) hostName);
|
||||
|
||||
reportStatus(a, "gethostbyname_r", __FILE__, __LINE__);
|
||||
app->status(app, "gethostbyname_r", __FILE__, __LINE__);
|
||||
|
||||
gettimeofday(&theTime, NULL);
|
||||
|
||||
|
@ -142,9 +142,9 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
reportTime(REPORT_TIME_GETHOSTBYNAME_FAILURE, &theTime);
|
||||
reportStatus(a, "gethostbyname_r failed", __FILE__, __LINE__);
|
||||
viewReportHTML(a, "failed<br><hr>");
|
||||
app->time(app, appTimeGetHostByNameFailure, &theTime);
|
||||
app->status(app, "gethostbyname_r failed", __FILE__, __LINE__);
|
||||
viewReportHTML(app, "failed<br><hr>");
|
||||
close(sock);
|
||||
#if !defined(HAVE_GETHOSTBYNAME_R)
|
||||
threadMutexUnlock();
|
||||
|
@ -152,11 +152,11 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
|||
return -1;
|
||||
}
|
||||
|
||||
reportTime(REPORT_TIME_GETHOSTBYNAME_SUCCESS, &theTime);
|
||||
app->time(app, appTimeGetHostByNameSuccess, &theTime);
|
||||
|
||||
reportStatus(a, "gethostbyname_r succeeded", __FILE__, __LINE__);
|
||||
app->status(app, "gethostbyname_r succeeded", __FILE__, __LINE__);
|
||||
|
||||
viewReportHTML(a, "succeeded<br><hr>");
|
||||
viewReportHTML(app, "succeeded<br><hr>");
|
||||
|
||||
memset(addr, 0, sizeof(*addr));
|
||||
addr->sin_family = host.h_addrtype /* PF_INET */;
|
||||
|
@ -174,7 +174,7 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
|
|||
}
|
||||
|
||||
int
|
||||
netListen(void *a, unsigned char **host, unsigned short *port)
|
||||
netListen(App *app, unsigned char **host, unsigned short *port)
|
||||
{
|
||||
unsigned char *hostName;
|
||||
struct sockaddr_in name;
|
||||
|
@ -187,7 +187,7 @@ netListen(void *a, unsigned char **host, unsigned short *port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
fd = getSocketAndIPAddress(a, hostName, *port, &name);
|
||||
fd = getSocketAndIPAddress(app, hostName, *port, &name);
|
||||
if (fd < 0)
|
||||
{
|
||||
return -1;
|
||||
|
@ -244,27 +244,27 @@ netAccept(int fd)
|
|||
}
|
||||
|
||||
int
|
||||
netConnect(void *a, unsigned char *hostName, int port)
|
||||
netConnect(App *app, unsigned char *hostName, int port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
int sock;
|
||||
struct timeval theTime;
|
||||
|
||||
sock = getSocketAndIPAddress(a, hostName, port, &addr);
|
||||
sock = getSocketAndIPAddress(app, hostName, port, &addr);
|
||||
if (sock < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
viewReport(a, "calling connect()");
|
||||
viewReport(app, "calling connect()");
|
||||
|
||||
reportStatus(a, "connect", __FILE__, __LINE__);
|
||||
app->status(app, "connect", __FILE__, __LINE__);
|
||||
|
||||
gettimeofday(&theTime, NULL);
|
||||
|
||||
if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) == -1)
|
||||
{
|
||||
reportTime(REPORT_TIME_CONNECT_FAILURE, &theTime);
|
||||
app->time(app, appTimeConnectFailure, &theTime);
|
||||
|
||||
/* XXX try again if Connection timed out? */
|
||||
/* XXX try again if Connection refused? */
|
||||
|
@ -279,18 +279,18 @@ netConnect(void *a, unsigned char *hostName, int port)
|
|||
perror(NULL);
|
||||
}
|
||||
close(sock);
|
||||
reportStatus(a, "connect failed", __FILE__, __LINE__);
|
||||
viewReport(a, "failed:");
|
||||
viewReport(a, strerror(errno) ? strerror(errno) : "NULL");
|
||||
viewReportHTML(a, "<hr>");
|
||||
app->status(app, "connect failed", __FILE__, __LINE__);
|
||||
viewReport(app, "failed:");
|
||||
viewReport(app, strerror(errno) ? strerror(errno) : "NULL");
|
||||
viewReportHTML(app, "<hr>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
reportTime(REPORT_TIME_CONNECT_SUCCESS, &theTime);
|
||||
app->time(app, appTimeConnectSuccess, &theTime);
|
||||
|
||||
reportStatus(a, "connect succeeded", __FILE__, __LINE__);
|
||||
app->status(app, "connect succeeded", __FILE__, __LINE__);
|
||||
|
||||
viewReportHTML(a, "succeeded<br><hr>");
|
||||
viewReportHTML(app, "succeeded<br><hr>");
|
||||
|
||||
threadMutexLock();
|
||||
connectCount++;
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
#define _NET_H_
|
||||
|
||||
int netAccept(int fd);
|
||||
int netConnect(void *a, unsigned char *hostName, int port);
|
||||
int netConnect(App *app, unsigned char *hostName, int port);
|
||||
int netGetConnectCount(void);
|
||||
int netGetDNSCount(void);
|
||||
int netInit(void);
|
||||
int netListen(void *a, unsigned char **host, unsigned short *port);
|
||||
int netListen(App *app, unsigned char **host, unsigned short *port);
|
||||
|
||||
#endif /* _NET_H_ */
|
||||
|
|
|
@ -124,68 +124,3 @@ main(int argc, char *argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -46,6 +46,16 @@ typedef struct Arg
|
|||
View *view;
|
||||
} Arg;
|
||||
|
||||
static void proxyHTML(App *app, Input *input);
|
||||
static void proxyHTMLAttributeName(App *app, HTML *html, Input *input);
|
||||
static void proxyHTMLAttributeValue(App *app, HTML *html, Input *input);
|
||||
static void proxyHTMLTag(App *app, HTML *html, Input *input);
|
||||
static void proxyHTMLText(App *app, Input *input);
|
||||
static void proxyHTTP(App *app, Input *input);
|
||||
static void proxyHTTPBody(App *app, Input *input);
|
||||
static void proxyHTTPHeaderName(App *app, Input *input);
|
||||
static void proxyHTTPHeaderValue(App *app, Input *input, unsigned char *url);
|
||||
|
||||
static fd_set fdSet;
|
||||
static int id = 0;
|
||||
static unsigned short mainPort = 40404;
|
||||
|
@ -172,10 +182,31 @@ removeFD(int fd)
|
|||
}
|
||||
}
|
||||
|
||||
static App *
|
||||
proxyApp(FD *f)
|
||||
{
|
||||
App *app;
|
||||
|
||||
app = appAlloc();
|
||||
app->html = proxyHTML;
|
||||
app->htmlAttributeName = proxyHTMLAttributeName;
|
||||
app->htmlAttributeValue = proxyHTMLAttributeValue;
|
||||
app->htmlTag = proxyHTMLTag;
|
||||
app->htmlText = proxyHTMLText;
|
||||
app->http = proxyHTTP;
|
||||
app->httpBody = proxyHTTPBody;
|
||||
app->httpHeaderName = proxyHTTPHeaderName;
|
||||
app->httpHeaderValue = proxyHTTPHeaderValue;
|
||||
app->view.backslash = 1;
|
||||
app->view.out = f->logFile;
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static int
|
||||
logRequest(FD *f, Input *input)
|
||||
{
|
||||
Arg arg;
|
||||
App *app;
|
||||
HTTP *http;
|
||||
|
||||
if
|
||||
|
@ -202,11 +233,9 @@ logRequest(FD *f, Input *input)
|
|||
);
|
||||
http = httpAlloc();
|
||||
http->input = input;
|
||||
arg.view = viewAlloc();
|
||||
arg.view->backslash = 1;
|
||||
arg.view->out = f->logFile;
|
||||
httpParseRequest(http, &arg, "logRequest");
|
||||
free(arg.view);
|
||||
app = proxyApp(f);
|
||||
httpParseRequest(http, app, "logRequest");
|
||||
free(app);
|
||||
httpFree(http);
|
||||
fprintf(f->logFile, "</b></pre>\");\n</script>\n");
|
||||
fflush(f->logFile);
|
||||
|
@ -234,7 +263,7 @@ readClientRequest(int fd)
|
|||
static int
|
||||
logResponse(FD *f, Input *input)
|
||||
{
|
||||
Arg arg;
|
||||
App *app;
|
||||
HTTP *http;
|
||||
|
||||
if ((table[fileno(f->logFile)]->suspend) || (f->suspend))
|
||||
|
@ -252,11 +281,9 @@ logResponse(FD *f, Input *input)
|
|||
);
|
||||
http = httpAlloc();
|
||||
http->input = input;
|
||||
arg.view = viewAlloc();
|
||||
arg.view->backslash = 1;
|
||||
arg.view->out = f->logFile;
|
||||
httpParseStream(http, &arg, (unsigned char *) "readProxyResponse");
|
||||
free(arg.view);
|
||||
app = proxyApp(f);
|
||||
httpParseStream(http, app, (unsigned char *) "readProxyResponse");
|
||||
free(app);
|
||||
httpFree(http);
|
||||
fprintf(f->logFile, "</b></pre>\");\n</script>\n");
|
||||
fflush(f->logFile);
|
||||
|
@ -509,105 +536,58 @@ acceptNewLogger(int fd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
static void
|
||||
proxyHTML(App *app, Input *input)
|
||||
{
|
||||
viewHTML(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
static void
|
||||
proxyHTMLAttributeName(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTML(arg->view, input);
|
||||
viewHTMLAttributeName(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
proxyHTMLAttributeValue(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTMLAttributeName(arg->view, input);
|
||||
viewHTMLAttributeValue(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
proxyHTMLTag(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTMLAttributeValue(arg->view, input);
|
||||
viewHTMLTag(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
proxyHTMLText(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTMLTag(arg->view, input);
|
||||
viewHTMLText(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
static void
|
||||
proxyHTTP(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTMLText(arg->view, input);
|
||||
viewHTTP(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
static void
|
||||
proxyHTTPBody(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTTP(arg->view, input);
|
||||
viewHTTP(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
static void
|
||||
proxyHTTPHeaderName(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTTP(arg->view, input);
|
||||
viewHTTPHeaderName(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTTPHeaderName(arg->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
viewHTTPHeaderValue(arg->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *theTime)
|
||||
static void
|
||||
proxyHTTPHeaderValue(App *app, Input *input, unsigned char *url)
|
||||
{
|
||||
viewHTTPHeaderValue(app, input);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct Entry
|
|||
unsigned char *url;
|
||||
} Entry;
|
||||
|
||||
typedef struct Arg
|
||||
typedef struct Robot
|
||||
{
|
||||
int slot;
|
||||
int count;
|
||||
|
@ -42,7 +42,7 @@ typedef struct Arg
|
|||
char viewFile[1024];
|
||||
int viewFileAdded;
|
||||
char viewURL[1024];
|
||||
} Arg;
|
||||
} Robot;
|
||||
|
||||
typedef struct StatusEntry
|
||||
{
|
||||
|
@ -142,27 +142,27 @@ static FILE *statsOut = NULL;
|
|||
static char *firstURL = NULL;
|
||||
static unsigned char *startTime = NULL;
|
||||
|
||||
void
|
||||
reportStatus(void *a, char *message, char *file, int line)
|
||||
static void
|
||||
robotStatus(App *app, char *message, char *file, int line)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
StatusEntry *entry;
|
||||
|
||||
if (!a)
|
||||
if (!app)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
arg = a;
|
||||
entry = &statusEntries[arg->slot];
|
||||
robot = app->data;
|
||||
entry = &statusEntries[robot->slot];
|
||||
time(&entry->time);
|
||||
entry->message = message;
|
||||
entry->file = file;
|
||||
entry->line = line;
|
||||
}
|
||||
|
||||
void
|
||||
reportTime(int task, struct timeval *before)
|
||||
static void
|
||||
robotTime(App *app, int task, struct timeval *before)
|
||||
{
|
||||
struct timeval after;
|
||||
double span;
|
||||
|
@ -186,7 +186,7 @@ reportTime(int task, struct timeval *before)
|
|||
}
|
||||
|
||||
static void
|
||||
addEntry(HashTable *table, Arg *arg, unsigned char *url, unsigned char *str)
|
||||
addEntry(HashTable *table, Robot *robot, unsigned char *url, unsigned char *str)
|
||||
{
|
||||
Entry *entry;
|
||||
HashEntry *hashEntry;
|
||||
|
@ -205,8 +205,8 @@ addEntry(HashTable *table, Arg *arg, unsigned char *url, unsigned char *str)
|
|||
exit(0);
|
||||
}
|
||||
entry->count = 1;
|
||||
entry->viewURL = copyString((unsigned char *) arg->viewURL);
|
||||
arg->viewFileAdded = 1;
|
||||
entry->viewURL = copyString((unsigned char *) robot->viewURL);
|
||||
robot->viewFileAdded = 1;
|
||||
entry->url = copyString(url);
|
||||
hashAdd(table, copyString(str), entry);
|
||||
}
|
||||
|
@ -225,24 +225,24 @@ freeEntry(unsigned char *str, void *e)
|
|||
}
|
||||
|
||||
static void
|
||||
reportScheme(Arg *arg, unsigned char *url, unsigned char *scheme)
|
||||
robotScheme(Robot *robot, unsigned char *url, unsigned char *scheme)
|
||||
{
|
||||
addEntry(schemeTable, arg, url, scheme);
|
||||
addEntry(schemeTable, robot, url, scheme);
|
||||
}
|
||||
|
||||
static void
|
||||
addURLFunc(void *a, URL *url)
|
||||
addURLFunc(App *app, URL *url)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
if (!url->scheme)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
reportScheme(arg, url->url, url->scheme);
|
||||
robotScheme(robot, url->url, url->scheme);
|
||||
|
||||
if (strcmp((char *) url->scheme, "http"))
|
||||
{
|
||||
|
@ -262,66 +262,66 @@ addURLFunc(void *a, URL *url)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTP(void *a, Input *input)
|
||||
static void
|
||||
robotHTTP(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
viewHTTP(arg->view, input);
|
||||
viewHTTP(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPBody(void *a, Input *input)
|
||||
static void
|
||||
robotHTTPBody(App *app, Input *input)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderName(void *a, Input *input)
|
||||
static void
|
||||
robotHTTPHeaderName(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
unsigned char *name;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
name = copyLower(input);
|
||||
addEntry(httpHeaderTable, arg, arg->url->url, name);
|
||||
addEntry(httpHeaderTable, robot, robot->url->url, name);
|
||||
free(name);
|
||||
|
||||
viewHTTPHeaderName(arg->view, input);
|
||||
viewHTTPHeaderName(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
|
||||
static void
|
||||
robotHTTPHeaderValue(App *app, Input *input, unsigned char *url)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
viewHTTPHeaderValue(arg->view, input);
|
||||
viewHTTPHeaderValue(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTML(void *a, Input *input)
|
||||
static void
|
||||
robotHTML(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
viewHTML(arg->view, input);
|
||||
viewHTML(app, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLText(void *a, Input *input)
|
||||
static void
|
||||
robotHTMLText(App *app, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
unsigned char *p;
|
||||
unsigned char *str;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
viewHTMLText(arg->view, input);
|
||||
viewHTMLText(app, input);
|
||||
|
||||
str = copy(input);
|
||||
p = str;
|
||||
|
@ -339,11 +339,11 @@ reportHTMLText(void *a, Input *input)
|
|||
{
|
||||
if (p[4] == '7')
|
||||
{
|
||||
fprintf(stderr, "147: %s\n", arg->url->url);
|
||||
fprintf(stderr, "147: %s\n", robot->url->url);
|
||||
}
|
||||
else if (p[4] == '8')
|
||||
{
|
||||
fprintf(stderr, "148: %s\n", arg->url->url);
|
||||
fprintf(stderr, "148: %s\n", robot->url->url);
|
||||
}
|
||||
}
|
||||
p++;
|
||||
|
@ -351,17 +351,17 @@ reportHTMLText(void *a, Input *input)
|
|||
free(str);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLTag(void *a, HTML *html, Input *input)
|
||||
static void
|
||||
robotHTMLTag(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
HashEntry *tagEntry;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
if (html->tagIsKnown)
|
||||
{
|
||||
#ifdef ROBOT_LOG_TAGS
|
||||
addEntry(tagTable, arg, arg->url->url, html->tag);
|
||||
addEntry(tagTable, robot, robot->url->url, html->tag);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -375,54 +375,54 @@ reportHTMLTag(void *a, HTML *html, Input *input)
|
|||
}
|
||||
}
|
||||
|
||||
viewHTMLTag(arg->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeName(void *a, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
if (html->tagIsKnown)
|
||||
{
|
||||
#ifdef ROBOT_LOG_ATTRIBUTES
|
||||
addEntry(attributeTable, arg, arg->url->url,
|
||||
html->currentAttribute->name);
|
||||
#endif
|
||||
}
|
||||
viewHTMLAttributeName(arg->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
|
||||
viewHTMLAttributeValue(arg->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
reportContentType(void *a, unsigned char *contentType)
|
||||
{
|
||||
Arg *arg;
|
||||
|
||||
arg = a;
|
||||
|
||||
addEntry(contentTypeTable, arg, arg->url->url, contentType);
|
||||
viewHTMLTag(app, input);
|
||||
}
|
||||
|
||||
static void
|
||||
metaHandler(void *a, HTML *html)
|
||||
robotHTMLAttributeName(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
robot = app->data;
|
||||
if (html->tagIsKnown)
|
||||
{
|
||||
#ifdef ROBOT_LOG_ATTRIBUTES
|
||||
addEntry(attributeTable, robot, robot->url->url,
|
||||
html->currentAttribute->name);
|
||||
#endif
|
||||
}
|
||||
viewHTMLAttributeName(app, input);
|
||||
}
|
||||
|
||||
static void
|
||||
robotHTMLAttributeValue(App *app, HTML *html, Input *input)
|
||||
{
|
||||
Robot *robot;
|
||||
|
||||
robot = app->data;
|
||||
|
||||
viewHTMLAttributeValue(app, input);
|
||||
}
|
||||
|
||||
static void
|
||||
robotContentType(App *app, unsigned char *contentType)
|
||||
{
|
||||
Robot *robot;
|
||||
|
||||
robot = app->data;
|
||||
|
||||
addEntry(contentTypeTable, robot, robot->url->url, contentType);
|
||||
}
|
||||
|
||||
static void
|
||||
metaHandler(App *app, HTML *html)
|
||||
{
|
||||
Robot *robot;
|
||||
HTMLAttribute *attr;
|
||||
unsigned char *charset;
|
||||
ContentType *contentType;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
attr = html->attributes;
|
||||
while (attr)
|
||||
|
@ -446,26 +446,26 @@ metaHandler(void *a, HTML *html)
|
|||
mimeFreeContentType(contentType);
|
||||
if (charset)
|
||||
{
|
||||
addEntry(metaCharsetTable, arg, arg->url->url,
|
||||
addEntry(metaCharsetTable, robot, robot->url->url,
|
||||
lowerCase(charset));
|
||||
free(charset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tagHandler(void *a, HTML *html)
|
||||
static void
|
||||
tagHandler(App *app, HTML *html)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
reportHTTPCharSet(void *a, unsigned char *charset)
|
||||
static void
|
||||
robotHTTPCharSet(App *app, unsigned char *charset)
|
||||
{
|
||||
Arg *arg;
|
||||
Robot *robot;
|
||||
|
||||
arg = a;
|
||||
robot = app->data;
|
||||
|
||||
addEntry(httpCharsetTable, arg, arg->url->url, charset);
|
||||
addEntry(httpCharsetTable, robot, robot->url->url, charset);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -525,7 +525,7 @@ printTimes(FILE *file)
|
|||
fprintf(file, "<td>Max</td>");
|
||||
fprintf(file, "</tr>");
|
||||
|
||||
for (i = 0; i < REPORT_TIME_MAX; i++)
|
||||
for (i = 0; i < appTimeMax; i++)
|
||||
{
|
||||
TimeEntry *entry;
|
||||
|
||||
|
@ -619,68 +619,93 @@ printStats(void)
|
|||
}
|
||||
|
||||
static void
|
||||
openViewFile(Arg *arg)
|
||||
openViewFile(App *app)
|
||||
{
|
||||
sprintf(arg->viewURL, "%010d.html", arg->count);
|
||||
sprintf(arg->viewFile, "%s%s", OUTPUT_DIRECTORY, arg->viewURL);
|
||||
Robot *robot;
|
||||
|
||||
robot = app->data;
|
||||
sprintf(robot->viewURL, "%010d.html", robot->count);
|
||||
sprintf(robot->viewFile, "%s%s", OUTPUT_DIRECTORY, robot->viewURL);
|
||||
/*
|
||||
sprintf(arg->viewFile, "/dev/null");
|
||||
sprintf(robot->viewFile, "/dev/null");
|
||||
*/
|
||||
arg->viewFileAdded = 0;
|
||||
arg->view = viewAlloc();
|
||||
arg->view->out = fopen(arg->viewFile, "w");
|
||||
if (!arg->view->out)
|
||||
robot->viewFileAdded = 0;
|
||||
app->view.out = fopen(robot->viewFile, "w");
|
||||
if (!app->view.out)
|
||||
{
|
||||
fprintf(stderr, "cannot open %s for writing: %s\n",
|
||||
arg->viewFile, strerror(errno));
|
||||
robot->viewFile, strerror(errno));
|
||||
exit(0);
|
||||
}
|
||||
fprintf(arg->view->out, "<html><head><title>View</title></head><body><tt>");
|
||||
fprintf(app->view.out, "<html><head><title>View</title></head><body><tt>");
|
||||
}
|
||||
|
||||
static void
|
||||
closeViewFile(Arg *arg)
|
||||
closeViewFile(App *app)
|
||||
{
|
||||
fprintf(arg->view->out, "</tt></body></html>");
|
||||
fclose(arg->view->out);
|
||||
if (!arg->viewFileAdded)
|
||||
Robot *robot;
|
||||
|
||||
robot = app->data;
|
||||
fprintf(app->view.out, "</tt></body></html>");
|
||||
fclose(app->view.out);
|
||||
if (!robot->viewFileAdded)
|
||||
{
|
||||
unlink(arg->viewFile);
|
||||
unlink(robot->viewFile);
|
||||
}
|
||||
arg->viewFileAdded = 0;
|
||||
FREE(arg->view);
|
||||
robot->viewFileAdded = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
processURL(Arg *arg)
|
||||
processURL(App *app)
|
||||
{
|
||||
Robot *robot;
|
||||
struct timeval theTime;
|
||||
|
||||
robot = app->data;
|
||||
|
||||
gettimeofday(&theTime, NULL);
|
||||
|
||||
reportStatus(arg, "processURL", __FILE__, __LINE__);
|
||||
app->status(app, "processURL", __FILE__, __LINE__);
|
||||
|
||||
openViewFile(arg);
|
||||
httpFree(httpProcess(arg, arg->url, NULL));
|
||||
closeViewFile(arg);
|
||||
openViewFile(app);
|
||||
httpFree(httpProcess(app, robot->url, NULL));
|
||||
closeViewFile(app);
|
||||
|
||||
reportStatus(arg, "processURL done", __FILE__, __LINE__);
|
||||
app->status(app, "processURL done", __FILE__, __LINE__);
|
||||
|
||||
reportTime(REPORT_TIME_TOTAL, &theTime);
|
||||
app->time(app, appTimeTotal, &theTime);
|
||||
}
|
||||
|
||||
static void *
|
||||
startHere(void *a)
|
||||
{
|
||||
Arg arg;
|
||||
Robot robot;
|
||||
App *app;
|
||||
|
||||
robot.slot = (int) a;
|
||||
|
||||
app = appAlloc();
|
||||
app->status = robotStatus;
|
||||
app->time = robotTime;
|
||||
app->http = robotHTTP;
|
||||
app->httpBody = robotHTTPBody;
|
||||
app->httpHeaderName = robotHTTPHeaderName;
|
||||
app->httpHeaderValue = robotHTTPHeaderValue;
|
||||
app->html = robotHTML;
|
||||
app->htmlText = robotHTMLText;
|
||||
app->htmlTag = robotHTMLTag;
|
||||
app->htmlAttributeName = robotHTMLAttributeName;
|
||||
app->htmlAttributeValue = robotHTMLAttributeValue;
|
||||
app->contentType = robotContentType;
|
||||
app->httpCharSet = robotHTTPCharSet;
|
||||
app->data = &robot;
|
||||
|
||||
arg.slot = (int) a;
|
||||
while (1)
|
||||
{
|
||||
threadMutexLock();
|
||||
while ((!currURL) && (count < LIMIT))
|
||||
{
|
||||
reportStatus(&arg, waiting, __FILE__, __LINE__);
|
||||
app->status(app, waiting, __FILE__, __LINE__);
|
||||
threadCondWait();
|
||||
}
|
||||
if (count >= LIMIT)
|
||||
|
@ -693,11 +718,11 @@ startHere(void *a)
|
|||
{
|
||||
printStats();
|
||||
}
|
||||
arg.count = count;
|
||||
arg.url = currURL;
|
||||
robot.count = count;
|
||||
robot.url = currURL;
|
||||
currURL = currURL->next;
|
||||
threadMutexUnlock();
|
||||
processURL(&arg);
|
||||
processURL(app);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -944,12 +969,14 @@ acceptNewClient(int fd)
|
|||
static void *
|
||||
startStatusFunc(void *a)
|
||||
{
|
||||
App *app;
|
||||
FD *f;
|
||||
int fd;
|
||||
fd_set localFDSet;
|
||||
int ret;
|
||||
|
||||
fd = netListen(NULL, NULL, &mainPort);
|
||||
app = appAlloc();
|
||||
fd = netListen(app, NULL, &mainPort);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "netListen failed\n");
|
||||
|
|
|
@ -154,63 +154,63 @@ print(View *view, Input *input)
|
|||
}
|
||||
|
||||
void
|
||||
viewHTML(View *view, Input *input)
|
||||
viewHTML(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#009900>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#009900>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
viewHTMLAttributeName(View *view, Input *input)
|
||||
viewHTMLAttributeName(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#FF6600>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#FF6600>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
viewHTMLAttributeValue(View *view, Input *input)
|
||||
viewHTMLAttributeValue(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#3333FF>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#3333FF>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
viewHTMLTag(View *view, Input *input)
|
||||
viewHTMLTag(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#CC33CC>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#CC33CC>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
viewHTMLText(View *view, Input *input)
|
||||
viewHTMLText(App *app, Input *input)
|
||||
{
|
||||
print(view, input);
|
||||
print(&app->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
viewHTTP(View *view, Input *input)
|
||||
viewHTTP(App *app, Input *input)
|
||||
{
|
||||
print(view, input);
|
||||
print(&app->view, input);
|
||||
}
|
||||
|
||||
void
|
||||
viewHTTPHeaderName(View *view, Input *input)
|
||||
viewHTTPHeaderName(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#FF6600>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#FF6600>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
viewHTTPHeaderValue(View *view, Input *input)
|
||||
viewHTTPHeaderValue(App *app, Input *input)
|
||||
{
|
||||
fprintf(view->out, "<font color=#3333FF>");
|
||||
print(view, input);
|
||||
fprintf(view->out, "</font>");
|
||||
fprintf(app->view.out, "<font color=#3333FF>");
|
||||
print(&app->view, input);
|
||||
fprintf(app->view.out, "</font>");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -220,38 +220,23 @@ viewVerbose(void)
|
|||
}
|
||||
|
||||
void
|
||||
viewReport(View *view, char *str)
|
||||
viewReport(App *app, char *str)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
fprintf(view->out, (char *) escapeHTML((unsigned char *) str));
|
||||
fprintf(view->out, "<br>");
|
||||
fflush(view->out);
|
||||
fprintf(app->view.out, (char *) escapeHTML((unsigned char *) str));
|
||||
fprintf(app->view.out, "<br>");
|
||||
fflush(app->view.out);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
viewReportHTML(View *view, char *str)
|
||||
viewReportHTML(App *app, char *str)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
fprintf(view->out, str);
|
||||
fprintf(view->out, "<br>");
|
||||
fflush(view->out);
|
||||
fprintf(app->view.out, str);
|
||||
fprintf(app->view.out, "<br>");
|
||||
fflush(app->view.out);
|
||||
}
|
||||
}
|
||||
|
||||
View *
|
||||
viewAlloc(void)
|
||||
{
|
||||
View *view;
|
||||
|
||||
view = calloc(sizeof(View), 1);
|
||||
if (!view)
|
||||
{
|
||||
fprintf(stderr, "cannot calloc View\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -33,17 +33,16 @@ typedef struct View
|
|||
FILE *out;
|
||||
} View;
|
||||
|
||||
View *viewAlloc(void);
|
||||
void viewHTML(View *view, Input *input);
|
||||
void viewHTMLAttributeName(View *view, Input *input);
|
||||
void viewHTMLAttributeValue(View *view, Input *input);
|
||||
void viewHTMLTag(View *view, Input *input);
|
||||
void viewHTMLText(View *view, Input *input);
|
||||
void viewHTTP(View *view, Input *input);
|
||||
void viewHTTPHeaderName(View *view, Input *input);
|
||||
void viewHTTPHeaderValue(View *view, Input *input);
|
||||
void viewReport(View *view, char *str);
|
||||
void viewReportHTML(View *view, char *str);
|
||||
void viewHTML(App *app, Input *input);
|
||||
void viewHTMLAttributeName(App *app, Input *input);
|
||||
void viewHTMLAttributeValue(App *app, Input *input);
|
||||
void viewHTMLTag(App *app, Input *input);
|
||||
void viewHTMLText(App *app, Input *input);
|
||||
void viewHTTP(App *app, Input *input);
|
||||
void viewHTTPHeaderName(App *app, Input *input);
|
||||
void viewHTTPHeaderValue(App *app, Input *input);
|
||||
void viewReport(App *app, char *str);
|
||||
void viewReportHTML(App *app, char *str);
|
||||
void viewVerbose(void);
|
||||
|
||||
#endif /* _VIEW_H_ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче