more Windows (without Cygwin) porting
now using autoconf
changed name from Web Sniffer to SniffURI
added reference to new sniffuri.org site
added HISTORY, INSTALL
updated to new boilerplate for MPL (license)
This commit is contained in:
erik%vanderpoel.org 2005-01-19 17:16:09 +00:00
Родитель 9df3f95d53
Коммит 6ee393f502
44 изменённых файлов: 7699 добавлений и 1560 удалений

Просмотреть файл

@ -0,0 +1,24 @@
How to Build these Tools
Linux/Unix (or Windows with Cygwin)
Type the following commands:
./configure
make
Windows (without Cygwin)
Type the following command:
nmake
How to Install the Tools
The view.cgi tool and index.html file must be installed in an appropriate
location for your Web server. See the Web server documentation.
The other tools are command line tools.

Просмотреть файл

@ -1,101 +1,118 @@
#
# 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 Web Sniffer.
#
# The Initial Developer of the Original Code is Erik van der Poel.
# Portions created by Erik van der Poel are
# Copyright (C) 1998,1999,2000 Erik van der Poel.
# All Rights Reserved.
#
# Contributor(s): Bruce Robson
#
# ***** 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 *****
# Solaris
LIBS = -lsocket -lnsl
# Linux, Unix or Windows with Cygwin (type "./configure; make")
CFLAGS = -Wall -pedantic -D_REENTRANT $(O_or_g)
EXE =
LIBS = @LIBS@
OBJ = o
RM = rm -f
# Windows NT
#LIBS =
CC = gcc
# Windows without Cygwin (type "nmake")
CFLAGS = /nologo /DWINDOWS=1 /D_WIN32_WINNT=0x0400
EXE = .exe
LIBS = wsock32.lib
OBJ = obj
RM = del
#O_or_g = -g
O_or_g = -O
CFLAGS = -Wall -pedantic -D_REENTRANT $(O_or_g)
PURIFY =
#PURIFY = purify
#PURIFY = purify -windows=no
OBJS = \
addurl.o \
file.o \
hash.o \
html.o \
http.o \
io.o \
mime.o \
net.o \
url.o \
utils.o \
view.o
OBJS = \
addurl.$(OBJ) \
file.$(OBJ) \
hash.$(OBJ) \
html.$(OBJ) \
http.$(OBJ) \
io.$(OBJ) \
mime.$(OBJ) \
net.$(OBJ) \
thread.$(OBJ) \
url.$(OBJ) \
utils.$(OBJ) \
view.$(OBJ)
EXES = \
dnstest \
ftp \
grab \
link \
pop \
proxy \
robot \
urltest \
view.cgi
EXES = \
dnstest$(EXE) \
ftp$(EXE) \
grab$(EXE) \
link$(EXE) \
pop$(EXE) \
proxy$(EXE) \
robot$(EXE) \
urltest$(EXE) \
view.cgi$(EXE)
#all: dnstest
#all: ftp
#all: grab
#all: link
#all: pop
#all: proxy
#all: robot
all: view.cgi
#all: $(EXES)
#all: dnstest$(EXE)
#all: ftp$(EXE)
#all: grab$(EXE)
#all: link$(EXE)
#all: pop$(EXE)
#all: proxy$(EXE)
#all: robot$(EXE)
#all: urltest$(EXE)
#all: view.cgi$(EXE)
all: $(EXES)
dnstest: dns.c $(OBJS)
dnstest$(EXE): dns.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) dns.c $(OBJS) $(LIBS) -o $@
ftp: ftp.c $(OBJS)
ftp$(EXE): ftp.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) ftp.c $(OBJS) $(LIBS) -o $@
grab: grab.c $(OBJS)
grab$(EXE): grab.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) grab.c $(OBJS) $(LIBS) -o $@
link: link.c $(OBJS)
link$(EXE): link.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) link.c $(OBJS) $(LIBS) -o $@
pop: pop.c $(OBJS)
pop$(EXE): pop.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) pop.c $(OBJS) $(LIBS) -o $@
proxy: proxy.c $(OBJS)
proxy$(EXE): proxy.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) proxy.c $(OBJS) $(LIBS) -o $@
robot: robot.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) robot.c $(OBJS) -lthread $(LIBS) -o $@
robot$(EXE): robot.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) robot.c $(OBJS) $(LIBS) -o $@
urltest: url.c utils.c
$(PURIFY) $(CC) $(CFLAGS) -DURL_TEST url.c utils.c -o $@
urltest$(EXE): urltest.c url.$(OBJ) utils.$(OBJ)
$(PURIFY) $(CC) $(CFLAGS) urltest.c url.$(OBJ) utils.$(OBJ) -o $@
view.cgi: cgiview.c $(OBJS)
view.cgi$(EXE): cgiview.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) cgiview.c $(OBJS) $(LIBS) -o $@
clean:
rm -f *.o $(EXES)
$(RM) *.$(OBJ) $(EXES)
win:
make -f Makefile.in clean
sed -e 's/^#Windows#//' Makefile.in > Makefile
tar cf - * | gzip > .ws.tgz
smbclient //10.1.1.3/ws -N -c 'put .ws.tgz'
rm .ws.tgz

Просмотреть файл

@ -0,0 +1,118 @@
# ***** 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 *****
# Linux, Unix or Windows with Cygwin (type "./configure; make")
CFLAGS = -Wall -pedantic -D_REENTRANT $(O_or_g)
EXE =
LIBS = @LIBS@
OBJ = o
RM = rm -f
# Windows without Cygwin (type "nmake")
#Windows#CFLAGS = /nologo /DWINDOWS=1 /D_WIN32_WINNT=0x0400
#Windows#EXE = .exe
#Windows#LIBS = wsock32.lib
#Windows#OBJ = obj
#Windows#RM = del
#O_or_g = -g
O_or_g = -O
PURIFY =
#PURIFY = purify
#PURIFY = purify -windows=no
OBJS = \
addurl.$(OBJ) \
file.$(OBJ) \
hash.$(OBJ) \
html.$(OBJ) \
http.$(OBJ) \
io.$(OBJ) \
mime.$(OBJ) \
net.$(OBJ) \
thread.$(OBJ) \
url.$(OBJ) \
utils.$(OBJ) \
view.$(OBJ)
EXES = \
dnstest$(EXE) \
ftp$(EXE) \
grab$(EXE) \
link$(EXE) \
pop$(EXE) \
proxy$(EXE) \
robot$(EXE) \
urltest$(EXE) \
view.cgi$(EXE)
#all: dnstest$(EXE)
#all: ftp$(EXE)
#all: grab$(EXE)
#all: link$(EXE)
#all: pop$(EXE)
#all: proxy$(EXE)
#all: robot$(EXE)
#all: urltest$(EXE)
#all: view.cgi$(EXE)
all: $(EXES)
dnstest$(EXE): dns.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) dns.c $(OBJS) $(LIBS) -o $@
ftp$(EXE): ftp.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) ftp.c $(OBJS) $(LIBS) -o $@
grab$(EXE): grab.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) grab.c $(OBJS) $(LIBS) -o $@
link$(EXE): link.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) link.c $(OBJS) $(LIBS) -o $@
pop$(EXE): pop.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) pop.c $(OBJS) $(LIBS) -o $@
proxy$(EXE): proxy.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) proxy.c $(OBJS) $(LIBS) -o $@
robot$(EXE): robot.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) robot.c $(OBJS) $(LIBS) -o $@
urltest$(EXE): urltest.c url.$(OBJ) utils.$(OBJ)
$(PURIFY) $(CC) $(CFLAGS) urltest.c url.$(OBJ) utils.$(OBJ) -o $@
view.cgi$(EXE): cgiview.c $(OBJS)
$(PURIFY) $(CC) $(CFLAGS) cgiview.c $(OBJS) $(LIBS) -o $@
clean:
$(RM) *.$(OBJ) $(EXES)
win:
make -f Makefile.in clean
sed -e 's/^#Windows#//' Makefile.in > Makefile
tar cf - * | gzip > .ws.tgz
smbclient //10.1.1.3/ws -N -c 'put .ws.tgz'
rm .ws.tgz

Просмотреть файл

@ -1,12 +1,14 @@
Web Sniffer
SniffURI
by Erik van der Poel <erik@netscape.com>
by Erik van der Poel <erik@vanderpoel.org>
originally created in 1998
http://sniffuri.org/
Introduction
@ -24,7 +26,7 @@ Description of Tools
documents are parsed and colored, and non-ASCII characters are shown in
hex. Links are turned into live links, that can be clicked to see the
source of that URL, allowing the user to "browse" source.
robot
Originally written to see how many documents actually include the HTTP
@ -32,20 +34,20 @@ Description of Tools
that collects various statistics, including HTML tag statistics, DNS
lookup timing, etc. This robot does not adhere to the standard robot
rules, so please exercise caution if you use this.
proxy
This is an HTTP proxy that sits between the user's browser and another
HTTP proxy. It captures all of the HTTP traffic between the browser and
the Internet, and presents it to the user in the same colorful way as
the above-mentioned view.cgi.
grab
Allows the user to "grab" a whole Web site, or everything under a
particular directory. This is useful if you want to grab a bunch of
related HTML files, e.g. the whole CSS2 spec.
link
Allows the user to recursively check for bad links in a Web site or
@ -55,28 +57,34 @@ Description of Tools
Description of Files
addurl.c, addurl.h: adds URLs to a list
cgiview.c, cgiview.html: the view.cgi tool
all.h: header that includes all the required headers
cgiview.c: the view.cgi tool
config*: autoconf-related files
dns.c: experimental DNS toy
doRun: used with robot
file.c, file.h: the file: URL
ftp.c: experimental FTP toy
grab.c: the "grab" tool
hash.c, hash.h: incomplete hash table routines
HISTORY: brief history of this project
html.c, html.h: HTML parser
http.c, http.h: simple HTTP implementation
index.html: used with view.cgi tool
INSTALL: see this file for build instructions
io.c, io.h: I/O routines
link.c: the "link" tool
main.h: very simple callbacks, could be more object-oriented
Makefile: the Solaris Makefile
Makefile, Makefile.in: to build everything
mime.c, mime.h: MIME Content-Type parser
mutex.h: for threading in the robot
net.c, net.h: low-level Internet APIs
pop.c: experimental POP toy
proxy.c: the "proxy" tool
robot.c: the "robot" tool
run: used with robot
test: directory used in testing
thread.c, thread.h: for threading in the robot and locks elsewhere
TODO: notes to myself
url.c, url.h: implementation of absolute and relative URLs
url.c, url.h, urltest.c: implementation of absolute and relative URLs
utils.c, utils.h: some little utility routines
view.c, view.h: presents stuff to the user

Просмотреть файл

@ -1,33 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "addurl.h"
#include "hash.h"
#include "html.h"
#include "url.h"
#include "utils.h"
#include "all.h"
static AddURLFunc addURLFunc = NULL;

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _ADDURL_H_
#define _ADDURL_H_

Просмотреть файл

@ -0,0 +1,81 @@
/* ***** 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 ***** */
#if !defined(WINDOWS)
#include "config.h"
#endif
#if HAVE_LIBPTHREAD
#undef HAVE_LIBTHREAD
#undef WINDOWS
#endif
#include <ctype.h>
#include <errno.h>
#include <float.h>
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_LIBPTHREAD
#include <pthread.h>
#endif
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <sys/stat.h>
#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if WINDOWS
#include <windows.h>
#define ECONNREFUSED WSAECONNREFUSED
#define ECONNRESET WSAECONNRESET
#define ETIMEDOUT WSAETIMEDOUT
typedef int socklen_t;
#endif
#include "addurl.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"
#include "url.h"
#include "utils.h"
#include "view.h"

Просмотреть файл

@ -1,38 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "html.h"
#include "http.h"
#include "io.h"
#include "main.h"
#include "mutex.h"
#include "url.h"
#include "utils.h"
#include "view.h"
mutex_t mainMutex;
#include "all.h"
static char *me = NULL;
@ -78,16 +68,16 @@ reportHTMLAttributeName(void *a, HTML *html, Input *input)
void
reportHTMLAttributeValue(void *a, HTML *html, Input *input)
{
URL *url;
View *view;
char *urlstring;
URL *url;
View *view;
unsigned char *urlstring;
view = a;
if (html->currentAttributeIsURL)
{
url = urlRelative(html->base, html->currentAttribute->value);
urlstring = escapeHTML(url ? (char*) url->url : "");
urlstring = escapeHTML(url ? url->url : (unsigned char *) "");
fprintf(view->out, "<a href=\"%s%s\">", me, urlstring);
free(urlstring);
urlFree(url);
@ -152,8 +142,8 @@ reportHTTPHeaderName(void *a, Input *input)
void
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
{
View *view;
char *urlstring;
View *view;
unsigned char *urlstring;
view = a;
@ -302,7 +292,14 @@ main(int argc, char *argv[])
char *verbose;
View *view;
MUTEX_INIT();
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
url = NULL;

Просмотреть файл

@ -0,0 +1,159 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <float.h> header file. */
#undef HAVE_FLOAT_H
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
/* Define to 1 if you have the `gethostbyname_r' function. */
#undef HAVE_GETHOSTBYNAME_R
/* Define to 1 if you have the `gethostname' function. */
#undef HAVE_GETHOSTNAME
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL
/* Define to 1 if you have the `pthread' library (-lpthread). */
#undef HAVE_LIBPTHREAD
/* Define to 1 if you have the `socket' library (-lsocket). */
#undef HAVE_LIBSOCKET
/* Define to 1 if you have the `thread' library (-lthread). */
#undef HAVE_LIBTHREAD
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the `mkdir' function. */
#undef HAVE_MKDIR
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
/* Define to 1 if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strcasecmp' function. */
#undef HAVE_STRCASECMP
/* Define to 1 if you have the `strchr' function. */
#undef HAVE_STRCHR
/* Define to 1 if you have the `strdup' function. */
#undef HAVE_STRDUP
/* Define to 1 if you have the `strerror' function. */
#undef HAVE_STRERROR
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strrchr' function. */
#undef HAVE_STRRCHR
/* Define to 1 if you have the `strstr' function. */
#undef HAVE_STRSTR
/* Define to 1 if you have the `sysinfo' function. */
#undef HAVE_SYSINFO
/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to the type of arg 1 for `select'. */
#undef SELECT_TYPE_ARG1
/* Define to the type of args 2, 3 and 4 for `select'. */
#undef SELECT_TYPE_ARG234
/* Define to the type of arg 5 for `select'. */
#undef SELECT_TYPE_ARG5
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc
/* Define to rpl_realloc if the replacement function should be used. */
#undef realloc
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t

5426
webtools/web-sniffer/configure поставляемый Executable file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,62 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# ***** 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 *****
AC_PREREQ(2.59)
AC_INIT(SniffURI, 0.1, erik@vanderpoel.org)
AC_CONFIG_SRCDIR([thread.h])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `XXX' with a function in `-lnsl':
AC_CHECK_LIB([nsl], [XXX])
AC_CHECK_LIB([pthread], [pthread_create])
# FIXME: Replace `XXX' with a function in `-lsocket':
AC_CHECK_LIB([socket], [XXX])
AC_CHECK_LIB([thread], [thr_create])
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([float.h netdb.h netinet/in.h stddef.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([gethostbyname gethostbyname_r gethostname gettimeofday memset mkdir select socket strcasecmp strchr strdup strerror strrchr strstr sysinfo])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Просмотреть файл

@ -1,31 +1,30 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <stdio.h>
#include <unistd.h>
#include "all.h"
#include "main.h"
#include "net.h"
#define server "host.domain.com"
#define server (unsigned char *) "host.domain.com"
#define QR 0 /* query */
#define OPCODE 0 /* standard query */
@ -39,10 +38,8 @@
static unsigned short ID = 0xbeef;
mutex_t mainMutex;
void
reportContentType(void *a, char *contentType)
reportContentType(void *a, unsigned char *contentType)
{
}
@ -82,7 +79,7 @@ reportHTTPBody(void *a, Input *input)
}
void
reportHTTPCharSet(void *a, char *charset)
reportHTTPCharSet(void *a, unsigned char *charset)
{
}
@ -92,12 +89,22 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
{
}
static char *
putDomainName(char *p, char *name)
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)
{
char *begin;
char *q;
@ -140,6 +147,15 @@ main(int argc, char *argv[])
int len;
unsigned char *p;
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
fd = netConnect(NULL, server, 53);
if (fd < 0)
{
@ -175,14 +191,14 @@ main(int argc, char *argv[])
buf[0] = 0;
buf[1] = len - 2;
bytesTransferred = write(fd, buf, len);
bytesTransferred = send(fd, buf, len, 0);
if (bytesTransferred != len)
{
fprintf(stderr, "wrong number of bytes written\n");
return 1;
}
bytesTransferred = read(fd, buf, sizeof(buf));
bytesTransferred = recv(fd, buf, sizeof(buf), 0);
for (i = 0; i < bytesTransferred; i++)
{

Просмотреть файл

@ -1,32 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <stdio.h>
#include <string.h>
#include "file.h"
#include "html.h"
#include "io.h"
#include "url.h"
#include "all.h"
void
fileProcess(void *a, URL *url)

Просмотреть файл

@ -1,29 +1,30 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _FILE_H_
#define _FILE_H_
#include <stdio.h>
#include "url.h"
void fileProcess(void *a, URL *url);

Просмотреть файл

@ -1,40 +1,35 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <stdio.h>
#include <string.h>
#include <unistd.h>
#include "main.h"
#include "net.h"
#include "url.h"
mutex_t mainMutex;
#include "all.h"
static int
readReply(int fd, char *buf, int size)
{
int bytesRead;
bytesRead = read(fd, buf, size - 1);
bytesRead = recv(fd, buf, size - 1, 0);
if (bytesRead < 0)
{
buf[0] = 0;
@ -67,7 +62,7 @@ writeRequest(int fd, char *command, char *argument)
}
strcat(buf, "\r\n");
len = strlen(buf);
bytesWritten = write(fd, buf, len);
bytesWritten = send(fd, buf, len, 0);
if (bytesWritten != len)
{
fprintf(stderr, "bytesWritten at line %d\n", __LINE__);
@ -154,7 +149,7 @@ ftpProcess(void *a, URL *url)
}
void
reportContentType(void *a, char *contentType)
reportContentType(void *a, unsigned char *contentType)
{
}
@ -194,7 +189,7 @@ reportHTTPBody(void *a, Input *input)
}
void
reportHTTPCharSet(void *a, char *charset)
reportHTTPCharSet(void *a, unsigned char *charset)
{
}
@ -204,17 +199,36 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
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[])
{
char *str;
URL *url;
unsigned char *str;
URL *url;
str = "ftp://ftp.somedomain.com/somedir/somefile";
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
str = (unsigned char *) "ftp://ftp.somedomain.com/somedir/somefile";
url = urlParse(str);
if (!url)
{

Просмотреть файл

@ -1,46 +1,34 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <errno.h>
#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "addurl.h"
#include "hash.h"
#include "html.h"
#include "http.h"
#include "main.h"
#include "mutex.h"
#include "url.h"
#include "utils.h"
#include "all.h"
typedef struct Arg
{
URL *url;
} Arg;
mutex_t mainMutex;
static char *limitURLs[] =
{
"http://www.w3.org/TR/REC-CSS2/",
@ -101,7 +89,7 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
{
}
@ -203,7 +191,14 @@ main(int argc, char *argv[])
char *prog;
URL *url;
MUTEX_INIT();
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
prog = strrchr(argv[0], '/');
if (prog)

Просмотреть файл

@ -1,31 +1,29 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "hash.h"
#include "mutex.h"
#include "all.h"
HashTable *
hashAlloc(void (*func)(unsigned char *key, void *value))
@ -101,7 +99,7 @@ hashLookup(HashTable *table, unsigned char *key)
{
HashEntry *entry;
MUTEX_LOCK();
threadMutexLock();
entry = table->buckets[hashValue(table, key)];
while (entry)
{
@ -111,7 +109,7 @@ hashLookup(HashTable *table, unsigned char *key)
}
entry = entry->next;
}
MUTEX_UNLOCK();
threadMutexUnlock();
return entry;
}
@ -122,7 +120,7 @@ hashAdd(HashTable *table, unsigned char *key, void *value)
HashEntry *entry;
unsigned long i;
MUTEX_LOCK();
threadMutexLock();
entry = calloc(sizeof(HashEntry), 1);
if (!entry)
{
@ -135,7 +133,7 @@ hashAdd(HashTable *table, unsigned char *key, void *value)
entry->next = table->buckets[i];
table->buckets[i] = entry;
table->count++;
MUTEX_UNLOCK();
threadMutexUnlock();
return entry;
}

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _HASH_H_
#define _HASH_H_

Просмотреть файл

@ -1,37 +1,29 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "hash.h"
#include "html.h"
#include "http.h"
#include "io.h"
#include "main.h"
#include "url.h"
#include "utils.h"
#include "all.h"
#define IS_WHITE_SPACE(c) \
( \

Просмотреть файл

@ -1,29 +1,30 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _HTML_H_
#define _HTML_H_
#include <stdio.h>
#include "io.h"
typedef struct HTMLAttribute

Просмотреть файл

@ -1,39 +1,29 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include "addurl.h"
#include "html.h"
#include "http.h"
#include "io.h"
#include "main.h"
#include "mime.h"
#include "net.h"
#include "url.h"
#include "utils.h"
#include "all.h"
static unsigned char *emptyHTTPResponse = (unsigned char *) "";
static unsigned char *http09Response = (unsigned char *) "";
@ -221,7 +211,7 @@ httpReadHeaders(HTTP *http, void *a, Input *input, unsigned char *url)
}
void
httpParseRequest(HTTP *http, void *a, unsigned char *url)
httpParseRequest(HTTP *http, void *a, char *url)
{
unsigned short c;
@ -301,31 +291,31 @@ httpGetObject(HTTP *http, void *a, int sock, URL *url, unsigned char **headers)
get = "GET ";
httpStr = " HTTP/1.0\n";
write(sock, get, strlen(get));
send(sock, get, strlen(get), 0);
if (url->path)
{
write(sock, url->path, strlen((char *) url->path));
send(sock, url->path, strlen((char *) url->path), 0);
}
if (url->params)
{
write(sock, url->params, strlen((char *) url->params));
send(sock, url->params, strlen((char *) url->params), 0);
}
if (url->query)
{
write(sock, url->query, strlen((char *) url->query));
send(sock, url->query, strlen((char *) url->query), 0);
}
write(sock, httpStr, strlen(httpStr));
send(sock, httpStr, strlen(httpStr), 0);
h = headers;
if (h)
{
while (*h)
{
write(sock, *h, strlen((char *) *h));
write(sock, "\n", 1);
send(sock, *h, strlen((char *) *h), 0);
send(sock, "\n", 1, 0);
h++;
}
}
write(sock, "\n", 1);
send(sock, "\n", 1, 0);
httpRead(http, a, sock, url->url);
}

Просмотреть файл

@ -1,29 +1,30 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _HTTP_H_
#define _HTTP_H_
#include <stdio.h>
#include "io.h"
#include "url.h"
@ -39,7 +40,7 @@ HTTP *httpAlloc(void);
void httpFree(HTTP *http);
int httpGetHTTP10OrGreaterCount(void);
int httpGetNonEmptyHTTPResponseCount(void);
void httpParseRequest(HTTP *http, void *a, unsigned char *url);
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);

Просмотреть файл

@ -1,41 +1,31 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
#include "plat.h"
#include "all.h"
#include <errno.h>
#include <malloc.h>
#include <memory.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef PLAT_UNIX
#include <sys/stropts.h>
#else
#include <sys/socket.h>
#endif
#include "io.h"
#include "utils.h"
#define GULP 2048
struct Input
{
@ -83,13 +73,11 @@ readInit(void)
Input *
readStream(int fd, unsigned char *url)
{
size_t bytesAvailable;
int bytesRead;
fd_set fdset;
Input *input;
int offset;
int ret;
struct stat statBuf;
unsigned long streamSize;
struct timeval timeout;
@ -119,39 +107,9 @@ readStream(int fd, unsigned char *url)
streamSize = 0;
break;
}
#ifdef PLAT_UNIX
if (ioctl(fd, I_NREAD, &bytesAvailable) == -1)
#else
if (ioctl(fd, FIONREAD, &bytesAvailable) == -1)
#endif
if (offset + GULP > input->readAlloc)
{
/* if fd is file, we get this error */
if (errno == ENOTTY)
{
if (fstat(fd, &statBuf))
{
perror("fstat");
streamSize = 0;
break;
}
else
{
bytesAvailable = statBuf.st_size;
}
}
else
{
if (errno != ECONNRESET)
{
perror("ioctl");
}
streamSize = 0;
break;
}
}
if (offset + bytesAvailable > input->readAlloc)
{
input->readAlloc = offset + bytesAvailable;
input->readAlloc = offset + GULP;
input->readBuf = realloc((void *) input->readBuf,
input->readAlloc + 1);
if (!input->readBuf)
@ -162,13 +120,13 @@ readStream(int fd, unsigned char *url)
break;
}
}
bytesRead = read(fd, (void *) (input->readBuf + offset),
bytesAvailable);
bytesRead = recv(fd, (void *) (input->readBuf + offset), GULP,
0);
if (bytesRead <= 0)
{
break;
}
else if (bytesRead > bytesAvailable)
else if (bytesRead > GULP)
{
/* should not happen */
streamSize = 0;
@ -208,10 +166,10 @@ readAvailableBytes(int fd)
input->readBufPtr = input->readBuf;
input->readBufEnd = input->readBuf;
input->readBufMarkEnd = input->readBuf;
bytesRead = read(fd, (void *) input->readBuf, input->readAlloc);
bytesRead = recv(fd, (void *) input->readBuf, input->readAlloc, 0);
if (bytesRead < 0)
{
perror("read");
perror("recv");
return input;
}
else if (bytesRead == input->readAlloc)

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _IO_H_
#define _IO_H_

Просмотреть файл

@ -1,46 +1,37 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <string.h>
#include "addurl.h"
#include "hash.h"
#include "html.h"
#include "http.h"
#include "main.h"
#include "mutex.h"
#include "url.h"
#include "utils.h"
#include "all.h"
typedef struct Arg
{
URL *url;
} Arg;
mutex_t mainMutex;
static unsigned char *limitURLs[] =
static char *limitURLs[] =
{
"http://lemming/people/erik/",
"http://sniffuri.org/test/",
NULL
};
@ -58,7 +49,7 @@ reportHTML(void *a, Input *input)
}
void
reportHTMLAttributeName(void *a, Input *input)
reportHTMLAttributeName(void *a, HTML *html, Input *input)
{
}
@ -68,7 +59,7 @@ reportHTMLAttributeValue(void *a, HTML *html, Input *input)
}
void
reportHTMLTag(void *a, Input *input)
reportHTMLTag(void *a, HTML *html, Input *input)
{
}
@ -98,7 +89,17 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
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)
{
}
@ -116,7 +117,14 @@ main(int argc, char *argv[])
HTTP *http;
URL *url;
MUTEX_INIT();
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
if (argc > 1)
{
@ -125,7 +133,7 @@ main(int argc, char *argv[])
addURLInit(addURLFunc, limitURLs, NULL);
url = urlParse(limitURLs[0]);
url = urlParse((unsigned char *) limitURLs[0]);
urls = url;
lastURL = url;
while (url)
@ -137,7 +145,7 @@ main(int argc, char *argv[])
switch (http->status)
{
case 200:
printf("%s\n", url->url);
printf("%s\n", (char *) url->url);
break;
case 302:
break;

Просмотреть файл

@ -1,43 +1,32 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 "plat.h"
#ifdef PLAT_UNIX
#include <synch.h>
#else
#include <windows.h>
#endif
#include "html.h"
#include "io.h"
#ifdef PLAT_UNIX
extern mutex_t mainMutex;
#else
extern HANDLE mainMutex;
#endif
#define REPORT_TIME_CONNECT_SUCCESS 0
#define REPORT_TIME_CONNECT_FAILURE 1

Просмотреть файл

@ -1,30 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <stdio.h>
#include <string.h>
#include "mime.h"
#include "utils.h"
#include "all.h"
#define IS_WHITE_SPACE(c) \
( \

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _MIME_H_
#define _MIME_H_

Просмотреть файл

@ -1,85 +0,0 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
#include "plat.h"
#ifdef PLAT_UNIX
#include <thread.h>
#include <synch.h>
#endif
#include "main.h"
#ifdef PLAT_UNIX
#define MUTEX_INIT() \
if (mutex_init(&mainMutex, USYNC_THREAD, NULL)) \
{ \
fprintf(stderr, "mutex_init failed\n"); \
exit(0); \
return 1; \
}
#define MUTEX_LOCK() \
do \
{ \
mutex_lock(&mainMutex); \
} while (0);
#define MUTEX_UNLOCK() \
do \
{ \
mutex_unlock(&mainMutex); \
} while (0);
#define DECLARE_MUTEX mutex_t mainMutex
#else /* Windows */
#define MUTEX_INIT() \
if ((mainMutex = CreateMutex (NULL, FALSE, NULL)) == NULL) \
{ \
fprintf(stderr, "CreateMutex failed\n"); \
exit(0); \
return 1; \
}
#define MUTEX_LOCK() \
do \
{ \
if (WaitForSingleObject(mainMutex, INFINITE) == WAIT_FAILED) \
{ \
fprintf(stderr, "WaitForSingleObject(mainMutex) failed\n"); \
} \
} while (0);
#define MUTEX_UNLOCK() \
do \
{ \
if (ReleaseMutex(mainMutex) == 0) \
{ \
fprintf(stderr, "ReleaseMutex failed\n"); \
} \
} while (0);
#define DECLARE_MUTEX HANDLE mainMutex = NULL
#endif

Просмотреть файл

@ -1,47 +1,29 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
#include "plat.h"
#include <errno.h>
#include <memory.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#ifdef PLAT_UNIX
#include <thread.h>
#include <sys/systeminfo.h>
#endif
#include <signal.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include "main.h"
#include "mutex.h"
#include "net.h"
#include "view.h"
#include "all.h"
static int connectCount = 0;
static int dnsCount = 0;
@ -51,9 +33,6 @@ getHostName(void)
{
size_t alloc;
char *hostName;
#ifdef PLAT_UNIX
long size;
#endif
alloc = 512;
hostName = calloc(alloc, 1);
@ -62,9 +41,19 @@ getHostName(void)
return NULL;
}
#ifdef PLAT_UNIX
#if HAVE_GETHOSTNAME
if (gethostname(hostName, alloc) != 0)
{
fprintf(stderr, "gethostname failed\n");
free(hostName);
return NULL;
}
#else
#if HAVE_SYSINFO
while (1)
{
long size;
size = sysinfo(SI_HOSTNAME, hostName, alloc);
if (size < 0)
{
@ -85,13 +74,7 @@ getHostName(void)
break;
}
}
#else /* Windows */
if (gethostname(hostName, alloc) != 0)
{
fprintf(stderr, "gethostname failed\n");
free(hostName);
return NULL;
}
#endif
#endif
return hostName;
@ -101,17 +84,25 @@ static int
getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
struct sockaddr_in *addr)
{
#ifdef PLAT_UNIX
#if HAVE_GETHOSTBYNAME_R
char buf[512];
int err;
#endif
struct hostent host;
struct protoent *proto;
struct hostent *ret;
unsigned short shortPort;
int sock;
struct timeval theTime;
sock = socket(PF_INET, SOCK_STREAM, 0);
proto = getprotobyname("tcp");
if (!proto)
{
perror("getprotobyname failed");
return -1;
}
sock = socket(PF_INET, SOCK_STREAM, proto->p_proto);
if (sock < 0)
{
perror("socket failed");
@ -127,10 +118,18 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
/* XXX implement my own DNS lookup to do timeouts? */
/* XXX implement my own DNS lookup to try again? */
#ifdef PLAT_UNIX
#if HAVE_GETHOSTBYNAME_R
#if HAVE_GETHOSTBYNAME_R_SOLARIS
ret = gethostbyname_r((char *) hostName, &host, buf, sizeof(buf), &err);
if (!ret)
#else /* Windows */
#else
gethostbyname_r((const char *) hostName, &host, buf, sizeof(buf), &ret,
&err);
if (!ret)
#endif
#else
threadMutexLock();
ret = gethostbyname((char *) hostName);
if (ret != NULL)
{
@ -143,6 +142,9 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
reportStatus(a, "gethostbyname_r failed", __FILE__, __LINE__);
fprintf(stdout, "failed<br><hr><br>");
close(sock);
#if !defined(HAVE_GETHOSTBYNAME_R)
threadMutexUnlock();
#endif
return -1;
}
@ -152,24 +154,27 @@ getSocketAndIPAddress(void *a, unsigned char *hostName, int port,
fprintf(stdout, "succeeded<br><hr><br>");
MUTEX_LOCK();
dnsCount++;
MUTEX_UNLOCK();
memset(addr, 0, sizeof(*addr));
addr->sin_family = host.h_addrtype /* PF_INET */;
shortPort = port;
addr->sin_port = htons(shortPort);
memcpy(&addr->sin_addr, host.h_addr, host.h_length /* 4 */);
#if HAVE_GETHOSTBYNAME_R
threadMutexLock();
#endif
dnsCount++;
threadMutexUnlock();
return sock;
}
int
netListen(void *a, unsigned char **host, u_short *port)
netListen(void *a, unsigned char **host, unsigned short *port)
{
unsigned char *hostName;
struct sockaddr_in name;
int namelen = sizeof(name);
socklen_t namelen = sizeof(name);
int fd;
hostName = (unsigned char *) getHostName();
@ -220,7 +225,7 @@ int
netAccept(int fd)
{
int newFD;
int addrlen = sizeof(struct sockaddr);
socklen_t addrlen = sizeof(struct sockaddr);
struct sockaddr addr;
while ((newFD = accept(fd, &addr, &addrlen)) < 0)
@ -283,9 +288,9 @@ netConnect(void *a, unsigned char *hostName, int port)
fprintf(stdout, "succeeded<br><hr><br>");
MUTEX_LOCK();
threadMutexLock();
connectCount++;
MUTEX_UNLOCK();
threadMutexUnlock();
return sock;
}
@ -301,3 +306,21 @@ netGetDNSCount(void)
{
return dnsCount;
}
int
netInit(void)
{
#if WINDOWS
int ret;
WSADATA wsaData;
ret = WSAStartup(0x0001, &wsaData);
if (ret)
{
fprintf(stderr, "WSAStartup failed\n");
return 0;
}
#endif
return 1;
}

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _NET_H_
#define _NET_H_
@ -26,6 +29,7 @@ int netAccept(int fd);
int netConnect(void *a, unsigned char *hostName, int port);
int netGetConnectCount(void);
int netGetDNSCount(void);
int netInit(void);
int netListen(void *a, unsigned char **host, unsigned short *port);
#endif /* _NET_H_ */

Просмотреть файл

@ -1,36 +0,0 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
#ifndef _PLAT_H_
#define _PLAT_H_
/* need to improve this! */
#undef PLAT_UNIX
#undef PLAT_WINDOWS
/* Unix */
#define PLAT_UNIX 1
/* Windows */
/* #define PLAT_WINDOWS 1 */
#endif /* _PLAT_H_ */

Просмотреть файл

@ -1,39 +1,35 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <stdio.h>
#include <string.h>
#include <unistd.h>
#include "main.h"
#include "net.h"
mutex_t mainMutex;
#include "all.h"
static int
readReply(int fd, unsigned char *buf, int size)
{
int bytesRead;
bytesRead = read(fd, buf, size - 1);
bytesRead = recv(fd, buf, size - 1, 0);
if (bytesRead < 0)
{
buf[0] = 0;
@ -47,7 +43,7 @@ readReply(int fd, unsigned char *buf, int size)
fprintf(stderr, "bytesRead %d at line %d\n", bytesRead,
__LINE__);
}
if (strncmp(buf, "+OK", 3))
if (strncmp((char *) buf, "+OK", 3))
{
return 1;
}
@ -69,7 +65,7 @@ writeRequest(int fd, char *command, char *argument)
}
strcat(buf, "\r\n");
len = strlen(buf);
bytesWritten = write(fd, buf, len);
bytesWritten = send(fd, buf, len, 0);
if (bytesWritten != len)
{
fprintf(stderr, "bytesWritten at line %d\n", __LINE__);
@ -85,7 +81,7 @@ pop(char *host, char *user, char *password)
unsigned char buf[4096];
int fd;
fd = netConnect(NULL, host, 110);
fd = netConnect(NULL, (unsigned char *) host, 110);
if (fd < 0)
{
fprintf(stderr, "netConnect failed\n");
@ -110,9 +106,18 @@ pop(char *host, char *user, char *password)
}
int
main(int argc, char *argv)
main(int argc, char *argv[])
{
unsigned char *password;
char *password;
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
password = NULL;
pop("nsmail-2", "erik", password);
@ -171,6 +176,16 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
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)
{
}

Просмотреть файл

@ -1,55 +1,33 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s): Bruce Robson
*/
/* ***** 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 ***** */
/* host and port of proxy that this proxy connects to */
#define PROXY_HOST "w3proxy.netscape.com"
#define PROXY_PORT 8080
/*
#define PROXY_HOST "127.0.0.1"
#define PROXY_PORT 4444
*/
#include "plat.h"
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#ifdef PLAT_WINDOWS
#include <windows.h>
#endif
#include "html.h"
#include "http.h"
#include "mutex.h"
#include "net.h"
#include "utils.h"
#include "view.h"
#include "all.h"
typedef int (*Handler)(int fd);
@ -68,63 +46,66 @@ typedef struct Arg
View *view;
} Arg;
DECLARE_MUTEX;
static fd_set fdSet;
static int id = 0;
static u_short mainPort = 40404;
static unsigned short mainPort = 40404;
static int maxFD = -1;
static FD **table = NULL;
static unsigned char suspendStr[1024];
static char suspendStr[1024];
static char *welcome =
"HTTP/1.0 200 OK
Content-Type: text/html
static char *welcome1 =
"HTTP/1.0 200 OK\n"
"Content-Type: text/html\n"
"\n"
"<title>Interceptor</title>\n"
"<h3>HTTP Interceptor Persistent Window</h3>\n"
"<p>\n"
"Keep this window alive as long as you want to continue the session.\n"
"It is recommended that you Minimize (Iconify) this window.\n"
"Do not click the Back button in this window.\n"
"Do not load another document in this window.\n"
"</p>\n"
"<script>\n";
<title>Interceptor</title>
<h3>HTTP Interceptor Persistent Window</h3>
<p>
Keep this window alive as long as you want to continue the session.
It is recommended that you Minimize (Iconify) this window.
Do not click the Back button in this window.
Do not load another document in this window.
</p>
<script>
interceptorSuspendResumeWindow =
window.open
(
\"\",
\"interceptorSuspendResumeWindow\",
\"menubar,toolbar,location,directories,scrollbars,status\"
);
interceptorSuspendResumeWindow.document.write(
\"<title>Welcome to the HTTP Interceptor</title>\" +
\"<h3>Welcome to the HTTP Interceptor</h3>\" +
\"<p>\" +
\"A new HTTP Interceptor session has been started for you. \" +
\"To start using this session, set your HTTP Proxy preference to the \" +
\"following. (Edit | Preferences | Advanced | Proxies | \" +
\"Manual proxy configuration | View | HTTP)\" +
\"</p>\" +
\"<pre>\" +
\"\\n\" +
\"\\tHTTP Proxy Server Address %s; Port %d\" +
\"\\n\" +
\"</pre>\" +
\"<h3>How to Suspend and Resume Logging</h3>\" +
\"<p>\" +
\"You can temporarily suspend and resume the HTTP Interceptor logging \" +
\"feature by clicking the links below.\" +
\"</p>\" +
\"<a href=http://%s:%d/suspend/%d>Suspend Logging</a><br>\" +
\"<a href=http://%s:%d/resume/%d>Resume Logging</a>\" +
\"<p>\" +
\"You may find it useful to drag these links to your Personal Toolbar.\" +
\"</p>\"
);
</script>
";
static char *welcome2 =
"interceptorSuspendResumeWindow =\n"
" window.open\n"
" (\n"
" \"\",\n"
" \"interceptorSuspendResumeWindow\",\n"
" \"menubar,toolbar,location,directories,scrollbars,status\"\n"
" );\n"
"interceptorSuspendResumeWindow.document.write(\n"
"\"<title>Welcome to the HTTP Interceptor</title>\" +\n"
"\"<h3>Welcome to the HTTP Interceptor</h3>\" +\n"
"\"<p>\" +\n"
"\"A new HTTP Interceptor session has been started for you. \" +\n";
static char *welcome3 =
"\"To start using this session, set your HTTP Proxy preference to the \" +\n"
"\"following. (Edit | Preferences | Advanced | Proxies | \" +\n"
"\"Manual proxy configuration | View | HTTP)\" +\n"
"\"</p>\" +\n"
"\"<pre>\" +\n"
"\"\\n\" +\n"
"\"\\tHTTP Proxy Server Address %s; Port %d\" +\n"
"\"\\n\" +\n"
"\"</pre>\" +\n"
"\"<h3>How to Suspend and Resume Logging</h3>\" +\n"
"\"<p>\" +\n"
"\"You can temporarily suspend and resume the HTTP Interceptor logging \" +\n"
"\"feature by clicking the links below.\" +\n";
static char *welcome4 =
"\"</p>\" +\n"
"\"<a href=http://%s:%d/suspend/%d>Suspend Logging</a><br>\" +\n"
"\"<a href=http://%s:%d/resume/%d>Resume Logging</a>\" +\n"
"\"<p>\" +\n"
"\"You may find it useful to drag these links to your Personal Toolbar.\" +\n"
"\"</p>\"\n"
");\n"
"</script>\n";
static FD *
addFD(int fd, Handler func)
@ -200,7 +181,7 @@ logRequest(FD *f, Input *input)
if
(
(table[fileno(f->logFile)]->suspend) ||
(strstr(current(input), suspendStr))
(strstr((char *) current(input), suspendStr))
)
{
table[f->writeFD]->suspend = 1;
@ -241,7 +222,7 @@ readClientRequest(int fd)
f = table[fd];
input = readAvailableBytes(fd);
write(f->writeFD, current(input), inputLength(input));
send(f->writeFD, current(input), inputLength(input), 0);
if (!logRequest(f, input))
{
inputFree(input);
@ -274,7 +255,7 @@ logResponse(FD *f, Input *input)
arg.view = viewAlloc();
arg.view->backslash = 1;
arg.view->out = f->logFile;
httpParseStream(http, &arg, "readProxyResponse");
httpParseStream(http, &arg, (unsigned char *) "readProxyResponse");
free(arg.view);
httpFree(http);
fprintf(f->logFile, "</b></pre>\");\n</script>\n");
@ -290,8 +271,8 @@ readProxyResponse(int fd)
Input *input;
f = table[fd];
input = readStream(fd, "readProxyResponse");
write(f->writeFD, current(input), inputLength(input));
input = readStream(fd, (unsigned char *) "readProxyResponse");
send(f->writeFD, current(input), inputLength(input), 0);
if (!logResponse(f, input))
{
inputFree(input);
@ -325,7 +306,7 @@ acceptNewClient(int fd)
return 0;
}
proxyFD = netConnect(NULL, PROXY_HOST, PROXY_PORT);
proxyFD = netConnect(NULL, (unsigned char *) PROXY_HOST, PROXY_PORT);
if (proxyFD < 0)
{
fprintf(stderr, "netConnect to proxy %s:%d failed\n",
@ -357,27 +338,27 @@ acceptNewClient(int fd)
static int
readLoggerRequest(int fd)
{
unsigned char buf[10240];
char buf[10240];
int bytesRead;
int doSuspend;
FD *f;
FILE *file;
unsigned char *host;
int i;
unsigned char *p;
u_short port;
char *p;
unsigned short port;
int proxyListenFD;
unsigned char *resume;
unsigned char *str;
unsigned char *suspend;
char *resume;
char *str;
char *suspend;
int suspendPort;
bytesRead = read(fd, buf, sizeof(buf) - 1);
bytesRead = recv(fd, buf, sizeof(buf) - 1, 0);
if (bytesRead < 0)
{
if (errno != ECONNRESET)
{
perror("read");
perror("recv");
}
removeFD(fd);
return 0;
@ -399,7 +380,7 @@ readLoggerRequest(int fd)
"\n"
"Bye!"
;
write(fd, goodbye, strlen(goodbye));
send(fd, goodbye, strlen(goodbye), 0);
removeFD(fd);
return 1;
}
@ -425,7 +406,7 @@ readLoggerRequest(int fd)
"\n"
"No backslash after command!"
;
write(fd, notOK, strlen(notOK));
send(fd, notOK, strlen(notOK), 0);
removeFD(fd);
return 0;
}
@ -446,7 +427,7 @@ readLoggerRequest(int fd)
"\n"
"OK!"
;
write(fd, ok, strlen(ok));
send(fd, ok, strlen(ok), 0);
}
else
{
@ -456,19 +437,19 @@ readLoggerRequest(int fd)
"\n"
"Cannot find port number in table!"
;
write(fd, notOK, strlen(notOK));
send(fd, notOK, strlen(notOK), 0);
}
removeFD(fd);
return 0;
}
/* XXX write(1, buf, bytesRead); */
/* XXX send(1, buf, bytesRead, 0); */
file = fdopen(fd, "w");
if (!file)
{
char *err = "fdopen failed\n";
write(fd, err, strlen(err));
send(fd, err, strlen(err), 0);
removeFD(fd);
return 0;
}
@ -492,19 +473,10 @@ readLoggerRequest(int fd)
return 0;
}
fprintf
(
file,
welcome,
host,
port,
host,
mainPort,
port,
host,
mainPort,
port
);
fprintf(file, welcome1);
fprintf(file, welcome2);
fprintf(file, welcome3, host, port);
fprintf(file, welcome4, host, mainPort, port, host, mainPort, port);
sprintf(suspendStr, "http://%s:%d/suspend/%d", host, mainPort, port);
free(host);
fflush(file);
@ -646,7 +618,14 @@ main(int argc, char *argv[])
fd_set localFDSet;
int ret;
MUTEX_INIT();
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
fd = netListen(NULL, NULL, &mainPort);
if (fd < 0)

Просмотреть файл

@ -1,55 +1,30 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <errno.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <thread.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/stropts.h>
#include "all.h"
#include "addurl.h"
#include "hash.h"
#include "html.h"
#include "http.h"
#include "io.h"
#include "main.h"
#include "mime.h"
#include "mutex.h"
#include "net.h"
#include "url.h"
#include "utils.h"
#include "view.h"
#define OUTPUT_DIRECTORY "/some/output/directory/"
#define OUTPUT_DIRECTORY "test/robot/"
typedef struct Entry
{
@ -94,16 +69,14 @@ typedef struct FD
FILE *file;
} FD;
mutex_t mainMutex;
#define numberOfSlots 64
static thread_t slots[numberOfSlots];
static Thread slots[numberOfSlots];
static thread_t statusThread;
static Thread statusThread;
static StatusEntry statusEntries[numberOfSlots];
static int sortedStatusEntries[numberOfSlots];
static u_short mainPort = 40404;
static unsigned short mainPort = 40404;
static int maxFD = -1;
static FD **table = NULL;
static fd_set fdSet;
@ -129,12 +102,21 @@ static unsigned char *limitURLs[] =
};
#endif
static char *outFile = OUTPUT_DIRECTORY "index.html";
static char *limitDomains[16];
static int limitDomainsIndex = 0;
static int count = 0;
#define LIMIT 50
#define INTERVAL ((LIMIT / 100) ? (LIMIT / 100) : 5)
static URL *currURL = NULL;
static URL *lastURL = NULL;
static URL *urls = NULL;
static char *waiting = "waiting";
#ifdef ROBOT_LOG_ATTRIBUTES
static HashTable *attributeTable = NULL;
#endif
@ -187,7 +169,7 @@ reportTime(int task, struct timeval *before)
gettimeofday(&after, NULL);
MUTEX_LOCK();
threadMutexLock();
span = (((after.tv_sec - before->tv_sec) * 1000000.0) +
after.tv_usec - before->tv_usec);
times[task].total += span;
@ -200,7 +182,7 @@ reportTime(int task, struct timeval *before)
times[task].max = span;
}
times[task].count++;
MUTEX_UNLOCK();
threadMutexUnlock();
}
static void
@ -268,8 +250,15 @@ addURLFunc(void *a, URL *url)
}
else
{
threadMutexLock();
lastURL->next = url;
lastURL = url;
if (!currURL)
{
currURL = url;
}
threadCondSignal();
threadMutexUnlock();
}
}
@ -304,7 +293,7 @@ reportHTTPHeaderName(void *a, Input *input)
}
void
reportHTTPHeaderValue(void *a, Input *input)
reportHTTPHeaderValue(void *a, Input *input, unsigned char *url)
{
Arg *arg;
@ -566,16 +555,15 @@ printTimes(FILE *file)
}
static void
printStats(char *file, int count)
printStats(void)
{
char backup[1024];
char **limit;
time_t theTime;
MUTEX_LOCK();
sprintf(backup, "%s.bak", file);
rename(file, backup);
statsOut = fopen(file, "w");
sprintf(backup, "%s.bak", outFile);
rename(outFile, backup);
statsOut = fopen(outFile, "w");
fprintf(statsOut, "<html><head><title>Stats</title></head><body>\n");
fprintf(statsOut, "<table bgcolor=#cccccc>\n");
fprintf(statsOut,
@ -628,17 +616,16 @@ printStats(char *file, int count)
#endif
fprintf(statsOut, "</body></html>\n");
fclose(statsOut);
MUTEX_UNLOCK();
}
static void
openViewFile(Arg *arg)
{
sprintf(arg->viewURL, "view/%010d.html", arg->count);
/*
sprintf(arg->viewURL, "%010d.html", arg->count);
sprintf(arg->viewFile, "%s%s", OUTPUT_DIRECTORY, arg->viewURL);
*/
/*
sprintf(arg->viewFile, "/dev/null");
*/
arg->viewFileAdded = 0;
arg->view = viewAlloc();
arg->view->out = fopen(arg->viewFile, "w");
@ -664,130 +651,72 @@ closeViewFile(Arg *arg)
FREE(arg->view);
}
static void *
startHere(void *a)
static void
processURL(Arg *arg)
{
Arg *arg;
struct timeval theTime;
gettimeofday(&theTime, NULL);
reportStatus(a, "startHere", __FILE__, __LINE__);
arg = a;
reportStatus(arg, "processURL", __FILE__, __LINE__);
openViewFile(arg);
httpFree(httpProcess(a, arg->url, NULL));
httpFree(httpProcess(arg, arg->url, NULL));
closeViewFile(arg);
reportStatus(a, "startHere done", __FILE__, __LINE__);
free(a);
reportStatus(arg, "processURL done", __FILE__, __LINE__);
reportTime(REPORT_TIME_TOTAL, &theTime);
}
static void *
startHere(void *a)
{
Arg arg;
arg.slot = (int) a;
while (1)
{
threadMutexLock();
while ((!currURL) && (count < LIMIT))
{
reportStatus(&arg, waiting, __FILE__, __LINE__);
threadCondWait();
}
if (count >= LIMIT)
{
threadMutexUnlock();
break;
}
count++;
if (!(count % INTERVAL))
{
printStats();
}
arg.count = count;
arg.url = currURL;
currURL = currURL->next;
threadMutexUnlock();
processURL(&arg);
}
return NULL;
}
static void
spinThread(int count, URL *url)
static int
allThreadsAreWaiting(void)
{
Arg *arg;
thread_t departed;
int i;
int ret;
if (numberOfSlots < 2)
{
arg = calloc(sizeof(Arg), 1);
if (!arg)
{
fprintf(stderr, "cannot calloc Arg\n");
exit(0);
}
arg->slot = 0;
arg->count = count;
arg->url = url;
startHere(arg);
return;
}
int i;
for (i = 0; i < numberOfSlots; i++)
{
if (!slots[i])
if (statusEntries[i].message != waiting)
{
break;
}
}
if (i < numberOfSlots)
{
arg = calloc(sizeof(Arg), 1);
if (!arg)
{
fprintf(stderr, "cannot calloc Arg\n");
exit(0);
}
arg->slot = i;
arg->count = count;
arg->url = url;
ret = thr_create(NULL, 0, startHere, arg, 0, &slots[i]);
if (ret)
{
fprintf(stderr, "thr_create: ret %d\n", ret);
exit(0);
}
}
else
{
ret = thr_join(0, &departed, NULL);
if (ret)
{
fprintf(stderr, "thr_join failed\n");
exit(0);
}
for (i = 0; i < numberOfSlots; i++)
{
if (slots[i] == departed)
{
slots[i] = 0;
spinThread(count, url);
break;
}
}
if (i >= numberOfSlots)
{
fprintf(stderr, "cannot find departed thread\n");
exit(0);
}
}
}
static void
waitForAllThreads(void)
{
if (numberOfSlots < 2)
{
return;
}
while (1)
{
if (thr_join(0, NULL, NULL))
{
break;
}
}
}
static int
waitForOneThread(void)
{
if (numberOfSlots < 2)
{
return 1;
}
return thr_join(0, NULL, NULL);
return i == numberOfSlots;
}
static void
@ -891,12 +820,12 @@ readClientRequest(int fd)
FILE *file;
int i;
bytesRead = read(fd, buf, sizeof(buf) - 1);
bytesRead = recv(fd, buf, sizeof(buf) - 1, 0);
if (bytesRead < 0)
{
if (errno != ECONNRESET)
{
perror("read");
perror("recv");
}
removeFD(fd);
return;
@ -912,7 +841,7 @@ readClientRequest(int fd)
if (!file)
{
char *err = "fdopen failed\n";
write(fd, err, strlen(err));
send(fd, err, strlen(err), 0);
removeFD(fd);
return;
}
@ -1059,10 +988,9 @@ startStatusThread(void)
{
int ret;
ret = thr_create(NULL, 0, startStatusFunc, NULL, 0, &statusThread);
ret = threadCreate(&statusThread, startStatusFunc, NULL);
if (ret)
{
fprintf(stderr, "thr_create: ret %d\n", ret);
exit(0);
}
}
@ -1070,21 +998,19 @@ startStatusThread(void)
int
main(int argc, char *argv[])
{
int count;
int i;
int interval;
int limit;
char *outFile;
time_t theTime;
URL *url;
int ret;
#if !defined(WINDOWS)
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
{
fprintf(stderr, "signal failed\n");
exit(0);
}
#endif
outFile = NULL;
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-d"))
@ -1105,7 +1031,14 @@ main(int argc, char *argv[])
}
}
MUTEX_INIT();
if (!netInit())
{
return 1;
}
if (!threadInit())
{
return 1;
}
time(&theTime);
startTime = copyString((unsigned char *) ctime(&theTime));
@ -1132,57 +1065,51 @@ main(int argc, char *argv[])
startStatusThread();
for (i = 0; i < numberOfSlots; i++)
{
ret = threadCreate(&slots[i], startHere, (void *) i);
if (ret)
{
exit(0);
}
}
threadYield();
if (!firstURL)
{
firstURL = "http://somehost/somedir/";
}
if (!outFile)
{
outFile = OUTPUT_DIRECTORY "zzz.html";
firstURL = "http://mozilla.org/";
}
url = urlParse((unsigned char *) firstURL);
hashAdd(urlTable, (unsigned char *) firstURL, 0);
urls = url;
lastURL = url;
limit = 50000;
interval = (limit / 100);
if (!interval)
{
interval = 5;
}
count = 0;
currURL = url;
threadCondSignal();
threadYield();
while (1)
{
count++;
spinThread(count, url);
if (!(count % interval))
if (allThreadsAreWaiting())
{
printStats(outFile, count);
}
if (count >= limit)
{
thr_kill(statusThread, SIGKILL);
waitForAllThreads();
for (i = 0; i < numberOfSlots; i++)
{
threadCancel(slots[i]);
}
break;
}
else if (!url->next)
if (count >= LIMIT)
{
while (!url->next)
threadCondBroadcast();
for (i = 0; i < numberOfSlots; i++)
{
if (waitForOneThread())
{
break;
}
}
if (!url->next)
{
break;
threadJoin(slots[i]);
}
threadCancel(statusThread);
break;
}
url = url->next;
}
printStats(outFile, count);
printStats();
#ifdef ROBOT_LOG_ATTRIBUTES
hashFree(attributeTable);

Просмотреть файл

@ -0,0 +1,369 @@
/* ***** 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 ***** */
#include "all.h"
#if HAVE_LIBPTHREAD
pthread_cond_t threadCond;
pthread_mutex_t threadMutex;
#endif
#if HAVE_LIBTHREAD
mutex_t threadMutex;
#endif
#if WINDOWS
HANDLE threadCond = NULL;
HANDLE threadMutex = NULL;
#endif
void
threadCancel(Thread thr)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_cancel(thr);
if (ret)
{
fprintf(stderr, "pthread_cancel %d\n", ret);
}
#endif
#if HAVE_LIBTHREAD
thr_kill(thr, SIGKILL);
#endif
#if WINDOWS
BOOL ret;
ret = TerminateThread(thr, 0);
if (!ret)
{
fprintf(stderr, "TerminateThread failed\n");
}
#endif
}
void
threadCondBroadcast(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_cond_broadcast(&threadCond);
if (ret)
{
fprintf(stderr, "pthread_cond_broadcast %d\n", ret);
}
#endif
#if HAVE_LIBTHREAD
thr_cond_broadcast();
#endif
#if WINDOWS
BOOL ret;
ret = SetEvent(threadCond);
if (!ret)
{
fprintf(stderr, "SetEvent failed\n");
}
#endif
}
void
threadCondSignal(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_cond_signal(&threadCond);
if (ret)
{
fprintf(stderr, "pthread_cond_signal %d\n", ret);
}
#endif
#if HAVE_LIBTHREAD
thr_cond_signal();
#endif
#if WINDOWS
BOOL ret;
ret = SetEvent(threadCond);
if (!ret)
{
fprintf(stderr, "SetEvent failed\n");
}
#endif
}
void
threadCondWait(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_cond_wait(&threadCond, &threadMutex);
if (ret)
{
fprintf(stderr, "pthread_cond_wait %d\n", ret);
}
#endif
#if HAVE_LIBTHREAD
thr_cond_wait();
#endif
#if WINDOWS
BOOL ret;
DWORD wait;
ret = ReleaseMutex(threadMutex);
if (!ret)
{
fprintf(stderr, "ReleaseMutex failed\n");
return;
}
wait = WaitForSingleObject(threadCond, INFINITE);
if (wait == WAIT_FAILED)
{
fprintf(stderr, "WaitForSingleObject(cond) failed\n");
}
wait = WaitForSingleObject(threadMutex, INFINITE);
if (wait == WAIT_FAILED)
{
fprintf(stderr, "WaitForSingleObject(mutex) failed\n");
}
#endif
}
int
threadCreate(Thread *thr, void *(*start)(void *), void *arg)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_create(thr, NULL, start, arg);
if (ret)
{
fprintf(stderr, "pthread_create %d\n", ret);
exit(0);
return 1;
}
#endif
#if HAVE_LIBTHREAD
int ret;
ret = thr_create(NULL, 0, start, arg, 0, thr);
if (ret)
{
fprintf(stderr, "thr_create %d\n", ret);
exit(0);
return 1;
}
#endif
#if WINDOWS
*thr = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) start, arg, 0,
NULL);
if (!*thr)
{
fprintf(stderr, "CreateThread failed\n");
exit(0);
return 1;
}
#endif
return 0;
}
int
threadInit(void)
{
#if HAVE_LIBPTHREAD
int ret;
pthread_mutexattr_t attr;
ret = pthread_cond_init(&threadCond, NULL);
if (ret)
{
fprintf(stderr, "pthread_cond_init %d\n", ret);
return 0;
}
pthread_mutexattr_init(&attr);
ret = pthread_mutex_init(&threadMutex, &attr);
if (ret)
{
fprintf(stderr, "pthread_mutex_init %d\n", ret);
return 0;
}
#endif
#if HAVE_LIBTHREAD
int ret;
cond_init();
ret = mutex_init(&threadMutex, USYNC_THREAD, NULL);
if (ret)
{
fprintf(stderr, "mutex_init failed\n");
return 0;
}
#endif
#if WINDOWS
threadCond = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!threadCond)
{
fprintf(stderr, "CreateEvent failed\n");
return 0;
}
threadMutex = CreateMutex(NULL, FALSE, NULL);
if (!threadMutex)
{
fprintf(stderr, "CreateMutex failed\n");
return 0;
}
#endif
return 1;
}
void
threadJoin(Thread thr)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_join(thr, NULL);
if (ret)
{
fprintf(stderr, "pthread_join %d\n", ret);
}
#endif
#if HAVE_LIBTHREAD
int ret;
ret = thr_join();
if (ret)
{
fprintf(stderr, "thr_join failed\n");
}
#endif
#if WINDOWS
DWORD wait;
wait = WaitForSingleObject(thr, INFINITE);
if (wait == WAIT_FAILED)
{
fprintf(stderr, "WaitForSingleObject(thr) failed\n");
}
#endif
}
void
threadMutexLock(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_mutex_lock(&threadMutex);
if (ret)
{
fprintf(stderr, "pthread_mutex_lock failed\n");
}
#endif
#if HAVE_LIBTHREAD
mutex_lock(&threadMutex);
#endif
#if WINDOWS
DWORD wait;
wait = WaitForSingleObject(threadMutex, INFINITE);
if (wait == WAIT_FAILED)
{
fprintf(stderr, "WaitForSingleObject(mutex) failed\n");
}
#endif
}
void
threadMutexUnlock(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = pthread_mutex_unlock(&threadMutex);
if (ret)
{
fprintf(stderr, "pthread_mutex_lock failed\n");
}
#endif
#if HAVE_LIBTHREAD
mutex_unlock(&threadMutex);
#endif
#if WINDOWS
BOOL ret;
ret = ReleaseMutex(threadMutex);
if (!ret)
{
fprintf(stderr, "ReleaseMutex failed\n");
}
#endif
}
void
threadYield(void)
{
#if HAVE_LIBPTHREAD
int ret;
ret = sched_yield();
if (ret)
{
fprintf(stderr, "sched_yield failed\n");
}
#endif
#if HAVE_LIBTHREAD
thr_yield();
#endif
#if WINDOWS
(void) SwitchToThread();
#endif
}

Просмотреть файл

@ -0,0 +1,46 @@
/* ***** 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 ***** */
#if HAVE_LIBPTHREAD
typedef pthread_t Thread;
#endif
#if HAVE_LIBTHREAD
typedef thread_t Thread;
#endif
#if WINDOWS
typedef HANDLE Thread;
#endif
void threadCancel(Thread thr);
void threadCondBroadcast(void);
void threadCondSignal(void);
void threadCondWait(void);
int threadCreate(Thread *thr, void *(*start)(void *), void *arg);
int threadInit(void);
void threadJoin(Thread thr);
void threadMutexLock(void);
void threadMutexUnlock(void);
void threadYield(void);

Просмотреть файл

@ -1,30 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <stdio.h>
#include <string.h>
#include "url.h"
#include "utils.h"
#include "all.h"
typedef struct StackEntry
{
@ -581,7 +579,7 @@ urlDecode(unsigned char *url)
unsigned char c;
unsigned char *in;
unsigned char *out;
int tmp;
unsigned int tmp;
in = url;
out = url;
@ -612,117 +610,3 @@ urlDecode(unsigned char *url)
}
*out++ = 0;
}
#ifdef URL_TEST
static unsigned char *baseURLTest = "http://a/b/c/d;p?q#f";
static char *relativeURLTests[] =
{
"g:h", "g:h",
"g", "http://a/b/c/g",
"./g", "http://a/b/c/g",
"g/", "http://a/b/c/g/",
"/g", "http://a/g",
"//g", "http://g",
"?y", "http://a/b/c/d;p?y",
"g?y", "http://a/b/c/g?y",
"g?y/./x", "http://a/b/c/g?y/./x",
"#s", "http://a/b/c/d;p?q#s",
"g#s", "http://a/b/c/g#s",
"g#s/./x", "http://a/b/c/g#s/./x",
"g?y#s", "http://a/b/c/g?y#s",
";x", "http://a/b/c/d;x",
"g;x", "http://a/b/c/g;x",
"g;x?y#s", "http://a/b/c/g;x?y#s",
".", "http://a/b/c/",
"./", "http://a/b/c/",
"..", "http://a/b/",
"../", "http://a/b/",
"../g", "http://a/b/g",
"../..", "http://a/",
"../../", "http://a/",
"../../g", "http://a/g",
"", "http://a/b/c/d;p?q#f",
"../../../g", "http://a/../g",
"../../../../g", "http://a/../../g",
"/./g", "http://a/./g",
"/../g", "http://a/../g",
"g.", "http://a/b/c/g.",
".g", "http://a/b/c/.g",
"g..", "http://a/b/c/g..",
"..g", "http://a/b/c/..g",
"./../g", "http://a/b/g",
"./g/.", "http://a/b/c/g/",
"g/./h", "http://a/b/c/g/h",
"g/../h", "http://a/b/c/h",
"http:g", "http:g",
"http:", "http:",
NULL
};
static unsigned char *loginTest =
"ftp://user:password@ftp.domain.com:64000/path1/path2/file#fragment";
static void
printURL(URL *url)
{
printf("url %s\n", url->url);
printf("scheme %s, ", url->scheme ? url->scheme : "NULL");
printf("login %s, ", url->login ? url->login : "NULL");
printf("password %s, ", url->password ? url->password : "NULL");
printf("host %s, ", url->host ? url->host : "NULL");
printf("port %d, ", url->port);
printf("path %s, ", url->path ? url->path : "NULL");
printf("file %s, ", url->file ? url->file : "NULL");
printf("fragment %s\n", url->fragment ? url->fragment : "NULL");
printf("======================================\n");
}
int
main(int argc, char *argv[])
{
int failures;
char **p;
int total;
URL *url;
printURL(urlParse(loginTest));
failures = 0;
total = 0;
p = relativeURLTests;
while (p[0])
{
total++;
url = urlRelative(baseURLTest, p[0]);
if (url)
{
if (strcmp((char *) url->url, p[1]))
{
failures++;
printf("urlRelative failed:\n");
printf("\"%s\" +\n", baseURLTest);
printf("\"%s\" =\n", p[0]);
printf("\"%s\"\n", url->url);
printf("should be:\n");
printf("\"%s\"\n", p[1]);
printf("-------------------\n");
}
urlFree(url);
}
else
{
failures++;
printf("urlRelative return NULL for \"%s\"\n", p[0]);
printf("----------------------------------\n");
}
p += 2;
}
printf("%d failures out of %d\n", failures, total);
return 0;
}
#endif /* URL_TEST */

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _URL_H_
#define _URL_H_

Просмотреть файл

@ -0,0 +1,135 @@
/* ***** 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 unsigned char *baseURLTest = (unsigned char *) "http://a/b/c/d;p?q#f";
static char *relativeURLTests[] =
{
"g:h", "g:h",
"g", "http://a/b/c/g",
"./g", "http://a/b/c/g",
"g/", "http://a/b/c/g/",
"/g", "http://a/g",
"//g", "http://g",
"?y", "http://a/b/c/d;p?y",
"g?y", "http://a/b/c/g?y",
"g?y/./x", "http://a/b/c/g?y/./x",
"#s", "http://a/b/c/d;p?q#s",
"g#s", "http://a/b/c/g#s",
"g#s/./x", "http://a/b/c/g#s/./x",
"g?y#s", "http://a/b/c/g?y#s",
";x", "http://a/b/c/d;x",
"g;x", "http://a/b/c/g;x",
"g;x?y#s", "http://a/b/c/g;x?y#s",
".", "http://a/b/c/",
"./", "http://a/b/c/",
"..", "http://a/b/",
"../", "http://a/b/",
"../g", "http://a/b/g",
"../..", "http://a/",
"../../", "http://a/",
"../../g", "http://a/g",
"", "http://a/b/c/d;p?q#f",
"../../../g", "http://a/../g",
"../../../../g", "http://a/../../g",
"/./g", "http://a/./g",
"/../g", "http://a/../g",
"g.", "http://a/b/c/g.",
".g", "http://a/b/c/.g",
"g..", "http://a/b/c/g..",
"..g", "http://a/b/c/..g",
"./../g", "http://a/b/g",
"./g/.", "http://a/b/c/g/",
"g/./h", "http://a/b/c/g/h",
"g/../h", "http://a/b/c/h",
"http:g", "http:g",
"http:", "http:",
NULL
};
static unsigned char *loginTest = (unsigned char *)
"ftp://user:password@ftp.domain.com:64000/path1/path2/file#fragment";
static void
printURL(URL *url)
{
printf("url %s\n", url->url);
printf("scheme %s, ", url->scheme ? (char *) url->scheme : "NULL");
printf("login %s, ", url->login ? (char *) url->login : "NULL");
printf("password %s, ", url->password ? (char *)url->password : "NULL");
printf("host %s, ", url->host ? (char *) url->host : "NULL");
printf("port %d, ", url->port);
printf("path %s, ", url->path ? (char *) url->path : "NULL");
printf("file %s, ", url->file ? (char *) url->file : "NULL");
printf("fragment %s\n", url->fragment ? (char *)url->fragment : "NULL");
printf("======================================\n");
}
int
main(int argc, char *argv[])
{
int failures;
char **p;
int total;
URL *url;
printURL(urlParse(loginTest));
failures = 0;
total = 0;
p = relativeURLTests;
while (p[0])
{
total++;
url = urlRelative(baseURLTest, (unsigned char *) p[0]);
if (url)
{
if (strcmp((char *) url->url, p[1]))
{
failures++;
printf("urlRelative failed:\n");
printf("\"%s\" +\n", baseURLTest);
printf("\"%s\" =\n", p[0]);
printf("\"%s\"\n", url->url);
printf("should be:\n");
printf("\"%s\"\n", p[1]);
printf("-------------------\n");
}
urlFree(url);
}
else
{
failures++;
printf("urlRelative return NULL for \"%s\"\n", p[0]);
printf("----------------------------------\n");
}
p += 2;
}
printf("%d failures out of %d\n", failures, total);
return 0;
}

Просмотреть файл

@ -1,29 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <stdio.h>
#include <string.h>
#include "utils.h"
#include "all.h"
unsigned char *
appendString(const unsigned char *str1, const unsigned char *str2)
@ -127,3 +126,21 @@ utilRealloc(void *ptr, size_t oldSize, size_t newSize)
return (void *) ret;
}
#if WINDOWS
int
strcasecmp(const char *s1, const char *s2)
{
return stricmp(s1, s2);
}
int
gettimeofday(void)
{
/* XXX */
return 0;
}
#endif

Просмотреть файл

@ -1,23 +1,26 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _UTILS_H_
#define _UTILS_H_

Просмотреть файл

@ -1,32 +1,28 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 <malloc.h>
#include <stdio.h>
#include <string.h>
#include "http.h"
#include "html.h"
#include "io.h"
#include "view.h"
#include "all.h"
#define CONTROL_START "<font color=#FF0000>"
#define CONTROL(str) CONTROL_START str CONTROL_END

Просмотреть файл

@ -1,28 +1,31 @@
/*
* 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 Web Sniffer.
*
* The Initial Developer of the Original Code is Erik van der Poel.
* Portions created by Erik van der Poel are
* Copyright (C) 1998,1999,2000 Erik van der Poel.
* All Rights Reserved.
*
* Contributor(s):
*/
/* ***** 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 ***** */
#ifndef _VIEW_H_
#define _VIEW_H_
#include <stdio.h>
#include "io.h"
typedef struct View
{