Kitxuuu commited on
Commit
c56f78d
·
verified ·
1 Parent(s): 6b5e046

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. local-test-curl-full-01/afc-curl/include/Makefile.am +28 -0
  2. local-test-curl-full-01/afc-curl/include/README.md +20 -0
  3. local-test-curl-full-01/afc-curl/lib/.gitignore +15 -0
  4. local-test-curl-full-01/afc-curl/lib/Makefile.am +171 -0
  5. local-test-curl-full-01/afc-curl/lib/Makefile.mk +340 -0
  6. local-test-curl-full-01/afc-curl/lib/altsvc.h +81 -0
  7. local-test-curl-full-01/afc-curl/lib/asyn.h +184 -0
  8. local-test-curl-full-01/afc-curl/lib/cf-h1-proxy.h +39 -0
  9. local-test-curl-full-01/afc-curl/lib/cf-h2-proxy.h +39 -0
  10. local-test-curl-full-01/afc-curl/lib/cf-haproxy.c +253 -0
  11. local-test-curl-full-01/afc-curl/lib/cf-haproxy.h +39 -0
  12. local-test-curl-full-01/afc-curl/lib/cf-https-connect.h +58 -0
  13. local-test-curl-full-01/afc-curl/lib/cfilters.h +696 -0
  14. local-test-curl-full-01/afc-curl/lib/config-os400.h +328 -0
  15. local-test-curl-full-01/afc-curl/lib/config-plan9.h +146 -0
  16. local-test-curl-full-01/afc-curl/lib/config-win32.h +511 -0
  17. local-test-curl-full-01/afc-curl/lib/content_encoding.h +34 -0
  18. local-test-curl-full-01/afc-curl/lib/curl_addrinfo.c +586 -0
  19. local-test-curl-full-01/afc-curl/lib/curl_base64.h +41 -0
  20. local-test-curl-full-01/afc-curl/lib/curl_ctype.h +51 -0
  21. local-test-curl-full-01/afc-curl/lib/curl_des.c +69 -0
  22. local-test-curl-full-01/afc-curl/lib/curl_fnmatch.h +46 -0
  23. local-test-curl-full-01/afc-curl/lib/curl_get_line.c +77 -0
  24. local-test-curl-full-01/afc-curl/lib/curl_gethostname.c +93 -0
  25. local-test-curl-full-01/afc-curl/lib/curl_gssapi.c +152 -0
  26. local-test-curl-full-01/afc-curl/lib/curl_krb5.h +52 -0
  27. local-test-curl-full-01/afc-curl/lib/curl_ldap.h +36 -0
  28. local-test-curl-full-01/afc-curl/lib/curl_md5.h +67 -0
  29. local-test-curl-full-01/afc-curl/lib/curl_memrchr.c +68 -0
  30. local-test-curl-full-01/afc-curl/lib/curl_multibyte.c +162 -0
  31. local-test-curl-full-01/afc-curl/lib/curl_multibyte.h +92 -0
  32. local-test-curl-full-01/afc-curl/lib/curl_rtmp.c +363 -0
  33. local-test-curl-full-01/afc-curl/lib/curl_sasl.c +760 -0
  34. local-test-curl-full-01/afc-curl/lib/curl_sspi.h +123 -0
  35. local-test-curl-full-01/afc-curl/lib/curl_threads.c +161 -0
  36. local-test-curl-full-01/afc-curl/lib/curl_threads.h +70 -0
  37. local-test-curl-full-01/afc-curl/lib/curlx.h +69 -0
  38. local-test-curl-full-01/afc-curl/lib/cw-out.c +473 -0
  39. local-test-curl-full-01/afc-curl/lib/dict.h +31 -0
  40. local-test-curl-full-01/afc-curl/lib/dllmain.c +81 -0
  41. local-test-curl-full-01/afc-curl/lib/doh.h +189 -0
  42. local-test-curl-full-01/afc-curl/lib/easygetopt.c +98 -0
  43. local-test-curl-full-01/afc-curl/lib/escape.h +44 -0
  44. local-test-curl-full-01/afc-curl/lib/file.c +659 -0
  45. local-test-curl-full-01/afc-curl/lib/fileinfo.c +46 -0
  46. local-test-curl-full-01/afc-curl/lib/fopen.c +158 -0
  47. local-test-curl-full-01/afc-curl/lib/fopen.h +30 -0
  48. local-test-curl-full-01/afc-curl/lib/ftp.h +167 -0
  49. local-test-curl-full-01/afc-curl/lib/getenv.c +80 -0
  50. local-test-curl-full-01/afc-curl/lib/getinfo.h +29 -0
local-test-curl-full-01/afc-curl/include/Makefile.am ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+ SUBDIRS = curl
25
+
26
+ EXTRA_DIST = README.md
27
+
28
+ AUTOMAKE_OPTIONS = foreign no-dependencies
local-test-curl-full-01/afc-curl/include/README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3
+
4
+ SPDX-License-Identifier: curl
5
+ -->
6
+
7
+ # include
8
+
9
+ Public include files for libcurl, external users.
10
+
11
+ They are all placed in the curl subdirectory here for better fit in any kind of
12
+ environment. You must include files from here using...
13
+
14
+ #include <curl/curl.h>
15
+
16
+ ... style and point the compiler's include path to the directory holding the
17
+ curl subdirectory. It makes it more likely to survive future modifications.
18
+
19
+ The public curl include files can be shared freely between different platforms
20
+ and different architectures.
local-test-curl-full-01/afc-curl/lib/.gitignore ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) Daniel Stenberg, <[email protected]>, et al.
2
+ #
3
+ # SPDX-License-Identifier: curl
4
+
5
+ *.a
6
+ *.imp
7
+ *.nlm
8
+ *.orig
9
+ *.rej
10
+ *.res
11
+ TAGS
12
+ curl_config.h
13
+ curl_config.h.in
14
+ libcurl.vers
15
+ stamp-h1
local-test-curl-full-01/afc-curl/lib/Makefile.am ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ ###########################################################################
24
+ AUTOMAKE_OPTIONS = foreign nostdinc
25
+
26
+ CMAKE_DIST = CMakeLists.txt curl_config.h.cmake
27
+
28
+ CHECKSRC_DIST = .checksrc vauth/.checksrc vquic/.checksrc vssh/.checksrc \
29
+ vtls/.checksrc
30
+
31
+ EXTRA_DIST = Makefile.mk config-win32.h config-win32ce.h config-plan9.h \
32
+ config-riscos.h config-mac.h curl_config.h.in config-dos.h libcurl.rc \
33
+ config-amigaos.h config-win32ce.h config-os400.h setup-os400.h \
34
+ $(CMAKE_DIST) setup-win32.h Makefile.soname optiontable.pl libcurl.def \
35
+ $(CHECKSRC_DIST)
36
+
37
+ lib_LTLIBRARIES = libcurl.la
38
+
39
+ if BUILD_UNITTESTS
40
+ noinst_LTLIBRARIES = libcurlu.la
41
+ else
42
+ noinst_LTLIBRARIES =
43
+ endif
44
+
45
+ # This might hold -Werror
46
+ CFLAGS += @CURL_CFLAG_EXTRAS@
47
+
48
+ # Specify our include paths here, and do it relative to $(top_srcdir) and
49
+ # $(top_builddir), to ensure that these paths which belong to the library
50
+ # being currently built and tested are searched before the library which
51
+ # might possibly already be installed in the system.
52
+ #
53
+ # $(top_srcdir)/include is for libcurl's external include files
54
+ # $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
55
+ # $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "private" files
56
+
57
+ AM_CPPFLAGS = -I$(top_srcdir)/include \
58
+ -I$(top_builddir)/lib \
59
+ -I$(top_srcdir)/lib
60
+
61
+ # Prevent LIBS from being used for all link targets
62
+ LIBS = $(BLANK_AT_MAKETIME)
63
+
64
+ include Makefile.soname
65
+
66
+ AM_CPPFLAGS += -DBUILDING_LIBCURL
67
+ AM_LDFLAGS =
68
+ AM_CFLAGS =
69
+
70
+ # Makefile.inc provides the CSOURCES and HHEADERS defines
71
+ include Makefile.inc
72
+
73
+ if USE_UNITY
74
+ # Keep these separate to avoid duplicate definitions when linking libtests
75
+ # in static mode.
76
+ curl_EXCLUDE = curl_threads.c timediff.c warnless.c
77
+ if DEBUGBUILD
78
+ # We must compile these sources separately to avoid memdebug.h redefinitions
79
+ # applying to them.
80
+ curl_EXCLUDE += memdebug.c curl_multibyte.c
81
+ endif
82
+ libcurl_unity.c: $(top_srcdir)/scripts/mk-unity.pl $(CSOURCES)
83
+ @PERL@ $(top_srcdir)/scripts/mk-unity.pl $(srcdir) $(CSOURCES) --exclude $(curl_EXCLUDE) > libcurl_unity.c
84
+
85
+ nodist_libcurl_la_SOURCES = libcurl_unity.c
86
+ libcurl_la_SOURCES = $(curl_EXCLUDE)
87
+ nodist_libcurlu_la_SOURCES = libcurl_unity.c
88
+ libcurlu_la_SOURCES = $(curl_EXCLUDE)
89
+ CLEANFILES = libcurl_unity.c
90
+ else
91
+ libcurl_la_SOURCES = $(CSOURCES) $(HHEADERS)
92
+ libcurlu_la_SOURCES = $(CSOURCES) $(HHEADERS)
93
+ endif
94
+
95
+ libcurl_la_CPPFLAGS_EXTRA =
96
+ libcurl_la_LDFLAGS_EXTRA =
97
+ libcurl_la_CFLAGS_EXTRA =
98
+
99
+ if CURL_LT_SHLIB_USE_VERSION_INFO
100
+ libcurl_la_LDFLAGS_EXTRA += $(VERSIONINFO)
101
+ endif
102
+
103
+ if CURL_LT_SHLIB_USE_NO_UNDEFINED
104
+ libcurl_la_LDFLAGS_EXTRA += -no-undefined
105
+ endif
106
+
107
+ if CURL_LT_SHLIB_USE_MIMPURE_TEXT
108
+ libcurl_la_LDFLAGS_EXTRA += -mimpure-text
109
+ endif
110
+
111
+ if CURL_LT_SHLIB_USE_VERSIONED_SYMBOLS
112
+ libcurl_la_LDFLAGS_EXTRA += -Wl,--version-script=libcurl.vers
113
+ else
114
+ # if symbol-hiding is enabled, hide them!
115
+ if DOING_CURL_SYMBOL_HIDING
116
+ libcurl_la_LDFLAGS_EXTRA += -export-symbols-regex '^curl_.*'
117
+ endif
118
+ endif
119
+
120
+ if USE_CPPFLAG_CURL_STATICLIB
121
+ libcurl_la_CPPFLAGS_EXTRA += -DCURL_STATICLIB
122
+ else
123
+ if HAVE_WINDRES
124
+ libcurl_la_SOURCES += $(LIB_RCFILES)
125
+ $(LIB_RCFILES): $(top_srcdir)/include/curl/curlver.h
126
+ endif
127
+ endif
128
+
129
+ if DOING_CURL_SYMBOL_HIDING
130
+ libcurl_la_CPPFLAGS_EXTRA += -DCURL_HIDDEN_SYMBOLS
131
+ libcurl_la_CFLAGS_EXTRA += $(CFLAG_CURL_SYMBOL_HIDING)
132
+ endif
133
+
134
+ libcurl_la_CPPFLAGS = $(AM_CPPFLAGS) $(libcurl_la_CPPFLAGS_EXTRA)
135
+ libcurl_la_LDFLAGS = $(AM_LDFLAGS) $(libcurl_la_LDFLAGS_EXTRA) $(CURL_LDFLAGS_LIB) $(LIBCURL_PC_LIBS_PRIVATE)
136
+ libcurl_la_CFLAGS = $(AM_CFLAGS) $(libcurl_la_CFLAGS_EXTRA)
137
+
138
+ libcurlu_la_CPPFLAGS = $(AM_CPPFLAGS) -DCURL_STATICLIB -DUNITTESTS
139
+ libcurlu_la_LDFLAGS = $(AM_LDFLAGS) -static $(LIBCURL_PC_LIBS_PRIVATE)
140
+ libcurlu_la_CFLAGS = $(AM_CFLAGS)
141
+
142
+ CHECKSRC = $(CS_$(V))
143
+ CS_0 = @echo " RUN " $@;
144
+ CS_1 =
145
+ CS_ = $(CS_0)
146
+
147
+ checksrc:
148
+ $(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
149
+ -W$(srcdir)/curl_config.h $(srcdir)/*.[ch] $(srcdir)/vauth/*.[ch] \
150
+ $(srcdir)/vtls/*.[ch] $(srcdir)/vquic/*.[ch] $(srcdir)/vssh/*.[ch])
151
+
152
+ if DEBUGBUILD
153
+ # for debug builds, we scan the sources on all regular make invokes
154
+ all-local: checksrc
155
+ endif
156
+
157
+ # disable the tests that are mostly causing false positives
158
+ TIDYFLAGS=-checks=-clang-analyzer-security.insecureAPI.strcpy,-clang-analyzer-optin.performance.Padding,-clang-analyzer-valist.Uninitialized,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-core.NullDereference -quiet
159
+
160
+ TIDY:=clang-tidy
161
+
162
+ tidy:
163
+ $(TIDY) $(CSOURCES) $(TIDYFLAGS) -- $(AM_CPPFLAGS) $(CPPFLAGS) -DHAVE_CONFIG_H
164
+
165
+ optiontable:
166
+ perl optiontable.pl < $(top_srcdir)/include/curl/curl.h > easyoptions.c
167
+
168
+ if HAVE_WINDRES
169
+ .rc.lo:
170
+ $(LIBTOOL) --tag=RC --mode=compile $(RC) -I$(top_srcdir)/include $(RCFLAGS) -i $< -o $@
171
+ endif
local-test-curl-full-01/afc-curl/lib/Makefile.mk ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #***************************************************************************
2
+ # _ _ ____ _
3
+ # Project ___| | | | _ \| |
4
+ # / __| | | | |_) | |
5
+ # | (__| |_| | _ <| |___
6
+ # \___|\___/|_| \_\_____|
7
+ #
8
+ # Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ #
10
+ # This software is licensed as described in the file COPYING, which
11
+ # you should have received as part of this distribution. The terms
12
+ # are also available at https://curl.se/docs/copyright.html.
13
+ #
14
+ # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ # copies of the Software, and permit persons to whom the Software is
16
+ # furnished to do so, under the terms of the COPYING file.
17
+ #
18
+ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ # KIND, either express or implied.
20
+ #
21
+ # SPDX-License-Identifier: curl
22
+ #
23
+ #***************************************************************************
24
+
25
+ # Makefile to build curl parts with GCC-like toolchains and optional features.
26
+ #
27
+ # Usage: make -f Makefile.mk CFG=-feat1[-feat2][-feat3][...]
28
+ # Example: make -f Makefile.mk CFG=-zlib-ssl-libssh2-ipv6
29
+ #
30
+ # Look for ' ?=' to find accepted customization variables.
31
+
32
+ # This script is reused by 'src' and 'docs/examples' Makefile.mk scripts.
33
+
34
+ ifndef PROOT
35
+ PROOT := ..
36
+ LOCAL := 1
37
+ endif
38
+
39
+ ### Common
40
+
41
+ CFLAGS ?=
42
+ CPPFLAGS ?=
43
+ LDFLAGS ?=
44
+ LIBS ?=
45
+
46
+ CROSSPREFIX ?=
47
+
48
+ ifeq ($(CC),cc)
49
+ CC := gcc
50
+ endif
51
+ CC := $(CROSSPREFIX)$(CC)
52
+ AR := $(CROSSPREFIX)$(AR)
53
+
54
+ TRIPLET ?= $(shell $(CC) -dumpmachine)
55
+
56
+ BIN_EXT :=
57
+
58
+ ifneq ($(findstring msdos,$(TRIPLET)),)
59
+ # Cross-tools: https://github.com/andrewwutw/build-djgpp
60
+ MSDOS := 1
61
+ BIN_EXT := .exe
62
+ else ifneq ($(findstring amigaos,$(TRIPLET)),)
63
+ # Cross-tools: https://github.com/bebbo/amiga-gcc
64
+ AMIGA := 1
65
+ endif
66
+
67
+ CPPFLAGS += -I. -I$(PROOT)/include
68
+
69
+ ### Deprecated settings. For compatibility.
70
+
71
+ ifdef WATT_ROOT
72
+ WATT_PATH := $(realpath $(WATT_ROOT))
73
+ endif
74
+
75
+ ### Optional features
76
+
77
+ ifneq ($(findstring -debug,$(CFG)),)
78
+ CFLAGS += -g
79
+ CPPFLAGS += -DDEBUGBUILD
80
+ else
81
+ CPPFLAGS += -DNDEBUG
82
+ endif
83
+ ifneq ($(findstring -trackmem,$(CFG)),)
84
+ CPPFLAGS += -DCURLDEBUG
85
+ endif
86
+ ifneq ($(findstring -map,$(CFG)),)
87
+ MAP := 1
88
+ endif
89
+
90
+ # CPPFLAGS below are only necessary when building libcurl via 'lib' (see
91
+ # comments below about exceptions). Always include them anyway to match
92
+ # behavior of other build systems.
93
+
94
+ ifneq ($(findstring -sync,$(CFG)),)
95
+ CPPFLAGS += -DUSE_SYNC_DNS
96
+ else ifneq ($(findstring -ares,$(CFG)),)
97
+ LIBCARES_PATH ?= $(PROOT)/../c-ares
98
+ CPPFLAGS += -DUSE_ARES
99
+ CPPFLAGS += -isystem "$(LIBCARES_PATH)/include"
100
+ LDFLAGS += -L"$(LIBCARES_PATH)/lib"
101
+ LIBS += -lcares
102
+ endif
103
+
104
+ ifneq ($(findstring -rtmp,$(CFG)),)
105
+ LIBRTMP_PATH ?= $(PROOT)/../librtmp
106
+ CPPFLAGS += -DUSE_LIBRTMP
107
+ CPPFLAGS += -isystem "$(LIBRTMP_PATH)"
108
+ LDFLAGS += -L"$(LIBRTMP_PATH)/librtmp"
109
+ LIBS += -lrtmp
110
+ ZLIB := 1
111
+ endif
112
+
113
+ ifneq ($(findstring -ssh2,$(CFG)),)
114
+ LIBSSH2_PATH ?= $(PROOT)/../libssh2
115
+ CPPFLAGS += -DUSE_LIBSSH2
116
+ CPPFLAGS += -isystem "$(LIBSSH2_PATH)/include"
117
+ LDFLAGS += -L"$(LIBSSH2_PATH)/lib"
118
+ LIBS += -lssh2
119
+ else ifneq ($(findstring -libssh,$(CFG)),)
120
+ LIBSSH_PATH ?= $(PROOT)/../libssh
121
+ CPPFLAGS += -DUSE_LIBSSH
122
+ CPPFLAGS += -isystem "$(LIBSSH_PATH)/include"
123
+ LDFLAGS += -L"$(LIBSSH_PATH)/lib"
124
+ LIBS += -lssh
125
+ else ifneq ($(findstring -wolfssh,$(CFG)),)
126
+ WOLFSSH_PATH ?= $(PROOT)/../wolfssh
127
+ CPPFLAGS += -DUSE_WOLFSSH
128
+ CPPFLAGS += -isystem "$(WOLFSSH_PATH)/include"
129
+ LDFLAGS += -L"$(WOLFSSH_PATH)/lib"
130
+ LIBS += -lwolfssh
131
+ endif
132
+
133
+ ifneq ($(findstring -ssl,$(CFG)),)
134
+ OPENSSL_PATH ?= $(PROOT)/../openssl
135
+ CPPFLAGS += -DUSE_OPENSSL
136
+ CPPFLAGS += -DCURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG
137
+ OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include
138
+ OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib
139
+ CPPFLAGS += -isystem "$(OPENSSL_INCLUDE)"
140
+ LDFLAGS += -L"$(OPENSSL_LIBPATH)"
141
+ OPENSSL_LIBS ?= -lssl -lcrypto
142
+ LIBS += $(OPENSSL_LIBS)
143
+
144
+ ifneq ($(findstring -srp,$(CFG)),)
145
+ ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h),)
146
+ # OpenSSL 1.0.1 and later.
147
+ CPPFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
148
+ endif
149
+ endif
150
+ SSLLIBS += 1
151
+ endif
152
+ ifneq ($(findstring -wolfssl,$(CFG)),)
153
+ WOLFSSL_PATH ?= $(PROOT)/../wolfssl
154
+ CPPFLAGS += -DUSE_WOLFSSL
155
+ CPPFLAGS += -DSIZEOF_LONG_LONG=8
156
+ CPPFLAGS += -isystem "$(WOLFSSL_PATH)/include"
157
+ LDFLAGS += -L"$(WOLFSSL_PATH)/lib"
158
+ LIBS += -lwolfssl
159
+ SSLLIBS += 1
160
+ endif
161
+ ifneq ($(findstring -mbedtls,$(CFG)),)
162
+ MBEDTLS_PATH ?= $(PROOT)/../mbedtls
163
+ CPPFLAGS += -DUSE_MBEDTLS
164
+ CPPFLAGS += -isystem "$(MBEDTLS_PATH)/include"
165
+ LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
166
+ LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
167
+ SSLLIBS += 1
168
+ endif
169
+ ifneq ($(findstring -bearssl,$(CFG)),)
170
+ BEARSSL_PATH ?= $(PROOT)/../bearssl
171
+ CPPFLAGS += -DUSE_BEARSSL
172
+ CPPFLAGS += -isystem "$(BEARSSL_PATH)/inc"
173
+ LDFLAGS += -L"$(BEARSSL_PATH)/build"
174
+ LIBS += -lbearssl
175
+ SSLLIBS += 1
176
+ endif
177
+
178
+ ifneq ($(findstring -nghttp2,$(CFG)),)
179
+ NGHTTP2_PATH ?= $(PROOT)/../nghttp2
180
+ CPPFLAGS += -DUSE_NGHTTP2
181
+ CPPFLAGS += -isystem "$(NGHTTP2_PATH)/include"
182
+ LDFLAGS += -L"$(NGHTTP2_PATH)/lib"
183
+ LIBS += -lnghttp2
184
+ endif
185
+
186
+ ifeq ($(findstring -nghttp3,$(CFG))$(findstring -ngtcp2,$(CFG)),-nghttp3-ngtcp2)
187
+ NGHTTP3_PATH ?= $(PROOT)/../nghttp3
188
+ CPPFLAGS += -DUSE_NGHTTP3
189
+ CPPFLAGS += -isystem "$(NGHTTP3_PATH)/include"
190
+ LDFLAGS += -L"$(NGHTTP3_PATH)/lib"
191
+ LIBS += -lnghttp3
192
+
193
+ NGTCP2_PATH ?= $(PROOT)/../ngtcp2
194
+ CPPFLAGS += -DUSE_NGTCP2
195
+ CPPFLAGS += -isystem "$(NGTCP2_PATH)/include"
196
+ LDFLAGS += -L"$(NGTCP2_PATH)/lib"
197
+
198
+ NGTCP2_LIBS ?=
199
+ ifeq ($(NGTCP2_LIBS),)
200
+ ifneq ($(findstring -ssl,$(CFG)),)
201
+ ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/aead.h),)
202
+ NGTCP2_LIBS := -lngtcp2_crypto_boringssl
203
+ else # including libressl
204
+ NGTCP2_LIBS := -lngtcp2_crypto_quictls
205
+ endif
206
+ else ifneq ($(findstring -wolfssl,$(CFG)),)
207
+ NGTCP2_LIBS := -lngtcp2_crypto_wolfssl
208
+ endif
209
+ endif
210
+
211
+ LIBS += -lngtcp2 $(NGTCP2_LIBS)
212
+ endif
213
+
214
+ ifneq ($(findstring -zlib,$(CFG))$(ZLIB),)
215
+ ZLIB_PATH ?= $(PROOT)/../zlib
216
+ # These CPPFLAGS are also required when compiling the curl tool via 'src'.
217
+ CPPFLAGS += -DHAVE_LIBZ
218
+ CPPFLAGS += -isystem "$(ZLIB_PATH)/include"
219
+ LDFLAGS += -L"$(ZLIB_PATH)/lib"
220
+ ZLIB_LIBS ?= -lz
221
+ LIBS += $(ZLIB_LIBS)
222
+ ZLIB := 1
223
+ endif
224
+ ifneq ($(findstring -zstd,$(CFG)),)
225
+ ZSTD_PATH ?= $(PROOT)/../zstd
226
+ CPPFLAGS += -DHAVE_ZSTD
227
+ CPPFLAGS += -isystem "$(ZSTD_PATH)/include"
228
+ LDFLAGS += -L"$(ZSTD_PATH)/lib"
229
+ ZSTD_LIBS ?= -lzstd
230
+ LIBS += $(ZSTD_LIBS)
231
+ endif
232
+ ifneq ($(findstring -brotli,$(CFG)),)
233
+ BROTLI_PATH ?= $(PROOT)/../brotli
234
+ CPPFLAGS += -DHAVE_BROTLI
235
+ CPPFLAGS += -isystem "$(BROTLI_PATH)/include"
236
+ LDFLAGS += -L"$(BROTLI_PATH)/lib"
237
+ BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon
238
+ LIBS += $(BROTLI_LIBS)
239
+ endif
240
+ ifneq ($(findstring -gsasl,$(CFG)),)
241
+ LIBGSASL_PATH ?= $(PROOT)/../gsasl
242
+ CPPFLAGS += -DUSE_GSASL
243
+ CPPFLAGS += -isystem "$(LIBGSASL_PATH)/include"
244
+ LDFLAGS += -L"$(LIBGSASL_PATH)/lib"
245
+ LIBS += -lgsasl
246
+ endif
247
+
248
+ ifneq ($(findstring -idn2,$(CFG)),)
249
+ LIBIDN2_PATH ?= $(PROOT)/../libidn2
250
+ CPPFLAGS += -DHAVE_LIBIDN2 -DHAVE_IDN2_H
251
+ CPPFLAGS += -isystem "$(LIBIDN2_PATH)/include"
252
+ LDFLAGS += -L"$(LIBIDN2_PATH)/lib"
253
+ LIBS += -lidn2
254
+
255
+ ifneq ($(findstring -psl,$(CFG)),)
256
+ LIBPSL_PATH ?= $(PROOT)/../libpsl
257
+ CPPFLAGS += -DUSE_LIBPSL
258
+ CPPFLAGS += -isystem "$(LIBPSL_PATH)/include"
259
+ LDFLAGS += -L"$(LIBPSL_PATH)/lib"
260
+ LIBS += -lpsl
261
+ endif
262
+ endif
263
+
264
+ ifneq ($(findstring -ipv6,$(CFG)),)
265
+ CPPFLAGS += -DUSE_IPV6
266
+ endif
267
+
268
+ ifneq ($(findstring -watt,$(CFG))$(MSDOS),)
269
+ WATT_PATH ?= $(PROOT)/../watt
270
+ CPPFLAGS += -isystem "$(WATT_PATH)/inc"
271
+ LDFLAGS += -L"$(WATT_PATH)/lib"
272
+ LIBS += -lwatt
273
+ endif
274
+
275
+ ifneq ($(findstring 11,$(subst $(subst ,, ),,$(SSLLIBS))),)
276
+ CPPFLAGS += -DCURL_WITH_MULTI_SSL
277
+ endif
278
+
279
+ ### Common rules
280
+
281
+ OBJ_DIR := $(TRIPLET)
282
+
283
+ ifneq ($(findstring /sh,$(SHELL)),)
284
+ DEL = rm -f $1
285
+ COPY = -cp -afv $1 $2
286
+ MKDIR = mkdir -p $1
287
+ RMDIR = rm -fr $1
288
+ else
289
+ DEL = -del 2>NUL /q /f $(subst /,\,$1)
290
+ COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
291
+ MKDIR = -md 2>NUL $(subst /,\,$1)
292
+ RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
293
+ endif
294
+
295
+ all: $(TARGETS)
296
+
297
+ $(OBJ_DIR):
298
+ -$(call MKDIR, $(OBJ_DIR))
299
+
300
+ $(OBJ_DIR)/%.o: %.c
301
+ $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
302
+
303
+ clean:
304
+ @$(call DEL, $(TOCLEAN))
305
+ @$(RMDIR) $(OBJ_DIR)
306
+
307
+ distclean vclean: clean
308
+ @$(call DEL, $(TARGETS) $(TOVCLEAN))
309
+
310
+ ### Local
311
+
312
+ ifdef LOCAL
313
+
314
+ CPPFLAGS += -DBUILDING_LIBCURL
315
+
316
+ ### Sources and targets
317
+
318
+ # Provides CSOURCES, HHEADERS
319
+ include Makefile.inc
320
+
321
+ vpath %.c vauth vquic vssh vtls
322
+
323
+ libcurl_a_LIBRARY := libcurl.a
324
+
325
+ TARGETS := $(libcurl_a_LIBRARY)
326
+
327
+ libcurl_a_OBJECTS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(strip $(CSOURCES))))
328
+ libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
329
+
330
+ TOCLEAN :=
331
+ TOVCLEAN :=
332
+
333
+ ### Rules
334
+
335
+ $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
336
+ @$(call DEL, $@)
337
+ $(AR) rcs $@ $(libcurl_a_OBJECTS)
338
+
339
+ all: $(OBJ_DIR) $(TARGETS)
340
+ endif
local-test-curl-full-01/afc-curl/lib/altsvc.h ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_ALTSVC_H
2
+ #define HEADER_CURL_ALTSVC_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #include "curl_setup.h"
27
+
28
+ #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
29
+ #include <curl/curl.h>
30
+ #include "llist.h"
31
+
32
+ enum alpnid {
33
+ ALPN_none = 0,
34
+ ALPN_h1 = CURLALTSVC_H1,
35
+ ALPN_h2 = CURLALTSVC_H2,
36
+ ALPN_h3 = CURLALTSVC_H3
37
+ };
38
+
39
+ struct althost {
40
+ char *host;
41
+ unsigned short port;
42
+ enum alpnid alpnid;
43
+ };
44
+
45
+ struct altsvc {
46
+ struct althost src;
47
+ struct althost dst;
48
+ time_t expires;
49
+ bool persist;
50
+ unsigned int prio;
51
+ struct Curl_llist_node node;
52
+ };
53
+
54
+ struct altsvcinfo {
55
+ char *filename;
56
+ struct Curl_llist list; /* list of entries */
57
+ long flags; /* the publicly set bitmask */
58
+ };
59
+
60
+ const char *Curl_alpnid2str(enum alpnid id);
61
+ struct altsvcinfo *Curl_altsvc_init(void);
62
+ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file);
63
+ CURLcode Curl_altsvc_save(struct Curl_easy *data,
64
+ struct altsvcinfo *asi, const char *file);
65
+ CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl);
66
+ void Curl_altsvc_cleanup(struct altsvcinfo **altsvc);
67
+ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
68
+ struct altsvcinfo *altsvc, const char *value,
69
+ enum alpnid srcalpn, const char *srchost,
70
+ unsigned short srcport);
71
+ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
72
+ enum alpnid srcalpnid, const char *srchost,
73
+ int srcport,
74
+ struct altsvc **dstentry,
75
+ const int versions); /* CURLALTSVC_H* bits */
76
+ #else
77
+ /* disabled */
78
+ #define Curl_altsvc_save(a,b,c)
79
+ #define Curl_altsvc_cleanup(x)
80
+ #endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_ALTSVC */
81
+ #endif /* HEADER_CURL_ALTSVC_H */
local-test-curl-full-01/afc-curl/lib/asyn.h ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_ASYN_H
2
+ #define HEADER_CURL_ASYN_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+ #include "curl_addrinfo.h"
29
+
30
+ struct addrinfo;
31
+ struct hostent;
32
+ struct Curl_easy;
33
+ struct connectdata;
34
+ struct Curl_dns_entry;
35
+
36
+ /*
37
+ * This header defines all functions in the internal asynch resolver interface.
38
+ * All asynch resolvers need to provide these functions.
39
+ * asyn-ares.c and asyn-thread.c are the current implementations of asynch
40
+ * resolver backends.
41
+ */
42
+
43
+ /*
44
+ * Curl_resolver_global_init()
45
+ *
46
+ * Called from curl_global_init() to initialize global resolver environment.
47
+ * Returning anything else than CURLE_OK fails curl_global_init().
48
+ */
49
+ int Curl_resolver_global_init(void);
50
+
51
+ /*
52
+ * Curl_resolver_global_cleanup()
53
+ * Called from curl_global_cleanup() to destroy global resolver environment.
54
+ */
55
+ void Curl_resolver_global_cleanup(void);
56
+
57
+ /*
58
+ * Curl_resolver_init()
59
+ * Called from curl_easy_init() -> Curl_open() to initialize resolver
60
+ * URL-state specific environment ('resolver' member of the UrlState
61
+ * structure). Should fill the passed pointer by the initialized handler.
62
+ * Returning anything else than CURLE_OK fails curl_easy_init() with the
63
+ * correspondent code.
64
+ */
65
+ CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver);
66
+
67
+ /*
68
+ * Curl_resolver_cleanup()
69
+ * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
70
+ * URL-state specific environment ('resolver' member of the UrlState
71
+ * structure). Should destroy the handler and free all resources connected to
72
+ * it.
73
+ */
74
+ void Curl_resolver_cleanup(void *resolver);
75
+
76
+ /*
77
+ * Curl_resolver_duphandle()
78
+ * Called from curl_easy_duphandle() to duplicate resolver URL-state specific
79
+ * environment ('resolver' member of the UrlState structure). Should
80
+ * duplicate the 'from' handle and pass the resulting handle to the 'to'
81
+ * pointer. Returning anything else than CURLE_OK causes failed
82
+ * curl_easy_duphandle() call.
83
+ */
84
+ CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to,
85
+ void *from);
86
+
87
+ /*
88
+ * Curl_resolver_cancel().
89
+ *
90
+ * It is called from inside other functions to cancel currently performing
91
+ * resolver request. Should also free any temporary resources allocated to
92
+ * perform a request. This never waits for resolver threads to complete.
93
+ *
94
+ * It is safe to call this when conn is in any state.
95
+ */
96
+ void Curl_resolver_cancel(struct Curl_easy *data);
97
+
98
+ /*
99
+ * Curl_resolver_kill().
100
+ *
101
+ * This acts like Curl_resolver_cancel() except it will block until any threads
102
+ * associated with the resolver are complete. This never blocks for resolvers
103
+ * that do not use threads. This is intended to be the "last chance" function
104
+ * that cleans up an in-progress resolver completely (before its owner is about
105
+ * to die).
106
+ *
107
+ * It is safe to call this when conn is in any state.
108
+ */
109
+ void Curl_resolver_kill(struct Curl_easy *data);
110
+
111
+ /* Curl_resolver_getsock()
112
+ *
113
+ * This function is called from the multi_getsock() function. 'sock' is a
114
+ * pointer to an array to hold the file descriptors, with 'numsock' being the
115
+ * size of that array (in number of entries). This function is supposed to
116
+ * return bitmask indicating what file descriptors (referring to array indexes
117
+ * in the 'sock' array) to wait for, read/write.
118
+ */
119
+ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *sock);
120
+
121
+ /*
122
+ * Curl_resolver_is_resolved()
123
+ *
124
+ * Called repeatedly to check if a previous name resolve request has
125
+ * completed. It should also make sure to time-out if the operation seems to
126
+ * take too long.
127
+ *
128
+ * Returns normal CURLcode errors.
129
+ */
130
+ CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
131
+ struct Curl_dns_entry **dns);
132
+
133
+ /*
134
+ * Curl_resolver_wait_resolv()
135
+ *
136
+ * Waits for a resolve to finish. This function should be avoided since using
137
+ * this risk getting the multi interface to "hang".
138
+ *
139
+ * If 'entry' is non-NULL, make it point to the resolved dns entry
140
+ *
141
+ * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
142
+ * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
143
+ */
144
+ CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
145
+ struct Curl_dns_entry **dnsentry);
146
+
147
+ /*
148
+ * Curl_resolver_getaddrinfo() - when using this resolver
149
+ *
150
+ * Returns name information about the given hostname and port number. If
151
+ * successful, the 'hostent' is returned and the fourth argument will point to
152
+ * memory we need to free after use. That memory *MUST* be freed with
153
+ * Curl_freeaddrinfo(), nothing else.
154
+ *
155
+ * Each resolver backend must of course make sure to return data in the
156
+ * correct format to comply with this.
157
+ */
158
+ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
159
+ const char *hostname,
160
+ int port,
161
+ int *waitp);
162
+
163
+ #ifndef CURLRES_ASYNCH
164
+ /* convert these functions if an asynch resolver is not used */
165
+ #define Curl_resolver_cancel(x) Curl_nop_stmt
166
+ #define Curl_resolver_kill(x) Curl_nop_stmt
167
+ #define Curl_resolver_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
168
+ #define Curl_resolver_wait_resolv(x,y) CURLE_COULDNT_RESOLVE_HOST
169
+ #define Curl_resolver_duphandle(x,y,z) CURLE_OK
170
+ #define Curl_resolver_init(x,y) CURLE_OK
171
+ #define Curl_resolver_global_init() CURLE_OK
172
+ #define Curl_resolver_global_cleanup() Curl_nop_stmt
173
+ #define Curl_resolver_cleanup(x) Curl_nop_stmt
174
+ #endif
175
+
176
+ #ifdef CURLRES_ASYNCH
177
+ #define Curl_resolver_asynch() 1
178
+ #else
179
+ #define Curl_resolver_asynch() 0
180
+ #endif
181
+
182
+
183
+ /********** end of generic resolver interface functions *****************/
184
+ #endif /* HEADER_CURL_ASYN_H */
local-test-curl-full-01/afc-curl/lib/cf-h1-proxy.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_H1_PROXY_H
2
+ #define HEADER_CURL_H1_PROXY_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+
29
+ #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
30
+
31
+ CURLcode Curl_cf_h1_proxy_insert_after(struct Curl_cfilter *cf,
32
+ struct Curl_easy *data);
33
+
34
+ extern struct Curl_cftype Curl_cft_h1_proxy;
35
+
36
+
37
+ #endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */
38
+
39
+ #endif /* HEADER_CURL_H1_PROXY_H */
local-test-curl-full-01/afc-curl/lib/cf-h2-proxy.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_H2_PROXY_H
2
+ #define HEADER_CURL_H2_PROXY_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+
29
+ #if defined(USE_NGHTTP2) && !defined(CURL_DISABLE_PROXY)
30
+
31
+ CURLcode Curl_cf_h2_proxy_insert_after(struct Curl_cfilter *cf,
32
+ struct Curl_easy *data);
33
+
34
+ extern struct Curl_cftype Curl_cft_h2_proxy;
35
+
36
+
37
+ #endif /* defined(USE_NGHTTP2) && !defined(CURL_DISABLE_PROXY) */
38
+
39
+ #endif /* HEADER_CURL_H2_PROXY_H */
local-test-curl-full-01/afc-curl/lib/cf-haproxy.c ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #if !defined(CURL_DISABLE_PROXY)
28
+
29
+ #include <curl/curl.h>
30
+ #include "urldata.h"
31
+ #include "cfilters.h"
32
+ #include "cf-haproxy.h"
33
+ #include "curl_trc.h"
34
+ #include "multiif.h"
35
+
36
+ /* The last 3 #include files should be in this order */
37
+ #include "curl_printf.h"
38
+ #include "curl_memory.h"
39
+ #include "memdebug.h"
40
+
41
+
42
+ typedef enum {
43
+ HAPROXY_INIT, /* init/default/no tunnel state */
44
+ HAPROXY_SEND, /* data_out being sent */
45
+ HAPROXY_DONE /* all work done */
46
+ } haproxy_state;
47
+
48
+ struct cf_haproxy_ctx {
49
+ int state;
50
+ struct dynbuf data_out;
51
+ };
52
+
53
+ static void cf_haproxy_ctx_reset(struct cf_haproxy_ctx *ctx)
54
+ {
55
+ DEBUGASSERT(ctx);
56
+ ctx->state = HAPROXY_INIT;
57
+ Curl_dyn_reset(&ctx->data_out);
58
+ }
59
+
60
+ static void cf_haproxy_ctx_free(struct cf_haproxy_ctx *ctx)
61
+ {
62
+ if(ctx) {
63
+ Curl_dyn_free(&ctx->data_out);
64
+ free(ctx);
65
+ }
66
+ }
67
+
68
+ static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter*cf,
69
+ struct Curl_easy *data)
70
+ {
71
+ struct cf_haproxy_ctx *ctx = cf->ctx;
72
+ CURLcode result;
73
+ const char *client_ip;
74
+ struct ip_quadruple ipquad;
75
+ int is_ipv6;
76
+
77
+ DEBUGASSERT(ctx);
78
+ DEBUGASSERT(ctx->state == HAPROXY_INIT);
79
+ #ifdef USE_UNIX_SOCKETS
80
+ if(cf->conn->unix_domain_socket)
81
+ /* the buffer is large enough to hold this! */
82
+ result = Curl_dyn_addn(&ctx->data_out, STRCONST("PROXY UNKNOWN\r\n"));
83
+ else {
84
+ #endif /* USE_UNIX_SOCKETS */
85
+ result = Curl_conn_cf_get_ip_info(cf->next, data, &is_ipv6, &ipquad);
86
+ if(result)
87
+ return result;
88
+
89
+ /* Emit the correct prefix for IPv6 */
90
+ if(data->set.str[STRING_HAPROXY_CLIENT_IP])
91
+ client_ip = data->set.str[STRING_HAPROXY_CLIENT_IP];
92
+ else
93
+ client_ip = ipquad.local_ip;
94
+
95
+ result = Curl_dyn_addf(&ctx->data_out, "PROXY %s %s %s %i %i\r\n",
96
+ is_ipv6 ? "TCP6" : "TCP4",
97
+ client_ip, ipquad.remote_ip,
98
+ ipquad.local_port, ipquad.remote_port);
99
+
100
+ #ifdef USE_UNIX_SOCKETS
101
+ }
102
+ #endif /* USE_UNIX_SOCKETS */
103
+ return result;
104
+ }
105
+
106
+ static CURLcode cf_haproxy_connect(struct Curl_cfilter *cf,
107
+ struct Curl_easy *data,
108
+ bool blocking, bool *done)
109
+ {
110
+ struct cf_haproxy_ctx *ctx = cf->ctx;
111
+ CURLcode result;
112
+ size_t len;
113
+
114
+ DEBUGASSERT(ctx);
115
+ if(cf->connected) {
116
+ *done = TRUE;
117
+ return CURLE_OK;
118
+ }
119
+
120
+ result = cf->next->cft->do_connect(cf->next, data, blocking, done);
121
+ if(result || !*done)
122
+ return result;
123
+
124
+ switch(ctx->state) {
125
+ case HAPROXY_INIT:
126
+ result = cf_haproxy_date_out_set(cf, data);
127
+ if(result)
128
+ goto out;
129
+ ctx->state = HAPROXY_SEND;
130
+ FALLTHROUGH();
131
+ case HAPROXY_SEND:
132
+ len = Curl_dyn_len(&ctx->data_out);
133
+ if(len > 0) {
134
+ ssize_t nwritten;
135
+ nwritten = Curl_conn_cf_send(cf->next, data,
136
+ Curl_dyn_ptr(&ctx->data_out), len, FALSE,
137
+ &result);
138
+ if(nwritten < 0) {
139
+ if(result != CURLE_AGAIN)
140
+ goto out;
141
+ result = CURLE_OK;
142
+ nwritten = 0;
143
+ }
144
+ Curl_dyn_tail(&ctx->data_out, len - (size_t)nwritten);
145
+ if(Curl_dyn_len(&ctx->data_out) > 0) {
146
+ result = CURLE_OK;
147
+ goto out;
148
+ }
149
+ }
150
+ ctx->state = HAPROXY_DONE;
151
+ FALLTHROUGH();
152
+ default:
153
+ Curl_dyn_free(&ctx->data_out);
154
+ break;
155
+ }
156
+
157
+ out:
158
+ *done = (!result) && (ctx->state == HAPROXY_DONE);
159
+ cf->connected = *done;
160
+ return result;
161
+ }
162
+
163
+ static void cf_haproxy_destroy(struct Curl_cfilter *cf,
164
+ struct Curl_easy *data)
165
+ {
166
+ (void)data;
167
+ CURL_TRC_CF(data, cf, "destroy");
168
+ cf_haproxy_ctx_free(cf->ctx);
169
+ }
170
+
171
+ static void cf_haproxy_close(struct Curl_cfilter *cf,
172
+ struct Curl_easy *data)
173
+ {
174
+ CURL_TRC_CF(data, cf, "close");
175
+ cf->connected = FALSE;
176
+ cf_haproxy_ctx_reset(cf->ctx);
177
+ if(cf->next)
178
+ cf->next->cft->do_close(cf->next, data);
179
+ }
180
+
181
+ static void cf_haproxy_adjust_pollset(struct Curl_cfilter *cf,
182
+ struct Curl_easy *data,
183
+ struct easy_pollset *ps)
184
+ {
185
+ if(cf->next->connected && !cf->connected) {
186
+ /* If we are not connected, but the filter "below" is
187
+ * and not waiting on something, we are sending. */
188
+ Curl_pollset_set_out_only(data, ps, Curl_conn_cf_get_socket(cf, data));
189
+ }
190
+ }
191
+
192
+ struct Curl_cftype Curl_cft_haproxy = {
193
+ "HAPROXY",
194
+ CF_TYPE_PROXY,
195
+ 0,
196
+ cf_haproxy_destroy,
197
+ cf_haproxy_connect,
198
+ cf_haproxy_close,
199
+ Curl_cf_def_shutdown,
200
+ Curl_cf_def_get_host,
201
+ cf_haproxy_adjust_pollset,
202
+ Curl_cf_def_data_pending,
203
+ Curl_cf_def_send,
204
+ Curl_cf_def_recv,
205
+ Curl_cf_def_cntrl,
206
+ Curl_cf_def_conn_is_alive,
207
+ Curl_cf_def_conn_keep_alive,
208
+ Curl_cf_def_query,
209
+ };
210
+
211
+ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf,
212
+ struct Curl_easy *data)
213
+ {
214
+ struct Curl_cfilter *cf = NULL;
215
+ struct cf_haproxy_ctx *ctx;
216
+ CURLcode result;
217
+
218
+ (void)data;
219
+ ctx = calloc(1, sizeof(*ctx));
220
+ if(!ctx) {
221
+ result = CURLE_OUT_OF_MEMORY;
222
+ goto out;
223
+ }
224
+ ctx->state = HAPROXY_INIT;
225
+ Curl_dyn_init(&ctx->data_out, DYN_HAXPROXY);
226
+
227
+ result = Curl_cf_create(&cf, &Curl_cft_haproxy, ctx);
228
+ if(result)
229
+ goto out;
230
+ ctx = NULL;
231
+
232
+ out:
233
+ cf_haproxy_ctx_free(ctx);
234
+ *pcf = result ? NULL : cf;
235
+ return result;
236
+ }
237
+
238
+ CURLcode Curl_cf_haproxy_insert_after(struct Curl_cfilter *cf_at,
239
+ struct Curl_easy *data)
240
+ {
241
+ struct Curl_cfilter *cf;
242
+ CURLcode result;
243
+
244
+ result = cf_haproxy_create(&cf, data);
245
+ if(result)
246
+ goto out;
247
+ Curl_conn_cf_insert_after(cf_at, cf);
248
+
249
+ out:
250
+ return result;
251
+ }
252
+
253
+ #endif /* !CURL_DISABLE_PROXY */
local-test-curl-full-01/afc-curl/lib/cf-haproxy.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CF_HAPROXY_H
2
+ #define HEADER_CURL_CF_HAPROXY_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+ #include "urldata.h"
29
+
30
+ #if !defined(CURL_DISABLE_PROXY)
31
+
32
+ CURLcode Curl_cf_haproxy_insert_after(struct Curl_cfilter *cf_at,
33
+ struct Curl_easy *data);
34
+
35
+ extern struct Curl_cftype Curl_cft_haproxy;
36
+
37
+ #endif /* !CURL_DISABLE_PROXY */
38
+
39
+ #endif /* HEADER_CURL_CF_HAPROXY_H */
local-test-curl-full-01/afc-curl/lib/cf-https-connect.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CF_HTTP_H
2
+ #define HEADER_CURL_CF_HTTP_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #include "curl_setup.h"
27
+
28
+ #if !defined(CURL_DISABLE_HTTP) && !defined(USE_HYPER)
29
+
30
+ struct Curl_cfilter;
31
+ struct Curl_easy;
32
+ struct connectdata;
33
+ struct Curl_cftype;
34
+ struct Curl_dns_entry;
35
+
36
+ extern struct Curl_cftype Curl_cft_http_connect;
37
+
38
+ CURLcode Curl_cf_http_connect_add(struct Curl_easy *data,
39
+ struct connectdata *conn,
40
+ int sockindex,
41
+ const struct Curl_dns_entry *remotehost,
42
+ bool try_h3, bool try_h21);
43
+
44
+ CURLcode
45
+ Curl_cf_http_connect_insert_after(struct Curl_cfilter *cf_at,
46
+ struct Curl_easy *data,
47
+ const struct Curl_dns_entry *remotehost,
48
+ bool try_h3, bool try_h21);
49
+
50
+
51
+ CURLcode Curl_cf_https_setup(struct Curl_easy *data,
52
+ struct connectdata *conn,
53
+ int sockindex,
54
+ const struct Curl_dns_entry *remotehost);
55
+
56
+
57
+ #endif /* !defined(CURL_DISABLE_HTTP) && !defined(USE_HYPER) */
58
+ #endif /* HEADER_CURL_CF_HTTP_H */
local-test-curl-full-01/afc-curl/lib/cfilters.h ADDED
@@ -0,0 +1,696 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CFILTERS_H
2
+ #define HEADER_CURL_CFILTERS_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "timediff.h"
28
+
29
+ struct Curl_cfilter;
30
+ struct Curl_easy;
31
+ struct Curl_dns_entry;
32
+ struct connectdata;
33
+ struct ip_quadruple;
34
+
35
+ /* Callback to destroy resources held by this filter instance.
36
+ * Implementations MUST NOT chain calls to cf->next.
37
+ */
38
+ typedef void Curl_cft_destroy_this(struct Curl_cfilter *cf,
39
+ struct Curl_easy *data);
40
+
41
+ /* Callback to close the connection immediately. */
42
+ typedef void Curl_cft_close(struct Curl_cfilter *cf,
43
+ struct Curl_easy *data);
44
+
45
+ /* Callback to close the connection filter gracefully, non-blocking.
46
+ * Implementations MUST NOT chain calls to cf->next.
47
+ */
48
+ typedef CURLcode Curl_cft_shutdown(struct Curl_cfilter *cf,
49
+ struct Curl_easy *data,
50
+ bool *done);
51
+
52
+ typedef CURLcode Curl_cft_connect(struct Curl_cfilter *cf,
53
+ struct Curl_easy *data,
54
+ bool blocking, bool *done);
55
+
56
+ /* Return the hostname and port the connection goes to.
57
+ * This may change with the connection state of filters when tunneling
58
+ * is involved.
59
+ * @param cf the filter to ask
60
+ * @param data the easy handle currently active
61
+ * @param phost on return, points to the relevant, real hostname.
62
+ * this is owned by the connection.
63
+ * @param pdisplay_host on return, points to the printable hostname.
64
+ * this is owned by the connection.
65
+ * @param pport on return, contains the port number
66
+ */
67
+ typedef void Curl_cft_get_host(struct Curl_cfilter *cf,
68
+ struct Curl_easy *data,
69
+ const char **phost,
70
+ const char **pdisplay_host,
71
+ int *pport);
72
+
73
+ struct easy_pollset;
74
+
75
+ /* Passing in an easy_pollset for monitoring of sockets, let
76
+ * filters add or remove sockets actions (CURL_POLL_OUT, CURL_POLL_IN).
77
+ * This may add a socket or, in case no actions remain, remove
78
+ * a socket from the set.
79
+ *
80
+ * Filter implementations need to call filters "below" *after* they have
81
+ * made their adjustments. This allows lower filters to override "upper"
82
+ * actions. If a "lower" filter is unable to write, it needs to be able
83
+ * to disallow POLL_OUT.
84
+ *
85
+ * A filter without own restrictions/preferences should not modify
86
+ * the pollset. Filters, whose filter "below" is not connected, should
87
+ * also do no adjustments.
88
+ *
89
+ * Examples: a TLS handshake, while ongoing, might remove POLL_IN when it
90
+ * needs to write, or vice versa. An HTTP/2 filter might remove POLL_OUT when
91
+ * a stream window is exhausted and a WINDOW_UPDATE needs to be received first
92
+ * and add instead POLL_IN.
93
+ *
94
+ * @param cf the filter to ask
95
+ * @param data the easy handle the pollset is about
96
+ * @param ps the pollset (inout) for the easy handle
97
+ */
98
+ typedef void Curl_cft_adjust_pollset(struct Curl_cfilter *cf,
99
+ struct Curl_easy *data,
100
+ struct easy_pollset *ps);
101
+
102
+ typedef bool Curl_cft_data_pending(struct Curl_cfilter *cf,
103
+ const struct Curl_easy *data);
104
+
105
+ typedef ssize_t Curl_cft_send(struct Curl_cfilter *cf,
106
+ struct Curl_easy *data, /* transfer */
107
+ const void *buf, /* data to write */
108
+ size_t len, /* amount to write */
109
+ bool eos, /* last chunk */
110
+ CURLcode *err); /* error to return */
111
+
112
+ typedef ssize_t Curl_cft_recv(struct Curl_cfilter *cf,
113
+ struct Curl_easy *data, /* transfer */
114
+ char *buf, /* store data here */
115
+ size_t len, /* amount to read */
116
+ CURLcode *err); /* error to return */
117
+
118
+ typedef bool Curl_cft_conn_is_alive(struct Curl_cfilter *cf,
119
+ struct Curl_easy *data,
120
+ bool *input_pending);
121
+
122
+ typedef CURLcode Curl_cft_conn_keep_alive(struct Curl_cfilter *cf,
123
+ struct Curl_easy *data);
124
+
125
+ /**
126
+ * Events/controls for connection filters, their arguments and
127
+ * return code handling. Filter callbacks are invoked "top down".
128
+ * Return code handling:
129
+ * "first fail" meaning that the first filter returning != CURLE_OK, will
130
+ * abort further event distribution and determine the result.
131
+ * "ignored" meaning return values are ignored and the event is distributed
132
+ * to all filters in the chain. Overall result is always CURLE_OK.
133
+ */
134
+ /* data event arg1 arg2 return */
135
+ #define CF_CTRL_DATA_ATTACH 1 /* 0 NULL ignored */
136
+ #define CF_CTRL_DATA_DETACH 2 /* 0 NULL ignored */
137
+ #define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */
138
+ #define CF_CTRL_DATA_IDLE 5 /* 0 NULL first fail */
139
+ #define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */
140
+ #define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */
141
+ #define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */
142
+ /* update conn info at connection and data */
143
+ #define CF_CTRL_CONN_INFO_UPDATE (256+0) /* 0 NULL ignored */
144
+ #define CF_CTRL_FORGET_SOCKET (256+1) /* 0 NULL ignored */
145
+ #define CF_CTRL_FLUSH (256+2) /* 0 NULL first fail */
146
+
147
+ /**
148
+ * Handle event/control for the filter.
149
+ * Implementations MUST NOT chain calls to cf->next.
150
+ */
151
+ typedef CURLcode Curl_cft_cntrl(struct Curl_cfilter *cf,
152
+ struct Curl_easy *data,
153
+ int event, int arg1, void *arg2);
154
+
155
+
156
+ /**
157
+ * Queries to ask via a `Curl_cft_query *query` method on a cfilter chain.
158
+ * - MAX_CONCURRENT: the maximum number of parallel transfers the filter
159
+ * chain expects to handle at the same time.
160
+ * default: 1 if no filter overrides.
161
+ * - CONNECT_REPLY_MS: milliseconds until the first indication of a server
162
+ * response was received on a connect. For TCP, this
163
+ * reflects the time until the socket connected. On UDP
164
+ * this gives the time the first bytes from the server
165
+ * were received.
166
+ * -1 if not determined yet.
167
+ * - CF_QUERY_SOCKET: the socket used by the filter chain
168
+ * - CF_QUERY_NEED_FLUSH: TRUE iff any of the filters have unsent data
169
+ * - CF_QUERY_IP_INFO: res1 says if connection used IPv6, res2 is the
170
+ * ip quadruple
171
+ */
172
+ /* query res1 res2 */
173
+ #define CF_QUERY_MAX_CONCURRENT 1 /* number - */
174
+ #define CF_QUERY_CONNECT_REPLY_MS 2 /* number - */
175
+ #define CF_QUERY_SOCKET 3 /* - curl_socket_t */
176
+ #define CF_QUERY_TIMER_CONNECT 4 /* - struct curltime */
177
+ #define CF_QUERY_TIMER_APPCONNECT 5 /* - struct curltime */
178
+ #define CF_QUERY_STREAM_ERROR 6 /* error code - */
179
+ #define CF_QUERY_NEED_FLUSH 7 /* TRUE/FALSE - */
180
+ #define CF_QUERY_IP_INFO 8 /* TRUE/FALSE struct ip_quadruple */
181
+
182
+ /**
183
+ * Query the cfilter for properties. Filters ignorant of a query will
184
+ * pass it "down" the filter chain.
185
+ */
186
+ typedef CURLcode Curl_cft_query(struct Curl_cfilter *cf,
187
+ struct Curl_easy *data,
188
+ int query, int *pres1, void *pres2);
189
+
190
+ /**
191
+ * Type flags for connection filters. A filter can have none, one or
192
+ * many of those. Use to evaluate state/capabilities of a filter chain.
193
+ *
194
+ * CF_TYPE_IP_CONNECT: provides an IP connection or sth equivalent, like
195
+ * a CONNECT tunnel, a UNIX domain socket, a QUIC
196
+ * connection, etc.
197
+ * CF_TYPE_SSL: provide SSL/TLS
198
+ * CF_TYPE_MULTIPLEX: provides multiplexing of easy handles
199
+ * CF_TYPE_PROXY provides proxying
200
+ */
201
+ #define CF_TYPE_IP_CONNECT (1 << 0)
202
+ #define CF_TYPE_SSL (1 << 1)
203
+ #define CF_TYPE_MULTIPLEX (1 << 2)
204
+ #define CF_TYPE_PROXY (1 << 3)
205
+
206
+ /* A connection filter type, e.g. specific implementation. */
207
+ struct Curl_cftype {
208
+ const char *name; /* name of the filter type */
209
+ int flags; /* flags of filter type */
210
+ int log_level; /* log level for such filters */
211
+ Curl_cft_destroy_this *destroy; /* destroy resources of this cf */
212
+ Curl_cft_connect *do_connect; /* establish connection */
213
+ Curl_cft_close *do_close; /* close conn */
214
+ Curl_cft_shutdown *do_shutdown; /* shutdown conn */
215
+ Curl_cft_get_host *get_host; /* host filter talks to */
216
+ Curl_cft_adjust_pollset *adjust_pollset; /* adjust transfer poll set */
217
+ Curl_cft_data_pending *has_data_pending;/* conn has data pending */
218
+ Curl_cft_send *do_send; /* send data */
219
+ Curl_cft_recv *do_recv; /* receive data */
220
+ Curl_cft_cntrl *cntrl; /* events/control */
221
+ Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */
222
+ Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */
223
+ Curl_cft_query *query; /* query filter chain */
224
+ };
225
+
226
+ /* A connection filter instance, e.g. registered at a connection */
227
+ struct Curl_cfilter {
228
+ const struct Curl_cftype *cft; /* the type providing implementation */
229
+ struct Curl_cfilter *next; /* next filter in chain */
230
+ void *ctx; /* filter type specific settings */
231
+ struct connectdata *conn; /* the connection this filter belongs to */
232
+ int sockindex; /* the index the filter is installed at */
233
+ BIT(connected); /* != 0 iff this filter is connected */
234
+ BIT(shutdown); /* != 0 iff this filter has shut down */
235
+ };
236
+
237
+ /* Default implementations for the type functions, implementing nop. */
238
+ void Curl_cf_def_destroy_this(struct Curl_cfilter *cf,
239
+ struct Curl_easy *data);
240
+
241
+ /* Default implementations for the type functions, implementing pass-through
242
+ * the filter chain. */
243
+ void Curl_cf_def_get_host(struct Curl_cfilter *cf, struct Curl_easy *data,
244
+ const char **phost, const char **pdisplay_host,
245
+ int *pport);
246
+ void Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf,
247
+ struct Curl_easy *data,
248
+ struct easy_pollset *ps);
249
+ bool Curl_cf_def_data_pending(struct Curl_cfilter *cf,
250
+ const struct Curl_easy *data);
251
+ ssize_t Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data,
252
+ const void *buf, size_t len, bool eos,
253
+ CURLcode *err);
254
+ ssize_t Curl_cf_def_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
255
+ char *buf, size_t len, CURLcode *err);
256
+ CURLcode Curl_cf_def_cntrl(struct Curl_cfilter *cf,
257
+ struct Curl_easy *data,
258
+ int event, int arg1, void *arg2);
259
+ bool Curl_cf_def_conn_is_alive(struct Curl_cfilter *cf,
260
+ struct Curl_easy *data,
261
+ bool *input_pending);
262
+ CURLcode Curl_cf_def_conn_keep_alive(struct Curl_cfilter *cf,
263
+ struct Curl_easy *data);
264
+ CURLcode Curl_cf_def_query(struct Curl_cfilter *cf,
265
+ struct Curl_easy *data,
266
+ int query, int *pres1, void *pres2);
267
+ CURLcode Curl_cf_def_shutdown(struct Curl_cfilter *cf,
268
+ struct Curl_easy *data, bool *done);
269
+
270
+ /**
271
+ * Create a new filter instance, unattached to the filter chain.
272
+ * Use Curl_conn_cf_add() to add it to the chain.
273
+ * @param pcf on success holds the created instance
274
+ * @param cft the filter type
275
+ * @param ctx the type specific context to use
276
+ */
277
+ CURLcode Curl_cf_create(struct Curl_cfilter **pcf,
278
+ const struct Curl_cftype *cft,
279
+ void *ctx);
280
+
281
+ /**
282
+ * Add a filter instance to the `sockindex` filter chain at connection
283
+ * `conn`. The filter must not already be attached. It is inserted at
284
+ * the start of the chain (top).
285
+ */
286
+ void Curl_conn_cf_add(struct Curl_easy *data,
287
+ struct connectdata *conn,
288
+ int sockindex,
289
+ struct Curl_cfilter *cf);
290
+
291
+ /**
292
+ * Insert a filter (chain) after `cf_at`.
293
+ * `cf_new` must not already be attached.
294
+ */
295
+ void Curl_conn_cf_insert_after(struct Curl_cfilter *cf_at,
296
+ struct Curl_cfilter *cf_new);
297
+
298
+ /**
299
+ * Discard, e.g. remove and destroy `discard` iff
300
+ * it still is in the filter chain below `cf`. If `discard`
301
+ * is no longer found beneath `cf` return FALSE.
302
+ * if `destroy_always` is TRUE, will call `discard`s destroy
303
+ * function and free it even if not found in the subchain.
304
+ */
305
+ bool Curl_conn_cf_discard_sub(struct Curl_cfilter *cf,
306
+ struct Curl_cfilter *discard,
307
+ struct Curl_easy *data,
308
+ bool destroy_always);
309
+
310
+ /**
311
+ * Discard all cfilters starting with `*pcf` and clearing it afterwards.
312
+ */
313
+ void Curl_conn_cf_discard_chain(struct Curl_cfilter **pcf,
314
+ struct Curl_easy *data);
315
+
316
+ /**
317
+ * Remove and destroy all filters at chain `sockindex` on connection `conn`.
318
+ */
319
+ void Curl_conn_cf_discard_all(struct Curl_easy *data,
320
+ struct connectdata *conn,
321
+ int sockindex);
322
+
323
+
324
+ CURLcode Curl_conn_cf_connect(struct Curl_cfilter *cf,
325
+ struct Curl_easy *data,
326
+ bool blocking, bool *done);
327
+ void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data);
328
+ ssize_t Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data,
329
+ const void *buf, size_t len, bool eos,
330
+ CURLcode *err);
331
+ ssize_t Curl_conn_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
332
+ char *buf, size_t len, CURLcode *err);
333
+ CURLcode Curl_conn_cf_cntrl(struct Curl_cfilter *cf,
334
+ struct Curl_easy *data,
335
+ bool ignore_result,
336
+ int event, int arg1, void *arg2);
337
+
338
+ /**
339
+ * Determine if the connection filter chain is using SSL to the remote host
340
+ * (or will be once connected).
341
+ */
342
+ bool Curl_conn_cf_is_ssl(struct Curl_cfilter *cf);
343
+
344
+ /**
345
+ * Get the socket used by the filter chain starting at `cf`.
346
+ * Returns CURL_SOCKET_BAD if not available.
347
+ */
348
+ curl_socket_t Curl_conn_cf_get_socket(struct Curl_cfilter *cf,
349
+ struct Curl_easy *data);
350
+
351
+ CURLcode Curl_conn_cf_get_ip_info(struct Curl_cfilter *cf,
352
+ struct Curl_easy *data,
353
+ int *is_ipv6, struct ip_quadruple *ipquad);
354
+
355
+ bool Curl_conn_cf_needs_flush(struct Curl_cfilter *cf,
356
+ struct Curl_easy *data);
357
+
358
+ #define CURL_CF_SSL_DEFAULT -1
359
+ #define CURL_CF_SSL_DISABLE 0
360
+ #define CURL_CF_SSL_ENABLE 1
361
+
362
+ /**
363
+ * Bring the filter chain at `sockindex` for connection `data->conn` into
364
+ * connected state. Which will set `*done` to TRUE.
365
+ * This can be called on an already connected chain with no side effects.
366
+ * When not `blocking`, calls may return without error and `*done != TRUE`,
367
+ * while the individual filters negotiated the connection.
368
+ */
369
+ CURLcode Curl_conn_connect(struct Curl_easy *data, int sockindex,
370
+ bool blocking, bool *done);
371
+
372
+ /**
373
+ * Check if the filter chain at `sockindex` for connection `conn` is
374
+ * completely connected.
375
+ */
376
+ bool Curl_conn_is_connected(struct connectdata *conn, int sockindex);
377
+
378
+ /**
379
+ * Determine if we have reached the remote host on IP level, e.g.
380
+ * have a TCP connection. This turns TRUE before a possible SSL
381
+ * handshake has been started/done.
382
+ */
383
+ bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex);
384
+
385
+ /**
386
+ * Determine if the connection is using SSL to the remote host
387
+ * (or will be once connected). This will return FALSE, if SSL
388
+ * is only used in proxying and not for the tunnel itself.
389
+ */
390
+ bool Curl_conn_is_ssl(struct connectdata *conn, int sockindex);
391
+
392
+ /**
393
+ * Connection provides multiplexing of easy handles at `socketindex`.
394
+ */
395
+ bool Curl_conn_is_multiplex(struct connectdata *conn, int sockindex);
396
+
397
+ /**
398
+ * Close the filter chain at `sockindex` for connection `data->conn`.
399
+ * Filters remain in place and may be connected again afterwards.
400
+ */
401
+ void Curl_conn_close(struct Curl_easy *data, int sockindex);
402
+
403
+ /**
404
+ * Shutdown the connection at `sockindex` non-blocking, using timeout
405
+ * from `data->set.shutdowntimeout`, default DEFAULT_SHUTDOWN_TIMEOUT_MS.
406
+ * Will return CURLE_OK and *done == FALSE if not finished.
407
+ */
408
+ CURLcode Curl_conn_shutdown(struct Curl_easy *data, int sockindex, bool *done);
409
+
410
+ /**
411
+ * Return if data is pending in some connection filter at chain
412
+ * `sockindex` for connection `data->conn`.
413
+ */
414
+ bool Curl_conn_data_pending(struct Curl_easy *data,
415
+ int sockindex);
416
+
417
+ /**
418
+ * Return TRUE if any of the connection filters at chain `sockindex`
419
+ * have data still to send.
420
+ */
421
+ bool Curl_conn_needs_flush(struct Curl_easy *data, int sockindex);
422
+
423
+ /**
424
+ * Flush any pending data on the connection filters at chain `sockindex`.
425
+ */
426
+ CURLcode Curl_conn_flush(struct Curl_easy *data, int sockindex);
427
+
428
+ /**
429
+ * Return the socket used on data's connection for the index.
430
+ * Returns CURL_SOCKET_BAD if not available.
431
+ */
432
+ curl_socket_t Curl_conn_get_socket(struct Curl_easy *data, int sockindex);
433
+
434
+ /**
435
+ * Tell filters to forget about the socket at sockindex.
436
+ */
437
+ void Curl_conn_forget_socket(struct Curl_easy *data, int sockindex);
438
+
439
+ /**
440
+ * Adjust the pollset for the filter chain startgin at `cf`.
441
+ */
442
+ void Curl_conn_cf_adjust_pollset(struct Curl_cfilter *cf,
443
+ struct Curl_easy *data,
444
+ struct easy_pollset *ps);
445
+
446
+ /**
447
+ * Adjust pollset from filters installed at transfer's connection.
448
+ */
449
+ void Curl_conn_adjust_pollset(struct Curl_easy *data,
450
+ struct easy_pollset *ps);
451
+
452
+ /**
453
+ * Curl_poll() the filter chain at `cf` with timeout `timeout_ms`.
454
+ * Returns 0 on timeout, negative on error or number of sockets
455
+ * with requested poll events.
456
+ */
457
+ int Curl_conn_cf_poll(struct Curl_cfilter *cf,
458
+ struct Curl_easy *data,
459
+ timediff_t timeout_ms);
460
+
461
+ /**
462
+ * Receive data through the filter chain at `sockindex` for connection
463
+ * `data->conn`. Copy at most `len` bytes into `buf`. Return the
464
+ * actual number of bytes copied or a negative value on error.
465
+ * The error code is placed into `*code`.
466
+ */
467
+ ssize_t Curl_cf_recv(struct Curl_easy *data, int sockindex, char *buf,
468
+ size_t len, CURLcode *code);
469
+
470
+ /**
471
+ * Send `len` bytes of data from `buf` through the filter chain `sockindex`
472
+ * at connection `data->conn`. Return the actual number of bytes written
473
+ * or a negative value on error.
474
+ * The error code is placed into `*code`.
475
+ */
476
+ ssize_t Curl_cf_send(struct Curl_easy *data, int sockindex,
477
+ const void *buf, size_t len, bool eos, CURLcode *code);
478
+
479
+ /**
480
+ * The easy handle `data` is being attached to `conn`. This does
481
+ * not mean that data will actually do a transfer. Attachment is
482
+ * also used for temporary actions on the connection.
483
+ */
484
+ void Curl_conn_ev_data_attach(struct connectdata *conn,
485
+ struct Curl_easy *data);
486
+
487
+ /**
488
+ * The easy handle `data` is being detached (no longer served)
489
+ * by connection `conn`. All filters are informed to release any resources
490
+ * related to `data`.
491
+ * Note: there may be several `data` attached to a connection at the same
492
+ * time.
493
+ */
494
+ void Curl_conn_ev_data_detach(struct connectdata *conn,
495
+ struct Curl_easy *data);
496
+
497
+ /**
498
+ * Notify connection filters that they need to setup data for
499
+ * a transfer.
500
+ */
501
+ CURLcode Curl_conn_ev_data_setup(struct Curl_easy *data);
502
+
503
+ /**
504
+ * Notify connection filters that now would be a good time to
505
+ * perform any idle, e.g. time related, actions.
506
+ */
507
+ CURLcode Curl_conn_ev_data_idle(struct Curl_easy *data);
508
+
509
+ /**
510
+ * Notify connection filters that the transfer represented by `data`
511
+ * is done with sending data (e.g. has uploaded everything).
512
+ */
513
+ void Curl_conn_ev_data_done_send(struct Curl_easy *data);
514
+
515
+ /**
516
+ * Notify connection filters that the transfer represented by `data`
517
+ * is finished - eventually premature, e.g. before being complete.
518
+ */
519
+ void Curl_conn_ev_data_done(struct Curl_easy *data, bool premature);
520
+
521
+ /**
522
+ * Notify connection filters that the transfer of data is paused/unpaused.
523
+ */
524
+ CURLcode Curl_conn_ev_data_pause(struct Curl_easy *data, bool do_pause);
525
+
526
+ /**
527
+ * Check if FIRSTSOCKET's cfilter chain deems connection alive.
528
+ */
529
+ bool Curl_conn_is_alive(struct Curl_easy *data, struct connectdata *conn,
530
+ bool *input_pending);
531
+
532
+ /**
533
+ * Try to upkeep the connection filters at sockindex.
534
+ */
535
+ CURLcode Curl_conn_keep_alive(struct Curl_easy *data,
536
+ struct connectdata *conn,
537
+ int sockindex);
538
+
539
+ #ifdef UNITTESTS
540
+ void Curl_cf_def_close(struct Curl_cfilter *cf, struct Curl_easy *data);
541
+ #endif
542
+ void Curl_conn_get_host(struct Curl_easy *data, int sockindex,
543
+ const char **phost, const char **pdisplay_host,
544
+ int *pport);
545
+
546
+ /**
547
+ * Get the maximum number of parallel transfers the connection
548
+ * expects to be able to handle at `sockindex`.
549
+ */
550
+ size_t Curl_conn_get_max_concurrent(struct Curl_easy *data,
551
+ struct connectdata *conn,
552
+ int sockindex);
553
+
554
+ /**
555
+ * Get the underlying error code for a transfer stream or 0 if not known.
556
+ */
557
+ int Curl_conn_get_stream_error(struct Curl_easy *data,
558
+ struct connectdata *conn,
559
+ int sockindex);
560
+
561
+ /**
562
+ * Get the index of the given socket in the connection's sockets.
563
+ * Useful in calling `Curl_conn_send()/Curl_conn_recv()` with the
564
+ * correct socket index.
565
+ */
566
+ int Curl_conn_sockindex(struct Curl_easy *data, curl_socket_t sockfd);
567
+
568
+ /*
569
+ * Receive data on the connection, using FIRSTSOCKET/SECONDARYSOCKET.
570
+ * Will return CURLE_AGAIN iff blocked on receiving.
571
+ */
572
+ CURLcode Curl_conn_recv(struct Curl_easy *data, int sockindex,
573
+ char *buf, size_t buffersize,
574
+ ssize_t *pnread);
575
+
576
+ /*
577
+ * Send data on the connection, using FIRSTSOCKET/SECONDARYSOCKET.
578
+ * Will return CURLE_AGAIN iff blocked on sending.
579
+ */
580
+ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex,
581
+ const void *buf, size_t blen, bool eos,
582
+ size_t *pnwritten);
583
+
584
+
585
+ void Curl_pollset_reset(struct Curl_easy *data,
586
+ struct easy_pollset *ps);
587
+
588
+ /* Change the poll flags (CURL_POLL_IN/CURL_POLL_OUT) to the poll set for
589
+ * socket `sock`. If the socket is not already part of the poll set, it
590
+ * will be added.
591
+ * If the socket is present and all poll flags are cleared, it will be removed.
592
+ */
593
+ void Curl_pollset_change(struct Curl_easy *data,
594
+ struct easy_pollset *ps, curl_socket_t sock,
595
+ int add_flags, int remove_flags);
596
+
597
+ void Curl_pollset_set(struct Curl_easy *data,
598
+ struct easy_pollset *ps, curl_socket_t sock,
599
+ bool do_in, bool do_out);
600
+
601
+ #define Curl_pollset_add_in(data, ps, sock) \
602
+ Curl_pollset_change((data), (ps), (sock), CURL_POLL_IN, 0)
603
+ #define Curl_pollset_add_out(data, ps, sock) \
604
+ Curl_pollset_change((data), (ps), (sock), CURL_POLL_OUT, 0)
605
+ #define Curl_pollset_add_inout(data, ps, sock) \
606
+ Curl_pollset_change((data), (ps), (sock), \
607
+ CURL_POLL_IN|CURL_POLL_OUT, 0)
608
+ #define Curl_pollset_set_in_only(data, ps, sock) \
609
+ Curl_pollset_change((data), (ps), (sock), \
610
+ CURL_POLL_IN, CURL_POLL_OUT)
611
+ #define Curl_pollset_set_out_only(data, ps, sock) \
612
+ Curl_pollset_change((data), (ps), (sock), \
613
+ CURL_POLL_OUT, CURL_POLL_IN)
614
+
615
+ void Curl_pollset_add_socks(struct Curl_easy *data,
616
+ struct easy_pollset *ps,
617
+ int (*get_socks_cb)(struct Curl_easy *data,
618
+ curl_socket_t *socks));
619
+
620
+ /**
621
+ * Check if the pollset, as is, wants to read and/or write regarding
622
+ * the given socket.
623
+ */
624
+ void Curl_pollset_check(struct Curl_easy *data,
625
+ struct easy_pollset *ps, curl_socket_t sock,
626
+ bool *pwant_read, bool *pwant_write);
627
+
628
+ /**
629
+ * Types and macros used to keep the current easy handle in filter calls,
630
+ * allowing for nested invocations. See #10336.
631
+ *
632
+ * `cf_call_data` is intended to be a member of the cfilter's `ctx` type.
633
+ * A filter defines the macro `CF_CTX_CALL_DATA` to give access to that.
634
+ *
635
+ * With all values 0, the default, this indicates that there is no cfilter
636
+ * call with `data` ongoing.
637
+ * Macro `CF_DATA_SAVE` preserves the current `cf_call_data` in a local
638
+ * variable and sets the `data` given, incrementing the `depth` counter.
639
+ *
640
+ * Macro `CF_DATA_RESTORE` restores the old values from the local variable,
641
+ * while checking that `depth` values are as expected (debug build), catching
642
+ * cases where a "lower" RESTORE was not called.
643
+ *
644
+ * Finally, macro `CF_DATA_CURRENT` gives the easy handle of the current
645
+ * invocation.
646
+ */
647
+ struct cf_call_data {
648
+ struct Curl_easy *data;
649
+ #ifdef DEBUGBUILD
650
+ int depth;
651
+ #endif
652
+ };
653
+
654
+ /**
655
+ * define to access the `struct cf_call_data for a cfilter. Normally
656
+ * a member in the cfilter's `ctx`.
657
+ *
658
+ * #define CF_CTX_CALL_DATA(cf) -> struct cf_call_data instance
659
+ */
660
+
661
+ #ifdef DEBUGBUILD
662
+
663
+ #define CF_DATA_SAVE(save, cf, data) \
664
+ do { \
665
+ (save) = CF_CTX_CALL_DATA(cf); \
666
+ DEBUGASSERT((save).data == NULL || (save).depth > 0); \
667
+ CF_CTX_CALL_DATA(cf).depth++; \
668
+ CF_CTX_CALL_DATA(cf).data = (struct Curl_easy *)data; \
669
+ } while(0)
670
+
671
+ #define CF_DATA_RESTORE(cf, save) \
672
+ do { \
673
+ DEBUGASSERT(CF_CTX_CALL_DATA(cf).depth == (save).depth + 1); \
674
+ DEBUGASSERT((save).data == NULL || (save).depth > 0); \
675
+ CF_CTX_CALL_DATA(cf) = (save); \
676
+ } while(0)
677
+
678
+ #else /* DEBUGBUILD */
679
+
680
+ #define CF_DATA_SAVE(save, cf, data) \
681
+ do { \
682
+ (save) = CF_CTX_CALL_DATA(cf); \
683
+ CF_CTX_CALL_DATA(cf).data = (struct Curl_easy *)data; \
684
+ } while(0)
685
+
686
+ #define CF_DATA_RESTORE(cf, save) \
687
+ do { \
688
+ CF_CTX_CALL_DATA(cf) = (save); \
689
+ } while(0)
690
+
691
+ #endif /* !DEBUGBUILD */
692
+
693
+ #define CF_DATA_CURRENT(cf) \
694
+ ((cf)? (CF_CTX_CALL_DATA(cf).data) : NULL)
695
+
696
+ #endif /* HEADER_CURL_CFILTERS_H */
local-test-curl-full-01/afc-curl/lib/config-os400.h ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CONFIG_OS400_H
2
+ #define HEADER_CURL_CONFIG_OS400_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ /* ================================================================ */
28
+ /* Hand crafted config file for OS/400 */
29
+ /* ================================================================ */
30
+
31
+ #pragma enum(int)
32
+
33
+ #undef PACKAGE
34
+
35
+ /* Version number of this archive. */
36
+ #undef VERSION
37
+
38
+ /* Define cpu-machine-OS */
39
+ #ifndef CURL_OS
40
+ #define CURL_OS "OS/400"
41
+ #endif
42
+
43
+ /* OS400 supports a 3-argument ASCII version of gethostbyaddr_r(), but its
44
+ * prototype is incompatible with the "standard" one (1st argument is not
45
+ * const). However, getaddrinfo() is supported (ASCII version defined as
46
+ * a local wrapper in setup-os400.h) in a threadsafe way: we can then
47
+ * configure getaddrinfo() as such and get rid of gethostbyname_r() without
48
+ * loss of threadsafeness. */
49
+ #undef HAVE_GETHOSTBYNAME_R
50
+ #undef HAVE_GETHOSTBYNAME_R_3
51
+ #undef HAVE_GETHOSTBYNAME_R_5
52
+ #undef HAVE_GETHOSTBYNAME_R_6
53
+ #define HAVE_GETADDRINFO
54
+ #define HAVE_GETADDRINFO_THREADSAFE
55
+
56
+ /* Define if you need the _REENTRANT define for some functions */
57
+ #undef NEED_REENTRANT
58
+
59
+ /* Define if you want to enable IPv6 support */
60
+ #define USE_IPV6
61
+
62
+ /* Define if struct sockaddr_in6 has the sin6_scope_id member */
63
+ #define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
64
+
65
+ /* Define this to 'int' if ssize_t is not an available typedefed type */
66
+ #undef ssize_t
67
+
68
+ /* Define to 1 if you have the alarm function. */
69
+ #define HAVE_ALARM 1
70
+
71
+ /* Define if you have the <arpa/inet.h> header file. */
72
+ #define HAVE_ARPA_INET_H
73
+
74
+ /* Define if you have the `closesocket' function. */
75
+ #undef HAVE_CLOSESOCKET
76
+
77
+ /* Define if you have the <fcntl.h> header file. */
78
+ #define HAVE_FCNTL_H
79
+
80
+ /* Define if you have the `geteuid' function. */
81
+ #define HAVE_GETEUID
82
+
83
+ /* Define if you have the `gethostname' function. */
84
+ #define HAVE_GETHOSTNAME
85
+
86
+ /* Define if you have the `getpass_r' function. */
87
+ #undef HAVE_GETPASS_R
88
+
89
+ /* Define to 1 if you have the getpeername function. */
90
+ #define HAVE_GETPEERNAME 1
91
+
92
+ /* Define if you have the `getpwuid' function. */
93
+ #define HAVE_GETPWUID
94
+
95
+ /* Define to 1 if you have the getsockname function. */
96
+ #define HAVE_GETSOCKNAME 1
97
+
98
+ /* Define if you have the `gettimeofday' function. */
99
+ #define HAVE_GETTIMEOFDAY
100
+
101
+ /* Define if you have the `timeval' struct. */
102
+ #define HAVE_STRUCT_TIMEVAL
103
+
104
+ /* Define if you have the <io.h> header file. */
105
+ #undef HAVE_IO_H
106
+
107
+ /* Define if you have GSS API. */
108
+ #define HAVE_GSSAPI
109
+
110
+ /* Define if you have the GNU gssapi libraries */
111
+ #undef HAVE_GSSGNU
112
+
113
+ /* Define if you need the malloc.h header file even with stdlib.h */
114
+ /* #define NEED_MALLOC_H 1 */
115
+
116
+ /* Define if you have the <netdb.h> header file. */
117
+ #define HAVE_NETDB_H
118
+
119
+ /* Define if you have the <netinet/in.h> header file. */
120
+ #define HAVE_NETINET_IN_H
121
+
122
+ /* Define if you have the <net/if.h> header file. */
123
+ #define HAVE_NET_IF_H
124
+
125
+ /* Define if you have the <pwd.h> header file. */
126
+ #define HAVE_PWD_H
127
+
128
+ /* Define if you have the `select' function. */
129
+ #define HAVE_SELECT
130
+
131
+ /* Define if you have the `sigaction' function. */
132
+ #define HAVE_SIGACTION
133
+
134
+ /* Define if you have the `signal' function. */
135
+ #undef HAVE_SIGNAL
136
+
137
+ /* Define if you have the `socket' function. */
138
+ #define HAVE_SOCKET
139
+
140
+
141
+ /* The following define is needed on OS400 to enable strcmpi(), stricmp() and
142
+ strdup(). */
143
+ #define __cplusplus__strings__
144
+
145
+ /* Define if you have the `strcasecmp' function. */
146
+ #undef HAVE_STRCASECMP
147
+
148
+ /* Define if you have the `strcmpi' function. */
149
+ #define HAVE_STRCMPI
150
+
151
+ /* Define if you have the `stricmp' function. */
152
+ #define HAVE_STRICMP
153
+
154
+ /* Define if you have the `strdup' function. */
155
+ #define HAVE_STRDUP
156
+
157
+ /* Define if you have the <strings.h> header file. */
158
+ #define HAVE_STRINGS_H
159
+
160
+ /* Define if you have the <stropts.h> header file. */
161
+ #undef HAVE_STROPTS_H
162
+
163
+ /* Define if you have the `strtok_r' function. */
164
+ #define HAVE_STRTOK_R
165
+
166
+ /* Define if you have the `strtoll' function. */
167
+ #undef HAVE_STRTOLL /* Allows ASCII compile on V5R1. */
168
+
169
+ /* Define if you have the <sys/param.h> header file. */
170
+ #define HAVE_SYS_PARAM_H
171
+
172
+ /* Define if you have the <sys/select.h> header file. */
173
+ #undef HAVE_SYS_SELECT_H
174
+
175
+ /* Define if you have the <sys/socket.h> header file. */
176
+ #define HAVE_SYS_SOCKET_H
177
+
178
+ /* Define if you have the <sys/sockio.h> header file. */
179
+ #undef HAVE_SYS_SOCKIO_H
180
+
181
+ /* Define if you have the <sys/stat.h> header file. */
182
+ #define HAVE_SYS_STAT_H
183
+
184
+ /* Define if you have the <sys/time.h> header file. */
185
+ #define HAVE_SYS_TIME_H
186
+
187
+ /* Define if you have the <sys/types.h> header file. */
188
+ #define HAVE_SYS_TYPES_H
189
+
190
+ /* Define if you have the <sys/un.h> header file. */
191
+ #define HAVE_SYS_UN_H
192
+
193
+ /* Define if you have the <sys/ioctl.h> header file. */
194
+ #define HAVE_SYS_IOCTL_H
195
+
196
+ /* Define if you have the <termios.h> header file. */
197
+ #undef HAVE_TERMIOS_H
198
+
199
+ /* Define if you have the <termio.h> header file. */
200
+ #undef HAVE_TERMIO_H
201
+
202
+ /* Define if you have the <unistd.h> header file. */
203
+ #define HAVE_UNISTD_H
204
+
205
+ /* Name of package */
206
+ #undef PACKAGE
207
+
208
+ /* The size of `int', as computed by sizeof. */
209
+ #define SIZEOF_INT 4
210
+
211
+ /* Define if the compiler supports the 'long long' data type. */
212
+ #define HAVE_LONGLONG
213
+
214
+ /* The size of a `long long', as computed by sizeof. */
215
+ #define SIZEOF_LONG_LONG 8
216
+
217
+ /* The size of `long', as computed by sizeof. */
218
+ #define SIZEOF_LONG 4
219
+
220
+ /* The size of `size_t', as computed by sizeof. */
221
+ #define SIZEOF_SIZE_T 4
222
+
223
+ /* The size of `curl_off_t', as computed by sizeof. */
224
+ #define SIZEOF_CURL_OFF_T 8
225
+
226
+ /* Define this if you have struct sockaddr_storage */
227
+ #define HAVE_STRUCT_SOCKADDR_STORAGE
228
+
229
+ /* Define if you have the ANSI C header files. */
230
+ #define STDC_HEADERS
231
+
232
+ /* Define to enable HTTP3 support (experimental, requires NGTCP2, quiche or
233
+ MSH3) */
234
+ #undef USE_HTTP3
235
+
236
+ /* Version number of package */
237
+ #undef VERSION
238
+
239
+ /* Number of bits in a file offset, on hosts where this is settable. */
240
+ #undef _FILE_OFFSET_BITS
241
+
242
+ /* Define for large files, on AIX-style hosts. */
243
+ #define _LARGE_FILES
244
+
245
+ /* Define to empty if `const' does not conform to ANSI C. */
246
+ #undef const
247
+
248
+ /* type to use in place of in_addr_t if not defined */
249
+ #define in_addr_t unsigned long
250
+
251
+ /* Define to `unsigned' if <sys/types.h> does not define. */
252
+ #undef size_t
253
+
254
+ /* Define if you have a working ioctl FIONBIO function. */
255
+ #define HAVE_IOCTL_FIONBIO
256
+
257
+ /* Define if you have a working ioctl SIOCGIFADDR function. */
258
+ #define HAVE_IOCTL_SIOCGIFADDR
259
+
260
+ /* To disable LDAP */
261
+ #undef CURL_DISABLE_LDAP
262
+
263
+ /* Definition to make a library symbol externally visible. */
264
+ #define CURL_EXTERN_SYMBOL
265
+
266
+ /* Define if you have the ldap_url_parse procedure. */
267
+ /* #define HAVE_LDAP_URL_PARSE */ /* Disabled because of an IBM bug. */
268
+
269
+ /* Define if you have the recv function. */
270
+ #define HAVE_RECV
271
+
272
+ /* Define to the type of arg 1 for recv. */
273
+ #define RECV_TYPE_ARG1 int
274
+
275
+ /* Define to the type of arg 2 for recv. */
276
+ #define RECV_TYPE_ARG2 char *
277
+
278
+ /* Define to the type of arg 3 for recv. */
279
+ #define RECV_TYPE_ARG3 int
280
+
281
+ /* Define to the type of arg 4 for recv. */
282
+ #define RECV_TYPE_ARG4 int
283
+
284
+ /* Define to the function return type for recv. */
285
+ #define RECV_TYPE_RETV int
286
+
287
+ /* Define if you have the send function. */
288
+ #define HAVE_SEND
289
+
290
+ /* Define to the type of arg 1 for send. */
291
+ #define SEND_TYPE_ARG1 int
292
+
293
+ /* Define to the type qualifier of arg 2 for send. */
294
+ #define SEND_QUAL_ARG2
295
+
296
+ /* Define to the type of arg 2 for send. */
297
+ #define SEND_TYPE_ARG2 char *
298
+
299
+ /* Define to the type of arg 3 for send. */
300
+ #define SEND_TYPE_ARG3 int
301
+
302
+ /* Define to the type of arg 4 for send. */
303
+ #define SEND_TYPE_ARG4 int
304
+
305
+ /* Define to the function return type for send. */
306
+ #define SEND_TYPE_RETV int
307
+
308
+ /* Define to use the OS/400 crypto library. */
309
+ #define USE_OS400CRYPTO
310
+
311
+ /* Define to use Unix sockets. */
312
+ #define USE_UNIX_SOCKETS
313
+
314
+ /* Use the system keyring as the default CA bundle. */
315
+ #define CURL_CA_BUNDLE "/QIBM/UserData/ICSS/Cert/Server/DEFAULT.KDB"
316
+
317
+ /* ---------------------------------------------------------------- */
318
+ /* ADDITIONAL DEFINITIONS */
319
+ /* ---------------------------------------------------------------- */
320
+
321
+ /* The following must be defined BEFORE system header files inclusion. */
322
+
323
+ #define __ptr128 /* No teraspace. */
324
+ #define qadrt_use_fputc_inline /* Generate fputc() wrapper inline. */
325
+ #define qadrt_use_fread_inline /* Generate fread() wrapper inline. */
326
+ #define qadrt_use_fwrite_inline /* Generate fwrite() wrapper inline. */
327
+
328
+ #endif /* HEADER_CURL_CONFIG_OS400_H */
local-test-curl-full-01/afc-curl/lib/config-plan9.h ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CONFIG_PLAN9_H
2
+ #define HEADER_CURL_CONFIG_PLAN9_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #define BUILDING_LIBCURL 1
28
+ #define CURL_CA_BUNDLE "/sys/lib/tls/ca.pem"
29
+ #define CURL_CA_PATH "/sys/lib/tls"
30
+ #define CURL_STATICLIB 1
31
+ #define USE_IPV6 1
32
+ #define CURL_DISABLE_LDAP 1
33
+
34
+ #define NEED_REENTRANT 1
35
+ #ifndef CURL_OS
36
+ #define CURL_OS "plan9"
37
+ #endif
38
+ #define PACKAGE "curl"
39
+ #define PACKAGE_NAME "curl"
40
+ #define PACKAGE_BUGREPORT "a suitable mailing list: https://curl.se/mail/"
41
+ #define PACKAGE_STRING "curl -"
42
+ #define PACKAGE_TARNAME "curl"
43
+ #define PACKAGE_VERSION "-"
44
+ #define VERSION "0.0.0" /* TODO */
45
+
46
+ #define STDC_HEADERS 1
47
+
48
+ #ifdef _BITS64
49
+ #error not implement
50
+ #else
51
+ #define SIZEOF_INT 4
52
+ #define SIZEOF_LONG 4
53
+ #define SIZEOF_OFF_T 8
54
+ #define SIZEOF_CURL_OFF_T 4 /* curl_off_t = timediff_t = int */
55
+ #define SIZEOF_SIZE_T 4
56
+ #define SIZEOF_TIME_T 4
57
+ #endif
58
+
59
+ #define HAVE_RECV 1
60
+ #define RECV_TYPE_ARG1 int
61
+ #define RECV_TYPE_ARG2 void *
62
+ #define RECV_TYPE_ARG3 int
63
+ #define RECV_TYPE_ARG4 int
64
+ #define RECV_TYPE_RETV int
65
+
66
+ #define HAVE_SELECT 1
67
+
68
+ #define HAVE_SEND 1
69
+ #define SEND_TYPE_ARG1 int
70
+ #define SEND_TYPE_ARG2 void *
71
+ #define SEND_QUAL_ARG2
72
+ #define SEND_TYPE_ARG3 int
73
+ #define SEND_TYPE_ARG4 int
74
+ #define SEND_TYPE_RETV int
75
+
76
+ #define HAVE_ALARM 1
77
+ #define HAVE_ARPA_INET_H 1
78
+ #define HAVE_BASENAME 1
79
+ #define HAVE_BOOL_T 1
80
+ #define HAVE_FCNTL 1
81
+ #define HAVE_FCNTL_H 1
82
+ #define HAVE_FREEADDRINFO 1
83
+ #define HAVE_FTRUNCATE 1
84
+ #define HAVE_GETADDRINFO 1
85
+ #define HAVE_GETEUID 1
86
+ #define HAVE_GETHOSTNAME 1
87
+ #define HAVE_GETPPID 1
88
+ #define HAVE_GETPWUID 1
89
+ #define HAVE_GETTIMEOFDAY 1
90
+ #define HAVE_GMTIME_R 1
91
+ #define HAVE_INET_NTOP 1
92
+ #define HAVE_INET_PTON 1
93
+ #define HAVE_LIBGEN_H 1
94
+ #define HAVE_LIBZ 1
95
+ #define HAVE_LOCALE_H 1
96
+ #define HAVE_LONGLONG 1
97
+ #define HAVE_NETDB_H 1
98
+ #define HAVE_NETINET_IN_H 1
99
+ #define HAVE_NETINET_TCP_H 1
100
+ #define HAVE_PWD_H 1
101
+ #define HAVE_SYS_SELECT_H 1
102
+
103
+ #define USE_OPENSSL 1
104
+
105
+ #define HAVE_PIPE 1
106
+ #define HAVE_POLL 1
107
+ #define HAVE_POLL_H 1
108
+ #define HAVE_PTHREAD_H 1
109
+ #define HAVE_SETLOCALE 1
110
+
111
+ #define HAVE_SIGACTION 1
112
+ #define HAVE_SIGNAL 1
113
+ #define HAVE_SIGSETJMP 1
114
+ #define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
115
+ #define HAVE_SOCKET 1
116
+ #define HAVE_SSL_GET_SHUTDOWN 1
117
+ #define HAVE_STDBOOL_H 1
118
+ #define HAVE_STRCASECMP 1
119
+ #define HAVE_STRDUP 1
120
+ #define HAVE_STRTOK_R 1
121
+ #define HAVE_STRTOLL 1
122
+ #define HAVE_STRUCT_TIMEVAL 1
123
+ #define HAVE_SYS_IOCTL_H 1
124
+ #define HAVE_SYS_PARAM_H 1
125
+ #define HAVE_SYS_RESOURCE_H 1
126
+ #define HAVE_SYS_SOCKET_H 1
127
+ #define HAVE_SYS_STAT_H 1
128
+ #define HAVE_SYS_TIME_H 1
129
+ #define HAVE_SYS_TYPES_H 1
130
+ #define HAVE_SYS_UN_H 1
131
+ #define HAVE_TERMIOS_H 1
132
+ #define HAVE_UNISTD_H 1
133
+ #define HAVE_UTIME 1
134
+ #define HAVE_UTIME_H 1
135
+
136
+ #define HAVE_POSIX_STRERROR_R 1
137
+ #define HAVE_STRERROR_R 1
138
+ #define USE_MANUAL 1
139
+
140
+ #define __attribute__(x)
141
+
142
+ #ifndef __cplusplus
143
+ #undef inline
144
+ #endif
145
+
146
+ #endif /* HEADER_CURL_CONFIG_PLAN9_H */
local-test-curl-full-01/afc-curl/lib/config-win32.h ADDED
@@ -0,0 +1,511 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CONFIG_WIN32_H
2
+ #define HEADER_CURL_CONFIG_WIN32_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ /* ================================================================ */
28
+ /* Hand crafted config file for Windows */
29
+ /* ================================================================ */
30
+
31
+ /* ---------------------------------------------------------------- */
32
+ /* HEADER FILES */
33
+ /* ---------------------------------------------------------------- */
34
+
35
+ /* Define if you have the <arpa/inet.h> header file. */
36
+ /* #define HAVE_ARPA_INET_H 1 */
37
+
38
+ /* Define if you have the <fcntl.h> header file. */
39
+ #define HAVE_FCNTL_H 1
40
+
41
+ /* Define if you have the <io.h> header file. */
42
+ #define HAVE_IO_H 1
43
+
44
+ /* Define if you have the <locale.h> header file. */
45
+ #define HAVE_LOCALE_H 1
46
+
47
+ /* Define if you need <malloc.h> header even with <stdlib.h> header file. */
48
+ #define NEED_MALLOC_H 1
49
+
50
+ /* Define if you have the <netdb.h> header file. */
51
+ /* #define HAVE_NETDB_H 1 */
52
+
53
+ /* Define if you have the <netinet/in.h> header file. */
54
+ /* #define HAVE_NETINET_IN_H 1 */
55
+
56
+ /* Define to 1 if you have the <stdbool.h> header file. */
57
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
58
+ #define HAVE_STDBOOL_H 1
59
+ #endif
60
+
61
+ /* Define if you have the <sys/param.h> header file. */
62
+ #if defined(__MINGW32__)
63
+ #define HAVE_SYS_PARAM_H 1
64
+ #endif
65
+
66
+ /* Define if you have the <sys/select.h> header file. */
67
+ /* #define HAVE_SYS_SELECT_H 1 */
68
+
69
+ /* Define if you have the <sys/socket.h> header file. */
70
+ /* #define HAVE_SYS_SOCKET_H 1 */
71
+
72
+ /* Define if you have the <sys/sockio.h> header file. */
73
+ /* #define HAVE_SYS_SOCKIO_H 1 */
74
+
75
+ /* Define if you have the <sys/stat.h> header file. */
76
+ #define HAVE_SYS_STAT_H 1
77
+
78
+ /* Define if you have the <sys/time.h> header file. */
79
+ #if defined(__MINGW32__)
80
+ #define HAVE_SYS_TIME_H 1
81
+ #endif
82
+
83
+ /* Define if you have the <sys/types.h> header file. */
84
+ #define HAVE_SYS_TYPES_H 1
85
+
86
+ /* Define if you have the <sys/utime.h> header file. */
87
+ #define HAVE_SYS_UTIME_H 1
88
+
89
+ /* Define if you have the <termio.h> header file. */
90
+ /* #define HAVE_TERMIO_H 1 */
91
+
92
+ /* Define if you have the <termios.h> header file. */
93
+ /* #define HAVE_TERMIOS_H 1 */
94
+
95
+ /* Define if you have the <unistd.h> header file. */
96
+ #if defined(__MINGW32__)
97
+ #define HAVE_UNISTD_H 1
98
+ #endif
99
+
100
+ /* Define to 1 if you have the <libgen.h> header file. */
101
+ #if defined(__MINGW32__)
102
+ #define HAVE_LIBGEN_H 1
103
+ #endif
104
+
105
+ /* ---------------------------------------------------------------- */
106
+ /* OTHER HEADER INFO */
107
+ /* ---------------------------------------------------------------- */
108
+
109
+ /* Define if you have the ANSI C header files. */
110
+ #define STDC_HEADERS 1
111
+
112
+ /* Define to 1 if bool is an available type. */
113
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
114
+ #define HAVE_BOOL_T 1
115
+ #endif
116
+
117
+ /* ---------------------------------------------------------------- */
118
+ /* FUNCTIONS */
119
+ /* ---------------------------------------------------------------- */
120
+
121
+ /* Define if you have the closesocket function. */
122
+ #define HAVE_CLOSESOCKET 1
123
+
124
+ /* Define if you have the ftruncate function. */
125
+ #if defined(__MINGW32__)
126
+ #define HAVE_FTRUNCATE 1
127
+ #endif
128
+
129
+ /* Define to 1 if you have the `getpeername' function. */
130
+ #define HAVE_GETPEERNAME 1
131
+
132
+ /* Define to 1 if you have the getsockname function. */
133
+ #define HAVE_GETSOCKNAME 1
134
+
135
+ /* Define if you have the gethostname function. */
136
+ #define HAVE_GETHOSTNAME 1
137
+
138
+ /* Define if you have the gettimeofday function. */
139
+ #if defined(__MINGW32__)
140
+ #define HAVE_GETTIMEOFDAY 1
141
+ #endif
142
+
143
+ /* Define if you have the ioctlsocket function. */
144
+ #define HAVE_IOCTLSOCKET 1
145
+
146
+ /* Define if you have a working ioctlsocket FIONBIO function. */
147
+ #define HAVE_IOCTLSOCKET_FIONBIO 1
148
+
149
+ /* Define if you have the select function. */
150
+ #define HAVE_SELECT 1
151
+
152
+ /* Define if you have the setlocale function. */
153
+ #define HAVE_SETLOCALE 1
154
+
155
+ /* Define if you have the setmode function. */
156
+ #define HAVE_SETMODE 1
157
+
158
+ /* Define if you have the _setmode function. */
159
+ #define HAVE__SETMODE 1
160
+
161
+ /* Define if you have the socket function. */
162
+ #define HAVE_SOCKET 1
163
+
164
+ /* Define if you have the strcasecmp function. */
165
+ #if defined(__MINGW32__)
166
+ #define HAVE_STRCASECMP 1
167
+ #endif
168
+
169
+ /* Define if you have the strdup function. */
170
+ #define HAVE_STRDUP 1
171
+
172
+ /* Define if you have the stricmp function. */
173
+ #define HAVE_STRICMP 1
174
+
175
+ /* Define if you have the strtoll function. */
176
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
177
+ #define HAVE_STRTOLL 1
178
+ #endif
179
+
180
+ /* Define if you have the utime function. */
181
+ #define HAVE_UTIME 1
182
+
183
+ /* Define if you have the recv function. */
184
+ #define HAVE_RECV 1
185
+
186
+ /* Define to the type of arg 1 for recv. */
187
+ #define RECV_TYPE_ARG1 SOCKET
188
+
189
+ /* Define to the type of arg 2 for recv. */
190
+ #define RECV_TYPE_ARG2 char *
191
+
192
+ /* Define to the type of arg 3 for recv. */
193
+ #define RECV_TYPE_ARG3 int
194
+
195
+ /* Define to the type of arg 4 for recv. */
196
+ #define RECV_TYPE_ARG4 int
197
+
198
+ /* Define to the function return type for recv. */
199
+ #define RECV_TYPE_RETV int
200
+
201
+ /* Define if you have the send function. */
202
+ #define HAVE_SEND 1
203
+
204
+ /* Define to the type of arg 1 for send. */
205
+ #define SEND_TYPE_ARG1 SOCKET
206
+
207
+ /* Define to the type qualifier of arg 2 for send. */
208
+ #define SEND_QUAL_ARG2 const
209
+
210
+ /* Define to the type of arg 2 for send. */
211
+ #define SEND_TYPE_ARG2 char *
212
+
213
+ /* Define to the type of arg 3 for send. */
214
+ #define SEND_TYPE_ARG3 int
215
+
216
+ /* Define to the type of arg 4 for send. */
217
+ #define SEND_TYPE_ARG4 int
218
+
219
+ /* Define to the function return type for send. */
220
+ #define SEND_TYPE_RETV int
221
+
222
+ /* Define to 1 if you have the snprintf function. */
223
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || defined(__MINGW32__)
224
+ #define HAVE_SNPRINTF 1
225
+ #endif
226
+
227
+ #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 /* Vista */
228
+ /* Define to 1 if you have a IPv6 capable working inet_ntop function. */
229
+ #define HAVE_INET_NTOP 1
230
+ /* Define to 1 if you have a IPv6 capable working inet_pton function. */
231
+ #define HAVE_INET_PTON 1
232
+ #endif
233
+
234
+ /* Define to 1 if you have the `basename' function. */
235
+ #if defined(__MINGW32__)
236
+ #define HAVE_BASENAME 1
237
+ #endif
238
+
239
+ /* Define to 1 if you have the strtok_r function. */
240
+ #if defined(__MINGW32__)
241
+ #define HAVE_STRTOK_R 1
242
+ #endif
243
+
244
+ /* Define to 1 if you have the signal function. */
245
+ #define HAVE_SIGNAL 1
246
+
247
+ /* ---------------------------------------------------------------- */
248
+ /* TYPEDEF REPLACEMENTS */
249
+ /* ---------------------------------------------------------------- */
250
+
251
+ /* Define if in_addr_t is not an available 'typedefed' type. */
252
+ #define in_addr_t unsigned long
253
+
254
+ /* Define if ssize_t is not an available 'typedefed' type. */
255
+ #ifndef _SSIZE_T_DEFINED
256
+ # if defined(__MINGW32__)
257
+ # elif defined(_WIN64)
258
+ # define _SSIZE_T_DEFINED
259
+ # define ssize_t __int64
260
+ # else
261
+ # define _SSIZE_T_DEFINED
262
+ # define ssize_t int
263
+ # endif
264
+ #endif
265
+
266
+ /* ---------------------------------------------------------------- */
267
+ /* TYPE SIZES */
268
+ /* ---------------------------------------------------------------- */
269
+
270
+ /* Define to the size of `int', as computed by sizeof. */
271
+ #define SIZEOF_INT 4
272
+
273
+ /* Define to the size of `long long', as computed by sizeof. */
274
+ /* #define SIZEOF_LONG_LONG 8 */
275
+
276
+ /* Define to the size of `long', as computed by sizeof. */
277
+ #define SIZEOF_LONG 4
278
+
279
+ /* Define to the size of `size_t', as computed by sizeof. */
280
+ #if defined(_WIN64)
281
+ # define SIZEOF_SIZE_T 8
282
+ #else
283
+ # define SIZEOF_SIZE_T 4
284
+ #endif
285
+
286
+ /* Define to the size of `curl_off_t', as computed by sizeof. */
287
+ #define SIZEOF_CURL_OFF_T 8
288
+
289
+ /* ---------------------------------------------------------------- */
290
+ /* COMPILER SPECIFIC */
291
+ /* ---------------------------------------------------------------- */
292
+
293
+ /* Define to nothing if compiler does not support 'const' qualifier. */
294
+ /* #define const */
295
+
296
+ /* Define to nothing if compiler does not support 'volatile' qualifier. */
297
+ /* #define volatile */
298
+
299
+ /* Windows should not have HAVE_GMTIME_R defined */
300
+ /* #undef HAVE_GMTIME_R */
301
+
302
+ /* Define if the compiler supports the 'long long' data type. */
303
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1310)) || defined(__MINGW32__)
304
+ #define HAVE_LONGLONG 1
305
+ #endif
306
+
307
+ /* Define to avoid VS2005 complaining about portable C functions. */
308
+ #if defined(_MSC_VER) && (_MSC_VER >= 1400)
309
+ #define _CRT_SECURE_NO_DEPRECATE 1
310
+ #define _CRT_NONSTDC_NO_DEPRECATE 1
311
+ #endif
312
+
313
+ /* mingw-w64 and visual studio >= 2005 (MSVCR80)
314
+ all default to 64-bit time_t unless _USE_32BIT_TIME_T is defined */
315
+ #if (defined(_MSC_VER) && (_MSC_VER >= 1400)) || defined(__MINGW32__)
316
+ # ifndef _USE_32BIT_TIME_T
317
+ # define SIZEOF_TIME_T 8
318
+ # else
319
+ # define SIZEOF_TIME_T 4
320
+ # endif
321
+ #endif
322
+
323
+ /* Define some minimum and default build targets for Visual Studio */
324
+ #if defined(_MSC_VER)
325
+ /* Officially, Microsoft's Windows SDK versions 6.X does not support Windows
326
+ 2000 as a supported build target. VS2008 default installations provides
327
+ an embedded Windows SDK v6.0A along with the claim that Windows 2000 is a
328
+ valid build target for VS2008. Popular belief is that binaries built with
329
+ VS2008 using Windows SDK versions v6.X and Windows 2000 as a build target
330
+ are functional. */
331
+ # define VS2008_MIN_TARGET 0x0500
332
+
333
+ /* The minimum build target for VS2012 is Vista unless Update 1 is installed
334
+ and the v110_xp toolset is chosen. */
335
+ # if defined(_USING_V110_SDK71_)
336
+ # define VS2012_MIN_TARGET 0x0501
337
+ # else
338
+ # define VS2012_MIN_TARGET 0x0600
339
+ # endif
340
+
341
+ /* VS2008 default build target is Windows Vista. We override default target
342
+ to be Windows XP. */
343
+ # define VS2008_DEF_TARGET 0x0501
344
+
345
+ /* VS2012 default build target is Windows Vista unless Update 1 is installed
346
+ and the v110_xp toolset is chosen. */
347
+ # if defined(_USING_V110_SDK71_)
348
+ # define VS2012_DEF_TARGET 0x0501
349
+ # else
350
+ # define VS2012_DEF_TARGET 0x0600
351
+ # endif
352
+ #endif
353
+
354
+ /* VS2008 default target settings and minimum build target check. */
355
+ #if defined(_MSC_VER) && (_MSC_VER >= 1500) && (_MSC_VER <= 1600)
356
+ # ifndef _WIN32_WINNT
357
+ # define _WIN32_WINNT VS2008_DEF_TARGET
358
+ # endif
359
+ # ifndef WINVER
360
+ # define WINVER VS2008_DEF_TARGET
361
+ # endif
362
+ # if (_WIN32_WINNT < VS2008_MIN_TARGET) || (WINVER < VS2008_MIN_TARGET)
363
+ # error VS2008 does not support Windows build targets prior to Windows 2000
364
+ # endif
365
+ #endif
366
+
367
+ /* VS2012 default target settings and minimum build target check. */
368
+ #if defined(_MSC_VER) && (_MSC_VER >= 1700)
369
+ # ifndef _WIN32_WINNT
370
+ # define _WIN32_WINNT VS2012_DEF_TARGET
371
+ # endif
372
+ # ifndef WINVER
373
+ # define WINVER VS2012_DEF_TARGET
374
+ # endif
375
+ # if (_WIN32_WINNT < VS2012_MIN_TARGET) || (WINVER < VS2012_MIN_TARGET)
376
+ # if defined(_USING_V110_SDK71_)
377
+ # error VS2012 does not support Windows build targets prior to Windows XP
378
+ # else
379
+ # error VS2012 does not support Windows build targets prior to Windows \
380
+ Vista
381
+ # endif
382
+ # endif
383
+ #endif
384
+
385
+ /* Windows XP is required for freeaddrinfo, getaddrinfo */
386
+ #define HAVE_FREEADDRINFO 1
387
+ #define HAVE_GETADDRINFO 1
388
+ #define HAVE_GETADDRINFO_THREADSAFE 1
389
+
390
+ /* ---------------------------------------------------------------- */
391
+ /* STRUCT RELATED */
392
+ /* ---------------------------------------------------------------- */
393
+
394
+ /* Define if you have struct sockaddr_storage. */
395
+ #define HAVE_STRUCT_SOCKADDR_STORAGE 1
396
+
397
+ /* Define if you have struct timeval. */
398
+ #define HAVE_STRUCT_TIMEVAL 1
399
+
400
+ /* Define if struct sockaddr_in6 has the sin6_scope_id member. */
401
+ #define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
402
+
403
+ /* ---------------------------------------------------------------- */
404
+ /* LARGE FILE SUPPORT */
405
+ /* ---------------------------------------------------------------- */
406
+
407
+ #if defined(_MSC_VER) && !defined(_WIN32_WCE)
408
+ # if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
409
+ # define USE_WIN32_LARGE_FILES
410
+ # else
411
+ # define USE_WIN32_SMALL_FILES
412
+ # endif
413
+ #endif
414
+
415
+ #if defined(__MINGW32__) && !defined(USE_WIN32_LARGE_FILES)
416
+ # define USE_WIN32_LARGE_FILES
417
+ #endif
418
+
419
+ #if !defined(USE_WIN32_LARGE_FILES) && !defined(USE_WIN32_SMALL_FILES)
420
+ # define USE_WIN32_SMALL_FILES
421
+ #endif
422
+
423
+ /* Number of bits in a file offset, on hosts where this is settable. */
424
+ #if defined(USE_WIN32_LARGE_FILES) && defined(__MINGW32__)
425
+ # ifndef _FILE_OFFSET_BITS
426
+ # define _FILE_OFFSET_BITS 64
427
+ # endif
428
+ #endif
429
+
430
+ /* Define to the size of `off_t', as computed by sizeof. */
431
+ #if defined(__MINGW32__) && \
432
+ defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
433
+ # define SIZEOF_OFF_T 8
434
+ #else
435
+ # define SIZEOF_OFF_T 4
436
+ #endif
437
+
438
+ /* ---------------------------------------------------------------- */
439
+ /* DNS RESOLVER SPECIALTY */
440
+ /* ---------------------------------------------------------------- */
441
+
442
+ /*
443
+ * Undefine both USE_ARES and USE_THREADS_WIN32 for synchronous DNS.
444
+ */
445
+
446
+ /* Define to enable c-ares asynchronous DNS lookups. */
447
+ /* #define USE_ARES 1 */
448
+
449
+ /* Default define to enable threaded asynchronous DNS lookups. */
450
+ #if !defined(USE_SYNC_DNS) && !defined(USE_ARES) && \
451
+ !defined(USE_THREADS_WIN32)
452
+ # define USE_THREADS_WIN32 1
453
+ #endif
454
+
455
+ #if defined(USE_ARES) && defined(USE_THREADS_WIN32)
456
+ # error "Only one DNS lookup specialty may be defined at most"
457
+ #endif
458
+
459
+ /* ---------------------------------------------------------------- */
460
+ /* LDAP SUPPORT */
461
+ /* ---------------------------------------------------------------- */
462
+
463
+ #if defined(CURL_HAS_NOVELL_LDAPSDK)
464
+ #undef USE_WIN32_LDAP
465
+ #define HAVE_LDAP_SSL_H 1
466
+ #define HAVE_LDAP_URL_PARSE 1
467
+ #elif defined(CURL_HAS_OPENLDAP_LDAPSDK)
468
+ #undef USE_WIN32_LDAP
469
+ #define HAVE_LDAP_URL_PARSE 1
470
+ #else
471
+ #undef HAVE_LDAP_URL_PARSE
472
+ #define HAVE_LDAP_SSL 1
473
+ #define USE_WIN32_LDAP 1
474
+ #endif
475
+
476
+ /* Define to use the Windows crypto library. */
477
+ #if !defined(CURL_WINDOWS_UWP)
478
+ #define USE_WIN32_CRYPTO
479
+ #endif
480
+
481
+ /* Define to use Unix sockets. */
482
+ #define USE_UNIX_SOCKETS
483
+
484
+ /* ---------------------------------------------------------------- */
485
+ /* ADDITIONAL DEFINITIONS */
486
+ /* ---------------------------------------------------------------- */
487
+
488
+ /* Define cpu-machine-OS */
489
+ #ifndef CURL_OS
490
+ #if defined(_M_IX86) || defined(__i386__) /* x86 (MSVC or gcc) */
491
+ #define CURL_OS "i386-pc-win32"
492
+ #elif defined(_M_X64) || defined(__x86_64__) /* x86_64 (MSVC >=2005 or gcc) */
493
+ #define CURL_OS "x86_64-pc-win32"
494
+ #elif defined(_M_IA64) || defined(__ia64__) /* Itanium */
495
+ #define CURL_OS "ia64-pc-win32"
496
+ #elif defined(_M_ARM_NT) || defined(__arm__) /* ARMv7-Thumb2 (Windows RT) */
497
+ #define CURL_OS "thumbv7a-pc-win32"
498
+ #elif defined(_M_ARM64) || defined(__aarch64__) /* ARM64 (Windows 10) */
499
+ #define CURL_OS "aarch64-pc-win32"
500
+ #else
501
+ #define CURL_OS "unknown-pc-win32"
502
+ #endif
503
+ #endif
504
+
505
+ /* Name of package */
506
+ #define PACKAGE "curl"
507
+
508
+ /* If you want to build curl with the built-in manual */
509
+ #define USE_MANUAL 1
510
+
511
+ #endif /* HEADER_CURL_CONFIG_WIN32_H */
local-test-curl-full-01/afc-curl/lib/content_encoding.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CONTENT_ENCODING_H
2
+ #define HEADER_CURL_CONTENT_ENCODING_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #include "curl_setup.h"
27
+
28
+ struct Curl_cwriter;
29
+
30
+ void Curl_all_content_encodings(char *buf, size_t blen);
31
+
32
+ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
33
+ const char *enclist, int is_transfer);
34
+ #endif /* HEADER_CURL_CONTENT_ENCODING_H */
local-test-curl-full-01/afc-curl/lib/curl_addrinfo.c ADDED
@@ -0,0 +1,586 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include <curl/curl.h>
28
+
29
+ #ifdef HAVE_NETINET_IN_H
30
+ # include <netinet/in.h>
31
+ #endif
32
+ #ifdef HAVE_NETINET_IN6_H
33
+ # include <netinet/in6.h>
34
+ #endif
35
+ #ifdef HAVE_NETDB_H
36
+ # include <netdb.h>
37
+ #endif
38
+ #ifdef HAVE_ARPA_INET_H
39
+ # include <arpa/inet.h>
40
+ #endif
41
+ #ifdef HAVE_SYS_UN_H
42
+ # include <sys/un.h>
43
+ #endif
44
+
45
+ #ifdef __VMS
46
+ # include <in.h>
47
+ # include <inet.h>
48
+ #endif
49
+
50
+ #include <stddef.h>
51
+
52
+ #include "curl_addrinfo.h"
53
+ #include "inet_pton.h"
54
+ #include "warnless.h"
55
+ /* The last 3 #include files should be in this order */
56
+ #include "curl_printf.h"
57
+ #include "curl_memory.h"
58
+ #include "memdebug.h"
59
+
60
+ /*
61
+ * Curl_freeaddrinfo()
62
+ *
63
+ * This is used to free a linked list of Curl_addrinfo structs along
64
+ * with all its associated allocated storage. This function should be
65
+ * called once for each successful call to Curl_getaddrinfo_ex() or to
66
+ * any function call which actually allocates a Curl_addrinfo struct.
67
+ */
68
+
69
+ #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 910) && \
70
+ defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__)
71
+ /* workaround icc 9.1 optimizer issue */
72
+ # define vqualifier volatile
73
+ #else
74
+ # define vqualifier
75
+ #endif
76
+
77
+ void
78
+ Curl_freeaddrinfo(struct Curl_addrinfo *cahead)
79
+ {
80
+ struct Curl_addrinfo *vqualifier canext;
81
+ struct Curl_addrinfo *ca;
82
+
83
+ for(ca = cahead; ca; ca = canext) {
84
+ canext = ca->ai_next;
85
+ free(ca);
86
+ }
87
+ }
88
+
89
+
90
+ #ifdef HAVE_GETADDRINFO
91
+ /*
92
+ * Curl_getaddrinfo_ex()
93
+ *
94
+ * This is a wrapper function around system's getaddrinfo(), with
95
+ * the only difference that instead of returning a linked list of
96
+ * addrinfo structs this one returns a linked list of Curl_addrinfo
97
+ * ones. The memory allocated by this function *MUST* be free'd with
98
+ * Curl_freeaddrinfo(). For each successful call to this function
99
+ * there must be an associated call later to Curl_freeaddrinfo().
100
+ *
101
+ * There should be no single call to system's getaddrinfo() in the
102
+ * whole library, any such call should be 'routed' through this one.
103
+ */
104
+
105
+ int
106
+ Curl_getaddrinfo_ex(const char *nodename,
107
+ const char *servname,
108
+ const struct addrinfo *hints,
109
+ struct Curl_addrinfo **result)
110
+ {
111
+ const struct addrinfo *ai;
112
+ struct addrinfo *aihead;
113
+ struct Curl_addrinfo *cafirst = NULL;
114
+ struct Curl_addrinfo *calast = NULL;
115
+ struct Curl_addrinfo *ca;
116
+ size_t ss_size;
117
+ int error;
118
+
119
+ *result = NULL; /* assume failure */
120
+
121
+ error = getaddrinfo(nodename, servname, hints, &aihead);
122
+ if(error)
123
+ return error;
124
+
125
+ /* traverse the addrinfo list */
126
+
127
+ for(ai = aihead; ai != NULL; ai = ai->ai_next) {
128
+ size_t namelen = ai->ai_canonname ? strlen(ai->ai_canonname) + 1 : 0;
129
+ /* ignore elements with unsupported address family, */
130
+ /* settle family-specific sockaddr structure size. */
131
+ if(ai->ai_family == AF_INET)
132
+ ss_size = sizeof(struct sockaddr_in);
133
+ #ifdef USE_IPV6
134
+ else if(ai->ai_family == AF_INET6)
135
+ ss_size = sizeof(struct sockaddr_in6);
136
+ #endif
137
+ else
138
+ continue;
139
+
140
+ /* ignore elements without required address info */
141
+ if(!ai->ai_addr || !(ai->ai_addrlen > 0))
142
+ continue;
143
+
144
+ /* ignore elements with bogus address size */
145
+ if((size_t)ai->ai_addrlen < ss_size)
146
+ continue;
147
+
148
+ ca = malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen);
149
+ if(!ca) {
150
+ error = EAI_MEMORY;
151
+ break;
152
+ }
153
+
154
+ /* copy each structure member individually, member ordering, */
155
+ /* size, or padding might be different for each platform. */
156
+
157
+ ca->ai_flags = ai->ai_flags;
158
+ ca->ai_family = ai->ai_family;
159
+ ca->ai_socktype = ai->ai_socktype;
160
+ ca->ai_protocol = ai->ai_protocol;
161
+ ca->ai_addrlen = (curl_socklen_t)ss_size;
162
+ ca->ai_addr = NULL;
163
+ ca->ai_canonname = NULL;
164
+ ca->ai_next = NULL;
165
+
166
+ ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo));
167
+ memcpy(ca->ai_addr, ai->ai_addr, ss_size);
168
+
169
+ if(namelen) {
170
+ ca->ai_canonname = (void *)((char *)ca->ai_addr + ss_size);
171
+ memcpy(ca->ai_canonname, ai->ai_canonname, namelen);
172
+ }
173
+
174
+ /* if the return list is empty, this becomes the first element */
175
+ if(!cafirst)
176
+ cafirst = ca;
177
+
178
+ /* add this element last in the return list */
179
+ if(calast)
180
+ calast->ai_next = ca;
181
+ calast = ca;
182
+
183
+ }
184
+
185
+ /* destroy the addrinfo list */
186
+ if(aihead)
187
+ freeaddrinfo(aihead);
188
+
189
+ /* if we failed, also destroy the Curl_addrinfo list */
190
+ if(error) {
191
+ Curl_freeaddrinfo(cafirst);
192
+ cafirst = NULL;
193
+ }
194
+ else if(!cafirst) {
195
+ #ifdef EAI_NONAME
196
+ /* rfc3493 conformant */
197
+ error = EAI_NONAME;
198
+ #else
199
+ /* rfc3493 obsoleted */
200
+ error = EAI_NODATA;
201
+ #endif
202
+ #ifdef USE_WINSOCK
203
+ SET_SOCKERRNO(error);
204
+ #endif
205
+ }
206
+
207
+ *result = cafirst;
208
+
209
+ /* This is not a CURLcode */
210
+ return error;
211
+ }
212
+ #endif /* HAVE_GETADDRINFO */
213
+
214
+
215
+ /*
216
+ * Curl_he2ai()
217
+ *
218
+ * This function returns a pointer to the first element of a newly allocated
219
+ * Curl_addrinfo struct linked list filled with the data of a given hostent.
220
+ * Curl_addrinfo is meant to work like the addrinfo struct does for a IPv6
221
+ * stack, but usable also for IPv4, all hosts and environments.
222
+ *
223
+ * The memory allocated by this function *MUST* be free'd later on calling
224
+ * Curl_freeaddrinfo(). For each successful call to this function there
225
+ * must be an associated call later to Curl_freeaddrinfo().
226
+ *
227
+ * Curl_addrinfo defined in "lib/curl_addrinfo.h"
228
+ *
229
+ * struct Curl_addrinfo {
230
+ * int ai_flags;
231
+ * int ai_family;
232
+ * int ai_socktype;
233
+ * int ai_protocol;
234
+ * curl_socklen_t ai_addrlen; * Follow rfc3493 struct addrinfo *
235
+ * char *ai_canonname;
236
+ * struct sockaddr *ai_addr;
237
+ * struct Curl_addrinfo *ai_next;
238
+ * };
239
+ *
240
+ * hostent defined in <netdb.h>
241
+ *
242
+ * struct hostent {
243
+ * char *h_name;
244
+ * char **h_aliases;
245
+ * int h_addrtype;
246
+ * int h_length;
247
+ * char **h_addr_list;
248
+ * };
249
+ *
250
+ * for backward compatibility:
251
+ *
252
+ * #define h_addr h_addr_list[0]
253
+ */
254
+
255
+ #if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE))
256
+ struct Curl_addrinfo *
257
+ Curl_he2ai(const struct hostent *he, int port)
258
+ {
259
+ struct Curl_addrinfo *ai;
260
+ struct Curl_addrinfo *prevai = NULL;
261
+ struct Curl_addrinfo *firstai = NULL;
262
+ struct sockaddr_in *addr;
263
+ #ifdef USE_IPV6
264
+ struct sockaddr_in6 *addr6;
265
+ #endif
266
+ CURLcode result = CURLE_OK;
267
+ int i;
268
+ char *curr;
269
+
270
+ if(!he)
271
+ /* no input == no output! */
272
+ return NULL;
273
+
274
+ DEBUGASSERT((he->h_name != NULL) && (he->h_addr_list != NULL));
275
+
276
+ for(i = 0; (curr = he->h_addr_list[i]) != NULL; i++) {
277
+ size_t ss_size;
278
+ size_t namelen = strlen(he->h_name) + 1; /* include null-terminator */
279
+ #ifdef USE_IPV6
280
+ if(he->h_addrtype == AF_INET6)
281
+ ss_size = sizeof(struct sockaddr_in6);
282
+ else
283
+ #endif
284
+ ss_size = sizeof(struct sockaddr_in);
285
+
286
+ /* allocate memory to hold the struct, the address and the name */
287
+ ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen);
288
+ if(!ai) {
289
+ result = CURLE_OUT_OF_MEMORY;
290
+ break;
291
+ }
292
+ /* put the address after the struct */
293
+ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
294
+ /* then put the name after the address */
295
+ ai->ai_canonname = (char *)ai->ai_addr + ss_size;
296
+ memcpy(ai->ai_canonname, he->h_name, namelen);
297
+
298
+ if(!firstai)
299
+ /* store the pointer we want to return from this function */
300
+ firstai = ai;
301
+
302
+ if(prevai)
303
+ /* make the previous entry point to this */
304
+ prevai->ai_next = ai;
305
+
306
+ ai->ai_family = he->h_addrtype;
307
+
308
+ /* we return all names as STREAM, so when using this address for TFTP
309
+ the type must be ignored and conn->socktype be used instead! */
310
+ ai->ai_socktype = SOCK_STREAM;
311
+
312
+ ai->ai_addrlen = (curl_socklen_t)ss_size;
313
+
314
+ /* leave the rest of the struct filled with zero */
315
+
316
+ switch(ai->ai_family) {
317
+ case AF_INET:
318
+ addr = (void *)ai->ai_addr; /* storage area for this info */
319
+
320
+ memcpy(&addr->sin_addr, curr, sizeof(struct in_addr));
321
+ #ifdef __MINGW32__
322
+ addr->sin_family = (short)(he->h_addrtype);
323
+ #else
324
+ addr->sin_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
325
+ #endif
326
+ addr->sin_port = htons((unsigned short)port);
327
+ break;
328
+
329
+ #ifdef USE_IPV6
330
+ case AF_INET6:
331
+ addr6 = (void *)ai->ai_addr; /* storage area for this info */
332
+
333
+ memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr));
334
+ #ifdef __MINGW32__
335
+ addr6->sin6_family = (short)(he->h_addrtype);
336
+ #else
337
+ addr6->sin6_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
338
+ #endif
339
+ addr6->sin6_port = htons((unsigned short)port);
340
+ break;
341
+ #endif
342
+ }
343
+
344
+ prevai = ai;
345
+ }
346
+
347
+ if(result) {
348
+ Curl_freeaddrinfo(firstai);
349
+ firstai = NULL;
350
+ }
351
+
352
+ return firstai;
353
+ }
354
+ #endif
355
+
356
+ /*
357
+ * Curl_ip2addr()
358
+ *
359
+ * This function takes an Internet address, in binary form, as input parameter
360
+ * along with its address family and the string version of the address, and it
361
+ * returns a Curl_addrinfo chain filled in correctly with information for the
362
+ * given address/host
363
+ */
364
+
365
+ struct Curl_addrinfo *
366
+ Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port)
367
+ {
368
+ struct Curl_addrinfo *ai;
369
+ size_t addrsize;
370
+ size_t namelen;
371
+ struct sockaddr_in *addr;
372
+ #ifdef USE_IPV6
373
+ struct sockaddr_in6 *addr6;
374
+ #endif
375
+
376
+ DEBUGASSERT(inaddr && hostname);
377
+
378
+ namelen = strlen(hostname) + 1;
379
+
380
+ if(af == AF_INET)
381
+ addrsize = sizeof(struct sockaddr_in);
382
+ #ifdef USE_IPV6
383
+ else if(af == AF_INET6)
384
+ addrsize = sizeof(struct sockaddr_in6);
385
+ #endif
386
+ else
387
+ return NULL;
388
+
389
+ /* allocate memory to hold the struct, the address and the name */
390
+ ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen);
391
+ if(!ai)
392
+ return NULL;
393
+ /* put the address after the struct */
394
+ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
395
+ /* then put the name after the address */
396
+ ai->ai_canonname = (char *)ai->ai_addr + addrsize;
397
+ memcpy(ai->ai_canonname, hostname, namelen);
398
+ ai->ai_family = af;
399
+ ai->ai_socktype = SOCK_STREAM;
400
+ ai->ai_addrlen = (curl_socklen_t)addrsize;
401
+ /* leave the rest of the struct filled with zero */
402
+
403
+ switch(af) {
404
+ case AF_INET:
405
+ addr = (void *)ai->ai_addr; /* storage area for this info */
406
+
407
+ memcpy(&addr->sin_addr, inaddr, sizeof(struct in_addr));
408
+ #ifdef __MINGW32__
409
+ addr->sin_family = (short)af;
410
+ #else
411
+ addr->sin_family = (CURL_SA_FAMILY_T)af;
412
+ #endif
413
+ addr->sin_port = htons((unsigned short)port);
414
+ break;
415
+
416
+ #ifdef USE_IPV6
417
+ case AF_INET6:
418
+ addr6 = (void *)ai->ai_addr; /* storage area for this info */
419
+
420
+ memcpy(&addr6->sin6_addr, inaddr, sizeof(struct in6_addr));
421
+ #ifdef __MINGW32__
422
+ addr6->sin6_family = (short)af;
423
+ #else
424
+ addr6->sin6_family = (CURL_SA_FAMILY_T)af;
425
+ #endif
426
+ addr6->sin6_port = htons((unsigned short)port);
427
+ break;
428
+ #endif
429
+ }
430
+
431
+ return ai;
432
+ }
433
+
434
+ /*
435
+ * Given an IPv4 or IPv6 dotted string address, this converts it to a proper
436
+ * allocated Curl_addrinfo struct and returns it.
437
+ */
438
+ struct Curl_addrinfo *Curl_str2addr(char *address, int port)
439
+ {
440
+ struct in_addr in;
441
+ if(Curl_inet_pton(AF_INET, address, &in) > 0)
442
+ /* This is a dotted IP address 123.123.123.123-style */
443
+ return Curl_ip2addr(AF_INET, &in, address, port);
444
+ #ifdef USE_IPV6
445
+ {
446
+ struct in6_addr in6;
447
+ if(Curl_inet_pton(AF_INET6, address, &in6) > 0)
448
+ /* This is a dotted IPv6 address ::1-style */
449
+ return Curl_ip2addr(AF_INET6, &in6, address, port);
450
+ }
451
+ #endif
452
+ return NULL; /* bad input format */
453
+ }
454
+
455
+ #ifdef USE_UNIX_SOCKETS
456
+ /**
457
+ * Given a path to a Unix domain socket, return a newly allocated Curl_addrinfo
458
+ * struct initialized with this path.
459
+ * Set '*longpath' to TRUE if the error is a too long path.
460
+ */
461
+ struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath,
462
+ bool abstract)
463
+ {
464
+ struct Curl_addrinfo *ai;
465
+ struct sockaddr_un *sa_un;
466
+ size_t path_len;
467
+
468
+ *longpath = FALSE;
469
+
470
+ ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un));
471
+ if(!ai)
472
+ return NULL;
473
+ ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
474
+
475
+ sa_un = (void *) ai->ai_addr;
476
+ sa_un->sun_family = AF_UNIX;
477
+
478
+ /* sun_path must be able to store the NUL-terminated path */
479
+ path_len = strlen(path) + 1;
480
+ if(path_len > sizeof(sa_un->sun_path)) {
481
+ free(ai);
482
+ *longpath = TRUE;
483
+ return NULL;
484
+ }
485
+
486
+ ai->ai_family = AF_UNIX;
487
+ ai->ai_socktype = SOCK_STREAM; /* assume reliable transport for HTTP */
488
+ ai->ai_addrlen = (curl_socklen_t)
489
+ ((offsetof(struct sockaddr_un, sun_path) + path_len) & 0x7FFFFFFF);
490
+
491
+ /* Abstract Unix domain socket have NULL prefix instead of suffix */
492
+ if(abstract)
493
+ memcpy(sa_un->sun_path + 1, path, path_len - 1);
494
+ else
495
+ memcpy(sa_un->sun_path, path, path_len); /* copy NUL byte */
496
+
497
+ return ai;
498
+ }
499
+ #endif
500
+
501
+ #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \
502
+ defined(HAVE_FREEADDRINFO)
503
+ /*
504
+ * curl_dbg_freeaddrinfo()
505
+ *
506
+ * This is strictly for memory tracing and are using the same style as the
507
+ * family otherwise present in memdebug.c. I put these ones here since they
508
+ * require a bunch of structs I did not want to include in memdebug.c
509
+ */
510
+
511
+ void
512
+ curl_dbg_freeaddrinfo(struct addrinfo *freethis,
513
+ int line, const char *source)
514
+ {
515
+ curl_dbg_log("ADDR %s:%d freeaddrinfo(%p)\n",
516
+ source, line, (void *)freethis);
517
+ #ifdef USE_LWIPSOCK
518
+ lwip_freeaddrinfo(freethis);
519
+ #else
520
+ (freeaddrinfo)(freethis);
521
+ #endif
522
+ }
523
+ #endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
524
+
525
+
526
+ #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
527
+ /*
528
+ * curl_dbg_getaddrinfo()
529
+ *
530
+ * This is strictly for memory tracing and are using the same style as the
531
+ * family otherwise present in memdebug.c. I put these ones here since they
532
+ * require a bunch of structs I did not want to include in memdebug.c
533
+ */
534
+
535
+ int
536
+ curl_dbg_getaddrinfo(const char *hostname,
537
+ const char *service,
538
+ const struct addrinfo *hints,
539
+ struct addrinfo **result,
540
+ int line, const char *source)
541
+ {
542
+ #ifdef USE_LWIPSOCK
543
+ int res = lwip_getaddrinfo(hostname, service, hints, result);
544
+ #else
545
+ int res = (getaddrinfo)(hostname, service, hints, result);
546
+ #endif
547
+ if(0 == res)
548
+ /* success */
549
+ curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n",
550
+ source, line, (void *)*result);
551
+ else
552
+ curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n",
553
+ source, line);
554
+ return res;
555
+ }
556
+ #endif /* defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) */
557
+
558
+ #if defined(HAVE_GETADDRINFO) && defined(USE_RESOLVE_ON_IPS)
559
+ /*
560
+ * Work-arounds the sin6_port is always zero bug on iOS 9.3.2 and macOS
561
+ * 10.11.5.
562
+ */
563
+ void Curl_addrinfo_set_port(struct Curl_addrinfo *addrinfo, int port)
564
+ {
565
+ struct Curl_addrinfo *ca;
566
+ struct sockaddr_in *addr;
567
+ #ifdef USE_IPV6
568
+ struct sockaddr_in6 *addr6;
569
+ #endif
570
+ for(ca = addrinfo; ca != NULL; ca = ca->ai_next) {
571
+ switch(ca->ai_family) {
572
+ case AF_INET:
573
+ addr = (void *)ca->ai_addr; /* storage area for this info */
574
+ addr->sin_port = htons((unsigned short)port);
575
+ break;
576
+
577
+ #ifdef USE_IPV6
578
+ case AF_INET6:
579
+ addr6 = (void *)ca->ai_addr; /* storage area for this info */
580
+ addr6->sin6_port = htons((unsigned short)port);
581
+ break;
582
+ #endif
583
+ }
584
+ }
585
+ }
586
+ #endif
local-test-curl-full-01/afc-curl/lib/curl_base64.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_BASE64_H
2
+ #define HEADER_CURL_BASE64_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #ifndef BUILDING_LIBCURL
28
+ /* this renames functions so that the tool code can use the same code
29
+ without getting symbol collisions */
30
+ #define Curl_base64_encode(a,b,c,d) curlx_base64_encode(a,b,c,d)
31
+ #define Curl_base64url_encode(a,b,c,d) curlx_base64url_encode(a,b,c,d)
32
+ #define Curl_base64_decode(a,b,c) curlx_base64_decode(a,b,c)
33
+ #endif
34
+
35
+ CURLcode Curl_base64_encode(const char *inputbuff, size_t insize,
36
+ char **outptr, size_t *outlen);
37
+ CURLcode Curl_base64url_encode(const char *inputbuff, size_t insize,
38
+ char **outptr, size_t *outlen);
39
+ CURLcode Curl_base64_decode(const char *src,
40
+ unsigned char **outptr, size_t *outlen);
41
+ #endif /* HEADER_CURL_BASE64_H */
local-test-curl-full-01/afc-curl/lib/curl_ctype.h ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CTYPE_H
2
+ #define HEADER_CURL_CTYPE_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #define ISLOWHEXALHA(x) (((x) >= 'a') && ((x) <= 'f'))
28
+ #define ISUPHEXALHA(x) (((x) >= 'A') && ((x) <= 'F'))
29
+
30
+ #define ISLOWCNTRL(x) ((unsigned char)(x) <= 0x1f)
31
+ #define IS7F(x) ((x) == 0x7f)
32
+
33
+ #define ISLOWPRINT(x) (((x) >= 9) && ((x) <= 0x0d))
34
+
35
+ #define ISPRINT(x) (ISLOWPRINT(x) || (((x) >= ' ') && ((x) <= 0x7e)))
36
+ #define ISGRAPH(x) (ISLOWPRINT(x) || (((x) > ' ') && ((x) <= 0x7e)))
37
+ #define ISCNTRL(x) (ISLOWCNTRL(x) || IS7F(x))
38
+ #define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
39
+ #define ISXDIGIT(x) (ISDIGIT(x) || ISLOWHEXALHA(x) || ISUPHEXALHA(x))
40
+ #define ISALNUM(x) (ISDIGIT(x) || ISLOWER(x) || ISUPPER(x))
41
+ #define ISUPPER(x) (((x) >= 'A') && ((x) <= 'Z'))
42
+ #define ISLOWER(x) (((x) >= 'a') && ((x) <= 'z'))
43
+ #define ISDIGIT(x) (((x) >= '0') && ((x) <= '9'))
44
+ #define ISBLANK(x) (((x) == ' ') || ((x) == '\t'))
45
+ #define ISSPACE(x) (ISBLANK(x) || (((x) >= 0xa) && ((x) <= 0x0d)))
46
+ #define ISURLPUNTCS(x) (((x) == '-') || ((x) == '.') || ((x) == '_') || \
47
+ ((x) == '~'))
48
+ #define ISUNRESERVED(x) (ISALNUM(x) || ISURLPUNTCS(x))
49
+
50
+
51
+ #endif /* HEADER_CURL_CTYPE_H */
local-test-curl-full-01/afc-curl/lib/curl_des.c ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Steve Holme, <[email protected]>.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #if defined(USE_CURL_NTLM_CORE) && \
28
+ (defined(USE_GNUTLS) || \
29
+ defined(USE_SECTRANSP) || \
30
+ defined(USE_OS400CRYPTO) || \
31
+ defined(USE_WIN32_CRYPTO))
32
+
33
+ #include "curl_des.h"
34
+
35
+ /*
36
+ * Curl_des_set_odd_parity()
37
+ *
38
+ * This is used to apply odd parity to the given byte array. It is typically
39
+ * used by when a cryptography engine does not have its own version.
40
+ *
41
+ * The function is a port of the Java based oddParity() function over at:
42
+ *
43
+ * https://davenport.sourceforge.net/ntlm.html
44
+ *
45
+ * Parameters:
46
+ *
47
+ * bytes [in/out] - The data whose parity bits are to be adjusted for
48
+ * odd parity.
49
+ * len [out] - The length of the data.
50
+ */
51
+ void Curl_des_set_odd_parity(unsigned char *bytes, size_t len)
52
+ {
53
+ size_t i;
54
+
55
+ for(i = 0; i < len; i++) {
56
+ unsigned char b = bytes[i];
57
+
58
+ bool needs_parity = (((b >> 7) ^ (b >> 6) ^ (b >> 5) ^
59
+ (b >> 4) ^ (b >> 3) ^ (b >> 2) ^
60
+ (b >> 1)) & 0x01) == 0;
61
+
62
+ if(needs_parity)
63
+ bytes[i] |= 0x01;
64
+ else
65
+ bytes[i] &= 0xfe;
66
+ }
67
+ }
68
+
69
+ #endif
local-test-curl-full-01/afc-curl/lib/curl_fnmatch.h ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_FNMATCH_H
2
+ #define HEADER_CURL_FNMATCH_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #define CURL_FNMATCH_MATCH 0
28
+ #define CURL_FNMATCH_NOMATCH 1
29
+ #define CURL_FNMATCH_FAIL 2
30
+
31
+ /* default pattern matching function
32
+ * =================================
33
+ * Implemented with recursive backtracking, if you want to use Curl_fnmatch,
34
+ * please note that there is not implemented UTF/Unicode support.
35
+ *
36
+ * Implemented features:
37
+ * '?' notation, does not match UTF characters
38
+ * '*' can also work with UTF string
39
+ * [a-zA-Z0-9] enumeration support
40
+ *
41
+ * keywords: alnum, digit, xdigit, alpha, print, blank, lower, graph, space
42
+ * and upper (use as "[[:alnum:]]")
43
+ */
44
+ int Curl_fnmatch(void *ptr, const char *pattern, const char *string);
45
+
46
+ #endif /* HEADER_CURL_FNMATCH_H */
local-test-curl-full-01/afc-curl/lib/curl_get_line.c ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \
28
+ !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)
29
+
30
+ #include "curl_get_line.h"
31
+ #include "curl_memory.h"
32
+ /* The last #include file should be: */
33
+ #include "memdebug.h"
34
+
35
+ /*
36
+ * Curl_get_line() makes sure to only return complete whole lines that end
37
+ * newlines.
38
+ */
39
+ int Curl_get_line(struct dynbuf *buf, FILE *input)
40
+ {
41
+ CURLcode result;
42
+ char buffer[128];
43
+ Curl_dyn_reset(buf);
44
+ while(1) {
45
+ char *b = fgets(buffer, sizeof(buffer), input);
46
+
47
+ if(b) {
48
+ size_t rlen = strlen(b);
49
+
50
+ if(!rlen)
51
+ break;
52
+
53
+ result = Curl_dyn_addn(buf, b, rlen);
54
+ if(result)
55
+ /* too long line or out of memory */
56
+ return 0; /* error */
57
+
58
+ else if(b[rlen-1] == '\n')
59
+ /* end of the line */
60
+ return 1; /* all good */
61
+
62
+ else if(feof(input)) {
63
+ /* append a newline */
64
+ result = Curl_dyn_addn(buf, "\n", 1);
65
+ if(result)
66
+ /* too long line or out of memory */
67
+ return 0; /* error */
68
+ return 1; /* all good */
69
+ }
70
+ }
71
+ else
72
+ break;
73
+ }
74
+ return 0;
75
+ }
76
+
77
+ #endif /* if not disabled */
local-test-curl-full-01/afc-curl/lib/curl_gethostname.c ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include "curl_gethostname.h"
28
+
29
+ /*
30
+ * Curl_gethostname() is a wrapper around gethostname() which allows
31
+ * overriding the hostname that the function would normally return.
32
+ * This capability is used by the test suite to verify exact matching
33
+ * of NTLM authentication, which exercises libcurl's MD4 and DES code
34
+ * as well as by the SMTP module when a hostname is not provided.
35
+ *
36
+ * For libcurl debug enabled builds hostname overriding takes place
37
+ * when environment variable CURL_GETHOSTNAME is set, using the value
38
+ * held by the variable to override returned hostname.
39
+ *
40
+ * Note: The function always returns the un-qualified hostname rather
41
+ * than being provider dependent.
42
+ */
43
+
44
+ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
45
+ {
46
+ #ifndef HAVE_GETHOSTNAME
47
+
48
+ /* Allow compilation and return failure when unavailable */
49
+ (void) name;
50
+ (void) namelen;
51
+ return -1;
52
+
53
+ #else
54
+ int err;
55
+ char *dot;
56
+
57
+ #ifdef DEBUGBUILD
58
+
59
+ /* Override hostname when environment variable CURL_GETHOSTNAME is set */
60
+ const char *force_hostname = getenv("CURL_GETHOSTNAME");
61
+ if(force_hostname) {
62
+ if(strlen(force_hostname) < (size_t)namelen)
63
+ strcpy(name, force_hostname);
64
+ else
65
+ return 1; /* can't do it */
66
+ err = 0;
67
+ }
68
+ else {
69
+ name[0] = '\0';
70
+ err = gethostname(name, namelen);
71
+ }
72
+
73
+ #else /* DEBUGBUILD */
74
+
75
+ name[0] = '\0';
76
+ err = gethostname(name, namelen);
77
+
78
+ #endif
79
+
80
+ name[namelen - 1] = '\0';
81
+
82
+ if(err)
83
+ return err;
84
+
85
+ /* Truncate domain, leave only machine name */
86
+ dot = strchr(name, '.');
87
+ if(dot)
88
+ *dot = '\0';
89
+
90
+ return 0;
91
+ #endif
92
+
93
+ }
local-test-curl-full-01/afc-curl/lib/curl_gssapi.c ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #ifdef HAVE_GSSAPI
28
+
29
+ #include "curl_gssapi.h"
30
+ #include "sendf.h"
31
+
32
+ /* The last 3 #include files should be in this order */
33
+ #include "curl_printf.h"
34
+ #include "curl_memory.h"
35
+ #include "memdebug.h"
36
+
37
+ #if defined(__GNUC__)
38
+ #define CURL_ALIGN8 __attribute__((aligned(8)))
39
+ #else
40
+ #define CURL_ALIGN8
41
+ #endif
42
+
43
+ gss_OID_desc Curl_spnego_mech_oid CURL_ALIGN8 = {
44
+ 6, (char *)"\x2b\x06\x01\x05\x05\x02"
45
+ };
46
+ gss_OID_desc Curl_krb5_mech_oid CURL_ALIGN8 = {
47
+ 9, (char *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"
48
+ };
49
+
50
+ OM_uint32 Curl_gss_init_sec_context(
51
+ struct Curl_easy *data,
52
+ OM_uint32 *minor_status,
53
+ gss_ctx_id_t *context,
54
+ gss_name_t target_name,
55
+ gss_OID mech_type,
56
+ gss_channel_bindings_t input_chan_bindings,
57
+ gss_buffer_t input_token,
58
+ gss_buffer_t output_token,
59
+ const bool mutual_auth,
60
+ OM_uint32 *ret_flags)
61
+ {
62
+ OM_uint32 req_flags = GSS_C_REPLAY_FLAG;
63
+
64
+ if(mutual_auth)
65
+ req_flags |= GSS_C_MUTUAL_FLAG;
66
+
67
+ if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_POLICY_FLAG) {
68
+ #ifdef GSS_C_DELEG_POLICY_FLAG
69
+ req_flags |= GSS_C_DELEG_POLICY_FLAG;
70
+ #else
71
+ infof(data, "WARNING: support for CURLGSSAPI_DELEGATION_POLICY_FLAG not "
72
+ "compiled in");
73
+ #endif
74
+ }
75
+
76
+ if(data->set.gssapi_delegation & CURLGSSAPI_DELEGATION_FLAG)
77
+ req_flags |= GSS_C_DELEG_FLAG;
78
+
79
+ return gss_init_sec_context(minor_status,
80
+ GSS_C_NO_CREDENTIAL, /* cred_handle */
81
+ context,
82
+ target_name,
83
+ mech_type,
84
+ req_flags,
85
+ 0, /* time_req */
86
+ input_chan_bindings,
87
+ input_token,
88
+ NULL, /* actual_mech_type */
89
+ output_token,
90
+ ret_flags,
91
+ NULL /* time_rec */);
92
+ }
93
+
94
+ #define GSS_LOG_BUFFER_LEN 1024
95
+ static size_t display_gss_error(OM_uint32 status, int type,
96
+ char *buf, size_t len) {
97
+ OM_uint32 maj_stat;
98
+ OM_uint32 min_stat;
99
+ OM_uint32 msg_ctx = 0;
100
+ gss_buffer_desc status_string = GSS_C_EMPTY_BUFFER;
101
+
102
+ do {
103
+ maj_stat = gss_display_status(&min_stat,
104
+ status,
105
+ type,
106
+ GSS_C_NO_OID,
107
+ &msg_ctx,
108
+ &status_string);
109
+ if(maj_stat == GSS_S_COMPLETE && status_string.length > 0) {
110
+ if(GSS_LOG_BUFFER_LEN > len + status_string.length + 3) {
111
+ len += msnprintf(buf + len, GSS_LOG_BUFFER_LEN - len,
112
+ "%.*s. ", (int)status_string.length,
113
+ (char *)status_string.value);
114
+ }
115
+ }
116
+ gss_release_buffer(&min_stat, &status_string);
117
+ } while(!GSS_ERROR(maj_stat) && msg_ctx);
118
+
119
+ return len;
120
+ }
121
+
122
+ /*
123
+ * Curl_gss_log_error()
124
+ *
125
+ * This is used to log a GSS-API error status.
126
+ *
127
+ * Parameters:
128
+ *
129
+ * data [in] - The session handle.
130
+ * prefix [in] - The prefix of the log message.
131
+ * major [in] - The major status code.
132
+ * minor [in] - The minor status code.
133
+ */
134
+ void Curl_gss_log_error(struct Curl_easy *data, const char *prefix,
135
+ OM_uint32 major, OM_uint32 minor)
136
+ {
137
+ char buf[GSS_LOG_BUFFER_LEN];
138
+ size_t len = 0;
139
+
140
+ if(major != GSS_S_FAILURE)
141
+ len = display_gss_error(major, GSS_C_GSS_CODE, buf, len);
142
+
143
+ display_gss_error(minor, GSS_C_MECH_CODE, buf, len);
144
+
145
+ infof(data, "%s%s", prefix, buf);
146
+ #ifdef CURL_DISABLE_VERBOSE_STRINGS
147
+ (void)data;
148
+ (void)prefix;
149
+ #endif
150
+ }
151
+
152
+ #endif /* HAVE_GSSAPI */
local-test-curl-full-01/afc-curl/lib/curl_krb5.h ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_KRB5_H
2
+ #define HEADER_CURL_KRB5_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ struct Curl_sec_client_mech {
28
+ const char *name;
29
+ size_t size;
30
+ int (*init)(void *);
31
+ int (*auth)(void *, struct Curl_easy *data, struct connectdata *);
32
+ void (*end)(void *);
33
+ int (*check_prot)(void *, int);
34
+ int (*encode)(void *, const void *, int, int, void **);
35
+ int (*decode)(void *, void *, int, int, struct connectdata *);
36
+ };
37
+
38
+ #define AUTH_OK 0
39
+ #define AUTH_CONTINUE 1
40
+ #define AUTH_ERROR 2
41
+
42
+ #ifdef HAVE_GSSAPI
43
+ int Curl_sec_read_msg(struct Curl_easy *data, struct connectdata *conn, char *,
44
+ enum protection_level);
45
+ void Curl_sec_end(struct connectdata *);
46
+ CURLcode Curl_sec_login(struct Curl_easy *, struct connectdata *);
47
+ int Curl_sec_request_prot(struct connectdata *conn, const char *level);
48
+ #else
49
+ #define Curl_sec_end(x)
50
+ #endif
51
+
52
+ #endif /* HEADER_CURL_KRB5_H */
local-test-curl-full-01/afc-curl/lib/curl_ldap.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_LDAP_H
2
+ #define HEADER_CURL_LDAP_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #ifndef CURL_DISABLE_LDAP
27
+ extern const struct Curl_handler Curl_handler_ldap;
28
+
29
+ #if !defined(CURL_DISABLE_LDAPS) && \
30
+ ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
31
+ (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
32
+ extern const struct Curl_handler Curl_handler_ldaps;
33
+ #endif
34
+
35
+ #endif
36
+ #endif /* HEADER_CURL_LDAP_H */
local-test-curl-full-01/afc-curl/lib/curl_md5.h ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_MD5_H
2
+ #define HEADER_CURL_MD5_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
28
+ || !defined(CURL_DISABLE_DIGEST_AUTH)
29
+
30
+ #include "curl_hmac.h"
31
+
32
+ #define MD5_DIGEST_LEN 16
33
+
34
+ typedef CURLcode (*Curl_MD5_init_func)(void *context);
35
+ typedef void (*Curl_MD5_update_func)(void *context,
36
+ const unsigned char *data,
37
+ unsigned int len);
38
+ typedef void (*Curl_MD5_final_func)(unsigned char *result, void *context);
39
+
40
+ struct MD5_params {
41
+ Curl_MD5_init_func md5_init_func; /* Initialize context procedure */
42
+ Curl_MD5_update_func md5_update_func; /* Update context with data */
43
+ Curl_MD5_final_func md5_final_func; /* Get final result procedure */
44
+ unsigned int md5_ctxtsize; /* Context structure size */
45
+ unsigned int md5_resultlen; /* Result length (bytes) */
46
+ };
47
+
48
+ struct MD5_context {
49
+ const struct MD5_params *md5_hash; /* Hash function definition */
50
+ void *md5_hashctx; /* Hash function context */
51
+ };
52
+
53
+ extern const struct MD5_params Curl_DIGEST_MD5;
54
+ extern const struct HMAC_params Curl_HMAC_MD5;
55
+
56
+ CURLcode Curl_md5it(unsigned char *output, const unsigned char *input,
57
+ const size_t len);
58
+
59
+ struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params);
60
+ CURLcode Curl_MD5_update(struct MD5_context *context,
61
+ const unsigned char *data,
62
+ unsigned int len);
63
+ CURLcode Curl_MD5_final(struct MD5_context *context, unsigned char *result);
64
+
65
+ #endif
66
+
67
+ #endif /* HEADER_CURL_MD5_H */
local-test-curl-full-01/afc-curl/lib/curl_memrchr.c ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include <curl/curl.h>
28
+
29
+ #include "curl_memrchr.h"
30
+ #include "curl_memory.h"
31
+
32
+ /* The last #include file should be: */
33
+ #include "memdebug.h"
34
+
35
+ #ifndef HAVE_MEMRCHR
36
+ #if (!defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)) || \
37
+ defined(USE_OPENSSL) || \
38
+ defined(USE_SCHANNEL)
39
+
40
+ /*
41
+ * Curl_memrchr()
42
+ *
43
+ * Our memrchr() function clone for systems which lack this function. The
44
+ * memrchr() function is like the memchr() function, except that it searches
45
+ * backwards from the end of the n bytes pointed to by s instead of forward
46
+ * from the beginning.
47
+ */
48
+
49
+ void *
50
+ Curl_memrchr(const void *s, int c, size_t n)
51
+ {
52
+ if(n > 0) {
53
+ const unsigned char *p = s;
54
+ const unsigned char *q = s;
55
+
56
+ p += n - 1;
57
+
58
+ while(p >= q) {
59
+ if(*p == (unsigned char)c)
60
+ return (void *)p;
61
+ p--;
62
+ }
63
+ }
64
+ return NULL;
65
+ }
66
+
67
+ #endif
68
+ #endif /* HAVE_MEMRCHR */
local-test-curl-full-01/afc-curl/lib/curl_multibyte.c ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ /*
26
+ * This file is 'mem-include-scan' clean, which means memdebug.h and
27
+ * curl_memory.h are purposely not included in this file. See test 1132.
28
+ *
29
+ * The functions in this file are curlx functions which are not tracked by the
30
+ * curl memory tracker memdebug.
31
+ */
32
+
33
+ #include "curl_setup.h"
34
+
35
+ #if defined(_WIN32)
36
+
37
+ #include "curl_multibyte.h"
38
+
39
+ /*
40
+ * MultiByte conversions using Windows kernel32 library.
41
+ */
42
+
43
+ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8)
44
+ {
45
+ wchar_t *str_w = NULL;
46
+
47
+ if(str_utf8) {
48
+ int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
49
+ str_utf8, -1, NULL, 0);
50
+ if(str_w_len > 0) {
51
+ str_w = malloc(str_w_len * sizeof(wchar_t));
52
+ if(str_w) {
53
+ if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
54
+ str_w_len) == 0) {
55
+ free(str_w);
56
+ return NULL;
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ return str_w;
63
+ }
64
+
65
+ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
66
+ {
67
+ char *str_utf8 = NULL;
68
+
69
+ if(str_w) {
70
+ int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
71
+ NULL, 0, NULL, NULL);
72
+ if(bytes > 0) {
73
+ str_utf8 = malloc(bytes);
74
+ if(str_utf8) {
75
+ if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
76
+ NULL, NULL) == 0) {
77
+ free(str_utf8);
78
+ return NULL;
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ return str_utf8;
85
+ }
86
+
87
+ #endif /* _WIN32 */
88
+
89
+ #if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)
90
+
91
+ int curlx_win32_open(const char *filename, int oflag, ...)
92
+ {
93
+ int pmode = 0;
94
+
95
+ #ifdef _UNICODE
96
+ int result = -1;
97
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
98
+ #endif
99
+
100
+ va_list param;
101
+ va_start(param, oflag);
102
+ if(oflag & O_CREAT)
103
+ pmode = va_arg(param, int);
104
+ va_end(param);
105
+
106
+ #ifdef _UNICODE
107
+ if(filename_w) {
108
+ result = _wopen(filename_w, oflag, pmode);
109
+ curlx_unicodefree(filename_w);
110
+ }
111
+ else
112
+ errno = EINVAL;
113
+ return result;
114
+ #else
115
+ return (_open)(filename, oflag, pmode);
116
+ #endif
117
+ }
118
+
119
+ FILE *curlx_win32_fopen(const char *filename, const char *mode)
120
+ {
121
+ #ifdef _UNICODE
122
+ FILE *result = NULL;
123
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
124
+ wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
125
+ if(filename_w && mode_w)
126
+ result = _wfopen(filename_w, mode_w);
127
+ else
128
+ errno = EINVAL;
129
+ curlx_unicodefree(filename_w);
130
+ curlx_unicodefree(mode_w);
131
+ return result;
132
+ #else
133
+ return (fopen)(filename, mode);
134
+ #endif
135
+ }
136
+
137
+ int curlx_win32_stat(const char *path, struct_stat *buffer)
138
+ {
139
+ #ifdef _UNICODE
140
+ int result = -1;
141
+ wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
142
+ if(path_w) {
143
+ #if defined(USE_WIN32_SMALL_FILES)
144
+ result = _wstat(path_w, buffer);
145
+ #else
146
+ result = _wstati64(path_w, buffer);
147
+ #endif
148
+ curlx_unicodefree(path_w);
149
+ }
150
+ else
151
+ errno = EINVAL;
152
+ return result;
153
+ #else
154
+ #if defined(USE_WIN32_SMALL_FILES)
155
+ return _stat(path, buffer);
156
+ #else
157
+ return _stati64(path, buffer);
158
+ #endif
159
+ #endif
160
+ }
161
+
162
+ #endif /* USE_WIN32_LARGE_FILES || USE_WIN32_SMALL_FILES */
local-test-curl-full-01/afc-curl/lib/curl_multibyte.h ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_MULTIBYTE_H
2
+ #define HEADER_CURL_MULTIBYTE_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #include "curl_setup.h"
27
+
28
+ #if defined(_WIN32)
29
+
30
+ /*
31
+ * MultiByte conversions using Windows kernel32 library.
32
+ */
33
+
34
+ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8);
35
+ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w);
36
+ #endif /* _WIN32 */
37
+
38
+ /*
39
+ * Macros curlx_convert_UTF8_to_tchar(), curlx_convert_tchar_to_UTF8()
40
+ * and curlx_unicodefree() main purpose is to minimize the number of
41
+ * preprocessor conditional directives needed by code using these
42
+ * to differentiate Unicode from non-Unicode builds.
43
+ *
44
+ * In the case of a non-Unicode build the tchar strings are char strings that
45
+ * are duplicated via strdup and remain in whatever the passed in encoding is,
46
+ * which is assumed to be UTF-8 but may be other encoding. Therefore the
47
+ * significance of the conversion functions is primarily for Unicode builds.
48
+ *
49
+ * Allocated memory should be free'd with curlx_unicodefree().
50
+ *
51
+ * Note: Because these are curlx functions their memory usage is not tracked
52
+ * by the curl memory tracker memdebug. you will notice that curlx
53
+ * function-like macros call free and strdup in parentheses, eg (strdup)(ptr),
54
+ * and that is to ensure that the curl memdebug override macros do not replace
55
+ * them.
56
+ */
57
+
58
+ #if defined(UNICODE) && defined(_WIN32)
59
+
60
+ #define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr))
61
+ #define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr))
62
+
63
+ typedef union {
64
+ unsigned short *tchar_ptr;
65
+ const unsigned short *const_tchar_ptr;
66
+ unsigned short *tbyte_ptr;
67
+ const unsigned short *const_tbyte_ptr;
68
+ } xcharp_u;
69
+
70
+ #else
71
+
72
+ #define curlx_convert_UTF8_to_tchar(ptr) (strdup)(ptr)
73
+ #define curlx_convert_tchar_to_UTF8(ptr) (strdup)(ptr)
74
+
75
+ typedef union {
76
+ char *tchar_ptr;
77
+ const char *const_tchar_ptr;
78
+ unsigned char *tbyte_ptr;
79
+ const unsigned char *const_tbyte_ptr;
80
+ } xcharp_u;
81
+
82
+ #endif /* UNICODE && _WIN32 */
83
+
84
+ #define curlx_unicodefree(ptr) \
85
+ do { \
86
+ if(ptr) { \
87
+ (free)(ptr); \
88
+ (ptr) = NULL; \
89
+ } \
90
+ } while(0)
91
+
92
+ #endif /* HEADER_CURL_MULTIBYTE_H */
local-test-curl-full-01/afc-curl/lib/curl_rtmp.c ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ * Copyright (C) Howard Chu, <[email protected]>
10
+ *
11
+ * This software is licensed as described in the file COPYING, which
12
+ * you should have received as part of this distribution. The terms
13
+ * are also available at https://curl.se/docs/copyright.html.
14
+ *
15
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
+ * copies of the Software, and permit persons to whom the Software is
17
+ * furnished to do so, under the terms of the COPYING file.
18
+ *
19
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
+ * KIND, either express or implied.
21
+ *
22
+ * SPDX-License-Identifier: curl
23
+ *
24
+ ***************************************************************************/
25
+
26
+ #include "curl_setup.h"
27
+
28
+ #ifdef USE_LIBRTMP
29
+
30
+ #include "curl_rtmp.h"
31
+ #include "urldata.h"
32
+ #include "nonblock.h" /* for curlx_nonblock */
33
+ #include "progress.h" /* for Curl_pgrsSetUploadSize */
34
+ #include "transfer.h"
35
+ #include "warnless.h"
36
+ #include <curl/curl.h>
37
+ #include <librtmp/rtmp.h>
38
+
39
+ /* The last 3 #include files should be in this order */
40
+ #include "curl_printf.h"
41
+ #include "curl_memory.h"
42
+ #include "memdebug.h"
43
+
44
+ #if defined(_WIN32) && !defined(USE_LWIPSOCK)
45
+ #define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e)
46
+ #define SET_RCVTIMEO(tv,s) int tv = s*1000
47
+ #elif defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD)
48
+ #define SET_RCVTIMEO(tv,s) int tv = s*1000
49
+ #else
50
+ #define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0}
51
+ #endif
52
+
53
+ #define DEF_BUFTIME (2*60*60*1000) /* 2 hours */
54
+
55
+ static CURLcode rtmp_setup_connection(struct Curl_easy *data,
56
+ struct connectdata *conn);
57
+ static CURLcode rtmp_do(struct Curl_easy *data, bool *done);
58
+ static CURLcode rtmp_done(struct Curl_easy *data, CURLcode, bool premature);
59
+ static CURLcode rtmp_connect(struct Curl_easy *data, bool *done);
60
+ static CURLcode rtmp_disconnect(struct Curl_easy *data,
61
+ struct connectdata *conn, bool dead);
62
+
63
+ static Curl_recv rtmp_recv;
64
+ static Curl_send rtmp_send;
65
+
66
+ /*
67
+ * RTMP protocol handler.h, based on https://rtmpdump.mplayerhq.hu
68
+ */
69
+
70
+ const struct Curl_handler Curl_handler_rtmp = {
71
+ "rtmp", /* scheme */
72
+ rtmp_setup_connection, /* setup_connection */
73
+ rtmp_do, /* do_it */
74
+ rtmp_done, /* done */
75
+ ZERO_NULL, /* do_more */
76
+ rtmp_connect, /* connect_it */
77
+ ZERO_NULL, /* connecting */
78
+ ZERO_NULL, /* doing */
79
+ ZERO_NULL, /* proto_getsock */
80
+ ZERO_NULL, /* doing_getsock */
81
+ ZERO_NULL, /* domore_getsock */
82
+ ZERO_NULL, /* perform_getsock */
83
+ rtmp_disconnect, /* disconnect */
84
+ ZERO_NULL, /* write_resp */
85
+ ZERO_NULL, /* write_resp_hd */
86
+ ZERO_NULL, /* connection_check */
87
+ ZERO_NULL, /* attach connection */
88
+ PORT_RTMP, /* defport */
89
+ CURLPROTO_RTMP, /* protocol */
90
+ CURLPROTO_RTMP, /* family */
91
+ PROTOPT_NONE /* flags */
92
+ };
93
+
94
+ const struct Curl_handler Curl_handler_rtmpt = {
95
+ "rtmpt", /* scheme */
96
+ rtmp_setup_connection, /* setup_connection */
97
+ rtmp_do, /* do_it */
98
+ rtmp_done, /* done */
99
+ ZERO_NULL, /* do_more */
100
+ rtmp_connect, /* connect_it */
101
+ ZERO_NULL, /* connecting */
102
+ ZERO_NULL, /* doing */
103
+ ZERO_NULL, /* proto_getsock */
104
+ ZERO_NULL, /* doing_getsock */
105
+ ZERO_NULL, /* domore_getsock */
106
+ ZERO_NULL, /* perform_getsock */
107
+ rtmp_disconnect, /* disconnect */
108
+ ZERO_NULL, /* write_resp */
109
+ ZERO_NULL, /* write_resp_hd */
110
+ ZERO_NULL, /* connection_check */
111
+ ZERO_NULL, /* attach connection */
112
+ PORT_RTMPT, /* defport */
113
+ CURLPROTO_RTMPT, /* protocol */
114
+ CURLPROTO_RTMPT, /* family */
115
+ PROTOPT_NONE /* flags */
116
+ };
117
+
118
+ const struct Curl_handler Curl_handler_rtmpe = {
119
+ "rtmpe", /* scheme */
120
+ rtmp_setup_connection, /* setup_connection */
121
+ rtmp_do, /* do_it */
122
+ rtmp_done, /* done */
123
+ ZERO_NULL, /* do_more */
124
+ rtmp_connect, /* connect_it */
125
+ ZERO_NULL, /* connecting */
126
+ ZERO_NULL, /* doing */
127
+ ZERO_NULL, /* proto_getsock */
128
+ ZERO_NULL, /* doing_getsock */
129
+ ZERO_NULL, /* domore_getsock */
130
+ ZERO_NULL, /* perform_getsock */
131
+ rtmp_disconnect, /* disconnect */
132
+ ZERO_NULL, /* write_resp */
133
+ ZERO_NULL, /* write_resp_hd */
134
+ ZERO_NULL, /* connection_check */
135
+ ZERO_NULL, /* attach connection */
136
+ PORT_RTMP, /* defport */
137
+ CURLPROTO_RTMPE, /* protocol */
138
+ CURLPROTO_RTMPE, /* family */
139
+ PROTOPT_NONE /* flags */
140
+ };
141
+
142
+ const struct Curl_handler Curl_handler_rtmpte = {
143
+ "rtmpte", /* scheme */
144
+ rtmp_setup_connection, /* setup_connection */
145
+ rtmp_do, /* do_it */
146
+ rtmp_done, /* done */
147
+ ZERO_NULL, /* do_more */
148
+ rtmp_connect, /* connect_it */
149
+ ZERO_NULL, /* connecting */
150
+ ZERO_NULL, /* doing */
151
+ ZERO_NULL, /* proto_getsock */
152
+ ZERO_NULL, /* doing_getsock */
153
+ ZERO_NULL, /* domore_getsock */
154
+ ZERO_NULL, /* perform_getsock */
155
+ rtmp_disconnect, /* disconnect */
156
+ ZERO_NULL, /* write_resp */
157
+ ZERO_NULL, /* write_resp_hd */
158
+ ZERO_NULL, /* connection_check */
159
+ ZERO_NULL, /* attach connection */
160
+ PORT_RTMPT, /* defport */
161
+ CURLPROTO_RTMPTE, /* protocol */
162
+ CURLPROTO_RTMPTE, /* family */
163
+ PROTOPT_NONE /* flags */
164
+ };
165
+
166
+ const struct Curl_handler Curl_handler_rtmps = {
167
+ "rtmps", /* scheme */
168
+ rtmp_setup_connection, /* setup_connection */
169
+ rtmp_do, /* do_it */
170
+ rtmp_done, /* done */
171
+ ZERO_NULL, /* do_more */
172
+ rtmp_connect, /* connect_it */
173
+ ZERO_NULL, /* connecting */
174
+ ZERO_NULL, /* doing */
175
+ ZERO_NULL, /* proto_getsock */
176
+ ZERO_NULL, /* doing_getsock */
177
+ ZERO_NULL, /* domore_getsock */
178
+ ZERO_NULL, /* perform_getsock */
179
+ rtmp_disconnect, /* disconnect */
180
+ ZERO_NULL, /* write_resp */
181
+ ZERO_NULL, /* write_resp_hd */
182
+ ZERO_NULL, /* connection_check */
183
+ ZERO_NULL, /* attach connection */
184
+ PORT_RTMPS, /* defport */
185
+ CURLPROTO_RTMPS, /* protocol */
186
+ CURLPROTO_RTMP, /* family */
187
+ PROTOPT_NONE /* flags */
188
+ };
189
+
190
+ const struct Curl_handler Curl_handler_rtmpts = {
191
+ "rtmpts", /* scheme */
192
+ rtmp_setup_connection, /* setup_connection */
193
+ rtmp_do, /* do_it */
194
+ rtmp_done, /* done */
195
+ ZERO_NULL, /* do_more */
196
+ rtmp_connect, /* connect_it */
197
+ ZERO_NULL, /* connecting */
198
+ ZERO_NULL, /* doing */
199
+ ZERO_NULL, /* proto_getsock */
200
+ ZERO_NULL, /* doing_getsock */
201
+ ZERO_NULL, /* domore_getsock */
202
+ ZERO_NULL, /* perform_getsock */
203
+ rtmp_disconnect, /* disconnect */
204
+ ZERO_NULL, /* write_resp */
205
+ ZERO_NULL, /* write_resp_hd */
206
+ ZERO_NULL, /* connection_check */
207
+ ZERO_NULL, /* attach connection */
208
+ PORT_RTMPS, /* defport */
209
+ CURLPROTO_RTMPTS, /* protocol */
210
+ CURLPROTO_RTMPT, /* family */
211
+ PROTOPT_NONE /* flags */
212
+ };
213
+
214
+ static CURLcode rtmp_setup_connection(struct Curl_easy *data,
215
+ struct connectdata *conn)
216
+ {
217
+ RTMP *r = RTMP_Alloc();
218
+ if(!r)
219
+ return CURLE_OUT_OF_MEMORY;
220
+
221
+ RTMP_Init(r);
222
+ RTMP_SetBufferMS(r, DEF_BUFTIME);
223
+ if(!RTMP_SetupURL(r, data->state.url)) {
224
+ RTMP_Free(r);
225
+ return CURLE_URL_MALFORMAT;
226
+ }
227
+ conn->proto.rtmp = r;
228
+ return CURLE_OK;
229
+ }
230
+
231
+ static CURLcode rtmp_connect(struct Curl_easy *data, bool *done)
232
+ {
233
+ struct connectdata *conn = data->conn;
234
+ RTMP *r = conn->proto.rtmp;
235
+ SET_RCVTIMEO(tv, 10);
236
+
237
+ r->m_sb.sb_socket = (int)conn->sock[FIRSTSOCKET];
238
+
239
+ /* We have to know if it is a write before we send the
240
+ * connect request packet
241
+ */
242
+ if(data->state.upload)
243
+ r->Link.protocol |= RTMP_FEATURE_WRITE;
244
+
245
+ /* For plain streams, use the buffer toggle trick to keep data flowing */
246
+ if(!(r->Link.lFlags & RTMP_LF_LIVE) &&
247
+ !(r->Link.protocol & RTMP_FEATURE_HTTP))
248
+ r->Link.lFlags |= RTMP_LF_BUFX;
249
+
250
+ (void)curlx_nonblock(r->m_sb.sb_socket, FALSE);
251
+ setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO,
252
+ (char *)&tv, sizeof(tv));
253
+
254
+ if(!RTMP_Connect1(r, NULL))
255
+ return CURLE_FAILED_INIT;
256
+
257
+ /* Clients must send a periodic BytesReceived report to the server */
258
+ r->m_bSendCounter = TRUE;
259
+
260
+ *done = TRUE;
261
+ conn->recv[FIRSTSOCKET] = rtmp_recv;
262
+ conn->send[FIRSTSOCKET] = rtmp_send;
263
+ return CURLE_OK;
264
+ }
265
+
266
+ static CURLcode rtmp_do(struct Curl_easy *data, bool *done)
267
+ {
268
+ struct connectdata *conn = data->conn;
269
+ RTMP *r = conn->proto.rtmp;
270
+
271
+ if(!RTMP_ConnectStream(r, 0))
272
+ return CURLE_FAILED_INIT;
273
+
274
+ if(data->state.upload) {
275
+ Curl_pgrsSetUploadSize(data, data->state.infilesize);
276
+ Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE);
277
+ }
278
+ else
279
+ Curl_xfer_setup1(data, CURL_XFER_RECV, -1, FALSE);
280
+ *done = TRUE;
281
+ return CURLE_OK;
282
+ }
283
+
284
+ static CURLcode rtmp_done(struct Curl_easy *data, CURLcode status,
285
+ bool premature)
286
+ {
287
+ (void)data; /* unused */
288
+ (void)status; /* unused */
289
+ (void)premature; /* unused */
290
+
291
+ return CURLE_OK;
292
+ }
293
+
294
+ static CURLcode rtmp_disconnect(struct Curl_easy *data,
295
+ struct connectdata *conn,
296
+ bool dead_connection)
297
+ {
298
+ RTMP *r = conn->proto.rtmp;
299
+ (void)data;
300
+ (void)dead_connection;
301
+ if(r) {
302
+ conn->proto.rtmp = NULL;
303
+ RTMP_Close(r);
304
+ RTMP_Free(r);
305
+ }
306
+ return CURLE_OK;
307
+ }
308
+
309
+ static ssize_t rtmp_recv(struct Curl_easy *data, int sockindex, char *buf,
310
+ size_t len, CURLcode *err)
311
+ {
312
+ struct connectdata *conn = data->conn;
313
+ RTMP *r = conn->proto.rtmp;
314
+ ssize_t nread;
315
+
316
+ (void)sockindex; /* unused */
317
+
318
+ nread = RTMP_Read(r, buf, curlx_uztosi(len));
319
+ if(nread < 0) {
320
+ if(r->m_read.status == RTMP_READ_COMPLETE ||
321
+ r->m_read.status == RTMP_READ_EOF) {
322
+ data->req.size = data->req.bytecount;
323
+ nread = 0;
324
+ }
325
+ else
326
+ *err = CURLE_RECV_ERROR;
327
+ }
328
+ return nread;
329
+ }
330
+
331
+ static ssize_t rtmp_send(struct Curl_easy *data, int sockindex,
332
+ const void *buf, size_t len, bool eos, CURLcode *err)
333
+ {
334
+ struct connectdata *conn = data->conn;
335
+ RTMP *r = conn->proto.rtmp;
336
+ ssize_t num;
337
+
338
+ (void)sockindex; /* unused */
339
+ (void)eos; /* unused */
340
+
341
+ num = RTMP_Write(r, (char *)buf, curlx_uztosi(len));
342
+ if(num < 0)
343
+ *err = CURLE_SEND_ERROR;
344
+
345
+ return num;
346
+ }
347
+
348
+ void Curl_rtmp_version(char *version, size_t len)
349
+ {
350
+ char suff[2];
351
+ if(RTMP_LIB_VERSION & 0xff) {
352
+ suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
353
+ suff[1] = '\0';
354
+ }
355
+ else
356
+ suff[0] = '\0';
357
+
358
+ msnprintf(version, len, "librtmp/%d.%d%s",
359
+ RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
360
+ suff);
361
+ }
362
+
363
+ #endif /* USE_LIBRTMP */
local-test-curl-full-01/afc-curl/lib/curl_sasl.c ADDED
@@ -0,0 +1,760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ * RFC2195 CRAM-MD5 authentication
24
+ * RFC2617 Basic and Digest Access Authentication
25
+ * RFC2831 DIGEST-MD5 authentication
26
+ * RFC4422 Simple Authentication and Security Layer (SASL)
27
+ * RFC4616 PLAIN authentication
28
+ * RFC5802 SCRAM-SHA-1 authentication
29
+ * RFC7677 SCRAM-SHA-256 authentication
30
+ * RFC6749 OAuth 2.0 Authorization Framework
31
+ * RFC7628 A Set of SASL Mechanisms for OAuth
32
+ * Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
33
+ *
34
+ ***************************************************************************/
35
+
36
+ #include "curl_setup.h"
37
+
38
+ #if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
39
+ !defined(CURL_DISABLE_POP3) || \
40
+ (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP))
41
+
42
+ #include <curl/curl.h>
43
+ #include "urldata.h"
44
+
45
+ #include "curl_base64.h"
46
+ #include "curl_md5.h"
47
+ #include "vauth/vauth.h"
48
+ #include "cfilters.h"
49
+ #include "vtls/vtls.h"
50
+ #include "curl_hmac.h"
51
+ #include "curl_sasl.h"
52
+ #include "warnless.h"
53
+ #include "strtok.h"
54
+ #include "sendf.h"
55
+ /* The last 3 #include files should be in this order */
56
+ #include "curl_printf.h"
57
+ #include "curl_memory.h"
58
+ #include "memdebug.h"
59
+
60
+ /* Supported mechanisms */
61
+ static const struct {
62
+ const char *name; /* Name */
63
+ size_t len; /* Name length */
64
+ unsigned short bit; /* Flag bit */
65
+ } mechtable[] = {
66
+ { "LOGIN", 5, SASL_MECH_LOGIN },
67
+ { "PLAIN", 5, SASL_MECH_PLAIN },
68
+ { "CRAM-MD5", 8, SASL_MECH_CRAM_MD5 },
69
+ { "DIGEST-MD5", 10, SASL_MECH_DIGEST_MD5 },
70
+ { "GSSAPI", 6, SASL_MECH_GSSAPI },
71
+ { "EXTERNAL", 8, SASL_MECH_EXTERNAL },
72
+ { "NTLM", 4, SASL_MECH_NTLM },
73
+ { "XOAUTH2", 7, SASL_MECH_XOAUTH2 },
74
+ { "OAUTHBEARER", 11, SASL_MECH_OAUTHBEARER },
75
+ { "SCRAM-SHA-1", 11, SASL_MECH_SCRAM_SHA_1 },
76
+ { "SCRAM-SHA-256",13, SASL_MECH_SCRAM_SHA_256 },
77
+ { ZERO_NULL, 0, 0 }
78
+ };
79
+
80
+ /*
81
+ * Curl_sasl_cleanup()
82
+ *
83
+ * This is used to cleanup any libraries or curl modules used by the sasl
84
+ * functions.
85
+ *
86
+ * Parameters:
87
+ *
88
+ * conn [in] - The connection data.
89
+ * authused [in] - The authentication mechanism used.
90
+ */
91
+ void Curl_sasl_cleanup(struct connectdata *conn, unsigned short authused)
92
+ {
93
+ (void)conn;
94
+ (void)authused;
95
+
96
+ #if defined(USE_KERBEROS5)
97
+ /* Cleanup the gssapi structure */
98
+ if(authused == SASL_MECH_GSSAPI) {
99
+ Curl_auth_cleanup_gssapi(&conn->krb5);
100
+ }
101
+ #endif
102
+
103
+ #if defined(USE_GSASL)
104
+ /* Cleanup the GSASL structure */
105
+ if(authused & (SASL_MECH_SCRAM_SHA_1 | SASL_MECH_SCRAM_SHA_256)) {
106
+ Curl_auth_gsasl_cleanup(&conn->gsasl);
107
+ }
108
+ #endif
109
+
110
+ #if defined(USE_NTLM)
111
+ /* Cleanup the NTLM structure */
112
+ if(authused == SASL_MECH_NTLM) {
113
+ Curl_auth_cleanup_ntlm(&conn->ntlm);
114
+ }
115
+ #endif
116
+ }
117
+
118
+ /*
119
+ * Curl_sasl_decode_mech()
120
+ *
121
+ * Convert a SASL mechanism name into a token.
122
+ *
123
+ * Parameters:
124
+ *
125
+ * ptr [in] - The mechanism string.
126
+ * maxlen [in] - Maximum mechanism string length.
127
+ * len [out] - If not NULL, effective name length.
128
+ *
129
+ * Returns the SASL mechanism token or 0 if no match.
130
+ */
131
+ unsigned short Curl_sasl_decode_mech(const char *ptr, size_t maxlen,
132
+ size_t *len)
133
+ {
134
+ unsigned int i;
135
+ char c;
136
+
137
+ for(i = 0; mechtable[i].name; i++) {
138
+ if(maxlen >= mechtable[i].len &&
139
+ !memcmp(ptr, mechtable[i].name, mechtable[i].len)) {
140
+ if(len)
141
+ *len = mechtable[i].len;
142
+
143
+ if(maxlen == mechtable[i].len)
144
+ return mechtable[i].bit;
145
+
146
+ c = ptr[mechtable[i].len];
147
+ if(!ISUPPER(c) && !ISDIGIT(c) && c != '-' && c != '_')
148
+ return mechtable[i].bit;
149
+ }
150
+ }
151
+
152
+ return 0;
153
+ }
154
+
155
+ /*
156
+ * Curl_sasl_parse_url_auth_option()
157
+ *
158
+ * Parse the URL login options.
159
+ */
160
+ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
161
+ const char *value, size_t len)
162
+ {
163
+ CURLcode result = CURLE_OK;
164
+ size_t mechlen;
165
+
166
+ if(!len)
167
+ return CURLE_URL_MALFORMAT;
168
+
169
+ if(sasl->resetprefs) {
170
+ sasl->resetprefs = FALSE;
171
+ sasl->prefmech = SASL_AUTH_NONE;
172
+ }
173
+
174
+ if(!strncmp(value, "*", len))
175
+ sasl->prefmech = SASL_AUTH_DEFAULT;
176
+ else {
177
+ unsigned short mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
178
+ if(mechbit && mechlen == len)
179
+ sasl->prefmech |= mechbit;
180
+ else
181
+ result = CURLE_URL_MALFORMAT;
182
+ }
183
+
184
+ return result;
185
+ }
186
+
187
+ /*
188
+ * Curl_sasl_init()
189
+ *
190
+ * Initializes the SASL structure.
191
+ */
192
+ void Curl_sasl_init(struct SASL *sasl, struct Curl_easy *data,
193
+ const struct SASLproto *params)
194
+ {
195
+ unsigned long auth = data->set.httpauth;
196
+
197
+ sasl->params = params; /* Set protocol dependent parameters */
198
+ sasl->state = SASL_STOP; /* Not yet running */
199
+ sasl->curmech = NULL; /* No mechanism yet. */
200
+ sasl->authmechs = SASL_AUTH_NONE; /* No known authentication mechanism yet */
201
+ sasl->prefmech = params->defmechs; /* Default preferred mechanisms */
202
+ sasl->authused = SASL_AUTH_NONE; /* The authentication mechanism used */
203
+ sasl->resetprefs = TRUE; /* Reset prefmech upon AUTH parsing. */
204
+ sasl->mutual_auth = FALSE; /* No mutual authentication (GSSAPI only) */
205
+ sasl->force_ir = FALSE; /* Respect external option */
206
+
207
+ if(auth != CURLAUTH_BASIC) {
208
+ unsigned short mechs = SASL_AUTH_NONE;
209
+
210
+ /* If some usable http authentication options have been set, determine
211
+ new defaults from them. */
212
+ if(auth & CURLAUTH_BASIC)
213
+ mechs |= SASL_MECH_PLAIN | SASL_MECH_LOGIN;
214
+ if(auth & CURLAUTH_DIGEST)
215
+ mechs |= SASL_MECH_DIGEST_MD5;
216
+ if(auth & CURLAUTH_NTLM)
217
+ mechs |= SASL_MECH_NTLM;
218
+ if(auth & CURLAUTH_BEARER)
219
+ mechs |= SASL_MECH_OAUTHBEARER | SASL_MECH_XOAUTH2;
220
+ if(auth & CURLAUTH_GSSAPI)
221
+ mechs |= SASL_MECH_GSSAPI;
222
+
223
+ if(mechs != SASL_AUTH_NONE)
224
+ sasl->prefmech = mechs;
225
+ }
226
+ }
227
+
228
+ /*
229
+ * sasl_state()
230
+ *
231
+ * This is the ONLY way to change SASL state!
232
+ */
233
+ static void sasl_state(struct SASL *sasl, struct Curl_easy *data,
234
+ saslstate newstate)
235
+ {
236
+ #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
237
+ /* for debug purposes */
238
+ static const char * const names[]={
239
+ "STOP",
240
+ "PLAIN",
241
+ "LOGIN",
242
+ "LOGIN_PASSWD",
243
+ "EXTERNAL",
244
+ "CRAMMD5",
245
+ "DIGESTMD5",
246
+ "DIGESTMD5_RESP",
247
+ "NTLM",
248
+ "NTLM_TYPE2MSG",
249
+ "GSSAPI",
250
+ "GSSAPI_TOKEN",
251
+ "GSSAPI_NO_DATA",
252
+ "OAUTH2",
253
+ "OAUTH2_RESP",
254
+ "GSASL",
255
+ "CANCEL",
256
+ "FINAL",
257
+ /* LAST */
258
+ };
259
+
260
+ if(sasl->state != newstate)
261
+ infof(data, "SASL %p state change from %s to %s",
262
+ (void *)sasl, names[sasl->state], names[newstate]);
263
+ #else
264
+ (void) data;
265
+ #endif
266
+
267
+ sasl->state = newstate;
268
+ }
269
+
270
+ #if defined(USE_NTLM) || defined(USE_GSASL) || defined(USE_KERBEROS5) || \
271
+ !defined(CURL_DISABLE_DIGEST_AUTH)
272
+ /* Get the SASL server message and convert it to binary. */
273
+ static CURLcode get_server_message(struct SASL *sasl, struct Curl_easy *data,
274
+ struct bufref *out)
275
+ {
276
+ CURLcode result = CURLE_OK;
277
+
278
+ result = sasl->params->getmessage(data, out);
279
+ if(!result && (sasl->params->flags & SASL_FLAG_BASE64)) {
280
+ unsigned char *msg;
281
+ size_t msglen;
282
+ const char *serverdata = (const char *) Curl_bufref_ptr(out);
283
+
284
+ if(!*serverdata || *serverdata == '=')
285
+ Curl_bufref_set(out, NULL, 0, NULL);
286
+ else {
287
+ result = Curl_base64_decode(serverdata, &msg, &msglen);
288
+ if(!result)
289
+ Curl_bufref_set(out, msg, msglen, curl_free);
290
+ }
291
+ }
292
+ return result;
293
+ }
294
+ #endif
295
+
296
+ /* Encode the outgoing SASL message. */
297
+ static CURLcode build_message(struct SASL *sasl, struct bufref *msg)
298
+ {
299
+ CURLcode result = CURLE_OK;
300
+
301
+ if(sasl->params->flags & SASL_FLAG_BASE64) {
302
+ if(!Curl_bufref_ptr(msg)) /* Empty message. */
303
+ Curl_bufref_set(msg, "", 0, NULL);
304
+ else if(!Curl_bufref_len(msg)) /* Explicit empty response. */
305
+ Curl_bufref_set(msg, "=", 1, NULL);
306
+ else {
307
+ char *base64;
308
+ size_t base64len;
309
+
310
+ result = Curl_base64_encode((const char *) Curl_bufref_ptr(msg),
311
+ Curl_bufref_len(msg), &base64, &base64len);
312
+ if(!result)
313
+ Curl_bufref_set(msg, base64, base64len, curl_free);
314
+ }
315
+ }
316
+
317
+ return result;
318
+ }
319
+
320
+ /*
321
+ * Curl_sasl_can_authenticate()
322
+ *
323
+ * Check if we have enough auth data and capabilities to authenticate.
324
+ */
325
+ bool Curl_sasl_can_authenticate(struct SASL *sasl, struct Curl_easy *data)
326
+ {
327
+ /* Have credentials been provided? */
328
+ if(data->state.aptr.user)
329
+ return TRUE;
330
+
331
+ /* EXTERNAL can authenticate without a username and/or password */
332
+ if(sasl->authmechs & sasl->prefmech & SASL_MECH_EXTERNAL)
333
+ return TRUE;
334
+
335
+ return FALSE;
336
+ }
337
+
338
+ /*
339
+ * Curl_sasl_start()
340
+ *
341
+ * Calculate the required login details for SASL authentication.
342
+ */
343
+ CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
344
+ bool force_ir, saslprogress *progress)
345
+ {
346
+ CURLcode result = CURLE_OK;
347
+ struct connectdata *conn = data->conn;
348
+ unsigned short enabledmechs;
349
+ const char *mech = NULL;
350
+ struct bufref resp;
351
+ saslstate state1 = SASL_STOP;
352
+ saslstate state2 = SASL_FINAL;
353
+ const char *hostname, *disp_hostname;
354
+ int port;
355
+ #if defined(USE_KERBEROS5) || defined(USE_NTLM)
356
+ const char *service = data->set.str[STRING_SERVICE_NAME] ?
357
+ data->set.str[STRING_SERVICE_NAME] :
358
+ sasl->params->service;
359
+ #endif
360
+ const char *oauth_bearer = data->set.str[STRING_BEARER];
361
+ struct bufref nullmsg;
362
+
363
+ Curl_conn_get_host(data, FIRSTSOCKET, &hostname, &disp_hostname, &port);
364
+ Curl_bufref_init(&nullmsg);
365
+ Curl_bufref_init(&resp);
366
+ sasl->force_ir = force_ir; /* Latch for future use */
367
+ sasl->authused = 0; /* No mechanism used yet */
368
+ enabledmechs = sasl->authmechs & sasl->prefmech;
369
+ *progress = SASL_IDLE;
370
+
371
+ /* Calculate the supported authentication mechanism, by decreasing order of
372
+ security, as well as the initial response where appropriate */
373
+ if((enabledmechs & SASL_MECH_EXTERNAL) && !conn->passwd[0]) {
374
+ mech = SASL_MECH_STRING_EXTERNAL;
375
+ state1 = SASL_EXTERNAL;
376
+ sasl->authused = SASL_MECH_EXTERNAL;
377
+
378
+ if(force_ir || data->set.sasl_ir)
379
+ Curl_auth_create_external_message(conn->user, &resp);
380
+ }
381
+ else if(data->state.aptr.user) {
382
+ #if defined(USE_KERBEROS5)
383
+ if((enabledmechs & SASL_MECH_GSSAPI) && Curl_auth_is_gssapi_supported() &&
384
+ Curl_auth_user_contains_domain(conn->user)) {
385
+ sasl->mutual_auth = FALSE;
386
+ mech = SASL_MECH_STRING_GSSAPI;
387
+ state1 = SASL_GSSAPI;
388
+ state2 = SASL_GSSAPI_TOKEN;
389
+ sasl->authused = SASL_MECH_GSSAPI;
390
+
391
+ if(force_ir || data->set.sasl_ir)
392
+ result = Curl_auth_create_gssapi_user_message(data, conn->user,
393
+ conn->passwd,
394
+ service,
395
+ conn->host.name,
396
+ sasl->mutual_auth,
397
+ NULL, &conn->krb5,
398
+ &resp);
399
+ }
400
+ else
401
+ #endif
402
+ #ifdef USE_GSASL
403
+ if((enabledmechs & SASL_MECH_SCRAM_SHA_256) &&
404
+ Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_256,
405
+ &conn->gsasl)) {
406
+ mech = SASL_MECH_STRING_SCRAM_SHA_256;
407
+ sasl->authused = SASL_MECH_SCRAM_SHA_256;
408
+ state1 = SASL_GSASL;
409
+ state2 = SASL_GSASL;
410
+
411
+ result = Curl_auth_gsasl_start(data, conn->user,
412
+ conn->passwd, &conn->gsasl);
413
+ if(result == CURLE_OK && (force_ir || data->set.sasl_ir))
414
+ result = Curl_auth_gsasl_token(data, &nullmsg, &conn->gsasl, &resp);
415
+ }
416
+ else if((enabledmechs & SASL_MECH_SCRAM_SHA_1) &&
417
+ Curl_auth_gsasl_is_supported(data, SASL_MECH_STRING_SCRAM_SHA_1,
418
+ &conn->gsasl)) {
419
+ mech = SASL_MECH_STRING_SCRAM_SHA_1;
420
+ sasl->authused = SASL_MECH_SCRAM_SHA_1;
421
+ state1 = SASL_GSASL;
422
+ state2 = SASL_GSASL;
423
+
424
+ result = Curl_auth_gsasl_start(data, conn->user,
425
+ conn->passwd, &conn->gsasl);
426
+ if(result == CURLE_OK && (force_ir || data->set.sasl_ir))
427
+ result = Curl_auth_gsasl_token(data, &nullmsg, &conn->gsasl, &resp);
428
+ }
429
+ else
430
+ #endif
431
+ #ifndef CURL_DISABLE_DIGEST_AUTH
432
+ if((enabledmechs & SASL_MECH_DIGEST_MD5) &&
433
+ Curl_auth_is_digest_supported()) {
434
+ mech = SASL_MECH_STRING_DIGEST_MD5;
435
+ state1 = SASL_DIGESTMD5;
436
+ sasl->authused = SASL_MECH_DIGEST_MD5;
437
+ }
438
+ else if(enabledmechs & SASL_MECH_CRAM_MD5) {
439
+ mech = SASL_MECH_STRING_CRAM_MD5;
440
+ state1 = SASL_CRAMMD5;
441
+ sasl->authused = SASL_MECH_CRAM_MD5;
442
+ }
443
+ else
444
+ #endif
445
+ #ifdef USE_NTLM
446
+ if((enabledmechs & SASL_MECH_NTLM) && Curl_auth_is_ntlm_supported()) {
447
+ mech = SASL_MECH_STRING_NTLM;
448
+ state1 = SASL_NTLM;
449
+ state2 = SASL_NTLM_TYPE2MSG;
450
+ sasl->authused = SASL_MECH_NTLM;
451
+
452
+ if(force_ir || data->set.sasl_ir)
453
+ result = Curl_auth_create_ntlm_type1_message(data,
454
+ conn->user, conn->passwd,
455
+ service,
456
+ hostname,
457
+ &conn->ntlm, &resp);
458
+ }
459
+ else
460
+ #endif
461
+ if((enabledmechs & SASL_MECH_OAUTHBEARER) && oauth_bearer) {
462
+ mech = SASL_MECH_STRING_OAUTHBEARER;
463
+ state1 = SASL_OAUTH2;
464
+ state2 = SASL_OAUTH2_RESP;
465
+ sasl->authused = SASL_MECH_OAUTHBEARER;
466
+
467
+ if(force_ir || data->set.sasl_ir)
468
+ result = Curl_auth_create_oauth_bearer_message(conn->user,
469
+ hostname,
470
+ port,
471
+ oauth_bearer,
472
+ &resp);
473
+ }
474
+ else if((enabledmechs & SASL_MECH_XOAUTH2) && oauth_bearer) {
475
+ mech = SASL_MECH_STRING_XOAUTH2;
476
+ state1 = SASL_OAUTH2;
477
+ sasl->authused = SASL_MECH_XOAUTH2;
478
+
479
+ if(force_ir || data->set.sasl_ir)
480
+ result = Curl_auth_create_xoauth_bearer_message(conn->user,
481
+ oauth_bearer,
482
+ &resp);
483
+ }
484
+ else if(enabledmechs & SASL_MECH_PLAIN) {
485
+ mech = SASL_MECH_STRING_PLAIN;
486
+ state1 = SASL_PLAIN;
487
+ sasl->authused = SASL_MECH_PLAIN;
488
+
489
+ if(force_ir || data->set.sasl_ir)
490
+ result = Curl_auth_create_plain_message(conn->sasl_authzid,
491
+ conn->user, conn->passwd,
492
+ &resp);
493
+ }
494
+ else if(enabledmechs & SASL_MECH_LOGIN) {
495
+ mech = SASL_MECH_STRING_LOGIN;
496
+ state1 = SASL_LOGIN;
497
+ state2 = SASL_LOGIN_PASSWD;
498
+ sasl->authused = SASL_MECH_LOGIN;
499
+
500
+ if(force_ir || data->set.sasl_ir)
501
+ Curl_auth_create_login_message(conn->user, &resp);
502
+ }
503
+ }
504
+
505
+ if(!result && mech) {
506
+ sasl->curmech = mech;
507
+ if(Curl_bufref_ptr(&resp))
508
+ result = build_message(sasl, &resp);
509
+
510
+ if(sasl->params->maxirlen &&
511
+ strlen(mech) + Curl_bufref_len(&resp) > sasl->params->maxirlen)
512
+ Curl_bufref_free(&resp);
513
+
514
+ if(!result)
515
+ result = sasl->params->sendauth(data, mech, &resp);
516
+
517
+ if(!result) {
518
+ *progress = SASL_INPROGRESS;
519
+ sasl_state(sasl, data, Curl_bufref_ptr(&resp) ? state2 : state1);
520
+ }
521
+ }
522
+
523
+ Curl_bufref_free(&resp);
524
+ return result;
525
+ }
526
+
527
+ /*
528
+ * Curl_sasl_continue()
529
+ *
530
+ * Continue the authentication.
531
+ */
532
+ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
533
+ int code, saslprogress *progress)
534
+ {
535
+ CURLcode result = CURLE_OK;
536
+ struct connectdata *conn = data->conn;
537
+ saslstate newstate = SASL_FINAL;
538
+ struct bufref resp;
539
+ const char *hostname, *disp_hostname;
540
+ int port;
541
+ #if defined(USE_KERBEROS5) || defined(USE_NTLM) \
542
+ || !defined(CURL_DISABLE_DIGEST_AUTH)
543
+ const char *service = data->set.str[STRING_SERVICE_NAME] ?
544
+ data->set.str[STRING_SERVICE_NAME] :
545
+ sasl->params->service;
546
+ #endif
547
+ const char *oauth_bearer = data->set.str[STRING_BEARER];
548
+ struct bufref serverdata;
549
+
550
+ Curl_conn_get_host(data, FIRSTSOCKET, &hostname, &disp_hostname, &port);
551
+ Curl_bufref_init(&serverdata);
552
+ Curl_bufref_init(&resp);
553
+ *progress = SASL_INPROGRESS;
554
+
555
+ if(sasl->state == SASL_FINAL) {
556
+ if(code != sasl->params->finalcode)
557
+ result = CURLE_LOGIN_DENIED;
558
+ *progress = SASL_DONE;
559
+ sasl_state(sasl, data, SASL_STOP);
560
+ return result;
561
+ }
562
+
563
+ if(sasl->state != SASL_CANCEL && sasl->state != SASL_OAUTH2_RESP &&
564
+ code != sasl->params->contcode) {
565
+ *progress = SASL_DONE;
566
+ sasl_state(sasl, data, SASL_STOP);
567
+ return CURLE_LOGIN_DENIED;
568
+ }
569
+
570
+ switch(sasl->state) {
571
+ case SASL_STOP:
572
+ *progress = SASL_DONE;
573
+ return result;
574
+ case SASL_PLAIN:
575
+ result = Curl_auth_create_plain_message(conn->sasl_authzid,
576
+ conn->user, conn->passwd, &resp);
577
+ break;
578
+ case SASL_LOGIN:
579
+ Curl_auth_create_login_message(conn->user, &resp);
580
+ newstate = SASL_LOGIN_PASSWD;
581
+ break;
582
+ case SASL_LOGIN_PASSWD:
583
+ Curl_auth_create_login_message(conn->passwd, &resp);
584
+ break;
585
+ case SASL_EXTERNAL:
586
+ Curl_auth_create_external_message(conn->user, &resp);
587
+ break;
588
+ #ifdef USE_GSASL
589
+ case SASL_GSASL:
590
+ result = get_server_message(sasl, data, &serverdata);
591
+ if(!result)
592
+ result = Curl_auth_gsasl_token(data, &serverdata, &conn->gsasl, &resp);
593
+ if(!result && Curl_bufref_len(&resp) > 0)
594
+ newstate = SASL_GSASL;
595
+ break;
596
+ #endif
597
+ #ifndef CURL_DISABLE_DIGEST_AUTH
598
+ case SASL_CRAMMD5:
599
+ result = get_server_message(sasl, data, &serverdata);
600
+ if(!result)
601
+ result = Curl_auth_create_cram_md5_message(&serverdata, conn->user,
602
+ conn->passwd, &resp);
603
+ break;
604
+ case SASL_DIGESTMD5:
605
+ result = get_server_message(sasl, data, &serverdata);
606
+ if(!result)
607
+ result = Curl_auth_create_digest_md5_message(data, &serverdata,
608
+ conn->user, conn->passwd,
609
+ service, &resp);
610
+ if(!result && (sasl->params->flags & SASL_FLAG_BASE64))
611
+ newstate = SASL_DIGESTMD5_RESP;
612
+ break;
613
+ case SASL_DIGESTMD5_RESP:
614
+ /* Keep response NULL to output an empty line. */
615
+ break;
616
+ #endif
617
+
618
+ #ifdef USE_NTLM
619
+ case SASL_NTLM:
620
+ /* Create the type-1 message */
621
+ result = Curl_auth_create_ntlm_type1_message(data,
622
+ conn->user, conn->passwd,
623
+ service, hostname,
624
+ &conn->ntlm, &resp);
625
+ newstate = SASL_NTLM_TYPE2MSG;
626
+ break;
627
+ case SASL_NTLM_TYPE2MSG:
628
+ /* Decode the type-2 message */
629
+ result = get_server_message(sasl, data, &serverdata);
630
+ if(!result)
631
+ result = Curl_auth_decode_ntlm_type2_message(data, &serverdata,
632
+ &conn->ntlm);
633
+ if(!result)
634
+ result = Curl_auth_create_ntlm_type3_message(data, conn->user,
635
+ conn->passwd, &conn->ntlm,
636
+ &resp);
637
+ break;
638
+ #endif
639
+
640
+ #if defined(USE_KERBEROS5)
641
+ case SASL_GSSAPI:
642
+ result = Curl_auth_create_gssapi_user_message(data, conn->user,
643
+ conn->passwd,
644
+ service,
645
+ conn->host.name,
646
+ sasl->mutual_auth, NULL,
647
+ &conn->krb5,
648
+ &resp);
649
+ newstate = SASL_GSSAPI_TOKEN;
650
+ break;
651
+ case SASL_GSSAPI_TOKEN:
652
+ result = get_server_message(sasl, data, &serverdata);
653
+ if(!result) {
654
+ if(sasl->mutual_auth) {
655
+ /* Decode the user token challenge and create the optional response
656
+ message */
657
+ result = Curl_auth_create_gssapi_user_message(data, NULL, NULL,
658
+ NULL, NULL,
659
+ sasl->mutual_auth,
660
+ &serverdata,
661
+ &conn->krb5,
662
+ &resp);
663
+ newstate = SASL_GSSAPI_NO_DATA;
664
+ }
665
+ else
666
+ /* Decode the security challenge and create the response message */
667
+ result = Curl_auth_create_gssapi_security_message(data,
668
+ conn->sasl_authzid,
669
+ &serverdata,
670
+ &conn->krb5,
671
+ &resp);
672
+ }
673
+ break;
674
+ case SASL_GSSAPI_NO_DATA:
675
+ /* Decode the security challenge and create the response message */
676
+ result = get_server_message(sasl, data, &serverdata);
677
+ if(!result)
678
+ result = Curl_auth_create_gssapi_security_message(data,
679
+ conn->sasl_authzid,
680
+ &serverdata,
681
+ &conn->krb5,
682
+ &resp);
683
+ break;
684
+ #endif
685
+
686
+ case SASL_OAUTH2:
687
+ /* Create the authorization message */
688
+ if(sasl->authused == SASL_MECH_OAUTHBEARER) {
689
+ result = Curl_auth_create_oauth_bearer_message(conn->user,
690
+ hostname,
691
+ port,
692
+ oauth_bearer,
693
+ &resp);
694
+
695
+ /* Failures maybe sent by the server as continuations for OAUTHBEARER */
696
+ newstate = SASL_OAUTH2_RESP;
697
+ }
698
+ else
699
+ result = Curl_auth_create_xoauth_bearer_message(conn->user,
700
+ oauth_bearer,
701
+ &resp);
702
+ break;
703
+
704
+ case SASL_OAUTH2_RESP:
705
+ /* The continuation is optional so check the response code */
706
+ if(code == sasl->params->finalcode) {
707
+ /* Final response was received so we are done */
708
+ *progress = SASL_DONE;
709
+ sasl_state(sasl, data, SASL_STOP);
710
+ return result;
711
+ }
712
+ else if(code == sasl->params->contcode) {
713
+ /* Acknowledge the continuation by sending a 0x01 response. */
714
+ Curl_bufref_set(&resp, "\x01", 1, NULL);
715
+ break;
716
+ }
717
+ else {
718
+ *progress = SASL_DONE;
719
+ sasl_state(sasl, data, SASL_STOP);
720
+ return CURLE_LOGIN_DENIED;
721
+ }
722
+
723
+ case SASL_CANCEL:
724
+ /* Remove the offending mechanism from the supported list */
725
+ sasl->authmechs ^= sasl->authused;
726
+
727
+ /* Start an alternative SASL authentication */
728
+ return Curl_sasl_start(sasl, data, sasl->force_ir, progress);
729
+ default:
730
+ failf(data, "Unsupported SASL authentication mechanism");
731
+ result = CURLE_UNSUPPORTED_PROTOCOL; /* Should not happen */
732
+ break;
733
+ }
734
+
735
+ Curl_bufref_free(&serverdata);
736
+
737
+ switch(result) {
738
+ case CURLE_BAD_CONTENT_ENCODING:
739
+ /* Cancel dialog */
740
+ result = sasl->params->cancelauth(data, sasl->curmech);
741
+ newstate = SASL_CANCEL;
742
+ break;
743
+ case CURLE_OK:
744
+ result = build_message(sasl, &resp);
745
+ if(!result)
746
+ result = sasl->params->contauth(data, sasl->curmech, &resp);
747
+ break;
748
+ default:
749
+ newstate = SASL_STOP; /* Stop on error */
750
+ *progress = SASL_DONE;
751
+ break;
752
+ }
753
+
754
+ Curl_bufref_free(&resp);
755
+
756
+ sasl_state(sasl, data, newstate);
757
+
758
+ return result;
759
+ }
760
+ #endif /* protocols are enabled that use SASL */
local-test-curl-full-01/afc-curl/lib/curl_sspi.h ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_SSPI_H
2
+ #define HEADER_CURL_SSPI_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+
29
+ #ifdef USE_WINDOWS_SSPI
30
+
31
+ #include <curl/curl.h>
32
+
33
+ /*
34
+ * When including the following three headers, it is mandatory to define either
35
+ * SECURITY_WIN32 or SECURITY_KERNEL, indicating who is compiling the code.
36
+ */
37
+
38
+ #undef SECURITY_WIN32
39
+ #undef SECURITY_KERNEL
40
+ #define SECURITY_WIN32 1
41
+ #include <security.h>
42
+ #include <sspi.h>
43
+ #include <rpc.h>
44
+
45
+ CURLcode Curl_sspi_global_init(void);
46
+ void Curl_sspi_global_cleanup(void);
47
+
48
+ /* This is used to populate the domain in a SSPI identity structure */
49
+ CURLcode Curl_override_sspi_http_realm(const char *chlg,
50
+ SEC_WINNT_AUTH_IDENTITY *identity);
51
+
52
+ /* This is used to generate an SSPI identity structure */
53
+ CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp,
54
+ SEC_WINNT_AUTH_IDENTITY *identity);
55
+
56
+ /* This is used to free an SSPI identity structure */
57
+ void Curl_sspi_free_identity(SEC_WINNT_AUTH_IDENTITY *identity);
58
+
59
+ /* Forward-declaration of global variables defined in curl_sspi.c */
60
+ extern HMODULE Curl_hSecDll;
61
+ extern PSecurityFunctionTable Curl_pSecFn;
62
+
63
+ /* Provide some definitions missing in old headers */
64
+ #define SP_NAME_DIGEST "WDigest"
65
+ #define SP_NAME_NTLM "NTLM"
66
+ #define SP_NAME_NEGOTIATE "Negotiate"
67
+ #define SP_NAME_KERBEROS "Kerberos"
68
+
69
+ #ifndef ISC_REQ_USE_HTTP_STYLE
70
+ #define ISC_REQ_USE_HTTP_STYLE 0x01000000
71
+ #endif
72
+
73
+ #ifndef SEC_E_INVALID_PARAMETER
74
+ # define SEC_E_INVALID_PARAMETER ((HRESULT)0x8009035DL)
75
+ #endif
76
+ #ifndef SEC_E_DELEGATION_POLICY
77
+ # define SEC_E_DELEGATION_POLICY ((HRESULT)0x8009035EL)
78
+ #endif
79
+ #ifndef SEC_E_POLICY_NLTM_ONLY
80
+ # define SEC_E_POLICY_NLTM_ONLY ((HRESULT)0x8009035FL)
81
+ #endif
82
+
83
+ #ifndef SEC_I_SIGNATURE_NEEDED
84
+ # define SEC_I_SIGNATURE_NEEDED ((HRESULT)0x0009035CL)
85
+ #endif
86
+
87
+ #ifndef CRYPT_E_REVOKED
88
+ # define CRYPT_E_REVOKED ((HRESULT)0x80092010L)
89
+ #endif
90
+
91
+ #ifndef CRYPT_E_NO_REVOCATION_DLL
92
+ # define CRYPT_E_NO_REVOCATION_DLL ((HRESULT)0x80092011L)
93
+ #endif
94
+
95
+ #ifndef CRYPT_E_NO_REVOCATION_CHECK
96
+ # define CRYPT_E_NO_REVOCATION_CHECK ((HRESULT)0x80092012L)
97
+ #endif
98
+
99
+ #ifndef CRYPT_E_REVOCATION_OFFLINE
100
+ # define CRYPT_E_REVOCATION_OFFLINE ((HRESULT)0x80092013L)
101
+ #endif
102
+
103
+ #ifndef CRYPT_E_NOT_IN_REVOCATION_DATABASE
104
+ # define CRYPT_E_NOT_IN_REVOCATION_DATABASE ((HRESULT)0x80092014L)
105
+ #endif
106
+
107
+ #ifdef UNICODE
108
+ # define SECFLAG_WINNT_AUTH_IDENTITY \
109
+ (unsigned long)SEC_WINNT_AUTH_IDENTITY_UNICODE
110
+ #else
111
+ # define SECFLAG_WINNT_AUTH_IDENTITY \
112
+ (unsigned long)SEC_WINNT_AUTH_IDENTITY_ANSI
113
+ #endif
114
+
115
+ /*
116
+ * Definitions required from ntsecapi.h are directly provided below this point
117
+ * to avoid including ntsecapi.h due to a conflict with OpenSSL's safestack.h
118
+ */
119
+ #define KERB_WRAP_NO_ENCRYPT 0x80000001
120
+
121
+ #endif /* USE_WINDOWS_SSPI */
122
+
123
+ #endif /* HEADER_CURL_SSPI_H */
local-test-curl-full-01/afc-curl/lib/curl_threads.c ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include <curl/curl.h>
28
+
29
+ #if defined(USE_THREADS_POSIX)
30
+ # ifdef HAVE_PTHREAD_H
31
+ # include <pthread.h>
32
+ # endif
33
+ #elif defined(USE_THREADS_WIN32)
34
+ # include <process.h>
35
+ #endif
36
+
37
+ #include "curl_threads.h"
38
+ #ifdef BUILDING_LIBCURL
39
+ #include "curl_memory.h"
40
+ #endif
41
+ /* The last #include file should be: */
42
+ #include "memdebug.h"
43
+
44
+ #if defined(USE_THREADS_POSIX)
45
+
46
+ struct Curl_actual_call {
47
+ unsigned int (*func)(void *);
48
+ void *arg;
49
+ };
50
+
51
+ static void *curl_thread_create_thunk(void *arg)
52
+ {
53
+ struct Curl_actual_call *ac = arg;
54
+ unsigned int (*func)(void *) = ac->func;
55
+ void *real_arg = ac->arg;
56
+
57
+ free(ac);
58
+
59
+ (*func)(real_arg);
60
+
61
+ return 0;
62
+ }
63
+
64
+ curl_thread_t Curl_thread_create(unsigned int (*func) (void *), void *arg)
65
+ {
66
+ curl_thread_t t = malloc(sizeof(pthread_t));
67
+ struct Curl_actual_call *ac = malloc(sizeof(struct Curl_actual_call));
68
+ if(!(ac && t))
69
+ goto err;
70
+
71
+ ac->func = func;
72
+ ac->arg = arg;
73
+
74
+ if(pthread_create(t, NULL, curl_thread_create_thunk, ac) != 0)
75
+ goto err;
76
+
77
+ return t;
78
+
79
+ err:
80
+ free(t);
81
+ free(ac);
82
+ return curl_thread_t_null;
83
+ }
84
+
85
+ void Curl_thread_destroy(curl_thread_t hnd)
86
+ {
87
+ if(hnd != curl_thread_t_null) {
88
+ pthread_detach(*hnd);
89
+ free(hnd);
90
+ }
91
+ }
92
+
93
+ int Curl_thread_join(curl_thread_t *hnd)
94
+ {
95
+ int ret = (pthread_join(**hnd, NULL) == 0);
96
+
97
+ free(*hnd);
98
+ *hnd = curl_thread_t_null;
99
+
100
+ return ret;
101
+ }
102
+
103
+ #elif defined(USE_THREADS_WIN32)
104
+
105
+ curl_thread_t Curl_thread_create(
106
+ #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
107
+ DWORD
108
+ #else
109
+ unsigned int
110
+ #endif
111
+ (CURL_STDCALL *func) (void *),
112
+ void *arg)
113
+ {
114
+ #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
115
+ typedef HANDLE curl_win_thread_handle_t;
116
+ #else
117
+ typedef uintptr_t curl_win_thread_handle_t;
118
+ #endif
119
+ curl_thread_t t;
120
+ curl_win_thread_handle_t thread_handle;
121
+ #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
122
+ thread_handle = CreateThread(NULL, 0, func, arg, 0, NULL);
123
+ #else
124
+ thread_handle = _beginthreadex(NULL, 0, func, arg, 0, NULL);
125
+ #endif
126
+ t = (curl_thread_t)thread_handle;
127
+ if((t == 0) || (t == LongToHandle(-1L))) {
128
+ #ifdef _WIN32_WCE
129
+ DWORD gle = GetLastError();
130
+ errno = ((gle == ERROR_ACCESS_DENIED ||
131
+ gle == ERROR_NOT_ENOUGH_MEMORY) ?
132
+ EACCES : EINVAL);
133
+ #endif
134
+ return curl_thread_t_null;
135
+ }
136
+ return t;
137
+ }
138
+
139
+ void Curl_thread_destroy(curl_thread_t hnd)
140
+ {
141
+ if(hnd != curl_thread_t_null)
142
+ CloseHandle(hnd);
143
+ }
144
+
145
+ int Curl_thread_join(curl_thread_t *hnd)
146
+ {
147
+ #if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
148
+ (_WIN32_WINNT < _WIN32_WINNT_VISTA)
149
+ int ret = (WaitForSingleObject(*hnd, INFINITE) == WAIT_OBJECT_0);
150
+ #else
151
+ int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0);
152
+ #endif
153
+
154
+ Curl_thread_destroy(*hnd);
155
+
156
+ *hnd = curl_thread_t_null;
157
+
158
+ return ret;
159
+ }
160
+
161
+ #endif /* USE_THREADS_* */
local-test-curl-full-01/afc-curl/lib/curl_threads.h ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_THREADS_H
2
+ #define HEADER_CURL_THREADS_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ #include "curl_setup.h"
27
+
28
+ #if defined(USE_THREADS_POSIX)
29
+ # define CURL_STDCALL
30
+ # define curl_mutex_t pthread_mutex_t
31
+ # define curl_thread_t pthread_t *
32
+ # define curl_thread_t_null (pthread_t *)0
33
+ # define Curl_mutex_init(m) pthread_mutex_init(m, NULL)
34
+ # define Curl_mutex_acquire(m) pthread_mutex_lock(m)
35
+ # define Curl_mutex_release(m) pthread_mutex_unlock(m)
36
+ # define Curl_mutex_destroy(m) pthread_mutex_destroy(m)
37
+ #elif defined(USE_THREADS_WIN32)
38
+ # define CURL_STDCALL __stdcall
39
+ # define curl_mutex_t CRITICAL_SECTION
40
+ # define curl_thread_t HANDLE
41
+ # define curl_thread_t_null (HANDLE)0
42
+ # if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
43
+ (_WIN32_WINNT < _WIN32_WINNT_VISTA)
44
+ # define Curl_mutex_init(m) InitializeCriticalSection(m)
45
+ # else
46
+ # define Curl_mutex_init(m) InitializeCriticalSectionEx(m, 0, 1)
47
+ # endif
48
+ # define Curl_mutex_acquire(m) EnterCriticalSection(m)
49
+ # define Curl_mutex_release(m) LeaveCriticalSection(m)
50
+ # define Curl_mutex_destroy(m) DeleteCriticalSection(m)
51
+ #endif
52
+
53
+ #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
54
+
55
+ curl_thread_t Curl_thread_create(
56
+ #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP)
57
+ DWORD
58
+ #else
59
+ unsigned int
60
+ #endif
61
+ (CURL_STDCALL *func) (void *),
62
+ void *arg);
63
+
64
+ void Curl_thread_destroy(curl_thread_t hnd);
65
+
66
+ int Curl_thread_join(curl_thread_t *hnd);
67
+
68
+ #endif /* USE_THREADS_POSIX || USE_THREADS_WIN32 */
69
+
70
+ #endif /* HEADER_CURL_THREADS_H */
local-test-curl-full-01/afc-curl/lib/curlx.h ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_CURLX_H
2
+ #define HEADER_CURL_CURLX_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ /*
28
+ * Defines protos and includes all header files that provide the curlx_*
29
+ * functions. The curlx_* functions are not part of the libcurl API, but are
30
+ * stand-alone functions whose sources can be built and linked by apps if need
31
+ * be.
32
+ */
33
+
34
+ /* map standard printf functions to curl implementations */
35
+ #include "curl_printf.h"
36
+
37
+ #include "strcase.h"
38
+ /* "strcase.h" provides the strcasecompare protos */
39
+
40
+ #include "strtoofft.h"
41
+ /* "strtoofft.h" provides this function: curlx_strtoofft(), returns a
42
+ curl_off_t number from a given string.
43
+ */
44
+
45
+ #include "nonblock.h"
46
+ /* "nonblock.h" provides curlx_nonblock() */
47
+
48
+ #include "warnless.h"
49
+ /* "warnless.h" provides functions:
50
+
51
+ curlx_ultous()
52
+ curlx_ultouc()
53
+ curlx_uztosi()
54
+ */
55
+
56
+ #include "curl_multibyte.h"
57
+ /* "curl_multibyte.h" provides these functions and macros:
58
+
59
+ curlx_convert_UTF8_to_wchar()
60
+ curlx_convert_wchar_to_UTF8()
61
+ curlx_convert_UTF8_to_tchar()
62
+ curlx_convert_tchar_to_UTF8()
63
+ curlx_unicodefree()
64
+ */
65
+
66
+ #include "version_win32.h"
67
+ /* "version_win32.h" provides curlx_verify_windows_version() */
68
+
69
+ #endif /* HEADER_CURL_CURLX_H */
local-test-curl-full-01/afc-curl/lib/cw-out.c ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include <curl/curl.h>
28
+
29
+ #include "urldata.h"
30
+ #include "cfilters.h"
31
+ #include "headers.h"
32
+ #include "multiif.h"
33
+ #include "sendf.h"
34
+ #include "cw-out.h"
35
+
36
+ /* The last 3 #include files should be in this order */
37
+ #include "curl_printf.h"
38
+ #include "curl_memory.h"
39
+ #include "memdebug.h"
40
+
41
+
42
+ /**
43
+ * OVERALL DESIGN of this client writer
44
+ *
45
+ * The 'cw-out' writer is supposed to be the last writer in a transfer's
46
+ * stack. It is always added when that stack is initialized. Its purpose
47
+ * is to pass BODY and HEADER bytes to the client-installed callback
48
+ * functions.
49
+ *
50
+ * These callback may return `CURL_WRITEFUNC_PAUSE` to indicate that the
51
+ * data had not been written and the whole transfer should stop receiving
52
+ * new data. Or at least, stop calling the functions. When the transfer
53
+ * is "unpaused" by the client, the previous data shall be passed as
54
+ * if nothing happened.
55
+ *
56
+ * The `cw-out` writer therefore manages buffers for bytes that could
57
+ * not be written. Data that was already in flight from the server also
58
+ * needs buffering on paused transfer when it arrives.
59
+ *
60
+ * In addition, the writer allows buffering of "small" body writes,
61
+ * so client functions are called less often. That is only enabled on a
62
+ * number of conditions.
63
+ *
64
+ * HEADER and BODY data may arrive in any order. For paused transfers,
65
+ * a list of `struct cw_out_buf` is kept for `cw_out_type` types. The
66
+ * list may be: [BODY]->[HEADER]->[BODY]->[HEADER]....
67
+ * When unpausing, this list is "played back" to the client callbacks.
68
+ *
69
+ * The amount of bytes being buffered is limited by `DYN_PAUSE_BUFFER`
70
+ * and when that is exceeded `CURLE_TOO_LARGE` is returned as error.
71
+ */
72
+ typedef enum {
73
+ CW_OUT_NONE,
74
+ CW_OUT_BODY,
75
+ CW_OUT_HDS
76
+ } cw_out_type;
77
+
78
+ struct cw_out_buf {
79
+ struct cw_out_buf *next;
80
+ struct dynbuf b;
81
+ cw_out_type type;
82
+ };
83
+
84
+ static struct cw_out_buf *cw_out_buf_create(cw_out_type otype)
85
+ {
86
+ struct cw_out_buf *cwbuf = calloc(1, sizeof(*cwbuf));
87
+ if(cwbuf) {
88
+ cwbuf->type = otype;
89
+ Curl_dyn_init(&cwbuf->b, DYN_PAUSE_BUFFER);
90
+ }
91
+ return cwbuf;
92
+ }
93
+
94
+ static void cw_out_buf_free(struct cw_out_buf *cwbuf)
95
+ {
96
+ if(cwbuf) {
97
+ Curl_dyn_free(&cwbuf->b);
98
+ free(cwbuf);
99
+ }
100
+ }
101
+
102
+ struct cw_out_ctx {
103
+ struct Curl_cwriter super;
104
+ struct cw_out_buf *buf;
105
+ BIT(paused);
106
+ BIT(errored);
107
+ };
108
+
109
+ static CURLcode cw_out_write(struct Curl_easy *data,
110
+ struct Curl_cwriter *writer, int type,
111
+ const char *buf, size_t nbytes);
112
+ static void cw_out_close(struct Curl_easy *data, struct Curl_cwriter *writer);
113
+ static CURLcode cw_out_init(struct Curl_easy *data,
114
+ struct Curl_cwriter *writer);
115
+
116
+ struct Curl_cwtype Curl_cwt_out = {
117
+ "cw-out",
118
+ NULL,
119
+ cw_out_init,
120
+ cw_out_write,
121
+ cw_out_close,
122
+ sizeof(struct cw_out_ctx)
123
+ };
124
+
125
+ static CURLcode cw_out_init(struct Curl_easy *data,
126
+ struct Curl_cwriter *writer)
127
+ {
128
+ struct cw_out_ctx *ctx = writer->ctx;
129
+ (void)data;
130
+ ctx->buf = NULL;
131
+ return CURLE_OK;
132
+ }
133
+
134
+ static void cw_out_bufs_free(struct cw_out_ctx *ctx)
135
+ {
136
+ while(ctx->buf) {
137
+ struct cw_out_buf *next = ctx->buf->next;
138
+ cw_out_buf_free(ctx->buf);
139
+ ctx->buf = next;
140
+ }
141
+ }
142
+
143
+ static size_t cw_out_bufs_len(struct cw_out_ctx *ctx)
144
+ {
145
+ struct cw_out_buf *cwbuf = ctx->buf;
146
+ size_t len = 0;
147
+ while(cwbuf) {
148
+ len += Curl_dyn_len(&cwbuf->b);
149
+ cwbuf = cwbuf->next;
150
+ }
151
+ return len;
152
+ }
153
+
154
+ static void cw_out_close(struct Curl_easy *data, struct Curl_cwriter *writer)
155
+ {
156
+ struct cw_out_ctx *ctx = writer->ctx;
157
+
158
+ (void)data;
159
+ cw_out_bufs_free(ctx);
160
+ }
161
+
162
+ /**
163
+ * Return the current curl_write_callback and user_data for the buf type
164
+ */
165
+ static void cw_get_writefunc(struct Curl_easy *data, cw_out_type otype,
166
+ curl_write_callback *pwcb, void **pwcb_data,
167
+ size_t *pmax_write, size_t *pmin_write)
168
+ {
169
+ switch(otype) {
170
+ case CW_OUT_BODY:
171
+ *pwcb = data->set.fwrite_func;
172
+ *pwcb_data = data->set.out;
173
+ *pmax_write = CURL_MAX_WRITE_SIZE;
174
+ /* if we ever want buffering of BODY output, we can set `min_write`
175
+ * the preferred size. The default should always be to pass data
176
+ * to the client as it comes without delay */
177
+ *pmin_write = 0;
178
+ break;
179
+ case CW_OUT_HDS:
180
+ *pwcb = data->set.fwrite_header ? data->set.fwrite_header :
181
+ (data->set.writeheader ? data->set.fwrite_func : NULL);
182
+ *pwcb_data = data->set.writeheader;
183
+ *pmax_write = 0; /* do not chunk-write headers, write them as they are */
184
+ *pmin_write = 0;
185
+ break;
186
+ default:
187
+ *pwcb = NULL;
188
+ *pwcb_data = NULL;
189
+ *pmax_write = CURL_MAX_WRITE_SIZE;
190
+ *pmin_write = 0;
191
+ }
192
+ }
193
+
194
+ static CURLcode cw_out_ptr_flush(struct cw_out_ctx *ctx,
195
+ struct Curl_easy *data,
196
+ cw_out_type otype,
197
+ bool flush_all,
198
+ const char *buf, size_t blen,
199
+ size_t *pconsumed)
200
+ {
201
+ curl_write_callback wcb;
202
+ void *wcb_data;
203
+ size_t max_write, min_write;
204
+ size_t wlen, nwritten;
205
+
206
+ /* If we errored once, we do not invoke the client callback again */
207
+ if(ctx->errored)
208
+ return CURLE_WRITE_ERROR;
209
+
210
+ /* write callbacks may get NULLed by the client between calls. */
211
+ cw_get_writefunc(data, otype, &wcb, &wcb_data, &max_write, &min_write);
212
+ if(!wcb) {
213
+ *pconsumed = blen;
214
+ return CURLE_OK;
215
+ }
216
+
217
+ *pconsumed = 0;
218
+ while(blen && !ctx->paused) {
219
+ if(!flush_all && blen < min_write)
220
+ break;
221
+ wlen = max_write ? CURLMIN(blen, max_write) : blen;
222
+ Curl_set_in_callback(data, TRUE);
223
+ nwritten = wcb((char *)buf, 1, wlen, wcb_data);
224
+ Curl_set_in_callback(data, FALSE);
225
+ CURL_TRC_WRITE(data, "cw_out, wrote %zu %s bytes -> %zu",
226
+ wlen, (otype == CW_OUT_BODY) ? "body" : "header",
227
+ nwritten);
228
+ if(CURL_WRITEFUNC_PAUSE == nwritten) {
229
+ if(data->conn && data->conn->handler->flags & PROTOPT_NONETWORK) {
230
+ /* Protocols that work without network cannot be paused. This is
231
+ actually only FILE:// just now, and it cannot pause since the
232
+ transfer is not done using the "normal" procedure. */
233
+ failf(data, "Write callback asked for PAUSE when not supported");
234
+ return CURLE_WRITE_ERROR;
235
+ }
236
+ /* mark the connection as RECV paused */
237
+ data->req.keepon |= KEEP_RECV_PAUSE;
238
+ ctx->paused = TRUE;
239
+ CURL_TRC_WRITE(data, "cw_out, PAUSE requested by client");
240
+ break;
241
+ }
242
+ else if(CURL_WRITEFUNC_ERROR == nwritten) {
243
+ failf(data, "client returned ERROR on write of %zu bytes", wlen);
244
+ return CURLE_WRITE_ERROR;
245
+ }
246
+ else if(nwritten != wlen) {
247
+ failf(data, "Failure writing output to destination, "
248
+ "passed %zu returned %zd", wlen, nwritten);
249
+ return CURLE_WRITE_ERROR;
250
+ }
251
+ *pconsumed += nwritten;
252
+ blen -= nwritten;
253
+ buf += nwritten;
254
+ }
255
+ return CURLE_OK;
256
+ }
257
+
258
+ static CURLcode cw_out_buf_flush(struct cw_out_ctx *ctx,
259
+ struct Curl_easy *data,
260
+ struct cw_out_buf *cwbuf,
261
+ bool flush_all)
262
+ {
263
+ CURLcode result = CURLE_OK;
264
+
265
+ if(Curl_dyn_len(&cwbuf->b)) {
266
+ size_t consumed;
267
+
268
+ result = cw_out_ptr_flush(ctx, data, cwbuf->type, flush_all,
269
+ Curl_dyn_ptr(&cwbuf->b),
270
+ Curl_dyn_len(&cwbuf->b),
271
+ &consumed);
272
+ if(result)
273
+ return result;
274
+
275
+ if(consumed) {
276
+ if(consumed == Curl_dyn_len(&cwbuf->b)) {
277
+ Curl_dyn_free(&cwbuf->b);
278
+ }
279
+ else {
280
+ DEBUGASSERT(consumed < Curl_dyn_len(&cwbuf->b));
281
+ result = Curl_dyn_tail(&cwbuf->b, Curl_dyn_len(&cwbuf->b) - consumed);
282
+ if(result)
283
+ return result;
284
+ }
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+
290
+ static CURLcode cw_out_flush_chain(struct cw_out_ctx *ctx,
291
+ struct Curl_easy *data,
292
+ struct cw_out_buf **pcwbuf,
293
+ bool flush_all)
294
+ {
295
+ struct cw_out_buf *cwbuf = *pcwbuf;
296
+ CURLcode result;
297
+
298
+ if(!cwbuf)
299
+ return CURLE_OK;
300
+ if(ctx->paused)
301
+ return CURLE_OK;
302
+
303
+ /* write the end of the chain until it blocks or gets empty */
304
+ while(cwbuf->next) {
305
+ struct cw_out_buf **plast = &cwbuf->next;
306
+ while((*plast)->next)
307
+ plast = &(*plast)->next;
308
+ result = cw_out_flush_chain(ctx, data, plast, flush_all);
309
+ if(result)
310
+ return result;
311
+ if(*plast) {
312
+ /* could not write last, paused again? */
313
+ DEBUGASSERT(ctx->paused);
314
+ return CURLE_OK;
315
+ }
316
+ }
317
+
318
+ result = cw_out_buf_flush(ctx, data, cwbuf, flush_all);
319
+ if(result)
320
+ return result;
321
+ if(!Curl_dyn_len(&cwbuf->b)) {
322
+ cw_out_buf_free(cwbuf);
323
+ *pcwbuf = NULL;
324
+ }
325
+ return CURLE_OK;
326
+ }
327
+
328
+ static CURLcode cw_out_append(struct cw_out_ctx *ctx,
329
+ cw_out_type otype,
330
+ const char *buf, size_t blen)
331
+ {
332
+ if(cw_out_bufs_len(ctx) + blen > DYN_PAUSE_BUFFER)
333
+ return CURLE_TOO_LARGE;
334
+
335
+ /* if we do not have a buffer, or it is of another type, make a new one.
336
+ * And for CW_OUT_HDS always make a new one, so we "replay" headers
337
+ * exactly as they came in */
338
+ if(!ctx->buf || (ctx->buf->type != otype) || (otype == CW_OUT_HDS)) {
339
+ struct cw_out_buf *cwbuf = cw_out_buf_create(otype);
340
+ if(!cwbuf)
341
+ return CURLE_OUT_OF_MEMORY;
342
+ cwbuf->next = ctx->buf;
343
+ ctx->buf = cwbuf;
344
+ }
345
+ DEBUGASSERT(ctx->buf && (ctx->buf->type == otype));
346
+ return Curl_dyn_addn(&ctx->buf->b, buf, blen);
347
+ }
348
+
349
+ static CURLcode cw_out_do_write(struct cw_out_ctx *ctx,
350
+ struct Curl_easy *data,
351
+ cw_out_type otype,
352
+ bool flush_all,
353
+ const char *buf, size_t blen)
354
+ {
355
+ CURLcode result = CURLE_OK;
356
+
357
+ /* if we have buffered data and it is a different type than what
358
+ * we are writing now, try to flush all */
359
+ if(ctx->buf && ctx->buf->type != otype) {
360
+ result = cw_out_flush_chain(ctx, data, &ctx->buf, TRUE);
361
+ if(result)
362
+ goto out;
363
+ }
364
+
365
+ if(ctx->buf) {
366
+ /* still have buffered data, append and flush */
367
+ result = cw_out_append(ctx, otype, buf, blen);
368
+ if(result)
369
+ return result;
370
+ result = cw_out_flush_chain(ctx, data, &ctx->buf, flush_all);
371
+ if(result)
372
+ goto out;
373
+ }
374
+ else {
375
+ /* nothing buffered, try direct write */
376
+ size_t consumed;
377
+ result = cw_out_ptr_flush(ctx, data, otype, flush_all,
378
+ buf, blen, &consumed);
379
+ if(result)
380
+ return result;
381
+ if(consumed < blen) {
382
+ /* did not write all, append the rest */
383
+ result = cw_out_append(ctx, otype, buf + consumed, blen - consumed);
384
+ if(result)
385
+ goto out;
386
+ }
387
+ }
388
+
389
+ out:
390
+ if(result) {
391
+ /* We do not want to invoked client callbacks a second time after
392
+ * encountering an error. See issue #13337 */
393
+ ctx->errored = TRUE;
394
+ cw_out_bufs_free(ctx);
395
+ }
396
+ return result;
397
+ }
398
+
399
+ static CURLcode cw_out_write(struct Curl_easy *data,
400
+ struct Curl_cwriter *writer, int type,
401
+ const char *buf, size_t blen)
402
+ {
403
+ struct cw_out_ctx *ctx = writer->ctx;
404
+ CURLcode result;
405
+ bool flush_all = !!(type & CLIENTWRITE_EOS);
406
+
407
+ if((type & CLIENTWRITE_BODY) ||
408
+ ((type & CLIENTWRITE_HEADER) && data->set.include_header)) {
409
+ result = cw_out_do_write(ctx, data, CW_OUT_BODY, flush_all, buf, blen);
410
+ if(result)
411
+ return result;
412
+ }
413
+
414
+ if(type & (CLIENTWRITE_HEADER|CLIENTWRITE_INFO)) {
415
+ result = cw_out_do_write(ctx, data, CW_OUT_HDS, flush_all, buf, blen);
416
+ if(result)
417
+ return result;
418
+ }
419
+
420
+ return CURLE_OK;
421
+ }
422
+
423
+ bool Curl_cw_out_is_paused(struct Curl_easy *data)
424
+ {
425
+ struct Curl_cwriter *cw_out;
426
+ struct cw_out_ctx *ctx;
427
+
428
+ cw_out = Curl_cwriter_get_by_type(data, &Curl_cwt_out);
429
+ if(!cw_out)
430
+ return FALSE;
431
+
432
+ ctx = (struct cw_out_ctx *)cw_out;
433
+ CURL_TRC_WRITE(data, "cw-out is%spaused", ctx->paused ? "" : " not");
434
+ return ctx->paused;
435
+ }
436
+
437
+ static CURLcode cw_out_flush(struct Curl_easy *data,
438
+ bool unpause, bool flush_all)
439
+ {
440
+ struct Curl_cwriter *cw_out;
441
+ CURLcode result = CURLE_OK;
442
+
443
+ cw_out = Curl_cwriter_get_by_type(data, &Curl_cwt_out);
444
+ if(cw_out) {
445
+ struct cw_out_ctx *ctx = (struct cw_out_ctx *)cw_out;
446
+ if(ctx->errored)
447
+ return CURLE_WRITE_ERROR;
448
+ if(unpause && ctx->paused)
449
+ ctx->paused = FALSE;
450
+ if(ctx->paused)
451
+ return CURLE_OK; /* not doing it */
452
+
453
+ result = cw_out_flush_chain(ctx, data, &ctx->buf, flush_all);
454
+ if(result) {
455
+ ctx->errored = TRUE;
456
+ cw_out_bufs_free(ctx);
457
+ return result;
458
+ }
459
+ }
460
+ return result;
461
+ }
462
+
463
+ CURLcode Curl_cw_out_unpause(struct Curl_easy *data)
464
+ {
465
+ CURL_TRC_WRITE(data, "cw-out unpause");
466
+ return cw_out_flush(data, TRUE, FALSE);
467
+ }
468
+
469
+ CURLcode Curl_cw_out_done(struct Curl_easy *data)
470
+ {
471
+ CURL_TRC_WRITE(data, "cw-out done");
472
+ return cw_out_flush(data, FALSE, TRUE);
473
+ }
local-test-curl-full-01/afc-curl/lib/dict.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_DICT_H
2
+ #define HEADER_CURL_DICT_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #ifndef CURL_DISABLE_DICT
28
+ extern const struct Curl_handler Curl_handler_dict;
29
+ #endif
30
+
31
+ #endif /* HEADER_CURL_DICT_H */
local-test-curl-full-01/afc-curl/lib/dllmain.c ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #ifdef USE_OPENSSL
28
+ #include <openssl/crypto.h>
29
+ #endif
30
+
31
+ /* The fourth-to-last include */
32
+ #ifdef __CYGWIN__
33
+ #define WIN32_LEAN_AND_MEAN
34
+ #include <windows.h>
35
+ #ifdef _WIN32
36
+ #undef _WIN32
37
+ #endif
38
+ #endif
39
+
40
+ /* The last 3 #include files should be in this order */
41
+ #include "curl_printf.h"
42
+ #include "curl_memory.h"
43
+ #include "memdebug.h"
44
+
45
+ /* DllMain() must only be defined for Windows and Cygwin DLL builds. */
46
+ #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(CURL_STATICLIB)
47
+
48
+ #if defined(USE_OPENSSL) && \
49
+ !defined(OPENSSL_IS_AWSLC) && \
50
+ !defined(OPENSSL_IS_BORINGSSL) && \
51
+ !defined(LIBRESSL_VERSION_NUMBER) && \
52
+ (OPENSSL_VERSION_NUMBER >= 0x10100000L)
53
+ #define PREVENT_OPENSSL_MEMLEAK
54
+ #endif
55
+
56
+ #ifdef PREVENT_OPENSSL_MEMLEAK
57
+ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
58
+ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
59
+ {
60
+ (void)hinstDLL;
61
+ (void)lpvReserved;
62
+
63
+ switch(fdwReason) {
64
+ case DLL_PROCESS_ATTACH:
65
+ break;
66
+ case DLL_PROCESS_DETACH:
67
+ break;
68
+ case DLL_THREAD_ATTACH:
69
+ break;
70
+ case DLL_THREAD_DETACH:
71
+ /* Call OPENSSL_thread_stop to prevent a memory leak in case OpenSSL is
72
+ linked statically.
73
+ https://github.com/curl/curl/issues/12327#issuecomment-1826405944 */
74
+ OPENSSL_thread_stop();
75
+ break;
76
+ }
77
+ return TRUE;
78
+ }
79
+ #endif /* OpenSSL */
80
+
81
+ #endif /* DLL build */
local-test-curl-full-01/afc-curl/lib/doh.h ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_DOH_H
2
+ #define HEADER_CURL_DOH_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "urldata.h"
28
+ #include "curl_addrinfo.h"
29
+ #ifdef USE_HTTPSRR
30
+ # include <stdint.h>
31
+ #endif
32
+
33
+ #ifndef CURL_DISABLE_DOH
34
+
35
+ typedef enum {
36
+ DOH_OK,
37
+ DOH_DNS_BAD_LABEL, /* 1 */
38
+ DOH_DNS_OUT_OF_RANGE, /* 2 */
39
+ DOH_DNS_LABEL_LOOP, /* 3 */
40
+ DOH_TOO_SMALL_BUFFER, /* 4 */
41
+ DOH_OUT_OF_MEM, /* 5 */
42
+ DOH_DNS_RDATA_LEN, /* 6 */
43
+ DOH_DNS_MALFORMAT, /* 7 */
44
+ DOH_DNS_BAD_RCODE, /* 8 - no such name */
45
+ DOH_DNS_UNEXPECTED_TYPE, /* 9 */
46
+ DOH_DNS_UNEXPECTED_CLASS, /* 10 */
47
+ DOH_NO_CONTENT, /* 11 */
48
+ DOH_DNS_BAD_ID, /* 12 */
49
+ DOH_DNS_NAME_TOO_LONG /* 13 */
50
+ } DOHcode;
51
+
52
+ typedef enum {
53
+ DNS_TYPE_A = 1,
54
+ DNS_TYPE_NS = 2,
55
+ DNS_TYPE_CNAME = 5,
56
+ DNS_TYPE_AAAA = 28,
57
+ DNS_TYPE_DNAME = 39, /* RFC6672 */
58
+ DNS_TYPE_HTTPS = 65
59
+ } DNStype;
60
+
61
+ /* one of these for each DoH request */
62
+ struct doh_probe {
63
+ curl_off_t easy_mid; /* multi id of easy handle doing the lookup */
64
+ DNStype dnstype;
65
+ unsigned char req_body[512];
66
+ size_t req_body_len;
67
+ struct dynbuf resp_body;
68
+ };
69
+
70
+ enum doh_slot_num {
71
+ /* Explicit values for first two symbols so as to match hard-coded
72
+ * constants in existing code
73
+ */
74
+ DOH_SLOT_IPV4 = 0, /* make 'V4' stand out for readability */
75
+ DOH_SLOT_IPV6 = 1, /* 'V6' likewise */
76
+
77
+ /* Space here for (possibly build-specific) additional slot definitions */
78
+ #ifdef USE_HTTPSRR
79
+ DOH_SLOT_HTTPS_RR = 2, /* for HTTPS RR */
80
+ #endif
81
+
82
+ /* for example */
83
+ /* #ifdef WANT_DOH_FOOBAR_TXT */
84
+ /* DOH_PROBE_SLOT_FOOBAR_TXT, */
85
+ /* #endif */
86
+
87
+ /* AFTER all slot definitions, establish how many we have */
88
+ DOH_SLOT_COUNT
89
+ };
90
+
91
+ struct doh_probes {
92
+ struct curl_slist *req_hds;
93
+ struct doh_probe probe[DOH_SLOT_COUNT];
94
+ unsigned int pending; /* still outstanding probes */
95
+ int port;
96
+ const char *host;
97
+ };
98
+
99
+ /*
100
+ * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name
101
+ * and returns a 'Curl_addrinfo *' with the address information.
102
+ */
103
+
104
+ struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
105
+ const char *hostname,
106
+ int port,
107
+ int *waitp);
108
+
109
+ CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
110
+ struct Curl_dns_entry **dns);
111
+
112
+ #define DOH_MAX_ADDR 24
113
+ #define DOH_MAX_CNAME 4
114
+ #define DOH_MAX_HTTPS 4
115
+
116
+ struct dohaddr {
117
+ int type;
118
+ union {
119
+ unsigned char v4[4]; /* network byte order */
120
+ unsigned char v6[16];
121
+ } ip;
122
+ };
123
+
124
+ #ifdef USE_HTTPSRR
125
+
126
+ /*
127
+ * These are the code points for DNS wire format SvcParams as
128
+ * per draft-ietf-dnsop-svcb-https
129
+ * Not all are supported now, and even those that are may need
130
+ * more work in future to fully support the spec.
131
+ */
132
+ #define HTTPS_RR_CODE_ALPN 0x01
133
+ #define HTTPS_RR_CODE_NO_DEF_ALPN 0x02
134
+ #define HTTPS_RR_CODE_PORT 0x03
135
+ #define HTTPS_RR_CODE_IPV4 0x04
136
+ #define HTTPS_RR_CODE_ECH 0x05
137
+ #define HTTPS_RR_CODE_IPV6 0x06
138
+
139
+ /*
140
+ * These may need escaping when found within an ALPN string
141
+ * value.
142
+ */
143
+ #define COMMA_CHAR ','
144
+ #define BACKSLASH_CHAR '\\'
145
+
146
+ struct dohhttps_rr {
147
+ uint16_t len; /* raw encoded length */
148
+ unsigned char *val; /* raw encoded octets */
149
+ };
150
+ #endif
151
+
152
+ struct dohentry {
153
+ struct dynbuf cname[DOH_MAX_CNAME];
154
+ struct dohaddr addr[DOH_MAX_ADDR];
155
+ int numaddr;
156
+ unsigned int ttl;
157
+ int numcname;
158
+ #ifdef USE_HTTPSRR
159
+ struct dohhttps_rr https_rrs[DOH_MAX_HTTPS];
160
+ int numhttps_rrs;
161
+ #endif
162
+ };
163
+
164
+ void Curl_doh_close(struct Curl_easy *data);
165
+ void Curl_doh_cleanup(struct Curl_easy *data);
166
+
167
+ #ifdef UNITTESTS
168
+ UNITTEST DOHcode doh_req_encode(const char *host,
169
+ DNStype dnstype,
170
+ unsigned char *dnsp, /* buffer */
171
+ size_t len, /* buffer size */
172
+ size_t *olen); /* output length */
173
+ UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
174
+ size_t dohlen,
175
+ DNStype dnstype,
176
+ struct dohentry *d);
177
+
178
+ UNITTEST void de_init(struct dohentry *d);
179
+ UNITTEST void de_cleanup(struct dohentry *d);
180
+ #endif
181
+
182
+ extern struct curl_trc_feat Curl_doh_trc;
183
+
184
+ #else /* if DoH is disabled */
185
+ #define Curl_doh(a,b,c,d) NULL
186
+ #define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
187
+ #endif
188
+
189
+ #endif /* HEADER_CURL_DOH_H */
local-test-curl-full-01/afc-curl/lib/easygetopt.c ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ | |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * ___|___/|_| ______|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+ #include "strcase.h"
27
+ #include "easyoptions.h"
28
+
29
+ #ifndef CURL_DISABLE_GETOPTIONS
30
+
31
+ /* Lookups easy options at runtime */
32
+ static struct curl_easyoption *lookup(const char *name, CURLoption id)
33
+ {
34
+ DEBUGASSERT(name || id);
35
+ DEBUGASSERT(!Curl_easyopts_check());
36
+ if(name || id) {
37
+ struct curl_easyoption *o = &Curl_easyopts[0];
38
+ do {
39
+ if(name) {
40
+ if(strcasecompare(o->name, name))
41
+ return o;
42
+ }
43
+ else {
44
+ if((o->id == id) && !(o->flags & CURLOT_FLAG_ALIAS))
45
+ /* do not match alias options */
46
+ return o;
47
+ }
48
+ o++;
49
+ } while(o->name);
50
+ }
51
+ return NULL;
52
+ }
53
+
54
+ const struct curl_easyoption *curl_easy_option_by_name(const char *name)
55
+ {
56
+ /* when name is used, the id argument is ignored */
57
+ return lookup(name, CURLOPT_LASTENTRY);
58
+ }
59
+
60
+ const struct curl_easyoption *curl_easy_option_by_id(CURLoption id)
61
+ {
62
+ return lookup(NULL, id);
63
+ }
64
+
65
+ /* Iterates over available options */
66
+ const struct curl_easyoption *
67
+ curl_easy_option_next(const struct curl_easyoption *prev)
68
+ {
69
+ if(prev && prev->name) {
70
+ prev++;
71
+ if(prev->name)
72
+ return prev;
73
+ }
74
+ else if(!prev)
75
+ return &Curl_easyopts[0];
76
+ return NULL;
77
+ }
78
+
79
+ #else
80
+ const struct curl_easyoption *curl_easy_option_by_name(const char *name)
81
+ {
82
+ (void)name;
83
+ return NULL;
84
+ }
85
+
86
+ const struct curl_easyoption *curl_easy_option_by_id (CURLoption id)
87
+ {
88
+ (void)id;
89
+ return NULL;
90
+ }
91
+
92
+ const struct curl_easyoption *
93
+ curl_easy_option_next(const struct curl_easyoption *prev)
94
+ {
95
+ (void)prev;
96
+ return NULL;
97
+ }
98
+ #endif
local-test-curl-full-01/afc-curl/lib/escape.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_ESCAPE_H
2
+ #define HEADER_CURL_ESCAPE_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ /* Escape and unescape URL encoding in strings. The functions return a new
27
+ * allocated string or NULL if an error occurred. */
28
+
29
+ #include "curl_ctype.h"
30
+
31
+ enum urlreject {
32
+ REJECT_NADA = 2,
33
+ REJECT_CTRL,
34
+ REJECT_ZERO
35
+ };
36
+
37
+ CURLcode Curl_urldecode(const char *string, size_t length,
38
+ char **ostring, size_t *olen,
39
+ enum urlreject ctrl);
40
+
41
+ void Curl_hexencode(const unsigned char *src, size_t len, /* input length */
42
+ unsigned char *out, size_t olen); /* output buffer size */
43
+
44
+ #endif /* HEADER_CURL_ESCAPE_H */
local-test-curl-full-01/afc-curl/lib/file.c ADDED
@@ -0,0 +1,659 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #ifndef CURL_DISABLE_FILE
28
+
29
+ #ifdef HAVE_NETINET_IN_H
30
+ #include <netinet/in.h>
31
+ #endif
32
+ #ifdef HAVE_NETDB_H
33
+ #include <netdb.h>
34
+ #endif
35
+ #ifdef HAVE_ARPA_INET_H
36
+ #include <arpa/inet.h>
37
+ #endif
38
+ #ifdef HAVE_NET_IF_H
39
+ #include <net/if.h>
40
+ #endif
41
+ #ifdef HAVE_SYS_IOCTL_H
42
+ #include <sys/ioctl.h>
43
+ #endif
44
+
45
+ #ifdef HAVE_SYS_PARAM_H
46
+ #include <sys/param.h>
47
+ #endif
48
+
49
+ #ifdef HAVE_FCNTL_H
50
+ #include <fcntl.h>
51
+ #endif
52
+
53
+ #ifdef HAVE_SYS_TYPES_H
54
+ #include <sys/types.h>
55
+ #endif
56
+
57
+ #ifdef HAVE_DIRENT_H
58
+ #include <dirent.h>
59
+ #endif
60
+
61
+ #include "strtoofft.h"
62
+ #include "urldata.h"
63
+ #include <curl/curl.h>
64
+ #include "progress.h"
65
+ #include "sendf.h"
66
+ #include "escape.h"
67
+ #include "file.h"
68
+ #include "speedcheck.h"
69
+ #include "getinfo.h"
70
+ #include "multiif.h"
71
+ #include "transfer.h"
72
+ #include "url.h"
73
+ #include "parsedate.h" /* for the week day and month names */
74
+ #include "warnless.h"
75
+ #include "curl_range.h"
76
+ /* The last 3 #include files should be in this order */
77
+ #include "curl_printf.h"
78
+ #include "curl_memory.h"
79
+ #include "memdebug.h"
80
+
81
+ #if defined(_WIN32) || defined(MSDOS) || defined(__EMX__)
82
+ #define DOS_FILESYSTEM 1
83
+ #elif defined(__amigaos4__)
84
+ #define AMIGA_FILESYSTEM 1
85
+ #endif
86
+
87
+ #ifdef OPEN_NEEDS_ARG3
88
+ # define open_readonly(p,f) open((p),(f),(0))
89
+ #else
90
+ # define open_readonly(p,f) open((p),(f))
91
+ #endif
92
+
93
+ /*
94
+ * Forward declarations.
95
+ */
96
+
97
+ static CURLcode file_do(struct Curl_easy *data, bool *done);
98
+ static CURLcode file_done(struct Curl_easy *data,
99
+ CURLcode status, bool premature);
100
+ static CURLcode file_connect(struct Curl_easy *data, bool *done);
101
+ static CURLcode file_disconnect(struct Curl_easy *data,
102
+ struct connectdata *conn,
103
+ bool dead_connection);
104
+ static CURLcode file_setup_connection(struct Curl_easy *data,
105
+ struct connectdata *conn);
106
+
107
+ /*
108
+ * FILE scheme handler.
109
+ */
110
+
111
+ const struct Curl_handler Curl_handler_file = {
112
+ "file", /* scheme */
113
+ file_setup_connection, /* setup_connection */
114
+ file_do, /* do_it */
115
+ file_done, /* done */
116
+ ZERO_NULL, /* do_more */
117
+ file_connect, /* connect_it */
118
+ ZERO_NULL, /* connecting */
119
+ ZERO_NULL, /* doing */
120
+ ZERO_NULL, /* proto_getsock */
121
+ ZERO_NULL, /* doing_getsock */
122
+ ZERO_NULL, /* domore_getsock */
123
+ ZERO_NULL, /* perform_getsock */
124
+ file_disconnect, /* disconnect */
125
+ ZERO_NULL, /* write_resp */
126
+ ZERO_NULL, /* write_resp_hd */
127
+ ZERO_NULL, /* connection_check */
128
+ ZERO_NULL, /* attach connection */
129
+ 0, /* defport */
130
+ CURLPROTO_FILE, /* protocol */
131
+ CURLPROTO_FILE, /* family */
132
+ PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */
133
+ };
134
+
135
+
136
+ static CURLcode file_setup_connection(struct Curl_easy *data,
137
+ struct connectdata *conn)
138
+ {
139
+ (void)conn;
140
+ /* allocate the FILE specific struct */
141
+ data->req.p.file = calloc(1, sizeof(struct FILEPROTO));
142
+ if(!data->req.p.file)
143
+ return CURLE_OUT_OF_MEMORY;
144
+
145
+ return CURLE_OK;
146
+ }
147
+
148
+ /*
149
+ * file_connect() gets called from Curl_protocol_connect() to allow us to
150
+ * do protocol-specific actions at connect-time. We emulate a
151
+ * connect-then-transfer protocol and "connect" to the file here
152
+ */
153
+ static CURLcode file_connect(struct Curl_easy *data, bool *done)
154
+ {
155
+ char *real_path;
156
+ struct FILEPROTO *file = data->req.p.file;
157
+ int fd;
158
+ #ifdef DOS_FILESYSTEM
159
+ size_t i;
160
+ char *actual_path;
161
+ #endif
162
+ size_t real_path_len;
163
+ CURLcode result;
164
+
165
+ if(file->path) {
166
+ /* already connected.
167
+ * the handler->connect_it() is normally only called once, but
168
+ * FILE does a special check on setting up the connection which
169
+ * calls this explicitly. */
170
+ *done = TRUE;
171
+ return CURLE_OK;
172
+ }
173
+
174
+ result = Curl_urldecode(data->state.up.path, 0, &real_path,
175
+ &real_path_len, REJECT_ZERO);
176
+ if(result)
177
+ return result;
178
+
179
+ #ifdef DOS_FILESYSTEM
180
+ /* If the first character is a slash, and there is
181
+ something that looks like a drive at the beginning of
182
+ the path, skip the slash. If we remove the initial
183
+ slash in all cases, paths without drive letters end up
184
+ relative to the current directory which is not how
185
+ browsers work.
186
+
187
+ Some browsers accept | instead of : as the drive letter
188
+ separator, so we do too.
189
+
190
+ On other platforms, we need the slash to indicate an
191
+ absolute pathname. On Windows, absolute paths start
192
+ with a drive letter.
193
+ */
194
+ actual_path = real_path;
195
+ if((actual_path[0] == '/') &&
196
+ actual_path[1] &&
197
+ (actual_path[2] == ':' || actual_path[2] == '|')) {
198
+ actual_path[2] = ':';
199
+ actual_path++;
200
+ real_path_len--;
201
+ }
202
+
203
+ /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */
204
+ for(i = 0; i < real_path_len; ++i)
205
+ if(actual_path[i] == '/')
206
+ actual_path[i] = '\\';
207
+ else if(!actual_path[i]) { /* binary zero */
208
+ Curl_safefree(real_path);
209
+ return CURLE_URL_MALFORMAT;
210
+ }
211
+
212
+ fd = open_readonly(actual_path, O_RDONLY|O_BINARY);
213
+ file->path = actual_path;
214
+ #else
215
+ if(memchr(real_path, 0, real_path_len)) {
216
+ /* binary zeroes indicate foul play */
217
+ Curl_safefree(real_path);
218
+ return CURLE_URL_MALFORMAT;
219
+ }
220
+
221
+ #ifdef AMIGA_FILESYSTEM
222
+ /*
223
+ * A leading slash in an AmigaDOS path denotes the parent
224
+ * directory, and hence we block this as it is relative.
225
+ * Absolute paths start with 'volumename:', so we check for
226
+ * this first. Failing that, we treat the path as a real Unix
227
+ * path, but only if the application was compiled with -lunix.
228
+ */
229
+ fd = -1;
230
+ file->path = real_path;
231
+
232
+ if(real_path[0] == '/') {
233
+ extern int __unix_path_semantics;
234
+ if(strchr(real_path + 1, ':')) {
235
+ /* Amiga absolute path */
236
+ fd = open_readonly(real_path + 1, O_RDONLY);
237
+ file->path++;
238
+ }
239
+ else if(__unix_path_semantics) {
240
+ /* -lunix fallback */
241
+ fd = open_readonly(real_path, O_RDONLY);
242
+ }
243
+ }
244
+ #else
245
+ fd = open_readonly(real_path, O_RDONLY);
246
+ file->path = real_path;
247
+ #endif
248
+ #endif
249
+ Curl_safefree(file->freepath);
250
+ file->freepath = real_path; /* free this when done */
251
+
252
+ file->fd = fd;
253
+ if(!data->state.upload && (fd == -1)) {
254
+ failf(data, "Couldn't open file %s", data->state.up.path);
255
+ file_done(data, CURLE_FILE_COULDNT_READ_FILE, FALSE);
256
+ return CURLE_FILE_COULDNT_READ_FILE;
257
+ }
258
+ *done = TRUE;
259
+
260
+ return CURLE_OK;
261
+ }
262
+
263
+ static CURLcode file_done(struct Curl_easy *data,
264
+ CURLcode status, bool premature)
265
+ {
266
+ struct FILEPROTO *file = data->req.p.file;
267
+ (void)status; /* not used */
268
+ (void)premature; /* not used */
269
+
270
+ if(file) {
271
+ Curl_safefree(file->freepath);
272
+ file->path = NULL;
273
+ if(file->fd != -1)
274
+ close(file->fd);
275
+ file->fd = -1;
276
+ }
277
+
278
+ return CURLE_OK;
279
+ }
280
+
281
+ static CURLcode file_disconnect(struct Curl_easy *data,
282
+ struct connectdata *conn,
283
+ bool dead_connection)
284
+ {
285
+ (void)dead_connection; /* not used */
286
+ (void)conn;
287
+ return file_done(data, CURLE_OK, FALSE);
288
+ }
289
+
290
+ #ifdef DOS_FILESYSTEM
291
+ #define DIRSEP '\\'
292
+ #else
293
+ #define DIRSEP '/'
294
+ #endif
295
+
296
+ static CURLcode file_upload(struct Curl_easy *data)
297
+ {
298
+ struct FILEPROTO *file = data->req.p.file;
299
+ const char *dir = strchr(file->path, DIRSEP);
300
+ int fd;
301
+ int mode;
302
+ CURLcode result = CURLE_OK;
303
+ char *xfer_ulbuf;
304
+ size_t xfer_ulblen;
305
+ curl_off_t bytecount = 0;
306
+ struct_stat file_stat;
307
+ const char *sendbuf;
308
+ bool eos = FALSE;
309
+
310
+ /*
311
+ * Since FILE: does not do the full init, we need to provide some extra
312
+ * assignments here.
313
+ */
314
+
315
+ if(!dir)
316
+ return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */
317
+
318
+ if(!dir[1])
319
+ return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */
320
+
321
+ #ifdef O_BINARY
322
+ #define MODE_DEFAULT O_WRONLY|O_CREAT|O_BINARY
323
+ #else
324
+ #define MODE_DEFAULT O_WRONLY|O_CREAT
325
+ #endif
326
+
327
+ if(data->state.resume_from)
328
+ mode = MODE_DEFAULT|O_APPEND;
329
+ else
330
+ mode = MODE_DEFAULT|O_TRUNC;
331
+
332
+ fd = open(file->path, mode, data->set.new_file_perms);
333
+ if(fd < 0) {
334
+ failf(data, "cannot open %s for writing", file->path);
335
+ return CURLE_WRITE_ERROR;
336
+ }
337
+
338
+ if(-1 != data->state.infilesize)
339
+ /* known size of data to "upload" */
340
+ Curl_pgrsSetUploadSize(data, data->state.infilesize);
341
+
342
+ /* treat the negative resume offset value as the case of "-" */
343
+ if(data->state.resume_from < 0) {
344
+ if(fstat(fd, &file_stat)) {
345
+ close(fd);
346
+ failf(data, "cannot get the size of %s", file->path);
347
+ return CURLE_WRITE_ERROR;
348
+ }
349
+ data->state.resume_from = (curl_off_t)file_stat.st_size;
350
+ }
351
+
352
+ result = Curl_multi_xfer_ulbuf_borrow(data, &xfer_ulbuf, &xfer_ulblen);
353
+ if(result)
354
+ goto out;
355
+
356
+ while(!result && !eos) {
357
+ size_t nread;
358
+ ssize_t nwrite;
359
+ size_t readcount;
360
+
361
+ result = Curl_client_read(data, xfer_ulbuf, xfer_ulblen, &readcount, &eos);
362
+ if(result)
363
+ break;
364
+
365
+ if(!readcount)
366
+ break;
367
+
368
+ nread = readcount;
369
+
370
+ /* skip bytes before resume point */
371
+ if(data->state.resume_from) {
372
+ if((curl_off_t)nread <= data->state.resume_from) {
373
+ data->state.resume_from -= nread;
374
+ nread = 0;
375
+ sendbuf = xfer_ulbuf;
376
+ }
377
+ else {
378
+ sendbuf = xfer_ulbuf + data->state.resume_from;
379
+ nread -= (size_t)data->state.resume_from;
380
+ data->state.resume_from = 0;
381
+ }
382
+ }
383
+ else
384
+ sendbuf = xfer_ulbuf;
385
+
386
+ /* write the data to the target */
387
+ nwrite = write(fd, sendbuf, nread);
388
+ if((size_t)nwrite != nread) {
389
+ result = CURLE_SEND_ERROR;
390
+ break;
391
+ }
392
+
393
+ bytecount += nread;
394
+
395
+ Curl_pgrsSetUploadCounter(data, bytecount);
396
+
397
+ if(Curl_pgrsUpdate(data))
398
+ result = CURLE_ABORTED_BY_CALLBACK;
399
+ else
400
+ result = Curl_speedcheck(data, Curl_now());
401
+ }
402
+ if(!result && Curl_pgrsUpdate(data))
403
+ result = CURLE_ABORTED_BY_CALLBACK;
404
+
405
+ out:
406
+ close(fd);
407
+ Curl_multi_xfer_ulbuf_release(data, xfer_ulbuf);
408
+
409
+ return result;
410
+ }
411
+
412
+ /*
413
+ * file_do() is the protocol-specific function for the do-phase, separated
414
+ * from the connect-phase above. Other protocols merely setup the transfer in
415
+ * the do-phase, to have it done in the main transfer loop but since some
416
+ * platforms we support do not allow select()ing etc on file handles (as
417
+ * opposed to sockets) we instead perform the whole do-operation in this
418
+ * function.
419
+ */
420
+ static CURLcode file_do(struct Curl_easy *data, bool *done)
421
+ {
422
+ /* This implementation ignores the hostname in conformance with
423
+ RFC 1738. Only local files (reachable via the standard file system)
424
+ are supported. This means that files on remotely mounted directories
425
+ (via NFS, Samba, NT sharing) can be accessed through a file:// URL
426
+ */
427
+ CURLcode result = CURLE_OK;
428
+ struct_stat statbuf; /* struct_stat instead of struct stat just to allow the
429
+ Windows version to have a different struct without
430
+ having to redefine the simple word 'stat' */
431
+ curl_off_t expected_size = -1;
432
+ bool size_known;
433
+ bool fstated = FALSE;
434
+ int fd;
435
+ struct FILEPROTO *file;
436
+ char *xfer_buf;
437
+ size_t xfer_blen;
438
+
439
+ *done = TRUE; /* unconditionally */
440
+
441
+ if(data->state.upload)
442
+ return file_upload(data);
443
+
444
+ file = data->req.p.file;
445
+
446
+ /* get the fd from the connection phase */
447
+ fd = file->fd;
448
+
449
+ /* VMS: This only works reliable for STREAMLF files */
450
+ if(-1 != fstat(fd, &statbuf)) {
451
+ if(!S_ISDIR(statbuf.st_mode))
452
+ expected_size = statbuf.st_size;
453
+ /* and store the modification time */
454
+ data->info.filetime = statbuf.st_mtime;
455
+ fstated = TRUE;
456
+ }
457
+
458
+ if(fstated && !data->state.range && data->set.timecondition &&
459
+ !Curl_meets_timecondition(data, data->info.filetime))
460
+ return CURLE_OK;
461
+
462
+ if(fstated) {
463
+ time_t filetime;
464
+ struct tm buffer;
465
+ const struct tm *tm = &buffer;
466
+ char header[80];
467
+ int headerlen;
468
+ static const char accept_ranges[]= { "Accept-ranges: bytes\r\n" };
469
+ static const char no_body[]= { "File-body: suppressed.The body of "
470
+ "this file has been supressed. If you would like to include "
471
+ "the contents of this file use the -i option.\r\n" };
472
+ static const char body_msg[]= { "File-body: included.\r\n"};
473
+ if(expected_size >= 0) {
474
+ headerlen =
475
+ msnprintf(header, sizeof(header), "Content-Length: %" FMT_OFF_T "\r\n",
476
+ expected_size);
477
+ result = Curl_client_write(data, CLIENTWRITE_HEADER,
478
+ header, headerlen);
479
+ if(result)
480
+ return result;
481
+
482
+ result = Curl_client_write(data, CLIENTWRITE_HEADER,
483
+ accept_ranges, sizeof(accept_ranges) - 1);
484
+ if(result != CURLE_OK)
485
+ return result;
486
+ }
487
+
488
+ filetime = (time_t)statbuf.st_mtime;
489
+ result = Curl_gmtime(filetime, &buffer);
490
+ if(result)
491
+ return result;
492
+
493
+ if(data->req.no_body) {
494
+ headerlen =
495
+ msnprintf(header, sizeof(no_body), "%s (%ld bytes) \r\n",
496
+ no_body, expected_size);
497
+ result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen);
498
+ }
499
+ else {
500
+ result = Curl_client_write(data, CLIENTWRITE_HEADER,
501
+ body_msg, sizeof(body_msg) - 1);
502
+ }
503
+ if(result)
504
+ return result;
505
+ /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
506
+ headerlen =
507
+ msnprintf(header, sizeof(header),
508
+ "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
509
+ Curl_wkday[tm->tm_wday ? tm->tm_wday-1 : 6],
510
+ tm->tm_mday,
511
+ Curl_month[tm->tm_mon],
512
+ tm->tm_year + 1900,
513
+ tm->tm_hour,
514
+ tm->tm_min,
515
+ tm->tm_sec);
516
+ result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen);
517
+ if(!result)
518
+ /* end of headers */
519
+ result = Curl_client_write(data, CLIENTWRITE_HEADER, "\r\n", 2);
520
+ if(result)
521
+ return result;
522
+ /* set the file size to make it available post transfer */
523
+ Curl_pgrsSetDownloadSize(data, expected_size);
524
+ if(data->req.no_body)
525
+ return CURLE_OK;
526
+ }
527
+
528
+ /* Check whether file range has been specified */
529
+ result = Curl_range(data);
530
+ if(result)
531
+ return result;
532
+
533
+ /* Adjust the start offset in case we want to get the N last bytes
534
+ * of the stream if the filesize could be determined */
535
+ if(data->state.resume_from < 0) {
536
+ if(!fstated) {
537
+ failf(data, "cannot get the size of file.");
538
+ return CURLE_READ_ERROR;
539
+ }
540
+ data->state.resume_from += (curl_off_t)statbuf.st_size;
541
+ }
542
+
543
+ if(data->state.resume_from > 0) {
544
+ /* We check explicitly if we have a start offset, because
545
+ * expected_size may be -1 if we do not know how large the file is,
546
+ * in which case we should not adjust it. */
547
+ if(data->state.resume_from <= expected_size)
548
+ expected_size -= data->state.resume_from;
549
+ else {
550
+ failf(data, "failed to resume file:// transfer");
551
+ return CURLE_BAD_DOWNLOAD_RESUME;
552
+ }
553
+ }
554
+
555
+ /* A high water mark has been specified so we obey... */
556
+ if(data->req.maxdownload > 0)
557
+ expected_size = data->req.maxdownload;
558
+
559
+ if(!fstated || (expected_size <= 0))
560
+ size_known = FALSE;
561
+ else
562
+ size_known = TRUE;
563
+
564
+ /* The following is a shortcut implementation of file reading
565
+ this is both more efficient than the former call to download() and
566
+ it avoids problems with select() and recv() on file descriptors
567
+ in Winsock */
568
+ if(size_known)
569
+ Curl_pgrsSetDownloadSize(data, expected_size);
570
+
571
+ if(data->state.resume_from) {
572
+ if(!S_ISDIR(statbuf.st_mode)) {
573
+ if(data->state.resume_from !=
574
+ lseek(fd, data->state.resume_from, SEEK_SET))
575
+ return CURLE_BAD_DOWNLOAD_RESUME;
576
+ }
577
+ else {
578
+ return CURLE_BAD_DOWNLOAD_RESUME;
579
+ }
580
+ }
581
+
582
+ result = Curl_multi_xfer_buf_borrow(data, &xfer_buf, &xfer_blen);
583
+ if(result)
584
+ goto out;
585
+
586
+ if(!S_ISDIR(statbuf.st_mode)) {
587
+ while(!result) {
588
+ ssize_t nread;
589
+ /* Do not fill a whole buffer if we want less than all data */
590
+ size_t bytestoread;
591
+
592
+ if(size_known) {
593
+ bytestoread = (expected_size < (curl_off_t)(xfer_blen-1)) ?
594
+ curlx_sotouz(expected_size) : (xfer_blen-1);
595
+ }
596
+ else
597
+ bytestoread = xfer_blen-1;
598
+
599
+ nread = read(fd, xfer_buf, bytestoread);
600
+
601
+ if(nread > 0)
602
+ xfer_buf[nread] = 0;
603
+
604
+ if(nread <= 0 || (size_known && (expected_size == 0)))
605
+ break;
606
+
607
+ if(size_known)
608
+ expected_size -= nread;
609
+
610
+ result = Curl_client_write(data, CLIENTWRITE_BODY, xfer_buf, nread);
611
+ if(result)
612
+ goto out;
613
+
614
+ if(Curl_pgrsUpdate(data))
615
+ result = CURLE_ABORTED_BY_CALLBACK;
616
+ else
617
+ result = Curl_speedcheck(data, Curl_now());
618
+ if(result)
619
+ goto out;
620
+ }
621
+ }
622
+ else {
623
+ #ifdef HAVE_OPENDIR
624
+ DIR *dir = opendir(file->path);
625
+ struct dirent *entry;
626
+
627
+ if(!dir) {
628
+ result = CURLE_READ_ERROR;
629
+ goto out;
630
+ }
631
+ else {
632
+ while((entry = readdir(dir))) {
633
+ if(entry->d_name[0] != '.') {
634
+ result = Curl_client_write(data, CLIENTWRITE_BODY,
635
+ entry->d_name, strlen(entry->d_name));
636
+ if(result)
637
+ break;
638
+ result = Curl_client_write(data, CLIENTWRITE_BODY, "\n", 1);
639
+ if(result)
640
+ break;
641
+ }
642
+ }
643
+ closedir(dir);
644
+ }
645
+ #else
646
+ failf(data, "Directory listing not yet implemented on this platform.");
647
+ result = CURLE_READ_ERROR;
648
+ #endif
649
+ }
650
+
651
+ if(Curl_pgrsUpdate(data))
652
+ result = CURLE_ABORTED_BY_CALLBACK;
653
+
654
+ out:
655
+ Curl_multi_xfer_buf_release(data, xfer_buf);
656
+ return result;
657
+ }
658
+
659
+ #endif
local-test-curl-full-01/afc-curl/lib/fileinfo.c ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+ #ifndef CURL_DISABLE_FTP
27
+ #include "strdup.h"
28
+ #include "fileinfo.h"
29
+ #include "curl_memory.h"
30
+ /* The last #include file should be: */
31
+ #include "memdebug.h"
32
+
33
+ struct fileinfo *Curl_fileinfo_alloc(void)
34
+ {
35
+ return calloc(1, sizeof(struct fileinfo));
36
+ }
37
+
38
+ void Curl_fileinfo_cleanup(struct fileinfo *finfo)
39
+ {
40
+ if(!finfo)
41
+ return;
42
+
43
+ Curl_dyn_free(&finfo->buf);
44
+ free(finfo);
45
+ }
46
+ #endif
local-test-curl-full-01/afc-curl/lib/fopen.c ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \
28
+ !defined(CURL_DISABLE_HSTS)
29
+
30
+ #ifdef HAVE_FCNTL_H
31
+ #include <fcntl.h>
32
+ #endif
33
+
34
+ #include "urldata.h"
35
+ #include "rand.h"
36
+ #include "fopen.h"
37
+ /* The last 3 #include files should be in this order */
38
+ #include "curl_printf.h"
39
+ #include "curl_memory.h"
40
+ #include "memdebug.h"
41
+
42
+ /*
43
+ The dirslash() function breaks a null-terminated pathname string into
44
+ directory and filename components then returns the directory component up
45
+ to, *AND INCLUDING*, a final '/'. If there is no directory in the path,
46
+ this instead returns a "" string.
47
+
48
+ This function returns a pointer to malloc'ed memory.
49
+
50
+ The input path to this function is expected to have a filename part.
51
+ */
52
+
53
+ #ifdef _WIN32
54
+ #define PATHSEP "\\"
55
+ #define IS_SEP(x) (((x) == '/') || ((x) == '\\'))
56
+ #elif defined(MSDOS) || defined(__EMX__) || defined(OS2)
57
+ #define PATHSEP "\\"
58
+ #define IS_SEP(x) ((x) == '\\')
59
+ #else
60
+ #define PATHSEP "/"
61
+ #define IS_SEP(x) ((x) == '/')
62
+ #endif
63
+
64
+ static char *dirslash(const char *path)
65
+ {
66
+ size_t n;
67
+ struct dynbuf out;
68
+ DEBUGASSERT(path);
69
+ Curl_dyn_init(&out, CURL_MAX_INPUT_LENGTH);
70
+ n = strlen(path);
71
+ if(n) {
72
+ /* find the rightmost path separator, if any */
73
+ while(n && !IS_SEP(path[n-1]))
74
+ --n;
75
+ /* skip over all the path separators, if any */
76
+ while(n && IS_SEP(path[n-1]))
77
+ --n;
78
+ }
79
+ if(Curl_dyn_addn(&out, path, n))
80
+ return NULL;
81
+ /* if there was a directory, append a single trailing slash */
82
+ if(n && Curl_dyn_addn(&out, PATHSEP, 1))
83
+ return NULL;
84
+ return Curl_dyn_ptr(&out);
85
+ }
86
+
87
+ /*
88
+ * Curl_fopen() opens a file for writing with a temp name, to be renamed
89
+ * to the final name when completed. If there is an existing file using this
90
+ * name at the time of the open, this function will clone the mode from that
91
+ * file. if 'tempname' is non-NULL, it needs a rename after the file is
92
+ * written.
93
+ */
94
+ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
95
+ FILE **fh, char **tempname)
96
+ {
97
+ CURLcode result = CURLE_WRITE_ERROR;
98
+ unsigned char randbuf[41];
99
+ char *tempstore = NULL;
100
+ struct_stat sb;
101
+ int fd = -1;
102
+ char *dir = NULL;
103
+ *tempname = NULL;
104
+
105
+ *fh = fopen(filename, FOPEN_WRITETEXT);
106
+ if(!*fh)
107
+ goto fail;
108
+ if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode)) {
109
+ return CURLE_OK;
110
+ }
111
+ fclose(*fh);
112
+ *fh = NULL;
113
+
114
+ result = Curl_rand_alnum(data, randbuf, sizeof(randbuf));
115
+ if(result)
116
+ goto fail;
117
+
118
+ dir = dirslash(filename);
119
+ if(dir) {
120
+ /* The temp filename should not end up too long for the target file
121
+ system */
122
+ tempstore = aprintf("%s%s.tmp", dir, randbuf);
123
+ free(dir);
124
+ }
125
+
126
+ if(!tempstore) {
127
+ result = CURLE_OUT_OF_MEMORY;
128
+ goto fail;
129
+ }
130
+
131
+ result = CURLE_WRITE_ERROR;
132
+ #if (defined(ANDROID) || defined(__ANDROID__)) && \
133
+ (defined(__i386__) || defined(__arm__))
134
+ fd = open(tempstore, O_WRONLY | O_CREAT | O_EXCL, (mode_t)(0600|sb.st_mode));
135
+ #else
136
+ fd = open(tempstore, O_WRONLY | O_CREAT | O_EXCL, 0600|sb.st_mode);
137
+ #endif
138
+ if(fd == -1)
139
+ goto fail;
140
+
141
+ *fh = fdopen(fd, FOPEN_WRITETEXT);
142
+ if(!*fh)
143
+ goto fail;
144
+
145
+ *tempname = tempstore;
146
+ return CURLE_OK;
147
+
148
+ fail:
149
+ if(fd != -1) {
150
+ close(fd);
151
+ unlink(tempstore);
152
+ }
153
+
154
+ free(tempstore);
155
+ return result;
156
+ }
157
+
158
+ #endif /* ! disabled */
local-test-curl-full-01/afc-curl/lib/fopen.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_FOPEN_H
2
+ #define HEADER_CURL_FOPEN_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
28
+ FILE **fh, char **tempname);
29
+
30
+ #endif
local-test-curl-full-01/afc-curl/lib/ftp.h ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_FTP_H
2
+ #define HEADER_CURL_FTP_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+
27
+ #include "curl_setup.h"
28
+
29
+ #include "pingpong.h"
30
+
31
+ #ifndef CURL_DISABLE_FTP
32
+ extern const struct Curl_handler Curl_handler_ftp;
33
+
34
+ #ifdef USE_SSL
35
+ extern const struct Curl_handler Curl_handler_ftps;
36
+ #endif
37
+
38
+ CURLcode Curl_GetFTPResponse(struct Curl_easy *data, ssize_t *nread,
39
+ int *ftpcode);
40
+ #endif /* CURL_DISABLE_FTP */
41
+
42
+ /****************************************************************************
43
+ * FTP unique setup
44
+ ***************************************************************************/
45
+ enum {
46
+ FTP_STOP, /* do nothing state, stops the state machine */
47
+ FTP_WAIT220, /* waiting for the initial 220 response immediately after
48
+ a connect */
49
+ FTP_AUTH,
50
+ FTP_USER,
51
+ FTP_PASS,
52
+ FTP_ACCT,
53
+ FTP_PBSZ,
54
+ FTP_PROT,
55
+ FTP_CCC,
56
+ FTP_PWD,
57
+ FTP_SYST,
58
+ FTP_NAMEFMT,
59
+ FTP_QUOTE, /* waiting for a response to a command sent in a quote list */
60
+ FTP_RETR_PREQUOTE,
61
+ FTP_STOR_PREQUOTE,
62
+ FTP_POSTQUOTE,
63
+ FTP_CWD, /* change dir */
64
+ FTP_MKD, /* if the dir did not exist */
65
+ FTP_MDTM, /* to figure out the datestamp */
66
+ FTP_TYPE, /* to set type when doing a head-like request */
67
+ FTP_LIST_TYPE, /* set type when about to do a dir list */
68
+ FTP_RETR_TYPE, /* set type when about to RETR a file */
69
+ FTP_STOR_TYPE, /* set type when about to STOR a file */
70
+ FTP_SIZE, /* get the remote file's size for head-like request */
71
+ FTP_RETR_SIZE, /* get the remote file's size for RETR */
72
+ FTP_STOR_SIZE, /* get the size for STOR */
73
+ FTP_REST, /* when used to check if the server supports it in head-like */
74
+ FTP_RETR_REST, /* when asking for "resume" in for RETR */
75
+ FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
76
+ FTP_PRET, /* generic state for PRET RETR, PRET STOR and PRET LIST/NLST */
77
+ FTP_PASV, /* generic state for PASV and EPSV, check count1 */
78
+ FTP_LIST, /* generic state for LIST, NLST or a custom list command */
79
+ FTP_RETR,
80
+ FTP_STOR, /* generic state for STOR and APPE */
81
+ FTP_QUIT,
82
+ FTP_LAST /* never used */
83
+ };
84
+ typedef unsigned char ftpstate; /* use the enum values */
85
+
86
+ struct ftp_parselist_data; /* defined later in ftplistparser.c */
87
+
88
+ struct ftp_wc {
89
+ struct ftp_parselist_data *parser;
90
+
91
+ struct {
92
+ curl_write_callback write_function;
93
+ FILE *file_descriptor;
94
+ } backup;
95
+ };
96
+
97
+ typedef enum {
98
+ FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */
99
+ FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */
100
+ FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the
101
+ file */
102
+ } curl_ftpfile;
103
+
104
+ /* This FTP struct is used in the Curl_easy. All FTP data that is
105
+ connection-oriented must be in FTP_conn to properly deal with the fact that
106
+ perhaps the Curl_easy is changed between the times the connection is
107
+ used. */
108
+ struct FTP {
109
+ char *path; /* points to the urlpieces struct field */
110
+ char *pathalloc; /* if non-NULL a pointer to an allocated path */
111
+
112
+ /* transfer a file/body or not, done as a typedefed enum just to make
113
+ debuggers display the full symbol and not just the numerical value */
114
+ curl_pp_transfer transfer;
115
+ curl_off_t downloadsize;
116
+ };
117
+
118
+
119
+ /* ftp_conn is used for struct connection-oriented data in the connectdata
120
+ struct */
121
+ struct ftp_conn {
122
+ struct pingpong pp;
123
+ char *account;
124
+ char *alternative_to_user;
125
+ char *entrypath; /* the PWD reply when we logged on */
126
+ char *file; /* url-decoded filename (or path) */
127
+ char **dirs; /* realloc()ed array for path components */
128
+ char *newhost;
129
+ char *prevpath; /* url-decoded conn->path from the previous transfer */
130
+ char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
131
+ and others (A/I or zero) */
132
+ curl_off_t retr_size_saved; /* Size of retrieved file saved */
133
+ char *server_os; /* The target server operating system. */
134
+ curl_off_t known_filesize; /* file size is different from -1, if wildcard
135
+ LIST parsing was done and wc_statemach set
136
+ it */
137
+ int dirdepth; /* number of entries used in the 'dirs' array */
138
+ int cwdcount; /* number of CWD commands issued */
139
+ int count1; /* general purpose counter for the state machine */
140
+ int count2; /* general purpose counter for the state machine */
141
+ int count3; /* general purpose counter for the state machine */
142
+ /* newhost is the (allocated) IP addr or hostname to connect the data
143
+ connection to */
144
+ unsigned short newport;
145
+ ftpstate state; /* always use ftp.c:state() to change state! */
146
+ ftpstate state_saved; /* transfer type saved to be reloaded after data
147
+ connection is established */
148
+ unsigned char use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or
149
+ IMAP or POP3 or others! (type: curl_usessl)*/
150
+ unsigned char ccc; /* ccc level for this connection */
151
+ BIT(ftp_trying_alternative);
152
+ BIT(dont_check); /* Set to TRUE to prevent the final (post-transfer)
153
+ file size and 226/250 status check. It should still
154
+ read the line, just ignore the result. */
155
+ BIT(ctl_valid); /* Tells Curl_ftp_quit() whether or not to do anything. If
156
+ the connection has timed out or been closed, this
157
+ should be FALSE when it gets to Curl_ftp_quit() */
158
+ BIT(cwddone); /* if it has been determined that the proper CWD combo
159
+ already has been done */
160
+ BIT(cwdfail); /* set TRUE if a CWD command fails, as then we must prevent
161
+ caching the current directory */
162
+ BIT(wait_data_conn); /* this is set TRUE if data connection is waited */
163
+ };
164
+
165
+ #define DEFAULT_ACCEPT_TIMEOUT 60000 /* milliseconds == one minute */
166
+
167
+ #endif /* HEADER_CURL_FTP_H */
local-test-curl-full-01/afc-curl/lib/getenv.c ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***************************************************************************
2
+ * _ _ ____ _
3
+ * Project ___| | | | _ \| |
4
+ * / __| | | | |_) | |
5
+ * | (__| |_| | _ <| |___
6
+ * \___|\___/|_| \_\_____|
7
+ *
8
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
+ *
10
+ * This software is licensed as described in the file COPYING, which
11
+ * you should have received as part of this distribution. The terms
12
+ * are also available at https://curl.se/docs/copyright.html.
13
+ *
14
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
+ * copies of the Software, and permit persons to whom the Software is
16
+ * furnished to do so, under the terms of the COPYING file.
17
+ *
18
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
+ * KIND, either express or implied.
20
+ *
21
+ * SPDX-License-Identifier: curl
22
+ *
23
+ ***************************************************************************/
24
+
25
+ #include "curl_setup.h"
26
+
27
+ #include <curl/curl.h>
28
+ #include "curl_memory.h"
29
+
30
+ #include "memdebug.h"
31
+
32
+ static char *GetEnv(const char *variable)
33
+ {
34
+ #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_UWP) || \
35
+ defined(__ORBIS__) || defined(__PROSPERO__) /* PlayStation 4 and 5 */
36
+ (void)variable;
37
+ return NULL;
38
+ #elif defined(_WIN32)
39
+ /* This uses Windows API instead of C runtime getenv() to get the environment
40
+ variable since some changes are not always visible to the latter. #4774 */
41
+ char *buf = NULL;
42
+ char *tmp;
43
+ DWORD bufsize;
44
+ DWORD rc = 1;
45
+ const DWORD max = 32768; /* max env var size from MSCRT source */
46
+
47
+ for(;;) {
48
+ tmp = realloc(buf, rc);
49
+ if(!tmp) {
50
+ free(buf);
51
+ return NULL;
52
+ }
53
+
54
+ buf = tmp;
55
+ bufsize = rc;
56
+
57
+ /* it is possible for rc to be 0 if the variable was found but empty.
58
+ Since getenv does not make that distinction we ignore it as well. */
59
+ rc = GetEnvironmentVariableA(variable, buf, bufsize);
60
+ if(!rc || rc == bufsize || rc > max) {
61
+ free(buf);
62
+ return NULL;
63
+ }
64
+
65
+ /* if rc < bufsize then rc is bytes written not including null */
66
+ if(rc < bufsize)
67
+ return buf;
68
+
69
+ /* else rc is bytes needed, try again */
70
+ }
71
+ #else
72
+ char *env = getenv(variable);
73
+ return (env && env[0]) ? strdup(env) : NULL;
74
+ #endif
75
+ }
76
+
77
+ char *curl_getenv(const char *v)
78
+ {
79
+ return GetEnv(v);
80
+ }
local-test-curl-full-01/afc-curl/lib/getinfo.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef HEADER_CURL_GETINFO_H
2
+ #define HEADER_CURL_GETINFO_H
3
+ /***************************************************************************
4
+ * _ _ ____ _
5
+ * Project ___| | | | _ \| |
6
+ * / __| | | | |_) | |
7
+ * | (__| |_| | _ <| |___
8
+ * \___|\___/|_| \_\_____|
9
+ *
10
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
+ *
12
+ * This software is licensed as described in the file COPYING, which
13
+ * you should have received as part of this distribution. The terms
14
+ * are also available at https://curl.se/docs/copyright.html.
15
+ *
16
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
+ * copies of the Software, and permit persons to whom the Software is
18
+ * furnished to do so, under the terms of the COPYING file.
19
+ *
20
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
+ * KIND, either express or implied.
22
+ *
23
+ * SPDX-License-Identifier: curl
24
+ *
25
+ ***************************************************************************/
26
+ CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...);
27
+ CURLcode Curl_initinfo(struct Curl_easy *data);
28
+
29
+ #endif /* HEADER_CURL_GETINFO_H */