mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-07-01 14:37:10 +02:00
Initial preparations for CURL and Discord integration.
This commit is contained in:
114
module/Vendor/CURL/src/CMakeLists.txt
vendored
Normal file
114
module/Vendor/CURL/src/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2020, 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.
|
||||
#
|
||||
###########################################################################
|
||||
set(EXE_NAME curl)
|
||||
|
||||
if(USE_MANUAL)
|
||||
# Use the C locale to ensure that only ASCII characters appear in the
|
||||
# embedded text. NROFF and MANOPT are set in the parent CMakeLists.txt
|
||||
add_custom_command(
|
||||
OUTPUT tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_setup.h\"" > tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#ifndef HAVE_LIBZ" >> tool_hugehelp.c
|
||||
COMMAND env LC_ALL=C "${NROFF}" ${NROFF_MANOPT}
|
||||
"${CURL_BINARY_DIR}/docs/curl.1" |
|
||||
"${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" >> tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#else" >> tool_hugehelp.c
|
||||
COMMAND env LC_ALL=C "${NROFF}" ${NROFF_MANOPT}
|
||||
"${CURL_BINARY_DIR}/docs/curl.1" |
|
||||
"${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" -c >> tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#endif /* HAVE_LIBZ */" >> tool_hugehelp.c
|
||||
DEPENDS
|
||||
generate-curl.1
|
||||
"${CURL_BINARY_DIR}/docs/curl.1"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h"
|
||||
VERBATIM)
|
||||
else()
|
||||
add_custom_command(
|
||||
OUTPUT tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "/* built-in manual is disabled, blank function */" > tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_hugehelp.h\"" >> tool_hugehelp.c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "void hugehelp(void) {}" >> tool_hugehelp.c
|
||||
DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h"
|
||||
VERBATIM)
|
||||
|
||||
endif()
|
||||
|
||||
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
||||
|
||||
if(MSVC)
|
||||
list(APPEND CURL_FILES curl.rc)
|
||||
endif()
|
||||
|
||||
# CURL_FILES comes from Makefile.inc
|
||||
add_executable(
|
||||
${EXE_NAME}
|
||||
${CURL_FILES}
|
||||
)
|
||||
|
||||
add_executable(
|
||||
${PROJECT_NAME}::${EXE_NAME}
|
||||
ALIAS ${EXE_NAME}
|
||||
)
|
||||
|
||||
if(CURL_HAS_LTO)
|
||||
set_target_properties(${EXE_NAME} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
||||
endif()
|
||||
|
||||
if(ENABLE_UNICODE AND MINGW)
|
||||
target_link_libraries(${EXE_NAME} -municode)
|
||||
# GCC doesn't know about wmain
|
||||
set_source_files_properties(tool_main.c PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-missing-declarations")
|
||||
endif()
|
||||
|
||||
source_group("curlX source files" FILES ${CURLX_CFILES})
|
||||
source_group("curl source files" FILES ${CURL_CFILES})
|
||||
source_group("curl header files" FILES ${CURL_HFILES})
|
||||
|
||||
include_directories(
|
||||
${CURL_SOURCE_DIR}/lib # To be able to reach "curl_setup_once.h"
|
||||
${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h"
|
||||
${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h"
|
||||
# This is needed as tool_hugehelp.c is generated in the binary dir
|
||||
${CURL_SOURCE_DIR}/src # To be able to reach "tool_hugehelp.h"
|
||||
)
|
||||
|
||||
#Build curl executable
|
||||
target_link_libraries(${EXE_NAME} libcurl ${CURL_LIBS})
|
||||
|
||||
################################################################################
|
||||
|
||||
#SET_TARGET_PROPERTIES(${EXE_NAME} ARCHIVE_OUTPUT_DIRECTORY "blah blah blah")
|
||||
#SET_TARGET_PROPERTIES(${EXE_NAME} RUNTIME_OUTPUT_DIRECTORY "blah blah blah")
|
||||
#SET_TARGET_PROPERTIES(${EXE_NAME} LIBRARY_OUTPUT_DIRECTORY "blah blah blah")
|
||||
|
||||
#INCLUDE(ModuleInstall OPTIONAL)
|
||||
|
||||
install(TARGETS ${EXE_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
export(TARGETS ${EXE_NAME}
|
||||
APPEND FILE ${PROJECT_BINARY_DIR}/curl-target.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
)
|
155
module/Vendor/CURL/src/Makefile.am
vendored
Normal file
155
module/Vendor/CURL/src/Makefile.am
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2020, 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.
|
||||
#
|
||||
###########################################################################
|
||||
AUTOMAKE_OPTIONS = foreign nostdinc
|
||||
|
||||
# remove targets if the command fails
|
||||
.DELETE_ON_ERROR:
|
||||
|
||||
# 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_builddir)/src is for curl's generated src/curl_config.h file
|
||||
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
|
||||
# $(top_srcdir)/src is for curl's src/tool_setup.h and "curl-private" files
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_builddir)/src \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
bin_PROGRAMS = curl
|
||||
|
||||
SUBDIRS = ../docs
|
||||
|
||||
if USE_CPPFLAG_CURL_STATICLIB
|
||||
AM_CPPFLAGS += -DCURL_STATICLIB
|
||||
endif
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
# CURL_FILES comes from Makefile.inc
|
||||
curl_SOURCES = $(CURL_FILES)
|
||||
|
||||
# This might hold -Werror
|
||||
CFLAGS += @CURL_CFLAG_EXTRAS@
|
||||
|
||||
# Prevent LIBS from being used for all link targets
|
||||
LIBS = $(BLANK_AT_MAKETIME)
|
||||
|
||||
if USE_EXPLICIT_LIB_DEPS
|
||||
curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@
|
||||
else
|
||||
curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @SSL_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@
|
||||
endif
|
||||
|
||||
curl_LDFLAGS = @LIBMETALINK_LDFLAGS@
|
||||
curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS)
|
||||
|
||||
# if unit tests are enabled, build a static library to link them with
|
||||
if BUILD_UNITTESTS
|
||||
noinst_LTLIBRARIES = libcurltool.la
|
||||
libcurltool_la_CPPFLAGS = $(LIBMETALINK_CPPFLAGS) $(AM_CPPFLAGS) \
|
||||
-DCURL_STATICLIB -DUNITTESTS
|
||||
libcurltool_la_CFLAGS =
|
||||
libcurltool_la_LDFLAGS = -static $(LINKFLAGS)
|
||||
libcurltool_la_SOURCES = $(curl_SOURCES)
|
||||
endif
|
||||
|
||||
CLEANFILES = tool_hugehelp.c
|
||||
# Use the C locale to ensure that only ASCII characters appear in the
|
||||
# embedded text.
|
||||
NROFF=env LC_ALL=C @NROFF@ @MANOPT@ # figured out by the configure script
|
||||
|
||||
EXTRA_DIST = mkhelp.pl makefile.dj \
|
||||
Makefile.m32 macos/curl.mcp.xml.sit.hqx macos/MACINSTALL.TXT \
|
||||
macos/src/curl_GUSIConfig.cpp macos/src/macos_main.cpp makefile.amiga \
|
||||
curl.rc Makefile.netware Makefile.inc CMakeLists.txt
|
||||
|
||||
# Use absolute directory to disable VPATH
|
||||
MANPAGE=$(abs_top_builddir)/docs/curl.1
|
||||
MKHELP=$(top_srcdir)/src/mkhelp.pl
|
||||
HUGE=tool_hugehelp.c
|
||||
|
||||
HUGECMD = $(HUGEIT_$(V))
|
||||
HUGEIT_0 = @echo " HUGE " $@;
|
||||
HUGEIT_1 =
|
||||
HUGEIT_ = $(HUGEIT_0)
|
||||
|
||||
CHECKSRC = $(CS_$(V))
|
||||
CS_0 = @echo " RUN " $@;
|
||||
CS_1 =
|
||||
CS_ = $(CS_0)
|
||||
|
||||
if USE_MANUAL
|
||||
# Here are the stuff to create a built-in manual
|
||||
|
||||
$(MANPAGE):
|
||||
cd $(top_builddir)/docs && $(MAKE)
|
||||
|
||||
if HAVE_LIBZ
|
||||
# This generates the tool_hugehelp.c file in both uncompressed and
|
||||
# compressed formats.
|
||||
$(HUGE): $(MANPAGE) $(MKHELP)
|
||||
$(HUGECMD) (echo '#include "tool_setup.h"' > $(HUGE); \
|
||||
echo '#ifndef HAVE_LIBZ' >> $(HUGE); \
|
||||
$(NROFF) $(MANPAGE) | $(PERL) $(MKHELP) >> $(HUGE); \
|
||||
echo '#else' >> $(HUGE); \
|
||||
$(NROFF) $(MANPAGE) | $(PERL) $(MKHELP) -c >> $(HUGE); \
|
||||
echo '#endif /* HAVE_LIBZ */' >> $(HUGE) )
|
||||
else # HAVE_LIBZ
|
||||
# This generates the tool_hugehelp.c file uncompressed only
|
||||
$(HUGE): $(MANPAGE) $(MKHELP)
|
||||
$(HUGECMD)(echo '#include "tool_setup.h"' > $(HUGE); \
|
||||
$(NROFF) $(MANPAGE) | $(PERL) $(MKHELP) >> $(HUGE) )
|
||||
endif
|
||||
|
||||
else # USE_MANUAL
|
||||
# built-in manual has been disabled, make a blank file
|
||||
$(HUGE):
|
||||
$(HUGECMD)(echo "/* built-in manual is disabled, blank function */" > $(HUGE); \
|
||||
echo '#include "tool_hugehelp.h"' >> $(HUGE); \
|
||||
echo "void hugehelp(void) {}" >>$(HUGE) )
|
||||
endif
|
||||
|
||||
# ignore tool_hugehelp.c since it is generated source code and it plays
|
||||
# by slightly different rules!
|
||||
checksrc:
|
||||
$(CHECKSRC)(@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(srcdir) \
|
||||
-W$(srcdir)/tool_hugehelp.c $(srcdir)/*.[ch])
|
||||
|
||||
if CURLDEBUG
|
||||
# for debug builds, we scan the sources on all regular make invokes
|
||||
all-local: checksrc
|
||||
endif
|
||||
|
||||
# disable the tests that are mostly causing false positives
|
||||
TIDYFLAGS=-checks=-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-optin.performance.Padding,-clang-analyzer-valist.Uninitialized,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-core.NullDereference
|
||||
|
||||
TIDY:=clang-tidy
|
||||
|
||||
tidy:
|
||||
$(TIDY) $(CURL_CFILES) $(TIDYFLAGS) -- $(curl_CPPFLAGS) $(CPPFLAGS) -DHAVE_CONFIG_H
|
144
module/Vendor/CURL/src/Makefile.inc
vendored
Normal file
144
module/Vendor/CURL/src/Makefile.inc
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2020, 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.
|
||||
#
|
||||
###########################################################################
|
||||
# ./src/Makefile.inc
|
||||
# Using the backslash as line continuation character might be problematic
|
||||
# with some make flavours, as Watcom's wmake showed us already. If we
|
||||
# ever want to change this in a portable manner then we should consider
|
||||
# this idea (posted to the libcurl list by Adam Kellas):
|
||||
# CSRC1 = file1.c file2.c file3.c
|
||||
# CSRC2 = file4.c file5.c file6.c
|
||||
# CSOURCES = $(CSRC1) $(CSRC2)
|
||||
|
||||
# libcurl has sources that provide functions named curlx_* that aren't part of
|
||||
# the official API, but we re-use the code here to avoid duplication.
|
||||
CURLX_CFILES = \
|
||||
../lib/strtoofft.c \
|
||||
../lib/nonblock.c \
|
||||
../lib/warnless.c \
|
||||
../lib/curl_ctype.c \
|
||||
../lib/curl_multibyte.c \
|
||||
../lib/version_win32.c \
|
||||
../lib/dynbuf.c
|
||||
|
||||
CURLX_HFILES = \
|
||||
../lib/curl_setup.h \
|
||||
../lib/strtoofft.h \
|
||||
../lib/nonblock.h \
|
||||
../lib/warnless.h \
|
||||
../lib/curl_ctype.h \
|
||||
../lib/curl_multibyte.h \
|
||||
../lib/version_win32.h \
|
||||
../lib/dynbuf.h
|
||||
|
||||
CURL_CFILES = \
|
||||
slist_wc.c \
|
||||
tool_binmode.c \
|
||||
tool_bname.c \
|
||||
tool_cb_dbg.c \
|
||||
tool_cb_hdr.c \
|
||||
tool_cb_prg.c \
|
||||
tool_cb_rea.c \
|
||||
tool_cb_see.c \
|
||||
tool_cb_wrt.c \
|
||||
tool_cfgable.c \
|
||||
tool_convert.c \
|
||||
tool_dirhie.c \
|
||||
tool_doswin.c \
|
||||
tool_easysrc.c \
|
||||
tool_filetime.c \
|
||||
tool_formparse.c \
|
||||
tool_getparam.c \
|
||||
tool_getpass.c \
|
||||
tool_help.c \
|
||||
tool_helpers.c \
|
||||
tool_homedir.c \
|
||||
tool_hugehelp.c \
|
||||
tool_libinfo.c \
|
||||
tool_main.c \
|
||||
tool_metalink.c \
|
||||
tool_msgs.c \
|
||||
tool_operate.c \
|
||||
tool_operhlp.c \
|
||||
tool_panykey.c \
|
||||
tool_paramhlp.c \
|
||||
tool_parsecfg.c \
|
||||
tool_progress.c \
|
||||
tool_strdup.c \
|
||||
tool_setopt.c \
|
||||
tool_sleep.c \
|
||||
tool_urlglob.c \
|
||||
tool_util.c \
|
||||
tool_vms.c \
|
||||
tool_writeout.c \
|
||||
tool_writeout_json.c \
|
||||
tool_xattr.c
|
||||
|
||||
CURL_HFILES = \
|
||||
slist_wc.h \
|
||||
tool_binmode.h \
|
||||
tool_bname.h \
|
||||
tool_cb_dbg.h \
|
||||
tool_cb_hdr.h \
|
||||
tool_cb_prg.h \
|
||||
tool_cb_rea.h \
|
||||
tool_cb_see.h \
|
||||
tool_cb_wrt.h \
|
||||
tool_cfgable.h \
|
||||
tool_convert.h \
|
||||
tool_dirhie.h \
|
||||
tool_doswin.h \
|
||||
tool_easysrc.h \
|
||||
tool_filetime.h \
|
||||
tool_formparse.h \
|
||||
tool_getparam.h \
|
||||
tool_getpass.h \
|
||||
tool_help.h \
|
||||
tool_helpers.h \
|
||||
tool_homedir.h \
|
||||
tool_hugehelp.h \
|
||||
tool_libinfo.h \
|
||||
tool_main.h \
|
||||
tool_metalink.h \
|
||||
tool_msgs.h \
|
||||
tool_operate.h \
|
||||
tool_operhlp.h \
|
||||
tool_panykey.h \
|
||||
tool_paramhlp.h \
|
||||
tool_parsecfg.h \
|
||||
tool_progress.h \
|
||||
tool_sdecls.h \
|
||||
tool_setopt.h \
|
||||
tool_setup.h \
|
||||
tool_sleep.h \
|
||||
tool_strdup.h \
|
||||
tool_urlglob.h \
|
||||
tool_util.h \
|
||||
tool_version.h \
|
||||
tool_vms.h \
|
||||
tool_writeout.h \
|
||||
tool_writeout_json.h \
|
||||
tool_xattr.h
|
||||
|
||||
CURL_RCFILES = curl.rc
|
||||
|
||||
# curl_SOURCES is special and gets assigned in src/Makefile.am
|
||||
CURL_FILES = $(CURL_CFILES) $(CURLX_CFILES) $(CURL_HFILES)
|
447
module/Vendor/CURL/src/Makefile.m32
vendored
Normal file
447
module/Vendor/CURL/src/Makefile.m32
vendored
Normal file
@ -0,0 +1,447 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1999 - 2020, 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.
|
||||
#
|
||||
#***************************************************************************
|
||||
|
||||
###########################################################################
|
||||
#
|
||||
## Makefile for building curl.exe with MingW (GCC-3.2 or later or LLVM/Clang)
|
||||
## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4),
|
||||
## brotli (1.0.1), zstd (1.4.5)
|
||||
##
|
||||
## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
|
||||
## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
|
||||
##
|
||||
## Hint: you can also set environment vars to control the build, f.e.:
|
||||
## set ZLIB_PATH=c:/zlib-1.2.8
|
||||
## set ZLIB=1
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
# Edit the path below to point to the base of your Zlib sources.
|
||||
ifndef ZLIB_PATH
|
||||
ZLIB_PATH = ../../zlib-1.2.8
|
||||
endif
|
||||
# Edit the path below to point to the base of your Zstandard sources.
|
||||
ifndef ZSTD_PATH
|
||||
ZSTD_PATH = ../../zstd-1.4.5
|
||||
endif
|
||||
# Edit the path below to point to the base of your Brotli sources.
|
||||
ifndef BROTLI_PATH
|
||||
BROTLI_PATH = ../../brotli-1.0.1
|
||||
endif
|
||||
# Edit the path below to point to the base of your OpenSSL package.
|
||||
ifndef OPENSSL_PATH
|
||||
OPENSSL_PATH = ../../openssl-1.0.2a
|
||||
endif
|
||||
# Edit the path below to point to the base of your LibSSH2 package.
|
||||
ifndef LIBSSH2_PATH
|
||||
LIBSSH2_PATH = ../../libssh2-1.5.0
|
||||
endif
|
||||
# Edit the path below to point to the base of your librtmp package.
|
||||
ifndef LIBRTMP_PATH
|
||||
LIBRTMP_PATH = ../../librtmp-2.4
|
||||
endif
|
||||
# Edit the path below to point to the base of your libmetalink package.
|
||||
ifndef LIBMETALINK_PATH
|
||||
LIBMETALINK_PATH = ../../libmetalink-0.1.3
|
||||
endif
|
||||
# Edit the path below to point to the base of your libexpat package.
|
||||
ifndef LIBEXPAT_PATH
|
||||
LIBEXPAT_PATH = ../../expat-2.1.0
|
||||
endif
|
||||
# Edit the path below to point to the base of your libxml2 package.
|
||||
ifndef LIBXML2_PATH
|
||||
LIBXML2_PATH = ../../libxml2-2.9.2
|
||||
endif
|
||||
# Edit the path below to point to the base of your libidn2 package.
|
||||
ifndef LIBIDN2_PATH
|
||||
LIBIDN2_PATH = ../../libidn2-2.0.3
|
||||
endif
|
||||
# Edit the path below to point to the base of your MS IDN package.
|
||||
# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
|
||||
# https://www.microsoft.com/en-us/download/details.aspx?id=734
|
||||
ifndef WINIDN_PATH
|
||||
WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
|
||||
endif
|
||||
# Edit the path below to point to the base of your Novell LDAP NDK.
|
||||
ifndef LDAP_SDK
|
||||
LDAP_SDK = c:/novell/ndk/cldapsdk/win32
|
||||
endif
|
||||
# Edit the path below to point to the base of your nghttp2 package.
|
||||
ifndef NGHTTP2_PATH
|
||||
NGHTTP2_PATH = ../../nghttp2-1.0.0
|
||||
endif
|
||||
# Edit the path below to point to the base of your nghttp3 package.
|
||||
ifndef NGHTTP3_PATH
|
||||
NGHTTP3_PATH = ../../nghttp3-1.0.0
|
||||
endif
|
||||
# Edit the path below to point to the base of your ngtcp2 package.
|
||||
ifndef NGTCP2_PATH
|
||||
NGTCP2_PATH = ../../ngtcp2-1.0.0
|
||||
endif
|
||||
|
||||
PROOT = ..
|
||||
|
||||
# Edit the path below to point to the base of your c-ares package.
|
||||
ifndef LIBCARES_PATH
|
||||
LIBCARES_PATH = $(PROOT)/ares
|
||||
endif
|
||||
|
||||
ifeq ($(CURL_CC),)
|
||||
CURL_CC := $(CROSSPREFIX)gcc
|
||||
endif
|
||||
ifeq ($(CURL_AR),)
|
||||
CURL_AR := $(CROSSPREFIX)ar
|
||||
endif
|
||||
|
||||
CC = $(CURL_CC)
|
||||
CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
|
||||
CFLAGS += -fno-strict-aliasing
|
||||
# comment LDFLAGS below to keep debug info
|
||||
LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
|
||||
AR = $(CURL_AR)
|
||||
RC = $(CROSSPREFIX)windres
|
||||
RCFLAGS = --include-dir=$(PROOT)/include -O coff -DCURL_EMBED_MANIFEST
|
||||
STRIP = $(CROSSPREFIX)strip -g
|
||||
|
||||
# We may need these someday
|
||||
# PERL = perl
|
||||
# NROFF = nroff
|
||||
|
||||
# Set environment var ARCH to your architecture to override autodetection.
|
||||
ifndef ARCH
|
||||
ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
|
||||
ARCH = w64
|
||||
else
|
||||
ARCH = w32
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),w64)
|
||||
CFLAGS += -m64 -D_AMD64_
|
||||
LDFLAGS += -m64
|
||||
RCFLAGS += -F pe-x86-64
|
||||
else
|
||||
CFLAGS += -m32
|
||||
LDFLAGS += -m32
|
||||
RCFLAGS += -F pe-i386
|
||||
endif
|
||||
|
||||
# Platform-dependent helper tool macros
|
||||
ifeq ($(findstring /sh,$(SHELL)),/sh)
|
||||
DEL = rm -f $1
|
||||
RMDIR = rm -fr $1
|
||||
MKDIR = mkdir -p $1
|
||||
COPY = -cp -afv $1 $2
|
||||
#COPYR = -cp -afr $1/* $2
|
||||
COPYR = -rsync -aC $1/* $2
|
||||
TOUCH = touch $1
|
||||
CAT = cat
|
||||
ECHONL = echo ""
|
||||
DL = '
|
||||
else
|
||||
ifeq "$(OS)" "Windows_NT"
|
||||
DEL = -del 2>NUL /q /f $(subst /,\,$1)
|
||||
RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
|
||||
else
|
||||
DEL = -del 2>NUL $(subst /,\,$1)
|
||||
RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
|
||||
endif
|
||||
MKDIR = -md 2>NUL $(subst /,\,$1)
|
||||
COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
|
||||
COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
|
||||
TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
|
||||
CAT = type
|
||||
ECHONL = $(ComSpec) /c echo.
|
||||
endif
|
||||
|
||||
########################################################
|
||||
## Nothing more to do below this line!
|
||||
|
||||
ifeq ($(findstring -dyn,$(CFG)),-dyn)
|
||||
DYN = 1
|
||||
endif
|
||||
ifeq ($(findstring -ares,$(CFG)),-ares)
|
||||
ARES = 1
|
||||
endif
|
||||
ifeq ($(findstring -sync,$(CFG)),-sync)
|
||||
SYNC = 1
|
||||
endif
|
||||
ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
|
||||
RTMP = 1
|
||||
SSL = 1
|
||||
ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
|
||||
SSH2 = 1
|
||||
SSL = 1
|
||||
ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -ssl,$(CFG)),-ssl)
|
||||
SSL = 1
|
||||
endif
|
||||
ifeq ($(findstring -zlib,$(CFG)),-zlib)
|
||||
ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -zstd,$(CFG)),-zstd)
|
||||
ZSTD = 1
|
||||
endif
|
||||
ifeq ($(findstring -brotli,$(CFG)),-brotli)
|
||||
BROTLI = 1
|
||||
endif
|
||||
ifeq ($(findstring -idn2,$(CFG)),-idn2)
|
||||
IDN2 = 1
|
||||
endif
|
||||
ifeq ($(findstring -winidn,$(CFG)),-winidn)
|
||||
WINIDN = 1
|
||||
endif
|
||||
ifeq ($(findstring -sspi,$(CFG)),-sspi)
|
||||
SSPI = 1
|
||||
endif
|
||||
ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
|
||||
LDAPS = 1
|
||||
endif
|
||||
ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
|
||||
IPV6 = 1
|
||||
endif
|
||||
ifeq ($(findstring -metalink,$(CFG)),-metalink)
|
||||
METALINK = 1
|
||||
endif
|
||||
ifeq ($(findstring -winssl,$(CFG)),-winssl)
|
||||
WINSSL = 1
|
||||
SSPI = 1
|
||||
endif
|
||||
ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
|
||||
NGHTTP2 = 1
|
||||
endif
|
||||
ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3)
|
||||
NGHTTP3 = 1
|
||||
endif
|
||||
ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2)
|
||||
NGTCP2 = 1
|
||||
endif
|
||||
ifeq ($(findstring -unicode,$(CFG)),-unicode)
|
||||
UNICODE = 1
|
||||
endif
|
||||
|
||||
INCLUDES = -I. -I../include -I../lib
|
||||
ifdef SSL
|
||||
ifdef WINSSL
|
||||
CFLAGS += -DCURL_WITH_MULTI_SSL
|
||||
endif
|
||||
endif
|
||||
ifdef UNICODE
|
||||
CFLAGS += -DUNICODE -D_UNICODE
|
||||
LDFLAGS += -municode
|
||||
endif
|
||||
|
||||
ifdef DYN
|
||||
curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
|
||||
curl_LDADD = -L$(PROOT)/lib -lcurldll
|
||||
else
|
||||
curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
|
||||
curl_LDADD = -L$(PROOT)/lib -lcurl
|
||||
CFLAGS += -DCURL_STATICLIB
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
ifdef SYNC
|
||||
CFLAGS += -DUSE_SYNC_DNS
|
||||
else
|
||||
ifdef ARES
|
||||
ifndef DYN
|
||||
curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
|
||||
endif
|
||||
CFLAGS += -DUSE_ARES -DCARES_STATICLIB
|
||||
curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
|
||||
endif
|
||||
endif
|
||||
ifdef RTMP
|
||||
CFLAGS += -DUSE_LIBRTMP
|
||||
curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
|
||||
endif
|
||||
ifdef NGHTTP2
|
||||
CFLAGS += -DUSE_NGHTTP2
|
||||
curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
|
||||
endif
|
||||
ifdef SSH2
|
||||
CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
|
||||
curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
|
||||
ifdef WINSSL
|
||||
ifndef DYN
|
||||
curl_LDADD += -lbcrypt -lcrypt32
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifdef SSL
|
||||
ifdef NGHTTP3
|
||||
CFLAGS += -DUSE_NGHTTP3
|
||||
curl_LDADD += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
|
||||
ifdef NGTCP2
|
||||
CFLAGS += -DUSE_NGTCP2
|
||||
curl_LDADD += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl
|
||||
endif
|
||||
endif
|
||||
|
||||
ifndef OPENSSL_INCLUDE
|
||||
ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
|
||||
OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
|
||||
endif
|
||||
ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
|
||||
OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
|
||||
endif
|
||||
endif
|
||||
ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
|
||||
$(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
|
||||
endif
|
||||
ifndef OPENSSL_LIBPATH
|
||||
OPENSSL_LIBS = -lssl -lcrypto
|
||||
ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
|
||||
OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
|
||||
ifdef DYN
|
||||
OPENSSL_LIBS = -lssl32 -leay32
|
||||
endif
|
||||
endif
|
||||
ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
|
||||
OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
|
||||
endif
|
||||
endif
|
||||
ifndef DYN
|
||||
OPENSSL_LIBS += -lgdi32 -lcrypt32
|
||||
endif
|
||||
INCLUDES += -I"$(OPENSSL_INCLUDE)"
|
||||
CFLAGS += -DUSE_OPENSSL
|
||||
curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
|
||||
endif
|
||||
ifdef WINSSL
|
||||
CFLAGS += -DUSE_SCHANNEL
|
||||
curl_LDADD += -lcrypt32
|
||||
endif
|
||||
ifdef ZLIB
|
||||
INCLUDES += -I"$(ZLIB_PATH)"
|
||||
CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
|
||||
curl_LDADD += -L"$(ZLIB_PATH)" -lz
|
||||
endif
|
||||
ifdef ZSTD
|
||||
INCLUDES += -I"$(ZSTD_PATH)/include"
|
||||
CFLAGS += -DHAVE_ZSTD
|
||||
curl_LDADD += -L"$(ZSTD_PATH)/lib"
|
||||
ifdef ZSTD_LIBS
|
||||
curl_LDADD += $(ZSTD_LIBS)
|
||||
else
|
||||
curl_LDADD += -lzstd
|
||||
endif
|
||||
endif
|
||||
ifdef BROTLI
|
||||
INCLUDES += -I"$(BROTLI_PATH)/include"
|
||||
CFLAGS += -DHAVE_BROTLI
|
||||
curl_LDADD += -L"$(BROTLI_PATH)/lib"
|
||||
ifdef BROTLI_LIBS
|
||||
curl_LDADD += $(BROTLI_LIBS)
|
||||
else
|
||||
curl_LDADD += -lbrotlidec
|
||||
endif
|
||||
endif
|
||||
ifdef IDN2
|
||||
CFLAGS += -DUSE_LIBIDN2
|
||||
curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2
|
||||
else
|
||||
ifdef WINIDN
|
||||
CFLAGS += -DUSE_WIN32_IDN
|
||||
curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
|
||||
endif
|
||||
endif
|
||||
ifdef METALINK
|
||||
INCLUDES += -I"$(LIBMETALINK_PATH)/include"
|
||||
CFLAGS += -DUSE_METALINK
|
||||
curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink
|
||||
ifndef DYN
|
||||
ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o)
|
||||
curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat
|
||||
else
|
||||
curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifdef SSPI
|
||||
CFLAGS += -DUSE_WINDOWS_SSPI
|
||||
endif
|
||||
ifdef IPV6
|
||||
CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
|
||||
endif
|
||||
ifdef LDAPS
|
||||
CFLAGS += -DHAVE_LDAP_SSL
|
||||
endif
|
||||
ifdef USE_LDAP_NOVELL
|
||||
CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
|
||||
curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
|
||||
endif
|
||||
ifdef USE_LDAP_OPENLDAP
|
||||
CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
|
||||
curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
|
||||
endif
|
||||
ifndef USE_LDAP_NOVELL
|
||||
ifndef USE_LDAP_OPENLDAP
|
||||
curl_LDADD += -lwldap32
|
||||
endif
|
||||
endif
|
||||
curl_LDADD += -lws2_32
|
||||
|
||||
# Makefile.inc provides the CSOURCES and HHEADERS defines
|
||||
include Makefile.inc
|
||||
|
||||
curl_PROGRAMS = curl.exe
|
||||
curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_CFILES)))
|
||||
curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_CFILES))))
|
||||
curl_OBJECTS += $(curlx_OBJECTS)
|
||||
vpath %.c $(PROOT)/lib
|
||||
|
||||
RESOURCE = curl.res
|
||||
|
||||
|
||||
all: $(curl_PROGRAMS)
|
||||
|
||||
curl.exe: $(RESOURCE) $(curl_OBJECTS) $(curl_DEPENDENCIES)
|
||||
$(call DEL, $@)
|
||||
$(CC) $(LDFLAGS) -o $@ $< $(curl_OBJECTS) $(curl_LDADD)
|
||||
|
||||
# We don't have nroff normally under win32
|
||||
# tool_hugehelp.c: $(PROOT)/docs/MANUAL $(PROOT)/docs/curl.1 mkhelp.pl
|
||||
# @$(call DEL, tool_hugehelp.c)
|
||||
# $(NROFF) -man $(PROOT)/docs/curl.1 | $(PERL) mkhelp.pl $(PROOT)/docs/MANUAL > tool_hugehelp.c
|
||||
|
||||
tool_hugehelp.c:
|
||||
@echo Creating $@
|
||||
@$(call COPY, $@.cvs, $@)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(INCLUDES) $(CFLAGS) -c $<
|
||||
|
||||
%.res: %.rc
|
||||
$(RC) $(RCFLAGS) -i $< -o $@
|
||||
|
||||
clean:
|
||||
ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
|
||||
@$(call DEL, tool_hugehelp.c)
|
||||
endif
|
||||
@$(call DEL, $(curl_OBJECTS) $(curlx_OBJECTS) $(RESOURCE))
|
||||
|
||||
distclean vclean: clean
|
||||
@$(call DEL, $(curl_PROGRAMS))
|
502
module/Vendor/CURL/src/Makefile.netware
vendored
Normal file
502
module/Vendor/CURL/src/Makefile.netware
vendored
Normal file
@ -0,0 +1,502 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 2004 - 2014, Guenter Knauf
|
||||
# Copyright (C) 2001 - 2020, 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.
|
||||
#
|
||||
#***************************************************************************
|
||||
|
||||
#################################################################
|
||||
#
|
||||
## Makefile for building curl.nlm (NetWare version - gnu make)
|
||||
##
|
||||
## Use: make -f Makefile.netware
|
||||
#
|
||||
#################################################################
|
||||
|
||||
# Edit the path below to point to the base of your Novell NDK.
|
||||
ifndef NDKBASE
|
||||
NDKBASE = c:/novell
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your Zlib sources.
|
||||
ifndef ZLIB_PATH
|
||||
ZLIB_PATH = ../../zlib-1.2.8
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your OpenSSL package.
|
||||
ifndef OPENSSL_PATH
|
||||
OPENSSL_PATH = ../../openssl-1.0.2a
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your LibSSH2 package.
|
||||
ifndef LIBSSH2_PATH
|
||||
LIBSSH2_PATH = ../../libssh2-1.5.0
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your libidn package.
|
||||
ifndef LIBIDN_PATH
|
||||
LIBIDN_PATH = ../../libidn-1.18
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your librtmp package.
|
||||
ifndef LIBRTMP_PATH
|
||||
LIBRTMP_PATH = ../../librtmp-2.3
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your nghttp2 package.
|
||||
ifndef NGHTTP2_PATH
|
||||
NGHTTP2_PATH = ../../nghttp2-0.6.7
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your fbopenssl package.
|
||||
ifndef FBOPENSSL_PATH
|
||||
FBOPENSSL_PATH = ../../fbopenssl-0.4
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your libmetalink package.
|
||||
ifndef LIBMETALINK_PATH
|
||||
LIBMETALINK_PATH = ../../libmetalink-0.1.2
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your libexpat package.
|
||||
ifndef LIBEXPAT_PATH
|
||||
LIBEXPAT_PATH = ../../expat-2.1.0
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your libXML2 package.
|
||||
ifndef LIBXML2_PATH
|
||||
LIBXML2_PATH = ../../libxml2-2.8.0
|
||||
endif
|
||||
|
||||
# Edit the path below to point to the base of your c-ares package.
|
||||
ifndef LIBCARES_PATH
|
||||
LIBCARES_PATH = ../ares
|
||||
endif
|
||||
|
||||
ifndef INSTDIR
|
||||
INSTDIR = ..$(DS)curl-$(LIBCURL_VERSION_STR)-bin-nw
|
||||
endif
|
||||
|
||||
# Edit the vars below to change NLM target settings.
|
||||
TARGET = curl
|
||||
VERSION = $(LIBCURL_VERSION)
|
||||
COPYR = Copyright (C) $(LIBCURL_COPYRIGHT_STR)
|
||||
DESCR = curl $(LIBCURL_VERSION_STR) ($(LIBARCH)) - https://curl.se
|
||||
MTSAFE = YES
|
||||
STACK = 64000
|
||||
SCREEN = $(TARGET) commandline utility
|
||||
# Comment the line below if you don't want to load protected automatically.
|
||||
# LDRING = 3
|
||||
|
||||
# Uncomment the next line to enable linking with POSIX semantics.
|
||||
# POSIXFL = 1
|
||||
|
||||
# Edit the var below to point to your lib architecture.
|
||||
ifndef LIBARCH
|
||||
LIBARCH = LIBC
|
||||
endif
|
||||
|
||||
# must be equal to NDEBUG or DEBUG, CURLDEBUG
|
||||
ifndef DB
|
||||
DB = NDEBUG
|
||||
endif
|
||||
# Optimization: -O<n> or debugging: -g
|
||||
ifeq ($(DB),NDEBUG)
|
||||
OPT = -O2
|
||||
OBJDIR = release
|
||||
else
|
||||
OPT = -g
|
||||
OBJDIR = debug
|
||||
endif
|
||||
|
||||
# The following lines defines your compiler.
|
||||
ifdef CWFolder
|
||||
METROWERKS = $(CWFolder)
|
||||
endif
|
||||
ifdef METROWERKS
|
||||
# MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support
|
||||
MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support
|
||||
CC = mwccnlm
|
||||
else
|
||||
CC = gcc
|
||||
endif
|
||||
PERL = perl
|
||||
# Here you can find a native Win32 binary of the original awk:
|
||||
# http://www.gknw.net/development/prgtools/awk-20100523.zip
|
||||
AWK = awk
|
||||
CP = cp -afv
|
||||
MKDIR = mkdir
|
||||
# RM = rm -f
|
||||
# If you want to mark the target as MTSAFE you will need a tool for
|
||||
# generating the xdc data for the linker; here's a minimal tool:
|
||||
# http://www.gknw.net/development/prgtools/mkxdc.zip
|
||||
MPKXDC = mkxdc
|
||||
|
||||
# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH))
|
||||
LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH))
|
||||
|
||||
# Include the version info retrieved from curlver.h
|
||||
-include $(OBJDIR)/version.inc
|
||||
|
||||
# Global flags for all compilers
|
||||
CFLAGS += $(OPT) -D$(DB) -DNETWARE -DHAVE_CONFIG_H -nostdinc
|
||||
|
||||
ifeq ($(CC),mwccnlm)
|
||||
LD = mwldnlm
|
||||
LDFLAGS = -nostdlib $(OBJS) $(PRELUDE) $(LDLIBS) -o $@ -commandfile
|
||||
LIBEXT = lib
|
||||
CFLAGS += -gccinc -inline off -opt nointrinsics -proc 586
|
||||
CFLAGS += -relax_pointers
|
||||
#CFLAGS += -w on
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
ifeq ($(POSIXFL),1)
|
||||
PRELUDE = $(NDK_LIBC)/imports/posixpre.o
|
||||
else
|
||||
PRELUDE = $(NDK_LIBC)/imports/libcpre.o
|
||||
endif
|
||||
CFLAGS += -align 4
|
||||
else
|
||||
# PRELUDE = $(NDK_CLIB)/imports/clibpre.o
|
||||
# to avoid the __init_* / __deinit_* woes don't use prelude from NDK
|
||||
PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj"
|
||||
# CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h"
|
||||
CFLAGS += -align 1
|
||||
endif
|
||||
else
|
||||
LD = nlmconv
|
||||
LDFLAGS = -T
|
||||
LIBEXT = a
|
||||
CFLAGS += -m32
|
||||
CFLAGS += -fno-builtin -fno-strict-aliasing
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
CFLAGS += -fpcc-struct-return
|
||||
endif
|
||||
CFLAGS += -Wall # -pedantic
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
ifeq ($(POSIXFL),1)
|
||||
PRELUDE = $(NDK_LIBC)/imports/posixpre.gcc.o
|
||||
else
|
||||
PRELUDE = $(NDK_LIBC)/imports/libcpre.gcc.o
|
||||
endif
|
||||
else
|
||||
# PRELUDE = $(NDK_CLIB)/imports/clibpre.gcc.o
|
||||
# to avoid the __init_* / __deinit_* woes don't use prelude from NDK
|
||||
# http://www.gknw.net/development/mk_nlm/gcc_pre.zip
|
||||
PRELUDE = $(NDK_ROOT)/pre/prelude.o
|
||||
CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h
|
||||
endif
|
||||
endif
|
||||
|
||||
NDK_ROOT = $(NDKBASE)/ndk
|
||||
ifndef NDK_CLIB
|
||||
NDK_CLIB = $(NDK_ROOT)/nwsdk
|
||||
endif
|
||||
ifndef NDK_LIBC
|
||||
NDK_LIBC = $(NDK_ROOT)/libc
|
||||
endif
|
||||
ifndef NDK_LDAP
|
||||
NDK_LDAP = $(NDK_ROOT)/cldapsdk/netware
|
||||
endif
|
||||
CURL_INC = ../include
|
||||
CURL_LIB = ../lib
|
||||
|
||||
INCLUDES = -I$(CURL_INC) -I$(CURL_LIB)
|
||||
|
||||
ifeq ($(findstring -static,$(CFG)),-static)
|
||||
LINK_STATIC = 1
|
||||
endif
|
||||
ifeq ($(findstring -ares,$(CFG)),-ares)
|
||||
WITH_ARES = 1
|
||||
endif
|
||||
ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
|
||||
WITH_RTMP = 1
|
||||
WITH_SSL = 1
|
||||
WITH_ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
|
||||
WITH_SSH2 = 1
|
||||
WITH_SSL = 1
|
||||
WITH_ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -ssl,$(CFG)),-ssl)
|
||||
WITH_SSL = 1
|
||||
endif
|
||||
ifeq ($(findstring -zlib,$(CFG)),-zlib)
|
||||
WITH_ZLIB = 1
|
||||
endif
|
||||
ifeq ($(findstring -idn,$(CFG)),-idn)
|
||||
WITH_IDN = 1
|
||||
endif
|
||||
ifeq ($(findstring -metalink,$(CFG)),-metalink)
|
||||
WITH_METALINK = 1
|
||||
WITH_SSL = 1
|
||||
endif
|
||||
ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
|
||||
WITH_NGHTTP2 = 1
|
||||
endif
|
||||
ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
|
||||
ENABLE_IPV6 = 1
|
||||
endif
|
||||
|
||||
ifdef LINK_STATIC
|
||||
LDLIBS = $(CURL_LIB)/libcurl.$(LIBEXT)
|
||||
ifdef WITH_ARES
|
||||
LDLIBS += $(LIBCARES_PATH)/libcares.$(LIBEXT)
|
||||
endif
|
||||
else
|
||||
MODULES = libcurl.nlm
|
||||
IMPORTS = @$(CURL_LIB)/libcurl.imp
|
||||
endif
|
||||
ifdef WITH_SSH2
|
||||
# INCLUDES += -I$(LIBSSH2_PATH)/include
|
||||
ifdef LINK_STATIC
|
||||
LDLIBS += $(LIBSSH2_PATH)/nw/libssh2.$(LIBEXT)
|
||||
else
|
||||
MODULES += libssh2.nlm
|
||||
IMPORTS += @$(LIBSSH2_PATH)/nw/libssh2.imp
|
||||
endif
|
||||
endif
|
||||
ifdef WITH_RTMP
|
||||
# INCLUDES += -I$(LIBRTMP_PATH)
|
||||
ifdef LINK_STATIC
|
||||
LDLIBS += $(LIBRTMP_PATH)/librtmp/librtmp.$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
ifdef WITH_SSL
|
||||
# INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L)
|
||||
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT)
|
||||
LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT)
|
||||
IMPORTS += GetProcessSwitchCount RunningProcess
|
||||
endif
|
||||
ifdef WITH_ZLIB
|
||||
INCLUDES += -I$(ZLIB_PATH)
|
||||
ifdef LINK_STATIC
|
||||
LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT)
|
||||
else
|
||||
MODULES += libz.nlm
|
||||
IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp
|
||||
endif
|
||||
endif
|
||||
ifdef WITH_IDN
|
||||
# INCLUDES += -I$(LIBIDN_PATH)/include
|
||||
LDLIBS += $(LIBIDN_PATH)/lib/libidn.$(LIBEXT)
|
||||
endif
|
||||
ifdef WITH_NGHTTP2
|
||||
INCLUDES += -I$(NGHTTP2_PATH)/include
|
||||
LDLIBS += $(NGHTTP2_PATH)/lib/libnghttp2.$(LIBEXT)
|
||||
endif
|
||||
ifdef WITH_METALINK
|
||||
CFLAGS += -DUSE_METALINK
|
||||
INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L)
|
||||
INCLUDES += -I$(LIBMETALINK_PATH)/include
|
||||
LDLIBS += $(LIBMETALINK_PATH)/lib/libmetalink.$(LIBEXT)
|
||||
ifdef WITH_LIBEXPAT
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
IMPORTS += @$(LIBEXPAT_PATH)/imports/expatlbc.imp
|
||||
MODULES += expatlbc
|
||||
else
|
||||
IMPORTS += @$(LIBEXPAT_PATH)/imports/expatlib.imp
|
||||
MODULES += expatlib
|
||||
endif
|
||||
else
|
||||
ifdef WITH_LIBXML2
|
||||
IMPORTS += @$(LIBXML2_PATH)/lib/libxml2.imp
|
||||
MODULES += libxml2
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(LIBARCH),LIBC)
|
||||
INCLUDES += -I$(NDK_LIBC)/include
|
||||
# INCLUDES += -I$(NDK_LIBC)/include/nks
|
||||
# INCLUDES += -I$(NDK_LIBC)/include/winsock
|
||||
CFLAGS += -D_POSIX_SOURCE
|
||||
else
|
||||
INCLUDES += -I$(NDK_CLIB)/include/nlm
|
||||
# INCLUDES += -I$(NDK_CLIB)/include
|
||||
endif
|
||||
ifndef DISABLE_LDAP
|
||||
# INCLUDES += -I$(NDK_LDAP)/$(LIBARCH_L)/inc
|
||||
endif
|
||||
CFLAGS += $(INCLUDES)
|
||||
|
||||
ifeq ($(MTSAFE),YES)
|
||||
XDCOPT = -n
|
||||
endif
|
||||
ifeq ($(MTSAFE),NO)
|
||||
XDCOPT = -u
|
||||
endif
|
||||
ifdef XDCOPT
|
||||
XDCDATA = $(OBJDIR)/$(TARGET).xdc
|
||||
endif
|
||||
|
||||
ifeq ($(findstring /sh,$(SHELL)),/sh)
|
||||
DL = '
|
||||
DS = /
|
||||
PCT = %
|
||||
#-include $(NDKBASE)/nlmconv/ncpfs.inc
|
||||
else
|
||||
DS = \\
|
||||
PCT = %%
|
||||
endif
|
||||
|
||||
# Makefile.inc provides the CSOURCES and HHEADERS defines
|
||||
include Makefile.inc
|
||||
|
||||
OBJX := $(patsubst %.c,$(OBJDIR)/%.o,$(notdir $(strip $(CURLX_CFILES))))
|
||||
OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(strip $(CURL_CFILES)))
|
||||
ifndef LINK_STATIC
|
||||
OBJS += $(OBJX)
|
||||
endif
|
||||
|
||||
vpath %.c $(CURL_LIB)
|
||||
|
||||
all: prebuild $(TARGET).nlm
|
||||
|
||||
prebuild: $(OBJDIR) $(OBJDIR)/version.inc
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
# @echo Compiling $<
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/version.inc: $(CURL_INC)/curl/curlver.h $(OBJDIR)
|
||||
@echo Creating $@
|
||||
@$(AWK) -f ../packages/NetWare/get_ver.awk $< > $@
|
||||
|
||||
install: $(INSTDIR) all
|
||||
@-$(CP) ../docs/$(TARGET).pdf $(INSTDIR)
|
||||
@-$(CP) ../docs/$(TARGET).html $(INSTDIR)
|
||||
@$(CP) $(TARGET).nlm $(INSTDIR)
|
||||
|
||||
clean:
|
||||
ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
|
||||
-$(RM) tool_hugehelp.c
|
||||
endif
|
||||
-$(RM) -r $(OBJDIR)
|
||||
|
||||
distclean vclean: clean
|
||||
-$(RM) $(TARGET).nlm
|
||||
|
||||
$(OBJDIR) $(INSTDIR):
|
||||
@$(MKDIR) $@
|
||||
|
||||
$(TARGET).nlm: $(OBJS) $(OBJDIR)/$(TARGET).def $(XDCDATA)
|
||||
@echo Linking $@
|
||||
@-$(RM) $@
|
||||
@$(LD) $(LDFLAGS) $(OBJDIR)/$(TARGET).def
|
||||
|
||||
$(OBJDIR)/%.xdc: Makefile.netware
|
||||
@echo Creating $@
|
||||
@$(MPKXDC) $(XDCOPT) $@
|
||||
|
||||
$(OBJDIR)/%.def: Makefile.netware
|
||||
@echo $(DL)# DEF file for linking with $(LD)$(DL) > $@
|
||||
@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
|
||||
@echo $(DL)# All your changes will be lost!!$(DL) >> $@
|
||||
@echo $(DL)#$(DL) >> $@
|
||||
@echo $(DL)copyright "$(COPYR)"$(DL) >> $@
|
||||
@echo $(DL)description "$(DESCR)"$(DL) >> $@
|
||||
@echo $(DL)version $(VERSION)$(DL) >> $@
|
||||
ifdef NLMTYPE
|
||||
@echo $(DL)type $(NLMTYPE)$(DL) >> $@
|
||||
endif
|
||||
ifdef STACK
|
||||
@echo $(DL)stack $(STACK)$(DL) >> $@
|
||||
endif
|
||||
ifdef SCREEN
|
||||
@echo $(DL)screenname "$(SCREEN)"$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)screenname "DEFAULT"$(DL) >> $@
|
||||
endif
|
||||
ifneq ($(DB),NDEBUG)
|
||||
@echo $(DL)debug$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)threadname "$(TARGET)"$(DL) >> $@
|
||||
ifdef XDCDATA
|
||||
@echo $(DL)xdcdata $(XDCDATA)$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LDRING),0)
|
||||
@echo $(DL)flag_on 16$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LDRING),3)
|
||||
@echo $(DL)flag_on 512$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(LIBARCH),CLIB)
|
||||
@echo $(DL)start _Prelude$(DL) >> $@
|
||||
@echo $(DL)exit _Stop$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_CLIB)/imports/clib.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_CLIB)/imports/threads.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_CLIB)/imports/nlmlib.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_CLIB)/imports/socklib.imp$(DL) >> $@
|
||||
@echo $(DL)module clib$(DL) >> $@
|
||||
ifndef DISABLE_LDAP
|
||||
@echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapsdk.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapssl.imp$(DL) >> $@
|
||||
# @echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapx.imp$(DL) >> $@
|
||||
@echo $(DL)module ldapsdk ldapssl$(DL) >> $@
|
||||
endif
|
||||
else
|
||||
ifeq ($(POSIXFL),1)
|
||||
@echo $(DL)flag_on 4194304$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)flag_on 64$(DL) >> $@
|
||||
@echo $(DL)pseudopreemption$(DL) >> $@
|
||||
ifeq ($(findstring posixpre,$(PRELUDE)),posixpre)
|
||||
@echo $(DL)start POSIX_Start$(DL) >> $@
|
||||
@echo $(DL)exit POSIX_Stop$(DL) >> $@
|
||||
@echo $(DL)check POSIX_CheckUnload$(DL) >> $@
|
||||
else
|
||||
@echo $(DL)start _LibCPrelude$(DL) >> $@
|
||||
@echo $(DL)exit _LibCPostlude$(DL) >> $@
|
||||
@echo $(DL)check _LibCCheckUnload$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)import @$(NDK_LIBC)/imports/libc.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_LIBC)/imports/netware.imp$(DL) >> $@
|
||||
@echo $(DL)module libc$(DL) >> $@
|
||||
ifndef DISABLE_LDAP
|
||||
@echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapsdk.imp$(DL) >> $@
|
||||
@echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapssl.imp$(DL) >> $@
|
||||
# @echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapx.imp$(DL) >> $@
|
||||
@echo $(DL)module lldapsdk lldapssl$(DL) >> $@
|
||||
endif
|
||||
endif
|
||||
ifdef MODULES
|
||||
@echo $(DL)module $(MODULES)$(DL) >> $@
|
||||
endif
|
||||
ifdef EXPORTS
|
||||
@echo $(DL)export $(EXPORTS)$(DL) >> $@
|
||||
endif
|
||||
ifdef IMPORTS
|
||||
@echo $(DL)import $(IMPORTS)$(DL) >> $@
|
||||
endif
|
||||
ifeq ($(findstring nlmconv,$(LD)),nlmconv)
|
||||
@echo $(DL)input $(PRELUDE)$(DL) >> $@
|
||||
@echo $(DL)input $(OBJS)$(DL) >> $@
|
||||
ifdef LDLIBS
|
||||
@echo $(DL)input $(LDLIBS)$(DL) >> $@
|
||||
endif
|
||||
@echo $(DL)output $(TARGET).nlm$(DL) >> $@
|
||||
endif
|
||||
|
||||
tool_hugehelp.c:
|
||||
@echo Creating $@
|
||||
@$(CP) tool_hugehelp.c.cvs $@
|
||||
|
||||
$(LIBCARES_PATH)/libcares.$(LIBEXT):
|
||||
$(MAKE) -C $(LIBCARES_PATH) -f Makefile.netware lib
|
111
module/Vendor/CURL/src/curl.rc
vendored
Normal file
111
module/Vendor/CURL/src/curl.rc
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include <winver.h>
|
||||
#include "tool_version.h"
|
||||
|
||||
LANGUAGE 0, 0
|
||||
|
||||
#define RC_VERSION CURL_VERSION_MAJOR, CURL_VERSION_MINOR, CURL_VERSION_PATCH, 0
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION RC_VERSION
|
||||
PRODUCTVERSION RC_VERSION
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
#if defined(DEBUGBUILD) || defined(_DEBUG)
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILESUBTYPE 0L
|
||||
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "curl, https://curl.se/\0"
|
||||
VALUE "FileDescription", "The curl executable\0"
|
||||
VALUE "FileVersion", CURL_VERSION "\0"
|
||||
VALUE "InternalName", "curl\0"
|
||||
VALUE "OriginalFilename", "curl.exe\0"
|
||||
VALUE "ProductName", "The curl executable\0"
|
||||
VALUE "ProductVersion", CURL_VERSION "\0"
|
||||
VALUE "LegalCopyright", "\xa9 " CURL_COPYRIGHT "\0" /* a9: Copyright symbol */
|
||||
VALUE "License", "https://curl.se/docs/copyright.html\0"
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
/* Manifest */
|
||||
|
||||
#if defined(CURL_EMBED_MANIFEST)
|
||||
|
||||
/* String escaping rules:
|
||||
https://msdn.microsoft.com/library/aa381050
|
||||
Application Manifest doc, including the list of 'supportedOS Id's:
|
||||
https://msdn.microsoft.com/library/aa374191 */
|
||||
|
||||
#ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID
|
||||
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
|
||||
#endif
|
||||
#ifndef RT_MANIFEST
|
||||
#define RT_MANIFEST 24
|
||||
#endif
|
||||
|
||||
#define _STR(macro) _STR_(macro)
|
||||
#define _STR_(macro) #macro
|
||||
|
||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST
|
||||
BEGIN
|
||||
"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>"
|
||||
"<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">"
|
||||
"<assemblyIdentity name=""The curl executable"" version="""
|
||||
_STR(LIBCURL_VERSION_MAJOR) "."
|
||||
_STR(LIBCURL_VERSION_MINOR) "."
|
||||
_STR(LIBCURL_VERSION_PATCH) ".0"" type=""win32""/>"
|
||||
"<compatibility xmlns=""urn:schemas-microsoft-com:compatibility.v1"">"
|
||||
"<application>"
|
||||
"<supportedOS Id=""{e2011457-1546-43c5-a5fe-008deee3d3f0}""/>" /* Vista / Server 2008 */
|
||||
"<supportedOS Id=""{35138b9a-5d96-4fbd-8e2d-a2440225f93a}""/>" /* 7 / Server 2008 R2 */
|
||||
"<supportedOS Id=""{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}""/>" /* 8 / Server 2012 */
|
||||
"<supportedOS Id=""{1f676c76-80e1-4239-95bb-83d0f6d0da78}""/>" /* 8.1 / Server 2012 R2 */
|
||||
"<supportedOS Id=""{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}""/>" /* 10 / Server 2016 */
|
||||
"</application>"
|
||||
"</compatibility>"
|
||||
"<trustInfo xmlns=""urn:schemas-microsoft-com:asm.v3"">"
|
||||
"<security>"
|
||||
"<requestedPrivileges>"
|
||||
"<requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>"
|
||||
"</requestedPrivileges>"
|
||||
"</security>"
|
||||
"</trustInfo>"
|
||||
"</assembly>"
|
||||
END
|
||||
|
||||
#endif
|
1
module/Vendor/CURL/src/macos/MACINSTALL.TXT
vendored
Normal file
1
module/Vendor/CURL/src/macos/MACINSTALL.TXT
vendored
Normal file
@ -0,0 +1 @@
|
||||
MACOS (not MACOS X)
|
1
module/Vendor/CURL/src/macos/curl.mcp.xml.sit.hqx
vendored
Normal file
1
module/Vendor/CURL/src/macos/curl.mcp.xml.sit.hqx
vendored
Normal file
File diff suppressed because one or more lines are too long
1
module/Vendor/CURL/src/macos/src/curl_GUSIConfig.cpp
vendored
Normal file
1
module/Vendor/CURL/src/macos/src/curl_GUSIConfig.cpp
vendored
Normal file
@ -0,0 +1 @@
|
||||
/**************** BEGIN GUSI CONFIGURATION ****************************
|
1
module/Vendor/CURL/src/macos/src/macos_main.cpp
vendored
Normal file
1
module/Vendor/CURL/src/macos/src/macos_main.cpp
vendored
Normal file
@ -0,0 +1 @@
|
||||
/* =========================================================================
|
50
module/Vendor/CURL/src/makefile.amiga
vendored
Normal file
50
module/Vendor/CURL/src/makefile.amiga
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2020, 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.
|
||||
#
|
||||
###########################################################################
|
||||
#
|
||||
# curl Makefile for AmigaOS ...
|
||||
#
|
||||
|
||||
# change the follow to where you have the AmiTCP SDK v4.3 includes:
|
||||
|
||||
ATCPSDKI= /GG/netinclude
|
||||
|
||||
|
||||
CC = m68k-amigaos-gcc
|
||||
CFLAGS = -I$(ATCPSDKI) -m68020-60 -O2 -msoft-float -noixemul -g -I. -I../include -W -Wall
|
||||
LIBS = ../lib/libcurl.a -lssl -lcrypto -lz
|
||||
MANPAGE = ../docs/curl.1
|
||||
README = ../docs/MANUAL
|
||||
MKHELP = ../src/mkhelp.pl
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
OBJS = $(CURL_CFILES:.c=.o) $(CURLX_CFILES:.c=.o)
|
||||
|
||||
all: tool_hugehelp.c $(OBJS)
|
||||
$(CC) $(CFLAGS) -o curl $(OBJS) $(LIBS) -Wl,-Map,curl.map,--cref
|
||||
|
||||
tool_hugehelp.c: $(README) $(MANPAGE) mkhelp.pl
|
||||
rm -f tool_hugehelp.c
|
||||
/bin/nroff -man $(MANPAGE) | /bin/perl $(MKHELP) -c $(README) > tool_hugehelp.c
|
||||
|
||||
install:
|
||||
$(INSTALL) -c curl /c/curl
|
93
module/Vendor/CURL/src/makefile.dj
vendored
Normal file
93
module/Vendor/CURL/src/makefile.dj
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 2003 - 2007, Gisle Vanem <gvanem@yahoo.no>.
|
||||
# Copyright (C) 2003 - 2020, 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.
|
||||
#
|
||||
#***************************************************************************
|
||||
|
||||
#
|
||||
# Adapted for djgpp2 / Watt-32 / DOS
|
||||
#
|
||||
|
||||
DEPEND_PREREQ = # tool_hugehelp.c
|
||||
|
||||
TOPDIR = ..
|
||||
|
||||
include ../packages/DOS/common.dj
|
||||
include Makefile.inc
|
||||
|
||||
CSOURCES = $(CURL_CFILES)
|
||||
|
||||
ifeq ($(USE_SSL),1)
|
||||
EX_LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_ARES),1)
|
||||
EX_LIBS += $(ARES_ROOT)/libcares.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_ZLIB),1)
|
||||
EX_LIBS += $(ZLIB_ROOT)/libz.a
|
||||
CFLAGS += -DUSE_MANUAL
|
||||
endif
|
||||
|
||||
ifeq ($(USE_IDNA),1)
|
||||
EX_LIBS += $(LIBIDN_ROOT)/lib/dj_obj/libidn.a -liconv
|
||||
endif
|
||||
|
||||
EX_LIBS += $(WATT32_ROOT)/lib/libwatt.a
|
||||
|
||||
PROGRAM = curl.exe
|
||||
OBJECTS += $(addprefix $(OBJ_DIR)/, $(CSOURCES:.c=.o))
|
||||
|
||||
all: $(OBJ_DIR) $(PROGRAM)
|
||||
@echo Welcome to curl
|
||||
|
||||
$(PROGRAM): $(OBJECTS) ../lib/libcurl.a
|
||||
$(CC) -o $@ $^ $(LDFLAGS) $(EX_LIBS)
|
||||
|
||||
#
|
||||
# groff 1.18+ requires "-P -c"
|
||||
#
|
||||
tool_hugehelp.c: ../docs/MANUAL ../docs/curl.1 mkhelp.pl
|
||||
groff -Tascii -man ../docs/curl.1 | \
|
||||
perl -w mkhelp.pl ../docs/MANUAL > $@
|
||||
|
||||
# clean generated files
|
||||
#
|
||||
genclean:
|
||||
- $(DELETE) tool_hugehelp.c
|
||||
|
||||
# clean object files and subdir
|
||||
#
|
||||
objclean: genclean
|
||||
- $(DELETE) $(OBJ_DIR)$(DS)*.o
|
||||
- $(RMDIR) $(OBJ_DIR)
|
||||
|
||||
# clean without removing built program
|
||||
#
|
||||
clean: objclean
|
||||
- $(DELETE) depend.dj
|
||||
|
||||
# clean everything
|
||||
#
|
||||
realclean vclean: clean
|
||||
- $(DELETE) $(PROGRAM)
|
||||
|
||||
-include depend.dj
|
235
module/Vendor/CURL/src/mkhelp.pl
vendored
Normal file
235
module/Vendor/CURL/src/mkhelp.pl
vendored
Normal file
@ -0,0 +1,235 @@
|
||||
#!/usr/bin/env perl
|
||||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2020, 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.
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
# Yeah, I know, probably 1000 other persons already wrote a script like
|
||||
# this, but I'll tell ya:
|
||||
|
||||
# THEY DON'T FIT ME :-)
|
||||
|
||||
# Get readme file as parameter:
|
||||
|
||||
if($ARGV[0] eq "-c") {
|
||||
$c=1;
|
||||
shift @ARGV;
|
||||
}
|
||||
|
||||
push @out, " _ _ ____ _\n";
|
||||
push @out, " Project ___| | | | _ \\| |\n";
|
||||
push @out, " / __| | | | |_) | |\n";
|
||||
push @out, " | (__| |_| | _ <| |___\n";
|
||||
push @out, " \\___|\\___/|_| \\_\\_____|\n";
|
||||
|
||||
my $olen=0;
|
||||
while (<STDIN>) {
|
||||
my $line = $_;
|
||||
|
||||
# this should be removed:
|
||||
$line =~ s/(.|_)//g;
|
||||
|
||||
# remove trailing CR from line. msysgit checks out files as line+CRLF
|
||||
$line =~ s/\r$//;
|
||||
|
||||
if($line =~ /^([ \t]*\n|curl)/i) {
|
||||
# cut off headers and empty lines
|
||||
$wline++; # count number of cut off lines
|
||||
next;
|
||||
}
|
||||
|
||||
my $text = $line;
|
||||
$text =~ s/^\s+//g; # cut off preceding...
|
||||
$text =~ s/\s+$//g; # and trailing whitespaces
|
||||
|
||||
$tlen = length($text);
|
||||
|
||||
if($wline && ($olen == $tlen)) {
|
||||
# if the previous line with contents was exactly as long as
|
||||
# this line, then we ignore the newlines!
|
||||
|
||||
# We do this magic because a header may abort a paragraph at
|
||||
# any line, but we don't want that to be noticed in the output
|
||||
# here
|
||||
$wline=0;
|
||||
}
|
||||
$olen = $tlen;
|
||||
|
||||
if($wline) {
|
||||
# we only make one empty line max
|
||||
$wline = 0;
|
||||
push @out, "\n";
|
||||
}
|
||||
push @out, $line;
|
||||
}
|
||||
push @out, "\n"; # just an extra newline
|
||||
|
||||
print <<HEAD
|
||||
/*
|
||||
* NEVER EVER edit this manually, fix the mkhelp.pl script instead!
|
||||
*/
|
||||
#ifdef USE_MANUAL
|
||||
#include "tool_hugehelp.h"
|
||||
HEAD
|
||||
;
|
||||
if($c) {
|
||||
# If compression requested, check that the Gzip module is available
|
||||
# or else disable compression
|
||||
$c = eval
|
||||
{
|
||||
require IO::Compress::Gzip;
|
||||
IO::Compress::Gzip->import();
|
||||
1;
|
||||
};
|
||||
print STDERR "Warning: compression requested but Gzip is not available\n" if (!$c)
|
||||
}
|
||||
|
||||
if($c)
|
||||
{
|
||||
my $content = join("", @out);
|
||||
my $gzippedContent;
|
||||
IO::Compress::Gzip::gzip(
|
||||
\$content, \$gzippedContent, Level => 9, TextFlag => 1, Time=>0) or die "gzip failed:";
|
||||
$gzip = length($content);
|
||||
$gzipped = length($gzippedContent);
|
||||
|
||||
print <<HEAD
|
||||
#include <zlib.h>
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
static const unsigned char hugehelpgz[] = {
|
||||
/* This mumbo-jumbo is the huge help text compressed with gzip.
|
||||
Thanks to this operation, the size of this data shrank from $gzip
|
||||
to $gzipped bytes. You can disable the use of compressed help
|
||||
texts by NOT passing -c to the mkhelp.pl tool. */
|
||||
HEAD
|
||||
;
|
||||
|
||||
my $c=0;
|
||||
print " ";
|
||||
for(split(//, $gzippedContent)) {
|
||||
my $num=ord($_);
|
||||
printf(" 0x%02x,", 0+$num);
|
||||
if(!(++$c % 12)) {
|
||||
print "\n ";
|
||||
}
|
||||
}
|
||||
print "\n};\n";
|
||||
|
||||
print <<EOF
|
||||
#define BUF_SIZE 0x10000
|
||||
static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size)
|
||||
{
|
||||
(void) opaque;
|
||||
/* not a typo, keep it calloc() */
|
||||
return (voidpf) calloc(items, size);
|
||||
}
|
||||
static void zfree_func(voidpf opaque, voidpf ptr)
|
||||
{
|
||||
(void) opaque;
|
||||
free(ptr);
|
||||
}
|
||||
/* Decompress and send to stdout a gzip-compressed buffer */
|
||||
void hugehelp(void)
|
||||
{
|
||||
unsigned char* buf;
|
||||
int status,headerlen;
|
||||
z_stream z;
|
||||
|
||||
/* Make sure no gzip options are set */
|
||||
if (hugehelpgz[3] & 0xfe)
|
||||
return;
|
||||
|
||||
headerlen = 10;
|
||||
memset(&z, 0, sizeof(z_stream));
|
||||
z.zalloc = (alloc_func)zalloc_func;
|
||||
z.zfree = (free_func)zfree_func;
|
||||
z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen);
|
||||
z.next_in = (unsigned char *)hugehelpgz + headerlen;
|
||||
|
||||
if (inflateInit2(&z, -MAX_WBITS) != Z_OK)
|
||||
return;
|
||||
|
||||
buf = malloc(BUF_SIZE);
|
||||
if (buf) {
|
||||
while(1) {
|
||||
z.avail_out = BUF_SIZE;
|
||||
z.next_out = buf;
|
||||
status = inflate(&z, Z_SYNC_FLUSH);
|
||||
if (status == Z_OK || status == Z_STREAM_END) {
|
||||
fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
|
||||
if (status == Z_STREAM_END)
|
||||
break;
|
||||
}
|
||||
else
|
||||
break; /* Error */
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
inflateEnd(&z);
|
||||
}
|
||||
EOF
|
||||
;
|
||||
foot();
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
print <<HEAD
|
||||
void hugehelp(void)
|
||||
{
|
||||
fputs(
|
||||
HEAD
|
||||
;
|
||||
}
|
||||
|
||||
$outsize=0;
|
||||
for(@out) {
|
||||
chop;
|
||||
|
||||
$new = $_;
|
||||
|
||||
$outsize += length($new)+1; # one for the newline
|
||||
|
||||
$new =~ s/\\/\\\\/g;
|
||||
$new =~ s/\"/\\\"/g;
|
||||
|
||||
# gcc 2.96 claims ISO C89 only is required to support 509 letter strings
|
||||
if($outsize > 500) {
|
||||
# terminate and make another fputs() call here
|
||||
print ", stdout);\n fputs(\n";
|
||||
$outsize=length($new)+1;
|
||||
}
|
||||
printf("\"%s\\n\"\n", $new);
|
||||
|
||||
}
|
||||
|
||||
print ", stdout) ;\n}\n";
|
||||
|
||||
foot();
|
||||
|
||||
sub foot {
|
||||
print <<FOOT
|
||||
#else /* !USE_MANUAL */
|
||||
/* built-in manual is disabled, blank function */
|
||||
#include "tool_hugehelp.h"
|
||||
void hugehelp(void) {}
|
||||
#endif /* USE_MANUAL */
|
||||
FOOT
|
||||
;
|
||||
}
|
72
module/Vendor/CURL/src/slist_wc.c
vendored
Normal file
72
module/Vendor/CURL/src/slist_wc.c
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
#include "slist_wc.h"
|
||||
|
||||
/* The last #include files should be: */
|
||||
#include "memdebug.h"
|
||||
|
||||
/*
|
||||
* slist_wc_append() appends a string to the linked list. This function can be
|
||||
* used as an initialization function as well as an append function.
|
||||
*/
|
||||
struct slist_wc *slist_wc_append(struct slist_wc *list,
|
||||
const char *data)
|
||||
{
|
||||
struct curl_slist *new_item = curl_slist_append(NULL, data);
|
||||
|
||||
if(!new_item)
|
||||
return NULL;
|
||||
|
||||
if(!list) {
|
||||
list = malloc(sizeof(struct slist_wc));
|
||||
|
||||
if(!list) {
|
||||
curl_slist_free_all(new_item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->first = new_item;
|
||||
list->last = new_item;
|
||||
return list;
|
||||
}
|
||||
|
||||
list->last->next = new_item;
|
||||
list->last = list->last->next;
|
||||
return list;
|
||||
}
|
||||
|
||||
/* be nice and clean up resources */
|
||||
void slist_wc_free_all(struct slist_wc *list)
|
||||
{
|
||||
if(!list)
|
||||
return;
|
||||
|
||||
curl_slist_free_all(list->first);
|
||||
free(list);
|
||||
}
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
55
module/Vendor/CURL/src/slist_wc.h
vendored
Normal file
55
module/Vendor/CURL/src/slist_wc.h
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef HEADER_CURL_SLIST_WC_H
|
||||
#define HEADER_CURL_SLIST_WC_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "tool_setup.h"
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
/* linked-list structure with last node cache for easysrc */
|
||||
struct slist_wc {
|
||||
struct curl_slist *first;
|
||||
struct curl_slist *last;
|
||||
};
|
||||
|
||||
/*
|
||||
* NAME curl_slist_wc_append()
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* Appends a string to a linked list. If no list exists, it will be created
|
||||
* first. Returns the new list, after appending.
|
||||
*/
|
||||
struct slist_wc *slist_wc_append(struct slist_wc *, const char *);
|
||||
|
||||
/*
|
||||
* NAME curl_slist_free_all()
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* free a previously built curl_slist_wc.
|
||||
*/
|
||||
void slist_wc_free_all(struct slist_wc *);
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
#endif /* HEADER_CURL_SLIST_WC_H */
|
51
module/Vendor/CURL/src/tool_binmode.c
vendored
Normal file
51
module/Vendor/CURL/src/tool_binmode.c
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_SETMODE
|
||||
|
||||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "tool_binmode.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void set_binmode(FILE *stream)
|
||||
{
|
||||
#ifdef O_BINARY
|
||||
# ifdef __HIGHC__
|
||||
_setmode(stream, O_BINARY);
|
||||
# else
|
||||
(void)setmode(fileno(stream), O_BINARY);
|
||||
# endif
|
||||
#else
|
||||
(void)stream;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* HAVE_SETMODE */
|
36
module/Vendor/CURL/src/tool_binmode.h
vendored
Normal file
36
module/Vendor/CURL/src/tool_binmode.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef HEADER_CURL_TOOL_BINMODE_H
|
||||
#define HEADER_CURL_TOOL_BINMODE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_SETMODE
|
||||
|
||||
void set_binmode(FILE *stream);
|
||||
|
||||
#else
|
||||
|
||||
#define set_binmode(x) Curl_nop_stmt
|
||||
|
||||
#endif /* HAVE_SETMODE */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_BINMODE_H */
|
49
module/Vendor/CURL/src/tool_bname.c
vendored
Normal file
49
module/Vendor/CURL/src/tool_bname.c
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_bname.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifndef HAVE_BASENAME
|
||||
|
||||
char *tool_basename(char *path)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = strrchr(path, '/');
|
||||
s2 = strrchr(path, '\\');
|
||||
|
||||
if(s1 && s2) {
|
||||
path = (s1 > s2) ? s1 + 1 : s2 + 1;
|
||||
}
|
||||
else if(s1)
|
||||
path = s1 + 1;
|
||||
else if(s2)
|
||||
path = s2 + 1;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif /* HAVE_BASENAME */
|
34
module/Vendor/CURL/src/tool_bname.h
vendored
Normal file
34
module/Vendor/CURL/src/tool_bname.h
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef HEADER_CURL_TOOL_BNAME_H
|
||||
#define HEADER_CURL_TOOL_BNAME_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_BASENAME
|
||||
|
||||
char *tool_basename(char *path);
|
||||
|
||||
#define basename(x) tool_basename((x))
|
||||
|
||||
#endif /* HAVE_BASENAME */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_BNAME_H */
|
282
module/Vendor/CURL/src/tool_cb_dbg.c
vendored
Normal file
282
module/Vendor/CURL/src/tool_cb_dbg.c
vendored
Normal file
@ -0,0 +1,282 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_convert.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_cb_dbg.h"
|
||||
#include "tool_util.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static void dump(const char *timebuf, const char *text,
|
||||
FILE *stream, const unsigned char *ptr, size_t size,
|
||||
trace tracetype, curl_infotype infotype);
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_DEBUGFUNCTION
|
||||
*/
|
||||
|
||||
int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
char *data, size_t size,
|
||||
void *userdata)
|
||||
{
|
||||
struct OperationConfig *operation = userdata;
|
||||
struct GlobalConfig *config = operation->global;
|
||||
FILE *output = config->errors;
|
||||
const char *text;
|
||||
struct timeval tv;
|
||||
char timebuf[20];
|
||||
time_t secs;
|
||||
|
||||
(void)handle; /* not used */
|
||||
|
||||
if(config->tracetime) {
|
||||
struct tm *now;
|
||||
static time_t epoch_offset;
|
||||
static int known_offset;
|
||||
tv = tvnow();
|
||||
if(!known_offset) {
|
||||
epoch_offset = time(NULL) - tv.tv_sec;
|
||||
known_offset = 1;
|
||||
}
|
||||
secs = epoch_offset + tv.tv_sec;
|
||||
/* !checksrc! disable BANNEDFUNC 1 */
|
||||
now = localtime(&secs); /* not thread safe but we don't care */
|
||||
msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ",
|
||||
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
|
||||
}
|
||||
else
|
||||
timebuf[0] = 0;
|
||||
|
||||
if(!config->trace_stream) {
|
||||
/* open for append */
|
||||
if(!strcmp("-", config->trace_dump))
|
||||
config->trace_stream = stdout;
|
||||
else if(!strcmp("%", config->trace_dump))
|
||||
/* Ok, this is somewhat hackish but we do it undocumented for now */
|
||||
config->trace_stream = config->errors; /* aka stderr */
|
||||
else {
|
||||
config->trace_stream = fopen(config->trace_dump, FOPEN_WRITETEXT);
|
||||
config->trace_fopened = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if(config->trace_stream)
|
||||
output = config->trace_stream;
|
||||
|
||||
if(!output) {
|
||||
warnf(config, "Failed to create/open output");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(config->tracetype == TRACE_PLAIN) {
|
||||
/*
|
||||
* This is the trace look that is similar to what libcurl makes on its
|
||||
* own.
|
||||
*/
|
||||
static const char * const s_infotype[] = {
|
||||
"*", "<", ">", "{", "}", "{", "}"
|
||||
};
|
||||
static bool newl = FALSE;
|
||||
static bool traced_data = FALSE;
|
||||
|
||||
switch(type) {
|
||||
case CURLINFO_HEADER_OUT:
|
||||
if(size > 0) {
|
||||
size_t st = 0;
|
||||
size_t i;
|
||||
for(i = 0; i < size - 1; i++) {
|
||||
if(data[i] == '\n') { /* LF */
|
||||
if(!newl) {
|
||||
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||
}
|
||||
(void)fwrite(data + st, i - st + 1, 1, output);
|
||||
st = i + 1;
|
||||
newl = FALSE;
|
||||
}
|
||||
}
|
||||
if(!newl)
|
||||
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||
(void)fwrite(data + st, i - st + 1, 1, output);
|
||||
}
|
||||
newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
|
||||
traced_data = FALSE;
|
||||
break;
|
||||
case CURLINFO_TEXT:
|
||||
case CURLINFO_HEADER_IN:
|
||||
if(!newl)
|
||||
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||
(void)fwrite(data, size, 1, output);
|
||||
newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
|
||||
traced_data = FALSE;
|
||||
break;
|
||||
case CURLINFO_DATA_OUT:
|
||||
case CURLINFO_DATA_IN:
|
||||
case CURLINFO_SSL_DATA_IN:
|
||||
case CURLINFO_SSL_DATA_OUT:
|
||||
if(!traced_data) {
|
||||
/* if the data is output to a tty and we're sending this debug trace
|
||||
to stderr or stdout, we don't display the alert about the data not
|
||||
being shown as the data _is_ shown then just not via this
|
||||
function */
|
||||
if(!config->isatty || ((output != stderr) && (output != stdout))) {
|
||||
if(!newl)
|
||||
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||
fprintf(output, "[%zu bytes data]\n", size);
|
||||
newl = FALSE;
|
||||
traced_data = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: /* nada */
|
||||
newl = FALSE;
|
||||
traced_data = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
/* Special processing is needed for CURLINFO_HEADER_OUT blocks
|
||||
* if they contain both headers and data (separated by CRLFCRLF).
|
||||
* We dump the header text and then switch type to CURLINFO_DATA_OUT.
|
||||
*/
|
||||
if((type == CURLINFO_HEADER_OUT) && (size > 4)) {
|
||||
size_t i;
|
||||
for(i = 0; i < size - 4; i++) {
|
||||
if(memcmp(&data[i], "\r\n\r\n", 4) == 0) {
|
||||
/* dump everything through the CRLFCRLF as a sent header */
|
||||
text = "=> Send header";
|
||||
dump(timebuf, text, output, (unsigned char *)data, i + 4,
|
||||
config->tracetype, type);
|
||||
data += i + 3;
|
||||
size -= i + 4;
|
||||
type = CURLINFO_DATA_OUT;
|
||||
data += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CURL_DOES_CONVERSIONS */
|
||||
|
||||
switch(type) {
|
||||
case CURLINFO_TEXT:
|
||||
fprintf(output, "%s== Info: %.*s", timebuf, (int)size, data);
|
||||
/* FALLTHROUGH */
|
||||
default: /* in case a new one is introduced to shock us */
|
||||
return 0;
|
||||
|
||||
case CURLINFO_HEADER_OUT:
|
||||
text = "=> Send header";
|
||||
break;
|
||||
case CURLINFO_DATA_OUT:
|
||||
text = "=> Send data";
|
||||
break;
|
||||
case CURLINFO_HEADER_IN:
|
||||
text = "<= Recv header";
|
||||
break;
|
||||
case CURLINFO_DATA_IN:
|
||||
text = "<= Recv data";
|
||||
break;
|
||||
case CURLINFO_SSL_DATA_IN:
|
||||
text = "<= Recv SSL data";
|
||||
break;
|
||||
case CURLINFO_SSL_DATA_OUT:
|
||||
text = "=> Send SSL data";
|
||||
break;
|
||||
}
|
||||
|
||||
dump(timebuf, text, output, (unsigned char *) data, size, config->tracetype,
|
||||
type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dump(const char *timebuf, const char *text,
|
||||
FILE *stream, const unsigned char *ptr, size_t size,
|
||||
trace tracetype, curl_infotype infotype)
|
||||
{
|
||||
size_t i;
|
||||
size_t c;
|
||||
|
||||
unsigned int width = 0x10;
|
||||
|
||||
if(tracetype == TRACE_ASCII)
|
||||
/* without the hex output, we can fit more on screen */
|
||||
width = 0x40;
|
||||
|
||||
fprintf(stream, "%s%s, %zu bytes (0x%zx)\n", timebuf, text, size, size);
|
||||
|
||||
for(i = 0; i < size; i += width) {
|
||||
|
||||
fprintf(stream, "%04zx: ", i);
|
||||
|
||||
if(tracetype == TRACE_BIN) {
|
||||
/* hex not disabled, show it */
|
||||
for(c = 0; c < width; c++)
|
||||
if(i + c < size)
|
||||
fprintf(stream, "%02x ", ptr[i + c]);
|
||||
else
|
||||
fputs(" ", stream);
|
||||
}
|
||||
|
||||
for(c = 0; (c < width) && (i + c < size); c++) {
|
||||
/* check for 0D0A; if found, skip past and start a new line of output */
|
||||
if((tracetype == TRACE_ASCII) &&
|
||||
(i + c + 1 < size) && (ptr[i + c] == 0x0D) &&
|
||||
(ptr[i + c + 1] == 0x0A)) {
|
||||
i += (c + 2 - width);
|
||||
break;
|
||||
}
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
/* repeat the 0D0A check above but use the host encoding for CRLF */
|
||||
if((tracetype == TRACE_ASCII) &&
|
||||
(i + c + 1 < size) && (ptr[i + c] == '\r') &&
|
||||
(ptr[i + c + 1] == '\n')) {
|
||||
i += (c + 2 - width);
|
||||
break;
|
||||
}
|
||||
/* convert to host encoding and print this character */
|
||||
fprintf(stream, "%c", convert_char(infotype, ptr[i + c]));
|
||||
#else
|
||||
(void)infotype;
|
||||
fprintf(stream, "%c", ((ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80)) ?
|
||||
ptr[i + c] : UNPRINTABLE_CHAR);
|
||||
#endif /* CURL_DOES_CONVERSIONS */
|
||||
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
||||
if((tracetype == TRACE_ASCII) &&
|
||||
(i + c + 2 < size) && (ptr[i + c + 1] == 0x0D) &&
|
||||
(ptr[i + c + 2] == 0x0A)) {
|
||||
i += (c + 3 - width);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fputc('\n', stream); /* newline */
|
||||
}
|
||||
fflush(stream);
|
||||
}
|
34
module/Vendor/CURL/src/tool_cb_dbg.h
vendored
Normal file
34
module/Vendor/CURL/src/tool_cb_dbg.h
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_DBG_H
|
||||
#define HEADER_CURL_TOOL_CB_DBG_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_DEBUGFUNCTION
|
||||
*/
|
||||
|
||||
int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
char *data, size_t size,
|
||||
void *userdata);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_DBG_H */
|
313
module/Vendor/CURL/src/tool_cb_hdr.c
vendored
Normal file
313
module/Vendor/CURL/src/tool_cb_hdr.c
vendored
Normal file
@ -0,0 +1,313 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_cb_hdr.h"
|
||||
#include "tool_cb_wrt.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static char *parse_filename(const char *ptr, size_t len);
|
||||
|
||||
#ifdef WIN32
|
||||
#define BOLD
|
||||
#define BOLDOFF
|
||||
#else
|
||||
#define BOLD "\x1b[1m"
|
||||
/* Switch off bold by setting "all attributes off" since the explicit
|
||||
bold-off code (21) isn't supported everywhere - like in the mac
|
||||
Terminal. */
|
||||
#define BOLDOFF "\x1b[0m"
|
||||
#endif
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_HEADERFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
struct per_transfer *per = userdata;
|
||||
struct HdrCbData *hdrcbdata = &per->hdrcbdata;
|
||||
struct OutStruct *outs = &per->outs;
|
||||
struct OutStruct *heads = &per->heads;
|
||||
struct OutStruct *etag_save = &per->etag_save;
|
||||
const char *str = ptr;
|
||||
const size_t cb = size * nmemb;
|
||||
const char *end = (char *)ptr + cb;
|
||||
long protocol = 0;
|
||||
|
||||
/*
|
||||
* Once that libcurl has called back tool_header_cb() the returned value
|
||||
* is checked against the amount that was intended to be written, if
|
||||
* it does not match then it fails with CURLE_WRITE_ERROR. So at this
|
||||
* point returning a value different from sz*nmemb indicates failure.
|
||||
*/
|
||||
size_t failure = (size && nmemb) ? 0 : 1;
|
||||
|
||||
if(!per->config)
|
||||
return failure;
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
|
||||
warnf(per->config->global, "Header data exceeds single call write "
|
||||
"limit!\n");
|
||||
return failure;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Write header data when curl option --dump-header (-D) is given.
|
||||
*/
|
||||
|
||||
if(per->config->headerfile && heads->stream) {
|
||||
size_t rc = fwrite(ptr, size, nmemb, heads->stream);
|
||||
if(rc != cb)
|
||||
return rc;
|
||||
/* flush the stream to send off what we got earlier */
|
||||
(void)fflush(heads->stream);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write etag to file when --etag-save option is given.
|
||||
*/
|
||||
if(per->config->etag_save_file && etag_save->stream) {
|
||||
/* match only header that start with etag (case insensitive) */
|
||||
if(curl_strnequal(str, "etag:", 5)) {
|
||||
const char *etag_h = &str[5];
|
||||
const char *eot = end - 1;
|
||||
if(*eot == '\n') {
|
||||
while(ISSPACE(*etag_h) && (etag_h < eot))
|
||||
etag_h++;
|
||||
while(ISSPACE(*eot))
|
||||
eot--;
|
||||
|
||||
if(eot >= etag_h) {
|
||||
size_t etag_length = eot - etag_h + 1;
|
||||
fwrite(etag_h, size, etag_length, etag_save->stream);
|
||||
/* terminate with newline */
|
||||
fputc('\n', etag_save->stream);
|
||||
(void)fflush(etag_save->stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback sets the filename where output shall be written when
|
||||
* curl options --remote-name (-O) and --remote-header-name (-J) have
|
||||
* been simultaneously given and additionally server returns an HTTP
|
||||
* Content-Disposition header specifying a filename property.
|
||||
*/
|
||||
|
||||
curl_easy_getinfo(per->curl, CURLINFO_PROTOCOL, &protocol);
|
||||
if(hdrcbdata->honor_cd_filename &&
|
||||
(cb > 20) && checkprefix("Content-disposition:", str) &&
|
||||
(protocol & (CURLPROTO_HTTPS|CURLPROTO_HTTP))) {
|
||||
const char *p = str + 20;
|
||||
|
||||
/* look for the 'filename=' parameter
|
||||
(encoded filenames (*=) are not supported) */
|
||||
for(;;) {
|
||||
char *filename;
|
||||
size_t len;
|
||||
|
||||
while(*p && (p < end) && !ISALPHA(*p))
|
||||
p++;
|
||||
if(p > end - 9)
|
||||
break;
|
||||
|
||||
if(memcmp(p, "filename=", 9)) {
|
||||
/* no match, find next parameter */
|
||||
while((p < end) && (*p != ';'))
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
p += 9;
|
||||
|
||||
/* this expression below typecasts 'cb' only to avoid
|
||||
warning: signed and unsigned type in conditional expression
|
||||
*/
|
||||
len = (ssize_t)cb - (p - str);
|
||||
filename = parse_filename(p, len);
|
||||
if(filename) {
|
||||
if(outs->stream) {
|
||||
/* indication of problem, get out! */
|
||||
free(filename);
|
||||
return failure;
|
||||
}
|
||||
|
||||
outs->is_cd_filename = TRUE;
|
||||
outs->s_isreg = TRUE;
|
||||
outs->fopened = FALSE;
|
||||
outs->filename = filename;
|
||||
outs->alloc_filename = TRUE;
|
||||
hdrcbdata->honor_cd_filename = FALSE; /* done now! */
|
||||
if(!tool_create_output_file(outs, per->config))
|
||||
return failure;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(!outs->stream && !tool_create_output_file(outs, per->config))
|
||||
return failure;
|
||||
}
|
||||
if(hdrcbdata->config->writeout) {
|
||||
char *value = memchr(ptr, ':', cb);
|
||||
if(value) {
|
||||
if(per->was_last_header_empty)
|
||||
per->num_headers = 0;
|
||||
per->was_last_header_empty = FALSE;
|
||||
per->num_headers++;
|
||||
}
|
||||
else if(ptr[0] == '\r' || ptr[0] == '\n')
|
||||
per->was_last_header_empty = TRUE;
|
||||
}
|
||||
if(hdrcbdata->config->show_headers &&
|
||||
(protocol &
|
||||
(CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_RTSP|CURLPROTO_FILE))) {
|
||||
/* bold headers only for selected protocols */
|
||||
char *value = NULL;
|
||||
|
||||
if(!outs->stream && !tool_create_output_file(outs, per->config))
|
||||
return failure;
|
||||
|
||||
if(hdrcbdata->global->isatty && hdrcbdata->global->styled_output)
|
||||
value = memchr(ptr, ':', cb);
|
||||
if(value) {
|
||||
size_t namelen = value - ptr;
|
||||
fprintf(outs->stream, BOLD "%.*s" BOLDOFF ":", namelen, ptr);
|
||||
fwrite(&value[1], cb - namelen - 1, 1, outs->stream);
|
||||
}
|
||||
else
|
||||
/* not "handled", just show it */
|
||||
fwrite(ptr, cb, 1, outs->stream);
|
||||
}
|
||||
return cb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copies a file name part and returns an ALLOCATED data buffer.
|
||||
*/
|
||||
static char *parse_filename(const char *ptr, size_t len)
|
||||
{
|
||||
char *copy;
|
||||
char *p;
|
||||
char *q;
|
||||
char stop = '\0';
|
||||
|
||||
/* simple implementation of strndup() */
|
||||
copy = malloc(len + 1);
|
||||
if(!copy)
|
||||
return NULL;
|
||||
memcpy(copy, ptr, len);
|
||||
copy[len] = '\0';
|
||||
|
||||
p = copy;
|
||||
if(*p == '\'' || *p == '"') {
|
||||
/* store the starting quote */
|
||||
stop = *p;
|
||||
p++;
|
||||
}
|
||||
else
|
||||
stop = ';';
|
||||
|
||||
/* scan for the end letter and stop there */
|
||||
q = strchr(p, stop);
|
||||
if(q)
|
||||
*q = '\0';
|
||||
|
||||
/* if the filename contains a path, only use filename portion */
|
||||
q = strrchr(p, '/');
|
||||
if(q) {
|
||||
p = q + 1;
|
||||
if(!*p) {
|
||||
Curl_safefree(copy);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the filename contains a backslash, only use filename portion. The idea
|
||||
is that even systems that don't handle backslashes as path separators
|
||||
probably want the path removed for convenience. */
|
||||
q = strrchr(p, '\\');
|
||||
if(q) {
|
||||
p = q + 1;
|
||||
if(!*p) {
|
||||
Curl_safefree(copy);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* make sure the file name doesn't end in \r or \n */
|
||||
q = strchr(p, '\r');
|
||||
if(q)
|
||||
*q = '\0';
|
||||
|
||||
q = strchr(p, '\n');
|
||||
if(q)
|
||||
*q = '\0';
|
||||
|
||||
if(copy != p)
|
||||
memmove(copy, p, strlen(p) + 1);
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
{
|
||||
char *sanitized;
|
||||
SANITIZEcode sc = sanitize_file_name(&sanitized, copy, 0);
|
||||
Curl_safefree(copy);
|
||||
if(sc)
|
||||
return NULL;
|
||||
copy = sanitized;
|
||||
}
|
||||
#endif /* MSDOS || WIN32 */
|
||||
|
||||
/* in case we built debug enabled, we allow an environment variable
|
||||
* named CURL_TESTDIR to prefix the given file name to put it into a
|
||||
* specific directory
|
||||
*/
|
||||
#ifdef DEBUGBUILD
|
||||
{
|
||||
char *tdir = curlx_getenv("CURL_TESTDIR");
|
||||
if(tdir) {
|
||||
char buffer[512]; /* suitably large */
|
||||
msnprintf(buffer, sizeof(buffer), "%s/%s", tdir, copy);
|
||||
Curl_safefree(copy);
|
||||
copy = strdup(buffer); /* clone the buffer, we don't use the libcurl
|
||||
aprintf() or similar since we want to use the
|
||||
same memory code as the "real" parse_filename
|
||||
function */
|
||||
curl_free(tdir);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return copy;
|
||||
}
|
56
module/Vendor/CURL/src/tool_cb_hdr.h
vendored
Normal file
56
module/Vendor/CURL/src/tool_cb_hdr.h
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_HDR_H
|
||||
#define HEADER_CURL_TOOL_CB_HDR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/*
|
||||
* curl operates using a single HdrCbData struct variable, a
|
||||
* pointer to this is passed as userdata pointer to tool_header_cb.
|
||||
*
|
||||
* 'outs' member is a pointer to the OutStruct variable used to keep
|
||||
* track of information relative to curl's output writing.
|
||||
*
|
||||
* 'heads' member is a pointer to the OutStruct variable used to keep
|
||||
* track of information relative to header response writing.
|
||||
*
|
||||
* 'honor_cd_filename' member is TRUE when tool_header_cb is allowed
|
||||
* to honor Content-Disposition filename property and accordingly
|
||||
* set 'outs' filename, otherwise FALSE;
|
||||
*/
|
||||
|
||||
struct HdrCbData {
|
||||
struct GlobalConfig *global;
|
||||
struct OperationConfig *config;
|
||||
struct OutStruct *outs;
|
||||
struct OutStruct *heads;
|
||||
struct OutStruct *etag_save;
|
||||
bool honor_cd_filename;
|
||||
};
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_HEADERFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_HDR_H */
|
273
module/Vendor/CURL/src/tool_cb_prg.c
vendored
Normal file
273
module/Vendor/CURL/src/tool_cb_prg.c
vendored
Normal file
@ -0,0 +1,273 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_cb_prg.h"
|
||||
#include "tool_util.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
# include <termio.h>
|
||||
#endif
|
||||
|
||||
/* 200 values generated by this perl code:
|
||||
|
||||
my $pi = 3.1415;
|
||||
foreach my $i (1 .. 200) {
|
||||
printf "%d, ", sin($i/200 * 2 * $pi) * 500000 + 500000;
|
||||
}
|
||||
*/
|
||||
static const unsigned int sinus[] = {
|
||||
515704, 531394, 547052, 562664, 578214, 593687, 609068, 624341, 639491,
|
||||
654504, 669364, 684057, 698568, 712883, 726989, 740870, 754513, 767906,
|
||||
781034, 793885, 806445, 818704, 830647, 842265, 853545, 864476, 875047,
|
||||
885248, 895069, 904500, 913532, 922156, 930363, 938145, 945495, 952406,
|
||||
958870, 964881, 970434, 975522, 980141, 984286, 987954, 991139, 993840,
|
||||
996054, 997778, 999011, 999752, 999999, 999754, 999014, 997783, 996060,
|
||||
993848, 991148, 987964, 984298, 980154, 975536, 970449, 964898, 958888,
|
||||
952426, 945516, 938168, 930386, 922180, 913558, 904527, 895097, 885277,
|
||||
875077, 864507, 853577, 842299, 830682, 818739, 806482, 793922, 781072,
|
||||
767945, 754553, 740910, 727030, 712925, 698610, 684100, 669407, 654548,
|
||||
639536, 624386, 609113, 593733, 578260, 562710, 547098, 531440, 515751,
|
||||
500046, 484341, 468651, 452993, 437381, 421830, 406357, 390976, 375703,
|
||||
360552, 345539, 330679, 315985, 301474, 287158, 273052, 259170, 245525,
|
||||
232132, 219003, 206152, 193590, 181331, 169386, 157768, 146487, 135555,
|
||||
124983, 114781, 104959, 95526, 86493, 77868, 69660, 61876, 54525, 47613,
|
||||
41147, 35135, 29581, 24491, 19871, 15724, 12056, 8868, 6166, 3951, 2225,
|
||||
990, 248, 0, 244, 982, 2212, 3933, 6144, 8842, 12025, 15690, 19832, 24448,
|
||||
29534, 35084, 41092, 47554, 54462, 61809, 69589, 77794, 86415, 95445,
|
||||
104873, 114692, 124891, 135460, 146389, 157667, 169282, 181224, 193480,
|
||||
206039, 218888, 232015, 245406, 259048, 272928, 287032, 301346, 315856,
|
||||
330548, 345407, 360419, 375568, 390841, 406221, 421693, 437243, 452854,
|
||||
468513, 484202, 499907
|
||||
};
|
||||
|
||||
static void fly(struct ProgressData *bar, bool moved)
|
||||
{
|
||||
char buf[256];
|
||||
int pos;
|
||||
int check = bar->width - 2;
|
||||
|
||||
msnprintf(buf, sizeof(buf), "%*s\r", bar->width-1, " ");
|
||||
memcpy(&buf[bar->bar], "-=O=-", 5);
|
||||
|
||||
pos = sinus[bar->tick%200] / (1000000 / check);
|
||||
buf[pos] = '#';
|
||||
pos = sinus[(bar->tick + 5)%200] / (1000000 / check);
|
||||
buf[pos] = '#';
|
||||
pos = sinus[(bar->tick + 10)%200] / (1000000 / check);
|
||||
buf[pos] = '#';
|
||||
pos = sinus[(bar->tick + 15)%200] / (1000000 / check);
|
||||
buf[pos] = '#';
|
||||
|
||||
fputs(buf, bar->out);
|
||||
bar->tick += 2;
|
||||
if(bar->tick >= 200)
|
||||
bar->tick -= 200;
|
||||
|
||||
bar->bar += (moved?bar->barmove:0);
|
||||
if(bar->bar >= (bar->width - 6)) {
|
||||
bar->barmove = -1;
|
||||
bar->bar = bar->width - 6;
|
||||
}
|
||||
else if(bar->bar < 0) {
|
||||
bar->barmove = 1;
|
||||
bar->bar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_XFERINFOFUNCTION
|
||||
*/
|
||||
|
||||
#define MAX_BARLENGTH 256
|
||||
|
||||
#if (SIZEOF_CURL_OFF_T == 4)
|
||||
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
|
||||
#else
|
||||
/* assume CURL_SIZEOF_CURL_OFF_T == 8 */
|
||||
# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
int tool_progress_cb(void *clientp,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
/* The original progress-bar source code was written for curl by Lars Aas,
|
||||
and this new edition inherits some of his concepts. */
|
||||
|
||||
struct timeval now = tvnow();
|
||||
struct per_transfer *per = clientp;
|
||||
struct OperationConfig *config = per->config;
|
||||
struct ProgressData *bar = &per->progressbar;
|
||||
curl_off_t total;
|
||||
curl_off_t point;
|
||||
|
||||
/* Calculate expected transfer size. initial_size can be less than zero
|
||||
when indicating that we are expecting to get the filesize from the
|
||||
remote */
|
||||
if(bar->initial_size < 0 ||
|
||||
((CURL_OFF_T_MAX - bar->initial_size) < (dltotal + ultotal)))
|
||||
total = CURL_OFF_T_MAX;
|
||||
else
|
||||
total = dltotal + ultotal + bar->initial_size;
|
||||
|
||||
/* Calculate the current progress. initial_size can be less than zero when
|
||||
indicating that we are expecting to get the filesize from the remote */
|
||||
if(bar->initial_size < 0 ||
|
||||
((CURL_OFF_T_MAX - bar->initial_size) < (dlnow + ulnow)))
|
||||
point = CURL_OFF_T_MAX;
|
||||
else
|
||||
point = dlnow + ulnow + bar->initial_size;
|
||||
|
||||
if(bar->calls) {
|
||||
/* after first call... */
|
||||
if(total) {
|
||||
/* we know the total data to get... */
|
||||
if(bar->prev == point)
|
||||
/* progress didn't change since last invoke */
|
||||
return 0;
|
||||
else if((tvdiff(now, bar->prevtime) < 100L) && point < total)
|
||||
/* limit progress-bar updating to 10 Hz except when we're at 100% */
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
/* total is unknown */
|
||||
if(tvdiff(now, bar->prevtime) < 100L)
|
||||
/* limit progress-bar updating to 10 Hz */
|
||||
return 0;
|
||||
fly(bar, point != bar->prev);
|
||||
}
|
||||
}
|
||||
|
||||
/* simply count invokes */
|
||||
bar->calls++;
|
||||
|
||||
if((total > 0) && (point != bar->prev)) {
|
||||
char line[MAX_BARLENGTH + 1];
|
||||
char format[40];
|
||||
double frac;
|
||||
double percent;
|
||||
int barwidth;
|
||||
int num;
|
||||
if(point > total)
|
||||
/* we have got more than the expected total! */
|
||||
total = point;
|
||||
|
||||
frac = (double)point / (double)total;
|
||||
percent = frac * 100.0;
|
||||
barwidth = bar->width - 7;
|
||||
num = (int) (((double)barwidth) * frac);
|
||||
if(num > MAX_BARLENGTH)
|
||||
num = MAX_BARLENGTH;
|
||||
memset(line, '#', num);
|
||||
line[num] = '\0';
|
||||
msnprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth);
|
||||
fprintf(bar->out, format, line, percent);
|
||||
}
|
||||
fflush(bar->out);
|
||||
bar->prev = point;
|
||||
bar->prevtime = now;
|
||||
|
||||
if(config->readbusy) {
|
||||
config->readbusy = FALSE;
|
||||
curl_easy_pause(per->curl, CURLPAUSE_CONT);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void progressbarinit(struct ProgressData *bar,
|
||||
struct OperationConfig *config)
|
||||
{
|
||||
char *colp;
|
||||
memset(bar, 0, sizeof(struct ProgressData));
|
||||
|
||||
/* pass this through to progress function so
|
||||
* it can display progress towards total file
|
||||
* not just the part that's left. (21-may-03, dbyron) */
|
||||
if(config->use_resume)
|
||||
bar->initial_size = config->resume_from;
|
||||
|
||||
colp = curlx_getenv("COLUMNS");
|
||||
if(colp) {
|
||||
char *endptr;
|
||||
long num = strtol(colp, &endptr, 10);
|
||||
if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 20) &&
|
||||
(num < 10000))
|
||||
bar->width = (int)num;
|
||||
curl_free(colp);
|
||||
}
|
||||
|
||||
if(!bar->width) {
|
||||
int cols = 0;
|
||||
|
||||
#ifdef TIOCGSIZE
|
||||
struct ttysize ts;
|
||||
if(!ioctl(STDIN_FILENO, TIOCGSIZE, &ts))
|
||||
cols = ts.ts_cols;
|
||||
#elif defined(TIOCGWINSZ)
|
||||
struct winsize ts;
|
||||
if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
|
||||
cols = ts.ws_col;
|
||||
#elif defined(WIN32)
|
||||
{
|
||||
HANDLE stderr_hnd = GetStdHandle(STD_ERROR_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||
|
||||
if((stderr_hnd != INVALID_HANDLE_VALUE) &&
|
||||
GetConsoleScreenBufferInfo(stderr_hnd, &console_info)) {
|
||||
/*
|
||||
* Do not use +1 to get the true screen-width since writing a
|
||||
* character at the right edge will cause a line wrap.
|
||||
*/
|
||||
cols = (int)
|
||||
(console_info.srWindow.Right - console_info.srWindow.Left);
|
||||
}
|
||||
}
|
||||
#endif /* TIOCGSIZE */
|
||||
if(cols > 20)
|
||||
bar->width = cols;
|
||||
}
|
||||
|
||||
if(!bar->width)
|
||||
bar->width = 79;
|
||||
else if(bar->width > MAX_BARLENGTH)
|
||||
bar->width = MAX_BARLENGTH;
|
||||
|
||||
bar->out = config->global->errors;
|
||||
bar->tick = 150;
|
||||
bar->barmove = 1;
|
||||
}
|
52
module/Vendor/CURL/src/tool_cb_prg.h
vendored
Normal file
52
module/Vendor/CURL/src/tool_cb_prg.h
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_PRG_H
|
||||
#define HEADER_CURL_TOOL_CB_PRG_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define CURL_PROGRESS_STATS 0 /* default progress display */
|
||||
#define CURL_PROGRESS_BAR 1
|
||||
|
||||
struct ProgressData {
|
||||
int calls;
|
||||
curl_off_t prev;
|
||||
struct timeval prevtime;
|
||||
int width;
|
||||
FILE *out; /* where to write everything to */
|
||||
curl_off_t initial_size;
|
||||
unsigned int tick;
|
||||
int bar;
|
||||
int barmove;
|
||||
};
|
||||
|
||||
void progressbarinit(struct ProgressData *bar,
|
||||
struct OperationConfig *config);
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_PROGRESSFUNCTION
|
||||
*/
|
||||
|
||||
int tool_progress_cb(void *clientp,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_PRG_H */
|
79
module/Vendor/CURL/src/tool_cb_rea.c
vendored
Normal file
79
module/Vendor/CURL/src/tool_cb_rea.c
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_cb_rea.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_READFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
|
||||
{
|
||||
ssize_t rc;
|
||||
struct InStruct *in = userdata;
|
||||
|
||||
rc = read(in->fd, buffer, sz*nmemb);
|
||||
if(rc < 0) {
|
||||
if(errno == EAGAIN) {
|
||||
errno = 0;
|
||||
in->config->readbusy = TRUE;
|
||||
return CURL_READFUNC_PAUSE;
|
||||
}
|
||||
/* since size_t is unsigned we can't return negative values fine */
|
||||
rc = 0;
|
||||
}
|
||||
in->config->readbusy = FALSE;
|
||||
return (size_t)rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
|
||||
*/
|
||||
|
||||
int tool_readbusy_cb(void *clientp,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
struct per_transfer *per = clientp;
|
||||
struct OperationConfig *config = per->config;
|
||||
|
||||
(void)dltotal; /* unused */
|
||||
(void)dlnow; /* unused */
|
||||
(void)ultotal; /* unused */
|
||||
(void)ulnow; /* unused */
|
||||
|
||||
if(config->readbusy) {
|
||||
config->readbusy = FALSE;
|
||||
curl_easy_pause(per->curl, CURLPAUSE_CONT);
|
||||
}
|
||||
|
||||
return per->noprogress? 0 : CURL_PROGRESSFUNC_CONTINUE;
|
||||
}
|
40
module/Vendor/CURL/src/tool_cb_rea.h
vendored
Normal file
40
module/Vendor/CURL/src/tool_cb_rea.h
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_REA_H
|
||||
#define HEADER_CURL_TOOL_CB_REA_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_READFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata);
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
|
||||
*/
|
||||
|
||||
int tool_readbusy_cb(void *clientp,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_REA_H */
|
132
module/Vendor/CURL/src/tool_cb_see.c
vendored
Normal file
132
module/Vendor/CURL/src/tool_cb_see.c
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_cb_see.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* OUR_MAX_SEEK_L has 'long' data type, OUR_MAX_SEEK_O has 'curl_off_t,
|
||||
both represent the same value. Maximum offset used here when we lseek
|
||||
using a 'long' data type offset */
|
||||
|
||||
#define OUR_MAX_SEEK_L 2147483647L - 1L
|
||||
#define OUR_MAX_SEEK_O CURL_OFF_T_C(0x7FFFFFFF) - CURL_OFF_T_C(0x1)
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_SEEKFUNCTION
|
||||
**
|
||||
** Notice that this is not supposed to return the resulting offset. This
|
||||
** shall only return CURL_SEEKFUNC_* return codes.
|
||||
*/
|
||||
|
||||
int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
|
||||
{
|
||||
struct InStruct *in = userdata;
|
||||
|
||||
#if(CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES)
|
||||
|
||||
/* The offset check following here is only interesting if curl_off_t is
|
||||
larger than off_t and we are not using the WIN32 large file support
|
||||
macros that provide the support to do 64bit seeks correctly */
|
||||
|
||||
if(offset > OUR_MAX_SEEK_O) {
|
||||
/* Some precaution code to work around problems with different data sizes
|
||||
to allow seeking >32bit even if off_t is 32bit. Should be very rare and
|
||||
is really valid on weirdo-systems. */
|
||||
curl_off_t left = offset;
|
||||
|
||||
if(whence != SEEK_SET)
|
||||
/* this code path doesn't support other types */
|
||||
return CURL_SEEKFUNC_FAIL;
|
||||
|
||||
if(LSEEK_ERROR == lseek(in->fd, 0, SEEK_SET))
|
||||
/* couldn't rewind to beginning */
|
||||
return CURL_SEEKFUNC_FAIL;
|
||||
|
||||
while(left) {
|
||||
long step = (left > OUR_MAX_SEEK_O) ? OUR_MAX_SEEK_L : (long)left;
|
||||
if(LSEEK_ERROR == lseek(in->fd, step, SEEK_CUR))
|
||||
/* couldn't seek forwards the desired amount */
|
||||
return CURL_SEEKFUNC_FAIL;
|
||||
left -= step;
|
||||
}
|
||||
return CURL_SEEKFUNC_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(LSEEK_ERROR == lseek(in->fd, offset, whence))
|
||||
/* couldn't rewind, the reason is in errno but errno is just not portable
|
||||
enough and we don't actually care that much why we failed. We'll let
|
||||
libcurl know that it may try other means if it wants to. */
|
||||
return CURL_SEEKFUNC_CANTSEEK;
|
||||
|
||||
return CURL_SEEKFUNC_OK;
|
||||
}
|
||||
|
||||
#ifdef USE_TOOL_FTRUNCATE
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
/* 64-bit lseek-like function unavailable */
|
||||
# define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
|
||||
#endif
|
||||
|
||||
#ifdef __POCC__
|
||||
# if(__POCC__ < 450)
|
||||
/* 64-bit lseek-like function unavailable */
|
||||
# define _lseeki64(hnd,ofs,whence) _lseek(hnd,ofs,whence)
|
||||
# else
|
||||
# define _lseeki64(hnd,ofs,whence) _lseek64(hnd,ofs,whence)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
/* 64-bit lseek-like function unavailable */
|
||||
# undef _lseeki64
|
||||
# define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
|
||||
# undef _get_osfhandle
|
||||
# define _get_osfhandle(fd) (fd)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Truncate a file handle at a 64-bit position 'where'.
|
||||
*/
|
||||
|
||||
int tool_ftruncate64(int fd, curl_off_t where)
|
||||
{
|
||||
intptr_t handle = _get_osfhandle(fd);
|
||||
|
||||
if(_lseeki64(fd, where, SEEK_SET) < 0)
|
||||
return -1;
|
||||
|
||||
if(!SetEndOfFile((HANDLE)handle))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* USE_TOOL_FTRUNCATE */
|
44
module/Vendor/CURL/src/tool_cb_see.h
vendored
Normal file
44
module/Vendor/CURL/src/tool_cb_see.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_SEE_H
|
||||
#define HEADER_CURL_TOOL_CB_SEE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(WIN32) && !defined(HAVE_FTRUNCATE)
|
||||
|
||||
int tool_ftruncate64(int fd, curl_off_t where);
|
||||
|
||||
#undef ftruncate
|
||||
#define ftruncate(fd,where) tool_ftruncate64(fd,where)
|
||||
|
||||
#define HAVE_FTRUNCATE 1
|
||||
#define USE_TOOL_FTRUNCATE 1
|
||||
|
||||
#endif /* WIN32 && ! HAVE_FTRUNCATE */
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_SEEKFUNCTION
|
||||
*/
|
||||
|
||||
int tool_seek_cb(void *userdata, curl_off_t offset, int whence);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_SEE_H */
|
249
module/Vendor/CURL/src/tool_cb_wrt.c
vendored
Normal file
249
module/Vendor/CURL/src/tool_cb_wrt.c
vendored
Normal file
@ -0,0 +1,249 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
/* for open() */
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_cb_wrt.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#define OPENMODE S_IREAD | S_IWRITE
|
||||
#else
|
||||
#define OPENMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
|
||||
#endif
|
||||
|
||||
/* create a local file for writing, return TRUE on success */
|
||||
bool tool_create_output_file(struct OutStruct *outs,
|
||||
struct OperationConfig *config)
|
||||
{
|
||||
struct GlobalConfig *global;
|
||||
FILE *file = NULL;
|
||||
DEBUGASSERT(outs);
|
||||
DEBUGASSERT(config);
|
||||
global = config->global;
|
||||
if(!outs->filename || !*outs->filename) {
|
||||
warnf(global, "Remote filename has no length!\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(outs->is_cd_filename) {
|
||||
/* don't overwrite existing files */
|
||||
int fd;
|
||||
char *name = outs->filename;
|
||||
char *aname = NULL;
|
||||
if(config->output_dir) {
|
||||
aname = aprintf("%s/%s", config->output_dir, name);
|
||||
if(!aname) {
|
||||
errorf(global, "out of memory\n");
|
||||
return FALSE;
|
||||
}
|
||||
name = aname;
|
||||
}
|
||||
fd = open(name, O_CREAT | O_WRONLY | O_EXCL | O_BINARY, OPENMODE);
|
||||
if(fd != -1) {
|
||||
file = fdopen(fd, "wb");
|
||||
if(!file)
|
||||
close(fd);
|
||||
}
|
||||
free(aname);
|
||||
}
|
||||
else
|
||||
/* open file for writing */
|
||||
file = fopen(outs->filename, "wb");
|
||||
|
||||
if(!file) {
|
||||
warnf(global, "Failed to create the file %s: %s\n", outs->filename,
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
outs->s_isreg = TRUE;
|
||||
outs->fopened = TRUE;
|
||||
outs->stream = file;
|
||||
outs->bytes = 0;
|
||||
outs->init = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_WRITEFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
|
||||
{
|
||||
size_t rc;
|
||||
struct per_transfer *per = userdata;
|
||||
struct OutStruct *outs = &per->outs;
|
||||
struct OperationConfig *config = per->config;
|
||||
size_t bytes = sz * nmemb;
|
||||
bool is_tty = config->global->isatty;
|
||||
#ifdef WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||
intptr_t fhnd;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Once that libcurl has called back tool_write_cb() the returned value
|
||||
* is checked against the amount that was intended to be written, if
|
||||
* it does not match then it fails with CURLE_WRITE_ERROR. So at this
|
||||
* point returning a value different from sz*nmemb indicates failure.
|
||||
*/
|
||||
const size_t failure = bytes ? 0 : 1;
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
{
|
||||
char *tty = curlx_getenv("CURL_ISATTY");
|
||||
if(tty) {
|
||||
is_tty = TRUE;
|
||||
curl_free(tty);
|
||||
}
|
||||
}
|
||||
|
||||
if(config->show_headers) {
|
||||
if(bytes > (size_t)CURL_MAX_HTTP_HEADER) {
|
||||
warnf(config->global, "Header data size exceeds single call write "
|
||||
"limit!\n");
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(bytes > (size_t)CURL_MAX_WRITE_SIZE) {
|
||||
warnf(config->global, "Data size exceeds single call write limit!\n");
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* Some internal congruency checks on received OutStruct */
|
||||
bool check_fails = FALSE;
|
||||
if(outs->filename) {
|
||||
/* regular file */
|
||||
if(!*outs->filename)
|
||||
check_fails = TRUE;
|
||||
if(!outs->s_isreg)
|
||||
check_fails = TRUE;
|
||||
if(outs->fopened && !outs->stream)
|
||||
check_fails = TRUE;
|
||||
if(!outs->fopened && outs->stream)
|
||||
check_fails = TRUE;
|
||||
if(!outs->fopened && outs->bytes)
|
||||
check_fails = TRUE;
|
||||
}
|
||||
else {
|
||||
/* standard stream */
|
||||
if(!outs->stream || outs->s_isreg || outs->fopened)
|
||||
check_fails = TRUE;
|
||||
if(outs->alloc_filename || outs->is_cd_filename || outs->init)
|
||||
check_fails = TRUE;
|
||||
}
|
||||
if(check_fails) {
|
||||
warnf(config->global, "Invalid output struct data for write callback\n");
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!outs->stream && !tool_create_output_file(outs, per->config))
|
||||
return failure;
|
||||
|
||||
if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) {
|
||||
/* binary output to terminal? */
|
||||
if(memchr(buffer, 0, bytes)) {
|
||||
warnf(config->global, "Binary output can mess up your terminal. "
|
||||
"Use \"--output -\" to tell curl to output it to your terminal "
|
||||
"anyway, or consider \"--output <FILE>\" to save to a file.\n");
|
||||
config->synthetic_error = ERR_BINARY_TERMINAL;
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
fhnd = _get_osfhandle(fileno(outs->stream));
|
||||
if(isatty(fileno(outs->stream)) &&
|
||||
GetConsoleScreenBufferInfo((HANDLE)fhnd, &console_info)) {
|
||||
DWORD in_len = (DWORD)(sz * nmemb);
|
||||
wchar_t* wc_buf;
|
||||
DWORD wc_len;
|
||||
|
||||
/* calculate buffer size for wide characters */
|
||||
wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, NULL, 0);
|
||||
wc_buf = (wchar_t*) malloc(wc_len * sizeof(wchar_t));
|
||||
if(!wc_buf)
|
||||
return failure;
|
||||
|
||||
/* calculate buffer size for multi-byte characters */
|
||||
wc_len = MultiByteToWideChar(CP_UTF8, 0, buffer, in_len, wc_buf, wc_len);
|
||||
if(!wc_len) {
|
||||
free(wc_buf);
|
||||
return failure;
|
||||
}
|
||||
|
||||
if(!WriteConsoleW(
|
||||
(HANDLE) fhnd,
|
||||
wc_buf,
|
||||
wc_len,
|
||||
&wc_len,
|
||||
NULL)) {
|
||||
free(wc_buf);
|
||||
return failure;
|
||||
}
|
||||
free(wc_buf);
|
||||
rc = bytes;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
rc = fwrite(buffer, sz, nmemb, outs->stream);
|
||||
|
||||
if(bytes == rc)
|
||||
/* we added this amount of data to the output */
|
||||
outs->bytes += bytes;
|
||||
|
||||
if(config->readbusy) {
|
||||
config->readbusy = FALSE;
|
||||
curl_easy_pause(per->curl, CURLPAUSE_CONT);
|
||||
}
|
||||
|
||||
if(config->nobuffer) {
|
||||
/* output buffering disabled */
|
||||
int res = fflush(outs->stream);
|
||||
if(res)
|
||||
return failure;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
36
module/Vendor/CURL/src/tool_cb_wrt.h
vendored
Normal file
36
module/Vendor/CURL/src/tool_cb_wrt.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef HEADER_CURL_TOOL_CB_WRT_H
|
||||
#define HEADER_CURL_TOOL_CB_WRT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/*
|
||||
** callback for CURLOPT_WRITEFUNCTION
|
||||
*/
|
||||
|
||||
size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata);
|
||||
|
||||
/* create a local file for writing, return TRUE on success */
|
||||
bool tool_create_output_file(struct OutStruct *outs,
|
||||
struct OperationConfig *config);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CB_WRT_H */
|
188
module/Vendor/CURL/src/tool_cfgable.c
vendored
Normal file
188
module/Vendor/CURL/src/tool_cfgable.c
vendored
Normal file
@ -0,0 +1,188 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_main.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void config_init(struct OperationConfig *config)
|
||||
{
|
||||
memset(config, 0, sizeof(struct OperationConfig));
|
||||
|
||||
config->postfieldsize = -1;
|
||||
config->use_httpget = FALSE;
|
||||
config->create_dirs = FALSE;
|
||||
config->maxredirs = DEFAULT_MAXREDIRS;
|
||||
config->proto = CURLPROTO_ALL;
|
||||
config->proto_present = FALSE;
|
||||
config->proto_redir = CURLPROTO_ALL & /* All except FILE, SCP and SMB */
|
||||
~(CURLPROTO_FILE | CURLPROTO_SCP | CURLPROTO_SMB |
|
||||
CURLPROTO_SMBS);
|
||||
config->proto_redir_present = FALSE;
|
||||
config->proto_default = NULL;
|
||||
config->tcp_nodelay = TRUE; /* enabled by default */
|
||||
config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT;
|
||||
config->http09_allowed = FALSE;
|
||||
config->ftp_skip_ip = TRUE;
|
||||
}
|
||||
|
||||
static void free_config_fields(struct OperationConfig *config)
|
||||
{
|
||||
struct getout *urlnode;
|
||||
|
||||
Curl_safefree(config->random_file);
|
||||
Curl_safefree(config->egd_file);
|
||||
Curl_safefree(config->useragent);
|
||||
Curl_safefree(config->altsvc);
|
||||
Curl_safefree(config->hsts);
|
||||
Curl_safefree(config->cookie);
|
||||
Curl_safefree(config->cookiejar);
|
||||
Curl_safefree(config->cookiefile);
|
||||
|
||||
Curl_safefree(config->postfields);
|
||||
Curl_safefree(config->referer);
|
||||
|
||||
Curl_safefree(config->headerfile);
|
||||
Curl_safefree(config->ftpport);
|
||||
Curl_safefree(config->iface);
|
||||
|
||||
Curl_safefree(config->range);
|
||||
|
||||
Curl_safefree(config->userpwd);
|
||||
Curl_safefree(config->tls_username);
|
||||
Curl_safefree(config->tls_password);
|
||||
Curl_safefree(config->tls_authtype);
|
||||
Curl_safefree(config->proxy_tls_username);
|
||||
Curl_safefree(config->proxy_tls_password);
|
||||
Curl_safefree(config->proxy_tls_authtype);
|
||||
Curl_safefree(config->proxyuserpwd);
|
||||
Curl_safefree(config->proxy);
|
||||
|
||||
Curl_safefree(config->dns_ipv6_addr);
|
||||
Curl_safefree(config->dns_ipv4_addr);
|
||||
Curl_safefree(config->dns_interface);
|
||||
Curl_safefree(config->dns_servers);
|
||||
|
||||
Curl_safefree(config->noproxy);
|
||||
|
||||
Curl_safefree(config->mail_from);
|
||||
curl_slist_free_all(config->mail_rcpt);
|
||||
Curl_safefree(config->mail_auth);
|
||||
|
||||
Curl_safefree(config->netrc_file);
|
||||
Curl_safefree(config->output_dir);
|
||||
|
||||
urlnode = config->url_list;
|
||||
while(urlnode) {
|
||||
struct getout *next = urlnode->next;
|
||||
Curl_safefree(urlnode->url);
|
||||
Curl_safefree(urlnode->outfile);
|
||||
Curl_safefree(urlnode->infile);
|
||||
Curl_safefree(urlnode);
|
||||
urlnode = next;
|
||||
}
|
||||
config->url_list = NULL;
|
||||
config->url_last = NULL;
|
||||
config->url_get = NULL;
|
||||
config->url_out = NULL;
|
||||
|
||||
Curl_safefree(config->doh_url);
|
||||
Curl_safefree(config->cipher_list);
|
||||
Curl_safefree(config->proxy_cipher_list);
|
||||
Curl_safefree(config->cert);
|
||||
Curl_safefree(config->proxy_cert);
|
||||
Curl_safefree(config->cert_type);
|
||||
Curl_safefree(config->proxy_cert_type);
|
||||
Curl_safefree(config->cacert);
|
||||
Curl_safefree(config->login_options);
|
||||
Curl_safefree(config->proxy_cacert);
|
||||
Curl_safefree(config->capath);
|
||||
Curl_safefree(config->proxy_capath);
|
||||
Curl_safefree(config->crlfile);
|
||||
Curl_safefree(config->pinnedpubkey);
|
||||
Curl_safefree(config->proxy_pinnedpubkey);
|
||||
Curl_safefree(config->proxy_crlfile);
|
||||
Curl_safefree(config->key);
|
||||
Curl_safefree(config->proxy_key);
|
||||
Curl_safefree(config->key_type);
|
||||
Curl_safefree(config->proxy_key_type);
|
||||
Curl_safefree(config->key_passwd);
|
||||
Curl_safefree(config->proxy_key_passwd);
|
||||
Curl_safefree(config->pubkey);
|
||||
Curl_safefree(config->hostpubmd5);
|
||||
Curl_safefree(config->engine);
|
||||
Curl_safefree(config->etag_save_file);
|
||||
Curl_safefree(config->etag_compare_file);
|
||||
Curl_safefree(config->request_target);
|
||||
Curl_safefree(config->customrequest);
|
||||
Curl_safefree(config->krblevel);
|
||||
|
||||
Curl_safefree(config->oauth_bearer);
|
||||
Curl_safefree(config->sasl_authzid);
|
||||
|
||||
Curl_safefree(config->unix_socket_path);
|
||||
Curl_safefree(config->writeout);
|
||||
Curl_safefree(config->proto_default);
|
||||
|
||||
curl_slist_free_all(config->quote);
|
||||
curl_slist_free_all(config->postquote);
|
||||
curl_slist_free_all(config->prequote);
|
||||
|
||||
curl_slist_free_all(config->headers);
|
||||
curl_slist_free_all(config->proxyheaders);
|
||||
|
||||
curl_mime_free(config->mimepost);
|
||||
config->mimepost = NULL;
|
||||
tool_mime_free(config->mimeroot);
|
||||
config->mimeroot = NULL;
|
||||
config->mimecurrent = NULL;
|
||||
|
||||
curl_slist_free_all(config->telnet_options);
|
||||
curl_slist_free_all(config->resolve);
|
||||
curl_slist_free_all(config->connect_to);
|
||||
|
||||
Curl_safefree(config->preproxy);
|
||||
Curl_safefree(config->proxy_service_name);
|
||||
Curl_safefree(config->service_name);
|
||||
|
||||
Curl_safefree(config->ftp_account);
|
||||
Curl_safefree(config->ftp_alternative_to_user);
|
||||
|
||||
Curl_safefree(config->aws_sigv4_provider);
|
||||
}
|
||||
|
||||
void config_free(struct OperationConfig *config)
|
||||
{
|
||||
struct OperationConfig *last = config;
|
||||
|
||||
/* Free each of the structures in reverse order */
|
||||
while(last) {
|
||||
struct OperationConfig *prev = last->prev;
|
||||
|
||||
free_config_fields(last);
|
||||
free(last);
|
||||
|
||||
last = prev;
|
||||
}
|
||||
}
|
327
module/Vendor/CURL/src/tool_cfgable.h
vendored
Normal file
327
module/Vendor/CURL/src/tool_cfgable.h
vendored
Normal file
@ -0,0 +1,327 @@
|
||||
#ifndef HEADER_CURL_TOOL_CFGABLE_H
|
||||
#define HEADER_CURL_TOOL_CFGABLE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_sdecls.h"
|
||||
#include "tool_metalink.h"
|
||||
#include "tool_urlglob.h"
|
||||
#include "tool_formparse.h"
|
||||
|
||||
typedef enum {
|
||||
ERR_NONE,
|
||||
ERR_BINARY_TERMINAL = 1, /* binary to terminal detected */
|
||||
ERR_LAST
|
||||
} curl_error;
|
||||
|
||||
struct GlobalConfig;
|
||||
|
||||
struct State {
|
||||
struct getout *urlnode;
|
||||
struct URLGlob *inglob;
|
||||
struct URLGlob *urls;
|
||||
char *outfiles;
|
||||
char *httpgetfields;
|
||||
char *uploadfile;
|
||||
unsigned long infilenum; /* number of files to upload */
|
||||
unsigned long up; /* upload file counter within a single upload glob */
|
||||
unsigned long urlnum; /* how many iterations this single URL has with ranges
|
||||
etc */
|
||||
unsigned long li;
|
||||
};
|
||||
|
||||
struct OperationConfig {
|
||||
bool remote_time;
|
||||
char *random_file;
|
||||
char *egd_file;
|
||||
char *useragent;
|
||||
char *cookie; /* single line with specified cookies */
|
||||
char *cookiejar; /* write to this file */
|
||||
char *cookiefile; /* read from this file */
|
||||
char *altsvc; /* alt-svc cache file name */
|
||||
char *hsts; /* HSTS cache file name */
|
||||
bool cookiesession; /* new session? */
|
||||
bool encoding; /* Accept-Encoding please */
|
||||
bool tr_encoding; /* Transfer-Encoding please */
|
||||
unsigned long authtype; /* auth bitmask */
|
||||
bool use_resume;
|
||||
bool resume_from_current;
|
||||
bool disable_epsv;
|
||||
bool disable_eprt;
|
||||
bool ftp_pret;
|
||||
long proto;
|
||||
bool proto_present;
|
||||
long proto_redir;
|
||||
bool proto_redir_present;
|
||||
char *proto_default;
|
||||
curl_off_t resume_from;
|
||||
char *postfields;
|
||||
curl_off_t postfieldsize;
|
||||
char *referer;
|
||||
double timeout;
|
||||
double connecttimeout;
|
||||
long maxredirs;
|
||||
curl_off_t max_filesize;
|
||||
char *output_dir;
|
||||
char *headerfile;
|
||||
char *ftpport;
|
||||
char *iface;
|
||||
long localport;
|
||||
long localportrange;
|
||||
unsigned short porttouse;
|
||||
char *range;
|
||||
long low_speed_limit;
|
||||
long low_speed_time;
|
||||
char *dns_servers; /* dot notation: 1.1.1.1;2.2.2.2 */
|
||||
char *dns_interface; /* interface name */
|
||||
char *dns_ipv4_addr; /* dot notation */
|
||||
char *dns_ipv6_addr; /* dot notation */
|
||||
char *userpwd;
|
||||
char *login_options;
|
||||
char *tls_username;
|
||||
char *tls_password;
|
||||
char *tls_authtype;
|
||||
char *proxy_tls_username;
|
||||
char *proxy_tls_password;
|
||||
char *proxy_tls_authtype;
|
||||
char *proxyuserpwd;
|
||||
char *proxy;
|
||||
int proxyver; /* set to CURLPROXY_HTTP* define */
|
||||
char *noproxy;
|
||||
char *mail_from;
|
||||
struct curl_slist *mail_rcpt;
|
||||
char *mail_auth;
|
||||
bool mail_rcpt_allowfails; /* --mail-rcpt-allowfails */
|
||||
char *sasl_authzid; /* Authorisation identity (identity to use) */
|
||||
bool sasl_ir; /* Enable/disable SASL initial response */
|
||||
bool proxytunnel;
|
||||
bool ftp_append; /* APPE on ftp */
|
||||
bool use_ascii; /* select ascii or text transfer */
|
||||
bool autoreferer; /* automatically set referer */
|
||||
bool failonerror; /* fail on (HTTP) errors */
|
||||
bool show_headers; /* show headers to data output */
|
||||
bool no_body; /* don't get the body */
|
||||
bool dirlistonly; /* only get the FTP dir list */
|
||||
bool followlocation; /* follow http redirects */
|
||||
bool unrestricted_auth; /* Continue to send authentication (user+password)
|
||||
when following ocations, even when hostname
|
||||
changed */
|
||||
bool netrc_opt;
|
||||
bool netrc;
|
||||
char *netrc_file;
|
||||
struct getout *url_list; /* point to the first node */
|
||||
struct getout *url_last; /* point to the last/current node */
|
||||
struct getout *url_get; /* point to the node to fill in URL */
|
||||
struct getout *url_out; /* point to the node to fill in outfile */
|
||||
struct getout *url_ul; /* point to the node to fill in upload */
|
||||
char *doh_url;
|
||||
char *cipher_list;
|
||||
char *proxy_cipher_list;
|
||||
char *cipher13_list;
|
||||
char *proxy_cipher13_list;
|
||||
char *cert;
|
||||
char *proxy_cert;
|
||||
char *cert_type;
|
||||
char *proxy_cert_type;
|
||||
char *cacert;
|
||||
char *proxy_cacert;
|
||||
char *capath;
|
||||
char *proxy_capath;
|
||||
char *crlfile;
|
||||
char *proxy_crlfile;
|
||||
char *pinnedpubkey;
|
||||
char *proxy_pinnedpubkey;
|
||||
char *key;
|
||||
char *proxy_key;
|
||||
char *key_type;
|
||||
char *proxy_key_type;
|
||||
char *key_passwd;
|
||||
char *proxy_key_passwd;
|
||||
char *pubkey;
|
||||
char *hostpubmd5;
|
||||
char *engine;
|
||||
char *etag_save_file;
|
||||
char *etag_compare_file;
|
||||
bool crlf;
|
||||
char *customrequest;
|
||||
char *ssl_ec_curves;
|
||||
char *krblevel;
|
||||
char *request_target;
|
||||
long httpversion;
|
||||
bool http09_allowed;
|
||||
bool nobuffer;
|
||||
bool readbusy; /* set when reading input returns EAGAIN */
|
||||
bool globoff;
|
||||
bool use_httpget;
|
||||
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
|
||||
bool proxy_insecure_ok; /* set TRUE to allow insecure SSL connects
|
||||
for proxy */
|
||||
bool terminal_binary_ok;
|
||||
bool verifystatus;
|
||||
bool create_dirs;
|
||||
bool ftp_create_dirs;
|
||||
bool ftp_skip_ip;
|
||||
bool proxynegotiate;
|
||||
bool proxyntlm;
|
||||
bool proxydigest;
|
||||
bool proxybasic;
|
||||
bool proxyanyauth;
|
||||
char *writeout; /* %-styled format string to output */
|
||||
struct curl_slist *quote;
|
||||
struct curl_slist *postquote;
|
||||
struct curl_slist *prequote;
|
||||
long ssl_version;
|
||||
long ssl_version_max;
|
||||
long proxy_ssl_version;
|
||||
long ip_version;
|
||||
long create_file_mode; /* CURLOPT_NEW_FILE_PERMS */
|
||||
curl_TimeCond timecond;
|
||||
curl_off_t condtime;
|
||||
struct curl_slist *headers;
|
||||
struct curl_slist *proxyheaders;
|
||||
struct tool_mime *mimeroot;
|
||||
struct tool_mime *mimecurrent;
|
||||
curl_mime *mimepost;
|
||||
struct curl_slist *telnet_options;
|
||||
struct curl_slist *resolve;
|
||||
struct curl_slist *connect_to;
|
||||
HttpReq httpreq;
|
||||
|
||||
/* for bandwidth limiting features: */
|
||||
curl_off_t sendpersecond; /* send to peer */
|
||||
curl_off_t recvpersecond; /* receive from peer */
|
||||
|
||||
bool ftp_ssl;
|
||||
bool ftp_ssl_reqd;
|
||||
bool ftp_ssl_control;
|
||||
bool ftp_ssl_ccc;
|
||||
int ftp_ssl_ccc_mode;
|
||||
char *preproxy;
|
||||
int socks5_gssapi_nec; /* The NEC reference server does not protect the
|
||||
encryption type exchange */
|
||||
unsigned long socks5_auth;/* auth bitmask for socks5 proxies */
|
||||
char *proxy_service_name; /* set authentication service name for HTTP and
|
||||
SOCKS5 proxies */
|
||||
char *service_name; /* set authentication service name for DIGEST-MD5,
|
||||
Kerberos 5 and SPNEGO */
|
||||
|
||||
bool tcp_nodelay;
|
||||
bool tcp_fastopen;
|
||||
long req_retry; /* number of retries */
|
||||
bool retry_all_errors; /* retry on any error */
|
||||
bool retry_connrefused; /* set connection refused as a transient error */
|
||||
long retry_delay; /* delay between retries (in seconds) */
|
||||
long retry_maxtime; /* maximum time to keep retrying */
|
||||
|
||||
char *ftp_account; /* for ACCT */
|
||||
char *ftp_alternative_to_user; /* send command if USER/PASS fails */
|
||||
int ftp_filemethod;
|
||||
long tftp_blksize; /* TFTP BLKSIZE option */
|
||||
bool tftp_no_options; /* do not send TFTP options requests */
|
||||
bool ignorecl; /* --ignore-content-length */
|
||||
bool disable_sessionid;
|
||||
|
||||
bool raw;
|
||||
bool post301;
|
||||
bool post302;
|
||||
bool post303;
|
||||
bool nokeepalive; /* for keepalive needs */
|
||||
long alivetime;
|
||||
bool content_disposition; /* use Content-disposition filename */
|
||||
|
||||
int default_node_flags; /* default flags to search for each 'node', which
|
||||
is basically each given URL to transfer */
|
||||
|
||||
bool xattr; /* store metadata in extended attributes */
|
||||
long gssapi_delegation;
|
||||
bool ssl_allow_beast; /* allow this SSL vulnerability */
|
||||
bool proxy_ssl_allow_beast; /* allow this SSL vulnerability for proxy*/
|
||||
|
||||
bool ssl_no_revoke; /* disable SSL certificate revocation checks */
|
||||
/*bool proxy_ssl_no_revoke; */
|
||||
|
||||
bool ssl_revoke_best_effort; /* ignore SSL revocation offline/missing
|
||||
revocation list errors */
|
||||
|
||||
bool native_ca_store; /* use the native os ca store */
|
||||
|
||||
bool use_metalink; /* process given URLs as metalink XML file */
|
||||
struct metalinkfile *metalinkfile_list; /* point to the first node */
|
||||
struct metalinkfile *metalinkfile_last; /* point to the last/current node */
|
||||
char *oauth_bearer; /* OAuth 2.0 bearer token */
|
||||
bool nonpn; /* enable/disable TLS NPN extension */
|
||||
bool noalpn; /* enable/disable TLS ALPN extension */
|
||||
char *unix_socket_path; /* path to Unix domain socket */
|
||||
bool abstract_unix_socket; /* path to an abstract Unix domain socket */
|
||||
bool falsestart;
|
||||
bool path_as_is;
|
||||
double expect100timeout;
|
||||
bool suppress_connect_headers; /* suppress proxy CONNECT response headers
|
||||
from user callbacks */
|
||||
curl_error synthetic_error; /* if non-zero, it overrides any libcurl
|
||||
error */
|
||||
bool ssh_compression; /* enable/disable SSH compression */
|
||||
long happy_eyeballs_timeout_ms; /* happy eyeballs timeout in milliseconds.
|
||||
0 is valid. default: CURL_HET_DEFAULT. */
|
||||
bool haproxy_protocol; /* whether to send HAProxy protocol v1 */
|
||||
bool disallow_username_in_url; /* disallow usernames in URLs */
|
||||
char *aws_sigv4_provider;
|
||||
struct GlobalConfig *global;
|
||||
struct OperationConfig *prev;
|
||||
struct OperationConfig *next; /* Always last in the struct */
|
||||
struct State state; /* for create_transfer() */
|
||||
};
|
||||
|
||||
struct GlobalConfig {
|
||||
int showerror; /* -1 == unset, default => show errors
|
||||
0 => -s is used to NOT show errors
|
||||
1 => -S has been used to show errors */
|
||||
bool mute; /* don't show messages, --silent given */
|
||||
bool noprogress; /* don't show progress bar --silent given */
|
||||
bool isatty; /* Updated internally if output is a tty */
|
||||
FILE *errors; /* Error stream, defaults to stderr */
|
||||
bool errors_fopened; /* Whether error stream isn't stderr */
|
||||
char *trace_dump; /* file to dump the network trace to */
|
||||
FILE *trace_stream;
|
||||
bool trace_fopened;
|
||||
trace tracetype;
|
||||
bool tracetime; /* include timestamp? */
|
||||
int progressmode; /* CURL_PROGRESS_BAR / CURL_PROGRESS_STATS */
|
||||
char *libcurl; /* Output libcurl code to this file name */
|
||||
bool fail_early; /* exit on first transfer error */
|
||||
bool styled_output; /* enable fancy output style detection */
|
||||
#ifdef CURLDEBUG
|
||||
bool test_event_based;
|
||||
#endif
|
||||
bool parallel;
|
||||
long parallel_max;
|
||||
bool parallel_connect;
|
||||
char *help_category; /* The help category, if set */
|
||||
struct OperationConfig *first;
|
||||
struct OperationConfig *current;
|
||||
struct OperationConfig *last; /* Always last in the struct */
|
||||
};
|
||||
|
||||
void config_init(struct OperationConfig *config);
|
||||
void config_free(struct OperationConfig *config);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CFGABLE_H */
|
147
module/Vendor/CURL/src/tool_convert.c
vendored
Normal file
147
module/Vendor/CURL/src/tool_convert.c
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
|
||||
#include "tool_convert.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
|
||||
/* curl tool iconv conversion descriptors */
|
||||
static iconv_t inbound_cd = (iconv_t)-1;
|
||||
static iconv_t outbound_cd = (iconv_t)-1;
|
||||
|
||||
/* set default codesets for iconv */
|
||||
#ifndef CURL_ICONV_CODESET_OF_NETWORK
|
||||
# define CURL_ICONV_CODESET_OF_NETWORK "ISO8859-1"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* convert_to_network() is a curl tool function to convert
|
||||
* from the host encoding to ASCII on non-ASCII platforms.
|
||||
*/
|
||||
CURLcode convert_to_network(char *buffer, size_t length)
|
||||
{
|
||||
/* translate from the host encoding to the network encoding */
|
||||
char *input_ptr, *output_ptr;
|
||||
size_t res, in_bytes, out_bytes;
|
||||
|
||||
/* open an iconv conversion descriptor if necessary */
|
||||
if(outbound_cd == (iconv_t)-1) {
|
||||
outbound_cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
|
||||
CURL_ICONV_CODESET_OF_HOST);
|
||||
if(outbound_cd == (iconv_t)-1) {
|
||||
return CURLE_CONV_FAILED;
|
||||
}
|
||||
}
|
||||
/* call iconv */
|
||||
input_ptr = output_ptr = buffer;
|
||||
in_bytes = out_bytes = length;
|
||||
res = iconv(outbound_cd, &input_ptr, &in_bytes,
|
||||
&output_ptr, &out_bytes);
|
||||
if((res == (size_t)-1) || (in_bytes != 0)) {
|
||||
return CURLE_CONV_FAILED;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* convert_from_network() is a curl tool function
|
||||
* for performing ASCII conversions on non-ASCII platforms.
|
||||
*/
|
||||
CURLcode convert_from_network(char *buffer, size_t length)
|
||||
{
|
||||
/* translate from the network encoding to the host encoding */
|
||||
char *input_ptr, *output_ptr;
|
||||
size_t res, in_bytes, out_bytes;
|
||||
|
||||
/* open an iconv conversion descriptor if necessary */
|
||||
if(inbound_cd == (iconv_t)-1) {
|
||||
inbound_cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
|
||||
CURL_ICONV_CODESET_OF_NETWORK);
|
||||
if(inbound_cd == (iconv_t)-1) {
|
||||
return CURLE_CONV_FAILED;
|
||||
}
|
||||
}
|
||||
/* call iconv */
|
||||
input_ptr = output_ptr = buffer;
|
||||
in_bytes = out_bytes = length;
|
||||
res = iconv(inbound_cd, &input_ptr, &in_bytes,
|
||||
&output_ptr, &out_bytes);
|
||||
if((res == (size_t)-1) || (in_bytes != 0)) {
|
||||
return CURLE_CONV_FAILED;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void convert_cleanup(void)
|
||||
{
|
||||
/* close iconv conversion descriptors */
|
||||
if(inbound_cd != (iconv_t)-1)
|
||||
(void)iconv_close(inbound_cd);
|
||||
if(outbound_cd != (iconv_t)-1)
|
||||
(void)iconv_close(outbound_cd);
|
||||
}
|
||||
|
||||
#endif /* HAVE_ICONV */
|
||||
|
||||
char convert_char(curl_infotype infotype, char this_char)
|
||||
{
|
||||
/* determine how this specific character should be displayed */
|
||||
switch(infotype) {
|
||||
case CURLINFO_DATA_IN:
|
||||
case CURLINFO_DATA_OUT:
|
||||
case CURLINFO_SSL_DATA_IN:
|
||||
case CURLINFO_SSL_DATA_OUT:
|
||||
/* data, treat as ASCII */
|
||||
if(this_char < 0x20 || this_char >= 0x7f) {
|
||||
/* non-printable ASCII, use a replacement character */
|
||||
return UNPRINTABLE_CHAR;
|
||||
}
|
||||
/* printable ASCII hex value: convert to host encoding */
|
||||
(void)convert_from_network(&this_char, 1);
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
/* treat as host encoding */
|
||||
if(ISPRINT(this_char)
|
||||
&& (this_char != '\t')
|
||||
&& (this_char != '\r')
|
||||
&& (this_char != '\n')) {
|
||||
/* printable characters excluding tabs and line end characters */
|
||||
return this_char;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* non-printable, use a replacement character */
|
||||
return UNPRINTABLE_CHAR;
|
||||
}
|
||||
|
||||
#endif /* CURL_DOES_CONVERSIONS */
|
44
module/Vendor/CURL/src/tool_convert.h
vendored
Normal file
44
module/Vendor/CURL/src/tool_convert.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef HEADER_CURL_TOOL_CONVERT_H
|
||||
#define HEADER_CURL_TOOL_CONVERT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
|
||||
CURLcode convert_to_network(char *buffer, size_t length);
|
||||
CURLcode convert_from_network(char *buffer, size_t length);
|
||||
void convert_cleanup(void);
|
||||
|
||||
#endif /* HAVE_ICONV */
|
||||
|
||||
char convert_char(curl_infotype infotype, char this_char);
|
||||
|
||||
#endif /* CURL_DOES_CONVERSIONS */
|
||||
|
||||
#if !defined(CURL_DOES_CONVERSIONS) || !defined(HAVE_ICONV)
|
||||
#define convert_cleanup() Curl_nop_stmt
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_CONVERT_H */
|
170
module/Vendor/CURL/src/tool_dirhie.c
vendored
Normal file
170
module/Vendor/CURL/src/tool_dirhie.c
vendored
Normal file
@ -0,0 +1,170 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <direct.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_dirhie.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef NETWARE
|
||||
# ifndef __NOVELL_LIBC__
|
||||
# define mkdir mkdir_510
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || (defined(MSDOS) && !defined(__DJGPP__))
|
||||
# define mkdir(x,y) (mkdir)((x))
|
||||
# ifndef F_OK
|
||||
# define F_OK 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static void show_dir_errno(FILE *errors, const char *name)
|
||||
{
|
||||
switch(errno) {
|
||||
#ifdef EACCES
|
||||
case EACCES:
|
||||
fprintf(errors, "You don't have permission to create %s.\n", name);
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENAMETOOLONG
|
||||
case ENAMETOOLONG:
|
||||
fprintf(errors, "The directory name %s is too long.\n", name);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EROFS
|
||||
case EROFS:
|
||||
fprintf(errors, "%s resides on a read-only file system.\n", name);
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENOSPC
|
||||
case ENOSPC:
|
||||
fprintf(errors, "No space left on the file system that will "
|
||||
"contain the directory %s.\n", name);
|
||||
break;
|
||||
#endif
|
||||
#ifdef EDQUOT
|
||||
case EDQUOT:
|
||||
fprintf(errors, "Cannot create directory %s because you "
|
||||
"exceeded your quota.\n", name);
|
||||
break;
|
||||
#endif
|
||||
default :
|
||||
fprintf(errors, "Error creating directory %s.\n", name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the needed directory hierarchy recursively in order to save
|
||||
* multi-GETs in file output, ie:
|
||||
* curl "http://my.site/dir[1-5]/file[1-5].txt" -o "dir#1/file#2.txt"
|
||||
* should create all the dir* automagically
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(__DJGPP__)
|
||||
/* systems that may use either or when specifying a path */
|
||||
#define PATH_DELIMITERS "\\/"
|
||||
#else
|
||||
#define PATH_DELIMITERS DIR_CHAR
|
||||
#endif
|
||||
|
||||
|
||||
CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
|
||||
{
|
||||
char *tempdir;
|
||||
char *tempdir2;
|
||||
char *outdup;
|
||||
char *dirbuildup;
|
||||
CURLcode result = CURLE_OK;
|
||||
size_t outlen;
|
||||
|
||||
outlen = strlen(outfile);
|
||||
outdup = strdup(outfile);
|
||||
if(!outdup)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
dirbuildup = malloc(outlen + 1);
|
||||
if(!dirbuildup) {
|
||||
Curl_safefree(outdup);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
dirbuildup[0] = '\0';
|
||||
|
||||
/* Allow strtok() here since this isn't used threaded */
|
||||
/* !checksrc! disable BANNEDFUNC 2 */
|
||||
tempdir = strtok(outdup, PATH_DELIMITERS);
|
||||
|
||||
while(tempdir != NULL) {
|
||||
bool skip = false;
|
||||
tempdir2 = strtok(NULL, PATH_DELIMITERS);
|
||||
/* since strtok returns a token for the last word even
|
||||
if not ending with DIR_CHAR, we need to prune it */
|
||||
if(tempdir2 != NULL) {
|
||||
size_t dlen = strlen(dirbuildup);
|
||||
if(dlen)
|
||||
msnprintf(&dirbuildup[dlen], outlen - dlen, "%s%s", DIR_CHAR, tempdir);
|
||||
else {
|
||||
if(outdup == tempdir) {
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
/* Skip creating a drive's current directory.
|
||||
It may seem as though that would harmlessly fail but it could be
|
||||
a corner case if X: did not exist, since we would be creating it
|
||||
erroneously.
|
||||
eg if outfile is X:\foo\bar\filename then don't mkdir X:
|
||||
This logic takes into account unsupported drives !:, 1:, etc. */
|
||||
char *p = strchr(tempdir, ':');
|
||||
if(p && !p[1])
|
||||
skip = true;
|
||||
#endif
|
||||
/* the output string doesn't start with a separator */
|
||||
strcpy(dirbuildup, tempdir);
|
||||
}
|
||||
else
|
||||
msnprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir);
|
||||
}
|
||||
/* Create directory. Ignore access denied error to allow traversal. */
|
||||
if(!skip && (-1 == mkdir(dirbuildup, (mode_t)0000750)) &&
|
||||
(errno != EACCES) && (errno != EEXIST)) {
|
||||
show_dir_errno(errors, dirbuildup);
|
||||
result = CURLE_WRITE_ERROR;
|
||||
break; /* get out of loop */
|
||||
}
|
||||
}
|
||||
tempdir = tempdir2;
|
||||
}
|
||||
|
||||
Curl_safefree(dirbuildup);
|
||||
Curl_safefree(outdup);
|
||||
|
||||
return result;
|
||||
}
|
28
module/Vendor/CURL/src/tool_dirhie.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_dirhie.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_DIRHIE_H
|
||||
#define HEADER_CURL_TOOL_DIRHIE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
CURLcode create_dir_hierarchy(const char *outfile, FILE *errors);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_DIRHIE_H */
|
784
module/Vendor/CURL/src/tool_doswin.c
vendored
Normal file
784
module/Vendor/CURL/src/tool_doswin.c
vendored
Normal file
@ -0,0 +1,784 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
|
||||
#if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME)
|
||||
# include <libgen.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# include <stdlib.h>
|
||||
# include <tlhelp32.h>
|
||||
# include "tool_cfgable.h"
|
||||
# include "tool_libinfo.h"
|
||||
#endif
|
||||
|
||||
#include "tool_bname.h"
|
||||
#include "tool_doswin.h"
|
||||
|
||||
#include "curlx.h"
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef WIN32
|
||||
# undef PATH_MAX
|
||||
# define PATH_MAX MAX_PATH
|
||||
#endif
|
||||
|
||||
#ifndef S_ISCHR
|
||||
# ifdef S_IFCHR
|
||||
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
# else
|
||||
# define S_ISCHR(m) (0) /* cannot tell if file is a device */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# define _use_lfn(f) (1) /* long file names always available */
|
||||
#elif !defined(__DJGPP__) || (__DJGPP__ < 2) /* DJGPP 2.0 has _use_lfn() */
|
||||
# define _use_lfn(f) (0) /* long file names never available */
|
||||
#elif defined(__DJGPP__)
|
||||
# include <fcntl.h> /* _use_lfn(f) prototype */
|
||||
#endif
|
||||
|
||||
#ifndef UNITTESTS
|
||||
static SANITIZEcode truncate_dryrun(const char *path,
|
||||
const size_t truncate_pos);
|
||||
#ifdef MSDOS
|
||||
static SANITIZEcode msdosify(char **const sanitized, const char *file_name,
|
||||
int flags);
|
||||
#endif
|
||||
static SANITIZEcode rename_if_reserved_dos_device_name(char **const sanitized,
|
||||
const char *file_name,
|
||||
int flags);
|
||||
#endif /* !UNITTESTS (static declarations used if no unit tests) */
|
||||
|
||||
|
||||
/*
|
||||
Sanitize a file or path name.
|
||||
|
||||
All banned characters are replaced by underscores, for example:
|
||||
f?*foo => f__foo
|
||||
f:foo::$DATA => f_foo__$DATA
|
||||
f:\foo:bar => f__foo_bar
|
||||
f:\foo:bar => f:\foo:bar (flag SANITIZE_ALLOW_PATH)
|
||||
|
||||
This function was implemented according to the guidelines in 'Naming Files,
|
||||
Paths, and Namespaces' section 'Naming Conventions'.
|
||||
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx
|
||||
|
||||
Flags
|
||||
-----
|
||||
SANITIZE_ALLOW_COLONS: Allow colons.
|
||||
Without this flag colons are sanitized.
|
||||
|
||||
SANITIZE_ALLOW_PATH: Allow path separators and colons.
|
||||
Without this flag path separators and colons are sanitized.
|
||||
|
||||
SANITIZE_ALLOW_RESERVED: Allow reserved device names.
|
||||
Without this flag a reserved device name is renamed (COM1 => _COM1) unless it's
|
||||
in a UNC prefixed path.
|
||||
|
||||
SANITIZE_ALLOW_TRUNCATE: Allow truncating a long filename.
|
||||
Without this flag if the sanitized filename or path will be too long an error
|
||||
occurs. With this flag the filename --and not any other parts of the path-- may
|
||||
be truncated to at least a single character. A filename followed by an
|
||||
alternate data stream (ADS) cannot be truncated in any case.
|
||||
|
||||
Success: (SANITIZE_ERR_OK) *sanitized points to a sanitized copy of file_name.
|
||||
Failure: (!= SANITIZE_ERR_OK) *sanitized is NULL.
|
||||
*/
|
||||
SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name,
|
||||
int flags)
|
||||
{
|
||||
char *p, *target;
|
||||
size_t len;
|
||||
SANITIZEcode sc;
|
||||
size_t max_sanitized_len;
|
||||
|
||||
if(!sanitized)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
*sanitized = NULL;
|
||||
|
||||
if(!file_name)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
if((flags & SANITIZE_ALLOW_PATH)) {
|
||||
#ifndef MSDOS
|
||||
if(file_name[0] == '\\' && file_name[1] == '\\')
|
||||
/* UNC prefixed path \\ (eg \\?\C:\foo) */
|
||||
max_sanitized_len = 32767-1;
|
||||
else
|
||||
#endif
|
||||
max_sanitized_len = PATH_MAX-1;
|
||||
}
|
||||
else
|
||||
/* The maximum length of a filename.
|
||||
FILENAME_MAX is often the same as PATH_MAX, in other words it is 260 and
|
||||
does not discount the path information therefore we shouldn't use it. */
|
||||
max_sanitized_len = (PATH_MAX-1 > 255) ? 255 : PATH_MAX-1;
|
||||
|
||||
len = strlen(file_name);
|
||||
if(len > max_sanitized_len) {
|
||||
if(!(flags & SANITIZE_ALLOW_TRUNCATE) ||
|
||||
truncate_dryrun(file_name, max_sanitized_len))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
len = max_sanitized_len;
|
||||
}
|
||||
|
||||
target = malloc(len + 1);
|
||||
if(!target)
|
||||
return SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
|
||||
strncpy(target, file_name, len);
|
||||
target[len] = '\0';
|
||||
|
||||
#ifndef MSDOS
|
||||
if((flags & SANITIZE_ALLOW_PATH) && !strncmp(target, "\\\\?\\", 4))
|
||||
/* Skip the literal path prefix \\?\ */
|
||||
p = target + 4;
|
||||
else
|
||||
#endif
|
||||
p = target;
|
||||
|
||||
/* replace control characters and other banned characters */
|
||||
for(; *p; ++p) {
|
||||
const char *banned;
|
||||
|
||||
if((1 <= *p && *p <= 31) ||
|
||||
(!(flags & (SANITIZE_ALLOW_COLONS|SANITIZE_ALLOW_PATH)) && *p == ':') ||
|
||||
(!(flags & SANITIZE_ALLOW_PATH) && (*p == '/' || *p == '\\'))) {
|
||||
*p = '_';
|
||||
continue;
|
||||
}
|
||||
|
||||
for(banned = "|<>\"?*"; *banned; ++banned) {
|
||||
if(*p == *banned) {
|
||||
*p = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* remove trailing spaces and periods if not allowing paths */
|
||||
if(!(flags & SANITIZE_ALLOW_PATH) && len) {
|
||||
char *clip = NULL;
|
||||
|
||||
p = &target[len];
|
||||
do {
|
||||
--p;
|
||||
if(*p != ' ' && *p != '.')
|
||||
break;
|
||||
clip = p;
|
||||
} while(p != target);
|
||||
|
||||
if(clip) {
|
||||
*clip = '\0';
|
||||
len = clip - target;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MSDOS
|
||||
sc = msdosify(&p, target, flags);
|
||||
free(target);
|
||||
if(sc)
|
||||
return sc;
|
||||
target = p;
|
||||
len = strlen(target);
|
||||
|
||||
if(len > max_sanitized_len) {
|
||||
free(target);
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!(flags & SANITIZE_ALLOW_RESERVED)) {
|
||||
sc = rename_if_reserved_dos_device_name(&p, target, flags);
|
||||
free(target);
|
||||
if(sc)
|
||||
return sc;
|
||||
target = p;
|
||||
len = strlen(target);
|
||||
|
||||
if(len > max_sanitized_len) {
|
||||
free(target);
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
*sanitized = target;
|
||||
return SANITIZE_ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Test if truncating a path to a file will leave at least a single character in
|
||||
the filename. Filenames suffixed by an alternate data stream can't be
|
||||
truncated. This performs a dry run, nothing is modified.
|
||||
|
||||
Good truncate_pos 9: C:\foo\bar => C:\foo\ba
|
||||
Good truncate_pos 6: C:\foo => C:\foo
|
||||
Good truncate_pos 5: C:\foo => C:\fo
|
||||
Bad* truncate_pos 5: C:foo => C:foo
|
||||
Bad truncate_pos 5: C:\foo:ads => C:\fo
|
||||
Bad truncate_pos 9: C:\foo:ads => C:\foo:ad
|
||||
Bad truncate_pos 5: C:\foo\bar => C:\fo
|
||||
Bad truncate_pos 5: C:\foo\ => C:\fo
|
||||
Bad truncate_pos 7: C:\foo\ => C:\foo\
|
||||
Error truncate_pos 7: C:\foo => (pos out of range)
|
||||
Bad truncate_pos 1: C:\foo\ => C
|
||||
|
||||
* C:foo is ambiguous, C could end up being a drive or file therefore something
|
||||
like C:superlongfilename can't be truncated.
|
||||
|
||||
Returns
|
||||
SANITIZE_ERR_OK: Good -- 'path' can be truncated
|
||||
SANITIZE_ERR_INVALID_PATH: Bad -- 'path' cannot be truncated
|
||||
!= SANITIZE_ERR_OK && != SANITIZE_ERR_INVALID_PATH: Error
|
||||
*/
|
||||
SANITIZEcode truncate_dryrun(const char *path, const size_t truncate_pos)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(!path)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
len = strlen(path);
|
||||
|
||||
if(truncate_pos > len)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
if(!len || !truncate_pos)
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
if(strpbrk(&path[truncate_pos - 1], "\\/:"))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
/* C:\foo can be truncated but C:\foo:ads can't */
|
||||
if(truncate_pos > 1) {
|
||||
const char *p = &path[truncate_pos - 1];
|
||||
do {
|
||||
--p;
|
||||
if(*p == ':')
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
} while(p != path && *p != '\\' && *p != '/');
|
||||
}
|
||||
|
||||
return SANITIZE_ERR_OK;
|
||||
}
|
||||
|
||||
/* The functions msdosify, rename_if_dos_device_name and __crt0_glob_function
|
||||
* were taken with modification from the DJGPP port of tar 1.12. They use
|
||||
* algorithms originally from DJTAR.
|
||||
*/
|
||||
|
||||
/*
|
||||
Extra sanitization MSDOS for file_name.
|
||||
|
||||
This is a supporting function for sanitize_file_name.
|
||||
|
||||
Warning: This is an MSDOS legacy function and was purposely written in a way
|
||||
that some path information may pass through. For example drive letter names
|
||||
(C:, D:, etc) are allowed to pass through. For sanitizing a filename use
|
||||
sanitize_file_name.
|
||||
|
||||
Success: (SANITIZE_ERR_OK) *sanitized points to a sanitized copy of file_name.
|
||||
Failure: (!= SANITIZE_ERR_OK) *sanitized is NULL.
|
||||
*/
|
||||
#if defined(MSDOS) || defined(UNITTESTS)
|
||||
SANITIZEcode msdosify(char **const sanitized, const char *file_name,
|
||||
int flags)
|
||||
{
|
||||
char dos_name[PATH_MAX];
|
||||
static const char illegal_chars_dos[] = ".+, ;=[]" /* illegal in DOS */
|
||||
"|<>/\\\":?*"; /* illegal in DOS & W95 */
|
||||
static const char *illegal_chars_w95 = &illegal_chars_dos[8];
|
||||
int idx, dot_idx;
|
||||
const char *s = file_name;
|
||||
char *d = dos_name;
|
||||
const char *const dlimit = dos_name + sizeof(dos_name) - 1;
|
||||
const char *illegal_aliens = illegal_chars_dos;
|
||||
size_t len = sizeof(illegal_chars_dos) - 1;
|
||||
|
||||
if(!sanitized)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
*sanitized = NULL;
|
||||
|
||||
if(!file_name)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
if(strlen(file_name) > PATH_MAX-1 &&
|
||||
(!(flags & SANITIZE_ALLOW_TRUNCATE) ||
|
||||
truncate_dryrun(file_name, PATH_MAX-1)))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
/* Support for Windows 9X VFAT systems, when available. */
|
||||
if(_use_lfn(file_name)) {
|
||||
illegal_aliens = illegal_chars_w95;
|
||||
len -= (illegal_chars_w95 - illegal_chars_dos);
|
||||
}
|
||||
|
||||
/* Get past the drive letter, if any. */
|
||||
if(s[0] >= 'A' && s[0] <= 'z' && s[1] == ':') {
|
||||
*d++ = *s++;
|
||||
*d = ((flags & (SANITIZE_ALLOW_COLONS|SANITIZE_ALLOW_PATH))) ? ':' : '_';
|
||||
++d, ++s;
|
||||
}
|
||||
|
||||
for(idx = 0, dot_idx = -1; *s && d < dlimit; s++, d++) {
|
||||
if(memchr(illegal_aliens, *s, len)) {
|
||||
|
||||
if((flags & (SANITIZE_ALLOW_COLONS|SANITIZE_ALLOW_PATH)) && *s == ':')
|
||||
*d = ':';
|
||||
else if((flags & SANITIZE_ALLOW_PATH) && (*s == '/' || *s == '\\'))
|
||||
*d = *s;
|
||||
/* Dots are special: DOS doesn't allow them as the leading character,
|
||||
and a file name cannot have more than a single dot. We leave the
|
||||
first non-leading dot alone, unless it comes too close to the
|
||||
beginning of the name: we want sh.lex.c to become sh_lex.c, not
|
||||
sh.lex-c. */
|
||||
else if(*s == '.') {
|
||||
if((flags & SANITIZE_ALLOW_PATH) && idx == 0 &&
|
||||
(s[1] == '/' || s[1] == '\\' ||
|
||||
(s[1] == '.' && (s[2] == '/' || s[2] == '\\')))) {
|
||||
/* Copy "./" and "../" verbatim. */
|
||||
*d++ = *s++;
|
||||
if(d == dlimit)
|
||||
break;
|
||||
if(*s == '.') {
|
||||
*d++ = *s++;
|
||||
if(d == dlimit)
|
||||
break;
|
||||
}
|
||||
*d = *s;
|
||||
}
|
||||
else if(idx == 0)
|
||||
*d = '_';
|
||||
else if(dot_idx >= 0) {
|
||||
if(dot_idx < 5) { /* 5 is a heuristic ad-hoc'ery */
|
||||
d[dot_idx - idx] = '_'; /* replace previous dot */
|
||||
*d = '.';
|
||||
}
|
||||
else
|
||||
*d = '-';
|
||||
}
|
||||
else
|
||||
*d = '.';
|
||||
|
||||
if(*s == '.')
|
||||
dot_idx = idx;
|
||||
}
|
||||
else if(*s == '+' && s[1] == '+') {
|
||||
if(idx - 2 == dot_idx) { /* .c++, .h++ etc. */
|
||||
*d++ = 'x';
|
||||
if(d == dlimit)
|
||||
break;
|
||||
*d = 'x';
|
||||
}
|
||||
else {
|
||||
/* libg++ etc. */
|
||||
if(dlimit - d < 4) {
|
||||
*d++ = 'x';
|
||||
if(d == dlimit)
|
||||
break;
|
||||
*d = 'x';
|
||||
}
|
||||
else {
|
||||
memcpy(d, "plus", 4);
|
||||
d += 3;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
idx++;
|
||||
}
|
||||
else
|
||||
*d = '_';
|
||||
}
|
||||
else
|
||||
*d = *s;
|
||||
if(*s == '/' || *s == '\\') {
|
||||
idx = 0;
|
||||
dot_idx = -1;
|
||||
}
|
||||
else
|
||||
idx++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
if(*s) {
|
||||
/* dos_name is truncated, check that truncation requirements are met,
|
||||
specifically truncating a filename suffixed by an alternate data stream
|
||||
or truncating the entire filename is not allowed. */
|
||||
if(!(flags & SANITIZE_ALLOW_TRUNCATE) || strpbrk(s, "\\/:") ||
|
||||
truncate_dryrun(dos_name, d - dos_name))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
}
|
||||
|
||||
*sanitized = strdup(dos_name);
|
||||
return (*sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY);
|
||||
}
|
||||
#endif /* MSDOS || UNITTESTS */
|
||||
|
||||
/*
|
||||
Rename file_name if it's a reserved dos device name.
|
||||
|
||||
This is a supporting function for sanitize_file_name.
|
||||
|
||||
Warning: This is an MSDOS legacy function and was purposely written in a way
|
||||
that some path information may pass through. For example drive letter names
|
||||
(C:, D:, etc) are allowed to pass through. For sanitizing a filename use
|
||||
sanitize_file_name.
|
||||
|
||||
Success: (SANITIZE_ERR_OK) *sanitized points to a sanitized copy of file_name.
|
||||
Failure: (!= SANITIZE_ERR_OK) *sanitized is NULL.
|
||||
*/
|
||||
SANITIZEcode rename_if_reserved_dos_device_name(char **const sanitized,
|
||||
const char *file_name,
|
||||
int flags)
|
||||
{
|
||||
/* We could have a file whose name is a device on MS-DOS. Trying to
|
||||
* retrieve such a file would fail at best and wedge us at worst. We need
|
||||
* to rename such files. */
|
||||
char *p, *base;
|
||||
char fname[PATH_MAX];
|
||||
#ifdef MSDOS
|
||||
struct_stat st_buf;
|
||||
#endif
|
||||
|
||||
if(!sanitized)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
*sanitized = NULL;
|
||||
|
||||
if(!file_name)
|
||||
return SANITIZE_ERR_BAD_ARGUMENT;
|
||||
|
||||
/* Ignore UNC prefixed paths, they are allowed to contain a reserved name. */
|
||||
#ifndef MSDOS
|
||||
if((flags & SANITIZE_ALLOW_PATH) &&
|
||||
file_name[0] == '\\' && file_name[1] == '\\') {
|
||||
size_t len = strlen(file_name);
|
||||
*sanitized = malloc(len + 1);
|
||||
if(!*sanitized)
|
||||
return SANITIZE_ERR_OUT_OF_MEMORY;
|
||||
strncpy(*sanitized, file_name, len + 1);
|
||||
return SANITIZE_ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(strlen(file_name) > PATH_MAX-1 &&
|
||||
(!(flags & SANITIZE_ALLOW_TRUNCATE) ||
|
||||
truncate_dryrun(file_name, PATH_MAX-1)))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
|
||||
strncpy(fname, file_name, PATH_MAX-1);
|
||||
fname[PATH_MAX-1] = '\0';
|
||||
base = basename(fname);
|
||||
|
||||
/* Rename reserved device names that are known to be accessible without \\.\
|
||||
Examples: CON => _CON, CON.EXT => CON_EXT, CON:ADS => CON_ADS
|
||||
https://support.microsoft.com/en-us/kb/74496
|
||||
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx
|
||||
*/
|
||||
for(p = fname; p; p = (p == fname && fname != base ? base : NULL)) {
|
||||
size_t p_len;
|
||||
int x = (curl_strnequal(p, "CON", 3) ||
|
||||
curl_strnequal(p, "PRN", 3) ||
|
||||
curl_strnequal(p, "AUX", 3) ||
|
||||
curl_strnequal(p, "NUL", 3)) ? 3 :
|
||||
(curl_strnequal(p, "CLOCK$", 6)) ? 6 :
|
||||
(curl_strnequal(p, "COM", 3) || curl_strnequal(p, "LPT", 3)) ?
|
||||
(('1' <= p[3] && p[3] <= '9') ? 4 : 3) : 0;
|
||||
|
||||
if(!x)
|
||||
continue;
|
||||
|
||||
/* the devices may be accessible with an extension or ADS, for
|
||||
example CON.AIR and 'CON . AIR' and CON:AIR access console */
|
||||
|
||||
for(; p[x] == ' '; ++x)
|
||||
;
|
||||
|
||||
if(p[x] == '.') {
|
||||
p[x] = '_';
|
||||
continue;
|
||||
}
|
||||
else if(p[x] == ':') {
|
||||
if(!(flags & (SANITIZE_ALLOW_COLONS|SANITIZE_ALLOW_PATH))) {
|
||||
p[x] = '_';
|
||||
continue;
|
||||
}
|
||||
++x;
|
||||
}
|
||||
else if(p[x]) /* no match */
|
||||
continue;
|
||||
|
||||
/* p points to 'CON' or 'CON ' or 'CON:', etc */
|
||||
p_len = strlen(p);
|
||||
|
||||
/* Prepend a '_' */
|
||||
if(strlen(fname) == PATH_MAX-1) {
|
||||
--p_len;
|
||||
if(!(flags & SANITIZE_ALLOW_TRUNCATE) || truncate_dryrun(p, p_len))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
p[p_len] = '\0';
|
||||
}
|
||||
memmove(p + 1, p, p_len + 1);
|
||||
p[0] = '_';
|
||||
++p_len;
|
||||
|
||||
/* if fname was just modified then the basename pointer must be updated */
|
||||
if(p == fname)
|
||||
base = basename(fname);
|
||||
}
|
||||
|
||||
/* This is the legacy portion from rename_if_dos_device_name that checks for
|
||||
reserved device names. It only works on MSDOS. On Windows XP the stat
|
||||
check errors with EINVAL if the device name is reserved. On Windows
|
||||
Vista/7/8 it sets mode S_IFREG (regular file or device). According to MSDN
|
||||
stat doc the latter behavior is correct, but that doesn't help us identify
|
||||
whether it's a reserved device name and not a regular file name. */
|
||||
#ifdef MSDOS
|
||||
if(base && ((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
|
||||
/* Prepend a '_' */
|
||||
size_t blen = strlen(base);
|
||||
if(blen) {
|
||||
if(strlen(fname) == PATH_MAX-1) {
|
||||
--blen;
|
||||
if(!(flags & SANITIZE_ALLOW_TRUNCATE) || truncate_dryrun(base, blen))
|
||||
return SANITIZE_ERR_INVALID_PATH;
|
||||
base[blen] = '\0';
|
||||
}
|
||||
memmove(base + 1, base, blen + 1);
|
||||
base[0] = '_';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
*sanitized = strdup(fname);
|
||||
return (*sanitized ? SANITIZE_ERR_OK : SANITIZE_ERR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
#if defined(MSDOS) && (defined(__DJGPP__) || defined(__GO32__))
|
||||
|
||||
/*
|
||||
* Disable program default argument globbing. We do it on our own.
|
||||
*/
|
||||
char **__crt0_glob_function(char *arg)
|
||||
{
|
||||
(void)arg;
|
||||
return (char **)0;
|
||||
}
|
||||
|
||||
#endif /* MSDOS && (__DJGPP__ || __GO32__) */
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/*
|
||||
* Function to find CACert bundle on a Win32 platform using SearchPath.
|
||||
* (SearchPath is already declared via inclusions done in setup header file)
|
||||
* (Use the ASCII version instead of the unicode one!)
|
||||
* The order of the directories it searches is:
|
||||
* 1. application's directory
|
||||
* 2. current working directory
|
||||
* 3. Windows System directory (e.g. C:\windows\system32)
|
||||
* 4. Windows Directory (e.g. C:\windows)
|
||||
* 5. all directories along %PATH%
|
||||
*
|
||||
* For WinXP and later search order actually depends on registry value:
|
||||
* HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode
|
||||
*/
|
||||
|
||||
CURLcode FindWin32CACert(struct OperationConfig *config,
|
||||
curl_sslbackend backend,
|
||||
const TCHAR *bundle_file)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
/* Search and set cert file only if libcurl supports SSL.
|
||||
*
|
||||
* If Schannel is the selected SSL backend then these locations are
|
||||
* ignored. We allow setting CA location for schannel only when explicitly
|
||||
* specified by the user via CURLOPT_CAINFO / --cacert.
|
||||
*/
|
||||
if((curlinfo->features & CURL_VERSION_SSL) &&
|
||||
backend != CURLSSLBACKEND_SCHANNEL) {
|
||||
|
||||
DWORD res_len;
|
||||
TCHAR buf[PATH_MAX];
|
||||
TCHAR *ptr = NULL;
|
||||
|
||||
buf[0] = TEXT('\0');
|
||||
|
||||
res_len = SearchPath(NULL, bundle_file, NULL, PATH_MAX, buf, &ptr);
|
||||
if(res_len > 0) {
|
||||
Curl_safefree(config->cacert);
|
||||
#ifdef UNICODE
|
||||
config->cacert = curlx_convert_wchar_to_UTF8(buf);
|
||||
#else
|
||||
config->cacert = strdup(buf);
|
||||
#endif
|
||||
if(!config->cacert)
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Get a list of all loaded modules with full paths.
|
||||
* Returns slist on success or NULL on error.
|
||||
*/
|
||||
struct curl_slist *GetLoadedModulePaths(void)
|
||||
{
|
||||
HANDLE hnd = INVALID_HANDLE_VALUE;
|
||||
MODULEENTRY32 mod = {0};
|
||||
struct curl_slist *slist = NULL;
|
||||
|
||||
mod.dwSize = sizeof(MODULEENTRY32);
|
||||
|
||||
do {
|
||||
hnd = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
|
||||
} while(hnd == INVALID_HANDLE_VALUE && GetLastError() == ERROR_BAD_LENGTH);
|
||||
|
||||
if(hnd == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
|
||||
if(!Module32First(hnd, &mod))
|
||||
goto error;
|
||||
|
||||
do {
|
||||
char *path; /* points to stack allocated buffer */
|
||||
struct curl_slist *temp;
|
||||
|
||||
#ifdef UNICODE
|
||||
/* sizeof(mod.szExePath) is the max total bytes of wchars. the max total
|
||||
bytes of multibyte chars won't be more than twice that. */
|
||||
char buffer[sizeof(mod.szExePath) * 2];
|
||||
if(!WideCharToMultiByte(CP_ACP, 0, mod.szExePath, -1,
|
||||
buffer, sizeof(buffer), NULL, NULL))
|
||||
goto error;
|
||||
path = buffer;
|
||||
#else
|
||||
path = mod.szExePath;
|
||||
#endif
|
||||
temp = curl_slist_append(slist, path);
|
||||
if(!temp)
|
||||
goto error;
|
||||
slist = temp;
|
||||
} while(Module32Next(hnd, &mod));
|
||||
|
||||
goto cleanup;
|
||||
|
||||
error:
|
||||
curl_slist_free_all(slist);
|
||||
slist = NULL;
|
||||
cleanup:
|
||||
if(hnd != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(hnd);
|
||||
return slist;
|
||||
}
|
||||
|
||||
/* The terminal settings to restore on exit */
|
||||
static struct TerminalSettings {
|
||||
HANDLE hStdOut;
|
||||
DWORD dwOutputMode;
|
||||
LONG valid;
|
||||
} TerminalSettings;
|
||||
|
||||
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
||||
#endif
|
||||
|
||||
static void restore_terminal(void)
|
||||
{
|
||||
if(InterlockedExchange(&TerminalSettings.valid, (LONG)FALSE))
|
||||
SetConsoleMode(TerminalSettings.hStdOut, TerminalSettings.dwOutputMode);
|
||||
}
|
||||
|
||||
/* This is the console signal handler.
|
||||
* The system calls it in a separate thread.
|
||||
*/
|
||||
static BOOL WINAPI signal_handler(DWORD type)
|
||||
{
|
||||
if(type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT)
|
||||
restore_terminal();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void init_terminal(void)
|
||||
{
|
||||
TerminalSettings.hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
/*
|
||||
* Enable VT (Virtual Terminal) output.
|
||||
* Note: VT mode flag can be set on any version of Windows, but VT
|
||||
* processing only performed on Win10 >= Creators Update)
|
||||
*/
|
||||
if((TerminalSettings.hStdOut != INVALID_HANDLE_VALUE) &&
|
||||
GetConsoleMode(TerminalSettings.hStdOut,
|
||||
&TerminalSettings.dwOutputMode) &&
|
||||
!(TerminalSettings.dwOutputMode &
|
||||
ENABLE_VIRTUAL_TERMINAL_PROCESSING)) {
|
||||
/* The signal handler is set before attempting to change the console mode
|
||||
because otherwise a signal would not be caught after the change but
|
||||
before the handler was installed. */
|
||||
(void)InterlockedExchange(&TerminalSettings.valid, (LONG)TRUE);
|
||||
if(SetConsoleCtrlHandler(signal_handler, TRUE)) {
|
||||
if(SetConsoleMode(TerminalSettings.hStdOut,
|
||||
(TerminalSettings.dwOutputMode |
|
||||
ENABLE_VIRTUAL_TERMINAL_PROCESSING))) {
|
||||
atexit(restore_terminal);
|
||||
}
|
||||
else {
|
||||
SetConsoleCtrlHandler(signal_handler, FALSE);
|
||||
(void)InterlockedExchange(&TerminalSettings.valid, (LONG)FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LARGE_INTEGER tool_freq;
|
||||
bool tool_isVistaOrGreater;
|
||||
|
||||
CURLcode win32_init(void)
|
||||
{
|
||||
if(curlx_verify_windows_version(6, 0, PLATFORM_WINNT,
|
||||
VERSION_GREATER_THAN_EQUAL))
|
||||
tool_isVistaOrGreater = true;
|
||||
else
|
||||
tool_isVistaOrGreater = false;
|
||||
|
||||
QueryPerformanceFrequency(&tool_freq);
|
||||
|
||||
init_terminal();
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* MSDOS || WIN32 */
|
70
module/Vendor/CURL/src/tool_doswin.h
vendored
Normal file
70
module/Vendor/CURL/src/tool_doswin.h
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef HEADER_CURL_TOOL_DOSWIN_H
|
||||
#define HEADER_CURL_TOOL_DOSWIN_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
|
||||
#define SANITIZE_ALLOW_COLONS (1<<0) /* Allow colons */
|
||||
#define SANITIZE_ALLOW_PATH (1<<1) /* Allow path separators and colons */
|
||||
#define SANITIZE_ALLOW_RESERVED (1<<2) /* Allow reserved device names */
|
||||
#define SANITIZE_ALLOW_TRUNCATE (1<<3) /* Allow truncating a long filename */
|
||||
|
||||
typedef enum {
|
||||
SANITIZE_ERR_OK = 0, /* 0 - OK */
|
||||
SANITIZE_ERR_INVALID_PATH, /* 1 - the path is invalid */
|
||||
SANITIZE_ERR_BAD_ARGUMENT, /* 2 - bad function parameter */
|
||||
SANITIZE_ERR_OUT_OF_MEMORY, /* 3 - out of memory */
|
||||
SANITIZE_ERR_LAST /* never use! */
|
||||
} SANITIZEcode;
|
||||
|
||||
SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name,
|
||||
int flags);
|
||||
#ifdef UNITTESTS
|
||||
SANITIZEcode truncate_dryrun(const char *path, const size_t truncate_pos);
|
||||
SANITIZEcode msdosify(char **const sanitized, const char *file_name,
|
||||
int flags);
|
||||
SANITIZEcode rename_if_reserved_dos_device_name(char **const sanitized,
|
||||
const char *file_name,
|
||||
int flags);
|
||||
#endif /* UNITTESTS */
|
||||
|
||||
#if defined(MSDOS) && (defined(__DJGPP__) || defined(__GO32__))
|
||||
|
||||
char **__crt0_glob_function(char *arg);
|
||||
|
||||
#endif /* MSDOS && (__DJGPP__ || __GO32__) */
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
CURLcode FindWin32CACert(struct OperationConfig *config,
|
||||
curl_sslbackend backend,
|
||||
const TCHAR *bundle_file);
|
||||
struct curl_slist *GetLoadedModulePaths(void);
|
||||
CURLcode win32_init(void);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* MSDOS || WIN32 */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_DOSWIN_H */
|
236
module/Vendor/CURL/src/tool_easysrc.c
vendored
Normal file
236
module/Vendor/CURL/src/tool_easysrc.c
vendored
Normal file
@ -0,0 +1,236 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "slist_wc.h"
|
||||
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_easysrc.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* global variable definitions, for easy-interface source code generation */
|
||||
|
||||
struct slist_wc *easysrc_decl = NULL; /* Variable declarations */
|
||||
struct slist_wc *easysrc_data = NULL; /* Build slists, forms etc. */
|
||||
struct slist_wc *easysrc_code = NULL; /* Setopt calls */
|
||||
struct slist_wc *easysrc_toohard = NULL; /* Unconvertible setopt */
|
||||
struct slist_wc *easysrc_clean = NULL; /* Clean up allocated data */
|
||||
int easysrc_mime_count = 0;
|
||||
int easysrc_slist_count = 0;
|
||||
|
||||
static const char *const srchead[]={
|
||||
"/********* Sample code generated by the curl command line tool **********",
|
||||
" * All curl_easy_setopt() options are documented at:",
|
||||
" * https://curl.se/libcurl/c/curl_easy_setopt.html",
|
||||
" ************************************************************************/",
|
||||
"#include <curl/curl.h>",
|
||||
"",
|
||||
"int main(int argc, char *argv[])",
|
||||
"{",
|
||||
" CURLcode ret;",
|
||||
" CURL *hnd;",
|
||||
NULL
|
||||
};
|
||||
/* easysrc_decl declarations come here */
|
||||
/* easysrc_data initialisations come here */
|
||||
/* easysrc_code statements come here */
|
||||
static const char *const srchard[]={
|
||||
"/* Here is a list of options the curl code used that cannot get generated",
|
||||
" as source easily. You may select to either not use them or implement",
|
||||
" them yourself.",
|
||||
"",
|
||||
NULL
|
||||
};
|
||||
static const char *const srcend[]={
|
||||
"",
|
||||
" return (int)ret;",
|
||||
"}",
|
||||
"/**** End of sample code ****/",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Clean up all source code if we run out of memory */
|
||||
static void easysrc_free(void)
|
||||
{
|
||||
slist_wc_free_all(easysrc_decl);
|
||||
easysrc_decl = NULL;
|
||||
slist_wc_free_all(easysrc_data);
|
||||
easysrc_data = NULL;
|
||||
slist_wc_free_all(easysrc_code);
|
||||
easysrc_code = NULL;
|
||||
slist_wc_free_all(easysrc_toohard);
|
||||
easysrc_toohard = NULL;
|
||||
slist_wc_free_all(easysrc_clean);
|
||||
easysrc_clean = NULL;
|
||||
}
|
||||
|
||||
/* Add a source line to the main code or remarks */
|
||||
CURLcode easysrc_add(struct slist_wc **plist, const char *line)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
struct slist_wc *list = slist_wc_append(*plist, line);
|
||||
if(!list) {
|
||||
easysrc_free();
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
*plist = list;
|
||||
return ret;
|
||||
}
|
||||
|
||||
CURLcode easysrc_addf(struct slist_wc **plist, const char *fmt, ...)
|
||||
{
|
||||
CURLcode ret;
|
||||
char *bufp;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
bufp = curlx_mvaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
if(!bufp) {
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
ret = easysrc_add(plist, bufp);
|
||||
curl_free(bufp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define CHKRET(v) do {CURLcode ret = (v); if(ret) return ret;} while(0)
|
||||
|
||||
CURLcode easysrc_init(void)
|
||||
{
|
||||
CHKRET(easysrc_add(&easysrc_code,
|
||||
"hnd = curl_easy_init();"));
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CURLcode easysrc_perform(void)
|
||||
{
|
||||
/* Note any setopt calls which we could not convert */
|
||||
if(easysrc_toohard) {
|
||||
int i;
|
||||
struct curl_slist *ptr;
|
||||
const char *c;
|
||||
CHKRET(easysrc_add(&easysrc_code, ""));
|
||||
/* Preamble comment */
|
||||
for(i = 0; ((c = srchard[i]) != NULL); i++)
|
||||
CHKRET(easysrc_add(&easysrc_code, c));
|
||||
/* Each unconverted option */
|
||||
if(easysrc_toohard) {
|
||||
for(ptr = easysrc_toohard->first; ptr; ptr = ptr->next)
|
||||
CHKRET(easysrc_add(&easysrc_code, ptr->data));
|
||||
}
|
||||
CHKRET(easysrc_add(&easysrc_code, ""));
|
||||
CHKRET(easysrc_add(&easysrc_code, "*/"));
|
||||
|
||||
slist_wc_free_all(easysrc_toohard);
|
||||
easysrc_toohard = NULL;
|
||||
}
|
||||
|
||||
CHKRET(easysrc_add(&easysrc_code, ""));
|
||||
CHKRET(easysrc_add(&easysrc_code, "ret = curl_easy_perform(hnd);"));
|
||||
CHKRET(easysrc_add(&easysrc_code, ""));
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
CURLcode easysrc_cleanup(void)
|
||||
{
|
||||
CHKRET(easysrc_add(&easysrc_code, "curl_easy_cleanup(hnd);"));
|
||||
CHKRET(easysrc_add(&easysrc_code, "hnd = NULL;"));
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void dumpeasysrc(struct GlobalConfig *config)
|
||||
{
|
||||
struct curl_slist *ptr;
|
||||
char *o = config->libcurl;
|
||||
|
||||
FILE *out;
|
||||
bool fopened = FALSE;
|
||||
if(strcmp(o, "-")) {
|
||||
out = fopen(o, FOPEN_WRITETEXT);
|
||||
fopened = TRUE;
|
||||
}
|
||||
else
|
||||
out = stdout;
|
||||
if(!out)
|
||||
warnf(config, "Failed to open %s to write libcurl code!\n", o);
|
||||
else {
|
||||
int i;
|
||||
const char *c;
|
||||
|
||||
for(i = 0; ((c = srchead[i]) != NULL); i++)
|
||||
fprintf(out, "%s\n", c);
|
||||
|
||||
/* Declare variables used for complex setopt values */
|
||||
if(easysrc_decl) {
|
||||
for(ptr = easysrc_decl->first; ptr; ptr = ptr->next)
|
||||
fprintf(out, " %s\n", ptr->data);
|
||||
}
|
||||
|
||||
/* Set up complex values for setopt calls */
|
||||
if(easysrc_data) {
|
||||
fprintf(out, "\n");
|
||||
|
||||
for(ptr = easysrc_data->first; ptr; ptr = ptr->next)
|
||||
fprintf(out, " %s\n", ptr->data);
|
||||
}
|
||||
|
||||
fprintf(out, "\n");
|
||||
if(easysrc_code) {
|
||||
for(ptr = easysrc_code->first; ptr; ptr = ptr->next) {
|
||||
if(ptr->data[0]) {
|
||||
fprintf(out, " %s\n", ptr->data);
|
||||
}
|
||||
else {
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(easysrc_clean) {
|
||||
for(ptr = easysrc_clean->first; ptr; ptr = ptr->next)
|
||||
fprintf(out, " %s\n", ptr->data);
|
||||
}
|
||||
|
||||
for(i = 0; ((c = srcend[i]) != NULL); i++)
|
||||
fprintf(out, "%s\n", c);
|
||||
|
||||
if(fopened)
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
easysrc_free();
|
||||
}
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
49
module/Vendor/CURL/src/tool_easysrc.h
vendored
Normal file
49
module/Vendor/CURL/src/tool_easysrc.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef HEADER_CURL_TOOL_EASYSRC_H
|
||||
#define HEADER_CURL_TOOL_EASYSRC_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
/* global variable declarations, for easy-interface source code generation */
|
||||
|
||||
extern struct slist_wc *easysrc_decl; /* Variable declarations */
|
||||
extern struct slist_wc *easysrc_data; /* Build slists, forms etc. */
|
||||
extern struct slist_wc *easysrc_code; /* Setopt calls etc. */
|
||||
extern struct slist_wc *easysrc_toohard; /* Unconvertible setopt */
|
||||
extern struct slist_wc *easysrc_clean; /* Clean up (reverse order) */
|
||||
|
||||
extern int easysrc_mime_count; /* Number of curl_mime variables */
|
||||
extern int easysrc_slist_count; /* Number of curl_slist variables */
|
||||
|
||||
extern CURLcode easysrc_init(void);
|
||||
extern CURLcode easysrc_add(struct slist_wc **plist, const char *bupf);
|
||||
extern CURLcode easysrc_addf(struct slist_wc **plist,
|
||||
const char *fmt, ...);
|
||||
extern CURLcode easysrc_perform(void);
|
||||
extern CURLcode easysrc_cleanup(void);
|
||||
|
||||
void dumpeasysrc(struct GlobalConfig *config);
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_EASYSRC_H */
|
166
module/Vendor/CURL/src/tool_filetime.c
vendored
Normal file
166
module/Vendor/CURL/src/tool_filetime.c
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_filetime.h"
|
||||
|
||||
#include "curlx.h"
|
||||
|
||||
#ifdef HAVE_UTIME_H
|
||||
# include <utime.h>
|
||||
#elif defined(HAVE_SYS_UTIME_H)
|
||||
# include <sys/utime.h>
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(__MINGW32__)
|
||||
/* GCC 10 on mingw has issues with this, disable */
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
|
||||
curl_off_t getfiletime(const char *filename, FILE *error_stream)
|
||||
{
|
||||
curl_off_t result = -1;
|
||||
|
||||
/* Windows stat() may attempt to adjust the unix GMT file time by a daylight
|
||||
saving time offset and since it's GMT that is bad behavior. When we have
|
||||
access to a 64-bit type we can bypass stat and get the times directly. */
|
||||
#if defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)
|
||||
HANDLE hfile;
|
||||
TCHAR *tchar_filename = curlx_convert_UTF8_to_tchar((char *)filename);
|
||||
|
||||
hfile = CreateFile(tchar_filename, FILE_READ_ATTRIBUTES,
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE |
|
||||
FILE_SHARE_DELETE),
|
||||
NULL, OPEN_EXISTING, 0, NULL);
|
||||
curlx_unicodefree(tchar_filename);
|
||||
if(hfile != INVALID_HANDLE_VALUE) {
|
||||
FILETIME ft;
|
||||
if(GetFileTime(hfile, NULL, NULL, &ft)) {
|
||||
curl_off_t converted = (curl_off_t)ft.dwLowDateTime
|
||||
| ((curl_off_t)ft.dwHighDateTime) << 32;
|
||||
|
||||
if(converted < CURL_OFF_T_C(116444736000000000)) {
|
||||
fprintf(error_stream,
|
||||
"Failed to get filetime: underflow\n");
|
||||
}
|
||||
else {
|
||||
result = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(error_stream,
|
||||
"Failed to get filetime: "
|
||||
"GetFileTime failed: GetLastError %u\n",
|
||||
(unsigned int)GetLastError());
|
||||
}
|
||||
CloseHandle(hfile);
|
||||
}
|
||||
else if(GetLastError() != ERROR_FILE_NOT_FOUND) {
|
||||
fprintf(error_stream,
|
||||
"Failed to get filetime: "
|
||||
"CreateFile failed: GetLastError %u\n",
|
||||
(unsigned int)GetLastError());
|
||||
}
|
||||
#else
|
||||
struct_stat statbuf;
|
||||
if(-1 != stat(filename, &statbuf)) {
|
||||
result = (curl_off_t)statbuf.st_mtime;
|
||||
}
|
||||
else if(errno != ENOENT) {
|
||||
fprintf(error_stream,
|
||||
"Failed to get filetime: %s\n", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
|
||||
(defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8))
|
||||
void setfiletime(curl_off_t filetime, const char *filename,
|
||||
FILE *error_stream)
|
||||
{
|
||||
if(filetime >= 0) {
|
||||
/* Windows utime() may attempt to adjust the unix GMT file time by a daylight
|
||||
saving time offset and since it's GMT that is bad behavior. When we have
|
||||
access to a 64-bit type we can bypass utime and set the times directly. */
|
||||
#if defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)
|
||||
HANDLE hfile;
|
||||
TCHAR *tchar_filename = curlx_convert_UTF8_to_tchar((char *)filename);
|
||||
|
||||
/* 910670515199 is the maximum unix filetime that can be used as a
|
||||
Windows FILETIME without overflow: 30827-12-31T23:59:59. */
|
||||
if(filetime > CURL_OFF_T_C(910670515199)) {
|
||||
fprintf(error_stream,
|
||||
"Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
|
||||
" on outfile: overflow\n", filetime);
|
||||
curlx_unicodefree(tchar_filename);
|
||||
return;
|
||||
}
|
||||
|
||||
hfile = CreateFile(tchar_filename, FILE_WRITE_ATTRIBUTES,
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE |
|
||||
FILE_SHARE_DELETE),
|
||||
NULL, OPEN_EXISTING, 0, NULL);
|
||||
curlx_unicodefree(tchar_filename);
|
||||
if(hfile != INVALID_HANDLE_VALUE) {
|
||||
curl_off_t converted = ((curl_off_t)filetime * 10000000) +
|
||||
CURL_OFF_T_C(116444736000000000);
|
||||
FILETIME ft;
|
||||
ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
|
||||
ft.dwHighDateTime = (DWORD)(converted >> 32);
|
||||
if(!SetFileTime(hfile, NULL, &ft, &ft)) {
|
||||
fprintf(error_stream,
|
||||
"Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
|
||||
" on outfile: SetFileTime failed: GetLastError %u\n",
|
||||
filetime, (unsigned int)GetLastError());
|
||||
}
|
||||
CloseHandle(hfile);
|
||||
}
|
||||
else {
|
||||
fprintf(error_stream,
|
||||
"Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
|
||||
" on outfile: CreateFile failed: GetLastError %u\n",
|
||||
filetime, (unsigned int)GetLastError());
|
||||
}
|
||||
|
||||
#elif defined(HAVE_UTIMES)
|
||||
struct timeval times[2];
|
||||
times[0].tv_sec = times[1].tv_sec = (time_t)filetime;
|
||||
times[0].tv_usec = times[1].tv_usec = 0;
|
||||
if(utimes(filename, times)) {
|
||||
fprintf(error_stream,
|
||||
"Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
|
||||
" on outfile: %s\n", filetime, strerror(errno));
|
||||
}
|
||||
|
||||
#elif defined(HAVE_UTIME)
|
||||
struct utimbuf times;
|
||||
times.actime = (time_t)filetime;
|
||||
times.modtime = (time_t)filetime;
|
||||
if(utime(filename, ×)) {
|
||||
fprintf(error_stream,
|
||||
"Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
|
||||
" on outfile: %s\n", filetime, strerror(errno));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
|
||||
(defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)) */
|
37
module/Vendor/CURL/src/tool_filetime.h
vendored
Normal file
37
module/Vendor/CURL/src/tool_filetime.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef HEADER_CURL_TOOL_FILETIME_H
|
||||
#define HEADER_CURL_TOOL_FILETIME_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
curl_off_t getfiletime(const char *filename, FILE *error_stream);
|
||||
|
||||
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
|
||||
(defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8))
|
||||
void setfiletime(curl_off_t filetime, const char *filename,
|
||||
FILE *error_stream);
|
||||
#else
|
||||
#define setfiletime(a,b,c) Curl_nop_stmt
|
||||
#endif /* defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
|
||||
(defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8)) */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_FILETIME_H */
|
923
module/Vendor/CURL/src/tool_formparse.c
vendored
Normal file
923
module/Vendor/CURL/src/tool_formparse.c
vendored
Normal file
@ -0,0 +1,923 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_convert.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_binmode.h"
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_paramhlp.h"
|
||||
#include "tool_formparse.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* Macros to free const pointers. */
|
||||
#define CONST_FREE(x) free((void *) (x))
|
||||
#define CONST_SAFEFREE(x) Curl_safefree(*((void **) &(x)))
|
||||
|
||||
/* tool_mime functions. */
|
||||
static struct tool_mime *tool_mime_new(struct tool_mime *parent,
|
||||
toolmimekind kind)
|
||||
{
|
||||
struct tool_mime *m = (struct tool_mime *) calloc(1, sizeof(*m));
|
||||
|
||||
if(m) {
|
||||
m->kind = kind;
|
||||
m->parent = parent;
|
||||
if(parent) {
|
||||
m->prev = parent->subparts;
|
||||
parent->subparts = m;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
static struct tool_mime *tool_mime_new_parts(struct tool_mime *parent)
|
||||
{
|
||||
return tool_mime_new(parent, TOOLMIME_PARTS);
|
||||
}
|
||||
|
||||
static struct tool_mime *tool_mime_new_data(struct tool_mime *parent,
|
||||
const char *data)
|
||||
{
|
||||
struct tool_mime *m = NULL;
|
||||
|
||||
data = strdup(data);
|
||||
if(data) {
|
||||
m = tool_mime_new(parent, TOOLMIME_DATA);
|
||||
if(!m)
|
||||
CONST_FREE(data);
|
||||
else
|
||||
m->data = data;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
|
||||
const char *filename,
|
||||
bool isremotefile,
|
||||
CURLcode *errcode)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct tool_mime *m = NULL;
|
||||
|
||||
*errcode = CURLE_OUT_OF_MEMORY;
|
||||
if(strcmp(filename, "-")) {
|
||||
/* This is a normal file. */
|
||||
filename = strdup(filename);
|
||||
if(filename) {
|
||||
m = tool_mime_new(parent, TOOLMIME_FILE);
|
||||
if(!m)
|
||||
CONST_FREE(filename);
|
||||
else {
|
||||
m->data = filename;
|
||||
if(!isremotefile)
|
||||
m->kind = TOOLMIME_FILEDATA;
|
||||
*errcode = CURLE_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* Standard input. */
|
||||
int fd = fileno(stdin);
|
||||
char *data = NULL;
|
||||
curl_off_t size;
|
||||
curl_off_t origin;
|
||||
struct_stat sbuf;
|
||||
|
||||
set_binmode(stdin);
|
||||
origin = ftell(stdin);
|
||||
/* If stdin is a regular file, do not buffer data but read it
|
||||
when needed. */
|
||||
if(fd >= 0 && origin >= 0 && !fstat(fd, &sbuf) &&
|
||||
#ifdef __VMS
|
||||
sbuf.st_fab_rfm != FAB$C_VAR && sbuf.st_fab_rfm != FAB$C_VFC &&
|
||||
#endif
|
||||
S_ISREG(sbuf.st_mode)) {
|
||||
size = sbuf.st_size - origin;
|
||||
if(size < 0)
|
||||
size = 0;
|
||||
}
|
||||
else { /* Not suitable for direct use, buffer stdin data. */
|
||||
size_t stdinsize = 0;
|
||||
|
||||
if(file2memory(&data, &stdinsize, stdin) != PARAM_OK) {
|
||||
/* Out of memory. */
|
||||
return m;
|
||||
}
|
||||
|
||||
if(ferror(stdin)) {
|
||||
result = CURLE_READ_ERROR;
|
||||
Curl_safefree(data);
|
||||
data = NULL;
|
||||
}
|
||||
else if(!stdinsize) {
|
||||
/* Zero-length data has been freed. Re-create it. */
|
||||
data = strdup("");
|
||||
if(!data)
|
||||
return m;
|
||||
}
|
||||
size = curlx_uztoso(stdinsize);
|
||||
origin = 0;
|
||||
}
|
||||
m = tool_mime_new(parent, TOOLMIME_STDIN);
|
||||
if(!m)
|
||||
Curl_safefree(data);
|
||||
else {
|
||||
m->data = data;
|
||||
m->origin = origin;
|
||||
m->size = size;
|
||||
m->curpos = 0;
|
||||
if(!isremotefile)
|
||||
m->kind = TOOLMIME_STDINDATA;
|
||||
*errcode = result;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
void tool_mime_free(struct tool_mime *mime)
|
||||
{
|
||||
if(mime) {
|
||||
if(mime->subparts)
|
||||
tool_mime_free(mime->subparts);
|
||||
if(mime->prev)
|
||||
tool_mime_free(mime->prev);
|
||||
CONST_SAFEFREE(mime->name);
|
||||
CONST_SAFEFREE(mime->filename);
|
||||
CONST_SAFEFREE(mime->type);
|
||||
CONST_SAFEFREE(mime->encoder);
|
||||
CONST_SAFEFREE(mime->data);
|
||||
curl_slist_free_all(mime->headers);
|
||||
free(mime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Mime part callbacks for stdin. */
|
||||
size_t tool_mime_stdin_read(char *buffer,
|
||||
size_t size, size_t nitems, void *arg)
|
||||
{
|
||||
struct tool_mime *sip = (struct tool_mime *) arg;
|
||||
curl_off_t bytesleft;
|
||||
(void) size; /* Always 1: ignored. */
|
||||
|
||||
if(sip->size >= 0) {
|
||||
if(sip->curpos >= sip->size)
|
||||
return 0; /* At eof. */
|
||||
bytesleft = sip->size - sip->curpos;
|
||||
if(curlx_uztoso(nitems) > bytesleft)
|
||||
nitems = curlx_sotouz(bytesleft);
|
||||
}
|
||||
if(nitems) {
|
||||
if(sip->data) {
|
||||
/* Return data from memory. */
|
||||
memcpy(buffer, sip->data + curlx_sotouz(sip->curpos), nitems);
|
||||
}
|
||||
else {
|
||||
/* Read from stdin. */
|
||||
nitems = fread(buffer, 1, nitems, stdin);
|
||||
if(ferror(stdin)) {
|
||||
/* Show error only once. */
|
||||
if(sip->config) {
|
||||
warnf(sip->config, "stdin: %s\n", strerror(errno));
|
||||
sip->config = NULL;
|
||||
}
|
||||
return CURL_READFUNC_ABORT;
|
||||
}
|
||||
}
|
||||
sip->curpos += curlx_uztoso(nitems);
|
||||
}
|
||||
return nitems;
|
||||
}
|
||||
|
||||
int tool_mime_stdin_seek(void *instream, curl_off_t offset, int whence)
|
||||
{
|
||||
struct tool_mime *sip = (struct tool_mime *) instream;
|
||||
|
||||
switch(whence) {
|
||||
case SEEK_CUR:
|
||||
offset += sip->curpos;
|
||||
break;
|
||||
case SEEK_END:
|
||||
offset += sip->size;
|
||||
break;
|
||||
}
|
||||
if(offset < 0)
|
||||
return CURL_SEEKFUNC_CANTSEEK;
|
||||
if(!sip->data) {
|
||||
if(fseek(stdin, (long) (offset + sip->origin), SEEK_SET))
|
||||
return CURL_SEEKFUNC_CANTSEEK;
|
||||
}
|
||||
sip->curpos = offset;
|
||||
return CURL_SEEKFUNC_OK;
|
||||
}
|
||||
|
||||
/* Translate an internal mime tree into a libcurl mime tree. */
|
||||
|
||||
static CURLcode tool2curlparts(CURL *curl, struct tool_mime *m,
|
||||
curl_mime *mime)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
curl_mimepart *part = NULL;
|
||||
curl_mime *submime = NULL;
|
||||
const char *filename = NULL;
|
||||
|
||||
if(m) {
|
||||
ret = tool2curlparts(curl, m->prev, mime);
|
||||
if(!ret) {
|
||||
part = curl_mime_addpart(mime);
|
||||
if(!part)
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
if(!ret) {
|
||||
filename = m->filename;
|
||||
switch(m->kind) {
|
||||
case TOOLMIME_PARTS:
|
||||
ret = tool2curlmime(curl, m, &submime);
|
||||
if(!ret) {
|
||||
ret = curl_mime_subparts(part, submime);
|
||||
if(ret)
|
||||
curl_mime_free(submime);
|
||||
}
|
||||
break;
|
||||
|
||||
case TOOLMIME_DATA:
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
/* Our data is always textual: convert it to ASCII. */
|
||||
{
|
||||
size_t size = strlen(m->data);
|
||||
char *cp = malloc(size + 1);
|
||||
|
||||
if(!cp)
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
else {
|
||||
memcpy(cp, m->data, size + 1);
|
||||
ret = convert_to_network(cp, size);
|
||||
if(!ret)
|
||||
ret = curl_mime_data(part, cp, CURL_ZERO_TERMINATED);
|
||||
free(cp);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ret = curl_mime_data(part, m->data, CURL_ZERO_TERMINATED);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case TOOLMIME_FILE:
|
||||
case TOOLMIME_FILEDATA:
|
||||
ret = curl_mime_filedata(part, m->data);
|
||||
if(!ret && m->kind == TOOLMIME_FILEDATA && !filename)
|
||||
ret = curl_mime_filename(part, NULL);
|
||||
break;
|
||||
|
||||
case TOOLMIME_STDIN:
|
||||
if(!filename)
|
||||
filename = "-";
|
||||
/* FALLTHROUGH */
|
||||
case TOOLMIME_STDINDATA:
|
||||
ret = curl_mime_data_cb(part, m->size,
|
||||
(curl_read_callback) tool_mime_stdin_read,
|
||||
(curl_seek_callback) tool_mime_stdin_seek,
|
||||
NULL, m);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Other cases not possible in this context. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!ret && filename)
|
||||
ret = curl_mime_filename(part, filename);
|
||||
if(!ret)
|
||||
ret = curl_mime_type(part, m->type);
|
||||
if(!ret)
|
||||
ret = curl_mime_headers(part, m->headers, 0);
|
||||
if(!ret)
|
||||
ret = curl_mime_encoder(part, m->encoder);
|
||||
if(!ret)
|
||||
ret = curl_mime_name(part, m->name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CURLcode tool2curlmime(CURL *curl, struct tool_mime *m, curl_mime **mime)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
|
||||
*mime = curl_mime_init(curl);
|
||||
if(!*mime)
|
||||
ret = CURLE_OUT_OF_MEMORY;
|
||||
else
|
||||
ret = tool2curlparts(curl, m->subparts, *mime);
|
||||
if(ret) {
|
||||
curl_mime_free(*mime);
|
||||
*mime = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to get a word from form param
|
||||
* after call get_parm_word, str either point to string end
|
||||
* or point to any of end chars.
|
||||
*/
|
||||
static char *get_param_word(char **str, char **end_pos, char endchar)
|
||||
{
|
||||
char *ptr = *str;
|
||||
/* the first non-space char is here */
|
||||
char *word_begin = ptr;
|
||||
char *ptr2;
|
||||
char *escape = NULL;
|
||||
|
||||
if(*ptr == '"') {
|
||||
++ptr;
|
||||
while(*ptr) {
|
||||
if(*ptr == '\\') {
|
||||
if(ptr[1] == '\\' || ptr[1] == '"') {
|
||||
/* remember the first escape position */
|
||||
if(!escape)
|
||||
escape = ptr;
|
||||
/* skip escape of back-slash or double-quote */
|
||||
ptr += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(*ptr == '"') {
|
||||
*end_pos = ptr;
|
||||
if(escape) {
|
||||
/* has escape, we restore the unescaped string here */
|
||||
ptr = ptr2 = escape;
|
||||
do {
|
||||
if(*ptr == '\\' && (ptr[1] == '\\' || ptr[1] == '"'))
|
||||
++ptr;
|
||||
*ptr2++ = *ptr++;
|
||||
}
|
||||
while(ptr < *end_pos);
|
||||
*end_pos = ptr2;
|
||||
}
|
||||
while(*ptr && *ptr != ';' && *ptr != endchar)
|
||||
++ptr;
|
||||
*str = ptr;
|
||||
return word_begin + 1;
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
/* end quote is missing, treat it as non-quoted. */
|
||||
ptr = word_begin;
|
||||
}
|
||||
|
||||
while(*ptr && *ptr != ';' && *ptr != endchar)
|
||||
++ptr;
|
||||
*str = *end_pos = ptr;
|
||||
return word_begin;
|
||||
}
|
||||
|
||||
/* Append slist item and return -1 if failed. */
|
||||
static int slist_append(struct curl_slist **plist, const char *data)
|
||||
{
|
||||
struct curl_slist *s = curl_slist_append(*plist, data);
|
||||
|
||||
if(!s)
|
||||
return -1;
|
||||
|
||||
*plist = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read headers from a file and append to list. */
|
||||
static int read_field_headers(struct OperationConfig *config,
|
||||
const char *filename, FILE *fp,
|
||||
struct curl_slist **pheaders)
|
||||
{
|
||||
size_t hdrlen = 0;
|
||||
size_t pos = 0;
|
||||
bool incomment = FALSE;
|
||||
int lineno = 1;
|
||||
char hdrbuf[999]; /* Max. header length + 1. */
|
||||
|
||||
for(;;) {
|
||||
int c = getc(fp);
|
||||
if(c == EOF || (!pos && !ISSPACE(c))) {
|
||||
/* Strip and flush the current header. */
|
||||
while(hdrlen && ISSPACE(hdrbuf[hdrlen - 1]))
|
||||
hdrlen--;
|
||||
if(hdrlen) {
|
||||
hdrbuf[hdrlen] = '\0';
|
||||
if(slist_append(pheaders, hdrbuf)) {
|
||||
fprintf(config->global->errors,
|
||||
"Out of memory for field headers!\n");
|
||||
return -1;
|
||||
}
|
||||
hdrlen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch(c) {
|
||||
case EOF:
|
||||
if(ferror(fp)) {
|
||||
fprintf(config->global->errors,
|
||||
"Header file %s read error: %s\n", filename, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0; /* Done. */
|
||||
case '\r':
|
||||
continue; /* Ignore. */
|
||||
case '\n':
|
||||
pos = 0;
|
||||
incomment = FALSE;
|
||||
lineno++;
|
||||
continue;
|
||||
case '#':
|
||||
if(!pos)
|
||||
incomment = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
pos++;
|
||||
if(!incomment) {
|
||||
if(hdrlen == sizeof(hdrbuf) - 1) {
|
||||
warnf(config->global, "File %s line %d: header too long (truncated)\n",
|
||||
filename, lineno);
|
||||
c = ' ';
|
||||
}
|
||||
if(hdrlen <= sizeof(hdrbuf) - 1)
|
||||
hdrbuf[hdrlen++] = (char) c;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static int get_param_part(struct OperationConfig *config, char endchar,
|
||||
char **str, char **pdata, char **ptype,
|
||||
char **pfilename, char **pencoder,
|
||||
struct curl_slist **pheaders)
|
||||
{
|
||||
char *p = *str;
|
||||
char *type = NULL;
|
||||
char *filename = NULL;
|
||||
char *encoder = NULL;
|
||||
char *endpos;
|
||||
char *tp;
|
||||
char sep;
|
||||
char type_major[128] = "";
|
||||
char type_minor[128] = "";
|
||||
char *endct = NULL;
|
||||
struct curl_slist *headers = NULL;
|
||||
|
||||
if(ptype)
|
||||
*ptype = NULL;
|
||||
if(pfilename)
|
||||
*pfilename = NULL;
|
||||
if(pheaders)
|
||||
*pheaders = NULL;
|
||||
if(pencoder)
|
||||
*pencoder = NULL;
|
||||
while(ISSPACE(*p))
|
||||
p++;
|
||||
tp = p;
|
||||
*pdata = get_param_word(&p, &endpos, endchar);
|
||||
/* If not quoted, strip trailing spaces. */
|
||||
if(*pdata == tp)
|
||||
while(endpos > *pdata && ISSPACE(endpos[-1]))
|
||||
endpos--;
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
while(sep == ';') {
|
||||
while(ISSPACE(*++p))
|
||||
;
|
||||
|
||||
if(!endct && checkprefix("type=", p)) {
|
||||
for(p += 5; ISSPACE(*p); p++)
|
||||
;
|
||||
/* set type pointer */
|
||||
type = p;
|
||||
|
||||
/* verify that this is a fine type specifier */
|
||||
if(2 != sscanf(type, "%127[^/ ]/%127[^;, \n]", type_major, type_minor)) {
|
||||
warnf(config->global, "Illegally formatted content-type field!\n");
|
||||
curl_slist_free_all(headers);
|
||||
return -1; /* illegal content-type syntax! */
|
||||
}
|
||||
|
||||
/* now point beyond the content-type specifier */
|
||||
p = type + strlen(type_major) + strlen(type_minor) + 1;
|
||||
for(endct = p; *p && *p != ';' && *p != endchar; p++)
|
||||
if(!ISSPACE(*p))
|
||||
endct = p + 1;
|
||||
sep = *p;
|
||||
}
|
||||
else if(checkprefix("filename=", p)) {
|
||||
if(endct) {
|
||||
*endct = '\0';
|
||||
endct = NULL;
|
||||
}
|
||||
for(p += 9; ISSPACE(*p); p++)
|
||||
;
|
||||
tp = p;
|
||||
filename = get_param_word(&p, &endpos, endchar);
|
||||
/* If not quoted, strip trailing spaces. */
|
||||
if(filename == tp)
|
||||
while(endpos > filename && ISSPACE(endpos[-1]))
|
||||
endpos--;
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
}
|
||||
else if(checkprefix("headers=", p)) {
|
||||
if(endct) {
|
||||
*endct = '\0';
|
||||
endct = NULL;
|
||||
}
|
||||
p += 8;
|
||||
if(*p == '@' || *p == '<') {
|
||||
char *hdrfile;
|
||||
FILE *fp;
|
||||
/* Read headers from a file. */
|
||||
|
||||
do {
|
||||
p++;
|
||||
} while(ISSPACE(*p));
|
||||
tp = p;
|
||||
hdrfile = get_param_word(&p, &endpos, endchar);
|
||||
/* If not quoted, strip trailing spaces. */
|
||||
if(hdrfile == tp)
|
||||
while(endpos > hdrfile && ISSPACE(endpos[-1]))
|
||||
endpos--;
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
fp = fopen(hdrfile, FOPEN_READTEXT);
|
||||
if(!fp)
|
||||
warnf(config->global, "Cannot read from %s: %s\n", hdrfile,
|
||||
strerror(errno));
|
||||
else {
|
||||
int i = read_field_headers(config, hdrfile, fp, &headers);
|
||||
|
||||
fclose(fp);
|
||||
if(i) {
|
||||
curl_slist_free_all(headers);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *hdr;
|
||||
|
||||
while(ISSPACE(*p))
|
||||
p++;
|
||||
tp = p;
|
||||
hdr = get_param_word(&p, &endpos, endchar);
|
||||
/* If not quoted, strip trailing spaces. */
|
||||
if(hdr == tp)
|
||||
while(endpos > hdr && ISSPACE(endpos[-1]))
|
||||
endpos--;
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
if(slist_append(&headers, hdr)) {
|
||||
fprintf(config->global->errors, "Out of memory for field header!\n");
|
||||
curl_slist_free_all(headers);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(checkprefix("encoder=", p)) {
|
||||
if(endct) {
|
||||
*endct = '\0';
|
||||
endct = NULL;
|
||||
}
|
||||
for(p += 8; ISSPACE(*p); p++)
|
||||
;
|
||||
tp = p;
|
||||
encoder = get_param_word(&p, &endpos, endchar);
|
||||
/* If not quoted, strip trailing spaces. */
|
||||
if(encoder == tp)
|
||||
while(endpos > encoder && ISSPACE(endpos[-1]))
|
||||
endpos--;
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
}
|
||||
else if(endct) {
|
||||
/* This is part of content type. */
|
||||
for(endct = p; *p && *p != ';' && *p != endchar; p++)
|
||||
if(!ISSPACE(*p))
|
||||
endct = p + 1;
|
||||
sep = *p;
|
||||
}
|
||||
else {
|
||||
/* unknown prefix, skip to next block */
|
||||
char *unknown = get_param_word(&p, &endpos, endchar);
|
||||
|
||||
sep = *p;
|
||||
*endpos = '\0';
|
||||
if(*unknown)
|
||||
warnf(config->global, "skip unknown form field: %s\n", unknown);
|
||||
}
|
||||
}
|
||||
|
||||
/* Terminate content type. */
|
||||
if(endct)
|
||||
*endct = '\0';
|
||||
|
||||
if(ptype)
|
||||
*ptype = type;
|
||||
else if(type)
|
||||
warnf(config->global, "Field content type not allowed here: %s\n", type);
|
||||
|
||||
if(pfilename)
|
||||
*pfilename = filename;
|
||||
else if(filename)
|
||||
warnf(config->global,
|
||||
"Field file name not allowed here: %s\n", filename);
|
||||
|
||||
if(pencoder)
|
||||
*pencoder = encoder;
|
||||
else if(encoder)
|
||||
warnf(config->global,
|
||||
"Field encoder not allowed here: %s\n", encoder);
|
||||
|
||||
if(pheaders)
|
||||
*pheaders = headers;
|
||||
else if(headers) {
|
||||
warnf(config->global,
|
||||
"Field headers not allowed here: %s\n", headers->data);
|
||||
curl_slist_free_all(headers);
|
||||
}
|
||||
|
||||
*str = p;
|
||||
return sep & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* formparse()
|
||||
*
|
||||
* Reads a 'name=value' parameter and builds the appropriate linked list.
|
||||
*
|
||||
* If the value is of the form '<filename', field data is read from the
|
||||
* given file.
|
||||
|
||||
* Specify files to upload with 'name=@filename', or 'name=@"filename"'
|
||||
* in case the filename contain ',' or ';'. Supports specified
|
||||
* given Content-Type of the files. Such as ';type=<content-type>'.
|
||||
*
|
||||
* If literal_value is set, any initial '@' or '<' in the value string
|
||||
* loses its special meaning, as does any embedded ';type='.
|
||||
*
|
||||
* You may specify more than one file for a single name (field). Specify
|
||||
* multiple files by writing it like:
|
||||
*
|
||||
* 'name=@filename,filename2,filename3'
|
||||
*
|
||||
* or use double-quotes quote the filename:
|
||||
*
|
||||
* 'name=@"filename","filename2","filename3"'
|
||||
*
|
||||
* If you want content-types specified for each too, write them like:
|
||||
*
|
||||
* 'name=@filename;type=image/gif,filename2,filename3'
|
||||
*
|
||||
* If you want custom headers added for a single part, write them in a separate
|
||||
* file and do like this:
|
||||
*
|
||||
* 'name=foo;headers=@headerfile' or why not
|
||||
* 'name=@filemame;headers=@headerfile'
|
||||
*
|
||||
* To upload a file, but to fake the file name that will be included in the
|
||||
* formpost, do like this:
|
||||
*
|
||||
* 'name=@filename;filename=/dev/null' or quote the faked filename like:
|
||||
* 'name=@filename;filename="play, play, and play.txt"'
|
||||
*
|
||||
* If filename/path contains ',' or ';', it must be quoted by double-quotes,
|
||||
* else curl will fail to figure out the correct filename. if the filename
|
||||
* tobe quoted contains '"' or '\', '"' and '\' must be escaped by backslash.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* Convenience macros for null pointer check. */
|
||||
#define NULL_CHECK(ptr, init, retcode) \
|
||||
do { \
|
||||
(ptr) = (init); \
|
||||
if(!(ptr)) { \
|
||||
warnf(config->global, "out of memory!\n"); \
|
||||
curl_slist_free_all(headers); \
|
||||
Curl_safefree(contents); \
|
||||
return retcode; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define SET_TOOL_MIME_PTR(m, field, retcode) \
|
||||
do { \
|
||||
if(field) \
|
||||
NULL_CHECK((m)->field, strdup(field), retcode); \
|
||||
} while(0)
|
||||
|
||||
int formparse(struct OperationConfig *config,
|
||||
const char *input,
|
||||
struct tool_mime **mimeroot,
|
||||
struct tool_mime **mimecurrent,
|
||||
bool literal_value)
|
||||
{
|
||||
/* input MUST be a string in the format 'name=contents' and we'll
|
||||
build a linked list with the info */
|
||||
char *name = NULL;
|
||||
char *contents = NULL;
|
||||
char *contp;
|
||||
char *data;
|
||||
char *type = NULL;
|
||||
char *filename = NULL;
|
||||
char *encoder = NULL;
|
||||
struct curl_slist *headers = NULL;
|
||||
struct tool_mime *part = NULL;
|
||||
CURLcode res;
|
||||
|
||||
/* Allocate the main mime structure if needed. */
|
||||
if(!*mimecurrent) {
|
||||
NULL_CHECK(*mimeroot, tool_mime_new_parts(NULL), 1);
|
||||
*mimecurrent = *mimeroot;
|
||||
}
|
||||
|
||||
/* Make a copy we can overwrite. */
|
||||
NULL_CHECK(contents, strdup(input), 2);
|
||||
|
||||
/* Scan for the end of the name. */
|
||||
contp = strchr(contents, '=');
|
||||
if(contp) {
|
||||
int sep = '\0';
|
||||
if(contp > contents)
|
||||
name = contents;
|
||||
*contp++ = '\0';
|
||||
|
||||
if(*contp == '(' && !literal_value) {
|
||||
/* Starting a multipart. */
|
||||
sep = get_param_part(config, '\0',
|
||||
&contp, &data, &type, NULL, NULL, &headers);
|
||||
if(sep < 0) {
|
||||
Curl_safefree(contents);
|
||||
return 3;
|
||||
}
|
||||
NULL_CHECK(part, tool_mime_new_parts(*mimecurrent), 4);
|
||||
*mimecurrent = part;
|
||||
part->headers = headers;
|
||||
headers = NULL;
|
||||
SET_TOOL_MIME_PTR(part, type, 5);
|
||||
}
|
||||
else if(!name && !strcmp(contp, ")") && !literal_value) {
|
||||
/* Ending a multipart. */
|
||||
if(*mimecurrent == *mimeroot) {
|
||||
warnf(config->global, "no multipart to terminate!\n");
|
||||
Curl_safefree(contents);
|
||||
return 6;
|
||||
}
|
||||
*mimecurrent = (*mimecurrent)->parent;
|
||||
}
|
||||
else if('@' == contp[0] && !literal_value) {
|
||||
|
||||
/* we use the @-letter to indicate file name(s) */
|
||||
|
||||
struct tool_mime *subparts = NULL;
|
||||
|
||||
do {
|
||||
/* since this was a file, it may have a content-type specifier
|
||||
at the end too, or a filename. Or both. */
|
||||
++contp;
|
||||
sep = get_param_part(config, ',', &contp,
|
||||
&data, &type, &filename, &encoder, &headers);
|
||||
if(sep < 0) {
|
||||
Curl_safefree(contents);
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* now contp point to comma or string end.
|
||||
If more files to come, make sure we have multiparts. */
|
||||
if(!subparts) {
|
||||
if(sep != ',') /* If there is a single file. */
|
||||
subparts = *mimecurrent;
|
||||
else
|
||||
NULL_CHECK(subparts, tool_mime_new_parts(*mimecurrent), 8);
|
||||
}
|
||||
|
||||
/* Store that file in a part. */
|
||||
NULL_CHECK(part,
|
||||
tool_mime_new_filedata(subparts, data, TRUE, &res), 9);
|
||||
part->headers = headers;
|
||||
headers = NULL;
|
||||
part->config = config->global;
|
||||
if(res == CURLE_READ_ERROR) {
|
||||
/* An error occurred while reading stdin: if read has started,
|
||||
issue the error now. Else, delay it until processed by
|
||||
libcurl. */
|
||||
if(part->size > 0) {
|
||||
warnf(config->global,
|
||||
"error while reading standard input\n");
|
||||
Curl_safefree(contents);
|
||||
return 10;
|
||||
}
|
||||
CONST_SAFEFREE(part->data);
|
||||
part->data = NULL;
|
||||
part->size = -1;
|
||||
res = CURLE_OK;
|
||||
}
|
||||
SET_TOOL_MIME_PTR(part, filename, 11);
|
||||
SET_TOOL_MIME_PTR(part, type, 12);
|
||||
SET_TOOL_MIME_PTR(part, encoder, 13);
|
||||
|
||||
/* *contp could be '\0', so we just check with the delimiter */
|
||||
} while(sep); /* loop if there's another file name */
|
||||
part = (*mimecurrent)->subparts; /* Set name on group. */
|
||||
}
|
||||
else {
|
||||
if(*contp == '<' && !literal_value) {
|
||||
++contp;
|
||||
sep = get_param_part(config, '\0', &contp,
|
||||
&data, &type, NULL, &encoder, &headers);
|
||||
if(sep < 0) {
|
||||
Curl_safefree(contents);
|
||||
return 14;
|
||||
}
|
||||
|
||||
NULL_CHECK(part, tool_mime_new_filedata(*mimecurrent, data, FALSE,
|
||||
&res), 15);
|
||||
part->headers = headers;
|
||||
headers = NULL;
|
||||
part->config = config->global;
|
||||
if(res == CURLE_READ_ERROR) {
|
||||
/* An error occurred while reading stdin: if read has started,
|
||||
issue the error now. Else, delay it until processed by
|
||||
libcurl. */
|
||||
if(part->size > 0) {
|
||||
warnf(config->global,
|
||||
"error while reading standard input\n");
|
||||
Curl_safefree(contents);
|
||||
return 16;
|
||||
}
|
||||
CONST_SAFEFREE(part->data);
|
||||
part->data = NULL;
|
||||
part->size = -1;
|
||||
res = CURLE_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(literal_value)
|
||||
data = contp;
|
||||
else {
|
||||
sep = get_param_part(config, '\0', &contp,
|
||||
&data, &type, &filename, &encoder, &headers);
|
||||
if(sep < 0) {
|
||||
Curl_safefree(contents);
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
|
||||
NULL_CHECK(part, tool_mime_new_data(*mimecurrent, data), 18);
|
||||
part->headers = headers;
|
||||
headers = NULL;
|
||||
}
|
||||
|
||||
SET_TOOL_MIME_PTR(part, filename, 19);
|
||||
SET_TOOL_MIME_PTR(part, type, 20);
|
||||
SET_TOOL_MIME_PTR(part, encoder, 21);
|
||||
|
||||
if(sep) {
|
||||
*contp = (char) sep;
|
||||
warnf(config->global,
|
||||
"garbage at end of field specification: %s\n", contp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set part name. */
|
||||
SET_TOOL_MIME_PTR(part, name, 22);
|
||||
}
|
||||
else {
|
||||
warnf(config->global, "Illegally formatted input field!\n");
|
||||
Curl_safefree(contents);
|
||||
return 23;
|
||||
}
|
||||
Curl_safefree(contents);
|
||||
return 0;
|
||||
}
|
71
module/Vendor/CURL/src/tool_formparse.h
vendored
Normal file
71
module/Vendor/CURL/src/tool_formparse.h
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef HEADER_CURL_TOOL_FORMPARSE_H
|
||||
#define HEADER_CURL_TOOL_FORMPARSE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/* Private structure for mime/parts. */
|
||||
|
||||
typedef enum {
|
||||
TOOLMIME_NONE = 0,
|
||||
TOOLMIME_PARTS,
|
||||
TOOLMIME_DATA,
|
||||
TOOLMIME_FILE,
|
||||
TOOLMIME_FILEDATA,
|
||||
TOOLMIME_STDIN,
|
||||
TOOLMIME_STDINDATA
|
||||
} toolmimekind;
|
||||
|
||||
struct tool_mime {
|
||||
/* Structural fields. */
|
||||
toolmimekind kind; /* Part kind. */
|
||||
struct tool_mime *parent; /* Parent item. */
|
||||
struct tool_mime *prev; /* Previous sibling (reverse order link). */
|
||||
/* Common fields. */
|
||||
const char *data; /* Actual data or data filename. */
|
||||
const char *name; /* Part name. */
|
||||
const char *filename; /* Part's filename. */
|
||||
const char *type; /* Part's mime type. */
|
||||
const char *encoder; /* Part's requested encoding. */
|
||||
struct curl_slist *headers; /* User-defined headers. */
|
||||
/* TOOLMIME_PARTS fields. */
|
||||
struct tool_mime *subparts; /* Part's subparts. */
|
||||
/* TOOLMIME_STDIN/TOOLMIME_STDINDATA fields. */
|
||||
curl_off_t origin; /* Stdin read origin offset. */
|
||||
curl_off_t size; /* Stdin data size. */
|
||||
curl_off_t curpos; /* Stdin current read position. */
|
||||
struct GlobalConfig *config; /* For access from callback. */
|
||||
};
|
||||
|
||||
size_t tool_mime_stdin_read(char *buffer,
|
||||
size_t size, size_t nitems, void *arg);
|
||||
int tool_mime_stdin_seek(void *instream, curl_off_t offset, int whence);
|
||||
|
||||
int formparse(struct OperationConfig *config,
|
||||
const char *input,
|
||||
struct tool_mime **mimeroot,
|
||||
struct tool_mime **mimecurrent,
|
||||
bool literal_value);
|
||||
CURLcode tool2curlmime(CURL *curl, struct tool_mime *m, curl_mime **mime);
|
||||
void tool_mime_free(struct tool_mime *mime);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_FORMPARSE_H */
|
2364
module/Vendor/CURL/src/tool_getparam.c
vendored
Normal file
2364
module/Vendor/CURL/src/tool_getparam.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
65
module/Vendor/CURL/src/tool_getparam.h
vendored
Normal file
65
module/Vendor/CURL/src/tool_getparam.h
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef HEADER_CURL_TOOL_GETPARAM_H
|
||||
#define HEADER_CURL_TOOL_GETPARAM_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
typedef enum {
|
||||
PARAM_OK = 0,
|
||||
PARAM_OPTION_AMBIGUOUS,
|
||||
PARAM_OPTION_UNKNOWN,
|
||||
PARAM_REQUIRES_PARAMETER,
|
||||
PARAM_BAD_USE,
|
||||
PARAM_HELP_REQUESTED,
|
||||
PARAM_MANUAL_REQUESTED,
|
||||
PARAM_VERSION_INFO_REQUESTED,
|
||||
PARAM_ENGINES_REQUESTED,
|
||||
PARAM_GOT_EXTRA_PARAMETER,
|
||||
PARAM_BAD_NUMERIC,
|
||||
PARAM_NEGATIVE_NUMERIC,
|
||||
PARAM_LIBCURL_DOESNT_SUPPORT,
|
||||
PARAM_LIBCURL_UNSUPPORTED_PROTOCOL,
|
||||
PARAM_NO_MEM,
|
||||
PARAM_NEXT_OPERATION,
|
||||
PARAM_NO_PREFIX,
|
||||
PARAM_NUMBER_TOO_LARGE,
|
||||
PARAM_NO_NOT_BOOLEAN,
|
||||
PARAM_LAST
|
||||
} ParameterError;
|
||||
|
||||
struct GlobalConfig;
|
||||
struct OperationConfig;
|
||||
|
||||
ParameterError getparameter(const char *flag, char *nextarg, bool *usedarg,
|
||||
struct GlobalConfig *global,
|
||||
struct OperationConfig *operation);
|
||||
|
||||
#ifdef UNITTESTS
|
||||
void parse_cert_parameter(const char *cert_parameter,
|
||||
char **certname,
|
||||
char **passphrase);
|
||||
#endif
|
||||
|
||||
ParameterError parse_args(struct GlobalConfig *config, int argc,
|
||||
argv_item_t argv[]);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_GETPARAM_H */
|
252
module/Vendor/CURL/src/tool_getpass.c
vendored
Normal file
252
module/Vendor/CURL/src/tool_getpass.c
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(__AMIGA__) && !defined(__amigaos4__)
|
||||
# undef HAVE_TERMIOS_H
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETPASS_R
|
||||
/* this file is only for systems without getpass_r() */
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
# include <termio.h>
|
||||
#endif
|
||||
|
||||
#ifdef __VMS
|
||||
# include descrip
|
||||
# include starlet
|
||||
# include iodef
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# include <conio.h>
|
||||
#endif
|
||||
|
||||
#ifdef NETWARE
|
||||
# ifdef __NOVELL_LIBC__
|
||||
# include <screen.h>
|
||||
# else
|
||||
# include <nwconio.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "tool_getpass.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef __VMS
|
||||
/* VMS implementation */
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
|
||||
{
|
||||
long sts;
|
||||
short chan;
|
||||
|
||||
/* MSK, 23-JAN-2004, iosbdef.h wasn't in VAX V7.2 or CC 6.4 */
|
||||
/* distribution so I created this. May revert back later to */
|
||||
/* struct _iosb iosb; */
|
||||
struct _iosb
|
||||
{
|
||||
short int iosb$w_status; /* status */
|
||||
short int iosb$w_bcnt; /* byte count */
|
||||
int unused; /* unused */
|
||||
} iosb;
|
||||
|
||||
$DESCRIPTOR(ttdesc, "TT");
|
||||
|
||||
buffer[0] = '\0';
|
||||
sts = sys$assign(&ttdesc, &chan, 0, 0);
|
||||
if(sts & 1) {
|
||||
sts = sys$qiow(0, chan,
|
||||
IO$_READPROMPT | IO$M_NOECHO,
|
||||
&iosb, 0, 0, buffer, buflen, 0, 0,
|
||||
prompt, strlen(prompt));
|
||||
|
||||
if((sts & 1) && (iosb.iosb$w_status & 1))
|
||||
buffer[iosb.iosb$w_bcnt] = '\0';
|
||||
|
||||
sys$dassgn(chan);
|
||||
}
|
||||
return buffer; /* we always return success */
|
||||
}
|
||||
#define DONE
|
||||
#endif /* __VMS */
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i;
|
||||
fputs(prompt, stderr);
|
||||
|
||||
for(i = 0; i < buflen; i++) {
|
||||
buffer[i] = (char)getch();
|
||||
if(buffer[i] == '\r' || buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
break;
|
||||
}
|
||||
else
|
||||
if(buffer[i] == '\b')
|
||||
/* remove this letter and if this is not the first key, remove the
|
||||
previous one as well */
|
||||
i = i - (i >= 1 ? 2 : 1);
|
||||
}
|
||||
/* since echo is disabled, print a newline */
|
||||
fputs("\n", stderr);
|
||||
/* if user didn't hit ENTER, terminate buffer */
|
||||
if(i == buflen)
|
||||
buffer[buflen-1] = '\0';
|
||||
|
||||
return buffer; /* we always return success */
|
||||
}
|
||||
#define DONE
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef NETWARE
|
||||
/* NetWare implementation */
|
||||
#ifdef __NOVELL_LIBC__
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
|
||||
{
|
||||
return getpassword(prompt, buffer, buflen);
|
||||
}
|
||||
#else
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
printf("%s", prompt);
|
||||
do {
|
||||
buffer[i++] = getch();
|
||||
if(buffer[i-1] == '\b') {
|
||||
/* remove this letter and if this is not the first key,
|
||||
remove the previous one as well */
|
||||
if(i > 1) {
|
||||
printf("\b \b");
|
||||
i = i - 2;
|
||||
}
|
||||
else {
|
||||
RingTheBell();
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
else if(buffer[i-1] != 13)
|
||||
putchar('*');
|
||||
|
||||
} while((buffer[i-1] != 13) && (i < buflen));
|
||||
buffer[i-1] = '\0';
|
||||
printf("\r\n");
|
||||
return buffer;
|
||||
}
|
||||
#endif /* __NOVELL_LIBC__ */
|
||||
#define DONE
|
||||
#endif /* NETWARE */
|
||||
|
||||
#ifndef DONE /* not previously provided */
|
||||
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# define struct_term struct termios
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
# define struct_term struct termio
|
||||
#else
|
||||
# undef struct_term
|
||||
#endif
|
||||
|
||||
static bool ttyecho(bool enable, int fd)
|
||||
{
|
||||
#ifdef struct_term
|
||||
static struct_term withecho;
|
||||
static struct_term noecho;
|
||||
#endif
|
||||
if(!enable) {
|
||||
/* disable echo by extracting the current 'withecho' mode and remove the
|
||||
ECHO bit and set back the struct */
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
tcgetattr(fd, &withecho);
|
||||
noecho = withecho;
|
||||
noecho.c_lflag &= ~ECHO;
|
||||
tcsetattr(fd, TCSANOW, &noecho);
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
ioctl(fd, TCGETA, &withecho);
|
||||
noecho = withecho;
|
||||
noecho.c_lflag &= ~ECHO;
|
||||
ioctl(fd, TCSETA, &noecho);
|
||||
#else
|
||||
/* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H, we can't disable echo! */
|
||||
(void)fd;
|
||||
return FALSE; /* not disabled */
|
||||
#endif
|
||||
return TRUE; /* disabled */
|
||||
}
|
||||
/* re-enable echo, assumes we disabled it before (and set the structs we
|
||||
now use to reset the terminal status) */
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
tcsetattr(fd, TCSAFLUSH, &withecho);
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
ioctl(fd, TCSETA, &withecho);
|
||||
#else
|
||||
return FALSE; /* not enabled */
|
||||
#endif
|
||||
return TRUE; /* enabled */
|
||||
}
|
||||
|
||||
char *getpass_r(const char *prompt, /* prompt to display */
|
||||
char *password, /* buffer to store password in */
|
||||
size_t buflen) /* size of buffer to store password in */
|
||||
{
|
||||
ssize_t nread;
|
||||
bool disabled;
|
||||
int fd = open("/dev/tty", O_RDONLY);
|
||||
if(-1 == fd)
|
||||
fd = STDIN_FILENO; /* use stdin if the tty couldn't be used */
|
||||
|
||||
disabled = ttyecho(FALSE, fd); /* disable terminal echo */
|
||||
|
||||
fputs(prompt, stderr);
|
||||
nread = read(fd, password, buflen);
|
||||
if(nread > 0)
|
||||
password[--nread] = '\0'; /* null-terminate where enter is stored */
|
||||
else
|
||||
password[0] = '\0'; /* got nothing */
|
||||
|
||||
if(disabled) {
|
||||
/* if echo actually was disabled, add a newline */
|
||||
fputs("\n", stderr);
|
||||
(void)ttyecho(TRUE, fd); /* enable echo */
|
||||
}
|
||||
|
||||
if(STDIN_FILENO != fd)
|
||||
close(fd);
|
||||
|
||||
return password; /* return pointer to buffer */
|
||||
}
|
||||
|
||||
#endif /* DONE */
|
||||
#endif /* HAVE_GETPASS_R */
|
36
module/Vendor/CURL/src/tool_getpass.h
vendored
Normal file
36
module/Vendor/CURL/src/tool_getpass.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef HEADER_CURL_TOOL_GETPASS_H
|
||||
#define HEADER_CURL_TOOL_GETPASS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_GETPASS_R
|
||||
/* If there's a system-provided function named like this, we trust it is
|
||||
also found in one of the standard headers. */
|
||||
|
||||
/*
|
||||
* Returning NULL will abort the continued operation!
|
||||
*/
|
||||
char *getpass_r(const char *prompt, char *buffer, size_t buflen);
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_GETPASS_H */
|
1011
module/Vendor/CURL/src/tool_help.c
vendored
Normal file
1011
module/Vendor/CURL/src/tool_help.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
30
module/Vendor/CURL/src/tool_help.h
vendored
Normal file
30
module/Vendor/CURL/src/tool_help.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef HEADER_CURL_TOOL_HELP_H
|
||||
#define HEADER_CURL_TOOL_HELP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
void tool_help(char *category);
|
||||
void tool_list_engines(void);
|
||||
void tool_version_info(void);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_HELP_H */
|
122
module/Vendor/CURL/src/tool_helpers.c
vendored
Normal file
122
module/Vendor/CURL/src/tool_helpers.c
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_helpers.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/*
|
||||
** Helper functions that are used from more than one source file.
|
||||
*/
|
||||
|
||||
const char *param2text(int res)
|
||||
{
|
||||
ParameterError error = (ParameterError)res;
|
||||
switch(error) {
|
||||
case PARAM_GOT_EXTRA_PARAMETER:
|
||||
return "had unsupported trailing garbage";
|
||||
case PARAM_OPTION_UNKNOWN:
|
||||
return "is unknown";
|
||||
case PARAM_OPTION_AMBIGUOUS:
|
||||
return "is ambiguous";
|
||||
case PARAM_REQUIRES_PARAMETER:
|
||||
return "requires parameter";
|
||||
case PARAM_BAD_USE:
|
||||
return "is badly used here";
|
||||
case PARAM_BAD_NUMERIC:
|
||||
return "expected a proper numerical parameter";
|
||||
case PARAM_NEGATIVE_NUMERIC:
|
||||
return "expected a positive numerical parameter";
|
||||
case PARAM_LIBCURL_DOESNT_SUPPORT:
|
||||
return "the installed libcurl version doesn't support this";
|
||||
case PARAM_LIBCURL_UNSUPPORTED_PROTOCOL:
|
||||
return "a specified protocol is unsupported by libcurl";
|
||||
case PARAM_NO_MEM:
|
||||
return "out of memory";
|
||||
case PARAM_NO_PREFIX:
|
||||
return "the given option can't be reversed with a --no- prefix";
|
||||
case PARAM_NUMBER_TOO_LARGE:
|
||||
return "too large number";
|
||||
case PARAM_NO_NOT_BOOLEAN:
|
||||
return "used '--no-' for option that isn't a boolean";
|
||||
default:
|
||||
return "unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
|
||||
{
|
||||
/* this mirrors the HttpReq enum in tool_sdecls.h */
|
||||
const char *reqname[]= {
|
||||
"", /* unspec */
|
||||
"GET (-G, --get)",
|
||||
"HEAD (-I, --head)",
|
||||
"multipart formpost (-F, --form)",
|
||||
"POST (-d, --data)"
|
||||
};
|
||||
|
||||
if((*store == HTTPREQ_UNSPEC) ||
|
||||
(*store == req)) {
|
||||
*store = req;
|
||||
return 0;
|
||||
}
|
||||
warnf(config->global, "You can only select one HTTP request method! "
|
||||
"You asked for both %s and %s.\n",
|
||||
reqname[req], reqname[*store]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void customrequest_helper(struct OperationConfig *config, HttpReq req,
|
||||
char *method)
|
||||
{
|
||||
/* this mirrors the HttpReq enum in tool_sdecls.h */
|
||||
const char *dflt[]= {
|
||||
"GET",
|
||||
"GET",
|
||||
"HEAD",
|
||||
"POST",
|
||||
"POST"
|
||||
};
|
||||
|
||||
if(!method)
|
||||
;
|
||||
else if(curl_strequal(method, dflt[req])) {
|
||||
notef(config->global, "Unnecessary use of -X or --request, %s is already "
|
||||
"inferred.\n", dflt[req]);
|
||||
}
|
||||
else if(curl_strequal(method, "head")) {
|
||||
warnf(config->global,
|
||||
"Setting custom HTTP method to HEAD with -X/--request may not work "
|
||||
"the way you want. Consider using -I/--head instead.\n");
|
||||
}
|
||||
}
|
34
module/Vendor/CURL/src/tool_helpers.h
vendored
Normal file
34
module/Vendor/CURL/src/tool_helpers.h
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef HEADER_CURL_TOOL_HELPERS_H
|
||||
#define HEADER_CURL_TOOL_HELPERS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
const char *param2text(int res);
|
||||
|
||||
int SetHTTPrequest(struct OperationConfig *config, HttpReq req,
|
||||
HttpReq *store);
|
||||
|
||||
void customrequest_helper(struct OperationConfig *config, HttpReq req,
|
||||
char *method);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_HELPERS_H */
|
132
module/Vendor/CURL/src/tool_homedir.c
vendored
Normal file
132
module/Vendor/CURL/src/tool_homedir.c
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_PWD_H
|
||||
# undef __NO_NET_API /* required for building for AmigaOS */
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
#include "tool_homedir.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static char *GetEnv(const char *variable)
|
||||
{
|
||||
char *dupe, *env;
|
||||
|
||||
env = curl_getenv(variable);
|
||||
if(!env)
|
||||
return NULL;
|
||||
|
||||
dupe = strdup(env);
|
||||
curl_free(env);
|
||||
return dupe;
|
||||
}
|
||||
|
||||
/* return the home directory of the current user as an allocated string */
|
||||
|
||||
/*
|
||||
* The original logic found a home dir to use (by checking a range of
|
||||
* environment variables and last using getpwuid) and returned that for the
|
||||
* parent to use.
|
||||
*
|
||||
* With the XDG_CONFIG_HOME support (added much later than the other), this
|
||||
* variable is treated differently in order to not ruin existing installations
|
||||
* even if this environment variable is set. If this variable is set, and a
|
||||
* file name is set to check, then only if that file name exists in that
|
||||
* directory will it be returned as a "home directory".
|
||||
*
|
||||
* 1. use CURL_HOME if set
|
||||
* 2. use XDG_CONFIG_HOME if set and fname is present
|
||||
* 3. use HOME if set
|
||||
* 4. Non-windows: use getpwuid
|
||||
* 5. Windows: use APPDATA if set
|
||||
* 6. Windows: use "USERPROFILE\Application Data" is set
|
||||
*/
|
||||
|
||||
char *homedir(const char *fname)
|
||||
{
|
||||
char *home;
|
||||
|
||||
home = GetEnv("CURL_HOME");
|
||||
if(home)
|
||||
return home;
|
||||
|
||||
if(fname) {
|
||||
home = GetEnv("XDG_CONFIG_HOME");
|
||||
if(home) {
|
||||
char *c = curl_maprintf("%s" DIR_CHAR "%s", home, fname);
|
||||
if(c) {
|
||||
int fd = open(c, O_RDONLY);
|
||||
curl_free(c);
|
||||
if(fd >= 0) {
|
||||
close(fd);
|
||||
return home;
|
||||
}
|
||||
}
|
||||
free(home);
|
||||
}
|
||||
}
|
||||
|
||||
home = GetEnv("HOME");
|
||||
if(home)
|
||||
return home;
|
||||
|
||||
#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
|
||||
{
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
|
||||
if(pw) {
|
||||
home = pw->pw_dir;
|
||||
if(home && home[0])
|
||||
home = strdup(home);
|
||||
else
|
||||
home = NULL;
|
||||
}
|
||||
}
|
||||
#endif /* PWD-stuff */
|
||||
#ifdef WIN32
|
||||
home = GetEnv("APPDATA");
|
||||
if(!home) {
|
||||
char *env = GetEnv("USERPROFILE");
|
||||
if(env) {
|
||||
char *path = curl_maprintf("%s\\Application Data", env);
|
||||
if(path) {
|
||||
home = strdup(path);
|
||||
curl_free(path);
|
||||
}
|
||||
free(env);
|
||||
}
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
return home;
|
||||
}
|
28
module/Vendor/CURL/src/tool_homedir.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_homedir.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_HOMEDIR_H
|
||||
#define HEADER_CURL_TOOL_HOMEDIR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
char *homedir(const char *fname);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_HOMEDIR_H */
|
29
module/Vendor/CURL/src/tool_hugehelp.c.cvs
vendored
Normal file
29
module/Vendor/CURL/src/tool_hugehelp.c.cvs
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "tool_setup.h"
|
||||
#include "tool_hugehelp.h"
|
||||
|
||||
void hugehelp(void)
|
||||
{
|
||||
puts("This is a silly replacement for the actual file.");
|
||||
}
|
28
module/Vendor/CURL/src/tool_hugehelp.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_hugehelp.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_HUGEHELP_H
|
||||
#define HEADER_CURL_TOOL_HUGEHELP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
void hugehelp(void);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_HUGEHELP_H */
|
104
module/Vendor/CURL/src/tool_libinfo.c
vendored
Normal file
104
module/Vendor/CURL/src/tool_libinfo.c
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2021, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_libinfo.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* global variable definitions, for libcurl run-time info */
|
||||
|
||||
curl_version_info_data *curlinfo = NULL;
|
||||
long built_in_protos = 0;
|
||||
|
||||
/*
|
||||
* libcurl_info_init: retrieves run-time information about libcurl,
|
||||
* setting a global pointer 'curlinfo' to libcurl's run-time info
|
||||
* struct, and a global bit pattern 'built_in_protos' composed of
|
||||
* CURLPROTO_* bits indicating which protocols are actually built
|
||||
* into library being used.
|
||||
*/
|
||||
|
||||
CURLcode get_libcurl_info(void)
|
||||
{
|
||||
static struct proto_name_pattern {
|
||||
const char *proto_name;
|
||||
long proto_pattern;
|
||||
} const possibly_built_in[] = {
|
||||
{ "dict", CURLPROTO_DICT },
|
||||
{ "file", CURLPROTO_FILE },
|
||||
{ "ftp", CURLPROTO_FTP },
|
||||
{ "ftps", CURLPROTO_FTPS },
|
||||
{ "gopher", CURLPROTO_GOPHER },
|
||||
{ "gophers",CURLPROTO_GOPHERS},
|
||||
{ "http", CURLPROTO_HTTP },
|
||||
{ "https", CURLPROTO_HTTPS },
|
||||
{ "imap", CURLPROTO_IMAP },
|
||||
{ "imaps", CURLPROTO_IMAPS },
|
||||
{ "ldap", CURLPROTO_LDAP },
|
||||
{ "ldaps", CURLPROTO_LDAPS },
|
||||
{ "mqtt", CURLPROTO_MQTT },
|
||||
{ "pop3", CURLPROTO_POP3 },
|
||||
{ "pop3s", CURLPROTO_POP3S },
|
||||
{ "rtmp", CURLPROTO_RTMP },
|
||||
{ "rtmps", CURLPROTO_RTMPS },
|
||||
{ "rtsp", CURLPROTO_RTSP },
|
||||
{ "scp", CURLPROTO_SCP },
|
||||
{ "sftp", CURLPROTO_SFTP },
|
||||
{ "smb", CURLPROTO_SMB },
|
||||
{ "smbs", CURLPROTO_SMBS },
|
||||
{ "smtp", CURLPROTO_SMTP },
|
||||
{ "smtps", CURLPROTO_SMTPS },
|
||||
{ "telnet", CURLPROTO_TELNET },
|
||||
{ "tftp", CURLPROTO_TFTP },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char *const *proto;
|
||||
|
||||
/* Pointer to libcurl's run-time version information */
|
||||
curlinfo = curl_version_info(CURLVERSION_NOW);
|
||||
if(!curlinfo)
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
/* Build CURLPROTO_* bit pattern with libcurl's built-in protocols */
|
||||
built_in_protos = 0;
|
||||
if(curlinfo->protocols) {
|
||||
for(proto = curlinfo->protocols; *proto; proto++) {
|
||||
struct proto_name_pattern const *p;
|
||||
for(p = possibly_built_in; p->proto_name; p++) {
|
||||
if(curl_strequal(*proto, p->proto_name)) {
|
||||
built_in_protos |= p->proto_pattern;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
33
module/Vendor/CURL/src/tool_libinfo.h
vendored
Normal file
33
module/Vendor/CURL/src/tool_libinfo.h
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef HEADER_CURL_TOOL_LIBINFO_H
|
||||
#define HEADER_CURL_TOOL_LIBINFO_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
/* global variable declarations, for libcurl run-time info */
|
||||
|
||||
extern curl_version_info_data *curlinfo;
|
||||
extern long built_in_protos;
|
||||
|
||||
CURLcode get_libcurl_info(void);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_LIBINFO_H */
|
295
module/Vendor/CURL/src/tool_main.c
vendored
Normal file
295
module/Vendor/CURL/src/tool_main.c
vendored
Normal file
@ -0,0 +1,295 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <tchar.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_NSS
|
||||
#include <nspr.h>
|
||||
#include <plarenas.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_convert.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_operate.h"
|
||||
#include "tool_panykey.h"
|
||||
#include "tool_vms.h"
|
||||
#include "tool_main.h"
|
||||
#include "tool_libinfo.h"
|
||||
|
||||
/*
|
||||
* This is low-level hard-hacking memory leak tracking and similar. Using
|
||||
* the library level code from this client-side is ugly, but we do this
|
||||
* anyway for convenience.
|
||||
*/
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef __VMS
|
||||
/*
|
||||
* vms_show is a global variable, used in main() as parameter for
|
||||
* function vms_special_exit() to allow proper curl tool exiting.
|
||||
* Its value may be set in other tool_*.c source files thanks to
|
||||
* forward declaration present in tool_vms.h
|
||||
*/
|
||||
int vms_show = 0;
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
/*
|
||||
* There seems to be no way to escape "*" in command-line arguments with MinGW
|
||||
* when command-line argument globbing is enabled under the MSYS shell, so turn
|
||||
* it off.
|
||||
*/
|
||||
int _CRT_glob = 0;
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
/* if we build a static library for unit tests, there is no main() function */
|
||||
#ifndef UNITTESTS
|
||||
|
||||
/*
|
||||
* Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are
|
||||
* open before starting to run. Otherwise, the first three network
|
||||
* sockets opened by curl could be used for input sources, downloaded data
|
||||
* or error logs as they will effectively be stdin, stdout and/or stderr.
|
||||
*/
|
||||
static void main_checkfds(void)
|
||||
{
|
||||
#ifdef HAVE_PIPE
|
||||
int fd[2] = { STDIN_FILENO, STDIN_FILENO };
|
||||
while(fd[0] == STDIN_FILENO ||
|
||||
fd[0] == STDOUT_FILENO ||
|
||||
fd[0] == STDERR_FILENO ||
|
||||
fd[1] == STDIN_FILENO ||
|
||||
fd[1] == STDOUT_FILENO ||
|
||||
fd[1] == STDERR_FILENO)
|
||||
if(pipe(fd) < 0)
|
||||
return; /* Out of handles. This isn't really a big problem now, but
|
||||
will be when we try to create a socket later. */
|
||||
close(fd[0]);
|
||||
close(fd[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CURLDEBUG
|
||||
static void memory_tracking_init(void)
|
||||
{
|
||||
char *env;
|
||||
/* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
|
||||
env = curlx_getenv("CURL_MEMDEBUG");
|
||||
if(env) {
|
||||
/* use the value as file name */
|
||||
char fname[CURL_MT_LOGFNAME_BUFSIZE];
|
||||
if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
|
||||
env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
|
||||
strcpy(fname, env);
|
||||
curl_free(env);
|
||||
curl_dbg_memdebug(fname);
|
||||
/* this weird stuff here is to make curl_free() get called before
|
||||
curl_gdb_memdebug() as otherwise memory tracking will log a free()
|
||||
without an alloc! */
|
||||
}
|
||||
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
|
||||
env = curlx_getenv("CURL_MEMLIMIT");
|
||||
if(env) {
|
||||
char *endptr;
|
||||
long num = strtol(env, &endptr, 10);
|
||||
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
|
||||
curl_dbg_memlimit(num);
|
||||
curl_free(env);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define memory_tracking_init() Curl_nop_stmt
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is the main global constructor for the app. Call this before
|
||||
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
|
||||
* used, or havoc may be the result.
|
||||
*/
|
||||
static CURLcode main_init(struct GlobalConfig *config)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
#if defined(__DJGPP__) || defined(__GO32__)
|
||||
/* stop stat() wasting time */
|
||||
_djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
|
||||
#endif
|
||||
|
||||
/* Initialise the global config */
|
||||
config->showerror = -1; /* Will show errors */
|
||||
config->errors = stderr; /* Default errors to stderr */
|
||||
config->styled_output = TRUE; /* enable detection */
|
||||
config->parallel_max = PARALLEL_DEFAULT;
|
||||
|
||||
/* Allocate the initial operate config */
|
||||
config->first = config->last = malloc(sizeof(struct OperationConfig));
|
||||
if(config->first) {
|
||||
/* Perform the libcurl initialization */
|
||||
result = curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
if(!result) {
|
||||
/* Get information about libcurl */
|
||||
result = get_libcurl_info();
|
||||
|
||||
if(!result) {
|
||||
/* Initialise the config */
|
||||
config_init(config->first);
|
||||
config->first->global = config;
|
||||
}
|
||||
else {
|
||||
errorf(config, "error retrieving curl library information\n");
|
||||
free(config->first);
|
||||
}
|
||||
}
|
||||
else {
|
||||
errorf(config, "error initializing curl library\n");
|
||||
free(config->first);
|
||||
}
|
||||
}
|
||||
else {
|
||||
errorf(config, "error initializing curl\n");
|
||||
result = CURLE_FAILED_INIT;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void free_globalconfig(struct GlobalConfig *config)
|
||||
{
|
||||
Curl_safefree(config->trace_dump);
|
||||
|
||||
if(config->errors_fopened && config->errors)
|
||||
fclose(config->errors);
|
||||
config->errors = NULL;
|
||||
|
||||
if(config->trace_fopened && config->trace_stream)
|
||||
fclose(config->trace_stream);
|
||||
config->trace_stream = NULL;
|
||||
|
||||
Curl_safefree(config->libcurl);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the main global destructor for the app. Call this after
|
||||
* _all_ libcurl usage is done.
|
||||
*/
|
||||
static void main_free(struct GlobalConfig *config)
|
||||
{
|
||||
/* Cleanup the easy handle */
|
||||
/* Main cleanup */
|
||||
curl_global_cleanup();
|
||||
convert_cleanup();
|
||||
metalink_cleanup();
|
||||
#ifdef USE_NSS
|
||||
if(PR_Initialized()) {
|
||||
/* prevent valgrind from reporting still reachable mem from NSRP arenas */
|
||||
PL_ArenaFinish();
|
||||
/* prevent valgrind from reporting possibly lost memory (fd cache, ...) */
|
||||
PR_Cleanup();
|
||||
}
|
||||
#endif
|
||||
free_globalconfig(config);
|
||||
|
||||
/* Free the config structures */
|
||||
config_free(config->last);
|
||||
config->first = NULL;
|
||||
config->last = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
** curl tool main function.
|
||||
*/
|
||||
#ifdef _UNICODE
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
#else
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
struct GlobalConfig global;
|
||||
memset(&global, 0, sizeof(global));
|
||||
|
||||
#ifdef WIN32
|
||||
/* Undocumented diagnostic option to list the full paths of all loaded
|
||||
modules. This is purposely pre-init. */
|
||||
if(argc == 2 && !_tcscmp(argv[1], _T("--dump-module-paths"))) {
|
||||
struct curl_slist *item, *head = GetLoadedModulePaths();
|
||||
for(item = head; item; item = item->next)
|
||||
printf("%s\n", item->data);
|
||||
curl_slist_free_all(head);
|
||||
return head ? 0 : 1;
|
||||
}
|
||||
/* win32_init must be called before other init routines. */
|
||||
result = win32_init();
|
||||
if(result) {
|
||||
fprintf(stderr, "curl: (%d) Windows-specific init failed.\n", result);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
main_checkfds();
|
||||
|
||||
#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
/* Initialize memory tracking */
|
||||
memory_tracking_init();
|
||||
|
||||
/* Initialize the curl library - do not call any libcurl functions before
|
||||
this point */
|
||||
result = main_init(&global);
|
||||
if(!result) {
|
||||
/* Start our curl operation */
|
||||
result = operate(&global, argc, argv);
|
||||
|
||||
/* Perform the main cleanup */
|
||||
main_free(&global);
|
||||
}
|
||||
|
||||
#ifdef __NOVELL_LIBC__
|
||||
if(getenv("_IN_NETWARE_BASH_") == NULL)
|
||||
tool_pressanykey();
|
||||
#endif
|
||||
|
||||
#ifdef __VMS
|
||||
vms_special_exit(result, vms_show);
|
||||
#else
|
||||
return (int)result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* ndef UNITTESTS */
|
46
module/Vendor/CURL/src/tool_main.h
vendored
Normal file
46
module/Vendor/CURL/src/tool_main.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef HEADER_CURL_TOOL_MAIN_H
|
||||
#define HEADER_CURL_TOOL_MAIN_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define DEFAULT_MAXREDIRS 50L
|
||||
|
||||
#define RETRY_SLEEP_DEFAULT 1000L /* ms */
|
||||
#define RETRY_SLEEP_MAX 600000L /* ms == 10 minutes */
|
||||
|
||||
#define MAX_PARALLEL 300 /* conservative */
|
||||
#define PARALLEL_DEFAULT 50
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO fileno(stdin)
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
# define STDOUT_FILENO fileno(stdout)
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
# define STDERR_FILENO fileno(stderr)
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_MAIN_H */
|
937
module/Vendor/CURL/src/tool_metalink.c
vendored
Normal file
937
module/Vendor/CURL/src/tool_metalink.c
vendored
Normal file
@ -0,0 +1,937 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef USE_METALINK
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#undef HAVE_NSS_CONTEXT
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
# include <openssl/md5.h>
|
||||
# include <openssl/sha.h>
|
||||
#elif defined(USE_GNUTLS_NETTLE)
|
||||
# include <nettle/md5.h>
|
||||
# include <nettle/sha.h>
|
||||
# define MD5_CTX struct md5_ctx
|
||||
# define SHA_CTX struct sha1_ctx
|
||||
# define SHA256_CTX struct sha256_ctx
|
||||
#elif defined(USE_GNUTLS)
|
||||
# include <gcrypt.h>
|
||||
# define MD5_CTX gcry_md_hd_t
|
||||
# define SHA_CTX gcry_md_hd_t
|
||||
# define SHA256_CTX gcry_md_hd_t
|
||||
#elif defined(USE_NSS)
|
||||
# include <nss.h>
|
||||
# include <pk11pub.h>
|
||||
# define MD5_CTX void *
|
||||
# define SHA_CTX void *
|
||||
# define SHA256_CTX void *
|
||||
# define HAVE_NSS_CONTEXT
|
||||
static NSSInitContext *nss_context;
|
||||
#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
|
||||
(__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \
|
||||
(defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
|
||||
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 20000))
|
||||
/* For Apple operating systems: CommonCrypto has the functions we need.
|
||||
The library's headers are even backward-compatible with OpenSSL's
|
||||
headers as long as we define COMMON_DIGEST_FOR_OPENSSL first.
|
||||
|
||||
These functions are available on Tiger and later, as well as iOS 2.0
|
||||
and later. If you're building for an older cat, well, sorry. */
|
||||
# define COMMON_DIGEST_FOR_OPENSSL
|
||||
# include <CommonCrypto/CommonDigest.h>
|
||||
#elif defined(USE_WIN32_CRYPTO)
|
||||
/* For Windows: If no other crypto library is provided, we fallback
|
||||
to the hash functions provided within the Microsoft Windows CryptoAPI */
|
||||
# include <wincrypt.h>
|
||||
/* Custom structure in order to store the required provider and hash handle */
|
||||
struct win32_crypto_hash {
|
||||
HCRYPTPROV hCryptProv;
|
||||
HCRYPTHASH hHash;
|
||||
};
|
||||
/* Custom Microsoft AES Cryptographic Provider defines required for MinGW */
|
||||
# ifndef ALG_SID_SHA_256
|
||||
# define ALG_SID_SHA_256 12
|
||||
# endif
|
||||
# ifndef CALG_SHA_256
|
||||
# define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
|
||||
# endif
|
||||
# define MD5_CTX struct win32_crypto_hash
|
||||
# define SHA_CTX struct win32_crypto_hash
|
||||
# define SHA256_CTX struct win32_crypto_hash
|
||||
#else
|
||||
# error "Can't compile METALINK support without a crypto library."
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_paramhlp.h"
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_metalink.h"
|
||||
#include "tool_operate.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* Copied from tool_getparam.c */
|
||||
#define GetStr(str,val) do { \
|
||||
if(*(str)) { \
|
||||
free(*(str)); \
|
||||
*(str) = NULL; \
|
||||
} \
|
||||
if((val)) \
|
||||
*(str) = strdup((val)); \
|
||||
if(!(val)) \
|
||||
return PARAM_NO_MEM; \
|
||||
} while(0)
|
||||
|
||||
#if defined(USE_OPENSSL)
|
||||
/* Functions are already defined */
|
||||
#elif defined(USE_GNUTLS_NETTLE)
|
||||
|
||||
static int MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
md5_init(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void MD5_Update(MD5_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
md5_update(ctx, inputLen, input);
|
||||
}
|
||||
|
||||
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
||||
{
|
||||
md5_digest(ctx, 16, digest);
|
||||
}
|
||||
|
||||
static int SHA1_Init(SHA_CTX *ctx)
|
||||
{
|
||||
sha1_init(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA1_Update(SHA_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
sha1_update(ctx, inputLen, input);
|
||||
}
|
||||
|
||||
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
||||
{
|
||||
sha1_digest(ctx, 20, digest);
|
||||
}
|
||||
|
||||
static int SHA256_Init(SHA256_CTX *ctx)
|
||||
{
|
||||
sha256_init(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA256_Update(SHA256_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
sha256_update(ctx, inputLen, input);
|
||||
}
|
||||
|
||||
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
||||
{
|
||||
sha256_digest(ctx, 32, digest);
|
||||
}
|
||||
|
||||
#elif defined(USE_GNUTLS)
|
||||
|
||||
static int MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
gcry_md_open(ctx, GCRY_MD_MD5, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void MD5_Update(MD5_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
gcry_md_write(*ctx, input, inputLen);
|
||||
}
|
||||
|
||||
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
||||
{
|
||||
memcpy(digest, gcry_md_read(*ctx, 0), 16);
|
||||
gcry_md_close(*ctx);
|
||||
}
|
||||
|
||||
static int SHA1_Init(SHA_CTX *ctx)
|
||||
{
|
||||
gcry_md_open(ctx, GCRY_MD_SHA1, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA1_Update(SHA_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
gcry_md_write(*ctx, input, inputLen);
|
||||
}
|
||||
|
||||
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
||||
{
|
||||
memcpy(digest, gcry_md_read(*ctx, 0), 20);
|
||||
gcry_md_close(*ctx);
|
||||
}
|
||||
|
||||
static int SHA256_Init(SHA256_CTX *ctx)
|
||||
{
|
||||
gcry_md_open(ctx, GCRY_MD_SHA256, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA256_Update(SHA256_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
gcry_md_write(*ctx, input, inputLen);
|
||||
}
|
||||
|
||||
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
||||
{
|
||||
memcpy(digest, gcry_md_read(*ctx, 0), 32);
|
||||
gcry_md_close(*ctx);
|
||||
}
|
||||
|
||||
#elif defined(USE_NSS)
|
||||
|
||||
static int nss_hash_init(void **pctx, SECOidTag hash_alg)
|
||||
{
|
||||
PK11Context *ctx;
|
||||
|
||||
/* we have to initialize NSS if not initialized already */
|
||||
if(!NSS_IsInitialized() && !nss_context) {
|
||||
static NSSInitParameters params;
|
||||
params.length = sizeof(params);
|
||||
nss_context = NSS_InitContext("", "", "", "", ¶ms, NSS_INIT_READONLY
|
||||
| NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN
|
||||
| NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD);
|
||||
}
|
||||
|
||||
ctx = PK11_CreateDigestContext(hash_alg);
|
||||
if(!ctx)
|
||||
return /* failure */ 0;
|
||||
|
||||
if(PK11_DigestBegin(ctx) != SECSuccess) {
|
||||
PK11_DestroyContext(ctx, PR_TRUE);
|
||||
return /* failure */ 0;
|
||||
}
|
||||
|
||||
*pctx = ctx;
|
||||
return /* success */ 1;
|
||||
}
|
||||
|
||||
static void nss_hash_final(void **pctx, unsigned char *out, unsigned int len)
|
||||
{
|
||||
PK11Context *ctx = *pctx;
|
||||
unsigned int outlen;
|
||||
PK11_DigestFinal(ctx, out, &outlen, len);
|
||||
PK11_DestroyContext(ctx, PR_TRUE);
|
||||
}
|
||||
|
||||
static int MD5_Init(MD5_CTX *pctx)
|
||||
{
|
||||
return nss_hash_init(pctx, SEC_OID_MD5);
|
||||
}
|
||||
|
||||
static void MD5_Update(MD5_CTX *pctx,
|
||||
const unsigned char *input,
|
||||
unsigned int input_len)
|
||||
{
|
||||
PK11_DigestOp(*pctx, input, input_len);
|
||||
}
|
||||
|
||||
static void MD5_Final(unsigned char digest[16], MD5_CTX *pctx)
|
||||
{
|
||||
nss_hash_final(pctx, digest, 16);
|
||||
}
|
||||
|
||||
static int SHA1_Init(SHA_CTX *pctx)
|
||||
{
|
||||
return nss_hash_init(pctx, SEC_OID_SHA1);
|
||||
}
|
||||
|
||||
static void SHA1_Update(SHA_CTX *pctx,
|
||||
const unsigned char *input,
|
||||
unsigned int input_len)
|
||||
{
|
||||
PK11_DigestOp(*pctx, input, input_len);
|
||||
}
|
||||
|
||||
static void SHA1_Final(unsigned char digest[20], SHA_CTX *pctx)
|
||||
{
|
||||
nss_hash_final(pctx, digest, 20);
|
||||
}
|
||||
|
||||
static int SHA256_Init(SHA256_CTX *pctx)
|
||||
{
|
||||
return nss_hash_init(pctx, SEC_OID_SHA256);
|
||||
}
|
||||
|
||||
static void SHA256_Update(SHA256_CTX *pctx,
|
||||
const unsigned char *input,
|
||||
unsigned int input_len)
|
||||
{
|
||||
PK11_DigestOp(*pctx, input, input_len);
|
||||
}
|
||||
|
||||
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *pctx)
|
||||
{
|
||||
nss_hash_final(pctx, digest, 32);
|
||||
}
|
||||
|
||||
#elif defined(USE_WIN32_CRYPTO)
|
||||
|
||||
static void win32_crypto_final(struct win32_crypto_hash *ctx,
|
||||
unsigned char *digest,
|
||||
unsigned int digestLen)
|
||||
{
|
||||
unsigned long length;
|
||||
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
||||
if(length == digestLen)
|
||||
CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
|
||||
if(ctx->hHash)
|
||||
CryptDestroyHash(ctx->hHash);
|
||||
if(ctx->hCryptProv)
|
||||
CryptReleaseContext(ctx->hCryptProv, 0);
|
||||
}
|
||||
|
||||
static int MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
||||
CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void MD5_Update(MD5_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
||||
}
|
||||
|
||||
static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
|
||||
{
|
||||
win32_crypto_final(ctx, digest, 16);
|
||||
}
|
||||
|
||||
static int SHA1_Init(SHA_CTX *ctx)
|
||||
{
|
||||
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
||||
CryptCreateHash(ctx->hCryptProv, CALG_SHA1, 0, 0, &ctx->hHash);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA1_Update(SHA_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
||||
}
|
||||
|
||||
static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
|
||||
{
|
||||
win32_crypto_final(ctx, digest, 20);
|
||||
}
|
||||
|
||||
static int SHA256_Init(SHA256_CTX *ctx)
|
||||
{
|
||||
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_AES,
|
||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
|
||||
CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void SHA256_Update(SHA256_CTX *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned int inputLen)
|
||||
{
|
||||
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
||||
}
|
||||
|
||||
static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
|
||||
{
|
||||
win32_crypto_final(ctx, digest, 32);
|
||||
}
|
||||
|
||||
#endif /* CRYPTO LIBS */
|
||||
|
||||
const struct digest_params MD5_DIGEST_PARAMS[] = {
|
||||
{
|
||||
CURLX_FUNCTION_CAST(digest_init_func, MD5_Init),
|
||||
CURLX_FUNCTION_CAST(digest_update_func, MD5_Update),
|
||||
CURLX_FUNCTION_CAST(digest_final_func, MD5_Final),
|
||||
sizeof(MD5_CTX),
|
||||
16
|
||||
}
|
||||
};
|
||||
|
||||
const struct digest_params SHA1_DIGEST_PARAMS[] = {
|
||||
{
|
||||
CURLX_FUNCTION_CAST(digest_init_func, SHA1_Init),
|
||||
CURLX_FUNCTION_CAST(digest_update_func, SHA1_Update),
|
||||
CURLX_FUNCTION_CAST(digest_final_func, SHA1_Final),
|
||||
sizeof(SHA_CTX),
|
||||
20
|
||||
}
|
||||
};
|
||||
|
||||
const struct digest_params SHA256_DIGEST_PARAMS[] = {
|
||||
{
|
||||
CURLX_FUNCTION_CAST(digest_init_func, SHA256_Init),
|
||||
CURLX_FUNCTION_CAST(digest_update_func, SHA256_Update),
|
||||
CURLX_FUNCTION_CAST(digest_final_func, SHA256_Final),
|
||||
sizeof(SHA256_CTX),
|
||||
32
|
||||
}
|
||||
};
|
||||
|
||||
static const struct metalink_digest_def SHA256_DIGEST_DEF[] = {
|
||||
{"sha-256", SHA256_DIGEST_PARAMS}
|
||||
};
|
||||
|
||||
static const struct metalink_digest_def SHA1_DIGEST_DEF[] = {
|
||||
{"sha-1", SHA1_DIGEST_PARAMS}
|
||||
};
|
||||
|
||||
static const struct metalink_digest_def MD5_DIGEST_DEF[] = {
|
||||
{"md5", MD5_DIGEST_PARAMS}
|
||||
};
|
||||
|
||||
/*
|
||||
* The alias of supported hash functions in the order by preference
|
||||
* (basically stronger hash comes first). We included "sha-256" and
|
||||
* "sha256". The former is the name defined in the IANA registry named
|
||||
* "Hash Function Textual Names". The latter is widely (and
|
||||
* historically) used in Metalink version 3.
|
||||
*/
|
||||
static const struct metalink_digest_alias digest_aliases[] = {
|
||||
{"sha-256", SHA256_DIGEST_DEF},
|
||||
{"sha256", SHA256_DIGEST_DEF},
|
||||
{"sha-1", SHA1_DIGEST_DEF},
|
||||
{"sha1", SHA1_DIGEST_DEF},
|
||||
{"md5", MD5_DIGEST_DEF},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static struct digest_context *digest_init(const struct digest_params *dparams)
|
||||
{
|
||||
struct digest_context *ctxt = malloc(sizeof(*ctxt));
|
||||
if(!ctxt)
|
||||
return ctxt;
|
||||
|
||||
ctxt->digest_hashctx = malloc(dparams->digest_ctxtsize);
|
||||
|
||||
if(!ctxt->digest_hashctx) {
|
||||
free(ctxt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctxt->digest_hash = dparams;
|
||||
|
||||
if(dparams->digest_init(ctxt->digest_hashctx) != 1) {
|
||||
free(ctxt->digest_hashctx);
|
||||
free(ctxt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctxt;
|
||||
}
|
||||
|
||||
static int digest_update(struct digest_context *context,
|
||||
const unsigned char *data,
|
||||
unsigned int len)
|
||||
{
|
||||
(*context->digest_hash->digest_update)(context->digest_hashctx, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int digest_final(struct digest_context *context, unsigned char *result)
|
||||
{
|
||||
if(result)
|
||||
(*context->digest_hash->digest_final)(result, context->digest_hashctx);
|
||||
|
||||
free(context->digest_hashctx);
|
||||
free(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned char hex_to_uint(const char *s)
|
||||
{
|
||||
char buf[3];
|
||||
unsigned long val;
|
||||
buf[0] = s[0];
|
||||
buf[1] = s[1];
|
||||
buf[2] = 0;
|
||||
val = strtoul(buf, NULL, 16);
|
||||
return (unsigned char)(val&0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check checksum of file denoted by filename. The expected hash value
|
||||
* is given in hex_hash which is hex-encoded string.
|
||||
*
|
||||
* This function returns 1 if it succeeds or one of the following
|
||||
* integers:
|
||||
*
|
||||
* 0:
|
||||
* Checksum didn't match.
|
||||
* -1:
|
||||
* Could not open file; or could not read data from file.
|
||||
* -2:
|
||||
* Hash algorithm not available.
|
||||
*/
|
||||
static int check_hash(const char *filename,
|
||||
const struct metalink_digest_def *digest_def,
|
||||
const unsigned char *digest, FILE *error)
|
||||
{
|
||||
unsigned char *result;
|
||||
struct digest_context *dctx;
|
||||
int check_ok, flags, fd;
|
||||
|
||||
flags = O_RDONLY;
|
||||
#ifdef O_BINARY
|
||||
/* O_BINARY is required in order to avoid binary EOF in text mode */
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
|
||||
fd = open(filename, flags);
|
||||
if(fd == -1) {
|
||||
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
||||
digest_def->hash_name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
dctx = digest_init(digest_def->dparams);
|
||||
if(!dctx) {
|
||||
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
||||
digest_def->hash_name, "failed to initialize hash algorithm");
|
||||
close(fd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
result = malloc(digest_def->dparams->digest_resultlen);
|
||||
if(!result) {
|
||||
close(fd);
|
||||
digest_final(dctx, NULL);
|
||||
return -1;
|
||||
}
|
||||
while(1) {
|
||||
unsigned char buf[4096];
|
||||
ssize_t len = read(fd, buf, sizeof(buf));
|
||||
if(len == 0) {
|
||||
break;
|
||||
}
|
||||
else if(len == -1) {
|
||||
fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
|
||||
digest_def->hash_name, strerror(errno));
|
||||
digest_final(dctx, result);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
digest_update(dctx, buf, (unsigned int)len);
|
||||
}
|
||||
digest_final(dctx, result);
|
||||
check_ok = memcmp(result, digest,
|
||||
digest_def->dparams->digest_resultlen) == 0;
|
||||
/* sha*sum style verdict output */
|
||||
if(check_ok)
|
||||
fprintf(error, "Metalink: validating (%s) [%s] OK\n", filename,
|
||||
digest_def->hash_name);
|
||||
else
|
||||
fprintf(error, "Metalink: validating (%s) [%s] FAILED (digest mismatch)\n",
|
||||
filename, digest_def->hash_name);
|
||||
|
||||
free(result);
|
||||
close(fd);
|
||||
return check_ok;
|
||||
}
|
||||
|
||||
int metalink_check_hash(struct GlobalConfig *config,
|
||||
struct metalinkfile *mlfile,
|
||||
const char *filename)
|
||||
{
|
||||
int rv;
|
||||
fprintf(config->errors, "Metalink: validating (%s)...\n", filename);
|
||||
if(mlfile->checksum == NULL) {
|
||||
fprintf(config->errors,
|
||||
"Metalink: validating (%s) FAILED (digest missing)\n", filename);
|
||||
return -2;
|
||||
}
|
||||
rv = check_hash(filename, mlfile->checksum->digest_def,
|
||||
mlfile->checksum->digest, config->errors);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static struct metalink_checksum *
|
||||
checksum_from_hex_digest(const struct metalink_digest_def *digest_def,
|
||||
const char *hex_digest)
|
||||
{
|
||||
struct metalink_checksum *chksum;
|
||||
unsigned char *digest;
|
||||
size_t i;
|
||||
size_t len = strlen(hex_digest);
|
||||
digest = malloc(len/2);
|
||||
if(!digest)
|
||||
return 0;
|
||||
|
||||
for(i = 0; i < len; i += 2) {
|
||||
digest[i/2] = hex_to_uint(hex_digest + i);
|
||||
}
|
||||
chksum = malloc(sizeof(struct metalink_checksum));
|
||||
if(chksum) {
|
||||
chksum->digest_def = digest_def;
|
||||
chksum->digest = digest;
|
||||
}
|
||||
else
|
||||
free(digest);
|
||||
return chksum;
|
||||
}
|
||||
|
||||
static struct metalink_resource *new_metalink_resource(const char *url)
|
||||
{
|
||||
struct metalink_resource *res = malloc(sizeof(struct metalink_resource));
|
||||
if(res) {
|
||||
res->next = NULL;
|
||||
res->url = strdup(url);
|
||||
if(!res->url) {
|
||||
free(res);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Returns nonzero if hex_digest is properly formatted; that is each
|
||||
letter is in [0-9A-Za-z] and the length of the string equals to the
|
||||
result length of digest * 2. */
|
||||
static int check_hex_digest(const char *hex_digest,
|
||||
const struct metalink_digest_def *digest_def)
|
||||
{
|
||||
size_t i;
|
||||
for(i = 0; hex_digest[i]; ++i) {
|
||||
char c = hex_digest[i];
|
||||
if(!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') ||
|
||||
('A' <= c && c <= 'Z'))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return digest_def->dparams->digest_resultlen * 2 == i;
|
||||
}
|
||||
|
||||
static struct metalinkfile *new_metalinkfile(metalink_file_t *fileinfo)
|
||||
{
|
||||
struct metalinkfile *f = malloc(sizeof(struct metalinkfile));
|
||||
if(!f)
|
||||
return NULL;
|
||||
|
||||
f->next = NULL;
|
||||
f->filename = strdup(fileinfo->name);
|
||||
if(!f->filename) {
|
||||
free(f);
|
||||
return NULL;
|
||||
}
|
||||
f->checksum = NULL;
|
||||
f->resource = NULL;
|
||||
if(fileinfo->checksums) {
|
||||
const struct metalink_digest_alias *digest_alias;
|
||||
for(digest_alias = digest_aliases; digest_alias->alias_name;
|
||||
++digest_alias) {
|
||||
metalink_checksum_t **p;
|
||||
for(p = fileinfo->checksums; *p; ++p) {
|
||||
if(curl_strequal(digest_alias->alias_name, (*p)->type) &&
|
||||
check_hex_digest((*p)->hash, digest_alias->digest_def)) {
|
||||
f->checksum =
|
||||
checksum_from_hex_digest(digest_alias->digest_def,
|
||||
(*p)->hash);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(f->checksum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fileinfo->resources) {
|
||||
metalink_resource_t **p;
|
||||
struct metalink_resource root, *tail;
|
||||
root.next = NULL;
|
||||
tail = &root;
|
||||
for(p = fileinfo->resources; *p; ++p) {
|
||||
struct metalink_resource *res;
|
||||
/* Filter by type if it is non-NULL. In Metalink v3, type
|
||||
includes the type of the resource. In curl, we are only
|
||||
interested in HTTP, HTTPS and FTP. In addition to them,
|
||||
Metalink v3 file may contain bittorrent type URL, which
|
||||
points to the BitTorrent metainfo file. We ignore it here.
|
||||
In Metalink v4, type was deprecated and all
|
||||
fileinfo->resources point to the target file. BitTorrent
|
||||
metainfo file URL may be appeared in fileinfo->metaurls.
|
||||
*/
|
||||
if((*p)->type == NULL ||
|
||||
curl_strequal((*p)->type, "http") ||
|
||||
curl_strequal((*p)->type, "https") ||
|
||||
curl_strequal((*p)->type, "ftp") ||
|
||||
curl_strequal((*p)->type, "ftps")) {
|
||||
res = new_metalink_resource((*p)->url);
|
||||
if(res) {
|
||||
tail->next = res;
|
||||
tail = res;
|
||||
}
|
||||
else {
|
||||
tail = root.next;
|
||||
|
||||
/* clean up the linked list */
|
||||
while(tail) {
|
||||
res = tail->next;
|
||||
free(tail->url);
|
||||
free(tail);
|
||||
tail = res;
|
||||
}
|
||||
free(f->filename);
|
||||
free(f);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
f->resource = root.next;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
int parse_metalink(struct OperationConfig *config, struct OutStruct *outs,
|
||||
const char *metalink_url)
|
||||
{
|
||||
metalink_error_t r;
|
||||
metalink_t* metalink;
|
||||
metalink_file_t **files;
|
||||
bool warnings = FALSE;
|
||||
|
||||
/* metlaink_parse_final deletes outs->metalink_parser */
|
||||
r = metalink_parse_final(outs->metalink_parser, NULL, 0, &metalink);
|
||||
outs->metalink_parser = NULL;
|
||||
if(r != 0) {
|
||||
return -1;
|
||||
}
|
||||
if(metalink->files == NULL) {
|
||||
fprintf(config->global->errors, "Metalink: parsing (%s) WARNING "
|
||||
"(missing or invalid file name)\n",
|
||||
metalink_url);
|
||||
metalink_delete(metalink);
|
||||
return -1;
|
||||
}
|
||||
for(files = metalink->files; *files; ++files) {
|
||||
struct getout *url;
|
||||
/* Skip an entry which has no resource. */
|
||||
if(!(*files)->resources) {
|
||||
fprintf(config->global->errors, "Metalink: parsing (%s) WARNING "
|
||||
"(missing or invalid resource)\n",
|
||||
metalink_url);
|
||||
continue;
|
||||
}
|
||||
if(config->url_get ||
|
||||
((config->url_get = config->url_list) != NULL)) {
|
||||
/* there's a node here, if it already is filled-in continue to
|
||||
find an "empty" node */
|
||||
while(config->url_get && (config->url_get->flags & GETOUT_URL))
|
||||
config->url_get = config->url_get->next;
|
||||
}
|
||||
|
||||
/* now there might or might not be an available node to fill in! */
|
||||
|
||||
if(config->url_get)
|
||||
/* existing node */
|
||||
url = config->url_get;
|
||||
else
|
||||
/* there was no free node, create one! */
|
||||
url = new_getout(config);
|
||||
|
||||
if(url) {
|
||||
struct metalinkfile *mlfile = new_metalinkfile(*files);
|
||||
if(!mlfile)
|
||||
break;
|
||||
|
||||
if(!mlfile->checksum) {
|
||||
warnings = TRUE;
|
||||
fprintf(config->global->errors,
|
||||
"Metalink: parsing (%s) WARNING (digest missing)\n",
|
||||
metalink_url);
|
||||
}
|
||||
/* Set name as url */
|
||||
GetStr(&url->url, mlfile->filename);
|
||||
|
||||
/* set flag metalink here */
|
||||
url->flags |= GETOUT_URL | GETOUT_METALINK;
|
||||
|
||||
if(config->metalinkfile_list) {
|
||||
config->metalinkfile_last->next = mlfile;
|
||||
config->metalinkfile_last = mlfile;
|
||||
}
|
||||
else {
|
||||
config->metalinkfile_list = config->metalinkfile_last = mlfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
metalink_delete(metalink);
|
||||
return (warnings) ? -2 : 0;
|
||||
}
|
||||
|
||||
size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
|
||||
void *userdata)
|
||||
{
|
||||
struct per_transfer *per = userdata;
|
||||
struct OutStruct *outs = &per->outs;
|
||||
struct OperationConfig *config = per->config;
|
||||
int rv;
|
||||
|
||||
/*
|
||||
* Once that libcurl has called back tool_write_cb() the returned value
|
||||
* is checked against the amount that was intended to be written, if
|
||||
* it does not match then it fails with CURLE_WRITE_ERROR. So at this
|
||||
* point returning a value different from sz*nmemb indicates failure.
|
||||
*/
|
||||
const size_t failure = (sz && nmemb) ? 0 : 1;
|
||||
|
||||
if(!config)
|
||||
return failure;
|
||||
|
||||
rv = metalink_parse_update(outs->metalink_parser, buffer, sz * nmemb);
|
||||
if(rv == 0)
|
||||
return sz * nmemb;
|
||||
else {
|
||||
fprintf(config->global->errors, "Metalink: parsing FAILED\n");
|
||||
return failure;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns nonzero if content_type includes mediatype.
|
||||
*/
|
||||
static int check_content_type(const char *content_type, const char *media_type)
|
||||
{
|
||||
const char *ptr = content_type;
|
||||
size_t media_type_len = strlen(media_type);
|
||||
for(; *ptr && (*ptr == ' ' || *ptr == '\t'); ++ptr);
|
||||
if(!*ptr) {
|
||||
return 0;
|
||||
}
|
||||
return curl_strnequal(ptr, media_type, media_type_len) &&
|
||||
(*(ptr + media_type_len) == '\0' || *(ptr + media_type_len) == ' ' ||
|
||||
*(ptr + media_type_len) == '\t' || *(ptr + media_type_len) == ';');
|
||||
}
|
||||
|
||||
int check_metalink_content_type(const char *content_type)
|
||||
{
|
||||
return check_content_type(content_type, "application/metalink+xml");
|
||||
}
|
||||
|
||||
int count_next_metalink_resource(struct metalinkfile *mlfile)
|
||||
{
|
||||
int count = 0;
|
||||
struct metalink_resource *res;
|
||||
for(res = mlfile->resource; res; res = res->next, ++count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void delete_metalink_checksum(struct metalink_checksum *chksum)
|
||||
{
|
||||
if(!chksum)
|
||||
return;
|
||||
Curl_safefree(chksum->digest);
|
||||
Curl_safefree(chksum);
|
||||
}
|
||||
|
||||
static void delete_metalink_resource(struct metalink_resource *res)
|
||||
{
|
||||
if(res == NULL) {
|
||||
return;
|
||||
}
|
||||
Curl_safefree(res->url);
|
||||
Curl_safefree(res);
|
||||
}
|
||||
|
||||
void delete_metalinkfile(struct metalinkfile *mlfile)
|
||||
{
|
||||
struct metalink_resource *res;
|
||||
if(mlfile == NULL) {
|
||||
return;
|
||||
}
|
||||
Curl_safefree(mlfile->filename);
|
||||
delete_metalink_checksum(mlfile->checksum);
|
||||
for(res = mlfile->resource; res;) {
|
||||
struct metalink_resource *next;
|
||||
next = res->next;
|
||||
delete_metalink_resource(res);
|
||||
res = next;
|
||||
}
|
||||
Curl_safefree(mlfile);
|
||||
}
|
||||
|
||||
void clean_metalink(struct OperationConfig *config)
|
||||
{
|
||||
if(config) {
|
||||
while(config->metalinkfile_list) {
|
||||
struct metalinkfile *mlfile = config->metalinkfile_list;
|
||||
config->metalinkfile_list = config->metalinkfile_list->next;
|
||||
delete_metalinkfile(mlfile);
|
||||
}
|
||||
config->metalinkfile_last = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void metalink_cleanup(void)
|
||||
{
|
||||
#ifdef HAVE_NSS_CONTEXT
|
||||
if(nss_context) {
|
||||
NSS_ShutdownContext(nss_context);
|
||||
nss_context = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* USE_METALINK */
|
165
module/Vendor/CURL/src/tool_metalink.h
vendored
Normal file
165
module/Vendor/CURL/src/tool_metalink.h
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
#ifndef HEADER_CURL_TOOL_METALINK_H
|
||||
#define HEADER_CURL_TOOL_METALINK_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_sdecls.h"
|
||||
|
||||
struct GlobalConfig;
|
||||
struct OperationConfig;
|
||||
|
||||
/* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */
|
||||
typedef int (*digest_init_func)(void *context);
|
||||
|
||||
typedef void (*digest_update_func)(void *context,
|
||||
const unsigned char *data,
|
||||
unsigned int len);
|
||||
typedef void (*digest_final_func)(unsigned char *result, void *context);
|
||||
|
||||
struct digest_params {
|
||||
digest_init_func digest_init; /* Initialize context procedure */
|
||||
digest_update_func digest_update; /* Update context with data */
|
||||
digest_final_func digest_final; /* Get final result procedure */
|
||||
unsigned int digest_ctxtsize; /* Context structure size */
|
||||
unsigned int digest_resultlen; /* Result length (bytes) */
|
||||
};
|
||||
|
||||
struct digest_context {
|
||||
const struct digest_params *digest_hash; /* Hash function definition */
|
||||
void *digest_hashctx; /* Hash function context */
|
||||
};
|
||||
|
||||
struct metalink_digest_def {
|
||||
const char *hash_name;
|
||||
const struct digest_params *dparams;
|
||||
};
|
||||
|
||||
struct metalink_digest_alias {
|
||||
const char *alias_name;
|
||||
const struct metalink_digest_def *digest_def;
|
||||
};
|
||||
|
||||
struct metalink_checksum {
|
||||
const struct metalink_digest_def *digest_def;
|
||||
/* raw digest value, not ascii hex digest */
|
||||
unsigned char *digest;
|
||||
};
|
||||
|
||||
struct metalink_resource {
|
||||
struct metalink_resource *next;
|
||||
char *url;
|
||||
};
|
||||
|
||||
struct metalinkfile {
|
||||
struct metalinkfile *next;
|
||||
char *filename;
|
||||
struct metalink_checksum *checksum;
|
||||
struct metalink_resource *resource;
|
||||
};
|
||||
|
||||
#ifdef USE_METALINK
|
||||
|
||||
/*
|
||||
* curl requires libmetalink 0.1.0 or newer
|
||||
*/
|
||||
#define CURL_REQ_LIBMETALINK_MAJOR 0
|
||||
#define CURL_REQ_LIBMETALINK_MINOR 1
|
||||
#define CURL_REQ_LIBMETALINK_PATCH 0
|
||||
|
||||
#define CURL_REQ_LIBMETALINK_VERS ((CURL_REQ_LIBMETALINK_MAJOR * 10000) + \
|
||||
(CURL_REQ_LIBMETALINK_MINOR * 100) + \
|
||||
CURL_REQ_LIBMETALINK_PATCH)
|
||||
|
||||
extern const struct digest_params MD5_DIGEST_PARAMS[1];
|
||||
extern const struct digest_params SHA1_DIGEST_PARAMS[1];
|
||||
extern const struct digest_params SHA256_DIGEST_PARAMS[1];
|
||||
|
||||
#include <metalink/metalink.h>
|
||||
|
||||
/*
|
||||
* Counts the resource in the metalinkfile.
|
||||
*/
|
||||
int count_next_metalink_resource(struct metalinkfile *mlfile);
|
||||
|
||||
void delete_metalinkfile(struct metalinkfile *mlfile);
|
||||
void clean_metalink(struct OperationConfig *config);
|
||||
|
||||
/*
|
||||
* Performs final parse operation and extracts information from
|
||||
* Metalink and creates metalinkfile structs.
|
||||
*
|
||||
* This function returns 0 if it succeeds without warnings, or one of
|
||||
* the following negative error codes:
|
||||
*
|
||||
* -1: Parsing failed; or no file is found
|
||||
* -2: Parsing succeeded with some warnings.
|
||||
*/
|
||||
int parse_metalink(struct OperationConfig *config, struct OutStruct *outs,
|
||||
const char *metalink_url);
|
||||
|
||||
/*
|
||||
* Callback function for CURLOPT_WRITEFUNCTION
|
||||
*/
|
||||
size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb,
|
||||
void *userdata);
|
||||
|
||||
/*
|
||||
* Returns nonzero if content_type includes "application/metalink+xml"
|
||||
* media-type. The check is done in case-insensitive manner.
|
||||
*/
|
||||
int check_metalink_content_type(const char *content_type);
|
||||
|
||||
/*
|
||||
* Check checksum of file denoted by filename.
|
||||
*
|
||||
* This function returns 1 if the checksum matches or one of the
|
||||
* following integers:
|
||||
*
|
||||
* 0:
|
||||
* Checksum didn't match.
|
||||
* -1:
|
||||
* Could not open file; or could not read data from file.
|
||||
* -2:
|
||||
* No checksum in Metalink supported, hash algorithm not available, or
|
||||
* Metalink does not contain checksum.
|
||||
*/
|
||||
int metalink_check_hash(struct GlobalConfig *config,
|
||||
struct metalinkfile *mlfile,
|
||||
const char *filename);
|
||||
|
||||
/*
|
||||
* Release resources allocated at global scope.
|
||||
*/
|
||||
void metalink_cleanup(void);
|
||||
|
||||
#else /* USE_METALINK */
|
||||
|
||||
#define count_next_metalink_resource(x) 0
|
||||
#define delete_metalinkfile(x) (void)x
|
||||
#define clean_metalink(x) (void)x
|
||||
|
||||
/* metalink_cleanup() takes no arguments */
|
||||
#define metalink_cleanup() Curl_nop_stmt
|
||||
|
||||
#endif /* USE_METALINK */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_METALINK_H */
|
139
module/Vendor/CURL/src/tool_msgs.c
vendored
Normal file
139
module/Vendor/CURL/src/tool_msgs.c
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define WARN_PREFIX "Warning: "
|
||||
#define NOTE_PREFIX "Note: "
|
||||
#define ERROR_PREFIX "curl: "
|
||||
|
||||
static void voutf(struct GlobalConfig *config,
|
||||
const char *prefix,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
{
|
||||
size_t width = (79 - strlen(prefix));
|
||||
if(!config->mute) {
|
||||
size_t len;
|
||||
char *ptr;
|
||||
char *print_buffer;
|
||||
|
||||
print_buffer = curlx_mvaprintf(fmt, ap);
|
||||
if(!print_buffer)
|
||||
return;
|
||||
len = strlen(print_buffer);
|
||||
|
||||
ptr = print_buffer;
|
||||
while(len > 0) {
|
||||
fputs(prefix, config->errors);
|
||||
|
||||
if(len > width) {
|
||||
size_t cut = width-1;
|
||||
|
||||
while(!ISSPACE(ptr[cut]) && cut) {
|
||||
cut--;
|
||||
}
|
||||
if(0 == cut)
|
||||
/* not a single cutting position was found, just cut it at the
|
||||
max text width then! */
|
||||
cut = width-1;
|
||||
|
||||
(void)fwrite(ptr, cut + 1, 1, config->errors);
|
||||
fputs("\n", config->errors);
|
||||
ptr += cut + 1; /* skip the space too */
|
||||
len -= cut + 1;
|
||||
}
|
||||
else {
|
||||
fputs(ptr, config->errors);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
curl_free(print_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Emit 'note' formatted message on configured 'errors' stream, if verbose was
|
||||
* selected.
|
||||
*/
|
||||
void notef(struct GlobalConfig *config, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if(config->tracetype)
|
||||
voutf(config, NOTE_PREFIX, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* Emit warning formatted message on configured 'errors' stream unless
|
||||
* mute (--silent) was selected.
|
||||
*/
|
||||
|
||||
void warnf(struct GlobalConfig *config, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
voutf(config, WARN_PREFIX, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
/*
|
||||
* Emit help formatted message on given stream. This is for errors with or
|
||||
* related to command line arguments.
|
||||
*/
|
||||
void helpf(FILE *errors, const char *fmt, ...)
|
||||
{
|
||||
if(fmt) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
fputs("curl: ", errors); /* prefix it */
|
||||
vfprintf(errors, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
fprintf(errors, "curl: try 'curl --help' "
|
||||
#ifdef USE_MANUAL
|
||||
"or 'curl --manual' "
|
||||
#endif
|
||||
"for more information\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Emit error message on error stream if not muted. When errors are not tied
|
||||
* to command line arguments, use helpf() for such errors.
|
||||
*/
|
||||
void errorf(struct GlobalConfig *config, const char *fmt, ...)
|
||||
{
|
||||
if(!config->mute) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
voutf(config, ERROR_PREFIX, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
31
module/Vendor/CURL/src/tool_msgs.h
vendored
Normal file
31
module/Vendor/CURL/src/tool_msgs.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef HEADER_CURL_TOOL_MSGS_H
|
||||
#define HEADER_CURL_TOOL_MSGS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
void warnf(struct GlobalConfig *config, const char *fmt, ...);
|
||||
void notef(struct GlobalConfig *config, const char *fmt, ...);
|
||||
void helpf(FILE *errors, const char *fmt, ...);
|
||||
void errorf(struct GlobalConfig *config, const char *fmt, ...);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_MSGS_H */
|
2639
module/Vendor/CURL/src/tool_operate.c
vendored
Normal file
2639
module/Vendor/CURL/src/tool_operate.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
82
module/Vendor/CURL/src/tool_operate.h
vendored
Normal file
82
module/Vendor/CURL/src/tool_operate.h
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef HEADER_CURL_TOOL_OPERATE_H
|
||||
#define HEADER_CURL_TOOL_OPERATE_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_cb_hdr.h"
|
||||
#include "tool_cb_prg.h"
|
||||
#include "tool_sdecls.h"
|
||||
|
||||
struct per_transfer {
|
||||
/* double linked */
|
||||
struct per_transfer *next;
|
||||
struct per_transfer *prev;
|
||||
struct OperationConfig *config; /* for this transfer */
|
||||
CURL *curl;
|
||||
long retry_numretries;
|
||||
long retry_sleep_default;
|
||||
long retry_sleep;
|
||||
struct timeval retrystart;
|
||||
bool metalink; /* nonzero for metalink download. */
|
||||
bool metalink_next_res;
|
||||
struct metalinkfile *mlfile;
|
||||
struct metalink_resource *mlres;
|
||||
char *this_url;
|
||||
unsigned int urlnum; /* the index of the given URL */
|
||||
char *outfile;
|
||||
bool infdopen; /* TRUE if infd needs closing */
|
||||
int infd;
|
||||
bool noprogress;
|
||||
struct ProgressData progressbar;
|
||||
struct OutStruct outs;
|
||||
struct OutStruct heads;
|
||||
struct OutStruct etag_save;
|
||||
struct InStruct input;
|
||||
struct HdrCbData hdrcbdata;
|
||||
long num_headers;
|
||||
bool was_last_header_empty;
|
||||
char errorbuffer[CURL_ERROR_SIZE];
|
||||
|
||||
bool added; /* set TRUE when added to the multi handle */
|
||||
time_t startat; /* when doing parallel transfers, this is a retry transfer
|
||||
that has been set to sleep until this time before it
|
||||
should get started (again) */
|
||||
|
||||
/* for parallel progress bar */
|
||||
curl_off_t dltotal;
|
||||
curl_off_t dlnow;
|
||||
curl_off_t ultotal;
|
||||
curl_off_t ulnow;
|
||||
bool dltotal_added; /* if the total has been added from this */
|
||||
bool ultotal_added;
|
||||
|
||||
/* NULL or malloced */
|
||||
char *separator_err;
|
||||
char *separator;
|
||||
char *uploadfile;
|
||||
};
|
||||
|
||||
CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[]);
|
||||
|
||||
extern struct per_transfer *transfers; /* first node */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_OPERATE_H */
|
197
module/Vendor/CURL/src/tool_operhlp.c
vendored
Normal file
197
module/Vendor/CURL/src/tool_operhlp.c
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_convert.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_operhlp.h"
|
||||
#include "tool_metalink.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void clean_getout(struct OperationConfig *config)
|
||||
{
|
||||
if(config) {
|
||||
struct getout *next;
|
||||
struct getout *node = config->url_list;
|
||||
|
||||
while(node) {
|
||||
next = node->next;
|
||||
Curl_safefree(node->url);
|
||||
Curl_safefree(node->outfile);
|
||||
Curl_safefree(node->infile);
|
||||
Curl_safefree(node);
|
||||
node = next;
|
||||
}
|
||||
config->url_list = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool output_expected(const char *url, const char *uploadfile)
|
||||
{
|
||||
if(!uploadfile)
|
||||
return TRUE; /* download */
|
||||
if(checkprefix("http://", url) || checkprefix("https://", url))
|
||||
return TRUE; /* HTTP(S) upload */
|
||||
|
||||
return FALSE; /* non-HTTP upload, probably no output should be expected */
|
||||
}
|
||||
|
||||
bool stdin_upload(const char *uploadfile)
|
||||
{
|
||||
return (!strcmp(uploadfile, "-") ||
|
||||
!strcmp(uploadfile, ".")) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the file name to the URL if it doesn't already have one.
|
||||
* url will be freed before return if the returned pointer is different
|
||||
*/
|
||||
char *add_file_name_to_url(char *url, const char *filename)
|
||||
{
|
||||
/* If no file name part is given in the URL, we add this file name */
|
||||
char *ptr = strstr(url, "://");
|
||||
CURL *curl = curl_easy_init(); /* for url escaping */
|
||||
if(!curl)
|
||||
return NULL; /* error! */
|
||||
if(ptr)
|
||||
ptr += 3;
|
||||
else
|
||||
ptr = url;
|
||||
ptr = strrchr(ptr, '/');
|
||||
if(!ptr || !*++ptr) {
|
||||
/* The URL has no file name part, add the local file name. In order
|
||||
to be able to do so, we have to create a new URL in another
|
||||
buffer.*/
|
||||
|
||||
/* We only want the part of the local path that is on the right
|
||||
side of the rightmost slash and backslash. */
|
||||
const char *filep = strrchr(filename, '/');
|
||||
char *file2 = strrchr(filep?filep:filename, '\\');
|
||||
char *encfile;
|
||||
|
||||
if(file2)
|
||||
filep = file2 + 1;
|
||||
else if(filep)
|
||||
filep++;
|
||||
else
|
||||
filep = filename;
|
||||
|
||||
/* URL encode the file name */
|
||||
encfile = curl_easy_escape(curl, filep, 0 /* use strlen */);
|
||||
if(encfile) {
|
||||
char *urlbuffer;
|
||||
if(ptr)
|
||||
/* there is a trailing slash on the URL */
|
||||
urlbuffer = aprintf("%s%s", url, encfile);
|
||||
else
|
||||
/* there is no trailing slash on the URL */
|
||||
urlbuffer = aprintf("%s/%s", url, encfile);
|
||||
|
||||
curl_free(encfile);
|
||||
|
||||
if(!urlbuffer) {
|
||||
url = NULL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
Curl_safefree(url);
|
||||
url = urlbuffer; /* use our new URL instead! */
|
||||
}
|
||||
}
|
||||
end:
|
||||
curl_easy_cleanup(curl);
|
||||
return url;
|
||||
}
|
||||
|
||||
/* Extracts the name portion of the URL.
|
||||
* Returns a pointer to a heap-allocated string or NULL if
|
||||
* no name part, at location indicated by first argument.
|
||||
*/
|
||||
CURLcode get_url_file_name(char **filename, const char *url)
|
||||
{
|
||||
const char *pc, *pc2;
|
||||
|
||||
*filename = NULL;
|
||||
|
||||
/* Find and get the remote file name */
|
||||
pc = strstr(url, "://");
|
||||
if(pc)
|
||||
pc += 3;
|
||||
else
|
||||
pc = url;
|
||||
|
||||
pc2 = strrchr(pc, '\\');
|
||||
pc = strrchr(pc, '/');
|
||||
if(pc2 && (!pc || pc < pc2))
|
||||
pc = pc2;
|
||||
|
||||
if(pc)
|
||||
/* duplicate the string beyond the slash */
|
||||
pc++;
|
||||
else
|
||||
/* no slash => empty string */
|
||||
pc = "";
|
||||
|
||||
*filename = strdup(pc);
|
||||
if(!*filename)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
{
|
||||
char *sanitized;
|
||||
SANITIZEcode sc = sanitize_file_name(&sanitized, *filename, 0);
|
||||
Curl_safefree(*filename);
|
||||
if(sc)
|
||||
return CURLE_URL_MALFORMAT;
|
||||
*filename = sanitized;
|
||||
}
|
||||
#endif /* MSDOS || WIN32 */
|
||||
|
||||
/* in case we built debug enabled, we allow an environment variable
|
||||
* named CURL_TESTDIR to prefix the given file name to put it into a
|
||||
* specific directory
|
||||
*/
|
||||
#ifdef DEBUGBUILD
|
||||
{
|
||||
char *tdir = curlx_getenv("CURL_TESTDIR");
|
||||
if(tdir) {
|
||||
char buffer[512]; /* suitably large */
|
||||
msnprintf(buffer, sizeof(buffer), "%s/%s", tdir, *filename);
|
||||
Curl_safefree(*filename);
|
||||
*filename = strdup(buffer); /* clone the buffer */
|
||||
curl_free(tdir);
|
||||
if(!*filename)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
38
module/Vendor/CURL/src/tool_operhlp.h
vendored
Normal file
38
module/Vendor/CURL/src/tool_operhlp.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef HEADER_CURL_TOOL_OPERHLP_H
|
||||
#define HEADER_CURL_TOOL_OPERHLP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
struct OperationConfig;
|
||||
|
||||
void clean_getout(struct OperationConfig *config);
|
||||
|
||||
bool output_expected(const char *url, const char *uploadfile);
|
||||
|
||||
bool stdin_upload(const char *uploadfile);
|
||||
|
||||
char *add_file_name_to_url(char *url, const char *filename);
|
||||
|
||||
CURLcode get_url_file_name(char **filename, const char *url);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_OPERHLP_H */
|
45
module/Vendor/CURL/src/tool_panykey.c
vendored
Normal file
45
module/Vendor/CURL/src/tool_panykey.c
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(NETWARE)
|
||||
|
||||
#ifdef NETWARE
|
||||
# ifdef __NOVELL_LIBC__
|
||||
# include <screen.h>
|
||||
# else
|
||||
# include <nwconio.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "tool_panykey.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void tool_pressanykey(void)
|
||||
{
|
||||
#if defined(NETWARE)
|
||||
pressanykey();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* NETWARE */
|
32
module/Vendor/CURL/src/tool_panykey.h
vendored
Normal file
32
module/Vendor/CURL/src/tool_panykey.h
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef HEADER_CURL_TOOL_PANYKEY_H
|
||||
#define HEADER_CURL_TOOL_PANYKEY_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#if defined(NETWARE)
|
||||
void tool_pressanykey(void);
|
||||
#else
|
||||
#define tool_pressanykey() Curl_nop_stmt
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_PANYKEY_H */
|
613
module/Vendor/CURL/src/tool_paramhlp.c
vendored
Normal file
613
module/Vendor/CURL/src/tool_paramhlp.c
vendored
Normal file
@ -0,0 +1,613 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "strcase.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_getpass.h"
|
||||
#include "tool_homedir.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_paramhlp.h"
|
||||
#include "tool_version.h"
|
||||
#include "dynbuf.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
struct getout *new_getout(struct OperationConfig *config)
|
||||
{
|
||||
static int outnum = 0;
|
||||
struct getout *node = calloc(1, sizeof(struct getout));
|
||||
struct getout *last = config->url_last;
|
||||
if(node) {
|
||||
/* append this new node last in the list */
|
||||
if(last)
|
||||
last->next = node;
|
||||
else
|
||||
config->url_list = node; /* first node */
|
||||
|
||||
/* move the last pointer */
|
||||
config->url_last = node;
|
||||
|
||||
node->flags = config->default_node_flags;
|
||||
node->num = outnum++;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
#define MAX_FILE2STRING (256*1024*1024) /* big enough ? */
|
||||
|
||||
ParameterError file2string(char **bufp, FILE *file)
|
||||
{
|
||||
struct curlx_dynbuf dyn;
|
||||
curlx_dyn_init(&dyn, MAX_FILE2STRING);
|
||||
if(file) {
|
||||
char buffer[256];
|
||||
|
||||
while(fgets(buffer, sizeof(buffer), file)) {
|
||||
char *ptr = strchr(buffer, '\r');
|
||||
if(ptr)
|
||||
*ptr = '\0';
|
||||
ptr = strchr(buffer, '\n');
|
||||
if(ptr)
|
||||
*ptr = '\0';
|
||||
if(curlx_dyn_add(&dyn, buffer))
|
||||
return PARAM_NO_MEM;
|
||||
}
|
||||
}
|
||||
*bufp = curlx_dyn_ptr(&dyn);
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
#define MAX_FILE2MEMORY (1024*1024*1024) /* big enough ? */
|
||||
|
||||
ParameterError file2memory(char **bufp, size_t *size, FILE *file)
|
||||
{
|
||||
if(file) {
|
||||
size_t nread;
|
||||
struct curlx_dynbuf dyn;
|
||||
curlx_dyn_init(&dyn, MAX_FILE2MEMORY);
|
||||
do {
|
||||
char buffer[4096];
|
||||
nread = fread(buffer, 1, sizeof(buffer), file);
|
||||
if(nread)
|
||||
if(curlx_dyn_addn(&dyn, buffer, nread))
|
||||
return PARAM_NO_MEM;
|
||||
} while(nread);
|
||||
*size = curlx_dyn_len(&dyn);
|
||||
*bufp = curlx_dyn_ptr(&dyn);
|
||||
}
|
||||
else {
|
||||
*size = 0;
|
||||
*bufp = NULL;
|
||||
}
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
void cleanarg(char *str)
|
||||
{
|
||||
#ifdef HAVE_WRITABLE_ARGV
|
||||
/* now that GetStr has copied the contents of nextarg, wipe the next
|
||||
* argument out so that the username:password isn't displayed in the
|
||||
* system process list */
|
||||
if(str) {
|
||||
size_t len = strlen(str);
|
||||
memset(str, ' ', len);
|
||||
}
|
||||
#else
|
||||
(void)str;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and write the long in the given address. Return PARAM_OK
|
||||
* on success, otherwise a parameter specific error enum.
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
static ParameterError getnum(long *val, const char *str, int base)
|
||||
{
|
||||
if(str) {
|
||||
char *endptr = NULL;
|
||||
long num;
|
||||
errno = 0;
|
||||
num = strtol(str, &endptr, base);
|
||||
if(errno == ERANGE)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
if((endptr != str) && (endptr == str + strlen(str))) {
|
||||
*val = num;
|
||||
return PARAM_OK; /* Ok */
|
||||
}
|
||||
}
|
||||
return PARAM_BAD_NUMERIC; /* badness */
|
||||
}
|
||||
|
||||
ParameterError str2num(long *val, const char *str)
|
||||
{
|
||||
return getnum(val, str, 10);
|
||||
}
|
||||
|
||||
ParameterError oct2nummax(long *val, const char *str, long max)
|
||||
{
|
||||
ParameterError result = getnum(val, str, 8);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
else if(*val > max)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
else if(*val < 0)
|
||||
return PARAM_NEGATIVE_NUMERIC;
|
||||
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and write the long in the given address. Return PARAM_OK
|
||||
* on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
ParameterError str2unum(long *val, const char *str)
|
||||
{
|
||||
ParameterError result = getnum(val, str, 10);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
if(*val < 0)
|
||||
return PARAM_NEGATIVE_NUMERIC;
|
||||
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and write the long in the given address if it is below the
|
||||
* maximum allowed value. Return PARAM_OK on success, otherwise a parameter
|
||||
* error enum. ONLY ACCEPTS POSITIVE NUMBERS!
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
ParameterError str2unummax(long *val, const char *str, long max)
|
||||
{
|
||||
ParameterError result = str2unum(val, str);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
if(*val > max)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse the string and write the double in the given address. Return PARAM_OK
|
||||
* on success, otherwise a parameter specific error enum.
|
||||
*
|
||||
* The 'max' argument is the maximum value allowed, as the numbers are often
|
||||
* multiplied when later used.
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
static ParameterError str2double(double *val, const char *str, long max)
|
||||
{
|
||||
if(str) {
|
||||
char *endptr;
|
||||
double num;
|
||||
errno = 0;
|
||||
num = strtod(str, &endptr);
|
||||
if(errno == ERANGE)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
if(num > max) {
|
||||
/* too large */
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
}
|
||||
if((endptr != str) && (endptr == str + strlen(str))) {
|
||||
*val = num;
|
||||
return PARAM_OK; /* Ok */
|
||||
}
|
||||
}
|
||||
return PARAM_BAD_NUMERIC; /* badness */
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and write the double in the given address. Return PARAM_OK
|
||||
* on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
|
||||
*
|
||||
* The 'max' argument is the maximum value allowed, as the numbers are often
|
||||
* multiplied when later used.
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
ParameterError str2udouble(double *valp, const char *str, long max)
|
||||
{
|
||||
double value;
|
||||
ParameterError result = str2double(&value, str, max);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
if(value < 0)
|
||||
return PARAM_NEGATIVE_NUMERIC;
|
||||
|
||||
*valp = value;
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and modify the long in the given address. Return
|
||||
* non-zero on failure, zero on success.
|
||||
*
|
||||
* The string is a list of protocols
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
long proto2num(struct OperationConfig *config, long *val, const char *str)
|
||||
{
|
||||
char *buffer;
|
||||
const char *sep = ",";
|
||||
char *token;
|
||||
|
||||
static struct sprotos {
|
||||
const char *name;
|
||||
long bit;
|
||||
} const protos[] = {
|
||||
{ "all", CURLPROTO_ALL },
|
||||
{ "http", CURLPROTO_HTTP },
|
||||
{ "https", CURLPROTO_HTTPS },
|
||||
{ "ftp", CURLPROTO_FTP },
|
||||
{ "ftps", CURLPROTO_FTPS },
|
||||
{ "scp", CURLPROTO_SCP },
|
||||
{ "sftp", CURLPROTO_SFTP },
|
||||
{ "telnet", CURLPROTO_TELNET },
|
||||
{ "ldap", CURLPROTO_LDAP },
|
||||
{ "ldaps", CURLPROTO_LDAPS },
|
||||
{ "dict", CURLPROTO_DICT },
|
||||
{ "file", CURLPROTO_FILE },
|
||||
{ "tftp", CURLPROTO_TFTP },
|
||||
{ "imap", CURLPROTO_IMAP },
|
||||
{ "imaps", CURLPROTO_IMAPS },
|
||||
{ "pop3", CURLPROTO_POP3 },
|
||||
{ "pop3s", CURLPROTO_POP3S },
|
||||
{ "smtp", CURLPROTO_SMTP },
|
||||
{ "smtps", CURLPROTO_SMTPS },
|
||||
{ "rtsp", CURLPROTO_RTSP },
|
||||
{ "gopher", CURLPROTO_GOPHER },
|
||||
{ "smb", CURLPROTO_SMB },
|
||||
{ "smbs", CURLPROTO_SMBS },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
if(!str)
|
||||
return 1;
|
||||
|
||||
buffer = strdup(str); /* because strtok corrupts it */
|
||||
if(!buffer)
|
||||
return 1;
|
||||
|
||||
/* Allow strtok() here since this isn't used threaded */
|
||||
/* !checksrc! disable BANNEDFUNC 2 */
|
||||
for(token = strtok(buffer, sep);
|
||||
token;
|
||||
token = strtok(NULL, sep)) {
|
||||
enum e_action { allow, deny, set } action = allow;
|
||||
|
||||
struct sprotos const *pp;
|
||||
|
||||
/* Process token modifiers */
|
||||
while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
|
||||
switch (*token++) {
|
||||
case '=':
|
||||
action = set;
|
||||
break;
|
||||
case '-':
|
||||
action = deny;
|
||||
break;
|
||||
case '+':
|
||||
action = allow;
|
||||
break;
|
||||
default: /* Includes case of terminating NULL */
|
||||
Curl_safefree(buffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(pp = protos; pp->name; pp++) {
|
||||
if(curl_strequal(token, pp->name)) {
|
||||
switch(action) {
|
||||
case deny:
|
||||
*val &= ~(pp->bit);
|
||||
break;
|
||||
case allow:
|
||||
*val |= pp->bit;
|
||||
break;
|
||||
case set:
|
||||
*val = pp->bit;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(pp->name)) { /* unknown protocol */
|
||||
/* If they have specified only this protocol, we say treat it as
|
||||
if no protocols are allowed */
|
||||
if(action == set)
|
||||
*val = 0;
|
||||
warnf(config->global, "unrecognized protocol '%s'\n", token);
|
||||
}
|
||||
}
|
||||
Curl_safefree(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given string is a protocol supported by libcurl
|
||||
*
|
||||
* @param str the protocol name
|
||||
* @return PARAM_OK protocol supported
|
||||
* @return PARAM_LIBCURL_UNSUPPORTED_PROTOCOL protocol not supported
|
||||
* @return PARAM_REQUIRES_PARAMETER missing parameter
|
||||
*/
|
||||
int check_protocol(const char *str)
|
||||
{
|
||||
const char * const *pp;
|
||||
const curl_version_info_data *curlinfo = curl_version_info(CURLVERSION_NOW);
|
||||
if(!str)
|
||||
return PARAM_REQUIRES_PARAMETER;
|
||||
for(pp = curlinfo->protocols; *pp; pp++) {
|
||||
if(curl_strequal(*pp, str))
|
||||
return PARAM_OK;
|
||||
}
|
||||
return PARAM_LIBCURL_UNSUPPORTED_PROTOCOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given string looking for an offset (which may be a
|
||||
* larger-than-integer value). The offset CANNOT be negative!
|
||||
*
|
||||
* @param val the offset to populate
|
||||
* @param str the buffer containing the offset
|
||||
* @return PARAM_OK if successful, a parameter specific error enum if failure.
|
||||
*/
|
||||
ParameterError str2offset(curl_off_t *val, const char *str)
|
||||
{
|
||||
char *endptr;
|
||||
if(str[0] == '-')
|
||||
/* offsets aren't negative, this indicates weird input */
|
||||
return PARAM_NEGATIVE_NUMERIC;
|
||||
|
||||
#if(SIZEOF_CURL_OFF_T > SIZEOF_LONG)
|
||||
{
|
||||
CURLofft offt = curlx_strtoofft(str, &endptr, 0, val);
|
||||
if(CURL_OFFT_FLOW == offt)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
else if(CURL_OFFT_INVAL == offt)
|
||||
return PARAM_BAD_NUMERIC;
|
||||
}
|
||||
#else
|
||||
errno = 0;
|
||||
*val = strtol(str, &endptr, 0);
|
||||
if((*val == LONG_MIN || *val == LONG_MAX) && errno == ERANGE)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
#endif
|
||||
if((endptr != str) && (endptr == str + strlen(str)))
|
||||
return PARAM_OK;
|
||||
|
||||
return PARAM_BAD_NUMERIC;
|
||||
}
|
||||
|
||||
#define MAX_USERPWDLENGTH (100*1024)
|
||||
static CURLcode checkpasswd(const char *kind, /* for what purpose */
|
||||
const size_t i, /* operation index */
|
||||
const bool last, /* TRUE if last operation */
|
||||
char **userpwd) /* pointer to allocated string */
|
||||
{
|
||||
char *psep;
|
||||
char *osep;
|
||||
|
||||
if(!*userpwd)
|
||||
return CURLE_OK;
|
||||
|
||||
/* Attempt to find the password separator */
|
||||
psep = strchr(*userpwd, ':');
|
||||
|
||||
/* Attempt to find the options separator */
|
||||
osep = strchr(*userpwd, ';');
|
||||
|
||||
if(!psep && **userpwd != ';') {
|
||||
/* no password present, prompt for one */
|
||||
char passwd[2048] = "";
|
||||
char prompt[256];
|
||||
struct curlx_dynbuf dyn;
|
||||
|
||||
curlx_dyn_init(&dyn, MAX_USERPWDLENGTH);
|
||||
if(osep)
|
||||
*osep = '\0';
|
||||
|
||||
/* build a nice-looking prompt */
|
||||
if(!i && last)
|
||||
curlx_msnprintf(prompt, sizeof(prompt),
|
||||
"Enter %s password for user '%s':",
|
||||
kind, *userpwd);
|
||||
else
|
||||
curlx_msnprintf(prompt, sizeof(prompt),
|
||||
"Enter %s password for user '%s' on URL #%zu:",
|
||||
kind, *userpwd, i + 1);
|
||||
|
||||
/* get password */
|
||||
getpass_r(prompt, passwd, sizeof(passwd));
|
||||
if(osep)
|
||||
*osep = ';';
|
||||
|
||||
if(curlx_dyn_addf(&dyn, "%s:%s", *userpwd, passwd))
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
/* return the new string */
|
||||
free(*userpwd);
|
||||
*userpwd = curlx_dyn_ptr(&dyn);
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
ParameterError add2list(struct curl_slist **list, const char *ptr)
|
||||
{
|
||||
struct curl_slist *newlist = curl_slist_append(*list, ptr);
|
||||
if(newlist)
|
||||
*list = newlist;
|
||||
else
|
||||
return PARAM_NO_MEM;
|
||||
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
int ftpfilemethod(struct OperationConfig *config, const char *str)
|
||||
{
|
||||
if(curl_strequal("singlecwd", str))
|
||||
return CURLFTPMETHOD_SINGLECWD;
|
||||
if(curl_strequal("nocwd", str))
|
||||
return CURLFTPMETHOD_NOCWD;
|
||||
if(curl_strequal("multicwd", str))
|
||||
return CURLFTPMETHOD_MULTICWD;
|
||||
|
||||
warnf(config->global, "unrecognized ftp file method '%s', using default\n",
|
||||
str);
|
||||
|
||||
return CURLFTPMETHOD_MULTICWD;
|
||||
}
|
||||
|
||||
int ftpcccmethod(struct OperationConfig *config, const char *str)
|
||||
{
|
||||
if(curl_strequal("passive", str))
|
||||
return CURLFTPSSL_CCC_PASSIVE;
|
||||
if(curl_strequal("active", str))
|
||||
return CURLFTPSSL_CCC_ACTIVE;
|
||||
|
||||
warnf(config->global, "unrecognized ftp CCC method '%s', using default\n",
|
||||
str);
|
||||
|
||||
return CURLFTPSSL_CCC_PASSIVE;
|
||||
}
|
||||
|
||||
long delegation(struct OperationConfig *config, const char *str)
|
||||
{
|
||||
if(curl_strequal("none", str))
|
||||
return CURLGSSAPI_DELEGATION_NONE;
|
||||
if(curl_strequal("policy", str))
|
||||
return CURLGSSAPI_DELEGATION_POLICY_FLAG;
|
||||
if(curl_strequal("always", str))
|
||||
return CURLGSSAPI_DELEGATION_FLAG;
|
||||
|
||||
warnf(config->global, "unrecognized delegation method '%s', using none\n",
|
||||
str);
|
||||
|
||||
return CURLGSSAPI_DELEGATION_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* my_useragent: returns allocated string with default user agent
|
||||
*/
|
||||
static char *my_useragent(void)
|
||||
{
|
||||
return strdup(CURL_NAME "/" CURL_VERSION);
|
||||
}
|
||||
|
||||
CURLcode get_args(struct OperationConfig *config, const size_t i)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
bool last = (config->next ? FALSE : TRUE);
|
||||
|
||||
/* Check we have a password for the given host user */
|
||||
if(config->userpwd && !config->oauth_bearer) {
|
||||
result = checkpasswd("host", i, last, &config->userpwd);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Check we have a password for the given proxy user */
|
||||
if(config->proxyuserpwd) {
|
||||
result = checkpasswd("proxy", i, last, &config->proxyuserpwd);
|
||||
if(result)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Check we have a user agent */
|
||||
if(!config->useragent) {
|
||||
config->useragent = my_useragent();
|
||||
if(!config->useragent) {
|
||||
errorf(config->global, "out of memory\n");
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and modify ssl_version in the val argument. Return PARAM_OK
|
||||
* on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
|
||||
*
|
||||
* Since this function gets called with the 'nextarg' pointer from within the
|
||||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
ParameterError str2tls_max(long *val, const char *str)
|
||||
{
|
||||
static struct s_tls_max {
|
||||
const char *tls_max_str;
|
||||
long tls_max;
|
||||
} const tls_max_array[] = {
|
||||
{ "default", CURL_SSLVERSION_MAX_DEFAULT },
|
||||
{ "1.0", CURL_SSLVERSION_MAX_TLSv1_0 },
|
||||
{ "1.1", CURL_SSLVERSION_MAX_TLSv1_1 },
|
||||
{ "1.2", CURL_SSLVERSION_MAX_TLSv1_2 },
|
||||
{ "1.3", CURL_SSLVERSION_MAX_TLSv1_3 }
|
||||
};
|
||||
size_t i = 0;
|
||||
if(!str)
|
||||
return PARAM_REQUIRES_PARAMETER;
|
||||
for(i = 0; i < sizeof(tls_max_array)/sizeof(tls_max_array[0]); i++) {
|
||||
if(!strcmp(str, tls_max_array[i].tls_max_str)) {
|
||||
*val = tls_max_array[i].tls_max;
|
||||
return PARAM_OK;
|
||||
}
|
||||
}
|
||||
return PARAM_BAD_USE;
|
||||
}
|
58
module/Vendor/CURL/src/tool_paramhlp.h
vendored
Normal file
58
module/Vendor/CURL/src/tool_paramhlp.h
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef HEADER_CURL_TOOL_PARAMHLP_H
|
||||
#define HEADER_CURL_TOOL_PARAMHLP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
struct getout *new_getout(struct OperationConfig *config);
|
||||
|
||||
ParameterError file2string(char **bufp, FILE *file);
|
||||
|
||||
ParameterError file2memory(char **bufp, size_t *size, FILE *file);
|
||||
|
||||
void cleanarg(char *str);
|
||||
|
||||
ParameterError str2num(long *val, const char *str);
|
||||
ParameterError str2unum(long *val, const char *str);
|
||||
ParameterError oct2nummax(long *val, const char *str, long max);
|
||||
ParameterError str2unummax(long *val, const char *str, long max);
|
||||
ParameterError str2udouble(double *val, const char *str, long max);
|
||||
|
||||
long proto2num(struct OperationConfig *config, long *val, const char *str);
|
||||
|
||||
int check_protocol(const char *str);
|
||||
|
||||
ParameterError str2offset(curl_off_t *val, const char *str);
|
||||
|
||||
CURLcode get_args(struct OperationConfig *config, const size_t i);
|
||||
|
||||
ParameterError add2list(struct curl_slist **list, const char *ptr);
|
||||
|
||||
int ftpfilemethod(struct OperationConfig *config, const char *str);
|
||||
|
||||
int ftpcccmethod(struct OperationConfig *config, const char *str);
|
||||
|
||||
long delegation(struct OperationConfig *config, const char *str);
|
||||
|
||||
ParameterError str2tls_max(long *val, const char *str);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_PARAMHLP_H */
|
368
module/Vendor/CURL/src/tool_parsecfg.c
vendored
Normal file
368
module/Vendor/CURL/src/tool_parsecfg.c
vendored
Normal file
@ -0,0 +1,368 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_getparam.h"
|
||||
#include "tool_helpers.h"
|
||||
#include "tool_homedir.h"
|
||||
#include "tool_msgs.h"
|
||||
#include "tool_parsecfg.h"
|
||||
#include "dynbuf.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* only acknowledge colon or equals as separators if the option was not
|
||||
specified with an initial dash! */
|
||||
#define ISSEP(x,dash) (!dash && (((x) == '=') || ((x) == ':')))
|
||||
|
||||
static const char *unslashquote(const char *line, char *param);
|
||||
|
||||
#define MAX_CONFIG_LINE_LENGTH (100*1024)
|
||||
static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error);
|
||||
|
||||
#ifdef WIN32
|
||||
static FILE *execpath(const char *filename)
|
||||
{
|
||||
char filebuffer[512];
|
||||
/* Get the filename of our executable. GetModuleFileName is already declared
|
||||
* via inclusions done in setup header file. We assume that we are using
|
||||
* the ASCII version here.
|
||||
*/
|
||||
unsigned long len = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer));
|
||||
if(len > 0 && len < sizeof(filebuffer)) {
|
||||
/* We got a valid filename - get the directory part */
|
||||
char *lastdirchar = strrchr(filebuffer, '\\');
|
||||
if(lastdirchar) {
|
||||
size_t remaining;
|
||||
*lastdirchar = 0;
|
||||
/* If we have enough space, build the RC filename */
|
||||
remaining = sizeof(filebuffer) - strlen(filebuffer);
|
||||
if(strlen(filename) < remaining - 1) {
|
||||
msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename);
|
||||
return fopen(filebuffer, FOPEN_READTEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* return 0 on everything-is-fine, and non-zero otherwise */
|
||||
int parseconfig(const char *filename, struct GlobalConfig *global)
|
||||
{
|
||||
FILE *file = NULL;
|
||||
bool usedarg = FALSE;
|
||||
int rc = 0;
|
||||
struct OperationConfig *operation = global->last;
|
||||
char *pathalloc = NULL;
|
||||
|
||||
if(!filename || !*filename) {
|
||||
/* NULL or no file name attempts to load .curlrc from the homedir! */
|
||||
|
||||
char *home = homedir(".curlrc");
|
||||
#ifndef WIN32
|
||||
if(home) {
|
||||
pathalloc = curl_maprintf("%s%s.curlrc", home, DIR_CHAR);
|
||||
if(!pathalloc) {
|
||||
free(home);
|
||||
return 1; /* out of memory */
|
||||
}
|
||||
filename = pathalloc;
|
||||
}
|
||||
#else /* Windows */
|
||||
if(home) {
|
||||
int i = 0;
|
||||
char prefix = '.';
|
||||
do {
|
||||
/* if it was allocated in a previous attempt */
|
||||
curl_free(pathalloc);
|
||||
/* check for .curlrc then _curlrc in the home dir */
|
||||
pathalloc = curl_maprintf("%s%s%ccurlrc", home, DIR_CHAR, prefix);
|
||||
if(!pathalloc) {
|
||||
free(home);
|
||||
return 1; /* out of memory */
|
||||
}
|
||||
|
||||
/* Check if the file exists - if not, try _curlrc */
|
||||
file = fopen(pathalloc, FOPEN_READTEXT);
|
||||
if(file) {
|
||||
filename = pathalloc;
|
||||
break;
|
||||
}
|
||||
prefix = '_';
|
||||
} while(++i < 2);
|
||||
}
|
||||
if(!filename) {
|
||||
/* check for .curlrc then _curlrc in the dir of the executable */
|
||||
file = execpath(".curlrc");
|
||||
if(!file)
|
||||
file = execpath("_curlrc");
|
||||
}
|
||||
#endif
|
||||
|
||||
Curl_safefree(home); /* we've used it, now free it */
|
||||
}
|
||||
|
||||
if(!file && filename) { /* no need to fopen() again */
|
||||
if(strcmp(filename, "-"))
|
||||
file = fopen(filename, FOPEN_READTEXT);
|
||||
else
|
||||
file = stdin;
|
||||
}
|
||||
|
||||
if(file) {
|
||||
char *line;
|
||||
char *option;
|
||||
char *param;
|
||||
int lineno = 0;
|
||||
bool dashed_option;
|
||||
struct curlx_dynbuf buf;
|
||||
bool fileerror;
|
||||
curlx_dyn_init(&buf, MAX_CONFIG_LINE_LENGTH);
|
||||
|
||||
while(my_get_line(file, &buf, &fileerror)) {
|
||||
int res;
|
||||
bool alloced_param = FALSE;
|
||||
lineno++;
|
||||
line = curlx_dyn_ptr(&buf);
|
||||
if(!line) {
|
||||
rc = 1; /* out of memory */
|
||||
break;
|
||||
}
|
||||
|
||||
/* line with # in the first non-blank column is a comment! */
|
||||
while(*line && ISSPACE(*line))
|
||||
line++;
|
||||
|
||||
switch(*line) {
|
||||
case '#':
|
||||
case '/':
|
||||
case '\r':
|
||||
case '\n':
|
||||
case '*':
|
||||
case '\0':
|
||||
curlx_dyn_reset(&buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* the option keywords starts here */
|
||||
option = line;
|
||||
|
||||
/* the option starts with a dash? */
|
||||
dashed_option = option[0]=='-'?TRUE:FALSE;
|
||||
|
||||
while(*line && !ISSPACE(*line) && !ISSEP(*line, dashed_option))
|
||||
line++;
|
||||
/* ... and has ended here */
|
||||
|
||||
if(*line)
|
||||
*line++ = '\0'; /* null-terminate, we have a local copy of the data */
|
||||
|
||||
#ifdef DEBUG_CONFIG
|
||||
fprintf(stderr, "GOT: %s\n", option);
|
||||
#endif
|
||||
|
||||
/* pass spaces and separator(s) */
|
||||
while(*line && (ISSPACE(*line) || ISSEP(*line, dashed_option)))
|
||||
line++;
|
||||
|
||||
/* the parameter starts here (unless quoted) */
|
||||
if(*line == '\"') {
|
||||
/* quoted parameter, do the quote dance */
|
||||
line++;
|
||||
param = malloc(strlen(line) + 1); /* parameter */
|
||||
if(!param) {
|
||||
/* out of memory */
|
||||
rc = 1;
|
||||
break;
|
||||
}
|
||||
alloced_param = TRUE;
|
||||
(void)unslashquote(line, param);
|
||||
}
|
||||
else {
|
||||
param = line; /* parameter starts here */
|
||||
while(*line && !ISSPACE(*line))
|
||||
line++;
|
||||
|
||||
if(*line) {
|
||||
*line = '\0'; /* null-terminate */
|
||||
|
||||
/* to detect mistakes better, see if there's data following */
|
||||
line++;
|
||||
/* pass all spaces */
|
||||
while(*line && ISSPACE(*line))
|
||||
line++;
|
||||
|
||||
switch(*line) {
|
||||
case '\0':
|
||||
case '\r':
|
||||
case '\n':
|
||||
case '#': /* comment */
|
||||
break;
|
||||
default:
|
||||
warnf(operation->global, "%s:%d: warning: '%s' uses unquoted "
|
||||
"whitespace in the line that may cause side-effects!\n",
|
||||
filename, lineno, option);
|
||||
}
|
||||
}
|
||||
if(!*param)
|
||||
/* do this so getparameter can check for required parameters.
|
||||
Otherwise it always thinks there's a parameter. */
|
||||
param = NULL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONFIG
|
||||
fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
|
||||
#endif
|
||||
res = getparameter(option, param, &usedarg, global, operation);
|
||||
operation = global->last;
|
||||
|
||||
if(!res && param && *param && !usedarg)
|
||||
/* we passed in a parameter that wasn't used! */
|
||||
res = PARAM_GOT_EXTRA_PARAMETER;
|
||||
|
||||
if(res == PARAM_NEXT_OPERATION) {
|
||||
if(operation->url_list && operation->url_list->url) {
|
||||
/* Allocate the next config */
|
||||
operation->next = malloc(sizeof(struct OperationConfig));
|
||||
if(operation->next) {
|
||||
/* Initialise the newly created config */
|
||||
config_init(operation->next);
|
||||
|
||||
/* Set the global config pointer */
|
||||
operation->next->global = global;
|
||||
|
||||
/* Update the last operation pointer */
|
||||
global->last = operation->next;
|
||||
|
||||
/* Move onto the new config */
|
||||
operation->next->prev = operation;
|
||||
operation = operation->next;
|
||||
}
|
||||
else
|
||||
res = PARAM_NO_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
if(res != PARAM_OK && res != PARAM_NEXT_OPERATION) {
|
||||
/* the help request isn't really an error */
|
||||
if(!strcmp(filename, "-")) {
|
||||
filename = "<stdin>";
|
||||
}
|
||||
if(res != PARAM_HELP_REQUESTED &&
|
||||
res != PARAM_MANUAL_REQUESTED &&
|
||||
res != PARAM_VERSION_INFO_REQUESTED &&
|
||||
res != PARAM_ENGINES_REQUESTED) {
|
||||
const char *reason = param2text(res);
|
||||
warnf(operation->global, "%s:%d: warning: '%s' %s\n",
|
||||
filename, lineno, option, reason);
|
||||
}
|
||||
}
|
||||
|
||||
if(alloced_param)
|
||||
Curl_safefree(param);
|
||||
|
||||
curlx_dyn_reset(&buf);
|
||||
}
|
||||
curlx_dyn_free(&buf);
|
||||
if(file != stdin)
|
||||
fclose(file);
|
||||
if(fileerror)
|
||||
rc = 1;
|
||||
}
|
||||
else
|
||||
rc = 1; /* couldn't open the file */
|
||||
|
||||
curl_free(pathalloc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copies the string from line to the buffer at param, unquoting
|
||||
* backslash-quoted characters and NUL-terminating the output string.
|
||||
* Stops at the first non-backslash-quoted double quote character or the
|
||||
* end of the input string. param must be at least as long as the input
|
||||
* string. Returns the pointer after the last handled input character.
|
||||
*/
|
||||
static const char *unslashquote(const char *line, char *param)
|
||||
{
|
||||
while(*line && (*line != '\"')) {
|
||||
if(*line == '\\') {
|
||||
char out;
|
||||
line++;
|
||||
|
||||
/* default is to output the letter after the backslash */
|
||||
switch(out = *line) {
|
||||
case '\0':
|
||||
continue; /* this'll break out of the loop */
|
||||
case 't':
|
||||
out = '\t';
|
||||
break;
|
||||
case 'n':
|
||||
out = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
out = '\r';
|
||||
break;
|
||||
case 'v':
|
||||
out = '\v';
|
||||
break;
|
||||
}
|
||||
*param++ = out;
|
||||
line++;
|
||||
}
|
||||
else
|
||||
*param++ = *line++;
|
||||
}
|
||||
*param = '\0'; /* always null-terminate */
|
||||
return line;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a line from the given file, ensuring is NUL terminated.
|
||||
*/
|
||||
static bool my_get_line(FILE *fp, struct curlx_dynbuf *db,
|
||||
bool *error)
|
||||
{
|
||||
char buf[4096];
|
||||
*error = FALSE;
|
||||
do {
|
||||
/* fgets() returns s on success, and NULL on error or when end of file
|
||||
occurs while no characters have been read. */
|
||||
if(!fgets(buf, sizeof(buf), fp))
|
||||
/* only if there's data in the line, return TRUE */
|
||||
return curlx_dyn_len(db) ? TRUE : FALSE;
|
||||
if(curlx_dyn_add(db, buf)) {
|
||||
*error = TRUE; /* error */
|
||||
return FALSE; /* stop reading */
|
||||
}
|
||||
} while(!strchr(buf, '\n'));
|
||||
|
||||
return TRUE; /* continue */
|
||||
}
|
28
module/Vendor/CURL/src/tool_parsecfg.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_parsecfg.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_PARSECFG_H
|
||||
#define HEADER_CURL_TOOL_PARSECFG_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
int parseconfig(const char *filename, struct GlobalConfig *config);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
321
module/Vendor/CURL/src/tool_progress.c
vendored
Normal file
321
module/Vendor/CURL/src/tool_progress.c
vendored
Normal file
@ -0,0 +1,321 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_operate.h"
|
||||
#include "tool_progress.h"
|
||||
#include "tool_util.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
/* The point of this function would be to return a string of the input data,
|
||||
but never longer than 5 columns (+ one zero byte).
|
||||
Add suffix k, M, G when suitable... */
|
||||
static char *max5data(curl_off_t bytes, char *max5)
|
||||
{
|
||||
#define ONE_KILOBYTE CURL_OFF_T_C(1024)
|
||||
#define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE)
|
||||
#define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE)
|
||||
#define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE)
|
||||
#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)
|
||||
|
||||
if(bytes < CURL_OFF_T_C(100000))
|
||||
msnprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE)
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE);
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE)
|
||||
/* 'XX.XM' is good as long as we're less than 100 megs */
|
||||
msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
|
||||
CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE,
|
||||
(bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
|
||||
|
||||
#if (CURL_SIZEOF_CURL_OFF_T > 4)
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE)
|
||||
/* 'XXXXM' is good until we're at 10000MB or above */
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE)
|
||||
/* 10000 MB - 100 GB, we show it as XX.XG */
|
||||
msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
|
||||
CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE,
|
||||
(bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE)
|
||||
/* up to 10000GB, display without decimal: XXXXG */
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE);
|
||||
|
||||
else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE)
|
||||
/* up to 10000TB, display without decimal: XXXXT */
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE);
|
||||
|
||||
else
|
||||
/* up to 10000PB, display without decimal: XXXXP */
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE);
|
||||
|
||||
/* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number
|
||||
can hold, but our data type is signed so 8192PB will be the maximum. */
|
||||
|
||||
#else
|
||||
|
||||
else
|
||||
msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
|
||||
|
||||
#endif
|
||||
|
||||
return max5;
|
||||
}
|
||||
|
||||
int xferinfo_cb(void *clientp,
|
||||
curl_off_t dltotal,
|
||||
curl_off_t dlnow,
|
||||
curl_off_t ultotal,
|
||||
curl_off_t ulnow)
|
||||
{
|
||||
struct per_transfer *per = clientp;
|
||||
struct OperationConfig *config = per->config;
|
||||
per->dltotal = dltotal;
|
||||
per->dlnow = dlnow;
|
||||
per->ultotal = ultotal;
|
||||
per->ulnow = ulnow;
|
||||
|
||||
if(config->readbusy) {
|
||||
config->readbusy = FALSE;
|
||||
curl_easy_pause(per->curl, CURLPAUSE_CONT);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
|
||||
byte) */
|
||||
static void time2str(char *r, curl_off_t seconds)
|
||||
{
|
||||
curl_off_t h;
|
||||
if(seconds <= 0) {
|
||||
strcpy(r, "--:--:--");
|
||||
return;
|
||||
}
|
||||
h = seconds / CURL_OFF_T_C(3600);
|
||||
if(h <= CURL_OFF_T_C(99)) {
|
||||
curl_off_t m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
|
||||
curl_off_t s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
|
||||
msnprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
|
||||
":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
|
||||
}
|
||||
else {
|
||||
/* this equals to more than 99 hours, switch to a more suitable output
|
||||
format to fit within the limits. */
|
||||
curl_off_t d = seconds / CURL_OFF_T_C(86400);
|
||||
h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
|
||||
if(d <= CURL_OFF_T_C(999))
|
||||
msnprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
|
||||
"d %02" CURL_FORMAT_CURL_OFF_T "h", d, h);
|
||||
else
|
||||
msnprintf(r, 9, "%7" CURL_FORMAT_CURL_OFF_T "d", d);
|
||||
}
|
||||
}
|
||||
|
||||
static curl_off_t all_dltotal = 0;
|
||||
static curl_off_t all_ultotal = 0;
|
||||
static curl_off_t all_dlalready = 0;
|
||||
static curl_off_t all_ulalready = 0;
|
||||
|
||||
curl_off_t all_xfers = 0; /* current total */
|
||||
|
||||
struct speedcount {
|
||||
curl_off_t dl;
|
||||
curl_off_t ul;
|
||||
struct timeval stamp;
|
||||
};
|
||||
#define SPEEDCNT 10
|
||||
static unsigned int speedindex;
|
||||
static bool indexwrapped;
|
||||
static struct speedcount speedstore[SPEEDCNT];
|
||||
|
||||
/*
|
||||
|DL% UL% Dled Uled Xfers Live Qd Total Current Left Speed
|
||||
| 6 -- 9.9G 0 2 2 0 0:00:40 0:00:02 0:00:37 4087M
|
||||
*/
|
||||
bool progress_meter(struct GlobalConfig *global,
|
||||
struct timeval *start,
|
||||
bool final)
|
||||
{
|
||||
static struct timeval stamp;
|
||||
static bool header = FALSE;
|
||||
struct timeval now;
|
||||
long diff;
|
||||
|
||||
if(global->noprogress)
|
||||
return FALSE;
|
||||
|
||||
now = tvnow();
|
||||
diff = tvdiff(now, stamp);
|
||||
|
||||
if(!header) {
|
||||
header = TRUE;
|
||||
fputs("DL% UL% Dled Uled Xfers Live Qd "
|
||||
"Total Current Left Speed\n",
|
||||
global->errors);
|
||||
}
|
||||
if(final || (diff > 500)) {
|
||||
char time_left[10];
|
||||
char time_total[10];
|
||||
char time_spent[10];
|
||||
char buffer[3][6];
|
||||
curl_off_t spent = tvdiff(now, *start)/1000;
|
||||
char dlpercen[4]="--";
|
||||
char ulpercen[4]="--";
|
||||
struct per_transfer *per;
|
||||
curl_off_t all_dlnow = 0;
|
||||
curl_off_t all_ulnow = 0;
|
||||
bool dlknown = TRUE;
|
||||
bool ulknown = TRUE;
|
||||
curl_off_t all_running = 0; /* in progress */
|
||||
curl_off_t all_queued = 0; /* pending */
|
||||
curl_off_t speed = 0;
|
||||
unsigned int i;
|
||||
stamp = now;
|
||||
|
||||
/* first add the amounts of the already completed transfers */
|
||||
all_dlnow += all_dlalready;
|
||||
all_ulnow += all_ulalready;
|
||||
|
||||
for(per = transfers; per; per = per->next) {
|
||||
all_dlnow += per->dlnow;
|
||||
all_ulnow += per->ulnow;
|
||||
if(!per->dltotal)
|
||||
dlknown = FALSE;
|
||||
else if(!per->dltotal_added) {
|
||||
/* only add this amount once */
|
||||
all_dltotal += per->dltotal;
|
||||
per->dltotal_added = TRUE;
|
||||
}
|
||||
if(!per->ultotal)
|
||||
ulknown = FALSE;
|
||||
else if(!per->ultotal_added) {
|
||||
/* only add this amount once */
|
||||
all_ultotal += per->ultotal;
|
||||
per->ultotal_added = TRUE;
|
||||
}
|
||||
if(!per->added)
|
||||
all_queued++;
|
||||
else
|
||||
all_running++;
|
||||
}
|
||||
if(dlknown && all_dltotal)
|
||||
/* TODO: handle integer overflow */
|
||||
msnprintf(dlpercen, sizeof(dlpercen), "%3" CURL_FORMAT_CURL_OFF_T,
|
||||
all_dlnow * 100 / all_dltotal);
|
||||
if(ulknown && all_ultotal)
|
||||
/* TODO: handle integer overflow */
|
||||
msnprintf(ulpercen, sizeof(ulpercen), "%3" CURL_FORMAT_CURL_OFF_T,
|
||||
all_ulnow * 100 / all_ultotal);
|
||||
|
||||
/* get the transfer speed, the higher of the two */
|
||||
|
||||
i = speedindex;
|
||||
speedstore[i].dl = all_dlnow;
|
||||
speedstore[i].ul = all_ulnow;
|
||||
speedstore[i].stamp = now;
|
||||
if(++speedindex >= SPEEDCNT) {
|
||||
indexwrapped = TRUE;
|
||||
speedindex = 0;
|
||||
}
|
||||
|
||||
{
|
||||
long deltams;
|
||||
curl_off_t dl;
|
||||
curl_off_t ul;
|
||||
curl_off_t dls;
|
||||
curl_off_t uls;
|
||||
if(indexwrapped) {
|
||||
/* 'speedindex' is the oldest stored data */
|
||||
deltams = tvdiff(now, speedstore[speedindex].stamp);
|
||||
dl = all_dlnow - speedstore[speedindex].dl;
|
||||
ul = all_ulnow - speedstore[speedindex].ul;
|
||||
}
|
||||
else {
|
||||
/* since the beginning */
|
||||
deltams = tvdiff(now, *start);
|
||||
dl = all_dlnow;
|
||||
ul = all_ulnow;
|
||||
}
|
||||
dls = (curl_off_t)((double)dl / ((double)deltams/1000.0));
|
||||
uls = (curl_off_t)((double)ul / ((double)deltams/1000.0));
|
||||
speed = dls > uls ? dls : uls;
|
||||
}
|
||||
|
||||
|
||||
if(dlknown && speed) {
|
||||
curl_off_t est = all_dltotal / speed;
|
||||
curl_off_t left = (all_dltotal - all_dlnow) / speed;
|
||||
time2str(time_left, left);
|
||||
time2str(time_total, est);
|
||||
}
|
||||
else {
|
||||
time2str(time_left, 0);
|
||||
time2str(time_total, 0);
|
||||
}
|
||||
time2str(time_spent, spent);
|
||||
|
||||
fprintf(global->errors,
|
||||
"\r"
|
||||
"%-3s " /* percent downloaded */
|
||||
"%-3s " /* percent uploaded */
|
||||
"%s " /* Dled */
|
||||
"%s " /* Uled */
|
||||
"%5" CURL_FORMAT_CURL_OFF_T " " /* Xfers */
|
||||
"%5" CURL_FORMAT_CURL_OFF_T " " /* Live */
|
||||
"%5" CURL_FORMAT_CURL_OFF_T " " /* Queued */
|
||||
"%s " /* Total time */
|
||||
"%s " /* Current time */
|
||||
"%s " /* Time left */
|
||||
"%s " /* Speed */
|
||||
"%5s" /* final newline */,
|
||||
|
||||
dlpercen, /* 3 letters */
|
||||
ulpercen, /* 3 letters */
|
||||
max5data(all_dlnow, buffer[0]),
|
||||
max5data(all_ulnow, buffer[1]),
|
||||
all_xfers,
|
||||
all_running,
|
||||
all_queued,
|
||||
time_total,
|
||||
time_spent,
|
||||
time_left,
|
||||
max5data(speed, buffer[2]), /* speed */
|
||||
final ? "\n" :"");
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void progress_finalize(struct per_transfer *per)
|
||||
{
|
||||
/* get the numbers before this transfer goes away */
|
||||
all_dlalready += per->dlnow;
|
||||
all_ulalready += per->ulnow;
|
||||
}
|
39
module/Vendor/CURL/src/tool_progress.h
vendored
Normal file
39
module/Vendor/CURL/src/tool_progress.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef HEADER_CURL_TOOL_PROGRESS_H
|
||||
#define HEADER_CURL_TOOL_PROGRESS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
int xferinfo_cb(void *clientp,
|
||||
curl_off_t dltotal,
|
||||
curl_off_t dlnow,
|
||||
curl_off_t ultotal,
|
||||
curl_off_t ulnow);
|
||||
|
||||
bool progress_meter(struct GlobalConfig *global,
|
||||
struct timeval *start,
|
||||
bool final);
|
||||
void progress_finalize(struct per_transfer *per);
|
||||
|
||||
extern curl_off_t all_xfers; /* total number */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_PROGRESS_H */
|
150
module/Vendor/CURL/src/tool_sdecls.h
vendored
Normal file
150
module/Vendor/CURL/src/tool_sdecls.h
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
#ifndef HEADER_CURL_TOOL_SDECLS_H
|
||||
#define HEADER_CURL_TOOL_SDECLS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#ifdef USE_METALINK
|
||||
# include <metalink/metalink.h>
|
||||
#endif /* USE_METALINK */
|
||||
|
||||
/*
|
||||
* OutStruct variables keep track of information relative to curl's
|
||||
* output writing, which may take place to a standard stream or a file.
|
||||
*
|
||||
* 'filename' member is either a pointer to a file name string or NULL
|
||||
* when dealing with a standard stream.
|
||||
*
|
||||
* 'alloc_filename' member is TRUE when string pointed by 'filename' has been
|
||||
* dynamically allocated and 'belongs' to this OutStruct, otherwise FALSE.
|
||||
*
|
||||
* 'is_cd_filename' member is TRUE when string pointed by 'filename' has been
|
||||
* set using a server-specified Content-Disposition filename, otherwise FALSE.
|
||||
*
|
||||
* 's_isreg' member is TRUE when output goes to a regular file, this also
|
||||
* implies that output is 'seekable' and 'appendable' and also that member
|
||||
* 'filename' points to file name's string. For any standard stream member
|
||||
* 's_isreg' will be FALSE.
|
||||
*
|
||||
* 'fopened' member is TRUE when output goes to a regular file and it
|
||||
* has been fopen'ed, requiring it to be closed later on. In any other
|
||||
* case this is FALSE.
|
||||
*
|
||||
* 'stream' member is a pointer to a stream controlling object as returned
|
||||
* from a 'fopen' call or a standard stream.
|
||||
*
|
||||
* 'config' member is a pointer to associated 'OperationConfig' struct.
|
||||
*
|
||||
* 'bytes' member represents amount written so far.
|
||||
*
|
||||
* 'init' member holds original file size or offset at which truncation is
|
||||
* taking place. Always zero unless appending to a non-empty regular file.
|
||||
*
|
||||
* 'metalink_parser' member is a pointer to Metalink XML parser
|
||||
* context.
|
||||
*/
|
||||
|
||||
struct OutStruct {
|
||||
char *filename;
|
||||
bool alloc_filename;
|
||||
bool is_cd_filename;
|
||||
bool s_isreg;
|
||||
bool fopened;
|
||||
FILE *stream;
|
||||
curl_off_t bytes;
|
||||
curl_off_t init;
|
||||
#ifdef USE_METALINK
|
||||
metalink_parser_context_t *metalink_parser;
|
||||
#endif /* USE_METALINK */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* InStruct variables keep track of information relative to curl's
|
||||
* input reading, which may take place from stdin or from some file.
|
||||
*
|
||||
* 'fd' member is either 'stdin' file descriptor number STDIN_FILENO
|
||||
* or a file descriptor as returned from an 'open' call for some file.
|
||||
*
|
||||
* 'config' member is a pointer to associated 'OperationConfig' struct.
|
||||
*/
|
||||
|
||||
struct InStruct {
|
||||
int fd;
|
||||
struct OperationConfig *config;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* A linked list of these 'getout' nodes contain URL's to fetch,
|
||||
* as well as information relative to where URL contents should
|
||||
* be stored or which file should be uploaded.
|
||||
*/
|
||||
|
||||
struct getout {
|
||||
struct getout *next; /* next one */
|
||||
char *url; /* the URL we deal with */
|
||||
char *outfile; /* where to store the output */
|
||||
char *infile; /* file to upload, if GETOUT_UPLOAD is set */
|
||||
int flags; /* options - composed of GETOUT_* bits */
|
||||
int num; /* which URL number in an invocation */
|
||||
};
|
||||
|
||||
#define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */
|
||||
#define GETOUT_URL (1<<1) /* set when URL is deemed done */
|
||||
#define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */
|
||||
#define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */
|
||||
#define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */
|
||||
#define GETOUT_METALINK (1<<5) /* set when Metalink download */
|
||||
|
||||
/*
|
||||
* 'trace' enumeration represents curl's output look'n feel possibilities.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
TRACE_NONE, /* no trace/verbose output at all */
|
||||
TRACE_BIN, /* tcpdump inspired look */
|
||||
TRACE_ASCII, /* like *BIN but without the hex output */
|
||||
TRACE_PLAIN /* -v/--verbose type */
|
||||
} trace;
|
||||
|
||||
|
||||
/*
|
||||
* 'HttpReq' enumeration represents HTTP request types.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
HTTPREQ_UNSPEC, /* first in list */
|
||||
HTTPREQ_GET,
|
||||
HTTPREQ_HEAD,
|
||||
HTTPREQ_MIMEPOST,
|
||||
HTTPREQ_SIMPLEPOST
|
||||
} HttpReq;
|
||||
|
||||
|
||||
/*
|
||||
* Complete struct declarations which have OperationConfig struct members,
|
||||
* just in case this header is directly included in some source file.
|
||||
*/
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_SDECLS_H */
|
884
module/Vendor/CURL/src/tool_setopt.c
vendored
Normal file
884
module/Vendor/CURL/src/tool_setopt.c
vendored
Normal file
@ -0,0 +1,884 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_easysrc.h"
|
||||
#include "tool_setopt.h"
|
||||
#include "tool_convert.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
/* Lookup tables for converting setopt values back to symbols */
|
||||
/* For enums, values may be in any order. */
|
||||
/* For bit masks, put combinations first, then single bits, */
|
||||
/* and finally any "NONE" value. */
|
||||
|
||||
#define NV(e) {#e, e}
|
||||
#define NV1(e, v) {#e, (v)}
|
||||
#define NVEND {NULL, 0} /* sentinel to mark end of list */
|
||||
|
||||
const struct NameValue setopt_nv_CURLPROXY[] = {
|
||||
NV(CURLPROXY_HTTP),
|
||||
NV(CURLPROXY_HTTP_1_0),
|
||||
NV(CURLPROXY_HTTPS),
|
||||
NV(CURLPROXY_SOCKS4),
|
||||
NV(CURLPROXY_SOCKS5),
|
||||
NV(CURLPROXY_SOCKS4A),
|
||||
NV(CURLPROXY_SOCKS5_HOSTNAME),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURL_SOCKS_PROXY[] = {
|
||||
NV(CURLPROXY_SOCKS4),
|
||||
NV(CURLPROXY_SOCKS5),
|
||||
NV(CURLPROXY_SOCKS4A),
|
||||
NV(CURLPROXY_SOCKS5_HOSTNAME),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValueUnsigned setopt_nv_CURLHSTS[] = {
|
||||
NV(CURLHSTS_ENABLE),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValueUnsigned setopt_nv_CURLAUTH[] = {
|
||||
NV(CURLAUTH_ANY), /* combination */
|
||||
NV(CURLAUTH_ANYSAFE), /* combination */
|
||||
NV(CURLAUTH_BASIC),
|
||||
NV(CURLAUTH_DIGEST),
|
||||
NV(CURLAUTH_GSSNEGOTIATE),
|
||||
NV(CURLAUTH_NTLM),
|
||||
NV(CURLAUTH_DIGEST_IE),
|
||||
NV(CURLAUTH_NTLM_WB),
|
||||
NV(CURLAUTH_ONLY),
|
||||
NV(CURLAUTH_NONE),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURL_HTTP_VERSION[] = {
|
||||
NV(CURL_HTTP_VERSION_NONE),
|
||||
NV(CURL_HTTP_VERSION_1_0),
|
||||
NV(CURL_HTTP_VERSION_1_1),
|
||||
NV(CURL_HTTP_VERSION_2_0),
|
||||
NV(CURL_HTTP_VERSION_2TLS),
|
||||
NV(CURL_HTTP_VERSION_3),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURL_SSLVERSION[] = {
|
||||
NV(CURL_SSLVERSION_DEFAULT),
|
||||
NV(CURL_SSLVERSION_TLSv1),
|
||||
NV(CURL_SSLVERSION_SSLv2),
|
||||
NV(CURL_SSLVERSION_SSLv3),
|
||||
NV(CURL_SSLVERSION_TLSv1_0),
|
||||
NV(CURL_SSLVERSION_TLSv1_1),
|
||||
NV(CURL_SSLVERSION_TLSv1_2),
|
||||
NV(CURL_SSLVERSION_TLSv1_3),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURL_TIMECOND[] = {
|
||||
NV(CURL_TIMECOND_IFMODSINCE),
|
||||
NV(CURL_TIMECOND_IFUNMODSINCE),
|
||||
NV(CURL_TIMECOND_LASTMOD),
|
||||
NV(CURL_TIMECOND_NONE),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURLFTPSSL_CCC[] = {
|
||||
NV(CURLFTPSSL_CCC_NONE),
|
||||
NV(CURLFTPSSL_CCC_PASSIVE),
|
||||
NV(CURLFTPSSL_CCC_ACTIVE),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURLUSESSL[] = {
|
||||
NV(CURLUSESSL_NONE),
|
||||
NV(CURLUSESSL_TRY),
|
||||
NV(CURLUSESSL_CONTROL),
|
||||
NV(CURLUSESSL_ALL),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValueUnsigned setopt_nv_CURLSSLOPT[] = {
|
||||
NV(CURLSSLOPT_ALLOW_BEAST),
|
||||
NV(CURLSSLOPT_NO_REVOKE),
|
||||
NV(CURLSSLOPT_NO_PARTIALCHAIN),
|
||||
NV(CURLSSLOPT_REVOKE_BEST_EFFORT),
|
||||
NV(CURLSSLOPT_NATIVE_CA),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
const struct NameValue setopt_nv_CURL_NETRC[] = {
|
||||
NV(CURL_NETRC_IGNORED),
|
||||
NV(CURL_NETRC_OPTIONAL),
|
||||
NV(CURL_NETRC_REQUIRED),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
/* These mappings essentially triplicated - see
|
||||
* tool_libinfo.c and tool_paramhlp.c */
|
||||
const struct NameValue setopt_nv_CURLPROTO[] = {
|
||||
NV(CURLPROTO_ALL), /* combination */
|
||||
NV(CURLPROTO_DICT),
|
||||
NV(CURLPROTO_FILE),
|
||||
NV(CURLPROTO_FTP),
|
||||
NV(CURLPROTO_FTPS),
|
||||
NV(CURLPROTO_GOPHER),
|
||||
NV(CURLPROTO_HTTP),
|
||||
NV(CURLPROTO_HTTPS),
|
||||
NV(CURLPROTO_IMAP),
|
||||
NV(CURLPROTO_IMAPS),
|
||||
NV(CURLPROTO_LDAP),
|
||||
NV(CURLPROTO_LDAPS),
|
||||
NV(CURLPROTO_POP3),
|
||||
NV(CURLPROTO_POP3S),
|
||||
NV(CURLPROTO_RTSP),
|
||||
NV(CURLPROTO_SCP),
|
||||
NV(CURLPROTO_SFTP),
|
||||
NV(CURLPROTO_SMB),
|
||||
NV(CURLPROTO_SMBS),
|
||||
NV(CURLPROTO_SMTP),
|
||||
NV(CURLPROTO_SMTPS),
|
||||
NV(CURLPROTO_TELNET),
|
||||
NV(CURLPROTO_TFTP),
|
||||
NVEND,
|
||||
};
|
||||
|
||||
/* These options have non-zero default values. */
|
||||
static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
|
||||
NV1(CURLOPT_SSL_VERIFYPEER, 1),
|
||||
NV1(CURLOPT_SSL_VERIFYHOST, 1),
|
||||
NV1(CURLOPT_SSL_ENABLE_NPN, 1),
|
||||
NV1(CURLOPT_SSL_ENABLE_ALPN, 1),
|
||||
NV1(CURLOPT_TCP_NODELAY, 1),
|
||||
NV1(CURLOPT_PROXY_SSL_VERIFYPEER, 1),
|
||||
NV1(CURLOPT_PROXY_SSL_VERIFYHOST, 1),
|
||||
NV1(CURLOPT_SOCKS5_AUTH, 1),
|
||||
NVEND
|
||||
};
|
||||
|
||||
/* Format and add code; jump to nomem on malloc error */
|
||||
#define ADD(args) do { \
|
||||
ret = easysrc_add args; \
|
||||
if(ret) \
|
||||
goto nomem; \
|
||||
} while(0)
|
||||
#define ADDF(args) do { \
|
||||
ret = easysrc_addf args; \
|
||||
if(ret) \
|
||||
goto nomem; \
|
||||
} while(0)
|
||||
#define NULL_CHECK(p) do { \
|
||||
if(!p) { \
|
||||
ret = CURLE_OUT_OF_MEMORY; \
|
||||
goto nomem; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define DECL0(s) ADD((&easysrc_decl, s))
|
||||
#define DECL1(f,a) ADDF((&easysrc_decl, f,a))
|
||||
|
||||
#define DATA0(s) ADD((&easysrc_data, s))
|
||||
#define DATA1(f,a) ADDF((&easysrc_data, f,a))
|
||||
#define DATA2(f,a,b) ADDF((&easysrc_data, f,a,b))
|
||||
#define DATA3(f,a,b,c) ADDF((&easysrc_data, f,a,b,c))
|
||||
|
||||
#define CODE0(s) ADD((&easysrc_code, s))
|
||||
#define CODE1(f,a) ADDF((&easysrc_code, f,a))
|
||||
#define CODE2(f,a,b) ADDF((&easysrc_code, f,a,b))
|
||||
#define CODE3(f,a,b,c) ADDF((&easysrc_code, f,a,b,c))
|
||||
|
||||
#define CLEAN0(s) ADD((&easysrc_clean, s))
|
||||
#define CLEAN1(f,a) ADDF((&easysrc_clean, f,a))
|
||||
|
||||
#define REM0(s) ADD((&easysrc_toohard, s))
|
||||
#define REM1(f,a) ADDF((&easysrc_toohard, f,a))
|
||||
#define REM2(f,a,b) ADDF((&easysrc_toohard, f,a,b))
|
||||
|
||||
/* Escape string to C string syntax. Return NULL if out of memory.
|
||||
* Is this correct for those wacky EBCDIC guys? */
|
||||
|
||||
#define MAX_STRING_LENGTH_OUTPUT 2000
|
||||
#define ZERO_TERMINATED -1
|
||||
|
||||
static char *c_escape(const char *str, curl_off_t len)
|
||||
{
|
||||
const char *s;
|
||||
unsigned char c;
|
||||
char *escaped, *e;
|
||||
unsigned int cutoff = 0;
|
||||
|
||||
if(len == ZERO_TERMINATED)
|
||||
len = strlen(str);
|
||||
|
||||
if(len > MAX_STRING_LENGTH_OUTPUT) {
|
||||
/* cap ridiculously long strings */
|
||||
len = MAX_STRING_LENGTH_OUTPUT;
|
||||
cutoff = 3;
|
||||
}
|
||||
|
||||
/* Allocate space based on worst-case */
|
||||
escaped = malloc(4 * (size_t)len + 1 + cutoff);
|
||||
if(!escaped)
|
||||
return NULL;
|
||||
|
||||
e = escaped;
|
||||
for(s = str; len; s++, len--) {
|
||||
c = *s;
|
||||
if(c == '\n') {
|
||||
strcpy(e, "\\n");
|
||||
e += 2;
|
||||
}
|
||||
else if(c == '\r') {
|
||||
strcpy(e, "\\r");
|
||||
e += 2;
|
||||
}
|
||||
else if(c == '\t') {
|
||||
strcpy(e, "\\t");
|
||||
e += 2;
|
||||
}
|
||||
else if(c == '\\') {
|
||||
strcpy(e, "\\\\");
|
||||
e += 2;
|
||||
}
|
||||
else if(c == '"') {
|
||||
strcpy(e, "\\\"");
|
||||
e += 2;
|
||||
}
|
||||
else if(!isprint(c)) {
|
||||
msnprintf(e, 5, "\\x%02x", (unsigned)c);
|
||||
e += 4;
|
||||
}
|
||||
else
|
||||
*e++ = c;
|
||||
}
|
||||
while(cutoff--)
|
||||
*e++ = '.';
|
||||
*e = '\0';
|
||||
return escaped;
|
||||
}
|
||||
|
||||
/* setopt wrapper for enum types */
|
||||
CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValue *nvlist, long lval)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
bool skip = FALSE;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, lval);
|
||||
if(!lval)
|
||||
skip = TRUE;
|
||||
|
||||
if(config->libcurl && !skip && !ret) {
|
||||
/* we only use this for real if --libcurl was used */
|
||||
const struct NameValue *nv = NULL;
|
||||
for(nv = nvlist; nv->name; nv++) {
|
||||
if(nv->value == lval)
|
||||
break; /* found it */
|
||||
}
|
||||
if(!nv->name) {
|
||||
/* If no definition was found, output an explicit value.
|
||||
* This could happen if new values are defined and used
|
||||
* but the NameValue list is not updated. */
|
||||
CODE2("curl_easy_setopt(hnd, %s, %ldL);", name, lval);
|
||||
}
|
||||
else {
|
||||
CODE2("curl_easy_setopt(hnd, %s, (long)%s);", name, nv->name);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
if(ret)
|
||||
warnf(config, "option %s returned error (%d)\n", name, (int)ret);
|
||||
#endif
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* setopt wrapper for flags */
|
||||
CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValue *nvlist, long lval)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
bool skip = FALSE;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, lval);
|
||||
if(!lval)
|
||||
skip = TRUE;
|
||||
|
||||
if(config->libcurl && !skip && !ret) {
|
||||
/* we only use this for real if --libcurl was used */
|
||||
char preamble[80]; /* should accommodate any symbol name */
|
||||
long rest = lval; /* bits not handled yet */
|
||||
const struct NameValue *nv = NULL;
|
||||
msnprintf(preamble, sizeof(preamble),
|
||||
"curl_easy_setopt(hnd, %s, ", name);
|
||||
for(nv = nvlist; nv->name; nv++) {
|
||||
if((nv->value & ~ rest) == 0) {
|
||||
/* all value flags contained in rest */
|
||||
rest &= ~ nv->value; /* remove bits handled here */
|
||||
CODE3("%s(long)%s%s",
|
||||
preamble, nv->name, rest ? " |" : ");");
|
||||
if(!rest)
|
||||
break; /* handled them all */
|
||||
/* replace with all spaces for continuation line */
|
||||
msnprintf(preamble, sizeof(preamble), "%*s", strlen(preamble), "");
|
||||
}
|
||||
}
|
||||
/* If any bits have no definition, output an explicit value.
|
||||
* This could happen if new bits are defined and used
|
||||
* but the NameValue list is not updated. */
|
||||
if(rest)
|
||||
CODE2("%s%ldL);", preamble, rest);
|
||||
}
|
||||
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* setopt wrapper for bitmasks */
|
||||
CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValueUnsigned *nvlist,
|
||||
long lval)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
bool skip = FALSE;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, lval);
|
||||
if(!lval)
|
||||
skip = TRUE;
|
||||
|
||||
if(config->libcurl && !skip && !ret) {
|
||||
/* we only use this for real if --libcurl was used */
|
||||
char preamble[80];
|
||||
unsigned long rest = (unsigned long)lval;
|
||||
const struct NameValueUnsigned *nv = NULL;
|
||||
msnprintf(preamble, sizeof(preamble),
|
||||
"curl_easy_setopt(hnd, %s, ", name);
|
||||
for(nv = nvlist; nv->name; nv++) {
|
||||
if((nv->value & ~ rest) == 0) {
|
||||
/* all value flags contained in rest */
|
||||
rest &= ~ nv->value; /* remove bits handled here */
|
||||
CODE3("%s(long)%s%s",
|
||||
preamble, nv->name, rest ? " |" : ");");
|
||||
if(!rest)
|
||||
break; /* handled them all */
|
||||
/* replace with all spaces for continuation line */
|
||||
msnprintf(preamble, sizeof(preamble), "%*s", strlen(preamble), "");
|
||||
}
|
||||
}
|
||||
/* If any bits have no definition, output an explicit value.
|
||||
* This could happen if new bits are defined and used
|
||||
* but the NameValue list is not updated. */
|
||||
if(rest)
|
||||
CODE2("%s%luUL);", preamble, rest);
|
||||
}
|
||||
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Generate code for a struct curl_slist. */
|
||||
static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
char *escaped = NULL;
|
||||
|
||||
/* May need several slist variables, so invent name */
|
||||
*slistno = ++easysrc_slist_count;
|
||||
|
||||
DECL1("struct curl_slist *slist%d;", *slistno);
|
||||
DATA1("slist%d = NULL;", *slistno);
|
||||
CLEAN1("curl_slist_free_all(slist%d);", *slistno);
|
||||
CLEAN1("slist%d = NULL;", *slistno);
|
||||
for(; slist; slist = slist->next) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(slist->data, ZERO_TERMINATED);
|
||||
if(!escaped)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
DATA3("slist%d = curl_slist_append(slist%d, \"%s\");",
|
||||
*slistno, *slistno, escaped);
|
||||
}
|
||||
|
||||
nomem:
|
||||
Curl_safefree(escaped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static CURLcode libcurl_generate_mime(CURL *curl,
|
||||
struct GlobalConfig *config,
|
||||
struct tool_mime *toolmime,
|
||||
int *mimeno); /* Forward. */
|
||||
|
||||
/* Wrapper to generate source code for a mime part. */
|
||||
static CURLcode libcurl_generate_mime_part(CURL *curl,
|
||||
struct GlobalConfig *config,
|
||||
struct tool_mime *part,
|
||||
int mimeno)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
int submimeno = 0;
|
||||
char *escaped = NULL;
|
||||
const char *data = NULL;
|
||||
const char *filename = part->filename;
|
||||
|
||||
/* Parts are linked in reverse order. */
|
||||
if(part->prev) {
|
||||
ret = libcurl_generate_mime_part(curl, config, part->prev, mimeno);
|
||||
if(ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create the part. */
|
||||
CODE2("part%d = curl_mime_addpart(mime%d);", mimeno, mimeno);
|
||||
|
||||
switch(part->kind) {
|
||||
case TOOLMIME_PARTS:
|
||||
ret = libcurl_generate_mime(curl, config, part, &submimeno);
|
||||
if(!ret) {
|
||||
CODE2("curl_mime_subparts(part%d, mime%d);", mimeno, submimeno);
|
||||
CODE1("mime%d = NULL;", submimeno); /* Avoid freeing in CLEAN. */
|
||||
}
|
||||
break;
|
||||
|
||||
case TOOLMIME_DATA:
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
/* Data will be set in ASCII, thus issue a comment with clear text. */
|
||||
escaped = c_escape(part->data, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE1("/* \"%s\" */", escaped);
|
||||
|
||||
/* Our data is always textual: convert it to ASCII. */
|
||||
{
|
||||
size_t size = strlen(part->data);
|
||||
char *cp = malloc(size + 1);
|
||||
|
||||
NULL_CHECK(cp);
|
||||
memcpy(cp, part->data, size + 1);
|
||||
ret = convert_to_network(cp, size);
|
||||
data = cp;
|
||||
}
|
||||
#else
|
||||
data = part->data;
|
||||
#endif
|
||||
if(!ret) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(data, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
|
||||
mimeno, escaped);
|
||||
}
|
||||
break;
|
||||
|
||||
case TOOLMIME_FILE:
|
||||
case TOOLMIME_FILEDATA:
|
||||
escaped = c_escape(part->data, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_filedata(part%d, \"%s\");", mimeno, escaped);
|
||||
if(part->kind == TOOLMIME_FILEDATA && !filename) {
|
||||
CODE1("curl_mime_filename(part%d, NULL);", mimeno);
|
||||
}
|
||||
break;
|
||||
|
||||
case TOOLMIME_STDIN:
|
||||
if(!filename)
|
||||
filename = "-";
|
||||
/* FALLTHROUGH */
|
||||
case TOOLMIME_STDINDATA:
|
||||
/* Can only be reading stdin in the current context. */
|
||||
CODE1("curl_mime_data_cb(part%d, -1, (curl_read_callback) fread, \\",
|
||||
mimeno);
|
||||
CODE0(" (curl_seek_callback) fseek, NULL, stdin);");
|
||||
break;
|
||||
default:
|
||||
/* Other cases not possible in this context. */
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ret && part->encoder) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(part->encoder, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_encoder(part%d, \"%s\");", mimeno, escaped);
|
||||
}
|
||||
|
||||
if(!ret && filename) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(filename, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_filename(part%d, \"%s\");", mimeno, escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->name) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(part->name, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_name(part%d, \"%s\");", mimeno, escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->type) {
|
||||
Curl_safefree(escaped);
|
||||
escaped = c_escape(part->type, ZERO_TERMINATED);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_mime_type(part%d, \"%s\");", mimeno, escaped);
|
||||
}
|
||||
|
||||
if(!ret && part->headers) {
|
||||
int slistno;
|
||||
|
||||
ret = libcurl_generate_slist(part->headers, &slistno);
|
||||
if(!ret) {
|
||||
CODE2("curl_mime_headers(part%d, slist%d, 1);", mimeno, slistno);
|
||||
CODE1("slist%d = NULL;", slistno); /* Prevent CLEANing. */
|
||||
}
|
||||
}
|
||||
|
||||
nomem:
|
||||
#ifdef CURL_DOES_CONVERSIONS
|
||||
if(data)
|
||||
free((char *) data);
|
||||
#endif
|
||||
|
||||
Curl_safefree(escaped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Wrapper to generate source code for a mime structure. */
|
||||
static CURLcode libcurl_generate_mime(CURL *curl,
|
||||
struct GlobalConfig *config,
|
||||
struct tool_mime *toolmime,
|
||||
int *mimeno)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
|
||||
/* May need several mime variables, so invent name. */
|
||||
*mimeno = ++easysrc_mime_count;
|
||||
DECL1("curl_mime *mime%d;", *mimeno);
|
||||
DATA1("mime%d = NULL;", *mimeno);
|
||||
CODE1("mime%d = curl_mime_init(hnd);", *mimeno);
|
||||
CLEAN1("curl_mime_free(mime%d);", *mimeno);
|
||||
CLEAN1("mime%d = NULL;", *mimeno);
|
||||
|
||||
if(toolmime->subparts) {
|
||||
DECL1("curl_mimepart *part%d;", *mimeno);
|
||||
ret = libcurl_generate_mime_part(curl, config,
|
||||
toolmime->subparts, *mimeno);
|
||||
}
|
||||
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* setopt wrapper for CURLOPT_MIMEPOST */
|
||||
CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
curl_mime *mimepost)
|
||||
{
|
||||
CURLcode ret = curl_easy_setopt(curl, tag, mimepost);
|
||||
int mimeno = 0;
|
||||
|
||||
if(!ret && config->libcurl) {
|
||||
ret = libcurl_generate_mime(curl, config,
|
||||
config->current->mimeroot, &mimeno);
|
||||
|
||||
if(!ret)
|
||||
CODE2("curl_easy_setopt(hnd, %s, mime%d);", name, mimeno);
|
||||
}
|
||||
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* setopt wrapper for curl_slist options */
|
||||
CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
struct curl_slist *list)
|
||||
{
|
||||
CURLcode ret = CURLE_OK;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, list);
|
||||
|
||||
if(config->libcurl && list && !ret) {
|
||||
int i;
|
||||
|
||||
ret = libcurl_generate_slist(list, &i);
|
||||
if(!ret)
|
||||
CODE2("curl_easy_setopt(hnd, %s, slist%d);", name, i);
|
||||
}
|
||||
|
||||
nomem:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* generic setopt wrapper for all other options.
|
||||
* Some type information is encoded in the tag value. */
|
||||
CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
|
||||
struct OperationConfig *config,
|
||||
const char *name, CURLoption tag, ...)
|
||||
{
|
||||
va_list arg;
|
||||
char buf[256];
|
||||
const char *value = NULL;
|
||||
bool remark = FALSE;
|
||||
bool skip = FALSE;
|
||||
bool escape = FALSE;
|
||||
char *escaped = NULL;
|
||||
CURLcode ret = CURLE_OK;
|
||||
|
||||
va_start(arg, tag);
|
||||
|
||||
if(tag < CURLOPTTYPE_OBJECTPOINT) {
|
||||
/* Value is expected to be a long */
|
||||
long lval = va_arg(arg, long);
|
||||
long defval = 0L;
|
||||
const struct NameValue *nv = NULL;
|
||||
for(nv = setopt_nv_CURLNONZERODEFAULTS; nv->name; nv++) {
|
||||
if(!strcmp(name, nv->name)) {
|
||||
defval = nv->value;
|
||||
break; /* found it */
|
||||
}
|
||||
}
|
||||
|
||||
msnprintf(buf, sizeof(buf), "%ldL", lval);
|
||||
value = buf;
|
||||
ret = curl_easy_setopt(curl, tag, lval);
|
||||
if(lval == defval)
|
||||
skip = TRUE;
|
||||
}
|
||||
else if(tag < CURLOPTTYPE_OFF_T) {
|
||||
/* Value is some sort of object pointer */
|
||||
void *pval = va_arg(arg, void *);
|
||||
|
||||
/* function pointers are never printable */
|
||||
if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
|
||||
if(pval) {
|
||||
value = "functionpointer";
|
||||
remark = TRUE;
|
||||
}
|
||||
else
|
||||
skip = TRUE;
|
||||
}
|
||||
|
||||
else if(pval && str) {
|
||||
value = (char *)pval;
|
||||
escape = TRUE;
|
||||
}
|
||||
else if(pval) {
|
||||
value = "objectpointer";
|
||||
remark = TRUE;
|
||||
}
|
||||
else
|
||||
skip = TRUE;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, pval);
|
||||
|
||||
}
|
||||
else if(tag < CURLOPTTYPE_BLOB) {
|
||||
/* Value is expected to be curl_off_t */
|
||||
curl_off_t oval = va_arg(arg, curl_off_t);
|
||||
msnprintf(buf, sizeof(buf),
|
||||
"(curl_off_t)%" CURL_FORMAT_CURL_OFF_T, oval);
|
||||
value = buf;
|
||||
ret = curl_easy_setopt(curl, tag, oval);
|
||||
|
||||
if(!oval)
|
||||
skip = TRUE;
|
||||
}
|
||||
else {
|
||||
/* Value is a blob */
|
||||
void *pblob = va_arg(arg, void *);
|
||||
|
||||
/* blobs are never printable */
|
||||
if(pblob) {
|
||||
value = "blobpointer";
|
||||
remark = TRUE;
|
||||
}
|
||||
else
|
||||
skip = TRUE;
|
||||
|
||||
ret = curl_easy_setopt(curl, tag, pblob);
|
||||
}
|
||||
|
||||
va_end(arg);
|
||||
|
||||
if(global->libcurl && !skip && !ret) {
|
||||
/* we only use this for real if --libcurl was used */
|
||||
|
||||
if(remark)
|
||||
REM2("%s set to a %s", name, value);
|
||||
else {
|
||||
if(escape) {
|
||||
curl_off_t len = ZERO_TERMINATED;
|
||||
if(tag == CURLOPT_POSTFIELDS)
|
||||
len = config->postfieldsize;
|
||||
escaped = c_escape(value, len);
|
||||
NULL_CHECK(escaped);
|
||||
CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped);
|
||||
}
|
||||
else
|
||||
CODE2("curl_easy_setopt(hnd, %s, %s);", name, value);
|
||||
}
|
||||
}
|
||||
|
||||
nomem:
|
||||
Curl_safefree(escaped);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_setopt.h"
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
/*
|
||||
* tool_setopt_skip() allows the curl tool code to avoid setopt options that
|
||||
* are explicitly disabled in the build.
|
||||
*/
|
||||
bool tool_setopt_skip(CURLoption tag)
|
||||
{
|
||||
#ifdef CURL_DISABLE_PROXY
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_HAPROXYPROTOCOL:
|
||||
case CURLOPT_HTTPPROXYTUNNEL:
|
||||
case CURLOPT_NOPROXY:
|
||||
case CURLOPT_PRE_PROXY:
|
||||
case CURLOPT_PROXY:
|
||||
case CURLOPT_PROXYAUTH:
|
||||
case CURLOPT_PROXY_CAINFO:
|
||||
case CURLOPT_PROXY_CAPATH:
|
||||
case CURLOPT_PROXY_CRLFILE:
|
||||
case CURLOPT_PROXYHEADER:
|
||||
case CURLOPT_PROXY_KEYPASSWD:
|
||||
case CURLOPT_PROXYPASSWORD:
|
||||
case CURLOPT_PROXY_PINNEDPUBLICKEY:
|
||||
case CURLOPT_PROXYPORT:
|
||||
case CURLOPT_PROXY_SERVICE_NAME:
|
||||
case CURLOPT_PROXY_SSLCERT:
|
||||
case CURLOPT_PROXY_SSLCERTTYPE:
|
||||
case CURLOPT_PROXY_SSL_CIPHER_LIST:
|
||||
case CURLOPT_PROXY_SSLKEY:
|
||||
case CURLOPT_PROXY_SSLKEYTYPE:
|
||||
case CURLOPT_PROXY_SSL_OPTIONS:
|
||||
case CURLOPT_PROXY_SSL_VERIFYHOST:
|
||||
case CURLOPT_PROXY_SSL_VERIFYPEER:
|
||||
case CURLOPT_PROXY_SSLVERSION:
|
||||
case CURLOPT_PROXY_TLS13_CIPHERS:
|
||||
case CURLOPT_PROXY_TLSAUTH_PASSWORD:
|
||||
case CURLOPT_PROXY_TLSAUTH_TYPE:
|
||||
case CURLOPT_PROXY_TLSAUTH_USERNAME:
|
||||
case CURLOPT_PROXY_TRANSFER_MODE:
|
||||
case CURLOPT_PROXYTYPE:
|
||||
case CURLOPT_PROXYUSERNAME:
|
||||
case CURLOPT_PROXYUSERPWD:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef CURL_DISABLE_FTP
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_FTPPORT:
|
||||
case CURLOPT_FTP_ACCOUNT:
|
||||
case CURLOPT_FTP_ALTERNATIVE_TO_USER:
|
||||
case CURLOPT_FTP_FILEMETHOD:
|
||||
case CURLOPT_FTP_SKIP_PASV_IP:
|
||||
case CURLOPT_FTP_USE_EPRT:
|
||||
case CURLOPT_FTP_USE_EPSV:
|
||||
case CURLOPT_FTP_USE_PRET:
|
||||
case CURLOPT_KRBLEVEL:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef CURL_DISABLE_RTSP
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_INTERLEAVEDATA:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_COOKIE:
|
||||
case CURLOPT_COOKIEFILE:
|
||||
case CURLOPT_COOKIEJAR:
|
||||
case CURLOPT_COOKIESESSION:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(CURL_DISABLE_TELNET)
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_TELNETOPTIONS:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef CURL_DISABLE_TFTP
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_TFTP_BLKSIZE:
|
||||
case CURLOPT_TFTP_NO_OPTIONS:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef CURL_DISABLE_NETRC
|
||||
#define USED_TAG
|
||||
switch(tag) {
|
||||
case CURLOPT_NETRC:
|
||||
case CURLOPT_NETRC_FILE:
|
||||
return TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef USED_TAG
|
||||
(void)tag;
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
163
module/Vendor/CURL/src/tool_setopt.h
vendored
Normal file
163
module/Vendor/CURL/src/tool_setopt.h
vendored
Normal file
@ -0,0 +1,163 @@
|
||||
#ifndef HEADER_CURL_TOOL_SETOPT_H
|
||||
#define HEADER_CURL_TOOL_SETOPT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_formparse.h"
|
||||
|
||||
/*
|
||||
* Macros used in operate()
|
||||
*/
|
||||
|
||||
#define SETOPT_CHECK(v,opt) do { \
|
||||
if(!tool_setopt_skip(opt)) { \
|
||||
result = (v); \
|
||||
if(result) \
|
||||
break; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* allow removed features to simulate success: */
|
||||
bool tool_setopt_skip(CURLoption tag);
|
||||
|
||||
#ifndef CURL_DISABLE_LIBCURL_OPTION
|
||||
|
||||
/* Associate symbolic names with option values */
|
||||
struct NameValue {
|
||||
const char *name;
|
||||
long value;
|
||||
};
|
||||
|
||||
struct NameValueUnsigned {
|
||||
const char *name;
|
||||
unsigned long value;
|
||||
};
|
||||
|
||||
extern const struct NameValue setopt_nv_CURLPROXY[];
|
||||
extern const struct NameValue setopt_nv_CURL_SOCKS_PROXY[];
|
||||
extern const struct NameValue setopt_nv_CURL_HTTP_VERSION[];
|
||||
extern const struct NameValue setopt_nv_CURL_SSLVERSION[];
|
||||
extern const struct NameValue setopt_nv_CURL_TIMECOND[];
|
||||
extern const struct NameValue setopt_nv_CURLFTPSSL_CCC[];
|
||||
extern const struct NameValue setopt_nv_CURLUSESSL[];
|
||||
extern const struct NameValueUnsigned setopt_nv_CURLSSLOPT[];
|
||||
extern const struct NameValue setopt_nv_CURL_NETRC[];
|
||||
extern const struct NameValue setopt_nv_CURLPROTO[];
|
||||
extern const struct NameValueUnsigned setopt_nv_CURLAUTH[];
|
||||
extern const struct NameValueUnsigned setopt_nv_CURLHSTS[];
|
||||
|
||||
/* Map options to NameValue sets */
|
||||
#define setopt_nv_CURLOPT_HSTS_CTRL setopt_nv_CURLHSTS
|
||||
#define setopt_nv_CURLOPT_HTTP_VERSION setopt_nv_CURL_HTTP_VERSION
|
||||
#define setopt_nv_CURLOPT_HTTPAUTH setopt_nv_CURLAUTH
|
||||
#define setopt_nv_CURLOPT_SSLVERSION setopt_nv_CURL_SSLVERSION
|
||||
#define setopt_nv_CURLOPT_PROXY_SSLVERSION setopt_nv_CURL_SSLVERSION
|
||||
#define setopt_nv_CURLOPT_TIMECONDITION setopt_nv_CURL_TIMECOND
|
||||
#define setopt_nv_CURLOPT_FTP_SSL_CCC setopt_nv_CURLFTPSSL_CCC
|
||||
#define setopt_nv_CURLOPT_USE_SSL setopt_nv_CURLUSESSL
|
||||
#define setopt_nv_CURLOPT_SSL_OPTIONS setopt_nv_CURLSSLOPT
|
||||
#define setopt_nv_CURLOPT_NETRC setopt_nv_CURL_NETRC
|
||||
#define setopt_nv_CURLOPT_PROTOCOLS setopt_nv_CURLPROTO
|
||||
#define setopt_nv_CURLOPT_REDIR_PROTOCOLS setopt_nv_CURLPROTO
|
||||
#define setopt_nv_CURLOPT_PROXYTYPE setopt_nv_CURLPROXY
|
||||
#define setopt_nv_CURLOPT_PROXYAUTH setopt_nv_CURLAUTH
|
||||
#define setopt_nv_CURLOPT_SOCKS5_AUTH setopt_nv_CURLAUTH
|
||||
|
||||
/* Intercept setopt calls for --libcurl */
|
||||
|
||||
CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValue *nv, long lval);
|
||||
CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValue *nv, long lval);
|
||||
CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
const struct NameValueUnsigned *nv, long lval);
|
||||
CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
curl_mime *mimepost);
|
||||
CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
|
||||
const char *name, CURLoption tag,
|
||||
struct curl_slist *list);
|
||||
CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
|
||||
struct OperationConfig *config,
|
||||
const char *name, CURLoption tag, ...);
|
||||
|
||||
#define my_setopt(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt(x, FALSE, global, config, #y, y, z), y)
|
||||
|
||||
#define my_setopt_str(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt(x, TRUE, global, config, #y, y, z), y)
|
||||
|
||||
#define my_setopt_enum(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt_enum(x, global, #y, y, setopt_nv_ ## y, z), y)
|
||||
|
||||
#define my_setopt_flags(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt_flags(x, global, #y, y, setopt_nv_ ## y, z), y)
|
||||
|
||||
#define my_setopt_bitmask(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt_bitmask(x, global, #y, y, setopt_nv_ ## y, z), y)
|
||||
|
||||
#define my_setopt_mimepost(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt_mimepost(x, global, #y, y, z), y)
|
||||
|
||||
#define my_setopt_slist(x,y,z) \
|
||||
SETOPT_CHECK(tool_setopt_slist(x, global, #y, y, z), y)
|
||||
|
||||
#define res_setopt(x,y,z) tool_setopt(x, FALSE, global, config, #y, y, z)
|
||||
|
||||
#define res_setopt_str(x,y,z) tool_setopt(x, TRUE, global, config, #y, y, z)
|
||||
|
||||
#else /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
/* No --libcurl, so pass options directly to library */
|
||||
|
||||
#define my_setopt(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_str(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_enum(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_flags(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_bitmask(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_mimepost(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define my_setopt_slist(x,y,z) \
|
||||
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
|
||||
|
||||
#define res_setopt(x,y,z) curl_easy_setopt(x,y,z)
|
||||
|
||||
#define res_setopt_str(x,y,z) curl_easy_setopt(x,y,z)
|
||||
|
||||
#endif /* CURL_DISABLE_LIBCURL_OPTION */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_SETOPT_H */
|
73
module/Vendor/CURL/src/tool_setup.h
vendored
Normal file
73
module/Vendor/CURL/src/tool_setup.h
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef HEADER_CURL_TOOL_SETUP_H
|
||||
#define HEADER_CURL_TOOL_SETUP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#define CURL_NO_OLDIES
|
||||
|
||||
/*
|
||||
* curl_setup.h may define preprocessor macros such as _FILE_OFFSET_BITS and
|
||||
* _LARGE_FILES in order to support files larger than 2 GB. On platforms
|
||||
* where this happens it is mandatory that these macros are defined before
|
||||
* any system header file is included, otherwise file handling function
|
||||
* prototypes will be misdeclared and curl tool may not build properly;
|
||||
* therefore we must include curl_setup.h before curl.h when building curl.
|
||||
*/
|
||||
|
||||
#include "curl_setup.h" /* from the lib directory */
|
||||
|
||||
/*
|
||||
* curl tool certainly uses libcurl's external interface.
|
||||
*/
|
||||
|
||||
#include <curl/curl.h> /* external interface */
|
||||
|
||||
/*
|
||||
* Platform specific stuff.
|
||||
*/
|
||||
|
||||
#if defined(macintosh) && defined(__MRC__)
|
||||
# define main(x,y) curl_main(x,y)
|
||||
#endif
|
||||
|
||||
#ifdef TPF
|
||||
# undef select
|
||||
/* change which select is used for the curl command line tool */
|
||||
# define select(a,b,c,d,e) tpf_select_bsd(a,b,c,d,e)
|
||||
/* and turn off the progress meter */
|
||||
# define CONF_DEFAULT (0|CONF_NOPROGRESS)
|
||||
#endif
|
||||
|
||||
#ifndef OS
|
||||
# define OS "unknown"
|
||||
#endif
|
||||
|
||||
#ifndef UNPRINTABLE_CHAR
|
||||
/* define what to use for unprintable characters */
|
||||
# define UNPRINTABLE_CHAR '.'
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
# include "tool_strdup.h"
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_SETUP_H */
|
59
module/Vendor/CURL/src/tool_sleep.c
vendored
Normal file
59
module/Vendor/CURL/src/tool_sleep.c
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#elif defined(HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_POLL_H
|
||||
# include <poll.h>
|
||||
#elif defined(HAVE_SYS_POLL_H)
|
||||
# include <sys/poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
# include <dos.h>
|
||||
#endif
|
||||
|
||||
#include "tool_sleep.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void tool_go_sleep(long ms)
|
||||
{
|
||||
#if defined(MSDOS)
|
||||
delay(ms);
|
||||
#elif defined(WIN32)
|
||||
Sleep(ms);
|
||||
#elif defined(HAVE_POLL_FINE)
|
||||
(void)poll((void *)0, 0, (int)ms);
|
||||
#else
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = ms / 1000L;
|
||||
ms = ms % 1000L;
|
||||
timeout.tv_usec = (int)ms * 1000;
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
#endif
|
||||
}
|
28
module/Vendor/CURL/src/tool_sleep.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_sleep.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_SLEEP_H
|
||||
#define HEADER_CURL_TOOL_SLEEP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
void tool_go_sleep(long ms);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_SLEEP_H */
|
42
module/Vendor/CURL/src/tool_strdup.c
vendored
Normal file
42
module/Vendor/CURL/src/tool_strdup.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_strdup.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
char *strdup(const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char *newstr;
|
||||
|
||||
if(!str)
|
||||
return (char *)NULL;
|
||||
|
||||
len = strlen(str) + 1;
|
||||
|
||||
newstr = malloc(len);
|
||||
if(!newstr)
|
||||
return (char *)NULL;
|
||||
|
||||
memcpy(newstr, str, len);
|
||||
return newstr;
|
||||
}
|
||||
#endif
|
30
module/Vendor/CURL/src/tool_strdup.h
vendored
Normal file
30
module/Vendor/CURL/src/tool_strdup.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef HEADER_TOOL_STRDUP_H
|
||||
#define HEADER_TOOL_STRDUP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
extern char *strdup(const char *str);
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_TOOL_STRDUP_H */
|
705
module/Vendor/CURL/src/tool_urlglob.c
vendored
Normal file
705
module/Vendor/CURL/src/tool_urlglob.c
vendored
Normal file
@ -0,0 +1,705 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_urlglob.h"
|
||||
#include "tool_vms.h"
|
||||
#include "dynbuf.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#define GLOBERROR(string, column, code) \
|
||||
glob->error = string, glob->pos = column, code
|
||||
|
||||
static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
|
||||
{
|
||||
struct URLPattern *pat = &glob->pattern[glob->size];
|
||||
pat->type = UPTSet;
|
||||
pat->content.Set.size = 1;
|
||||
pat->content.Set.ptr_s = 0;
|
||||
pat->globindex = -1;
|
||||
|
||||
pat->content.Set.elements = malloc(sizeof(char *));
|
||||
|
||||
if(!pat->content.Set.elements)
|
||||
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
||||
|
||||
pat->content.Set.elements[0] = malloc(len + 1);
|
||||
if(!pat->content.Set.elements[0])
|
||||
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
||||
|
||||
memcpy(pat->content.Set.elements[0], fixed, len);
|
||||
pat->content.Set.elements[0][len] = 0;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/* multiply
|
||||
*
|
||||
* Multiplies and checks for overflow.
|
||||
*/
|
||||
static int multiply(unsigned long *amount, long with)
|
||||
{
|
||||
unsigned long sum = *amount * with;
|
||||
if(!with) {
|
||||
*amount = 0;
|
||||
return 0;
|
||||
}
|
||||
if(sum/with != *amount)
|
||||
return 1; /* didn't fit, bail out */
|
||||
*amount = sum;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CURLcode glob_set(struct URLGlob *glob, char **patternp,
|
||||
size_t *posp, unsigned long *amount,
|
||||
int globindex)
|
||||
{
|
||||
/* processes a set expression with the point behind the opening '{'
|
||||
','-separated elements are collected until the next closing '}'
|
||||
*/
|
||||
struct URLPattern *pat;
|
||||
bool done = FALSE;
|
||||
char *buf = glob->glob_buffer;
|
||||
char *pattern = *patternp;
|
||||
char *opattern = pattern;
|
||||
size_t opos = *posp-1;
|
||||
|
||||
pat = &glob->pattern[glob->size];
|
||||
/* patterns 0,1,2,... correspond to size=1,3,5,... */
|
||||
pat->type = UPTSet;
|
||||
pat->content.Set.size = 0;
|
||||
pat->content.Set.ptr_s = 0;
|
||||
pat->content.Set.elements = NULL;
|
||||
pat->globindex = globindex;
|
||||
|
||||
while(!done) {
|
||||
switch (*pattern) {
|
||||
case '\0': /* URL ended while set was still open */
|
||||
return GLOBERROR("unmatched brace", opos, CURLE_URL_MALFORMAT);
|
||||
|
||||
case '{':
|
||||
case '[': /* no nested expressions at this time */
|
||||
return GLOBERROR("nested brace", *posp, CURLE_URL_MALFORMAT);
|
||||
|
||||
case '}': /* set element completed */
|
||||
if(opattern == pattern)
|
||||
return GLOBERROR("empty string within braces", *posp,
|
||||
CURLE_URL_MALFORMAT);
|
||||
|
||||
/* add 1 to size since it'll be incremented below */
|
||||
if(multiply(amount, pat->content.Set.size + 1))
|
||||
return GLOBERROR("range overflow", 0, CURLE_URL_MALFORMAT);
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case ',':
|
||||
|
||||
*buf = '\0';
|
||||
if(pat->content.Set.elements) {
|
||||
char **new_arr = realloc(pat->content.Set.elements,
|
||||
(pat->content.Set.size + 1) * sizeof(char *));
|
||||
if(!new_arr)
|
||||
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
||||
|
||||
pat->content.Set.elements = new_arr;
|
||||
}
|
||||
else
|
||||
pat->content.Set.elements = malloc(sizeof(char *));
|
||||
|
||||
if(!pat->content.Set.elements)
|
||||
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
||||
|
||||
pat->content.Set.elements[pat->content.Set.size] =
|
||||
strdup(glob->glob_buffer);
|
||||
if(!pat->content.Set.elements[pat->content.Set.size])
|
||||
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
|
||||
++pat->content.Set.size;
|
||||
|
||||
if(*pattern == '}') {
|
||||
pattern++; /* pass the closing brace */
|
||||
done = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
buf = glob->glob_buffer;
|
||||
++pattern;
|
||||
++(*posp);
|
||||
break;
|
||||
|
||||
case ']': /* illegal closing bracket */
|
||||
return GLOBERROR("unexpected close bracket", *posp, CURLE_URL_MALFORMAT);
|
||||
|
||||
case '\\': /* escaped character, skip '\' */
|
||||
if(pattern[1]) {
|
||||
++pattern;
|
||||
++(*posp);
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
*buf++ = *pattern++; /* copy character to set element */
|
||||
++(*posp);
|
||||
}
|
||||
}
|
||||
|
||||
*patternp = pattern; /* return with the new position */
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static CURLcode glob_range(struct URLGlob *glob, char **patternp,
|
||||
size_t *posp, unsigned long *amount,
|
||||
int globindex)
|
||||
{
|
||||
/* processes a range expression with the point behind the opening '['
|
||||
- char range: e.g. "a-z]", "B-Q]"
|
||||
- num range: e.g. "0-9]", "17-2000]"
|
||||
- num range with leading zeros: e.g. "001-999]"
|
||||
expression is checked for well-formedness and collected until the next ']'
|
||||
*/
|
||||
struct URLPattern *pat;
|
||||
int rc;
|
||||
char *pattern = *patternp;
|
||||
char *c;
|
||||
|
||||
pat = &glob->pattern[glob->size];
|
||||
pat->globindex = globindex;
|
||||
|
||||
if(ISALPHA(*pattern)) {
|
||||
/* character range detected */
|
||||
char min_c;
|
||||
char max_c;
|
||||
char end_c;
|
||||
unsigned long step = 1;
|
||||
|
||||
pat->type = UPTCharRange;
|
||||
|
||||
rc = sscanf(pattern, "%c-%c%c", &min_c, &max_c, &end_c);
|
||||
|
||||
if(rc == 3) {
|
||||
if(end_c == ':') {
|
||||
char *endp;
|
||||
errno = 0;
|
||||
step = strtoul(&pattern[4], &endp, 10);
|
||||
if(errno || &pattern[4] == endp || *endp != ']')
|
||||
step = 0;
|
||||
else
|
||||
pattern = endp + 1;
|
||||
}
|
||||
else if(end_c != ']')
|
||||
/* then this is wrong */
|
||||
rc = 0;
|
||||
else
|
||||
/* end_c == ']' */
|
||||
pattern += 4;
|
||||
}
|
||||
|
||||
*posp += (pattern - *patternp);
|
||||
|
||||
if(rc != 3 || !step || step > (unsigned)INT_MAX ||
|
||||
(min_c == max_c && step != 1) ||
|
||||
(min_c != max_c && (min_c > max_c || step > (unsigned)(max_c - min_c) ||
|
||||
(max_c - min_c) > ('z' - 'a'))))
|
||||
/* the pattern is not well-formed */
|
||||
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
|
||||
|
||||
/* if there was a ":[num]" thing, use that as step or else use 1 */
|
||||
pat->content.CharRange.step = (int)step;
|
||||
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
|
||||
pat->content.CharRange.max_c = max_c;
|
||||
|
||||
if(multiply(amount, ((pat->content.CharRange.max_c -
|
||||
pat->content.CharRange.min_c) /
|
||||
pat->content.CharRange.step + 1)))
|
||||
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
|
||||
}
|
||||
else if(ISDIGIT(*pattern)) {
|
||||
/* numeric range detected */
|
||||
unsigned long min_n;
|
||||
unsigned long max_n = 0;
|
||||
unsigned long step_n = 0;
|
||||
char *endp;
|
||||
|
||||
pat->type = UPTNumRange;
|
||||
pat->content.NumRange.padlength = 0;
|
||||
|
||||
if(*pattern == '0') {
|
||||
/* leading zero specified, count them! */
|
||||
c = pattern;
|
||||
while(ISDIGIT(*c)) {
|
||||
c++;
|
||||
++pat->content.NumRange.padlength; /* padding length is set for all
|
||||
instances of this pattern */
|
||||
}
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
min_n = strtoul(pattern, &endp, 10);
|
||||
if(errno || (endp == pattern))
|
||||
endp = NULL;
|
||||
else {
|
||||
if(*endp != '-')
|
||||
endp = NULL;
|
||||
else {
|
||||
pattern = endp + 1;
|
||||
while(*pattern && ISBLANK(*pattern))
|
||||
pattern++;
|
||||
if(!ISDIGIT(*pattern)) {
|
||||
endp = NULL;
|
||||
goto fail;
|
||||
}
|
||||
errno = 0;
|
||||
max_n = strtoul(pattern, &endp, 10);
|
||||
if(errno)
|
||||
/* overflow */
|
||||
endp = NULL;
|
||||
else if(*endp == ':') {
|
||||
pattern = endp + 1;
|
||||
errno = 0;
|
||||
step_n = strtoul(pattern, &endp, 10);
|
||||
if(errno)
|
||||
/* over/underflow situation */
|
||||
endp = NULL;
|
||||
}
|
||||
else
|
||||
step_n = 1;
|
||||
if(endp && (*endp == ']')) {
|
||||
pattern = endp + 1;
|
||||
}
|
||||
else
|
||||
endp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
*posp += (pattern - *patternp);
|
||||
|
||||
if(!endp || !step_n ||
|
||||
(min_n == max_n && step_n != 1) ||
|
||||
(min_n != max_n && (min_n > max_n || step_n > (max_n - min_n))))
|
||||
/* the pattern is not well-formed */
|
||||
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
|
||||
|
||||
/* typecasting to ints are fine here since we make sure above that we
|
||||
are within 31 bits */
|
||||
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n;
|
||||
pat->content.NumRange.max_n = max_n;
|
||||
pat->content.NumRange.step = step_n;
|
||||
|
||||
if(multiply(amount, ((pat->content.NumRange.max_n -
|
||||
pat->content.NumRange.min_n) /
|
||||
pat->content.NumRange.step + 1)))
|
||||
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
|
||||
}
|
||||
else
|
||||
return GLOBERROR("bad range specification", *posp, CURLE_URL_MALFORMAT);
|
||||
|
||||
*patternp = pattern;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#define MAX_IP6LEN 128
|
||||
|
||||
static bool peek_ipv6(const char *str, size_t *skip)
|
||||
{
|
||||
/*
|
||||
* Scan for a potential IPv6 literal.
|
||||
* - Valid globs contain a hyphen and <= 1 colon.
|
||||
* - IPv6 literals contain no hyphens and >= 2 colons.
|
||||
*/
|
||||
char hostname[MAX_IP6LEN];
|
||||
CURLU *u;
|
||||
char *endbr = strchr(str, ']');
|
||||
size_t hlen;
|
||||
CURLUcode rc;
|
||||
if(!endbr)
|
||||
return FALSE;
|
||||
|
||||
hlen = endbr - str + 1;
|
||||
if(hlen >= MAX_IP6LEN)
|
||||
return FALSE;
|
||||
|
||||
u = curl_url();
|
||||
if(!u)
|
||||
return FALSE;
|
||||
|
||||
memcpy(hostname, str, hlen);
|
||||
hostname[hlen] = 0;
|
||||
|
||||
/* ask to "guess scheme" as then it works without a https:// prefix */
|
||||
rc = curl_url_set(u, CURLUPART_URL, hostname, CURLU_GUESS_SCHEME);
|
||||
|
||||
curl_url_cleanup(u);
|
||||
if(!rc)
|
||||
*skip = hlen;
|
||||
return rc ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
static CURLcode glob_parse(struct URLGlob *glob, char *pattern,
|
||||
size_t pos, unsigned long *amount)
|
||||
{
|
||||
/* processes a literal string component of a URL
|
||||
special characters '{' and '[' branch to set/range processing functions
|
||||
*/
|
||||
CURLcode res = CURLE_OK;
|
||||
int globindex = 0; /* count "actual" globs */
|
||||
|
||||
*amount = 1;
|
||||
|
||||
while(*pattern && !res) {
|
||||
char *buf = glob->glob_buffer;
|
||||
size_t sublen = 0;
|
||||
while(*pattern && *pattern != '{') {
|
||||
if(*pattern == '[') {
|
||||
/* skip over IPv6 literals and [] */
|
||||
size_t skip = 0;
|
||||
if(!peek_ipv6(pattern, &skip) && (pattern[1] == ']'))
|
||||
skip = 2;
|
||||
if(skip) {
|
||||
memcpy(buf, pattern, skip);
|
||||
buf += skip;
|
||||
pattern += skip;
|
||||
sublen += skip;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(*pattern == '}' || *pattern == ']')
|
||||
return GLOBERROR("unmatched close brace/bracket", pos,
|
||||
CURLE_URL_MALFORMAT);
|
||||
|
||||
/* only allow \ to escape known "special letters" */
|
||||
if(*pattern == '\\' &&
|
||||
(*(pattern + 1) == '{' || *(pattern + 1) == '[' ||
|
||||
*(pattern + 1) == '}' || *(pattern + 1) == ']') ) {
|
||||
|
||||
/* escape character, skip '\' */
|
||||
++pattern;
|
||||
++pos;
|
||||
}
|
||||
*buf++ = *pattern++; /* copy character to literal */
|
||||
++pos;
|
||||
sublen++;
|
||||
}
|
||||
if(sublen) {
|
||||
/* we got a literal string, add it as a single-item list */
|
||||
*buf = '\0';
|
||||
res = glob_fixed(glob, glob->glob_buffer, sublen);
|
||||
}
|
||||
else {
|
||||
switch (*pattern) {
|
||||
case '\0': /* done */
|
||||
break;
|
||||
|
||||
case '{':
|
||||
/* process set pattern */
|
||||
pattern++;
|
||||
pos++;
|
||||
res = glob_set(glob, &pattern, &pos, amount, globindex++);
|
||||
break;
|
||||
|
||||
case '[':
|
||||
/* process range pattern */
|
||||
pattern++;
|
||||
pos++;
|
||||
res = glob_range(glob, &pattern, &pos, amount, globindex++);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(++glob->size >= GLOB_PATTERN_NUM)
|
||||
return GLOBERROR("too many globs", pos, CURLE_URL_MALFORMAT);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
CURLcode glob_url(struct URLGlob **glob, char *url, unsigned long *urlnum,
|
||||
FILE *error)
|
||||
{
|
||||
/*
|
||||
* We can deal with any-size, just make a buffer with the same length
|
||||
* as the specified URL!
|
||||
*/
|
||||
struct URLGlob *glob_expand;
|
||||
unsigned long amount = 0;
|
||||
char *glob_buffer;
|
||||
CURLcode res;
|
||||
|
||||
*glob = NULL;
|
||||
|
||||
glob_buffer = malloc(strlen(url) + 1);
|
||||
if(!glob_buffer)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
glob_buffer[0] = 0;
|
||||
|
||||
glob_expand = calloc(1, sizeof(struct URLGlob));
|
||||
if(!glob_expand) {
|
||||
Curl_safefree(glob_buffer);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
glob_expand->urllen = strlen(url);
|
||||
glob_expand->glob_buffer = glob_buffer;
|
||||
|
||||
res = glob_parse(glob_expand, url, 1, &amount);
|
||||
if(!res)
|
||||
*urlnum = amount;
|
||||
else {
|
||||
if(error && glob_expand->error) {
|
||||
char text[512];
|
||||
const char *t;
|
||||
if(glob_expand->pos) {
|
||||
msnprintf(text, sizeof(text), "%s in URL position %zu:\n%s\n%*s^",
|
||||
glob_expand->error,
|
||||
glob_expand->pos, url, glob_expand->pos - 1, " ");
|
||||
t = text;
|
||||
}
|
||||
else
|
||||
t = glob_expand->error;
|
||||
|
||||
/* send error description to the error-stream */
|
||||
fprintf(error, "curl: (%d) %s\n", res, t);
|
||||
}
|
||||
/* it failed, we cleanup */
|
||||
glob_cleanup(glob_expand);
|
||||
*urlnum = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
*glob = glob_expand;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void glob_cleanup(struct URLGlob *glob)
|
||||
{
|
||||
size_t i;
|
||||
int elem;
|
||||
|
||||
if(!glob)
|
||||
return;
|
||||
|
||||
for(i = 0; i < glob->size; i++) {
|
||||
if((glob->pattern[i].type == UPTSet) &&
|
||||
(glob->pattern[i].content.Set.elements)) {
|
||||
for(elem = glob->pattern[i].content.Set.size - 1;
|
||||
elem >= 0;
|
||||
--elem) {
|
||||
Curl_safefree(glob->pattern[i].content.Set.elements[elem]);
|
||||
}
|
||||
Curl_safefree(glob->pattern[i].content.Set.elements);
|
||||
}
|
||||
}
|
||||
Curl_safefree(glob->glob_buffer);
|
||||
Curl_safefree(glob);
|
||||
}
|
||||
|
||||
CURLcode glob_next_url(char **globbed, struct URLGlob *glob)
|
||||
{
|
||||
struct URLPattern *pat;
|
||||
size_t i;
|
||||
size_t len;
|
||||
size_t buflen = glob->urllen + 1;
|
||||
char *buf = glob->glob_buffer;
|
||||
|
||||
*globbed = NULL;
|
||||
|
||||
if(!glob->beenhere)
|
||||
glob->beenhere = 1;
|
||||
else {
|
||||
bool carry = TRUE;
|
||||
|
||||
/* implement a counter over the index ranges of all patterns, starting
|
||||
with the rightmost pattern */
|
||||
for(i = 0; carry && (i < glob->size); i++) {
|
||||
carry = FALSE;
|
||||
pat = &glob->pattern[glob->size - 1 - i];
|
||||
switch(pat->type) {
|
||||
case UPTSet:
|
||||
if((pat->content.Set.elements) &&
|
||||
(++pat->content.Set.ptr_s == pat->content.Set.size)) {
|
||||
pat->content.Set.ptr_s = 0;
|
||||
carry = TRUE;
|
||||
}
|
||||
break;
|
||||
case UPTCharRange:
|
||||
pat->content.CharRange.ptr_c =
|
||||
(char)(pat->content.CharRange.step +
|
||||
(int)((unsigned char)pat->content.CharRange.ptr_c));
|
||||
if(pat->content.CharRange.ptr_c > pat->content.CharRange.max_c) {
|
||||
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c;
|
||||
carry = TRUE;
|
||||
}
|
||||
break;
|
||||
case UPTNumRange:
|
||||
pat->content.NumRange.ptr_n += pat->content.NumRange.step;
|
||||
if(pat->content.NumRange.ptr_n > pat->content.NumRange.max_n) {
|
||||
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n;
|
||||
carry = TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("internal error: invalid pattern type (%d)\n", (int)pat->type);
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
}
|
||||
if(carry) { /* first pattern ptr has run into overflow, done! */
|
||||
return CURLE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < glob->size; ++i) {
|
||||
pat = &glob->pattern[i];
|
||||
switch(pat->type) {
|
||||
case UPTSet:
|
||||
if(pat->content.Set.elements) {
|
||||
msnprintf(buf, buflen, "%s",
|
||||
pat->content.Set.elements[pat->content.Set.ptr_s]);
|
||||
len = strlen(buf);
|
||||
buf += len;
|
||||
buflen -= len;
|
||||
}
|
||||
break;
|
||||
case UPTCharRange:
|
||||
if(buflen) {
|
||||
*buf++ = pat->content.CharRange.ptr_c;
|
||||
*buf = '\0';
|
||||
buflen--;
|
||||
}
|
||||
break;
|
||||
case UPTNumRange:
|
||||
msnprintf(buf, buflen, "%0*lu",
|
||||
pat->content.NumRange.padlength,
|
||||
pat->content.NumRange.ptr_n);
|
||||
len = strlen(buf);
|
||||
buf += len;
|
||||
buflen -= len;
|
||||
break;
|
||||
default:
|
||||
printf("internal error: invalid pattern type (%d)\n", (int)pat->type);
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
*globbed = strdup(glob->glob_buffer);
|
||||
if(!*globbed)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#define MAX_OUTPUT_GLOB_LENGTH (10*1024)
|
||||
|
||||
CURLcode glob_match_url(char **result, char *filename, struct URLGlob *glob)
|
||||
{
|
||||
char numbuf[18];
|
||||
char *appendthis = (char *)"";
|
||||
size_t appendlen = 0;
|
||||
struct curlx_dynbuf dyn;
|
||||
|
||||
*result = NULL;
|
||||
|
||||
/* We cannot use the glob_buffer for storage since the filename may be
|
||||
* longer than the URL we use.
|
||||
*/
|
||||
curlx_dyn_init(&dyn, MAX_OUTPUT_GLOB_LENGTH);
|
||||
|
||||
while(*filename) {
|
||||
if(*filename == '#' && ISDIGIT(filename[1])) {
|
||||
char *ptr = filename;
|
||||
unsigned long num = strtoul(&filename[1], &filename, 10);
|
||||
struct URLPattern *pat = NULL;
|
||||
|
||||
if(num && (num < glob->size)) {
|
||||
unsigned long i;
|
||||
num--; /* make it zero based */
|
||||
/* find the correct glob entry */
|
||||
for(i = 0; i<glob->size; i++) {
|
||||
if(glob->pattern[i].globindex == (int)num) {
|
||||
pat = &glob->pattern[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(pat) {
|
||||
switch(pat->type) {
|
||||
case UPTSet:
|
||||
if(pat->content.Set.elements) {
|
||||
appendthis = pat->content.Set.elements[pat->content.Set.ptr_s];
|
||||
appendlen =
|
||||
strlen(pat->content.Set.elements[pat->content.Set.ptr_s]);
|
||||
}
|
||||
break;
|
||||
case UPTCharRange:
|
||||
numbuf[0] = pat->content.CharRange.ptr_c;
|
||||
numbuf[1] = 0;
|
||||
appendthis = numbuf;
|
||||
appendlen = 1;
|
||||
break;
|
||||
case UPTNumRange:
|
||||
msnprintf(numbuf, sizeof(numbuf), "%0*lu",
|
||||
pat->content.NumRange.padlength,
|
||||
pat->content.NumRange.ptr_n);
|
||||
appendthis = numbuf;
|
||||
appendlen = strlen(numbuf);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "internal error: invalid pattern type (%d)\n",
|
||||
(int)pat->type);
|
||||
curlx_dyn_free(&dyn);
|
||||
return CURLE_FAILED_INIT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* #[num] out of range, use the #[num] in the output */
|
||||
filename = ptr;
|
||||
appendthis = filename++;
|
||||
appendlen = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
appendthis = filename++;
|
||||
appendlen = 1;
|
||||
}
|
||||
if(curlx_dyn_addn(&dyn, appendthis, appendlen))
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
{
|
||||
char *sanitized;
|
||||
SANITIZEcode sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn),
|
||||
(SANITIZE_ALLOW_PATH |
|
||||
SANITIZE_ALLOW_RESERVED));
|
||||
curlx_dyn_free(&dyn);
|
||||
if(sc)
|
||||
return CURLE_URL_MALFORMAT;
|
||||
*result = sanitized;
|
||||
return CURLE_OK;
|
||||
}
|
||||
#else
|
||||
*result = curlx_dyn_ptr(&dyn);
|
||||
return CURLE_OK;
|
||||
#endif /* MSDOS || WIN32 */
|
||||
}
|
76
module/Vendor/CURL/src/tool_urlglob.h
vendored
Normal file
76
module/Vendor/CURL/src/tool_urlglob.h
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef HEADER_CURL_TOOL_URLGLOB_H
|
||||
#define HEADER_CURL_TOOL_URLGLOB_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
typedef enum {
|
||||
UPTSet = 1,
|
||||
UPTCharRange,
|
||||
UPTNumRange
|
||||
} URLPatternType;
|
||||
|
||||
struct URLPattern {
|
||||
URLPatternType type;
|
||||
int globindex; /* the number of this particular glob or -1 if not used
|
||||
within {} or [] */
|
||||
union {
|
||||
struct {
|
||||
char **elements;
|
||||
int size;
|
||||
int ptr_s;
|
||||
} Set;
|
||||
struct {
|
||||
char min_c;
|
||||
char max_c;
|
||||
char ptr_c;
|
||||
int step;
|
||||
} CharRange;
|
||||
struct {
|
||||
unsigned long min_n;
|
||||
unsigned long max_n;
|
||||
int padlength;
|
||||
unsigned long ptr_n;
|
||||
unsigned long step;
|
||||
} NumRange;
|
||||
} content;
|
||||
};
|
||||
|
||||
/* the total number of globs supported */
|
||||
#define GLOB_PATTERN_NUM 100
|
||||
|
||||
struct URLGlob {
|
||||
struct URLPattern pattern[GLOB_PATTERN_NUM];
|
||||
size_t size;
|
||||
size_t urllen;
|
||||
char *glob_buffer;
|
||||
char beenhere;
|
||||
const char *error; /* error message */
|
||||
size_t pos; /* column position of error or 0 */
|
||||
};
|
||||
|
||||
CURLcode glob_url(struct URLGlob**, char *, unsigned long *, FILE *);
|
||||
CURLcode glob_next_url(char **, struct URLGlob *);
|
||||
CURLcode glob_match_url(char **, char *, struct URLGlob *);
|
||||
void glob_cleanup(struct URLGlob *glob);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_URLGLOB_H */
|
135
module/Vendor/CURL/src/tool_util.c
vendored
Normal file
135
module/Vendor/CURL/src/tool_util.c
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#include "tool_util.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#if defined(WIN32) && !defined(MSDOS)
|
||||
|
||||
/* set in win32_init() */
|
||||
extern LARGE_INTEGER tool_freq;
|
||||
extern bool tool_isVistaOrGreater;
|
||||
|
||||
/* In case of bug fix this function has a counterpart in timeval.c */
|
||||
struct timeval tvnow(void)
|
||||
{
|
||||
struct timeval now;
|
||||
if(tool_isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
|
||||
LARGE_INTEGER count;
|
||||
QueryPerformanceCounter(&count);
|
||||
now.tv_sec = (long)(count.QuadPart / tool_freq.QuadPart);
|
||||
now.tv_usec = (long)((count.QuadPart % tool_freq.QuadPart) * 1000000 /
|
||||
tool_freq.QuadPart);
|
||||
}
|
||||
else {
|
||||
/* Disable /analyze warning that GetTickCount64 is preferred */
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:28159)
|
||||
#endif
|
||||
DWORD milliseconds = GetTickCount();
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
now.tv_sec = (long)(milliseconds / 1000);
|
||||
now.tv_usec = (long)((milliseconds % 1000) * 1000);
|
||||
}
|
||||
return now;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
|
||||
|
||||
struct timeval tvnow(void)
|
||||
{
|
||||
/*
|
||||
** clock_gettime() is granted to be increased monotonically when the
|
||||
** monotonic clock is queried. Time starting point is unspecified, it
|
||||
** could be the system start-up time, the Epoch, or something else,
|
||||
** in any case the time starting point does not change once that the
|
||||
** system has started up.
|
||||
*/
|
||||
struct timeval now;
|
||||
struct timespec tsnow;
|
||||
if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
|
||||
now.tv_sec = tsnow.tv_sec;
|
||||
now.tv_usec = (int)(tsnow.tv_nsec / 1000);
|
||||
}
|
||||
/*
|
||||
** Even when the configure process has truly detected monotonic clock
|
||||
** availability, it might happen that it is not actually available at
|
||||
** run-time. When this occurs simply fallback to other time source.
|
||||
*/
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
else
|
||||
(void)gettimeofday(&now, NULL);
|
||||
#else
|
||||
else {
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
#endif
|
||||
return now;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_GETTIMEOFDAY)
|
||||
|
||||
struct timeval tvnow(void)
|
||||
{
|
||||
/*
|
||||
** gettimeofday() is not granted to be increased monotonically, due to
|
||||
** clock drifting and external source time synchronization it can jump
|
||||
** forward or backward in time.
|
||||
*/
|
||||
struct timeval now;
|
||||
(void)gettimeofday(&now, NULL);
|
||||
return now;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
struct timeval tvnow(void)
|
||||
{
|
||||
/*
|
||||
** time() returns the value of time in seconds since the Epoch.
|
||||
*/
|
||||
struct timeval now;
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
return now;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Make sure that the first argument is the more recent time, as otherwise
|
||||
* we'll get a weird negative time-diff back...
|
||||
*
|
||||
* Returns: the time difference in number of milliseconds.
|
||||
*/
|
||||
long tvdiff(struct timeval newer, struct timeval older)
|
||||
{
|
||||
return (long)(newer.tv_sec-older.tv_sec)*1000+
|
||||
(long)(newer.tv_usec-older.tv_usec)/1000;
|
||||
}
|
36
module/Vendor/CURL/src/tool_util.h
vendored
Normal file
36
module/Vendor/CURL/src/tool_util.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef HEADER_CURL_TOOL_UTIL_H
|
||||
#define HEADER_CURL_TOOL_UTIL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
struct timeval tvnow(void);
|
||||
|
||||
/*
|
||||
* Make sure that the first argument (t1) is the more recent time and t2 is
|
||||
* the older time, as otherwise you get a weird negative time-diff back...
|
||||
*
|
||||
* Returns: the time difference in number of milliseconds.
|
||||
*/
|
||||
long tvdiff(struct timeval t1, struct timeval t2);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_UTIL_H */
|
34
module/Vendor/CURL/src/tool_version.h
vendored
Normal file
34
module/Vendor/CURL/src/tool_version.h
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef HEADER_CURL_TOOL_VERSION_H
|
||||
#define HEADER_CURL_TOOL_VERSION_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include <curl/curlver.h>
|
||||
|
||||
#define CURL_NAME "curl"
|
||||
#define CURL_COPYRIGHT LIBCURL_COPYRIGHT
|
||||
#define CURL_VERSION LIBCURL_VERSION
|
||||
#define CURL_VERSION_MAJOR LIBCURL_VERSION_MAJOR
|
||||
#define CURL_VERSION_MINOR LIBCURL_VERSION_MINOR
|
||||
#define CURL_VERSION_PATCH LIBCURL_VERSION_PATCH
|
||||
#define CURL_ID CURL_NAME " " CURL_VERSION " (" OS ") "
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_VERSION_H */
|
218
module/Vendor/CURL/src/tool_vms.c
vendored
Normal file
218
module/Vendor/CURL/src/tool_vms.c
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
#if defined(__DECC) && !defined(__VAX) && \
|
||||
defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
|
||||
#include <unixlib.h>
|
||||
#endif
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
#include "curlx.h"
|
||||
|
||||
#include "curlmsg_vms.h"
|
||||
#include "tool_vms.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
void decc$__posix_exit(int __status);
|
||||
void decc$exit(int __status);
|
||||
|
||||
static int vms_shell = -1;
|
||||
|
||||
/* VMS has a DCL shell and and also has Unix shells ported to it.
|
||||
* When curl is running under a Unix shell, we want it to be as much
|
||||
* like Unix as possible.
|
||||
*/
|
||||
int is_vms_shell(void)
|
||||
{
|
||||
char *shell;
|
||||
|
||||
/* Have we checked the shell yet? */
|
||||
if(vms_shell >= 0)
|
||||
return vms_shell;
|
||||
|
||||
shell = getenv("SHELL");
|
||||
|
||||
/* No shell, means DCL */
|
||||
if(shell == NULL) {
|
||||
vms_shell = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Have to make sure some one did not set shell to DCL */
|
||||
if(strcmp(shell, "DCL") == 0) {
|
||||
vms_shell = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
vms_shell = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* VMS has two exit() routines. When running under a Unix style shell, then
|
||||
* Unix style and the __posix_exit() routine is used.
|
||||
*
|
||||
* When running under the DCL shell, then the VMS encoded codes and decc$exit()
|
||||
* is used.
|
||||
*
|
||||
* We can not use exit() or return a code from main() because the actual
|
||||
* routine called depends on both the compiler version, compile options, and
|
||||
* feature macro settings, and one of the exit routines is hidden at compile
|
||||
* time.
|
||||
*
|
||||
* Since we want Curl to work properly under the VMS DCL shell and Unix
|
||||
* shells under VMS, this routine should compile correctly regardless of
|
||||
* the settings.
|
||||
*/
|
||||
|
||||
void vms_special_exit(int code, int vms_show)
|
||||
{
|
||||
int vms_code;
|
||||
|
||||
/* The Posix exit mode is only available after VMS 7.0 */
|
||||
#if __CRTL_VER >= 70000000
|
||||
if(is_vms_shell() == 0) {
|
||||
decc$__posix_exit(code);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(code > CURL_LAST) { /* If CURL_LAST exceeded then */
|
||||
vms_code = CURL_LAST; /* curlmsg.h is out of sync. */
|
||||
}
|
||||
else {
|
||||
vms_code = vms_cond[code] | vms_show;
|
||||
}
|
||||
decc$exit(vms_code);
|
||||
}
|
||||
|
||||
#if defined(__DECC) && !defined(__VAX) && \
|
||||
defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
|
||||
|
||||
/*
|
||||
* 2004-09-19 SMS.
|
||||
*
|
||||
* decc_init()
|
||||
*
|
||||
* On non-VAX systems, use LIB$INITIALIZE to set a collection of C
|
||||
* RTL features without using the DECC$* logical name method, nor
|
||||
* requiring the user to define the corresponding logical names.
|
||||
*/
|
||||
|
||||
/* Structure to hold a DECC$* feature name and its desired value. */
|
||||
struct decc_feat_t {
|
||||
char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
/* Array of DECC$* feature names and their desired values. */
|
||||
static struct decc_feat_t decc_feat_array[] = {
|
||||
/* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
|
||||
{ "DECC$ARGV_PARSE_STYLE", 1 },
|
||||
/* Preserve case for file names on ODS5 disks. */
|
||||
{ "DECC$EFS_CASE_PRESERVE", 1 },
|
||||
/* Enable multiple dots (and most characters) in ODS5 file names,
|
||||
while preserving VMS-ness of ";version". */
|
||||
{ "DECC$EFS_CHARSET", 1 },
|
||||
/* List terminator. */
|
||||
{ (char *)NULL, 0 }
|
||||
};
|
||||
|
||||
/* Flag to sense if decc_init() was called. */
|
||||
static int decc_init_done = -1;
|
||||
|
||||
/* LIB$INITIALIZE initialization function. */
|
||||
static void decc_init(void)
|
||||
{
|
||||
int feat_index;
|
||||
int feat_value;
|
||||
int feat_value_max;
|
||||
int feat_value_min;
|
||||
int i;
|
||||
int sts;
|
||||
|
||||
/* Set the global flag to indicate that LIB$INITIALIZE worked. */
|
||||
decc_init_done = 1;
|
||||
|
||||
/* Loop through all items in the decc_feat_array[]. */
|
||||
for(i = 0; decc_feat_array[i].name != NULL; i++) {
|
||||
|
||||
/* Get the feature index. */
|
||||
feat_index = decc$feature_get_index(decc_feat_array[i].name);
|
||||
|
||||
if(feat_index >= 0) {
|
||||
/* Valid item. Collect its properties. */
|
||||
feat_value = decc$feature_get_value(feat_index, 1);
|
||||
feat_value_min = decc$feature_get_value(feat_index, 2);
|
||||
feat_value_max = decc$feature_get_value(feat_index, 3);
|
||||
|
||||
if((decc_feat_array[i].value >= feat_value_min) &&
|
||||
(decc_feat_array[i].value <= feat_value_max)) {
|
||||
/* Valid value. Set it if necessary. */
|
||||
if(feat_value != decc_feat_array[i].value) {
|
||||
sts = decc$feature_set_value(feat_index, 1,
|
||||
decc_feat_array[i].value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Invalid DECC feature value. */
|
||||
printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",
|
||||
feat_value,
|
||||
feat_value_min, decc_feat_array[i].name, feat_value_max);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Invalid DECC feature name. */
|
||||
printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
|
||||
|
||||
#pragma nostandard
|
||||
|
||||
/* Establish the LIB$INITIALIZE PSECTs, with proper alignment and
|
||||
other attributes. Note that "nopic" is significant only on VAX. */
|
||||
#pragma extern_model save
|
||||
#pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrt
|
||||
const int spare[8] = {0};
|
||||
#pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrt
|
||||
void (*const x_decc_init)() = decc_init;
|
||||
#pragma extern_model restore
|
||||
|
||||
/* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
|
||||
#pragma extern_model save
|
||||
int LIB$INITIALIZE(void);
|
||||
#pragma extern_model strict_refdef
|
||||
int dmy_lib$initialize = (int) LIB$INITIALIZE;
|
||||
#pragma extern_model restore
|
||||
|
||||
#pragma standard
|
||||
|
||||
#endif /* __DECC && !__VAX && __CRTL_VER && __CRTL_VER >= 70301000 */
|
||||
|
||||
#endif /* __VMS */
|
46
module/Vendor/CURL/src/tool_vms.h
vendored
Normal file
46
module/Vendor/CURL/src/tool_vms.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef HEADER_CURL_TOOL_VMS_H
|
||||
#define HEADER_CURL_TOOL_VMS_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef __VMS
|
||||
|
||||
/*
|
||||
* Forward-declaration of global variable vms_show defined
|
||||
* in tool_main.c, used in main() as parameter for function
|
||||
* vms_special_exit() to allow proper curl tool exiting.
|
||||
*/
|
||||
extern int vms_show;
|
||||
|
||||
int is_vms_shell(void);
|
||||
void vms_special_exit(int code, int vms_show);
|
||||
|
||||
#undef exit
|
||||
#define exit(__code) vms_special_exit((__code), (0))
|
||||
|
||||
#define VMS_STS(c,f,e,s) (((c&0xF)<<28)|((f&0xFFF)<<16)|((e&0x1FFF)<3)|(s&7))
|
||||
#define VMSSTS_HIDE VMS_STS(1,0,0,0)
|
||||
|
||||
#endif /* __VMS */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_VMS_H */
|
394
module/Vendor/CURL/src/tool_writeout.c
vendored
Normal file
394
module/Vendor/CURL/src/tool_writeout.c
vendored
Normal file
@ -0,0 +1,394 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_writeout.h"
|
||||
#include "tool_writeout_json.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
static const struct writeoutvar variables[] = {
|
||||
{"content_type", VAR_CONTENT_TYPE, 0, CURLINFO_CONTENT_TYPE, JSON_STRING},
|
||||
{"filename_effective", VAR_EFFECTIVE_FILENAME, 0, 0, JSON_FILENAME},
|
||||
{"exitcode", VAR_EXITCODE, 0, 0, JSON_LONG},
|
||||
{"errormsg", VAR_ERRORMSG, 0, 0, JSON_STRING},
|
||||
{"ftp_entry_path", VAR_FTP_ENTRY_PATH, 0, CURLINFO_FTP_ENTRY_PATH,
|
||||
JSON_STRING},
|
||||
{"http_code", VAR_HTTP_CODE, 0, CURLINFO_RESPONSE_CODE, JSON_LONG},
|
||||
{"http_connect", VAR_HTTP_CODE_PROXY, 0, CURLINFO_HTTP_CONNECTCODE,
|
||||
JSON_LONG},
|
||||
{"http_version", VAR_HTTP_VERSION, 0, CURLINFO_HTTP_VERSION, JSON_VERSION},
|
||||
{"json", VAR_JSON, 1, 0, JSON_NONE},
|
||||
{"local_ip", VAR_LOCAL_IP, 0, CURLINFO_LOCAL_IP, JSON_STRING},
|
||||
{"local_port", VAR_LOCAL_PORT, 0, CURLINFO_LOCAL_PORT, JSON_LONG},
|
||||
{"method", VAR_EFFECTIVE_METHOD, 0, CURLINFO_EFFECTIVE_METHOD, JSON_STRING},
|
||||
{"num_connects", VAR_NUM_CONNECTS, 0, CURLINFO_NUM_CONNECTS, JSON_LONG},
|
||||
{"num_headers", VAR_NUM_HEADERS, 0, 0, JSON_LONG},
|
||||
{"num_redirects", VAR_REDIRECT_COUNT, 0, CURLINFO_REDIRECT_COUNT, JSON_LONG},
|
||||
{"onerror", VAR_ONERROR, 1, 0, JSON_NONE},
|
||||
{"proxy_ssl_verify_result", VAR_PROXY_SSL_VERIFY_RESULT, 0,
|
||||
CURLINFO_PROXY_SSL_VERIFYRESULT, JSON_LONG},
|
||||
{"redirect_url", VAR_REDIRECT_URL, 0, CURLINFO_REDIRECT_URL, JSON_STRING},
|
||||
{"remote_ip", VAR_PRIMARY_IP, 0, CURLINFO_PRIMARY_IP, JSON_STRING},
|
||||
{"remote_port", VAR_PRIMARY_PORT, 0, CURLINFO_PRIMARY_PORT, JSON_LONG},
|
||||
{"response_code", VAR_HTTP_CODE, 0, CURLINFO_RESPONSE_CODE, JSON_LONG},
|
||||
{"scheme", VAR_SCHEME, 0, CURLINFO_SCHEME, JSON_STRING},
|
||||
{"size_download", VAR_SIZE_DOWNLOAD, 0, CURLINFO_SIZE_DOWNLOAD_T,
|
||||
JSON_OFFSET},
|
||||
{"size_header", VAR_HEADER_SIZE, 0, CURLINFO_HEADER_SIZE, JSON_LONG},
|
||||
{"size_request", VAR_REQUEST_SIZE, 0, CURLINFO_REQUEST_SIZE, JSON_LONG},
|
||||
{"size_upload", VAR_SIZE_UPLOAD, 0, CURLINFO_SIZE_UPLOAD_T, JSON_OFFSET},
|
||||
{"speed_download", VAR_SPEED_DOWNLOAD, 0, CURLINFO_SPEED_DOWNLOAD_T,
|
||||
JSON_OFFSET},
|
||||
{"speed_upload", VAR_SPEED_UPLOAD, 0, CURLINFO_SPEED_UPLOAD_T, JSON_OFFSET},
|
||||
{"ssl_verify_result", VAR_SSL_VERIFY_RESULT, 0, CURLINFO_SSL_VERIFYRESULT,
|
||||
JSON_LONG},
|
||||
{"stderr", VAR_STDERR, 1, 0, JSON_NONE},
|
||||
{"stdout", VAR_STDOUT, 1, 0, JSON_NONE},
|
||||
{"time_appconnect", VAR_APPCONNECT_TIME, 0, CURLINFO_APPCONNECT_TIME_T,
|
||||
JSON_TIME},
|
||||
{"time_connect", VAR_CONNECT_TIME, 0, CURLINFO_CONNECT_TIME_T, JSON_TIME},
|
||||
{"time_namelookup", VAR_NAMELOOKUP_TIME, 0, CURLINFO_NAMELOOKUP_TIME_T,
|
||||
JSON_TIME},
|
||||
{"time_pretransfer", VAR_PRETRANSFER_TIME, 0, CURLINFO_PRETRANSFER_TIME_T,
|
||||
JSON_TIME},
|
||||
{"time_redirect", VAR_REDIRECT_TIME, 0, CURLINFO_REDIRECT_TIME_T, JSON_TIME},
|
||||
{"time_starttransfer", VAR_STARTTRANSFER_TIME, 0,
|
||||
CURLINFO_STARTTRANSFER_TIME_T, JSON_TIME},
|
||||
{"time_total", VAR_TOTAL_TIME, 0, CURLINFO_TOTAL_TIME_T, JSON_TIME},
|
||||
{"url", VAR_INPUT_URL, 0, 0, JSON_STRING},
|
||||
{"url_effective", VAR_EFFECTIVE_URL, 0, CURLINFO_EFFECTIVE_URL, JSON_STRING},
|
||||
{"urlnum", VAR_URLNUM, 0, 0, JSON_LONG},
|
||||
{NULL, VAR_NONE, 1, 0, JSON_NONE}
|
||||
};
|
||||
|
||||
static void us2sec(FILE *stream, curl_off_t us)
|
||||
{
|
||||
curl_off_t secs = us / 1000000;
|
||||
us %= 1000000;
|
||||
fprintf(stream, "%" CURL_FORMAT_CURL_OFF_TU ".%06" CURL_FORMAT_CURL_OFF_TU,
|
||||
secs, us);
|
||||
}
|
||||
|
||||
void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo,
|
||||
CURLcode result)
|
||||
{
|
||||
FILE *stream = stdout;
|
||||
const char *ptr = writeinfo;
|
||||
char *stringp = NULL;
|
||||
long longinfo;
|
||||
curl_off_t offinfo;
|
||||
bool done = FALSE;
|
||||
|
||||
while(ptr && *ptr && !done) {
|
||||
if('%' == *ptr && ptr[1]) {
|
||||
if('%' == ptr[1]) {
|
||||
/* an escaped %-letter */
|
||||
fputc('%', stream);
|
||||
ptr += 2;
|
||||
}
|
||||
else {
|
||||
/* this is meant as a variable to output */
|
||||
char *end;
|
||||
if('{' == ptr[1]) {
|
||||
char keepit;
|
||||
int i;
|
||||
bool match = FALSE;
|
||||
end = strchr(ptr, '}');
|
||||
ptr += 2; /* pass the % and the { */
|
||||
if(!end) {
|
||||
fputs("%{", stream);
|
||||
continue;
|
||||
}
|
||||
keepit = *end;
|
||||
*end = 0; /* null-terminate */
|
||||
for(i = 0; variables[i].name; i++) {
|
||||
if(curl_strequal(ptr, variables[i].name)) {
|
||||
match = TRUE;
|
||||
switch(variables[i].id) {
|
||||
case VAR_ONERROR:
|
||||
if(result == CURLE_OK)
|
||||
/* this isn't error so skip the rest */
|
||||
done = TRUE;
|
||||
break;
|
||||
case VAR_EXITCODE:
|
||||
fprintf(stream, "%d", (int)result);
|
||||
break;
|
||||
case VAR_ERRORMSG:
|
||||
fputs(per->errorbuffer[0] ? per->errorbuffer :
|
||||
curl_easy_strerror(result), stream);
|
||||
break;
|
||||
case VAR_INPUT_URL:
|
||||
if(per->this_url)
|
||||
fputs(per->this_url, stream);
|
||||
break;
|
||||
case VAR_URLNUM:
|
||||
fprintf(stream, "%u", per->urlnum);
|
||||
break;
|
||||
case VAR_EFFECTIVE_URL:
|
||||
if((CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
|
||||
&& stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_EFFECTIVE_METHOD:
|
||||
if((CURLE_OK == curl_easy_getinfo(curl,
|
||||
CURLINFO_EFFECTIVE_METHOD,
|
||||
&stringp))
|
||||
&& stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_HTTP_CODE:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
|
||||
fprintf(stream, "%03ld", longinfo);
|
||||
break;
|
||||
case VAR_NUM_HEADERS:
|
||||
fprintf(stream, "%ld", per->num_headers);
|
||||
break;
|
||||
case VAR_HTTP_CODE_PROXY:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
|
||||
&longinfo))
|
||||
fprintf(stream, "%03ld", longinfo);
|
||||
break;
|
||||
case VAR_HEADER_SIZE:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_REQUEST_SIZE:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_NUM_CONNECTS:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_REDIRECT_COUNT:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_REDIRECT_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME_T, &offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_TOTAL_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_NAMELOOKUP_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME_T,
|
||||
&offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_CONNECT_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_APPCONNECT_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME_T,
|
||||
&offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_PRETRANSFER_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T,
|
||||
&offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_STARTTRANSFER_TIME:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME_T,
|
||||
&offinfo))
|
||||
us2sec(stream, offinfo);
|
||||
break;
|
||||
case VAR_SIZE_UPLOAD:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &offinfo))
|
||||
fprintf(stream, "%" CURL_FORMAT_CURL_OFF_TU, offinfo);
|
||||
break;
|
||||
case VAR_SIZE_DOWNLOAD:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T,
|
||||
&offinfo))
|
||||
fprintf(stream, "%" CURL_FORMAT_CURL_OFF_TU, offinfo);
|
||||
break;
|
||||
case VAR_SPEED_DOWNLOAD:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD_T,
|
||||
&offinfo))
|
||||
fprintf(stream, "%" CURL_FORMAT_CURL_OFF_TU, offinfo);
|
||||
break;
|
||||
case VAR_SPEED_UPLOAD:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD_T, &offinfo))
|
||||
fprintf(stream, "%" CURL_FORMAT_CURL_OFF_TU, offinfo);
|
||||
break;
|
||||
case VAR_CONTENT_TYPE:
|
||||
if((CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
|
||||
&& stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_FTP_ENTRY_PATH:
|
||||
if((CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
|
||||
&& stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_REDIRECT_URL:
|
||||
if((CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
|
||||
&& stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_SSL_VERIFY_RESULT:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
|
||||
&longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_PROXY_SSL_VERIFY_RESULT:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT,
|
||||
&longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_EFFECTIVE_FILENAME:
|
||||
if(per->outs.filename)
|
||||
fputs(per->outs.filename, stream);
|
||||
break;
|
||||
case VAR_PRIMARY_IP:
|
||||
if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
|
||||
&stringp)) && stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_PRIMARY_PORT:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT,
|
||||
&longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_LOCAL_IP:
|
||||
if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
|
||||
&stringp)) && stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_LOCAL_PORT:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT,
|
||||
&longinfo))
|
||||
fprintf(stream, "%ld", longinfo);
|
||||
break;
|
||||
case VAR_HTTP_VERSION:
|
||||
if(CURLE_OK ==
|
||||
curl_easy_getinfo(curl, CURLINFO_HTTP_VERSION,
|
||||
&longinfo)) {
|
||||
const char *version = "0";
|
||||
switch(longinfo) {
|
||||
case CURL_HTTP_VERSION_1_0:
|
||||
version = "1.0";
|
||||
break;
|
||||
case CURL_HTTP_VERSION_1_1:
|
||||
version = "1.1";
|
||||
break;
|
||||
case CURL_HTTP_VERSION_2_0:
|
||||
version = "2";
|
||||
break;
|
||||
case CURL_HTTP_VERSION_3:
|
||||
version = "3";
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stream, version);
|
||||
}
|
||||
break;
|
||||
case VAR_SCHEME:
|
||||
if((CURLE_OK == curl_easy_getinfo(curl, CURLINFO_SCHEME,
|
||||
&stringp)) && stringp)
|
||||
fputs(stringp, stream);
|
||||
break;
|
||||
case VAR_STDOUT:
|
||||
stream = stdout;
|
||||
break;
|
||||
case VAR_STDERR:
|
||||
stream = stderr;
|
||||
break;
|
||||
case VAR_JSON:
|
||||
ourWriteOutJSON(variables, curl, per, stream);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!match) {
|
||||
fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
|
||||
}
|
||||
ptr = end + 1; /* pass the end */
|
||||
*end = keepit;
|
||||
}
|
||||
else {
|
||||
/* illegal syntax, then just output the characters that are used */
|
||||
fputc('%', stream);
|
||||
fputc(ptr[1], stream);
|
||||
ptr += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if('\\' == *ptr && ptr[1]) {
|
||||
switch(ptr[1]) {
|
||||
case 'r':
|
||||
fputc('\r', stream);
|
||||
break;
|
||||
case 'n':
|
||||
fputc('\n', stream);
|
||||
break;
|
||||
case 't':
|
||||
fputc('\t', stream);
|
||||
break;
|
||||
default:
|
||||
/* unknown, just output this */
|
||||
fputc(*ptr, stream);
|
||||
fputc(ptr[1], stream);
|
||||
break;
|
||||
}
|
||||
ptr += 2;
|
||||
}
|
||||
else {
|
||||
fputc(*ptr, stream);
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
93
module/Vendor/CURL/src/tool_writeout.h
vendored
Normal file
93
module/Vendor/CURL/src/tool_writeout.h
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef HEADER_CURL_TOOL_WRITEOUT_H
|
||||
#define HEADER_CURL_TOOL_WRITEOUT_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_operate.h"
|
||||
|
||||
typedef enum {
|
||||
VAR_NONE, /* must be the first */
|
||||
VAR_APPCONNECT_TIME,
|
||||
VAR_CONNECT_TIME,
|
||||
VAR_CONTENT_TYPE,
|
||||
VAR_EFFECTIVE_FILENAME,
|
||||
VAR_EFFECTIVE_METHOD,
|
||||
VAR_EFFECTIVE_URL,
|
||||
VAR_ERRORMSG,
|
||||
VAR_EXITCODE,
|
||||
VAR_FTP_ENTRY_PATH,
|
||||
VAR_HEADER_SIZE,
|
||||
VAR_HTTP_CODE,
|
||||
VAR_HTTP_CODE_PROXY,
|
||||
VAR_HTTP_VERSION,
|
||||
VAR_INPUT_URL,
|
||||
VAR_JSON,
|
||||
VAR_LOCAL_IP,
|
||||
VAR_LOCAL_PORT,
|
||||
VAR_NAMELOOKUP_TIME,
|
||||
VAR_NUM_CONNECTS,
|
||||
VAR_NUM_HEADERS,
|
||||
VAR_ONERROR,
|
||||
VAR_PRETRANSFER_TIME,
|
||||
VAR_PRIMARY_IP,
|
||||
VAR_PRIMARY_PORT,
|
||||
VAR_PROXY_SSL_VERIFY_RESULT,
|
||||
VAR_REDIRECT_COUNT,
|
||||
VAR_REDIRECT_TIME,
|
||||
VAR_REDIRECT_URL,
|
||||
VAR_REQUEST_SIZE,
|
||||
VAR_SCHEME,
|
||||
VAR_SIZE_DOWNLOAD,
|
||||
VAR_SIZE_UPLOAD,
|
||||
VAR_SPEED_DOWNLOAD,
|
||||
VAR_SPEED_UPLOAD,
|
||||
VAR_SSL_VERIFY_RESULT,
|
||||
VAR_STARTTRANSFER_TIME,
|
||||
VAR_STDERR,
|
||||
VAR_STDOUT,
|
||||
VAR_TOTAL_TIME,
|
||||
VAR_URLNUM,
|
||||
VAR_NUM_OF_VARS /* must be the last */
|
||||
} writeoutid;
|
||||
|
||||
typedef enum {
|
||||
JSON_NONE,
|
||||
JSON_STRING,
|
||||
JSON_LONG,
|
||||
JSON_OFFSET,
|
||||
JSON_TIME,
|
||||
JSON_VERSION,
|
||||
JSON_FILENAME
|
||||
} jsontype;
|
||||
|
||||
struct writeoutvar {
|
||||
const char *name;
|
||||
writeoutid id;
|
||||
int is_ctrl;
|
||||
CURLINFO cinfo;
|
||||
jsontype jsontype;
|
||||
};
|
||||
|
||||
void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo,
|
||||
CURLcode exitcode);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_WRITEOUT_H */
|
203
module/Vendor/CURL/src/tool_writeout_json.c
vendored
Normal file
203
module/Vendor/CURL/src/tool_writeout_json.c
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
|
||||
/* use our own printf() functions */
|
||||
#include "curlx.h"
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_writeout_json.h"
|
||||
#include "tool_writeout.h"
|
||||
|
||||
|
||||
static const char *http_version[] = {
|
||||
"0", /* CURL_HTTP_VERSION_NONE */
|
||||
"1", /* CURL_HTTP_VERSION_1_0 */
|
||||
"1.1", /* CURL_HTTP_VERSION_1_1 */
|
||||
"2", /* CURL_HTTP_VERSION_2 */
|
||||
"3" /* CURL_HTTP_VERSION_3 */
|
||||
};
|
||||
|
||||
static void jsonEscape(FILE *stream, const char *in)
|
||||
{
|
||||
const char *i = in;
|
||||
const char *in_end = in + strlen(in);
|
||||
|
||||
for(; i < in_end; i++) {
|
||||
switch(*i) {
|
||||
case '\\':
|
||||
fputs("\\\\", stream);
|
||||
break;
|
||||
case '\"':
|
||||
fputs("\\\"", stream);
|
||||
break;
|
||||
case '\b':
|
||||
fputs("\\b", stream);
|
||||
break;
|
||||
case '\f':
|
||||
fputs("\\f", stream);
|
||||
break;
|
||||
case '\n':
|
||||
fputs("\\n", stream);
|
||||
break;
|
||||
case '\r':
|
||||
fputs("\\r", stream);
|
||||
break;
|
||||
case '\t':
|
||||
fputs("\\t", stream);
|
||||
break;
|
||||
default:
|
||||
if (*i < 32) {
|
||||
fprintf(stream, "u%04x", *i);
|
||||
}
|
||||
else {
|
||||
fputc(*i, stream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int writeTime(FILE *str, CURL *curl, const char *key, CURLINFO ci)
|
||||
{
|
||||
curl_off_t val = 0;
|
||||
if(CURLE_OK == curl_easy_getinfo(curl, ci, &val)) {
|
||||
curl_off_t s = val / 1000000l;
|
||||
curl_off_t ms = val % 1000000l;
|
||||
fprintf(str, "\"%s\":%" CURL_FORMAT_CURL_OFF_T
|
||||
".%06" CURL_FORMAT_CURL_OFF_T, key, s, ms);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int writeString(FILE *str, CURL *curl, const char *key, CURLINFO ci)
|
||||
{
|
||||
char *valp = NULL;
|
||||
if((CURLE_OK == curl_easy_getinfo(curl, ci, &valp)) && valp) {
|
||||
fprintf(str, "\"%s\":\"", key);
|
||||
jsonEscape(str, valp);
|
||||
fprintf(str, "\"");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int writeLong(FILE *str, CURL *curl, const char *key, CURLINFO ci,
|
||||
struct per_transfer *per, const struct writeoutvar *wovar)
|
||||
{
|
||||
if(wovar->id == VAR_NUM_HEADERS) {
|
||||
fprintf(str, "\"%s\":%ld", key, per->num_headers);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
long val = 0;
|
||||
if(CURLE_OK == curl_easy_getinfo(curl, ci, &val)) {
|
||||
fprintf(str, "\"%s\":%ld", key, val);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int writeOffset(FILE *str, CURL *curl, const char *key, CURLINFO ci)
|
||||
{
|
||||
curl_off_t val = 0;
|
||||
if(CURLE_OK == curl_easy_getinfo(curl, ci, &val)) {
|
||||
fprintf(str, "\"%s\":%" CURL_FORMAT_CURL_OFF_T, key, val);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int writeFilename(FILE *str, const char *key, const char *filename)
|
||||
{
|
||||
if(filename) {
|
||||
fprintf(str, "\"%s\":\"", key);
|
||||
jsonEscape(str, filename);
|
||||
fprintf(str, "\"");
|
||||
}
|
||||
else {
|
||||
fprintf(str, "\"%s\":null", key);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int writeVersion(FILE *str, CURL *curl, const char *key, CURLINFO ci)
|
||||
{
|
||||
long version = 0;
|
||||
if(CURLE_OK == curl_easy_getinfo(curl, ci, &version) &&
|
||||
(version >= 0) &&
|
||||
(version < (long)(sizeof(http_version)/sizeof(char *)))) {
|
||||
fprintf(str, "\"%s\":\"%s\"", key, http_version[version]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ourWriteOutJSON(const struct writeoutvar mappings[], CURL *curl,
|
||||
struct per_transfer *per, FILE *stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
fputs("{", stream);
|
||||
for(i = 0; mappings[i].name != NULL; i++) {
|
||||
const struct writeoutvar *wovar = &mappings[i];
|
||||
const char *name = mappings[i].name;
|
||||
CURLINFO cinfo = mappings[i].cinfo;
|
||||
int ok = 0;
|
||||
|
||||
if(mappings[i].is_ctrl == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(mappings[i].jsontype) {
|
||||
case JSON_STRING:
|
||||
ok = writeString(stream, curl, name, cinfo);
|
||||
break;
|
||||
case JSON_LONG:
|
||||
ok = writeLong(stream, curl, name, cinfo, per, wovar);
|
||||
break;
|
||||
case JSON_OFFSET:
|
||||
ok = writeOffset(stream, curl, name, cinfo);
|
||||
break;
|
||||
case JSON_TIME:
|
||||
ok = writeTime(stream, curl, name, cinfo);
|
||||
break;
|
||||
case JSON_FILENAME:
|
||||
ok = writeFilename(stream, name, per->outs.filename);
|
||||
break;
|
||||
case JSON_VERSION:
|
||||
ok = writeVersion(stream, curl, name, cinfo);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(ok) {
|
||||
fputs(",", stream);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stream, "\"curl_version\":\"%s\"}", curl_version());
|
||||
}
|
30
module/Vendor/CURL/src/tool_writeout_json.h
vendored
Normal file
30
module/Vendor/CURL/src/tool_writeout_json.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef HEADER_CURL_TOOL_WRITEOUT_JSON_H
|
||||
#define HEADER_CURL_TOOL_WRITEOUT_JSON_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
#include "tool_writeout.h"
|
||||
|
||||
void ourWriteOutJSON(const struct writeoutvar mappings[], CURL *curl,
|
||||
struct per_transfer *per, FILE *stream);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_WRITEOUT_H */
|
139
module/Vendor/CURL/src/tool_xattr.c
vendored
Normal file
139
module/Vendor/CURL/src/tool_xattr.c
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
#ifdef HAVE_FSETXATTR
|
||||
# include <sys/xattr.h> /* header from libc, not from libattr */
|
||||
# define USE_XATTR
|
||||
#elif defined(__FreeBSD_version) && (__FreeBSD_version > 500000)
|
||||
# include <sys/types.h>
|
||||
# include <sys/extattr.h>
|
||||
# define USE_XATTR
|
||||
#endif
|
||||
|
||||
#include "tool_xattr.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
#ifdef USE_XATTR
|
||||
|
||||
/* mapping table of curl metadata to extended attribute names */
|
||||
static const struct xattr_mapping {
|
||||
const char *attr; /* name of the xattr */
|
||||
CURLINFO info;
|
||||
} mappings[] = {
|
||||
/* mappings proposed by
|
||||
* https://freedesktop.org/wiki/CommonExtendedAttributes/
|
||||
*/
|
||||
{ "user.xdg.origin.url", CURLINFO_EFFECTIVE_URL },
|
||||
{ "user.mime_type", CURLINFO_CONTENT_TYPE },
|
||||
{ NULL, CURLINFO_NONE } /* last element, abort loop here */
|
||||
};
|
||||
|
||||
/* returns TRUE if a new URL is returned, that then needs to be freed */
|
||||
/* @unittest: 1621 */
|
||||
#ifdef UNITTESTS
|
||||
bool stripcredentials(char **url);
|
||||
#else
|
||||
static
|
||||
#endif
|
||||
bool stripcredentials(char **url)
|
||||
{
|
||||
CURLU *u;
|
||||
CURLUcode uc;
|
||||
char *nurl;
|
||||
u = curl_url();
|
||||
if(u) {
|
||||
uc = curl_url_set(u, CURLUPART_URL, *url, 0);
|
||||
if(uc)
|
||||
goto error;
|
||||
|
||||
uc = curl_url_set(u, CURLUPART_USER, NULL, 0);
|
||||
if(uc)
|
||||
goto error;
|
||||
|
||||
uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0);
|
||||
if(uc)
|
||||
goto error;
|
||||
|
||||
uc = curl_url_get(u, CURLUPART_URL, &nurl, 0);
|
||||
if(uc)
|
||||
goto error;
|
||||
|
||||
curl_url_cleanup(u);
|
||||
|
||||
*url = nurl;
|
||||
return TRUE;
|
||||
}
|
||||
error:
|
||||
curl_url_cleanup(u);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* store metadata from the curl request alongside the downloaded
|
||||
* file using extended attributes
|
||||
*/
|
||||
int fwrite_xattr(CURL *curl, int fd)
|
||||
{
|
||||
int i = 0;
|
||||
int err = 0;
|
||||
|
||||
/* loop through all xattr-curlinfo pairs and abort on a set error */
|
||||
while(err == 0 && mappings[i].attr != NULL) {
|
||||
char *value = NULL;
|
||||
CURLcode result = curl_easy_getinfo(curl, mappings[i].info, &value);
|
||||
if(!result && value) {
|
||||
bool freeptr = FALSE;
|
||||
if(CURLINFO_EFFECTIVE_URL == mappings[i].info)
|
||||
freeptr = stripcredentials(&value);
|
||||
if(value) {
|
||||
#ifdef HAVE_FSETXATTR_6
|
||||
err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0, 0);
|
||||
#elif defined(HAVE_FSETXATTR_5)
|
||||
err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0);
|
||||
#elif defined(__FreeBSD_version)
|
||||
{
|
||||
ssize_t rc = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER,
|
||||
mappings[i].attr, value, strlen(value));
|
||||
/* FreeBSD's extattr_set_fd returns the length of the extended
|
||||
attribute */
|
||||
err = (rc < 0 ? -1 : 0);
|
||||
}
|
||||
#endif
|
||||
if(freeptr)
|
||||
curl_free(value);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
int fwrite_xattr(CURL *curl, int fd)
|
||||
{
|
||||
(void)curl;
|
||||
(void)fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
28
module/Vendor/CURL/src/tool_xattr.h
vendored
Normal file
28
module/Vendor/CURL/src/tool_xattr.h
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef HEADER_CURL_TOOL_XATTR_H
|
||||
#define HEADER_CURL_TOOL_XATTR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "tool_setup.h"
|
||||
|
||||
int fwrite_xattr(CURL *curl, int fd);
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_XATTR_H */
|
Reference in New Issue
Block a user