mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-11 12:07:06 +00:00
add curl 7.16.0 to in tree libs
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3744 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
a97672afa9
commit
5626cdd351
896 files changed
+211049
-3
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
# are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the COPYING file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.18 2006-08-07 18:06:38 yangtse Exp $
|
||||
###########################################################################
|
||||
|
||||
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib
|
||||
|
||||
noinst_PROGRAMS = sws getpart sockfilt resolve tftpd
|
||||
|
||||
useful = getpart.c getpart.h $(top_srcdir)/lib/strequal.c \
|
||||
$(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c \
|
||||
$(top_srcdir)/lib/memdebug.c $(top_srcdir)/lib/timeval.c
|
||||
|
||||
resolve_SOURCES= resolve.c util.c util.h $(useful)
|
||||
sws_SOURCES= sws.c util.c util.h $(useful)
|
||||
sockfilt_SOURCES = sockfilt.c util.c util.h $(useful) \
|
||||
$(top_srcdir)/lib/inet_pton.c
|
||||
getpart_SOURCES= testpart.c $(useful)
|
||||
tftpd_SOURCES = tftpd.c util.c util.h $(useful) tftp.h
|
||||
|
||||
extra_DIST = base64.pl
|
||||
|
||||
@@ -0,0 +1,639 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
# are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the COPYING file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.18 2006-08-07 18:06:38 yangtse Exp $
|
||||
###########################################################################
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
noinst_PROGRAMS = sws$(EXEEXT) getpart$(EXEEXT) sockfilt$(EXEEXT) \
|
||||
resolve$(EXEEXT) tftpd$(EXEEXT)
|
||||
subdir = tests/server
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = $(top_builddir)/lib/config.h \
|
||||
$(top_builddir)/src/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(noinst_PROGRAMS)
|
||||
am__objects_1 = getpart.$(OBJEXT) strequal.$(OBJEXT) base64.$(OBJEXT) \
|
||||
mprintf.$(OBJEXT) memdebug.$(OBJEXT) timeval.$(OBJEXT)
|
||||
am_getpart_OBJECTS = testpart.$(OBJEXT) $(am__objects_1)
|
||||
getpart_OBJECTS = $(am_getpart_OBJECTS)
|
||||
getpart_LDADD = $(LDADD)
|
||||
am_resolve_OBJECTS = resolve.$(OBJEXT) util.$(OBJEXT) $(am__objects_1)
|
||||
resolve_OBJECTS = $(am_resolve_OBJECTS)
|
||||
resolve_LDADD = $(LDADD)
|
||||
am_sockfilt_OBJECTS = sockfilt.$(OBJEXT) util.$(OBJEXT) \
|
||||
$(am__objects_1) inet_pton.$(OBJEXT)
|
||||
sockfilt_OBJECTS = $(am_sockfilt_OBJECTS)
|
||||
sockfilt_LDADD = $(LDADD)
|
||||
am_sws_OBJECTS = sws.$(OBJEXT) util.$(OBJEXT) $(am__objects_1)
|
||||
sws_OBJECTS = $(am_sws_OBJECTS)
|
||||
sws_LDADD = $(LDADD)
|
||||
am_tftpd_OBJECTS = tftpd.$(OBJEXT) util.$(OBJEXT) $(am__objects_1)
|
||||
tftpd_OBJECTS = $(am_tftpd_OBJECTS)
|
||||
tftpd_LDADD = $(LDADD)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/lib -I$(top_builddir)/src
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(getpart_SOURCES) $(resolve_SOURCES) $(sockfilt_SOURCES) \
|
||||
$(sws_SOURCES) $(tftpd_SOURCES)
|
||||
DIST_SOURCES = $(getpart_SOURCES) $(resolve_SOURCES) \
|
||||
$(sockfilt_SOURCES) $(sws_SOURCES) $(tftpd_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AS = @AS@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CABUNDLE_FALSE = @CABUNDLE_FALSE@
|
||||
CABUNDLE_TRUE = @CABUNDLE_TRUE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CROSSCOMPILING_FALSE = @CROSSCOMPILING_FALSE@
|
||||
CROSSCOMPILING_TRUE = @CROSSCOMPILING_TRUE@
|
||||
CURL_CA_BUNDLE = @CURL_CA_BUNDLE@
|
||||
CURL_DISABLE_COOKIES = @CURL_DISABLE_COOKIES@
|
||||
CURL_DISABLE_CRYPTO_AUTH = @CURL_DISABLE_CRYPTO_AUTH@
|
||||
CURL_DISABLE_DICT = @CURL_DISABLE_DICT@
|
||||
CURL_DISABLE_FILE = @CURL_DISABLE_FILE@
|
||||
CURL_DISABLE_FTP = @CURL_DISABLE_FTP@
|
||||
CURL_DISABLE_HTTP = @CURL_DISABLE_HTTP@
|
||||
CURL_DISABLE_LDAP = @CURL_DISABLE_LDAP@
|
||||
CURL_DISABLE_TELNET = @CURL_DISABLE_TELNET@
|
||||
CURL_DISABLE_TFTP = @CURL_DISABLE_TFTP@
|
||||
CURL_DISABLE_VERBOSE_STRINGS = @CURL_DISABLE_VERBOSE_STRINGS@
|
||||
CURL_EXTERN_SYMBOL = @CURL_EXTERN_SYMBOL@
|
||||
CURL_HIDDEN_SYMBOLS = @CURL_HIDDEN_SYMBOLS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
GREP = @GREP@
|
||||
HAVE_ARES = @HAVE_ARES@
|
||||
HAVE_LIBZ = @HAVE_LIBZ@
|
||||
HAVE_LIBZ_FALSE = @HAVE_LIBZ_FALSE@
|
||||
HAVE_LIBZ_TRUE = @HAVE_LIBZ_TRUE@
|
||||
IDN_ENABLED = @IDN_ENABLED@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
IPV6_ENABLED = @IPV6_ENABLED@
|
||||
KRB4_ENABLED = @KRB4_ENABLED@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
|
||||
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANOPT = @MANOPT@
|
||||
MIMPURE_FALSE = @MIMPURE_FALSE@
|
||||
MIMPURE_TRUE = @MIMPURE_TRUE@
|
||||
NO_UNDEFINED_FALSE = @NO_UNDEFINED_FALSE@
|
||||
NO_UNDEFINED_TRUE = @NO_UNDEFINED_TRUE@
|
||||
NROFF = @NROFF@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PERL = @PERL@
|
||||
PKGADD_NAME = @PKGADD_NAME@
|
||||
PKGADD_PKG = @PKGADD_PKG@
|
||||
PKGADD_VENDOR = @PKGADD_VENDOR@
|
||||
PKGCONFIG = @PKGCONFIG@
|
||||
RANDOM_FILE = @RANDOM_FILE@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
USE_GNUTLS = @USE_GNUTLS@
|
||||
USE_MANUAL_FALSE = @USE_MANUAL_FALSE@
|
||||
USE_MANUAL_TRUE = @USE_MANUAL_TRUE@
|
||||
USE_SSLEAY = @USE_SSLEAY@
|
||||
USE_WINDOWS_SSPI = @USE_WINDOWS_SSPI@
|
||||
VERSION = @VERSION@
|
||||
VERSIONNUM = @VERSIONNUM@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
subdirs = @subdirs@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
INCLUDES = -I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib
|
||||
|
||||
useful = getpart.c getpart.h $(top_srcdir)/lib/strequal.c \
|
||||
$(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c \
|
||||
$(top_srcdir)/lib/memdebug.c $(top_srcdir)/lib/timeval.c
|
||||
|
||||
resolve_SOURCES = resolve.c util.c util.h $(useful)
|
||||
sws_SOURCES = sws.c util.c util.h $(useful)
|
||||
sockfilt_SOURCES = sockfilt.c util.c util.h $(useful) \
|
||||
$(top_srcdir)/lib/inet_pton.c
|
||||
|
||||
getpart_SOURCES = testpart.c $(useful)
|
||||
tftpd_SOURCES = tftpd.c util.c util.h $(useful) tftp.h
|
||||
extra_DIST = base64.pl
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/server/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign tests/server/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
clean-noinstPROGRAMS:
|
||||
@list='$(noinst_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
echo " rm -f $$p $$f"; \
|
||||
rm -f $$p $$f ; \
|
||||
done
|
||||
getpart$(EXEEXT): $(getpart_OBJECTS) $(getpart_DEPENDENCIES)
|
||||
@rm -f getpart$(EXEEXT)
|
||||
$(LINK) $(getpart_LDFLAGS) $(getpart_OBJECTS) $(getpart_LDADD) $(LIBS)
|
||||
resolve$(EXEEXT): $(resolve_OBJECTS) $(resolve_DEPENDENCIES)
|
||||
@rm -f resolve$(EXEEXT)
|
||||
$(LINK) $(resolve_LDFLAGS) $(resolve_OBJECTS) $(resolve_LDADD) $(LIBS)
|
||||
sockfilt$(EXEEXT): $(sockfilt_OBJECTS) $(sockfilt_DEPENDENCIES)
|
||||
@rm -f sockfilt$(EXEEXT)
|
||||
$(LINK) $(sockfilt_LDFLAGS) $(sockfilt_OBJECTS) $(sockfilt_LDADD) $(LIBS)
|
||||
sws$(EXEEXT): $(sws_OBJECTS) $(sws_DEPENDENCIES)
|
||||
@rm -f sws$(EXEEXT)
|
||||
$(LINK) $(sws_LDFLAGS) $(sws_OBJECTS) $(sws_LDADD) $(LIBS)
|
||||
tftpd$(EXEEXT): $(tftpd_OBJECTS) $(tftpd_DEPENDENCIES)
|
||||
@rm -f tftpd$(EXEEXT)
|
||||
$(LINK) $(tftpd_LDFLAGS) $(tftpd_OBJECTS) $(tftpd_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base64.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getpart.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_pton.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memdebug.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprintf.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resolve.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockfilt.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strequal.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sws.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testpart.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tftpd.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timeval.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
strequal.o: $(top_srcdir)/lib/strequal.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strequal.o -MD -MP -MF "$(DEPDIR)/strequal.Tpo" -c -o strequal.o `test -f '$(top_srcdir)/lib/strequal.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/strequal.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/strequal.Tpo" "$(DEPDIR)/strequal.Po"; else rm -f "$(DEPDIR)/strequal.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/strequal.c' object='strequal.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o strequal.o `test -f '$(top_srcdir)/lib/strequal.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/strequal.c
|
||||
|
||||
strequal.obj: $(top_srcdir)/lib/strequal.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strequal.obj -MD -MP -MF "$(DEPDIR)/strequal.Tpo" -c -o strequal.obj `if test -f '$(top_srcdir)/lib/strequal.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/strequal.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/strequal.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/strequal.Tpo" "$(DEPDIR)/strequal.Po"; else rm -f "$(DEPDIR)/strequal.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/strequal.c' object='strequal.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o strequal.obj `if test -f '$(top_srcdir)/lib/strequal.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/strequal.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/strequal.c'; fi`
|
||||
|
||||
base64.o: $(top_srcdir)/lib/base64.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT base64.o -MD -MP -MF "$(DEPDIR)/base64.Tpo" -c -o base64.o `test -f '$(top_srcdir)/lib/base64.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/base64.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/base64.Tpo" "$(DEPDIR)/base64.Po"; else rm -f "$(DEPDIR)/base64.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/base64.c' object='base64.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o base64.o `test -f '$(top_srcdir)/lib/base64.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/base64.c
|
||||
|
||||
base64.obj: $(top_srcdir)/lib/base64.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT base64.obj -MD -MP -MF "$(DEPDIR)/base64.Tpo" -c -o base64.obj `if test -f '$(top_srcdir)/lib/base64.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/base64.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/base64.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/base64.Tpo" "$(DEPDIR)/base64.Po"; else rm -f "$(DEPDIR)/base64.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/base64.c' object='base64.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o base64.obj `if test -f '$(top_srcdir)/lib/base64.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/base64.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/base64.c'; fi`
|
||||
|
||||
mprintf.o: $(top_srcdir)/lib/mprintf.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mprintf.o -MD -MP -MF "$(DEPDIR)/mprintf.Tpo" -c -o mprintf.o `test -f '$(top_srcdir)/lib/mprintf.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/mprintf.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mprintf.Tpo" "$(DEPDIR)/mprintf.Po"; else rm -f "$(DEPDIR)/mprintf.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/mprintf.c' object='mprintf.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mprintf.o `test -f '$(top_srcdir)/lib/mprintf.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/mprintf.c
|
||||
|
||||
mprintf.obj: $(top_srcdir)/lib/mprintf.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mprintf.obj -MD -MP -MF "$(DEPDIR)/mprintf.Tpo" -c -o mprintf.obj `if test -f '$(top_srcdir)/lib/mprintf.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/mprintf.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/mprintf.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mprintf.Tpo" "$(DEPDIR)/mprintf.Po"; else rm -f "$(DEPDIR)/mprintf.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/mprintf.c' object='mprintf.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mprintf.obj `if test -f '$(top_srcdir)/lib/mprintf.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/mprintf.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/mprintf.c'; fi`
|
||||
|
||||
memdebug.o: $(top_srcdir)/lib/memdebug.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT memdebug.o -MD -MP -MF "$(DEPDIR)/memdebug.Tpo" -c -o memdebug.o `test -f '$(top_srcdir)/lib/memdebug.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/memdebug.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/memdebug.Tpo" "$(DEPDIR)/memdebug.Po"; else rm -f "$(DEPDIR)/memdebug.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/memdebug.c' object='memdebug.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memdebug.o `test -f '$(top_srcdir)/lib/memdebug.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/memdebug.c
|
||||
|
||||
memdebug.obj: $(top_srcdir)/lib/memdebug.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT memdebug.obj -MD -MP -MF "$(DEPDIR)/memdebug.Tpo" -c -o memdebug.obj `if test -f '$(top_srcdir)/lib/memdebug.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/memdebug.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/memdebug.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/memdebug.Tpo" "$(DEPDIR)/memdebug.Po"; else rm -f "$(DEPDIR)/memdebug.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/memdebug.c' object='memdebug.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memdebug.obj `if test -f '$(top_srcdir)/lib/memdebug.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/memdebug.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/memdebug.c'; fi`
|
||||
|
||||
timeval.o: $(top_srcdir)/lib/timeval.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT timeval.o -MD -MP -MF "$(DEPDIR)/timeval.Tpo" -c -o timeval.o `test -f '$(top_srcdir)/lib/timeval.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/timeval.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/timeval.Tpo" "$(DEPDIR)/timeval.Po"; else rm -f "$(DEPDIR)/timeval.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/timeval.c' object='timeval.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o timeval.o `test -f '$(top_srcdir)/lib/timeval.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/timeval.c
|
||||
|
||||
timeval.obj: $(top_srcdir)/lib/timeval.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT timeval.obj -MD -MP -MF "$(DEPDIR)/timeval.Tpo" -c -o timeval.obj `if test -f '$(top_srcdir)/lib/timeval.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/timeval.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/timeval.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/timeval.Tpo" "$(DEPDIR)/timeval.Po"; else rm -f "$(DEPDIR)/timeval.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/timeval.c' object='timeval.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o timeval.obj `if test -f '$(top_srcdir)/lib/timeval.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/timeval.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/timeval.c'; fi`
|
||||
|
||||
inet_pton.o: $(top_srcdir)/lib/inet_pton.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.o -MD -MP -MF "$(DEPDIR)/inet_pton.Tpo" -c -o inet_pton.o `test -f '$(top_srcdir)/lib/inet_pton.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/inet_pton.c; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_pton.Tpo" "$(DEPDIR)/inet_pton.Po"; else rm -f "$(DEPDIR)/inet_pton.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/inet_pton.c' object='inet_pton.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_pton.o `test -f '$(top_srcdir)/lib/inet_pton.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/inet_pton.c
|
||||
|
||||
inet_pton.obj: $(top_srcdir)/lib/inet_pton.c
|
||||
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.obj -MD -MP -MF "$(DEPDIR)/inet_pton.Tpo" -c -o inet_pton.obj `if test -f '$(top_srcdir)/lib/inet_pton.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/inet_pton.c'; fi`; \
|
||||
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_pton.Tpo" "$(DEPDIR)/inet_pton.Po"; else rm -f "$(DEPDIR)/inet_pton.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/inet_pton.c' object='inet_pton.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_pton.obj `if test -f '$(top_srcdir)/lib/inet_pton.c'; then $(CYGPATH_W) '$(top_srcdir)/lib/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/lib/inet_pton.c'; fi`
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
|
||||
list='$(DISTFILES)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(PROGRAMS)
|
||||
installdirs:
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-info-am
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libtool clean-noinstPROGRAMS ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am install-exec \
|
||||
install-exec-am install-info install-info-am install-man \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am \
|
||||
uninstall-info-am
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
@@ -0,0 +1,221 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: getpart.c,v 1.20 2006-10-27 03:47:58 yangtse Exp $
|
||||
***************************************************************************/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "getpart.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#define EAT_SPACE(ptr) while( ptr && *ptr && ISSPACE(*ptr) ) ptr++
|
||||
#define EAT_WORD(ptr) while( ptr && *ptr && !ISSPACE(*ptr) && \
|
||||
('>' != *ptr)) ptr++
|
||||
|
||||
#ifdef DEBUG
|
||||
#define show(x) printf x
|
||||
#else
|
||||
#define show(x)
|
||||
#endif
|
||||
|
||||
curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
|
||||
curl_free_callback Curl_cfree = (curl_free_callback)free;
|
||||
curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
|
||||
curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
|
||||
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
|
||||
|
||||
static
|
||||
char *appendstring(char *string, /* original string */
|
||||
char *buffer, /* to append */
|
||||
size_t *stringlen, /* length of string */
|
||||
size_t *stralloc, /* allocated size */
|
||||
char base64) /* 1 if base64 encoded */
|
||||
{
|
||||
size_t len = strlen(buffer);
|
||||
size_t needed_len = len + *stringlen + 1;
|
||||
char *buf64=NULL;
|
||||
|
||||
if(base64) {
|
||||
/* decode the given buffer first */
|
||||
len = Curl_base64_decode(buffer, (unsigned char**)&buf64); /* updated len */
|
||||
buffer = buf64;
|
||||
needed_len = len + *stringlen + 1; /* recalculate */
|
||||
}
|
||||
|
||||
if(needed_len >= *stralloc) {
|
||||
char *newptr;
|
||||
size_t newsize = needed_len*2; /* get twice the needed size */
|
||||
|
||||
newptr = realloc(string, newsize);
|
||||
if(newptr) {
|
||||
string = newptr;
|
||||
*stralloc = newsize;
|
||||
}
|
||||
else {
|
||||
if(buf64)
|
||||
free(buf64);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* memcpy to support binary blobs */
|
||||
memcpy(&string[*stringlen], buffer, len);
|
||||
*stringlen += len;
|
||||
string[*stringlen]=0;
|
||||
|
||||
if(buf64)
|
||||
free(buf64);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
const char *spitout(FILE *stream,
|
||||
const char *main,
|
||||
const char *sub, size_t *size)
|
||||
{
|
||||
char buffer[8192]; /* big enough for anything */
|
||||
char cmain[128]=""; /* current main section */
|
||||
char csub[128]=""; /* current sub section */
|
||||
char *ptr;
|
||||
char *end;
|
||||
char display = 0;
|
||||
|
||||
char *string;
|
||||
size_t stringlen=0;
|
||||
size_t stralloc=256;
|
||||
char base64 = 0; /* set to 1 if true */
|
||||
|
||||
enum {
|
||||
STATE_OUTSIDE,
|
||||
STATE_INMAIN,
|
||||
STATE_INSUB,
|
||||
STATE_ILLEGAL
|
||||
} state = STATE_OUTSIDE;
|
||||
|
||||
string = (char *)malloc(stralloc);
|
||||
if(!string)
|
||||
return NULL;
|
||||
|
||||
string[0] = 0; /* zero first byte in case of no data */
|
||||
|
||||
while(fgets(buffer, sizeof(buffer), stream)) {
|
||||
|
||||
ptr = buffer;
|
||||
|
||||
/* pass white spaces */
|
||||
EAT_SPACE(ptr);
|
||||
|
||||
if('<' != *ptr) {
|
||||
if(display) {
|
||||
show(("=> %s", buffer));
|
||||
string = appendstring(string, buffer, &stringlen, &stralloc, base64);
|
||||
show(("* %s\n", buffer));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
EAT_SPACE(ptr);
|
||||
|
||||
if('/' == *ptr) {
|
||||
/* end of a section */
|
||||
ptr++;
|
||||
EAT_SPACE(ptr);
|
||||
|
||||
end = ptr;
|
||||
EAT_WORD(end);
|
||||
*end = 0;
|
||||
|
||||
if((state == STATE_INSUB) &&
|
||||
!strcmp(csub, ptr)) {
|
||||
/* this is the end of the currently read sub section */
|
||||
state--;
|
||||
csub[0]=0; /* no sub anymore */
|
||||
display=0;
|
||||
}
|
||||
else if((state == STATE_INMAIN) &&
|
||||
!strcmp(cmain, ptr)) {
|
||||
/* this is the end of the currently read main section */
|
||||
state--;
|
||||
cmain[0]=0; /* no main anymore */
|
||||
display=0;
|
||||
}
|
||||
}
|
||||
else if(!display) {
|
||||
/* this is the beginning of a section */
|
||||
end = ptr;
|
||||
EAT_WORD(end);
|
||||
|
||||
*end = 0;
|
||||
switch(state) {
|
||||
case STATE_OUTSIDE:
|
||||
strcpy(cmain, ptr);
|
||||
state = STATE_INMAIN;
|
||||
break;
|
||||
case STATE_INMAIN:
|
||||
strcpy(csub, ptr);
|
||||
state = STATE_INSUB;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(!end[1] != '>') {
|
||||
/* There might be attributes here. Check for those we know of and care
|
||||
about. */
|
||||
if(strstr(&end[1], "base64=")) {
|
||||
/* rought and dirty, but "mostly" functional */
|
||||
/* Treat all data as base64 encoded */
|
||||
base64 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(display) {
|
||||
string = appendstring(string, buffer, &stringlen, &stralloc, base64);
|
||||
show(("* %s\n", buffer));
|
||||
}
|
||||
|
||||
if((STATE_INSUB == state) &&
|
||||
!strcmp(cmain, main) &&
|
||||
!strcmp(csub, sub)) {
|
||||
show(("* (%d bytes) %s\n", stringlen, buffer));
|
||||
display = 1; /* start displaying */
|
||||
}
|
||||
else {
|
||||
show(("%d (%s/%s): %s\n", state, cmain, csub, buffer));
|
||||
display = 0; /* no display */
|
||||
}
|
||||
}
|
||||
|
||||
*size = stringlen;
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: getpart.h,v 1.3 2004/11/29 12:10:09 bagder Exp $
|
||||
***************************************************************************/
|
||||
const char *
|
||||
spitout(FILE *stream,
|
||||
const char *main,
|
||||
const char *sub,
|
||||
size_t *size);
|
||||
@@ -0,0 +1,149 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: resolve.c,v 1.7 2006-10-11 16:01:20 yangtse Exp $
|
||||
***************************************************************************/
|
||||
|
||||
/* Purpose
|
||||
*
|
||||
* Resolve the given name, using system name resolve functions (NOT any
|
||||
* function provided by libcurl). Used to see if the name exists and thus if
|
||||
* we can allow a test case to use it for testing.
|
||||
*
|
||||
* Like if 'localhost' actual exists etc.
|
||||
*
|
||||
*/
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* make the curlx header define all printf() functions to use the curlx_*
|
||||
versions instead */
|
||||
#include "curlx.h" /* from the private lib dir */
|
||||
#include "util.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
char use_ipv6=FALSE;
|
||||
|
||||
const char *serverlogfile=""; /* for a util.c function we don't use */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int arg=1;
|
||||
char *host;
|
||||
int rc;
|
||||
|
||||
while(argc>arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("resolve IPv4%s\n",
|
||||
#ifdef ENABLE_IPV6
|
||||
"/IPv6"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp("--ipv6", argv[arg])) {
|
||||
#ifdef ENABLE_IPV6
|
||||
use_ipv6=TRUE;
|
||||
#endif
|
||||
arg++;
|
||||
}
|
||||
else if(!strcmp("--ipv4", argv[arg])) {
|
||||
/* for completeness, we support this option as well */
|
||||
use_ipv6=FALSE;
|
||||
arg++;
|
||||
}
|
||||
else {
|
||||
host = argv[arg++];
|
||||
}
|
||||
}
|
||||
if(!host) {
|
||||
puts("Usage: resolve [option] <host>\n"
|
||||
" --version\n"
|
||||
" --ipv4\n"
|
||||
" --ipv6");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6)
|
||||
#endif
|
||||
{
|
||||
/* gethostbyname() resolve */
|
||||
struct hostent *he;
|
||||
|
||||
he = gethostbyname(host);
|
||||
|
||||
rc = !he;
|
||||
}
|
||||
#ifdef ENABLE_IPV6
|
||||
else {
|
||||
/* getaddrinfo() resolve */
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_INET6;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
rc = (getaddrinfo)(host, "80", &hints, &ai);
|
||||
|
||||
}
|
||||
#endif
|
||||
if(rc)
|
||||
printf("Resolving '%s' didn't work\n", host);
|
||||
|
||||
return !rc?0:1;
|
||||
}
|
||||
@@ -0,0 +1,645 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: sockfilt.c,v 1.26 2006-10-27 03:47:58 yangtse Exp $
|
||||
***************************************************************************/
|
||||
|
||||
/* Purpose
|
||||
*
|
||||
* 1. Accept a TCP connection on a custom port (ipv4 or ipv6), or connect
|
||||
* to a given (localhost) port.
|
||||
*
|
||||
* 2. Get commands on STDIN. Pass data on to the TCP stream.
|
||||
* Get data from TCP stream and pass on to STDOUT.
|
||||
*
|
||||
* This program is made to perform all the socket/stream/connection stuff for
|
||||
* the test suite's (perl) FTP server. Previously the perl code did all of
|
||||
* this by its own, but I decided to let this program do the socket layer
|
||||
* because of several things:
|
||||
*
|
||||
* o We want the perl code to work with rather old perl installations, thus
|
||||
* we cannot use recent perl modules or features.
|
||||
*
|
||||
* o We want IPv6 support for systems that provide it, and doing optional IPv6
|
||||
* support in perl seems if not impossible so at least awkward.
|
||||
*
|
||||
* o We want FTP-SSL support, which means that a connection that starts with
|
||||
* plain sockets needs to be able to "go SSL" in the midst. This would also
|
||||
* require some nasty perl stuff I'd rather avoid.
|
||||
*
|
||||
* (Source originally based on sws.c)
|
||||
*/
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* make the curlx header define all printf() functions to use the curlx_*
|
||||
versions instead */
|
||||
#include "curlx.h" /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
#include "inet_pton.h"
|
||||
#include "util.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/sockfilt.log"
|
||||
#endif
|
||||
|
||||
#ifdef SIGPIPE
|
||||
static volatile int sigpipe; /* Why? It's not used */
|
||||
#endif
|
||||
|
||||
const char *serverlogfile = (char *)DEFAULT_LOGFILE;
|
||||
|
||||
static void lograw(unsigned char *buffer, ssize_t len)
|
||||
{
|
||||
char data[120];
|
||||
ssize_t i;
|
||||
unsigned char *ptr = buffer;
|
||||
char *optr = data;
|
||||
ssize_t width=0;
|
||||
|
||||
for(i=0; i<len; i++) {
|
||||
switch(ptr[i]) {
|
||||
case '\n':
|
||||
sprintf(optr, "\\n");
|
||||
width += 2;
|
||||
optr += 2;
|
||||
break;
|
||||
case '\r':
|
||||
sprintf(optr, "\\r");
|
||||
width += 2;
|
||||
optr += 2;
|
||||
break;
|
||||
default:
|
||||
sprintf(optr, "%c", (ISGRAPH(ptr[i]) || ptr[i]==0x20) ?ptr[i]:'.');
|
||||
width++;
|
||||
optr++;
|
||||
break;
|
||||
}
|
||||
|
||||
if(width>60) {
|
||||
logmsg("'%s'", data);
|
||||
width = 0;
|
||||
optr = data;
|
||||
}
|
||||
}
|
||||
if(width)
|
||||
logmsg("'%s'", data);
|
||||
}
|
||||
|
||||
#ifdef SIGPIPE
|
||||
static void sigpipe_handler(int sig)
|
||||
{
|
||||
(void)sig; /* prevent warning */
|
||||
sigpipe = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
char use_ipv6=FALSE;
|
||||
unsigned short port = DEFAULT_PORT;
|
||||
unsigned short connectport = 0; /* if non-zero, we activate this mode */
|
||||
|
||||
enum sockmode {
|
||||
PASSIVE_LISTEN, /* as a server waiting for connections */
|
||||
PASSIVE_CONNECT, /* as a server, connected to a client */
|
||||
ACTIVE, /* as a client, connected to a server */
|
||||
ACTIVE_DISCONNECT /* as a client, disconnected from server */
|
||||
};
|
||||
|
||||
/*
|
||||
sockfdp is a pointer to an established stream or CURL_SOCKET_BAD
|
||||
|
||||
if sockfd is CURL_SOCKET_BAD, listendfd is a listening socket we must
|
||||
accept()
|
||||
*/
|
||||
static int juggle(curl_socket_t *sockfdp,
|
||||
curl_socket_t listenfd,
|
||||
enum sockmode *mode)
|
||||
{
|
||||
struct timeval timeout;
|
||||
fd_set fds_read;
|
||||
fd_set fds_write;
|
||||
fd_set fds_err;
|
||||
curl_socket_t sockfd;
|
||||
curl_socket_t maxfd;
|
||||
ssize_t rc;
|
||||
ssize_t nread_stdin;
|
||||
ssize_t nread_socket;
|
||||
ssize_t bytes_written;
|
||||
ssize_t buffer_len;
|
||||
unsigned char buffer[256]; /* FIX: bigger buffer */
|
||||
char data[256];
|
||||
|
||||
timeout.tv_sec = 120;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fds_read);
|
||||
FD_ZERO(&fds_write);
|
||||
FD_ZERO(&fds_err);
|
||||
|
||||
FD_SET(fileno(stdin), &fds_read);
|
||||
|
||||
switch(*mode) {
|
||||
|
||||
case PASSIVE_LISTEN:
|
||||
|
||||
/* server mode */
|
||||
sockfd = listenfd;
|
||||
/* there's always a socket to wait for */
|
||||
FD_SET(sockfd, &fds_read);
|
||||
maxfd = sockfd;
|
||||
break;
|
||||
|
||||
case PASSIVE_CONNECT:
|
||||
|
||||
sockfd = *sockfdp;
|
||||
if(CURL_SOCKET_BAD == sockfd) {
|
||||
/* eeek, we are supposedly connected and then this cannot be -1 ! */
|
||||
logmsg("socket is -1! on %s:%d", __FILE__, __LINE__);
|
||||
maxfd = 0; /* stdin */
|
||||
}
|
||||
else {
|
||||
/* there's always a socket to wait for */
|
||||
FD_SET(sockfd, &fds_read);
|
||||
maxfd = sockfd;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
|
||||
sockfd = *sockfdp;
|
||||
/* sockfd turns CURL_SOCKET_BAD when our connection has been closed */
|
||||
if(CURL_SOCKET_BAD != sockfd) {
|
||||
FD_SET(sockfd, &fds_read);
|
||||
maxfd = sockfd;
|
||||
}
|
||||
else {
|
||||
logmsg("No socket to read on");
|
||||
maxfd = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACTIVE_DISCONNECT:
|
||||
|
||||
logmsg("disconnected, no socket to read on");
|
||||
maxfd = 0;
|
||||
sockfd = CURL_SOCKET_BAD;
|
||||
break;
|
||||
|
||||
} /* switch(*mode) */
|
||||
|
||||
do {
|
||||
rc = select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
|
||||
} while((rc == -1) && (our_sockerrno() == EINTR));
|
||||
|
||||
switch(rc) {
|
||||
case -1:
|
||||
return FALSE;
|
||||
|
||||
case 0: /* timeout! */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
if(FD_ISSET(fileno(stdin), &fds_read)) {
|
||||
/* read from stdin, commands/data to be dealt with and possibly passed on
|
||||
to the socket
|
||||
|
||||
protocol:
|
||||
|
||||
4 letter command + LF [mandatory]
|
||||
|
||||
4-digit hexadecimal data length + LF [if the command takes data]
|
||||
data [the data being as long as set above]
|
||||
|
||||
Commands:
|
||||
|
||||
DATA - plain pass-thru data
|
||||
*/
|
||||
nread_stdin = read(fileno(stdin), buffer, 5);
|
||||
if(5 == nread_stdin) {
|
||||
|
||||
logmsg("Received %c%c%c%c (on stdin)",
|
||||
buffer[0], buffer[1], buffer[2], buffer[3] );
|
||||
|
||||
if(!memcmp("PING", buffer, 4)) {
|
||||
/* send reply on stdout, just proving we are alive */
|
||||
write(fileno(stdout), "PONG\n", 5);
|
||||
}
|
||||
|
||||
else if(!memcmp("PORT", buffer, 4)) {
|
||||
/* Question asking us what PORT number we are listening to.
|
||||
Replies to PORT with "IPv[num]/[port]" */
|
||||
sprintf((char *)buffer, "IPv%d/%d\n", use_ipv6?6:4, (int)port);
|
||||
buffer_len = (ssize_t)strlen((char *)buffer);
|
||||
sprintf(data, "PORT\n%04x\n", buffer_len);
|
||||
write(fileno(stdout), data, 10);
|
||||
write(fileno(stdout), buffer, buffer_len);
|
||||
}
|
||||
else if(!memcmp("QUIT", buffer, 4)) {
|
||||
/* just die */
|
||||
logmsg("quits");
|
||||
return FALSE;
|
||||
}
|
||||
else if(!memcmp("DATA", buffer, 4)) {
|
||||
/* data IN => data OUT */
|
||||
|
||||
if(5 != read(fileno(stdin), buffer, 5))
|
||||
return FALSE;
|
||||
buffer[5] = '\0';
|
||||
|
||||
buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
|
||||
if (buffer_len > (ssize_t)sizeof(buffer)) {
|
||||
logmsg("Buffer size %d too small for data size %d",
|
||||
(int)sizeof(buffer), buffer_len);
|
||||
return FALSE;
|
||||
}
|
||||
nread_stdin = read(fileno(stdin), buffer, buffer_len);
|
||||
if(nread_stdin != buffer_len)
|
||||
return FALSE;
|
||||
|
||||
logmsg("> %d bytes data, server => client", buffer_len);
|
||||
lograw(buffer, buffer_len);
|
||||
|
||||
if(*mode == PASSIVE_LISTEN) {
|
||||
logmsg("*** We are disconnected!");
|
||||
write(fileno(stdout), "DISC\n", 5);
|
||||
}
|
||||
else {
|
||||
/* send away on the socket */
|
||||
bytes_written = swrite(sockfd, buffer, buffer_len);
|
||||
if(bytes_written != buffer_len) {
|
||||
logmsg("Not all data was sent. Bytes to send: %d sent: %d",
|
||||
buffer_len, bytes_written);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!memcmp("DISC", buffer, 4)) {
|
||||
/* disconnect! */
|
||||
write(fileno(stdout), "DISC\n", 5);
|
||||
if(sockfd != CURL_SOCKET_BAD) {
|
||||
logmsg("====> Client forcibly disconnected");
|
||||
sclose(sockfd);
|
||||
*sockfdp = CURL_SOCKET_BAD;
|
||||
if(*mode == PASSIVE_CONNECT)
|
||||
*mode = PASSIVE_LISTEN;
|
||||
else
|
||||
*mode = ACTIVE_DISCONNECT;
|
||||
}
|
||||
else
|
||||
logmsg("attempt to close already dead connection");
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else if(-1 == nread_stdin) {
|
||||
logmsg("read %d from stdin, exiting", nread_stdin);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read)) ) {
|
||||
|
||||
if(*mode == PASSIVE_LISTEN) {
|
||||
/* there's no stream set up yet, this is an indication that there's a
|
||||
client connecting. */
|
||||
sockfd = accept(sockfd, NULL, NULL);
|
||||
if(CURL_SOCKET_BAD == sockfd)
|
||||
logmsg("accept() failed\n");
|
||||
else {
|
||||
logmsg("====> Client connect");
|
||||
write(fileno(stdout), "CNCT\n", 5);
|
||||
*sockfdp = sockfd; /* store the new socket */
|
||||
*mode = PASSIVE_CONNECT; /* we have connected */
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* read from socket, pass on data to stdout */
|
||||
nread_socket = sread(sockfd, buffer, sizeof(buffer));
|
||||
|
||||
if(nread_socket <= 0) {
|
||||
logmsg("====> Client disconnect");
|
||||
write(fileno(stdout), "DISC\n", 5);
|
||||
sclose(sockfd);
|
||||
*sockfdp = CURL_SOCKET_BAD;
|
||||
if(*mode == PASSIVE_CONNECT)
|
||||
*mode = PASSIVE_LISTEN;
|
||||
else
|
||||
*mode = ACTIVE_DISCONNECT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
sprintf(data, "DATA\n%04x\n", nread_socket);
|
||||
write(fileno(stdout), data, 10);
|
||||
write(fileno(stdout), buffer, nread_socket);
|
||||
|
||||
logmsg("< %d bytes data, client => server", nread_socket);
|
||||
lograw(buffer, nread_socket);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static curl_socket_t sockdaemon(curl_socket_t sock,
|
||||
unsigned short *port)
|
||||
{
|
||||
/* passive daemon style */
|
||||
struct sockaddr_in me;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 me6;
|
||||
#endif /* ENABLE_IPV6 */
|
||||
int flag = 1;
|
||||
int rc;
|
||||
|
||||
if (setsockopt
|
||||
(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flag,
|
||||
sizeof(flag)) < 0) {
|
||||
perror("setsockopt(SO_REUSEADDR)");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6) {
|
||||
#endif
|
||||
me.sin_family = AF_INET;
|
||||
me.sin_addr.s_addr = INADDR_ANY;
|
||||
me.sin_port = htons(*port);
|
||||
rc = bind(sock, (struct sockaddr *) &me, sizeof(me));
|
||||
#ifdef ENABLE_IPV6
|
||||
}
|
||||
else {
|
||||
memset(&me6, 0, sizeof(struct sockaddr_in6));
|
||||
me6.sin6_family = AF_INET6;
|
||||
me6.sin6_addr = in6addr_any;
|
||||
me6.sin6_port = htons(*port);
|
||||
rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6));
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
if(rc < 0) {
|
||||
perror("binding stream socket");
|
||||
logmsg("Error binding socket");
|
||||
return CURL_SOCKET_BAD;
|
||||
}
|
||||
|
||||
if(!*port) {
|
||||
/* The system picked a port number, now figure out which port we actually
|
||||
got */
|
||||
/* we succeeded to bind */
|
||||
struct sockaddr_in add;
|
||||
socklen_t socksize = sizeof(add);
|
||||
|
||||
if(getsockname(sock, (struct sockaddr *) &add,
|
||||
&socksize)<0) {
|
||||
fprintf(stderr, "getsockname() failed");
|
||||
return CURL_SOCKET_BAD;
|
||||
}
|
||||
*port = ntohs(add.sin_port);
|
||||
}
|
||||
|
||||
/* start accepting connections */
|
||||
rc = listen(sock, 4);
|
||||
if(0 != rc) {
|
||||
logmsg("listen() failed with error: %d", errno);
|
||||
sclose(sock);
|
||||
return CURL_SOCKET_BAD;
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
static curl_socket_t mksock(bool use_ipv6)
|
||||
{
|
||||
curl_socket_t sock;
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6)
|
||||
#else
|
||||
(void)use_ipv6;
|
||||
#endif
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
#ifdef ENABLE_IPV6
|
||||
else
|
||||
sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
#endif
|
||||
|
||||
if (CURL_SOCKET_BAD == sock) {
|
||||
perror("opening stream socket");
|
||||
logmsg("Error opening socket");
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_in me;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 me6;
|
||||
#endif /* ENABLE_IPV6 */
|
||||
curl_socket_t sock;
|
||||
curl_socket_t msgsock;
|
||||
FILE *pidfile;
|
||||
char *pidname= (char *)".sockfilt.pid";
|
||||
int rc;
|
||||
int arg=1;
|
||||
enum sockmode mode = PASSIVE_LISTEN; /* default */
|
||||
|
||||
while(argc>arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("sockfilt IPv4%s\n",
|
||||
#ifdef ENABLE_IPV6
|
||||
"/IPv6"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp("--pidfile", argv[arg])) {
|
||||
arg++;
|
||||
if(argc>arg)
|
||||
pidname = argv[arg++];
|
||||
}
|
||||
else if(!strcmp("--logfile", argv[arg])) {
|
||||
arg++;
|
||||
if(argc>arg)
|
||||
serverlogfile = argv[arg++];
|
||||
}
|
||||
else if(!strcmp("--ipv6", argv[arg])) {
|
||||
#ifdef ENABLE_IPV6
|
||||
use_ipv6=TRUE;
|
||||
#endif
|
||||
arg++;
|
||||
}
|
||||
else if(!strcmp("--ipv4", argv[arg])) {
|
||||
/* for completeness, we support this option as well */
|
||||
use_ipv6=FALSE;
|
||||
arg++;
|
||||
}
|
||||
else if(!strcmp("--port", argv[arg])) {
|
||||
arg++;
|
||||
if(argc>arg) {
|
||||
port = (unsigned short)atoi(argv[arg]);
|
||||
arg++;
|
||||
}
|
||||
}
|
||||
else if(!strcmp("--connect", argv[arg])) {
|
||||
/* Asked to actively connect to the specified local port instead of
|
||||
doing a passive server-style listening. */
|
||||
arg++;
|
||||
if(argc>arg) {
|
||||
connectport = (unsigned short)atoi(argv[arg]);
|
||||
arg++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
puts("Usage: sockfilt [option]\n"
|
||||
" --version\n"
|
||||
" --logfile [file]\n"
|
||||
" --pidfile [file]\n"
|
||||
" --ipv4\n"
|
||||
" --ipv6\n"
|
||||
" --port [port]");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
#else
|
||||
|
||||
#ifdef SIGPIPE
|
||||
#ifdef HAVE_SIGNAL
|
||||
signal(SIGPIPE, sigpipe_handler);
|
||||
#endif
|
||||
#ifdef HAVE_SIGINTERRUPT
|
||||
siginterrupt(SIGPIPE, 1);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
sock = mksock(use_ipv6);
|
||||
if (CURL_SOCKET_BAD == sock) {
|
||||
logmsg("Error opening socket: %d", errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(connectport) {
|
||||
/* Active mode, we should connect to the given port number */
|
||||
mode = ACTIVE;
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6) {
|
||||
#endif
|
||||
memset(&me, 0, sizeof(me));
|
||||
me.sin_family = AF_INET;
|
||||
me.sin_port = htons(connectport);
|
||||
me.sin_addr.s_addr = INADDR_ANY;
|
||||
Curl_inet_pton(AF_INET, "127.0.0.1", &me.sin_addr);
|
||||
|
||||
rc = connect(sock, (struct sockaddr *) &me, sizeof(me));
|
||||
#ifdef ENABLE_IPV6
|
||||
}
|
||||
else {
|
||||
memset(&me6, 0, sizeof(me6));
|
||||
me6.sin6_family = AF_INET6;
|
||||
me6.sin6_port = htons(connectport);
|
||||
Curl_inet_pton(AF_INET6, "::1", &me6.sin6_addr);
|
||||
|
||||
rc = connect(sock, (struct sockaddr *) &me6, sizeof(me6));
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
if(rc) {
|
||||
perror("connecting stream socket");
|
||||
logmsg("Error connecting to port %d", port);
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
logmsg("====> Client connect");
|
||||
msgsock = sock; /* use this as stream */
|
||||
}
|
||||
else {
|
||||
/* passive daemon style */
|
||||
sock = sockdaemon(sock, &port);
|
||||
if(CURL_SOCKET_BAD == sock)
|
||||
return 1;
|
||||
msgsock = CURL_SOCKET_BAD; /* no stream socket yet */
|
||||
}
|
||||
|
||||
logmsg("Running IPv%d version",
|
||||
(use_ipv6?6:4));
|
||||
|
||||
if(connectport)
|
||||
logmsg("Connected to port %d", connectport);
|
||||
else
|
||||
logmsg("Listening on port %d", port);
|
||||
|
||||
pidfile = fopen(pidname, "w");
|
||||
if(pidfile) {
|
||||
int pid = (int)getpid();
|
||||
fprintf(pidfile, "%d\n", pid);
|
||||
fclose(pidfile);
|
||||
logmsg("Wrote pid %d to %s", pid, pidname);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Couldn't write pid file\n");
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(juggle(&msgsock, sock, &mode));
|
||||
|
||||
sclose(sock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,935 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: sws.c,v 1.95 2006-10-23 19:16:19 yangtse Exp $
|
||||
***************************************************************************/
|
||||
|
||||
/* sws.c: simple (silly?) web server
|
||||
|
||||
This code was originally graciously donated to the project by Juergen
|
||||
Wilke. Thanks a bunch!
|
||||
|
||||
*/
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* make the curlx header define all printf() functions to use the curlx_*
|
||||
versions instead */
|
||||
#include "curlx.h" /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
#include "util.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#if !defined(CURL_SWS_FORK_ENABLED) && defined(HAVE_FORK)
|
||||
/*
|
||||
* The normal sws build for the plain standard curl test suite has no use for
|
||||
* fork(), but if you feel wild and crazy and want to setup some more exotic
|
||||
* tests. Define this and run...
|
||||
*/
|
||||
#define CURL_SWS_FORK_ENABLED
|
||||
#endif
|
||||
|
||||
#define REQBUFSIZ 150000
|
||||
#define REQBUFSIZ_TXT "149999"
|
||||
|
||||
long prevtestno=-1; /* previous test number we served */
|
||||
long prevpartno=-1; /* previous part number we served */
|
||||
bool prevbounce; /* instructs the server to increase the part number for
|
||||
a test in case the identical testno+partno request
|
||||
shows up again */
|
||||
|
||||
#define RCMD_NORMALREQ 0 /* default request, use the tests file normally */
|
||||
#define RCMD_IDLE 1 /* told to sit idle */
|
||||
#define RCMD_STREAM 2 /* told to stream */
|
||||
|
||||
struct httprequest {
|
||||
char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
|
||||
int checkindex; /* where to start checking of the request */
|
||||
int offset; /* size of the incoming request */
|
||||
long testno; /* test number found in the request */
|
||||
long partno; /* part number found in the request */
|
||||
int open; /* keep connection open info, as found in the request */
|
||||
bool auth_req; /* authentication required, don't wait for body unless
|
||||
there's an Authorization header */
|
||||
bool auth; /* Authorization header present in the incoming request */
|
||||
size_t cl; /* Content-Length of the incoming request */
|
||||
bool digest; /* Authorization digest header found */
|
||||
bool ntlm; /* Authorization ntlm header found */
|
||||
int pipe; /* if non-zero, expect this many requests to do a "piped"
|
||||
request/response */
|
||||
int rcmd; /* doing a special command, see defines above */
|
||||
};
|
||||
|
||||
int ProcessRequest(struct httprequest *req);
|
||||
void storerequest(char *reqbuf);
|
||||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/sws.log"
|
||||
#endif
|
||||
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
|
||||
#define SWSVERSION "cURL test suite HTTP server/0.1"
|
||||
|
||||
#define REQUEST_DUMP "log/server.input"
|
||||
#define RESPONSE_DUMP "log/server.response"
|
||||
|
||||
/* very-big-path support */
|
||||
#define MAXDOCNAMELEN 140000
|
||||
#define MAXDOCNAMELEN_TXT "139999"
|
||||
|
||||
#define REQUEST_KEYWORD_SIZE 256
|
||||
|
||||
#define CMD_AUTH_REQUIRED "auth_required"
|
||||
|
||||
/* 'idle' means that it will accept the request fine but never respond
|
||||
any data. Just keep the connection alive. */
|
||||
#define CMD_IDLE "idle"
|
||||
|
||||
/* 'stream' means to send a never-ending stream of data */
|
||||
#define CMD_STREAM "stream"
|
||||
|
||||
#define END_OF_HEADERS "\r\n\r\n"
|
||||
|
||||
enum {
|
||||
DOCNUMBER_NOTHING = -7,
|
||||
DOCNUMBER_QUIT = -6,
|
||||
DOCNUMBER_BADCONNECT = -5,
|
||||
DOCNUMBER_INTERNAL= -4,
|
||||
DOCNUMBER_CONNECT = -3,
|
||||
DOCNUMBER_WERULEZ = -2,
|
||||
DOCNUMBER_404 = -1
|
||||
};
|
||||
|
||||
|
||||
/* sent as reply to a QUIT */
|
||||
static const char *docquit =
|
||||
"HTTP/1.1 200 Goodbye" END_OF_HEADERS;
|
||||
|
||||
/* sent as reply to a CONNECT */
|
||||
static const char *docconnect =
|
||||
"HTTP/1.1 200 Mighty fine indeed" END_OF_HEADERS;
|
||||
|
||||
/* sent as reply to a "bad" CONNECT */
|
||||
static const char *docbadconnect =
|
||||
"HTTP/1.1 501 Forbidden you fool" END_OF_HEADERS;
|
||||
|
||||
/* send back this on 404 file not found */
|
||||
static const char *doc404 = "HTTP/1.1 404 Not Found\r\n"
|
||||
"Server: " SWSVERSION "\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Type: text/html"
|
||||
END_OF_HEADERS
|
||||
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
|
||||
"<HTML><HEAD>\n"
|
||||
"<TITLE>404 Not Found</TITLE>\n"
|
||||
"</HEAD><BODY>\n"
|
||||
"<H1>Not Found</H1>\n"
|
||||
"The requested URL was not found on this server.\n"
|
||||
"<P><HR><ADDRESS>" SWSVERSION "</ADDRESS>\n" "</BODY></HTML>\n";
|
||||
|
||||
#ifdef SIGPIPE
|
||||
static volatile int sigpipe; /* Why? It's not used */
|
||||
#endif
|
||||
|
||||
#ifdef SIGPIPE
|
||||
static void sigpipe_handler(int sig)
|
||||
{
|
||||
(void)sig; /* prevent warning */
|
||||
sigpipe = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ProcessRequest(struct httprequest *req)
|
||||
{
|
||||
char *line=&req->reqbuf[req->checkindex];
|
||||
char chunked=FALSE;
|
||||
static char request[REQUEST_KEYWORD_SIZE];
|
||||
static char doc[MAXDOCNAMELEN];
|
||||
char logbuf[256];
|
||||
int prot_major, prot_minor;
|
||||
char *end;
|
||||
end = strstr(line, END_OF_HEADERS);
|
||||
|
||||
logmsg("ProcessRequest() called");
|
||||
|
||||
/* try to figure out the request characteristics as soon as possible, but
|
||||
only once! */
|
||||
if((req->testno == DOCNUMBER_NOTHING) &&
|
||||
sscanf(line, "%" REQBUFSIZ_TXT"s %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
||||
request,
|
||||
doc,
|
||||
&prot_major,
|
||||
&prot_minor) == 4) {
|
||||
char *ptr;
|
||||
|
||||
/* find the last slash */
|
||||
ptr = strrchr(doc, '/');
|
||||
|
||||
/* get the number after it */
|
||||
if(ptr) {
|
||||
FILE *stream;
|
||||
char *filename;
|
||||
|
||||
if((strlen(doc) + strlen(request)) < 200)
|
||||
sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
|
||||
request, doc, prot_major, prot_minor);
|
||||
else
|
||||
sprintf(logbuf, "Got a *HUGE* request HTTP/%d.%d",
|
||||
prot_major, prot_minor);
|
||||
logmsg("%s", logbuf);
|
||||
|
||||
if(!strncmp("/verifiedserver", ptr, 15)) {
|
||||
logmsg("Are-we-friendly question received");
|
||||
req->testno = DOCNUMBER_WERULEZ;
|
||||
return 1; /* done */
|
||||
}
|
||||
|
||||
if(!strncmp("/quit", ptr, 5)) {
|
||||
logmsg("Request-to-quit received");
|
||||
req->testno = DOCNUMBER_QUIT;
|
||||
return 1; /* done */
|
||||
}
|
||||
|
||||
ptr++; /* skip the slash */
|
||||
|
||||
/* skip all non-numericals following the slash */
|
||||
while(*ptr && !ISDIGIT(*ptr))
|
||||
ptr++;
|
||||
|
||||
req->testno = strtol(ptr, &ptr, 10);
|
||||
|
||||
if(req->testno > 10000) {
|
||||
req->partno = req->testno % 10000;
|
||||
req->testno /= 10000;
|
||||
}
|
||||
else
|
||||
req->partno = 0;
|
||||
|
||||
sprintf(logbuf, "Requested test number %ld part %ld",
|
||||
req->testno, req->partno);
|
||||
|
||||
logmsg("%s", logbuf);
|
||||
|
||||
filename = test2file(req->testno);
|
||||
|
||||
stream=fopen(filename, "rb");
|
||||
if(!stream) {
|
||||
logmsg("Couldn't open test file %d", req->testno);
|
||||
req->open = FALSE; /* closes connection */
|
||||
return 1; /* done */
|
||||
}
|
||||
else {
|
||||
char *cmd = NULL;
|
||||
size_t cmdsize = 0;
|
||||
int num=0;
|
||||
|
||||
/* get the custom server control "commands" */
|
||||
cmd = (char *)spitout(stream, "reply", "servercmd", &cmdsize);
|
||||
fclose(stream);
|
||||
|
||||
if(cmdsize) {
|
||||
logmsg("Found a reply-servercmd section!");
|
||||
|
||||
if(!strncmp(CMD_AUTH_REQUIRED, cmd, strlen(CMD_AUTH_REQUIRED))) {
|
||||
logmsg("instructed to require authorization header");
|
||||
req->auth_req = TRUE;
|
||||
}
|
||||
else if(!strncmp(CMD_IDLE, cmd, strlen(CMD_IDLE))) {
|
||||
logmsg("instructed to idle");
|
||||
req->rcmd = RCMD_IDLE;
|
||||
req->open = TRUE;
|
||||
}
|
||||
else if(!strncmp(CMD_STREAM, cmd, strlen(CMD_STREAM))) {
|
||||
logmsg("instructed to stream");
|
||||
req->rcmd = RCMD_STREAM;
|
||||
}
|
||||
else if(1 == sscanf(cmd, "pipe: %d", &num)) {
|
||||
logmsg("instructed to allow a pipe size %d", num);
|
||||
req->pipe = num-1; /* decrease by one since we don't count the
|
||||
first request in this number */
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
||||
doc, &prot_major, &prot_minor) == 3) {
|
||||
sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
|
||||
doc, prot_major, prot_minor);
|
||||
logmsg("%s", logbuf);
|
||||
|
||||
if(prot_major*10+prot_minor == 10)
|
||||
req->open = FALSE; /* HTTP 1.0 closes connection by default */
|
||||
|
||||
if(!strncmp(doc, "bad", 3))
|
||||
/* if the host name starts with bad, we fake an error here */
|
||||
req->testno = DOCNUMBER_BADCONNECT;
|
||||
else if(!strncmp(doc, "test", 4)) {
|
||||
/* if the host name starts with test, the port number used in the
|
||||
CONNECT line will be used as test number! */
|
||||
char *portp = strchr(doc, ':');
|
||||
if(portp)
|
||||
req->testno = atoi(portp+1);
|
||||
else
|
||||
req->testno = DOCNUMBER_CONNECT;
|
||||
}
|
||||
else
|
||||
req->testno = DOCNUMBER_CONNECT;
|
||||
}
|
||||
else {
|
||||
logmsg("Did not find test number in PATH");
|
||||
req->testno = DOCNUMBER_404;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!end) {
|
||||
/* we don't have a complete request yet! */
|
||||
logmsg("ProcessRequest returned without a complete request");
|
||||
return 0;
|
||||
}
|
||||
logmsg("ProcessRequest found a complete request");
|
||||
|
||||
if(req->pipe)
|
||||
/* we do have a full set, advance the checkindex to after the end of the
|
||||
headers, for the pipelining case mostly */
|
||||
req->checkindex += (end - line) + strlen(END_OF_HEADERS);
|
||||
|
||||
/* **** Persistancy ****
|
||||
*
|
||||
* If the request is a HTTP/1.0 one, we close the connection unconditionally
|
||||
* when we're done.
|
||||
*
|
||||
* If the request is a HTTP/1.1 one, we MUST check for a "Connection:"
|
||||
* header that might say "close". If it does, we close a connection when
|
||||
* this request is processed. Otherwise, we keep the connection alive for X
|
||||
* seconds.
|
||||
*/
|
||||
|
||||
do {
|
||||
if(!req->cl && curlx_strnequal("Content-Length:", line, 15)) {
|
||||
/* If we don't ignore content-length, we read it and we read the whole
|
||||
request including the body before we return. If we've been told to
|
||||
ignore the content-length, we will return as soon as all headers
|
||||
have been received */
|
||||
req->cl = strtol(line+15, &line, 10);
|
||||
|
||||
logmsg("Found Content-Length: %d in the request", req->cl);
|
||||
break;
|
||||
}
|
||||
else if(curlx_strnequal("Transfer-Encoding: chunked", line,
|
||||
strlen("Transfer-Encoding: chunked"))) {
|
||||
/* chunked data coming in */
|
||||
chunked = TRUE;
|
||||
}
|
||||
|
||||
if(chunked) {
|
||||
if(strstr(req->reqbuf, "\r\n0\r\n\r\n"))
|
||||
/* end of chunks reached */
|
||||
return 1; /* done */
|
||||
else
|
||||
return 0; /* not done */
|
||||
}
|
||||
|
||||
line = strchr(line, '\n');
|
||||
if(line)
|
||||
line++;
|
||||
} while(line);
|
||||
|
||||
if(!req->auth && strstr(req->reqbuf, "Authorization:")) {
|
||||
req->auth = TRUE; /* Authorization: header present! */
|
||||
if(req->auth_req)
|
||||
logmsg("Authorization header found, as required");
|
||||
}
|
||||
|
||||
if(!req->digest && strstr(req->reqbuf, "Authorization: Digest")) {
|
||||
/* If the client is passing this Digest-header, we set the part number
|
||||
to 1000. Not only to spice up the complexity of this, but to make
|
||||
Digest stuff to work in the test suite. */
|
||||
req->partno += 1000;
|
||||
req->digest = TRUE; /* header found */
|
||||
logmsg("Received Digest request, sending back data %d", req->partno);
|
||||
}
|
||||
else if(!req->ntlm &&
|
||||
strstr(req->reqbuf, "Authorization: NTLM TlRMTVNTUAAD")) {
|
||||
/* If the client is passing this type-3 NTLM header */
|
||||
req->partno += 1002;
|
||||
req->ntlm = TRUE; /* NTLM found */
|
||||
logmsg("Received NTLM type-3, sending back data %d", req->partno);
|
||||
if(req->cl) {
|
||||
logmsg(" Expecting %d POSTed bytes", req->cl);
|
||||
}
|
||||
}
|
||||
else if(!req->ntlm &&
|
||||
strstr(req->reqbuf, "Authorization: NTLM TlRMTVNTUAAB")) {
|
||||
/* If the client is passing this type-1 NTLM header */
|
||||
req->partno += 1001;
|
||||
req->ntlm = TRUE; /* NTLM found */
|
||||
logmsg("Received NTLM type-1, sending back data %d", req->partno);
|
||||
}
|
||||
if(strstr(req->reqbuf, "Connection: close"))
|
||||
req->open = FALSE; /* close connection after this request */
|
||||
|
||||
while(req->pipe) {
|
||||
/* scan for more header ends within this chunk */
|
||||
line = &req->reqbuf[req->checkindex];
|
||||
end = strstr(line, END_OF_HEADERS);
|
||||
if(!end)
|
||||
break;
|
||||
req->checkindex += (end - line) + strlen(END_OF_HEADERS);
|
||||
req->pipe--;
|
||||
}
|
||||
|
||||
|
||||
/* If authentication is required and no auth was provided, end now. This
|
||||
makes the server NOT wait for PUT/POST data and you can then make the
|
||||
test case send a rejection before any such data has been sent. Test case
|
||||
154 uses this.*/
|
||||
if(req->auth_req && !req->auth)
|
||||
return 1;
|
||||
|
||||
if(req->cl) {
|
||||
if(req->cl <= strlen(end+strlen(END_OF_HEADERS)))
|
||||
return 1; /* done */
|
||||
else
|
||||
return 0; /* not complete yet */
|
||||
}
|
||||
|
||||
return 1; /* done */
|
||||
}
|
||||
|
||||
/* store the entire request in a file */
|
||||
void storerequest(char *reqbuf)
|
||||
{
|
||||
FILE *dump;
|
||||
|
||||
dump = fopen(REQUEST_DUMP, "ab"); /* b is for windows-preparing */
|
||||
if(dump) {
|
||||
size_t len = strlen(reqbuf);
|
||||
fwrite(reqbuf, 1, len, dump);
|
||||
|
||||
fclose(dump);
|
||||
logmsg("Wrote request (%d bytes) input to " REQUEST_DUMP,
|
||||
(int)len);
|
||||
}
|
||||
else {
|
||||
logmsg("Failed to write request input to " REQUEST_DUMP);
|
||||
}
|
||||
}
|
||||
|
||||
/* return 0 on success, non-zero on failure */
|
||||
static int get_request(curl_socket_t sock, struct httprequest *req)
|
||||
{
|
||||
int fail= FALSE;
|
||||
char *reqbuf = req->reqbuf;
|
||||
|
||||
/*** Init the httpreqest structure properly for the upcoming request ***/
|
||||
memset(req, 0, sizeof(struct httprequest));
|
||||
|
||||
/* here's what should not be 0 from the start */
|
||||
req->testno = DOCNUMBER_NOTHING; /* safe default */
|
||||
req->open = TRUE; /* connection should remain open and wait for more
|
||||
commands */
|
||||
req->pipe = 0;
|
||||
|
||||
/*** end of httprequest init ***/
|
||||
|
||||
while (req->offset < REQBUFSIZ) {
|
||||
ssize_t got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
|
||||
if (got <= 0) {
|
||||
if (got < 0) {
|
||||
logmsg("recv() returned error: %d", errno);
|
||||
return DOCNUMBER_INTERNAL;
|
||||
}
|
||||
logmsg("Connection closed by client");
|
||||
reqbuf[req->offset]=0;
|
||||
|
||||
/* dump the request receivied so far to the external file */
|
||||
storerequest(reqbuf);
|
||||
return DOCNUMBER_INTERNAL;
|
||||
}
|
||||
|
||||
logmsg("Read %d bytes", got);
|
||||
|
||||
req->offset += got;
|
||||
|
||||
reqbuf[req->offset] = 0;
|
||||
|
||||
if(ProcessRequest(req)) {
|
||||
if(req->pipe--) {
|
||||
logmsg("Waiting for another piped request");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (req->offset >= REQBUFSIZ) {
|
||||
logmsg("Request buffer overflow, closing connection");
|
||||
reqbuf[REQBUFSIZ-1]=0;
|
||||
fail = TRUE;
|
||||
/* dump the request to an external file anyway */
|
||||
}
|
||||
else
|
||||
reqbuf[req->offset]=0;
|
||||
|
||||
/* dump the request to an external file */
|
||||
storerequest(reqbuf);
|
||||
|
||||
return fail; /* success */
|
||||
}
|
||||
|
||||
/* returns -1 on failure */
|
||||
static int send_doc(curl_socket_t sock, struct httprequest *req)
|
||||
{
|
||||
ssize_t written;
|
||||
size_t count;
|
||||
const char *buffer;
|
||||
char *ptr;
|
||||
FILE *stream;
|
||||
char *cmd=NULL;
|
||||
size_t cmdsize=0;
|
||||
FILE *dump;
|
||||
int persistant = TRUE;
|
||||
size_t responsesize;
|
||||
|
||||
static char weare[256];
|
||||
|
||||
char partbuf[80]="data";
|
||||
|
||||
logmsg("Send response number %d part %d", req->testno, req->partno);
|
||||
|
||||
switch(req->rcmd) {
|
||||
default:
|
||||
case RCMD_NORMALREQ:
|
||||
break; /* continue with business as usual */
|
||||
case RCMD_STREAM:
|
||||
#define STREAMTHIS "a string to stream 01234567890\n"
|
||||
count = strlen(STREAMTHIS);
|
||||
while(1) {
|
||||
written = swrite(sock, STREAMTHIS, count);
|
||||
if(written != (ssize_t)count) {
|
||||
logmsg("Stopped streaming");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
case RCMD_IDLE:
|
||||
/* Do nothing. Sit idle. Pretend it rains. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
req->open = FALSE;
|
||||
|
||||
if(req->testno < 0) {
|
||||
switch(req->testno) {
|
||||
case DOCNUMBER_QUIT:
|
||||
logmsg("Replying to QUIT");
|
||||
buffer = docquit;
|
||||
break;
|
||||
case DOCNUMBER_WERULEZ:
|
||||
/* we got a "friends?" question, reply back that we sure are */
|
||||
logmsg("Identifying ourselves as friends");
|
||||
sprintf(weare, "HTTP/1.1 200 OK\r\n\r\nWE ROOLZ: %d\r\n",
|
||||
(int)getpid());
|
||||
buffer = weare;
|
||||
break;
|
||||
case DOCNUMBER_INTERNAL:
|
||||
logmsg("Bailing out due to internal error");
|
||||
return -1;
|
||||
case DOCNUMBER_CONNECT:
|
||||
logmsg("Replying to CONNECT");
|
||||
buffer = docconnect;
|
||||
break;
|
||||
case DOCNUMBER_BADCONNECT:
|
||||
logmsg("Replying to a bad CONNECT");
|
||||
buffer = docbadconnect;
|
||||
break;
|
||||
case DOCNUMBER_404:
|
||||
default:
|
||||
logmsg("Replying to with a 404");
|
||||
buffer = doc404;
|
||||
break;
|
||||
}
|
||||
ptr = NULL;
|
||||
stream=NULL;
|
||||
|
||||
count = strlen(buffer);
|
||||
}
|
||||
else {
|
||||
char *filename = test2file(req->testno);
|
||||
|
||||
if(0 != req->partno)
|
||||
sprintf(partbuf, "data%ld", req->partno);
|
||||
|
||||
stream=fopen(filename, "rb");
|
||||
if(!stream) {
|
||||
logmsg("Couldn't open test file");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
buffer = spitout(stream, "reply", partbuf, &count);
|
||||
ptr = (char *)buffer;
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
/* re-open the same file again */
|
||||
stream=fopen(filename, "rb");
|
||||
if(!stream) {
|
||||
logmsg("Couldn't open test file");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
/* get the custom server control "commands" */
|
||||
cmd = (char *)spitout(stream, "reply", "postcmd", &cmdsize);
|
||||
fclose(stream);
|
||||
}
|
||||
}
|
||||
|
||||
dump = fopen(RESPONSE_DUMP, "ab"); /* b is for windows-preparing */
|
||||
if(!dump) {
|
||||
logmsg("couldn't create logfile: " RESPONSE_DUMP);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If the word 'swsclose' is present anywhere in the reply chunk, the
|
||||
connection will be closed after the data has been sent to the requesting
|
||||
client... */
|
||||
if(strstr(buffer, "swsclose") || !count) {
|
||||
persistant = FALSE;
|
||||
logmsg("connection close instruction \"swsclose\" found in response");
|
||||
}
|
||||
if(strstr(buffer, "swsbounce")) {
|
||||
prevbounce = TRUE;
|
||||
logmsg("enable \"swsbounce\" in the next request");
|
||||
}
|
||||
else
|
||||
prevbounce = FALSE;
|
||||
|
||||
|
||||
responsesize = count;
|
||||
do {
|
||||
written = swrite(sock, buffer, count);
|
||||
if (written < 0) {
|
||||
logmsg("Sending response failed and we bailed out!");
|
||||
return -1;
|
||||
}
|
||||
/* write to file as well */
|
||||
fwrite(buffer, 1, written, dump);
|
||||
|
||||
count -= written;
|
||||
buffer += written;
|
||||
} while(count>0);
|
||||
|
||||
fclose(dump);
|
||||
|
||||
logmsg("Response sent (%d bytes) and written to " RESPONSE_DUMP,
|
||||
responsesize);
|
||||
|
||||
if(ptr)
|
||||
free(ptr);
|
||||
|
||||
if(cmdsize > 0 ) {
|
||||
char command[32];
|
||||
int num;
|
||||
ptr=cmd;
|
||||
do {
|
||||
if(2 == sscanf(ptr, "%31s %d", command, &num)) {
|
||||
if(!strcmp("wait", command)) {
|
||||
logmsg("Told to sleep for %d seconds", num);
|
||||
sleep(num); /* wait this many seconds */
|
||||
}
|
||||
else
|
||||
logmsg("Unknown command in reply command section");
|
||||
}
|
||||
ptr = strchr(ptr, '\n');
|
||||
if(ptr)
|
||||
ptr++;
|
||||
else
|
||||
ptr = NULL;
|
||||
} while(ptr && *ptr);
|
||||
}
|
||||
if(cmd)
|
||||
free(cmd);
|
||||
|
||||
req->open = persistant;
|
||||
|
||||
prevtestno = req->testno;
|
||||
prevpartno = req->partno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char use_ipv6=FALSE;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sockaddr_in me;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 me6;
|
||||
#endif /* ENABLE_IPV6 */
|
||||
curl_socket_t sock, msgsock;
|
||||
int flag;
|
||||
unsigned short port = DEFAULT_PORT;
|
||||
FILE *pidfile;
|
||||
char *pidname= (char *)".http.pid";
|
||||
struct httprequest req;
|
||||
int rc;
|
||||
int arg=1;
|
||||
#ifdef CURL_SWS_FORK_ENABLED
|
||||
bool use_fork = FALSE;
|
||||
#endif
|
||||
|
||||
while(argc>arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("sws IPv4%s"
|
||||
#ifdef CURL_SWS_FORK_ENABLED
|
||||
" FORK"
|
||||
#endif
|
||||
"\n"
|
||||
,
|
||||
#ifdef ENABLE_IPV6
|
||||
"/IPv6"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp("--pidfile", argv[arg])) {
|
||||
arg++;
|
||||
if(argc>arg)
|
||||
pidname = argv[arg++];
|
||||
}
|
||||
else if(!strcmp("--ipv6", argv[arg])) {
|
||||
#ifdef ENABLE_IPV6
|
||||
use_ipv6=TRUE;
|
||||
#endif
|
||||
arg++;
|
||||
}
|
||||
#ifdef CURL_SWS_FORK_ENABLED
|
||||
else if(!strcmp("--fork", argv[arg])) {
|
||||
use_fork=TRUE;
|
||||
arg++;
|
||||
}
|
||||
#endif
|
||||
else if(argc>arg) {
|
||||
|
||||
if(atoi(argv[arg]))
|
||||
port = (unsigned short)atoi(argv[arg++]);
|
||||
|
||||
if(argc>arg)
|
||||
path = argv[arg++];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
#else
|
||||
|
||||
#ifdef SIGPIPE
|
||||
#ifdef HAVE_SIGNAL
|
||||
signal(SIGPIPE, sigpipe_handler);
|
||||
#endif
|
||||
#ifdef HAVE_SIGINTERRUPT
|
||||
siginterrupt(SIGPIPE, 1);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6)
|
||||
#endif
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
#ifdef ENABLE_IPV6
|
||||
else
|
||||
sock = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
#endif
|
||||
|
||||
if (CURL_SOCKET_BAD == sock) {
|
||||
logmsg("Error opening socket: %d", errno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
flag = 1;
|
||||
if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
(void *) &flag, sizeof(flag))) {
|
||||
logmsg("setsockopt(SO_REUSEADDR) failed: %d", errno);
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6) {
|
||||
#endif
|
||||
memset(&me, 0, sizeof(me));
|
||||
me.sin_family = AF_INET;
|
||||
me.sin_addr.s_addr = INADDR_ANY;
|
||||
me.sin_port = htons(port);
|
||||
rc = bind(sock, (struct sockaddr *) &me, sizeof(me));
|
||||
#ifdef ENABLE_IPV6
|
||||
}
|
||||
else {
|
||||
memset(&me6, 0, sizeof(me6));
|
||||
me6.sin6_family = AF_INET6;
|
||||
me6.sin6_addr = in6addr_any;
|
||||
me6.sin6_port = htons(port);
|
||||
rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6));
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
if(0 != rc) {
|
||||
logmsg("Error binding socket: %d", errno);
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pidfile = fopen(pidname, "w");
|
||||
if(pidfile) {
|
||||
fprintf(pidfile, "%d\n", (int)getpid());
|
||||
fclose(pidfile);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Couldn't write pid file\n");
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
logmsg("Running IPv%d version on port %d",
|
||||
#ifdef ENABLE_IPV6
|
||||
(use_ipv6?6:4)
|
||||
#else
|
||||
4
|
||||
#endif
|
||||
, port );
|
||||
|
||||
/* start accepting connections */
|
||||
rc = listen(sock, 5);
|
||||
if(0 != rc) {
|
||||
logmsg("listen() failed with error: %d", errno);
|
||||
sclose(sock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
msgsock = accept(sock, NULL, NULL);
|
||||
|
||||
if (CURL_SOCKET_BAD == msgsock) {
|
||||
printf("MAJOR ERROR: accept() failed with error: &d\n", errno);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef CURL_SWS_FORK_ENABLED
|
||||
if(use_fork) {
|
||||
/* The fork enabled version just forks off the child and don't care
|
||||
about it anymore, so don't assume otherwise. Beware and don't do
|
||||
this at home. */
|
||||
rc = fork();
|
||||
if(-1 == rc) {
|
||||
printf("MAJOR ERROR: fork() failed!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* not a fork, just set rc so the following proceeds nicely */
|
||||
rc = 0;
|
||||
/* 0 is returned to the child */
|
||||
if(0 == rc) {
|
||||
#endif
|
||||
logmsg("====> Client connect");
|
||||
|
||||
do {
|
||||
if(get_request(msgsock, &req))
|
||||
/* non-zero means error, break out of loop */
|
||||
break;
|
||||
|
||||
if(prevbounce) {
|
||||
/* bounce treatment requested */
|
||||
if((req.testno == prevtestno) &&
|
||||
(req.partno == prevpartno)) {
|
||||
req.partno++;
|
||||
logmsg("BOUNCE part number to %ld", req.partno);
|
||||
}
|
||||
}
|
||||
|
||||
send_doc(msgsock, &req);
|
||||
|
||||
if((req.testno < 0) && (req.testno != DOCNUMBER_CONNECT)) {
|
||||
logmsg("special request received, no persistancy");
|
||||
break;
|
||||
}
|
||||
if(!req.open) {
|
||||
logmsg("instructed to close connection after server-reply");
|
||||
break;
|
||||
}
|
||||
|
||||
if(req.open)
|
||||
logmsg("=> persistant connection request ended, awaits new request");
|
||||
/* if we got a CONNECT, loop and get another request as well! */
|
||||
} while(req.open || (req.testno == DOCNUMBER_CONNECT));
|
||||
|
||||
logmsg("====> Client disconnect");
|
||||
sclose(msgsock);
|
||||
|
||||
if (req.testno == DOCNUMBER_QUIT)
|
||||
break;
|
||||
#ifdef CURL_SWS_FORK_ENABLED
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
sclose(sock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: testpart.c,v 1.1 2005/04/18 06:57:44 bagder Exp $
|
||||
***************************************************************************/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "getpart.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(argc< 3) {
|
||||
printf("./testpart main sub\n");
|
||||
}
|
||||
else {
|
||||
size_t size;
|
||||
unsigned int i;
|
||||
const char *buffer = spitout(stdin, argv[1], argv[2], &size);
|
||||
for(i=0; i< size; i++)
|
||||
printf("%c", buffer[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef __SERVER_TFTP_H
|
||||
#define __SERVER_TFTP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: tftp.h,v 1.2 2006/01/09 13:17:14 bagder Exp $
|
||||
***************************************************************************/
|
||||
|
||||
/* This file is a rewrite/clone of the arpa/telnet.h file for systems without
|
||||
it. */
|
||||
|
||||
#define SEGSIZE 512 /* data segment size */
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
/* Using a packed struct as binary in a program is begging for problems, but
|
||||
the tftpd server was written like this so we have this struct here to make
|
||||
things build. */
|
||||
|
||||
struct tftphdr {
|
||||
short th_opcode; /* packet type */
|
||||
unsigned short th_block; /* all sorts of things */
|
||||
char th_data[1]; /* data or error string */
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
#define th_stuff th_block
|
||||
#define th_code th_block
|
||||
#define th_msg th_data
|
||||
|
||||
#define RRQ 1
|
||||
#define WRQ 2
|
||||
#define DATA 3
|
||||
#define ACK 4
|
||||
#define ERROR 5
|
||||
|
||||
#define EUNDEF 0
|
||||
#define ENOTFOUND 1
|
||||
#define EACCESS 2
|
||||
#define ENOSPACE 3
|
||||
#define EBADOP 4
|
||||
#define EBADID 5
|
||||
#define EEXISTS 6
|
||||
#define ENOUSER 7
|
||||
|
||||
#endif /* __SERVER_TFTP_H */
|
||||
@@ -0,0 +1,936 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* $Id: tftpd.c,v 1.22 2006-10-23 19:14:54 yangtse Exp $
|
||||
*
|
||||
* Trivial file transfer protocol server.
|
||||
*
|
||||
* This code includes many modifications by Jim Guyton <guyton@rand-unix>
|
||||
*
|
||||
* This source file was started based on netkit-tftpd 0.17
|
||||
* Heavily modified for curl's test suite
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_TFTP_H
|
||||
#include <arpa/tftp.h>
|
||||
#else
|
||||
#include "tftp.h"
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
/* FIONREAD on Solaris 7 */
|
||||
#include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* make the curlx header define all printf() functions to use the curlx_*
|
||||
versions instead */
|
||||
#include "curlx.h" /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
#include "util.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
struct testcase {
|
||||
char *buffer; /* holds the file data to send to the client */
|
||||
size_t bufsize; /* size of the data in buffer */
|
||||
char *rptr; /* read pointer into the buffer */
|
||||
size_t rcount; /* amount of data left to read of the file */
|
||||
long num; /* test case number */
|
||||
int ofile; /* file descriptor for output file when uploading to us */
|
||||
FILE *server; /* write input "protocol" there for client verification */
|
||||
};
|
||||
|
||||
static int synchnet(curl_socket_t);
|
||||
static struct tftphdr *r_init(void);
|
||||
static struct tftphdr *w_init(void);
|
||||
static int readit(struct testcase *test, struct tftphdr **dpp, int convert);
|
||||
static int writeit(struct testcase *test, struct tftphdr **dpp, int ct,
|
||||
int convert);
|
||||
static void mysignal(int, void (*func)(int));
|
||||
|
||||
|
||||
#define TIMEOUT 5
|
||||
|
||||
#define PKTSIZE SEGSIZE+4
|
||||
|
||||
struct formats;
|
||||
static int tftp(struct testcase *test, struct tftphdr *tp, int size);
|
||||
static void nak(int error);
|
||||
static void sendtftp(struct testcase *test, struct formats *pf);
|
||||
static void recvtftp(struct testcase *test, struct formats *pf);
|
||||
static int validate_access(struct testcase *test, const char *, int);
|
||||
|
||||
static curl_socket_t peer;
|
||||
static int rexmtval = TIMEOUT;
|
||||
static int maxtimeout = 5*TIMEOUT;
|
||||
|
||||
static char buf[PKTSIZE];
|
||||
static char ackbuf[PKTSIZE];
|
||||
static struct sockaddr_in from;
|
||||
static socklen_t fromlen;
|
||||
|
||||
struct bf {
|
||||
int counter; /* size of data in buffer, or flag */
|
||||
char buf[PKTSIZE]; /* room for data packet */
|
||||
} bfs[2];
|
||||
|
||||
/* Values for bf.counter */
|
||||
#define BF_ALLOC -3 /* alloc'd but not yet filled */
|
||||
#define BF_FREE -2 /* free */
|
||||
/* [-1 .. SEGSIZE] = size of data in the data buffer */
|
||||
|
||||
static int nextone; /* index of next buffer to use */
|
||||
static int current; /* index of buffer in use */
|
||||
|
||||
/* control flags for crlf conversions */
|
||||
int newline = 0; /* fillbuf: in middle of newline expansion */
|
||||
int prevchar = -1; /* putbuf: previous char (cr check) */
|
||||
|
||||
static void read_ahead(struct testcase *test,
|
||||
int convert /* if true, convert to ascii */);
|
||||
static ssize_t write_behind(struct testcase *test, int convert);
|
||||
static struct tftphdr *rw_init(int);
|
||||
static struct tftphdr *w_init(void) { return rw_init(0); } /* write-behind */
|
||||
static struct tftphdr *r_init(void) { return rw_init(1); } /* read-ahead */
|
||||
|
||||
static struct tftphdr *
|
||||
rw_init(int x) /* init for either read-ahead or write-behind */
|
||||
{ /* zero for write-behind, one for read-head */
|
||||
newline = 0; /* init crlf flag */
|
||||
prevchar = -1;
|
||||
bfs[0].counter = BF_ALLOC; /* pass out the first buffer */
|
||||
current = 0;
|
||||
bfs[1].counter = BF_FREE;
|
||||
nextone = x; /* ahead or behind? */
|
||||
return (struct tftphdr *)bfs[0].buf;
|
||||
}
|
||||
|
||||
|
||||
/* Have emptied current buffer by sending to net and getting ack.
|
||||
Free it and return next buffer filled with data.
|
||||
*/
|
||||
static int readit(struct testcase *test, struct tftphdr **dpp,
|
||||
int convert /* if true, convert to ascii */)
|
||||
{
|
||||
struct bf *b;
|
||||
|
||||
bfs[current].counter = BF_FREE; /* free old one */
|
||||
current = !current; /* "incr" current */
|
||||
|
||||
b = &bfs[current]; /* look at new buffer */
|
||||
if (b->counter == BF_FREE) /* if it's empty */
|
||||
read_ahead(test, convert); /* fill it */
|
||||
|
||||
*dpp = (struct tftphdr *)b->buf; /* set caller's ptr */
|
||||
return b->counter;
|
||||
}
|
||||
|
||||
#undef MIN /* some systems have this defined already, some don't */
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y));
|
||||
|
||||
/*
|
||||
* fill the input buffer, doing ascii conversions if requested
|
||||
* conversions are lf -> cr,lf and cr -> cr, nul
|
||||
*/
|
||||
static void read_ahead(struct testcase *test,
|
||||
int convert /* if true, convert to ascii */)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
int c;
|
||||
struct bf *b;
|
||||
struct tftphdr *dp;
|
||||
|
||||
b = &bfs[nextone]; /* look at "next" buffer */
|
||||
if (b->counter != BF_FREE) /* nop if not free */
|
||||
return;
|
||||
nextone = !nextone; /* "incr" next buffer ptr */
|
||||
|
||||
dp = (struct tftphdr *)b->buf;
|
||||
|
||||
if (convert == 0) {
|
||||
/* The former file reading code did this:
|
||||
b->counter = read(fileno(file), dp->th_data, SEGSIZE); */
|
||||
size_t copy_n = MIN(SEGSIZE, test->rcount);
|
||||
memcpy(dp->th_data, test->rptr, copy_n);
|
||||
|
||||
/* decrease amount, advance pointer */
|
||||
test->rcount -= copy_n;
|
||||
test->rptr += copy_n;
|
||||
b->counter = (int)copy_n;
|
||||
return;
|
||||
}
|
||||
|
||||
p = dp->th_data;
|
||||
for (i = 0 ; i < SEGSIZE; i++) {
|
||||
if (newline) {
|
||||
if (prevchar == '\n')
|
||||
c = '\n'; /* lf to cr,lf */
|
||||
else
|
||||
c = '\0'; /* cr to cr,nul */
|
||||
newline = 0;
|
||||
}
|
||||
else {
|
||||
if(test->rcount) {
|
||||
c=test->rptr[0];
|
||||
test->rptr++;
|
||||
test->rcount--;
|
||||
}
|
||||
else
|
||||
break;
|
||||
if (c == '\n' || c == '\r') {
|
||||
prevchar = c;
|
||||
c = '\r';
|
||||
newline = 1;
|
||||
}
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
b->counter = (int)(p - dp->th_data);
|
||||
}
|
||||
|
||||
/* Update count associated with the buffer, get new buffer from the queue.
|
||||
Calls write_behind only if next buffer not available.
|
||||
*/
|
||||
static int writeit(struct testcase *test, struct tftphdr **dpp,
|
||||
int ct, int convert)
|
||||
{
|
||||
bfs[current].counter = ct; /* set size of data to write */
|
||||
current = !current; /* switch to other buffer */
|
||||
if (bfs[current].counter != BF_FREE) /* if not free */
|
||||
write_behind(test, convert); /* flush it */
|
||||
bfs[current].counter = BF_ALLOC; /* mark as alloc'd */
|
||||
*dpp = (struct tftphdr *)bfs[current].buf;
|
||||
return ct; /* this is a lie of course */
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a buffer to a file, converting from netascii if requested.
|
||||
* CR,NUL -> CR and CR,LF => LF.
|
||||
* Note spec is undefined if we get CR as last byte of file or a
|
||||
* CR followed by anything else. In this case we leave it alone.
|
||||
*/
|
||||
static ssize_t write_behind(struct testcase *test, int convert)
|
||||
{
|
||||
char *buf;
|
||||
int count;
|
||||
int ct;
|
||||
char *p;
|
||||
int c; /* current character */
|
||||
struct bf *b;
|
||||
struct tftphdr *dp;
|
||||
|
||||
b = &bfs[nextone];
|
||||
if (b->counter < -1) /* anything to flush? */
|
||||
return 0; /* just nop if nothing to do */
|
||||
|
||||
if(!test->ofile) {
|
||||
char outfile[256];
|
||||
snprintf(outfile, sizeof(outfile), "log/upload.%ld", test->num);
|
||||
test->ofile=open(outfile, O_CREAT|O_RDWR, 0777);
|
||||
if(test->ofile == -1) {
|
||||
logmsg("Couldn't create and/or open file %s for upload!", outfile);
|
||||
return -1; /* failure! */
|
||||
}
|
||||
}
|
||||
|
||||
count = b->counter; /* remember byte count */
|
||||
b->counter = BF_FREE; /* reset flag */
|
||||
dp = (struct tftphdr *)b->buf;
|
||||
nextone = !nextone; /* incr for next time */
|
||||
buf = dp->th_data;
|
||||
|
||||
if (count <= 0)
|
||||
return -1; /* nak logic? */
|
||||
|
||||
if (convert == 0)
|
||||
return write(test->ofile, buf, count);
|
||||
|
||||
p = buf;
|
||||
ct = count;
|
||||
while (ct--) { /* loop over the buffer */
|
||||
c = *p++; /* pick up a character */
|
||||
if (prevchar == '\r') { /* if prev char was cr */
|
||||
if (c == '\n') /* if have cr,lf then just */
|
||||
lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
|
||||
else
|
||||
if (c == '\0') /* if have cr,nul then */
|
||||
goto skipit; /* just skip over the putc */
|
||||
/* else just fall through and allow it */
|
||||
}
|
||||
/* formerly
|
||||
putc(c, file); */
|
||||
write(test->ofile, &c, 1);
|
||||
skipit:
|
||||
prevchar = c;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/* When an error has occurred, it is possible that the two sides are out of
|
||||
* synch. Ie: that what I think is the other side's response to packet N is
|
||||
* really their response to packet N-1.
|
||||
*
|
||||
* So, to try to prevent that, we flush all the input queued up for us on the
|
||||
* network connection on our host.
|
||||
*
|
||||
* We return the number of packets we flushed (mostly for reporting when trace
|
||||
* is active).
|
||||
*/
|
||||
|
||||
static int synchnet(curl_socket_t f /* socket to flush */)
|
||||
{
|
||||
|
||||
#if defined(HAVE_IOCTLSOCKET)
|
||||
unsigned long i;
|
||||
#else
|
||||
int i;
|
||||
#endif
|
||||
int j = 0;
|
||||
char rbuf[PKTSIZE];
|
||||
struct sockaddr_in from;
|
||||
socklen_t fromlen;
|
||||
|
||||
while (1) {
|
||||
#if defined(HAVE_IOCTLSOCKET)
|
||||
(void) ioctlsocket(f, FIONREAD, &i);
|
||||
#else
|
||||
(void) ioctl(f, FIONREAD, &i);
|
||||
#endif
|
||||
if (i) {
|
||||
j++;
|
||||
fromlen = sizeof from;
|
||||
(void) recvfrom(f, rbuf, sizeof (rbuf), 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
#if defined(HAVE_ALARM) && defined(SIGALRM)
|
||||
/*
|
||||
* Like signal(), but with well-defined semantics.
|
||||
*/
|
||||
static void mysignal(int sig, void (*handler)(int))
|
||||
{
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = handler;
|
||||
sigaction(sig, &sa, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_LOGFILE
|
||||
#define DEFAULT_LOGFILE "log/tftpd.log"
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PORT 8999 /* UDP */
|
||||
const char *serverlogfile = DEFAULT_LOGFILE;
|
||||
|
||||
#define REQUEST_DUMP "log/server.input"
|
||||
|
||||
char use_ipv6=FALSE;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_in me;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 me6;
|
||||
#endif /* ENABLE_IPV6 */
|
||||
|
||||
struct tftphdr *tp;
|
||||
int n = 0;
|
||||
int arg = 1;
|
||||
FILE *pidfile;
|
||||
char *pidname= (char *)".tftpd.pid";
|
||||
unsigned short port = DEFAULT_PORT;
|
||||
curl_socket_t sock;
|
||||
int flag;
|
||||
int rc;
|
||||
struct testcase test;
|
||||
|
||||
while(argc>arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("tftpd IPv4%s\n",
|
||||
#ifdef ENABLE_IPV6
|
||||
"/IPv6"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp("--pidfile", argv[arg])) {
|
||||
arg++;
|
||||
if(argc>arg)
|
||||
pidname = argv[arg++];
|
||||
}
|
||||
else if(!strcmp("--ipv6", argv[arg])) {
|
||||
#ifdef ENABLE_IPV6
|
||||
use_ipv6=TRUE;
|
||||
#endif
|
||||
arg++;
|
||||
}
|
||||
else if(argc>arg) {
|
||||
|
||||
if(atoi(argv[arg]))
|
||||
port = (unsigned short)atoi(argv[arg++]);
|
||||
|
||||
if(argc>arg)
|
||||
path = argv[arg++];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6)
|
||||
#endif
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
#ifdef ENABLE_IPV6
|
||||
else
|
||||
sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
#endif
|
||||
|
||||
if (sock < 0) {
|
||||
perror("opening stream socket");
|
||||
logmsg("Error opening socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
flag = 1;
|
||||
if (setsockopt
|
||||
(sock, SOL_SOCKET, SO_REUSEADDR, (const void *) &flag,
|
||||
sizeof(int)) < 0) {
|
||||
perror("setsockopt(SO_REUSEADDR)");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(!use_ipv6) {
|
||||
#endif
|
||||
me.sin_family = AF_INET;
|
||||
me.sin_addr.s_addr = INADDR_ANY;
|
||||
me.sin_port = htons(port);
|
||||
rc = bind(sock, (struct sockaddr *) &me, sizeof(me));
|
||||
#ifdef ENABLE_IPV6
|
||||
}
|
||||
else {
|
||||
memset(&me6, 0, sizeof(struct sockaddr_in6));
|
||||
me6.sin6_family = AF_INET6;
|
||||
me6.sin6_addr = in6addr_any;
|
||||
me6.sin6_port = htons(port);
|
||||
rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6));
|
||||
}
|
||||
#endif /* ENABLE_IPV6 */
|
||||
if(rc < 0) {
|
||||
perror("binding stream socket");
|
||||
logmsg("Error binding socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pidfile = fopen(pidname, "w");
|
||||
if(pidfile) {
|
||||
fprintf(pidfile, "%d\n", (int)getpid());
|
||||
fclose(pidfile);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "Couldn't write pid file\n");
|
||||
|
||||
logmsg("Running IPv%d version on port UDP/%d",
|
||||
#ifdef ENABLE_IPV6
|
||||
(use_ipv6?6:4)
|
||||
#else
|
||||
4
|
||||
#endif
|
||||
, port );
|
||||
|
||||
do {
|
||||
FILE *server;
|
||||
|
||||
fromlen = sizeof(from);
|
||||
n = recvfrom(sock, buf, sizeof (buf), 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
if (n < 0) {
|
||||
logmsg("recvfrom:\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
from.sin_family = AF_INET;
|
||||
|
||||
peer = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (peer < 0) {
|
||||
logmsg("socket:\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) {
|
||||
logmsg("connect: fail\n");
|
||||
return 1;
|
||||
}
|
||||
maxtimeout = 5*TIMEOUT;
|
||||
|
||||
tp = (struct tftphdr *)buf;
|
||||
tp->th_opcode = ntohs(tp->th_opcode);
|
||||
if (tp->th_opcode == RRQ || tp->th_opcode == WRQ) {
|
||||
memset(&test, 0, sizeof(test));
|
||||
server = fopen(REQUEST_DUMP, "ab");
|
||||
if(!server)
|
||||
break;
|
||||
test.server = server;
|
||||
tftp(&test, tp, n);
|
||||
if(test.buffer)
|
||||
free(test.buffer);
|
||||
}
|
||||
fclose(server);
|
||||
sclose(peer);
|
||||
} while(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct formats {
|
||||
const char *f_mode;
|
||||
int f_convert;
|
||||
} formats[] = {
|
||||
{ "netascii", 1 },
|
||||
{ "octet", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Handle initial connection protocol.
|
||||
*/
|
||||
static int tftp(struct testcase *test, struct tftphdr *tp, int size)
|
||||
{
|
||||
char *cp;
|
||||
int first = 1, ecode;
|
||||
struct formats *pf;
|
||||
char *filename, *mode = NULL;
|
||||
|
||||
/* store input protocol */
|
||||
fprintf(test->server, "opcode: %x\n", tp->th_opcode);
|
||||
|
||||
cp = (char *)&tp->th_stuff;
|
||||
filename = cp;
|
||||
again:
|
||||
while (cp < buf + size) {
|
||||
if (*cp == '\0')
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
if (*cp) {
|
||||
nak(EBADOP);
|
||||
return 3;
|
||||
}
|
||||
if (first) {
|
||||
mode = ++cp;
|
||||
first = 0;
|
||||
goto again;
|
||||
}
|
||||
/* store input protocol */
|
||||
fprintf(test->server, "filename: %s\n", filename);
|
||||
|
||||
for (cp = mode; *cp; cp++)
|
||||
if (isupper((int)*cp))
|
||||
*cp = tolower((int)*cp);
|
||||
|
||||
/* store input protocol */
|
||||
fprintf(test->server, "mode: %s\n", mode);
|
||||
|
||||
for (pf = formats; pf->f_mode; pf++)
|
||||
if (strcmp(pf->f_mode, mode) == 0)
|
||||
break;
|
||||
if (!pf->f_mode) {
|
||||
nak(EBADOP);
|
||||
return 2;
|
||||
}
|
||||
ecode = validate_access(test, filename, tp->th_opcode);
|
||||
if (ecode) {
|
||||
nak(ecode);
|
||||
return 1;
|
||||
}
|
||||
if (tp->th_opcode == WRQ)
|
||||
recvtftp(test, pf);
|
||||
else
|
||||
sendtftp(test, pf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate file access.
|
||||
*/
|
||||
static int validate_access(struct testcase *test,
|
||||
const char *filename, int mode)
|
||||
{
|
||||
char *ptr;
|
||||
long testno;
|
||||
|
||||
logmsg("trying to get file: %s mode %x", filename, mode);
|
||||
|
||||
if(!strncmp("verifiedserver", filename, 15)) {
|
||||
char weare[128];
|
||||
size_t count = sprintf(weare, "WE ROOLZ: %d\r\n", (int)getpid());
|
||||
|
||||
logmsg("Are-we-friendly question received");
|
||||
test->buffer = strdup(weare);
|
||||
test->rptr = test->buffer; /* set read pointer */
|
||||
test->bufsize = count; /* set total count */
|
||||
test->rcount = count; /* set data left to read */
|
||||
return 0; /* fine */
|
||||
}
|
||||
|
||||
/* find the last slash */
|
||||
ptr = strrchr(filename, '/');
|
||||
|
||||
if(ptr) {
|
||||
char *file;
|
||||
|
||||
ptr++; /* skip the slash */
|
||||
|
||||
/* skip all non-numericals following the slash */
|
||||
while(*ptr && !ISDIGIT(*ptr))
|
||||
ptr++;
|
||||
|
||||
/* get the number */
|
||||
testno = strtol(ptr, &ptr, 10);
|
||||
|
||||
logmsg("requested test number %d", testno);
|
||||
|
||||
test->num = testno;
|
||||
|
||||
file = test2file(testno);
|
||||
|
||||
if(file) {
|
||||
FILE *stream=fopen(file, "rb");
|
||||
if(!stream) {
|
||||
logmsg("Couldn't open test file: %s", file);
|
||||
return EACCESS;
|
||||
}
|
||||
else {
|
||||
size_t count;
|
||||
test->buffer = (char *)spitout(stream, "reply", "data", &count);
|
||||
fclose(stream);
|
||||
if(test->buffer) {
|
||||
test->rptr = test->buffer; /* set read pointer */
|
||||
test->bufsize = count; /* set total count */
|
||||
test->rcount = count; /* set data left to read */
|
||||
}
|
||||
else
|
||||
return EACCESS;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
return EACCESS;
|
||||
}
|
||||
else {
|
||||
logmsg("no slash found in path");
|
||||
return EACCESS; /* failure */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int timeout;
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
sigjmp_buf timeoutbuf;
|
||||
#endif
|
||||
|
||||
static void timer(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
|
||||
logmsg("alarm!");
|
||||
|
||||
timeout += rexmtval;
|
||||
if (timeout >= maxtimeout)
|
||||
exit(1);
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
siglongjmp(timeoutbuf, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the requested file.
|
||||
*/
|
||||
static void sendtftp(struct testcase *test, struct formats *pf)
|
||||
{
|
||||
struct tftphdr *dp;
|
||||
struct tftphdr *ap; /* ack packet */
|
||||
unsigned short block = 1;
|
||||
int size;
|
||||
ssize_t n;
|
||||
#if defined(HAVE_ALARM) && defined(SIGALRM)
|
||||
mysignal(SIGALRM, timer);
|
||||
#endif
|
||||
dp = r_init();
|
||||
ap = (struct tftphdr *)ackbuf;
|
||||
do {
|
||||
size = readit(test, &dp, pf->f_convert);
|
||||
if (size < 0) {
|
||||
nak(errno + 100);
|
||||
return;
|
||||
}
|
||||
dp->th_opcode = htons((u_short)DATA);
|
||||
dp->th_block = htons((u_short)block);
|
||||
timeout = 0;
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
(void) sigsetjmp(timeoutbuf, 1);
|
||||
#endif
|
||||
send_data:
|
||||
if (swrite(peer, dp, size + 4) != size + 4) {
|
||||
logmsg("write\n");
|
||||
return;
|
||||
}
|
||||
read_ahead(test, pf->f_convert);
|
||||
for ( ; ; ) {
|
||||
#ifdef HAVE_ALARM
|
||||
alarm(rexmtval); /* read the ack */
|
||||
#endif
|
||||
n = sread(peer, ackbuf, sizeof (ackbuf));
|
||||
#ifdef HAVE_ALARM
|
||||
alarm(0);
|
||||
#endif
|
||||
if (n < 0) {
|
||||
logmsg("read: fail\n");
|
||||
return;
|
||||
}
|
||||
ap->th_opcode = ntohs((u_short)ap->th_opcode);
|
||||
ap->th_block = ntohs((u_short)ap->th_block);
|
||||
|
||||
if (ap->th_opcode == ERROR) {
|
||||
logmsg("got ERROR");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ap->th_opcode == ACK) {
|
||||
if (ap->th_block == block) {
|
||||
break;
|
||||
}
|
||||
/* Re-synchronize with the other side */
|
||||
(void) synchnet(peer);
|
||||
if (ap->th_block == (block -1)) {
|
||||
goto send_data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
block++;
|
||||
} while (size == SEGSIZE);
|
||||
}
|
||||
|
||||
static void justquit(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Receive a file.
|
||||
*/
|
||||
static void recvtftp(struct testcase *test, struct formats *pf)
|
||||
{
|
||||
struct tftphdr *dp;
|
||||
struct tftphdr *ap; /* ack buffer */
|
||||
unsigned short block = 0;
|
||||
ssize_t n, size;
|
||||
#if defined(HAVE_ALARM) && defined(SIGALRM)
|
||||
mysignal(SIGALRM, timer);
|
||||
#endif
|
||||
dp = w_init();
|
||||
ap = (struct tftphdr *)ackbuf;
|
||||
do {
|
||||
timeout = 0;
|
||||
ap->th_opcode = htons((u_short)ACK);
|
||||
ap->th_block = htons((u_short)block);
|
||||
block++;
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
(void) sigsetjmp(timeoutbuf, 1);
|
||||
#endif
|
||||
send_ack:
|
||||
if (swrite(peer, ackbuf, 4) != 4) {
|
||||
logmsg("write: fail\n");
|
||||
goto abort;
|
||||
}
|
||||
write_behind(test, pf->f_convert);
|
||||
for ( ; ; ) {
|
||||
#ifdef HAVE_ALARM
|
||||
alarm(rexmtval);
|
||||
#endif
|
||||
n = sread(peer, dp, PKTSIZE);
|
||||
#ifdef HAVE_ALARM
|
||||
alarm(0);
|
||||
#endif
|
||||
if (n < 0) { /* really? */
|
||||
logmsg("read: fail\n");
|
||||
goto abort;
|
||||
}
|
||||
dp->th_opcode = ntohs((u_short)dp->th_opcode);
|
||||
dp->th_block = ntohs((u_short)dp->th_block);
|
||||
if (dp->th_opcode == ERROR)
|
||||
goto abort;
|
||||
if (dp->th_opcode == DATA) {
|
||||
if (dp->th_block == block) {
|
||||
break; /* normal */
|
||||
}
|
||||
/* Re-synchronize with the other side */
|
||||
(void) synchnet(peer);
|
||||
if (dp->th_block == (block-1))
|
||||
goto send_ack; /* rexmit */
|
||||
}
|
||||
}
|
||||
|
||||
size = writeit(test, &dp, (int)(n - 4), pf->f_convert);
|
||||
if (size != (n-4)) { /* ahem */
|
||||
if (size < 0)
|
||||
nak(errno + 100);
|
||||
else
|
||||
nak(ENOSPACE);
|
||||
goto abort;
|
||||
}
|
||||
} while (size == SEGSIZE);
|
||||
write_behind(test, pf->f_convert);
|
||||
|
||||
ap->th_opcode = htons((u_short)ACK); /* send the "final" ack */
|
||||
ap->th_block = htons((u_short)(block));
|
||||
(void) swrite(peer, ackbuf, 4);
|
||||
#if defined(HAVE_ALARM) && defined(SIGALRM)
|
||||
mysignal(SIGALRM, justquit); /* just quit on timeout */
|
||||
alarm(rexmtval);
|
||||
#endif
|
||||
n = sread(peer, buf, sizeof(buf)); /* normally times out and quits */
|
||||
#ifdef HAVE_ALARM
|
||||
alarm(0);
|
||||
#endif
|
||||
if (n >= 4 && /* if read some data */
|
||||
dp->th_opcode == DATA && /* and got a data block */
|
||||
block == dp->th_block) { /* then my last ack was lost */
|
||||
(void) swrite(peer, ackbuf, 4); /* resend final ack */
|
||||
}
|
||||
abort:
|
||||
return;
|
||||
}
|
||||
|
||||
struct errmsg {
|
||||
int e_code;
|
||||
const char *e_msg;
|
||||
} errmsgs[] = {
|
||||
{ EUNDEF, "Undefined error code" },
|
||||
{ ENOTFOUND, "File not found" },
|
||||
{ EACCESS, "Access violation" },
|
||||
{ ENOSPACE, "Disk full or allocation exceeded" },
|
||||
{ EBADOP, "Illegal TFTP operation" },
|
||||
{ EBADID, "Unknown transfer ID" },
|
||||
{ EEXISTS, "File already exists" },
|
||||
{ ENOUSER, "No such user" },
|
||||
{ -1, 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* Send a nak packet (error message). Error code passed in is one of the
|
||||
* standard TFTP codes, or a UNIX errno offset by 100.
|
||||
*/
|
||||
static void nak(int error)
|
||||
{
|
||||
struct tftphdr *tp;
|
||||
int length;
|
||||
struct errmsg *pe;
|
||||
|
||||
tp = (struct tftphdr *)buf;
|
||||
tp->th_opcode = htons((u_short)ERROR);
|
||||
tp->th_code = htons((u_short)error);
|
||||
for (pe = errmsgs; pe->e_code >= 0; pe++)
|
||||
if (pe->e_code == error)
|
||||
break;
|
||||
if (pe->e_code < 0) {
|
||||
pe->e_msg = strerror(error - 100);
|
||||
tp->th_code = EUNDEF; /* set 'undef' errorcode */
|
||||
}
|
||||
strcpy(tp->th_msg, pe->e_msg);
|
||||
length = (int)strlen(pe->e_msg);
|
||||
tp->th_msg[length] = '\0';
|
||||
length += 5;
|
||||
if (swrite(peer, buf, length) != length)
|
||||
logmsg("nak: fail\n");
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: util.c,v 1.11 2006-10-18 21:05:50 yangtse Exp $
|
||||
***************************************************************************/
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* make the curlx header define all printf() functions to use the curlx_*
|
||||
versions instead */
|
||||
#include "curlx.h" /* from the private lib dir */
|
||||
#include "getpart.h"
|
||||
#include "util.h"
|
||||
|
||||
#if defined(ENABLE_IPV6) && defined(__MINGW32__)
|
||||
const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* our_sockerrno() returns the *socket-related* errno (or equivalent) on this
|
||||
* platform to hide platform specific for the function that calls this.
|
||||
*/
|
||||
int our_sockerrno(void)
|
||||
{
|
||||
#ifdef USE_WINSOCK
|
||||
return (int)WSAGetLastError();
|
||||
#else
|
||||
return errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* someone else must set this properly */
|
||||
extern const char *serverlogfile;
|
||||
|
||||
void logmsg(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buffer[256]; /* possible overflow if you pass in a huge string */
|
||||
FILE *logfp;
|
||||
|
||||
struct timeval tv = curlx_tvnow();
|
||||
time_t sec = tv.tv_sec;
|
||||
struct tm *now =
|
||||
localtime(&sec); /* not multithread safe but we don't care */
|
||||
|
||||
char timebuf[20];
|
||||
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
|
||||
now->tm_hour, now->tm_min, now->tm_sec, tv.tv_usec);
|
||||
|
||||
va_start(ap, msg);
|
||||
vsprintf(buffer, msg, ap);
|
||||
va_end(ap);
|
||||
|
||||
logfp = fopen(serverlogfile, "a");
|
||||
if(logfp) {
|
||||
fprintf(logfp, "%s %s\n", timebuf, buffer);
|
||||
fclose(logfp);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
/* use instead of perror() on generic windows */
|
||||
void win32_perror (const char *msg)
|
||||
{
|
||||
char buf[256];
|
||||
DWORD err = WSAGetLastError();
|
||||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
||||
LANG_NEUTRAL, buf, sizeof(buf), NULL))
|
||||
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
|
||||
if (msg)
|
||||
fprintf(stderr, "%s: ", msg);
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
void win32_init(void)
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
|
||||
|
||||
err = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (err != 0) {
|
||||
perror("Winsock init failed");
|
||||
logmsg("Error initialising winsock -- aborting\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( LOBYTE( wsaData.wVersion ) != USE_WINSOCK ||
|
||||
HIBYTE( wsaData.wVersion ) != USE_WINSOCK ) {
|
||||
|
||||
WSACleanup();
|
||||
perror("Winsock init failed");
|
||||
logmsg("No suitable winsock.dll found -- aborting\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void win32_cleanup(void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* set by the main code to point to where the test dir is */
|
||||
const char *path=".";
|
||||
|
||||
char *test2file(long testno)
|
||||
{
|
||||
static char filename[256];
|
||||
snprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);
|
||||
return filename;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef __SERVER_UTIL_H
|
||||
#define __SERVER_UTIL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* $Id: util.h,v 1.9 2006-10-27 03:47:58 yangtse Exp $
|
||||
***************************************************************************/
|
||||
|
||||
int our_sockerrno(void);
|
||||
void logmsg(const char *msg, ...);
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#define TEST_DATA_PATH "%s/data/test%ld"
|
||||
|
||||
/* global variable, where to find the 'data' dir */
|
||||
extern const char *path;
|
||||
|
||||
#ifdef WIN32
|
||||
#include <process.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define sleep(sec) Sleep ((sec)*1000)
|
||||
|
||||
#undef perror
|
||||
#define perror(m) win32_perror(m)
|
||||
void win32_perror (const char *msg);
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EISCONN WSAEISCONN
|
||||
#define ENOTSOCK WSAENOTSOCK
|
||||
#define ECONNREFUSED WSAECONNREFUSED
|
||||
|
||||
void win32_init(void);
|
||||
void win32_cleanup(void);
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* returns the path name to the test case file */
|
||||
char *test2file(long testno);
|
||||
|
||||
#endif /* __SERVER_UTIL_H */
|
||||
Reference in new issue
Block a user