Update networking layer w/ CURL and emscripten impl

This commit is contained in:
2025-11-08 01:50:36 +11:00
parent a17925904d
commit f6874dc55a
4105 changed files with 694617 additions and 179 deletions
+61
View File
@@ -0,0 +1,61 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Get BUNDLE, FIRST_C, FIRST_H, UTILS_C, UTILS_H, CURLX_C, TESTS_C variables
curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
if(LIB_SELECTED STREQUAL LIB_STATIC)
set(CURLX_C "") # Already exported from the libcurl static build. Skip them.
endif()
add_custom_command(OUTPUT "lib1521.c"
COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${PROJECT_SOURCE_DIR}/include/curl/curl.h" "lib1521.c"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl"
"${PROJECT_SOURCE_DIR}/include/curl/curl.h"
VERBATIM)
list(APPEND TESTS_C "lib1521.c")
add_custom_command(OUTPUT "${BUNDLE}.c"
COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl"
--include ${UTILS_C} ${CURLX_C} --test ${TESTS_C} > "${BUNDLE}.c"
DEPENDS
"${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
${FIRST_C} ${UTILS_C} ${CURLX_C} ${TESTS_C}
VERBATIM)
add_executable(${BUNDLE} EXCLUDE_FROM_ALL "${BUNDLE}.c")
add_dependencies(testdeps ${BUNDLE})
target_link_libraries(${BUNDLE} ${LIB_SELECTED} ${CURL_LIBS})
target_include_directories(${BUNDLE} PRIVATE
"${PROJECT_BINARY_DIR}/lib" # for "curl_config.h"
"${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h", curlx
"${CMAKE_CURRENT_SOURCE_DIR}" # for the generated bundle source to find included test sources
)
target_compile_definitions(${BUNDLE} PRIVATE ${CURL_DEBUG_MACROS})
set_target_properties(${BUNDLE} PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF C_CLANG_TIDY "")
curl_add_clang_tidy_test_target("${BUNDLE}-clang-tidy" ${BUNDLE} ${FIRST_C} ${UTILS_C} ${TESTS_C})
+94
View File
@@ -0,0 +1,94 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
AUTOMAKE_OPTIONS = foreign nostdinc
# Specify our include paths here, and do it relative to $(top_srcdir) and
# $(top_builddir), to ensure that these paths which belong to the library
# being currently built and tested are searched before the library which
# might possibly already be installed in the system.
#
# $(top_srcdir)/include is for libcurl's external include files
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
# $(srcdir) for the generated bundle source to find included test sources
AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib \
-I$(srcdir)
# Get BUNDLE, FIRST_C, FIRST_H, UTILS_C, UTILS_H, CURLX_C, TESTS_C variables
include Makefile.inc
EXTRA_DIST = CMakeLists.txt $(FIRST_C) $(FIRST_H) $(UTILS_C) $(UTILS_H) $(TESTS_C) \
test307.pl test610.pl test613.pl test1013.pl test1022.pl mk-lib1521.pl
CFLAGS += @CURL_CFLAG_EXTRAS@
# Prevent LIBS from being used for all link targets
LIBS = $(BLANK_AT_MAKETIME)
if USE_CPPFLAG_CURL_STATICLIB
AM_CPPFLAGS += -DCURL_STATICLIB
endif
if DEBUGBUILD
AM_CPPFLAGS += -DDEBUGBUILD
endif
if CURLDEBUG
AM_CPPFLAGS += -DCURLDEBUG
endif
if USE_CPPFLAG_CURL_STATICLIB
curlx_c_lib =
else
# These are part of the libcurl static lib. Add them here when linking shared.
curlx_c_lib = $(CURLX_C)
endif
$(BUNDLE).c: $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRST_C) $(UTILS_C) $(curlx_c_lib) $(TESTS_C) lib1521.c
@PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS_C) $(curlx_c_lib) --test $(TESTS_C) lib1521.c > $(BUNDLE).c
noinst_PROGRAMS = $(BUNDLE)
LDADD = $(top_builddir)/lib/libcurl.la @LIBCURL_PC_LIBS_PRIVATE@
CLEANFILES = $(BUNDLE).c lib1521.c
lib1521.c: $(top_srcdir)/tests/libtest/mk-lib1521.pl $(top_srcdir)/include/curl/curl.h
@PERL@ $(top_srcdir)/tests/libtest/mk-lib1521.pl < $(top_srcdir)/include/curl/curl.h lib1521.c
CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
CS_ = $(CS_0)
# ignore generated C files since they play by slightly different rules!
checksrc: lib1521.c
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
-W$(srcdir)/$(BUNDLE).c \
$(srcdir)/*.[ch])
if NOT_CURL_CI
all-local: checksrc
endif
clean-local:
rm -f $(BUNDLE)
+853
View File
@@ -0,0 +1,853 @@
# Makefile.in generated by automake 1.16.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2021 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Shared between CMakeLists.txt and Makefile.am
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@USE_CPPFLAG_CURL_STATICLIB_TRUE@am__append_1 = -DCURL_STATICLIB
@DEBUGBUILD_TRUE@am__append_2 = -DDEBUGBUILD
@CURLDEBUG_TRUE@am__append_3 = -DCURLDEBUG
noinst_PROGRAMS = $(am__EXEEXT_1)
subdir = tests/libtest
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/curl-amissl.m4 \
$(top_srcdir)/m4/curl-apple-sectrust.m4 \
$(top_srcdir)/m4/curl-compilers.m4 \
$(top_srcdir)/m4/curl-confopts.m4 \
$(top_srcdir)/m4/curl-functions.m4 \
$(top_srcdir)/m4/curl-gnutls.m4 \
$(top_srcdir)/m4/curl-mbedtls.m4 \
$(top_srcdir)/m4/curl-openssl.m4 \
$(top_srcdir)/m4/curl-override.m4 \
$(top_srcdir)/m4/curl-reentrant.m4 \
$(top_srcdir)/m4/curl-rustls.m4 \
$(top_srcdir)/m4/curl-schannel.m4 \
$(top_srcdir)/m4/curl-sysconfig.m4 \
$(top_srcdir)/m4/curl-wolfssl.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/xc-am-iface.m4 \
$(top_srcdir)/m4/xc-cc-check.m4 \
$(top_srcdir)/m4/xc-lt-iface.m4 \
$(top_srcdir)/m4/xc-val-flgs.m4 \
$(top_srcdir)/m4/zz40-xc-ovr.m4 \
$(top_srcdir)/m4/zz50-xc-ovr.m4 \
$(top_srcdir)/m4/zz60-xc-ovr.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/lib/curl_config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__EXEEXT_1 = libtests$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
libtests_SOURCES = libtests.c
libtests_OBJECTS = libtests.$(OBJEXT)
libtests_LDADD = $(LDADD)
libtests_DEPENDENCIES = $(top_builddir)/lib/libcurl.la
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/libtests.Po
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = libtests.c
DIST_SOURCES = libtests.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.inc \
$(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
APXS = @APXS@
AR = @AR@
AR_FLAGS = @AR_FLAGS@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BLANK_AT_MAKETIME = @BLANK_AT_MAKETIME@
CADDY = @CADDY@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@ @CURL_CFLAG_EXTRAS@
CFLAG_CURL_SYMBOL_HIDING = @CFLAG_CURL_SYMBOL_HIDING@
CONFIGURE_OPTIONS = @CONFIGURE_OPTIONS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CSCOPE = @CSCOPE@
CTAGS = @CTAGS@
CURLVERSION = @CURLVERSION@
CURL_CA_BUNDLE = @CURL_CA_BUNDLE@
CURL_CA_EMBED = @CURL_CA_EMBED@
CURL_CFLAG_EXTRAS = @CURL_CFLAG_EXTRAS@
CURL_CPP = @CURL_CPP@
CURL_LIBCURL_VERSIONED_SYMBOLS_PREFIX = @CURL_LIBCURL_VERSIONED_SYMBOLS_PREFIX@
CURL_LIBCURL_VERSIONED_SYMBOLS_SONAME = @CURL_LIBCURL_VERSIONED_SYMBOLS_SONAME@
CURL_NETWORK_AND_TIME_LIBS = @CURL_NETWORK_AND_TIME_LIBS@
CYGPATH_W = @CYGPATH_W@
DANTED = @DANTED@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_SHARED = @ENABLE_SHARED@
ENABLE_STATIC = @ENABLE_STATIC@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
FILECMD = @FILECMD@
FISH_FUNCTIONS_DIR = @FISH_FUNCTIONS_DIR@
GCOV = @GCOV@
GREP = @GREP@
HAVE_LIBZ = @HAVE_LIBZ@
HTTPD = @HTTPD@
HTTPD_NGHTTPX = @HTTPD_NGHTTPX@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LCOV = @LCOV@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBCURL_PC_CFLAGS = @LIBCURL_PC_CFLAGS@
LIBCURL_PC_CFLAGS_PRIVATE = @LIBCURL_PC_CFLAGS_PRIVATE@
LIBCURL_PC_LDFLAGS_PRIVATE = @LIBCURL_PC_LDFLAGS_PRIVATE@
LIBCURL_PC_LIBS = @LIBCURL_PC_LIBS@
LIBCURL_PC_LIBS_PRIVATE = @LIBCURL_PC_LIBS_PRIVATE@
LIBCURL_PC_REQUIRES = @LIBCURL_PC_REQUIRES@
LIBCURL_PC_REQUIRES_PRIVATE = @LIBCURL_PC_REQUIRES_PRIVATE@
LIBOBJS = @LIBOBJS@
# Prevent LIBS from being used for all link targets
LIBS = $(BLANK_AT_MAKETIME)
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PERL = @PERL@
PKGCONFIG = @PKGCONFIG@
RANLIB = @RANLIB@
RC = @RC@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SSL_BACKENDS = @SSL_BACKENDS@
STRIP = @STRIP@
SUPPORT_FEATURES = @SUPPORT_FEATURES@
SUPPORT_PROTOCOLS = @SUPPORT_PROTOCOLS@
TEST_NGHTTPX = @TEST_NGHTTPX@
VERSION = @VERSION@
VERSIONNUM = @VERSIONNUM@
VSFTPD = @VSFTPD@
ZLIB_LIBS = @ZLIB_LIBS@
ZSH_FUNCTIONS_DIR = @ZSH_FUNCTIONS_DIR@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
libext = @libext@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
AUTOMAKE_OPTIONS = foreign nostdinc
# Specify our include paths here, and do it relative to $(top_srcdir) and
# $(top_builddir), to ensure that these paths which belong to the library
# being currently built and tested are searched before the library which
# might possibly already be installed in the system.
#
# $(top_srcdir)/include is for libcurl's external include files
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
# $(srcdir) for the generated bundle source to find included test sources
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/lib \
-I$(top_srcdir)/lib -I$(srcdir) $(am__append_1) \
$(am__append_2) $(am__append_3)
BUNDLE = libtests
# Files referenced from the bundle source
FIRST_C = first.c
FIRST_H = first.h
# Common files used by test programs
UTILS_C = memptr.c testutil.c testtrace.c
UTILS_H = testutil.h testtrace.h unitcheck.h
CURLX_C = \
../../lib/curl_threads.c \
../../lib/curlx/fopen.c \
../../lib/curlx/multibyte.c \
../../lib/curlx/strerr.c \
../../lib/curlx/timediff.c \
../../lib/curlx/timeval.c \
../../lib/curlx/version_win32.c \
../../lib/curlx/wait.c \
../../lib/curlx/warnless.c \
../../lib/curlx/winapi.c
# All libtest programs
TESTS_C = \
cli_h2_pausing.c \
cli_h2_serverpush.c \
cli_h2_upgrade_extreme.c \
cli_hx_download.c \
cli_hx_upload.c \
cli_tls_session_reuse.c \
cli_upload_pausing.c \
cli_ws_data.c \
cli_ws_pingpong.c \
\
lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c \
lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c \
lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c \
lib525.c lib526.c lib530.c \
lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c \
lib542.c lib543.c lib544.c lib547.c lib549.c \
lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c \
lib560.c lib562.c lib564.c lib566.c lib567.c \
lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c \
lib576.c lib578.c lib579.c lib582.c lib583.c \
lib586.c lib589.c lib590.c lib591.c \
lib597.c lib598.c lib599.c \
lib643.c \
lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c \
lib661.c lib666.c lib667.c lib668.c \
lib670.c lib674.c lib676.c lib677.c lib678.c \
lib694.c lib695.c \
lib751.c lib753.c lib758.c \
lib757.c \
lib766.c \
lib1156.c \
lib1301.c lib1308.c \
lib1485.c \
lib1500.c lib1501.c lib1502.c lib1506.c \
lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c \
lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c \
lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c \
lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c \
lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c \
lib1545.c lib1549.c lib1550.c lib1551.c \
lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c \
lib1559.c lib1560.c lib1564.c lib1565.c \
lib1567.c lib1568.c lib1569.c lib1571.c \
lib1576.c \
lib1582.c \
lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c \
lib1598.c lib1599.c \
lib1662.c \
lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c \
lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c \
lib1915.c lib1916.c lib1918.c lib1919.c \
lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c \
lib1940.c lib1945.c \
lib1947.c lib1948.c \
lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c \
lib1964.c lib1970.c \
lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c \
lib2023.c lib2032.c lib2082.c \
lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c \
lib2402.c lib2404.c lib2405.c \
lib2502.c \
lib2700.c \
lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c \
lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c \
lib3207.c lib3208.c
# Get BUNDLE, FIRST_C, FIRST_H, UTILS_C, UTILS_H, CURLX_C, TESTS_C variables
EXTRA_DIST = CMakeLists.txt $(FIRST_C) $(FIRST_H) $(UTILS_C) $(UTILS_H) $(TESTS_C) \
test307.pl test610.pl test613.pl test1013.pl test1022.pl mk-lib1521.pl
# These are part of the libcurl static lib. Add them here when linking shared.
@USE_CPPFLAG_CURL_STATICLIB_FALSE@curlx_c_lib = $(CURLX_C)
@USE_CPPFLAG_CURL_STATICLIB_TRUE@curlx_c_lib =
LDADD = $(top_builddir)/lib/libcurl.la @LIBCURL_PC_LIBS_PRIVATE@
CLEANFILES = $(BUNDLE).c lib1521.c
CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
CS_ = $(CS_0)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(srcdir)/Makefile.inc $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/libtest/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign tests/libtest/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
esac;
$(srcdir)/Makefile.inc $(am__empty):
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
libtests$(EXEEXT): $(libtests_OBJECTS) $(libtests_DEPENDENCIES) $(EXTRA_libtests_DEPENDENCIES)
@rm -f libtests$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(libtests_OBJECTS) $(libtests_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtests.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
am--depfiles: $(am__depfiles_remade)
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) distdir-am
distdir-am: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
@NOT_CURL_CI_FALSE@all-local:
all-am: Makefile $(PROGRAMS) all-local
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool clean-local clean-noinstPROGRAMS \
mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/libtests.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libtests.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS TAGS all all-am all-local am--depfiles check \
check-am clean clean-generic clean-libtool clean-local \
clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am
.PRECIOUS: Makefile
$(BUNDLE).c: $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRST_C) $(UTILS_C) $(curlx_c_lib) $(TESTS_C) lib1521.c
@PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS_C) $(curlx_c_lib) --test $(TESTS_C) lib1521.c > $(BUNDLE).c
lib1521.c: $(top_srcdir)/tests/libtest/mk-lib1521.pl $(top_srcdir)/include/curl/curl.h
@PERL@ $(top_srcdir)/tests/libtest/mk-lib1521.pl < $(top_srcdir)/include/curl/curl.h lib1521.c
# ignore generated C files since they play by slightly different rules!
checksrc: lib1521.c
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
-W$(srcdir)/$(BUNDLE).c \
$(srcdir)/*.[ch])
@NOT_CURL_CI_TRUE@all-local: checksrc
clean-local:
rm -f $(BUNDLE)
# 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:
+114
View File
@@ -0,0 +1,114 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Shared between CMakeLists.txt and Makefile.am
BUNDLE = libtests
# Files referenced from the bundle source
FIRST_C = first.c
FIRST_H = first.h
# Common files used by test programs
UTILS_C = memptr.c testutil.c testtrace.c
UTILS_H = testutil.h testtrace.h unitcheck.h
CURLX_C = \
../../lib/curl_threads.c \
../../lib/curlx/fopen.c \
../../lib/curlx/multibyte.c \
../../lib/curlx/strerr.c \
../../lib/curlx/timediff.c \
../../lib/curlx/timeval.c \
../../lib/curlx/version_win32.c \
../../lib/curlx/wait.c \
../../lib/curlx/warnless.c \
../../lib/curlx/winapi.c
# All libtest programs
TESTS_C = \
cli_h2_pausing.c \
cli_h2_serverpush.c \
cli_h2_upgrade_extreme.c \
cli_hx_download.c \
cli_hx_upload.c \
cli_tls_session_reuse.c \
cli_upload_pausing.c \
cli_ws_data.c \
cli_ws_pingpong.c \
\
lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c \
lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c \
lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c \
lib525.c lib526.c lib530.c \
lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c \
lib542.c lib543.c lib544.c lib547.c lib549.c \
lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c \
lib560.c lib562.c lib564.c lib566.c lib567.c \
lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c \
lib576.c lib578.c lib579.c lib582.c lib583.c \
lib586.c lib589.c lib590.c lib591.c \
lib597.c lib598.c lib599.c \
lib643.c \
lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c \
lib661.c lib666.c lib667.c lib668.c \
lib670.c lib674.c lib676.c lib677.c lib678.c \
lib694.c lib695.c \
lib751.c lib753.c lib758.c \
lib757.c \
lib766.c \
lib1156.c \
lib1301.c lib1308.c \
lib1485.c \
lib1500.c lib1501.c lib1502.c lib1506.c \
lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c \
lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c \
lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c \
lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c \
lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c \
lib1545.c lib1549.c lib1550.c lib1551.c \
lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c \
lib1559.c lib1560.c lib1564.c lib1565.c \
lib1567.c lib1568.c lib1569.c lib1571.c \
lib1576.c \
lib1582.c \
lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c \
lib1598.c lib1599.c \
lib1662.c \
lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c \
lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c \
lib1915.c lib1916.c lib1918.c lib1919.c \
lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c \
lib1940.c lib1945.c \
lib1947.c lib1948.c \
lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c \
lib1964.c lib1970.c \
lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c \
lib2023.c lib2032.c lib2082.c \
lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c \
lib2402.c lib2404.c lib2405.c \
lib2502.c \
lib2700.c \
lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c \
lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c \
lib3207.c lib3208.c
+318
View File
@@ -0,0 +1,318 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* This is based on the PoC client of issue #11982
*/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static void usage_h2_pausing(const char *msg)
{
if(msg)
curl_mfprintf(stderr, "%s\n", msg);
curl_mfprintf(stderr,
"usage: [options] url\n"
" pause downloads with following options:\n"
" -V http_version (http/1.1, h2, h3) http version to use\n"
);
}
struct handle
{
size_t idx;
int paused;
int resumed;
int errored;
int fail_write;
CURL *curl;
};
static size_t cb(char *data, size_t size, size_t nmemb, void *clientp)
{
size_t realsize = size * nmemb;
struct handle *handle = (struct handle *) clientp;
curl_off_t totalsize;
(void)data;
if(curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
&totalsize) == CURLE_OK)
curl_mfprintf(stderr, "INFO: [%zu] write, "
"Content-Length %" CURL_FORMAT_CURL_OFF_T "\n",
handle->idx, totalsize);
if(!handle->resumed) {
++handle->paused;
curl_mfprintf(stderr, "INFO: [%zu] write, PAUSING %d time on %zu bytes\n",
handle->idx, handle->paused, realsize);
assert(handle->paused == 1);
return CURL_WRITEFUNC_PAUSE;
}
if(handle->fail_write) {
++handle->errored;
curl_mfprintf(stderr, "INFO: [%zu] FAIL write of %zu bytes, %d time\n",
handle->idx, realsize, handle->errored);
return CURL_WRITEFUNC_ERROR;
}
curl_mfprintf(stderr, "INFO: [%zu] write, accepting %zu bytes\n",
handle->idx, realsize);
return realsize;
}
static CURLcode test_cli_h2_pausing(const char *URL)
{
struct handle handles[2];
CURLM *multi = NULL;
int still_running = 1, msgs_left, numfds;
size_t i;
CURLMsg *msg;
int rounds = 0;
CURLcode result = CURLE_OK;
CURLU *cu;
struct curl_slist *resolve = NULL;
char resolve_buf[1024];
const char *url;
char *host = NULL, *port = NULL;
int all_paused = 0;
int resume_round = -1;
long http_version = CURL_HTTP_VERSION_2_0;
int ch;
(void)URL;
while((ch = cgetopt(test_argc, test_argv, "hV:")) != -1) {
switch(ch) {
case 'h':
usage_h2_pausing(NULL);
return (CURLcode)2;
case 'V': {
if(!strcmp("http/1.1", coptarg))
http_version = CURL_HTTP_VERSION_1_1;
else if(!strcmp("h2", coptarg))
http_version = CURL_HTTP_VERSION_2_0;
else if(!strcmp("h3", coptarg))
http_version = CURL_HTTP_VERSION_3ONLY;
else {
usage_h2_pausing("invalid http version");
return (CURLcode)1;
}
break;
}
default:
usage_h2_pausing("invalid option");
return (CURLcode)1;
}
}
test_argc -= coptind;
test_argv += coptind;
if(test_argc != 1) {
curl_mfprintf(stderr, "ERROR: need URL as argument\n");
return (CURLcode)2;
}
url = test_argv[0];
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
curl_global_trace("ids,time,http/2,http/3");
memset(handles, 0, sizeof(handles));
cu = curl_url();
if(!cu) {
curl_mfprintf(stderr, "out of memory\n");
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
curl_mfprintf(stderr, "not a URL: '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
curl_mfprintf(stderr, "could not get host of '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
curl_mfprintf(stderr, "could not get port of '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
memset(&resolve, 0, sizeof(resolve));
curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
host, port);
resolve = curl_slist_append(resolve, resolve_buf);
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
handles[i].idx = i;
handles[i].paused = 0;
handles[i].resumed = 0;
handles[i].errored = 0;
handles[i].fail_write = 1;
handles[i].curl = curl_easy_init();
if(!handles[i].curl ||
curl_easy_setopt(handles[i].curl, CURLOPT_WRITEFUNCTION, cb)
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_WRITEDATA, &handles[i])
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_FOLLOWLOCATION, 1L)
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_VERBOSE, 1L) != CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb)
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_SSL_VERIFYPEER, 0L)
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_RESOLVE, resolve)
!= CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_PIPEWAIT, 1L) != CURLE_OK ||
curl_easy_setopt(handles[i].curl, CURLOPT_URL, url) != CURLE_OK) {
curl_mfprintf(stderr, "failed configuring easy handle - bailing out\n");
result = (CURLcode)2;
goto cleanup;
}
curl_easy_setopt(handles[i].curl, CURLOPT_HTTP_VERSION, http_version);
}
multi = curl_multi_init();
if(!multi) {
curl_mfprintf(stderr, "curl_multi_init() failed - bailing out\n");
result = (CURLcode)2;
goto cleanup;
}
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
if(curl_multi_add_handle(multi, handles[i].curl) != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_add_handle() failed - bailing out\n");
result = (CURLcode)2;
goto cleanup;
}
}
for(rounds = 0;; rounds++) {
curl_mfprintf(stderr, "INFO: multi_perform round %d\n", rounds);
if(curl_multi_perform(multi, &still_running) != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_perform() failed - bailing out\n");
result = (CURLcode)2;
goto cleanup;
}
if(!still_running) {
int as_expected = 1;
curl_mfprintf(stderr, "INFO: no more handles running\n");
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
if(!handles[i].paused) {
curl_mfprintf(stderr, "ERROR: [%zu] NOT PAUSED\n", i);
as_expected = 0;
}
else if(handles[i].paused != 1) {
curl_mfprintf(stderr, "ERROR: [%zu] PAUSED %d times!\n",
i, handles[i].paused);
as_expected = 0;
}
else if(!handles[i].resumed) {
curl_mfprintf(stderr, "ERROR: [%zu] NOT resumed!\n", i);
as_expected = 0;
}
else if(handles[i].errored != 1) {
curl_mfprintf(stderr, "ERROR: [%zu] NOT errored once, %d instead!\n",
i, handles[i].errored);
as_expected = 0;
}
}
if(!as_expected) {
curl_mfprintf(stderr, "ERROR: handles not in expected state "
"after %d rounds\n", rounds);
result = (CURLcode)1;
}
break;
}
if(curl_multi_poll(multi, NULL, 0, 100, &numfds) != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_poll() failed - bailing out\n");
result = (CURLcode)2;
goto cleanup;
}
/* !checksrc! disable EQUALSNULL 1 */
while((msg = curl_multi_info_read(multi, &msgs_left)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
if(msg->easy_handle == handles[i].curl) {
if(handles[i].paused != 1 || !handles[i].resumed) {
curl_mfprintf(stderr, "ERROR: [%zu] done, paused=%d, "
"resumed=%d, result %d - wtf?\n", i,
handles[i].paused,
handles[i].resumed, msg->data.result);
result = (CURLcode)1;
goto cleanup;
}
}
}
}
}
/* Successfully paused? */
if(!all_paused) {
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
if(!handles[i].paused) {
break;
}
}
all_paused = (i == CURL_ARRAYSIZE(handles));
if(all_paused) {
curl_mfprintf(stderr, "INFO: all transfers paused\n");
/* give transfer some rounds to mess things up */
resume_round = rounds + 2;
}
}
if(resume_round > 0 && rounds == resume_round) {
/* time to resume */
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
curl_mfprintf(stderr, "INFO: [%zu] resumed\n", i);
handles[i].resumed = 1;
curl_easy_pause(handles[i].curl, CURLPAUSE_CONT);
}
}
}
cleanup:
for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
curl_multi_remove_handle(multi, handles[i].curl);
curl_easy_cleanup(handles[i].curl);
}
curl_slist_free_all(resolve);
curl_free(host);
curl_free(port);
curl_url_cleanup(cu);
curl_multi_cleanup(multi);
curl_global_cleanup();
return result;
}
+193
View File
@@ -0,0 +1,193 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static FILE *out_download = NULL;
static int setup_h2_serverpush(CURL *curl, const char *url)
{
out_download = curlx_fopen("download_0.data", "wb");
if(!out_download)
return 1; /* failed */
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_download);
/* please be verbose */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
/* wait for pipe connection to confirm */
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
return 0; /* all is good */
}
static FILE *out_push = NULL;
/* called when there is an incoming push */
static int server_push_callback(CURL *parent,
CURL *curl,
size_t num_headers,
struct curl_pushheaders *headers,
void *userp)
{
char *headp;
size_t i;
int *transfers = (int *)userp;
char filename[128];
static unsigned int count = 0;
(void)parent;
curl_msnprintf(filename, sizeof(filename) - 1, "push%u", count++);
/* here's a new stream, save it in a new file for each new push */
out_push = curlx_fopen(filename, "wb");
if(!out_push) {
/* if we cannot save it, deny it */
curl_mfprintf(stderr, "Failed to create output file for push\n");
return CURL_PUSH_DENY;
}
/* write to this file */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_push);
curl_mfprintf(stderr, "**** push callback approves stream %u, "
"got %zu headers!\n", count, num_headers);
for(i = 0; i < num_headers; i++) {
headp = curl_pushheader_bynum(headers, i);
curl_mfprintf(stderr, "**** header %zu: %s\n", i, headp);
}
headp = curl_pushheader_byname(headers, ":path");
if(headp) {
curl_mfprintf(stderr, "**** The PATH is %s\n",
headp /* skip :path + colon */);
}
(*transfers)++; /* one more */
return CURL_PUSH_OK;
}
/*
* Download a file over HTTP/2, take care of server push.
*/
static CURLcode test_cli_h2_serverpush(const char *URL)
{
CURL *curl = NULL;
CURLM *multi;
int transfers = 1; /* we start with one */
CURLcode result = CURLE_OK;
debug_config.nohex = TRUE;
debug_config.tracetime = FALSE;
if(!URL) {
curl_mfprintf(stderr, "need URL as argument\n");
return (CURLcode)2;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
multi = curl_multi_init();
if(!multi) {
result = (CURLcode)1;
goto cleanup;
}
curl = curl_easy_init();
if(!curl) {
result = (CURLcode)1;
goto cleanup;
}
if(setup_h2_serverpush(curl, URL)) {
curl_mfprintf(stderr, "failed\n");
result = (CURLcode)1;
goto cleanup;
}
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback);
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers);
curl_multi_add_handle(multi, curl);
do {
struct CURLMsg *m;
int still_running; /* keep number of running handles */
CURLMcode mc = curl_multi_perform(multi, &still_running);
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
if(mc)
break;
/*
* A little caution when doing server push is that libcurl itself has
* created and added one or more easy handles but we need to clean them up
* when we are done.
*/
do {
int msgq = 0;
m = curl_multi_info_read(multi, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
CURL *easy = m->easy_handle;
transfers--;
curl_multi_remove_handle(multi, easy);
curl_easy_cleanup(easy);
}
} while(m);
} while(transfers); /* as long as we have transfers going */
cleanup:
curl_multi_cleanup(multi);
if(out_download)
curlx_fclose(out_download);
if(out_push)
curlx_fclose(out_push);
curl_global_cleanup();
return result;
}
@@ -0,0 +1,172 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static size_t write_h2_upg_extreme_cb(char *ptr, size_t size, size_t nmemb,
void *opaque)
{
(void)ptr;
(void)opaque;
return size * nmemb;
}
static CURLcode test_cli_h2_upgrade_extreme(const char *URL)
{
CURLM *multi = NULL;
CURL *curl;
CURLMcode mc;
int running_handles = 0, start_count, numfds;
CURLMsg *msg;
int msgs_in_queue;
char range[128];
CURLcode result = (CURLcode)1;
if(!URL) {
curl_mfprintf(stderr, "need URL as argument\n");
return (CURLcode)2;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
multi = curl_multi_init();
if(!multi) {
curl_mfprintf(stderr, "curl_multi_init failed\n");
goto cleanup;
}
start_count = 200;
do {
if(start_count) {
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init failed\n");
goto cleanup;
}
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_h2_upg_extreme_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_msnprintf(range, sizeof(range),
"%" CURL_FORMAT_CURL_OFF_TU "-"
"%" CURL_FORMAT_CURL_OFF_TU,
(curl_off_t)0,
(curl_off_t)16384);
curl_easy_setopt(curl, CURLOPT_RANGE, range);
mc = curl_multi_add_handle(multi, curl);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",
curl_multi_strerror(mc));
curl_easy_cleanup(curl);
goto cleanup;
}
--start_count;
}
mc = curl_multi_perform(multi, &running_handles);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_perform: %s\n",
curl_multi_strerror(mc));
goto cleanup;
}
if(running_handles) {
mc = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_poll: %s\n",
curl_multi_strerror(mc));
goto cleanup;
}
}
/* Check for finished handles and remove. */
/* !checksrc! disable EQUALSNULL 1 */
while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
long status = 0;
curl_off_t xfer_id;
curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id);
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status);
if(msg->data.result == CURLE_SEND_ERROR ||
msg->data.result == CURLE_RECV_ERROR) {
/* We get these if the server had a GOAWAY in transit on
* reusing a connection */
}
else if(msg->data.result) {
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
": failed with %d\n", xfer_id, msg->data.result);
goto cleanup;
}
else if(status != 206) {
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
": wrong http status %ld (expected 206)\n", xfer_id,
status);
goto cleanup;
}
curl_multi_remove_handle(multi, msg->easy_handle);
curl_easy_cleanup(msg->easy_handle);
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T" retiring "
"(%d now running)\n", xfer_id, running_handles);
}
}
curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
running_handles, start_count);
} while(running_handles > 0 || start_count);
curl_mfprintf(stderr, "exiting\n");
result = CURLE_OK;
cleanup:
if(multi) {
CURL **list = curl_multi_get_handles(multi);
if(list) {
int i;
for(i = 0; list[i]; i++) {
curl_multi_remove_handle(multi, list[i]);
curl_easy_cleanup(list[i]);
}
curl_free(list);
}
curl_multi_cleanup(multi);
}
curl_global_cleanup();
return result;
}
+566
View File
@@ -0,0 +1,566 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "curl_mem_undef.h"
#if defined(USE_QUICHE) || defined(USE_OPENSSL)
#include <openssl/ssl.h>
#endif
#ifdef USE_WOLFSSL
#include <wolfssl/options.h>
#include <wolfssl/version.h>
#include <wolfssl/ssl.h>
#endif
#ifdef USE_GNUTLS
#include <gnutls/gnutls.h>
#endif
#ifdef USE_MBEDTLS
#include <mbedtls/ssl.h>
#endif
#ifdef USE_RUSTLS
#include <rustls.h>
#endif
#include "memdebug.h"
static int verbose_d = 1;
struct transfer_d {
size_t idx;
CURL *curl;
char filename[128];
FILE *out;
curl_off_t recv_size;
curl_off_t fail_at;
curl_off_t pause_at;
curl_off_t abort_at;
int started;
int paused;
int resumed;
int done;
int checked_ssl;
CURLcode result;
};
static size_t transfer_count_d = 1;
static struct transfer_d *transfer_d;
static int forbid_reuse_d = 0;
static struct transfer_d *get_transfer_for_easy_d(CURL *curl)
{
size_t i;
for(i = 0; i < transfer_count_d; ++i) {
if(curl == transfer_d[i].curl)
return &transfer_d[i];
}
return NULL;
}
static size_t my_write_d_cb(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct transfer_d *t = userdata;
size_t blen = (nitems * buflen);
size_t nwritten;
curl_mfprintf(stderr, "[t-%zu] RECV %zu bytes, "
"total=%" CURL_FORMAT_CURL_OFF_T ", "
"pause_at=%" CURL_FORMAT_CURL_OFF_T "\n",
t->idx, blen, t->recv_size, t->pause_at);
if(!t->out) {
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data",
t->idx);
t->out = curlx_fopen(t->filename, "wb");
if(!t->out)
return 0;
}
if(!t->resumed &&
t->recv_size < t->pause_at &&
((t->recv_size + (curl_off_t)blen) >= t->pause_at)) {
curl_mfprintf(stderr, "[t-%zu] PAUSE\n", t->idx);
t->paused = 1;
return CURL_WRITEFUNC_PAUSE;
}
nwritten = fwrite(buf, nitems, buflen, t->out);
if(nwritten < blen) {
curl_mfprintf(stderr, "[t-%zu] write failure\n", t->idx);
return 0;
}
t->recv_size += (curl_off_t)nwritten;
if(t->fail_at > 0 && t->recv_size >= t->fail_at) {
curl_mfprintf(stderr, "[t-%zu] FAIL by write callback at "
"%" CURL_FORMAT_CURL_OFF_T " bytes\n", t->idx, t->recv_size);
return CURL_WRITEFUNC_ERROR;
}
return (size_t)nwritten;
}
static int my_progress_d_cb(void *userdata,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
struct transfer_d *t = userdata;
(void)ultotal;
(void)ulnow;
(void)dltotal;
if(t->abort_at > 0 && dlnow >= t->abort_at) {
curl_mfprintf(stderr, "[t-%zu] ABORT by progress_cb at "
"%" CURL_FORMAT_CURL_OFF_T " bytes\n", t->idx, dlnow);
return 1;
}
#if defined(USE_QUICHE) || defined(USE_OPENSSL) || defined(USE_WOLFSSL) || \
defined(USE_GNUTLS) || defined(USE_MBEDTLS) || defined(USE_RUSTLS)
if(!t->checked_ssl && dlnow > 0) {
struct curl_tlssessioninfo *tls;
CURLcode res;
t->checked_ssl = TRUE;
res = curl_easy_getinfo(t->curl, CURLINFO_TLS_SSL_PTR, &tls);
if(res) {
curl_mfprintf(stderr, "[t-%zu] info CURLINFO_TLS_SSL_PTR failed: %d\n",
t->idx, res);
assert(0);
}
else {
switch(tls->backend) {
#if defined(USE_QUICHE) || defined(USE_OPENSSL)
case CURLSSLBACKEND_OPENSSL: {
const char *version = SSL_get_version((SSL*)tls->internals);
assert(version);
assert(strcmp(version, "unknown"));
curl_mfprintf(stderr, "[t-%zu] info OpenSSL using %s\n",
t->idx, version);
break;
}
#endif
#ifdef USE_WOLFSSL
case CURLSSLBACKEND_WOLFSSL: {
const char *version = wolfSSL_get_version((WOLFSSL*)tls->internals);
assert(version);
assert(strcmp(version, "unknown"));
curl_mfprintf(stderr, "[t-%zu] info wolfSSL using %s\n",
t->idx, version);
break;
}
#endif
#ifdef USE_GNUTLS
case CURLSSLBACKEND_GNUTLS: {
int v = gnutls_protocol_get_version((gnutls_session_t)tls->internals);
assert(v);
curl_mfprintf(stderr, "[t-%zu] info GnuTLS using %s\n",
t->idx, gnutls_protocol_get_name(v));
break;
}
#endif
#ifdef USE_MBEDTLS
case CURLSSLBACKEND_MBEDTLS: {
const char *version = mbedtls_ssl_get_version(
(mbedtls_ssl_context*)tls->internals);
assert(version);
assert(strcmp(version, "unknown"));
curl_mfprintf(stderr, "[t-%zu] info mbedTLS using %s\n",
t->idx, version);
break;
}
#endif
#ifdef USE_RUSTLS
case CURLSSLBACKEND_RUSTLS: {
int v = rustls_connection_get_protocol_version(
(struct rustls_connection*)tls->internals);
assert(v);
curl_mfprintf(stderr, "[t-%zu] info rustls TLS version 0x%x\n",
t->idx, v);
break;
}
#endif
default:
curl_mfprintf(stderr, "[t-%zu] info SSL_PTR backend=%d, ptr=%p\n",
t->idx, tls->backend, (void *)tls->internals);
break;
}
}
}
#endif
return 0;
}
static int setup_hx_download(CURL *curl, const char *url, struct transfer_d *t,
long http_version, struct curl_slist *host,
CURLSH *share, int use_earlydata,
int fresh_connect)
{
curl_easy_setopt(curl, CURLOPT_SHARE, share);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, (long)(128 * 1024));
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_d_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, t);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, my_progress_d_cb);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, t);
if(use_earlydata)
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_EARLYDATA);
if(forbid_reuse_d)
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
if(host)
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
if(fresh_connect)
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
/* please be verbose */
if(verbose_d) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);
}
/* wait for pipe connection to confirm */
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
return 0; /* all is good */
}
static void usage_hx_download(const char *msg)
{
if(msg)
curl_mfprintf(stderr, "%s\n", msg);
curl_mfprintf(stderr,
"usage: [options] url\n"
" download a url with following options:\n"
" -a abort paused transfer\n"
" -m number max parallel downloads\n"
" -e use TLS early data when possible\n"
" -f forbid connection reuse\n"
" -n number total downloads\n");
curl_mfprintf(stderr,
" -A number abort transfer after `number` response bytes\n"
" -F number fail writing response after `number` response bytes\n"
" -M number max concurrent connections to a host\n"
" -P number pause transfer after `number` response bytes\n"
" -r <host>:<port>:<addr> resolve information\n"
" -T number max concurrent connections total\n"
" -V http_version (http/1.1, h2, h3) http version to use\n"
);
}
/*
* Download a file over HTTP/2, take care of server push.
*/
static CURLcode test_cli_hx_download(const char *URL)
{
CURLM *multi = NULL;
struct CURLMsg *m;
CURLSH *share = NULL;
const char *url;
size_t i, n, max_parallel = 1;
size_t active_transfers;
size_t pause_offset = 0;
size_t abort_offset = 0;
size_t fail_offset = 0;
int abort_paused = 0, use_earlydata = 0;
struct transfer_d *t = NULL;
long http_version = CURL_HTTP_VERSION_2_0;
int ch;
struct curl_slist *host = NULL;
char *resolve = NULL;
size_t max_host_conns = 0;
size_t max_total_conns = 0;
int fresh_connect = 0;
CURLcode result = CURLE_OK;
(void)URL;
while((ch = cgetopt(test_argc, test_argv, "aefhm:n:xA:F:M:P:r:T:V:"))
!= -1) {
switch(ch) {
case 'h':
usage_hx_download(NULL);
result = (CURLcode)2;
goto optcleanup;
case 'a':
abort_paused = 1;
break;
case 'e':
use_earlydata = 1;
break;
case 'f':
forbid_reuse_d = 1;
break;
case 'm':
max_parallel = (size_t)atol(coptarg);
break;
case 'n':
transfer_count_d = (size_t)atol(coptarg);
break;
case 'x':
fresh_connect = 1;
break;
case 'A':
abort_offset = (size_t)atol(coptarg);
break;
case 'F':
fail_offset = (size_t)atol(coptarg);
break;
case 'M':
max_host_conns = (size_t)atol(coptarg);
break;
case 'P':
pause_offset = (size_t)atol(coptarg);
break;
case 'r':
free(resolve);
resolve = strdup(coptarg);
break;
case 'T':
max_total_conns = (size_t)atol(coptarg);
break;
case 'V': {
if(!strcmp("http/1.1", coptarg))
http_version = CURL_HTTP_VERSION_1_1;
else if(!strcmp("h2", coptarg))
http_version = CURL_HTTP_VERSION_2_0;
else if(!strcmp("h3", coptarg))
http_version = CURL_HTTP_VERSION_3ONLY;
else {
usage_hx_download("invalid http version");
result = (CURLcode)1;
goto optcleanup;
}
break;
}
default:
usage_hx_download("invalid option");
result = (CURLcode)1;
goto optcleanup;
}
}
test_argc -= coptind;
test_argv += coptind;
curl_global_trace("ids,time,http/2,http/3");
if(test_argc != 1) {
usage_hx_download("not enough arguments");
result = (CURLcode)2;
goto optcleanup;
}
url = test_argv[0];
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
result = (CURLcode)3;
goto optcleanup;
}
if(resolve)
host = curl_slist_append(NULL, resolve);
share = curl_share_init();
if(!share) {
curl_mfprintf(stderr, "error allocating share\n");
result = (CURLcode)1;
goto cleanup;
}
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
/* curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); */
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS);
transfer_d = calloc(transfer_count_d, sizeof(*transfer_d));
if(!transfer_d) {
curl_mfprintf(stderr, "error allocating transfer structs\n");
result = (CURLcode)1;
goto cleanup;
}
multi = curl_multi_init();
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt(multi, CURLMOPT_MAX_TOTAL_CONNECTIONS,
(long)max_total_conns);
curl_multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS,
(long)max_host_conns);
active_transfers = 0;
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
t->idx = i;
t->abort_at = (curl_off_t)abort_offset;
t->fail_at = (curl_off_t)fail_offset;
t->pause_at = (curl_off_t)pause_offset;
}
n = (max_parallel < transfer_count_d) ? max_parallel : transfer_count_d;
for(i = 0; i < n; ++i) {
t = &transfer_d[i];
t->curl = curl_easy_init();
if(!t->curl ||
setup_hx_download(t->curl, url, t, http_version, host, share,
use_earlydata, fresh_connect)) {
curl_mfprintf(stderr, "[t-%zu] FAILED setup\n", i);
result = (CURLcode)1;
goto cleanup;
}
curl_multi_add_handle(multi, t->curl);
t->started = 1;
++active_transfers;
curl_mfprintf(stderr, "[t-%zu] STARTED\n", t->idx);
}
do {
int still_running; /* keep number of running handles */
CURLMcode mc = curl_multi_perform(multi, &still_running);
if(still_running) {
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
}
if(mc)
break;
do {
int msgq = 0;
m = curl_multi_info_read(multi, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
CURL *easy = m->easy_handle;
--active_transfers;
curl_multi_remove_handle(multi, easy);
t = get_transfer_for_easy_d(easy);
if(t) {
t->done = 1;
t->result = m->data.result;
curl_mfprintf(stderr, "[t-%zu] FINISHED with result %d\n",
t->idx, t->result);
if(use_earlydata) {
curl_off_t sent;
curl_easy_getinfo(easy, CURLINFO_EARLYDATA_SENT_T, &sent);
curl_mfprintf(stderr, "[t-%zu] EarlyData: "
"%" CURL_FORMAT_CURL_OFF_T "\n", t->idx, sent);
}
}
else {
curl_easy_cleanup(easy);
curl_mfprintf(stderr, "unknown FINISHED???\n");
}
}
/* nothing happening, maintenance */
if(abort_paused) {
/* abort paused transfers */
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
if(!t->done && t->paused && t->curl) {
curl_multi_remove_handle(multi, t->curl);
t->done = 1;
active_transfers--;
curl_mfprintf(stderr, "[t-%zu] ABORTED\n", t->idx);
}
}
}
else {
/* resume one paused transfer */
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
if(!t->done && t->paused) {
t->resumed = 1;
t->paused = 0;
curl_easy_pause(t->curl, CURLPAUSE_CONT);
curl_mfprintf(stderr, "[t-%zu] RESUMED\n", t->idx);
break;
}
}
}
while(active_transfers < max_parallel) {
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
if(!t->started) {
t->curl = curl_easy_init();
if(!t->curl ||
setup_hx_download(t->curl, url, t, http_version, host, share,
use_earlydata, fresh_connect)) {
curl_mfprintf(stderr, "[t-%zu] FAILED setup\n", i);
result = (CURLcode)1;
goto cleanup;
}
curl_multi_add_handle(multi, t->curl);
t->started = 1;
++active_transfers;
curl_mfprintf(stderr, "[t-%zu] STARTED\n", t->idx);
break;
}
}
/* all started */
if(i == transfer_count_d)
break;
}
} while(m);
} while(active_transfers); /* as long as we have transfers going */
cleanup:
curl_multi_cleanup(multi);
if(transfer_d) {
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
if(t->out) {
curlx_fclose(t->out);
t->out = NULL;
}
if(t->curl) {
curl_easy_cleanup(t->curl);
t->curl = NULL;
}
if(t->result)
result = t->result;
else /* on success we expect ssl to have been checked */
assert(t->checked_ssl);
}
free(transfer_d);
}
curl_share_cleanup(share);
curl_slist_free_all(host);
curl_global_cleanup();
optcleanup:
free(resolve);
return result;
}
+542
View File
@@ -0,0 +1,542 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static int verbose_u = 1;
struct transfer_u {
size_t idx;
CURL *curl;
const char *method;
char filename[128];
curl_mime *mime;
FILE *out;
curl_off_t send_total;
curl_off_t recv_size;
curl_off_t send_size;
curl_off_t fail_at;
curl_off_t pause_at;
curl_off_t abort_at;
int started;
int paused;
int resumed;
int done;
};
static size_t transfer_count_u = 1;
static struct transfer_u *transfer_u;
static int forbid_reuse_u = 0;
static struct transfer_u *get_transfer_for_easy_u(CURL *curl)
{
size_t i;
for(i = 0; i < transfer_count_u; ++i) {
if(curl == transfer_u[i].curl)
return &transfer_u[i];
}
return NULL;
}
static size_t my_write_u_cb(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct transfer_u *t = userdata;
size_t blen = (nitems * buflen);
size_t nwritten;
curl_mfprintf(stderr, "[t-%zu] RECV %zu bytes, "
"total=%" CURL_FORMAT_CURL_OFF_T ", "
"pause_at=%" CURL_FORMAT_CURL_OFF_T "\n",
t->idx, blen, t->recv_size, t->pause_at);
if(!t->out) {
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data",
t->idx);
t->out = curlx_fopen(t->filename, "wb");
if(!t->out)
return 0;
}
nwritten = fwrite(buf, nitems, buflen, t->out);
if(nwritten < blen) {
curl_mfprintf(stderr, "[t-%zu] write failure\n", t->idx);
return 0;
}
t->recv_size += (curl_off_t)nwritten;
return (size_t)nwritten;
}
static size_t my_read_cb(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct transfer_u *t = userdata;
size_t blen = (nitems * buflen);
size_t nread;
if(t->send_total <= t->send_size)
nread = 0;
else if((t->send_total - t->send_size) < (curl_off_t)blen)
nread = (size_t)(t->send_total - t->send_size);
else
nread = blen;
curl_mfprintf(stderr, "[t-%zu] SEND %zu bytes, "
"total=%" CURL_FORMAT_CURL_OFF_T ", "
"pause_at=%" CURL_FORMAT_CURL_OFF_T "\n",
t->idx, nread, t->send_total, t->pause_at);
if(!t->resumed &&
t->send_size < t->pause_at &&
((t->send_size + (curl_off_t)blen) >= t->pause_at)) {
curl_mfprintf(stderr, "[t-%zu] PAUSE\n", t->idx);
t->paused = 1;
return CURL_READFUNC_PAUSE;
}
memset(buf, 'x', nread);
t->send_size += (curl_off_t)nread;
if(t->fail_at > 0 && t->send_size >= t->fail_at) {
curl_mfprintf(stderr, "[t-%zu] ABORT by read callback at "
"%" CURL_FORMAT_CURL_OFF_T " bytes\n", t->idx, t->send_size);
return CURL_READFUNC_ABORT;
}
return (size_t)nread;
}
static int my_progress_u_cb(void *userdata,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
struct transfer_u *t = userdata;
(void)ultotal;
(void)dlnow;
(void)dltotal;
if(t->abort_at > 0 && ulnow >= t->abort_at) {
curl_mfprintf(stderr, "[t-%zu] ABORT by progress_cb at "
"%" CURL_FORMAT_CURL_OFF_T " bytes sent\n", t->idx, ulnow);
return 1;
}
return 0;
}
static int setup_hx_upload(CURL *curl, const char *url, struct transfer_u *t,
long http_version, struct curl_slist *host,
CURLSH *share, int use_earlydata,
int announce_length)
{
curl_easy_setopt(curl, CURLOPT_SHARE, share);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, (long)(128 * 1024));
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_OBEYCODE);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_u_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, t);
if(use_earlydata)
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_EARLYDATA);
if(!strcmp("MIME", t->method)) {
curl_mimepart *part;
t->mime = curl_mime_init(curl);
part = curl_mime_addpart(t->mime);
curl_mime_name(part, "file");
curl_mime_data_cb(part, -1, my_read_cb, NULL, NULL, t);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, t->mime);
}
else {
if(!t->method || !strcmp("PUT", t->method))
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
else if(!strcmp("POST", t->method))
curl_easy_setopt(curl, CURLOPT_POST, 1L);
else {
curl_mfprintf(stderr, "unsupported method '%s'\n", t->method);
return 1;
}
curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_cb);
curl_easy_setopt(curl, CURLOPT_READDATA, t);
if(announce_length)
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, t->send_total);
}
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, my_progress_u_cb);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, t);
if(forbid_reuse_u)
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
if(host)
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
/* please be verbose */
if(verbose_u) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);
}
/* wait for pipe connection to confirm */
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
return 0; /* all is good */
}
static void usage_hx_upload(const char *msg)
{
if(msg)
curl_mfprintf(stderr, "%s\n", msg);
curl_mfprintf(stderr,
"usage: [options] url\n"
" upload to a url with following options:\n"
" -a abort paused transfer\n"
" -e use TLS earlydata\n"
" -m number max parallel uploads\n"
" -n number total uploads\n"
" -A number abort transfer after `number` request body bytes\n"
" -F number fail reading request body after `number` of bytes\n"
" -P number pause transfer after `number` request body bytes\n"
" -r <host>:<port>:<addr> resolve information\n"
" -S number size to upload\n"
" -V http_version (http/1.1, h2, h3) http version to use\n"
);
}
/*
* Download a file over HTTP/2, take care of server push.
*/
static CURLcode test_cli_hx_upload(const char *URL)
{
CURLM *multi;
CURLSH *share;
const char *url;
const char *method = "PUT";
size_t i, n, max_parallel = 1;
size_t active_transfers;
size_t pause_offset = 0;
size_t abort_offset = 0;
size_t fail_offset = 0;
size_t send_total = (128 * 1024);
int abort_paused = 0;
int reuse_easy = 0;
int use_earlydata = 0;
int announce_length = 0;
struct transfer_u *t = NULL;
long http_version = CURL_HTTP_VERSION_2_0;
struct curl_slist *host = NULL;
const char *resolve = NULL;
int ch;
CURLcode result = CURLE_OK;
(void)URL;
while((ch = cgetopt(test_argc, test_argv, "aefhlm:n:A:F:M:P:r:RS:V:"))
!= -1) {
switch(ch) {
case 'h':
usage_hx_upload(NULL);
return (CURLcode)2;
case 'a':
abort_paused = 1;
break;
case 'e':
use_earlydata = 1;
break;
case 'f':
forbid_reuse_u = 1;
break;
case 'l':
announce_length = 1;
break;
case 'm':
max_parallel = (size_t)atol(coptarg);
break;
case 'n':
transfer_count_u = (size_t)atol(coptarg);
break;
case 'A':
abort_offset = (size_t)atol(coptarg);
break;
case 'F':
fail_offset = (size_t)atol(coptarg);
break;
case 'M':
method = coptarg;
break;
case 'P':
pause_offset = (size_t)atol(coptarg);
break;
case 'r':
resolve = coptarg;
break;
case 'R':
reuse_easy = 1;
break;
case 'S':
send_total = (size_t)atol(coptarg);
break;
case 'V': {
if(!strcmp("http/1.1", coptarg))
http_version = CURL_HTTP_VERSION_1_1;
else if(!strcmp("h2", coptarg))
http_version = CURL_HTTP_VERSION_2_0;
else if(!strcmp("h3", coptarg))
http_version = CURL_HTTP_VERSION_3ONLY;
else {
usage_hx_upload("invalid http version");
return (CURLcode)1;
}
break;
}
default:
usage_hx_upload("invalid option");
return (CURLcode)1;
}
}
test_argc -= coptind;
test_argv += coptind;
if(max_parallel > 1 && reuse_easy) {
usage_hx_upload("cannot mix -R and -P");
return (CURLcode)2;
}
if(test_argc != 1) {
usage_hx_upload("not enough arguments");
return (CURLcode)2;
}
url = test_argv[0];
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
curl_global_trace("ids,time,http/2,http/3");
if(resolve)
host = curl_slist_append(NULL, resolve);
share = curl_share_init();
if(!share) {
curl_mfprintf(stderr, "error allocating share\n");
result = (CURLcode)1;
goto cleanup;
}
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS);
transfer_u = calloc(transfer_count_u, sizeof(*transfer_u));
if(!transfer_u) {
curl_mfprintf(stderr, "error allocating transfer structs\n");
result = (CURLcode)1;
goto cleanup;
}
active_transfers = 0;
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
t->idx = i;
t->method = method;
t->send_total = (curl_off_t)send_total;
t->abort_at = (curl_off_t)abort_offset;
t->fail_at = (curl_off_t)fail_offset;
t->pause_at = (curl_off_t)pause_offset;
}
if(reuse_easy) {
CURL *curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "failed to init easy handle\n");
result = (CURLcode)1;
goto cleanup;
}
for(i = 0; i < transfer_count_u; ++i) {
CURLcode rc;
t = &transfer_u[i];
t->curl = curl;
if(setup_hx_upload(t->curl, url, t, http_version, host, share,
use_earlydata, announce_length)) {
curl_mfprintf(stderr, "[t-%zu] FAILED setup\n", i);
result = (CURLcode)1;
goto cleanup;
}
curl_mfprintf(stderr, "[t-%zu] STARTING\n", t->idx);
rc = curl_easy_perform(curl);
curl_mfprintf(stderr, "[t-%zu] DONE -> %d\n", t->idx, rc);
t->curl = NULL;
curl_easy_reset(curl);
}
curl_easy_cleanup(curl);
}
else {
multi = curl_multi_init();
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
n = (max_parallel < transfer_count_u) ? max_parallel : transfer_count_u;
for(i = 0; i < n; ++i) {
t = &transfer_u[i];
t->curl = curl_easy_init();
if(!t->curl || setup_hx_upload(t->curl, url, t, http_version, host,
share, use_earlydata, announce_length)) {
curl_mfprintf(stderr, "[t-%zu] FAILED setup\n", i);
result = (CURLcode)1;
goto cleanup;
}
curl_multi_add_handle(multi, t->curl);
t->started = 1;
++active_transfers;
curl_mfprintf(stderr, "[t-%zu] STARTED\n", t->idx);
}
do {
int still_running; /* keep number of running handles */
CURLMcode mc = curl_multi_perform(multi, &still_running);
struct CURLMsg *m;
if(still_running) {
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
}
if(mc)
break;
do {
int msgq = 0;
m = curl_multi_info_read(multi, &msgq);
if(m && (m->msg == CURLMSG_DONE)) {
CURL *easy = m->easy_handle;
--active_transfers;
curl_multi_remove_handle(multi, easy);
t = get_transfer_for_easy_u(easy);
if(t) {
long res_status;
curl_easy_getinfo(easy, CURLINFO_RESPONSE_CODE, &res_status);
t->done = 1;
curl_mfprintf(stderr, "[t-%zu] FINISHED, "
"result=%d, response=%ld\n",
t->idx, m->data.result, res_status);
if(use_earlydata) {
curl_off_t sent;
curl_easy_getinfo(easy, CURLINFO_EARLYDATA_SENT_T, &sent);
curl_mfprintf(stderr, "[t-%zu] EarlyData: "
"%" CURL_FORMAT_CURL_OFF_T "\n", t->idx, sent);
}
}
else {
curl_easy_cleanup(easy);
curl_mfprintf(stderr, "unknown FINISHED???\n");
}
}
/* nothing happening, maintenance */
if(abort_paused) {
/* abort paused transfers */
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
if(!t->done && t->paused && t->curl) {
curl_multi_remove_handle(multi, t->curl);
t->done = 1;
active_transfers--;
curl_mfprintf(stderr, "[t-%zu] ABORTED\n", t->idx);
}
}
}
else {
/* resume one paused transfer */
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
if(!t->done && t->paused) {
t->resumed = 1;
t->paused = 0;
curl_easy_pause(t->curl, CURLPAUSE_CONT);
curl_mfprintf(stderr, "[t-%zu] RESUMED\n", t->idx);
break;
}
}
}
while(active_transfers < max_parallel) {
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
if(!t->started) {
t->curl = curl_easy_init();
if(!t->curl || setup_hx_upload(t->curl, url, t, http_version,
host, share, use_earlydata,
announce_length)) {
curl_mfprintf(stderr, "[t-%zu] FAILED setup\n", i);
result = (CURLcode)1;
goto cleanup;
}
curl_multi_add_handle(multi, t->curl);
t->started = 1;
++active_transfers;
curl_mfprintf(stderr, "[t-%zu] STARTED\n", t->idx);
break;
}
}
/* all started */
if(i == transfer_count_u)
break;
}
} while(m);
} while(active_transfers); /* as long as we have transfers going */
curl_mfprintf(stderr, "all transfers done, cleanup multi\n");
curl_multi_cleanup(multi);
}
cleanup:
if(transfer_u) {
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
if(t->out) {
curlx_fclose(t->out);
t->out = NULL;
}
if(t->curl) {
curl_easy_cleanup(t->curl);
t->curl = NULL;
}
if(t->mime) {
curl_mime_free(t->mime);
}
}
free(transfer_u);
}
curl_share_cleanup(share);
curl_slist_free_all(host);
curl_global_cleanup();
return result;
}
@@ -0,0 +1,269 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static int tse_found_tls_session = FALSE;
static size_t write_tse_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
{
CURL *curl = opaque;
(void)ptr;
if(!tse_found_tls_session) {
struct curl_tlssessioninfo *tlssession;
CURLcode rc;
rc = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tlssession);
if(rc) {
curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
"failed: %s\n", curl_easy_strerror(rc));
return rc;
}
if(tlssession->backend == CURLSSLBACKEND_NONE) {
curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
"gave no backend\n");
return CURLE_FAILED_INIT;
}
if(!tlssession->internals) {
curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
"missing\n");
return CURLE_FAILED_INIT;
}
tse_found_tls_session = TRUE;
}
return size * nmemb;
}
static CURL *tse_add_transfer(CURLM *multi, CURLSH *share,
struct curl_slist *resolve,
const char *url, long http_version)
{
CURL *curl;
CURLMcode mc;
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init failed\n");
return NULL;
}
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_SHARE, share);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_tse_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
if(resolve)
curl_easy_setopt(curl, CURLOPT_RESOLVE, resolve);
mc = curl_multi_add_handle(multi, curl);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",
curl_multi_strerror(mc));
curl_easy_cleanup(curl);
return NULL;
}
return curl;
}
static CURLcode test_cli_tls_session_reuse(const char *URL)
{
CURLM *multi = NULL;
CURLMcode mc;
int running_handles = 0, numfds;
CURLMsg *msg;
CURLSH *share = NULL;
CURLU *cu;
struct curl_slist *resolve = NULL;
char resolve_buf[1024];
int msgs_in_queue;
int add_more, waits, ongoing = 0;
char *host = NULL, *port = NULL;
long http_version = CURL_HTTP_VERSION_1_1;
CURLcode result = (CURLcode)1;
if(!URL || !libtest_arg2) {
curl_mfprintf(stderr, "need args: URL proto\n");
return (CURLcode)2;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
if(!strcmp("h2", libtest_arg2))
http_version = CURL_HTTP_VERSION_2;
else if(!strcmp("h3", libtest_arg2))
http_version = CURL_HTTP_VERSION_3ONLY;
cu = curl_url();
if(!cu) {
curl_mfprintf(stderr, "out of memory\n");
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_set(cu, CURLUPART_URL, URL, 0)) {
curl_mfprintf(stderr, "not a URL: '%s'\n", URL);
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
curl_mfprintf(stderr, "could not get host of '%s'\n", URL);
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
curl_mfprintf(stderr, "could not get port of '%s'\n", URL);
goto cleanup;
}
curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
host, port);
resolve = curl_slist_append(resolve, resolve_buf);
multi = curl_multi_init();
if(!multi) {
curl_mfprintf(stderr, "curl_multi_init failed\n");
goto cleanup;
}
share = curl_share_init();
if(!share) {
curl_mfprintf(stderr, "curl_share_init failed\n");
goto cleanup;
}
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
if(!tse_add_transfer(multi, share, resolve, URL, http_version))
goto cleanup;
++ongoing;
add_more = 6;
waits = 3;
do {
mc = curl_multi_perform(multi, &running_handles);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_perform: %s\n",
curl_multi_strerror(mc));
goto cleanup;
}
if(running_handles) {
mc = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_poll: %s\n",
curl_multi_strerror(mc));
goto cleanup;
}
}
if(waits) {
--waits;
}
else {
while(add_more) {
if(!tse_add_transfer(multi, share, resolve, URL, http_version))
goto cleanup;
++ongoing;
--add_more;
}
}
/* Check for finished handles and remove. */
/* !checksrc! disable EQUALSNULL 1 */
while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {
if(msg->msg == CURLMSG_DONE) {
long status = 0;
curl_off_t xfer_id;
curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id);
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status);
if(msg->data.result == CURLE_SEND_ERROR ||
msg->data.result == CURLE_RECV_ERROR) {
/* We get these if the server had a GOAWAY in transit on
* reusing a connection */
}
else if(msg->data.result) {
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
": failed with %d\n", xfer_id, msg->data.result);
goto cleanup;
}
else if(status != 200) {
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
": wrong http status %ld (expected 200)\n", xfer_id,
status);
goto cleanup;
}
curl_multi_remove_handle(multi, msg->easy_handle);
curl_easy_cleanup(msg->easy_handle);
--ongoing;
curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T" retiring "
"(%d now running)\n", xfer_id, running_handles);
}
}
curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
running_handles, add_more);
} while(ongoing || add_more);
if(!tse_found_tls_session) {
curl_mfprintf(stderr, "CURLINFO_TLS_SSL_PTR not found during run\n");
result = CURLE_FAILED_INIT;
goto cleanup;
}
curl_mfprintf(stderr, "exiting\n");
result = CURLE_OK;
cleanup:
if(multi) {
CURL **list = curl_multi_get_handles(multi);
if(list) {
int i;
for(i = 0; list[i]; i++) {
curl_multi_remove_handle(multi, list[i]);
curl_easy_cleanup(list[i]);
}
curl_free(list);
}
curl_multi_cleanup(multi);
}
curl_share_cleanup(share);
curl_slist_free_all(resolve);
curl_free(host);
curl_free(port);
if(cu)
curl_url_cleanup(cu);
curl_global_cleanup();
return result;
}
+214
View File
@@ -0,0 +1,214 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* This is based on the PoC client of issue #11769
*/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static size_t total_read = 0;
static size_t read_callback(char *ptr, size_t size, size_t nmemb,
void *userdata)
{
static const size_t PAUSE_READ_AFTER = 1;
(void)size;
(void)nmemb;
(void)userdata;
if(total_read >= PAUSE_READ_AFTER) {
curl_mfprintf(stderr, "read_callback, return PAUSE\n");
return CURL_READFUNC_PAUSE;
}
else {
ptr[0] = '\n';
++total_read;
curl_mfprintf(stderr, "read_callback, return 1 byte\n");
return 1;
}
}
static int progress_callback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow)
{
(void)dltotal;
(void)dlnow;
(void)ultotal;
(void)ulnow;
(void)clientp;
#if 0
/* Used to unpause on progress, but keeping for now. */
{
CURL *curl = (CURL *)clientp;
curl_easy_pause(curl, CURLPAUSE_CONT);
/* curl_easy_pause(curl, CURLPAUSE_RECV_CONT); */
}
#endif
return 0;
}
static void usage_upload_pausing(const char *msg)
{
if(msg)
curl_mfprintf(stderr, "%s\n", msg);
curl_mfprintf(stderr,
"usage: [options] url\n"
" upload and pause, options:\n"
" -V http_version (http/1.1, h2, h3) http version to use\n"
);
}
static CURLcode test_cli_upload_pausing(const char *URL)
{
CURL *curl = NULL;
CURLcode result = CURLE_OK;
CURLU *cu;
struct curl_slist *resolve = NULL;
char resolve_buf[1024];
const char *url;
char *host = NULL, *port = NULL;
long http_version = CURL_HTTP_VERSION_1_1;
int ch;
(void)URL;
while((ch = cgetopt(test_argc, test_argv, "V:")) != -1) {
switch(ch) {
case 'V': {
if(!strcmp("http/1.1", coptarg))
http_version = CURL_HTTP_VERSION_1_1;
else if(!strcmp("h2", coptarg))
http_version = CURL_HTTP_VERSION_2_0;
else if(!strcmp("h3", coptarg))
http_version = CURL_HTTP_VERSION_3ONLY;
else {
usage_upload_pausing("invalid http version");
return (CURLcode)1;
}
break;
}
default:
usage_upload_pausing("invalid option");
return (CURLcode)1;
}
}
test_argc -= coptind;
test_argv += coptind;
if(test_argc != 1) {
usage_upload_pausing("not enough arguments");
return (CURLcode)2;
}
url = test_argv[0];
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
curl_global_trace("ids,time");
cu = curl_url();
if(!cu) {
curl_mfprintf(stderr, "out of memory\n");
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
curl_mfprintf(stderr, "not a URL: '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
curl_mfprintf(stderr, "could not get host of '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
curl_mfprintf(stderr, "could not get port of '%s'\n", url);
result = (CURLcode)1;
goto cleanup;
}
memset(&resolve, 0, sizeof(resolve));
curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
host, port);
resolve = curl_slist_append(resolve, resolve_buf);
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "out of memory\n");
result = (CURLcode)1;
goto cleanup;
}
/* We want to use our own read function. */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* It will help us to continue the read function. */
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, curl);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
/* It will help us to ensure that keepalive does not help. */
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPCNT, 1L);
/* Enable uploading. */
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
if(curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L) != CURLE_OK ||
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb) != CURLE_OK ||
curl_easy_setopt(curl, CURLOPT_RESOLVE, resolve) != CURLE_OK) {
curl_mfprintf(stderr, "something unexpected went wrong - bailing out!\n");
result = (CURLcode)2;
goto cleanup;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
result = curl_easy_perform(curl);
cleanup:
if(curl)
curl_easy_cleanup(curl);
curl_slist_free_all(resolve);
curl_free(host);
curl_free(port);
if(cu)
curl_url_cleanup(cu);
curl_global_cleanup();
return result;
}
+483
View File
@@ -0,0 +1,483 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
#ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode
test_ws_data_m2_check_recv(const struct curl_ws_frame *frame,
size_t r_offset, size_t nread,
size_t exp_len)
{
if(!frame)
return CURLE_OK;
if(frame->flags & CURLWS_CLOSE) {
curl_mfprintf(stderr, "recv_data: unexpected CLOSE frame from server, "
"got %zu bytes, offset=%zu, rflags %x\n",
nread, r_offset, frame->flags);
return CURLE_RECV_ERROR;
}
if(!r_offset && !(frame->flags & CURLWS_BINARY)) {
curl_mfprintf(stderr, "recv_data: wrong frame, got %zu bytes, offset=%zu, "
"rflags %x\n",
nread, r_offset, frame->flags);
return CURLE_RECV_ERROR;
}
if(frame->offset != (curl_off_t)r_offset) {
curl_mfprintf(stderr, "recv_data: frame offset, expected %zu, "
"got %" CURL_FORMAT_CURL_OFF_T "\n",
r_offset, frame->offset);
return CURLE_RECV_ERROR;
}
if(frame->bytesleft != (curl_off_t)(exp_len - r_offset - nread)) {
curl_mfprintf(stderr, "recv_data: frame bytesleft, "
"expected %" CURL_FORMAT_CURL_OFF_T ", "
"got %" CURL_FORMAT_CURL_OFF_T "\n",
(curl_off_t)(exp_len - r_offset - nread), frame->bytesleft);
return CURLE_RECV_ERROR;
}
if(r_offset + nread > exp_len) {
curl_mfprintf(stderr, "recv_data: data length, expected %zu, now at %zu\n",
exp_len, r_offset + nread);
return CURLE_RECV_ERROR;
}
return CURLE_OK;
}
/* WebSocket Mode 2: CONNECT_ONLY 2, curl_ws_send()/curl_ws_recv() */
static CURLcode test_ws_data_m2_echo(const char *url,
size_t count,
size_t plen_min,
size_t plen_max)
{
CURL *curl = NULL;
CURLcode r = CURLE_OK;
const struct curl_ws_frame *frame;
size_t len;
char *send_buf = NULL, *recv_buf = NULL;
size_t i, scount = count, rcount = count;
int rblock, sblock;
send_buf = calloc(1, plen_max + 1);
recv_buf = calloc(1, plen_max + 1);
if(!send_buf || !recv_buf) {
r = CURLE_OUT_OF_MEMORY;
goto out;
}
for(i = 0; i < plen_max; ++i) {
send_buf[i] = (char)('0' + ((int)i % 10));
}
curl = curl_easy_init();
if(!curl) {
r = CURLE_OUT_OF_MEMORY;
goto out;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
/* use the callback style */
curl_easy_setopt(curl, CURLOPT_USERAGENT, "ws-data");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
r = curl_easy_perform(curl);
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", r);
if(r != CURLE_OK)
goto out;
for(len = plen_min; len <= plen_max; ++len) {
size_t nwritten, nread, slen = len, rlen = len;
char *sbuf = send_buf, *rbuf = recv_buf;
memset(recv_buf, 0, plen_max);
while(slen || rlen || scount || rcount) {
sblock = rblock = 1;
if(slen) {
r = curl_ws_send(curl, sbuf, slen, &nwritten, 0, CURLWS_BINARY);
sblock = (r == CURLE_AGAIN);
if(!r || (r == CURLE_AGAIN)) {
curl_mfprintf(stderr, "curl_ws_send(len=%zu) -> %d, "
"%zu (%" CURL_FORMAT_CURL_OFF_T "/%zu)\n",
slen, r, nwritten, (curl_off_t)(len - slen), len);
sbuf += nwritten;
slen -= nwritten;
}
else
goto out;
}
if(!slen && scount) { /* go again? */
scount--;
sbuf = send_buf;
slen = len;
}
if(rlen) {
size_t max_recv = (64 * 1024);
r = curl_ws_recv(curl, rbuf, (rlen > max_recv) ? max_recv : rlen,
&nread, &frame);
if(!r || (r == CURLE_AGAIN)) {
rblock = (r == CURLE_AGAIN);
curl_mfprintf(stderr, "curl_ws_recv(len=%zu) -> %d, %zu (%ld/%zu) "
"\n", rlen, r, nread, (long)(len - rlen), len);
if(!r) {
r = test_ws_data_m2_check_recv(frame, len - rlen, nread, len);
if(r)
goto out;
}
rbuf += nread;
rlen -= nread;
}
else
goto out;
}
if(!rlen && rcount) { /* go again? */
rcount--;
rbuf = recv_buf;
rlen = len;
}
if(rblock && sblock) {
curl_mfprintf(stderr, "EAGAIN, sleep, try again\n");
curlx_wait_ms(1);
}
}
if(memcmp(send_buf, recv_buf, len)) {
curl_mfprintf(stderr, "recv_data: data differs\n");
debug_dump("", "expected:", stderr,
(const unsigned char *)send_buf, len, FALSE);
debug_dump("", "received:", stderr,
(const unsigned char *)recv_buf, len, FALSE);
r = CURLE_RECV_ERROR;
goto out;
}
}
out:
if(curl) {
if(!r)
ws_close(curl);
curl_easy_cleanup(curl);
}
free(send_buf);
free(recv_buf);
return r;
}
struct test_ws_m1_ctx {
CURL *curl;
char *send_buf;
char *recv_buf;
size_t send_len, nsent;
size_t recv_len, nrcvd;
int nframes;
int read_calls;
int write_calls;
int frames_read;
int frames_written;
BIT(frame_reading);
};
static size_t test_ws_data_m1_read(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct test_ws_m1_ctx *ctx = userdata;
size_t len = nitems * buflen;
size_t left = ctx->send_len - ctx->nsent;
ctx->read_calls++;
if(ctx->frames_read >= ctx->nframes)
goto out;
if(!ctx->frame_reading) {
curl_ws_start_frame(ctx->curl, CURLWS_BINARY, ctx->send_len);
ctx->frame_reading = TRUE;
}
if(ctx->frame_reading) {
bool complete;
if(left > len)
left = len;
memcpy(buf, ctx->send_buf + ctx->nsent, left);
ctx->nsent += left;
complete = (ctx->send_len == ctx->nsent);
curl_mfprintf(stderr, "m1_read(len=%zu, call #%d, frame #%d%s) -> %zu\n",
len, ctx->read_calls, ctx->frames_read,
complete ? " complete" : "", left);
if(complete) {
++ctx->frames_read;
ctx->frame_reading = FALSE;
ctx->nsent = 0;
}
return left;
}
out:
curl_mfprintf(stderr, "m1_read(len=%zu, call #%d) -> EOS\n",
len, ctx->read_calls);
return 0;
}
static size_t test_ws_data_m1_write(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct test_ws_m1_ctx *ctx = userdata;
size_t len = nitems * buflen;
bool complete;
ctx->write_calls++;
if(len > (ctx->recv_len - ctx->nrcvd)) {
curl_mfprintf(stderr, "m1_write(len=%zu, call #%d) -> ERROR\n",
len, ctx->write_calls);
return CURL_WRITEFUNC_ERROR;
}
memcpy(ctx->recv_buf + ctx->nrcvd, buf, len);
ctx->nrcvd += len;
complete = (ctx->recv_len == ctx->nrcvd);
if(memcmp(ctx->send_buf, ctx->recv_buf, ctx->nrcvd)) {
curl_mfprintf(stderr, "m1_write(len=%zu, call #%d, frame #%d) -> "
"data differs\n",
len, ctx->write_calls, ctx->frames_written);
debug_dump("", "expected:", stderr,
(unsigned char *)ctx->send_buf, ctx->nrcvd, 0);
debug_dump("", "received:", stderr,
(unsigned char *)ctx->recv_buf, ctx->nrcvd, 0);
return CURL_WRITEFUNC_ERROR;
}
curl_mfprintf(stderr, "m1_write(len=%zu, call #%d, frame #%d%s) -> %zu\n",
len, ctx->write_calls, ctx->frames_written,
complete ? " complete" : "", len);
if(complete) {
++ctx->frames_written;
ctx->nrcvd = 0;
}
return len;
}
/* WebSocket Mode 1: multi handle, READ/WRITEFUNCTION use */
static CURLcode test_ws_data_m1_echo(const char *url,
size_t plen_min,
size_t plen_max)
{
CURLM *multi = NULL;
CURLcode r = CURLE_OK;
struct test_ws_m1_ctx m1_ctx;
size_t i, len;
curl_mfprintf(stderr, "test_ws_data_m1_echo(min=%zu, max=%zu)\n",
plen_min, plen_max);
memset(&m1_ctx, 0, sizeof(m1_ctx));
m1_ctx.send_buf = calloc(1, plen_max + 1);
m1_ctx.recv_buf = calloc(1, plen_max + 1);
if(!m1_ctx.send_buf || !m1_ctx.recv_buf) {
r = CURLE_OUT_OF_MEMORY;
goto out;
}
for(i = 0; i < plen_max; ++i) {
m1_ctx.send_buf[i] = (char)('0' + ((int)i % 10));
}
multi = curl_multi_init();
if(!multi) {
r = CURLE_OUT_OF_MEMORY;
goto out;
}
m1_ctx.curl = curl_easy_init();
if(!m1_ctx.curl) {
r = CURLE_OUT_OF_MEMORY;
goto out;
}
for(len = plen_min; len <= plen_max; ++len) {
/* init what we want to send and expect to receive */
curl_mfprintf(stderr, "m1_echo, iter len=%zu\n", len);
m1_ctx.send_len = len;
m1_ctx.nsent = 0;
m1_ctx.recv_len = len;
m1_ctx.nrcvd = 0;
m1_ctx.nframes = 2;
m1_ctx.read_calls = 0;
m1_ctx.write_calls = 0;
m1_ctx.frames_read = 0;
m1_ctx.frames_written = 0;
memset(m1_ctx.recv_buf, 0, plen_max);
curl_easy_pause(m1_ctx.curl, CURLPAUSE_CONT);
curl_easy_reset(m1_ctx.curl);
curl_easy_setopt(m1_ctx.curl, CURLOPT_URL, url);
/* use the callback style */
curl_easy_setopt(m1_ctx.curl, CURLOPT_USERAGENT, "ws-data");
curl_easy_setopt(m1_ctx.curl, CURLOPT_VERBOSE, 1L);
/* we want to send */
curl_easy_setopt(m1_ctx.curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(m1_ctx.curl, CURLOPT_READFUNCTION, test_ws_data_m1_read);
curl_easy_setopt(m1_ctx.curl, CURLOPT_READDATA, &m1_ctx);
curl_easy_setopt(m1_ctx.curl, CURLOPT_WRITEFUNCTION,
test_ws_data_m1_write);
curl_easy_setopt(m1_ctx.curl, CURLOPT_WRITEDATA, &m1_ctx);
curl_multi_add_handle(multi, m1_ctx.curl);
while(1) {
int still_running; /* keep number of running handles */
CURLMcode mc = curl_multi_perform(multi, &still_running);
if(!still_running || (m1_ctx.frames_written >= m1_ctx.nframes)) {
/* got the full echo back or failed */
break;
}
if(!mc && still_running) {
mc = curl_multi_poll(multi, NULL, 0, 1, NULL);
}
if(mc) {
r = CURLE_RECV_ERROR;
goto out;
}
}
curl_multi_remove_handle(multi, m1_ctx.curl);
/* check results */
if(m1_ctx.frames_read < m1_ctx.nframes) {
curl_mfprintf(stderr, "m1_echo, sent only %d/%d frames\n",
m1_ctx.frames_read, m1_ctx.nframes);
r = CURLE_SEND_ERROR;
goto out;
}
if(m1_ctx.frames_written < m1_ctx.frames_read) {
curl_mfprintf(stderr, "m1_echo, received only %d/%d frames\n",
m1_ctx.frames_written, m1_ctx.frames_read);
r = CURLE_RECV_ERROR;
goto out;
}
}
out:
if(multi)
curl_multi_cleanup(multi);
if(m1_ctx.curl) {
curl_easy_cleanup(m1_ctx.curl);
}
free(m1_ctx.send_buf);
free(m1_ctx.recv_buf);
return r;
}
static void test_ws_data_usage(const char *msg)
{
if(msg)
curl_mfprintf(stderr, "%s\n", msg);
curl_mfprintf(stderr,
"usage: [options] url\n"
" -m number minimum frame size\n"
" -M number maximum frame size\n"
);
}
#endif
static CURLcode test_cli_ws_data(const char *URL)
{
#ifndef CURL_DISABLE_WEBSOCKETS
CURLcode result = CURLE_OK;
const char *url;
size_t plen_min = 0, plen_max = 0, count = 1;
int ch, model = 2;
(void)URL;
while((ch = cgetopt(test_argc, test_argv, "12c:hm:M:")) != -1) {
switch(ch) {
case '1':
model = 1;
break;
case '2':
model = 2;
break;
case 'h':
test_ws_data_usage(NULL);
return CURLE_BAD_FUNCTION_ARGUMENT;
case 'c':
count = (size_t)atol(coptarg);
break;
case 'm':
plen_min = (size_t)atol(coptarg);
break;
case 'M':
plen_max = (size_t)atol(coptarg);
break;
default:
test_ws_data_usage("invalid option");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
}
test_argc -= coptind;
test_argv += coptind;
if(!plen_max)
plen_max = plen_min;
if(plen_max < plen_min) {
curl_mfprintf(stderr, "maxlen must be >= minlen, got %zu-%zu\n",
plen_min, plen_max);
return CURLE_BAD_FUNCTION_ARGUMENT;
}
if(test_argc != 1) {
test_ws_data_usage(NULL);
return CURLE_BAD_FUNCTION_ARGUMENT;
}
url = test_argv[0];
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
if(model == 1)
result = test_ws_data_m1_echo(url, plen_min, plen_max);
else
result = test_ws_data_m2_echo(url, count, plen_min, plen_max);
curl_global_cleanup();
return result;
#else /* !CURL_DISABLE_WEBSOCKETS */
(void)URL;
curl_mfprintf(stderr, "WebSockets not enabled in libcurl\n");
return (CURLcode)1;
#endif /* CURL_DISABLE_WEBSOCKETS */
}
+97
View File
@@ -0,0 +1,97 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
#ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode pingpong(CURL *curl, const char *payload)
{
CURLcode res;
int i;
res = ws_send_ping(curl, payload);
if(res)
return res;
for(i = 0; i < 10; ++i) {
curl_mfprintf(stderr, "Receive pong\n");
res = ws_recv_pong(curl, payload);
if(res == CURLE_AGAIN) {
curlx_wait_ms(100);
continue;
}
ws_close(curl);
return res;
}
ws_close(curl);
return CURLE_RECV_ERROR;
}
#endif
static CURLcode test_cli_ws_pingpong(const char *URL)
{
#ifndef CURL_DISABLE_WEBSOCKETS
CURL *curl;
CURLcode result = CURLE_OK;
const char *payload;
if(!URL || !libtest_arg2) {
curl_mfprintf(stderr, "need args: URL payload\n");
return (CURLcode)2;
}
payload = libtest_arg2;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return (CURLcode)3;
}
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
/* use the callback style */
curl_easy_setopt(curl, CURLOPT_USERAGENT, "ws-pingpong");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
result = curl_easy_perform(curl);
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", result);
if(result == CURLE_OK)
result = pingpong(curl, payload);
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return result;
#else /* !CURL_DISABLE_WEBSOCKETS */
(void)URL;
curl_mfprintf(stderr, "WebSockets not enabled in libcurl\n");
return (CURLcode)1;
#endif /* CURL_DISABLE_WEBSOCKETS */
}
+291
View File
@@ -0,0 +1,291 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#ifdef HAVE_LOCALE_H
#include <locale.h> /* for setlocale() */
#endif
#include "memdebug.h"
int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
struct timeval *tv)
{
if(nfds < 0) {
SET_SOCKERRNO(SOCKEINVAL);
return -1;
}
#ifdef USE_WINSOCK
/*
* Winsock select() requires that at least one of the three fd_set
* pointers is not NULL and points to a non-empty fdset. IOW Winsock
* select() can not be used to sleep without a single fd_set.
*/
if(!nfds) {
Sleep((DWORD)curlx_tvtoms(tv));
return 0;
}
#endif
return select(nfds, rd, wr, exc, tv);
}
const char *libtest_arg2 = NULL;
const char *libtest_arg3 = NULL;
const char *libtest_arg4 = NULL;
int test_argc;
const char **test_argv;
int testnum;
struct curltime tv_test_start; /* for test timing */
int unitfail; /* for unittests */
int coptind;
const char *coptarg;
int cgetopt(int argc, const char * const argv[], const char *optstring)
{
static int optpos = 1;
int coptopt;
const char *arg;
if(coptind == 0) { /* Reset? */
coptind = !!argc;
optpos = 1;
}
arg = argv[coptind];
if(arg && strcmp(arg, "--") == 0) {
coptind++;
return -1;
}
else if(!arg || arg[0] != '-') {
return -1;
}
else {
const char *opt = strchr(optstring, arg[optpos]);
coptopt = arg[optpos];
if(!opt) {
if(!arg[++optpos]) {
coptind++;
optpos = 1;
}
return '?';
}
else if(opt[1] == ':') {
if(arg[optpos + 1]) {
coptarg = arg + optpos + 1;
coptind++;
optpos = 1;
return coptopt;
}
else if(argv[coptind + 1]) {
coptarg = argv[coptind + 1];
coptind += 2;
optpos = 1;
return coptopt;
}
else {
if(!arg[++optpos]) {
coptind++;
optpos = 1;
}
return *optstring == ':' ? ':' : '?';
}
}
else {
if(!arg[++optpos]) {
coptind++;
optpos = 1;
}
return coptopt;
}
}
}
#ifdef CURLDEBUG
static void memory_tracking_init(void)
{
char *env;
/* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
env = getenv("CURL_MEMDEBUG");
if(env) {
/* use the value as file name */
curl_dbg_memdebug(env);
}
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
env = getenv("CURL_MEMLIMIT");
if(env) {
long num = atol(env);
if(num > 0)
curl_dbg_memlimit(num);
}
}
#else
# define memory_tracking_init() Curl_nop_stmt
#endif
/* returns a hexdump in a static memory area */
char *hexdump(const unsigned char *buf, size_t len)
{
static char dump[200 * 3 + 1];
char *p = dump;
size_t i;
if(len > 200)
return NULL;
for(i = 0; i < len; i++, p += 3)
curl_msnprintf(p, 4, "%02x ", buf[i]);
return dump;
}
#ifndef CURL_DISABLE_WEBSOCKETS
CURLcode ws_send_ping(CURL *curl, const char *send_payload)
{
size_t sent;
CURLcode result = curl_ws_send(curl, send_payload, strlen(send_payload),
&sent, 0, CURLWS_PING);
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %zu\n",
result, sent);
return result;
}
CURLcode ws_recv_pong(CURL *curl, const char *expected_payload)
{
size_t rlen;
const struct curl_ws_frame *meta;
char buffer[256];
CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
if(result) {
curl_mfprintf(stderr, "ws: curl_ws_recv returned %u, received %zu\n",
result, rlen);
return result;
}
if(!(meta->flags & CURLWS_PONG)) {
curl_mfprintf(stderr, "recv_pong: wrong frame, got %zu bytes rflags %x\n",
rlen, meta->flags);
return CURLE_RECV_ERROR;
}
curl_mfprintf(stderr, "ws: got PONG back\n");
if(rlen == strlen(expected_payload) &&
!memcmp(expected_payload, buffer, rlen)) {
curl_mfprintf(stderr, "ws: got the same payload back\n");
return CURLE_OK; /* lib2304 returned 'result' here. Intentional? */
}
curl_mfprintf(stderr, "ws: did NOT get the same payload back\n");
return CURLE_RECV_ERROR;
}
/* just close the connection */
void ws_close(CURL *curl)
{
size_t sent;
CURLcode result = curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE);
curl_mfprintf(stderr, "ws: curl_ws_send returned %u, sent %zu\n",
result, sent);
}
#endif /* CURL_DISABLE_WEBSOCKETS */
int main(int argc, const char **argv)
{
const char *URL = "";
CURLcode result;
entry_func_t entry_func;
const char *entry_name;
char *env;
size_t tmp;
CURLX_SET_BINMODE(stdout);
memory_tracking_init();
#ifdef _WIN32
curlx_now_init();
#endif
/*
* Setup proper locale from environment. This is needed to enable locale-
* specific behavior by the C library in order to test for undesired side
* effects that could cause in libcurl.
*/
#ifdef HAVE_SETLOCALE
setlocale(LC_ALL, "");
#endif
test_argc = argc - 1;
test_argv = argv + 1;
if(argc < 2) {
curl_mfprintf(stderr, "Pass testname "
"(and URL as argument for numbered tests) please\n");
return 1;
}
entry_name = argv[1];
entry_func = NULL;
for(tmp = 0; s_entries[tmp].ptr; ++tmp) {
if(strcmp(entry_name, s_entries[tmp].name) == 0) {
entry_func = s_entries[tmp].ptr;
break;
}
}
if(!entry_func) {
curl_mfprintf(stderr, "Test '%s' not found.\n", entry_name);
return 1;
}
if(argc > 2) {
URL = argv[2];
curl_mfprintf(stderr, "URL: %s\n", URL);
}
if(argc > 3)
libtest_arg2 = argv[3];
if(argc > 4)
libtest_arg3 = argv[4];
if(argc > 5)
libtest_arg4 = argv[5];
env = getenv("CURL_TESTNUM");
if(env)
testnum = atoi(env);
else
testnum = 0;
result = entry_func(URL);
curl_mfprintf(stderr, "Test ended with result %d\n", result);
#ifdef _WIN32
/* flush buffers of all streams regardless of mode */
_flushall();
#endif
/* Regular program status codes are limited to 0..127 and 126 and 127 have
* special meanings by the shell, so limit a normal return code to 125 */
return (int)result <= 125 ? (int)result : 125;
}
+527
View File
@@ -0,0 +1,527 @@
#ifndef HEADER_LIBTEST_FIRST_H
#define HEADER_LIBTEST_FIRST_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_NO_OLDIES
#define CURL_DISABLE_DEPRECATION
/* Now include the curl_setup.h file from libcurl's private libdir (the source
version, but that might include "curl_config.h" from the build dir so we
need both of them in the include path), so that we get good in-depth
knowledge about the system we're building this on */
#include "curl_setup.h"
#include <curl/curl.h>
typedef CURLcode (*entry_func_t)(const char *);
struct entry_s {
const char *name;
entry_func_t ptr;
};
extern const struct entry_s s_entries[];
extern int unitfail; /* for unittests */
#include <curlx/curlx.h>
#ifdef HAVE_SYS_SELECT_H
/* since so many tests use select(), we can just as well include it here */
#include <sys/select.h>
#endif
/* GCC <4.6 does not support '#pragma GCC diagnostic push' and
does not support 'pragma GCC diagnostic' inside functions. */
#if (defined(__GNUC__) && \
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
#define CURL_GNUC_DIAG
#endif
#define test_setopt(A,B,C) \
if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) \
goto test_cleanup
#define test_multi_setopt(A,B,C) \
if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK) \
goto test_cleanup
extern const char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
extern const char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
extern const char *libtest_arg4; /* set by first.c to the argv[4] or NULL */
/* argc and argv as passed in to the main() function */
extern int test_argc;
extern const char **test_argv;
extern int testnum;
extern struct curltime tv_test_start; /* for test timing */
extern int coptind;
extern const char *coptarg;
int cgetopt(int argc, const char * const argv[], const char *optstring);
extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
struct timeval *tv);
extern char *hexdump(const unsigned char *buffer, size_t len);
#ifndef CURL_DISABLE_WEBSOCKETS
CURLcode ws_send_ping(CURL *curl, const char *send_payload);
CURLcode ws_recv_pong(CURL *curl, const char *expected_payload);
/* just close the connection */
void ws_close(CURL *curl);
#endif
/*
** TEST_ERR_* values must within the CURLcode range to not cause compiler
** errors.
** For portability reasons TEST_ERR_* values should be less than 127.
*/
#define TEST_ERR_MAJOR_BAD CURLE_OBSOLETE20
#define TEST_ERR_RUNS_FOREVER CURLE_OBSOLETE24
#define TEST_ERR_EASY_INIT CURLE_OBSOLETE29
#define TEST_ERR_MULTI CURLE_OBSOLETE32
#define TEST_ERR_NUM_HANDLES CURLE_OBSOLETE34
#define TEST_ERR_SELECT CURLE_OBSOLETE40
#define TEST_ERR_SUCCESS CURLE_OBSOLETE41
#define TEST_ERR_FAILURE CURLE_OBSOLETE44
#define TEST_ERR_USAGE CURLE_OBSOLETE46
#define TEST_ERR_FOPEN CURLE_OBSOLETE50
#define TEST_ERR_FSTAT CURLE_OBSOLETE51
#define TEST_ERR_BAD_TIMEOUT CURLE_OBSOLETE57
/*
** Macros for test source code readability/maintainability.
**
** All of the following macros require that an int data type 'res' variable
** exists in scope where macro is used, and that it has been initialized to
** zero before the macro is used.
**
** exe_* and chk_* macros are helper macros not intended to be used from
** outside of this header file. Arguments 'Y' and 'Z' of these represent
** source code file and line number, while Arguments 'A', 'B', etc, are
** the arguments used to actually call a libcurl function.
**
** All easy_* and multi_* macros call a libcurl function and evaluate if
** the function has succeeded or failed. When the function succeeds 'res'
** variable is not set nor cleared and program continues normal flow. On
** the other hand if function fails 'res' variable is set and a jump to
** label 'test_cleanup' is performed.
**
** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
** counterpart that operates in the same way with the exception that no
** jump takes place in case of failure. res_easy_* and res_multi_* macros
** should be immediately followed by checking if 'res' variable has been
** set.
**
** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
** TEST_ERR_* values defined above. It is advisable to return this value
** as test result.
*/
/* ---------------------------------------------------------------- */
#define exe_easy_init(A,Y,Z) do { \
if(((A) = curl_easy_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
res = TEST_ERR_EASY_INIT; \
} \
} while(0)
#define res_easy_init(A) \
exe_easy_init((A), (__FILE__), (__LINE__))
#define chk_easy_init(A,Y,Z) do { \
exe_easy_init((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define easy_init(A) \
chk_easy_init((A), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_init(A,Y,Z) do { \
if(((A) = curl_multi_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_init(A) \
exe_multi_init((A), (__FILE__), (__LINE__))
#define chk_multi_init(A,Y,Z) do { \
exe_multi_init((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_init(A) \
chk_multi_init((A), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_easy_setopt(A,B,C,Y,Z) do { \
CURLcode ec; \
if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) { \
curl_mfprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define res_easy_setopt(A, B, C) \
exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
#define chk_easy_setopt(A, B, C, Y, Z) do { \
exe_easy_setopt((A), (B), (C), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define easy_setopt(A, B, C) \
chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_setopt(A, B, C, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_setopt(A,B,C) \
exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
#define chk_multi_setopt(A,B,C,Y,Z) do { \
exe_multi_setopt((A), (B), (C), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_setopt(A,B,C) \
chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_add_handle(A,B,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_add_handle(A, B) \
exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
#define chk_multi_add_handle(A, B, Y, Z) do { \
exe_multi_add_handle((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_add_handle(A, B) \
chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_remove_handle(A,B,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_remove_handle(A, B) \
exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
#define chk_multi_remove_handle(A, B, Y, Z) do { \
exe_multi_remove_handle((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_remove_handle(A, B) \
chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_perform(A,B,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_perform((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_perform() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((B)) < 0) { \
curl_mfprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \
"but returned invalid running_handles value (%d)\n", \
(Y), (Z), (int)*((B))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_perform(A, B) \
exe_multi_perform((A), (B), (__FILE__), (__LINE__))
#define chk_multi_perform(A, B, Y, Z) do { \
exe_multi_perform((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_perform(A,B) \
chk_multi_perform((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_fdset(A, B, C, D, E, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_fdset() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((E)) < -1) { \
curl_mfprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \
"but returned invalid max_fd value (%d)\n", \
(Y), (Z), (int)*((E))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_fdset(A, B, C, D, E) \
exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_multi_fdset(A, B, C, D, E, Y, Z) do { \
exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_fdset(A, B, C, D, E) \
chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_timeout(A,B,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_timeout() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
else if(*((B)) < -1L) { \
curl_mfprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
"but returned invalid timeout value (%ld)\n", \
(Y), (Z), (long)*((B))); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
} while(0)
#define res_multi_timeout(A, B) \
exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
#define chk_multi_timeout(A, B, Y, Z) do { \
exe_multi_timeout((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_timeout(A, B) \
chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_poll(A,B,C,D,E,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_poll((A), (B), (C), (D), (E))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_poll() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((E)) < 0) { \
curl_mfprintf(stderr, "%s:%d curl_multi_poll() succeeded, " \
"but returned invalid numfds value (%d)\n", \
(Y), (Z), (int)*((E))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_poll(A, B, C, D, E) \
exe_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_multi_poll(A, B, C, D, E, Y, Z) do { \
exe_multi_poll((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_poll(A, B, C, D, E) \
chk_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_wakeup(A,Y,Z) do { \
CURLMcode ec; \
if((ec = curl_multi_wakeup((A))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_wakeup() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_wakeup(A) \
exe_multi_wakeup((A), (__FILE__), (__LINE__))
#define chk_multi_wakeup(A, Y, Z) do { \
exe_multi_wakeup((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_wakeup(A) \
chk_multi_wakeup((A), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_select_test(A, B, C, D, E, Y, Z) do { \
int ec; \
if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \
char ecbuf[STRERROR_LEN]; \
ec = SOCKERRNO; \
curl_mfprintf(stderr, "%s:%d select() failed, with " \
"errno %d (%s)\n", \
(Y), (Z), \
ec, curlx_strerror(ec, ecbuf, sizeof(ecbuf))); \
res = TEST_ERR_SELECT; \
} \
} while(0)
#define res_select_test(A, B, C, D, E) \
exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_select_test(A, B, C, D, E, Y, Z) do { \
exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define select_test(A, B, C, D, E) \
chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define start_test_timing() do { \
tv_test_start = curlx_now(); \
} while(0)
#define TEST_HANG_TIMEOUT 60 * 1000 /* global default */
#define exe_test_timedout(T,Y,Z) do { \
timediff_t timediff = curlx_timediff(curlx_now(), tv_test_start); \
if(timediff > (T)) { \
curl_mfprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
"that it would have run forever (%ld ms > %ld ms)\n", \
(Y), (Z), (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
res = TEST_ERR_RUNS_FOREVER; \
} \
} while(0)
#define res_test_timedout() \
exe_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
#define res_test_timedout_custom(T) \
exe_test_timedout((T), (__FILE__), (__LINE__))
#define chk_test_timedout(T, Y, Z) do { \
exe_test_timedout(T, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define abort_on_test_timeout() \
chk_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
#define abort_on_test_timeout_custom(T) \
chk_test_timedout((T), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_global_init(A,Y,Z) do { \
CURLcode ec; \
if((ec = curl_global_init((A))) != CURLE_OK) { \
curl_mfprintf(stderr, "%s:%d curl_global_init() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define res_global_init(A) \
exe_global_init((A), (__FILE__), (__LINE__))
#define chk_global_init(A, Y, Z) do { \
exe_global_init((A), (Y), (Z)); \
if(res) \
return res; \
} while(0)
/* global_init() is different than other macros. In case of
failure it 'return's instead of going to 'test_cleanup'. */
#define global_init(A) \
chk_global_init((A), (__FILE__), (__LINE__))
#define NO_SUPPORT_BUILT_IN \
{ \
(void)URL; \
curl_mfprintf(stderr, "Missing support\n"); \
return CURLE_UNSUPPORTED_PROTOCOL; \
}
#define NUM_HANDLES 4 /* global default */
#endif /* HEADER_LIBTEST_FIRST_H */
+173
View File
@@ -0,0 +1,173 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
/*
Check range/resume returned error codes and data presence.
The input parameters are:
- CURLOPT_RANGE/CURLOPT_RESUME_FROM
- CURLOPT_FAILONERROR
- Returned http code (2xx/416)
- Content-Range header present in reply.
*/
#include "memdebug.h"
#define F_RESUME (1 << 0) /* resume/range. */
#define F_HTTP416 (1 << 1) /* Server returns http code 416. */
#define F_FAIL (1 << 2) /* Fail on error. */
#define F_CONTENTRANGE (1 << 3) /* Server sends content-range hdr. */
#define F_IGNOREBODY (1 << 4) /* Body should be ignored. */
struct testparams {
unsigned int flags; /* ORed flags as above. */
CURLcode result; /* Code that should be returned by curl_easy_perform(). */
};
static const struct testparams testparams[] = {
{ 0, CURLE_OK },
{ F_CONTENTRANGE, CURLE_OK },
{ F_FAIL, CURLE_OK },
{ F_FAIL | F_CONTENTRANGE, CURLE_OK },
{ F_HTTP416, CURLE_OK },
{ F_HTTP416 | F_CONTENTRANGE, CURLE_OK },
{ F_HTTP416 | F_FAIL | F_IGNOREBODY,
CURLE_HTTP_RETURNED_ERROR },
{ F_HTTP416 | F_FAIL | F_CONTENTRANGE | F_IGNOREBODY,
CURLE_HTTP_RETURNED_ERROR },
{ F_RESUME | F_IGNOREBODY,
CURLE_RANGE_ERROR },
{ F_RESUME | F_CONTENTRANGE, CURLE_OK },
{ F_RESUME | F_FAIL | F_IGNOREBODY,
CURLE_RANGE_ERROR },
{ F_RESUME | F_FAIL | F_CONTENTRANGE, CURLE_OK },
{ F_RESUME | F_HTTP416 | F_IGNOREBODY, CURLE_OK },
{ F_RESUME | F_HTTP416 | F_CONTENTRANGE | F_IGNOREBODY, CURLE_OK },
{ F_RESUME | F_HTTP416 | F_FAIL | F_IGNOREBODY, CURLE_OK },
{ F_RESUME | F_HTTP416 | F_FAIL | F_CONTENTRANGE | F_IGNOREBODY,
CURLE_OK }
};
static int hasbody;
static size_t writedata(char *data, size_t size, size_t nmemb, void *userdata)
{
(void)data;
(void)userdata;
if(size && nmemb)
hasbody = 1;
return size * nmemb;
}
static int onetest(CURL *curl, const char *url, const struct testparams *p,
size_t num)
{
CURLcode res;
unsigned int replyselector;
char urlbuf[256];
replyselector = (p->flags & F_CONTENTRANGE) ? 1 : 0;
if(p->flags & F_HTTP416)
replyselector += 2;
curl_msnprintf(urlbuf, sizeof(urlbuf), "%s%04u", url, replyselector);
test_setopt(curl, CURLOPT_URL, urlbuf);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_RESUME_FROM, (p->flags & F_RESUME) ? 3L : 0L);
test_setopt(curl, CURLOPT_RANGE, !(p->flags & F_RESUME) ?
"3-1000000": (char *)NULL);
test_setopt(curl, CURLOPT_FAILONERROR, (p->flags & F_FAIL) ? 1L : 0L);
hasbody = 0;
res = curl_easy_perform(curl);
if(res != p->result) {
curl_mprintf("%zu: bad error code (%d): resume=%s, fail=%s, http416=%s, "
"content-range=%s, expected=%d\n", num, res,
(p->flags & F_RESUME) ? "yes": "no",
(p->flags & F_FAIL) ? "yes": "no",
(p->flags & F_HTTP416) ? "yes": "no",
(p->flags & F_CONTENTRANGE) ? "yes": "no",
p->result);
return 1;
}
if(hasbody && (p->flags & F_IGNOREBODY)) {
curl_mprintf("body should be ignored and is not: resume=%s, fail=%s, "
"http416=%s, content-range=%s\n",
(p->flags & F_RESUME) ? "yes": "no",
(p->flags & F_FAIL) ? "yes": "no",
(p->flags & F_HTTP416) ? "yes": "no",
(p->flags & F_CONTENTRANGE) ? "yes": "no");
return 1;
}
return 0;
test_cleanup:
return 1;
}
/* for debugging: */
/* #define SINGLETEST 9 */
static CURLcode test_lib1156(const char *URL)
{
CURLcode res;
CURL *curl;
size_t i;
int status = 0;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
for(i = 0; i < CURL_ARRAYSIZE(testparams); i++) {
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_WRITEFUNCTION, writedata);
#ifdef SINGLETEST
if(SINGLETEST == i)
#endif
status |= onetest(curl, URL, testparams + i, i);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
curl_mprintf("%d\n", status);
return (CURLcode)status;
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#define t1301_fail_unless(expr, msg) \
do { \
if(!(expr)) { \
curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
__FILE__, __LINE__, #expr, msg); \
return TEST_ERR_FAILURE; \
} \
} while(0)
static CURLcode test_lib1301(const char *URL)
{
int rc;
(void)URL;
rc = curl_strequal("iii", "III");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strequal("iiia", "III");
t1301_fail_unless(rc == 0, "return code should be zero");
rc = curl_strequal("iii", "IIIa");
t1301_fail_unless(rc == 0, "return code should be zero");
rc = curl_strequal("iiiA", "IIIa");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("iii", "III", 3);
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("iiiABC", "IIIcba", 3);
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("ii", "II", 3);
t1301_fail_unless(rc != 0, "return code should be non-zero");
return CURLE_OK;
}
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
{
fwrite(buf, len, 1, stdout);
(*(size_t *) arg) += len;
return len;
}
#define t1308_fail_unless(expr, msg) \
do { \
if(!(expr)) { \
curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
__FILE__, __LINE__, #expr, msg); \
errorcount++; \
} \
} while(0)
static CURLcode test_lib1308(const char *URL)
{
int errorcount = 0;
CURLFORMcode rc;
CURLcode res = CURLE_OK;
int formres = 0;
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
size_t total_size = 0;
char buffer[] = "test buffer";
global_init(CURL_GLOBAL_ALL);
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
t1308_fail_unless(rc == 0, "curl_formadd returned error");
/* after the first curl_formadd when there's a single entry, both pointers
should point to the same struct */
t1308_fail_unless(post == last, "post and last weren't the same");
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
CURLFORM_COPYCONTENTS, "<HTML></HTML>",
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
t1308_fail_unless(rc == 0, "curl_formadd returned error");
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
t1308_fail_unless(rc == 0, "curl_formadd returned error");
formres = curl_formget(post, &total_size, print_httppost_callback);
t1308_fail_unless(formres == 0, "curl_formget returned error");
t1308_fail_unless(total_size == 518, "curl_formget got wrong size back");
curl_formfree(post);
/* start a new formpost with a file upload and formget */
post = last = NULL;
rc = curl_formadd(&post, &last,
CURLFORM_PTRNAME, "name of file field",
CURLFORM_FILE, URL,
CURLFORM_FILENAME, "custom named file",
CURLFORM_END);
t1308_fail_unless(rc == 0, "curl_formadd returned error");
formres = curl_formget(post, &total_size, print_httppost_callback);
t1308_fail_unless(formres == 0, "curl_formget returned error");
t1308_fail_unless(total_size == 899, "curl_formget got wrong size back");
curl_formfree(post);
curl_global_cleanup();
return errorcount ? TEST_ERR_FAILURE : CURLE_OK;
}
+119
View File
@@ -0,0 +1,119 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
struct t1485_transfer_status {
CURL *curl;
curl_off_t out_len;
size_t hd_line;
CURLcode result;
int http_status;
};
static size_t t1485_header_callback(char *ptr, size_t size, size_t nmemb,
void *userp)
{
struct t1485_transfer_status *st = (struct t1485_transfer_status *)userp;
const char *hd = ptr;
size_t len = size * nmemb;
CURLcode result;
(void)fwrite(ptr, size, nmemb, stdout);
++st->hd_line;
if(len == 2 && hd[0] == '\r' && hd[1] == '\n') {
curl_off_t clen;
long httpcode = 0;
/* end of a response */
result = curl_easy_getinfo(st->curl, CURLINFO_RESPONSE_CODE, &httpcode);
curl_mfprintf(stderr, "header_callback, get status: %ld, %d\n",
httpcode, result);
if(httpcode < 100 || httpcode >= 1000) {
curl_mfprintf(stderr, "header_callback, invalid status: %ld, %d\n",
httpcode, result);
return CURLE_WRITE_ERROR;
}
st->http_status = (int)httpcode;
if(st->http_status >= 200 && st->http_status < 300) {
result = curl_easy_getinfo(st->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
&clen);
curl_mfprintf(stderr, "header_callback, info Content-Length: "
"%" CURL_FORMAT_CURL_OFF_T ", %d\n", clen, result);
if(result) {
st->result = result;
return CURLE_WRITE_ERROR;
}
if(clen < 0) {
curl_mfprintf(stderr,
"header_callback, expected known Content-Length, "
"got: %" CURL_FORMAT_CURL_OFF_T "\n", clen);
return CURLE_WRITE_ERROR;
}
}
}
return len;
}
static size_t t1485_write_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct t1485_transfer_status *st = (struct t1485_transfer_status *)userp;
size_t len = size * nmemb;
fwrite(ptr, size, nmemb, stdout);
st->out_len += (curl_off_t)len;
return len;
}
static CURLcode test_lib1485(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
struct t1485_transfer_status st;
start_test_timing();
memset(&st, 0, sizeof(st));
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
st.curl = curl; /* to allow callbacks access */
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_WRITEFUNCTION, t1485_write_cb);
easy_setopt(curl, CURLOPT_WRITEDATA, &st);
easy_setopt(curl, CURLOPT_HEADERFUNCTION, t1485_header_callback);
easy_setopt(curl, CURLOPT_HEADERDATA, &st);
easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res; /* return the final return code */
}
+89
View File
@@ -0,0 +1,89 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1500(const char *URL)
{
CURL *curl = NULL;
CURLM *multi = NULL;
int still_running;
CURLcode i = TEST_ERR_FAILURE;
CURLcode res = CURLE_OK;
CURLMsg *msg;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout();
while(still_running) {
CURLMcode mres;
int num;
mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
if(mres != CURLM_OK) {
curl_mprintf("curl_multi_wait() returned %d\n", mres);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
multi_perform(multi, &still_running);
abort_on_test_timeout();
}
msg = curl_multi_info_read(multi, &still_running);
if(msg)
/* this should now contain a result code from the easy handle,
get it */
i = msg->data.result;
test_cleanup:
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
if(res)
i = res;
return i; /* return the final return code */
}
+108
View File
@@ -0,0 +1,108 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1501(const char *URL)
{
static const long HANG_TIMEOUT = 30 * 1000;
/* 500 milliseconds allowed. An extreme number but lets be really
conservative to allow old and slow machines to run this test too */
static const int MAX_BLOCKED_TIME_MS = 500;
CURL *curl = NULL;
CURLM *multi = NULL;
CURLcode res = CURLE_OK;
int still_running = 0;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
multi_init(multi);
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout_custom(HANG_TIMEOUT);
while(still_running) {
struct timeval timeout;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -99;
struct curltime before;
struct curltime after;
timediff_t e;
timeout.tv_sec = 0;
timeout.tv_usec = 100000L; /* 100 ms */
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
abort_on_test_timeout_custom(HANG_TIMEOUT);
curl_mfprintf(stderr, "ping\n");
before = curlx_now();
multi_perform(multi, &still_running);
abort_on_test_timeout_custom(HANG_TIMEOUT);
after = curlx_now();
e = curlx_timediff(after, before);
curl_mfprintf(stderr, "pong = %ld\n", (long)e);
if(e > MAX_BLOCKED_TIME_MS) {
res = CURLE_TOO_LARGE;
break;
}
}
test_cleanup:
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+152
View File
@@ -0,0 +1,152 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This source code is used for lib1502, lib1503, lib1504 and lib1505 with
* only the testnum controlling the cleanup sequence.
*
* Test case 1502 converted from bug report #3575448, identifying a memory
* leak in the CURLOPT_RESOLVE handling with the multi interface.
*/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1502(const char *URL)
{
CURL *curl = NULL;
CURL *curldupe;
CURLM *multi = NULL;
int still_running;
CURLcode res = CURLE_OK;
char redirect[160];
/* DNS cache injection */
struct curl_slist *dns_cache_list;
res_global_init(CURL_GLOBAL_ALL);
if(res) {
return res;
}
curl_msnprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2,
libtest_arg3);
start_test_timing();
dns_cache_list = curl_slist_append(NULL, redirect);
if(!dns_cache_list) {
curl_mfprintf(stderr, "curl_slist_append() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_RESOLVE, dns_cache_list);
curldupe = curl_easy_duphandle(curl);
if(curldupe) {
curl_easy_cleanup(curl);
curl = curldupe;
}
else {
curl_slist_free_all(dns_cache_list);
curl_easy_cleanup(curl);
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
multi_init(multi);
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout();
while(still_running) {
struct timeval timeout;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -99;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
abort_on_test_timeout();
multi_perform(multi, &still_running);
abort_on_test_timeout();
}
test_cleanup:
switch(testnum) {
case 1502:
default:
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
break;
case 1503:
/* proper cleanup sequence - type PA */
curl_multi_remove_handle(multi, curl);
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
break;
case 1504:
/* undocumented cleanup sequence - type UB */
curl_easy_cleanup(curl);
curl_multi_cleanup(multi);
curl_global_cleanup();
break;
case 1505:
/* proper cleanup sequence - type PB */
curl_multi_remove_handle(multi, curl);
curl_easy_cleanup(curl);
curl_multi_cleanup(multi);
curl_global_cleanup();
break;
}
curl_slist_free_all(dns_cache_list);
return res;
}
+133
View File
@@ -0,0 +1,133 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1506(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl[NUM_HANDLES] = {0};
int running;
CURLM *multi = NULL;
size_t i;
char target_url[256];
char dnsentry[256];
struct curl_slist *slist = NULL, *slist2;
const char *port = libtest_arg3;
const char *address = libtest_arg2;
(void)URL;
/* Create fake DNS entries for serverX.example.com for all handles */
for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
curl_msnprintf(dnsentry, sizeof(dnsentry), "server%zu.example.com:%s:%s",
i + 1, port, address);
curl_mprintf("%s\n", dnsentry);
slist2 = curl_slist_append(slist, dnsentry);
if(!slist2) {
curl_mfprintf(stderr, "curl_slist_append() failed\n");
goto test_cleanup;
}
slist = slist2;
}
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
multi_setopt(multi, CURLMOPT_MAXCONNECTS, 3L);
/* get each easy handle */
for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
curl_msnprintf(target_url, sizeof(target_url),
"http://server%zu.example.com:%s/path/1506%04zu",
i + 1, port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl[i], CURLOPT_URL, target_url);
/* go verbose */
easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
/* include headers */
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
}
curl_mfprintf(stderr, "Start at URL 0\n");
for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
/* add handle to multi */
multi_add_handle(multi, curl[i]);
for(;;) {
struct timeval interval;
fd_set rd, wr, exc;
int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
multi_perform(multi, &running);
abort_on_test_timeout();
if(!running)
break; /* done */
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
multi_fdset(multi, &rd, &wr, &exc, &maxfd);
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
select_test(maxfd + 1, &rd, &wr, &exc, &interval);
abort_on_test_timeout();
}
curlx_wait_ms(1); /* to ensure different end times */
}
test_cleanup:
/* proper cleanup sequence - type PB */
for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
curl_multi_remove_handle(multi, curl[i]);
curl_easy_cleanup(curl[i]);
}
curl_slist_free_all(slist);
curl_multi_cleanup(multi);
curl_global_cleanup();
return res;
}
+141
View File
@@ -0,0 +1,141 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static size_t t1507_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
(void)ptr;
(void)size;
(void)nmemb;
(void)userp;
return CURL_READFUNC_ABORT;
}
static CURLcode test_lib1507(const char *URL)
{
static const int MULTI_PERFORM_HANG_TIMEOUT = 60 * 1000;
CURLcode res = CURLE_OK;
CURL *curl = NULL;
CURLM *multi = NULL;
int still_running = 1;
struct curltime mp_start;
struct curl_slist *rcpt_list = NULL;
curl_global_init(CURL_GLOBAL_DEFAULT);
easy_init(curl);
multi_init(multi);
rcpt_list = curl_slist_append(rcpt_list, "<1507-recipient@example.com>");
#if 0
/* more addresses can be added here */
rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
#endif
curl_easy_setopt(curl, CURLOPT_URL, URL);
#if 0
curl_easy_setopt(curl, CURLOPT_USERNAME, "user@example.com");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "123qwerty");
#endif
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, t1507_read_cb);
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "<1507-realuser@example.com>");
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
multi_add_handle(multi, curl);
mp_start = curlx_now();
/* we start some action by calling perform right away */
curl_multi_perform(multi, &still_running);
while(still_running) {
struct timeval timeout;
int rc; /* select() return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
long curl_timeo = -1;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(multi, &curl_timeo);
if(curl_timeo >= 0) {
curlx_mstotv(&timeout, curl_timeo);
if(timeout.tv_sec > 1) {
timeout.tv_sec = 1;
timeout.tv_usec = 0;
}
}
/* get file descriptors from the transfers */
curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
/* In a real-world program you OF COURSE check the return code of the
function calls. On success, the value of maxfd is guaranteed to be
greater or equal than -1. We call select(maxfd + 1, ...), specially in
case of (maxfd == -1), we call select(0, ...), which is basically equal
to sleep. */
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
if(curlx_timediff(curlx_now(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
curl_mfprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
break;
}
switch(rc) {
case -1:
/* select error */
break;
case 0: /* timeout */
default: /* action */
curl_multi_perform(multi, &still_running);
break;
}
}
test_cleanup:
curl_slist_free_all(rcpt_list);
curl_multi_remove_handle(multi, curl);
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+49
View File
@@ -0,0 +1,49 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1508(const char *URL)
{
CURLcode res = CURLE_OK;
CURLM *multi = NULL;
(void)URL;
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
test_cleanup:
/* proper cleanup sequence - type PB */
curl_multi_cleanup(multi);
curl_global_cleanup();
curl_mprintf("We are done\n");
return res;
}
+97
View File
@@ -0,0 +1,97 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream);
size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream);
static size_t realHeaderSize = 0;
static CURLcode test_lib1509(const char *URL)
{
long headerSize;
CURLcode code;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
easy_setopt(curl, CURLOPT_WRITEFUNCTION, *WriteOutput);
easy_setopt(curl, CURLOPT_HEADERFUNCTION, *WriteHeader);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
code = curl_easy_perform(curl);
if(CURLE_OK != code) {
curl_mfprintf(stderr, "%s:%d curl_easy_perform() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
code = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
if(CURLE_OK != code) {
curl_mfprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
curl_mprintf("header length is ........: %ld\n", headerSize);
curl_mprintf("header length should be..: %zu\n", realHeaderSize);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream)
{
fwrite(ptr, size, nmemb, stream);
return nmemb * size;
}
size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream)
{
(void)ptr;
(void)stream;
realHeaderSize += size * nmemb;
return nmemb * size;
}
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1510(const char *URL)
{
static const int NUM_URLS = 4;
CURLcode res = CURLE_OK;
CURL *curl = NULL;
int i;
char target_url[256];
char dnsentry[256];
struct curl_slist *slist = NULL, *slist2;
const char *port = libtest_arg3;
const char *address = libtest_arg2;
(void)URL;
/* Create fake DNS entries for serverX.example.com for all handles */
for(i = 0; i < NUM_URLS; i++) {
curl_msnprintf(dnsentry, sizeof(dnsentry),
"server%d.example.com:%s:%s", i + 1, port, address);
curl_mprintf("%s\n", dnsentry);
slist2 = curl_slist_append(slist, dnsentry);
if(!slist2) {
curl_mfprintf(stderr, "curl_slist_append() failed\n");
goto test_cleanup;
}
slist = slist2;
}
start_test_timing();
global_init(CURL_GLOBAL_ALL);
/* get an easy handle */
easy_init(curl);
/* go verbose */
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* include headers */
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_RESOLVE, slist);
easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
/* get NUM_URLS easy handles */
for(i = 0; i < NUM_URLS; i++) {
/* specify target */
curl_msnprintf(target_url, sizeof(target_url),
"http://server%d.example.com:%s/path/1510%04i",
i + 1, port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl, CURLOPT_URL, target_url);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
abort_on_test_timeout();
}
test_cleanup:
/* proper cleanup sequence - type PB */
curl_easy_cleanup(curl);
curl_slist_free_all(slist);
curl_global_cleanup();
return res;
}
+77
View File
@@ -0,0 +1,77 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1511(const char *URL)
{
long unmet;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
/* TIMEVALUE in the future */
easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
if(unmet != 1L) {
res = TEST_ERR_FAILURE; /* not correct */
goto test_cleanup;
}
/* TIMEVALUE in the past */
easy_setopt(curl, CURLOPT_TIMEVALUE, 1L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
if(unmet) {
res = TEST_ERR_FAILURE; /* not correct */
goto test_cleanup;
}
res = TEST_ERR_SUCCESS; /* this is where we should be */
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+93
View File
@@ -0,0 +1,93 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Use global DNS cache (while deprecated it should still work), populate it
* with CURLOPT_RESOLVE in the first request and then make sure a subsequent
* easy transfer finds and uses the populated stuff.
*/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1512(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl[2] = {NULL, NULL};
const char *port = libtest_arg3;
const char *address = libtest_arg2;
char dnsentry[256];
struct curl_slist *slist = NULL;
size_t i;
char target_url[256];
(void)URL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl_msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",
port, address);
curl_mprintf("%s\n", dnsentry);
slist = curl_slist_append(slist, dnsentry);
/* get each easy handle */
for(i = 0; i < CURL_ARRAYSIZE(curl); i++) {
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
curl_msnprintf(target_url, sizeof(target_url),
"http://server.example.curl:%s/path/1512%04zu",
port, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
easy_setopt(curl[i], CURLOPT_URL, target_url);
/* go verbose */
easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
/* include headers */
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
}
/* make the first one populate the GLOBAL cache */
easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
/* run each transfer */
for(i = 0; (i < CURL_ARRAYSIZE(curl)) && !res; i++) {
res = curl_easy_perform(curl[i]);
if(res)
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl[0]);
curl_easy_cleanup(curl[1]);
curl_slist_free_all(slist);
curl_global_cleanup();
return res;
}
+76
View File
@@ -0,0 +1,76 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Test case converted from bug report #1318 by Petr Novak.
*
* Before the fix, this test program returned 52 (CURLE_GOT_NOTHING) instead
* of 42 (CURLE_ABORTED_BY_CALLBACK).
*/
#include "first.h"
#include "memdebug.h"
static int progressKiller(void *arg,
double dltotal,
double dlnow,
double ultotal,
double ulnow)
{
(void)arg;
(void)dltotal;
(void)dlnow;
(void)ultotal;
(void)ulnow;
curl_mprintf("PROGRESSFUNCTION called\n");
return 1;
}
static CURLcode test_lib1513(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMEOUT, 7L);
easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressKiller);
easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(curl);
test_cleanup:
/* undocumented cleanup sequence - type UA */
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+87
View File
@@ -0,0 +1,87 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST
* size is unknown.
*/
#include "first.h"
#include "memdebug.h"
struct t1514_WriteThis {
char *readptr;
size_t sizeleft;
};
static size_t t1514_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct t1514_WriteThis *pooh = (struct t1514_WriteThis *)userp;
if(size*nmemb < 1)
return 0;
if(pooh->sizeleft) {
*ptr = pooh->readptr[0]; /* copy one single byte */
pooh->readptr++; /* advance pointer */
pooh->sizeleft--; /* less data left */
return 1; /* we return 1 byte at a time! */
}
return 0; /* no more data left to deliver */
}
static CURLcode test_lib1514(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
static char testdata[] = "dummy";
struct t1514_WriteThis pooh = { testdata, sizeof(testdata)-1 };
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_POST, 1L);
/* Purposely omit to set CURLOPT_POSTFIELDSIZE */
easy_setopt(curl, CURLOPT_READFUNCTION, t1514_read_cb);
easy_setopt(curl, CURLOPT_READDATA, &pooh);
if(testnum == 1539) {
/* speak HTTP 1.0 - no chunked! */
easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
}
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+146
View File
@@ -0,0 +1,146 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Check for bugs #1303 and #1327: libcurl should never remove DNS entries
* created via CURLOPT_RESOLVE, neither after DNS_CACHE_TIMEOUT elapses
* (test1515) nor a dead connection is detected (test1616).
*/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
#define DNS_TIMEOUT 1L
static CURLcode do_one_request(CURLM *multi, const char *URL,
const char *resolve)
{
CURL *curl;
struct curl_slist *resolve_list = NULL;
int still_running;
CURLcode res = CURLE_OK;
CURLMsg *msg;
int msgs_left;
resolve_list = curl_slist_append(resolve_list, resolve);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_RESOLVE, resolve_list);
easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, DNS_TIMEOUT);
debug_config.nohex = TRUE;
debug_config.tracetime = TRUE;
easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout();
while(still_running) {
struct timeval timeout;
fd_set fdread, fdwrite, fdexcep;
int maxfd = -99;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
abort_on_test_timeout();
multi_perform(multi, &still_running);
abort_on_test_timeout();
}
do {
msg = curl_multi_info_read(multi, &msgs_left);
if(msg && msg->msg == CURLMSG_DONE && msg->easy_handle == curl) {
res = msg->data.result;
break;
}
} while(msg);
test_cleanup:
curl_multi_remove_handle(multi, curl);
curl_easy_cleanup(curl);
curl_slist_free_all(resolve_list);
return res;
}
static CURLcode test_lib1515(const char *URL)
{
CURLM *multi = NULL;
CURLcode res = CURLE_OK;
const char *path = URL;
const char *address = libtest_arg2;
const char *port = libtest_arg3;
char dns_entry[256];
int i;
int count = 2;
curl_msnprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s",
port, address);
start_test_timing();
global_init(CURL_GLOBAL_ALL);
curl_global_trace("all");
multi_init(multi);
for(i = 1; i <= count; i++) {
char target_url[256];
curl_msnprintf(target_url, sizeof(target_url),
"http://testserver.example.com:%s/%s%04d", port, path, i);
/* second request must succeed like the first one */
res = do_one_request(multi, target_url, dns_entry);
if(res != CURLE_OK) {
curl_mfprintf(stderr, "request %s failed with %d\n", target_url, res);
goto test_cleanup;
}
if(i < count)
curlx_wait_ms((DNS_TIMEOUT + 1) * 1000);
}
test_cleanup:
curl_multi_cleanup(multi);
curl_global_cleanup();
return res;
}
+114
View File
@@ -0,0 +1,114 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
struct t1517_WriteThis {
const char *readptr;
size_t sizeleft;
};
static size_t t1517_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct t1517_WriteThis *pooh = (struct t1517_WriteThis *)userp;
size_t tocopy = size * nmemb;
/* Wait one second before return POST data *
* so libcurl will wait before sending request body */
curlx_wait_ms(1000);
if(tocopy < 1 || !pooh->sizeleft)
return 0;
if(pooh->sizeleft < tocopy)
tocopy = pooh->sizeleft;
memcpy(ptr, pooh->readptr, tocopy);/* copy requested data */
pooh->readptr += tocopy; /* advance pointer */
pooh->sizeleft -= tocopy; /* less data left */
return tocopy;
}
static CURLcode test_lib1517(const char *URL)
{
static const char testdata[] =
"this is what we post to the silly web server\n";
CURL *curl;
CURLcode res = CURLE_OK;
struct t1517_WriteThis pooh;
pooh.readptr = testdata;
pooh.sizeleft = strlen(testdata);
if(curl_global_init(CURL_GLOBAL_ALL)) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
/* First set the URL that is about to receive our POST. */
test_setopt(curl, CURLOPT_URL, URL);
/* Now specify we want to POST data */
test_setopt(curl, CURLOPT_POST, 1L);
/* Set the expected POST size */
test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
/* we want to use our own read function */
test_setopt(curl, CURLOPT_READFUNCTION, t1517_read_cb);
/* pointer to pass to our read function */
test_setopt(curl, CURLOPT_READDATA, &pooh);
/* get verbose debug output please */
test_setopt(curl, CURLOPT_VERBOSE, 1L);
/* include headers in the output */
test_setopt(curl, CURLOPT_HEADER, 1L);
/* detect HTTP error codes >= 400 */
/* test_setopt(curl, CURLOPT_FAILONERROR, 1L); */
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+102
View File
@@ -0,0 +1,102 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* Test inspired by github issue 3340 */
static size_t t1518_write_cb(char *buffer, size_t size, size_t nitems,
void *outstream)
{
(void)buffer;
(void)size;
(void)nitems;
(void)outstream;
return 0;
}
static CURLcode test_lib1518(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
long curlResponseCode;
long curlRedirectCount;
char *effectiveUrl = NULL;
char *redirectUrl = NULL;
CURLU *urlu = NULL;
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
if(testnum == 1543) {
/* set CURLOPT_URLU */
CURLUcode rc = CURLUE_OK;
urlu = curl_url();
if(urlu)
rc = curl_url_set(urlu, CURLUPART_URL, URL, CURLU_ALLOW_SPACE);
if(!urlu || rc) {
goto test_cleanup;
}
test_setopt(curl, CURLOPT_CURLU, urlu);
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
}
else {
test_setopt(curl, CURLOPT_URL, URL);
/* just to make it explicit and visible in this test: */
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
}
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode);
curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
test_setopt(curl, CURLOPT_WRITEFUNCTION, t1518_write_cb);
curl_mprintf("res %d\n"
"status %ld\n"
"redirects %ld\n"
"effectiveurl %s\n"
"redirecturl %s\n",
res,
curlResponseCode,
curlRedirectCount,
effectiveUrl,
redirectUrl ? redirectUrl : "blank");
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_global_cleanup();
curl_url_cleanup(urlu);
return res;
}
+109
View File
@@ -0,0 +1,109 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Steve Holme, <steve_holme@hotmail.com>.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
struct upload_status {
int lines_read;
};
static size_t t1520_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
static const char *payload_text[] = {
"From: different\r\n",
"To: another\r\n",
"\r\n",
"\r\n",
".\r\n",
".\r\n",
"\r\n",
".\r\n",
"\r\n",
"body",
NULL
};
struct upload_status *upload_ctx = (struct upload_status *)userp;
const char *data;
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
data = payload_text[upload_ctx->lines_read];
if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
upload_ctx->lines_read++;
return len;
}
return 0;
}
static CURLcode test_lib1520(const char *URL)
{
CURLcode res;
CURL *curl;
struct curl_slist *rcpt_list = NULL;
struct upload_status upload_ctx = {0};
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
rcpt_list = curl_slist_append(rcpt_list, "<recipient@example.com>");
#if 0
/* more addresses can be added here */
rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
#endif
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_READFUNCTION, t1520_read_cb);
test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
test_setopt(curl, CURLOPT_MAIL_FROM, "<sender@example.com>");
test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_slist_free_all(rcpt_list);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
/* test case and code based on https://github.com/curl/curl/issues/2847 */
#include "testtrace.h"
#include "memdebug.h"
static int sockopt_callback(void *clientp, curl_socket_t curlfd,
curlsocktype purpose)
{
#if defined(SOL_SOCKET) && defined(SO_SNDBUF)
int sndbufsize = 4 * 1024; /* 4KB send buffer */
(void)clientp;
(void)purpose;
setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
(char *)&sndbufsize, sizeof(sndbufsize));
#else
(void)clientp;
(void)curlfd;
(void)purpose;
#endif
return CURL_SOCKOPT_OK;
}
static CURLcode test_lib1522(const char *URL)
{
static char g_Data[40 * 1024]; /* POST 40KB */
CURLcode code = TEST_ERR_MAJOR_BAD;
CURLcode res;
struct curl_slist *pHeaderList = NULL;
CURL *curl = curl_easy_init();
memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, g_Data);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(g_Data));
debug_config.nohex = TRUE;
debug_config.tracetime = TRUE;
test_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
/* Remove "Expect: 100-continue" */
pHeaderList = curl_slist_append(pHeaderList, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList);
code = curl_easy_perform(curl);
if(code == CURLE_OK) {
curl_off_t uploadSize;
curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
curl_mprintf("uploadSize = %" CURL_FORMAT_CURL_OFF_T "\n", uploadSize);
if((size_t) uploadSize == sizeof(g_Data)) {
curl_mprintf("!!!!!!!!!! PASS\n");
}
else {
curl_mprintf("sent %zu, libcurl says %" CURL_FORMAT_CURL_OFF_T "\n",
sizeof(g_Data), uploadSize);
}
}
else {
curl_mprintf("curl_easy_perform() failed. e = %d\n", code);
}
test_cleanup:
curl_slist_free_all(pHeaderList);
curl_easy_cleanup(curl);
curl_global_cleanup();
return code;
}
+83
View File
@@ -0,0 +1,83 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
/* test case and code based on https://github.com/curl/curl/issues/3927 */
#include "memdebug.h"
static int dload_progress_cb(void *a, curl_off_t b, curl_off_t c,
curl_off_t d, curl_off_t e)
{
(void)a;
(void)b;
(void)c;
(void)d;
(void)e;
return 0;
}
static size_t t1523_write_cb(char *d, size_t n, size_t l, void *p)
{
/* take care of the data here, ignored in this example */
(void)d;
(void)p;
return n*l;
}
static CURLcode run(CURL *curl, long limit, long time)
{
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, limit);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, time);
return curl_easy_perform(curl);
}
static CURLcode test_lib1523(const char *URL)
{
CURLcode ret;
CURL *curl;
char buffer[CURL_ERROR_SIZE];
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, t1523_write_cb);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, buffer);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, dload_progress_cb);
ret = run(curl, 1, 2);
if(ret)
curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);
ret = run(curl, 12000, 1);
if(ret != CURLE_OPERATION_TIMEDOUT)
curl_mfprintf(stderr, "error (%d) %s\n", ret, buffer);
else
ret = CURLE_OK;
curl_easy_cleanup(curl);
curl_global_cleanup();
return ret;
}
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) Vijay Panghal, <vpanghal@maginatics.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This unit test PUT http data over proxy. Proxy header will be different
* from server http header
*/
#include "first.h"
#include "memdebug.h"
static const char t1525_testdata[] = "Hello Cloud!\n";
static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
size_t amount = nmemb * size; /* Total bytes curl wants */
if(amount < strlen(t1525_testdata)) {
return strlen(t1525_testdata);
}
(void)stream;
memcpy(ptr, t1525_testdata, strlen(t1525_testdata));
return strlen(t1525_testdata);
}
static CURLcode test_lib1525(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http and proxy header list */
struct curl_slist *hhl = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
if(!hhl) {
goto test_cleanup;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
test_setopt(curl, CURLOPT_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, t1525_read_cb);
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1525_testdata));
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_global_cleanup();
return res;
}
+105
View File
@@ -0,0 +1,105 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Vijay Panghal, <vpanghal@maginatics.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This unit test PUT http data over proxy. Proxy header will be different
* from server http header
*/
#include "first.h"
#include "memdebug.h"
static const char t1526_testdata[] = "Hello Cloud!\n";
static size_t t1526_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
size_t amount = nmemb * size; /* Total bytes curl wants */
if(amount < strlen(t1526_testdata)) {
return strlen(t1526_testdata);
}
(void)stream;
memcpy(ptr, t1526_testdata, strlen(t1526_testdata));
return strlen(t1526_testdata);
}
static CURLcode test_lib1526(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http and proxy header list */
struct curl_slist *hhl = NULL, *phl = NULL, *tmp = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
phl = curl_slist_append(phl, "User-Agent: Proxy Agent");
if(!hhl || !phl) {
goto test_cleanup;
}
tmp = curl_slist_append(phl, "Expect:");
if(!tmp) {
goto test_cleanup;
}
phl = tmp;
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, phl);
test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
test_setopt(curl, CURLOPT_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, t1526_read_cb);
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1526_testdata));
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_slist_free_all(phl);
curl_global_cleanup();
return res;
}
+101
View File
@@ -0,0 +1,101 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Vijay Panghal, <vpanghal@maginatics.com>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This unit test PUT http data over proxy. Same http header will be generated
* for server and proxy
*/
#include "first.h"
#include "memdebug.h"
static const char t1527_testdata[] = "Hello Cloud!\n";
static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
size_t amount = nmemb * size; /* Total bytes curl wants */
if(amount < strlen(t1527_testdata)) {
return strlen(t1527_testdata);
}
(void)stream;
memcpy(ptr, t1527_testdata, strlen(t1527_testdata));
return strlen(t1527_testdata);
}
static CURLcode test_lib1527(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http header list */
struct curl_slist *hhl = NULL, *tmp = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
if(!hhl) {
goto test_cleanup;
}
tmp = curl_slist_append(hhl, "Expect: 100-continue");
if(!tmp) {
goto test_cleanup;
}
hhl = tmp;
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, t1527_read_cb);
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1527_testdata));
test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_global_cleanup();
return res;
}
+74
View File
@@ -0,0 +1,74 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1528(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http header list */
struct curl_slist *hhl = NULL;
struct curl_slist *phl = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
phl = curl_slist_append(phl, "Proxy-User-Agent: Http Agent2");
if(!hhl) {
goto test_cleanup;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, phl);
test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
test_setopt(curl, CURLOPT_HEADER, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_slist_free_all(phl);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1529(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
char bURL[512];
curl_msnprintf(bURL, sizeof(bURL),
"%s HTTP/1.1\r\nGET http://1529.com/1529", URL);
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_URL, bURL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
test_setopt(curl, CURLOPT_HEADER, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+69
View File
@@ -0,0 +1,69 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static curl_socket_t opensocket(void *clientp,
curlsocktype purpose,
struct curl_sockaddr *address)
{
(void)purpose;
(void)address;
(void)clientp;
curl_mfprintf(stderr, "opensocket() returns CURL_SOCKET_BAD\n");
return CURL_SOCKET_BAD;
}
static CURLcode test_lib1530(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
(void)URL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+148
View File
@@ -0,0 +1,148 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1531(const char *URL)
{
static char const testData[] = ".abc\0xyz";
static curl_off_t const testDataSize = sizeof(testData) - 1;
CURL *curl;
CURLM *multi;
int still_running; /* keep number of running handles */
CURLMsg *msg; /* for picking up messages with the transfer status */
int msgs_left; /* how many messages are left */
CURLcode res = CURLE_OK;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
/* Allocate one curl handle per transfer */
curl = curl_easy_init();
/* init a multi stack */
multi = curl_multi_init();
/* add the individual transfer */
curl_multi_add_handle(multi, curl);
/* set the options (I left out a few, you'll get the point anyway) */
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, testDataSize);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, testData);
/* we start some action by calling perform right away */
curl_multi_perform(multi, &still_running);
abort_on_test_timeout();
do {
struct timeval timeout;
int rc; /* select() return code */
CURLMcode mc; /* curl_multi_fdset() return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
long curl_timeo = -1;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(multi, &curl_timeo);
if(curl_timeo >= 0) {
curlx_mstotv(&timeout, curl_timeo);
if(timeout.tv_sec > 1) {
timeout.tv_sec = 1;
timeout.tv_usec = 0;
}
}
/* get file descriptors from the transfers */
mc = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) {
curl_mfprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break;
}
/* On success the value of maxfd is guaranteed to be >= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if(maxfd == -1) {
rc = curlx_wait_ms(100);
}
else {
/* Note that on some platforms 'timeout' may be modified by select().
If you need access to the original value save a copy beforehand. */
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
}
switch(rc) {
case -1:
/* select error */
break;
case 0: /* timeout */
default: /* action */
curl_multi_perform(multi, &still_running);
break;
}
abort_on_test_timeout();
} while(still_running);
/* See how the transfers went */
do {
msg = curl_multi_info_read(multi, &msgs_left);
if(msg && msg->msg == CURLMSG_DONE) {
curl_mprintf("HTTP transfer completed with status %d\n",
msg->data.result);
break;
}
abort_on_test_timeout();
} while(msg);
test_cleanup:
curl_multi_cleanup(multi);
/* Free the curl handles */
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+87
View File
@@ -0,0 +1,87 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* Test CURLINFO_RESPONSE_CODE */
static CURLcode test_lib1532(const char *URL)
{
CURL *curl;
long httpcode;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
res = curl_easy_perform(curl);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_perform() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(httpcode != 200) {
curl_mfprintf(stderr, "%s:%d unexpected response code %ld\n",
__FILE__, __LINE__, httpcode);
res = CURLE_HTTP_RETURNED_ERROR;
goto test_cleanup;
}
/* Test for a regression of github bug 1017 (response code does not reset) */
curl_easy_reset(curl);
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpcode);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(httpcode) {
curl_mfprintf(stderr,
"%s:%d curl_easy_reset failed to zero the response code\n"
"possible regression of github bug 1017\n",
__FILE__, __LINE__);
res = CURLE_HTTP_RETURNED_ERROR;
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+201
View File
@@ -0,0 +1,201 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This test sends data with CURLOPT_KEEP_SENDING_ON_ERROR.
* The server responds with an early error response.
* The test is successful if the connection can be reused for the next request,
* because this implies that the data has been sent completely to the server.
*/
#include "first.h"
#include "memdebug.h"
struct cb_data {
CURL *curl;
int response_received;
int paused;
size_t remaining_bytes;
};
static void reset_data(struct cb_data *data, CURL *curl)
{
data->curl = curl;
data->response_received = 0;
data->paused = 0;
data->remaining_bytes = 3;
}
static size_t t1533_read_cb(char *ptr, size_t size, size_t nitems, void *userp)
{
struct cb_data *data = (struct cb_data *)userp;
/* wait until the server has sent all response headers */
if(data->response_received) {
size_t totalsize = nitems * size;
size_t bytes_to_send = data->remaining_bytes;
if(bytes_to_send > totalsize) {
bytes_to_send = totalsize;
}
memset(ptr, 'a', bytes_to_send);
data->remaining_bytes -= bytes_to_send;
return bytes_to_send;
}
else {
data->paused = 1;
return CURL_READFUNC_PAUSE;
}
}
static size_t t1533_write_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct cb_data *data = (struct cb_data *)userp;
size_t totalsize = nmemb * size;
(void)ptr;
/* all response headers have been received */
data->response_received = 1;
if(data->paused) {
/* continue to send request body data */
data->paused = 0;
curl_easy_pause(data->curl, CURLPAUSE_CONT);
}
return totalsize;
}
static CURLcode perform_and_check_connections(CURL *curl,
const char *description,
long expected_connections)
{
CURLcode res;
long connections = 0;
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
curl_mfprintf(stderr, "curl_easy_perform() failed with %d\n", res);
return TEST_ERR_MAJOR_BAD;
}
res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connections);
if(res != CURLE_OK) {
curl_mfprintf(stderr, "curl_easy_getinfo() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl_mfprintf(stderr,
"%s: expected: %ld connections; actual: %ld connections\n",
description, expected_connections, connections);
if(connections != expected_connections) {
return TEST_ERR_FAILURE;
}
return TEST_ERR_SUCCESS;
}
static CURLcode test_lib1533(const char *URL)
{
struct cb_data data;
CURL *curl = NULL;
CURLcode res = TEST_ERR_FAILURE;
CURLcode result;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
reset_data(&data, curl);
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_POST, 1L);
test_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)data.remaining_bytes);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_READFUNCTION, t1533_read_cb);
test_setopt(curl, CURLOPT_READDATA, &data);
test_setopt(curl, CURLOPT_WRITEFUNCTION, t1533_write_cb);
test_setopt(curl, CURLOPT_WRITEDATA, &data);
result = perform_and_check_connections(curl,
"First request without CURLOPT_KEEP_SENDING_ON_ERROR", 1);
if(result != TEST_ERR_SUCCESS) {
res = result;
goto test_cleanup;
}
reset_data(&data, curl);
result = perform_and_check_connections(curl,
"Second request without CURLOPT_KEEP_SENDING_ON_ERROR", 1);
if(result != TEST_ERR_SUCCESS) {
res = result;
goto test_cleanup;
}
test_setopt(curl, CURLOPT_KEEP_SENDING_ON_ERROR, 1L);
reset_data(&data, curl);
result = perform_and_check_connections(curl,
"First request with CURLOPT_KEEP_SENDING_ON_ERROR", 1);
if(result != TEST_ERR_SUCCESS) {
res = result;
goto test_cleanup;
}
reset_data(&data, curl);
result = perform_and_check_connections(curl,
"Second request with CURLOPT_KEEP_SENDING_ON_ERROR", 0);
if(result != TEST_ERR_SUCCESS) {
res = result;
goto test_cleanup;
}
res = TEST_ERR_SUCCESS;
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+138
View File
@@ -0,0 +1,138 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* Test CURLINFO_FILETIME */
static CURLcode test_lib1534(const char *URL)
{
CURL *curl, *dupe = NULL;
long filetime;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
/* Test that a filetime is properly initialized on curl_easy_init.
*/
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(filetime != -1) {
curl_mfprintf(stderr,
"%s:%d filetime init failed; expected -1 but is %ld\n",
__FILE__, __LINE__, filetime);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_FILETIME, 1L);
res = curl_easy_perform(curl);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_perform() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
/* Test that a filetime is properly set after receiving an HTTP resource.
*/
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(filetime != 30) {
curl_mfprintf(stderr, "%s:%d filetime of http resource is incorrect; "
"expected 30 but is %ld\n",
__FILE__, __LINE__, filetime);
res = CURLE_HTTP_RETURNED_ERROR;
goto test_cleanup;
}
/* Test that a filetime is properly initialized on curl_easy_duphandle.
*/
dupe = curl_easy_duphandle(curl);
if(!dupe) {
curl_mfprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
res = curl_easy_getinfo(dupe, CURLINFO_FILETIME, &filetime);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(filetime != -1) {
curl_mfprintf(stderr,
"%s:%d filetime init failed; expected -1 but is %ld\n",
__FILE__, __LINE__, filetime);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
/* Test that a filetime is properly initialized on curl_easy_reset.
*/
curl_easy_reset(curl);
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(filetime != -1) {
curl_mfprintf(stderr,
"%s:%d filetime init failed; expected -1 but is %ld\n",
__FILE__, __LINE__, filetime);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl);
curl_easy_cleanup(dupe);
curl_global_cleanup();
return res;
}
+142
View File
@@ -0,0 +1,142 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* Test CURLINFO_PROTOCOL */
static CURLcode test_lib1535(const char *URL)
{
CURL *curl, *dupe = NULL;
long protocol;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
/* Test that protocol is properly initialized on curl_easy_init.
*/
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(protocol) {
curl_mfprintf(stderr,
"%s:%d protocol init failed; expected 0 but is %ld\n",
__FILE__, __LINE__, protocol);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
easy_setopt(curl, CURLOPT_URL, URL);
res = curl_easy_perform(curl);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_perform() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
/* Test that a protocol is properly set after receiving an HTTP resource.
*/
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(protocol != CURLPROTO_HTTP) {
curl_mfprintf(stderr,
"%s:%d protocol of http resource is incorrect; "
"expected %ld but is %ld\n",
__FILE__, __LINE__, CURLPROTO_HTTP, protocol);
res = CURLE_HTTP_RETURNED_ERROR;
goto test_cleanup;
}
/* Test that a protocol is properly initialized on curl_easy_duphandle.
*/
dupe = curl_easy_duphandle(curl);
if(!dupe) {
curl_mfprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(protocol) {
curl_mfprintf(stderr,
"%s:%d protocol init failed; expected 0 but is %ld\n",
__FILE__, __LINE__, protocol);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
/* Test that a protocol is properly initialized on curl_easy_reset.
*/
curl_easy_reset(curl);
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(protocol) {
curl_mfprintf(stderr,
"%s:%d protocol init failed; expected 0 but is %ld\n",
__FILE__, __LINE__, protocol);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl);
curl_easy_cleanup(dupe);
curl_global_cleanup();
return res;
}
+136
View File
@@ -0,0 +1,136 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* Test CURLINFO_SCHEME */
static CURLcode test_lib1536(const char *URL)
{
CURL *curl, *dupe = NULL;
char *scheme;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
/* Test that scheme is properly initialized on curl_easy_init.
*/
res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(scheme) {
curl_mfprintf(stderr,
"%s:%d scheme init failed; expected NULL\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
easy_setopt(curl, CURLOPT_URL, URL);
res = curl_easy_perform(curl);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_perform() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
/* Test that a scheme is properly set after receiving an HTTP resource.
*/
res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(!scheme || memcmp(scheme, "http", 5) != 0) {
curl_mfprintf(stderr, "%s:%d scheme of http resource is incorrect; "
"expected 'http' but is %s\n",
__FILE__, __LINE__,
(scheme == NULL ? "NULL" : "invalid"));
res = CURLE_HTTP_RETURNED_ERROR;
goto test_cleanup;
}
/* Test that a scheme is properly initialized on curl_easy_duphandle.
*/
dupe = curl_easy_duphandle(curl);
if(!dupe) {
curl_mfprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
res = curl_easy_getinfo(dupe, CURLINFO_SCHEME, &scheme);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(scheme) {
curl_mfprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
/* Test that a scheme is properly initialized on curl_easy_reset.
*/
curl_easy_reset(curl);
res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
if(res) {
curl_mfprintf(stderr,
"%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
__FILE__, __LINE__, res, curl_easy_strerror(res));
goto test_cleanup;
}
if(scheme) {
curl_mfprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
__FILE__, __LINE__);
res = CURLE_FAILED_INIT;
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl);
curl_easy_cleanup(dupe);
curl_global_cleanup();
return res;
}
+91
View File
@@ -0,0 +1,91 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1537(const char *URL)
{
const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
CURLcode res = CURLE_OK;
char *ptr = NULL;
int asize;
int outlen = 0;
char *raw;
(void)URL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
asize = (int)sizeof(a);
ptr = curl_easy_escape(NULL, (const char *)a, asize);
curl_mprintf("%s\n", ptr);
curl_free(ptr);
/* deprecated API */
ptr = curl_escape((const char *)a, asize);
if(!ptr) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
curl_mprintf("%s\n", ptr);
raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen);
curl_mprintf("outlen == %d\n", outlen);
curl_mprintf("unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
curl_free(raw);
/* deprecated API */
raw = curl_unescape(ptr, (int)strlen(ptr));
if(!raw) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
outlen = (int)strlen(raw);
curl_mprintf("[old] outlen == %d\n", outlen);
curl_mprintf("[old] unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
curl_free(raw);
curl_free(ptr);
/* weird input length */
ptr = curl_easy_escape(NULL, (const char *)a, -1);
curl_mprintf("escape -1 length: %s\n", ptr);
/* weird input length */
outlen = 2017; /* just a value */
ptr = curl_easy_unescape(NULL, "moahahaha", -1, &outlen);
curl_mprintf("unescape -1 length: %s %d\n", ptr, outlen);
test_cleanup:
curl_free(ptr);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1538(const char *URL)
{
CURLcode res = CURLE_OK;
CURLcode easyret;
CURLMcode multiret;
CURLSHcode shareret;
CURLUcode urlret;
(void)URL;
/* NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
curl_easy_strerror((CURLcode)INT_MAX);
curl_multi_strerror((CURLMcode)INT_MAX);
curl_share_strerror((CURLSHcode)INT_MAX);
curl_url_strerror((CURLUcode)INT_MAX);
curl_easy_strerror((CURLcode)-INT_MAX);
curl_multi_strerror((CURLMcode)-INT_MAX);
curl_share_strerror((CURLSHcode)-INT_MAX);
curl_url_strerror((CURLUcode)-INT_MAX);
/* NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
for(easyret = CURLE_OK; easyret <= CURL_LAST; easyret++) {
curl_mprintf("e%d: %s\n", easyret, curl_easy_strerror(easyret));
}
for(multiret = CURLM_CALL_MULTI_PERFORM; multiret <= CURLM_LAST;
multiret++) {
curl_mprintf("m%d: %s\n", multiret, curl_multi_strerror(multiret));
}
for(shareret = CURLSHE_OK; shareret <= CURLSHE_LAST; shareret++) {
curl_mprintf("s%d: %s\n", shareret, curl_share_strerror(shareret));
}
for(urlret = CURLUE_OK; urlret <= CURLUE_LAST; urlret++) {
curl_mprintf("u%d: %s\n", urlret, curl_url_strerror(urlret));
}
return res;
}
+123
View File
@@ -0,0 +1,123 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
struct t1540_transfer_status {
CURL *curl;
int halted;
int counter; /* count write callback invokes */
int please; /* number of times xferinfo is called while halted */
};
static int please_continue(void *userp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow)
{
struct t1540_transfer_status *st = (struct t1540_transfer_status *)userp;
(void)dltotal;
(void)dlnow;
(void)ultotal;
(void)ulnow;
if(st->halted) {
st->please++;
if(st->please == 2) {
/* waited enough, unpause! */
curl_easy_pause(st->curl, CURLPAUSE_CONT);
}
}
curl_mfprintf(stderr, "xferinfo: paused %d\n", st->halted);
return 0; /* go on */
}
static size_t t1540_header_callback(char *ptr, size_t size, size_t nmemb,
void *userp)
{
size_t len = size * nmemb;
(void)userp;
(void)fwrite(ptr, size, nmemb, stdout);
return len;
}
static size_t t1540_write_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct t1540_transfer_status *st = (struct t1540_transfer_status *)userp;
size_t len = size * nmemb;
st->counter++;
if(st->counter > 1) {
/* the first call puts us on pause, so subsequent calls are after
unpause */
fwrite(ptr, size, nmemb, stdout);
return len;
}
if(len)
curl_mprintf("Got bytes but pausing!\n");
st->halted = 1;
return CURL_WRITEFUNC_PAUSE;
}
static CURLcode test_lib1540(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
struct t1540_transfer_status st;
start_test_timing();
memset(&st, 0, sizeof(st));
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
st.curl = curl; /* to allow callbacks access */
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_WRITEFUNCTION, t1540_write_cb);
easy_setopt(curl, CURLOPT_WRITEDATA, &st);
easy_setopt(curl, CURLOPT_HEADERFUNCTION, t1540_header_callback);
easy_setopt(curl, CURLOPT_HEADERDATA, &st);
easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, please_continue);
easy_setopt(curl, CURLOPT_XFERINFODATA, &st);
easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
debug_config.nohex = TRUE;
debug_config.tracetime = TRUE;
test_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res; /* return the final return code */
}
+150
View File
@@ -0,0 +1,150 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
struct t1541_transfer_status {
CURL *curl;
int hd_count;
int bd_count;
CURLcode result;
};
#define KN(a) a, #a
static void t1541_geterr(const char *name, CURLcode val, int lineno)
{
curl_mprintf("CURLINFO_%s returned %d, \"%s\" on line %d\n",
name, val, curl_easy_strerror(val), lineno);
}
static void report_time(const char *key, const char *where, curl_off_t time,
bool ok)
{
if(ok)
curl_mprintf("%s on %s is OK\n", key, where);
else
curl_mprintf("%s on %s is WRONG: %" CURL_FORMAT_CURL_OFF_T "\n",
key, where, time);
}
static void check_time(CURL *curl, int key, const char *name,
const char *where)
{
curl_off_t tval;
CURLcode res = curl_easy_getinfo(curl, (CURLINFO)key, &tval);
if(res) {
t1541_geterr(name, res, __LINE__);
}
else
report_time(name, where, tval, tval > 0);
}
static void check_time0(CURL *curl, int key, const char *name,
const char *where)
{
curl_off_t tval;
CURLcode res = curl_easy_getinfo(curl, (CURLINFO)key, &tval);
if(res) {
t1541_geterr(name, res, __LINE__);
}
else
report_time(name, where, tval, !tval);
}
static size_t t1541_header_callback(char *ptr, size_t size, size_t nmemb,
void *userp)
{
struct t1541_transfer_status *st = (struct t1541_transfer_status *)userp;
size_t len = size * nmemb;
(void)ptr;
if(!st->hd_count++) {
/* first header, check some CURLINFO value to be reported. See #13125 */
check_time(st->curl, KN(CURLINFO_CONNECT_TIME_T), "1st header");
check_time(st->curl, KN(CURLINFO_PRETRANSFER_TIME_T), "1st header");
check_time(st->curl, KN(CURLINFO_STARTTRANSFER_TIME_T), "1st header");
/* continuously updated */
check_time(st->curl, KN(CURLINFO_TOTAL_TIME_T), "1st header");
/* no SSL, must be 0 */
check_time0(st->curl, KN(CURLINFO_APPCONNECT_TIME_T), "1st header");
/* download not really started */
check_time0(st->curl, KN(CURLINFO_SPEED_DOWNLOAD_T), "1st header");
}
(void)fwrite(ptr, size, nmemb, stdout);
return len;
}
static size_t t1541_write_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
struct t1541_transfer_status *st = (struct t1541_transfer_status *)userp;
(void)ptr;
(void)st;
fwrite(ptr, size, nmemb, stdout);
return size * nmemb;
}
static CURLcode test_lib1541(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
struct t1541_transfer_status st;
start_test_timing();
memset(&st, 0, sizeof(st));
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
st.curl = curl; /* to allow callbacks access */
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_WRITEFUNCTION, t1541_write_cb);
easy_setopt(curl, CURLOPT_WRITEDATA, &st);
easy_setopt(curl, CURLOPT_HEADERFUNCTION, t1541_header_callback);
easy_setopt(curl, CURLOPT_HEADERDATA, &st);
easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(curl);
check_time(curl, KN(CURLINFO_CONNECT_TIME_T), "done");
check_time(curl, KN(CURLINFO_PRETRANSFER_TIME_T), "done");
check_time(curl, KN(CURLINFO_POSTTRANSFER_TIME_T), "done");
check_time(curl, KN(CURLINFO_STARTTRANSFER_TIME_T), "done");
/* no SSL, must be 0 */
check_time0(curl, KN(CURLINFO_APPCONNECT_TIME_T), "done");
check_time(curl, KN(CURLINFO_SPEED_DOWNLOAD_T), "done");
check_time(curl, KN(CURLINFO_TOTAL_TIME_T), "done");
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res; /* return the final return code */
}
+83
View File
@@ -0,0 +1,83 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Test CURLOPT_MAXLIFETIME_CONN:
* Send four requests, sleeping between the second and third and setting
* MAXLIFETIME_CONN between the third and fourth. The first three requests
* should use the same connection, and the fourth request should close the
* first connection and open a second.
*/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static CURLcode test_lib1542(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
res_easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
debug_config.nohex = TRUE;
debug_config.tracetime = FALSE;
easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
/* CURLOPT_MAXLIFETIME_CONN is inclusive - the connection needs to be 2
* seconds old */
curlx_wait_ms(2000);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 1L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+52
View File
@@ -0,0 +1,52 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static CURLcode test_lib1545(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
struct curl_httppost *lastptr = NULL;
struct curl_httppost *m_formpost = NULL;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
curl_formadd(&m_formpost, &lastptr, CURLFORM_COPYNAME, "file",
CURLFORM_FILE, "missing-file", CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, m_formpost);
(void)curl_easy_perform(curl);
(void)curl_easy_perform(curl);
test_cleanup:
curl_formfree(m_formpost);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+76
View File
@@ -0,0 +1,76 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static CURLcode test_lib1549(const char *URL)
{
CURLcode res;
CURL *curl;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_COOKIEFILE, "");
res = curl_easy_perform(curl);
if(!res) {
/* extract all known cookies */
struct curl_slist *cookies = NULL;
int num = 0;
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
if(!res && cookies) {
/* a linked list of cookies in cookie file format */
struct curl_slist *each = cookies;
while(each) {
curl_mprintf("%s\n", each->data);
each = each->next;
num++;
}
/* we must free these cookies when we are done */
curl_slist_free_all(cookies);
}
curl_mfprintf(stderr, "%d cookies\n", num);
}
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+48
View File
@@ -0,0 +1,48 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#include <curl/multi.h>
static CURLcode test_lib1550(const char *URL)
{
CURLM *multi;
CURLcode res = CURLE_OK;
static const char * const bl_servers[] =
{"Microsoft-IIS/6.0", "nginx/0.8.54", NULL};
static const char * const bl_sites[] =
{"curl.se:443", "example.com:80", NULL};
global_init(CURL_GLOBAL_ALL);
multi = curl_multi_init();
(void)URL;
curl_multi_setopt(multi, CURLMOPT_PIPELINING_SERVER_BL, bl_servers);
curl_multi_setopt(multi, CURLMOPT_PIPELINING_SITE_BL, bl_sites);
curl_multi_cleanup(multi);
curl_global_cleanup();
return CURLE_OK;
}
+53
View File
@@ -0,0 +1,53 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#include <curl/multi.h>
static CURLcode test_lib1551(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_mfprintf(stderr, "****************************** Do it again\n");
res = curl_easy_perform(curl);
}
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+92
View File
@@ -0,0 +1,92 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1552(const char *URL)
{
CURL *curl = NULL;
CURLM *multi = NULL;
int still_running;
CURLcode i = CURLE_OK;
CURLcode res = CURLE_OK;
CURLMsg *msg;
int counter = 3;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_USERPWD, "u:s");
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout();
while(still_running && counter--) {
CURLMcode mres;
int num;
mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
if(mres != CURLM_OK) {
curl_mprintf("curl_multi_wait() returned %d\n", mres);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
multi_perform(multi, &still_running);
abort_on_test_timeout();
}
msg = curl_multi_info_read(multi, &still_running);
if(msg)
/* this should now contain a result code from the easy handle,
get it */
i = msg->data.result;
test_cleanup:
/* undocumented cleanup sequence - type UA */
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
if(res)
i = res;
return i; /* return the final return code */
}
+115
View File
@@ -0,0 +1,115 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
static int t1553_xferinfo(void *p,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
(void)p;
(void)dlnow;
(void)dltotal;
(void)ulnow;
(void)ultotal;
curl_mfprintf(stderr, "xferinfo fail!\n");
return 1; /* fail as fast as we can */
}
static CURLcode test_lib1553(const char *URL)
{
CURL *curl = NULL;
CURLM *multi = NULL;
int still_running;
CURLcode i = CURLE_OK;
CURLcode res = CURLE_OK;
curl_mimepart *field = NULL;
curl_mime *mime = NULL;
int counter = 1;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
easy_init(curl);
mime = curl_mime_init(curl);
field = curl_mime_addpart(mime);
curl_mime_name(field, "name");
curl_mime_data(field, "value", CURL_ZERO_TERMINATED);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_HEADER, 1L);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_MIMEPOST, mime);
easy_setopt(curl, CURLOPT_USERPWD, "u:s");
easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, t1553_xferinfo);
easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
debug_config.nohex = TRUE;
debug_config.tracetime = TRUE;
test_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
multi_add_handle(multi, curl);
multi_perform(multi, &still_running);
abort_on_test_timeout();
while(still_running && counter--) {
CURLMcode mres;
int num;
mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
if(mres != CURLM_OK) {
curl_mprintf("curl_multi_wait() returned %d\n", mres);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
multi_perform(multi, &still_running);
abort_on_test_timeout();
}
test_cleanup:
curl_mime_free(mime);
curl_multi_remove_handle(multi, curl);
curl_multi_cleanup(multi);
curl_easy_cleanup(curl);
curl_global_cleanup();
if(res)
i = res;
return i; /* return the final return code */
}
+108
View File
@@ -0,0 +1,108 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static const char *ldata_names[] = {
"NONE",
"SHARE",
"COOKIE",
"DNS",
"SESSION",
"CONNECT",
"PSL",
"HSTS",
"NULL",
};
static void t1554_test_lock(CURL *curl, curl_lock_data data,
curl_lock_access laccess, void *useptr)
{
(void)curl;
(void)data;
(void)laccess;
(void)useptr;
curl_mprintf("-> Mutex lock %s\n", ldata_names[data]);
}
static void t1554_test_unlock(CURL *curl, curl_lock_data data, void *useptr)
{
(void)curl;
(void)data;
(void)useptr;
curl_mprintf("<- Mutex unlock %s\n", ldata_names[data]);
}
/* test function */
static CURLcode test_lib1554(const char *URL)
{
CURLcode res = CURLE_OK;
CURLSH *share = NULL;
int i;
global_init(CURL_GLOBAL_ALL);
share = curl_share_init();
if(!share) {
curl_mfprintf(stderr, "curl_share_init() failed\n");
goto test_cleanup;
}
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
curl_share_setopt(share, CURLSHOPT_LOCKFUNC, t1554_test_lock);
curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, t1554_test_unlock);
/* Loop the transfer and cleanup the handle properly every lap. This will
still reuse connections since the pool is in the shared object! */
for(i = 0; i < 3; i++) {
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
/* use the share object */
curl_easy_setopt(curl, CURLOPT_SHARE, share);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
/* Check for errors */
if(res != CURLE_OK) {
curl_mfprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
goto test_cleanup;
}
}
}
test_cleanup:
curl_share_cleanup(share);
curl_global_cleanup();
return res;
}
+81
View File
@@ -0,0 +1,81 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* Verify that some API functions are locked from being called inside callback
*/
#include "first.h"
#include "memdebug.h"
static CURL *t1555_curl;
static int progressCallback(void *arg,
double dltotal,
double dlnow,
double ultotal,
double ulnow)
{
CURLcode res = CURLE_OK;
char buffer[256];
size_t n = 0;
(void)arg;
(void)dltotal;
(void)dlnow;
(void)ultotal;
(void)ulnow;
res = curl_easy_recv(t1555_curl, buffer, 256, &n);
curl_mprintf("curl_easy_recv returned %d\n", res);
res = curl_easy_send(t1555_curl, buffer, n, &n);
curl_mprintf("curl_easy_send returned %d\n", res);
return 1;
}
static CURLcode test_lib1555(const char *URL)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(t1555_curl);
easy_setopt(t1555_curl, CURLOPT_URL, URL);
easy_setopt(t1555_curl, CURLOPT_TIMEOUT, 7L);
easy_setopt(t1555_curl, CURLOPT_NOSIGNAL, 1L);
easy_setopt(t1555_curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
easy_setopt(t1555_curl, CURLOPT_PROGRESSDATA, NULL);
easy_setopt(t1555_curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(t1555_curl);
test_cleanup:
/* undocumented cleanup sequence - type UA */
curl_easy_cleanup(t1555_curl);
curl_global_cleanup();
return res;
}
+78
View File
@@ -0,0 +1,78 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
struct headerinfo {
size_t largest;
};
static size_t header(char *ptr, size_t size, size_t nmemb, void *stream)
{
size_t headersize = size * nmemb;
struct headerinfo *info = (struct headerinfo *)stream;
(void)ptr;
if(headersize > info->largest)
/* remember the longest header */
info->largest = headersize;
return nmemb * size;
}
static CURLcode test_lib1556(const char *URL)
{
CURLcode code;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
struct headerinfo info = {0};
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_HEADERFUNCTION, header);
easy_setopt(curl, CURLOPT_HEADERDATA, &info);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_URL, URL);
code = curl_easy_perform(curl);
if(CURLE_OK != code) {
curl_mfprintf(stderr, "%s:%d curl_easy_perform() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
curl_mprintf("Max = %zu\n", info.largest);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1557(const char *URL)
{
CURLM *multi = NULL;
CURL *curl1 = NULL;
CURL *curl2 = NULL;
int running_handles = 0;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, 1L);
easy_init(curl1);
easy_setopt(curl1, CURLOPT_URL, URL);
multi_add_handle(multi, curl1);
easy_init(curl2);
easy_setopt(curl2, CURLOPT_URL, URL);
multi_add_handle(multi, curl2);
multi_perform(multi, &running_handles);
multi_remove_handle(multi, curl2);
/* If curl2 is still in the connect-pending list, this will crash */
multi_remove_handle(multi, curl1);
test_cleanup:
curl_easy_cleanup(curl1);
curl_easy_cleanup(curl2);
curl_multi_cleanup(multi);
curl_global_cleanup();
return res;
}
+65
View File
@@ -0,0 +1,65 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1558(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl = NULL;
long protocol = 0;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
res = curl_easy_perform(curl);
if(res) {
curl_mfprintf(stderr, "curl_easy_perform() returned %d (%s)\n",
res, curl_easy_strerror(res));
goto test_cleanup;
}
res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
if(res) {
curl_mfprintf(stderr, "curl_easy_getinfo() returned %d (%s)\n",
res, curl_easy_strerror(res));
goto test_cleanup;
}
curl_mprintf("Protocol: %lx\n", protocol);
curl_easy_cleanup(curl);
curl_global_cleanup();
return CURLE_OK;
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res; /* return the final return code */
}
+78
View File
@@ -0,0 +1,78 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1559(const char *URL)
{
static const int EXCESSIVE = 10*1000*1000;
CURLcode res = CURLE_OK;
CURL *curl = NULL;
char *longurl = NULL;
CURLU *u;
(void)URL;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
longurl = malloc(EXCESSIVE);
if(!longurl) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
memset(longurl, 'a', EXCESSIVE);
longurl[EXCESSIVE-1] = 0;
res = curl_easy_setopt(curl, CURLOPT_URL, longurl);
curl_mprintf("CURLOPT_URL %d bytes URL == %d\n",
EXCESSIVE, res);
res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, longurl);
curl_mprintf("CURLOPT_POSTFIELDS %d bytes data == %d\n",
EXCESSIVE, res);
u = curl_url();
if(u) {
CURLUcode uc = curl_url_set(u, CURLUPART_URL, longurl, 0);
curl_mprintf("CURLUPART_URL %d bytes URL == %d (%s)\n",
EXCESSIVE, uc, curl_url_strerror(uc));
uc = curl_url_set(u, CURLUPART_SCHEME, longurl, CURLU_NON_SUPPORT_SCHEME);
curl_mprintf("CURLUPART_SCHEME %d bytes scheme == %d (%s)\n",
EXCESSIVE, uc, curl_url_strerror(uc));
uc = curl_url_set(u, CURLUPART_USER, longurl, 0);
curl_mprintf("CURLUPART_USER %d bytes user == %d (%s)\n",
EXCESSIVE, uc, curl_url_strerror(uc));
curl_url_cleanup(u);
}
test_cleanup:
free(longurl);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res; /* return the final return code */
}
File diff suppressed because it is too large Load Diff
+132
View File
@@ -0,0 +1,132 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#define WAKEUP_NUM 10
static CURLcode test_lib1564(const char *URL)
{
CURLM *multi = NULL;
int numfds;
int i;
CURLcode res = CURLE_OK;
struct curltime time_before_wait, time_after_wait;
(void)URL;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
/* no wakeup */
time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
time_after_wait = curlx_now();
if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
/* try a single wakeup */
res_multi_wakeup(multi);
time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
time_after_wait = curlx_now();
if(curlx_timediff(time_after_wait, time_before_wait) > 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
/* previous wakeup should not wake up this */
time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
time_after_wait = curlx_now();
if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
/* try lots of wakeup */
for(i = 0; i < WAKEUP_NUM; ++i)
res_multi_wakeup(multi);
time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
time_after_wait = curlx_now();
if(curlx_timediff(time_after_wait, time_before_wait) > 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
/* Even lots of previous wakeups should not wake up this. */
time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
time_after_wait = curlx_now();
if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
test_cleanup:
curl_multi_cleanup(multi);
curl_global_cleanup();
return res;
}
+207
View File
@@ -0,0 +1,207 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#define CONN_NUM 3
#define TIME_BETWEEN_START_SECS 2
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static CURL *pending_curls[CONN_NUM];
static int pending_num = 0;
static CURLcode t1565_test_failure = CURLE_OK;
static CURLM *testmulti = NULL;
static const char *t1565_url;
static void *t1565_run_thread(void *ptr)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
int i;
(void)ptr;
for(i = 0; i < CONN_NUM; i++) {
curlx_wait_ms(TIME_BETWEEN_START_SECS * 1000);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, t1565_url);
easy_setopt(curl, CURLOPT_VERBOSE, 0L);
pthread_mutex_lock(&lock);
if(t1565_test_failure) {
pthread_mutex_unlock(&lock);
goto test_cleanup;
}
pending_curls[pending_num] = curl;
pending_num++;
curl = NULL;
pthread_mutex_unlock(&lock);
res_multi_wakeup(testmulti);
}
test_cleanup:
curl_easy_cleanup(curl);
pthread_mutex_lock(&lock);
if(!t1565_test_failure)
t1565_test_failure = res;
pthread_mutex_unlock(&lock);
return NULL;
}
static CURLcode test_lib1565(const char *URL)
{
int still_running;
int num;
int i;
int result;
CURLcode res = CURLE_OK;
CURL *started_curls[CONN_NUM];
int started_num = 0;
int finished_num = 0;
pthread_t tid = 0;
bool tid_valid = false;
struct CURLMsg *message;
start_test_timing();
global_init(CURL_GLOBAL_ALL);
multi_init(testmulti);
t1565_url = URL;
result = pthread_create(&tid, NULL, t1565_run_thread, NULL);
if(!result)
tid_valid = true;
else {
curl_mfprintf(stderr, "%s:%d Couldn't create thread, errno %d\n",
__FILE__, __LINE__, result);
goto test_cleanup;
}
while(1) {
multi_perform(testmulti, &still_running);
abort_on_test_timeout();
while((message = curl_multi_info_read(testmulti, &num))) {
if(message->msg == CURLMSG_DONE) {
res = message->data.result;
if(res)
goto test_cleanup;
multi_remove_handle(testmulti, message->easy_handle);
finished_num++;
}
else {
curl_mfprintf(stderr,
"%s:%d Got an unexpected message from curl: %i\n",
__FILE__, __LINE__, message->msg);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
abort_on_test_timeout();
}
if(CONN_NUM == finished_num)
break;
multi_poll(testmulti, NULL, 0, TEST_HANG_TIMEOUT, &num);
abort_on_test_timeout();
pthread_mutex_lock(&lock);
while(pending_num > 0) {
res_multi_add_handle(testmulti, pending_curls[pending_num - 1]);
if(res) {
pthread_mutex_unlock(&lock);
goto test_cleanup;
}
started_curls[started_num] = pending_curls[pending_num - 1];
started_num++;
pending_num--;
}
pthread_mutex_unlock(&lock);
abort_on_test_timeout();
}
if(CONN_NUM != started_num) {
curl_mfprintf(stderr, "%s:%d Not all connections started: %d of %d\n",
__FILE__, __LINE__, started_num, CONN_NUM);
goto test_cleanup;
}
if(CONN_NUM != finished_num) {
curl_mfprintf(stderr, "%s:%d Not all connections finished: %d of %d\n",
__FILE__, __LINE__, started_num, CONN_NUM);
goto test_cleanup;
}
test_cleanup:
pthread_mutex_lock(&lock);
if(!t1565_test_failure)
t1565_test_failure = res;
pthread_mutex_unlock(&lock);
if(tid_valid)
pthread_join(tid, NULL);
curl_multi_cleanup(testmulti);
for(i = 0; i < pending_num; i++)
curl_easy_cleanup(pending_curls[i]);
for(i = 0; i < started_num; i++)
curl_easy_cleanup(started_curls[i]);
curl_global_cleanup();
return t1565_test_failure;
}
#else /* without pthread, this test doesn't work */
static CURLcode test_lib1565(const char *URL)
{
(void)URL;
return CURLE_OK;
}
#endif
+59
View File
@@ -0,0 +1,59 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#include <curl/multi.h>
static CURLcode test_lib1567(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
CURLU *u = NULL;
global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
u = curl_url();
if(u) {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_url_set(u, CURLUPART_URL, URL, 0);
curl_easy_setopt(curl, CURLOPT_CURLU, u);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_mfprintf(stderr, "****************************** Do it again\n");
res = curl_easy_perform(curl);
}
}
test_cleanup:
curl_url_cleanup(u);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+51
View File
@@ -0,0 +1,51 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1568(const char *URL)
{
CURLcode ret;
CURL *curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
curl_easy_setopt(curl, CURLOPT_USERPWD, "testuser:testpass");
curl_easy_setopt(curl, CURLOPT_USERAGENT, "lib1568");
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(curl, CURLOPT_PORT, atol(libtest_arg2));
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl = NULL;
curl_global_cleanup();
return ret;
}
+50
View File
@@ -0,0 +1,50 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1569(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_HEADER, 1L);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_easy_setopt(curl, CURLOPT_URL, libtest_arg2);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+72
View File
@@ -0,0 +1,72 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1571(const char *URL)
{
CURLcode res;
CURL *curl;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_URL, URL);
if((testnum == 1571) || (testnum == 1572) ||
(testnum == 1575) || (testnum == 1581)) {
test_setopt(curl, CURLOPT_POSTFIELDS, "moo");
}
if(testnum == 1581) {
test_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_301);
}
test_setopt(curl, CURLOPT_CUSTOMREQUEST, "IGLOO");
if((testnum == 1574) || (testnum == 1575)) {
test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_FIRSTONLY);
}
else {
test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_OBEYCODE);
}
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+95
View File
@@ -0,0 +1,95 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static char t1576_testdata[] = "request indicates that the client, which made";
static size_t t1576_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
size_t amount = nmemb * size; /* Total bytes curl wants */
if(amount < strlen(t1576_testdata)) {
return strlen(t1576_testdata);
}
(void)stream;
memcpy(ptr, t1576_testdata, strlen(t1576_testdata));
return strlen(t1576_testdata);
}
static int t1576_seek_callback(void *ptr, curl_off_t offset, int origin)
{
(void)ptr;
(void)offset;
if(origin != SEEK_SET)
return CURL_SEEKFUNC_FAIL;
return CURL_SEEKFUNC_OK;
}
static CURLcode test_lib1576(const char *URL)
{
CURLcode res;
CURL *curl;
struct curl_slist *pHeaderList = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_READFUNCTION, t1576_read_cb);
test_setopt(curl, CURLOPT_SEEKFUNCTION, t1576_seek_callback);
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1576_testdata));
test_setopt(curl, CURLOPT_CUSTOMREQUEST, "CURL");
if(testnum == 1578 || testnum == 1580) {
test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_FIRSTONLY);
}
else {
test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_OBEYCODE);
}
/* Remove "Expect: 100-continue" */
pHeaderList = curl_slist_append(pHeaderList, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
curl_slist_free_all(pHeaderList);
return res;
}
+60
View File
@@ -0,0 +1,60 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1582(const char *URL)
{
CURLcode res;
CURL *curl;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_NEGOTIATE);
test_setopt(curl, CURLOPT_USERPWD, ":");
test_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
test_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+120
View File
@@ -0,0 +1,120 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This unit test PUT http data over proxy. Proxy header will be different
* from server http header
*/
#include "first.h"
#include "memdebug.h"
static size_t consumed = 0;
static size_t t1591_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
static const char testdata[] = "Hello Cloud!\r\n";
size_t amount = nmemb * size; /* Total bytes curl wants */
if(consumed == strlen(testdata)) {
return 0;
}
if(amount > strlen(testdata) - consumed) {
amount = strlen(testdata);
}
consumed += amount;
(void)stream;
memcpy(ptr, testdata, amount);
return amount;
}
/*
* carefully not leak memory on OOM
*/
static int t1591_trailers_callback(struct curl_slist **list, void *userdata)
{
struct curl_slist *nlist = NULL;
struct curl_slist *nlist2 = NULL;
(void)userdata;
nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
if(nlist)
nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
if(nlist2) {
*list = nlist2;
return CURL_TRAILERFUNC_OK;
}
else {
curl_slist_free_all(nlist);
return CURL_TRAILERFUNC_ABORT;
}
}
static CURLcode test_lib1591(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http and proxy header list */
struct curl_slist *hhl = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer,"
" my-other-awesome-trailer");
if(!hhl) {
goto test_cleanup;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_READFUNCTION, t1591_read_cb);
test_setopt(curl, CURLOPT_TRAILERFUNCTION, t1591_trailers_callback);
test_setopt(curl, CURLOPT_TRAILERDATA, NULL);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_global_cleanup();
return res;
}
+121
View File
@@ -0,0 +1,121 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* See https://github.com/curl/curl/issues/3371
*
* This test case checks whether curl_multi_remove_handle() cancels
* asynchronous DNS resolvers without blocking where possible. Obviously, it
* only tests whichever resolver cURL is actually built with.
*/
/* We're willing to wait a very generous two seconds for the removal. This is
as low as we can go while still easily supporting SIGALRM timing for the
non-threaded blocking resolver. It doesn't matter that much because when
the test passes, we never wait this long. We set it much higher via
the default TEST_HANG_TIMEOUT to avoid issues when running on overloaded
CI machines. */
#include "first.h"
static CURLcode test_lib1592(const char *URL)
{
int stillRunning;
CURLM *multi = NULL;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
CURLMcode mres;
long timeout;
global_init(CURL_GLOBAL_ALL);
multi_init(multi);
easy_init(curl);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_URL, URL);
/* Set a DNS server that hopefully will not respond when using c-ares. */
if(curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, "0.0.0.0") == CURLE_OK)
/* Since we could set the DNS server, presume we are working with a
resolver that can be cancelled (i.e. c-ares). Thus,
curl_multi_remove_handle() should not block even when the resolver
request is outstanding. So, set a request timeout _longer_ than the
test hang timeout so we will fail if the handle removal call incorrectly
blocks. */
timeout = TEST_HANG_TIMEOUT * 2;
else {
/* If we can't set the DNS server, presume that we are configured to use a
resolver that can't be cancelled (i.e. the threaded resolver or the
non-threaded blocking resolver). So, we just test that the
curl_multi_remove_handle() call does finish well within our test
timeout.
But, it is very unlikely that the resolver request will take any time at
all because we haven't been able to configure the resolver to use an
non-responsive DNS server. At least we exercise the flow.
*/
curl_mfprintf(stderr,
"CURLOPT_DNS_SERVERS not supported; "
"assuming curl_multi_remove_handle() will block\n");
timeout = TEST_HANG_TIMEOUT / 2;
}
/* Setting a timeout on the request should ensure that even if we have to
wait for the resolver during curl_multi_remove_handle(), it won't take
longer than this, because the resolver request inherits its timeout from
this. */
easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout);
multi_add_handle(multi, curl);
/* This should move the handle from INIT => CONNECT => WAITRESOLVE. */
curl_mfprintf(stderr, "curl_multi_perform()...\n");
multi_perform(multi, &stillRunning);
curl_mfprintf(stderr, "curl_multi_perform() succeeded\n");
/* Start measuring how long it takes to remove the handle. */
curl_mfprintf(stderr, "curl_multi_remove_handle()...\n");
start_test_timing();
mres = curl_multi_remove_handle(multi, curl);
if(mres) {
curl_mfprintf(stderr,
"curl_multi_remove_handle() failed, with code %d\n", mres);
res = TEST_ERR_MULTI;
goto test_cleanup;
}
curl_mfprintf(stderr, "curl_multi_remove_handle() succeeded\n");
/* Fail the test if it took too long to remove. This happens after the fact,
and says "it seems that it would have run forever", which isn't true, but
it's close enough, and simple to do. */
abort_on_test_timeout();
test_cleanup:
curl_easy_cleanup(curl);
curl_multi_cleanup(multi);
curl_global_cleanup();
return res;
}
+81
View File
@@ -0,0 +1,81 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* Test suppressing the If-Modified-Since header */
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1593(const char *URL)
{
struct curl_slist *header = NULL;
long unmet;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
/* Some TIMEVALUE; it doesn't matter. */
easy_setopt(curl, CURLOPT_TIMEVALUE, 1566210680L);
header = curl_slist_append(NULL, "If-Modified-Since:");
if(!header) {
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
easy_setopt(curl, CURLOPT_HTTPHEADER, header);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
/* Confirm that the condition checking still worked, even though we
* suppressed the actual header.
* The server returns 304, which means the condition is "unmet".
*/
res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
if(res)
goto test_cleanup;
if(unmet != 1L) {
res = TEST_ERR_FAILURE;
goto test_cleanup;
}
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_slist_free_all(header);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* Testing Retry-After header parser */
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1594(const char *URL)
{
struct curl_slist *header = NULL;
curl_off_t retry;
CURL *curl = NULL;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
res = curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry);
if(res)
goto test_cleanup;
curl_mprintf("Retry-After %" CURL_FORMAT_CURL_OFF_T "\n", retry);
test_cleanup:
/* always cleanup */
curl_easy_cleanup(curl);
curl_slist_free_all(header);
curl_global_cleanup();
return res;
}
+112
View File
@@ -0,0 +1,112 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/* Testing CURLOPT_PROTOCOLS_STR */
#include "first.h"
#include "memdebug.h"
struct pair {
const char *in;
CURLcode *exp;
};
static CURLcode test_lib1597(const char *URL)
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
curl_version_info_data *curlinfo;
const char *const *proto;
int n;
int i;
static CURLcode ok = CURLE_OK;
static CURLcode bad = CURLE_BAD_FUNCTION_ARGUMENT;
static CURLcode unsup = CURLE_UNSUPPORTED_PROTOCOL;
static CURLcode httpcode = CURLE_UNSUPPORTED_PROTOCOL;
static CURLcode httpscode = CURLE_UNSUPPORTED_PROTOCOL;
static char protolist[1024];
static const struct pair prots[] = {
{"goobar", &unsup},
{"http ", &unsup},
{" http", &unsup},
{"http", &httpcode},
{"http,", &httpcode},
{"https,", &httpscode},
{"https,http", &httpscode},
{"http,http", &httpcode},
{"HTTP,HTTP", &httpcode},
{",HTTP,HTTP", &httpcode},
{"http,http,ft", &unsup},
{"", &bad},
{",,", &bad},
{protolist, &ok},
{"all", &ok},
{NULL, NULL},
};
(void)URL;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
/* Get enabled protocols.*/
curlinfo = curl_version_info(CURLVERSION_NOW);
if(!curlinfo) {
fputs("curl_version_info failed\n", stderr);
res = TEST_ERR_FAILURE;
goto test_cleanup;
}
n = 0;
for(proto = curlinfo->protocols; *proto; proto++) {
if((size_t) n >= sizeof(protolist)) {
puts("protolist buffer too small\n");
res = TEST_ERR_FAILURE;
goto test_cleanup;
}
n += curl_msnprintf(protolist + n, sizeof(protolist) - n, ",%s", *proto);
if(curl_strequal(*proto, "http"))
httpcode = CURLE_OK;
if(curl_strequal(*proto, "https"))
httpscode = CURLE_OK;
}
/* Run the tests. */
for(i = 0; prots[i].in; i++) {
res = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
if(res != *prots[i].exp) {
curl_mprintf("unexpectedly '%s' returned %d\n", prots[i].in, res);
break;
}
}
curl_mprintf("Tested %u strings\n", i);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+106
View File
@@ -0,0 +1,106 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* This unit test PUT http data over proxy. Proxy header will be different
* from server http header
*/
#include "first.h"
#include "memdebug.h"
/*
* carefully not leak memory on OOM
*/
static int t1598_trailers_callback(struct curl_slist **list, void *userdata)
{
struct curl_slist *nlist = NULL;
struct curl_slist *nlist2 = NULL;
(void)userdata;
nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
if(nlist)
nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
if(nlist2) {
*list = nlist2;
return CURL_TRAILERFUNC_OK;
}
else {
curl_slist_free_all(nlist);
return CURL_TRAILERFUNC_ABORT;
}
}
static CURLcode test_lib1598(const char *URL)
{
static const char *post_data = "xxx=yyy&aaa=bbbbb";
CURL *curl = NULL;
CURLcode res = CURLE_FAILED_INIT;
/* http and proxy header list */
struct curl_slist *hhl = NULL, *list;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer,"
" my-other-awesome-trailer");
if(!hhl)
goto test_cleanup;
if(hhl) {
list = curl_slist_append(hhl, "Transfer-Encoding: chunked");
if(!list)
goto test_cleanup;
hhl = list;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(post_data));
test_setopt(curl, CURLOPT_POSTFIELDS, post_data);
test_setopt(curl, CURLOPT_TRAILERFUNCTION, t1598_trailers_callback);
test_setopt(curl, CURLOPT_TRAILERDATA, NULL);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(hhl);
curl_global_cleanup();
return res;
}
+44
View File
@@ -0,0 +1,44 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
static CURLcode test_lib1599(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_NETRC_FILE, libtest_arg2);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return res;
}
+88
View File
@@ -0,0 +1,88 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
struct t1662_WriteThis {
size_t sizeleft;
};
static size_t t1662_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
{
static const char testdata[] = "mooaaa";
struct t1662_WriteThis *pooh = (struct t1662_WriteThis *)userp;
size_t len = strlen(testdata);
if(size*nmemb < len)
return 0;
if(pooh->sizeleft) {
memcpy(ptr, testdata, strlen(testdata));
pooh->sizeleft = 0;
return len;
}
return 0; /* no more data left to deliver */
}
static CURLcode test_lib1662(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl;
curl_mime *mime1;
curl_mimepart *part1;
struct t1662_WriteThis pooh = { 1 };
mime1 = NULL;
global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
mime1 = curl_mime_init(curl);
if(mime1) {
part1 = curl_mime_addpart(mime1);
curl_mime_data_cb(part1, -1, t1662_read_cb, NULL, NULL, &pooh);
curl_mime_filename(part1, "poetry.txt");
curl_mime_name(part1, "content");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime1);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/2000");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
res = curl_easy_perform(curl);
}
}
curl_easy_cleanup(curl);
curl_mime_free(mime1);
curl_global_cleanup();
return res;
}
+53
View File
@@ -0,0 +1,53 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1900(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl1 = NULL;
CURL *curl2 = NULL;
global_init(CURL_GLOBAL_ALL);
easy_init(curl1);
easy_setopt(curl1, CURLOPT_URL, URL);
easy_setopt(curl1, CURLOPT_HSTS, "first-hsts.txt");
easy_setopt(curl1, CURLOPT_HSTS, "second-hsts.txt");
curl2 = curl_easy_duphandle(curl1);
curl_easy_cleanup(curl1);
curl_easy_cleanup(curl2);
curl_global_cleanup();
return CURLE_OK;
test_cleanup:
curl_easy_cleanup(curl1);
curl_easy_cleanup(curl2);
curl_global_cleanup();
return res;
}
+89
View File
@@ -0,0 +1,89 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static size_t t1901_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
{
static const char *chunks[] = {
"one",
"two",
"three",
"four",
NULL
};
static int ix = 0;
(void)size;
(void)nmemb;
(void)stream;
if(chunks[ix]) {
size_t len = strlen(chunks[ix]);
strcpy(ptr, chunks[ix]);
ix++;
return len;
}
return 0;
}
static CURLcode test_lib1901(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *chunk = NULL;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
/* deliberately setting the size - to a wrong value to make sure libcurl
ignores it */
easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 4L);
easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
easy_setopt(curl, CURLOPT_READFUNCTION, t1901_read_cb);
easy_setopt(curl, CURLOPT_POST, 1L);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_READDATA, NULL);
chunk = curl_slist_append(chunk, "Expect:");
if(chunk) {
struct curl_slist *n =
curl_slist_append(chunk, "Transfer-Encoding: chunked");
if(n)
chunk = n;
if(n)
easy_setopt(curl, CURLOPT_HTTPHEADER, n);
}
res = curl_easy_perform(curl);
}
test_cleanup:
curl_easy_cleanup(curl);
curl_slist_free_all(chunk);
curl_global_cleanup();
return res;
}
+48
View File
@@ -0,0 +1,48 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1902(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
easy_setopt(curl, CURLOPT_COOKIEFILE, URL);
easy_setopt(curl, CURLOPT_COOKIEJAR, URL);
/* Do not perform any actual network operation,
the issue occur when not calling curl.*perform */
}
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+54
View File
@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1903(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl = NULL;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_COOKIEFILE, libtest_arg2);
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
curl_easy_reset(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_COOKIEFILE, libtest_arg2);
easy_setopt(curl, CURLOPT_COOKIEJAR, libtest_arg3);
res = curl_easy_perform(curl);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+97
View File
@@ -0,0 +1,97 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1905(const char *URL)
{
CURLSH *share = NULL;
CURL *curl = NULL;
int unfinished;
CURLM *multi;
curl_global_init(CURL_GLOBAL_ALL);
multi = curl_multi_init();
if(!multi) {
curl_global_cleanup();
return TEST_ERR_MULTI;
}
share = curl_share_init();
if(!share)
goto cleanup;
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
curl = curl_easy_init();
if(!curl)
goto cleanup;
curl_easy_setopt(curl, CURLOPT_SHARE, share);
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, libtest_arg2);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, libtest_arg2);
curl_multi_add_handle(multi, curl);
unfinished = 1;
while(unfinished) {
int MAX = 0;
long max_tout;
fd_set R, W, E;
struct timeval timeout;
FD_ZERO(&R);
FD_ZERO(&W);
FD_ZERO(&E);
curl_multi_perform(multi, &unfinished);
curl_multi_fdset(multi, &R, &W, &E, &MAX);
curl_multi_timeout(multi, &max_tout);
if(max_tout > 0) {
curlx_mstotv(&timeout, max_tout);
}
else {
timeout.tv_sec = 0;
timeout.tv_usec = 1000;
}
select(MAX + 1, &R, &W, &E, &timeout);
}
curl_easy_setopt(curl, CURLOPT_COOKIELIST, "FLUSH");
curl_easy_setopt(curl, CURLOPT_SHARE, NULL);
curl_multi_remove_handle(multi, curl);
cleanup:
curl_easy_cleanup(curl);
curl_share_cleanup(share);
curl_multi_cleanup(multi);
curl_global_cleanup();
return CURLE_OK;
}
+83
View File
@@ -0,0 +1,83 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1906(const char *URL)
{
CURLcode res = CURLE_OK;
char *url_after = NULL;
CURLU *curlu = curl_url();
char error_buffer[CURL_ERROR_SIZE] = "";
CURL *curl;
easy_init(curl);
curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME);
easy_setopt(curl, CURLOPT_CURLU, curlu);
easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* msys2 times out instead of CURLE_COULDNT_CONNECT, so make it faster */
easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000L);
/* set a port number that makes this request fail */
easy_setopt(curl, CURLOPT_PORT, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) {
curl_mfprintf(stderr, "failure expected, "
"curl_easy_perform returned %d: <%s>, <%s>\n",
res, curl_easy_strerror(res), error_buffer);
if(res == CURLE_OK)
res = TEST_ERR_MAJOR_BAD; /* force an error return */
goto test_cleanup;
}
res = CURLE_OK; /* reset for next use */
/* print the used url */
curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
curl_mfprintf(stderr, "curlu now: <%s>\n", url_after);
curl_free(url_after);
url_after = NULL;
/* now reset CURLOP_PORT to go back to originally set port number */
easy_setopt(curl, CURLOPT_PORT, 0L);
res = curl_easy_perform(curl);
if(res)
curl_mfprintf(stderr, "success expected, "
"curl_easy_perform returned %d: <%s>, <%s>\n",
res, curl_easy_strerror(res), error_buffer);
/* print url */
curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
curl_mfprintf(stderr, "curlu now: <%s>\n", url_after);
test_cleanup:
curl_free(url_after);
curl_easy_cleanup(curl);
curl_url_cleanup(curlu);
curl_global_cleanup();
return res;
}
+54
View File
@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1907(const char *URL)
{
char *url_after;
CURL *curl;
CURLcode res = CURLE_OK;
char error_buffer[CURL_ERROR_SIZE] = "";
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(!res)
curl_mfprintf(stderr, "failure expected, "
"curl_easy_perform returned %d: <%s>, <%s>\n",
res, curl_easy_strerror(res), error_buffer);
/* print the used url */
if(!curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url_after))
curl_mprintf("Effective URL: %s\n", url_after);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1908(const char *URL)
{
CURLcode ret = CURLE_OK;
CURL *curl;
start_test_timing();
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_ALTSVC, libtest_arg2);
ret = curl_easy_perform(curl);
if(!ret) {
/* make a copy and check that this also has alt-svc activated */
CURL *curldupe = curl_easy_duphandle(curl);
if(curldupe) {
ret = curl_easy_perform(curldupe);
/* we close the second handle first, which makes it store the alt-svc
file only to get overwritten when the next handle is closed! */
curl_easy_cleanup(curldupe);
}
}
curl_easy_reset(curl);
/* using the same file name for the alt-svc cache, this clobbers the
content just written from the 'curldupe' handle */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return ret;
}
+47
View File
@@ -0,0 +1,47 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1910(const char *URL)
{
CURLcode ret = CURLE_OK;
CURL *curl;
start_test_timing();
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_USERPWD, "user\nname:pass\nword");
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return ret;
}
+94
View File
@@ -0,0 +1,94 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
/* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal
define not publicly exposed so we set our own */
#define MAX_INPUT_LENGTH 8000000
static CURLcode test_lib1911(const char *URL)
{
static char testbuf[MAX_INPUT_LENGTH + 2];
const struct curl_easyoption *o;
CURL *curl;
int error = 0;
(void)URL;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(!curl) {
curl_global_cleanup();
return TEST_ERR_EASY_INIT;
}
/* make it a null-terminated C string with just As */
memset(testbuf, 'A', MAX_INPUT_LENGTH + 1);
testbuf[MAX_INPUT_LENGTH + 1] = 0;
curl_mprintf("string length: %zu\n", strlen(testbuf));
for(o = curl_easy_option_next(NULL);
o;
o = curl_easy_option_next(o)) {
if(o->type == CURLOT_STRING) {
CURLcode result;
/*
* Whitelist string options that are safe for abuse
*/
switch(o->id) {
case CURLOPT_PROXY_TLSAUTH_TYPE:
case CURLOPT_TLSAUTH_TYPE:
case CURLOPT_RANDOM_FILE:
case CURLOPT_EGDSOCKET:
continue;
default:
/* check this */
break;
}
/* This is a string. Make sure that passing in a string longer
CURL_MAX_INPUT_LENGTH returns an error */
result = curl_easy_setopt(curl, o->id, testbuf);
switch(result) {
case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */
case CURLE_UNKNOWN_OPTION: /* left out from the build */
case CURLE_NOT_BUILT_IN: /* not supported */
case CURLE_UNSUPPORTED_PROTOCOL: /* detected by protocol2num() */
break;
default:
/* all other return codes are unexpected */
curl_mfprintf(stderr, "curl_easy_setopt(%s...) returned %d\n",
o->name, result);
error++;
break;
}
}
}
curl_easy_cleanup(curl);
curl_global_cleanup();
return error == 0 ? CURLE_OK : TEST_ERR_FAILURE;
}
+81
View File
@@ -0,0 +1,81 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
#define print_err(name, exp) \
curl_mfprintf(stderr, "Type mismatch for CURLOPT_%s (expected %s)\n", \
name, exp)
static CURLcode test_lib1912(const char *URL)
{
/* Only test if GCC typechecking is available */
int error = 0;
#ifdef CURLINC_TYPECHECK_GCC_H
const struct curl_easyoption *o;
for(o = curl_easy_option_next(NULL);
o;
o = curl_easy_option_next(o)) {
/* Test for mismatch OR missing typecheck macros */
if(curlcheck_long_option(o->id) !=
(o->type == CURLOT_LONG || o->type == CURLOT_VALUES)) {
print_err(o->name, "CURLOT_LONG or CURLOT_VALUES");
error++;
}
if(curlcheck_off_t_option(o->id) != (o->type == CURLOT_OFF_T)) {
print_err(o->name, "CURLOT_OFF_T");
error++;
}
if(curlcheck_string_option(o->id) != (o->type == CURLOT_STRING)) {
print_err(o->name, "CURLOT_STRING");
error++;
}
if(curlcheck_slist_option(o->id) != (o->type == CURLOT_SLIST)) {
print_err(o->name, "CURLOT_SLIST");
error++;
}
if(curlcheck_cb_data_option(o->id) != (o->type == CURLOT_CBPTR)) {
print_err(o->name, "CURLOT_CBPTR");
error++;
}
/* From here: only test that the type matches if macro is known */
if(curlcheck_write_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_conv_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) {
print_err(o->name, "CURLOT_FUNCTION");
error++;
}
if(curlcheck_postfields_option(o->id) && (o->type != CURLOT_OBJECT)) {
print_err(o->name, "CURLOT_OBJECT");
error++;
}
/* Todo: no gcc typecheck for CURLOPTTYPE_BLOB types? */
}
#endif
(void)URL;
return error == 0 ? CURLE_OK : TEST_ERR_FAILURE;
}
+48
View File
@@ -0,0 +1,48 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1913(const char *URL)
{
CURLcode ret = CURLE_OK;
CURL *curl;
start_test_timing();
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
if(libtest_arg2)
/* test1914 sets this extra arg */
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return ret;
}
+148
View File
@@ -0,0 +1,148 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "testtrace.h"
#include "memdebug.h"
struct state {
int index;
};
/* "read" is from the point of the library, it wants data from us */
static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e,
void *userp)
{
struct entry {
const char *name;
const char *exp;
};
static const struct entry preload_hosts[] = {
#if (SIZEOF_TIME_T < 5)
{ "1.example.com", "20370320 01:02:03" },
{ "2.example.com", "20370320 03:02:01" },
{ "3.example.com", "20370319 01:02:03" },
#else
{ "1.example.com", "25250320 01:02:03" },
{ "2.example.com", "25250320 03:02:01" },
{ "3.example.com", "25250319 01:02:03" },
#endif
{ "4.example.com", "" },
{ NULL, NULL } /* end of list marker */
};
const char *host;
const char *expire;
struct state *s = (struct state *)userp;
(void)curl;
host = preload_hosts[s->index].name;
expire = preload_hosts[s->index++].exp;
if(host && (strlen(host) < e->namelen)) {
strcpy(e->name, host);
e->includeSubDomains = FALSE;
strcpy(e->expire, expire);
curl_mfprintf(stderr, "add '%s'\n", host);
}
else
return CURLSTS_DONE;
return CURLSTS_OK;
}
/* verify error from callback */
static CURLSTScode hstsreadfail(CURL *curl, struct curl_hstsentry *e,
void *userp)
{
(void)curl;
(void)e;
(void)userp;
return CURLSTS_FAIL;
}
/* check that we get the hosts back in the save */
static CURLSTScode hstswrite(CURL *curl, struct curl_hstsentry *e,
struct curl_index *i, void *userp)
{
(void)curl;
(void)userp;
curl_mprintf("[%zu/%zu] %s %s\n", i->index, i->total, e->name, e->expire);
return CURLSTS_OK;
}
/*
* Read/write HSTS cache entries via callback.
*/
static CURLcode test_lib1915(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl;
struct state st = {0};
global_init(CURL_GLOBAL_ALL);
debug_config.nohex = TRUE;
debug_config.tracetime = TRUE;
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);
easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hstsread);
easy_setopt(curl, CURLOPT_HSTSREADDATA, &st);
easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &st);
easy_setopt(curl, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl = NULL;
if(res == CURLE_OPERATION_TIMEDOUT) /* we expect that on Windows */
res = CURLE_COULDNT_CONNECT;
curl_mprintf("First request returned %d\n", res);
res = CURLE_OK;
easy_init(curl);
easy_setopt(curl, CURLOPT_URL, URL);
easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1L);
easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hstsreadfail);
easy_setopt(curl, CURLOPT_HSTSREADDATA, &st);
easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &st);
easy_setopt(curl, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl = NULL;
curl_mprintf("Second request returned %d\n", res);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+56
View File
@@ -0,0 +1,56 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1916(const char *URL)
{
CURL *curl;
CURLcode res = CURLE_OK;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
if(testnum == 1917) {
/* without any postfields set! */
curl_easy_setopt(curl, CURLOPT_POST, 1L);
}
else {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
}
res = curl_easy_perform(curl);
if(res) {
curl_mprintf("res: %d\n", res);
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return res;
}
+54
View File
@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1918(const char *URL)
{
const struct curl_easyoption *o;
(void)URL;
curl_global_init(CURL_GLOBAL_ALL);
for(o = curl_easy_option_next(NULL);
o;
o = curl_easy_option_next(o)) {
const struct curl_easyoption *ename =
curl_easy_option_by_name(o->name);
const struct curl_easyoption *eid =
curl_easy_option_by_id(o->id);
if(ename->id != o->id) {
curl_mprintf("name lookup id %d doesn't match %d\n",
ename->id, o->id);
}
else if(eid->id != o->id) {
curl_mprintf("ID lookup %d doesn't match %d\n",
ename->id, o->id);
}
}
curl_global_cleanup();
return CURLE_OK;
}
+54
View File
@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1919(const char *URL)
{
CURLcode res = CURLE_OK;
CURL *curl;
int i;
global_init(CURL_GLOBAL_ALL);
easy_init(curl);
easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
easy_setopt(curl, CURLOPT_XOAUTH2_BEARER,
"c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1");
easy_setopt(curl, CURLOPT_SASL_AUTHZID,
"c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2");
easy_setopt(curl, CURLOPT_URL, URL);
for(i = 0; i < 2; i++) {
/* the second request needs to do connection reuse */
res = curl_easy_perform(curl);
if(res)
goto test_cleanup;
}
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}
+68
View File
@@ -0,0 +1,68 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "first.h"
#include "memdebug.h"
static CURLcode test_lib1933(const char *URL)
{
CURL *curl;
CURLcode res = TEST_ERR_MAJOR_BAD;
struct curl_slist *connect_to = NULL;
struct curl_slist *list = NULL;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_AWS_SIGV4, "xxx");
test_setopt(curl, CURLOPT_HEADER, 0L);
test_setopt(curl, CURLOPT_URL, URL);
if(libtest_arg2) {
connect_to = curl_slist_append(connect_to, libtest_arg2);
}
test_setopt(curl, CURLOPT_CONNECT_TO, connect_to);
list = curl_slist_append(list, "Content-Type: application/json");
test_setopt(curl, CURLOPT_HTTPHEADER, list);
res = curl_easy_perform(curl);
test_cleanup:
curl_slist_free_all(connect_to);
curl_slist_free_all(list);
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}

Some files were not shown because too many files have changed in this diff Show More