mirror of
https://github.com/curl/curl.git
synced 2026-08-26 05:43:31 +03:00
Initial revision
This commit is contained in:
commit
ae1912cb0d
144 changed files with 37273 additions and 0 deletions
282
lib/Makefile
Normal file
282
lib/Makefile
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
# Generated automatically from Makefile.in by configure.
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 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.
|
||||
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = ..
|
||||
prefix = /usr/local
|
||||
exec_prefix = ${prefix}
|
||||
|
||||
bindir = ${exec_prefix}/bin
|
||||
sbindir = ${exec_prefix}/sbin
|
||||
libexecdir = ${exec_prefix}/libexec
|
||||
datadir = ${prefix}/share
|
||||
sysconfdir = ${prefix}/etc
|
||||
sharedstatedir = ${prefix}/com
|
||||
localstatedir = ${prefix}/var
|
||||
libdir = ${exec_prefix}/lib
|
||||
infodir = ${prefix}/info
|
||||
mandir = ${prefix}/man
|
||||
includedir = ${prefix}/include
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/curl
|
||||
pkglibdir = $(libdir)/curl
|
||||
pkgincludedir = $(includedir)/curl
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
ACLOCAL = aclocal
|
||||
AUTOCONF = autoconf
|
||||
AUTOMAKE = automake
|
||||
AUTOHEADER = autoheader
|
||||
|
||||
INSTALL = .././install-sh -c
|
||||
INSTALL_PROGRAM = ${INSTALL} $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = ${INSTALL} -m 644
|
||||
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
|
||||
transform = s,x,x,
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
host_alias = sparc-sun-solaris2.6
|
||||
host_triplet = sparc-sun-solaris2.6
|
||||
CC = gcc
|
||||
MAKEINFO = makeinfo
|
||||
NROFF = /bin/nroff
|
||||
PACKAGE = curl
|
||||
PERL = /usr/local/bin/perl
|
||||
RANLIB = ranlib
|
||||
VERSION = 6.3.1
|
||||
YACC = bison -y
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies
|
||||
|
||||
noinst_LIBRARIES = libcurl.a
|
||||
|
||||
# Some flags needed when trying to cause warnings ;-)
|
||||
# CFLAGS = -Wall -pedantic
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
libcurl_a_SOURCES = arpa_telnet.h file.c getpass.h netrc.h timeval.c base64.c file.h hostip.c progress.c timeval.h base64.h formdata.c hostip.h progress.h upload.c cookie.c formdata.h http.c sendf.c upload.h cookie.h ftp.c http.h sendf.h url.c dict.c ftp.h if2ip.c speedcheck.c url.h dict.h getdate.c if2ip.h speedcheck.h urldata.h download.c getdate.h ldap.c ssluse.c version.c download.h getenv.c ldap.h ssluse.h escape.c getenv.h mprintf.c telnet.c escape.h getpass.c netrc.c telnet.h
|
||||
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../config.h ../src/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
|
||||
DEFS = -DHAVE_CONFIG_H -I. -I$(srcdir) -I.. -I../src
|
||||
CPPFLAGS = -I/home/dast/include/openssl -I/home/dast/include
|
||||
LDFLAGS =
|
||||
LIBS = -lssl -lcrypto -ldl -lsocket -lnsl -L/home/dast/lib
|
||||
libcurl_a_LIBADD =
|
||||
libcurl_a_OBJECTS = file.o timeval.o base64.o hostip.o progress.o \
|
||||
formdata.o upload.o cookie.o http.o sendf.o ftp.o url.o dict.o if2ip.o \
|
||||
speedcheck.o getdate.o download.o ldap.o ssluse.o version.o getenv.o \
|
||||
escape.o mprintf.o telnet.o getpass.o netrc.o
|
||||
AR = ar
|
||||
CFLAGS = -g -O2
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(libcurl_a_SOURCES)
|
||||
OBJECTS = $(libcurl_a_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .o .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps lib/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-noinstLIBRARIES:
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
|
||||
distclean-noinstLIBRARIES:
|
||||
|
||||
maintainer-clean-noinstLIBRARIES:
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
libcurl.a: $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
|
||||
-rm -f libcurl.a
|
||||
$(AR) cru libcurl.a $(libcurl_a_OBJECTS) $(libcurl_a_LIBADD)
|
||||
$(RANLIB) libcurl.a
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = lib
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am:
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am:
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am:
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(LIBRARIES)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
|
||||
mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-noinstLIBRARIES distclean-compile \
|
||||
distclean-tags distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
|
||||
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
|
||||
mostlyclean-compile distclean-compile clean-compile \
|
||||
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
|
||||
check-am installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Say $(srcdir), so GNU make does not report an ambiguity with the .y.c rule.
|
||||
$(srcdir)/getdate.c: getdate.y
|
||||
cd $(srcdir) && \
|
||||
$(YACC) $(YFLAGS) getdate.y; \
|
||||
mv -f y.tab.c getdate.c
|
||||
|
||||
# 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:
|
||||
31
lib/Makefile.am
Normal file
31
lib/Makefile.am
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies
|
||||
|
||||
noinst_LIBRARIES = libcurl.a
|
||||
|
||||
# Some flags needed when trying to cause warnings ;-)
|
||||
# CFLAGS = -Wall -pedantic
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
libcurl_a_SOURCES = \
|
||||
arpa_telnet.h file.c getpass.h netrc.h timeval.c \
|
||||
base64.c file.h hostip.c progress.c timeval.h \
|
||||
base64.h formdata.c hostip.h progress.h upload.c \
|
||||
cookie.c formdata.h http.c sendf.c upload.h \
|
||||
cookie.h ftp.c http.h sendf.h url.c \
|
||||
dict.c ftp.h if2ip.c speedcheck.c url.h \
|
||||
dict.h getdate.c if2ip.h speedcheck.h urldata.h \
|
||||
download.c getdate.h ldap.c ssluse.c version.c \
|
||||
download.h getenv.c ldap.h ssluse.h \
|
||||
escape.c getenv.h mprintf.c telnet.c \
|
||||
escape.h getpass.c netrc.c telnet.h
|
||||
|
||||
# Say $(srcdir), so GNU make does not report an ambiguity with the .y.c rule.
|
||||
$(srcdir)/getdate.c: getdate.y
|
||||
cd $(srcdir) && \
|
||||
$(YACC) $(YFLAGS) getdate.y; \
|
||||
mv -f y.tab.c getdate.c
|
||||
282
lib/Makefile.in
Normal file
282
lib/Makefile.in
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 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.
|
||||
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
host_alias = @host_alias@
|
||||
host_triplet = @host@
|
||||
CC = @CC@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
NROFF = @NROFF@
|
||||
PACKAGE = @PACKAGE@
|
||||
PERL = @PERL@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
YACC = @YACC@
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies
|
||||
|
||||
noinst_LIBRARIES = libcurl.a
|
||||
|
||||
# Some flags needed when trying to cause warnings ;-)
|
||||
# CFLAGS = -Wall -pedantic
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
libcurl_a_SOURCES = arpa_telnet.h file.c getpass.h netrc.h timeval.c base64.c file.h hostip.c progress.c timeval.h base64.h formdata.c hostip.h progress.h upload.c cookie.c formdata.h http.c sendf.c upload.h cookie.h ftp.c http.h sendf.h url.c dict.c ftp.h if2ip.c speedcheck.c url.h dict.h getdate.c if2ip.h speedcheck.h urldata.h download.c getdate.h ldap.c ssluse.c version.c download.h getenv.c ldap.h ssluse.h escape.c getenv.h mprintf.c telnet.c escape.h getpass.c netrc.c telnet.h
|
||||
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../config.h ../src/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I.. -I../src
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
libcurl_a_LIBADD =
|
||||
libcurl_a_OBJECTS = file.o timeval.o base64.o hostip.o progress.o \
|
||||
formdata.o upload.o cookie.o http.o sendf.o ftp.o url.o dict.o if2ip.o \
|
||||
speedcheck.o getdate.o download.o ldap.o ssluse.o version.o getenv.o \
|
||||
escape.o mprintf.o telnet.o getpass.o netrc.o
|
||||
AR = ar
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(libcurl_a_SOURCES)
|
||||
OBJECTS = $(libcurl_a_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .o .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps lib/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-noinstLIBRARIES:
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
|
||||
distclean-noinstLIBRARIES:
|
||||
|
||||
maintainer-clean-noinstLIBRARIES:
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
libcurl.a: $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
|
||||
-rm -f libcurl.a
|
||||
$(AR) cru libcurl.a $(libcurl_a_OBJECTS) $(libcurl_a_LIBADD)
|
||||
$(RANLIB) libcurl.a
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = lib
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am:
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am:
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am:
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(LIBRARIES)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
|
||||
mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-noinstLIBRARIES distclean-compile \
|
||||
distclean-tags distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
|
||||
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
|
||||
mostlyclean-compile distclean-compile clean-compile \
|
||||
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
|
||||
check-am installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Say $(srcdir), so GNU make does not report an ambiguity with the .y.c rule.
|
||||
$(srcdir)/getdate.c: getdate.y
|
||||
cd $(srcdir) && \
|
||||
$(YACC) $(YFLAGS) getdate.y; \
|
||||
mv -f y.tab.c getdate.c
|
||||
|
||||
# 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:
|
||||
67
lib/Makefile.m32
Normal file
67
lib/Makefile.m32
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#############################################################
|
||||
## Makefile for building libcurl.a with MingW32 (GCC-2.95) and
|
||||
## optionally OpenSSL (0.9.4)
|
||||
## Use: make -f Makefile.m32
|
||||
##
|
||||
## Comments to: Troy Engel <tengel@sonic.net> or
|
||||
## Joern Hartroth <hartroth@acm.org>
|
||||
|
||||
CC = gcc
|
||||
AR = ar
|
||||
RANLIB = ranlib
|
||||
OPENSSL_PATH = ../../openssl-0.9.4
|
||||
|
||||
########################################################
|
||||
## Nothing more to do below this line!
|
||||
|
||||
INCLUDES = -I. -I.. -I../include
|
||||
CFLAGS = -g -O2
|
||||
ifdef SSL
|
||||
INCLUDES += -I"$(OPENSSL_PATH)/outinc" -I"$(OPENSSL_PATH)/outinc/openssl"
|
||||
CFLAGS += -DUSE_SSLEAY
|
||||
endif
|
||||
COMPILE = $(CC) $(INCLUDES) $(CFLAGS)
|
||||
|
||||
libcurl_a_LIBRARIES = libcurl.a
|
||||
|
||||
libcurl_a_SOURCES = base64.c getenv.c if2ip.h progress.h upload.h \
|
||||
base64.h getenv.h mprintf.c setup.h url.c download.c getpass.c \
|
||||
mprintf.h ssluse.c url.h download.h hostip.c netrc.c ssluse.h \
|
||||
urldata.h formdata.c hostip.h netrc.h stdcheaders.h formdata.h \
|
||||
if2ip.c progress.c upload.c sendf.c sendf.h speedcheck.c speedcheck.h \
|
||||
ftp.c ftp.h getpass.c getpass.h version.c timeval.c timeval.h cookie.c \
|
||||
cookie.h escape.c escape.h getdate.c getdate.h dict.h dict.c http.c \
|
||||
http.h telnet.c telnet.h file.c file.h ldap.c ldap.h
|
||||
|
||||
libcurl_a_OBJECTS = base64.o getenv.o mprintf.o url.o download.o \
|
||||
getpass.o ssluse.o hostip.o netrc.o formdata.o if2ip.o progress.o \
|
||||
upload.o sendf.o speedcheck.o ftp.o getpass.o version.o timeval.o \
|
||||
cookie.o escape.o getdate.o dict.o http.o telnet.o file.o ldap.o
|
||||
|
||||
LIBRARIES = $(libcurl_a_LIBRARIES)
|
||||
SOURCES = $(libcurl_a_SOURCES)
|
||||
OBJECTS = $(libcurl_a_OBJECTS)
|
||||
|
||||
|
||||
all: libcurl.a
|
||||
|
||||
libcurl.a: $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
|
||||
-@erase libcurl.a
|
||||
$(AR) cru libcurl.a $(libcurl_a_OBJECTS)
|
||||
$(RANLIB) libcurl.a
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
clean:
|
||||
-@erase $(libcurl_a_OBJECTS)
|
||||
|
||||
distrib: clean
|
||||
-@erase $(libcurl_a_LIBRARIES)
|
||||
|
||||
315
lib/Makefile.vc6
Normal file
315
lib/Makefile.vc6
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
#############################################################
|
||||
## Makefile for building libcurl.lib with MSVC6
|
||||
## Use: nmake -f makefile.vc6 [release | release-ssl | debug]
|
||||
## (default is release)
|
||||
##
|
||||
## Comments to: Troy Engel <tengel@sonic.net>
|
||||
|
||||
PROGRAM_NAME = libcurl.lib
|
||||
OPENSSL_PATH = ../../openssl-0.9.3a
|
||||
|
||||
########################################################
|
||||
## Nothing more to do below this line!
|
||||
|
||||
## Release
|
||||
CCR = cl.exe /ML /O2 /D "NDEBUG"
|
||||
LINKR = link.exe -lib
|
||||
|
||||
## Debug
|
||||
CCD = cl.exe /MLd /Gm /ZI /Od /D "_DEBUG" /GZ
|
||||
LINKD = link.exe -lib
|
||||
|
||||
## SSL Release
|
||||
CCRS = cl.exe /ML /O2 /D "NDEBUG" /D "USE_SSLEAY" /I "$(OPENSSL_PATH)/inc32" /I "$(OPENSSL_PATH)/inc32/openssl"
|
||||
LINKRS = link.exe -lib /LIBPATH:$(OPENSSL_PATH)/out32dll
|
||||
|
||||
CFLAGS = /nologo /W3 /GX /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
LFLAGS = /nologo /out:$(PROGRAM_NAME)
|
||||
LINKLIBS = kernel32.lib wsock32.lib
|
||||
LINKSLIBS = libeay32.lib ssleay32.lib RSAglue.lib
|
||||
|
||||
RELEASE_OBJS= \
|
||||
base64r.obj \
|
||||
cookier.obj \
|
||||
downloadr.obj \
|
||||
escaper.obj \
|
||||
formdatar.obj \
|
||||
ftpr.obj \
|
||||
httpr.obj \
|
||||
dictr.obj \
|
||||
telnetr.obj \
|
||||
getdater.obj \
|
||||
getenvr.obj \
|
||||
getpassr.obj \
|
||||
hostipr.obj \
|
||||
if2ipr.obj \
|
||||
mprintfr.obj \
|
||||
netrcr.obj \
|
||||
progressr.obj \
|
||||
sendfr.obj \
|
||||
speedcheckr.obj \
|
||||
ssluser.obj \
|
||||
timevalr.obj \
|
||||
uploadr.obj \
|
||||
urlr.obj \
|
||||
filer.obj \
|
||||
versionr.obj
|
||||
|
||||
DEBUG_OBJS= \
|
||||
base64d.obj \
|
||||
cookied.obj \
|
||||
downloadd.obj \
|
||||
escaped.obj \
|
||||
formdatad.obj \
|
||||
ftpd.obj \
|
||||
httpd.obj \
|
||||
dictd.obj \
|
||||
telnetd.obj \
|
||||
getdated.obj \
|
||||
getenvd.obj \
|
||||
getpassd.obj \
|
||||
hostipd.obj \
|
||||
if2ipd.obj \
|
||||
mprintfd.obj \
|
||||
netrcd.obj \
|
||||
progressd.obj \
|
||||
sendfd.obj \
|
||||
speedcheckd.obj \
|
||||
sslused.obj \
|
||||
timevald.obj \
|
||||
uploadd.obj \
|
||||
urld.obj \
|
||||
filed.obj \
|
||||
versiond.obj
|
||||
|
||||
RELEASE_SSL_OBJS= \
|
||||
base64rs.obj \
|
||||
cookiers.obj \
|
||||
downloadrs.obj \
|
||||
escapers.obj \
|
||||
formdatars.obj \
|
||||
ftprs.obj \
|
||||
httprs.obj \
|
||||
dictrs.obj \
|
||||
telnetrs.obj \
|
||||
getdaters.obj \
|
||||
getenvrs.obj \
|
||||
getpassrs.obj \
|
||||
hostiprs.obj \
|
||||
if2iprs.obj \
|
||||
mprintfrs.obj \
|
||||
netrcrs.obj \
|
||||
progressrs.obj \
|
||||
sendfrs.obj \
|
||||
speedcheckrs.obj \
|
||||
sslusers.obj \
|
||||
timevalrs.obj \
|
||||
uploadrs.obj \
|
||||
urlrs.obj \
|
||||
filers.obj \
|
||||
versionrs.obj
|
||||
|
||||
LINK_OBJS= \
|
||||
base64.obj \
|
||||
cookie.obj \
|
||||
download.obj \
|
||||
escape.obj \
|
||||
formdata.obj \
|
||||
ftp.obj \
|
||||
http.obj \
|
||||
dict.obj \
|
||||
telnet.obj \
|
||||
getdate.obj \
|
||||
getenv.obj \
|
||||
getpass.obj \
|
||||
hostip.obj \
|
||||
if2ip.obj \
|
||||
mprintf.obj \
|
||||
netrc.obj \
|
||||
progress.obj \
|
||||
sendf.obj \
|
||||
speedcheck.obj \
|
||||
ssluse.obj \
|
||||
timeval.obj \
|
||||
upload.obj \
|
||||
url.obj \
|
||||
file.obj \
|
||||
version.obj
|
||||
|
||||
all : release
|
||||
|
||||
release: $(RELEASE_OBJS)
|
||||
$(LINKR) $(LFLAGS) $(LINKLIBS) $(LINK_OBJS)
|
||||
|
||||
debug: $(DEBUG_OBJS)
|
||||
$(LINKD) $(LFLAGS) $(LINKLIBS) $(LINK_OBJS)
|
||||
|
||||
release-ssl: $(RELEASE_SSL_OBJS)
|
||||
$(LINKRS) $(LFLAGS) $(LINKLIBS) $(LINKSLIBS) $(LINK_OBJS)
|
||||
|
||||
|
||||
## Release
|
||||
base64r.obj: base64.c
|
||||
$(CCR) $(CFLAGS) base64.c
|
||||
cookier.obj: cookie.c
|
||||
$(CCR) $(CFLAGS) cookie.c
|
||||
downloadr.obj: download.c
|
||||
$(CCR) $(CFLAGS) download.c
|
||||
escaper.obj: escape.c
|
||||
$(CCR) $(CFLAGS) escape.c
|
||||
formdatar.obj: formdata.c
|
||||
$(CCR) $(CFLAGS) formdata.c
|
||||
ftpr.obj: ftp.c
|
||||
$(CCR) $(CFLAGS) ftp.c
|
||||
httpr.obj: http.c
|
||||
$(CCR) $(CFLAGS) http.c
|
||||
dictr.obj: dict.c
|
||||
$(CCR) $(CFLAGS) dict.c
|
||||
telnetr.obj: telnet.c
|
||||
$(CCR) $(CFLAGS) telnet.c
|
||||
getdater.obj: getdate.c
|
||||
$(CCR) $(CFLAGS) getdate.c
|
||||
getenvr.obj: getenv.c
|
||||
$(CCR) $(CFLAGS) getenv.c
|
||||
getpassr.obj: getpass.c
|
||||
$(CCR) $(CFLAGS) getpass.c
|
||||
hostipr.obj: hostip.c
|
||||
$(CCR) $(CFLAGS) hostip.c
|
||||
if2ipr.obj: if2ip.c
|
||||
$(CCR) $(CFLAGS) if2ip.c
|
||||
mprintfr.obj: mprintf.c
|
||||
$(CCR) $(CFLAGS) mprintf.c
|
||||
netrcr.obj: netrc.c
|
||||
$(CCR) $(CFLAGS) netrc.c
|
||||
progressr.obj: progress.c
|
||||
$(CCR) $(CFLAGS) progress.c
|
||||
sendfr.obj: sendf.c
|
||||
$(CCR) $(CFLAGS) sendf.c
|
||||
speedcheckr.obj: speedcheck.c
|
||||
$(CCR) $(CFLAGS) speedcheck.c
|
||||
ssluser.obj: ssluse.c
|
||||
$(CCR) $(CFLAGS) ssluse.c
|
||||
timevalr.obj: timeval.c
|
||||
$(CCR) $(CFLAGS) timeval.c
|
||||
uploadr.obj: upload.c
|
||||
$(CCR) $(CFLAGS) upload.c
|
||||
urlr.obj: url.c
|
||||
$(CCR) $(CFLAGS) url.c
|
||||
filer.obj: file.c
|
||||
$(CCR) $(CFLAGS) file.c
|
||||
versionr.obj: version.c
|
||||
$(CCR) $(CFLAGS) version.c
|
||||
|
||||
## Debug
|
||||
base64d.obj: base64.c
|
||||
$(CCD) $(CFLAGS) base64.c
|
||||
cookied.obj: cookie.c
|
||||
$(CCD) $(CFLAGS) cookie.c
|
||||
downloadd.obj: download.c
|
||||
$(CCD) $(CFLAGS) download.c
|
||||
escaped.obj: escape.c
|
||||
$(CCD) $(CFLAGS) escape.c
|
||||
formdatad.obj: formdata.c
|
||||
$(CCD) $(CFLAGS) formdata.c
|
||||
ftpd.obj: ftp.c
|
||||
$(CCD) $(CFLAGS) ftp.c
|
||||
httpd.obj: http.c
|
||||
$(CCD) $(CFLAGS) http.c
|
||||
dictd.obj: dict.c
|
||||
$(CCD) $(CFLAGS) dict.c
|
||||
telnetd.obj: telnet.c
|
||||
$(CCD) $(CFLAGS) telnet.c
|
||||
getdated.obj: getdate.c
|
||||
$(CCD) $(CFLAGS) getdate.c
|
||||
getenvd.obj: getenv.c
|
||||
$(CCD) $(CFLAGS) getenv.c
|
||||
getpassd.obj: getpass.c
|
||||
$(CCD) $(CFLAGS) getpass.c
|
||||
hostipd.obj: hostip.c
|
||||
$(CCD) $(CFLAGS) hostip.c
|
||||
if2ipd.obj: if2ip.c
|
||||
$(CCD) $(CFLAGS) if2ip.c
|
||||
mprintfd.obj: mprintf.c
|
||||
$(CCD) $(CFLAGS) mprintf.c
|
||||
netrcd.obj: netrc.c
|
||||
$(CCD) $(CFLAGS) netrc.c
|
||||
progressd.obj: progress.c
|
||||
$(CCD) $(CFLAGS) progress.c
|
||||
sendfd.obj: sendf.c
|
||||
$(CCD) $(CFLAGS) sendf.c
|
||||
speedcheckd.obj: speedcheck.c
|
||||
$(CCD) $(CFLAGS) speedcheck.c
|
||||
sslused.obj: ssluse.c
|
||||
$(CCD) $(CFLAGS) ssluse.c
|
||||
timevald.obj: timeval.c
|
||||
$(CCD) $(CFLAGS) timeval.c
|
||||
uploadd.obj: upload.c
|
||||
$(CCD) $(CFLAGS) upload.c
|
||||
urld.obj: url.c
|
||||
$(CCD) $(CFLAGS) url.c
|
||||
filed.obj: file.c
|
||||
$(CCD) $(CFLAGS) file.c
|
||||
versiond.obj: version.c
|
||||
$(CCD) $(CFLAGS) version.c
|
||||
|
||||
|
||||
## Release SSL
|
||||
base64rs.obj: base64.c
|
||||
$(CCRS) $(CFLAGS) base64.c
|
||||
cookiers.obj: cookie.c
|
||||
$(CCRS) $(CFLAGS) cookie.c
|
||||
downloadrs.obj: download.c
|
||||
$(CCRS) $(CFLAGS) download.c
|
||||
escapers.obj: escape.c
|
||||
$(CCRS) $(CFLAGS) escape.c
|
||||
formdatars.obj: formdata.c
|
||||
$(CCRS) $(CFLAGS) formdata.c
|
||||
ftprs.obj: ftp.c
|
||||
$(CCRS) $(CFLAGS) ftp.c
|
||||
httprs.obj: http.c
|
||||
$(CCRS) $(CFLAGS) http.c
|
||||
dictrs.obj: dict.c
|
||||
$(CCRS) $(CFLAGS) dict.c
|
||||
telnetrs.obj: telnet.c
|
||||
$(CCRS) $(CFLAGS) telnet.c
|
||||
getdaters.obj: getdate.c
|
||||
$(CCRS) $(CFLAGS) getdate.c
|
||||
getenvrs.obj: getenv.c
|
||||
$(CCRS) $(CFLAGS) getenv.c
|
||||
getpassrs.obj: getpass.c
|
||||
$(CCRS) $(CFLAGS) getpass.c
|
||||
hostiprs.obj: hostip.c
|
||||
$(CCRS) $(CFLAGS) hostip.c
|
||||
if2iprs.obj: if2ip.c
|
||||
$(CCRS) $(CFLAGS) if2ip.c
|
||||
mprintfrs.obj: mprintf.c
|
||||
$(CCRS) $(CFLAGS) mprintf.c
|
||||
netrcrs.obj: netrc.c
|
||||
$(CCRS) $(CFLAGS) netrc.c
|
||||
progressrs.obj: progress.c
|
||||
$(CCRS) $(CFLAGS) progress.c
|
||||
sendfrs.obj: sendf.c
|
||||
$(CCRS) $(CFLAGS) sendf.c
|
||||
speedcheckrs.obj: speedcheck.c
|
||||
$(CCRS) $(CFLAGS) speedcheck.c
|
||||
sslusers.obj: ssluse.c
|
||||
$(CCRS) $(CFLAGS) ssluse.c
|
||||
timevalrs.obj: timeval.c
|
||||
$(CCRS) $(CFLAGS) timeval.c
|
||||
uploadrs.obj: upload.c
|
||||
$(CCRS) $(CFLAGS) upload.c
|
||||
urlrs.obj: url.c
|
||||
$(CCRS) $(CFLAGS) url.c
|
||||
filers.obj: file.c
|
||||
$(CCRS) $(CFLAGS) file.c
|
||||
versionrs.obj: version.c
|
||||
$(CCRS) $(CFLAGS) version.c
|
||||
|
||||
clean:
|
||||
-@erase *.obj
|
||||
-@erase vc60.idb
|
||||
-@erase vc60.pch
|
||||
|
||||
distrib: clean
|
||||
-@erase $(PROGRAM_NAME)
|
||||
|
||||
319
lib/arpa_telnet.h
Normal file
319
lib/arpa_telnet.h
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* The 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.
|
||||
*
|
||||
* @(#)telnet.h 8.2 (Berkeley) 12/15/93
|
||||
*/
|
||||
|
||||
#ifndef _ARPA_TELNET_H
|
||||
#define _ARPA_TELNET_H
|
||||
|
||||
/*
|
||||
* Definitions for the TELNET protocol.
|
||||
*/
|
||||
#define IAC 255 /* interpret as command: */
|
||||
#define DONT 254 /* you are not to use option */
|
||||
#define DO 253 /* please, you use option */
|
||||
#define WONT 252 /* I won't use option */
|
||||
#define WILL 251 /* I will use option */
|
||||
#define SB 250 /* interpret as subnegotiation */
|
||||
#define GA 249 /* you may reverse the line */
|
||||
#define EL 248 /* erase the current line */
|
||||
#define EC 247 /* erase the current character */
|
||||
#define AYT 246 /* are you there */
|
||||
#define AO 245 /* abort output--but let prog finish */
|
||||
#define IP 244 /* interrupt process--permanently */
|
||||
#define BREAK 243 /* break */
|
||||
#define DM 242 /* data mark--for connect. cleaning */
|
||||
#define NOP 241 /* nop */
|
||||
#define SE 240 /* end sub negotiation */
|
||||
#define EOR 239 /* end of record (transparent mode) */
|
||||
#define ABORT 238 /* Abort process */
|
||||
#define SUSP 237 /* Suspend process */
|
||||
#define xEOF 236 /* End of file: EOF is already used... */
|
||||
|
||||
#define SYNCH 242 /* for telfunc calls */
|
||||
|
||||
#ifdef TELCMDS
|
||||
char *telcmds[] = {
|
||||
"EOF", "SUSP", "ABORT", "EOR",
|
||||
"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
|
||||
"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
|
||||
};
|
||||
#else
|
||||
extern char *telcmds[];
|
||||
#endif
|
||||
|
||||
#define TELCMD_FIRST xEOF
|
||||
#define TELCMD_LAST IAC
|
||||
#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
|
||||
(unsigned int)(x) >= TELCMD_FIRST)
|
||||
#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
|
||||
|
||||
/* telnet options */
|
||||
#define TELOPT_BINARY 0 /* 8-bit data path */
|
||||
#define TELOPT_ECHO 1 /* echo */
|
||||
#define TELOPT_RCP 2 /* prepare to reconnect */
|
||||
#define TELOPT_SGA 3 /* suppress go ahead */
|
||||
#define TELOPT_NAMS 4 /* approximate message size */
|
||||
#define TELOPT_STATUS 5 /* give status */
|
||||
#define TELOPT_TM 6 /* timing mark */
|
||||
#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
|
||||
#define TELOPT_NAOL 8 /* negotiate about output line width */
|
||||
#define TELOPT_NAOP 9 /* negotiate about output page size */
|
||||
#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
|
||||
#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
|
||||
#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
|
||||
#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
|
||||
#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
|
||||
#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
|
||||
#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
|
||||
#define TELOPT_XASCII 17 /* extended ascic character set */
|
||||
#define TELOPT_LOGOUT 18 /* force logout */
|
||||
#define TELOPT_BM 19 /* byte macro */
|
||||
#define TELOPT_DET 20 /* data entry terminal */
|
||||
#define TELOPT_SUPDUP 21 /* supdup protocol */
|
||||
#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
|
||||
#define TELOPT_SNDLOC 23 /* send location */
|
||||
#define TELOPT_TTYPE 24 /* terminal type */
|
||||
#define TELOPT_EOR 25 /* end or record */
|
||||
#define TELOPT_TUID 26 /* TACACS user identification */
|
||||
#define TELOPT_OUTMRK 27 /* output marking */
|
||||
#define TELOPT_TTYLOC 28 /* terminal location number */
|
||||
#define TELOPT_3270REGIME 29 /* 3270 regime */
|
||||
#define TELOPT_X3PAD 30 /* X.3 PAD */
|
||||
#define TELOPT_NAWS 31 /* window size */
|
||||
#define TELOPT_TSPEED 32 /* terminal speed */
|
||||
#define TELOPT_LFLOW 33 /* remote flow control */
|
||||
#define TELOPT_LINEMODE 34 /* Linemode option */
|
||||
#define TELOPT_XDISPLOC 35 /* X Display Location */
|
||||
#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
|
||||
#define TELOPT_AUTHENTICATION 37/* Authenticate */
|
||||
#define TELOPT_ENCRYPT 38 /* Encryption option */
|
||||
#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
|
||||
#define TELOPT_EXOPL 255 /* extended-options-list */
|
||||
|
||||
|
||||
#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
|
||||
#ifdef TELOPTS
|
||||
char *telopts[NTELOPTS+1] = {
|
||||
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
|
||||
"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
|
||||
"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
|
||||
"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
|
||||
"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
|
||||
"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
|
||||
"TACACS UID", "OUTPUT MARKING", "TTYLOC",
|
||||
"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
|
||||
"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
|
||||
"ENCRYPT", "NEW-ENVIRON",
|
||||
0,
|
||||
};
|
||||
#define TELOPT_FIRST TELOPT_BINARY
|
||||
#define TELOPT_LAST TELOPT_NEW_ENVIRON
|
||||
#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
|
||||
#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
|
||||
#endif
|
||||
|
||||
/* sub-option qualifiers */
|
||||
#define TELQUAL_IS 0 /* option is... */
|
||||
#define TELQUAL_SEND 1 /* send option */
|
||||
#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
|
||||
#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
|
||||
#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
|
||||
|
||||
#define LFLOW_OFF 0 /* Disable remote flow control */
|
||||
#define LFLOW_ON 1 /* Enable remote flow control */
|
||||
#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
|
||||
#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
|
||||
|
||||
/*
|
||||
* LINEMODE suboptions
|
||||
*/
|
||||
|
||||
#define LM_MODE 1
|
||||
#define LM_FORWARDMASK 2
|
||||
#define LM_SLC 3
|
||||
|
||||
#define MODE_EDIT 0x01
|
||||
#define MODE_TRAPSIG 0x02
|
||||
#define MODE_ACK 0x04
|
||||
#define MODE_SOFT_TAB 0x08
|
||||
#define MODE_LIT_ECHO 0x10
|
||||
|
||||
#define MODE_MASK 0x1f
|
||||
|
||||
/* Not part of protocol, but needed to simplify things... */
|
||||
#define MODE_FLOW 0x0100
|
||||
#define MODE_ECHO 0x0200
|
||||
#define MODE_INBIN 0x0400
|
||||
#define MODE_OUTBIN 0x0800
|
||||
#define MODE_FORCE 0x1000
|
||||
|
||||
#define SLC_SYNCH 1
|
||||
#define SLC_BRK 2
|
||||
#define SLC_IP 3
|
||||
#define SLC_AO 4
|
||||
#define SLC_AYT 5
|
||||
#define SLC_EOR 6
|
||||
#define SLC_ABORT 7
|
||||
#define SLC_EOF 8
|
||||
#define SLC_SUSP 9
|
||||
#define SLC_EC 10
|
||||
#define SLC_EL 11
|
||||
#define SLC_EW 12
|
||||
#define SLC_RP 13
|
||||
#define SLC_LNEXT 14
|
||||
#define SLC_XON 15
|
||||
#define SLC_XOFF 16
|
||||
#define SLC_FORW1 17
|
||||
#define SLC_FORW2 18
|
||||
|
||||
#define NSLC 18
|
||||
|
||||
/*
|
||||
* For backwards compatability, we define SLC_NAMES to be the
|
||||
* list of names if SLC_NAMES is not defined.
|
||||
*/
|
||||
#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
|
||||
"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
|
||||
"LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0,
|
||||
#ifdef SLC_NAMES
|
||||
char *slc_names[] = {
|
||||
SLC_NAMELIST
|
||||
};
|
||||
#else
|
||||
extern char *slc_names[];
|
||||
#define SLC_NAMES SLC_NAMELIST
|
||||
#endif
|
||||
|
||||
#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC)
|
||||
#define SLC_NAME(x) slc_names[x]
|
||||
|
||||
#define SLC_NOSUPPORT 0
|
||||
#define SLC_CANTCHANGE 1
|
||||
#define SLC_VARIABLE 2
|
||||
#define SLC_DEFAULT 3
|
||||
#define SLC_LEVELBITS 0x03
|
||||
|
||||
#define SLC_FUNC 0
|
||||
#define SLC_FLAGS 1
|
||||
#define SLC_VALUE 2
|
||||
|
||||
#define SLC_ACK 0x80
|
||||
#define SLC_FLUSHIN 0x40
|
||||
#define SLC_FLUSHOUT 0x20
|
||||
|
||||
#define OLD_ENV_VAR 1
|
||||
#define OLD_ENV_VALUE 0
|
||||
#define NEW_ENV_VAR 0
|
||||
#define NEW_ENV_VALUE 1
|
||||
#define ENV_ESC 2
|
||||
#define ENV_USERVAR 3
|
||||
|
||||
/*
|
||||
* AUTHENTICATION suboptions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Who is authenticating who ...
|
||||
*/
|
||||
#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
|
||||
#define AUTH_WHO_SERVER 1 /* Server authenticating client */
|
||||
#define AUTH_WHO_MASK 1
|
||||
|
||||
/*
|
||||
* amount of authentication done
|
||||
*/
|
||||
#define AUTH_HOW_ONE_WAY 0
|
||||
#define AUTH_HOW_MUTUAL 2
|
||||
#define AUTH_HOW_MASK 2
|
||||
|
||||
#define AUTHTYPE_NULL 0
|
||||
#define AUTHTYPE_KERBEROS_V4 1
|
||||
#define AUTHTYPE_KERBEROS_V5 2
|
||||
#define AUTHTYPE_SPX 3
|
||||
#define AUTHTYPE_MINK 4
|
||||
#define AUTHTYPE_CNT 5
|
||||
|
||||
#define AUTHTYPE_TEST 99
|
||||
|
||||
#ifdef AUTH_NAMES
|
||||
char *authtype_names[] = {
|
||||
"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0,
|
||||
};
|
||||
#else
|
||||
extern char *authtype_names[];
|
||||
#endif
|
||||
|
||||
#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
|
||||
#define AUTHTYPE_NAME(x) authtype_names[x]
|
||||
|
||||
/*
|
||||
* ENCRYPTion suboptions
|
||||
*/
|
||||
#define ENCRYPT_IS 0 /* I pick encryption type ... */
|
||||
#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
|
||||
#define ENCRYPT_REPLY 2 /* Initial setup response */
|
||||
#define ENCRYPT_START 3 /* Am starting to send encrypted */
|
||||
#define ENCRYPT_END 4 /* Am ending encrypted */
|
||||
#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
|
||||
#define ENCRYPT_REQEND 6 /* Request you send encrypting */
|
||||
#define ENCRYPT_ENC_KEYID 7
|
||||
#define ENCRYPT_DEC_KEYID 8
|
||||
#define ENCRYPT_CNT 9
|
||||
|
||||
#define ENCTYPE_ANY 0
|
||||
#define ENCTYPE_DES_CFB64 1
|
||||
#define ENCTYPE_DES_OFB64 2
|
||||
#define ENCTYPE_CNT 3
|
||||
|
||||
#ifdef ENCRYPT_NAMES
|
||||
char *encrypt_names[] = {
|
||||
"IS", "SUPPORT", "REPLY", "START", "END",
|
||||
"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
|
||||
0,
|
||||
};
|
||||
char *enctype_names[] = {
|
||||
"ANY", "DES_CFB64", "DES_OFB64", 0,
|
||||
};
|
||||
#else
|
||||
extern char *encrypt_names[];
|
||||
extern char *enctype_names[];
|
||||
#endif
|
||||
|
||||
|
||||
#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
|
||||
#define ENCRYPT_NAME(x) encrypt_names[x]
|
||||
|
||||
#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
|
||||
#define ENCTYPE_NAME(x) enctype_names[x]
|
||||
#endif /* _ARPA_TELNET_H */
|
||||
94
lib/base64.c
Normal file
94
lib/base64.c
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* ---- Base64 Encoding --- */
|
||||
static char table64[]=
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
void base64Encode(char *intext, char *output)
|
||||
{
|
||||
unsigned char ibuf[3];
|
||||
unsigned char obuf[4];
|
||||
int i;
|
||||
int inputparts;
|
||||
|
||||
while(*intext) {
|
||||
for (i = inputparts = 0; i < 3; i++) {
|
||||
if(*intext) {
|
||||
inputparts++;
|
||||
ibuf[i] = *intext;
|
||||
intext++;
|
||||
}
|
||||
else
|
||||
ibuf[i] = 0;
|
||||
}
|
||||
|
||||
obuf [0] = (ibuf [0] & 0xFC) >> 2;
|
||||
obuf [1] = ((ibuf [0] & 0x03) << 4) | ((ibuf [1] & 0xF0) >> 4);
|
||||
obuf [2] = ((ibuf [1] & 0x0F) << 2) | ((ibuf [2] & 0xC0) >> 6);
|
||||
obuf [3] = ibuf [2] & 0x3F;
|
||||
|
||||
switch(inputparts) {
|
||||
case 1: /* only one byte read */
|
||||
sprintf(output, "%c%c==",
|
||||
table64[obuf[0]],
|
||||
table64[obuf[1]]);
|
||||
break;
|
||||
case 2: /* two bytes read */
|
||||
sprintf(output, "%c%c%c=",
|
||||
table64[obuf[0]],
|
||||
table64[obuf[1]],
|
||||
table64[obuf[2]]);
|
||||
break;
|
||||
default:
|
||||
sprintf(output, "%c%c%c%c",
|
||||
table64[obuf[0]],
|
||||
table64[obuf[1]],
|
||||
table64[obuf[2]],
|
||||
table64[obuf[3]] );
|
||||
break;
|
||||
}
|
||||
output += 4;
|
||||
}
|
||||
*output=0;
|
||||
}
|
||||
/* ---- End of Base64 Encoding ---- */
|
||||
44
lib/base64.h
Normal file
44
lib/base64.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef __BASE64_H
|
||||
#define __BASE64_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
void base64Encode(char *intext, char *output);
|
||||
#endif
|
||||
457
lib/cookie.c
Normal file
457
lib/cookie.c
Normal file
|
|
@ -0,0 +1,457 @@
|
|||
|
||||
/***
|
||||
|
||||
|
||||
RECEIVING COOKIE INFORMATION
|
||||
============================
|
||||
|
||||
struct CookieInfo *cookie_init(char *file);
|
||||
|
||||
Inits a cookie struct to store data in a local file. This is always
|
||||
called before any cookies are set.
|
||||
|
||||
int cookies_set(struct CookieInfo *cookie, char *cookie_line);
|
||||
|
||||
The 'cookie_line' parameter is a full "Set-cookie:" line as
|
||||
received from a server.
|
||||
|
||||
The function need to replace previously stored lines that this new
|
||||
line superceeds.
|
||||
|
||||
It may remove lines that are expired.
|
||||
|
||||
It should return an indication of success/error.
|
||||
|
||||
|
||||
SENDING COOKIE INFORMATION
|
||||
==========================
|
||||
|
||||
struct Cookies *cookie_getlist(struct CookieInfo *cookie,
|
||||
char *host, char *path, bool secure);
|
||||
|
||||
For a given host and path, return a linked list of cookies that
|
||||
the client should send to the server if used now. The secure
|
||||
boolean informs the cookie if a secure connection is achieved or
|
||||
not.
|
||||
|
||||
It shall only return cookies that haven't expired.
|
||||
|
||||
|
||||
Example set of cookies:
|
||||
|
||||
Set-cookie: PRODUCTINFO=webxpress; domain=.fidelity.com; path=/; secure
|
||||
Set-cookie: PERSONALIZE=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
||||
domain=.fidelity.com; path=/ftgw; secure
|
||||
Set-cookie: FidHist=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
||||
domain=.fidelity.com; path=/; secure
|
||||
Set-cookie: FidOrder=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
||||
domain=.fidelity.com; path=/; secure
|
||||
Set-cookie: DisPend=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
||||
domain=.fidelity.com; path=/; secure
|
||||
Set-cookie: FidDis=none;expires=Monday, 13-Jun-1988 03:04:55 GMT;
|
||||
domain=.fidelity.com; path=/; secure
|
||||
Set-cookie:
|
||||
Session_Key@6791a9e0-901a-11d0-a1c8-9b012c88aa77=none;expires=Monday,
|
||||
13-Jun-1988 03:04:55 GMT; domain=.fidelity.com; path=/; secure
|
||||
****/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cookie.h"
|
||||
#include "setup.h"
|
||||
#include "getdate.h"
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* cookie_add()
|
||||
*
|
||||
* Add a single cookie line to the cookie keeping object.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
struct Cookie *cookie_add(struct CookieInfo *c,
|
||||
bool httpheader, /* TRUE if HTTP header-style line */
|
||||
char *lineptr) /* first non-space of the line */
|
||||
{
|
||||
struct Cookie *clist;
|
||||
char what[MAX_COOKIE_LINE];
|
||||
char name[MAX_NAME];
|
||||
char *ptr;
|
||||
char *semiptr;
|
||||
struct Cookie *co;
|
||||
time_t now = time(NULL);
|
||||
bool replace_old = FALSE;
|
||||
|
||||
/* First, alloc and init a new struct for it */
|
||||
co = (struct Cookie *)malloc(sizeof(struct Cookie));
|
||||
if(!co)
|
||||
return NULL; /* bail out if we're this low on memory */
|
||||
|
||||
/* clear the whole struct first */
|
||||
memset(co, 0, sizeof(struct Cookie));
|
||||
|
||||
if(httpheader) {
|
||||
/* This line was read off a HTTP-header */
|
||||
|
||||
semiptr=strchr(lineptr, ';'); /* first, find a semicolon */
|
||||
ptr = lineptr;
|
||||
while(semiptr) {
|
||||
*semiptr='\0'; /* zero terminate for a while */
|
||||
/* we have a <what>=<this> pair or a 'secure' word here */
|
||||
if(strchr(ptr, '=')) {
|
||||
if(2 == sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
|
||||
MAX_COOKIE_LINE_TXT "[^\r\n]",
|
||||
name, what)) {
|
||||
/* this is a legal <what>=<this> pair */
|
||||
if(strequal("path", name)) {
|
||||
co->path=strdup(what);
|
||||
}
|
||||
else if(strequal("domain", name)) {
|
||||
co->domain=strdup(what);
|
||||
}
|
||||
else if(strequal("expires", name)) {
|
||||
co->expirestr=strdup(what);
|
||||
co->expires = get_date(what, &now);
|
||||
}
|
||||
else if(!co->name) {
|
||||
co->name = strdup(name);
|
||||
co->value = strdup(what);
|
||||
}
|
||||
else
|
||||
;/* this is the second (or more) name we don't know
|
||||
about! */
|
||||
}
|
||||
else {
|
||||
/* this is an "illegal" <what>=<this> pair */
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(sscanf(ptr, "%" MAX_COOKIE_LINE_TXT "[^\r\n]",
|
||||
what)) {
|
||||
if(strequal("secure", what))
|
||||
co->secure = TRUE;
|
||||
else
|
||||
; /* unsupported keyword without assign! */
|
||||
}
|
||||
}
|
||||
*semiptr=';'; /* put the semicolon back */
|
||||
ptr=semiptr+1;
|
||||
while(ptr && *ptr && isspace((int)*ptr))
|
||||
ptr++;
|
||||
semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* This line is NOT a HTTP header style line, we do offer support for
|
||||
reading the odd netscape cookies-file format here */
|
||||
char *firstptr;
|
||||
int fields;
|
||||
|
||||
if(lineptr[0]=='#') {
|
||||
/* don't even try the comments */
|
||||
free(co);
|
||||
return NULL;
|
||||
}
|
||||
/* strip off the possible end-of-line characters */
|
||||
if(ptr=strchr(lineptr, '\r'))
|
||||
*ptr=0; /* clear it */
|
||||
if(ptr=strchr(lineptr, '\n'))
|
||||
*ptr=0; /* clear it */
|
||||
|
||||
firstptr=strtok(lineptr, "\t"); /* first tokenize it on the TAB */
|
||||
|
||||
/* Here's a quick check to eliminate normal HTTP-headers from this */
|
||||
if(!firstptr || strchr(firstptr, ':')) {
|
||||
free(co);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Now loop through the fields and init the struct we already have
|
||||
allocated */
|
||||
for(ptr=firstptr, fields=0; ptr; ptr=strtok(NULL, "\t"), fields++) {
|
||||
switch(fields) {
|
||||
case 0:
|
||||
co->domain = strdup(ptr);
|
||||
break;
|
||||
case 1:
|
||||
/* what _is_ this field for? */
|
||||
break;
|
||||
case 2:
|
||||
co->path = strdup(ptr);
|
||||
break;
|
||||
case 3:
|
||||
co->secure = strequal(ptr, "TRUE");
|
||||
break;
|
||||
case 4:
|
||||
co->expires = atoi(ptr);
|
||||
break;
|
||||
case 5:
|
||||
co->name = strdup(ptr);
|
||||
break;
|
||||
case 6:
|
||||
co->value = strdup(ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(7 != fields) {
|
||||
/* we did not find the sufficient number of fields to recognize this
|
||||
as a valid line, abort and go home */
|
||||
|
||||
if(co->domain)
|
||||
free(co->domain);
|
||||
if(co->path)
|
||||
free(co->path);
|
||||
if(co->name)
|
||||
free(co->name);
|
||||
if(co->value)
|
||||
free(co->value);
|
||||
|
||||
free(co);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* now, we have parsed the incoming line, we must now check if this
|
||||
superceeds an already existing cookie, which it may if the previous have
|
||||
the same domain and path as this */
|
||||
|
||||
clist = c->cookies;
|
||||
replace_old = FALSE;
|
||||
while(clist) {
|
||||
if(strequal(clist->name, co->name)) {
|
||||
/* the names are identical */
|
||||
|
||||
if(clist->domain && co->domain) {
|
||||
if(strequal(clist->domain, co->domain))
|
||||
replace_old=TRUE;
|
||||
}
|
||||
else if(!clist->domain && !co->domain)
|
||||
replace_old = TRUE;
|
||||
|
||||
if(replace_old) {
|
||||
/* the domains were identical */
|
||||
|
||||
if(clist->path && co->path) {
|
||||
if(strequal(clist->path, co->path)) {
|
||||
replace_old = TRUE;
|
||||
}
|
||||
else
|
||||
replace_old = FALSE;
|
||||
}
|
||||
else if(!clist->path && !co->path)
|
||||
replace_old = TRUE;
|
||||
else
|
||||
replace_old = FALSE;
|
||||
|
||||
}
|
||||
|
||||
if(replace_old) {
|
||||
co->next = clist->next; /* get the next-pointer first */
|
||||
|
||||
/* then free all the old pointers */
|
||||
if(clist->name)
|
||||
free(clist->name);
|
||||
if(clist->value)
|
||||
free(clist->value);
|
||||
if(clist->domain)
|
||||
free(clist->domain);
|
||||
if(clist->path)
|
||||
free(clist->path);
|
||||
if(clist->expirestr)
|
||||
free(clist->expirestr);
|
||||
|
||||
*clist = *co; /* then store all the new data */
|
||||
}
|
||||
|
||||
}
|
||||
clist = clist->next;
|
||||
}
|
||||
|
||||
if(!replace_old) {
|
||||
|
||||
/* first, point to our "next" */
|
||||
co->next = c->cookies;
|
||||
/* then make ourselves first in the list */
|
||||
c->cookies = co;
|
||||
}
|
||||
return co;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* cookie_init()
|
||||
*
|
||||
* Inits a cookie struct to read data from a local file. This is always
|
||||
* called before any cookies are set. File may be NULL.
|
||||
*
|
||||
****************************************************************************/
|
||||
struct CookieInfo *cookie_init(char *file)
|
||||
{
|
||||
char line[MAX_COOKIE_LINE];
|
||||
struct CookieInfo *c;
|
||||
FILE *fp;
|
||||
|
||||
c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
|
||||
if(!c)
|
||||
return NULL; /* failed to get memory */
|
||||
memset(c, 0, sizeof(struct CookieInfo));
|
||||
c->filename = strdup(file?file:"none"); /* copy the name just in case */
|
||||
|
||||
fp = file?fopen(file, "r"):NULL;
|
||||
if(fp) {
|
||||
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
||||
if(strnequal("Set-Cookie:", line, 11)) {
|
||||
/* This is a cookie line, get it! */
|
||||
char *lineptr=&line[11];
|
||||
while(*lineptr && isspace((int)*lineptr))
|
||||
lineptr++;
|
||||
|
||||
cookie_add(c, TRUE, lineptr);
|
||||
}
|
||||
else {
|
||||
/* This might be a netscape cookie-file line, get it! */
|
||||
char *lineptr=line;
|
||||
while(*lineptr && isspace((int)*lineptr))
|
||||
lineptr++;
|
||||
|
||||
cookie_add(c, FALSE, lineptr);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* cookie_getlist()
|
||||
*
|
||||
* For a given host and path, return a linked list of cookies that the
|
||||
* client should send to the server if used now. The secure boolean informs
|
||||
* the cookie if a secure connection is achieved or not.
|
||||
*
|
||||
* It shall only return cookies that haven't expired.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct Cookie *cookie_getlist(struct CookieInfo *c,
|
||||
char *host, char *path, bool secure)
|
||||
{
|
||||
struct Cookie *newco;
|
||||
struct Cookie *co;
|
||||
time_t now = time(NULL);
|
||||
int hostlen=strlen(host);
|
||||
int domlen;
|
||||
|
||||
struct Cookie *mainco=NULL;
|
||||
|
||||
if(!c || !c->cookies)
|
||||
return NULL; /* no cookie struct or no cookies in the struct */
|
||||
|
||||
co = c->cookies;
|
||||
|
||||
while(co) {
|
||||
/* only process this cookie if it is not expired or had no expire
|
||||
date AND that if the cookie requires we're secure we must only
|
||||
continue if we are! */
|
||||
if( (co->expires<=0 || (co->expires> now)) &&
|
||||
(co->secure?secure:TRUE) ) {
|
||||
|
||||
/* now check if the domain is correct */
|
||||
domlen=co->domain?strlen(co->domain):0;
|
||||
if(!co->domain ||
|
||||
((domlen<hostlen) &&
|
||||
strequal(host+(hostlen-domlen), co->domain)) ) {
|
||||
/* the right part of the host matches the domain stuff in the
|
||||
cookie data */
|
||||
|
||||
/* now check the left part of the path with the cookies path
|
||||
requirement */
|
||||
if(!co->path ||
|
||||
strnequal(path, co->path, strlen(co->path))) {
|
||||
|
||||
/* and now, we know this is a match and we should create an
|
||||
entry for the return-linked-list */
|
||||
|
||||
newco = (struct Cookie *)malloc(sizeof(struct Cookie));
|
||||
if(newco) {
|
||||
/* first, copy the whole source cookie: */
|
||||
memcpy(newco, co, sizeof(struct Cookie));
|
||||
|
||||
/* then modify our next */
|
||||
newco->next = mainco;
|
||||
|
||||
/* point the main to us */
|
||||
mainco = newco;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
co = co->next;
|
||||
}
|
||||
|
||||
return mainco; /* return the new list */
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* cookie_freelist()
|
||||
*
|
||||
* Free a list previously returned by cookie_getlist();
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void cookie_freelist(struct Cookie *co)
|
||||
{
|
||||
struct Cookie *next;
|
||||
if(co) {
|
||||
while(co) {
|
||||
next = co->next;
|
||||
free(co); /* we only free the struct since the "members" are all
|
||||
just copied! */
|
||||
co = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* cookie_cleanup()
|
||||
*
|
||||
* Free a "cookie object" previous created with cookie_init().
|
||||
*
|
||||
****************************************************************************/
|
||||
void cookie_cleanup(struct CookieInfo *c)
|
||||
{
|
||||
struct Cookie *co;
|
||||
struct Cookie *next;
|
||||
if(c) {
|
||||
if(c->filename)
|
||||
free(c->filename);
|
||||
co = c->cookies;
|
||||
|
||||
while(co) {
|
||||
if(co->name)
|
||||
free(co->name);
|
||||
if(co->value)
|
||||
free(co->value);
|
||||
if(co->domain)
|
||||
free(co->domain);
|
||||
if(co->path)
|
||||
free(co->path);
|
||||
if(co->expirestr)
|
||||
free(co->expirestr);
|
||||
|
||||
next = co->next;
|
||||
free(co);
|
||||
co = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
lib/cookie.h
Normal file
45
lib/cookie.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __COOKIE_H
|
||||
#define __COOKIE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef WIN32
|
||||
#include <time.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
struct Cookie {
|
||||
struct Cookie *next; /* next in the chain */
|
||||
char *name; /* <this> = value */
|
||||
char *value; /* name = <this> */
|
||||
char *path; /* path = <this> */
|
||||
char *domain; /* domain = <this> */
|
||||
time_t expires; /* expires = <this> */
|
||||
char *expirestr; /* the plain text version */
|
||||
bool secure; /* whether the 'secure' keyword was used */
|
||||
};
|
||||
|
||||
struct CookieInfo {
|
||||
/* linked list of cookies we know of */
|
||||
struct Cookie *cookies;
|
||||
|
||||
char *filename; /* file we read from/write to */
|
||||
};
|
||||
|
||||
/* This is the maximum line length we accept for a cookie line */
|
||||
#define MAX_COOKIE_LINE 2048
|
||||
#define MAX_COOKIE_LINE_TXT "2047"
|
||||
|
||||
/* This is the maximum length of a cookie name we deal with: */
|
||||
#define MAX_NAME 256
|
||||
#define MAX_NAME_TXT "255"
|
||||
|
||||
struct Cookie *cookie_add(struct CookieInfo *, bool, char *);
|
||||
struct CookieInfo *cookie_init(char *);
|
||||
struct Cookie *cookie_getlist(struct CookieInfo *, char *, char *, bool);
|
||||
void cookie_freelist(struct Cookie *);
|
||||
void cookie_cleanup(struct CookieInfo *);
|
||||
|
||||
#endif
|
||||
245
lib/dict.c
Normal file
245
lib/dict.c
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* -- WIN32 approved -- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
#include "download.h"
|
||||
#include "sendf.h"
|
||||
|
||||
#include "progress.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
|
||||
UrgError dict(struct UrlData *data, char *path, long *bytecount)
|
||||
{
|
||||
int nth;
|
||||
char *word;
|
||||
char *ppath;
|
||||
char *database = NULL;
|
||||
char *strategy = NULL;
|
||||
char *nthdef = NULL; /* This is not part of the protocol, but required
|
||||
by RFC 2229 */
|
||||
UrgError result=URG_OK;
|
||||
|
||||
if(data->conf & CONF_USERPWD) {
|
||||
/* AUTH is missing */
|
||||
}
|
||||
|
||||
if (strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
|
||||
strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
|
||||
strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
|
||||
|
||||
word = strchr(path, ':');
|
||||
if (word) {
|
||||
word++;
|
||||
database = strchr(word, ':');
|
||||
if (database) {
|
||||
*database++ = (char)0;
|
||||
strategy = strchr(database, ':');
|
||||
if (strategy) {
|
||||
*strategy++ = (char)0;
|
||||
nthdef = strchr(strategy, ':');
|
||||
if (nthdef) {
|
||||
*nthdef++ = (char)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((word == NULL) || (*word == (char)0)) {
|
||||
failf(data, "lookup word is missing\n");
|
||||
}
|
||||
if ((database == NULL) || (*database == (char)0)) {
|
||||
database = "!";
|
||||
}
|
||||
if ((strategy == NULL) || (*strategy == (char)0)) {
|
||||
strategy = ".";
|
||||
}
|
||||
if ((nthdef == NULL) || (*nthdef == (char)0)) {
|
||||
nth = 0;
|
||||
}
|
||||
else {
|
||||
nth = atoi(nthdef);
|
||||
}
|
||||
|
||||
sendf(data->firstsocket, data,
|
||||
"CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
|
||||
"MATCH "
|
||||
"%s " /* database */
|
||||
"%s " /* strategy */
|
||||
"%s\n" /* word */
|
||||
"QUIT\n",
|
||||
|
||||
database,
|
||||
strategy,
|
||||
word
|
||||
);
|
||||
|
||||
result = Download(data, data->firstsocket, -1, FALSE, bytecount);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
}
|
||||
else if (strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
|
||||
strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
|
||||
strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
|
||||
|
||||
word = strchr(path, ':');
|
||||
if (word) {
|
||||
word++;
|
||||
database = strchr(word, ':');
|
||||
if (database) {
|
||||
*database++ = (char)0;
|
||||
nthdef = strchr(database, ':');
|
||||
if (nthdef) {
|
||||
*nthdef++ = (char)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((word == NULL) || (*word == (char)0)) {
|
||||
failf(data, "lookup word is missing\n");
|
||||
}
|
||||
if ((database == NULL) || (*database == (char)0)) {
|
||||
database = "!";
|
||||
}
|
||||
if ((nthdef == NULL) || (*nthdef == (char)0)) {
|
||||
nth = 0;
|
||||
}
|
||||
else {
|
||||
nth = atoi(nthdef);
|
||||
}
|
||||
|
||||
sendf(data->firstsocket, data,
|
||||
"CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
|
||||
"DEFINE "
|
||||
"%s " /* database */
|
||||
"%s\n" /* word */
|
||||
"QUIT\n",
|
||||
|
||||
database,
|
||||
word
|
||||
);
|
||||
|
||||
result = Download(data, data->firstsocket, -1, FALSE, bytecount);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
ppath = strchr(path, '/');
|
||||
if (ppath) {
|
||||
int i;
|
||||
|
||||
ppath++;
|
||||
for (i = 0; (i < URL_MAX_LENGTH) && (ppath[i]); i++) {
|
||||
if (ppath[i] == ':')
|
||||
ppath[i] = ' ';
|
||||
}
|
||||
sendf(data->firstsocket, data,
|
||||
"CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
|
||||
"%s\n"
|
||||
"QUIT\n",
|
||||
ppath);
|
||||
|
||||
result = Download(data, data->firstsocket, -1, FALSE, bytecount);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ProgressEnd(data);
|
||||
return URG_OK;
|
||||
}
|
||||
45
lib/dict.h
Normal file
45
lib/dict.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __DICT_H
|
||||
#define __DICT_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError dict(struct UrlData *data, char *path, long *bytecountp);
|
||||
|
||||
#endif
|
||||
484
lib/download.c
Normal file
484
lib/download.c
Normal file
|
|
@ -0,0 +1,484 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifdef __BEOS__
|
||||
#include <net/socket.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#if !defined( __GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <time.h> /* for the time_t typedef! */
|
||||
|
||||
#if defined(__GNUC__) && defined(TIME_WITH_SYS_TIME)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include "progress.h"
|
||||
#include "speedcheck.h"
|
||||
#include "sendf.h"
|
||||
|
||||
#ifdef USE_ZLIB
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
/* --- download a stream from a socket --- */
|
||||
|
||||
/* This newly edited version of Download() was brought to us by the friendly
|
||||
Mark Butler <butlerm@xmission.com>. Re-indented with the indent command. */
|
||||
|
||||
UrgError
|
||||
Download (struct UrlData *data,
|
||||
int sockfd, /* socket to read from */
|
||||
int size, /* -1 if unknown at this point */
|
||||
bool getheader, /* TRUE if header parsing is wanted */
|
||||
long *bytecountp /* return number of bytes read */
|
||||
)
|
||||
{
|
||||
char *buf = data->buffer;
|
||||
size_t nread;
|
||||
int bytecount = 0;
|
||||
long contentlength=0;
|
||||
struct timeval start = tvnow();
|
||||
struct timeval now = start;
|
||||
bool header = TRUE;
|
||||
int headerline = 0; /* counts header lines to better track the first one */
|
||||
|
||||
char *hbufp; /* points at *end* of header line */
|
||||
int hbuflen = 0;
|
||||
char *str; /* within buf */
|
||||
char *str_start; /* within buf */
|
||||
char *end_ptr; /* within buf */
|
||||
char *p; /* within headerbuff */
|
||||
bool content_range = FALSE; /* set TRUE if Content-Range: was found */
|
||||
int offset = 0; /* possible resume offset read from the
|
||||
Content-Range: header */
|
||||
int code = 0; /* error code from the 'HTTP/1.? XXX' line */
|
||||
#ifdef USE_ZLIB
|
||||
gzFile gzfile=NULL;
|
||||
#endif
|
||||
|
||||
/* for the low speed checks: */
|
||||
UrgError urg;
|
||||
time_t timeofdoc=0;
|
||||
long bodywrites=0;
|
||||
|
||||
char newurl[URL_MAX_LENGTH]; /* buffer for Location: URL */
|
||||
|
||||
hbufp = data->headerbuff;
|
||||
|
||||
myalarm (0); /* switch off the alarm-style timeout */
|
||||
|
||||
now = tvnow();
|
||||
start = now;
|
||||
|
||||
if (!getheader) {
|
||||
header = FALSE;
|
||||
ProgressInit (data, size);
|
||||
}
|
||||
{
|
||||
fd_set readfd;
|
||||
fd_set keepfd;
|
||||
struct timeval interval;
|
||||
bool keepon = TRUE;
|
||||
|
||||
/* timeout every X second
|
||||
- makes a better progressmeter (i.e even when no data is read, the
|
||||
meter can be updated and reflect reality)
|
||||
- allows removal of the alarm() crap
|
||||
- variable timeout is easier
|
||||
*/
|
||||
|
||||
FD_ZERO (&readfd); /* clear it */
|
||||
FD_SET (sockfd, &readfd);
|
||||
|
||||
keepfd = readfd;
|
||||
#ifdef USE_ZLIB
|
||||
gzfile = gzdopen(sockfd, "rb");
|
||||
#endif
|
||||
while (keepon) {
|
||||
readfd = keepfd; /* set this every lap in the loop */
|
||||
interval.tv_sec = 2;
|
||||
interval.tv_usec = 0;
|
||||
|
||||
switch (select (sockfd + 1, &readfd, NULL, NULL, &interval)) {
|
||||
case -1: /* error, stop reading */
|
||||
keepon = FALSE;
|
||||
continue;
|
||||
case 0: /* timeout */
|
||||
break;
|
||||
default: /* read! */
|
||||
#ifdef USE_SSLEAY
|
||||
if (data->use_ssl) {
|
||||
nread = SSL_read (data->ssl, buf, BUFSIZE - 1);
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
#ifdef USE_ZLIB
|
||||
nread = gzread(gzfile, buf, BUFSIZE -1 );
|
||||
#else
|
||||
nread = sread (sockfd, buf, BUFSIZE - 1);
|
||||
#endif
|
||||
#ifdef USE_SSLEAY
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
|
||||
/* NULL terminate, allowing string ops to be used */
|
||||
if (0 < (signed int) nread)
|
||||
buf[nread] = 0;
|
||||
|
||||
/* if we receive 0 or less here, the server closed the connection and
|
||||
we bail out from this! */
|
||||
else if (0 >= (signed int) nread) {
|
||||
keepon = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
str = buf; /* Default buffer to use when we write the
|
||||
buffer, it may be changed in the flow below
|
||||
before the actual storing is done. */
|
||||
|
||||
/* Since this is a two-state thing, we check if we are parsing
|
||||
headers at the moment or not. */
|
||||
|
||||
if (header) {
|
||||
/* we are in parse-the-header-mode */
|
||||
|
||||
/* header line within buffer loop */
|
||||
do {
|
||||
int hbufp_index;
|
||||
|
||||
str_start = str; /* str_start is start of line within buf */
|
||||
|
||||
end_ptr = strchr (str_start, '\n');
|
||||
|
||||
if (!end_ptr) {
|
||||
/* no more complete header lines within buffer */
|
||||
/* copy what is remaining into headerbuff */
|
||||
int str_length = (int)strlen(str);
|
||||
|
||||
if (hbuflen + (int)str_length >= data->headersize) {
|
||||
char *newbuff;
|
||||
long newsize=MAX((hbuflen+str_length)*3/2,
|
||||
data->headersize*2);
|
||||
hbufp_index = hbufp - data->headerbuff;
|
||||
newbuff = (char *)realloc(data->headerbuff, newsize);
|
||||
if(!newbuff) {
|
||||
failf (data, "Failed to alloc memory for big header!");
|
||||
return URG_READ_ERROR;
|
||||
}
|
||||
data->headersize=newsize;
|
||||
data->headerbuff = newbuff;
|
||||
hbufp = data->headerbuff + hbufp_index;
|
||||
}
|
||||
strcpy (hbufp, str);
|
||||
hbufp += strlen (str);
|
||||
hbuflen += strlen (str);
|
||||
break; /* read more and try again */
|
||||
}
|
||||
|
||||
str = end_ptr + 1; /* move just past new line */
|
||||
|
||||
if (hbuflen + (str - str_start) >= data->headersize) {
|
||||
char *newbuff;
|
||||
long newsize=MAX((hbuflen+(str-str_start))*3/2,
|
||||
data->headersize*2);
|
||||
hbufp_index = hbufp - data->headerbuff;
|
||||
newbuff = (char *)realloc(data->headerbuff, newsize);
|
||||
if(!newbuff) {
|
||||
failf (data, "Failed to alloc memory for big header!");
|
||||
return URG_READ_ERROR;
|
||||
}
|
||||
data->headersize= newsize;
|
||||
data->headerbuff = newbuff;
|
||||
hbufp = data->headerbuff + hbufp_index;
|
||||
}
|
||||
|
||||
/* copy to end of line */
|
||||
strncpy (hbufp, str_start, str - str_start);
|
||||
hbufp += str - str_start;
|
||||
hbuflen += str - str_start;
|
||||
*hbufp = 0;
|
||||
|
||||
p = data->headerbuff;
|
||||
|
||||
/* we now have a full line that p points to */
|
||||
if (('\n' == *p) || ('\r' == *p)) {
|
||||
/* Zero-length line means end of header! */
|
||||
if (-1 != size) /* if known */
|
||||
size += bytecount; /* we append the already read size */
|
||||
|
||||
|
||||
if ('\r' == *p)
|
||||
p++; /* pass the \r byte */
|
||||
if ('\n' == *p)
|
||||
p++; /* pass the \n byte */
|
||||
|
||||
ProgressInit (data, size); /* init progress meter */
|
||||
header = FALSE; /* no more header to parse! */
|
||||
|
||||
/* now, only output this if the header AND body are requested: */
|
||||
if ((data->conf & (CONF_HEADER | CONF_NOBODY)) == CONF_HEADER) {
|
||||
if((p - data->headerbuff) !=
|
||||
data->fwrite (data->headerbuff, 1,
|
||||
p - data->headerbuff, data->out)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
if(data->writeheader) {
|
||||
/* obviously, the header is requested to be written to
|
||||
this file: */
|
||||
if((p - data->headerbuff) !=
|
||||
fwrite (data->headerbuff, 1, p - data->headerbuff,
|
||||
data->writeheader)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
break; /* exit header line loop */
|
||||
}
|
||||
|
||||
if (!headerline++) {
|
||||
/* This is the first header, it MUST be the error code line
|
||||
or else we consiser this to be the body right away! */
|
||||
if (sscanf (p, " HTTP/1.%*c %3d", &code)) {
|
||||
/* 404 -> URL not found! */
|
||||
if (
|
||||
( ((data->conf & CONF_FOLLOWLOCATION) && (code >= 400)) ||
|
||||
!(data->conf & CONF_FOLLOWLOCATION) && (code >= 300))
|
||||
&& (data->conf & CONF_FAILONERROR)) {
|
||||
/* If we have been told to fail hard on HTTP-errors,
|
||||
here is the check for that: */
|
||||
/* serious error, go home! */
|
||||
failf (data, "The requested file was not found");
|
||||
return URG_HTTP_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else {
|
||||
header = FALSE; /* this is not a header line */
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* check for Content-Length: header lines to get size */
|
||||
if (strnequal("Content-Length", p, 14) &&
|
||||
sscanf (p+14, ": %ld", &contentlength))
|
||||
size = contentlength;
|
||||
else if (strnequal("Content-Range", p, 13) &&
|
||||
sscanf (p+13, ": bytes %d-", &offset)) {
|
||||
if (data->resume_from == offset) {
|
||||
/* we asked for a resume and we got it */
|
||||
content_range = TRUE;
|
||||
}
|
||||
}
|
||||
else if(data->cookies &&
|
||||
strnequal("Set-Cookie: ", p, 11)) {
|
||||
cookie_add(data->cookies, TRUE, &p[12]);
|
||||
}
|
||||
else if(strnequal("Last-Modified:", p, strlen("Last-Modified:")) &&
|
||||
data->timecondition) {
|
||||
time_t secs=time(NULL);
|
||||
timeofdoc = get_date(p+strlen("Last-Modified:"), &secs);
|
||||
}
|
||||
else if ((code >= 300 && code < 400) &&
|
||||
(data->conf & CONF_FOLLOWLOCATION) &&
|
||||
strnequal("Location", p, 8) &&
|
||||
sscanf (p+8, ": %" URL_MAX_LENGTH_TXT "s", newurl)) {
|
||||
/* this is the URL that the server advices us to get
|
||||
instead */
|
||||
data->newurl = strdup (newurl);
|
||||
}
|
||||
|
||||
if (data->conf & CONF_HEADER) {
|
||||
if(hbuflen != data->fwrite (p, 1, hbuflen, data->out)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
if(data->writeheader) {
|
||||
/* the header is requested to be written to this file */
|
||||
if(hbuflen != fwrite (p, 1, hbuflen, data->writeheader)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* reset hbufp pointer && hbuflen */
|
||||
hbufp = data->headerbuff;
|
||||
hbuflen = 0;
|
||||
}
|
||||
while (*str); /* header line within buffer */
|
||||
|
||||
/* We might have reached the end of the header part here, but
|
||||
there might be a non-header part left in the end of the read
|
||||
buffer. */
|
||||
|
||||
if (!header) {
|
||||
/* the next token and forward is not part of
|
||||
the header! */
|
||||
|
||||
/* we subtract the remaining header size from the buffer */
|
||||
nread -= (str - buf);
|
||||
}
|
||||
|
||||
} /* end if header mode */
|
||||
|
||||
/* This is not an 'else if' since it may be a rest from the header
|
||||
parsing, where the beginning of the buffer is headers and the end
|
||||
is non-headers. */
|
||||
if (str && !header && (nread > 0)) {
|
||||
|
||||
if(0 == bodywrites) {
|
||||
/* These checks are only made the first time we are about to
|
||||
write a chunk of the body */
|
||||
if(data->conf&CONF_HTTP) {
|
||||
/* HTTP-only checks */
|
||||
if (data->resume_from && !content_range ) {
|
||||
/* we wanted to resume a download, although the server doesn't
|
||||
seem to support this */
|
||||
failf (data, "HTTP server doesn't seem to support byte ranges. Cannot resume.");
|
||||
return URG_HTTP_RANGE_ERROR;
|
||||
}
|
||||
else if (data->newurl) {
|
||||
/* abort after the headers if "follow Location" is set */
|
||||
infof (data, "Follow to new URL: %s\n", data->newurl);
|
||||
return URG_OK;
|
||||
}
|
||||
else if(data->timecondition && !data->range) {
|
||||
/* A time condition has been set AND no ranges have been
|
||||
requested. This seems to be what chapter 13.3.4 of RFC 2616
|
||||
defines to be the correct action for a HTTP/1.1 client */
|
||||
if((timeofdoc > 0) && (data->timevalue > 0)) {
|
||||
switch(data->timecondition) {
|
||||
case TIMECOND_IFMODSINCE:
|
||||
default:
|
||||
if(timeofdoc < data->timevalue) {
|
||||
infof(data, "The requested document is not new enough");
|
||||
return URG_OK;
|
||||
}
|
||||
break;
|
||||
case TIMECOND_IFUNMODSINCE:
|
||||
if(timeofdoc > data->timevalue) {
|
||||
infof(data, "The requested document is not old enough");
|
||||
return URG_OK;
|
||||
}
|
||||
break;
|
||||
} /* switch */
|
||||
} /* two valid time strings */
|
||||
} /* we have a time condition */
|
||||
} /* this is HTTP */
|
||||
} /* this is the first time we write a body part */
|
||||
bodywrites++;
|
||||
|
||||
if(data->maxdownload &&
|
||||
(bytecount + nread > data->maxdownload)) {
|
||||
nread = data->maxdownload - bytecount;
|
||||
if(nread < 0 ) /* this should be unusual */
|
||||
nread = 0;
|
||||
keepon = FALSE; /* we're done now! */
|
||||
}
|
||||
|
||||
bytecount += nread;
|
||||
|
||||
if (nread != data->fwrite (str, 1, nread, data->out)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
now = tvnow();
|
||||
if (!header) {
|
||||
ProgressShow (data, bytecount, start, now, FALSE);
|
||||
}
|
||||
urg = speedcheck (data, now);
|
||||
if (urg)
|
||||
return urg;
|
||||
|
||||
if (data->timeout && (tvdiff (now, start) > data->timeout)) {
|
||||
failf (data, "Operation timed out with %d out of %d bytes received",
|
||||
bytecount, size);
|
||||
return URG_OPERATION_TIMEOUTED;
|
||||
}
|
||||
#ifdef MULTIDOC
|
||||
if(contentlength && bytecount >= contentlength) {
|
||||
/* we're done with this download, now stop it */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(contentlength && (bytecount != contentlength)) {
|
||||
failf(data, "transfer closed with %d bytes remaining", contentlength-bytecount);
|
||||
return URG_PARTIAL_FILE;
|
||||
}
|
||||
ProgressShow (data, bytecount, start, now, TRUE);
|
||||
|
||||
*bytecountp = bytecount;
|
||||
|
||||
#ifdef USE_ZLIB
|
||||
gzclose(gzfile);
|
||||
#endif
|
||||
return URG_OK;
|
||||
}
|
||||
|
||||
|
||||
50
lib/download.h
Normal file
50
lib/download.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef __DOWNLOAD_H
|
||||
#define __DOWNLOAD_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError
|
||||
Download (struct UrlData *data,
|
||||
int sockfd, /* socket to read from */
|
||||
int size, /* -1 if unknown at this point */
|
||||
bool getheader, /* TRUE if header parsing is wanted */
|
||||
long *bytecountp /* return number of bytes read */
|
||||
);
|
||||
|
||||
#endif
|
||||
111
lib/escape.c
Normal file
111
lib/escape.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* Escape and unescape URL encoding in strings. The functions return a new
|
||||
* allocated string or NULL if an error occurred. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *curl_escape(char *string)
|
||||
{
|
||||
int alloc=strlen(string);
|
||||
char *ns = malloc(alloc);
|
||||
unsigned char in;
|
||||
int newlen = alloc;
|
||||
int index=0;
|
||||
|
||||
while(*string) {
|
||||
in = *string;
|
||||
if(' ' == in)
|
||||
ns[index++] = '+';
|
||||
else if(!(in >= 'a' && in <= 'z') &&
|
||||
!(in >= 'A' && in <= 'Z') &&
|
||||
!(in >= '0' && in <= '9')) {
|
||||
/* encode it */
|
||||
newlen += 2; /* the size grows with two, since this'll become a %XX */
|
||||
if(newlen > alloc) {
|
||||
alloc *= 2;
|
||||
ns = realloc(ns, alloc);
|
||||
if(!ns)
|
||||
return NULL;
|
||||
}
|
||||
sprintf(&ns[index], "%%%02X", in);
|
||||
index+=3;
|
||||
}
|
||||
else {
|
||||
/* just copy this */
|
||||
ns[index++]=in;
|
||||
}
|
||||
string++;
|
||||
}
|
||||
ns[index]=0; /* terminate it */
|
||||
return ns;
|
||||
}
|
||||
|
||||
char *curl_unescape(char *string)
|
||||
{
|
||||
int alloc = strlen(string);
|
||||
char *ns = malloc(alloc);
|
||||
unsigned char in;
|
||||
int index=0;
|
||||
int hex;
|
||||
|
||||
|
||||
while(*string) {
|
||||
in = *string;
|
||||
if('+' == in)
|
||||
in = ' ';
|
||||
else if('%' == in) {
|
||||
/* encoded part */
|
||||
if(sscanf(string+1, "%02X", &hex)) {
|
||||
in = hex;
|
||||
string+=2;
|
||||
}
|
||||
}
|
||||
|
||||
ns[index++] = in;
|
||||
string++;
|
||||
}
|
||||
ns[index]=0; /* terminate it */
|
||||
return ns;
|
||||
|
||||
}
|
||||
49
lib/escape.h
Normal file
49
lib/escape.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef __ESCAPE_H
|
||||
#define __ESCAPE_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
/* Escape and unescape URL encoding in strings. The functions return a new
|
||||
* allocated string or NULL if an error occurred. */
|
||||
|
||||
char *curl_escape(char *string);
|
||||
char *curl_unescape(char *string);
|
||||
|
||||
#endif
|
||||
175
lib/file.c
Normal file
175
lib/file.c
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1999.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* -- WIN32 approved -- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
#include "progress.h"
|
||||
#include "sendf.h"
|
||||
#include "escape.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
|
||||
UrgError file(struct UrlData *data, char *path, long *bytecountp)
|
||||
{
|
||||
/* This implementation ignores the host name in conformance with
|
||||
RFC 1738. Only local files (reachable via the standard file system)
|
||||
are supported. This means that files on remotely mounted directories
|
||||
(via NFS, Samba, NT sharing) can be accessed through a file:// URL
|
||||
*/
|
||||
|
||||
struct stat statbuf;
|
||||
size_t expected_size=-1;
|
||||
size_t nread;
|
||||
char *buf = data->buffer;
|
||||
int bytecount = 0;
|
||||
struct timeval start = tvnow();
|
||||
struct timeval now = start;
|
||||
int fd;
|
||||
char *actual_path = curl_unescape(path);
|
||||
|
||||
#ifdef WIN32
|
||||
int i;
|
||||
|
||||
/* change path separators from '/' to '\\' for Windows */
|
||||
for (i=0; actual_path[i] != '\0'; ++i)
|
||||
if (actual_path[i] == '/')
|
||||
actual_path[i] = '\\';
|
||||
|
||||
fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */
|
||||
#else
|
||||
fd = open(actual_path, O_RDONLY);
|
||||
#endif
|
||||
free(actual_path);
|
||||
|
||||
if(fd == -1) {
|
||||
failf(data, "Couldn't open file %s", path);
|
||||
return URG_FILE_COULDNT_READ_FILE;
|
||||
}
|
||||
if( -1 != fstat(fd, &statbuf)) {
|
||||
/* we could stat it, then read out the size */
|
||||
expected_size = statbuf.st_size;
|
||||
}
|
||||
|
||||
/* The following is a shortcut implementation of file reading
|
||||
this is both more efficient than the former call to download() and
|
||||
it avoids problems with select() and recv() on file descriptors
|
||||
in Winsock */
|
||||
ProgressInit (data, expected_size);
|
||||
while (1) {
|
||||
nread = read(fd, buf, BUFSIZE-1);
|
||||
|
||||
if (0 <= nread)
|
||||
buf[nread] = 0;
|
||||
|
||||
if (nread <= 0)
|
||||
break;
|
||||
bytecount += nread;
|
||||
/* NOTE: The following call to fwrite does CR/LF translation on
|
||||
Windows systems if the target is stdout. Use -O or -o parameters
|
||||
to prevent CR/LF translation (this then goes to a binary mode
|
||||
file descriptor). */
|
||||
if(nread != data->fwrite (buf, 1, nread, data->out)) {
|
||||
failf (data, "Failed writing output");
|
||||
return URG_WRITE_ERROR;
|
||||
}
|
||||
now = tvnow();
|
||||
ProgressShow (data, bytecount, start, now, FALSE);
|
||||
}
|
||||
now = tvnow();
|
||||
ProgressShow (data, bytecount, start, now, TRUE);
|
||||
|
||||
close(fd);
|
||||
|
||||
return URG_OK;
|
||||
}
|
||||
45
lib/file.h
Normal file
45
lib/file.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __FILE_H
|
||||
#define __FILE_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError file(struct UrlData *data, char *path, long *bytecountp);
|
||||
|
||||
#endif
|
||||
BIN
lib/formdata
Executable file
BIN
lib/formdata
Executable file
Binary file not shown.
617
lib/formdata.c
Normal file
617
lib/formdata.c
Normal file
|
|
@ -0,0 +1,617 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
Debug the form generator stand-alone by compiling this source file with:
|
||||
|
||||
gcc -DHAVE_CONFIG_H -I../ -g -D_FORM_DEBUG -o formdata -I../include formdata.c
|
||||
|
||||
run the 'formdata' executable and make sure the output is ok!
|
||||
|
||||
try './formdata "name=Daniel" "poo=noo" "foo=bar"' and similarly
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "setup.h"
|
||||
#include <curl/curl.h>
|
||||
#include "formdata.h"
|
||||
|
||||
/* Length of the random boundary string. The risk of this being used
|
||||
in binary data is very close to zero, 64^32 makes
|
||||
6277101735386680763835789423207666416102355444464034512896
|
||||
combinations... */
|
||||
#define BOUNDARY_LENGTH 32
|
||||
|
||||
/* What kind of Content-Type to use on un-specified files with unrecognized
|
||||
extensions. */
|
||||
#define HTTPPOST_CONTENTTYPE_DEFAULT "text/plain"
|
||||
|
||||
/* This is a silly duplicate of the function in main.c to enable this source
|
||||
to compile stand-alone for better debugging */
|
||||
static void GetStr(char **string,
|
||||
char *value)
|
||||
{
|
||||
if(*string)
|
||||
free(*string);
|
||||
*string = strdup(value);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FormParse()
|
||||
*
|
||||
* Reads a 'name=value' paramter and builds the appropriate linked list.
|
||||
*
|
||||
* Specify files to upload with 'name=@filename'. Supports specified
|
||||
* given Content-Type of the files. Such as ';type=<content-type>'.
|
||||
*
|
||||
* You may specify more than one file for a single name (field). Specify
|
||||
* multiple files by writing it like:
|
||||
*
|
||||
* 'name=@filename,filename2,filename3'
|
||||
*
|
||||
* If you want content-types specified for each too, write them like:
|
||||
*
|
||||
* 'name=@filename;type=image/gif,filename2,filename3'
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
int curl_FormParse(char *input,
|
||||
struct HttpPost **httppost,
|
||||
struct HttpPost **last_post)
|
||||
{
|
||||
return FormParse(input, httppost, last_post);
|
||||
}
|
||||
|
||||
#define FORM_FILE_SEPARATOR ','
|
||||
#define FORM_TYPE_SEPARATOR ';'
|
||||
|
||||
int FormParse(char *input,
|
||||
struct HttpPost **httppost,
|
||||
struct HttpPost **last_post)
|
||||
{
|
||||
/* nextarg MUST be a string in the format 'name=contents' and we'll
|
||||
build a linked list with the info */
|
||||
char name[256];
|
||||
char contents[1024]="";
|
||||
char major[128];
|
||||
char minor[128];
|
||||
long flags = 0;
|
||||
char *contp;
|
||||
char *type = NULL;
|
||||
char *prevtype = NULL;
|
||||
char *sep;
|
||||
char *sep2;
|
||||
struct HttpPost *post;
|
||||
struct HttpPost *subpost; /* a sub-node */
|
||||
unsigned int i;
|
||||
|
||||
if(1 <= sscanf(input, "%255[^ =] = %1023[^\n]", name, contents)) {
|
||||
/* the input was using the correct format */
|
||||
contp = contents;
|
||||
|
||||
if('@' == contp[0]) {
|
||||
/* we use the @-letter to indicate file name(s) */
|
||||
|
||||
flags = HTTPPOST_FILENAME;
|
||||
contp++;
|
||||
|
||||
post=NULL;
|
||||
|
||||
do {
|
||||
/* since this was a file, it may have a content-type specifier
|
||||
at the end too */
|
||||
|
||||
sep=strchr(contp, FORM_TYPE_SEPARATOR);
|
||||
sep2=strchr(contp, FORM_FILE_SEPARATOR);
|
||||
|
||||
/* pick the closest */
|
||||
if(sep2 && (sep2 < sep)) {
|
||||
sep = sep2;
|
||||
|
||||
/* no type was specified! */
|
||||
}
|
||||
if(sep) {
|
||||
|
||||
/* if we got here on a comma, don't do much */
|
||||
if(FORM_FILE_SEPARATOR != *sep)
|
||||
type = strstr(sep+1, "type=");
|
||||
else
|
||||
type=NULL;
|
||||
|
||||
*sep=0; /* terminate file name at separator */
|
||||
|
||||
if(type) {
|
||||
type += strlen("type=");
|
||||
|
||||
if(2 != sscanf(type, "%127[^/]/%127[^,\n]",
|
||||
major, minor)) {
|
||||
fprintf(stderr, "Illegally formatted content-type field!\n");
|
||||
return 2; /* illegal content-type syntax! */
|
||||
}
|
||||
/* now point beyond the content-type specifier */
|
||||
sep = type + strlen(major)+strlen(minor)+1;
|
||||
|
||||
/* find the following comma */
|
||||
sep=strchr(sep, FORM_FILE_SEPARATOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
type=NULL;
|
||||
sep=strchr(contp, FORM_FILE_SEPARATOR);
|
||||
}
|
||||
if(sep) {
|
||||
/* the next file name starts here */
|
||||
*sep =0;
|
||||
sep++;
|
||||
}
|
||||
if(!type) {
|
||||
/*
|
||||
* No type was specified, we scan through a few well-known
|
||||
* extensions and pick the first we match!
|
||||
*/
|
||||
struct ContentType {
|
||||
char *extension;
|
||||
char *type;
|
||||
};
|
||||
static struct ContentType ctts[]={
|
||||
{".gif", "image/gif"},
|
||||
{".jpg", "image/jpeg"},
|
||||
{".jpeg", "image/jpeg"},
|
||||
{".txt", "text/plain"},
|
||||
{".html", "text/plain"}
|
||||
};
|
||||
|
||||
if(prevtype)
|
||||
/* default to the previously set/used! */
|
||||
type = prevtype;
|
||||
else
|
||||
/* It seems RFC1867 defines no Content-Type to default to
|
||||
text/plain so we don't actually need to set this: */
|
||||
type = HTTPPOST_CONTENTTYPE_DEFAULT;
|
||||
|
||||
for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
|
||||
if(strlen(contp) >= strlen(ctts[i].extension)) {
|
||||
if(strequal(contp +
|
||||
strlen(contp) - strlen(ctts[i].extension),
|
||||
ctts[i].extension)) {
|
||||
type = ctts[i].type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* we have a type by now */
|
||||
}
|
||||
|
||||
if(NULL == post) {
|
||||
/* For the first file name, we allocate and initiate the main list
|
||||
node */
|
||||
|
||||
post = (struct HttpPost *)malloc(sizeof(struct HttpPost));
|
||||
if(post) {
|
||||
memset(post, 0, sizeof(struct HttpPost));
|
||||
GetStr(&post->name, name); /* get the name */
|
||||
GetStr(&post->contents, contp); /* get the contents */
|
||||
post->flags = flags;
|
||||
if(type) {
|
||||
GetStr(&post->contenttype, type); /* get type */
|
||||
prevtype=post->contenttype; /* point to the allocated string! */
|
||||
}
|
||||
/* make the previous point to this */
|
||||
if(*last_post)
|
||||
(*last_post)->next = post;
|
||||
else
|
||||
(*httppost) = post;
|
||||
|
||||
(*last_post) = post;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
/* we add a file name to the previously allocated node, known as
|
||||
'post' now */
|
||||
subpost =(struct HttpPost *)malloc(sizeof(struct HttpPost));
|
||||
if(subpost) {
|
||||
memset(subpost, 0, sizeof(struct HttpPost));
|
||||
GetStr(&subpost->name, name); /* get the name */
|
||||
GetStr(&subpost->contents, contp); /* get the contents */
|
||||
subpost->flags = flags;
|
||||
if(type) {
|
||||
GetStr(&subpost->contenttype, type); /* get type */
|
||||
prevtype=subpost->contenttype; /* point to the allocated string! */
|
||||
}
|
||||
/* now, point our 'more' to the original 'more' */
|
||||
subpost->more = post->more;
|
||||
|
||||
/* then move the original 'more' to point to ourselves */
|
||||
post->more = subpost;
|
||||
}
|
||||
}
|
||||
contp = sep; /* move the contents pointer to after the separator */
|
||||
} while(sep && *sep); /* loop if there's another file name */
|
||||
}
|
||||
else {
|
||||
post = (struct HttpPost *)malloc(sizeof(struct HttpPost));
|
||||
if(post) {
|
||||
memset(post, 0, sizeof(struct HttpPost));
|
||||
GetStr(&post->name, name); /* get the name */
|
||||
GetStr(&post->contents, contp); /* get the contents */
|
||||
post->flags = 0;
|
||||
|
||||
/* make the previous point to this */
|
||||
if(*last_post)
|
||||
(*last_post)->next = post;
|
||||
else
|
||||
(*httppost) = post;
|
||||
|
||||
(*last_post) = post;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Illegally formatted input field!\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AddFormData(struct FormData **formp,
|
||||
void *line,
|
||||
long length)
|
||||
{
|
||||
struct FormData *newform = (struct FormData *)
|
||||
malloc(sizeof(struct FormData));
|
||||
newform->next = NULL;
|
||||
|
||||
/* we make it easier for plain strings: */
|
||||
if(!length)
|
||||
length = strlen((char *)line);
|
||||
|
||||
newform->line = (char *)malloc(length+1);
|
||||
memcpy(newform->line, line, length+1);
|
||||
newform->length = length;
|
||||
|
||||
if(*formp) {
|
||||
(*formp)->next = newform;
|
||||
*formp = newform;
|
||||
}
|
||||
else
|
||||
*formp = newform;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
static int AddFormDataf(struct FormData **formp,
|
||||
char *fmt, ...)
|
||||
{
|
||||
char s[1024];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsprintf(s, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return AddFormData(formp, s, 0);
|
||||
}
|
||||
|
||||
|
||||
char *MakeFormBoundary(void)
|
||||
{
|
||||
char *retstring;
|
||||
static int randomizer=0; /* this is just so that two boundaries within
|
||||
the same form won't be identical */
|
||||
int i;
|
||||
|
||||
static char table64[]=
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
retstring = (char *)malloc(BOUNDARY_LENGTH);
|
||||
|
||||
if(!retstring)
|
||||
return NULL; /* failed */
|
||||
|
||||
srand(time(NULL)+randomizer++); /* seed */
|
||||
|
||||
strcpy(retstring, "curl"); /* bonus commercials 8*) */
|
||||
|
||||
for(i=4; i<(BOUNDARY_LENGTH-1); i++) {
|
||||
retstring[i] = table64[rand()%64];
|
||||
}
|
||||
retstring[BOUNDARY_LENGTH-1]=0; /* zero terminate */
|
||||
|
||||
return retstring;
|
||||
}
|
||||
|
||||
|
||||
void FormFree(struct FormData *form)
|
||||
{
|
||||
struct FormData *next;
|
||||
do {
|
||||
next=form->next; /* the following form line */
|
||||
free(form->line); /* free the line */
|
||||
free(form); /* free the struct */
|
||||
|
||||
} while(form=next); /* continue */
|
||||
}
|
||||
|
||||
struct FormData *getFormData(struct HttpPost *post,
|
||||
int *sizep)
|
||||
{
|
||||
struct FormData *form = NULL;
|
||||
struct FormData *firstform;
|
||||
|
||||
struct HttpPost *file;
|
||||
|
||||
int size =0;
|
||||
char *boundary;
|
||||
char *fileboundary=NULL;
|
||||
|
||||
if(!post)
|
||||
return NULL; /* no input => no output! */
|
||||
|
||||
boundary = MakeFormBoundary();
|
||||
|
||||
/* Make the first line of the output */
|
||||
AddFormDataf(&form,
|
||||
"Content-Type: multipart/form-data;"
|
||||
" boundary=%s\r\n",
|
||||
boundary);
|
||||
/* we DO NOT count that line since that'll be part of the header! */
|
||||
|
||||
firstform = form;
|
||||
|
||||
do {
|
||||
|
||||
/* boundary */
|
||||
size += AddFormDataf(&form, "\r\n--%s\r\n", boundary);
|
||||
|
||||
size += AddFormDataf(&form,
|
||||
"Content-Disposition: form-data; name=\"%s\"",
|
||||
post->name);
|
||||
|
||||
if(post->more) {
|
||||
/* If used, this is a link to more file names, we must then do
|
||||
the magic to include several files with the same field name */
|
||||
|
||||
fileboundary = MakeFormBoundary();
|
||||
|
||||
size += AddFormDataf(&form,
|
||||
"\r\nContent-Type: multipart/mixed,"
|
||||
" boundary=%s\r\n",
|
||||
fileboundary);
|
||||
}
|
||||
|
||||
file = post;
|
||||
|
||||
do {
|
||||
if(post->more) {
|
||||
/* if multiple-file */
|
||||
size += AddFormDataf(&form,
|
||||
"\r\n--%s\r\nContent-Disposition: attachment; filename=\"%s\"",
|
||||
fileboundary, file->contents);
|
||||
}
|
||||
else if(post->flags & HTTPPOST_FILENAME) {
|
||||
size += AddFormDataf(&form,
|
||||
"; filename=\"%s\"",
|
||||
post->contents);
|
||||
}
|
||||
|
||||
if(file->contenttype) {
|
||||
/* we have a specified type */
|
||||
size += AddFormDataf(&form,
|
||||
"\r\nContent-Type: %s",
|
||||
file->contenttype);
|
||||
}
|
||||
if(file->contenttype &&
|
||||
!strnequal("text/", file->contenttype, 5)) {
|
||||
/* this is not a text content, mention our binary encoding */
|
||||
size += AddFormDataf(&form,
|
||||
"\r\nContent-Transfer-Encoding: binary");
|
||||
}
|
||||
|
||||
|
||||
size += AddFormDataf(&form,
|
||||
"\r\n\r\n");
|
||||
|
||||
if(post->flags & HTTPPOST_FILENAME) {
|
||||
/* we should include the contents from the specified file */
|
||||
FILE *fileread;
|
||||
char buffer[1024];
|
||||
int nread;
|
||||
|
||||
fileread = strequal("-", file->contents)?stdin:
|
||||
/* binary read for win32 crap */
|
||||
fopen(file->contents, "rb");
|
||||
if(fileread) {
|
||||
while((nread = fread(buffer, 1, 1024, fileread))) {
|
||||
size += AddFormData(&form,
|
||||
buffer,
|
||||
nread);
|
||||
}
|
||||
if(fileread != stdin)
|
||||
fclose(fileread);
|
||||
}
|
||||
else {
|
||||
size += AddFormDataf(&form, "[File wasn't found by client]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* include the contents we got */
|
||||
size += AddFormDataf(&form,
|
||||
post->contents);
|
||||
}
|
||||
} while((file = file->more)); /* for each specified file for this field */
|
||||
|
||||
if(post->more) {
|
||||
/* this was a multiple-file inclusion, make a termination file
|
||||
boundary: */
|
||||
size += AddFormDataf(&form,
|
||||
"\r\n--%s--",
|
||||
fileboundary);
|
||||
free(fileboundary);
|
||||
}
|
||||
|
||||
} while((post=post->next)); /* for each field */
|
||||
|
||||
/* end-boundary for everything */
|
||||
size += AddFormDataf(&form,
|
||||
"\r\n--%s--\r\n",
|
||||
boundary);
|
||||
|
||||
*sizep = size;
|
||||
|
||||
free(boundary);
|
||||
|
||||
return firstform;
|
||||
}
|
||||
|
||||
int FormInit(struct Form *form, struct FormData *formdata )
|
||||
{
|
||||
form->data = formdata;
|
||||
form->sent = 0;
|
||||
|
||||
if(!formdata)
|
||||
return 1; /* error */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fread() emulation */
|
||||
int FormReader(char *buffer,
|
||||
size_t size,
|
||||
size_t nitems,
|
||||
FILE *mydata)
|
||||
{
|
||||
struct Form *form;
|
||||
int wantedsize;
|
||||
int gotsize;
|
||||
|
||||
form=(struct Form *)mydata;
|
||||
|
||||
wantedsize = size * nitems;
|
||||
|
||||
if(!form->data)
|
||||
return 0; /* nothing, error, empty */
|
||||
|
||||
do {
|
||||
|
||||
if( (form->data->length - form->sent ) > wantedsize ) {
|
||||
|
||||
memcpy(buffer, form->data->line + form->sent, wantedsize);
|
||||
|
||||
form->sent += wantedsize;
|
||||
|
||||
return wantedsize;
|
||||
}
|
||||
|
||||
memcpy(buffer,
|
||||
form->data->line + form->sent,
|
||||
gotsize = (form->data->length - form->sent) );
|
||||
|
||||
form->sent = 0;
|
||||
|
||||
form->data = form->data->next; /* advance */
|
||||
|
||||
} while(!gotsize && form->data);
|
||||
/* If we got an empty line and we have more data, we proceed to the next
|
||||
line immediately to avoid returning zero before we've reached the end.
|
||||
This is the bug reported November 22 1999 on curl 6.3. (Daniel) */
|
||||
|
||||
return gotsize;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _FORM_DEBUG
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if 0
|
||||
char *testargs[]={
|
||||
"name1 = data in number one",
|
||||
"name2 = number two data",
|
||||
"test = @upload"
|
||||
};
|
||||
#endif
|
||||
int i;
|
||||
char *nextarg;
|
||||
struct HttpPost *httppost=NULL;
|
||||
struct HttpPost *last_post=NULL;
|
||||
struct HttpPost *post;
|
||||
int size;
|
||||
int nread;
|
||||
char buffer[4096];
|
||||
|
||||
struct FormData *form;
|
||||
struct Form formread;
|
||||
|
||||
for(i=1; i<argc; i++) {
|
||||
|
||||
if( FormParse( argv[i],
|
||||
&httppost,
|
||||
&last_post)) {
|
||||
fprintf(stderr, "Illegally formatted input field: '%s'!\n",
|
||||
argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
form=getFormData(httppost, &size);
|
||||
|
||||
FormInit(&formread, form);
|
||||
|
||||
while(nread = FormReader(buffer, 1, sizeof(buffer), (FILE *)&formread)) {
|
||||
fwrite(buffer, nread, 1, stderr);
|
||||
}
|
||||
|
||||
fprintf(stderr, "size: %d\n", size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
103
lib/formdata.h
Normal file
103
lib/formdata.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef __FORMDATA_H
|
||||
#define __FORMDATA_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rafael Sagula <sagula@inf.ufrgs.br>
|
||||
* Sampo Kellomaki <sampo@iki.fi>
|
||||
* Linas Vepstas <linas@linas.org>
|
||||
* Bjorn Reese <breese@imada.ou.dk>
|
||||
* Johan Anderson <johan@homemail.com>
|
||||
* Kjell Ericson <Kjell.Ericson@haxx.nu>
|
||||
* Troy Engel <tengel@palladium.net>
|
||||
* Ryan Nelson <ryan@inch.com>
|
||||
* Bjorn Stenberg <Bjorn.Stenberg@haxx.nu>
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* $Log$
|
||||
* Revision 1.1 1999-12-29 14:21:22 bagder
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.4 1999/09/06 06:59:40 dast
|
||||
* Changed email info
|
||||
*
|
||||
* Revision 1.3 1999/08/13 07:34:47 dast
|
||||
* Changed the URL in the header
|
||||
*
|
||||
* Revision 1.2 1999/07/30 12:59:47 dast
|
||||
* FormFree() was added to properly cleanup after a form was posted.
|
||||
*
|
||||
* Revision 1.1.1.1 1999/03/11 22:23:34 dast
|
||||
* Imported sources
|
||||
*
|
||||
****************************************************************************/
|
||||
/* plain and simple linked list with lines to send */
|
||||
struct FormData {
|
||||
struct FormData *next;
|
||||
char *line;
|
||||
long length;
|
||||
};
|
||||
|
||||
struct Form {
|
||||
struct FormData *data; /* current form line to send */
|
||||
int sent; /* number of bytes of the current line that has already
|
||||
been sent in a previous invoke */
|
||||
};
|
||||
|
||||
int FormParse(char *string,
|
||||
struct HttpPost **httppost,
|
||||
struct HttpPost **last_post);
|
||||
|
||||
int FormInit(struct Form *form, struct FormData *formdata );
|
||||
|
||||
struct FormData *getFormData(struct HttpPost *post,
|
||||
int *size);
|
||||
|
||||
/* fread() emulation */
|
||||
int FormReader(char *buffer,
|
||||
size_t size,
|
||||
size_t nitems,
|
||||
FILE *mydata);
|
||||
|
||||
char *MakeFormBoundary(void);
|
||||
|
||||
void FormFree(struct FormData *);
|
||||
|
||||
#endif
|
||||
52
lib/ftp.h
Normal file
52
lib/ftp.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef __FTP_H
|
||||
#define __FTP_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError ftp(struct UrlData *data,
|
||||
long *bytecountp,
|
||||
char *ftpuser,
|
||||
char *ftppasswd,
|
||||
char *ppath);
|
||||
|
||||
struct curl_slist *curl_slist_append(struct curl_slist *list, char *data);
|
||||
void curl_slist_free_all(struct curl_slist *list);
|
||||
|
||||
#endif
|
||||
2101
lib/getdate.c
Normal file
2101
lib/getdate.c
Normal file
File diff suppressed because it is too large
Load diff
46
lib/getdate.h
Normal file
46
lib/getdate.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef vms
|
||||
# include <types.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
# else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif /* defined (vms) */
|
||||
|
||||
time_t get_date PARAMS ((const char *p, const time_t *now));
|
||||
1051
lib/getdate.y
Normal file
1051
lib/getdate.y
Normal file
File diff suppressed because it is too large
Load diff
95
lib/getenv.c
Normal file
95
lib/getenv.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rafael Sagula <sagula@inf.ufrgs.br>
|
||||
* Sampo Kellomaki <sampo@iki.fi>
|
||||
* Linas Vepstas <linas@linas.org>
|
||||
* Bjorn Reese <breese@imada.ou.dk>
|
||||
* Johan Anderson <johan@homemail.com>
|
||||
* Kjell Ericson <Kjell.Ericson@haxx.nu>
|
||||
* Troy Engel <tengel@palladium.net>
|
||||
* Ryan Nelson <ryan@inch.com>
|
||||
* Bjorn Stenberg <Bjorn.Stenberg@haxx.nu>
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* $Log$
|
||||
* Revision 1.1 1999-12-29 14:21:29 bagder
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.4 1999/09/06 06:59:40 dast
|
||||
* Changed email info
|
||||
*
|
||||
* Revision 1.3 1999/08/13 07:34:48 dast
|
||||
* Changed the URL in the header
|
||||
*
|
||||
* Revision 1.2 1999/03/13 00:56:09 dast
|
||||
* Big changes done due to url.c being split up in X smaller files and that
|
||||
* the lib is now more stand-alone.
|
||||
*
|
||||
* Revision 1.1.1.1 1999/03/11 22:23:34 dast
|
||||
* Imported sources
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
char *GetEnv(char *variable)
|
||||
{
|
||||
#ifdef WIN32
|
||||
/* This shit requires windows.h (HUGE) to be included */
|
||||
static char env[MAX_PATH]; /* MAX_PATH is from windef.h */
|
||||
char *temp = getenv(variable);
|
||||
env[0] = '\0';
|
||||
ExpandEnvironmentStrings(temp, env, sizeof(env));
|
||||
#else
|
||||
/* no length control */
|
||||
char *env = getenv(variable);
|
||||
#endif
|
||||
return env;
|
||||
}
|
||||
|
||||
char *curl_GetEnv(char *v)
|
||||
{
|
||||
return GetEnv(v);
|
||||
}
|
||||
71
lib/getenv.h
Normal file
71
lib/getenv.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#ifndef __GETENV_H
|
||||
#define __GETENV_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rafael Sagula <sagula@inf.ufrgs.br>
|
||||
* Sampo Kellomaki <sampo@iki.fi>
|
||||
* Linas Vepstas <linas@linas.org>
|
||||
* Bjorn Reese <breese@imada.ou.dk>
|
||||
* Johan Anderson <johan@homemail.com>
|
||||
* Kjell Ericson <Kjell.Ericson@haxx.nu>
|
||||
* Troy Engel <tengel@palladium.net>
|
||||
* Ryan Nelson <ryan@inch.com>
|
||||
* Bjorn Stenberg <Bjorn.Stenberg@haxx.nu>
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* $Log$
|
||||
* Revision 1.1 1999-12-29 14:21:30 bagder
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.3 1999/09/06 06:59:40 dast
|
||||
* Changed email info
|
||||
*
|
||||
* Revision 1.2 1999/08/13 07:34:48 dast
|
||||
* Changed the URL in the header
|
||||
*
|
||||
* Revision 1.1.1.1 1999/03/11 22:23:34 dast
|
||||
* Imported sources
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* Unix and Win32 getenv function call */
|
||||
char *GetEnv(char *variable);
|
||||
|
||||
#endif
|
||||
185
lib/getpass.c
Normal file
185
lib/getpass.c
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/* ============================================================================
|
||||
* Copyright (C) 1998 Angus Mackay. All rights reserved;
|
||||
*
|
||||
* Redistribution and use are freely permitted provided that:
|
||||
*
|
||||
* 1) This header remain in tact.
|
||||
* 2) The prototype for getpass is not changed from:
|
||||
* char *getpass(const char *prompt)
|
||||
* 3) This source code is not used outside of this(getpass.c) file.
|
||||
* 3) Any changes to this(getpass.c) source code are made publicly available.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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
|
||||
* AUTHOR 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.
|
||||
* ============================================================================
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* The spirit of this license is to allow use of this source code in any
|
||||
* project be it open or closed but still encourage the use of the open,
|
||||
* library based equivilents.
|
||||
*
|
||||
* Author(s):
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* Contributor(s):
|
||||
* Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# if !defined(HAVE_TCGETATTR) && !defined(HAVE_TCSETATTR)
|
||||
# undef HAVE_TERMIOS_H
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define INPUT_BUFFER 128
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#else
|
||||
# ifdef HAVE_TERMIO_H
|
||||
# include <termio.h>
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* no perror? make an fprintf! */
|
||||
#ifndef HAVE_PERROR
|
||||
# define perror(x) fprintf(stderr, "Error in: %s\n", x)
|
||||
#endif
|
||||
|
||||
char *getpass(const char *prompt)
|
||||
{
|
||||
FILE *infp;
|
||||
FILE *outfp;
|
||||
static char buf[INPUT_BUFFER];
|
||||
RETSIGTYPE (*sigint)();
|
||||
RETSIGTYPE (*sigtstp)();
|
||||
size_t bytes_read;
|
||||
int infd;
|
||||
int outfd;
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
struct termios orig;
|
||||
struct termios noecho;
|
||||
#else
|
||||
# ifdef HAVE_TERMIO_H
|
||||
struct termio orig;
|
||||
struct termio noecho;
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
|
||||
sigint = signal(SIGINT, SIG_IGN);
|
||||
sigtstp = signal(SIGTSTP, SIG_IGN);
|
||||
|
||||
if( (infp=fopen("/dev/tty", "r")) == NULL )
|
||||
{
|
||||
infp = stdin;
|
||||
}
|
||||
if( (outfp=fopen("/dev/tty", "w")) == NULL )
|
||||
{
|
||||
outfp = stderr;
|
||||
}
|
||||
infd = fileno(infp);
|
||||
outfd = fileno(outfp);
|
||||
|
||||
/* dissable echo */
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
if(tcgetattr(outfd, &orig) != 0)
|
||||
{
|
||||
perror("tcgetattr");
|
||||
}
|
||||
noecho = orig;
|
||||
noecho.c_lflag &= ~ECHO;
|
||||
if(tcsetattr(outfd, TCSANOW, &noecho) != 0)
|
||||
{
|
||||
perror("tcgetattr");
|
||||
}
|
||||
#else
|
||||
# ifdef HAVE_TERMIO_H
|
||||
if(ioctl(outfd, TCGETA, &orig) != 0)
|
||||
{
|
||||
perror("ioctl");
|
||||
}
|
||||
noecho = orig;
|
||||
noecho.c_lflag &= ~ECHO;
|
||||
if(ioctl(outfd, TCSETA, &noecho) != 0)
|
||||
{
|
||||
perror("ioctl");
|
||||
}
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
|
||||
fputs(prompt, outfp);
|
||||
fflush(outfp);
|
||||
|
||||
bytes_read=read(infd, buf, INPUT_BUFFER);
|
||||
buf[bytes_read > 0 ? (bytes_read -1) : 0] = '\0';
|
||||
|
||||
/* print a new line if needed */
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
fputs("\n", outfp);
|
||||
#else
|
||||
# ifdef HAVE_TERMIO_H
|
||||
fputs("\n", outfp);
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* reset term charectaristics, use TCSAFLUSH incase the
|
||||
* user types more than INPUT_BUFFER
|
||||
*/
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
if(tcsetattr(outfd, TCSAFLUSH, &orig) != 0)
|
||||
{
|
||||
perror("tcgetattr");
|
||||
}
|
||||
#else
|
||||
# ifdef HAVE_TERMIO_H
|
||||
if(ioctl(outfd, TCSETA, &orig) != 0)
|
||||
{
|
||||
perror("ioctl");
|
||||
}
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
signal(SIGTSTP, sigtstp);
|
||||
|
||||
return(buf);
|
||||
}
|
||||
#else
|
||||
#include <stdio.h>
|
||||
char *getpass(const char *prompt)
|
||||
{
|
||||
static char password[80];
|
||||
printf(prompt);
|
||||
gets(password);
|
||||
return password;
|
||||
}
|
||||
#endif /* don't do anything if WIN32 */
|
||||
1
lib/getpass.h
Normal file
1
lib/getpass.h
Normal file
|
|
@ -0,0 +1 @@
|
|||
char *getpass(const char *prompt);
|
||||
111
lib/hostip.c
Normal file
111
lib/hostip.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include "sendf.h"
|
||||
|
||||
/* --- resolve name or IP-number --- */
|
||||
|
||||
char *MakeIP(unsigned long num)
|
||||
{
|
||||
#ifdef HAVE_INET_NTOA
|
||||
struct in_addr in;
|
||||
|
||||
in.s_addr = htonl(num);
|
||||
return (inet_ntoa(in));
|
||||
#else
|
||||
static char addr[128];
|
||||
unsigned char *paddr;
|
||||
|
||||
num = htonl(num); /* htonl() added to avoid endian probs */
|
||||
paddr = (unsigned char *)#
|
||||
sprintf(addr, "%u.%u.%u.%u", paddr[0], paddr[1], paddr[2], paddr[3]);
|
||||
return (addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Stolen from Dancer source code, written by
|
||||
Bjorn Reese <breese@imada.ou.dk> */
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE (unsigned long) ~0
|
||||
#endif
|
||||
struct hostent *GetHost(struct UrlData *data, char *hostname)
|
||||
{
|
||||
struct hostent *h = NULL;
|
||||
unsigned long in;
|
||||
static struct hostent he;
|
||||
static char name[MAXHOSTNAMELEN];
|
||||
static char *addrlist[2];
|
||||
static struct in_addr addrentry;
|
||||
|
||||
if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
|
||||
addrentry.s_addr = in;
|
||||
addrlist[0] = (char *)&addrentry;
|
||||
addrlist[1] = NULL;
|
||||
he.h_name = strncpy(name, MakeIP(ntohl(in)), MAXHOSTNAMELEN);
|
||||
he.h_addrtype = AF_INET;
|
||||
he.h_length = sizeof(struct in_addr);
|
||||
he.h_addr_list = addrlist;
|
||||
h = &he;
|
||||
} else if ( (h=gethostbyname(hostname)) == NULL ) {
|
||||
infof(data, "gethostbyname(2) failed for %s\n", hostname);
|
||||
}
|
||||
return (h);
|
||||
}
|
||||
46
lib/hostip.h
Normal file
46
lib/hostip.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef __HOSTIP_H
|
||||
#define __HOSTIP_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
struct hostent *GetHost(struct UrlData *data, char *hostname);
|
||||
char *MakeIP(unsigned long num);
|
||||
|
||||
#endif
|
||||
381
lib/http.c
Normal file
381
lib/http.c
Normal file
|
|
@ -0,0 +1,381 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* -- WIN32 approved -- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
#include "download.h"
|
||||
#include "sendf.h"
|
||||
#include "formdata.h"
|
||||
#include "progress.h"
|
||||
#include "base64.h"
|
||||
#include "upload.h"
|
||||
#include "cookie.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
/*
|
||||
* This function checks the linked list of custom HTTP headers for a particular
|
||||
* header (prefix).
|
||||
*/
|
||||
bool static checkheaders(struct UrlData *data, char *thisheader)
|
||||
{
|
||||
struct HttpHeader *head;
|
||||
size_t thislen = strlen(thisheader);
|
||||
|
||||
for(head = data->headers; head; head=head->next) {
|
||||
if(strnequal(head->header, thisheader, thislen)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UrgError http(struct UrlData *data, char *ppath, char *host, long *bytecount)
|
||||
{
|
||||
/* Send the GET line to the HTTP server */
|
||||
|
||||
struct FormData *sendit=NULL;
|
||||
int postsize=0;
|
||||
UrgError result;
|
||||
char *buf;
|
||||
struct Cookie *co = NULL;
|
||||
char *p_pragma = NULL;
|
||||
char *p_accept = NULL;
|
||||
|
||||
buf = data->buffer; /* this is our buffer */
|
||||
|
||||
if ( (data->conf&(CONF_HTTP|CONF_FTP)) &&
|
||||
(data->conf&CONF_UPLOAD)) {
|
||||
data->conf |= CONF_PUT;
|
||||
}
|
||||
#if 0 /* old version */
|
||||
if((data->conf&(CONF_HTTP|CONF_UPLOAD)) ==
|
||||
(CONF_HTTP|CONF_UPLOAD)) {
|
||||
/* enable PUT! */
|
||||
data->conf |= CONF_PUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The User-Agent string has been built in url.c already, because it might
|
||||
have been used in the proxy connect, but if we have got a header with
|
||||
the user-agent string specified, we erase the previosly made string
|
||||
here. */
|
||||
if(checkheaders(data, "User-Agent:") && data->ptr_uagent) {
|
||||
free(data->ptr_uagent);
|
||||
data->ptr_uagent=NULL;
|
||||
}
|
||||
|
||||
if((data->conf & CONF_USERPWD) && !checkheaders(data, "Authorization:")) {
|
||||
char authorization[512];
|
||||
sprintf(data->buffer, "%s:%s", data->user, data->passwd);
|
||||
base64Encode(data->buffer, authorization);
|
||||
data->ptr_userpwd = maprintf( "Authorization: Basic %s\015\012",
|
||||
authorization);
|
||||
}
|
||||
if((data->conf & CONF_RANGE) && !checkheaders(data, "Range:")) {
|
||||
data->ptr_rangeline = maprintf("Range: bytes=%s\015\012", data->range);
|
||||
}
|
||||
if((data->conf & CONF_REFERER) && !checkheaders(data, "Referer:")) {
|
||||
data->ptr_ref = maprintf("Referer: %s\015\012", data->referer);
|
||||
}
|
||||
if(data->cookie && !checkheaders(data, "Cookie:")) {
|
||||
data->ptr_cookie = maprintf("Cookie: %s\015\012", data->cookie);
|
||||
}
|
||||
|
||||
if(data->cookies) {
|
||||
co = cookie_getlist(data->cookies,
|
||||
host,
|
||||
ppath,
|
||||
data->conf&CONF_HTTPS?TRUE:FALSE);
|
||||
}
|
||||
if ((data->conf & CONF_PROXY) && (!(data->conf & CONF_HTTPS))) {
|
||||
/* The path sent to the proxy is in fact the entire URL */
|
||||
strncpy(ppath, data->url, URL_MAX_LENGTH-1);
|
||||
}
|
||||
if(data->conf & CONF_HTTPPOST) {
|
||||
/* we must build the whole darned post sequence first, so that we have
|
||||
a size of the whole shebang before we start to send it */
|
||||
sendit = getFormData(data->httppost, &postsize);
|
||||
}
|
||||
|
||||
if(!checkheaders(data, "Host:"))
|
||||
data->ptr_host = maprintf("Host: %s\r\n", host);
|
||||
|
||||
|
||||
if(!checkheaders(data, "Pragma:"))
|
||||
p_pragma = "Pragma: no-cache\r\n";
|
||||
|
||||
if(!checkheaders(data, "Accept:"))
|
||||
p_accept = "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n";
|
||||
|
||||
do {
|
||||
sendf(data->firstsocket, data,
|
||||
"%s " /* GET/HEAD/POST/PUT */
|
||||
"%s HTTP/1.0\r\n" /* path */
|
||||
"%s" /* proxyuserpwd */
|
||||
"%s" /* userpwd */
|
||||
"%s" /* range */
|
||||
"%s" /* user agent */
|
||||
"%s" /* cookie */
|
||||
"%s" /* host */
|
||||
"%s" /* pragma */
|
||||
"%s" /* accept */
|
||||
"%s", /* referer */
|
||||
|
||||
data->customrequest?data->customrequest:
|
||||
(data->conf&CONF_NOBODY?"HEAD":
|
||||
(data->conf&(CONF_POST|CONF_HTTPPOST))?"POST":
|
||||
(data->conf&CONF_PUT)?"PUT":"GET"),
|
||||
ppath,
|
||||
(data->conf&CONF_PROXYUSERPWD && data->ptr_proxyuserpwd)?data->ptr_proxyuserpwd:"",
|
||||
(data->conf&CONF_USERPWD && data->ptr_userpwd)?data->ptr_userpwd:"",
|
||||
(data->conf&CONF_RANGE && data->ptr_rangeline)?data->ptr_rangeline:"",
|
||||
(data->useragent && *data->useragent && data->ptr_uagent)?data->ptr_uagent:"",
|
||||
(data->ptr_cookie?data->ptr_cookie:""), /* Cookie: <data> */
|
||||
(data->ptr_host?data->ptr_host:""), /* Host: host */
|
||||
p_pragma?p_pragma:"",
|
||||
p_accept?p_accept:"",
|
||||
(data->conf&CONF_REFERER && data->ptr_ref)?data->ptr_ref:"" /* Referer: <data> <CRLF> */
|
||||
);
|
||||
|
||||
if(co) {
|
||||
int count=0;
|
||||
/* now loop through all cookies that matched */
|
||||
while(co) {
|
||||
if(0 == count) {
|
||||
sendf(data->firstsocket, data,
|
||||
"Cookie: ");
|
||||
}
|
||||
count++;
|
||||
sendf(data->firstsocket, data,
|
||||
"%s=%s;", co->name, co->value);
|
||||
co = co->next; /* next cookie please */
|
||||
}
|
||||
if(count) {
|
||||
sendf(data->firstsocket, data,
|
||||
"\r\n");
|
||||
}
|
||||
cookie_freelist(co); /* free the cookie list */
|
||||
co=NULL;
|
||||
}
|
||||
|
||||
if(data->timecondition) {
|
||||
struct tm *thistime;
|
||||
|
||||
thistime = localtime(&data->timevalue);
|
||||
|
||||
#if defined(HAVE_STRFTIME) || defined(WIN32)
|
||||
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
|
||||
strftime(buf, BUFSIZE-1, "%a, %d %b %Y %H:%M:%S %Z", thistime);
|
||||
#else
|
||||
/* Right, we *could* write a replacement here */
|
||||
strcpy(buf, "no strftime() support");
|
||||
#endif
|
||||
switch(data->timecondition) {
|
||||
case TIMECOND_IFMODSINCE:
|
||||
default:
|
||||
sendf(data->firstsocket, data,
|
||||
"If-Modified-Since: %s\r\n", buf);
|
||||
break;
|
||||
case TIMECOND_IFUNMODSINCE:
|
||||
sendf(data->firstsocket, data,
|
||||
"If-Unmodified-Since: %s\r\n", buf);
|
||||
break;
|
||||
case TIMECOND_LASTMOD:
|
||||
sendf(data->firstsocket, data,
|
||||
"Last-Modified: %s\r\n", buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while(data->headers) {
|
||||
sendf(data->firstsocket, data,
|
||||
"%s\015\012",
|
||||
data->headers->header);
|
||||
data->headers = data->headers->next;
|
||||
}
|
||||
|
||||
if(data->conf&(CONF_POST|CONF_HTTPPOST)) {
|
||||
if(data->conf & CONF_POST) {
|
||||
/* this is the simple x-www-form-urlencoded style */
|
||||
sendf(data->firstsocket, data,
|
||||
"Content-Length: %d\015\012"
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n\r\n"
|
||||
"%s\015\012",
|
||||
strlen(data->postfields),
|
||||
data->postfields );
|
||||
}
|
||||
else {
|
||||
struct Form form;
|
||||
size_t (*storefread)(char *, size_t , size_t , FILE *);
|
||||
FILE *in;
|
||||
long conf;
|
||||
|
||||
if(FormInit(&form, sendit)) {
|
||||
failf(data, "Internal HTTP POST error!\n");
|
||||
return URG_HTTP_POST_ERROR;
|
||||
}
|
||||
|
||||
storefread = data->fread; /* backup */
|
||||
in = data->in; /* backup */
|
||||
|
||||
data->fread =
|
||||
(size_t (*)(char *, size_t, size_t, FILE *))
|
||||
FormReader; /* set the read function to read from the
|
||||
generated form data */
|
||||
data->in = (FILE *)&form;
|
||||
|
||||
sendf(data->firstsocket, data,
|
||||
"Content-Length: %d\r\n",
|
||||
postsize-2);
|
||||
|
||||
conf = data->conf;
|
||||
data->conf &= ~CONF_NOPROGRESS; /* enable progress meter */
|
||||
ProgressInit(data, postsize);
|
||||
|
||||
result = Upload(data, data->firstsocket, bytecount);
|
||||
|
||||
FormFree(sendit); /* Now free that whole lot */
|
||||
|
||||
data->conf = conf; /* restore conf values for the download */
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
data->fread = storefread; /* restore */
|
||||
data->in = in; /* restore */
|
||||
|
||||
sendf(data->firstsocket, data,
|
||||
"\r\n\r\n");
|
||||
}
|
||||
}
|
||||
else if(data->conf&CONF_PUT) {
|
||||
/* Let's PUT the data to the server! */
|
||||
long conf;
|
||||
|
||||
if(data->infilesize>0) {
|
||||
sendf(data->firstsocket, data,
|
||||
"Content-Length: %d\r\n\r\n", /* file size */
|
||||
data->infilesize );
|
||||
}
|
||||
else
|
||||
sendf(data->firstsocket, data,
|
||||
"\015\012");
|
||||
|
||||
conf = data->conf;
|
||||
data->conf &= ~CONF_NOPROGRESS; /* enable progress meter */
|
||||
|
||||
ProgressInit(data, data->infilesize);
|
||||
|
||||
result = Upload(data, data->firstsocket, bytecount);
|
||||
|
||||
data->conf = conf;
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
/* reset the byte counter */
|
||||
*bytecount=0;
|
||||
}
|
||||
else {
|
||||
sendf(data->firstsocket, data, "\r\n");
|
||||
}
|
||||
/* HTTP GET/HEAD download: */
|
||||
result = Download(data, data->firstsocket, -1, TRUE, bytecount);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
ProgressEnd(data);
|
||||
} while (0); /* this is just a left-over from the multiple document download
|
||||
attempts */
|
||||
|
||||
return URG_OK;
|
||||
}
|
||||
|
||||
45
lib/http.h
Normal file
45
lib/http.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __HTTP_H
|
||||
#define __HTTP_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError http(struct UrlData *data, char *path, char *host, long *bytecountp);
|
||||
|
||||
#endif
|
||||
110
lib/if2ip.c
Normal file
110
lib/if2ip.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if ! defined(WIN32) && ! defined(__BEOS__)
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* -- if2ip() -- */
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#define SYS_ERROR -1
|
||||
|
||||
char *if2ip(char *interface)
|
||||
{
|
||||
int dummy;
|
||||
char *ip=NULL;
|
||||
|
||||
if(!interface)
|
||||
return NULL;
|
||||
|
||||
dummy = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (SYS_ERROR == dummy) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
struct ifreq req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
strcpy(req.ifr_name, interface);
|
||||
req.ifr_addr.sa_family = AF_INET;
|
||||
if (SYS_ERROR == ioctl(dummy, SIOCGIFADDR, &req, sizeof(req))) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
struct in_addr in;
|
||||
|
||||
struct sockaddr_in *s = (struct sockaddr_in *)&req.ifr_dstaddr;
|
||||
memcpy(&in, &(s->sin_addr.s_addr), sizeof(in));
|
||||
ip = (char *)strdup(inet_ntoa(in));
|
||||
}
|
||||
close(dummy);
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/* -- end of if2ip() -- */
|
||||
#else
|
||||
#define if2ip(x) NULL
|
||||
#endif
|
||||
50
lib/if2ip.h
Normal file
50
lib/if2ip.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef __IF2IP_H
|
||||
#define __IF2IP_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
#include "setup.h"
|
||||
|
||||
#if ! defined(WIN32) && ! defined(__BEOS__)
|
||||
char *if2ip(char *interface);
|
||||
#else
|
||||
#define if2ip(x) NULL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
226
lib/ldap.c
Normal file
226
lib/ldap.c
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Contributor(s):
|
||||
* Bjørn Reese <breese@mail1.stofanet.dk>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* -- WIN32 approved -- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__)
|
||||
#else
|
||||
# ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# ifdef HAVE_DLFCN_H
|
||||
# include <dlfcn.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
#include "sendf.h"
|
||||
#include "escape.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
|
||||
#define DYNA_GET_FUNCTION(type, fnc) \
|
||||
(fnc) = (type)DynaGetFunction(#fnc); \
|
||||
if ((fnc) == NULL) { \
|
||||
return URG_FUNCTION_NOT_FOUND; \
|
||||
} \
|
||||
|
||||
/***********************************************************************
|
||||
*/
|
||||
static void *libldap = NULL;
|
||||
static void *liblber = NULL;
|
||||
|
||||
static void DynaOpen(void)
|
||||
{
|
||||
#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
|
||||
if (libldap == NULL) {
|
||||
/*
|
||||
* libldap.so should be able to resolve its dependency on
|
||||
* liblber.so automatically, but since it does not we will
|
||||
* handle it here by opening liblber.so as global.
|
||||
*/
|
||||
dlopen("liblber.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||
libldap = dlopen("libldap.so", RTLD_LAZY);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DynaClose(void)
|
||||
{
|
||||
#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
|
||||
if (libldap) {
|
||||
dlclose(libldap);
|
||||
}
|
||||
if (liblber) {
|
||||
dlclose(liblber);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void * DynaGetFunction(char *name)
|
||||
{
|
||||
void *func = NULL;
|
||||
|
||||
#if defined(HAVE_DLOPEN) || defined(HAVE_LIBDL)
|
||||
if (libldap) {
|
||||
func = dlsym(libldap, name);
|
||||
}
|
||||
#endif
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
static int WriteProc(void *param, char *text, int len)
|
||||
{
|
||||
struct UrlData *data = (struct UrlData *)param;
|
||||
|
||||
printf("%s\n", text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*/
|
||||
UrgError ldap(struct UrlData *data, char *path, long *bytecount)
|
||||
{
|
||||
UrgError status = URG_OK;
|
||||
int rc;
|
||||
void *(*ldap_open)(char *, int);
|
||||
int (*ldap_simple_bind_s)(void *, char *, char *);
|
||||
int (*ldap_unbind_s)(void *);
|
||||
int (*ldap_url_search_s)(void *, char *, int, void **);
|
||||
void *(*ldap_first_entry)(void *, void *);
|
||||
void *(*ldap_next_entry)(void *, void *);
|
||||
char *(*ldap_err2string)(int);
|
||||
int (*ldap_entry2text)(void *, char *, void *, void *, char **, char **, int (*)(void *, char *, int), void *, char *, int, unsigned long);
|
||||
int (*ldap_entry2html)(void *, char *, void *, void *, char **, char **, int (*)(void *, char *, int), void *, char *, int, unsigned long, char *, char *);
|
||||
void *server;
|
||||
void *result;
|
||||
void *entryIterator;
|
||||
#if 0
|
||||
char *dn;
|
||||
char **attrArray;
|
||||
char *attrIterator;
|
||||
char *attrString;
|
||||
void *dummy;
|
||||
#endif
|
||||
int ldaptext;
|
||||
|
||||
infof(data, "LDAP: %s %s\n", data->url);
|
||||
|
||||
DynaOpen();
|
||||
if (libldap == NULL) {
|
||||
failf(data, "The needed LDAP library/libraries couldn't be opened");
|
||||
return URG_LIBRARY_NOT_FOUND;
|
||||
}
|
||||
|
||||
ldaptext = data->conf & CONF_FTPASCII; /* This is a dirty hack */
|
||||
|
||||
/* The types are needed because ANSI C distinguishes between
|
||||
* pointer-to-object (data) and pointer-to-function.
|
||||
*/
|
||||
DYNA_GET_FUNCTION(void *(*)(char *, int), ldap_open);
|
||||
DYNA_GET_FUNCTION(int (*)(void *, char *, char *), ldap_simple_bind_s);
|
||||
DYNA_GET_FUNCTION(int (*)(void *), ldap_unbind_s);
|
||||
DYNA_GET_FUNCTION(int (*)(void *, char *, int, void **), ldap_url_search_s);
|
||||
DYNA_GET_FUNCTION(void *(*)(void *, void *), ldap_first_entry);
|
||||
DYNA_GET_FUNCTION(void *(*)(void *, void *), ldap_next_entry);
|
||||
DYNA_GET_FUNCTION(char *(*)(int), ldap_err2string);
|
||||
DYNA_GET_FUNCTION(int (*)(void *, char *, void *, void *, char **, char **, int (*)(void *, char *, int), void *, char *, int, unsigned long), ldap_entry2text);
|
||||
DYNA_GET_FUNCTION(int (*)(void *, char *, void *, void *, char **, char **, int (*)(void *, char *, int), void *, char *, int, unsigned long, char *, char *), ldap_entry2html);
|
||||
|
||||
server = ldap_open(data->hostname, data->port);
|
||||
if (server == NULL) {
|
||||
failf(data, "LDAP: Cannot connect to %s:%d",
|
||||
data->hostname, data->port);
|
||||
status = URG_COULDNT_CONNECT;
|
||||
} else {
|
||||
rc = ldap_simple_bind_s(server, data->user, data->passwd);
|
||||
if (rc != 0) {
|
||||
failf(data, "LDAP: %s", ldap_err2string(rc));
|
||||
status = URG_LDAP_CANNOT_BIND;
|
||||
} else {
|
||||
rc = ldap_url_search_s(server, data->url, 0, &result);
|
||||
if (rc != 0) {
|
||||
failf(data, "LDAP: %s", ldap_err2string(rc));
|
||||
status = URG_LDAP_SEARCH_FAILED;
|
||||
} else {
|
||||
for (entryIterator = ldap_first_entry(server, result);
|
||||
entryIterator;
|
||||
entryIterator = ldap_next_entry(server, entryIterator))
|
||||
{
|
||||
if (ldaptext) {
|
||||
rc = ldap_entry2text(server, NULL, entryIterator, NULL,
|
||||
NULL, NULL, WriteProc, data,
|
||||
"", 0, 0);
|
||||
if (rc != 0) {
|
||||
failf(data, "LDAP: %s", ldap_err2string(rc));
|
||||
status = URG_LDAP_SEARCH_FAILED;
|
||||
}
|
||||
} else {
|
||||
rc = ldap_entry2html(server, NULL, entryIterator, NULL,
|
||||
NULL, NULL, WriteProc, data,
|
||||
"", 0, 0, NULL, NULL);
|
||||
if (rc != 0) {
|
||||
failf(data, "LDAP: %s", ldap_err2string(rc));
|
||||
status = URG_LDAP_SEARCH_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ldap_unbind_s(server);
|
||||
}
|
||||
}
|
||||
DynaClose();
|
||||
|
||||
return status;
|
||||
}
|
||||
45
lib/ldap.h
Normal file
45
lib/ldap.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __LDAP_H
|
||||
#define __LDAP_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://www.fts.frontec.se/~dast/curl/
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError ldap(struct UrlData *data, char *path, long *bytecount);
|
||||
|
||||
#endif /* __LDAP_H */
|
||||
1253
lib/mprintf.c
Normal file
1253
lib/mprintf.c
Normal file
File diff suppressed because it is too large
Load diff
182
lib/netrc.c
Normal file
182
lib/netrc.c
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rafael Sagula <sagula@inf.ufrgs.br>
|
||||
* Sampo Kellomaki <sampo@iki.fi>
|
||||
* Linas Vepstas <linas@linas.org>
|
||||
* Bjorn Reese <breese@imada.ou.dk>
|
||||
* Johan Anderson <johan@homemail.com>
|
||||
* Kjell Ericson <Kjell.Ericson@haxx.nu>
|
||||
* Troy Engel <tengel@palladium.net>
|
||||
* Ryan Nelson <ryan@inch.com>
|
||||
* Bjorn Stenberg <Bjorn.Stenberg@haxx.nu>
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "setup.h"
|
||||
#include "getenv.h"
|
||||
|
||||
/* Debug this single source file with:
|
||||
'make netrc' then run './netrc'!
|
||||
|
||||
Oh, make sure you have a .netrc file too ;-)
|
||||
*/
|
||||
|
||||
/* Get user and password from .netrc when given a machine name */
|
||||
|
||||
enum {
|
||||
NOTHING,
|
||||
HOSTFOUND, /* the 'machine' keyword was found */
|
||||
HOSTCOMPLETE, /* the machine name following the keyword was found too */
|
||||
HOSTVALID, /* this is "our" machine! */
|
||||
|
||||
HOSTEND /* LAST enum */
|
||||
};
|
||||
|
||||
/* make sure we have room for at least this size: */
|
||||
#define LOGINSIZE 64
|
||||
#define PASSWORDSIZE 64
|
||||
|
||||
int ParseNetrc(char *host,
|
||||
char *login,
|
||||
char *password)
|
||||
{
|
||||
FILE *file;
|
||||
char netrcbuffer[256];
|
||||
int retcode=1;
|
||||
|
||||
char *home = GetEnv("HOME"); /* portable environment reader */
|
||||
int state=NOTHING;
|
||||
|
||||
char state_login=0;
|
||||
char state_password=0;
|
||||
|
||||
#define NETRC DOT_CHAR "netrc"
|
||||
|
||||
if(!home || (strlen(home)>(sizeof(netrcbuffer)-strlen(NETRC))))
|
||||
return -1;
|
||||
|
||||
sprintf(netrcbuffer, "%s%s%s", home, DIR_CHAR, NETRC);
|
||||
|
||||
file = fopen(netrcbuffer, "r");
|
||||
if(file) {
|
||||
char *tok;
|
||||
while(fgets(netrcbuffer, sizeof(netrcbuffer), file)) {
|
||||
tok=strtok(netrcbuffer, " \t\n");
|
||||
while(tok) {
|
||||
switch(state) {
|
||||
case NOTHING:
|
||||
if(strequal("machine", tok)) {
|
||||
/* the next tok is the machine name, this is in itself the
|
||||
delimiter that starts the stuff entered for this machine,
|
||||
after this we need to search for 'login' and
|
||||
'password'. */
|
||||
state=HOSTFOUND;
|
||||
}
|
||||
break;
|
||||
case HOSTFOUND:
|
||||
if(strequal(host, tok)) {
|
||||
/* and yes, this is our host! */
|
||||
state=HOSTVALID;
|
||||
#ifdef _NETRC_DEBUG
|
||||
printf("HOST: %s\n", tok);
|
||||
#endif
|
||||
retcode=0; /* we did find our host */
|
||||
}
|
||||
else
|
||||
/* not our host */
|
||||
state=NOTHING;
|
||||
break;
|
||||
case HOSTVALID:
|
||||
/* we are now parsing sub-keywords concerning "our" host */
|
||||
if(state_login) {
|
||||
strncpy(login, tok, LOGINSIZE-1);
|
||||
#ifdef _NETRC_DEBUG
|
||||
printf("LOGIN: %s\n", login);
|
||||
#endif
|
||||
state_login=0;
|
||||
}
|
||||
else if(state_password) {
|
||||
strncpy(password, tok, PASSWORDSIZE-1);
|
||||
#if _NETRC_DEBUG
|
||||
printf("PASSWORD: %s\n", password);
|
||||
#endif
|
||||
state_password=0;
|
||||
}
|
||||
else if(strequal("login", tok))
|
||||
state_login=1;
|
||||
else if(strequal("password", tok))
|
||||
state_password=1;
|
||||
else if(strequal("machine", tok)) {
|
||||
/* ok, there's machine here go => */
|
||||
state = HOSTFOUND;
|
||||
}
|
||||
break;
|
||||
} /* switch (state) */
|
||||
tok = strtok(NULL, " \t\n");
|
||||
} /* while (tok) */
|
||||
} /* while fgets() */
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
#ifdef _NETRC_DEBUG
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char login[64]="";
|
||||
char password[64]="";
|
||||
|
||||
if(argc<2)
|
||||
return -1;
|
||||
|
||||
if(0 == ParseNetrc(argv[1], login, password)) {
|
||||
printf("HOST: %s LOGIN: %s PASSWORD: %s\n",
|
||||
argv[1], login, password);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
70
lib/netrc.h
Normal file
70
lib/netrc.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef __NETRC_H
|
||||
#define __NETRC_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rafael Sagula <sagula@inf.ufrgs.br>
|
||||
* Sampo Kellomaki <sampo@iki.fi>
|
||||
* Linas Vepstas <linas@linas.org>
|
||||
* Bjorn Reese <breese@imada.ou.dk>
|
||||
* Johan Anderson <johan@homemail.com>
|
||||
* Kjell Ericson <Kjell.Ericson@haxx.nu>
|
||||
* Troy Engel <tengel@palladium.net>
|
||||
* Ryan Nelson <ryan@inch.com>
|
||||
* Bjorn Stenberg <Bjorn.Stenberg@haxx.nu>
|
||||
* Angus Mackay <amackay@gus.ml.org>
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* $Log$
|
||||
* Revision 1.1 1999-12-29 14:21:35 bagder
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 1.3 1999/09/06 06:59:41 dast
|
||||
* Changed email info
|
||||
*
|
||||
* Revision 1.2 1999/08/13 07:34:48 dast
|
||||
* Changed the URL in the header
|
||||
*
|
||||
* Revision 1.1.1.1 1999/03/11 22:23:34 dast
|
||||
* Imported sources
|
||||
*
|
||||
****************************************************************************/
|
||||
int ParseNetrc(char *host,
|
||||
char *login,
|
||||
char *password);
|
||||
#endif
|
||||
221
lib/progress.c
Normal file
221
lib/progress.c
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#if defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include "urldata.h"
|
||||
|
||||
#include "progress.h"
|
||||
|
||||
/* --- start of progress routines --- */
|
||||
int progressmax=-1;
|
||||
|
||||
static int prev = 0;
|
||||
static int width = 0;
|
||||
|
||||
void ProgressInit(struct UrlData *data, int max)
|
||||
{
|
||||
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
|
||||
return;
|
||||
|
||||
prev = 0;
|
||||
|
||||
/* TODO: get terminal width through ansi escapes or something similar.
|
||||
try to update width when xterm is resized... - 19990617 larsa */
|
||||
if (curl_GetEnv("COLUMNS") != NULL)
|
||||
width = atoi(curl_GetEnv("COLUMNS"));
|
||||
else
|
||||
width = 80;
|
||||
|
||||
progressmax = max;
|
||||
if(-1 == max)
|
||||
return;
|
||||
if(progressmax <= LEAST_SIZE_PROGRESS) {
|
||||
progressmax = -1; /* disable */
|
||||
return;
|
||||
}
|
||||
|
||||
if ( data->progressmode == CURL_PROGRESS_STATS )
|
||||
fprintf(data->err,
|
||||
" %% Received Total Speed Time left Total Curr.Speed\n");
|
||||
}
|
||||
|
||||
void time2str(char *r, int t)
|
||||
{
|
||||
int h = (t/3600);
|
||||
int m = (t-(h*3600))/60;
|
||||
int s = (t-(h*3600)-(m*60));
|
||||
sprintf(r,"%3d:%02d:%02d",h,m,s);
|
||||
}
|
||||
|
||||
void ProgressShow(struct UrlData *data,
|
||||
int point, struct timeval start, struct timeval now, bool force)
|
||||
{
|
||||
switch ( data->progressmode ) {
|
||||
case CURL_PROGRESS_STATS:
|
||||
{
|
||||
static long lastshow;
|
||||
double percen;
|
||||
|
||||
double spent;
|
||||
double speed;
|
||||
|
||||
#define CURR_TIME 5
|
||||
|
||||
static int speeder[ CURR_TIME ];
|
||||
static int speeder_c=0;
|
||||
|
||||
int nowindex = speeder_c% CURR_TIME;
|
||||
int checkindex;
|
||||
int count;
|
||||
|
||||
if(!force && (point != progressmax) && (lastshow == tvlong(now)))
|
||||
return; /* never update this more than once a second if the end isn't
|
||||
reached */
|
||||
|
||||
spent = tvdiff (now, start);
|
||||
speed = point/(spent!=0.0?spent:1.0);
|
||||
if(!speed)
|
||||
speed=1;
|
||||
|
||||
/* point is where we are right now */
|
||||
speeder[ nowindex ] = point;
|
||||
speeder_c++; /* increase */
|
||||
count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1;
|
||||
checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0;
|
||||
|
||||
/* find out the average speed the last CURR_TIME seconds */
|
||||
data->current_speed = (speeder[nowindex]-speeder[checkindex])/(count?count:1);
|
||||
|
||||
#if 0
|
||||
printf("NOW %d(%d) THEN %d(%d) DIFF %lf COUNT %d\n",
|
||||
speeder[nowindex], nowindex,
|
||||
speeder[checkindex], checkindex,
|
||||
data->current_speed, count);
|
||||
#endif
|
||||
|
||||
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
|
||||
return;
|
||||
|
||||
if(-1 != progressmax) {
|
||||
char left[20],estim[20];
|
||||
int estimate = progressmax/(int) speed;
|
||||
|
||||
time2str(left,estimate-(int) spent);
|
||||
time2str(estim,estimate);
|
||||
|
||||
percen=(double)point/progressmax;
|
||||
percen=percen*100;
|
||||
|
||||
fprintf(data->err, "\r%3d %8d %8d %6.0lf %s %s %6.0lf ",
|
||||
(int)percen, point, progressmax,
|
||||
speed, left, estim, data->current_speed);
|
||||
}
|
||||
else
|
||||
fprintf(data->err,
|
||||
"\r%d bytes received in %.3lf seconds (%.0lf bytes/sec)",
|
||||
point, spent, speed);
|
||||
|
||||
lastshow = now.tv_sec;
|
||||
break;
|
||||
}
|
||||
case CURL_PROGRESS_BAR: /* 19990617 larsa */
|
||||
{
|
||||
if (point == prev) break;
|
||||
if (progressmax == -1) {
|
||||
int prevblock = prev / 1024;
|
||||
int thisblock = point / 1024;
|
||||
while ( thisblock > prevblock ) {
|
||||
fprintf( data->err, "#" );
|
||||
prevblock++;
|
||||
}
|
||||
prev = point;
|
||||
} else {
|
||||
char line[256];
|
||||
char outline[256];
|
||||
char format[40];
|
||||
float frac = (float) point / (float) progressmax;
|
||||
float percent = frac * 100.0f;
|
||||
int barwidth = width - 7;
|
||||
int num = (int) (((float)barwidth) * frac);
|
||||
int i = 0;
|
||||
for ( i = 0; i < num; i++ ) {
|
||||
line[i] = '#';
|
||||
}
|
||||
line[i] = '\0';
|
||||
sprintf( format, "%%-%ds %%5.1f%%%%", barwidth );
|
||||
sprintf( outline, format, line, percent );
|
||||
fprintf( data->err, "\r%s", outline );
|
||||
}
|
||||
prev = point;
|
||||
break;
|
||||
}
|
||||
default: /* 19990617 larsa */
|
||||
{
|
||||
int prevblock = prev / 1024;
|
||||
int thisblock = point / 1024;
|
||||
if (prev == point) break;
|
||||
while ( thisblock > prevblock ) {
|
||||
fprintf( data->err, "#" );
|
||||
prevblock++;
|
||||
}
|
||||
prev = point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressEnd(struct UrlData *data)
|
||||
{
|
||||
if(data->conf&(CONF_NOPROGRESS|CONF_MUTE))
|
||||
return;
|
||||
fputs("\n", data->err);
|
||||
}
|
||||
|
||||
/* --- end of progress routines --- */
|
||||
54
lib/progress.h
Normal file
54
lib/progress.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef __PROGRESS_H
|
||||
#define __PROGRESS_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include "timeval.h"
|
||||
|
||||
void ProgressInit(struct UrlData *data, int max);
|
||||
void ProgressShow(struct UrlData *data,
|
||||
int point, struct timeval start, struct timeval now, bool force);
|
||||
void ProgressEnd(struct UrlData *data);
|
||||
void ProgressMode(int mode);
|
||||
|
||||
/* Don't show progress for sizes smaller than: */
|
||||
#define LEAST_SIZE_PROGRESS BUFSIZE
|
||||
|
||||
#endif /* __PROGRESS_H */
|
||||
115
lib/sendf.c
Normal file
115
lib/sendf.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include "urldata.h"
|
||||
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
/* infof() is for info message along the way */
|
||||
|
||||
void infof(struct UrlData *data, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
if(data->conf & CONF_VERBOSE) {
|
||||
va_start(ap, fmt);
|
||||
fputs("* ", data->err);
|
||||
vfprintf(data->err, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
/* failf() is for messages stating why we failed, the LAST one will be
|
||||
returned for the user (if requested) */
|
||||
|
||||
void failf(struct UrlData *data, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if(data->errorbuffer)
|
||||
vsprintf(data->errorbuffer, fmt, ap);
|
||||
else /* no errorbuffer receives this, write to data->err instead */
|
||||
vfprintf(data->err, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* sendf() sends the formated data to the server */
|
||||
|
||||
int sendf(int fd, struct UrlData *data, char *fmt, ...)
|
||||
{
|
||||
size_t bytes_written;
|
||||
char *s;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
s = mvaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
if(!s)
|
||||
return 0; /* failure */
|
||||
if(data->conf & CONF_VERBOSE)
|
||||
fprintf(data->err, "> %s", s);
|
||||
#ifndef USE_SSLEAY
|
||||
bytes_written = swrite(fd, s, strlen(s));
|
||||
#else
|
||||
if (data->use_ssl) {
|
||||
bytes_written = SSL_write(data->ssl, s, strlen(s));
|
||||
} else {
|
||||
bytes_written = swrite(fd, s, strlen(s));
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
free(s); /* free the output string */
|
||||
return(bytes_written);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
47
lib/sendf.h
Normal file
47
lib/sendf.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef __SENDF_H
|
||||
#define __SENDF_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
int sendf(int fd, struct UrlData *, char *fmt, ...);
|
||||
void infof(struct UrlData *, char *fmt, ...);
|
||||
void failf(struct UrlData *, char *fmt, ...);
|
||||
|
||||
#endif
|
||||
169
lib/setup.h
Normal file
169
lib/setup.h
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
#ifndef __SETUP_H
|
||||
#define __SETUP_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if !defined(WIN32) && defined(_WIN32)
|
||||
/* This _might_ be a good Borland fix. Please report whether this works or
|
||||
not! */
|
||||
#define WIN32
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h" /* the configure script results */
|
||||
#else
|
||||
#ifdef WIN32
|
||||
/* include the hand-modified win32 adjusted config.h! */
|
||||
#include "../config-win32.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef OS
|
||||
#ifdef WIN32
|
||||
#define OS "win32"
|
||||
#else
|
||||
#define OS "unknown"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_X509_H) && defined(HAVE_SSL_H) && defined(HAVE_RSA_H) && \
|
||||
defined(HAVE_PEM_H) && defined(HAVE_ERR_H) && defined(HAVE_CRYPTO_H) && \
|
||||
defined(HAVE_LIBSSL) && defined(HAVE_LIBCRYPTO)
|
||||
/* the six important includes files all exist and so do both libs,
|
||||
defined SSLeay usage */
|
||||
#define USE_SSLEAY 1
|
||||
#endif
|
||||
#if defined(HAVE_OPENSSL_X509_H) && defined(HAVE_OPENSSL_SSL_H) && \
|
||||
defined(HAVE_OPENSSL_RSA_H) && defined(HAVE_OPENSSL_PEM_H) && \
|
||||
defined(HAVE_OPENSSL_ERR_H) && defined(HAVE_OPENSSL_CRYPTO_H) && \
|
||||
defined(HAVE_LIBSSL) && defined(HAVE_LIBCRYPTO)
|
||||
/* the six important includes files all exist and so do both libs,
|
||||
defined SSLeay usage */
|
||||
#define USE_SSLEAY 1
|
||||
#define USE_OPENSSL 1
|
||||
#endif
|
||||
|
||||
#ifndef STDC_HEADERS /* no standard C headers! */
|
||||
#include "stdcheaders.h"
|
||||
#else
|
||||
#ifdef _AIX
|
||||
#include "stdcheaders.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0 /* zlib experiments are halted 17th october, 1999 (Daniel) */
|
||||
#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
|
||||
/* Both lib and header file exist, we have libz! */
|
||||
#define USE_ZLIB
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRCASECMP
|
||||
#define strnequal(x,y,z) !(strncasecmp)(x,y,z)
|
||||
#define strequal(x,y) !(strcasecmp)(x,y)
|
||||
|
||||
#else
|
||||
#define strnequal(x,y,z) !strnicmp(x,y,z)
|
||||
#define strequal(x,y) !stricmp(x,y)
|
||||
#endif
|
||||
|
||||
/* Below we define four functions. They should
|
||||
1. close a socket
|
||||
2. read from a socket
|
||||
3. write to a socket
|
||||
(Hopefully, only win32-crap do this weird name changing)
|
||||
|
||||
4. set the SIGALRM signal timeout
|
||||
5. set dir/file naming defines
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#if !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#define sclose(x) closesocket(x)
|
||||
#define sread(x,y,z) recv(x,y,z,0)
|
||||
#define swrite(x,y,z) (size_t)send(x,y,z,0)
|
||||
#define myalarm(x) /* win32 is a silly system */
|
||||
#else
|
||||
/* gcc-for-win is still good :) */
|
||||
#define sclose(x) close(x)
|
||||
#define sread(x,y,z) read(x,y,z)
|
||||
#define swrite(x,y,z) write(x,y,z)
|
||||
#define myalarm(x) alarm(x)
|
||||
#endif
|
||||
|
||||
#define PATH_CHAR ";"
|
||||
#define DIR_CHAR "\\"
|
||||
#define DOT_CHAR "_"
|
||||
|
||||
#else
|
||||
#define sclose(x) close(x)
|
||||
#define sread(x,y,z) read(x,y,z)
|
||||
#define swrite(x,y,z) write(x,y,z)
|
||||
#define myalarm(x) alarm(x)
|
||||
|
||||
#define PATH_CHAR ":"
|
||||
#define DIR_CHAR "/"
|
||||
#define DOT_CHAR "."
|
||||
|
||||
#ifdef HAVE_STRCASECMP
|
||||
/* this is for "-ansi -Wall -pedantic" to stop complaining! */
|
||||
extern int (strcasecmp)(const char *s1, const char *s2);
|
||||
extern int (strncasecmp)(const char *s1, const char *s2, size_t n);
|
||||
#ifndef fileno /* sunos 4 have this as a macro! */
|
||||
int fileno( FILE *stream);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FIXME: code for getting a passwd in windows/non termcap/signal systems?
|
||||
*/
|
||||
#ifndef WIN32
|
||||
#define get_password(x) getpass(x)
|
||||
#else
|
||||
#define get_password(x)
|
||||
#endif
|
||||
|
||||
#endif /* __CONFIG_H */
|
||||
81
lib/speedcheck.c
Normal file
81
lib/speedcheck.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include "urldata.h"
|
||||
#include "sendf.h"
|
||||
#include "speedcheck.h"
|
||||
|
||||
UrgError speedcheck(struct UrlData *data,
|
||||
struct timeval now)
|
||||
{
|
||||
static struct timeval keeps_speed;
|
||||
|
||||
if((data->current_speed >= 0) &&
|
||||
data->low_speed_time &&
|
||||
(tvlong(keeps_speed) != 0) &&
|
||||
(data->current_speed < data->low_speed_limit)) {
|
||||
|
||||
/* We are now below the "low speed limit". If we are below it
|
||||
for "low speed time" seconds we consider that enough reason
|
||||
to abort the download. */
|
||||
|
||||
if( tvdiff(now, keeps_speed) > data->low_speed_time) {
|
||||
/* we have been this slow for long enough, now die */
|
||||
failf(data,
|
||||
"Operation too slow. "
|
||||
"Less than %d bytes/sec transfered the last %d seconds",
|
||||
data->low_speed_limit,
|
||||
data->low_speed_time);
|
||||
return URG_OPERATION_TIMEOUTED;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* we keep up the required speed all right */
|
||||
keeps_speed = now;
|
||||
}
|
||||
return URG_OK;
|
||||
}
|
||||
|
||||
50
lib/speedcheck.h
Normal file
50
lib/speedcheck.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef __SPEEDCHECK_H
|
||||
#define __SPEEDCHECK_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include "timeval.h"
|
||||
|
||||
UrgError speedcheck(struct UrlData *data,
|
||||
struct timeval now);
|
||||
|
||||
#endif
|
||||
265
lib/ssluse.c
Normal file
265
lib/ssluse.c
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "urldata.h"
|
||||
#include "sendf.h"
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
|
||||
static char global_passwd[64];
|
||||
|
||||
static int passwd_callback(char *buf, int num, int verify
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00904100L
|
||||
/* This was introduced in 0.9.4, we can set this
|
||||
using SSL_CTX_set_default_passwd_cb_userdata()
|
||||
*/
|
||||
, void *userdata
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if(verify)
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
else {
|
||||
if(num > strlen(global_passwd)) {
|
||||
strcpy(buf, global_passwd);
|
||||
return strlen(buf);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function is *highly* inspired by (and parts are directly stolen
|
||||
* from) source from the SSLeay package written by Eric Young
|
||||
* (eay@cryptsoft.com). */
|
||||
|
||||
int SSL_cert_stuff(struct UrlData *data,
|
||||
char *cert_file,
|
||||
char *key_file)
|
||||
{
|
||||
if (cert_file != NULL) {
|
||||
SSL *ssl;
|
||||
X509 *x509;
|
||||
|
||||
if(data->cert_passwd) {
|
||||
/*
|
||||
* If password has been given, we store that in the global
|
||||
* area (*shudder*) for a while:
|
||||
*/
|
||||
strcpy(global_passwd, data->cert_passwd);
|
||||
/* Set passwd callback: */
|
||||
SSL_CTX_set_default_passwd_cb(data->ctx, passwd_callback);
|
||||
}
|
||||
|
||||
if (SSL_CTX_use_certificate_file(data->ctx,
|
||||
cert_file,
|
||||
SSL_FILETYPE_PEM) <= 0) {
|
||||
failf(data, "unable to set certificate file (wrong password?)\n");
|
||||
return(0);
|
||||
}
|
||||
if (key_file == NULL)
|
||||
key_file=cert_file;
|
||||
|
||||
if (SSL_CTX_use_PrivateKey_file(data->ctx,
|
||||
key_file,
|
||||
SSL_FILETYPE_PEM) <= 0) {
|
||||
failf(data, "unable to set public key file\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
ssl=SSL_new(data->ctx);
|
||||
x509=SSL_get_certificate(ssl);
|
||||
|
||||
if (x509 != NULL)
|
||||
EVP_PKEY_copy_parameters(X509_get_pubkey(x509),
|
||||
SSL_get_privatekey(ssl));
|
||||
SSL_free(ssl);
|
||||
|
||||
/* If we are using DSA, we can copy the parameters from
|
||||
* the private key */
|
||||
|
||||
|
||||
/* Now we know that a key and cert have been set against
|
||||
* the SSL context */
|
||||
if (!SSL_CTX_check_private_key(data->ctx)) {
|
||||
failf(data, "Private key does not match the certificate public key\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* erase it now */
|
||||
memset(global_passwd, 0, sizeof(global_passwd));
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if SSL_VERIFY_CERT
|
||||
int cert_verify_callback(int ok, X509_STORE_CTX *ctx)
|
||||
{
|
||||
X509 *err_cert;
|
||||
char buf[256];
|
||||
|
||||
err_cert=X509_STORE_CTX_get_current_cert(ctx);
|
||||
X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ====================================================== */
|
||||
int
|
||||
UrgSSLConnect (struct UrlData *data)
|
||||
{
|
||||
#ifdef USE_SSLEAY
|
||||
int err;
|
||||
char * str;
|
||||
SSL_METHOD *req_method;
|
||||
|
||||
/* mark this is being ssl enabled from here on out. */
|
||||
data->use_ssl = 1;
|
||||
|
||||
/* Lets get nice error messages */
|
||||
SSL_load_error_strings();
|
||||
|
||||
/* Setup all the global SSL stuff */
|
||||
SSLeay_add_ssl_algorithms();
|
||||
|
||||
switch(data->ssl_version) {
|
||||
default:
|
||||
req_method = SSLv23_client_method();
|
||||
break;
|
||||
case 2:
|
||||
req_method = SSLv2_client_method();
|
||||
break;
|
||||
case 3:
|
||||
req_method = SSLv3_client_method();
|
||||
break;
|
||||
}
|
||||
|
||||
data->ctx = SSL_CTX_new(req_method);
|
||||
|
||||
if(!data->ctx) {
|
||||
failf(data, "SSL: couldn't create a context!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(data->cert) {
|
||||
if (!SSL_cert_stuff(data, data->cert, data->cert)) {
|
||||
failf(data, "couldn't use certificate!\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
#if SSL_VERIFY_CERT
|
||||
SSL_CTX_set_verify(data->ctx,
|
||||
SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT|
|
||||
SSL_VERIFY_CLIENT_ONCE,
|
||||
cert_verify_callback);
|
||||
#endif
|
||||
|
||||
/* Lets make an SSL structure */
|
||||
data->ssl = SSL_new (data->ctx);
|
||||
SSL_set_connect_state (data->ssl);
|
||||
|
||||
data->server_cert = 0x0;
|
||||
|
||||
/* pass the raw socket into the SSL layers */
|
||||
SSL_set_fd (data->ssl, data->firstsocket);
|
||||
err = SSL_connect (data->ssl);
|
||||
|
||||
if (-1 == err) {
|
||||
err = ERR_get_error();
|
||||
failf(data, "SSL: %s", ERR_error_string(err, NULL));
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
infof (data, "SSL connection using %s\n", SSL_get_cipher (data->ssl));
|
||||
|
||||
/* Get server's certificate (note: beware of dynamic allocation) - opt */
|
||||
/* major serious hack alert -- we should check certificates
|
||||
* to authenticate the server; otherwise we risk man-in-the-middle
|
||||
* attack
|
||||
*/
|
||||
|
||||
data->server_cert = SSL_get_peer_certificate (data->ssl);
|
||||
if(!data->server_cert) {
|
||||
failf(data, "SSL: couldn't get peer certificate!");
|
||||
return 3;
|
||||
}
|
||||
infof (data, "Server certificate:\n");
|
||||
|
||||
str = X509_NAME_oneline (X509_get_subject_name (data->server_cert), NULL, 0);
|
||||
if(!str) {
|
||||
failf(data, "SSL: couldn't get X509-subject!");
|
||||
return 4;
|
||||
}
|
||||
infof (data, "\t subject: %s\n", str);
|
||||
Free (str);
|
||||
|
||||
str = X509_NAME_oneline (X509_get_issuer_name (data->server_cert), NULL, 0);
|
||||
if(!str) {
|
||||
failf(data, "SSL: couldn't get X509-issuer name!");
|
||||
return 5;
|
||||
}
|
||||
infof (data, "\t issuer: %s\n", str);
|
||||
Free (str);
|
||||
|
||||
/* We could do all sorts of certificate verification stuff here before
|
||||
deallocating the certificate. */
|
||||
|
||||
|
||||
#if SSL_VERIFY_CERT
|
||||
infof(data, "Verify result: %d\n", SSL_get_verify_result(data->ssl));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
X509_free (data->server_cert);
|
||||
#else /* USE_SSLEAY */
|
||||
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
|
||||
(void) data;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
46
lib/ssluse.h
Normal file
46
lib/ssluse.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef __SSLUSE_H
|
||||
#define __SSLUSE_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
int SSL_cert_stuff(struct UrlData *data,
|
||||
char *cert_file,
|
||||
char *key_file);
|
||||
int UrgSSLConnect (struct UrlData *data);
|
||||
#endif
|
||||
BIN
lib/sta01005
Normal file
BIN
lib/sta01005
Normal file
Binary file not shown.
BIN
lib/sta18057
Normal file
BIN
lib/sta18057
Normal file
Binary file not shown.
937
lib/telnet.c
Normal file
937
lib/telnet.c
Normal file
|
|
@ -0,0 +1,937 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* This implementation of the TELNET protocol is written by
|
||||
* Linus Nielsen <Linus.Nielsen@haxx.nu>,
|
||||
* with some code snippets stolen from the BSD Telnet client.
|
||||
*
|
||||
* The negotiation is performed according to RFC 1143 (D. Bernstein,
|
||||
* "The Q Method of Implementing TELNET Option Negotiation")
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* -- WIN32 approved -- */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NET_IF_H
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include <curl/curl.h>
|
||||
#include "download.h"
|
||||
#include "sendf.h"
|
||||
#include "formdata.h"
|
||||
#include "progress.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#define TELOPTS
|
||||
#define TELCMDS
|
||||
#define SLC_NAMES
|
||||
|
||||
#include "arpa_telnet.h"
|
||||
|
||||
#define SUBBUFSIZE 512
|
||||
|
||||
#define SB_CLEAR() subpointer = subbuffer;
|
||||
#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
|
||||
#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
|
||||
*subpointer++ = (c); \
|
||||
}
|
||||
|
||||
#define SB_GET() ((*subpointer++)&0xff)
|
||||
#define SB_PEEK() ((*subpointer)&0xff)
|
||||
#define SB_EOF() (subpointer >= subend)
|
||||
#define SB_LEN() (subend - subpointer)
|
||||
|
||||
void telwrite(struct UrlData *data,
|
||||
unsigned char *buffer, /* Data to write */
|
||||
int count); /* Number of bytes to write */
|
||||
|
||||
void telrcv(struct UrlData *data,
|
||||
unsigned char *inbuf, /* Data received from socket */
|
||||
int count); /* Number of bytes received */
|
||||
|
||||
static void printoption(struct UrlData *data,
|
||||
const char *direction,
|
||||
int cmd, int option);
|
||||
|
||||
static void negotiate(struct UrlData *data);
|
||||
static void send_negotiation(struct UrlData *data, int cmd, int option);
|
||||
static void set_local_option(struct UrlData *data, int cmd, int option);
|
||||
static void set_remote_option(struct UrlData *data, int cmd, int option);
|
||||
|
||||
static void printsub(struct UrlData *data,
|
||||
int direction, unsigned char *pointer, int length);
|
||||
static void suboption(struct UrlData *data);
|
||||
|
||||
/* suboptions */
|
||||
static char subbuffer[SUBBUFSIZE];
|
||||
static char *subpointer, *subend; /* buffer for sub-options */
|
||||
|
||||
/*
|
||||
* Telnet receiver states for fsm
|
||||
*/
|
||||
static enum
|
||||
{
|
||||
TS_DATA = 0,
|
||||
TS_IAC,
|
||||
TS_WILL,
|
||||
TS_WONT,
|
||||
TS_DO,
|
||||
TS_DONT,
|
||||
TS_CR,
|
||||
TS_SB, /* sub-option collection */
|
||||
TS_SE /* looking for sub-option end */
|
||||
} telrcv_state;
|
||||
|
||||
/* For negotiation compliant to RFC 1143 */
|
||||
#define NO 0
|
||||
#define YES 1
|
||||
#define WANTYES 2
|
||||
#define WANTNO 3
|
||||
|
||||
#define EMPTY 0
|
||||
#define OPPOSITE 1
|
||||
|
||||
static int us[256];
|
||||
static int usq[256];
|
||||
static int us_preferred[256];
|
||||
static int him[256];
|
||||
static int himq[256];
|
||||
static int him_preferred[256];
|
||||
|
||||
void init_telnet(struct UrlData *data)
|
||||
{
|
||||
telrcv_state = TS_DATA;
|
||||
|
||||
/* Init suboptions */
|
||||
SB_CLEAR();
|
||||
|
||||
/* Set all options to NO */
|
||||
memset(us, NO, 256);
|
||||
memset(usq, NO, 256);
|
||||
memset(us_preferred, NO, 256);
|
||||
memset(him, NO, 256);
|
||||
memset(himq, NO, 256);
|
||||
memset(him_preferred, NO, 256);
|
||||
|
||||
/* Set the options we want */
|
||||
us_preferred[TELOPT_BINARY] = YES;
|
||||
us_preferred[TELOPT_SGA] = YES;
|
||||
him_preferred[TELOPT_BINARY] = YES;
|
||||
him_preferred[TELOPT_SGA] = YES;
|
||||
|
||||
/* Start negotiating */
|
||||
negotiate(data);
|
||||
}
|
||||
|
||||
static void negotiate(struct UrlData *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0;i < NTELOPTS;i++)
|
||||
{
|
||||
if(us_preferred[i] == YES)
|
||||
set_local_option(data, i, YES);
|
||||
|
||||
if(him_preferred[i] == YES)
|
||||
set_remote_option(data, i, YES);
|
||||
}
|
||||
}
|
||||
|
||||
static void printoption(struct UrlData *data,
|
||||
const char *direction, int cmd, int option)
|
||||
{
|
||||
char *fmt;
|
||||
char *opt;
|
||||
|
||||
if (data->conf & CONF_VERBOSE)
|
||||
{
|
||||
if (cmd == IAC)
|
||||
{
|
||||
if (TELCMD_OK(option))
|
||||
printf("%s IAC %s\n", direction, TELCMD(option));
|
||||
else
|
||||
printf("%s IAC %d\n", direction, option);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
|
||||
(cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
|
||||
if (fmt)
|
||||
{
|
||||
if (TELOPT_OK(option))
|
||||
opt = TELOPT(option);
|
||||
else if (option == TELOPT_EXOPL)
|
||||
opt = "EXOPL";
|
||||
else
|
||||
opt = NULL;
|
||||
|
||||
if(opt)
|
||||
printf("%s %s %s\n", direction, fmt, opt);
|
||||
else
|
||||
printf("%s %s %d\n", direction, fmt, option);
|
||||
}
|
||||
else
|
||||
printf("%s %d %d\n", direction, cmd, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void send_negotiation(struct UrlData *data, int cmd, int option)
|
||||
{
|
||||
unsigned char buf[3];
|
||||
|
||||
buf[0] = IAC;
|
||||
buf[1] = cmd;
|
||||
buf[2] = option;
|
||||
|
||||
swrite(data->firstsocket, buf, 3);
|
||||
|
||||
printoption(data, "SENT", cmd, option);
|
||||
}
|
||||
|
||||
void set_remote_option(struct UrlData *data, int option, int newstate)
|
||||
{
|
||||
if(newstate == YES)
|
||||
{
|
||||
switch(him[option])
|
||||
{
|
||||
case NO:
|
||||
him[option] = WANTYES;
|
||||
send_negotiation(data, DO, option);
|
||||
break;
|
||||
|
||||
case YES:
|
||||
/* Already enabled */
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Already negotiating for YES, queue the request */
|
||||
himq[option] = OPPOSITE;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
/* Error: already queued an enable request */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Error: already negotiating for enable */
|
||||
break;
|
||||
case OPPOSITE:
|
||||
himq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else /* NO */
|
||||
{
|
||||
switch(him[option])
|
||||
{
|
||||
case NO:
|
||||
/* Already disabled */
|
||||
break;
|
||||
|
||||
case YES:
|
||||
him[option] = WANTNO;
|
||||
send_negotiation(data, DONT, option);
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Already negotiating for NO */
|
||||
break;
|
||||
case OPPOSITE:
|
||||
himq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
himq[option] = OPPOSITE;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rec_will(struct UrlData *data, int option)
|
||||
{
|
||||
switch(him[option])
|
||||
{
|
||||
case NO:
|
||||
if(him_preferred[option] == YES)
|
||||
{
|
||||
him[option] = YES;
|
||||
send_negotiation(data, DO, option);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_negotiation(data, DONT, option);
|
||||
}
|
||||
break;
|
||||
|
||||
case YES:
|
||||
/* Already enabled */
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Error: DONT answered by WILL */
|
||||
him[option] = NO;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
/* Error: DONT answered by WILL */
|
||||
him[option] = YES;
|
||||
himq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
him[option] = YES;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
him[option] = WANTNO;
|
||||
himq[option] = EMPTY;
|
||||
send_negotiation(data, DONT, option);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rec_wont(struct UrlData *data, int option)
|
||||
{
|
||||
switch(him[option])
|
||||
{
|
||||
case NO:
|
||||
/* Already disabled */
|
||||
break;
|
||||
|
||||
case YES:
|
||||
him[option] = NO;
|
||||
send_negotiation(data, DONT, option);
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
him[option] = NO;
|
||||
break;
|
||||
|
||||
case OPPOSITE:
|
||||
him[option] = WANTYES;
|
||||
himq[option] = EMPTY;
|
||||
send_negotiation(data, DO, option);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(himq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
him[option] = NO;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
him[option] = NO;
|
||||
himq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void set_local_option(struct UrlData *data, int option, int newstate)
|
||||
{
|
||||
if(newstate == YES)
|
||||
{
|
||||
switch(us[option])
|
||||
{
|
||||
case NO:
|
||||
us[option] = WANTYES;
|
||||
send_negotiation(data, WILL, option);
|
||||
break;
|
||||
|
||||
case YES:
|
||||
/* Already enabled */
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Already negotiating for YES, queue the request */
|
||||
usq[option] = OPPOSITE;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
/* Error: already queued an enable request */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Error: already negotiating for enable */
|
||||
break;
|
||||
case OPPOSITE:
|
||||
usq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else /* NO */
|
||||
{
|
||||
switch(us[option])
|
||||
{
|
||||
case NO:
|
||||
/* Already disabled */
|
||||
break;
|
||||
|
||||
case YES:
|
||||
us[option] = WANTNO;
|
||||
send_negotiation(data, WONT, option);
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Already negotiating for NO */
|
||||
break;
|
||||
case OPPOSITE:
|
||||
usq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
usq[option] = OPPOSITE;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rec_do(struct UrlData *data, int option)
|
||||
{
|
||||
switch(us[option])
|
||||
{
|
||||
case NO:
|
||||
if(us_preferred[option] == YES)
|
||||
{
|
||||
us[option] = YES;
|
||||
send_negotiation(data, WILL, option);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_negotiation(data, WONT, option);
|
||||
}
|
||||
break;
|
||||
|
||||
case YES:
|
||||
/* Already enabled */
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
/* Error: DONT answered by WILL */
|
||||
us[option] = NO;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
/* Error: DONT answered by WILL */
|
||||
us[option] = YES;
|
||||
usq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
us[option] = YES;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
us[option] = WANTNO;
|
||||
himq[option] = EMPTY;
|
||||
send_negotiation(data, WONT, option);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rec_dont(struct UrlData *data, int option)
|
||||
{
|
||||
switch(us[option])
|
||||
{
|
||||
case NO:
|
||||
/* Already disabled */
|
||||
break;
|
||||
|
||||
case YES:
|
||||
us[option] = NO;
|
||||
send_negotiation(data, WONT, option);
|
||||
break;
|
||||
|
||||
case WANTNO:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
us[option] = NO;
|
||||
break;
|
||||
|
||||
case OPPOSITE:
|
||||
us[option] = WANTYES;
|
||||
usq[option] = EMPTY;
|
||||
send_negotiation(data, WILL, option);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WANTYES:
|
||||
switch(usq[option])
|
||||
{
|
||||
case EMPTY:
|
||||
us[option] = NO;
|
||||
break;
|
||||
case OPPOSITE:
|
||||
us[option] = NO;
|
||||
usq[option] = EMPTY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void printsub(struct UrlData *data,
|
||||
int direction, /* '<' or '>' */
|
||||
unsigned char *pointer, /* where suboption data is */
|
||||
int length) /* length of suboption data */
|
||||
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (data->conf & CONF_VERBOSE)
|
||||
{
|
||||
if (direction)
|
||||
{
|
||||
printf("%s IAC SB ", (direction == '<')? "RCVD":"SENT");
|
||||
if (length >= 3)
|
||||
{
|
||||
int j;
|
||||
|
||||
i = pointer[length-2];
|
||||
j = pointer[length-1];
|
||||
|
||||
if (i != IAC || j != SE)
|
||||
{
|
||||
printf("(terminated by ");
|
||||
if (TELOPT_OK(i))
|
||||
printf("%s ", TELOPT(i));
|
||||
else if (TELCMD_OK(i))
|
||||
printf("%s ", TELCMD(i));
|
||||
else
|
||||
printf("%d ", i);
|
||||
if (TELOPT_OK(j))
|
||||
printf("%s", TELOPT(j));
|
||||
else if (TELCMD_OK(j))
|
||||
printf("%s", TELCMD(j));
|
||||
else
|
||||
printf("%d", j);
|
||||
printf(", not IAC SE!) ");
|
||||
}
|
||||
}
|
||||
length -= 2;
|
||||
}
|
||||
if (length < 1)
|
||||
{
|
||||
printf("(Empty suboption?)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (TELOPT_OK(pointer[0]))
|
||||
printf("%s (unknown)", TELOPT(pointer[0]));
|
||||
else
|
||||
printf("%d (unknown)", pointer[i]);
|
||||
for (i = 1; i < length; i++)
|
||||
printf(" %d", pointer[i]);
|
||||
|
||||
if (direction)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* suboption()
|
||||
*
|
||||
* Look at the sub-option buffer, and try to be helpful to the other
|
||||
* side.
|
||||
* No suboptions are supported yet.
|
||||
*/
|
||||
|
||||
static void suboption(struct UrlData *data)
|
||||
{
|
||||
printsub(data, '<', (unsigned char *)subbuffer, SB_LEN()+2);
|
||||
return;
|
||||
}
|
||||
|
||||
void telrcv(struct UrlData *data,
|
||||
unsigned char *inbuf, /* Data received from socket */
|
||||
int count) /* Number of bytes received */
|
||||
{
|
||||
unsigned char c;
|
||||
int index = 0;
|
||||
|
||||
while(count--)
|
||||
{
|
||||
c = inbuf[index++];
|
||||
|
||||
switch (telrcv_state)
|
||||
{
|
||||
case TS_CR:
|
||||
telrcv_state = TS_DATA;
|
||||
if (c == '\0')
|
||||
{
|
||||
break; /* Ignore \0 after CR */
|
||||
}
|
||||
|
||||
data->fwrite((char *)&c, 1, 1, data->out);
|
||||
continue;
|
||||
|
||||
case TS_DATA:
|
||||
if (c == IAC)
|
||||
{
|
||||
telrcv_state = TS_IAC;
|
||||
break;
|
||||
}
|
||||
else if(c == '\r')
|
||||
{
|
||||
telrcv_state = TS_CR;
|
||||
}
|
||||
|
||||
data->fwrite((char *)&c, 1, 1, data->out);
|
||||
continue;
|
||||
|
||||
case TS_IAC:
|
||||
process_iac:
|
||||
switch (c)
|
||||
{
|
||||
case WILL:
|
||||
telrcv_state = TS_WILL;
|
||||
continue;
|
||||
case WONT:
|
||||
telrcv_state = TS_WONT;
|
||||
continue;
|
||||
case DO:
|
||||
telrcv_state = TS_DO;
|
||||
continue;
|
||||
case DONT:
|
||||
telrcv_state = TS_DONT;
|
||||
continue;
|
||||
case SB:
|
||||
SB_CLEAR();
|
||||
telrcv_state = TS_SB;
|
||||
continue;
|
||||
case IAC:
|
||||
data->fwrite((char *)&c, 1, 1, data->out);
|
||||
break;
|
||||
case DM:
|
||||
case NOP:
|
||||
case GA:
|
||||
default:
|
||||
printoption(data, "RCVD", IAC, c);
|
||||
break;
|
||||
}
|
||||
telrcv_state = TS_DATA;
|
||||
continue;
|
||||
|
||||
case TS_WILL:
|
||||
printoption(data, "RCVD", WILL, c);
|
||||
rec_will(data, c);
|
||||
telrcv_state = TS_DATA;
|
||||
continue;
|
||||
|
||||
case TS_WONT:
|
||||
printoption(data, "RCVD", WONT, c);
|
||||
rec_wont(data, c);
|
||||
telrcv_state = TS_DATA;
|
||||
continue;
|
||||
|
||||
case TS_DO:
|
||||
printoption(data, "RCVD", DO, c);
|
||||
rec_do(data, c);
|
||||
telrcv_state = TS_DATA;
|
||||
continue;
|
||||
|
||||
case TS_DONT:
|
||||
printoption(data, "RCVD", DONT, c);
|
||||
rec_dont(data, c);
|
||||
telrcv_state = TS_DATA;
|
||||
continue;
|
||||
|
||||
case TS_SB:
|
||||
if (c == IAC)
|
||||
{
|
||||
telrcv_state = TS_SE;
|
||||
}
|
||||
else
|
||||
{
|
||||
SB_ACCUM(c);
|
||||
}
|
||||
continue;
|
||||
|
||||
case TS_SE:
|
||||
if (c != SE)
|
||||
{
|
||||
if (c != IAC)
|
||||
{
|
||||
/*
|
||||
* This is an error. We only expect to get
|
||||
* "IAC IAC" or "IAC SE". Several things may
|
||||
* have happend. An IAC was not doubled, the
|
||||
* IAC SE was left off, or another option got
|
||||
* inserted into the suboption are all possibilities.
|
||||
* If we assume that the IAC was not doubled,
|
||||
* and really the IAC SE was left off, we could
|
||||
* get into an infinate loop here. So, instead,
|
||||
* we terminate the suboption, and process the
|
||||
* partial suboption if we can.
|
||||
*/
|
||||
SB_ACCUM((unsigned char)IAC);
|
||||
SB_ACCUM(c);
|
||||
subpointer -= 2;
|
||||
SB_TERM();
|
||||
|
||||
printoption(data, "In SUBOPTION processing, RCVD", IAC, c);
|
||||
suboption(data); /* handle sub-option */
|
||||
telrcv_state = TS_IAC;
|
||||
goto process_iac;
|
||||
}
|
||||
SB_ACCUM(c);
|
||||
telrcv_state = TS_SB;
|
||||
}
|
||||
else
|
||||
{
|
||||
SB_ACCUM((unsigned char)IAC);
|
||||
SB_ACCUM((unsigned char)SE);
|
||||
subpointer -= 2;
|
||||
SB_TERM();
|
||||
suboption(data); /* handle sub-option */
|
||||
telrcv_state = TS_DATA;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void telwrite(struct UrlData *data,
|
||||
unsigned char *buffer, /* Data to write */
|
||||
int count) /* Number of bytes to write */
|
||||
{
|
||||
unsigned char outbuf[2];
|
||||
int out_count = 0;
|
||||
int bytes_written;
|
||||
|
||||
while(count--)
|
||||
{
|
||||
outbuf[0] = *buffer++;
|
||||
out_count = 1;
|
||||
if(outbuf[0] == IAC)
|
||||
outbuf[out_count++] = IAC;
|
||||
|
||||
#ifndef USE_SSLEAY
|
||||
bytes_written = swrite(data->firstsocket, outbuf, out_count);
|
||||
#else
|
||||
if (data->use_ssl) {
|
||||
bytes_written = SSL_write(data->ssl, (char *)outbuf, out_count);
|
||||
}
|
||||
else {
|
||||
bytes_written = swrite(data->firstsocket, outbuf, out_count);
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
}
|
||||
}
|
||||
|
||||
UrgError telnet(struct UrlData *data)
|
||||
{
|
||||
int sockfd = data->firstsocket;
|
||||
fd_set readfd;
|
||||
fd_set keepfd;
|
||||
|
||||
bool keepon = TRUE;
|
||||
char *buf = data->buffer;
|
||||
int nread;
|
||||
|
||||
init_telnet(data);
|
||||
|
||||
FD_ZERO (&readfd); /* clear it */
|
||||
FD_SET (sockfd, &readfd);
|
||||
FD_SET (1, &readfd);
|
||||
|
||||
keepfd = readfd;
|
||||
|
||||
while (keepon)
|
||||
{
|
||||
readfd = keepfd; /* set this every lap in the loop */
|
||||
|
||||
switch (select (sockfd + 1, &readfd, NULL, NULL, NULL))
|
||||
{
|
||||
case -1: /* error, stop reading */
|
||||
keepon = FALSE;
|
||||
continue;
|
||||
case 0: /* timeout */
|
||||
break;
|
||||
default: /* read! */
|
||||
if(FD_ISSET(1, &readfd))
|
||||
{
|
||||
nread = read(1, buf, 255);
|
||||
telwrite(data, (unsigned char *)buf, nread);
|
||||
}
|
||||
|
||||
if(FD_ISSET(sockfd, &readfd))
|
||||
{
|
||||
#ifndef USE_SSLEAY
|
||||
nread = sread (sockfd, buf, BUFSIZE - 1);
|
||||
#else
|
||||
if (data->use_ssl) {
|
||||
nread = SSL_read (data->ssl, buf, BUFSIZE - 1);
|
||||
}
|
||||
else {
|
||||
nread = sread (sockfd, buf, BUFSIZE - 1);
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
}
|
||||
|
||||
/* if we receive 0 or less here, the server closed the connection and
|
||||
we bail out from this! */
|
||||
if (nread <= 0) {
|
||||
keepon = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
telrcv(data, (unsigned char *)buf, nread);
|
||||
}
|
||||
}
|
||||
return URG_OK;
|
||||
}
|
||||
|
||||
|
||||
45
lib/telnet.h
Normal file
45
lib/telnet.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __TELNET_H
|
||||
#define __TELNET_H
|
||||
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError telnet(struct UrlData *data);
|
||||
|
||||
#endif
|
||||
93
lib/timeval.c
Normal file
93
lib/timeval.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "timeval.h"
|
||||
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
|
||||
#ifdef WIN32
|
||||
int
|
||||
gettimeofday (struct timeval *tp, void *nothing)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
time_t tt;
|
||||
struct tm tmtm;
|
||||
/* mktime converts local to UTC */
|
||||
GetLocalTime (&st);
|
||||
tmtm.tm_sec = st.wSecond;
|
||||
tmtm.tm_min = st.wMinute;
|
||||
tmtm.tm_hour = st.wHour;
|
||||
tmtm.tm_mday = st.wDay;
|
||||
tmtm.tm_mon = st.wMonth - 1;
|
||||
tmtm.tm_year = st.wYear - 1900;
|
||||
tmtm.tm_isdst = -1;
|
||||
tt = mktime (&tmtm);
|
||||
tp->tv_sec = tt;
|
||||
tp->tv_usec = st.wMilliseconds * 1000;
|
||||
return 1;
|
||||
}
|
||||
#define HAVE_GETTIMEOFDAY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct timeval tvnow ()
|
||||
{
|
||||
struct timeval now;
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
gettimeofday (&now, NULL);
|
||||
#else
|
||||
now.tv_sec = (long) time(NULL);
|
||||
now.tv_usec = 0;
|
||||
#endif
|
||||
return now;
|
||||
}
|
||||
|
||||
double tvdiff (struct timeval t1, struct timeval t2)
|
||||
{
|
||||
return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0);
|
||||
}
|
||||
|
||||
long tvlong (struct timeval t1)
|
||||
{
|
||||
return t1.tv_sec;
|
||||
}
|
||||
64
lib/timeval.h
Normal file
64
lib/timeval.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef __TIMEVAL_H
|
||||
#define __TIMEVAL_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <time.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
#if !defined(_WINSOCKAPI_) && !defined(__MINGW32__)
|
||||
struct timeval {
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct timeval tvnow ();
|
||||
double tvdiff (struct timeval t1, struct timeval t2);
|
||||
long tvlong (struct timeval t1);
|
||||
|
||||
#endif
|
||||
178
lib/upload.c
Normal file
178
lib/upload.c
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include "setup.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#if !defined(__GNUC__) || defined(__MINGW32__)
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <time.h> /* for the time_t typedef! */
|
||||
|
||||
#if defined(__GNUC__) && defined(TIME_WITH_SYS_TIME)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifdef __BEOS__
|
||||
#include <net/socket.h>
|
||||
#endif
|
||||
|
||||
#include "urldata.h"
|
||||
#include "speedcheck.h"
|
||||
#include "sendf.h"
|
||||
#include "progress.h"
|
||||
|
||||
/* --- upload a stream to a socket --- */
|
||||
|
||||
UrgError Upload(struct UrlData *data,
|
||||
int sockfd,
|
||||
long *bytecountp)
|
||||
{
|
||||
fd_set writefd;
|
||||
fd_set keepfd;
|
||||
struct timeval interval;
|
||||
bool keepon=TRUE;
|
||||
char *buf = data->buffer;
|
||||
size_t nread;
|
||||
long bytecount=0;
|
||||
struct timeval start;
|
||||
struct timeval now;
|
||||
UrgError urg;
|
||||
char scratch[BUFSIZE * 2];
|
||||
int i, si;
|
||||
|
||||
/* timeout every X second
|
||||
- makes a better progressmeter (i.e even when no data is sent, the
|
||||
meter can be updated and reflect reality)
|
||||
- allows removal of the alarm() crap
|
||||
- variable timeout is easier
|
||||
*/
|
||||
|
||||
myalarm(0); /* switch off the alarm-style timeout */
|
||||
|
||||
start = tvnow();
|
||||
now = start;
|
||||
|
||||
FD_ZERO(&writefd); /* clear it */
|
||||
FD_SET(sockfd, &writefd);
|
||||
|
||||
keepfd = writefd;
|
||||
|
||||
while(keepon) {
|
||||
size_t bytes_written = 0;
|
||||
|
||||
writefd = keepfd; /* set this every lap in the loop */
|
||||
interval.tv_sec = 2;
|
||||
interval.tv_usec = 0;
|
||||
|
||||
switch(select(sockfd+1, NULL, &writefd, NULL, &interval)) {
|
||||
case -1: /* error, stop writing */
|
||||
keepon=FALSE;
|
||||
continue;
|
||||
case 0: /* timeout */
|
||||
break;
|
||||
default: /* write! */
|
||||
if(data->crlf)
|
||||
buf = data->buffer; /* put it back on the buffer */
|
||||
|
||||
nread = data->fread(buf, 1, BUFSIZE, data->in);
|
||||
bytecount += nread;
|
||||
|
||||
if (nread==0) {
|
||||
/* done */
|
||||
keepon = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* convert LF to CRLF if so asked */
|
||||
if (data->crlf) {
|
||||
for(i = 0, si = 0; i < (int)nread; i++, si++) {
|
||||
if (buf[i] == 0x0a) {
|
||||
scratch[si++] = 0x0d;
|
||||
scratch[si] = 0x0a;
|
||||
}
|
||||
else {
|
||||
scratch[si] = buf[i];
|
||||
}
|
||||
}
|
||||
nread = si;
|
||||
buf = scratch; /* point to the new buffer */
|
||||
}
|
||||
|
||||
/* write to socket */
|
||||
#ifndef USE_SSLEAY
|
||||
bytes_written = swrite(sockfd, buf, nread);
|
||||
#else
|
||||
if (data->use_ssl) {
|
||||
bytes_written = SSL_write(data->ssl, buf, nread);
|
||||
} else {
|
||||
bytes_written = swrite(sockfd, buf, nread);
|
||||
}
|
||||
#endif /* USE_SSLEAY */
|
||||
if(nread != bytes_written) {
|
||||
failf(data, "Failed uploading file");
|
||||
return URG_FTP_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
now = tvnow();
|
||||
ProgressShow(data, bytecount, start, now, FALSE);
|
||||
urg=speedcheck(data, now);
|
||||
if(urg)
|
||||
return urg;
|
||||
if(data->timeout && (tvdiff(now,start)>data->timeout)) {
|
||||
failf(data, "Upload timed out with %d bytes sent", bytecount);
|
||||
return URG_OPERATION_TIMEOUTED;
|
||||
}
|
||||
|
||||
}
|
||||
ProgressShow(data, bytecount, start, now, TRUE);
|
||||
*bytecountp = bytecount;
|
||||
|
||||
return URG_OK;
|
||||
}
|
||||
46
lib/upload.h
Normal file
46
lib/upload.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef __UPLOAD_H
|
||||
#define __UPLOAD_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
UrgError Upload(struct UrlData *data,
|
||||
int sockfd,
|
||||
long *bytecountp);
|
||||
|
||||
#endif
|
||||
0
lib/url.h
Normal file
0
lib/url.h
Normal file
212
lib/urldata.h
Normal file
212
lib/urldata.h
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
#ifndef __URLDATA_H
|
||||
#define __URLDATA_H
|
||||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
/* This file is for lib internal stuff */
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 256
|
||||
#endif
|
||||
|
||||
#define PORT_FTP 21
|
||||
#define PORT_TELNET 23
|
||||
#define PORT_GOPHER 70
|
||||
#define PORT_HTTP 80
|
||||
#define PORT_HTTPS 443
|
||||
#define PORT_DICT 2628
|
||||
#define PORT_LDAP 389
|
||||
|
||||
#define DICT_MATCH "/MATCH:"
|
||||
#define DICT_MATCH2 "/M:"
|
||||
#define DICT_MATCH3 "/FIND:"
|
||||
#define DICT_DEFINE "/DEFINE:"
|
||||
#define DICT_DEFINE2 "/D:"
|
||||
#define DICT_DEFINE3 "/LOOKUP:"
|
||||
|
||||
#define CURL_DEFAULT_USER "anonymous"
|
||||
#define CURL_DEFAULT_PASSWORD "curl_by_Daniel.Stenberg@haxx.nu"
|
||||
|
||||
#include "cookie.h"
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
/* SSLeay stuff usually in /usr/local/ssl/include */
|
||||
#ifdef USE_OPENSSL
|
||||
#include "openssl/rsa.h"
|
||||
#include "openssl/crypto.h"
|
||||
#include "openssl/x509.h"
|
||||
#include "openssl/pem.h"
|
||||
#include "openssl/ssl.h"
|
||||
#include "openssl/err.h"
|
||||
#else
|
||||
#include "rsa.h"
|
||||
#include "crypto.h"
|
||||
#include "x509.h"
|
||||
#include "pem.h"
|
||||
#include "ssl.h"
|
||||
#include "err.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Download buffer size, keep it fairly big for speed reasons */
|
||||
#define BUFSIZE (1024*50)
|
||||
|
||||
/* Initial size of the buffer to store headers in, it'll be enlarged in case
|
||||
of need. */
|
||||
#define HEADERSIZE 256
|
||||
|
||||
struct UrlData {
|
||||
FILE *out; /* the fetched file goes here */
|
||||
FILE *in; /* the uploaded file is read from here */
|
||||
FILE *err; /* the stderr writes goes here */
|
||||
FILE *writeheader; /* write the header to this is non-NULL */
|
||||
char *url; /* what to get */
|
||||
char *freethis; /* if non-NULL, an allocated string for the URL */
|
||||
char *hostname; /* hostname to contect, as parsed from url */
|
||||
unsigned short port; /* which port to use (if non-protocol bind) set
|
||||
CONF_PORT to use this */
|
||||
unsigned short remote_port; /* what remote port to connect to, not the proxy
|
||||
port! */
|
||||
char *proxy; /* if proxy, set it here, set CONF_PROXY to use this */
|
||||
long conf; /* configure flags */
|
||||
char *userpwd; /* <user:password>, if used */
|
||||
char *proxyuserpwd; /* Proxy <user:password>, if used */
|
||||
char *range; /* range, if used. See README for detailed specification on
|
||||
this syntax. */
|
||||
char *postfields; /* if POST, set the fields' values here */
|
||||
char *referer;
|
||||
char *errorbuffer; /* store failure messages in here */
|
||||
char *useragent; /* User-Agent string */
|
||||
|
||||
char *ftpport; /* port to send with the PORT command */
|
||||
|
||||
/* function that stores the output:*/
|
||||
size_t (*fwrite)(char *buffer,
|
||||
size_t size,
|
||||
size_t nitems,
|
||||
FILE *outstream);
|
||||
|
||||
/* function that reads the input:*/
|
||||
size_t (*fread)(char *buffer,
|
||||
size_t size,
|
||||
size_t nitems,
|
||||
FILE *outstream);
|
||||
|
||||
long timeout; /* in seconds, 0 means no timeout */
|
||||
long infilesize; /* size of file to upload, -1 means unknown */
|
||||
|
||||
long maxdownload; /* in bytes, the maximum amount of data to fetch, 0
|
||||
means unlimited */
|
||||
|
||||
/* fields only set and used within _urlget() */
|
||||
int firstsocket; /* the main socket to use */
|
||||
int secondarysocket; /* for i.e ftp transfers */
|
||||
|
||||
char buffer[BUFSIZE+1]; /* buffer with size BUFSIZE */
|
||||
|
||||
double current_speed; /* the ProgressShow() funcion sets this */
|
||||
|
||||
long low_speed_limit; /* bytes/second */
|
||||
long low_speed_time; /* number of seconds */
|
||||
|
||||
int resume_from; /* continue [ftp] transfer from here */
|
||||
|
||||
char *cookie; /* HTTP cookie string to send */
|
||||
|
||||
short use_ssl; /* use ssl encrypted communications */
|
||||
|
||||
char *newurl; /* This can only be set if a Location: was in the
|
||||
document headers */
|
||||
|
||||
#ifdef MULTIDOC
|
||||
struct MoreDoc *moredoc; /* linked list of more docs to get */
|
||||
#endif
|
||||
struct HttpHeader *headers; /* linked list of extra headers */
|
||||
struct HttpPost *httppost; /* linked list of POST data */
|
||||
|
||||
char *cert; /* PEM-formatted certificate */
|
||||
char *cert_passwd; /* plain text certificate password */
|
||||
|
||||
struct CookieInfo *cookies;
|
||||
|
||||
long ssl_version; /* what version the client wants to use */
|
||||
#ifdef USE_SSLEAY
|
||||
SSL_CTX* ctx;
|
||||
SSL* ssl;
|
||||
X509* server_cert;
|
||||
#endif /* USE_SSLEAY */
|
||||
long crlf;
|
||||
struct curl_slist *quote;
|
||||
|
||||
TimeCond timecondition;
|
||||
time_t timevalue;
|
||||
|
||||
char *customrequest; /* http/ftp request to use */
|
||||
|
||||
char *headerbuff; /* allocated buffer to store headers in */
|
||||
int headersize; /* size of the allocation */
|
||||
int progressmode; /* what kind of progress meter to display */
|
||||
|
||||
#define MAX_CURL_USER_LENGTH 128
|
||||
#define MAX_CURL_PASSWORD_LENGTH 128
|
||||
|
||||
char user[MAX_CURL_USER_LENGTH];
|
||||
char passwd[MAX_CURL_PASSWORD_LENGTH];
|
||||
char proxyuser[MAX_CURL_USER_LENGTH];
|
||||
char proxypasswd[MAX_CURL_PASSWORD_LENGTH];
|
||||
|
||||
/**** Dynamicly allocated strings, may need to be freed on return ****/
|
||||
char *ptr_proxyuserpwd; /* free later if not NULL! */
|
||||
char *ptr_uagent; /* free later if not NULL! */
|
||||
char *ptr_userpwd; /* free later if not NULL! */
|
||||
char *ptr_rangeline; /* free later if not NULL! */
|
||||
char *ptr_ref; /* free later if not NULL! */
|
||||
char *ptr_cookie; /* free later if not NULL! */
|
||||
char *ptr_host; /* free later if not NULL */
|
||||
};
|
||||
|
||||
#define LIBCURL_NAME "libcurl"
|
||||
#define LIBCURL_ID LIBCURL_NAME " " LIBCURL_VERSION " " SSL_ID
|
||||
|
||||
|
||||
#endif
|
||||
86
lib/version.c
Normal file
86
lib/version.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Curl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Daniel Stenberg.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* Main author:
|
||||
* - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
|
||||
*
|
||||
* http://curl.haxx.nu
|
||||
*
|
||||
* $Source$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
* $State$
|
||||
* $Locker$
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "setup.h"
|
||||
#include <curl/curl.h>
|
||||
#include "urldata.h"
|
||||
|
||||
char *curl_version(void)
|
||||
{
|
||||
static char version[200];
|
||||
char *ptr;
|
||||
#if defined(USE_SSLEAY)
|
||||
static char sub[2];
|
||||
#endif
|
||||
strcpy(version, LIBCURL_NAME " " LIBCURL_VERSION );
|
||||
ptr=strchr(version, '\0');
|
||||
|
||||
#ifdef USE_SSLEAY
|
||||
|
||||
#if (SSLEAY_VERSION_NUMBER >= 0x900000)
|
||||
sprintf(ptr, " (SSL %x.%x.%x)",
|
||||
(SSLEAY_VERSION_NUMBER>>28)&0xff,
|
||||
(SSLEAY_VERSION_NUMBER>>20)&0xff,
|
||||
(SSLEAY_VERSION_NUMBER>>12)&0xf);
|
||||
#else
|
||||
if(SSLEAY_VERSION_NUMBER&0x0f) {
|
||||
sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
|
||||
}
|
||||
else
|
||||
sub[0]=0;
|
||||
|
||||
sprintf(ptr, " (SSL %x.%x.%x%s)",
|
||||
(SSLEAY_VERSION_NUMBER>>12)&0xff,
|
||||
(SSLEAY_VERSION_NUMBER>>8)&0xf,
|
||||
(SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
|
||||
|
||||
#endif
|
||||
ptr=strchr(ptr, '\0');
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZLIB
|
||||
sprintf(ptr, " (zlib %s)", zlibVersion());
|
||||
#endif
|
||||
|
||||
return version;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue