Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- local-test-curl-delta-01/afc-curl/CMake/Platforms/WindowsCache.cmake +194 -0
- local-test-curl-delta-01/afc-curl/docs/examples/.checksrc +3 -0
- local-test-curl-delta-01/afc-curl/docs/examples/.gitignore +120 -0
- local-test-curl-delta-01/afc-curl/docs/examples/10-at-a-time.c +153 -0
- local-test-curl-delta-01/afc-curl/docs/examples/CMakeLists.txt +43 -0
- local-test-curl-delta-01/afc-curl/docs/examples/Makefile.am +68 -0
- local-test-curl-delta-01/afc-curl/docs/examples/Makefile.example +55 -0
- local-test-curl-delta-01/afc-curl/docs/examples/Makefile.inc +159 -0
- local-test-curl-delta-01/afc-curl/docs/examples/Makefile.mk +52 -0
- local-test-curl-delta-01/afc-curl/docs/examples/README.md +41 -0
- local-test-curl-delta-01/afc-curl/docs/examples/adddocsref.pl +58 -0
- local-test-curl-delta-01/afc-curl/docs/examples/address-scope.c +62 -0
- local-test-curl-delta-01/afc-curl/docs/examples/altsvc.c +58 -0
- local-test-curl-delta-01/afc-curl/docs/examples/anyauthput.c +155 -0
- local-test-curl-delta-01/afc-curl/docs/examples/cacertinmem.c +182 -0
- local-test-curl-delta-01/afc-curl/docs/examples/certinfo.c +87 -0
- local-test-curl-delta-01/afc-curl/docs/examples/chkspeed.c +224 -0
- local-test-curl-delta-01/afc-curl/docs/examples/connect-to.c +70 -0
- local-test-curl-delta-01/afc-curl/docs/examples/cookie_interface.c +138 -0
- local-test-curl-delta-01/afc-curl/docs/examples/crawler.c +237 -0
- local-test-curl-delta-01/afc-curl/docs/examples/debug.c +155 -0
- local-test-curl-delta-01/afc-curl/docs/examples/default-scheme.c +57 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ephiperfifo.c +547 -0
- local-test-curl-delta-01/afc-curl/docs/examples/evhiperfifo.c +450 -0
- local-test-curl-delta-01/afc-curl/docs/examples/externalsocket.c +178 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ftp-wildcard.c +152 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ftpget.c +94 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ftpgetresp.c +79 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ftpsget.c +101 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ftpuploadresume.c +165 -0
- local-test-curl-delta-01/afc-curl/docs/examples/getinfo.c +54 -0
- local-test-curl-delta-01/afc-curl/docs/examples/getinmemory.c +118 -0
- local-test-curl-delta-01/afc-curl/docs/examples/getredirect.c +72 -0
- local-test-curl-delta-01/afc-curl/docs/examples/getreferrer.c +59 -0
- local-test-curl-delta-01/afc-curl/docs/examples/ghiper.c +438 -0
- local-test-curl-delta-01/afc-curl/docs/examples/href_extractor.c +88 -0
- local-test-curl-delta-01/afc-curl/docs/examples/hsts-preload.c +118 -0
- local-test-curl-delta-01/afc-curl/docs/examples/htmltidy.c +130 -0
- local-test-curl-delta-01/afc-curl/docs/examples/htmltitle.cpp +296 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http-options.c +59 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http-post.c +61 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http2-download.c +230 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http2-pushinmemory.c +186 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http2-upload.c +326 -0
- local-test-curl-delta-01/afc-curl/docs/examples/http3-present.c +49 -0
- local-test-curl-delta-01/afc-curl/docs/examples/httpcustomheader.c +72 -0
- local-test-curl-delta-01/afc-curl/docs/examples/httpput-postfields.c +105 -0
- local-test-curl-delta-01/afc-curl/docs/examples/httpput.c +123 -0
- local-test-curl-delta-01/afc-curl/docs/examples/https.c +83 -0
- local-test-curl-delta-01/afc-curl/docs/examples/imap-append.c +130 -0
local-test-curl-delta-01/afc-curl/CMake/Platforms/WindowsCache.cmake
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
if(NOT WIN32)
|
| 25 |
+
message(FATAL_ERROR "This file should be included on Windows platform only")
|
| 26 |
+
endif()
|
| 27 |
+
|
| 28 |
+
set(HAVE_LOCALE_H 1)
|
| 29 |
+
|
| 30 |
+
if(MINGW)
|
| 31 |
+
set(HAVE_SNPRINTF 1)
|
| 32 |
+
set(HAVE_UNISTD_H 1)
|
| 33 |
+
set(HAVE_LIBGEN_H 1)
|
| 34 |
+
set(HAVE_STDDEF_H 1) # detected by CMake internally in check_type_size()
|
| 35 |
+
set(HAVE_STDBOOL_H 1)
|
| 36 |
+
set(HAVE_BOOL_T "${HAVE_STDBOOL_H}")
|
| 37 |
+
set(HAVE_STRTOLL 1)
|
| 38 |
+
set(HAVE_BASENAME 1)
|
| 39 |
+
set(HAVE_STRCASECMP 1)
|
| 40 |
+
set(HAVE_FTRUNCATE 1)
|
| 41 |
+
set(HAVE_SYS_PARAM_H 1)
|
| 42 |
+
set(HAVE_SYS_TIME_H 1)
|
| 43 |
+
set(HAVE_GETTIMEOFDAY 1)
|
| 44 |
+
set(HAVE_STRINGS_H 1) # wrapper to string.h
|
| 45 |
+
set(HAVE_UTIME_H 1) # wrapper to sys/utime.h
|
| 46 |
+
set(HAVE_DIRENT_H 1)
|
| 47 |
+
set(HAVE_OPENDIR 1)
|
| 48 |
+
else()
|
| 49 |
+
set(HAVE_LIBGEN_H 0)
|
| 50 |
+
set(HAVE_STRCASECMP 0)
|
| 51 |
+
set(HAVE_FTRUNCATE 0)
|
| 52 |
+
set(HAVE_SYS_PARAM_H 0)
|
| 53 |
+
set(HAVE_SYS_TIME_H 0)
|
| 54 |
+
set(HAVE_GETTIMEOFDAY 0)
|
| 55 |
+
set(HAVE_STRINGS_H 0)
|
| 56 |
+
set(HAVE_UTIME_H 0)
|
| 57 |
+
set(HAVE_DIRENT_H 0)
|
| 58 |
+
set(HAVE_OPENDIR 0)
|
| 59 |
+
if(MSVC)
|
| 60 |
+
set(HAVE_UNISTD_H 0)
|
| 61 |
+
set(HAVE_LOCALE_H 1)
|
| 62 |
+
set(HAVE_STDDEF_H 1) # detected by CMake internally in check_type_size()
|
| 63 |
+
set(HAVE_STDATOMIC_H 0)
|
| 64 |
+
if(NOT MSVC_VERSION LESS 1800)
|
| 65 |
+
set(HAVE_STDBOOL_H 1)
|
| 66 |
+
set(HAVE_STRTOLL 1)
|
| 67 |
+
else()
|
| 68 |
+
set(HAVE_STDBOOL_H 0)
|
| 69 |
+
set(HAVE_STRTOLL 0)
|
| 70 |
+
endif()
|
| 71 |
+
set(HAVE_BOOL_T "${HAVE_STDBOOL_H}")
|
| 72 |
+
if(NOT MSVC_VERSION LESS 1900)
|
| 73 |
+
set(HAVE_SNPRINTF 1)
|
| 74 |
+
else()
|
| 75 |
+
set(HAVE_SNPRINTF 0)
|
| 76 |
+
endif()
|
| 77 |
+
set(HAVE_BASENAME 0)
|
| 78 |
+
set(HAVE_STRTOK_R 0)
|
| 79 |
+
set(HAVE_FILE_OFFSET_BITS 0)
|
| 80 |
+
set(HAVE_ATOMIC 0)
|
| 81 |
+
endif()
|
| 82 |
+
endif()
|
| 83 |
+
|
| 84 |
+
# Available in Windows XP and newer
|
| 85 |
+
set(HAVE_GETADDRINFO 1)
|
| 86 |
+
set(HAVE_FREEADDRINFO 1)
|
| 87 |
+
|
| 88 |
+
set(HAVE_FCHMOD 0)
|
| 89 |
+
set(HAVE_SOCKETPAIR 0)
|
| 90 |
+
set(HAVE_SENDMSG 0)
|
| 91 |
+
set(HAVE_SENDMMSG 0)
|
| 92 |
+
set(HAVE_ALARM 0)
|
| 93 |
+
set(HAVE_FCNTL 0)
|
| 94 |
+
set(HAVE_GETPPID 0)
|
| 95 |
+
set(HAVE_UTIMES 0)
|
| 96 |
+
set(HAVE_GETPWUID_R 0)
|
| 97 |
+
set(HAVE_STRERROR_R 0)
|
| 98 |
+
set(HAVE_SIGINTERRUPT 0)
|
| 99 |
+
set(HAVE_PIPE 0)
|
| 100 |
+
set(HAVE_EVENTFD 0)
|
| 101 |
+
set(HAVE_IF_NAMETOINDEX 0)
|
| 102 |
+
set(HAVE_GETRLIMIT 0)
|
| 103 |
+
set(HAVE_SETRLIMIT 0)
|
| 104 |
+
set(HAVE_FSETXATTR 0)
|
| 105 |
+
set(HAVE_SETLOCALE 1)
|
| 106 |
+
set(HAVE_SETMODE 1)
|
| 107 |
+
set(HAVE__SETMODE 1)
|
| 108 |
+
set(HAVE_GETPEERNAME 1)
|
| 109 |
+
set(HAVE_GETSOCKNAME 1)
|
| 110 |
+
set(HAVE_GETHOSTNAME 1)
|
| 111 |
+
|
| 112 |
+
set(HAVE_RECV 1)
|
| 113 |
+
set(HAVE_SEND 1)
|
| 114 |
+
set(HAVE_STROPTS_H 0)
|
| 115 |
+
set(HAVE_SYS_XATTR_H 0)
|
| 116 |
+
set(HAVE_ARC4RANDOM 0)
|
| 117 |
+
set(HAVE_FNMATCH 0)
|
| 118 |
+
set(HAVE_SCHED_YIELD 0)
|
| 119 |
+
set(HAVE_ARPA_INET_H 0)
|
| 120 |
+
set(HAVE_FCNTL_H 1)
|
| 121 |
+
set(HAVE_IFADDRS_H 0)
|
| 122 |
+
set(HAVE_IO_H 1)
|
| 123 |
+
set(HAVE_NETDB_H 0)
|
| 124 |
+
set(HAVE_NETINET_IN_H 0)
|
| 125 |
+
set(HAVE_NETINET_IN6_H 0)
|
| 126 |
+
set(HAVE_NETINET_TCP_H 0)
|
| 127 |
+
set(HAVE_NETINET_UDP_H 0)
|
| 128 |
+
set(HAVE_NET_IF_H 0)
|
| 129 |
+
set(HAVE_IOCTL_SIOCGIFADDR 0)
|
| 130 |
+
set(HAVE_POLL_H 0)
|
| 131 |
+
set(HAVE_POLL 0)
|
| 132 |
+
set(HAVE_PWD_H 0)
|
| 133 |
+
set(HAVE_SYS_EVENTFD_H 0)
|
| 134 |
+
set(HAVE_SYS_FILIO_H 0)
|
| 135 |
+
set(HAVE_SYS_WAIT_H 0)
|
| 136 |
+
set(HAVE_SYS_IOCTL_H 0)
|
| 137 |
+
set(HAVE_SYS_POLL_H 0)
|
| 138 |
+
set(HAVE_SYS_RESOURCE_H 0)
|
| 139 |
+
set(HAVE_SYS_SELECT_H 0)
|
| 140 |
+
set(HAVE_SYS_SOCKET_H 0)
|
| 141 |
+
set(HAVE_SYS_SOCKIO_H 0)
|
| 142 |
+
set(HAVE_SYS_STAT_H 1)
|
| 143 |
+
set(HAVE_SYS_TYPES_H 1)
|
| 144 |
+
set(HAVE_SYS_UN_H 0)
|
| 145 |
+
set(HAVE_SYS_UTIME_H 1)
|
| 146 |
+
set(HAVE_TERMIOS_H 0)
|
| 147 |
+
set(HAVE_TERMIO_H 0)
|
| 148 |
+
set(HAVE_LINUX_TCP_H 0)
|
| 149 |
+
|
| 150 |
+
set(HAVE_FSEEKO 0) # mingw-w64 2.0.0 and newer has it
|
| 151 |
+
set(HAVE_SOCKET 1)
|
| 152 |
+
set(HAVE_SELECT 1)
|
| 153 |
+
set(HAVE_STRDUP 1)
|
| 154 |
+
set(HAVE_STRICMP 1)
|
| 155 |
+
set(HAVE_STRCMPI 1)
|
| 156 |
+
set(HAVE_MEMRCHR 0)
|
| 157 |
+
set(HAVE_CLOSESOCKET 1)
|
| 158 |
+
set(HAVE_SIGSETJMP 0)
|
| 159 |
+
set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1)
|
| 160 |
+
set(HAVE_GETPASS_R 0)
|
| 161 |
+
set(HAVE_GETPWUID 0)
|
| 162 |
+
set(HAVE_GETEUID 0)
|
| 163 |
+
set(HAVE_UTIME 1)
|
| 164 |
+
set(HAVE_GMTIME_R 0)
|
| 165 |
+
set(HAVE_GETHOSTBYNAME_R 0)
|
| 166 |
+
set(HAVE_SIGNAL 1)
|
| 167 |
+
set(HAVE_SIGACTION 0)
|
| 168 |
+
set(HAVE_GLIBC_STRERROR_R 0)
|
| 169 |
+
set(HAVE_GETIFADDRS 0)
|
| 170 |
+
set(HAVE_FCNTL_O_NONBLOCK 0)
|
| 171 |
+
set(HAVE_IOCTLSOCKET 1)
|
| 172 |
+
set(HAVE_IOCTLSOCKET_CAMEL 0)
|
| 173 |
+
set(HAVE_IOCTLSOCKET_CAMEL_FIONBIO 0)
|
| 174 |
+
set(HAVE_IOCTLSOCKET_FIONBIO 1)
|
| 175 |
+
set(HAVE_IOCTL_FIONBIO 0)
|
| 176 |
+
set(HAVE_SETSOCKOPT_SO_NONBLOCK 0)
|
| 177 |
+
set(HAVE_POSIX_STRERROR_R 0)
|
| 178 |
+
set(HAVE_MSG_NOSIGNAL 0)
|
| 179 |
+
set(HAVE_STRUCT_TIMEVAL 1)
|
| 180 |
+
set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
|
| 181 |
+
|
| 182 |
+
set(HAVE_GETHOSTBYNAME_R_3 0)
|
| 183 |
+
set(HAVE_GETHOSTBYNAME_R_3_REENTRANT 0)
|
| 184 |
+
set(HAVE_GETHOSTBYNAME_R_5 0)
|
| 185 |
+
set(HAVE_GETHOSTBYNAME_R_5_REENTRANT 0)
|
| 186 |
+
set(HAVE_GETHOSTBYNAME_R_6 0)
|
| 187 |
+
set(HAVE_GETHOSTBYNAME_R_6_REENTRANT 0)
|
| 188 |
+
|
| 189 |
+
set(HAVE_O_NONBLOCK 0)
|
| 190 |
+
set(HAVE_IN_ADDR_T 0)
|
| 191 |
+
set(STDC_HEADERS 1)
|
| 192 |
+
|
| 193 |
+
set(HAVE_SIZEOF_SUSECONDS_T 0)
|
| 194 |
+
set(HAVE_SIZEOF_SA_FAMILY_T 0)
|
local-test-curl-delta-01/afc-curl/docs/examples/.checksrc
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
disable TYPEDEFSTRUCT
|
| 2 |
+
disable SNPRINTF
|
| 3 |
+
disable BANNEDFUNC
|
local-test-curl-delta-01/afc-curl/docs/examples/.gitignore
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
|
| 2 |
+
#
|
| 3 |
+
# SPDX-License-Identifier: curl
|
| 4 |
+
|
| 5 |
+
10-at-a-time
|
| 6 |
+
address-scope
|
| 7 |
+
altsvc
|
| 8 |
+
anyauthput
|
| 9 |
+
certinfo
|
| 10 |
+
chkspeed
|
| 11 |
+
connect-to
|
| 12 |
+
cookie_interface
|
| 13 |
+
debug
|
| 14 |
+
default-scheme
|
| 15 |
+
externalsocket
|
| 16 |
+
fileupload
|
| 17 |
+
fopen
|
| 18 |
+
ftp-wildcard
|
| 19 |
+
ftpget
|
| 20 |
+
ftpgetinfo
|
| 21 |
+
ftpgetresp
|
| 22 |
+
ftpsget
|
| 23 |
+
ftpupload
|
| 24 |
+
ftpuploadfrommem
|
| 25 |
+
ftpuploadresume
|
| 26 |
+
getinfo
|
| 27 |
+
getinmemory
|
| 28 |
+
getredirect
|
| 29 |
+
getreferrer
|
| 30 |
+
headerapi
|
| 31 |
+
hsts-preload
|
| 32 |
+
http-options
|
| 33 |
+
http-post
|
| 34 |
+
http2-download
|
| 35 |
+
http2-pushinmemory
|
| 36 |
+
http2-serverpush
|
| 37 |
+
http2-upload
|
| 38 |
+
http3
|
| 39 |
+
http3-present
|
| 40 |
+
httpcustomheader
|
| 41 |
+
httpput
|
| 42 |
+
httpput-postfields
|
| 43 |
+
https
|
| 44 |
+
imap-append
|
| 45 |
+
imap-authzid
|
| 46 |
+
imap-copy
|
| 47 |
+
imap-create
|
| 48 |
+
imap-delete
|
| 49 |
+
imap-examine
|
| 50 |
+
imap-fetch
|
| 51 |
+
imap-list
|
| 52 |
+
imap-lsub
|
| 53 |
+
imap-multi
|
| 54 |
+
imap-noop
|
| 55 |
+
imap-search
|
| 56 |
+
imap-ssl
|
| 57 |
+
imap-store
|
| 58 |
+
imap-tls
|
| 59 |
+
interface
|
| 60 |
+
ipv6
|
| 61 |
+
keepalive
|
| 62 |
+
localport
|
| 63 |
+
maxconnects
|
| 64 |
+
multi-app
|
| 65 |
+
multi-debugcallback
|
| 66 |
+
multi-double
|
| 67 |
+
multi-formadd
|
| 68 |
+
multi-legacy
|
| 69 |
+
multi-poll
|
| 70 |
+
multi-post
|
| 71 |
+
multi-single
|
| 72 |
+
netrc
|
| 73 |
+
new-gitignore
|
| 74 |
+
parseurl
|
| 75 |
+
persistent
|
| 76 |
+
pop3-authzid
|
| 77 |
+
pop3-dele
|
| 78 |
+
pop3-list
|
| 79 |
+
pop3-multi
|
| 80 |
+
pop3-noop
|
| 81 |
+
pop3-retr
|
| 82 |
+
pop3-ssl
|
| 83 |
+
pop3-stat
|
| 84 |
+
pop3-tls
|
| 85 |
+
pop3-top
|
| 86 |
+
pop3-uidl
|
| 87 |
+
post-callback
|
| 88 |
+
postinmemory
|
| 89 |
+
postit2
|
| 90 |
+
postit2-formadd
|
| 91 |
+
progressfunc
|
| 92 |
+
protofeats
|
| 93 |
+
range
|
| 94 |
+
resolve
|
| 95 |
+
rtsp
|
| 96 |
+
rtsp-options
|
| 97 |
+
sendrecv
|
| 98 |
+
sepheaders
|
| 99 |
+
sftpget
|
| 100 |
+
sftpuploadresume
|
| 101 |
+
shared-connection-cache
|
| 102 |
+
simple
|
| 103 |
+
simplepost
|
| 104 |
+
simplessl
|
| 105 |
+
smtp-authzid
|
| 106 |
+
smtp-expn
|
| 107 |
+
smtp-mail
|
| 108 |
+
smtp-mime
|
| 109 |
+
smtp-multi
|
| 110 |
+
smtp-ssl
|
| 111 |
+
smtp-tls
|
| 112 |
+
smtp-vrfy
|
| 113 |
+
sslbackend
|
| 114 |
+
unixsocket
|
| 115 |
+
url2file
|
| 116 |
+
urlapi
|
| 117 |
+
usercertinmem
|
| 118 |
+
websocket
|
| 119 |
+
websocket-cb
|
| 120 |
+
xmlstream
|
local-test-curl-delta-01/afc-curl/docs/examples/10-at-a-time.c
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Download many files in parallel, in the same thread.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#include <stdlib.h>
|
| 30 |
+
#include <string.h>
|
| 31 |
+
#include <curl/curl.h>
|
| 32 |
+
|
| 33 |
+
static const char *urls[] = {
|
| 34 |
+
"https://www.microsoft.com",
|
| 35 |
+
"https://opensource.org",
|
| 36 |
+
"https://www.google.com",
|
| 37 |
+
"https://www.yahoo.com",
|
| 38 |
+
"https://www.ibm.com",
|
| 39 |
+
"https://www.mysql.com",
|
| 40 |
+
"https://www.oracle.com",
|
| 41 |
+
"https://www.ripe.net",
|
| 42 |
+
"https://www.iana.org",
|
| 43 |
+
"https://www.amazon.com",
|
| 44 |
+
"https://www.netcraft.com",
|
| 45 |
+
"https://www.heise.de",
|
| 46 |
+
"https://www.chip.de",
|
| 47 |
+
"https://www.ca.com",
|
| 48 |
+
"https://www.cnet.com",
|
| 49 |
+
"https://www.mozilla.org",
|
| 50 |
+
"https://www.cnn.com",
|
| 51 |
+
"https://www.wikipedia.org",
|
| 52 |
+
"https://www.dell.com",
|
| 53 |
+
"https://www.hp.com",
|
| 54 |
+
"https://www.cert.org",
|
| 55 |
+
"https://www.mit.edu",
|
| 56 |
+
"https://www.nist.gov",
|
| 57 |
+
"https://www.ebay.com",
|
| 58 |
+
"https://www.playstation.com",
|
| 59 |
+
"https://www.uefa.com",
|
| 60 |
+
"https://www.ieee.org",
|
| 61 |
+
"https://www.apple.com",
|
| 62 |
+
"https://www.symantec.com",
|
| 63 |
+
"https://www.zdnet.com",
|
| 64 |
+
"https://www.fujitsu.com/global/",
|
| 65 |
+
"https://www.supermicro.com",
|
| 66 |
+
"https://www.hotmail.com",
|
| 67 |
+
"https://www.ietf.org",
|
| 68 |
+
"https://www.bbc.co.uk",
|
| 69 |
+
"https://news.google.com",
|
| 70 |
+
"https://www.foxnews.com",
|
| 71 |
+
"https://www.msn.com",
|
| 72 |
+
"https://www.wired.com",
|
| 73 |
+
"https://www.sky.com",
|
| 74 |
+
"https://www.usatoday.com",
|
| 75 |
+
"https://www.cbs.com",
|
| 76 |
+
"https://www.nbc.com/",
|
| 77 |
+
"https://slashdot.org",
|
| 78 |
+
"https://www.informationweek.com",
|
| 79 |
+
"https://apache.org",
|
| 80 |
+
"https://www.un.org",
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
#define MAX_PARALLEL 10 /* number of simultaneous transfers */
|
| 84 |
+
#define NUM_URLS sizeof(urls)/sizeof(char *)
|
| 85 |
+
|
| 86 |
+
static size_t write_cb(char *data, size_t n, size_t l, void *userp)
|
| 87 |
+
{
|
| 88 |
+
/* take care of the data here, ignored in this example */
|
| 89 |
+
(void)data;
|
| 90 |
+
(void)userp;
|
| 91 |
+
return n*l;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
static void add_transfer(CURLM *cm, unsigned int i, int *left)
|
| 95 |
+
{
|
| 96 |
+
CURL *eh = curl_easy_init();
|
| 97 |
+
curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, write_cb);
|
| 98 |
+
curl_easy_setopt(eh, CURLOPT_URL, urls[i]);
|
| 99 |
+
curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]);
|
| 100 |
+
curl_multi_add_handle(cm, eh);
|
| 101 |
+
(*left)++;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
int main(void)
|
| 105 |
+
{
|
| 106 |
+
CURLM *cm;
|
| 107 |
+
CURLMsg *msg;
|
| 108 |
+
unsigned int transfers = 0;
|
| 109 |
+
int msgs_left = -1;
|
| 110 |
+
int left = 0;
|
| 111 |
+
|
| 112 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 113 |
+
cm = curl_multi_init();
|
| 114 |
+
|
| 115 |
+
/* Limit the amount of simultaneous connections curl should allow: */
|
| 116 |
+
curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
|
| 117 |
+
|
| 118 |
+
for(transfers = 0; transfers < MAX_PARALLEL && transfers < NUM_URLS;
|
| 119 |
+
transfers++)
|
| 120 |
+
add_transfer(cm, transfers, &left);
|
| 121 |
+
|
| 122 |
+
do {
|
| 123 |
+
int still_alive = 1;
|
| 124 |
+
curl_multi_perform(cm, &still_alive);
|
| 125 |
+
|
| 126 |
+
/* !checksrc! disable EQUALSNULL 1 */
|
| 127 |
+
while((msg = curl_multi_info_read(cm, &msgs_left)) != NULL) {
|
| 128 |
+
if(msg->msg == CURLMSG_DONE) {
|
| 129 |
+
char *url;
|
| 130 |
+
CURL *e = msg->easy_handle;
|
| 131 |
+
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);
|
| 132 |
+
fprintf(stderr, "R: %d - %s <%s>\n",
|
| 133 |
+
msg->data.result, curl_easy_strerror(msg->data.result), url);
|
| 134 |
+
curl_multi_remove_handle(cm, e);
|
| 135 |
+
curl_easy_cleanup(e);
|
| 136 |
+
left--;
|
| 137 |
+
}
|
| 138 |
+
else {
|
| 139 |
+
fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg);
|
| 140 |
+
}
|
| 141 |
+
if(transfers < NUM_URLS)
|
| 142 |
+
add_transfer(cm, transfers++, &left);
|
| 143 |
+
}
|
| 144 |
+
if(left)
|
| 145 |
+
curl_multi_wait(cm, NULL, 0, 1000, NULL);
|
| 146 |
+
|
| 147 |
+
} while(left);
|
| 148 |
+
|
| 149 |
+
curl_multi_cleanup(cm);
|
| 150 |
+
curl_global_cleanup();
|
| 151 |
+
|
| 152 |
+
return EXIT_SUCCESS;
|
| 153 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/CMakeLists.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
add_custom_target(curl-examples)
|
| 26 |
+
|
| 27 |
+
# Get 'check_PROGRAMS' variable
|
| 28 |
+
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
| 29 |
+
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
| 30 |
+
|
| 31 |
+
foreach(_target IN LISTS check_PROGRAMS)
|
| 32 |
+
set(_target_name "curl-example-${_target}")
|
| 33 |
+
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c")
|
| 34 |
+
add_dependencies(curl-examples ${_target_name})
|
| 35 |
+
target_link_libraries(${_target_name} ${LIB_SELECTED} ${CURL_LIBS})
|
| 36 |
+
target_compile_definitions(${_target_name} PRIVATE "CURL_NO_OLDIES")
|
| 37 |
+
if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
|
| 38 |
+
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
|
| 39 |
+
endif()
|
| 40 |
+
set_target_properties(${_target_name} PROPERTIES
|
| 41 |
+
OUTPUT_NAME "${_target}" UNITY_BUILD OFF
|
| 42 |
+
PROJECT_LABEL "Example ${_target}")
|
| 43 |
+
endforeach()
|
local-test-curl-delta-01/afc-curl/docs/examples/Makefile.am
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 |
+
AUTOMAKE_OPTIONS = foreign nostdinc
|
| 26 |
+
|
| 27 |
+
EXTRA_DIST = README.md Makefile.example Makefile.mk CMakeLists.txt \
|
| 28 |
+
$(COMPLICATED_EXAMPLES) .checksrc
|
| 29 |
+
|
| 30 |
+
# Specify our include paths here, and do it relative to $(top_srcdir) and
|
| 31 |
+
# $(top_builddir), to ensure that these paths which belong to the library
|
| 32 |
+
# being currently built and tested are searched before the library which
|
| 33 |
+
# might possibly already be installed in the system.
|
| 34 |
+
#
|
| 35 |
+
# $(top_srcdir)/include is for libcurl's external include files
|
| 36 |
+
|
| 37 |
+
AM_CPPFLAGS = -I$(top_srcdir)/include
|
| 38 |
+
|
| 39 |
+
LIBDIR = $(top_builddir)/lib
|
| 40 |
+
|
| 41 |
+
# Avoid libcurl obsolete stuff
|
| 42 |
+
AM_CPPFLAGS += -DCURL_NO_OLDIES
|
| 43 |
+
|
| 44 |
+
if USE_CPPFLAG_CURL_STATICLIB
|
| 45 |
+
AM_CPPFLAGS += -DCURL_STATICLIB
|
| 46 |
+
endif
|
| 47 |
+
|
| 48 |
+
# Prevent LIBS from being used for all link targets
|
| 49 |
+
LIBS = $(BLANK_AT_MAKETIME)
|
| 50 |
+
|
| 51 |
+
# Dependencies
|
| 52 |
+
LDADD = $(LIBDIR)/libcurl.la @LIBCURL_PC_LIBS_PRIVATE@
|
| 53 |
+
|
| 54 |
+
# This might hold -Werror
|
| 55 |
+
CFLAGS += @CURL_CFLAG_EXTRAS@
|
| 56 |
+
|
| 57 |
+
# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines
|
| 58 |
+
include Makefile.inc
|
| 59 |
+
|
| 60 |
+
all: $(check_PROGRAMS)
|
| 61 |
+
|
| 62 |
+
CHECKSRC = $(CS_$(V))
|
| 63 |
+
CS_0 = @echo " RUN " $@;
|
| 64 |
+
CS_1 =
|
| 65 |
+
CS_ = $(CS_0)
|
| 66 |
+
|
| 67 |
+
checksrc:
|
| 68 |
+
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) $(srcdir)/*.c)
|
local-test-curl-delta-01/afc-curl/docs/examples/Makefile.example
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# What to call the final executable
|
| 26 |
+
TARGET = example
|
| 27 |
+
|
| 28 |
+
# Which object files that the executable consists of
|
| 29 |
+
OBJS= ftpget.o
|
| 30 |
+
|
| 31 |
+
# What compiler to use
|
| 32 |
+
CC = gcc
|
| 33 |
+
|
| 34 |
+
# Compiler flags, -g for debug, -c to make an object file
|
| 35 |
+
CFLAGS = -c -g
|
| 36 |
+
|
| 37 |
+
# This should point to a directory that holds libcurl, if it is not
|
| 38 |
+
# in the system's standard lib dir
|
| 39 |
+
# We also set a -L to include the directory where we have the OpenSSL
|
| 40 |
+
# libraries
|
| 41 |
+
LDFLAGS = -L/home/dast/lib -L/usr/local/ssl/lib
|
| 42 |
+
|
| 43 |
+
# We need -lcurl for the curl stuff
|
| 44 |
+
# We need -lsocket and -lnsl when on Solaris
|
| 45 |
+
# We need -lssl and -lcrypto when using libcurl with SSL support
|
| 46 |
+
# We need -lpthread for the pthread example
|
| 47 |
+
LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto
|
| 48 |
+
|
| 49 |
+
# Link the target with all objects and libraries
|
| 50 |
+
$(TARGET) : $(OBJS)
|
| 51 |
+
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LIBS)
|
| 52 |
+
|
| 53 |
+
# Compile the source files into object files
|
| 54 |
+
ftpget.o : ftpget.c
|
| 55 |
+
$(CC) $(CFLAGS) $<
|
local-test-curl-delta-01/afc-curl/docs/examples/Makefile.inc
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# These are all libcurl example programs to be test compiled
|
| 26 |
+
check_PROGRAMS = \
|
| 27 |
+
10-at-a-time \
|
| 28 |
+
address-scope \
|
| 29 |
+
altsvc \
|
| 30 |
+
anyauthput \
|
| 31 |
+
certinfo \
|
| 32 |
+
chkspeed \
|
| 33 |
+
connect-to \
|
| 34 |
+
cookie_interface \
|
| 35 |
+
debug \
|
| 36 |
+
default-scheme \
|
| 37 |
+
externalsocket \
|
| 38 |
+
fileupload \
|
| 39 |
+
ftp-wildcard \
|
| 40 |
+
ftpget \
|
| 41 |
+
ftpgetinfo \
|
| 42 |
+
ftpgetresp \
|
| 43 |
+
ftpsget \
|
| 44 |
+
ftpupload \
|
| 45 |
+
ftpuploadfrommem \
|
| 46 |
+
ftpuploadresume \
|
| 47 |
+
getinfo \
|
| 48 |
+
getinmemory \
|
| 49 |
+
getredirect \
|
| 50 |
+
getreferrer \
|
| 51 |
+
headerapi \
|
| 52 |
+
hsts-preload \
|
| 53 |
+
http-options \
|
| 54 |
+
http-post \
|
| 55 |
+
http2-download \
|
| 56 |
+
http2-pushinmemory \
|
| 57 |
+
http2-serverpush \
|
| 58 |
+
http2-upload \
|
| 59 |
+
http3 \
|
| 60 |
+
http3-present \
|
| 61 |
+
httpcustomheader \
|
| 62 |
+
httpput \
|
| 63 |
+
httpput-postfields \
|
| 64 |
+
https \
|
| 65 |
+
imap-append \
|
| 66 |
+
imap-authzid \
|
| 67 |
+
imap-copy \
|
| 68 |
+
imap-create \
|
| 69 |
+
imap-delete \
|
| 70 |
+
imap-examine \
|
| 71 |
+
imap-fetch \
|
| 72 |
+
imap-list \
|
| 73 |
+
imap-lsub \
|
| 74 |
+
imap-multi \
|
| 75 |
+
imap-noop \
|
| 76 |
+
imap-search \
|
| 77 |
+
imap-ssl \
|
| 78 |
+
imap-store \
|
| 79 |
+
imap-tls \
|
| 80 |
+
interface \
|
| 81 |
+
ipv6 \
|
| 82 |
+
keepalive \
|
| 83 |
+
localport \
|
| 84 |
+
maxconnects \
|
| 85 |
+
multi-app \
|
| 86 |
+
multi-debugcallback \
|
| 87 |
+
multi-double \
|
| 88 |
+
multi-formadd \
|
| 89 |
+
multi-legacy \
|
| 90 |
+
multi-post \
|
| 91 |
+
multi-single \
|
| 92 |
+
netrc \
|
| 93 |
+
parseurl \
|
| 94 |
+
persistent \
|
| 95 |
+
pop3-authzid \
|
| 96 |
+
pop3-dele \
|
| 97 |
+
pop3-list \
|
| 98 |
+
pop3-multi \
|
| 99 |
+
pop3-noop \
|
| 100 |
+
pop3-retr \
|
| 101 |
+
pop3-ssl \
|
| 102 |
+
pop3-stat \
|
| 103 |
+
pop3-tls \
|
| 104 |
+
pop3-top \
|
| 105 |
+
pop3-uidl \
|
| 106 |
+
post-callback \
|
| 107 |
+
postinmemory \
|
| 108 |
+
postit2 \
|
| 109 |
+
postit2-formadd \
|
| 110 |
+
progressfunc \
|
| 111 |
+
protofeats \
|
| 112 |
+
range \
|
| 113 |
+
resolve \
|
| 114 |
+
rtsp-options \
|
| 115 |
+
sendrecv \
|
| 116 |
+
sepheaders \
|
| 117 |
+
sftpget \
|
| 118 |
+
sftpuploadresume \
|
| 119 |
+
shared-connection-cache \
|
| 120 |
+
simple \
|
| 121 |
+
simplepost \
|
| 122 |
+
simplessl \
|
| 123 |
+
smtp-authzid \
|
| 124 |
+
smtp-expn \
|
| 125 |
+
smtp-mail \
|
| 126 |
+
smtp-mime \
|
| 127 |
+
smtp-multi \
|
| 128 |
+
smtp-ssl \
|
| 129 |
+
smtp-tls \
|
| 130 |
+
smtp-vrfy \
|
| 131 |
+
sslbackend \
|
| 132 |
+
unixsocket \
|
| 133 |
+
url2file \
|
| 134 |
+
urlapi \
|
| 135 |
+
websocket \
|
| 136 |
+
websocket-cb
|
| 137 |
+
|
| 138 |
+
# These examples require external dependencies that may not be commonly
|
| 139 |
+
# available on POSIX systems, so do not bother attempting to compile them here.
|
| 140 |
+
COMPLICATED_EXAMPLES = \
|
| 141 |
+
cacertinmem.c \
|
| 142 |
+
crawler.c \
|
| 143 |
+
ephiperfifo.c \
|
| 144 |
+
evhiperfifo.c \
|
| 145 |
+
ghiper.c \
|
| 146 |
+
hiperfifo.c \
|
| 147 |
+
href_extractor.c \
|
| 148 |
+
htmltidy.c \
|
| 149 |
+
htmltitle.cpp \
|
| 150 |
+
multi-event.c \
|
| 151 |
+
multi-uv.c \
|
| 152 |
+
multithread.c \
|
| 153 |
+
sessioninfo.c \
|
| 154 |
+
smooth-gtk-thread.c \
|
| 155 |
+
synctime.c \
|
| 156 |
+
threaded-ssl.c \
|
| 157 |
+
usercertinmem.c \
|
| 158 |
+
version-check.pl \
|
| 159 |
+
xmlstream.c
|
local-test-curl-delta-01/afc-curl/docs/examples/Makefile.mk
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Build libcurl via lib/Makefile.mk first.
|
| 26 |
+
|
| 27 |
+
PROOT := ../..
|
| 28 |
+
|
| 29 |
+
### Common
|
| 30 |
+
|
| 31 |
+
include $(PROOT)/lib/Makefile.mk
|
| 32 |
+
|
| 33 |
+
### Local
|
| 34 |
+
|
| 35 |
+
CPPFLAGS += -DCURL_NO_OLDIES
|
| 36 |
+
LDFLAGS += -L$(PROOT)/lib
|
| 37 |
+
LIBS := -lcurl $(LIBS)
|
| 38 |
+
|
| 39 |
+
### Sources and targets
|
| 40 |
+
|
| 41 |
+
# Provides check_PROGRAMS
|
| 42 |
+
include Makefile.inc
|
| 43 |
+
|
| 44 |
+
TARGETS := $(patsubst %,%$(BIN_EXT),$(strip $(check_PROGRAMS)))
|
| 45 |
+
TOCLEAN := $(TARGETS)
|
| 46 |
+
|
| 47 |
+
### Rules
|
| 48 |
+
|
| 49 |
+
%$(BIN_EXT): %.c $(PROOT)/lib/libcurl.a
|
| 50 |
+
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LIBS)
|
| 51 |
+
|
| 52 |
+
all: $(TARGETS)
|
local-test-curl-delta-01/afc-curl/docs/examples/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--
|
| 2 |
+
Copyright (C) Daniel Stenberg, <[email protected]>, et al.
|
| 3 |
+
|
| 4 |
+
SPDX-License-Identifier: curl
|
| 5 |
+
-->
|
| 6 |
+
|
| 7 |
+
# libcurl examples
|
| 8 |
+
|
| 9 |
+
This directory is for libcurl programming examples. They are meant to show
|
| 10 |
+
some simple steps on how you can build your own application to take full
|
| 11 |
+
advantage of libcurl.
|
| 12 |
+
|
| 13 |
+
If you end up with other small but still useful example sources, please mail
|
| 14 |
+
them for submission in future packages and on the website.
|
| 15 |
+
|
| 16 |
+
## Building
|
| 17 |
+
|
| 18 |
+
The `Makefile.example` is an example Makefile that could be used to build
|
| 19 |
+
these examples. Just edit the file according to your system and requirements
|
| 20 |
+
first.
|
| 21 |
+
|
| 22 |
+
Most examples should build fine using a command line like this:
|
| 23 |
+
|
| 24 |
+
`curl-config --cc --cflags --libs` -o example-my example.c
|
| 25 |
+
|
| 26 |
+
Some compilers do not like having the arguments in this order but instead
|
| 27 |
+
want you do reorganize them like:
|
| 28 |
+
|
| 29 |
+
`curl-config --cc` -o example-my example.c `curl-config --cflags --libs`
|
| 30 |
+
|
| 31 |
+
**Please** do not use the `curl.se` site as a test target for your libcurl
|
| 32 |
+
applications/experiments. Even if some of the examples use that site as a URL
|
| 33 |
+
at some places, it does not mean that the URLs work or that we expect you to
|
| 34 |
+
actually torture our website with your tests. Thanks.
|
| 35 |
+
|
| 36 |
+
## Examples
|
| 37 |
+
|
| 38 |
+
Each example source code file is designed to be and work stand-alone and
|
| 39 |
+
rather self-explanatory. The examples may at times lack the level of error
|
| 40 |
+
checks you need in a real world, but that is then only for the sake of
|
| 41 |
+
readability: to make the code smaller and easier to follow.
|
local-test-curl-delta-01/afc-curl/docs/examples/adddocsref.pl
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env perl
|
| 2 |
+
#***************************************************************************
|
| 3 |
+
# _ _ ____ _
|
| 4 |
+
# Project ___| | | | _ \| |
|
| 5 |
+
# / __| | | | |_) | |
|
| 6 |
+
# | (__| |_| | _ <| |___
|
| 7 |
+
# \___|\___/|_| \_\_____|
|
| 8 |
+
#
|
| 9 |
+
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
|
| 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 |
+
# pass files as argument(s)
|
| 27 |
+
|
| 28 |
+
my $docroot="https://curl.se/libcurl/c";
|
| 29 |
+
|
| 30 |
+
for $f (@ARGV) {
|
| 31 |
+
open(NEW, ">$f.new");
|
| 32 |
+
open(F, "<$f");
|
| 33 |
+
while(<F>) {
|
| 34 |
+
my $l = $_;
|
| 35 |
+
if($l =~ /\/* $docroot/) {
|
| 36 |
+
# just ignore preciously added refs
|
| 37 |
+
}
|
| 38 |
+
elsif($l =~ /^( *).*curl_easy_setopt\([^,]*, *([^ ,]*) *,/) {
|
| 39 |
+
my ($prefix, $anc) = ($1, $2);
|
| 40 |
+
$anc =~ s/_//g;
|
| 41 |
+
print NEW "$prefix/* $docroot/curl_easy_setopt.html#$anc */\n";
|
| 42 |
+
print NEW $l;
|
| 43 |
+
}
|
| 44 |
+
elsif($l =~ /^( *).*(curl_([^\(]*))\(/) {
|
| 45 |
+
my ($prefix, $func) = ($1, $2);
|
| 46 |
+
print NEW "$prefix/* $docroot/$func.html */\n";
|
| 47 |
+
print NEW $l;
|
| 48 |
+
}
|
| 49 |
+
else {
|
| 50 |
+
print NEW $l;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
close(F);
|
| 54 |
+
close(NEW);
|
| 55 |
+
|
| 56 |
+
system("mv $f $f.org");
|
| 57 |
+
system("mv $f.new $f");
|
| 58 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/address-scope.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP GET to an IPv6 address with specific scope
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
#ifndef _WIN32
|
| 32 |
+
#include <net/if.h>
|
| 33 |
+
#endif
|
| 34 |
+
|
| 35 |
+
int main(void)
|
| 36 |
+
{
|
| 37 |
+
#ifndef _WIN32
|
| 38 |
+
/* Windows users need to find how to use if_nametoindex() */
|
| 39 |
+
CURL *curl;
|
| 40 |
+
CURLcode res;
|
| 41 |
+
|
| 42 |
+
curl = curl_easy_init();
|
| 43 |
+
if(curl) {
|
| 44 |
+
long my_scope_id;
|
| 45 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
| 46 |
+
|
| 47 |
+
my_scope_id = (long)if_nametoindex("eth0");
|
| 48 |
+
curl_easy_setopt(curl, CURLOPT_ADDRESS_SCOPE, my_scope_id);
|
| 49 |
+
|
| 50 |
+
/* Perform the request, res gets the return code */
|
| 51 |
+
res = curl_easy_perform(curl);
|
| 52 |
+
/* Check for errors */
|
| 53 |
+
if(res != CURLE_OK)
|
| 54 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 55 |
+
curl_easy_strerror(res));
|
| 56 |
+
|
| 57 |
+
/* always cleanup */
|
| 58 |
+
curl_easy_cleanup(curl);
|
| 59 |
+
}
|
| 60 |
+
#endif
|
| 61 |
+
return 0;
|
| 62 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/altsvc.c
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP with Alt-Svc support
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl = curl_easy_init();
|
| 37 |
+
if(curl) {
|
| 38 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
| 39 |
+
|
| 40 |
+
/* cache the alternatives in this file */
|
| 41 |
+
curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc.txt");
|
| 42 |
+
|
| 43 |
+
/* restrict which HTTP versions to use alternatives */
|
| 44 |
+
curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, (long)
|
| 45 |
+
CURLALTSVC_H1|CURLALTSVC_H2|CURLALTSVC_H3);
|
| 46 |
+
|
| 47 |
+
/* Perform the request, res gets the return code */
|
| 48 |
+
res = curl_easy_perform(curl);
|
| 49 |
+
/* Check for errors */
|
| 50 |
+
if(res != CURLE_OK)
|
| 51 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 52 |
+
curl_easy_strerror(res));
|
| 53 |
+
|
| 54 |
+
/* always cleanup */
|
| 55 |
+
curl_easy_cleanup(curl);
|
| 56 |
+
}
|
| 57 |
+
return 0;
|
| 58 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/anyauthput.c
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP PUT upload with authentication using "any" method. libcurl picks the
|
| 26 |
+
* one the server supports/wants.
|
| 27 |
+
* </DESC>
|
| 28 |
+
*/
|
| 29 |
+
#include <stdio.h>
|
| 30 |
+
#include <fcntl.h>
|
| 31 |
+
#include <sys/types.h>
|
| 32 |
+
#include <sys/stat.h>
|
| 33 |
+
|
| 34 |
+
#include <curl/curl.h>
|
| 35 |
+
|
| 36 |
+
#ifdef _WIN32
|
| 37 |
+
# define FILENO(fp) _fileno(fp)
|
| 38 |
+
#else
|
| 39 |
+
# define FILENO(fp) fileno(fp)
|
| 40 |
+
#endif
|
| 41 |
+
|
| 42 |
+
#if LIBCURL_VERSION_NUM < 0x070c03
|
| 43 |
+
#error "upgrade your libcurl to no less than 7.12.3"
|
| 44 |
+
#endif
|
| 45 |
+
|
| 46 |
+
/*
|
| 47 |
+
* This example shows an HTTP PUT operation with authentication using "any"
|
| 48 |
+
* type. It PUTs a file given as a command line argument to the URL also given
|
| 49 |
+
* on the command line.
|
| 50 |
+
*
|
| 51 |
+
* Since libcurl 7.12.3, using "any" auth and POST/PUT requires a set seek
|
| 52 |
+
* function.
|
| 53 |
+
*
|
| 54 |
+
* This example also uses its own read callback.
|
| 55 |
+
*/
|
| 56 |
+
|
| 57 |
+
/* seek callback function */
|
| 58 |
+
static int my_seek(void *userp, curl_off_t offset, int origin)
|
| 59 |
+
{
|
| 60 |
+
FILE *fp = (FILE *) userp;
|
| 61 |
+
|
| 62 |
+
if(-1 == fseek(fp, (long) offset, origin))
|
| 63 |
+
/* could not seek */
|
| 64 |
+
return CURL_SEEKFUNC_CANTSEEK;
|
| 65 |
+
|
| 66 |
+
return CURL_SEEKFUNC_OK; /* success! */
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* read callback function, fread() look alike */
|
| 70 |
+
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
|
| 71 |
+
{
|
| 72 |
+
size_t nread;
|
| 73 |
+
|
| 74 |
+
nread = fread(ptr, size, nmemb, stream);
|
| 75 |
+
|
| 76 |
+
if(nread > 0) {
|
| 77 |
+
fprintf(stderr, "*** We read %lu bytes from file\n", (unsigned long)nread);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return nread;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
int main(int argc, char **argv)
|
| 84 |
+
{
|
| 85 |
+
CURL *curl;
|
| 86 |
+
CURLcode res;
|
| 87 |
+
FILE *fp;
|
| 88 |
+
struct stat file_info;
|
| 89 |
+
|
| 90 |
+
char *file;
|
| 91 |
+
char *url;
|
| 92 |
+
|
| 93 |
+
if(argc < 3)
|
| 94 |
+
return 1;
|
| 95 |
+
|
| 96 |
+
file = argv[1];
|
| 97 |
+
url = argv[2];
|
| 98 |
+
|
| 99 |
+
/* get the file size of the local file */
|
| 100 |
+
fp = fopen(file, "rb");
|
| 101 |
+
fstat(FILENO(fp), &file_info);
|
| 102 |
+
|
| 103 |
+
/* In Windows, this inits the Winsock stuff */
|
| 104 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 105 |
+
|
| 106 |
+
/* get a curl handle */
|
| 107 |
+
curl = curl_easy_init();
|
| 108 |
+
if(curl) {
|
| 109 |
+
/* we want to use our own read function */
|
| 110 |
+
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
| 111 |
+
|
| 112 |
+
/* which file to upload */
|
| 113 |
+
curl_easy_setopt(curl, CURLOPT_READDATA, (void *) fp);
|
| 114 |
+
|
| 115 |
+
/* set the seek function */
|
| 116 |
+
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, my_seek);
|
| 117 |
+
|
| 118 |
+
/* pass the file descriptor to the seek callback as well */
|
| 119 |
+
curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *) fp);
|
| 120 |
+
|
| 121 |
+
/* enable "uploading" (which means PUT when doing HTTP) */
|
| 122 |
+
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
| 123 |
+
|
| 124 |
+
/* specify target URL, and note that this URL should also include a file
|
| 125 |
+
name, not only a directory (as you can do with GTP uploads) */
|
| 126 |
+
curl_easy_setopt(curl, CURLOPT_URL, url);
|
| 127 |
+
|
| 128 |
+
/* and give the size of the upload, this supports large file sizes
|
| 129 |
+
on systems that have general support for it */
|
| 130 |
+
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
|
| 131 |
+
(curl_off_t)file_info.st_size);
|
| 132 |
+
|
| 133 |
+
/* tell libcurl we can use "any" auth, which lets the lib pick one, but it
|
| 134 |
+
also costs one extra round-trip and possibly sending of all the PUT
|
| 135 |
+
data twice!!! */
|
| 136 |
+
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
|
| 137 |
+
|
| 138 |
+
/* set user name and password for the authentication */
|
| 139 |
+
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
|
| 140 |
+
|
| 141 |
+
/* Now run off and do what you have been told! */
|
| 142 |
+
res = curl_easy_perform(curl);
|
| 143 |
+
/* Check for errors */
|
| 144 |
+
if(res != CURLE_OK)
|
| 145 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 146 |
+
curl_easy_strerror(res));
|
| 147 |
+
|
| 148 |
+
/* always cleanup */
|
| 149 |
+
curl_easy_cleanup(curl);
|
| 150 |
+
}
|
| 151 |
+
fclose(fp); /* close the local file */
|
| 152 |
+
|
| 153 |
+
curl_global_cleanup();
|
| 154 |
+
return 0;
|
| 155 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/cacertinmem.c
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* CA cert in memory with OpenSSL to get an HTTPS page.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#include <openssl/err.h>
|
| 30 |
+
#include <openssl/ssl.h>
|
| 31 |
+
#include <curl/curl.h>
|
| 32 |
+
#include <stdio.h>
|
| 33 |
+
|
| 34 |
+
static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
| 35 |
+
{
|
| 36 |
+
fwrite(ptr, size, nmemb, (FILE *)stream);
|
| 37 |
+
return (nmemb*size);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
| 41 |
+
{
|
| 42 |
+
CURLcode rv = CURLE_ABORTED_BY_CALLBACK;
|
| 43 |
+
|
| 44 |
+
/** This example uses two (fake) certificates **/
|
| 45 |
+
static const char mypem[] =
|
| 46 |
+
"-----BEGIN CERTIFICATE-----\n"
|
| 47 |
+
"MIIH0zCCBbugAwIBAgIIXsO3pkN/pOAwDQYJKoZIhvcNAQEFBQAwQjESMBAGA1UE\n"
|
| 48 |
+
"AwwJQUNDVlJBSVoxMRAwDgYDVQQLDAdQS0lBQ0NWMQ0wCwYDVQQKDARBQ0NWMQsw\n"
|
| 49 |
+
"CQYDVQQGEwJFUzAeFw0xMTA1MDUwOTM3MzdaFw0zMDEyMzEwOTM3MzdaMEIxEjAQ\n"
|
| 50 |
+
"BgNVBAMMCUFDQ1ZSQUlaMTEQMA4GA1UECwwHUEtJQUNDVjENMAsGA1UECgwEQUND\n"
|
| 51 |
+
"VjELMAkGA1UEBhMCRVMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCb\n"
|
| 52 |
+
"qau/YUqXry+XZpp0X9DZlv3P4uRm7x8fRzPCRKPfmt4ftVTdFXxpNRFvu8gMjmoY\n"
|
| 53 |
+
"HtiP2Ra8EEg2XPBjs5BaXCQ316PWywlxufEBcoSwfdtNgM3802/J+Nq2DoLSRYWo\n"
|
| 54 |
+
"G2ioPej0RGy9ocLLA76MPhMAhN9KSMDjIgro6TenGEyxCQ0jVn8ETdkXhBilyNpA\n"
|
| 55 |
+
"0KIV9VMJcRz/RROE5iZe+OCIHAr8Fraocwa48GOEAqDGWuzndN9wrqODJerWx5eH\n"
|
| 56 |
+
"k6fGioozl2A3ED6XPm4pFdahD9GILBKfb6qkxkLrQaLjlUPTAYVtjrs78yM2x/47\n"
|
| 57 |
+
"JyCpZET/LtZ1qmxNYEAZSUNUY9rizLpm5U9EelvZaoErQNV/+QEnWCzI7UiRfD+m\n"
|
| 58 |
+
"AM/EKXMRNt6GGT6d7hmKG9Ww7Y49nCrADdg9ZuM8Db3VlFzi4qc1GwQA9j9ajepD\n"
|
| 59 |
+
"vV+JHanBsMyZ4k0ACtrJJ1vnE5Bc5PUzolVt3OAJTS+xJlsndQAJxGJ3KQhfnlms\n"
|
| 60 |
+
"tn6tn1QwIgPBHnFk/vk4CpYY3QIUrCPLBhwepH2NDd4nQeit2hW3sCPdK6jT2iWH\n"
|
| 61 |
+
"7ehVRE2I9DZ+hJp4rPcOVkkO1jMl1oRQQmwgEh0q1b688nCBpHBgvgW1m54ERL5h\n"
|
| 62 |
+
"I6zppSSMEYCUWqKiuUnSwdzRp+0xESyeGabu4VXhwOrPDYTkF7eifKXeVSUG7szA\n"
|
| 63 |
+
"h1xA2syVP1XgNce4hL60Xc16gwFy7ofmXx2utYXGJt/mwZrpHgJHnyqobalbz+xF\n"
|
| 64 |
+
"d3+YJ5oyXSrjhO7FmGYvliAd3djDJ9ew+f7Zfc3Qn48LFFhRny+Lwzgt3uiP1o2H\n"
|
| 65 |
+
"pPVWQxaZLPSkVrQ0uGE3ycJYgBugl6H8WY3pEfbRD0tVNEYqi4Y7\n"
|
| 66 |
+
"-----END CERTIFICATE-----\n"
|
| 67 |
+
"-----BEGIN CERTIFICATE-----\n"
|
| 68 |
+
"MIIFtTCCA52gAwIBAgIIYY3HhjsBggUwDQYJKoZIhvcNAQEFBQAwRDEWMBQGA1UE\n"
|
| 69 |
+
"AwwNQUNFRElDT00gUm9vdDEMMAoGA1UECwwDUEtJMQ8wDQYDVQQKDAZFRElDT00x\n"
|
| 70 |
+
"CzAJBgNVBAYTAkVTMB4XDTA4MDQxODE2MjQyMloXDTI4MDQxMzE2MjQyMlowRDEW\n"
|
| 71 |
+
"MBQGA1UEAwwNQUNFRElDT00gUm9vdDEMMAoGA1UECwwDUEtJMQ8wDQYDVQQKDAZF\n"
|
| 72 |
+
"RElDT00xCzAJBgNVBAYTAkVTMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC\n"
|
| 73 |
+
"AgEA/5KV4WgGdrQsyFhIyv2AVClVYyT/kGWbEHV7w2rbYgIB8hiGtXxaOLHkWLn7\n"
|
| 74 |
+
"09gtn70yN78sFW2+tfQh0hOR2QetAQXW8713zl9CgQr5auODAKgrLlUTY4HKRxx7\n"
|
| 75 |
+
"XBZXehuDYAQ6PmXDzQHe3qTWDLqO3tkE7hdWIpuPY/1NFgu3e3eM+SW10W2ZEi5P\n"
|
| 76 |
+
"gvoFNTPhNahXwOf9jU8/kzJPeGYDdwdY6ZXIfj7QeQCM8htRM5u8lOk6e25SLTKe\n"
|
| 77 |
+
"I6RF+7YuE7CLGLHdztUdp0J/Vb77W7tH1PwkzQSulgUV1qzOMPPKC8W64iLgpq0i\n"
|
| 78 |
+
"5ALudBF/TP94HTXa5gI06xgSYXcGCRZj6hitoocf8seACQl1ThCojz2GuHURwCRi\n"
|
| 79 |
+
"ipZ7SkXp7FnFvmuD5uHorLUwHv4FB4D54SMNUI8FmP8sX+g7tq3PgbUhh8oIKiMn\n"
|
| 80 |
+
"MCArz+2UW6yyetLHKKGKC5tNSixthT8Jcjxn4tncB7rrZXtaAWPWkFtPF2Y9fwsZ\n"
|
| 81 |
+
"o5NjEFIqnxQWWOLcpfShFosOkYuByptZ+thrkQdlVV9SH686+5DdaaVbnG0OLLb6\n"
|
| 82 |
+
"zqylfDJKZ0DcMDQj3dcEI2bw/FWAp/tmGYI1Z2JwOV5vx+qQQEQIHriy1tvuWacN\n"
|
| 83 |
+
"GHk0vFQYXlPKNFHtRQrmjseCNj6nOGOpMCwXEGCSn1WHElkQwg9naRHMTh5+Spqt\n"
|
| 84 |
+
"r0CodaxWkHS4oJyleW/c6RrIaQXpuvoDs3zk4E7Czp3otkYNbn5XOmeUwssfnHdK\n"
|
| 85 |
+
"Z05phkOTOPu220+DkdRgfks+KzgHVZhepA==\n"
|
| 86 |
+
"-----END CERTIFICATE-----\n";
|
| 87 |
+
|
| 88 |
+
BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem));
|
| 89 |
+
X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
|
| 90 |
+
int i;
|
| 91 |
+
STACK_OF(X509_INFO) *inf;
|
| 92 |
+
(void)curl;
|
| 93 |
+
(void)parm;
|
| 94 |
+
|
| 95 |
+
if(!cts || !cbio) {
|
| 96 |
+
return rv;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
inf = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
|
| 100 |
+
|
| 101 |
+
if(!inf) {
|
| 102 |
+
BIO_free(cbio);
|
| 103 |
+
return rv;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
for(i = 0; i < sk_X509_INFO_num(inf); i++) {
|
| 107 |
+
X509_INFO *itmp = sk_X509_INFO_value(inf, i);
|
| 108 |
+
if(itmp->x509) {
|
| 109 |
+
X509_STORE_add_cert(cts, itmp->x509);
|
| 110 |
+
}
|
| 111 |
+
if(itmp->crl) {
|
| 112 |
+
X509_STORE_add_crl(cts, itmp->crl);
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
sk_X509_INFO_pop_free(inf, X509_INFO_free);
|
| 117 |
+
BIO_free(cbio);
|
| 118 |
+
|
| 119 |
+
rv = CURLE_OK;
|
| 120 |
+
return rv;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
int main(void)
|
| 124 |
+
{
|
| 125 |
+
CURL *ch;
|
| 126 |
+
CURLcode rv;
|
| 127 |
+
|
| 128 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 129 |
+
ch = curl_easy_init();
|
| 130 |
+
curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L);
|
| 131 |
+
curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
|
| 132 |
+
curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L);
|
| 133 |
+
curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L);
|
| 134 |
+
curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writefunction);
|
| 135 |
+
curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout);
|
| 136 |
+
curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, writefunction);
|
| 137 |
+
curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr);
|
| 138 |
+
curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");
|
| 139 |
+
curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L);
|
| 140 |
+
curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/");
|
| 141 |
+
|
| 142 |
+
/* Turn off the default CA locations, otherwise libcurl loads CA
|
| 143 |
+
* certificates from the locations that were detected/specified at
|
| 144 |
+
* build-time
|
| 145 |
+
*/
|
| 146 |
+
curl_easy_setopt(ch, CURLOPT_CAINFO, NULL);
|
| 147 |
+
curl_easy_setopt(ch, CURLOPT_CAPATH, NULL);
|
| 148 |
+
|
| 149 |
+
/* first try: retrieve page without ca certificates -> should fail
|
| 150 |
+
* unless libcurl was built --with-ca-fallback enabled at build-time
|
| 151 |
+
*/
|
| 152 |
+
rv = curl_easy_perform(ch);
|
| 153 |
+
if(rv == CURLE_OK)
|
| 154 |
+
printf("*** transfer succeeded ***\n");
|
| 155 |
+
else
|
| 156 |
+
printf("*** transfer failed ***\n");
|
| 157 |
+
|
| 158 |
+
/* use a fresh connection (optional) this option seriously impacts
|
| 159 |
+
* performance of multiple transfers but it is necessary order to
|
| 160 |
+
* demonstrate this example. recall that the ssl ctx callback is only called
|
| 161 |
+
* _before_ an SSL connection is established, therefore it does not affect
|
| 162 |
+
* existing verified SSL connections already in the connection cache
|
| 163 |
+
* associated with this handle. normally you would set the ssl ctx function
|
| 164 |
+
* before making any transfers, and not use this option.
|
| 165 |
+
*/
|
| 166 |
+
curl_easy_setopt(ch, CURLOPT_FRESH_CONNECT, 1L);
|
| 167 |
+
|
| 168 |
+
/* second try: retrieve page using cacerts' certificate -> succeeds to load
|
| 169 |
+
* the certificate by installing a function doing the necessary
|
| 170 |
+
* "modifications" to the SSL CONTEXT just before link init
|
| 171 |
+
*/
|
| 172 |
+
curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);
|
| 173 |
+
rv = curl_easy_perform(ch);
|
| 174 |
+
if(rv == CURLE_OK)
|
| 175 |
+
printf("*** transfer succeeded ***\n");
|
| 176 |
+
else
|
| 177 |
+
printf("*** transfer failed ***\n");
|
| 178 |
+
|
| 179 |
+
curl_easy_cleanup(ch);
|
| 180 |
+
curl_global_cleanup();
|
| 181 |
+
return rv;
|
| 182 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/certinfo.c
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Extract lots of TLS certificate info.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
|
| 30 |
+
#include <curl/curl.h>
|
| 31 |
+
|
| 32 |
+
static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
|
| 33 |
+
{
|
| 34 |
+
(void)stream;
|
| 35 |
+
(void)ptr;
|
| 36 |
+
return size * nmemb;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
int main(void)
|
| 40 |
+
{
|
| 41 |
+
CURL *curl;
|
| 42 |
+
CURLcode res;
|
| 43 |
+
|
| 44 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 45 |
+
|
| 46 |
+
curl = curl_easy_init();
|
| 47 |
+
if(curl) {
|
| 48 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
| 49 |
+
|
| 50 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
|
| 51 |
+
|
| 52 |
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
| 53 |
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
| 54 |
+
|
| 55 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
| 56 |
+
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
|
| 57 |
+
|
| 58 |
+
res = curl_easy_perform(curl);
|
| 59 |
+
|
| 60 |
+
if(!res) {
|
| 61 |
+
struct curl_certinfo *certinfo;
|
| 62 |
+
|
| 63 |
+
res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);
|
| 64 |
+
|
| 65 |
+
if(!res && certinfo) {
|
| 66 |
+
int i;
|
| 67 |
+
|
| 68 |
+
printf("%d certs!\n", certinfo->num_of_certs);
|
| 69 |
+
|
| 70 |
+
for(i = 0; i < certinfo->num_of_certs; i++) {
|
| 71 |
+
struct curl_slist *slist;
|
| 72 |
+
|
| 73 |
+
for(slist = certinfo->certinfo[i]; slist; slist = slist->next)
|
| 74 |
+
printf("%s\n", slist->data);
|
| 75 |
+
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
curl_easy_cleanup(curl);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
curl_global_cleanup();
|
| 85 |
+
|
| 86 |
+
return 0;
|
| 87 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/chkspeed.c
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Show transfer timing info after download completes.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
/* Example source code to show how the callback function can be used to
|
| 29 |
+
* download data into a chunk of memory instead of storing it in a file.
|
| 30 |
+
* After successful download we use curl_easy_getinfo() calls to get the
|
| 31 |
+
* amount of downloaded bytes, the time used for the whole download, and
|
| 32 |
+
* the average download speed.
|
| 33 |
+
* On Linux you can create the download test files with:
|
| 34 |
+
* dd if=/dev/urandom of=file_1M.bin bs=1M count=1
|
| 35 |
+
*
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
#include <stdio.h>
|
| 39 |
+
#include <stdlib.h>
|
| 40 |
+
#include <time.h>
|
| 41 |
+
|
| 42 |
+
#include <curl/curl.h>
|
| 43 |
+
|
| 44 |
+
#define URL_BASE "http://speedtest.your.domain/"
|
| 45 |
+
#define URL_1M URL_BASE "file_1M.bin"
|
| 46 |
+
#define URL_2M URL_BASE "file_2M.bin"
|
| 47 |
+
#define URL_5M URL_BASE "file_5M.bin"
|
| 48 |
+
#define URL_10M URL_BASE "file_10M.bin"
|
| 49 |
+
#define URL_20M URL_BASE "file_20M.bin"
|
| 50 |
+
#define URL_50M URL_BASE "file_50M.bin"
|
| 51 |
+
#define URL_100M URL_BASE "file_100M.bin"
|
| 52 |
+
|
| 53 |
+
#define CHKSPEED_VERSION "1.0"
|
| 54 |
+
|
| 55 |
+
static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
| 56 |
+
{
|
| 57 |
+
/* we are not interested in the downloaded bytes itself,
|
| 58 |
+
so we only return the size we would have saved ... */
|
| 59 |
+
(void)ptr; /* unused */
|
| 60 |
+
(void)data; /* unused */
|
| 61 |
+
return (size_t)(size * nmemb);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
int main(int argc, char *argv[])
|
| 65 |
+
{
|
| 66 |
+
CURL *curl_handle;
|
| 67 |
+
CURLcode res;
|
| 68 |
+
int prtall = 0, prtsep = 0, prttime = 0;
|
| 69 |
+
const char *url = URL_1M;
|
| 70 |
+
char *appname = argv[0];
|
| 71 |
+
|
| 72 |
+
if(argc > 1) {
|
| 73 |
+
/* parse input parameters */
|
| 74 |
+
for(argc--, argv++; *argv; argc--, argv++) {
|
| 75 |
+
if(argv[0][0] == '-') {
|
| 76 |
+
switch(argv[0][1]) {
|
| 77 |
+
case 'h':
|
| 78 |
+
case 'H':
|
| 79 |
+
fprintf(stderr,
|
| 80 |
+
"\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n",
|
| 81 |
+
appname);
|
| 82 |
+
exit(1);
|
| 83 |
+
case 'v':
|
| 84 |
+
case 'V':
|
| 85 |
+
fprintf(stderr, "\r%s %s - %s\n",
|
| 86 |
+
appname, CHKSPEED_VERSION, curl_version());
|
| 87 |
+
exit(1);
|
| 88 |
+
case 'a':
|
| 89 |
+
case 'A':
|
| 90 |
+
prtall = 1;
|
| 91 |
+
break;
|
| 92 |
+
case 'x':
|
| 93 |
+
case 'X':
|
| 94 |
+
prtsep = 1;
|
| 95 |
+
break;
|
| 96 |
+
case 't':
|
| 97 |
+
case 'T':
|
| 98 |
+
prttime = 1;
|
| 99 |
+
break;
|
| 100 |
+
case 'm':
|
| 101 |
+
case 'M':
|
| 102 |
+
if(argv[0][2] == '=') {
|
| 103 |
+
long m = strtol((*argv) + 3, NULL, 10);
|
| 104 |
+
switch(m) {
|
| 105 |
+
case 1:
|
| 106 |
+
url = URL_1M;
|
| 107 |
+
break;
|
| 108 |
+
case 2:
|
| 109 |
+
url = URL_2M;
|
| 110 |
+
break;
|
| 111 |
+
case 5:
|
| 112 |
+
url = URL_5M;
|
| 113 |
+
break;
|
| 114 |
+
case 10:
|
| 115 |
+
url = URL_10M;
|
| 116 |
+
break;
|
| 117 |
+
case 20:
|
| 118 |
+
url = URL_20M;
|
| 119 |
+
break;
|
| 120 |
+
case 50:
|
| 121 |
+
url = URL_50M;
|
| 122 |
+
break;
|
| 123 |
+
case 100:
|
| 124 |
+
url = URL_100M;
|
| 125 |
+
break;
|
| 126 |
+
default:
|
| 127 |
+
fprintf(stderr, "\r%s: invalid parameter %s\n",
|
| 128 |
+
appname, *argv + 3);
|
| 129 |
+
return 1;
|
| 130 |
+
}
|
| 131 |
+
break;
|
| 132 |
+
}
|
| 133 |
+
fprintf(stderr, "\r%s: invalid or unknown option %s\n",
|
| 134 |
+
appname, *argv);
|
| 135 |
+
return 1;
|
| 136 |
+
default:
|
| 137 |
+
fprintf(stderr, "\r%s: invalid or unknown option %s\n",
|
| 138 |
+
appname, *argv);
|
| 139 |
+
return 1;
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
else {
|
| 143 |
+
url = *argv;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/* print separator line */
|
| 149 |
+
if(prtsep) {
|
| 150 |
+
printf("-------------------------------------------------\n");
|
| 151 |
+
}
|
| 152 |
+
/* print localtime */
|
| 153 |
+
if(prttime) {
|
| 154 |
+
time_t t = time(NULL);
|
| 155 |
+
printf("Localtime: %s", ctime(&t));
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/* init libcurl */
|
| 159 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 160 |
+
|
| 161 |
+
/* init the curl session */
|
| 162 |
+
curl_handle = curl_easy_init();
|
| 163 |
+
|
| 164 |
+
/* specify URL to get */
|
| 165 |
+
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
| 166 |
+
|
| 167 |
+
/* send all data to this function */
|
| 168 |
+
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteCallback);
|
| 169 |
+
|
| 170 |
+
/* some servers do not like requests that are made without a user-agent
|
| 171 |
+
field, so we provide one */
|
| 172 |
+
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT,
|
| 173 |
+
"libcurl-speedchecker/" CHKSPEED_VERSION);
|
| 174 |
+
|
| 175 |
+
/* get it! */
|
| 176 |
+
res = curl_easy_perform(curl_handle);
|
| 177 |
+
|
| 178 |
+
if(CURLE_OK == res) {
|
| 179 |
+
curl_off_t val;
|
| 180 |
+
|
| 181 |
+
/* check for bytes downloaded */
|
| 182 |
+
res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD_T, &val);
|
| 183 |
+
if((CURLE_OK == res) && (val > 0))
|
| 184 |
+
printf("Data downloaded: %lu bytes.\n", (unsigned long)val);
|
| 185 |
+
|
| 186 |
+
/* check for total download time */
|
| 187 |
+
res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME_T, &val);
|
| 188 |
+
if((CURLE_OK == res) && (val > 0))
|
| 189 |
+
printf("Total download time: %lu.%06lu sec.\n",
|
| 190 |
+
(unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
|
| 191 |
+
|
| 192 |
+
/* check for average download speed */
|
| 193 |
+
res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD_T, &val);
|
| 194 |
+
if((CURLE_OK == res) && (val > 0))
|
| 195 |
+
printf("Average download speed: %lu kbyte/sec.\n",
|
| 196 |
+
(unsigned long)(val / 1024));
|
| 197 |
+
|
| 198 |
+
if(prtall) {
|
| 199 |
+
/* check for name resolution time */
|
| 200 |
+
res = curl_easy_getinfo(curl_handle, CURLINFO_NAMELOOKUP_TIME_T, &val);
|
| 201 |
+
if((CURLE_OK == res) && (val > 0))
|
| 202 |
+
printf("Name lookup time: %lu.%06lu sec.\n",
|
| 203 |
+
(unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
|
| 204 |
+
|
| 205 |
+
/* check for connect time */
|
| 206 |
+
res = curl_easy_getinfo(curl_handle, CURLINFO_CONNECT_TIME_T, &val);
|
| 207 |
+
if((CURLE_OK == res) && (val > 0))
|
| 208 |
+
printf("Connect time: %lu.%06lu sec.\n",
|
| 209 |
+
(unsigned long)(val / 1000000), (unsigned long)(val % 1000000));
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
else {
|
| 213 |
+
fprintf(stderr, "Error while fetching '%s' : %s\n",
|
| 214 |
+
url, curl_easy_strerror(res));
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/* cleanup curl stuff */
|
| 218 |
+
curl_easy_cleanup(curl_handle);
|
| 219 |
+
|
| 220 |
+
/* we are done with libcurl, so clean it up */
|
| 221 |
+
curl_global_cleanup();
|
| 222 |
+
|
| 223 |
+
return 0;
|
| 224 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/connect-to.c
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Use CURLOPT_CONNECT_TO to connect to "wrong" hostname
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res = CURLE_OK;
|
| 35 |
+
|
| 36 |
+
/*
|
| 37 |
+
Each single string should be written using the format
|
| 38 |
+
HOST:PORT:CONNECT-TO-HOST:CONNECT-TO-PORT where HOST is the host of the
|
| 39 |
+
request, PORT is the port of the request, CONNECT-TO-HOST is the host name
|
| 40 |
+
to connect to, and CONNECT-TO-PORT is the port to connect to.
|
| 41 |
+
*/
|
| 42 |
+
/* instead of curl.se:443, it resolves and uses example.com:443 but in other
|
| 43 |
+
aspects work as if it still is curl.se */
|
| 44 |
+
struct curl_slist *host = curl_slist_append(NULL,
|
| 45 |
+
"curl.se:443:example.com:443");
|
| 46 |
+
|
| 47 |
+
curl = curl_easy_init();
|
| 48 |
+
if(curl) {
|
| 49 |
+
curl_easy_setopt(curl, CURLOPT_CONNECT_TO, host);
|
| 50 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 51 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/");
|
| 52 |
+
|
| 53 |
+
/* since this connects to the wrong host, checking the host name in the
|
| 54 |
+
server certificate fails, so unless we disable the check libcurl
|
| 55 |
+
returns CURLE_PEER_FAILED_VERIFICATION */
|
| 56 |
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
| 57 |
+
|
| 58 |
+
/* Letting the wrong host name in the certificate be okay, the transfer
|
| 59 |
+
goes through but (most likely) causes a 404 or similar because it sends
|
| 60 |
+
an unknown name in the Host: header field */
|
| 61 |
+
res = curl_easy_perform(curl);
|
| 62 |
+
|
| 63 |
+
/* always cleanup */
|
| 64 |
+
curl_easy_cleanup(curl);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
curl_slist_free_all(host);
|
| 68 |
+
|
| 69 |
+
return (int)res;
|
| 70 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/cookie_interface.c
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Import and export cookies with COOKIELIST.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#include <stdio.h>
|
| 30 |
+
#include <string.h>
|
| 31 |
+
#include <stdlib.h>
|
| 32 |
+
#include <time.h>
|
| 33 |
+
|
| 34 |
+
#include <curl/curl.h>
|
| 35 |
+
#include <curl/mprintf.h>
|
| 36 |
+
|
| 37 |
+
static void
|
| 38 |
+
print_cookies(CURL *curl)
|
| 39 |
+
{
|
| 40 |
+
CURLcode res;
|
| 41 |
+
struct curl_slist *cookies;
|
| 42 |
+
struct curl_slist *nc;
|
| 43 |
+
int i;
|
| 44 |
+
|
| 45 |
+
printf("Cookies, curl knows:\n");
|
| 46 |
+
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
|
| 47 |
+
if(res != CURLE_OK) {
|
| 48 |
+
fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n",
|
| 49 |
+
curl_easy_strerror(res));
|
| 50 |
+
exit(1);
|
| 51 |
+
}
|
| 52 |
+
nc = cookies;
|
| 53 |
+
i = 1;
|
| 54 |
+
while(nc) {
|
| 55 |
+
printf("[%d]: %s\n", i, nc->data);
|
| 56 |
+
nc = nc->next;
|
| 57 |
+
i++;
|
| 58 |
+
}
|
| 59 |
+
if(i == 1) {
|
| 60 |
+
printf("(none)\n");
|
| 61 |
+
}
|
| 62 |
+
curl_slist_free_all(cookies);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
int
|
| 66 |
+
main(void)
|
| 67 |
+
{
|
| 68 |
+
CURL *curl;
|
| 69 |
+
CURLcode res;
|
| 70 |
+
|
| 71 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 72 |
+
curl = curl_easy_init();
|
| 73 |
+
if(curl) {
|
| 74 |
+
char nline[512];
|
| 75 |
+
|
| 76 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
| 77 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 78 |
+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* start cookie engine */
|
| 79 |
+
res = curl_easy_perform(curl);
|
| 80 |
+
if(res != CURLE_OK) {
|
| 81 |
+
fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res));
|
| 82 |
+
return 1;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
print_cookies(curl);
|
| 86 |
+
|
| 87 |
+
printf("Erasing curl's knowledge of cookies!\n");
|
| 88 |
+
curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL");
|
| 89 |
+
|
| 90 |
+
print_cookies(curl);
|
| 91 |
+
|
| 92 |
+
printf("-----------------------------------------------\n"
|
| 93 |
+
"Setting a cookie \"PREF\" via cookie interface:\n");
|
| 94 |
+
/* Netscape format cookie */
|
| 95 |
+
curl_msnprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
|
| 96 |
+
".example.com", "TRUE", "/", "FALSE",
|
| 97 |
+
difftime(time(NULL) + 31337, (time_t)0),
|
| 98 |
+
"PREF", "hello example, i like you!");
|
| 99 |
+
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
|
| 100 |
+
if(res != CURLE_OK) {
|
| 101 |
+
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
|
| 102 |
+
curl_easy_strerror(res));
|
| 103 |
+
return 1;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/* HTTP-header style cookie. If you use the Set-Cookie format and do not
|
| 107 |
+
specify a domain then the cookie is sent for any domain and is not
|
| 108 |
+
modified, likely not what you intended. For more information refer to
|
| 109 |
+
the CURLOPT_COOKIELIST documentation.
|
| 110 |
+
*/
|
| 111 |
+
curl_msnprintf(nline, sizeof(nline),
|
| 112 |
+
"Set-Cookie: OLD_PREF=3d141414bf4209321; "
|
| 113 |
+
"expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com");
|
| 114 |
+
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
|
| 115 |
+
if(res != CURLE_OK) {
|
| 116 |
+
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
|
| 117 |
+
curl_easy_strerror(res));
|
| 118 |
+
return 1;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
print_cookies(curl);
|
| 122 |
+
|
| 123 |
+
res = curl_easy_perform(curl);
|
| 124 |
+
if(res != CURLE_OK) {
|
| 125 |
+
fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res));
|
| 126 |
+
return 1;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
curl_easy_cleanup(curl);
|
| 130 |
+
}
|
| 131 |
+
else {
|
| 132 |
+
fprintf(stderr, "Curl init failed!\n");
|
| 133 |
+
return 1;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
curl_global_cleanup();
|
| 137 |
+
return 0;
|
| 138 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/crawler.c
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/***************************************************************************
|
| 2 |
+
* _ _ ____ _
|
| 3 |
+
* Project ___| | | | _ \| |
|
| 4 |
+
* / __| | | | |_) | |
|
| 5 |
+
* | (__| |_| | _ <| |___
|
| 6 |
+
* \___|\___/|_| \_\_____|
|
| 7 |
+
*
|
| 8 |
+
* Copyright (C) Jeroen Ooms <[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 |
+
* To compile:
|
| 24 |
+
* gcc crawler.c $(pkg-config --cflags --libs libxml-2.0 libcurl)
|
| 25 |
+
*
|
| 26 |
+
*/
|
| 27 |
+
/* <DESC>
|
| 28 |
+
* Web crawler based on curl and libxml2 to stress-test curl with
|
| 29 |
+
* hundreds of concurrent connections to various servers.
|
| 30 |
+
* </DESC>
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
/* Parameters */
|
| 34 |
+
int max_con = 200;
|
| 35 |
+
int max_total = 20000;
|
| 36 |
+
int max_requests = 500;
|
| 37 |
+
int max_link_per_page = 5;
|
| 38 |
+
int follow_relative_links = 0;
|
| 39 |
+
char *start_page = "https://www.reuters.com";
|
| 40 |
+
|
| 41 |
+
#include <libxml/HTMLparser.h>
|
| 42 |
+
#include <libxml/xpath.h>
|
| 43 |
+
#include <libxml/uri.h>
|
| 44 |
+
#include <curl/curl.h>
|
| 45 |
+
#include <stdlib.h>
|
| 46 |
+
#include <string.h>
|
| 47 |
+
#include <math.h>
|
| 48 |
+
#include <signal.h>
|
| 49 |
+
|
| 50 |
+
int pending_interrupt = 0;
|
| 51 |
+
void sighandler(int dummy)
|
| 52 |
+
{
|
| 53 |
+
pending_interrupt = 1;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* resizable buffer */
|
| 57 |
+
typedef struct {
|
| 58 |
+
char *buf;
|
| 59 |
+
size_t size;
|
| 60 |
+
} memory;
|
| 61 |
+
|
| 62 |
+
size_t grow_buffer(void *contents, size_t sz, size_t nmemb, void *ctx)
|
| 63 |
+
{
|
| 64 |
+
size_t realsize = sz * nmemb;
|
| 65 |
+
memory *mem = (memory*) ctx;
|
| 66 |
+
char *ptr = realloc(mem->buf, mem->size + realsize);
|
| 67 |
+
if(!ptr) {
|
| 68 |
+
/* out of memory */
|
| 69 |
+
printf("not enough memory (realloc returned NULL)\n");
|
| 70 |
+
return 0;
|
| 71 |
+
}
|
| 72 |
+
mem->buf = ptr;
|
| 73 |
+
memcpy(&(mem->buf[mem->size]), contents, realsize);
|
| 74 |
+
mem->size += realsize;
|
| 75 |
+
return realsize;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
CURL *make_handle(char *url)
|
| 79 |
+
{
|
| 80 |
+
CURL *handle = curl_easy_init();
|
| 81 |
+
|
| 82 |
+
/* Important: use HTTP2 over HTTPS */
|
| 83 |
+
curl_easy_setopt(handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
|
| 84 |
+
curl_easy_setopt(handle, CURLOPT_URL, url);
|
| 85 |
+
|
| 86 |
+
/* buffer body */
|
| 87 |
+
memory *mem = malloc(sizeof(memory));
|
| 88 |
+
mem->size = 0;
|
| 89 |
+
mem->buf = malloc(1);
|
| 90 |
+
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, grow_buffer);
|
| 91 |
+
curl_easy_setopt(handle, CURLOPT_WRITEDATA, mem);
|
| 92 |
+
curl_easy_setopt(handle, CURLOPT_PRIVATE, mem);
|
| 93 |
+
|
| 94 |
+
/* For completeness */
|
| 95 |
+
curl_easy_setopt(handle, CURLOPT_ACCEPT_ENCODING, "");
|
| 96 |
+
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 5L);
|
| 97 |
+
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
|
| 98 |
+
/* only allow redirects to HTTP and HTTPS URLs */
|
| 99 |
+
curl_easy_setopt(handle, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
|
| 100 |
+
curl_easy_setopt(handle, CURLOPT_AUTOREFERER, 1L);
|
| 101 |
+
curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10L);
|
| 102 |
+
/* each transfer needs to be done within 20 seconds! */
|
| 103 |
+
curl_easy_setopt(handle, CURLOPT_TIMEOUT_MS, 20000L);
|
| 104 |
+
/* connect fast or fail */
|
| 105 |
+
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT_MS, 2000L);
|
| 106 |
+
/* skip files larger than a gigabyte */
|
| 107 |
+
curl_easy_setopt(handle, CURLOPT_MAXFILESIZE_LARGE,
|
| 108 |
+
(curl_off_t)1024*1024*1024);
|
| 109 |
+
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "");
|
| 110 |
+
curl_easy_setopt(handle, CURLOPT_FILETIME, 1L);
|
| 111 |
+
curl_easy_setopt(handle, CURLOPT_USERAGENT, "mini crawler");
|
| 112 |
+
curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
| 113 |
+
curl_easy_setopt(handle, CURLOPT_UNRESTRICTED_AUTH, 1L);
|
| 114 |
+
curl_easy_setopt(handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
|
| 115 |
+
curl_easy_setopt(handle, CURLOPT_EXPECT_100_TIMEOUT_MS, 0L);
|
| 116 |
+
return handle;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/* HREF finder implemented in libxml2 but could be any HTML parser */
|
| 120 |
+
size_t follow_links(CURLM *multi_handle, memory *mem, char *url)
|
| 121 |
+
{
|
| 122 |
+
int opts = HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | \
|
| 123 |
+
HTML_PARSE_NOWARNING | HTML_PARSE_NONET;
|
| 124 |
+
htmlDocPtr doc = htmlReadMemory(mem->buf, mem->size, url, NULL, opts);
|
| 125 |
+
if(!doc)
|
| 126 |
+
return 0;
|
| 127 |
+
xmlChar *xpath = (xmlChar*) "//a/@href";
|
| 128 |
+
xmlXPathContextPtr context = xmlXPathNewContext(doc);
|
| 129 |
+
xmlXPathObjectPtr result = xmlXPathEvalExpression(xpath, context);
|
| 130 |
+
xmlXPathFreeContext(context);
|
| 131 |
+
if(!result)
|
| 132 |
+
return 0;
|
| 133 |
+
xmlNodeSetPtr nodeset = result->nodesetval;
|
| 134 |
+
if(xmlXPathNodeSetIsEmpty(nodeset)) {
|
| 135 |
+
xmlXPathFreeObject(result);
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
size_t count = 0;
|
| 139 |
+
int i;
|
| 140 |
+
for(i = 0; i < nodeset->nodeNr; i++) {
|
| 141 |
+
double r = rand();
|
| 142 |
+
int x = r * nodeset->nodeNr / RAND_MAX;
|
| 143 |
+
const xmlNode *node = nodeset->nodeTab[x]->xmlChildrenNode;
|
| 144 |
+
xmlChar *href = xmlNodeListGetString(doc, node, 1);
|
| 145 |
+
if(follow_relative_links) {
|
| 146 |
+
xmlChar *orig = href;
|
| 147 |
+
href = xmlBuildURI(href, (xmlChar *) url);
|
| 148 |
+
xmlFree(orig);
|
| 149 |
+
}
|
| 150 |
+
char *link = (char *) href;
|
| 151 |
+
if(!link || strlen(link) < 20)
|
| 152 |
+
continue;
|
| 153 |
+
if(!strncmp(link, "http://", 7) || !strncmp(link, "https://", 8)) {
|
| 154 |
+
curl_multi_add_handle(multi_handle, make_handle(link));
|
| 155 |
+
if(count++ == max_link_per_page)
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
xmlFree(link);
|
| 159 |
+
}
|
| 160 |
+
xmlXPathFreeObject(result);
|
| 161 |
+
return count;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
int is_html(char *ctype)
|
| 165 |
+
{
|
| 166 |
+
return ctype != NULL && strlen(ctype) > 10 && strstr(ctype, "text/html");
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
int main(void)
|
| 170 |
+
{
|
| 171 |
+
signal(SIGINT, sighandler);
|
| 172 |
+
LIBXML_TEST_VERSION;
|
| 173 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 174 |
+
CURLM *multi_handle = curl_multi_init();
|
| 175 |
+
curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, max_con);
|
| 176 |
+
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 6L);
|
| 177 |
+
|
| 178 |
+
/* enables http/2 if available */
|
| 179 |
+
#ifdef CURLPIPE_MULTIPLEX
|
| 180 |
+
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
| 181 |
+
#endif
|
| 182 |
+
|
| 183 |
+
/* sets html start page */
|
| 184 |
+
curl_multi_add_handle(multi_handle, make_handle(start_page));
|
| 185 |
+
|
| 186 |
+
int msgs_left;
|
| 187 |
+
int pending = 0;
|
| 188 |
+
int complete = 0;
|
| 189 |
+
int still_running = 1;
|
| 190 |
+
while(still_running && !pending_interrupt) {
|
| 191 |
+
int numfds;
|
| 192 |
+
curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
| 193 |
+
curl_multi_perform(multi_handle, &still_running);
|
| 194 |
+
|
| 195 |
+
/* See how the transfers went */
|
| 196 |
+
CURLMsg *m = NULL;
|
| 197 |
+
while((m = curl_multi_info_read(multi_handle, &msgs_left))) {
|
| 198 |
+
if(m->msg == CURLMSG_DONE) {
|
| 199 |
+
CURL *handle = m->easy_handle;
|
| 200 |
+
char *url;
|
| 201 |
+
memory *mem;
|
| 202 |
+
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &mem);
|
| 203 |
+
curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
|
| 204 |
+
if(m->data.result == CURLE_OK) {
|
| 205 |
+
long res_status;
|
| 206 |
+
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &res_status);
|
| 207 |
+
if(res_status == 200) {
|
| 208 |
+
char *ctype;
|
| 209 |
+
curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, &ctype);
|
| 210 |
+
printf("[%d] HTTP 200 (%s): %s\n", complete, ctype, url);
|
| 211 |
+
if(is_html(ctype) && mem->size > 100) {
|
| 212 |
+
if(pending < max_requests && (complete + pending) < max_total) {
|
| 213 |
+
pending += follow_links(multi_handle, mem, url);
|
| 214 |
+
still_running = 1;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
else {
|
| 219 |
+
printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url);
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
else {
|
| 223 |
+
printf("[%d] Connection failure: %s\n", complete, url);
|
| 224 |
+
}
|
| 225 |
+
curl_multi_remove_handle(multi_handle, handle);
|
| 226 |
+
curl_easy_cleanup(handle);
|
| 227 |
+
free(mem->buf);
|
| 228 |
+
free(mem);
|
| 229 |
+
complete++;
|
| 230 |
+
pending--;
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
}
|
| 234 |
+
curl_multi_cleanup(multi_handle);
|
| 235 |
+
curl_global_cleanup();
|
| 236 |
+
return 0;
|
| 237 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/debug.c
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Show how CURLOPT_DEBUGFUNCTION can be used.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
struct data {
|
| 32 |
+
char trace_ascii; /* 1 or 0 */
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
static
|
| 36 |
+
void dump(const char *text,
|
| 37 |
+
FILE *stream, unsigned char *ptr, size_t size,
|
| 38 |
+
char nohex)
|
| 39 |
+
{
|
| 40 |
+
size_t i;
|
| 41 |
+
size_t c;
|
| 42 |
+
|
| 43 |
+
unsigned int width = 0x10;
|
| 44 |
+
|
| 45 |
+
if(nohex)
|
| 46 |
+
/* without the hex output, we can fit more on screen */
|
| 47 |
+
width = 0x40;
|
| 48 |
+
|
| 49 |
+
fprintf(stream, "%s, %10.10lu bytes (0x%8.8lx)\n",
|
| 50 |
+
text, (unsigned long)size, (unsigned long)size);
|
| 51 |
+
|
| 52 |
+
for(i = 0; i < size; i += width) {
|
| 53 |
+
|
| 54 |
+
fprintf(stream, "%4.4lx: ", (unsigned long)i);
|
| 55 |
+
|
| 56 |
+
if(!nohex) {
|
| 57 |
+
/* hex not disabled, show it */
|
| 58 |
+
for(c = 0; c < width; c++)
|
| 59 |
+
if(i + c < size)
|
| 60 |
+
fprintf(stream, "%02x ", ptr[i + c]);
|
| 61 |
+
else
|
| 62 |
+
fputs(" ", stream);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
for(c = 0; (c < width) && (i + c < size); c++) {
|
| 66 |
+
/* check for 0D0A; if found, skip past and start a new line of output */
|
| 67 |
+
if(nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D &&
|
| 68 |
+
ptr[i + c + 1] == 0x0A) {
|
| 69 |
+
i += (c + 2 - width);
|
| 70 |
+
break;
|
| 71 |
+
}
|
| 72 |
+
fprintf(stream, "%c",
|
| 73 |
+
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
|
| 74 |
+
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
| 75 |
+
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
|
| 76 |
+
ptr[i + c + 2] == 0x0A) {
|
| 77 |
+
i += (c + 3 - width);
|
| 78 |
+
break;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
fputc('\n', stream); /* newline */
|
| 82 |
+
}
|
| 83 |
+
fflush(stream);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
static
|
| 87 |
+
int my_trace(CURL *handle, curl_infotype type,
|
| 88 |
+
char *data, size_t size,
|
| 89 |
+
void *userp)
|
| 90 |
+
{
|
| 91 |
+
struct data *config = (struct data *)userp;
|
| 92 |
+
const char *text;
|
| 93 |
+
(void)handle; /* prevent compiler warning */
|
| 94 |
+
|
| 95 |
+
switch(type) {
|
| 96 |
+
case CURLINFO_TEXT:
|
| 97 |
+
fprintf(stderr, "== Info: %s", data);
|
| 98 |
+
return 0;
|
| 99 |
+
case CURLINFO_HEADER_OUT:
|
| 100 |
+
text = "=> Send header";
|
| 101 |
+
break;
|
| 102 |
+
case CURLINFO_DATA_OUT:
|
| 103 |
+
text = "=> Send data";
|
| 104 |
+
break;
|
| 105 |
+
case CURLINFO_SSL_DATA_OUT:
|
| 106 |
+
text = "=> Send SSL data";
|
| 107 |
+
break;
|
| 108 |
+
case CURLINFO_HEADER_IN:
|
| 109 |
+
text = "<= Recv header";
|
| 110 |
+
break;
|
| 111 |
+
case CURLINFO_DATA_IN:
|
| 112 |
+
text = "<= Recv data";
|
| 113 |
+
break;
|
| 114 |
+
case CURLINFO_SSL_DATA_IN:
|
| 115 |
+
text = "<= Recv SSL data";
|
| 116 |
+
break;
|
| 117 |
+
default: /* in case a new one is introduced to shock us */
|
| 118 |
+
return 0;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
|
| 122 |
+
return 0;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
int main(void)
|
| 126 |
+
{
|
| 127 |
+
CURL *curl;
|
| 128 |
+
CURLcode res;
|
| 129 |
+
struct data config;
|
| 130 |
+
|
| 131 |
+
config.trace_ascii = 1; /* enable ASCII tracing */
|
| 132 |
+
|
| 133 |
+
curl = curl_easy_init();
|
| 134 |
+
if(curl) {
|
| 135 |
+
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
| 136 |
+
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
|
| 137 |
+
|
| 138 |
+
/* the DEBUGFUNCTION has no effect until we enable VERBOSE */
|
| 139 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 140 |
+
|
| 141 |
+
/* example.com is redirected, so we tell libcurl to follow redirection */
|
| 142 |
+
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
| 143 |
+
|
| 144 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
|
| 145 |
+
res = curl_easy_perform(curl);
|
| 146 |
+
/* Check for errors */
|
| 147 |
+
if(res != CURLE_OK)
|
| 148 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 149 |
+
curl_easy_strerror(res));
|
| 150 |
+
|
| 151 |
+
/* always cleanup */
|
| 152 |
+
curl_easy_cleanup(curl);
|
| 153 |
+
}
|
| 154 |
+
return 0;
|
| 155 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/default-scheme.c
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Change default scheme when none is provided in the URL
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl = curl_easy_init();
|
| 37 |
+
if(curl) {
|
| 38 |
+
curl_easy_setopt(curl, CURLOPT_URL, "example.com");
|
| 39 |
+
|
| 40 |
+
/* Change the default protocol (scheme) for schemeless URLs from plain
|
| 41 |
+
"http" to use a secure one instead. */
|
| 42 |
+
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
|
| 43 |
+
|
| 44 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 45 |
+
|
| 46 |
+
/* Perform the request, res gets the return code */
|
| 47 |
+
res = curl_easy_perform(curl);
|
| 48 |
+
/* Check for errors */
|
| 49 |
+
if(res != CURLE_OK)
|
| 50 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 51 |
+
curl_easy_strerror(res));
|
| 52 |
+
|
| 53 |
+
/* always cleanup */
|
| 54 |
+
curl_easy_cleanup(curl);
|
| 55 |
+
}
|
| 56 |
+
return 0;
|
| 57 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ephiperfifo.c
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* multi socket API usage with epoll and timerfd
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
/* Example application source code using the multi socket interface to
|
| 29 |
+
* download many files at once.
|
| 30 |
+
*
|
| 31 |
+
* This example features the same basic functionality as hiperfifo.c does,
|
| 32 |
+
* but this uses epoll and timerfd instead of libevent.
|
| 33 |
+
*
|
| 34 |
+
* Written by Jeff Pohlmeyer, converted to use epoll by Josh Bialkowski
|
| 35 |
+
|
| 36 |
+
Requires a Linux system with epoll
|
| 37 |
+
|
| 38 |
+
When running, the program creates the named pipe "hiper.fifo"
|
| 39 |
+
|
| 40 |
+
Whenever there is input into the fifo, the program reads the input as a list
|
| 41 |
+
of URL's and creates some new easy handles to fetch each URL via the
|
| 42 |
+
curl_multi "hiper" API.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Thus, you can try a single URL:
|
| 46 |
+
% echo http://www.yahoo.com > hiper.fifo
|
| 47 |
+
|
| 48 |
+
Or a whole bunch of them:
|
| 49 |
+
% cat my-url-list > hiper.fifo
|
| 50 |
+
|
| 51 |
+
The fifo buffer is handled almost instantly, so you can even add more URL's
|
| 52 |
+
while the previous requests are still being downloaded.
|
| 53 |
+
|
| 54 |
+
Note:
|
| 55 |
+
For the sake of simplicity, URL length is limited to 1023 char's !
|
| 56 |
+
|
| 57 |
+
This is purely a demo app, all retrieved data is simply discarded by the write
|
| 58 |
+
callback.
|
| 59 |
+
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
#include <errno.h>
|
| 63 |
+
#include <fcntl.h>
|
| 64 |
+
#include <signal.h>
|
| 65 |
+
#include <stdio.h>
|
| 66 |
+
#include <stdlib.h>
|
| 67 |
+
#include <string.h>
|
| 68 |
+
#include <sys/epoll.h>
|
| 69 |
+
#include <sys/stat.h>
|
| 70 |
+
#include <sys/time.h>
|
| 71 |
+
#include <sys/timerfd.h>
|
| 72 |
+
#include <sys/types.h>
|
| 73 |
+
#include <time.h>
|
| 74 |
+
#include <unistd.h>
|
| 75 |
+
|
| 76 |
+
#include <curl/curl.h>
|
| 77 |
+
|
| 78 |
+
#define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
/* Global information, common to all connections */
|
| 82 |
+
typedef struct _GlobalInfo
|
| 83 |
+
{
|
| 84 |
+
int epfd; /* epoll filedescriptor */
|
| 85 |
+
int tfd; /* timer filedescriptor */
|
| 86 |
+
int fifofd; /* fifo filedescriptor */
|
| 87 |
+
CURLM *multi;
|
| 88 |
+
int still_running;
|
| 89 |
+
FILE *input;
|
| 90 |
+
} GlobalInfo;
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
/* Information associated with a specific easy handle */
|
| 94 |
+
typedef struct _ConnInfo
|
| 95 |
+
{
|
| 96 |
+
CURL *easy;
|
| 97 |
+
char *url;
|
| 98 |
+
GlobalInfo *global;
|
| 99 |
+
char error[CURL_ERROR_SIZE];
|
| 100 |
+
} ConnInfo;
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
/* Information associated with a specific socket */
|
| 104 |
+
typedef struct _SockInfo
|
| 105 |
+
{
|
| 106 |
+
curl_socket_t sockfd;
|
| 107 |
+
CURL *easy;
|
| 108 |
+
int action;
|
| 109 |
+
long timeout;
|
| 110 |
+
GlobalInfo *global;
|
| 111 |
+
} SockInfo;
|
| 112 |
+
|
| 113 |
+
#define mycase(code) \
|
| 114 |
+
case code: s = __STRING(code)
|
| 115 |
+
|
| 116 |
+
/* Die if we get a bad CURLMcode somewhere */
|
| 117 |
+
static void mcode_or_die(const char *where, CURLMcode code)
|
| 118 |
+
{
|
| 119 |
+
if(CURLM_OK != code) {
|
| 120 |
+
const char *s;
|
| 121 |
+
switch(code) {
|
| 122 |
+
mycase(CURLM_BAD_HANDLE); break;
|
| 123 |
+
mycase(CURLM_BAD_EASY_HANDLE); break;
|
| 124 |
+
mycase(CURLM_OUT_OF_MEMORY); break;
|
| 125 |
+
mycase(CURLM_INTERNAL_ERROR); break;
|
| 126 |
+
mycase(CURLM_UNKNOWN_OPTION); break;
|
| 127 |
+
mycase(CURLM_LAST); break;
|
| 128 |
+
default: s = "CURLM_unknown"; break;
|
| 129 |
+
mycase(CURLM_BAD_SOCKET);
|
| 130 |
+
fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s);
|
| 131 |
+
/* ignore this error */
|
| 132 |
+
return;
|
| 133 |
+
}
|
| 134 |
+
fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s);
|
| 135 |
+
exit(code);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
static void timer_cb(GlobalInfo* g, int revents);
|
| 140 |
+
|
| 141 |
+
/* Update the timer after curl_multi library does its thing. Curl informs the
|
| 142 |
+
* application through this callback what it wants the new timeout to be,
|
| 143 |
+
* after it does some work. */
|
| 144 |
+
static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
|
| 145 |
+
{
|
| 146 |
+
struct itimerspec its;
|
| 147 |
+
|
| 148 |
+
fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms);
|
| 149 |
+
|
| 150 |
+
if(timeout_ms > 0) {
|
| 151 |
+
its.it_interval.tv_sec = 0;
|
| 152 |
+
its.it_interval.tv_nsec = 0;
|
| 153 |
+
its.it_value.tv_sec = timeout_ms / 1000;
|
| 154 |
+
its.it_value.tv_nsec = (timeout_ms % 1000) * 1000 * 1000;
|
| 155 |
+
}
|
| 156 |
+
else if(timeout_ms == 0) {
|
| 157 |
+
/* libcurl wants us to timeout now, however setting both fields of
|
| 158 |
+
* new_value.it_value to zero disarms the timer. The closest we can
|
| 159 |
+
* do is to schedule the timer to fire in 1 ns. */
|
| 160 |
+
its.it_interval.tv_sec = 0;
|
| 161 |
+
its.it_interval.tv_nsec = 0;
|
| 162 |
+
its.it_value.tv_sec = 0;
|
| 163 |
+
its.it_value.tv_nsec = 1;
|
| 164 |
+
}
|
| 165 |
+
else {
|
| 166 |
+
memset(&its, 0, sizeof(struct itimerspec));
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
timerfd_settime(g->tfd, /* flags= */0, &its, NULL);
|
| 170 |
+
return 0;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
/* Check for completed transfers, and remove their easy handles */
|
| 175 |
+
static void check_multi_info(GlobalInfo *g)
|
| 176 |
+
{
|
| 177 |
+
char *eff_url;
|
| 178 |
+
CURLMsg *msg;
|
| 179 |
+
int msgs_left;
|
| 180 |
+
ConnInfo *conn;
|
| 181 |
+
CURL *easy;
|
| 182 |
+
CURLcode res;
|
| 183 |
+
|
| 184 |
+
fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
|
| 185 |
+
while((msg = curl_multi_info_read(g->multi, &msgs_left))) {
|
| 186 |
+
if(msg->msg == CURLMSG_DONE) {
|
| 187 |
+
easy = msg->easy_handle;
|
| 188 |
+
res = msg->data.result;
|
| 189 |
+
curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
|
| 190 |
+
curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
|
| 191 |
+
fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
|
| 192 |
+
curl_multi_remove_handle(g->multi, easy);
|
| 193 |
+
free(conn->url);
|
| 194 |
+
curl_easy_cleanup(easy);
|
| 195 |
+
free(conn);
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/* Called by libevent when we get action on a multi socket filedescriptor */
|
| 201 |
+
static void event_cb(GlobalInfo *g, int fd, int revents)
|
| 202 |
+
{
|
| 203 |
+
CURLMcode rc;
|
| 204 |
+
struct itimerspec its;
|
| 205 |
+
|
| 206 |
+
int action = ((revents & EPOLLIN) ? CURL_CSELECT_IN : 0) |
|
| 207 |
+
((revents & EPOLLOUT) ? CURL_CSELECT_OUT : 0);
|
| 208 |
+
|
| 209 |
+
rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
|
| 210 |
+
mcode_or_die("event_cb: curl_multi_socket_action", rc);
|
| 211 |
+
|
| 212 |
+
check_multi_info(g);
|
| 213 |
+
if(g->still_running <= 0) {
|
| 214 |
+
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
|
| 215 |
+
memset(&its, 0, sizeof(struct itimerspec));
|
| 216 |
+
timerfd_settime(g->tfd, 0, &its, NULL);
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/* Called by main loop when our timeout expires */
|
| 221 |
+
static void timer_cb(GlobalInfo* g, int revents)
|
| 222 |
+
{
|
| 223 |
+
CURLMcode rc;
|
| 224 |
+
uint64_t count = 0;
|
| 225 |
+
ssize_t err = 0;
|
| 226 |
+
|
| 227 |
+
err = read(g->tfd, &count, sizeof(uint64_t));
|
| 228 |
+
if(err == -1) {
|
| 229 |
+
/* Note that we may call the timer callback even if the timerfd is not
|
| 230 |
+
* readable. It's possible that there are multiple events stored in the
|
| 231 |
+
* epoll buffer (i.e. the timer may have fired multiple times). The event
|
| 232 |
+
* count is cleared after the first call so future events in the epoll
|
| 233 |
+
* buffer fails to read from the timer. */
|
| 234 |
+
if(errno == EAGAIN) {
|
| 235 |
+
fprintf(MSG_OUT, "EAGAIN on tfd %d\n", g->tfd);
|
| 236 |
+
return;
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
if(err != sizeof(uint64_t)) {
|
| 240 |
+
fprintf(stderr, "read(tfd) == %ld", err);
|
| 241 |
+
perror("read(tfd)");
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
rc = curl_multi_socket_action(g->multi,
|
| 245 |
+
CURL_SOCKET_TIMEOUT, 0, &g->still_running);
|
| 246 |
+
mcode_or_die("timer_cb: curl_multi_socket_action", rc);
|
| 247 |
+
check_multi_info(g);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
/* Clean up the SockInfo structure */
|
| 253 |
+
static void remsock(SockInfo *f, GlobalInfo* g)
|
| 254 |
+
{
|
| 255 |
+
if(f) {
|
| 256 |
+
if(f->sockfd) {
|
| 257 |
+
if(epoll_ctl(g->epfd, EPOLL_CTL_DEL, f->sockfd, NULL))
|
| 258 |
+
fprintf(stderr, "EPOLL_CTL_DEL failed for fd: %d : %s\n",
|
| 259 |
+
f->sockfd, strerror(errno));
|
| 260 |
+
}
|
| 261 |
+
free(f);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
/* Assign information to a SockInfo structure */
|
| 268 |
+
static void setsock(SockInfo *f, curl_socket_t s, CURL *e, int act,
|
| 269 |
+
GlobalInfo *g)
|
| 270 |
+
{
|
| 271 |
+
struct epoll_event ev;
|
| 272 |
+
int kind = ((act & CURL_POLL_IN) ? EPOLLIN : 0) |
|
| 273 |
+
((act & CURL_POLL_OUT) ? EPOLLOUT : 0);
|
| 274 |
+
|
| 275 |
+
if(f->sockfd) {
|
| 276 |
+
if(epoll_ctl(g->epfd, EPOLL_CTL_DEL, f->sockfd, NULL))
|
| 277 |
+
fprintf(stderr, "EPOLL_CTL_DEL failed for fd: %d : %s\n",
|
| 278 |
+
f->sockfd, strerror(errno));
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
f->sockfd = s;
|
| 282 |
+
f->action = act;
|
| 283 |
+
f->easy = e;
|
| 284 |
+
|
| 285 |
+
ev.events = kind;
|
| 286 |
+
ev.data.fd = s;
|
| 287 |
+
if(epoll_ctl(g->epfd, EPOLL_CTL_ADD, s, &ev))
|
| 288 |
+
fprintf(stderr, "EPOLL_CTL_ADD failed for fd: %d : %s\n",
|
| 289 |
+
s, strerror(errno));
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
/* Initialize a new SockInfo structure */
|
| 295 |
+
static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
|
| 296 |
+
{
|
| 297 |
+
SockInfo *fdp = (SockInfo*)calloc(1, sizeof(SockInfo));
|
| 298 |
+
|
| 299 |
+
fdp->global = g;
|
| 300 |
+
setsock(fdp, s, easy, action, g);
|
| 301 |
+
curl_multi_assign(g->multi, s, fdp);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/* CURLMOPT_SOCKETFUNCTION */
|
| 305 |
+
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
|
| 306 |
+
{
|
| 307 |
+
GlobalInfo *g = (GlobalInfo*) cbp;
|
| 308 |
+
SockInfo *fdp = (SockInfo*) sockp;
|
| 309 |
+
const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" };
|
| 310 |
+
|
| 311 |
+
fprintf(MSG_OUT,
|
| 312 |
+
"socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
|
| 313 |
+
if(what == CURL_POLL_REMOVE) {
|
| 314 |
+
fprintf(MSG_OUT, "\n");
|
| 315 |
+
remsock(fdp, g);
|
| 316 |
+
}
|
| 317 |
+
else {
|
| 318 |
+
if(!fdp) {
|
| 319 |
+
fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]);
|
| 320 |
+
addsock(s, e, what, g);
|
| 321 |
+
}
|
| 322 |
+
else {
|
| 323 |
+
fprintf(MSG_OUT,
|
| 324 |
+
"Changing action from %s to %s\n",
|
| 325 |
+
whatstr[fdp->action], whatstr[what]);
|
| 326 |
+
setsock(fdp, s, e, what, g);
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
return 0;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
/* CURLOPT_WRITEFUNCTION */
|
| 335 |
+
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)
|
| 336 |
+
{
|
| 337 |
+
(void)ptr;
|
| 338 |
+
(void)data;
|
| 339 |
+
return size * nmemb;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
/* CURLOPT_PROGRESSFUNCTION */
|
| 344 |
+
static int prog_cb(void *p, double dltotal, double dlnow, double ult,
|
| 345 |
+
double uln)
|
| 346 |
+
{
|
| 347 |
+
ConnInfo *conn = (ConnInfo *)p;
|
| 348 |
+
(void)ult;
|
| 349 |
+
(void)uln;
|
| 350 |
+
|
| 351 |
+
fprintf(MSG_OUT, "Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal);
|
| 352 |
+
return 0;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
/* Create a new easy handle, and add it to the global curl_multi */
|
| 357 |
+
static void new_conn(char *url, GlobalInfo *g)
|
| 358 |
+
{
|
| 359 |
+
ConnInfo *conn;
|
| 360 |
+
CURLMcode rc;
|
| 361 |
+
|
| 362 |
+
conn = (ConnInfo*)calloc(1, sizeof(ConnInfo));
|
| 363 |
+
conn->error[0]='\0';
|
| 364 |
+
|
| 365 |
+
conn->easy = curl_easy_init();
|
| 366 |
+
if(!conn->easy) {
|
| 367 |
+
fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n");
|
| 368 |
+
exit(2);
|
| 369 |
+
}
|
| 370 |
+
conn->global = g;
|
| 371 |
+
conn->url = strdup(url);
|
| 372 |
+
curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url);
|
| 373 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
|
| 374 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, conn);
|
| 375 |
+
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1L);
|
| 376 |
+
curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error);
|
| 377 |
+
curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
|
| 378 |
+
curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0L);
|
| 379 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb);
|
| 380 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn);
|
| 381 |
+
curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1L);
|
| 382 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L);
|
| 383 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 10L);
|
| 384 |
+
fprintf(MSG_OUT,
|
| 385 |
+
"Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
|
| 386 |
+
rc = curl_multi_add_handle(g->multi, conn->easy);
|
| 387 |
+
mcode_or_die("new_conn: curl_multi_add_handle", rc);
|
| 388 |
+
|
| 389 |
+
/* note that the add_handle() sets a timeout to trigger soon so that the
|
| 390 |
+
* necessary socket_action() call gets called by this app */
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
/* This gets called whenever data is received from the fifo */
|
| 394 |
+
static void fifo_cb(GlobalInfo* g, int revents)
|
| 395 |
+
{
|
| 396 |
+
char s[1024];
|
| 397 |
+
long int rv = 0;
|
| 398 |
+
int n = 0;
|
| 399 |
+
|
| 400 |
+
do {
|
| 401 |
+
s[0]='\0';
|
| 402 |
+
rv = fscanf(g->input, "%1023s%n", s, &n);
|
| 403 |
+
s[n]='\0';
|
| 404 |
+
if(n && s[0]) {
|
| 405 |
+
new_conn(s, g); /* if we read a URL, go get it! */
|
| 406 |
+
}
|
| 407 |
+
else
|
| 408 |
+
break;
|
| 409 |
+
} while(rv != EOF);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
/* Create a named pipe and tell libevent to monitor it */
|
| 413 |
+
static const char *fifo = "hiper.fifo";
|
| 414 |
+
static int init_fifo(GlobalInfo *g)
|
| 415 |
+
{
|
| 416 |
+
struct stat st;
|
| 417 |
+
curl_socket_t sockfd;
|
| 418 |
+
struct epoll_event epev;
|
| 419 |
+
|
| 420 |
+
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
| 421 |
+
if(lstat (fifo, &st) == 0) {
|
| 422 |
+
if((st.st_mode & S_IFMT) == S_IFREG) {
|
| 423 |
+
errno = EEXIST;
|
| 424 |
+
perror("lstat");
|
| 425 |
+
exit(1);
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
unlink(fifo);
|
| 429 |
+
if(mkfifo (fifo, 0600) == -1) {
|
| 430 |
+
perror("mkfifo");
|
| 431 |
+
exit(1);
|
| 432 |
+
}
|
| 433 |
+
sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0);
|
| 434 |
+
if(sockfd == -1) {
|
| 435 |
+
perror("open");
|
| 436 |
+
exit(1);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
g->fifofd = sockfd;
|
| 440 |
+
g->input = fdopen(sockfd, "r");
|
| 441 |
+
|
| 442 |
+
epev.events = EPOLLIN;
|
| 443 |
+
epev.data.fd = sockfd;
|
| 444 |
+
epoll_ctl(g->epfd, EPOLL_CTL_ADD, sockfd, &epev);
|
| 445 |
+
|
| 446 |
+
fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo);
|
| 447 |
+
return 0;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
static void clean_fifo(GlobalInfo *g)
|
| 451 |
+
{
|
| 452 |
+
epoll_ctl(g->epfd, EPOLL_CTL_DEL, g->fifofd, NULL);
|
| 453 |
+
fclose(g->input);
|
| 454 |
+
unlink(fifo);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
int g_should_exit_ = 0;
|
| 459 |
+
|
| 460 |
+
void sigint_handler(int signo)
|
| 461 |
+
{
|
| 462 |
+
g_should_exit_ = 1;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
int main(int argc, char **argv)
|
| 466 |
+
{
|
| 467 |
+
GlobalInfo g;
|
| 468 |
+
struct itimerspec its;
|
| 469 |
+
struct epoll_event ev;
|
| 470 |
+
struct epoll_event events[10];
|
| 471 |
+
(void)argc;
|
| 472 |
+
(void)argv;
|
| 473 |
+
|
| 474 |
+
g_should_exit_ = 0;
|
| 475 |
+
signal(SIGINT, sigint_handler);
|
| 476 |
+
|
| 477 |
+
memset(&g, 0, sizeof(GlobalInfo));
|
| 478 |
+
g.epfd = epoll_create1(EPOLL_CLOEXEC);
|
| 479 |
+
if(g.epfd == -1) {
|
| 480 |
+
perror("epoll_create1 failed");
|
| 481 |
+
exit(1);
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
g.tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
| 485 |
+
if(g.tfd == -1) {
|
| 486 |
+
perror("timerfd_create failed");
|
| 487 |
+
exit(1);
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
memset(&its, 0, sizeof(struct itimerspec));
|
| 491 |
+
its.it_interval.tv_sec = 0;
|
| 492 |
+
its.it_value.tv_sec = 1;
|
| 493 |
+
timerfd_settime(g.tfd, 0, &its, NULL);
|
| 494 |
+
|
| 495 |
+
ev.events = EPOLLIN;
|
| 496 |
+
ev.data.fd = g.tfd;
|
| 497 |
+
epoll_ctl(g.epfd, EPOLL_CTL_ADD, g.tfd, &ev);
|
| 498 |
+
|
| 499 |
+
init_fifo(&g);
|
| 500 |
+
g.multi = curl_multi_init();
|
| 501 |
+
|
| 502 |
+
/* setup the generic multi interface options we want */
|
| 503 |
+
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
| 504 |
+
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
|
| 505 |
+
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
|
| 506 |
+
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
|
| 507 |
+
|
| 508 |
+
/* we do not call any curl_multi_socket*() function yet as we have no handles
|
| 509 |
+
added! */
|
| 510 |
+
|
| 511 |
+
fprintf(MSG_OUT, "Entering wait loop\n");
|
| 512 |
+
fflush(MSG_OUT);
|
| 513 |
+
while(!g_should_exit_) {
|
| 514 |
+
int idx;
|
| 515 |
+
int err = epoll_wait(g.epfd, events,
|
| 516 |
+
sizeof(events)/sizeof(struct epoll_event), 10000);
|
| 517 |
+
if(err == -1) {
|
| 518 |
+
if(errno == EINTR) {
|
| 519 |
+
fprintf(MSG_OUT, "note: wait interrupted\n");
|
| 520 |
+
continue;
|
| 521 |
+
}
|
| 522 |
+
else {
|
| 523 |
+
perror("epoll_wait");
|
| 524 |
+
exit(1);
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
for(idx = 0; idx < err; ++idx) {
|
| 529 |
+
if(events[idx].data.fd == g.fifofd) {
|
| 530 |
+
fifo_cb(&g, events[idx].events);
|
| 531 |
+
}
|
| 532 |
+
else if(events[idx].data.fd == g.tfd) {
|
| 533 |
+
timer_cb(&g, events[idx].events);
|
| 534 |
+
}
|
| 535 |
+
else {
|
| 536 |
+
event_cb(&g, events[idx].data.fd, events[idx].events);
|
| 537 |
+
}
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
fprintf(MSG_OUT, "Exiting normally.\n");
|
| 542 |
+
fflush(MSG_OUT);
|
| 543 |
+
|
| 544 |
+
curl_multi_cleanup(g.multi);
|
| 545 |
+
clean_fifo(&g);
|
| 546 |
+
return 0;
|
| 547 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/evhiperfifo.c
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* multi socket interface together with libev
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
/* Example application source code using the multi socket interface to
|
| 29 |
+
* download many files at once.
|
| 30 |
+
*
|
| 31 |
+
* This example features the same basic functionality as hiperfifo.c does,
|
| 32 |
+
* but this uses libev instead of libevent.
|
| 33 |
+
*
|
| 34 |
+
* Written by Jeff Pohlmeyer, converted to use libev by Markus Koetter
|
| 35 |
+
|
| 36 |
+
Requires libev and a (POSIX?) system that has mkfifo().
|
| 37 |
+
|
| 38 |
+
This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c"
|
| 39 |
+
sample programs.
|
| 40 |
+
|
| 41 |
+
When running, the program creates the named pipe "hiper.fifo"
|
| 42 |
+
|
| 43 |
+
Whenever there is input into the fifo, the program reads the input as a list
|
| 44 |
+
of URL's and creates some new easy handles to fetch each URL via the
|
| 45 |
+
curl_multi "hiper" API.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Thus, you can try a single URL:
|
| 49 |
+
% echo http://www.yahoo.com > hiper.fifo
|
| 50 |
+
|
| 51 |
+
Or a whole bunch of them:
|
| 52 |
+
% cat my-url-list > hiper.fifo
|
| 53 |
+
|
| 54 |
+
The fifo buffer is handled almost instantly, so you can even add more URL's
|
| 55 |
+
while the previous requests are still being downloaded.
|
| 56 |
+
|
| 57 |
+
Note:
|
| 58 |
+
For the sake of simplicity, URL length is limited to 1023 char's !
|
| 59 |
+
|
| 60 |
+
This is purely a demo app, all retrieved data is simply discarded by the write
|
| 61 |
+
callback.
|
| 62 |
+
|
| 63 |
+
*/
|
| 64 |
+
|
| 65 |
+
#include <stdio.h>
|
| 66 |
+
#include <string.h>
|
| 67 |
+
#include <stdlib.h>
|
| 68 |
+
#include <sys/time.h>
|
| 69 |
+
#include <time.h>
|
| 70 |
+
#include <unistd.h>
|
| 71 |
+
#include <sys/poll.h>
|
| 72 |
+
#include <curl/curl.h>
|
| 73 |
+
#include <ev.h>
|
| 74 |
+
#include <fcntl.h>
|
| 75 |
+
#include <sys/stat.h>
|
| 76 |
+
#include <errno.h>
|
| 77 |
+
|
| 78 |
+
#define DPRINT(x...) printf(x)
|
| 79 |
+
|
| 80 |
+
#define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
/* Global information, common to all connections */
|
| 84 |
+
typedef struct _GlobalInfo
|
| 85 |
+
{
|
| 86 |
+
struct ev_loop *loop;
|
| 87 |
+
struct ev_io fifo_event;
|
| 88 |
+
struct ev_timer timer_event;
|
| 89 |
+
CURLM *multi;
|
| 90 |
+
int still_running;
|
| 91 |
+
FILE *input;
|
| 92 |
+
} GlobalInfo;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
/* Information associated with a specific easy handle */
|
| 96 |
+
typedef struct _ConnInfo
|
| 97 |
+
{
|
| 98 |
+
CURL *easy;
|
| 99 |
+
char *url;
|
| 100 |
+
GlobalInfo *global;
|
| 101 |
+
char error[CURL_ERROR_SIZE];
|
| 102 |
+
} ConnInfo;
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
/* Information associated with a specific socket */
|
| 106 |
+
typedef struct _SockInfo
|
| 107 |
+
{
|
| 108 |
+
curl_socket_t sockfd;
|
| 109 |
+
CURL *easy;
|
| 110 |
+
int action;
|
| 111 |
+
long timeout;
|
| 112 |
+
struct ev_io ev;
|
| 113 |
+
int evset;
|
| 114 |
+
GlobalInfo *global;
|
| 115 |
+
} SockInfo;
|
| 116 |
+
|
| 117 |
+
static void timer_cb(EV_P_ struct ev_timer *w, int revents);
|
| 118 |
+
|
| 119 |
+
/* Update the event timer after curl_multi library calls */
|
| 120 |
+
static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
|
| 121 |
+
{
|
| 122 |
+
DPRINT("%s %li\n", __PRETTY_FUNCTION__, timeout_ms);
|
| 123 |
+
ev_timer_stop(g->loop, &g->timer_event);
|
| 124 |
+
if(timeout_ms >= 0) {
|
| 125 |
+
/* -1 means delete, other values are timeout times in milliseconds */
|
| 126 |
+
double t = timeout_ms / 1000;
|
| 127 |
+
ev_timer_init(&g->timer_event, timer_cb, t, 0.);
|
| 128 |
+
ev_timer_start(g->loop, &g->timer_event);
|
| 129 |
+
}
|
| 130 |
+
return 0;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/* Die if we get a bad CURLMcode somewhere */
|
| 134 |
+
static void mcode_or_die(const char *where, CURLMcode code)
|
| 135 |
+
{
|
| 136 |
+
if(CURLM_OK != code) {
|
| 137 |
+
const char *s;
|
| 138 |
+
switch(code) {
|
| 139 |
+
case CURLM_BAD_HANDLE:
|
| 140 |
+
s = "CURLM_BAD_HANDLE";
|
| 141 |
+
break;
|
| 142 |
+
case CURLM_BAD_EASY_HANDLE:
|
| 143 |
+
s = "CURLM_BAD_EASY_HANDLE";
|
| 144 |
+
break;
|
| 145 |
+
case CURLM_OUT_OF_MEMORY:
|
| 146 |
+
s = "CURLM_OUT_OF_MEMORY";
|
| 147 |
+
break;
|
| 148 |
+
case CURLM_INTERNAL_ERROR:
|
| 149 |
+
s = "CURLM_INTERNAL_ERROR";
|
| 150 |
+
break;
|
| 151 |
+
case CURLM_UNKNOWN_OPTION:
|
| 152 |
+
s = "CURLM_UNKNOWN_OPTION";
|
| 153 |
+
break;
|
| 154 |
+
case CURLM_LAST:
|
| 155 |
+
s = "CURLM_LAST";
|
| 156 |
+
break;
|
| 157 |
+
default:
|
| 158 |
+
s = "CURLM_unknown";
|
| 159 |
+
break;
|
| 160 |
+
case CURLM_BAD_SOCKET:
|
| 161 |
+
s = "CURLM_BAD_SOCKET";
|
| 162 |
+
fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s);
|
| 163 |
+
/* ignore this error */
|
| 164 |
+
return;
|
| 165 |
+
}
|
| 166 |
+
fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s);
|
| 167 |
+
exit(code);
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
/* Check for completed transfers, and remove their easy handles */
|
| 174 |
+
static void check_multi_info(GlobalInfo *g)
|
| 175 |
+
{
|
| 176 |
+
char *eff_url;
|
| 177 |
+
CURLMsg *msg;
|
| 178 |
+
int msgs_left;
|
| 179 |
+
ConnInfo *conn;
|
| 180 |
+
CURL *easy;
|
| 181 |
+
CURLcode res;
|
| 182 |
+
|
| 183 |
+
fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
|
| 184 |
+
while((msg = curl_multi_info_read(g->multi, &msgs_left))) {
|
| 185 |
+
if(msg->msg == CURLMSG_DONE) {
|
| 186 |
+
easy = msg->easy_handle;
|
| 187 |
+
res = msg->data.result;
|
| 188 |
+
curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
|
| 189 |
+
curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
|
| 190 |
+
fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error);
|
| 191 |
+
curl_multi_remove_handle(g->multi, easy);
|
| 192 |
+
free(conn->url);
|
| 193 |
+
curl_easy_cleanup(easy);
|
| 194 |
+
free(conn);
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
/* Called by libevent when we get action on a multi socket */
|
| 202 |
+
static void event_cb(EV_P_ struct ev_io *w, int revents)
|
| 203 |
+
{
|
| 204 |
+
DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents);
|
| 205 |
+
GlobalInfo *g = (GlobalInfo*) w->data;
|
| 206 |
+
CURLMcode rc;
|
| 207 |
+
|
| 208 |
+
int action = ((revents & EV_READ) ? CURL_POLL_IN : 0) |
|
| 209 |
+
((revents & EV_WRITE) ? CURL_POLL_OUT : 0);
|
| 210 |
+
rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running);
|
| 211 |
+
mcode_or_die("event_cb: curl_multi_socket_action", rc);
|
| 212 |
+
check_multi_info(g);
|
| 213 |
+
if(g->still_running <= 0) {
|
| 214 |
+
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
|
| 215 |
+
ev_timer_stop(g->loop, &g->timer_event);
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/* Called by libevent when our timeout expires */
|
| 220 |
+
static void timer_cb(EV_P_ struct ev_timer *w, int revents)
|
| 221 |
+
{
|
| 222 |
+
DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents);
|
| 223 |
+
|
| 224 |
+
GlobalInfo *g = (GlobalInfo *)w->data;
|
| 225 |
+
CURLMcode rc;
|
| 226 |
+
|
| 227 |
+
rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0,
|
| 228 |
+
&g->still_running);
|
| 229 |
+
mcode_or_die("timer_cb: curl_multi_socket_action", rc);
|
| 230 |
+
check_multi_info(g);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/* Clean up the SockInfo structure */
|
| 234 |
+
static void remsock(SockInfo *f, GlobalInfo *g)
|
| 235 |
+
{
|
| 236 |
+
printf("%s \n", __PRETTY_FUNCTION__);
|
| 237 |
+
if(f) {
|
| 238 |
+
if(f->evset)
|
| 239 |
+
ev_io_stop(g->loop, &f->ev);
|
| 240 |
+
free(f);
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
/* Assign information to a SockInfo structure */
|
| 247 |
+
static void setsock(SockInfo *f, curl_socket_t s, CURL *e, int act,
|
| 248 |
+
GlobalInfo *g)
|
| 249 |
+
{
|
| 250 |
+
printf("%s \n", __PRETTY_FUNCTION__);
|
| 251 |
+
|
| 252 |
+
int kind = ((act & CURL_POLL_IN) ? EV_READ : 0) |
|
| 253 |
+
((act & CURL_POLL_OUT) ? EV_WRITE : 0);
|
| 254 |
+
|
| 255 |
+
f->sockfd = s;
|
| 256 |
+
f->action = act;
|
| 257 |
+
f->easy = e;
|
| 258 |
+
if(f->evset)
|
| 259 |
+
ev_io_stop(g->loop, &f->ev);
|
| 260 |
+
ev_io_init(&f->ev, event_cb, f->sockfd, kind);
|
| 261 |
+
f->ev.data = g;
|
| 262 |
+
f->evset = 1;
|
| 263 |
+
ev_io_start(g->loop, &f->ev);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
/* Initialize a new SockInfo structure */
|
| 269 |
+
static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
|
| 270 |
+
{
|
| 271 |
+
SockInfo *fdp = calloc(1, sizeof(SockInfo));
|
| 272 |
+
|
| 273 |
+
fdp->global = g;
|
| 274 |
+
setsock(fdp, s, easy, action, g);
|
| 275 |
+
curl_multi_assign(g->multi, s, fdp);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
/* CURLMOPT_SOCKETFUNCTION */
|
| 279 |
+
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
|
| 280 |
+
{
|
| 281 |
+
DPRINT("%s e %p s %i what %i cbp %p sockp %p\n",
|
| 282 |
+
__PRETTY_FUNCTION__, e, s, what, cbp, sockp);
|
| 283 |
+
|
| 284 |
+
GlobalInfo *g = (GlobalInfo*) cbp;
|
| 285 |
+
SockInfo *fdp = (SockInfo*) sockp;
|
| 286 |
+
const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"};
|
| 287 |
+
|
| 288 |
+
fprintf(MSG_OUT,
|
| 289 |
+
"socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
|
| 290 |
+
if(what == CURL_POLL_REMOVE) {
|
| 291 |
+
fprintf(MSG_OUT, "\n");
|
| 292 |
+
remsock(fdp, g);
|
| 293 |
+
}
|
| 294 |
+
else {
|
| 295 |
+
if(!fdp) {
|
| 296 |
+
fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]);
|
| 297 |
+
addsock(s, e, what, g);
|
| 298 |
+
}
|
| 299 |
+
else {
|
| 300 |
+
fprintf(MSG_OUT,
|
| 301 |
+
"Changing action from %s to %s\n",
|
| 302 |
+
whatstr[fdp->action], whatstr[what]);
|
| 303 |
+
setsock(fdp, s, e, what, g);
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
return 0;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
/* CURLOPT_WRITEFUNCTION */
|
| 311 |
+
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)
|
| 312 |
+
{
|
| 313 |
+
size_t realsize = size * nmemb;
|
| 314 |
+
ConnInfo *conn = (ConnInfo*) data;
|
| 315 |
+
(void)ptr;
|
| 316 |
+
(void)conn;
|
| 317 |
+
return realsize;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
/* CURLOPT_PROGRESSFUNCTION */
|
| 322 |
+
static int prog_cb(void *p, double dltotal, double dlnow, double ult,
|
| 323 |
+
double uln)
|
| 324 |
+
{
|
| 325 |
+
ConnInfo *conn = (ConnInfo *)p;
|
| 326 |
+
(void)ult;
|
| 327 |
+
(void)uln;
|
| 328 |
+
|
| 329 |
+
fprintf(MSG_OUT, "Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal);
|
| 330 |
+
return 0;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
/* Create a new easy handle, and add it to the global curl_multi */
|
| 335 |
+
static void new_conn(char *url, GlobalInfo *g)
|
| 336 |
+
{
|
| 337 |
+
ConnInfo *conn;
|
| 338 |
+
CURLMcode rc;
|
| 339 |
+
|
| 340 |
+
conn = calloc(1, sizeof(ConnInfo));
|
| 341 |
+
conn->error[0]='\0';
|
| 342 |
+
|
| 343 |
+
conn->easy = curl_easy_init();
|
| 344 |
+
if(!conn->easy) {
|
| 345 |
+
fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n");
|
| 346 |
+
exit(2);
|
| 347 |
+
}
|
| 348 |
+
conn->global = g;
|
| 349 |
+
conn->url = strdup(url);
|
| 350 |
+
curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url);
|
| 351 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
|
| 352 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, conn);
|
| 353 |
+
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1L);
|
| 354 |
+
curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error);
|
| 355 |
+
curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
|
| 356 |
+
curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0L);
|
| 357 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb);
|
| 358 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn);
|
| 359 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L);
|
| 360 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 10L);
|
| 361 |
+
|
| 362 |
+
fprintf(MSG_OUT,
|
| 363 |
+
"Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
|
| 364 |
+
rc = curl_multi_add_handle(g->multi, conn->easy);
|
| 365 |
+
mcode_or_die("new_conn: curl_multi_add_handle", rc);
|
| 366 |
+
|
| 367 |
+
/* note that add_handle() sets a timeout to trigger soon so that the
|
| 368 |
+
necessary socket_action() gets called */
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
/* This gets called whenever data is received from the fifo */
|
| 372 |
+
static void fifo_cb(EV_P_ struct ev_io *w, int revents)
|
| 373 |
+
{
|
| 374 |
+
char s[1024];
|
| 375 |
+
long int rv = 0;
|
| 376 |
+
int n = 0;
|
| 377 |
+
GlobalInfo *g = (GlobalInfo *)w->data;
|
| 378 |
+
|
| 379 |
+
do {
|
| 380 |
+
s[0]='\0';
|
| 381 |
+
rv = fscanf(g->input, "%1023s%n", s, &n);
|
| 382 |
+
s[n]='\0';
|
| 383 |
+
if(n && s[0]) {
|
| 384 |
+
new_conn(s, g); /* if we read a URL, go get it! */
|
| 385 |
+
}
|
| 386 |
+
else
|
| 387 |
+
break;
|
| 388 |
+
} while(rv != EOF);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
/* Create a named pipe and tell libevent to monitor it */
|
| 392 |
+
static int init_fifo(GlobalInfo *g)
|
| 393 |
+
{
|
| 394 |
+
struct stat st;
|
| 395 |
+
static const char *fifo = "hiper.fifo";
|
| 396 |
+
curl_socket_t sockfd;
|
| 397 |
+
|
| 398 |
+
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
| 399 |
+
if(lstat (fifo, &st) == 0) {
|
| 400 |
+
if((st.st_mode & S_IFMT) == S_IFREG) {
|
| 401 |
+
errno = EEXIST;
|
| 402 |
+
perror("lstat");
|
| 403 |
+
exit(1);
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
unlink(fifo);
|
| 407 |
+
if(mkfifo (fifo, 0600) == -1) {
|
| 408 |
+
perror("mkfifo");
|
| 409 |
+
exit(1);
|
| 410 |
+
}
|
| 411 |
+
sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0);
|
| 412 |
+
if(sockfd == -1) {
|
| 413 |
+
perror("open");
|
| 414 |
+
exit(1);
|
| 415 |
+
}
|
| 416 |
+
g->input = fdopen(sockfd, "r");
|
| 417 |
+
|
| 418 |
+
fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo);
|
| 419 |
+
ev_io_init(&g->fifo_event, fifo_cb, sockfd, EV_READ);
|
| 420 |
+
ev_io_start(g->loop, &g->fifo_event);
|
| 421 |
+
return (0);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
int main(int argc, char **argv)
|
| 425 |
+
{
|
| 426 |
+
GlobalInfo g;
|
| 427 |
+
(void)argc;
|
| 428 |
+
(void)argv;
|
| 429 |
+
|
| 430 |
+
memset(&g, 0, sizeof(GlobalInfo));
|
| 431 |
+
g.loop = ev_default_loop(0);
|
| 432 |
+
|
| 433 |
+
init_fifo(&g);
|
| 434 |
+
g.multi = curl_multi_init();
|
| 435 |
+
|
| 436 |
+
ev_timer_init(&g.timer_event, timer_cb, 0., 0.);
|
| 437 |
+
g.timer_event.data = &g;
|
| 438 |
+
g.fifo_event.data = &g;
|
| 439 |
+
curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
| 440 |
+
curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g);
|
| 441 |
+
curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb);
|
| 442 |
+
curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g);
|
| 443 |
+
|
| 444 |
+
/* we do not call any curl_multi_socket*() function yet as we have no handles
|
| 445 |
+
added! */
|
| 446 |
+
|
| 447 |
+
ev_loop(g.loop, 0);
|
| 448 |
+
curl_multi_cleanup(g.multi);
|
| 449 |
+
return 0;
|
| 450 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/externalsocket.c
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Pass in a custom socket for libcurl to use.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#ifdef _WIN32
|
| 29 |
+
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
|
| 30 |
+
#define _WINSOCK_DEPRECATED_NO_WARNINGS /* for inet_addr() */
|
| 31 |
+
#endif
|
| 32 |
+
#endif
|
| 33 |
+
|
| 34 |
+
#include <stdio.h>
|
| 35 |
+
#include <string.h>
|
| 36 |
+
#include <stdlib.h>
|
| 37 |
+
#include <curl/curl.h>
|
| 38 |
+
|
| 39 |
+
#ifdef _WIN32
|
| 40 |
+
#define close closesocket
|
| 41 |
+
#else
|
| 42 |
+
#include <sys/types.h> /* socket types */
|
| 43 |
+
#include <sys/socket.h> /* socket definitions */
|
| 44 |
+
#include <netinet/in.h>
|
| 45 |
+
#include <arpa/inet.h> /* inet (3) functions */
|
| 46 |
+
#include <unistd.h> /* misc. Unix functions */
|
| 47 |
+
#endif
|
| 48 |
+
|
| 49 |
+
#include <errno.h>
|
| 50 |
+
|
| 51 |
+
/* The IP address and port number to connect to */
|
| 52 |
+
#define IPADDR "127.0.0.1"
|
| 53 |
+
#define PORTNUM 80
|
| 54 |
+
|
| 55 |
+
#ifndef INADDR_NONE
|
| 56 |
+
#define INADDR_NONE 0xffffffff
|
| 57 |
+
#endif
|
| 58 |
+
|
| 59 |
+
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
| 60 |
+
{
|
| 61 |
+
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
|
| 62 |
+
return written;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
static int closecb(void *clientp, curl_socket_t item)
|
| 66 |
+
{
|
| 67 |
+
(void)clientp;
|
| 68 |
+
printf("libcurl wants to close %d now\n", (int)item);
|
| 69 |
+
return 0;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
static curl_socket_t opensocket(void *clientp,
|
| 73 |
+
curlsocktype purpose,
|
| 74 |
+
struct curl_sockaddr *address)
|
| 75 |
+
{
|
| 76 |
+
curl_socket_t sockfd;
|
| 77 |
+
(void)purpose;
|
| 78 |
+
(void)address;
|
| 79 |
+
sockfd = *(curl_socket_t *)clientp;
|
| 80 |
+
/* the actual externally set socket is passed in via the OPENSOCKETDATA
|
| 81 |
+
option */
|
| 82 |
+
return sockfd;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
static int sockopt_callback(void *clientp, curl_socket_t curlfd,
|
| 86 |
+
curlsocktype purpose)
|
| 87 |
+
{
|
| 88 |
+
(void)clientp;
|
| 89 |
+
(void)curlfd;
|
| 90 |
+
(void)purpose;
|
| 91 |
+
/* This return code was added in libcurl 7.21.5 */
|
| 92 |
+
return CURL_SOCKOPT_ALREADY_CONNECTED;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
int main(void)
|
| 96 |
+
{
|
| 97 |
+
CURL *curl;
|
| 98 |
+
CURLcode res;
|
| 99 |
+
struct sockaddr_in servaddr; /* socket address structure */
|
| 100 |
+
curl_socket_t sockfd;
|
| 101 |
+
|
| 102 |
+
#ifdef _WIN32
|
| 103 |
+
WSADATA wsaData;
|
| 104 |
+
int initwsa = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
| 105 |
+
if(initwsa) {
|
| 106 |
+
printf("WSAStartup failed: %d\n", initwsa);
|
| 107 |
+
return 1;
|
| 108 |
+
}
|
| 109 |
+
#endif
|
| 110 |
+
|
| 111 |
+
curl = curl_easy_init();
|
| 112 |
+
if(curl) {
|
| 113 |
+
/*
|
| 114 |
+
* Note that libcurl internally thinks that you connect to the host and
|
| 115 |
+
* port that you specify in the URL option.
|
| 116 |
+
*/
|
| 117 |
+
curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
|
| 118 |
+
|
| 119 |
+
/* Create the socket "manually" */
|
| 120 |
+
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
| 121 |
+
if(sockfd == CURL_SOCKET_BAD) {
|
| 122 |
+
printf("Error creating listening socket.\n");
|
| 123 |
+
return 3;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
memset(&servaddr, 0, sizeof(servaddr));
|
| 127 |
+
servaddr.sin_family = AF_INET;
|
| 128 |
+
servaddr.sin_port = htons(PORTNUM);
|
| 129 |
+
|
| 130 |
+
servaddr.sin_addr.s_addr = inet_addr(IPADDR);
|
| 131 |
+
if(INADDR_NONE == servaddr.sin_addr.s_addr) {
|
| 132 |
+
close(sockfd);
|
| 133 |
+
return 2;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) ==
|
| 137 |
+
-1) {
|
| 138 |
+
close(sockfd);
|
| 139 |
+
printf("client error: connect: %s\n", strerror(errno));
|
| 140 |
+
return 1;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* no progress meter please */
|
| 144 |
+
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
|
| 145 |
+
|
| 146 |
+
/* send all data to this function */
|
| 147 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
| 148 |
+
|
| 149 |
+
/* call this function to get a socket */
|
| 150 |
+
curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
|
| 151 |
+
curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
|
| 152 |
+
|
| 153 |
+
/* call this function to close sockets */
|
| 154 |
+
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closecb);
|
| 155 |
+
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
|
| 156 |
+
|
| 157 |
+
/* call this function to set options for the socket */
|
| 158 |
+
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
|
| 159 |
+
|
| 160 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
| 161 |
+
|
| 162 |
+
res = curl_easy_perform(curl);
|
| 163 |
+
|
| 164 |
+
curl_easy_cleanup(curl);
|
| 165 |
+
|
| 166 |
+
close(sockfd);
|
| 167 |
+
|
| 168 |
+
if(res) {
|
| 169 |
+
printf("libcurl error: %d\n", res);
|
| 170 |
+
return 4;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
#ifdef _WIN32
|
| 175 |
+
WSACleanup();
|
| 176 |
+
#endif
|
| 177 |
+
return 0;
|
| 178 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ftp-wildcard.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 |
+
/* <DESC>
|
| 25 |
+
* FTP wildcard pattern matching
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <curl/curl.h>
|
| 29 |
+
#include <stdio.h>
|
| 30 |
+
|
| 31 |
+
struct callback_data {
|
| 32 |
+
FILE *output;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
static long file_is_coming(struct curl_fileinfo *finfo,
|
| 36 |
+
struct callback_data *data,
|
| 37 |
+
int remains);
|
| 38 |
+
|
| 39 |
+
static long file_is_downloaded(struct callback_data *data);
|
| 40 |
+
|
| 41 |
+
static size_t write_it(char *buff, size_t size, size_t nmemb,
|
| 42 |
+
void *cb_data);
|
| 43 |
+
|
| 44 |
+
int main(int argc, char **argv)
|
| 45 |
+
{
|
| 46 |
+
/* curl easy handle */
|
| 47 |
+
CURL *handle;
|
| 48 |
+
|
| 49 |
+
/* help data */
|
| 50 |
+
struct callback_data data = { 0 };
|
| 51 |
+
|
| 52 |
+
/* global initialization */
|
| 53 |
+
CURLcode rc = curl_global_init(CURL_GLOBAL_ALL);
|
| 54 |
+
if(rc)
|
| 55 |
+
return (int)rc;
|
| 56 |
+
|
| 57 |
+
/* initialization of easy handle */
|
| 58 |
+
handle = curl_easy_init();
|
| 59 |
+
if(!handle) {
|
| 60 |
+
curl_global_cleanup();
|
| 61 |
+
return CURLE_OUT_OF_MEMORY;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/* turn on wildcard matching */
|
| 65 |
+
curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
|
| 66 |
+
|
| 67 |
+
/* callback is called before download of concrete file started */
|
| 68 |
+
curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
|
| 69 |
+
|
| 70 |
+
/* callback is called after data from the file have been transferred */
|
| 71 |
+
curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
|
| 72 |
+
|
| 73 |
+
/* this callback writes contents into files */
|
| 74 |
+
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_it);
|
| 75 |
+
|
| 76 |
+
/* put transfer data into callbacks */
|
| 77 |
+
curl_easy_setopt(handle, CURLOPT_CHUNK_DATA, &data);
|
| 78 |
+
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);
|
| 79 |
+
|
| 80 |
+
/* curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); */
|
| 81 |
+
|
| 82 |
+
/* set a URL containing wildcard pattern (only in the last part) */
|
| 83 |
+
if(argc == 2)
|
| 84 |
+
curl_easy_setopt(handle, CURLOPT_URL, argv[1]);
|
| 85 |
+
else
|
| 86 |
+
curl_easy_setopt(handle, CURLOPT_URL, "ftp://example.com/test/*");
|
| 87 |
+
|
| 88 |
+
/* and start transfer! */
|
| 89 |
+
rc = curl_easy_perform(handle);
|
| 90 |
+
|
| 91 |
+
curl_easy_cleanup(handle);
|
| 92 |
+
curl_global_cleanup();
|
| 93 |
+
return (int)rc;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
static long file_is_coming(struct curl_fileinfo *finfo,
|
| 97 |
+
struct callback_data *data,
|
| 98 |
+
int remains)
|
| 99 |
+
{
|
| 100 |
+
printf("%3d %40s %10luB ", remains, finfo->filename,
|
| 101 |
+
(unsigned long)finfo->size);
|
| 102 |
+
|
| 103 |
+
switch(finfo->filetype) {
|
| 104 |
+
case CURLFILETYPE_DIRECTORY:
|
| 105 |
+
printf(" DIR\n");
|
| 106 |
+
break;
|
| 107 |
+
case CURLFILETYPE_FILE:
|
| 108 |
+
printf("FILE ");
|
| 109 |
+
break;
|
| 110 |
+
default:
|
| 111 |
+
printf("OTHER\n");
|
| 112 |
+
break;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
if(finfo->filetype == CURLFILETYPE_FILE) {
|
| 116 |
+
/* do not transfer files >= 50B */
|
| 117 |
+
if(finfo->size > 50) {
|
| 118 |
+
printf("SKIPPED\n");
|
| 119 |
+
return CURL_CHUNK_BGN_FUNC_SKIP;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
data->output = fopen(finfo->filename, "wb");
|
| 123 |
+
if(!data->output) {
|
| 124 |
+
return CURL_CHUNK_BGN_FUNC_FAIL;
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
return CURL_CHUNK_BGN_FUNC_OK;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
static long file_is_downloaded(struct callback_data *data)
|
| 132 |
+
{
|
| 133 |
+
if(data->output) {
|
| 134 |
+
printf("DOWNLOADED\n");
|
| 135 |
+
fclose(data->output);
|
| 136 |
+
data->output = 0x0;
|
| 137 |
+
}
|
| 138 |
+
return CURL_CHUNK_END_FUNC_OK;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
static size_t write_it(char *buff, size_t size, size_t nmemb,
|
| 142 |
+
void *cb_data)
|
| 143 |
+
{
|
| 144 |
+
struct callback_data *data = cb_data;
|
| 145 |
+
size_t written = 0;
|
| 146 |
+
if(data->output)
|
| 147 |
+
written = fwrite(buff, size, nmemb, data->output);
|
| 148 |
+
else
|
| 149 |
+
/* listing output */
|
| 150 |
+
written = fwrite(buff, size, nmemb, stdout);
|
| 151 |
+
return written;
|
| 152 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ftpget.c
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#include <stdio.h>
|
| 25 |
+
|
| 26 |
+
#include <curl/curl.h>
|
| 27 |
+
|
| 28 |
+
/* <DESC>
|
| 29 |
+
* Get a single file from an FTP server.
|
| 30 |
+
* </DESC>
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
struct FtpFile {
|
| 34 |
+
const char *filename;
|
| 35 |
+
FILE *stream;
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
|
| 39 |
+
{
|
| 40 |
+
struct FtpFile *out = (struct FtpFile *)stream;
|
| 41 |
+
if(!out->stream) {
|
| 42 |
+
/* open file for writing */
|
| 43 |
+
out->stream = fopen(out->filename, "wb");
|
| 44 |
+
if(!out->stream)
|
| 45 |
+
return 0; /* failure, cannot open file to write */
|
| 46 |
+
}
|
| 47 |
+
return fwrite(buffer, size, nmemb, out->stream);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
int main(void)
|
| 52 |
+
{
|
| 53 |
+
CURL *curl;
|
| 54 |
+
CURLcode res;
|
| 55 |
+
struct FtpFile ftpfile = {
|
| 56 |
+
"curl.tar.gz", /* name to store the file as if successful */
|
| 57 |
+
NULL
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 61 |
+
|
| 62 |
+
curl = curl_easy_init();
|
| 63 |
+
if(curl) {
|
| 64 |
+
/*
|
| 65 |
+
* You better replace the URL with one that works!
|
| 66 |
+
*/
|
| 67 |
+
curl_easy_setopt(curl, CURLOPT_URL,
|
| 68 |
+
"ftp://ftp.example.com/curl/curl-7.9.2.tar.gz");
|
| 69 |
+
/* Define our callback to get called when there is data to be written */
|
| 70 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
| 71 |
+
/* Set a pointer to our struct to pass to the callback */
|
| 72 |
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
| 73 |
+
|
| 74 |
+
/* Switch on full protocol/debug output */
|
| 75 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 76 |
+
|
| 77 |
+
res = curl_easy_perform(curl);
|
| 78 |
+
|
| 79 |
+
/* always cleanup */
|
| 80 |
+
curl_easy_cleanup(curl);
|
| 81 |
+
|
| 82 |
+
if(CURLE_OK != res) {
|
| 83 |
+
/* we failed */
|
| 84 |
+
fprintf(stderr, "curl told us %d\n", res);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
if(ftpfile.stream)
|
| 89 |
+
fclose(ftpfile.stream); /* close the local file */
|
| 90 |
+
|
| 91 |
+
curl_global_cleanup();
|
| 92 |
+
|
| 93 |
+
return 0;
|
| 94 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ftpgetresp.c
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#include <stdio.h>
|
| 25 |
+
|
| 26 |
+
#include <curl/curl.h>
|
| 27 |
+
|
| 28 |
+
/* <DESC>
|
| 29 |
+
* Similar to ftpget.c but also stores the received response-lines
|
| 30 |
+
* in a separate file using our own callback!
|
| 31 |
+
* </DESC>
|
| 32 |
+
*/
|
| 33 |
+
static size_t
|
| 34 |
+
write_response(void *ptr, size_t size, size_t nmemb, void *data)
|
| 35 |
+
{
|
| 36 |
+
FILE *writehere = (FILE *)data;
|
| 37 |
+
return fwrite(ptr, size, nmemb, writehere);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#define FTPBODY "ftp-list"
|
| 41 |
+
#define FTPHEADERS "ftp-responses"
|
| 42 |
+
|
| 43 |
+
int main(void)
|
| 44 |
+
{
|
| 45 |
+
CURL *curl;
|
| 46 |
+
CURLcode res;
|
| 47 |
+
FILE *ftpfile;
|
| 48 |
+
FILE *respfile;
|
| 49 |
+
|
| 50 |
+
/* local filename to store the file as */
|
| 51 |
+
ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on Windows */
|
| 52 |
+
|
| 53 |
+
/* local filename to store the FTP server's response lines in */
|
| 54 |
+
respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on Windows */
|
| 55 |
+
|
| 56 |
+
curl = curl_easy_init();
|
| 57 |
+
if(curl) {
|
| 58 |
+
/* Get a file listing from sunet */
|
| 59 |
+
curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/");
|
| 60 |
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
|
| 61 |
+
/* If you intend to use this on Windows with a libcurl DLL, you must use
|
| 62 |
+
CURLOPT_WRITEFUNCTION as well */
|
| 63 |
+
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
|
| 64 |
+
curl_easy_setopt(curl, CURLOPT_HEADERDATA, respfile);
|
| 65 |
+
res = curl_easy_perform(curl);
|
| 66 |
+
/* Check for errors */
|
| 67 |
+
if(res != CURLE_OK)
|
| 68 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 69 |
+
curl_easy_strerror(res));
|
| 70 |
+
|
| 71 |
+
/* always cleanup */
|
| 72 |
+
curl_easy_cleanup(curl);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
fclose(ftpfile); /* close the local file */
|
| 76 |
+
fclose(respfile); /* close the response file */
|
| 77 |
+
|
| 78 |
+
return 0;
|
| 79 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ftpsget.c
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 <stdio.h>
|
| 26 |
+
|
| 27 |
+
#include <curl/curl.h>
|
| 28 |
+
|
| 29 |
+
/* <DESC>
|
| 30 |
+
* Get a single file from an FTPS server.
|
| 31 |
+
* </DESC>
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
struct FtpFile {
|
| 35 |
+
const char *filename;
|
| 36 |
+
FILE *stream;
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
|
| 40 |
+
void *stream)
|
| 41 |
+
{
|
| 42 |
+
struct FtpFile *out = (struct FtpFile *)stream;
|
| 43 |
+
if(!out->stream) {
|
| 44 |
+
/* open file for writing */
|
| 45 |
+
out->stream = fopen(out->filename, "wb");
|
| 46 |
+
if(!out->stream)
|
| 47 |
+
return 0; /* failure, cannot open file to write */
|
| 48 |
+
}
|
| 49 |
+
return fwrite(buffer, size, nmemb, out->stream);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
int main(void)
|
| 54 |
+
{
|
| 55 |
+
CURL *curl;
|
| 56 |
+
CURLcode res;
|
| 57 |
+
struct FtpFile ftpfile = {
|
| 58 |
+
"yourfile.bin", /* name to store the file as if successful */
|
| 59 |
+
NULL
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 63 |
+
|
| 64 |
+
curl = curl_easy_init();
|
| 65 |
+
if(curl) {
|
| 66 |
+
/*
|
| 67 |
+
* You better replace the URL with one that works! Note that we use an
|
| 68 |
+
* FTP:// URL with standard explicit FTPS. You can also do FTPS:// URLs if
|
| 69 |
+
* you want to do the rarer kind of transfers: implicit.
|
| 70 |
+
*/
|
| 71 |
+
curl_easy_setopt(curl, CURLOPT_URL,
|
| 72 |
+
"ftp://user@server/home/user/file.txt");
|
| 73 |
+
/* Define our callback to get called when there is data to be written */
|
| 74 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
| 75 |
+
/* Set a pointer to our struct to pass to the callback */
|
| 76 |
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
| 77 |
+
|
| 78 |
+
/* We activate SSL and we require it for both control and data */
|
| 79 |
+
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
| 80 |
+
|
| 81 |
+
/* Switch on full protocol/debug output */
|
| 82 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 83 |
+
|
| 84 |
+
res = curl_easy_perform(curl);
|
| 85 |
+
|
| 86 |
+
/* always cleanup */
|
| 87 |
+
curl_easy_cleanup(curl);
|
| 88 |
+
|
| 89 |
+
if(CURLE_OK != res) {
|
| 90 |
+
/* we failed */
|
| 91 |
+
fprintf(stderr, "curl told us %d\n", res);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if(ftpfile.stream)
|
| 96 |
+
fclose(ftpfile.stream); /* close the local file */
|
| 97 |
+
|
| 98 |
+
curl_global_cleanup();
|
| 99 |
+
|
| 100 |
+
return 0;
|
| 101 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ftpuploadresume.c
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Upload to FTP, resuming failed transfers. Active mode.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
|
| 29 |
+
#include <stdlib.h>
|
| 30 |
+
#include <stdio.h>
|
| 31 |
+
#include <curl/curl.h>
|
| 32 |
+
|
| 33 |
+
/* parse headers for Content-Length */
|
| 34 |
+
static size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb,
|
| 35 |
+
void *stream)
|
| 36 |
+
{
|
| 37 |
+
int r;
|
| 38 |
+
long len = 0;
|
| 39 |
+
|
| 40 |
+
r = sscanf(ptr, "Content-Length: %ld\n", &len);
|
| 41 |
+
if(r)
|
| 42 |
+
*((long *) stream) = len;
|
| 43 |
+
|
| 44 |
+
return size * nmemb;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* discard downloaded data */
|
| 48 |
+
static size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream)
|
| 49 |
+
{
|
| 50 |
+
(void)ptr;
|
| 51 |
+
(void)stream;
|
| 52 |
+
return size * nmemb;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* read data to upload */
|
| 56 |
+
static size_t readfunc(char *ptr, size_t size, size_t nmemb, void *stream)
|
| 57 |
+
{
|
| 58 |
+
FILE *f = stream;
|
| 59 |
+
size_t n;
|
| 60 |
+
|
| 61 |
+
if(ferror(f))
|
| 62 |
+
return CURL_READFUNC_ABORT;
|
| 63 |
+
|
| 64 |
+
n = fread(ptr, size, nmemb, f) * size;
|
| 65 |
+
|
| 66 |
+
return n;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
static int upload(CURL *curlhandle, const char *remotepath,
|
| 71 |
+
const char *localpath, long timeout, long tries)
|
| 72 |
+
{
|
| 73 |
+
FILE *f;
|
| 74 |
+
long uploaded_len = 0;
|
| 75 |
+
CURLcode r = CURLE_GOT_NOTHING;
|
| 76 |
+
int c;
|
| 77 |
+
|
| 78 |
+
f = fopen(localpath, "rb");
|
| 79 |
+
if(!f) {
|
| 80 |
+
perror(NULL);
|
| 81 |
+
return 0;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L);
|
| 85 |
+
|
| 86 |
+
curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath);
|
| 87 |
+
|
| 88 |
+
if(timeout)
|
| 89 |
+
curl_easy_setopt(curlhandle, CURLOPT_SERVER_RESPONSE_TIMEOUT, timeout);
|
| 90 |
+
|
| 91 |
+
curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc);
|
| 92 |
+
curl_easy_setopt(curlhandle, CURLOPT_HEADERDATA, &uploaded_len);
|
| 93 |
+
|
| 94 |
+
curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, discardfunc);
|
| 95 |
+
|
| 96 |
+
curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
|
| 97 |
+
curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
|
| 98 |
+
|
| 99 |
+
/* enable active mode */
|
| 100 |
+
curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-");
|
| 101 |
+
|
| 102 |
+
/* allow the server no more than 7 seconds to connect back */
|
| 103 |
+
curl_easy_setopt(curlhandle, CURLOPT_ACCEPTTIMEOUT_MS, 7000L);
|
| 104 |
+
|
| 105 |
+
curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
|
| 106 |
+
|
| 107 |
+
curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L);
|
| 108 |
+
|
| 109 |
+
for(c = 0; (r != CURLE_OK) && (c < tries); c++) {
|
| 110 |
+
/* are we resuming? */
|
| 111 |
+
if(c) { /* yes */
|
| 112 |
+
/* determine the length of the file already written */
|
| 113 |
+
|
| 114 |
+
/*
|
| 115 |
+
* With NOBODY and NOHEADER, libcurl issues a SIZE command, but the only
|
| 116 |
+
* way to retrieve the result is to parse the returned Content-Length
|
| 117 |
+
* header. Thus, getcontentlengthfunc(). We need discardfunc() above
|
| 118 |
+
* because HEADER dumps the headers to stdout without it.
|
| 119 |
+
*/
|
| 120 |
+
curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1L);
|
| 121 |
+
curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L);
|
| 122 |
+
|
| 123 |
+
r = curl_easy_perform(curlhandle);
|
| 124 |
+
if(r != CURLE_OK)
|
| 125 |
+
continue;
|
| 126 |
+
|
| 127 |
+
curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L);
|
| 128 |
+
curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0L);
|
| 129 |
+
|
| 130 |
+
fseek(f, uploaded_len, SEEK_SET);
|
| 131 |
+
|
| 132 |
+
curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1L);
|
| 133 |
+
}
|
| 134 |
+
else { /* no */
|
| 135 |
+
curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0L);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
r = curl_easy_perform(curlhandle);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
fclose(f);
|
| 142 |
+
|
| 143 |
+
if(r == CURLE_OK)
|
| 144 |
+
return 1;
|
| 145 |
+
else {
|
| 146 |
+
fprintf(stderr, "%s\n", curl_easy_strerror(r));
|
| 147 |
+
return 0;
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
int main(void)
|
| 152 |
+
{
|
| 153 |
+
CURL *curlhandle = NULL;
|
| 154 |
+
|
| 155 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 156 |
+
curlhandle = curl_easy_init();
|
| 157 |
+
|
| 158 |
+
upload(curlhandle, "ftp://user:[email protected]/path/file", "C:\\file",
|
| 159 |
+
0, 3);
|
| 160 |
+
|
| 161 |
+
curl_easy_cleanup(curlhandle);
|
| 162 |
+
curl_global_cleanup();
|
| 163 |
+
|
| 164 |
+
return 0;
|
| 165 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/getinfo.c
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Use getinfo to get content-type after completed transfer.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl = curl_easy_init();
|
| 37 |
+
if(curl) {
|
| 38 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
| 39 |
+
res = curl_easy_perform(curl);
|
| 40 |
+
|
| 41 |
+
if(CURLE_OK == res) {
|
| 42 |
+
char *ct;
|
| 43 |
+
/* ask for the content-type */
|
| 44 |
+
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
|
| 45 |
+
|
| 46 |
+
if((CURLE_OK == res) && ct)
|
| 47 |
+
printf("We received Content-Type: %s\n", ct);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* always cleanup */
|
| 51 |
+
curl_easy_cleanup(curl);
|
| 52 |
+
}
|
| 53 |
+
return 0;
|
| 54 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/getinmemory.c
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Shows how the write callback function can be used to download data into a
|
| 26 |
+
* chunk of memory instead of storing it in a file.
|
| 27 |
+
* </DESC>
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
#include <stdio.h>
|
| 31 |
+
#include <stdlib.h>
|
| 32 |
+
#include <string.h>
|
| 33 |
+
|
| 34 |
+
#include <curl/curl.h>
|
| 35 |
+
|
| 36 |
+
struct MemoryStruct {
|
| 37 |
+
char *memory;
|
| 38 |
+
size_t size;
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
static size_t
|
| 42 |
+
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
| 43 |
+
{
|
| 44 |
+
size_t realsize = size * nmemb;
|
| 45 |
+
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
|
| 46 |
+
|
| 47 |
+
char *ptr = realloc(mem->memory, mem->size + realsize + 1);
|
| 48 |
+
if(!ptr) {
|
| 49 |
+
/* out of memory! */
|
| 50 |
+
printf("not enough memory (realloc returned NULL)\n");
|
| 51 |
+
return 0;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
mem->memory = ptr;
|
| 55 |
+
memcpy(&(mem->memory[mem->size]), contents, realsize);
|
| 56 |
+
mem->size += realsize;
|
| 57 |
+
mem->memory[mem->size] = 0;
|
| 58 |
+
|
| 59 |
+
return realsize;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
int main(void)
|
| 63 |
+
{
|
| 64 |
+
CURL *curl_handle;
|
| 65 |
+
CURLcode res;
|
| 66 |
+
|
| 67 |
+
struct MemoryStruct chunk;
|
| 68 |
+
|
| 69 |
+
chunk.memory = malloc(1); /* grown as needed by the realloc above */
|
| 70 |
+
chunk.size = 0; /* no data at this point */
|
| 71 |
+
|
| 72 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 73 |
+
|
| 74 |
+
/* init the curl session */
|
| 75 |
+
curl_handle = curl_easy_init();
|
| 76 |
+
|
| 77 |
+
/* specify URL to get */
|
| 78 |
+
curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.example.com/");
|
| 79 |
+
|
| 80 |
+
/* send all data to this function */
|
| 81 |
+
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
| 82 |
+
|
| 83 |
+
/* we pass our 'chunk' struct to the callback function */
|
| 84 |
+
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
| 85 |
+
|
| 86 |
+
/* some servers do not like requests that are made without a user-agent
|
| 87 |
+
field, so we provide one */
|
| 88 |
+
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
| 89 |
+
|
| 90 |
+
/* get it! */
|
| 91 |
+
res = curl_easy_perform(curl_handle);
|
| 92 |
+
|
| 93 |
+
/* check for errors */
|
| 94 |
+
if(res != CURLE_OK) {
|
| 95 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 96 |
+
curl_easy_strerror(res));
|
| 97 |
+
}
|
| 98 |
+
else {
|
| 99 |
+
/*
|
| 100 |
+
* Now, our chunk.memory points to a memory block that is chunk.size
|
| 101 |
+
* bytes big and contains the remote file.
|
| 102 |
+
*
|
| 103 |
+
* Do something nice with it!
|
| 104 |
+
*/
|
| 105 |
+
|
| 106 |
+
printf("%lu bytes retrieved\n", (unsigned long)chunk.size);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* cleanup curl stuff */
|
| 110 |
+
curl_easy_cleanup(curl_handle);
|
| 111 |
+
|
| 112 |
+
free(chunk.memory);
|
| 113 |
+
|
| 114 |
+
/* we are done with libcurl, so clean it up */
|
| 115 |
+
curl_global_cleanup();
|
| 116 |
+
|
| 117 |
+
return 0;
|
| 118 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/getredirect.c
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Show how to extract Location: header and URL to redirect to.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
char *location;
|
| 36 |
+
long response_code;
|
| 37 |
+
|
| 38 |
+
curl = curl_easy_init();
|
| 39 |
+
if(curl) {
|
| 40 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
| 41 |
+
|
| 42 |
+
/* example.com is redirected, figure out the redirection! */
|
| 43 |
+
|
| 44 |
+
/* Perform the request, res gets the return code */
|
| 45 |
+
res = curl_easy_perform(curl);
|
| 46 |
+
/* Check for errors */
|
| 47 |
+
if(res != CURLE_OK)
|
| 48 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 49 |
+
curl_easy_strerror(res));
|
| 50 |
+
else {
|
| 51 |
+
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
|
| 52 |
+
if((res == CURLE_OK) &&
|
| 53 |
+
((response_code / 100) != 3)) {
|
| 54 |
+
/* a redirect implies a 3xx response code */
|
| 55 |
+
fprintf(stderr, "Not a redirect.\n");
|
| 56 |
+
}
|
| 57 |
+
else {
|
| 58 |
+
res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &location);
|
| 59 |
+
|
| 60 |
+
if((res == CURLE_OK) && location) {
|
| 61 |
+
/* This is the new absolute URL that you could redirect to, even if
|
| 62 |
+
* the Location: response header may have been a relative URL. */
|
| 63 |
+
printf("Redirected to: %s\n", location);
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/* always cleanup */
|
| 69 |
+
curl_easy_cleanup(curl);
|
| 70 |
+
}
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/getreferrer.c
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Show how to extract referrer header.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
|
| 35 |
+
curl = curl_easy_init();
|
| 36 |
+
if(curl) {
|
| 37 |
+
CURLcode res;
|
| 38 |
+
|
| 39 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
| 40 |
+
curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
|
| 41 |
+
|
| 42 |
+
/* Perform the request, res gets the return code */
|
| 43 |
+
res = curl_easy_perform(curl);
|
| 44 |
+
/* Check for errors */
|
| 45 |
+
if(res != CURLE_OK)
|
| 46 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 47 |
+
curl_easy_strerror(res));
|
| 48 |
+
else {
|
| 49 |
+
char *hdr;
|
| 50 |
+
res = curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr);
|
| 51 |
+
if((res == CURLE_OK) && hdr)
|
| 52 |
+
printf("Referrer header: %s\n", hdr);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* always cleanup */
|
| 56 |
+
curl_easy_cleanup(curl);
|
| 57 |
+
}
|
| 58 |
+
return 0;
|
| 59 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/ghiper.c
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* multi socket API usage together with glib2
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
/* Example application source code using the multi socket interface to
|
| 29 |
+
* download many files at once.
|
| 30 |
+
*
|
| 31 |
+
* Written by Jeff Pohlmeyer
|
| 32 |
+
|
| 33 |
+
Requires glib-2.x and a (POSIX?) system that has mkfifo().
|
| 34 |
+
|
| 35 |
+
This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c"
|
| 36 |
+
sample programs, adapted to use glib's g_io_channel in place of libevent.
|
| 37 |
+
|
| 38 |
+
When running, the program creates the named pipe "hiper.fifo"
|
| 39 |
+
|
| 40 |
+
Whenever there is input into the fifo, the program reads the input as a list
|
| 41 |
+
of URL's and creates some new easy handles to fetch each URL via the
|
| 42 |
+
curl_multi "hiper" API.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Thus, you can try a single URL:
|
| 46 |
+
% echo http://www.yahoo.com > hiper.fifo
|
| 47 |
+
|
| 48 |
+
Or a whole bunch of them:
|
| 49 |
+
% cat my-url-list > hiper.fifo
|
| 50 |
+
|
| 51 |
+
The fifo buffer is handled almost instantly, so you can even add more URL's
|
| 52 |
+
while the previous requests are still being downloaded.
|
| 53 |
+
|
| 54 |
+
This is purely a demo app, all retrieved data is simply discarded by the write
|
| 55 |
+
callback.
|
| 56 |
+
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
#include <glib.h>
|
| 60 |
+
#include <sys/stat.h>
|
| 61 |
+
#include <unistd.h>
|
| 62 |
+
#include <fcntl.h>
|
| 63 |
+
#include <stdlib.h>
|
| 64 |
+
#include <stdio.h>
|
| 65 |
+
#include <errno.h>
|
| 66 |
+
#include <curl/curl.h>
|
| 67 |
+
|
| 68 |
+
#define MSG_OUT g_print /* Change to "g_error" to write to stderr */
|
| 69 |
+
#define SHOW_VERBOSE 0 /* Set to non-zero for libcurl messages */
|
| 70 |
+
#define SHOW_PROGRESS 0 /* Set to non-zero to enable progress callback */
|
| 71 |
+
|
| 72 |
+
/* Global information, common to all connections */
|
| 73 |
+
typedef struct _GlobalInfo {
|
| 74 |
+
CURLM *multi;
|
| 75 |
+
guint timer_event;
|
| 76 |
+
int still_running;
|
| 77 |
+
} GlobalInfo;
|
| 78 |
+
|
| 79 |
+
/* Information associated with a specific easy handle */
|
| 80 |
+
typedef struct _ConnInfo {
|
| 81 |
+
CURL *easy;
|
| 82 |
+
char *url;
|
| 83 |
+
GlobalInfo *global;
|
| 84 |
+
char error[CURL_ERROR_SIZE];
|
| 85 |
+
} ConnInfo;
|
| 86 |
+
|
| 87 |
+
/* Information associated with a specific socket */
|
| 88 |
+
typedef struct _SockInfo {
|
| 89 |
+
curl_socket_t sockfd;
|
| 90 |
+
CURL *easy;
|
| 91 |
+
int action;
|
| 92 |
+
long timeout;
|
| 93 |
+
GIOChannel *ch;
|
| 94 |
+
guint ev;
|
| 95 |
+
GlobalInfo *global;
|
| 96 |
+
} SockInfo;
|
| 97 |
+
|
| 98 |
+
/* Die if we get a bad CURLMcode somewhere */
|
| 99 |
+
static void mcode_or_die(const char *where, CURLMcode code)
|
| 100 |
+
{
|
| 101 |
+
if(CURLM_OK != code) {
|
| 102 |
+
const char *s;
|
| 103 |
+
switch(code) {
|
| 104 |
+
case CURLM_BAD_HANDLE: s = "CURLM_BAD_HANDLE"; break;
|
| 105 |
+
case CURLM_BAD_EASY_HANDLE: s = "CURLM_BAD_EASY_HANDLE"; break;
|
| 106 |
+
case CURLM_OUT_OF_MEMORY: s = "CURLM_OUT_OF_MEMORY"; break;
|
| 107 |
+
case CURLM_INTERNAL_ERROR: s = "CURLM_INTERNAL_ERROR"; break;
|
| 108 |
+
case CURLM_BAD_SOCKET: s = "CURLM_BAD_SOCKET"; break;
|
| 109 |
+
case CURLM_UNKNOWN_OPTION: s = "CURLM_UNKNOWN_OPTION"; break;
|
| 110 |
+
case CURLM_LAST: s = "CURLM_LAST"; break;
|
| 111 |
+
default: s = "CURLM_unknown";
|
| 112 |
+
}
|
| 113 |
+
MSG_OUT("ERROR: %s returns %s\n", where, s);
|
| 114 |
+
exit(code);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/* Check for completed transfers, and remove their easy handles */
|
| 119 |
+
static void check_multi_info(GlobalInfo *g)
|
| 120 |
+
{
|
| 121 |
+
char *eff_url;
|
| 122 |
+
CURLMsg *msg;
|
| 123 |
+
int msgs_left;
|
| 124 |
+
ConnInfo *conn;
|
| 125 |
+
CURL *easy;
|
| 126 |
+
CURLcode res;
|
| 127 |
+
|
| 128 |
+
MSG_OUT("REMAINING: %d\n", g->still_running);
|
| 129 |
+
while((msg = curl_multi_info_read(g->multi, &msgs_left))) {
|
| 130 |
+
if(msg->msg == CURLMSG_DONE) {
|
| 131 |
+
easy = msg->easy_handle;
|
| 132 |
+
res = msg->data.result;
|
| 133 |
+
curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
|
| 134 |
+
curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);
|
| 135 |
+
MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error);
|
| 136 |
+
curl_multi_remove_handle(g->multi, easy);
|
| 137 |
+
free(conn->url);
|
| 138 |
+
curl_easy_cleanup(easy);
|
| 139 |
+
free(conn);
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* Called by glib when our timeout expires */
|
| 145 |
+
static gboolean timer_cb(gpointer data)
|
| 146 |
+
{
|
| 147 |
+
GlobalInfo *g = (GlobalInfo *)data;
|
| 148 |
+
CURLMcode rc;
|
| 149 |
+
|
| 150 |
+
rc = curl_multi_socket_action(g->multi,
|
| 151 |
+
CURL_SOCKET_TIMEOUT, 0, &g->still_running);
|
| 152 |
+
mcode_or_die("timer_cb: curl_multi_socket_action", rc);
|
| 153 |
+
check_multi_info(g);
|
| 154 |
+
return FALSE;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* Update the event timer after curl_multi library calls */
|
| 158 |
+
static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp)
|
| 159 |
+
{
|
| 160 |
+
struct timeval timeout;
|
| 161 |
+
GlobalInfo *g = (GlobalInfo *)userp;
|
| 162 |
+
timeout.tv_sec = timeout_ms/1000;
|
| 163 |
+
timeout.tv_usec = (timeout_ms%1000)*1000;
|
| 164 |
+
|
| 165 |
+
MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n",
|
| 166 |
+
timeout_ms, timeout.tv_sec, timeout.tv_usec);
|
| 167 |
+
|
| 168 |
+
/*
|
| 169 |
+
* if timeout_ms is -1, just delete the timer
|
| 170 |
+
*
|
| 171 |
+
* For other values of timeout_ms, this should set or *update* the timer to
|
| 172 |
+
* the new value
|
| 173 |
+
*/
|
| 174 |
+
if(timeout_ms >= 0)
|
| 175 |
+
g->timer_event = g_timeout_add(timeout_ms, timer_cb, g);
|
| 176 |
+
return 0;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* Called by glib when we get action on a multi socket */
|
| 180 |
+
static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
|
| 181 |
+
{
|
| 182 |
+
GlobalInfo *g = (GlobalInfo*) data;
|
| 183 |
+
CURLMcode rc;
|
| 184 |
+
int fd = g_io_channel_unix_get_fd(ch);
|
| 185 |
+
|
| 186 |
+
int action =
|
| 187 |
+
((condition & G_IO_IN) ? CURL_CSELECT_IN : 0) |
|
| 188 |
+
((condition & G_IO_OUT) ? CURL_CSELECT_OUT : 0);
|
| 189 |
+
|
| 190 |
+
rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running);
|
| 191 |
+
mcode_or_die("event_cb: curl_multi_socket_action", rc);
|
| 192 |
+
|
| 193 |
+
check_multi_info(g);
|
| 194 |
+
if(g->still_running) {
|
| 195 |
+
return TRUE;
|
| 196 |
+
}
|
| 197 |
+
else {
|
| 198 |
+
MSG_OUT("last transfer done, kill timeout\n");
|
| 199 |
+
if(g->timer_event) {
|
| 200 |
+
g_source_remove(g->timer_event);
|
| 201 |
+
}
|
| 202 |
+
return FALSE;
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* Clean up the SockInfo structure */
|
| 207 |
+
static void remsock(SockInfo *f)
|
| 208 |
+
{
|
| 209 |
+
if(!f) {
|
| 210 |
+
return;
|
| 211 |
+
}
|
| 212 |
+
if(f->ev) {
|
| 213 |
+
g_source_remove(f->ev);
|
| 214 |
+
}
|
| 215 |
+
g_free(f);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/* Assign information to a SockInfo structure */
|
| 219 |
+
static void setsock(SockInfo *f, curl_socket_t s, CURL *e, int act,
|
| 220 |
+
GlobalInfo *g)
|
| 221 |
+
{
|
| 222 |
+
GIOCondition kind =
|
| 223 |
+
((act & CURL_POLL_IN) ? G_IO_IN : 0) |
|
| 224 |
+
((act & CURL_POLL_OUT) ? G_IO_OUT : 0);
|
| 225 |
+
|
| 226 |
+
f->sockfd = s;
|
| 227 |
+
f->action = act;
|
| 228 |
+
f->easy = e;
|
| 229 |
+
if(f->ev) {
|
| 230 |
+
g_source_remove(f->ev);
|
| 231 |
+
}
|
| 232 |
+
f->ev = g_io_add_watch(f->ch, kind, event_cb, g);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
/* Initialize a new SockInfo structure */
|
| 236 |
+
static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
|
| 237 |
+
{
|
| 238 |
+
SockInfo *fdp = g_malloc0(sizeof(SockInfo));
|
| 239 |
+
|
| 240 |
+
fdp->global = g;
|
| 241 |
+
fdp->ch = g_io_channel_unix_new(s);
|
| 242 |
+
setsock(fdp, s, easy, action, g);
|
| 243 |
+
curl_multi_assign(g->multi, s, fdp);
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/* CURLMOPT_SOCKETFUNCTION */
|
| 247 |
+
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
|
| 248 |
+
{
|
| 249 |
+
GlobalInfo *g = (GlobalInfo*) cbp;
|
| 250 |
+
SockInfo *fdp = (SockInfo*) sockp;
|
| 251 |
+
static const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" };
|
| 252 |
+
|
| 253 |
+
MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
|
| 254 |
+
if(what == CURL_POLL_REMOVE) {
|
| 255 |
+
MSG_OUT("\n");
|
| 256 |
+
remsock(fdp);
|
| 257 |
+
}
|
| 258 |
+
else {
|
| 259 |
+
if(!fdp) {
|
| 260 |
+
MSG_OUT("Adding data: %s%s\n",
|
| 261 |
+
(what & CURL_POLL_IN) ? "READ" : "",
|
| 262 |
+
(what & CURL_POLL_OUT) ? "WRITE" : "");
|
| 263 |
+
addsock(s, e, what, g);
|
| 264 |
+
}
|
| 265 |
+
else {
|
| 266 |
+
MSG_OUT(
|
| 267 |
+
"Changing action from %d to %d\n", fdp->action, what);
|
| 268 |
+
setsock(fdp, s, e, what, g);
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
return 0;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/* CURLOPT_WRITEFUNCTION */
|
| 275 |
+
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)
|
| 276 |
+
{
|
| 277 |
+
size_t realsize = size * nmemb;
|
| 278 |
+
ConnInfo *conn = (ConnInfo*) data;
|
| 279 |
+
(void)ptr;
|
| 280 |
+
(void)conn;
|
| 281 |
+
return realsize;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
/* CURLOPT_PROGRESSFUNCTION */
|
| 285 |
+
static int prog_cb(void *p, double dltotal, double dlnow, double ult,
|
| 286 |
+
double uln)
|
| 287 |
+
{
|
| 288 |
+
ConnInfo *conn = (ConnInfo *)p;
|
| 289 |
+
MSG_OUT("Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal);
|
| 290 |
+
return 0;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
/* Create a new easy handle, and add it to the global curl_multi */
|
| 294 |
+
static void new_conn(char *url, GlobalInfo *g)
|
| 295 |
+
{
|
| 296 |
+
ConnInfo *conn;
|
| 297 |
+
CURLMcode rc;
|
| 298 |
+
|
| 299 |
+
conn = g_malloc0(sizeof(ConnInfo));
|
| 300 |
+
conn->error[0]='\0';
|
| 301 |
+
conn->easy = curl_easy_init();
|
| 302 |
+
if(!conn->easy) {
|
| 303 |
+
MSG_OUT("curl_easy_init() failed, exiting!\n");
|
| 304 |
+
exit(2);
|
| 305 |
+
}
|
| 306 |
+
conn->global = g;
|
| 307 |
+
conn->url = g_strdup(url);
|
| 308 |
+
curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url);
|
| 309 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
|
| 310 |
+
curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn);
|
| 311 |
+
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, (long)SHOW_VERBOSE);
|
| 312 |
+
curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error);
|
| 313 |
+
curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
|
| 314 |
+
curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS ? 0L : 1L);
|
| 315 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb);
|
| 316 |
+
curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn);
|
| 317 |
+
curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1L);
|
| 318 |
+
curl_easy_setopt(conn->easy, CURLOPT_CONNECTTIMEOUT, 30L);
|
| 319 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 1L);
|
| 320 |
+
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 30L);
|
| 321 |
+
|
| 322 |
+
MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url);
|
| 323 |
+
rc = curl_multi_add_handle(g->multi, conn->easy);
|
| 324 |
+
mcode_or_die("new_conn: curl_multi_add_handle", rc);
|
| 325 |
+
|
| 326 |
+
/* note that add_handle() sets a timeout to trigger soon so that the
|
| 327 |
+
necessary socket_action() gets called */
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/* This gets called by glib whenever data is received from the fifo */
|
| 331 |
+
static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
|
| 332 |
+
{
|
| 333 |
+
#define BUF_SIZE 1024
|
| 334 |
+
gsize len, tp;
|
| 335 |
+
gchar *buf, *tmp, *all = NULL;
|
| 336 |
+
GIOStatus rv;
|
| 337 |
+
|
| 338 |
+
do {
|
| 339 |
+
GError *err = NULL;
|
| 340 |
+
rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err);
|
| 341 |
+
if(buf) {
|
| 342 |
+
if(tp) {
|
| 343 |
+
buf[tp]='\0';
|
| 344 |
+
}
|
| 345 |
+
new_conn(buf, (GlobalInfo*)data);
|
| 346 |
+
g_free(buf);
|
| 347 |
+
}
|
| 348 |
+
else {
|
| 349 |
+
buf = g_malloc(BUF_SIZE + 1);
|
| 350 |
+
while(TRUE) {
|
| 351 |
+
buf[BUF_SIZE]='\0';
|
| 352 |
+
g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err);
|
| 353 |
+
if(len) {
|
| 354 |
+
buf[len]='\0';
|
| 355 |
+
if(all) {
|
| 356 |
+
tmp = all;
|
| 357 |
+
all = g_strdup_printf("%s%s", tmp, buf);
|
| 358 |
+
g_free(tmp);
|
| 359 |
+
}
|
| 360 |
+
else {
|
| 361 |
+
all = g_strdup(buf);
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
else {
|
| 365 |
+
break;
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
if(all) {
|
| 369 |
+
new_conn(all, (GlobalInfo*)data);
|
| 370 |
+
g_free(all);
|
| 371 |
+
}
|
| 372 |
+
g_free(buf);
|
| 373 |
+
}
|
| 374 |
+
if(err) {
|
| 375 |
+
g_error("fifo_cb: %s", err->message);
|
| 376 |
+
g_free(err);
|
| 377 |
+
break;
|
| 378 |
+
}
|
| 379 |
+
} while((len) && (rv == G_IO_STATUS_NORMAL));
|
| 380 |
+
return TRUE;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
int init_fifo(void)
|
| 384 |
+
{
|
| 385 |
+
struct stat st;
|
| 386 |
+
const char *fifo = "hiper.fifo";
|
| 387 |
+
int socket;
|
| 388 |
+
|
| 389 |
+
if(lstat (fifo, &st) == 0) {
|
| 390 |
+
if((st.st_mode & S_IFMT) == S_IFREG) {
|
| 391 |
+
errno = EEXIST;
|
| 392 |
+
perror("lstat");
|
| 393 |
+
exit(1);
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
unlink(fifo);
|
| 398 |
+
if(mkfifo (fifo, 0600) == -1) {
|
| 399 |
+
perror("mkfifo");
|
| 400 |
+
exit(1);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
socket = open(fifo, O_RDWR | O_NONBLOCK, 0);
|
| 404 |
+
|
| 405 |
+
if(socket == -1) {
|
| 406 |
+
perror("open");
|
| 407 |
+
exit(1);
|
| 408 |
+
}
|
| 409 |
+
MSG_OUT("Now, pipe some URL's into > %s\n", fifo);
|
| 410 |
+
|
| 411 |
+
return socket;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
int main(int argc, char **argv)
|
| 415 |
+
{
|
| 416 |
+
GlobalInfo *g;
|
| 417 |
+
GMainLoop*gmain;
|
| 418 |
+
int fd;
|
| 419 |
+
GIOChannel* ch;
|
| 420 |
+
g = g_malloc0(sizeof(GlobalInfo));
|
| 421 |
+
|
| 422 |
+
fd = init_fifo();
|
| 423 |
+
ch = g_io_channel_unix_new(fd);
|
| 424 |
+
g_io_add_watch(ch, G_IO_IN, fifo_cb, g);
|
| 425 |
+
gmain = g_main_loop_new(NULL, FALSE);
|
| 426 |
+
g->multi = curl_multi_init();
|
| 427 |
+
curl_multi_setopt(g->multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
| 428 |
+
curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g);
|
| 429 |
+
curl_multi_setopt(g->multi, CURLMOPT_TIMERFUNCTION, update_timeout_cb);
|
| 430 |
+
curl_multi_setopt(g->multi, CURLMOPT_TIMERDATA, g);
|
| 431 |
+
|
| 432 |
+
/* we do not call any curl_multi_socket*() function yet as we have no handles
|
| 433 |
+
added! */
|
| 434 |
+
|
| 435 |
+
g_main_loop_run(gmain);
|
| 436 |
+
curl_multi_cleanup(g->multi);
|
| 437 |
+
return 0;
|
| 438 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/href_extractor.c
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 26 |
+
* Uses the "Streaming HTML parser" to extract the href pieces in a streaming
|
| 27 |
+
* manner from a downloaded HTML.
|
| 28 |
+
* </DESC>
|
| 29 |
+
*/
|
| 30 |
+
/*
|
| 31 |
+
* The HTML parser is found at https://github.com/arjunc77/htmlstreamparser
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
#include <stdio.h>
|
| 35 |
+
#include <curl/curl.h>
|
| 36 |
+
#include <htmlstreamparser.h>
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
static size_t write_callback(void *buffer, size_t size, size_t nmemb,
|
| 40 |
+
void *hsp)
|
| 41 |
+
{
|
| 42 |
+
size_t realsize = size * nmemb, p;
|
| 43 |
+
for(p = 0; p < realsize; p++) {
|
| 44 |
+
html_parser_char_parse(hsp, ((char *)buffer)[p]);
|
| 45 |
+
if(html_parser_cmp_tag(hsp, "a", 1))
|
| 46 |
+
if(html_parser_cmp_attr(hsp, "href", 4))
|
| 47 |
+
if(html_parser_is_in(hsp, HTML_VALUE_ENDED)) {
|
| 48 |
+
html_parser_val(hsp)[html_parser_val_length(hsp)] = '\0';
|
| 49 |
+
printf("%s\n", html_parser_val(hsp));
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
return realsize;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
int main(int argc, char *argv[])
|
| 56 |
+
{
|
| 57 |
+
char tag[1], attr[4], val[128];
|
| 58 |
+
CURL *curl;
|
| 59 |
+
HTMLSTREAMPARSER *hsp;
|
| 60 |
+
|
| 61 |
+
if(argc != 2) {
|
| 62 |
+
printf("Usage: %s URL\n", argv[0]);
|
| 63 |
+
return EXIT_FAILURE;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
curl = curl_easy_init();
|
| 67 |
+
|
| 68 |
+
hsp = html_parser_init();
|
| 69 |
+
|
| 70 |
+
html_parser_set_tag_to_lower(hsp, 1);
|
| 71 |
+
html_parser_set_attr_to_lower(hsp, 1);
|
| 72 |
+
html_parser_set_tag_buffer(hsp, tag, sizeof(tag));
|
| 73 |
+
html_parser_set_attr_buffer(hsp, attr, sizeof(attr));
|
| 74 |
+
html_parser_set_val_buffer(hsp, val, sizeof(val)-1);
|
| 75 |
+
|
| 76 |
+
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
| 77 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
| 78 |
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, hsp);
|
| 79 |
+
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
| 80 |
+
|
| 81 |
+
curl_easy_perform(curl);
|
| 82 |
+
|
| 83 |
+
curl_easy_cleanup(curl);
|
| 84 |
+
|
| 85 |
+
html_parser_cleanup(hsp);
|
| 86 |
+
|
| 87 |
+
return EXIT_SUCCESS;
|
| 88 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/hsts-preload.c
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Preload domains to HSTS
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <string.h>
|
| 30 |
+
#include <curl/curl.h>
|
| 31 |
+
|
| 32 |
+
struct entry {
|
| 33 |
+
const char *name;
|
| 34 |
+
const char *exp;
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
static const struct entry preload_hosts[] = {
|
| 38 |
+
{ "example.com", "20370320 01:02:03" },
|
| 39 |
+
{ "curl.se", "20370320 03:02:01" },
|
| 40 |
+
{ NULL, NULL } /* end of list marker */
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
struct state {
|
| 44 |
+
int index;
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
/* "read" is from the point of the library, it wants data from us. One domain
|
| 48 |
+
entry per invoke. */
|
| 49 |
+
static CURLSTScode hstsread(CURL *easy, struct curl_hstsentry *e,
|
| 50 |
+
void *userp)
|
| 51 |
+
{
|
| 52 |
+
const char *host;
|
| 53 |
+
const char *expire;
|
| 54 |
+
struct state *s = (struct state *)userp;
|
| 55 |
+
(void)easy;
|
| 56 |
+
host = preload_hosts[s->index].name;
|
| 57 |
+
expire = preload_hosts[s->index++].exp;
|
| 58 |
+
|
| 59 |
+
if(host && (strlen(host) < e->namelen)) {
|
| 60 |
+
strcpy(e->name, host);
|
| 61 |
+
e->includeSubDomains = 0;
|
| 62 |
+
strcpy(e->expire, expire);
|
| 63 |
+
fprintf(stderr, "HSTS preload '%s' until '%s'\n", host, expire);
|
| 64 |
+
}
|
| 65 |
+
else
|
| 66 |
+
return CURLSTS_DONE;
|
| 67 |
+
return CURLSTS_OK;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
static CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *e,
|
| 71 |
+
struct curl_index *i, void *userp)
|
| 72 |
+
{
|
| 73 |
+
(void)easy;
|
| 74 |
+
(void)userp; /* we have no custom input */
|
| 75 |
+
printf("[%u/%u] %s %s\n", (unsigned int)i->index, (unsigned int)i->total,
|
| 76 |
+
e->name, e->expire);
|
| 77 |
+
return CURLSTS_OK;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
int main(void)
|
| 81 |
+
{
|
| 82 |
+
CURL *curl;
|
| 83 |
+
CURLcode res;
|
| 84 |
+
|
| 85 |
+
curl = curl_easy_init();
|
| 86 |
+
if(curl) {
|
| 87 |
+
struct state st = {0};
|
| 88 |
+
|
| 89 |
+
/* enable HSTS for this handle */
|
| 90 |
+
curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, (long)CURLHSTS_ENABLE);
|
| 91 |
+
|
| 92 |
+
/* function to call at first to populate the cache before the transfer */
|
| 93 |
+
curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hstsread);
|
| 94 |
+
curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &st);
|
| 95 |
+
|
| 96 |
+
/* function to call after transfer to store the new state of the HSTS
|
| 97 |
+
cache */
|
| 98 |
+
curl_easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
|
| 99 |
+
curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, NULL);
|
| 100 |
+
|
| 101 |
+
/* use the domain with HTTP but due to the preload, it should do the
|
| 102 |
+
transfer using HTTPS */
|
| 103 |
+
curl_easy_setopt(curl, CURLOPT_URL, "http://curl.se");
|
| 104 |
+
|
| 105 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 106 |
+
|
| 107 |
+
/* Perform the request, res gets the return code */
|
| 108 |
+
res = curl_easy_perform(curl);
|
| 109 |
+
/* Check for errors */
|
| 110 |
+
if(res != CURLE_OK)
|
| 111 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 112 |
+
curl_easy_strerror(res));
|
| 113 |
+
|
| 114 |
+
/* always cleanup */
|
| 115 |
+
curl_easy_cleanup(curl);
|
| 116 |
+
}
|
| 117 |
+
return 0;
|
| 118 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/htmltidy.c
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Download a document and use libtidy to parse the HTML.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
/*
|
| 29 |
+
* LibTidy => https://www.html-tidy.org/
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
#include <stdio.h>
|
| 33 |
+
#include <tidy/tidy.h>
|
| 34 |
+
#include <tidy/tidybuffio.h>
|
| 35 |
+
#include <curl/curl.h>
|
| 36 |
+
|
| 37 |
+
/* curl write callback, to fill tidy's input buffer... */
|
| 38 |
+
uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out)
|
| 39 |
+
{
|
| 40 |
+
uint r;
|
| 41 |
+
r = size * nmemb;
|
| 42 |
+
tidyBufAppend(out, in, r);
|
| 43 |
+
return r;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Traverse the document tree */
|
| 47 |
+
void dumpNode(TidyDoc doc, TidyNode tnod, int indent)
|
| 48 |
+
{
|
| 49 |
+
TidyNode child;
|
| 50 |
+
for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) {
|
| 51 |
+
ctmbstr name = tidyNodeGetName(child);
|
| 52 |
+
if(name) {
|
| 53 |
+
/* if it has a name, then it's an HTML tag ... */
|
| 54 |
+
TidyAttr attr;
|
| 55 |
+
printf("%*.*s%s ", indent, indent, "<", name);
|
| 56 |
+
/* walk the attribute list */
|
| 57 |
+
for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr) ) {
|
| 58 |
+
printf("%s", tidyAttrName(attr));
|
| 59 |
+
tidyAttrValue(attr) ? printf("=\"%s\" ",
|
| 60 |
+
tidyAttrValue(attr)) : printf(" ");
|
| 61 |
+
}
|
| 62 |
+
printf(">\n");
|
| 63 |
+
}
|
| 64 |
+
else {
|
| 65 |
+
/* if it does not have a name, then it's probably text, cdata, etc... */
|
| 66 |
+
TidyBuffer buf;
|
| 67 |
+
tidyBufInit(&buf);
|
| 68 |
+
tidyNodeGetText(doc, child, &buf);
|
| 69 |
+
printf("%*.*s\n", indent, indent, buf.bp ? (char *)buf.bp : "");
|
| 70 |
+
tidyBufFree(&buf);
|
| 71 |
+
}
|
| 72 |
+
dumpNode(doc, child, indent + 4); /* recursive */
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
int main(int argc, char **argv)
|
| 78 |
+
{
|
| 79 |
+
if(argc == 2) {
|
| 80 |
+
CURL *curl;
|
| 81 |
+
char curl_errbuf[CURL_ERROR_SIZE];
|
| 82 |
+
TidyDoc tdoc;
|
| 83 |
+
TidyBuffer docbuf = {0};
|
| 84 |
+
TidyBuffer tidy_errbuf = {0};
|
| 85 |
+
int err;
|
| 86 |
+
|
| 87 |
+
curl = curl_easy_init();
|
| 88 |
+
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
| 89 |
+
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
|
| 90 |
+
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
| 91 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 92 |
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
| 93 |
+
|
| 94 |
+
tdoc = tidyCreate();
|
| 95 |
+
tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
|
| 96 |
+
tidyOptSetInt(tdoc, TidyWrapLen, 4096);
|
| 97 |
+
tidySetErrorBuffer(tdoc, &tidy_errbuf);
|
| 98 |
+
tidyBufInit(&docbuf);
|
| 99 |
+
|
| 100 |
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
|
| 101 |
+
err = curl_easy_perform(curl);
|
| 102 |
+
if(!err) {
|
| 103 |
+
err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
|
| 104 |
+
if(err >= 0) {
|
| 105 |
+
err = tidyCleanAndRepair(tdoc); /* fix any problems */
|
| 106 |
+
if(err >= 0) {
|
| 107 |
+
err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
|
| 108 |
+
if(err >= 0) {
|
| 109 |
+
dumpNode(tdoc, tidyGetRoot(tdoc), 0); /* walk the tree */
|
| 110 |
+
fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
else
|
| 116 |
+
fprintf(stderr, "%s\n", curl_errbuf);
|
| 117 |
+
|
| 118 |
+
/* clean-up */
|
| 119 |
+
curl_easy_cleanup(curl);
|
| 120 |
+
tidyBufFree(&docbuf);
|
| 121 |
+
tidyBufFree(&tidy_errbuf);
|
| 122 |
+
tidyRelease(tdoc);
|
| 123 |
+
return err;
|
| 124 |
+
|
| 125 |
+
}
|
| 126 |
+
else
|
| 127 |
+
printf("usage: %s <url>\n", argv[0]);
|
| 128 |
+
|
| 129 |
+
return 0;
|
| 130 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/htmltitle.cpp
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Get a web page, extract the title with libxml.
|
| 26 |
+
* </DESC>
|
| 27 |
+
|
| 28 |
+
Written by Lars Nilsson
|
| 29 |
+
|
| 30 |
+
GNU C++ compile command line suggestion (edit paths accordingly):
|
| 31 |
+
|
| 32 |
+
g++ -Wall -I/opt/curl/include -I/opt/libxml/include/libxml2 htmltitle.cpp \
|
| 33 |
+
-o htmltitle -L/opt/curl/lib -L/opt/libxml/lib -lcurl -lxml2
|
| 34 |
+
*/
|
| 35 |
+
#include <stdio.h>
|
| 36 |
+
#include <string.h>
|
| 37 |
+
#include <stdlib.h>
|
| 38 |
+
#include <string>
|
| 39 |
+
#include <curl/curl.h>
|
| 40 |
+
#include <libxml/HTMLparser.h>
|
| 41 |
+
|
| 42 |
+
//
|
| 43 |
+
// Case-insensitive string comparison
|
| 44 |
+
//
|
| 45 |
+
|
| 46 |
+
#ifdef _MSC_VER
|
| 47 |
+
#define COMPARE(a, b) (!_stricmp((a), (b)))
|
| 48 |
+
#else
|
| 49 |
+
#define COMPARE(a, b) (!strcasecmp((a), (b)))
|
| 50 |
+
#endif
|
| 51 |
+
|
| 52 |
+
//
|
| 53 |
+
// libxml callback context structure
|
| 54 |
+
//
|
| 55 |
+
|
| 56 |
+
struct Context
|
| 57 |
+
{
|
| 58 |
+
Context(): addTitle(false) { }
|
| 59 |
+
|
| 60 |
+
bool addTitle;
|
| 61 |
+
std::string title;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
//
|
| 65 |
+
// libcurl variables for error strings and returned data
|
| 66 |
+
|
| 67 |
+
static char errorBuffer[CURL_ERROR_SIZE];
|
| 68 |
+
static std::string buffer;
|
| 69 |
+
|
| 70 |
+
//
|
| 71 |
+
// libcurl write callback function
|
| 72 |
+
//
|
| 73 |
+
|
| 74 |
+
static int writer(char *data, size_t size, size_t nmemb,
|
| 75 |
+
std::string *writerData)
|
| 76 |
+
{
|
| 77 |
+
if(writerData == NULL)
|
| 78 |
+
return 0;
|
| 79 |
+
|
| 80 |
+
writerData->append(data, size*nmemb);
|
| 81 |
+
|
| 82 |
+
return size * nmemb;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
//
|
| 86 |
+
// libcurl connection initialization
|
| 87 |
+
//
|
| 88 |
+
|
| 89 |
+
static bool init(CURL *&conn, char *url)
|
| 90 |
+
{
|
| 91 |
+
CURLcode code;
|
| 92 |
+
|
| 93 |
+
conn = curl_easy_init();
|
| 94 |
+
|
| 95 |
+
if(conn == NULL) {
|
| 96 |
+
fprintf(stderr, "Failed to create CURL connection\n");
|
| 97 |
+
exit(EXIT_FAILURE);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, errorBuffer);
|
| 101 |
+
if(code != CURLE_OK) {
|
| 102 |
+
fprintf(stderr, "Failed to set error buffer [%d]\n", code);
|
| 103 |
+
return false;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
code = curl_easy_setopt(conn, CURLOPT_URL, url);
|
| 107 |
+
if(code != CURLE_OK) {
|
| 108 |
+
fprintf(stderr, "Failed to set URL [%s]\n", errorBuffer);
|
| 109 |
+
return false;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1L);
|
| 113 |
+
if(code != CURLE_OK) {
|
| 114 |
+
fprintf(stderr, "Failed to set redirect option [%s]\n", errorBuffer);
|
| 115 |
+
return false;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writer);
|
| 119 |
+
if(code != CURLE_OK) {
|
| 120 |
+
fprintf(stderr, "Failed to set writer [%s]\n", errorBuffer);
|
| 121 |
+
return false;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
code = curl_easy_setopt(conn, CURLOPT_WRITEDATA, &buffer);
|
| 125 |
+
if(code != CURLE_OK) {
|
| 126 |
+
fprintf(stderr, "Failed to set write data [%s]\n", errorBuffer);
|
| 127 |
+
return false;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
return true;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
//
|
| 134 |
+
// libxml start element callback function
|
| 135 |
+
//
|
| 136 |
+
|
| 137 |
+
static void StartElement(void *voidContext,
|
| 138 |
+
const xmlChar *name,
|
| 139 |
+
const xmlChar **attributes)
|
| 140 |
+
{
|
| 141 |
+
Context *context = static_cast<Context *>(voidContext);
|
| 142 |
+
|
| 143 |
+
if(COMPARE(reinterpret_cast<char *>(name), "TITLE")) {
|
| 144 |
+
context->title = "";
|
| 145 |
+
context->addTitle = true;
|
| 146 |
+
}
|
| 147 |
+
(void) attributes;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
//
|
| 151 |
+
// libxml end element callback function
|
| 152 |
+
//
|
| 153 |
+
|
| 154 |
+
static void EndElement(void *voidContext,
|
| 155 |
+
const xmlChar *name)
|
| 156 |
+
{
|
| 157 |
+
Context *context = static_cast<Context *>(voidContext);
|
| 158 |
+
|
| 159 |
+
if(COMPARE(reinterpret_cast<char *>(name), "TITLE"))
|
| 160 |
+
context->addTitle = false;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
//
|
| 164 |
+
// Text handling helper function
|
| 165 |
+
//
|
| 166 |
+
|
| 167 |
+
static void handleCharacters(Context *context,
|
| 168 |
+
const xmlChar *chars,
|
| 169 |
+
int length)
|
| 170 |
+
{
|
| 171 |
+
if(context->addTitle)
|
| 172 |
+
context->title.append(reinterpret_cast<char *>(chars), length);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
//
|
| 176 |
+
// libxml PCDATA callback function
|
| 177 |
+
//
|
| 178 |
+
|
| 179 |
+
static void Characters(void *voidContext,
|
| 180 |
+
const xmlChar *chars,
|
| 181 |
+
int length)
|
| 182 |
+
{
|
| 183 |
+
Context *context = static_cast<Context *>(voidContext);
|
| 184 |
+
|
| 185 |
+
handleCharacters(context, chars, length);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
//
|
| 189 |
+
// libxml CDATA callback function
|
| 190 |
+
//
|
| 191 |
+
|
| 192 |
+
static void cdata(void *voidContext,
|
| 193 |
+
const xmlChar *chars,
|
| 194 |
+
int length)
|
| 195 |
+
{
|
| 196 |
+
Context *context = static_cast<Context *>(voidContext);
|
| 197 |
+
|
| 198 |
+
handleCharacters(context, chars, length);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
//
|
| 202 |
+
// libxml SAX callback structure
|
| 203 |
+
//
|
| 204 |
+
|
| 205 |
+
static htmlSAXHandler saxHandler =
|
| 206 |
+
{
|
| 207 |
+
NULL,
|
| 208 |
+
NULL,
|
| 209 |
+
NULL,
|
| 210 |
+
NULL,
|
| 211 |
+
NULL,
|
| 212 |
+
NULL,
|
| 213 |
+
NULL,
|
| 214 |
+
NULL,
|
| 215 |
+
NULL,
|
| 216 |
+
NULL,
|
| 217 |
+
NULL,
|
| 218 |
+
NULL,
|
| 219 |
+
NULL,
|
| 220 |
+
NULL,
|
| 221 |
+
StartElement,
|
| 222 |
+
EndElement,
|
| 223 |
+
NULL,
|
| 224 |
+
Characters,
|
| 225 |
+
NULL,
|
| 226 |
+
NULL,
|
| 227 |
+
NULL,
|
| 228 |
+
NULL,
|
| 229 |
+
NULL,
|
| 230 |
+
NULL,
|
| 231 |
+
NULL,
|
| 232 |
+
cdata,
|
| 233 |
+
NULL
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
//
|
| 237 |
+
// Parse given (assumed to be) HTML text and return the title
|
| 238 |
+
//
|
| 239 |
+
|
| 240 |
+
static void parseHtml(const std::string &html,
|
| 241 |
+
std::string &title)
|
| 242 |
+
{
|
| 243 |
+
htmlParserCtxtPtr ctxt;
|
| 244 |
+
Context context;
|
| 245 |
+
|
| 246 |
+
ctxt = htmlCreatePushParserCtxt(&saxHandler, &context, "", 0, "",
|
| 247 |
+
XML_CHAR_ENCODING_NONE);
|
| 248 |
+
|
| 249 |
+
htmlParseChunk(ctxt, html.c_str(), html.size(), 0);
|
| 250 |
+
htmlParseChunk(ctxt, "", 0, 1);
|
| 251 |
+
|
| 252 |
+
htmlFreeParserCtxt(ctxt);
|
| 253 |
+
|
| 254 |
+
title = context.title;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
int main(int argc, char *argv[])
|
| 258 |
+
{
|
| 259 |
+
CURL *conn = NULL;
|
| 260 |
+
CURLcode code;
|
| 261 |
+
std::string title;
|
| 262 |
+
|
| 263 |
+
// Ensure one argument is given
|
| 264 |
+
|
| 265 |
+
if(argc != 2) {
|
| 266 |
+
fprintf(stderr, "Usage: %s <url>\n", argv[0]);
|
| 267 |
+
exit(EXIT_FAILURE);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 271 |
+
|
| 272 |
+
// Initialize CURL connection
|
| 273 |
+
|
| 274 |
+
if(!init(conn, argv[1])) {
|
| 275 |
+
fprintf(stderr, "Connection initialization failed\n");
|
| 276 |
+
exit(EXIT_FAILURE);
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// Retrieve content for the URL
|
| 280 |
+
|
| 281 |
+
code = curl_easy_perform(conn);
|
| 282 |
+
curl_easy_cleanup(conn);
|
| 283 |
+
|
| 284 |
+
if(code != CURLE_OK) {
|
| 285 |
+
fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer);
|
| 286 |
+
exit(EXIT_FAILURE);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
// Parse the (assumed) HTML code
|
| 290 |
+
parseHtml(buffer, title);
|
| 291 |
+
|
| 292 |
+
// Display the extracted title
|
| 293 |
+
printf("Title: %s\n", title.c_str());
|
| 294 |
+
|
| 295 |
+
return EXIT_SUCCESS;
|
| 296 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http-options.c
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Issue an HTTP 'OPTIONS *' request
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl = curl_easy_init();
|
| 37 |
+
if(curl) {
|
| 38 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
| 39 |
+
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
|
| 40 |
+
|
| 41 |
+
/* issue an OPTIONS * request (no leading slash) */
|
| 42 |
+
curl_easy_setopt(curl, CURLOPT_REQUEST_TARGET, "*");
|
| 43 |
+
|
| 44 |
+
/* if this operation fails, allow risking a memory leak and do quick exit
|
| 45 |
+
from libcurl as this exits anyway */
|
| 46 |
+
curl_easy_setopt(curl, CURLOPT_QUICK_EXIT, 1L);
|
| 47 |
+
|
| 48 |
+
/* Perform the request, res gets the return code */
|
| 49 |
+
res = curl_easy_perform(curl);
|
| 50 |
+
/* Check for errors */
|
| 51 |
+
if(res != CURLE_OK)
|
| 52 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 53 |
+
curl_easy_strerror(res));
|
| 54 |
+
|
| 55 |
+
/* always cleanup */
|
| 56 |
+
curl_easy_cleanup(curl);
|
| 57 |
+
}
|
| 58 |
+
return 0;
|
| 59 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http-post.c
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* simple HTTP POST using the easy interface
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
/* In Windows, this inits the Winsock stuff */
|
| 37 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 38 |
+
|
| 39 |
+
/* get a curl handle */
|
| 40 |
+
curl = curl_easy_init();
|
| 41 |
+
if(curl) {
|
| 42 |
+
/* First set the URL that is about to receive our POST. This URL can
|
| 43 |
+
just as well be an https:// URL if that is what should receive the
|
| 44 |
+
data. */
|
| 45 |
+
curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
|
| 46 |
+
/* Now specify the POST data */
|
| 47 |
+
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");
|
| 48 |
+
|
| 49 |
+
/* Perform the request, res gets the return code */
|
| 50 |
+
res = curl_easy_perform(curl);
|
| 51 |
+
/* Check for errors */
|
| 52 |
+
if(res != CURLE_OK)
|
| 53 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 54 |
+
curl_easy_strerror(res));
|
| 55 |
+
|
| 56 |
+
/* always cleanup */
|
| 57 |
+
curl_easy_cleanup(curl);
|
| 58 |
+
}
|
| 59 |
+
curl_global_cleanup();
|
| 60 |
+
return 0;
|
| 61 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http2-download.c
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Multiplexed HTTP/2 downloads over a single connection
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <stdlib.h>
|
| 30 |
+
#include <string.h>
|
| 31 |
+
#include <errno.h>
|
| 32 |
+
|
| 33 |
+
/* curl stuff */
|
| 34 |
+
#include <curl/curl.h>
|
| 35 |
+
#include <curl/mprintf.h>
|
| 36 |
+
|
| 37 |
+
#ifndef CURLPIPE_MULTIPLEX
|
| 38 |
+
/* This little trick makes sure that we do not enable pipelining for libcurls
|
| 39 |
+
old enough to not have this symbol. It is _not_ defined to zero in a recent
|
| 40 |
+
libcurl header. */
|
| 41 |
+
#define CURLPIPE_MULTIPLEX 0
|
| 42 |
+
#endif
|
| 43 |
+
|
| 44 |
+
struct transfer {
|
| 45 |
+
CURL *easy;
|
| 46 |
+
unsigned int num;
|
| 47 |
+
FILE *out;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
#define NUM_HANDLES 1000
|
| 51 |
+
|
| 52 |
+
static
|
| 53 |
+
void dump(const char *text, unsigned int num, unsigned char *ptr, size_t size,
|
| 54 |
+
char nohex)
|
| 55 |
+
{
|
| 56 |
+
size_t i;
|
| 57 |
+
size_t c;
|
| 58 |
+
|
| 59 |
+
unsigned int width = 0x10;
|
| 60 |
+
|
| 61 |
+
if(nohex)
|
| 62 |
+
/* without the hex output, we can fit more on screen */
|
| 63 |
+
width = 0x40;
|
| 64 |
+
|
| 65 |
+
fprintf(stderr, "%u %s, %lu bytes (0x%lx)\n",
|
| 66 |
+
num, text, (unsigned long)size, (unsigned long)size);
|
| 67 |
+
|
| 68 |
+
for(i = 0; i < size; i += width) {
|
| 69 |
+
|
| 70 |
+
fprintf(stderr, "%4.4lx: ", (unsigned long)i);
|
| 71 |
+
|
| 72 |
+
if(!nohex) {
|
| 73 |
+
/* hex not disabled, show it */
|
| 74 |
+
for(c = 0; c < width; c++)
|
| 75 |
+
if(i + c < size)
|
| 76 |
+
fprintf(stderr, "%02x ", ptr[i + c]);
|
| 77 |
+
else
|
| 78 |
+
fputs(" ", stderr);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
for(c = 0; (c < width) && (i + c < size); c++) {
|
| 82 |
+
/* check for 0D0A; if found, skip past and start a new line of output */
|
| 83 |
+
if(nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D &&
|
| 84 |
+
ptr[i + c + 1] == 0x0A) {
|
| 85 |
+
i += (c + 2 - width);
|
| 86 |
+
break;
|
| 87 |
+
}
|
| 88 |
+
fprintf(stderr, "%c",
|
| 89 |
+
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
|
| 90 |
+
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
| 91 |
+
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
|
| 92 |
+
ptr[i + c + 2] == 0x0A) {
|
| 93 |
+
i += (c + 3 - width);
|
| 94 |
+
break;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
fputc('\n', stderr); /* newline */
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
static
|
| 102 |
+
int my_trace(CURL *handle, curl_infotype type,
|
| 103 |
+
char *data, size_t size,
|
| 104 |
+
void *userp)
|
| 105 |
+
{
|
| 106 |
+
const char *text;
|
| 107 |
+
struct transfer *t = (struct transfer *)userp;
|
| 108 |
+
unsigned int num = t->num;
|
| 109 |
+
(void)handle; /* prevent compiler warning */
|
| 110 |
+
|
| 111 |
+
switch(type) {
|
| 112 |
+
case CURLINFO_TEXT:
|
| 113 |
+
fprintf(stderr, "== %u Info: %s", num, data);
|
| 114 |
+
return 0;
|
| 115 |
+
case CURLINFO_HEADER_OUT:
|
| 116 |
+
text = "=> Send header";
|
| 117 |
+
break;
|
| 118 |
+
case CURLINFO_DATA_OUT:
|
| 119 |
+
text = "=> Send data";
|
| 120 |
+
break;
|
| 121 |
+
case CURLINFO_SSL_DATA_OUT:
|
| 122 |
+
text = "=> Send SSL data";
|
| 123 |
+
break;
|
| 124 |
+
case CURLINFO_HEADER_IN:
|
| 125 |
+
text = "<= Recv header";
|
| 126 |
+
break;
|
| 127 |
+
case CURLINFO_DATA_IN:
|
| 128 |
+
text = "<= Recv data";
|
| 129 |
+
break;
|
| 130 |
+
case CURLINFO_SSL_DATA_IN:
|
| 131 |
+
text = "<= Recv SSL data";
|
| 132 |
+
break;
|
| 133 |
+
default: /* in case a new one is introduced to shock us */
|
| 134 |
+
return 0;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
dump(text, num, (unsigned char *)data, size, 1);
|
| 138 |
+
return 0;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
static void setup(struct transfer *t, int num)
|
| 142 |
+
{
|
| 143 |
+
char filename[128];
|
| 144 |
+
CURL *hnd;
|
| 145 |
+
|
| 146 |
+
hnd = t->easy = curl_easy_init();
|
| 147 |
+
|
| 148 |
+
curl_msnprintf(filename, 128, "dl-%d", num);
|
| 149 |
+
|
| 150 |
+
t->out = fopen(filename, "wb");
|
| 151 |
+
if(!t->out) {
|
| 152 |
+
fprintf(stderr, "error: could not open file %s for writing: %s\n",
|
| 153 |
+
filename, strerror(errno));
|
| 154 |
+
exit(1);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* write to this file */
|
| 158 |
+
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, t->out);
|
| 159 |
+
|
| 160 |
+
/* set the same URL */
|
| 161 |
+
curl_easy_setopt(hnd, CURLOPT_URL, "https://localhost:8443/index.html");
|
| 162 |
+
|
| 163 |
+
/* please be verbose */
|
| 164 |
+
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
|
| 165 |
+
curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace);
|
| 166 |
+
curl_easy_setopt(hnd, CURLOPT_DEBUGDATA, t);
|
| 167 |
+
|
| 168 |
+
/* enlarge the receive buffer for potentially higher transfer speeds */
|
| 169 |
+
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 100000L);
|
| 170 |
+
|
| 171 |
+
/* HTTP/2 please */
|
| 172 |
+
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
| 173 |
+
|
| 174 |
+
#if (CURLPIPE_MULTIPLEX > 0)
|
| 175 |
+
/* wait for pipe connection to confirm */
|
| 176 |
+
curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L);
|
| 177 |
+
#endif
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/*
|
| 181 |
+
* Download many transfers over HTTP/2, using the same connection!
|
| 182 |
+
*/
|
| 183 |
+
int main(int argc, char **argv)
|
| 184 |
+
{
|
| 185 |
+
struct transfer trans[NUM_HANDLES];
|
| 186 |
+
CURLM *multi_handle;
|
| 187 |
+
int i;
|
| 188 |
+
int still_running = 0; /* keep number of running handles */
|
| 189 |
+
int num_transfers;
|
| 190 |
+
if(argc > 1) {
|
| 191 |
+
/* if given a number, do that many transfers */
|
| 192 |
+
num_transfers = atoi(argv[1]);
|
| 193 |
+
if((num_transfers < 1) || (num_transfers > NUM_HANDLES))
|
| 194 |
+
num_transfers = 3; /* a suitable low default */
|
| 195 |
+
}
|
| 196 |
+
else
|
| 197 |
+
num_transfers = 3; /* suitable default */
|
| 198 |
+
|
| 199 |
+
/* init a multi stack */
|
| 200 |
+
multi_handle = curl_multi_init();
|
| 201 |
+
|
| 202 |
+
for(i = 0; i < num_transfers; i++) {
|
| 203 |
+
setup(&trans[i], i);
|
| 204 |
+
|
| 205 |
+
/* add the individual transfer */
|
| 206 |
+
curl_multi_add_handle(multi_handle, trans[i].easy);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
| 210 |
+
|
| 211 |
+
do {
|
| 212 |
+
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
| 213 |
+
|
| 214 |
+
if(still_running)
|
| 215 |
+
/* wait for activity, timeout or "nothing" */
|
| 216 |
+
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
|
| 217 |
+
|
| 218 |
+
if(mc)
|
| 219 |
+
break;
|
| 220 |
+
} while(still_running);
|
| 221 |
+
|
| 222 |
+
for(i = 0; i < num_transfers; i++) {
|
| 223 |
+
curl_multi_remove_handle(multi_handle, trans[i].easy);
|
| 224 |
+
curl_easy_cleanup(trans[i].easy);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
curl_multi_cleanup(multi_handle);
|
| 228 |
+
|
| 229 |
+
return 0;
|
| 230 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http2-pushinmemory.c
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP/2 server push. Receive all data in memory.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <stdlib.h>
|
| 30 |
+
#include <string.h>
|
| 31 |
+
|
| 32 |
+
/* curl stuff */
|
| 33 |
+
#include <curl/curl.h>
|
| 34 |
+
|
| 35 |
+
struct Memory {
|
| 36 |
+
char *memory;
|
| 37 |
+
size_t size;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
static size_t
|
| 41 |
+
write_cb(void *contents, size_t size, size_t nmemb, void *userp)
|
| 42 |
+
{
|
| 43 |
+
size_t realsize = size * nmemb;
|
| 44 |
+
struct Memory *mem = (struct Memory *)userp;
|
| 45 |
+
char *ptr = realloc(mem->memory, mem->size + realsize + 1);
|
| 46 |
+
if(!ptr) {
|
| 47 |
+
/* out of memory! */
|
| 48 |
+
printf("not enough memory (realloc returned NULL)\n");
|
| 49 |
+
return 0;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
mem->memory = ptr;
|
| 53 |
+
memcpy(&(mem->memory[mem->size]), contents, realsize);
|
| 54 |
+
mem->size += realsize;
|
| 55 |
+
mem->memory[mem->size] = 0;
|
| 56 |
+
|
| 57 |
+
return realsize;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
#define MAX_FILES 10
|
| 61 |
+
static struct Memory files[MAX_FILES];
|
| 62 |
+
static int pushindex = 1;
|
| 63 |
+
|
| 64 |
+
static void init_memory(struct Memory *chunk)
|
| 65 |
+
{
|
| 66 |
+
chunk->memory = malloc(1); /* grown as needed with realloc */
|
| 67 |
+
chunk->size = 0; /* no data at this point */
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
static void setup(CURL *hnd)
|
| 71 |
+
{
|
| 72 |
+
/* set the same URL */
|
| 73 |
+
curl_easy_setopt(hnd, CURLOPT_URL, "https://localhost:8443/index.html");
|
| 74 |
+
|
| 75 |
+
/* HTTP/2 please */
|
| 76 |
+
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
| 77 |
+
|
| 78 |
+
/* we use a self-signed test server, skip verification during debugging */
|
| 79 |
+
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
|
| 80 |
+
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
|
| 81 |
+
|
| 82 |
+
/* write data to a struct */
|
| 83 |
+
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_cb);
|
| 84 |
+
init_memory(&files[0]);
|
| 85 |
+
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &files[0]);
|
| 86 |
+
|
| 87 |
+
/* wait for pipe connection to confirm */
|
| 88 |
+
curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/* called when there is an incoming push */
|
| 92 |
+
static int server_push_callback(CURL *parent,
|
| 93 |
+
CURL *easy,
|
| 94 |
+
size_t num_headers,
|
| 95 |
+
struct curl_pushheaders *headers,
|
| 96 |
+
void *userp)
|
| 97 |
+
{
|
| 98 |
+
char *headp;
|
| 99 |
+
int *transfers = (int *)userp;
|
| 100 |
+
(void)parent; /* we have no use for this */
|
| 101 |
+
(void)num_headers; /* unused */
|
| 102 |
+
|
| 103 |
+
if(pushindex == MAX_FILES)
|
| 104 |
+
/* cannot fit anymore */
|
| 105 |
+
return CURL_PUSH_DENY;
|
| 106 |
+
|
| 107 |
+
/* write to this buffer */
|
| 108 |
+
init_memory(&files[pushindex]);
|
| 109 |
+
curl_easy_setopt(easy, CURLOPT_WRITEDATA, &files[pushindex]);
|
| 110 |
+
pushindex++;
|
| 111 |
+
|
| 112 |
+
headp = curl_pushheader_byname(headers, ":path");
|
| 113 |
+
if(headp)
|
| 114 |
+
fprintf(stderr, "* Pushed :path '%s'\n", headp /* skip :path + colon */);
|
| 115 |
+
|
| 116 |
+
(*transfers)++; /* one more */
|
| 117 |
+
return CURL_PUSH_OK;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
/*
|
| 122 |
+
* Download a file over HTTP/2, take care of server push.
|
| 123 |
+
*/
|
| 124 |
+
int main(void)
|
| 125 |
+
{
|
| 126 |
+
CURL *easy;
|
| 127 |
+
CURLM *multi;
|
| 128 |
+
int still_running; /* keep number of running handles */
|
| 129 |
+
int transfers = 1; /* we start with one */
|
| 130 |
+
int i;
|
| 131 |
+
struct CURLMsg *m;
|
| 132 |
+
|
| 133 |
+
/* init a multi stack */
|
| 134 |
+
multi = curl_multi_init();
|
| 135 |
+
|
| 136 |
+
easy = curl_easy_init();
|
| 137 |
+
|
| 138 |
+
/* set options */
|
| 139 |
+
setup(easy);
|
| 140 |
+
|
| 141 |
+
/* add the easy transfer */
|
| 142 |
+
curl_multi_add_handle(multi, easy);
|
| 143 |
+
|
| 144 |
+
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
| 145 |
+
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback);
|
| 146 |
+
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers);
|
| 147 |
+
|
| 148 |
+
while(transfers) {
|
| 149 |
+
int rc;
|
| 150 |
+
CURLMcode mcode = curl_multi_perform(multi, &still_running);
|
| 151 |
+
if(mcode)
|
| 152 |
+
break;
|
| 153 |
+
|
| 154 |
+
mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
|
| 155 |
+
if(mcode)
|
| 156 |
+
break;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
/*
|
| 160 |
+
* When doing server push, libcurl itself created and added one or more
|
| 161 |
+
* easy handles but *we* need to clean them up when they are done.
|
| 162 |
+
*/
|
| 163 |
+
do {
|
| 164 |
+
int msgq = 0;
|
| 165 |
+
m = curl_multi_info_read(multi, &msgq);
|
| 166 |
+
if(m && (m->msg == CURLMSG_DONE)) {
|
| 167 |
+
CURL *e = m->easy_handle;
|
| 168 |
+
transfers--;
|
| 169 |
+
curl_multi_remove_handle(multi, e);
|
| 170 |
+
curl_easy_cleanup(e);
|
| 171 |
+
}
|
| 172 |
+
} while(m);
|
| 173 |
+
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
curl_multi_cleanup(multi);
|
| 178 |
+
|
| 179 |
+
/* 'pushindex' is now the number of received transfers */
|
| 180 |
+
for(i = 0; i < pushindex; i++) {
|
| 181 |
+
/* do something fun with the data, and then free it when done */
|
| 182 |
+
free(files[i].memory);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return 0;
|
| 186 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http2-upload.c
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Multiplexed HTTP/2 uploads over a single connection
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <stdlib.h>
|
| 30 |
+
#include <string.h>
|
| 31 |
+
#include <fcntl.h>
|
| 32 |
+
#include <sys/stat.h>
|
| 33 |
+
#include <errno.h>
|
| 34 |
+
|
| 35 |
+
/* somewhat Unix-specific */
|
| 36 |
+
#ifndef _MSC_VER
|
| 37 |
+
#include <sys/time.h>
|
| 38 |
+
#include <unistd.h>
|
| 39 |
+
#endif
|
| 40 |
+
|
| 41 |
+
/* curl stuff */
|
| 42 |
+
#include <curl/curl.h>
|
| 43 |
+
#include <curl/mprintf.h>
|
| 44 |
+
|
| 45 |
+
#ifndef CURLPIPE_MULTIPLEX
|
| 46 |
+
/* This little trick makes sure that we do not enable pipelining for libcurls
|
| 47 |
+
old enough to not have this symbol. It is _not_ defined to zero in a recent
|
| 48 |
+
libcurl header. */
|
| 49 |
+
#define CURLPIPE_MULTIPLEX 0
|
| 50 |
+
#endif
|
| 51 |
+
|
| 52 |
+
#define NUM_HANDLES 1000
|
| 53 |
+
|
| 54 |
+
#ifdef _MSC_VER
|
| 55 |
+
#define gettimeofday(a, b) my_gettimeofday((a), (b))
|
| 56 |
+
static
|
| 57 |
+
int my_gettimeofday(struct timeval *tp, void *tzp)
|
| 58 |
+
{
|
| 59 |
+
(void)tzp;
|
| 60 |
+
if(tp) {
|
| 61 |
+
/* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */
|
| 62 |
+
#define _WIN32_FT_OFFSET (116444736000000000)
|
| 63 |
+
union {
|
| 64 |
+
CURL_TYPEOF_CURL_OFF_T ns100; /* time since 1 Jan 1601 in 100ns units */
|
| 65 |
+
FILETIME ft;
|
| 66 |
+
} _now;
|
| 67 |
+
GetSystemTimeAsFileTime(&_now.ft);
|
| 68 |
+
tp->tv_usec = (long)((_now.ns100 / 10) % 1000000);
|
| 69 |
+
tp->tv_sec = (long)((_now.ns100 - _WIN32_FT_OFFSET) / 10000000);
|
| 70 |
+
}
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
| 73 |
+
#endif
|
| 74 |
+
|
| 75 |
+
struct input {
|
| 76 |
+
FILE *in;
|
| 77 |
+
size_t bytes_read; /* count up */
|
| 78 |
+
CURL *hnd;
|
| 79 |
+
int num;
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
static
|
| 83 |
+
void dump(const char *text, int num, unsigned char *ptr, size_t size,
|
| 84 |
+
char nohex)
|
| 85 |
+
{
|
| 86 |
+
size_t i;
|
| 87 |
+
size_t c;
|
| 88 |
+
unsigned int width = 0x10;
|
| 89 |
+
|
| 90 |
+
if(nohex)
|
| 91 |
+
/* without the hex output, we can fit more on screen */
|
| 92 |
+
width = 0x40;
|
| 93 |
+
|
| 94 |
+
fprintf(stderr, "%d %s, %lu bytes (0x%lx)\n",
|
| 95 |
+
num, text, (unsigned long)size, (unsigned long)size);
|
| 96 |
+
|
| 97 |
+
for(i = 0; i < size; i += width) {
|
| 98 |
+
|
| 99 |
+
fprintf(stderr, "%4.4lx: ", (unsigned long)i);
|
| 100 |
+
|
| 101 |
+
if(!nohex) {
|
| 102 |
+
/* hex not disabled, show it */
|
| 103 |
+
for(c = 0; c < width; c++)
|
| 104 |
+
if(i + c < size)
|
| 105 |
+
fprintf(stderr, "%02x ", ptr[i + c]);
|
| 106 |
+
else
|
| 107 |
+
fputs(" ", stderr);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
for(c = 0; (c < width) && (i + c < size); c++) {
|
| 111 |
+
/* check for 0D0A; if found, skip past and start a new line of output */
|
| 112 |
+
if(nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D &&
|
| 113 |
+
ptr[i + c + 1] == 0x0A) {
|
| 114 |
+
i += (c + 2 - width);
|
| 115 |
+
break;
|
| 116 |
+
}
|
| 117 |
+
fprintf(stderr, "%c",
|
| 118 |
+
(ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80) ? ptr[i + c] : '.');
|
| 119 |
+
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
| 120 |
+
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
|
| 121 |
+
ptr[i + c + 2] == 0x0A) {
|
| 122 |
+
i += (c + 3 - width);
|
| 123 |
+
break;
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
fputc('\n', stderr); /* newline */
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
static
|
| 131 |
+
int my_trace(CURL *handle, curl_infotype type,
|
| 132 |
+
char *data, size_t size,
|
| 133 |
+
void *userp)
|
| 134 |
+
{
|
| 135 |
+
char timebuf[60];
|
| 136 |
+
const char *text;
|
| 137 |
+
struct input *i = (struct input *)userp;
|
| 138 |
+
int num = i->num;
|
| 139 |
+
static time_t epoch_offset;
|
| 140 |
+
static int known_offset;
|
| 141 |
+
struct timeval tv;
|
| 142 |
+
time_t secs;
|
| 143 |
+
struct tm *now;
|
| 144 |
+
(void)handle; /* prevent compiler warning */
|
| 145 |
+
|
| 146 |
+
gettimeofday(&tv, NULL);
|
| 147 |
+
if(!known_offset) {
|
| 148 |
+
epoch_offset = time(NULL) - tv.tv_sec;
|
| 149 |
+
known_offset = 1;
|
| 150 |
+
}
|
| 151 |
+
secs = epoch_offset + tv.tv_sec;
|
| 152 |
+
now = localtime(&secs); /* not thread safe but we do not care */
|
| 153 |
+
curl_msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
|
| 154 |
+
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
|
| 155 |
+
|
| 156 |
+
switch(type) {
|
| 157 |
+
case CURLINFO_TEXT:
|
| 158 |
+
fprintf(stderr, "%s [%d] Info: %s", timebuf, num, data);
|
| 159 |
+
return 0;
|
| 160 |
+
case CURLINFO_HEADER_OUT:
|
| 161 |
+
text = "=> Send header";
|
| 162 |
+
break;
|
| 163 |
+
case CURLINFO_DATA_OUT:
|
| 164 |
+
text = "=> Send data";
|
| 165 |
+
break;
|
| 166 |
+
case CURLINFO_SSL_DATA_OUT:
|
| 167 |
+
text = "=> Send SSL data";
|
| 168 |
+
break;
|
| 169 |
+
case CURLINFO_HEADER_IN:
|
| 170 |
+
text = "<= Recv header";
|
| 171 |
+
break;
|
| 172 |
+
case CURLINFO_DATA_IN:
|
| 173 |
+
text = "<= Recv data";
|
| 174 |
+
break;
|
| 175 |
+
case CURLINFO_SSL_DATA_IN:
|
| 176 |
+
text = "<= Recv SSL data";
|
| 177 |
+
break;
|
| 178 |
+
default: /* in case a new one is introduced to shock us */
|
| 179 |
+
return 0;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
dump(text, num, (unsigned char *)data, size, 1);
|
| 183 |
+
return 0;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp)
|
| 187 |
+
{
|
| 188 |
+
struct input *i = userp;
|
| 189 |
+
size_t retcode = fread(ptr, size, nmemb, i->in);
|
| 190 |
+
i->bytes_read += retcode;
|
| 191 |
+
return retcode;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
static void setup(struct input *i, int num, const char *upload)
|
| 195 |
+
{
|
| 196 |
+
FILE *out;
|
| 197 |
+
char url[256];
|
| 198 |
+
char filename[128];
|
| 199 |
+
struct stat file_info;
|
| 200 |
+
curl_off_t uploadsize;
|
| 201 |
+
CURL *hnd;
|
| 202 |
+
|
| 203 |
+
hnd = i->hnd = curl_easy_init();
|
| 204 |
+
i->num = num;
|
| 205 |
+
curl_msnprintf(filename, 128, "dl-%d", num);
|
| 206 |
+
out = fopen(filename, "wb");
|
| 207 |
+
if(!out) {
|
| 208 |
+
fprintf(stderr, "error: could not open file %s for writing: %s\n", upload,
|
| 209 |
+
strerror(errno));
|
| 210 |
+
exit(1);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
curl_msnprintf(url, 256, "https://localhost:8443/upload-%d", num);
|
| 214 |
+
|
| 215 |
+
/* get the file size of the local file */
|
| 216 |
+
if(stat(upload, &file_info)) {
|
| 217 |
+
fprintf(stderr, "error: could not stat file %s: %s\n", upload,
|
| 218 |
+
strerror(errno));
|
| 219 |
+
exit(1);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
uploadsize = file_info.st_size;
|
| 223 |
+
|
| 224 |
+
i->in = fopen(upload, "rb");
|
| 225 |
+
if(!i->in) {
|
| 226 |
+
fprintf(stderr, "error: could not open file %s for reading: %s\n", upload,
|
| 227 |
+
strerror(errno));
|
| 228 |
+
exit(1);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/* write to this file */
|
| 232 |
+
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out);
|
| 233 |
+
|
| 234 |
+
/* we want to use our own read function */
|
| 235 |
+
curl_easy_setopt(hnd, CURLOPT_READFUNCTION, read_callback);
|
| 236 |
+
/* read from this file */
|
| 237 |
+
curl_easy_setopt(hnd, CURLOPT_READDATA, i);
|
| 238 |
+
/* provide the size of the upload */
|
| 239 |
+
curl_easy_setopt(hnd, CURLOPT_INFILESIZE_LARGE, uploadsize);
|
| 240 |
+
|
| 241 |
+
/* send in the URL to store the upload as */
|
| 242 |
+
curl_easy_setopt(hnd, CURLOPT_URL, url);
|
| 243 |
+
|
| 244 |
+
/* upload please */
|
| 245 |
+
curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L);
|
| 246 |
+
|
| 247 |
+
/* please be verbose */
|
| 248 |
+
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
|
| 249 |
+
curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace);
|
| 250 |
+
curl_easy_setopt(hnd, CURLOPT_DEBUGDATA, i);
|
| 251 |
+
|
| 252 |
+
/* HTTP/2 please */
|
| 253 |
+
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
| 254 |
+
|
| 255 |
+
/* we use a self-signed test server, skip verification during debugging */
|
| 256 |
+
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
|
| 257 |
+
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
|
| 258 |
+
|
| 259 |
+
#if (CURLPIPE_MULTIPLEX > 0)
|
| 260 |
+
/* wait for pipe connection to confirm */
|
| 261 |
+
curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L);
|
| 262 |
+
#endif
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/*
|
| 266 |
+
* Upload all files over HTTP/2, using the same physical connection!
|
| 267 |
+
*/
|
| 268 |
+
int main(int argc, char **argv)
|
| 269 |
+
{
|
| 270 |
+
struct input trans[NUM_HANDLES];
|
| 271 |
+
CURLM *multi_handle;
|
| 272 |
+
int i;
|
| 273 |
+
int still_running = 0; /* keep number of running handles */
|
| 274 |
+
const char *filename = "index.html";
|
| 275 |
+
int num_transfers;
|
| 276 |
+
|
| 277 |
+
if(argc > 1) {
|
| 278 |
+
/* if given a number, do that many transfers */
|
| 279 |
+
num_transfers = atoi(argv[1]);
|
| 280 |
+
|
| 281 |
+
if(!num_transfers || (num_transfers > NUM_HANDLES))
|
| 282 |
+
num_transfers = 3; /* a suitable low default */
|
| 283 |
+
|
| 284 |
+
if(argc > 2)
|
| 285 |
+
/* if given a file name, upload this! */
|
| 286 |
+
filename = argv[2];
|
| 287 |
+
}
|
| 288 |
+
else
|
| 289 |
+
num_transfers = 3;
|
| 290 |
+
|
| 291 |
+
/* init a multi stack */
|
| 292 |
+
multi_handle = curl_multi_init();
|
| 293 |
+
|
| 294 |
+
for(i = 0; i < num_transfers; i++) {
|
| 295 |
+
setup(&trans[i], i, filename);
|
| 296 |
+
|
| 297 |
+
/* add the individual transfer */
|
| 298 |
+
curl_multi_add_handle(multi_handle, trans[i].hnd);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
| 302 |
+
|
| 303 |
+
/* We do HTTP/2 so let's stick to one connection per host */
|
| 304 |
+
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 1L);
|
| 305 |
+
|
| 306 |
+
do {
|
| 307 |
+
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
| 308 |
+
|
| 309 |
+
if(still_running)
|
| 310 |
+
/* wait for activity, timeout or "nothing" */
|
| 311 |
+
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
|
| 312 |
+
|
| 313 |
+
if(mc)
|
| 314 |
+
break;
|
| 315 |
+
|
| 316 |
+
} while(still_running);
|
| 317 |
+
|
| 318 |
+
curl_multi_cleanup(multi_handle);
|
| 319 |
+
|
| 320 |
+
for(i = 0; i < num_transfers; i++) {
|
| 321 |
+
curl_multi_remove_handle(multi_handle, trans[i].hnd);
|
| 322 |
+
curl_easy_cleanup(trans[i].hnd);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
return 0;
|
| 326 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/http3-present.c
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Checks if HTTP/3 support is present in libcurl.
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
curl_version_info_data *ver;
|
| 34 |
+
|
| 35 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 36 |
+
|
| 37 |
+
ver = curl_version_info(CURLVERSION_NOW);
|
| 38 |
+
if(ver->features & CURL_VERSION_HTTP2)
|
| 39 |
+
printf("HTTP/2 support is present\n");
|
| 40 |
+
|
| 41 |
+
if(ver->features & CURL_VERSION_HTTP3)
|
| 42 |
+
printf("HTTP/3 support is present\n");
|
| 43 |
+
|
| 44 |
+
if(ver->features & CURL_VERSION_ALTSVC)
|
| 45 |
+
printf("Alt-svc support is present\n");
|
| 46 |
+
|
| 47 |
+
curl_global_cleanup();
|
| 48 |
+
return 0;
|
| 49 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/httpcustomheader.c
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP request with custom modified, removed and added headers
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl = curl_easy_init();
|
| 37 |
+
if(curl) {
|
| 38 |
+
struct curl_slist *chunk = NULL;
|
| 39 |
+
|
| 40 |
+
/* Remove a header curl would otherwise add by itself */
|
| 41 |
+
chunk = curl_slist_append(chunk, "Accept:");
|
| 42 |
+
|
| 43 |
+
/* Add a custom header */
|
| 44 |
+
chunk = curl_slist_append(chunk, "Another: yes");
|
| 45 |
+
|
| 46 |
+
/* Modify a header curl otherwise adds differently */
|
| 47 |
+
chunk = curl_slist_append(chunk, "Host: example.com");
|
| 48 |
+
|
| 49 |
+
/* Add a header with "blank" contents to the right of the colon. Note that
|
| 50 |
+
we are then using a semicolon in the string we pass to curl! */
|
| 51 |
+
chunk = curl_slist_append(chunk, "X-silly-header;");
|
| 52 |
+
|
| 53 |
+
/* set our custom set of headers */
|
| 54 |
+
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
|
| 55 |
+
|
| 56 |
+
curl_easy_setopt(curl, CURLOPT_URL, "localhost");
|
| 57 |
+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
| 58 |
+
|
| 59 |
+
res = curl_easy_perform(curl);
|
| 60 |
+
/* Check for errors */
|
| 61 |
+
if(res != CURLE_OK)
|
| 62 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 63 |
+
curl_easy_strerror(res));
|
| 64 |
+
|
| 65 |
+
/* always cleanup */
|
| 66 |
+
curl_easy_cleanup(curl);
|
| 67 |
+
|
| 68 |
+
/* free the custom headers */
|
| 69 |
+
curl_slist_free_all(chunk);
|
| 70 |
+
}
|
| 71 |
+
return 0;
|
| 72 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/httpput-postfields.c
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP PUT using CURLOPT_POSTFIELDS
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <fcntl.h>
|
| 30 |
+
#include <sys/stat.h>
|
| 31 |
+
#include <curl/curl.h>
|
| 32 |
+
|
| 33 |
+
static const char olivertwist[]=
|
| 34 |
+
"Among other public buildings in a certain town, which for many reasons "
|
| 35 |
+
"it will be prudent to refrain from mentioning, and to which I will assign "
|
| 36 |
+
"no fictitious name, there is one anciently common to most towns, great or "
|
| 37 |
+
"small: to wit, a workhouse; and in this workhouse was born; on a day and "
|
| 38 |
+
"date which I need not trouble myself to repeat, inasmuch as it can be of "
|
| 39 |
+
"no possible consequence to the reader, in this stage of the business at "
|
| 40 |
+
"all events; the item of mortality whose name is prefixed";
|
| 41 |
+
|
| 42 |
+
/* ... to the head of this chapter. String cut off to stick within the C90
|
| 43 |
+
509 byte limit. */
|
| 44 |
+
|
| 45 |
+
/*
|
| 46 |
+
* This example shows an HTTP PUT operation that sends a fixed buffer with
|
| 47 |
+
* CURLOPT_POSTFIELDS to the URL given as an argument.
|
| 48 |
+
*/
|
| 49 |
+
|
| 50 |
+
int main(int argc, char **argv)
|
| 51 |
+
{
|
| 52 |
+
CURL *curl;
|
| 53 |
+
CURLcode res;
|
| 54 |
+
char *url;
|
| 55 |
+
|
| 56 |
+
if(argc < 2)
|
| 57 |
+
return 1;
|
| 58 |
+
|
| 59 |
+
url = argv[1];
|
| 60 |
+
|
| 61 |
+
/* In Windows, this inits the Winsock stuff */
|
| 62 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 63 |
+
|
| 64 |
+
/* get a curl handle */
|
| 65 |
+
curl = curl_easy_init();
|
| 66 |
+
if(curl) {
|
| 67 |
+
struct curl_slist *headers = NULL;
|
| 68 |
+
|
| 69 |
+
/* default type with postfields is application/x-www-form-urlencoded,
|
| 70 |
+
change it if you want */
|
| 71 |
+
headers = curl_slist_append(headers, "Content-Type: literature/classic");
|
| 72 |
+
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
| 73 |
+
|
| 74 |
+
/* pass on content in request body. When CURLOPT_POSTFIELDSIZE is not used,
|
| 75 |
+
curl does strlen to get the size. */
|
| 76 |
+
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, olivertwist);
|
| 77 |
+
|
| 78 |
+
/* override the POST implied by CURLOPT_POSTFIELDS
|
| 79 |
+
*
|
| 80 |
+
* Warning: CURLOPT_CUSTOMREQUEST is problematic, especially if you want
|
| 81 |
+
* to follow redirects. Be aware.
|
| 82 |
+
*/
|
| 83 |
+
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
| 84 |
+
|
| 85 |
+
/* specify target URL, and note that this URL should include a file
|
| 86 |
+
name, not only a directory */
|
| 87 |
+
curl_easy_setopt(curl, CURLOPT_URL, url);
|
| 88 |
+
|
| 89 |
+
/* Now run off and do what you have been told! */
|
| 90 |
+
res = curl_easy_perform(curl);
|
| 91 |
+
/* Check for errors */
|
| 92 |
+
if(res != CURLE_OK)
|
| 93 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 94 |
+
curl_easy_strerror(res));
|
| 95 |
+
|
| 96 |
+
/* always cleanup */
|
| 97 |
+
curl_easy_cleanup(curl);
|
| 98 |
+
|
| 99 |
+
/* free headers */
|
| 100 |
+
curl_slist_free_all(headers);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
curl_global_cleanup();
|
| 104 |
+
return 0;
|
| 105 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/httpput.c
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* HTTP PUT with easy interface and read callback
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <fcntl.h>
|
| 30 |
+
#include <sys/stat.h>
|
| 31 |
+
#include <curl/curl.h>
|
| 32 |
+
|
| 33 |
+
/*
|
| 34 |
+
* This example shows an HTTP PUT operation. PUTs a file given as a command
|
| 35 |
+
* line argument to the URL also given on the command line.
|
| 36 |
+
*
|
| 37 |
+
* This example also uses its own read callback.
|
| 38 |
+
*
|
| 39 |
+
* Here's an article on how to setup a PUT handler for Apache:
|
| 40 |
+
* http://www.apacheweek.com/features/put
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
|
| 44 |
+
{
|
| 45 |
+
size_t retcode;
|
| 46 |
+
unsigned long nread;
|
| 47 |
+
|
| 48 |
+
/* in real-world cases, this would probably get this data differently
|
| 49 |
+
as this fread() stuff is exactly what the library already would do
|
| 50 |
+
by default internally */
|
| 51 |
+
retcode = fread(ptr, size, nmemb, stream);
|
| 52 |
+
|
| 53 |
+
if(retcode > 0) {
|
| 54 |
+
nread = (unsigned long)retcode;
|
| 55 |
+
fprintf(stderr, "*** We read %lu bytes from file\n", nread);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return retcode;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
int main(int argc, char **argv)
|
| 62 |
+
{
|
| 63 |
+
CURL *curl;
|
| 64 |
+
CURLcode res;
|
| 65 |
+
FILE * hd_src;
|
| 66 |
+
struct stat file_info;
|
| 67 |
+
|
| 68 |
+
char *file;
|
| 69 |
+
char *url;
|
| 70 |
+
|
| 71 |
+
if(argc < 3)
|
| 72 |
+
return 1;
|
| 73 |
+
|
| 74 |
+
file = argv[1];
|
| 75 |
+
url = argv[2];
|
| 76 |
+
|
| 77 |
+
/* get the file size of the local file */
|
| 78 |
+
stat(file, &file_info);
|
| 79 |
+
|
| 80 |
+
/* get a FILE * of the same file, could also be made with
|
| 81 |
+
fdopen() from the previous descriptor, but hey this is just
|
| 82 |
+
an example! */
|
| 83 |
+
hd_src = fopen(file, "rb");
|
| 84 |
+
|
| 85 |
+
/* In Windows, this inits the Winsock stuff */
|
| 86 |
+
curl_global_init(CURL_GLOBAL_ALL);
|
| 87 |
+
|
| 88 |
+
/* get a curl handle */
|
| 89 |
+
curl = curl_easy_init();
|
| 90 |
+
if(curl) {
|
| 91 |
+
/* we want to use our own read function */
|
| 92 |
+
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
| 93 |
+
|
| 94 |
+
/* enable uploading (implies PUT over HTTP) */
|
| 95 |
+
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
| 96 |
+
|
| 97 |
+
/* specify target URL, and note that this URL should include a file
|
| 98 |
+
name, not only a directory */
|
| 99 |
+
curl_easy_setopt(curl, CURLOPT_URL, url);
|
| 100 |
+
|
| 101 |
+
/* now specify which file to upload */
|
| 102 |
+
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
|
| 103 |
+
|
| 104 |
+
/* provide the size of the upload, we typecast the value to curl_off_t
|
| 105 |
+
since we must be sure to use the correct data size */
|
| 106 |
+
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
|
| 107 |
+
(curl_off_t)file_info.st_size);
|
| 108 |
+
|
| 109 |
+
/* Now run off and do what you have been told! */
|
| 110 |
+
res = curl_easy_perform(curl);
|
| 111 |
+
/* Check for errors */
|
| 112 |
+
if(res != CURLE_OK)
|
| 113 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 114 |
+
curl_easy_strerror(res));
|
| 115 |
+
|
| 116 |
+
/* always cleanup */
|
| 117 |
+
curl_easy_cleanup(curl);
|
| 118 |
+
}
|
| 119 |
+
fclose(hd_src); /* close the local file */
|
| 120 |
+
|
| 121 |
+
curl_global_cleanup();
|
| 122 |
+
return 0;
|
| 123 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/https.c
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 25 |
+
* Simple HTTPS GET
|
| 26 |
+
* </DESC>
|
| 27 |
+
*/
|
| 28 |
+
#include <stdio.h>
|
| 29 |
+
#include <curl/curl.h>
|
| 30 |
+
|
| 31 |
+
int main(void)
|
| 32 |
+
{
|
| 33 |
+
CURL *curl;
|
| 34 |
+
CURLcode res;
|
| 35 |
+
|
| 36 |
+
curl_global_init(CURL_GLOBAL_DEFAULT);
|
| 37 |
+
|
| 38 |
+
curl = curl_easy_init();
|
| 39 |
+
if(curl) {
|
| 40 |
+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
|
| 41 |
+
|
| 42 |
+
#ifdef SKIP_PEER_VERIFICATION
|
| 43 |
+
/*
|
| 44 |
+
* If you want to connect to a site who is not using a certificate that is
|
| 45 |
+
* signed by one of the certs in the CA bundle you have, you can skip the
|
| 46 |
+
* verification of the server's certificate. This makes the connection
|
| 47 |
+
* A LOT LESS SECURE.
|
| 48 |
+
*
|
| 49 |
+
* If you have a CA cert for the server stored someplace else than in the
|
| 50 |
+
* default bundle, then the CURLOPT_CAPATH option might come handy for
|
| 51 |
+
* you.
|
| 52 |
+
*/
|
| 53 |
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
| 54 |
+
#endif
|
| 55 |
+
|
| 56 |
+
#ifdef SKIP_HOSTNAME_VERIFICATION
|
| 57 |
+
/*
|
| 58 |
+
* If the site you are connecting to uses a different host name that what
|
| 59 |
+
* they have mentioned in their server certificate's commonName (or
|
| 60 |
+
* subjectAltName) fields, libcurl refuses to connect. You can skip this
|
| 61 |
+
* check, but it makes the connection insecure.
|
| 62 |
+
*/
|
| 63 |
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
/* cache the CA cert bundle in memory for a week */
|
| 67 |
+
curl_easy_setopt(curl, CURLOPT_CA_CACHE_TIMEOUT, 604800L);
|
| 68 |
+
|
| 69 |
+
/* Perform the request, res gets the return code */
|
| 70 |
+
res = curl_easy_perform(curl);
|
| 71 |
+
/* Check for errors */
|
| 72 |
+
if(res != CURLE_OK)
|
| 73 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 74 |
+
curl_easy_strerror(res));
|
| 75 |
+
|
| 76 |
+
/* always cleanup */
|
| 77 |
+
curl_easy_cleanup(curl);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
curl_global_cleanup();
|
| 81 |
+
|
| 82 |
+
return 0;
|
| 83 |
+
}
|
local-test-curl-delta-01/afc-curl/docs/examples/imap-append.c
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
/* <DESC>
|
| 26 |
+
* Send email with IMAP
|
| 27 |
+
* </DESC>
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
#include <stdio.h>
|
| 31 |
+
#include <string.h>
|
| 32 |
+
#include <curl/curl.h>
|
| 33 |
+
|
| 34 |
+
/* This is a simple example showing how to send mail using libcurl's IMAP
|
| 35 |
+
* capabilities.
|
| 36 |
+
*
|
| 37 |
+
* Note that this example requires libcurl 7.30.0 or above.
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
#define FROM "<[email protected]>"
|
| 41 |
+
#define TO "<[email protected]>"
|
| 42 |
+
#define CC "<[email protected]>"
|
| 43 |
+
|
| 44 |
+
static const char *payload_text =
|
| 45 |
+
"Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n"
|
| 46 |
+
"To: " TO "\r\n"
|
| 47 |
+
"From: " FROM "(Example User)\r\n"
|
| 48 |
+
"Cc: " CC "(Another example User)\r\n"
|
| 49 |
+
"Message-ID: "
|
| 50 |
+
"<[email protected]>\r\n"
|
| 51 |
+
"Subject: IMAP example message\r\n"
|
| 52 |
+
"\r\n" /* empty line to divide headers from body, see RFC 5322 */
|
| 53 |
+
"The body of the message starts here.\r\n"
|
| 54 |
+
"\r\n"
|
| 55 |
+
"It could be a lot of lines, could be MIME encoded, whatever.\r\n"
|
| 56 |
+
"Check RFC 5322.\r\n";
|
| 57 |
+
|
| 58 |
+
struct upload_status {
|
| 59 |
+
size_t bytes_read;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp)
|
| 63 |
+
{
|
| 64 |
+
struct upload_status *upload_ctx = (struct upload_status *)userp;
|
| 65 |
+
const char *data;
|
| 66 |
+
size_t room = size * nmemb;
|
| 67 |
+
|
| 68 |
+
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
|
| 69 |
+
return 0;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
data = &payload_text[upload_ctx->bytes_read];
|
| 73 |
+
|
| 74 |
+
if(*data) {
|
| 75 |
+
size_t len = strlen(data);
|
| 76 |
+
if(room < len)
|
| 77 |
+
len = room;
|
| 78 |
+
memcpy(ptr, data, len);
|
| 79 |
+
upload_ctx->bytes_read += len;
|
| 80 |
+
|
| 81 |
+
return len;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
return 0;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
int main(void)
|
| 88 |
+
{
|
| 89 |
+
CURL *curl;
|
| 90 |
+
CURLcode res = CURLE_OK;
|
| 91 |
+
|
| 92 |
+
curl = curl_easy_init();
|
| 93 |
+
if(curl) {
|
| 94 |
+
size_t filesize;
|
| 95 |
+
long infilesize = LONG_MAX;
|
| 96 |
+
struct upload_status upload_ctx = { 0 };
|
| 97 |
+
|
| 98 |
+
/* Set username and password */
|
| 99 |
+
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
| 100 |
+
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
| 101 |
+
|
| 102 |
+
/* This creates a new message in folder "Sent". */
|
| 103 |
+
curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/Sent");
|
| 104 |
+
|
| 105 |
+
/* In this case, we are using a callback function to specify the data. You
|
| 106 |
+
* could just use the CURLOPT_READDATA option to specify a FILE pointer to
|
| 107 |
+
* read from. */
|
| 108 |
+
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
|
| 109 |
+
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
|
| 110 |
+
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
| 111 |
+
|
| 112 |
+
filesize = strlen(payload_text);
|
| 113 |
+
if(filesize <= LONG_MAX)
|
| 114 |
+
infilesize = (long)filesize;
|
| 115 |
+
curl_easy_setopt(curl, CURLOPT_INFILESIZE, infilesize);
|
| 116 |
+
|
| 117 |
+
/* Perform the append */
|
| 118 |
+
res = curl_easy_perform(curl);
|
| 119 |
+
|
| 120 |
+
/* Check for errors */
|
| 121 |
+
if(res != CURLE_OK)
|
| 122 |
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
| 123 |
+
curl_easy_strerror(res));
|
| 124 |
+
|
| 125 |
+
/* Always cleanup */
|
| 126 |
+
curl_easy_cleanup(curl);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
return (int)res;
|
| 130 |
+
}
|