diff options
Diffstat (limited to 'docs/examples')
46 files changed, 688 insertions, 323 deletions
diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 1da0ee21..638f425f 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,54 +35,53 @@ #include <curl/multi.h> static const char *urls[] = { - "http://www.microsoft.com", - "http://www.opensource.org", - "http://www.google.com", - "http://www.yahoo.com", - "http://www.ibm.com", - "http://www.mysql.com", - "http://www.oracle.com", - "http://www.ripe.net", - "http://www.iana.org", - "http://www.amazon.com", - "http://www.netcraft.com", - "http://www.heise.de", - "http://www.chip.de", - "http://www.ca.com", - "http://www.cnet.com", - "http://www.news.com", - "http://www.cnn.com", - "http://www.wikipedia.org", - "http://www.dell.com", - "http://www.hp.com", - "http://www.cert.org", - "http://www.mit.edu", - "http://www.nist.gov", - "http://www.ebay.com", - "http://www.playstation.com", - "http://www.uefa.com", - "http://www.ieee.org", - "http://www.apple.com", - "http://www.symantec.com", - "http://www.zdnet.com", - "http://www.fujitsu.com", - "http://www.supermicro.com", - "http://www.hotmail.com", - "http://www.ecma.com", - "http://www.bbc.co.uk", - "http://news.google.com", - "http://www.foxnews.com", - "http://www.msn.com", - "http://www.wired.com", - "http://www.sky.com", - "http://www.usatoday.com", - "http://www.cbs.com", - "http://www.nbc.com", - "http://slashdot.org", - "http://www.bloglines.com", - "http://www.techweb.com", - "http://www.newslink.org", - "http://www.un.org", + "https://www.microsoft.com", + "https://opensource.org", + "https://www.google.com", + "https://www.yahoo.com", + "https://www.ibm.com", + "https://www.mysql.com", + "https://www.oracle.com", + "https://www.ripe.net", + "https://www.iana.org", + "https://www.amazon.com", + "https://www.netcraft.com", + "https://www.heise.de", + "https://www.chip.de", + "https://www.ca.com", + "https://www.cnet.com", + "https://www.mozilla.org", + "https://www.cnn.com", + "https://www.wikipedia.org", + "https://www.dell.com", + "https://www.hp.com", + "https://www.cert.org", + "https://www.mit.edu", + "https://www.nist.gov", + "https://www.ebay.com", + "https://www.playstation.com", + "https://www.uefa.com", + "https://www.ieee.org", + "https://www.apple.com", + "https://www.symantec.com", + "https://www.zdnet.com", + "https://www.fujitsu.com/global/", + "https://www.supermicro.com", + "https://www.hotmail.com", + "https://www.ietf.org", + "https://www.bbc.co.uk", + "https://news.google.com", + "https://www.foxnews.com", + "https://www.msn.com", + "https://www.wired.com", + "https://www.sky.com", + "https://www.usatoday.com", + "https://www.cbs.com", + "https://www.nbc.com/", + "https://slashdot.org", + "https://www.informationweek.com", + "https://apache.org", + "https://www.un.org", }; #define MAX 10 /* number of simultaneous transfers */ diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index e5ed222e..ce2e924d 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ - Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) + Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) # Specify our include paths here, and do it relative to $(top_srcdir) and # $(top_builddir), to ensure that these paths which belong to the library diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 72eb0d4b..f51871f0 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -24,7 +24,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ fopen ftpget ftpgetresp ftpupload getinfo getinmemory http-post httpput \ https multi-app multi-debugcallback multi-double multi-post multi-single \ - persistant post-callback postit2 sepheaders simple simplepost simplessl \ + persistent post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-mail smtp-mime smtp-multi smtp-ssl smtp-tls smtp-vrfy smtp-expn \ rtsp externalsocket resolve progressfunc pop3-retr pop3-list pop3-uidl \ @@ -34,13 +34,13 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ imap-tls imap-multi url2file sftpget ftpsget postinmemory http2-download \ http2-upload http2-serverpush getredirect ftpuploadfrommem \ ftpuploadresume sslbackend postit2-formadd multi-formadd \ - shared-connection-cache sftpuploadresume + shared-connection-cache sftpuploadresume http2-pushinmemory parseurl # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cpp cacertinmem.c \ - ghiper.c hiperfifo.c htmltidy.c multithread.c opensslthreadlock.c \ - sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ - smooth-gtk-thread.c version-check.pl href_extractor.c asiohiper.cpp \ - multi-uv.c xmlstream.c usercertinmem.c sessioninfo.c \ +COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cpp cacertinmem.c \ + ghiper.c hiperfifo.c htmltidy.c multithread.c opensslthreadlock.c \ + sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ + smooth-gtk-thread.c version-check.pl href_extractor.c asiohiper.cpp \ + multi-uv.c xmlstream.c usercertinmem.c sessioninfo.c \ threaded-shared-conn.c crawler.c ephiperfifo.c diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 5fbc5d66..160afb62 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -5,7 +5,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. +# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms @@ -18,13 +18,16 @@ # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # +#*************************************************************************** + ########################################################################### # ## Makefile for building curl examples with MingW (GCC-3.2 or later) -## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4) +## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4), +## brotli (1.0.1) ## ## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...] -## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-spi-winidn +## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn ## ## Hint: you can also set environment vars to control the build, f.e.: ## set ZLIB_PATH=c:/zlib-1.2.8 @@ -36,6 +39,10 @@ ifndef ZLIB_PATH ZLIB_PATH = ../../../zlib-1.2.8 endif +# Edit the path below to point to the base of your Brotli sources. +ifndef BROTLI_PATH +BROTLI_PATH = ../../../brotli-1.0.1 +endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH OPENSSL_PATH = ../../../openssl-1.0.2a @@ -48,9 +55,21 @@ endif ifndef LIBRTMP_PATH LIBRTMP_PATH = ../../../librtmp-2.4 endif -# Edit the path below to point to the base of your libidn package. -ifndef LIBIDN_PATH -LIBIDN_PATH = ../../../libidn-1.32 +# Edit the path below to point to the base of your libmetalink package. +ifndef LIBMETALINK_PATH +LIBMETALINK_PATH = ../../../libmetalink-0.1.3 +endif +# Edit the path below to point to the base of your libexpat package. +ifndef LIBEXPAT_PATH +LIBEXPAT_PATH = ../../../expat-2.1.0 +endif +# Edit the path below to point to the base of your libxml2 package. +ifndef LIBXML2_PATH +LIBXML2_PATH = ../../../libxml2-2.9.2 +endif +# Edit the path below to point to the base of your libidn2 package. +ifndef LIBIDN2_PATH +LIBIDN2_PATH = ../../../libidn2-2.0.3 endif # Edit the path below to point to the base of your MS IDN package. # Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1 @@ -74,58 +93,66 @@ ifndef LIBCARES_PATH LIBCARES_PATH = $(PROOT)/ares endif -# Edit the var below to set to your architecture or set environment var. +ifeq ($(CURL_CC),) +CURL_CC := $(CROSSPREFIX)gcc +endif +ifeq ($(CURL_AR),) +CURL_AR := $(CROSSPREFIX)ar +endif + +CC = $(CURL_CC) +CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W +CFLAGS += -fno-strict-aliasing +# comment LDFLAGS below to keep debug info +LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s +RC = $(CROSSPREFIX)windres +RCFLAGS = --include-dir=$(PROOT)/include -O COFF + +# Set environment var ARCH to your architecture to override autodetection. ifndef ARCH ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) -ARCH = w64 +ARCH = w64 else -ARCH = w32 +ARCH = w32 endif endif -CC = $(CROSSPREFIX)gcc -CFLAGS = -g -O2 -Wall -W -CFLAGS += -fno-strict-aliasing ifeq ($(ARCH),w64) -CFLAGS += -m64 -D_AMD64_ +CFLAGS += -m64 -D_AMD64_ LDFLAGS += -m64 RCFLAGS += -F pe-x86-64 else -CFLAGS += -m32 +CFLAGS += -m32 LDFLAGS += -m32 RCFLAGS += -F pe-i386 endif -# comment LDFLAGS below to keep debug info -LDFLAGS = -s -RC = $(CROSSPREFIX)windres -RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i # Platform-dependent helper tool macros ifeq ($(findstring /sh,$(SHELL)),/sh) -DEL = rm -f $1 -RMDIR = rm -fr $1 -MKDIR = mkdir -p $1 -COPY = -cp -afv $1 $2 -#COPYR = -cp -afr $1/* $2 -COPYR = -rsync -aC $1/* $2 -TOUCH = touch $1 -CAT = cat -ECHONL = echo "" -DL = ' +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' else ifeq "$(OS)" "Windows_NT" -DEL = -del 2>NUL /q /f $(subst /,\,$1) -RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) else -DEL = -del 2>NUL $(subst /,\,$1) -RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) endif -MKDIR = -md 2>NUL $(subst /,\,$1) -COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) -COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) -TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, -CAT = type -ECHONL = $(ComSpec) /c echo. +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. endif ######################################################## @@ -153,8 +180,11 @@ endif ifeq ($(findstring -zlib,$(CFG)),-zlib) ZLIB = 1 endif -ifeq ($(findstring -idn,$(CFG)),-idn) -IDN = 1 +ifeq ($(findstring -brotli,$(CFG)),-brotli) +BROTLI = 1 +endif +ifeq ($(findstring -idn2,$(CFG)),-idn2) +IDN2 = 1 endif ifeq ($(findstring -winidn,$(CFG)),-winidn) WINIDN = 1 @@ -208,8 +238,24 @@ endif ifdef SSH2 CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2 + ifdef WINSSL + ifndef DYN + curl_LDADD += -lbcrypt -lcrypt32 + endif + endif endif ifdef SSL + ifndef OPENSSL_INCLUDE + ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc + endif + ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" + OPENSSL_INCLUDE = $(OPENSSL_PATH)/include + endif + endif + ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" + $(error Invalid path to OpenSSL package: $(OPENSSL_PATH)) + endif ifndef OPENSSL_LIBPATH OPENSSL_LIBS = -lssl -lcrypto ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" @@ -225,28 +271,52 @@ ifdef SSL ifndef DYN OPENSSL_LIBS += -lgdi32 -lcrypt32 endif + INCLUDES += -I"$(OPENSSL_INCLUDE)" CFLAGS += -DUSE_OPENSSL curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS) endif +ifdef WINSSL + CFLAGS += -DUSE_SCHANNEL + curl_LDADD += -lcrypt32 +endif ifdef ZLIB INCLUDES += -I"$(ZLIB_PATH)" CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H curl_LDADD += -L"$(ZLIB_PATH)" -lz endif -ifdef IDN - CFLAGS += -DUSE_LIBIDN - curl_LDADD += -L"$(LIBIDN_PATH)/lib" -lidn +ifdef BROTLI + INCLUDES += -I"$(BROTLI_PATH)/include" + CFLAGS += -DHAVE_BROTLI + curl_LDADD += -L"$(BROTLI_PATH)/lib" + ifdef BROTLI_LIBS + curl_LDADD += $(BROTLI_LIBS) + else + curl_LDADD += -lbrotlidec + endif +endif +ifdef IDN2 + CFLAGS += -DUSE_LIBIDN2 + curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2 else ifdef WINIDN CFLAGS += -DUSE_WIN32_IDN curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz endif endif +ifdef METALINK + INCLUDES += -I"$(LIBMETALINK_PATH)/include" + CFLAGS += -DUSE_METALINK + curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink + ifndef DYN + ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o) + curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat + else + curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2 + endif + endif +endif ifdef SSPI CFLAGS += -DUSE_WINDOWS_SSPI - ifdef WINSSL - CFLAGS += -DUSE_SCHANNEL - endif endif ifdef IPV6 CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501 @@ -287,11 +357,10 @@ all: $(check_PROGRAMS) $(CC) $(INCLUDES) $(CFLAGS) -c $< %.res: %.rc - $(RC) $(RCFLAGS) $< -o $@ + $(RC) $(RCFLAGS) -i $< -o $@ clean: @$(call DEL, $(check_PROGRAMS:.exe=.o)) distclean vclean: clean @$(call DEL, $(check_PROGRAMS)) - diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index 9ff6d949..9b6c69b8 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -3,13 +3,13 @@ ## Makefile for building curl.nlm (NetWare version - gnu make) ## Use: make -f Makefile.netware ## -## Comments to: Guenter Knauf http://www.gknw.net/phpbb +## Comments to: Guenter Knauf # ################################################################# # Edit the path below to point to the base of your Novell NDK. ifndef NDKBASE -NDKBASE = c:/novell +NDKBASE = c:/novell endif # Edit the path below to point to the base of your Zlib sources. @@ -53,17 +53,17 @@ LIBCARES_PATH = ../../ares endif ifndef INSTDIR -INSTDIR = ..$(DS)..$(DS)curl-$(LIBCURL_VERSION_STR)-bin-nw +INSTDIR = ..$(DS)..$(DS)curl-$(LIBCURL_VERSION_STR)-bin-nw endif # Edit the vars below to change NLM target settings. TARGET = examples -VERSION = $(LIBCURL_VERSION) -COPYR = Copyright (C) $(LIBCURL_COPYRIGHT_STR) -DESCR = curl ($(LIBARCH)) -MTSAFE = YES -STACK = 8192 -SCREEN = Example Program +VERSION = $(LIBCURL_VERSION) +COPYR = Copyright (C) $(LIBCURL_COPYRIGHT_STR) +DESCR = curl ($(LIBARCH)) +MTSAFE = YES +STACK = 8192 +SCREEN = Example Program # Comment the line below if you don't want to load protected automatically. # LDRING = 3 @@ -77,39 +77,39 @@ endif # must be equal to NDEBUG or DEBUG, CURLDEBUG ifndef DB -DB = NDEBUG +DB = NDEBUG endif # Optimization: -O<n> or debugging: -g ifeq ($(DB),NDEBUG) - OPT = -O2 - OBJDIR = release + OPT = -O2 + OBJDIR = release else - OPT = -g - OBJDIR = debug + OPT = -g + OBJDIR = debug endif # The following lines defines your compiler. ifdef CWFolder - METROWERKS = $(CWFolder) + METROWERKS = $(CWFolder) endif ifdef METROWERKS - # MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support - MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support - CC = mwccnlm + # MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support + MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support + CC = mwccnlm else - CC = gcc + CC = gcc endif -PERL = perl +PERL = perl # Here you can find a native Win32 binary of the original awk: # http://www.gknw.net/development/prgtools/awk-20100523.zip -AWK = awk -CP = cp -afv -MKDIR = mkdir -# RM = rm -f +AWK = awk +CP = cp -afv +MKDIR = mkdir +# RM = rm -f # If you want to mark the target as MTSAFE you will need a tool for # generating the xdc data for the linker; here's a minimal tool: # http://www.gknw.net/development/prgtools/mkxdc.zip -MPKXDC = mkxdc +MPKXDC = mkxdc # LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) @@ -118,52 +118,52 @@ LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) -include $(OBJDIR)/version.inc # Global flags for all compilers -CFLAGS += $(OPT) -D$(DB) -DNETWARE -DHAVE_CONFIG_H -nostdinc +CFLAGS += $(OPT) -D$(DB) -DNETWARE -DHAVE_CONFIG_H -nostdinc ifeq ($(CC),mwccnlm) -LD = mwldnlm -LDFLAGS = -nostdlib $< $(PRELUDE) $(LDLIBS) -o $@ -commandfile -LIBEXT = lib -CFLAGS += -gccinc -inline off -opt nointrinsics -proc 586 -CFLAGS += -relax_pointers -#CFLAGS += -w on -ifeq ($(LIBARCH),LIBC) -ifeq ($(POSIXFL),1) - PRELUDE = $(NDK_LIBC)/imports/posixpre.o -else - PRELUDE = $(NDK_LIBC)/imports/libcpre.o -endif - CFLAGS += -align 4 + LD = mwldnlm + LDFLAGS = -nostdlib $< $(PRELUDE) $(LDLIBS) -o $@ -commandfile + LIBEXT = lib + CFLAGS += -gccinc -inline off -opt nointrinsics -proc 586 + CFLAGS += -relax_pointers + #CFLAGS += -w on + ifeq ($(LIBARCH),LIBC) + ifeq ($(POSIXFL),1) + PRELUDE = $(NDK_LIBC)/imports/posixpre.o + else + PRELUDE = $(NDK_LIBC)/imports/libcpre.o + endif + CFLAGS += -align 4 + else + # PRELUDE = $(NDK_CLIB)/imports/clibpre.o + # to avoid the __init_* / __deinit_* woes don't use prelude from NDK + PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" + # CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" + CFLAGS += -align 1 + endif else - # PRELUDE = $(NDK_CLIB)/imports/clibpre.o - # to avoid the __init_* / __deinit_* woes don't use prelude from NDK - PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" - # CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" - CFLAGS += -align 1 -endif -else -LD = nlmconv -LDFLAGS = -T -LIBEXT = a -CFLAGS += -m32 -CFLAGS += -fno-builtin -fno-strict-aliasing -ifeq ($(findstring gcc,$(CC)),gcc) -CFLAGS += -fpcc-struct-return -endif -CFLAGS += -Wall # -pedantic -ifeq ($(LIBARCH),LIBC) -ifeq ($(POSIXFL),1) - PRELUDE = $(NDK_LIBC)/imports/posixpre.gcc.o -else - PRELUDE = $(NDK_LIBC)/imports/libcpre.gcc.o -endif -else - # PRELUDE = $(NDK_CLIB)/imports/clibpre.gcc.o - # to avoid the __init_* / __deinit_* woes don't use prelude from NDK - # http://www.gknw.net/development/mk_nlm/gcc_pre.zip - PRELUDE = $(NDK_ROOT)/pre/prelude.o - CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h -endif + LD = nlmconv + LDFLAGS = -T + LIBEXT = a + CFLAGS += -m32 + CFLAGS += -fno-builtin -fno-strict-aliasing + ifeq ($(findstring gcc,$(CC)),gcc) + CFLAGS += -fpcc-struct-return + endif + CFLAGS += -Wall # -pedantic + ifeq ($(LIBARCH),LIBC) + ifeq ($(POSIXFL),1) + PRELUDE = $(NDK_LIBC)/imports/posixpre.gcc.o + else + PRELUDE = $(NDK_LIBC)/imports/libcpre.gcc.o + endif + else + # PRELUDE = $(NDK_CLIB)/imports/clibpre.gcc.o + # to avoid the __init_* / __deinit_* woes don't use prelude from NDK + # http://www.gknw.net/development/mk_nlm/gcc_pre.zip + PRELUDE = $(NDK_ROOT)/pre/prelude.o + CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h + endif endif NDK_ROOT = $(NDKBASE)/ndk @@ -216,91 +216,91 @@ ENABLE_IPV6 = 1 endif ifdef LINK_STATIC - LDLIBS = $(CURL_LIB)/libcurl.$(LIBEXT) + LDLIBS = $(CURL_LIB)/libcurl.$(LIBEXT) ifdef WITH_ARES - LDLIBS += $(LIBCARES_PATH)/libcares.$(LIBEXT) + LDLIBS += $(LIBCARES_PATH)/libcares.$(LIBEXT) endif else - MODULES = libcurl.nlm - IMPORTS = @$(CURL_LIB)/libcurl.imp + MODULES = libcurl.nlm + IMPORTS = @$(CURL_LIB)/libcurl.imp endif ifdef WITH_SSH2 - # INCLUDES += -I$(LIBSSH2_PATH)/include -ifdef LINK_STATIC - LDLIBS += $(LIBSSH2_PATH)/nw/libssh2.$(LIBEXT) -else - MODULES += libssh2.nlm - IMPORTS += @$(LIBSSH2_PATH)/nw/libssh2.imp -endif + # INCLUDES += -I$(LIBSSH2_PATH)/include + ifdef LINK_STATIC + LDLIBS += $(LIBSSH2_PATH)/nw/libssh2.$(LIBEXT) + else + MODULES += libssh2.nlm + IMPORTS += @$(LIBSSH2_PATH)/nw/libssh2.imp + endif endif ifdef WITH_RTMP - # INCLUDES += -I$(LIBRTMP_PATH) + # INCLUDES += -I$(LIBRTMP_PATH) ifdef LINK_STATIC - LDLIBS += $(LIBRTMP_PATH)/librtmp/librtmp.$(LIBEXT) + LDLIBS += $(LIBRTMP_PATH)/librtmp/librtmp.$(LIBEXT) endif endif ifdef WITH_SSL - INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) - LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) - LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) - IMPORTS += GetProcessSwitchCount RunningProcess + INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) + LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) + LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) + IMPORTS += GetProcessSwitchCount RunningProcess else ifdef WITH_AXTLS - INCLUDES += -I$(AXTLS_PATH)/inc + INCLUDES += -I$(AXTLS_PATH)/inc ifdef LINK_STATIC - LDLIBS += $(AXTLS_PATH)/lib/libaxtls.$(LIBEXT) + LDLIBS += $(AXTLS_PATH)/lib/libaxtls.$(LIBEXT) else - MODULES += libaxtls.nlm - IMPORTS += $(AXTLS_PATH)/lib/libaxtls.imp + MODULES += libaxtls.nlm + IMPORTS += $(AXTLS_PATH)/lib/libaxtls.imp endif endif endif ifdef WITH_ZLIB - # INCLUDES += -I$(ZLIB_PATH) + # INCLUDES += -I$(ZLIB_PATH) ifdef LINK_STATIC - LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) + LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) else - MODULES += libz.nlm - IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp + MODULES += libz.nlm + IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp endif endif ifdef WITH_IDN - # INCLUDES += -I$(LIBIDN_PATH)/include - LDLIBS += $(LIBIDN_PATH)/lib/libidn.$(LIBEXT) + # INCLUDES += -I$(LIBIDN_PATH)/include + LDLIBS += $(LIBIDN_PATH)/lib/libidn.$(LIBEXT) endif ifeq ($(LIBARCH),LIBC) - INCLUDES += -I$(NDK_LIBC)/include - # INCLUDES += -I$(NDK_LIBC)/include/nks - # INCLUDES += -I$(NDK_LIBC)/include/winsock - CFLAGS += -D_POSIX_SOURCE + INCLUDES += -I$(NDK_LIBC)/include + # INCLUDES += -I$(NDK_LIBC)/include/nks + # INCLUDES += -I$(NDK_LIBC)/include/winsock + CFLAGS += -D_POSIX_SOURCE else - INCLUDES += -I$(NDK_CLIB)/include/nlm - # INCLUDES += -I$(NDK_CLIB)/include + INCLUDES += -I$(NDK_CLIB)/include/nlm + # INCLUDES += -I$(NDK_CLIB)/include endif ifndef DISABLE_LDAP - # INCLUDES += -I$(NDK_LDAP)/$(LIBARCH_L)/inc + # INCLUDES += -I$(NDK_LDAP)/$(LIBARCH_L)/inc endif -CFLAGS += $(INCLUDES) +CFLAGS += $(INCLUDES) ifeq ($(MTSAFE),YES) - XDCOPT = -n + XDCOPT = -n endif ifeq ($(MTSAFE),NO) - XDCOPT = -u + XDCOPT = -u endif ifdef XDCOPT - XDCDATA = $(OBJDIR)/$(TARGET).xdc + XDCDATA = $(OBJDIR)/$(TARGET).xdc endif ifeq ($(findstring /sh,$(SHELL)),/sh) -DL = ' -DS = / -PCT = % +DL = ' +DS = / +PCT = % #-include $(NDKBASE)/nlmconv/ncpfs.inc else -DS = \\ -PCT = %% +DS = \\ +PCT = %% endif # Makefile.inc provides the CSOURCES and HHEADERS defines diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index eb91d991..14da10c3 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -26,15 +26,18 @@ */ #include <stdio.h> #include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <curl/curl.h> + #ifdef WIN32 # include <io.h> +# define READ_3RD_ARG unsigned int #else # include <unistd.h> +# define READ_3RD_ARG size_t #endif -#include <sys/types.h> -#include <sys/stat.h> - -#include <curl/curl.h> #if LIBCURL_VERSION_NUM < 0x070c03 #error "upgrade your libcurl to no less than 7.12.3" @@ -83,7 +86,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) int *fdp = (int *)stream; int fd = *fdp; - retcode = read(fd, ptr, size * nmemb); + retcode = read(fd, ptr, (READ_3RD_ARG)(size * nmemb)); nread = (curl_off_t)retcode; diff --git a/docs/examples/asiohiper.cpp b/docs/examples/asiohiper.cpp index 9e0554f5..de148050 100644 --- a/docs/examples/asiohiper.cpp +++ b/docs/examples/asiohiper.cpp @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2012 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -42,6 +42,16 @@ * * This is purely a demo app, all retrieved data is simply discarded by the * write callback. + * + * =========================================================================== + * WARNING: This example program is known to have flaws: + * https://github.com/curl/curl/issues/2407 + * + * It still kept in the example repository with the hope that it might be + * useful, and maybe some day someone who knows enough about boost::asio will + * read this text, accept the challenge and make the example code work + * correctly. Until then: expect this example program to fail occasionally. + * =========================================================================== */ diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 2af0619b..32e9a1d1 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -71,7 +71,7 @@ main(void) if(curl) { char nline[256]; - curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* start cookie engine */ res = curl_easy_perform(curl); diff --git a/docs/examples/crawler.c b/docs/examples/crawler.c index 0aeb8654..d8fa5a45 100644 --- a/docs/examples/crawler.c +++ b/docs/examples/crawler.c @@ -52,7 +52,13 @@ size_t grow_buffer(void *contents, size_t sz, size_t nmemb, void *ctx) { size_t realsize = sz * nmemb; memory *mem = (memory*) ctx; - mem->buf = realloc(mem->buf, mem->size + realsize); + char *ptr = realloc(mem->buf, mem->size + realsize); + if(!ptr) { + /* out of memory */ + printf("not enough memory (realloc returned NULL)\n"); + return 0; + } + mem->buf = ptr; memcpy(&(mem->buf[mem->size]), contents, realsize); mem->size += realsize; return realsize; diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index c3129c19..79e89acc 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -106,4 +106,3 @@ int main(int argc, char **argv) gdk_threads_leave(); return 0; } - diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 141f5a88..49f52e61 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -515,12 +515,20 @@ int main(int argc, char **argv) curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); { + char *ptr; int lu; int i = 0; while((lu = BIO_read(in, &binaryptr[i], tabLength-i)) >0) { i += lu; if(i == tabLength) { tabLength += 100; - binaryptr = realloc(binaryptr, tabLength); /* should be more careful */ + ptr = realloc(binaryptr, tabLength); /* should be more careful */ + if(!ptr) { + /* out of memory */ + BIO_printf(p.errorbio, "out of memory (realloc returned NULL)\n"); + goto fail; + } + binaryptr = ptr; + ptr = NULL; } } tabLength = i; @@ -551,7 +559,7 @@ int main(int argc, char **argv) /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ /* free the header list*/ - +fail: curl_slist_free_all(headers); /* always cleanup */ diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 79250146..884184a5 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -140,7 +140,7 @@ int main(void) /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index 5585564c..d5a820d1 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -33,7 +33,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/"); res = curl_easy_perform(curl); if(CURLE_OK == res) { diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index f5e8942f..130d821d 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -42,13 +42,14 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; - mem->memory = realloc(mem->memory, mem->size + realsize + 1); - if(mem->memory == NULL) { + char *ptr = realloc(mem->memory, mem->size + realsize + 1); + if(ptr == NULL) { /* out of memory! */ printf("not enough memory (realloc returned NULL)\n"); return 0; } + mem->memory = ptr; memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; @@ -72,7 +73,7 @@ int main(void) curl_handle = curl_easy_init(); /* specify URL to get */ - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.example.com/"); /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); diff --git a/docs/examples/getredirect.c b/docs/examples/getredirect.c index 347b1e9b..64157f9c 100644 --- a/docs/examples/getredirect.c +++ b/docs/examples/getredirect.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,7 +35,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); /* example.com is redirected, figure out the redirection! */ diff --git a/docs/examples/href_extractor.c b/docs/examples/href_extractor.c index 16f50c0e..aa2b4381 100644 --- a/docs/examples/href_extractor.c +++ b/docs/examples/href_extractor.c @@ -26,7 +26,7 @@ * </DESC> */ /* - * The HTML parser is found at http://code.google.com/p/htmlstreamparser/ + * The HTML parser is found at https://github.com/arjunc77/htmlstreamparser */ #include <stdio.h> diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 44af0c51..2f4500f5 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -24,12 +24,12 @@ * </DESC> */ /* - * LibTidy => http://tidy.sourceforge.net + * LibTidy => https://www.html-tidy.org/ */ #include <stdio.h> -#include <tidy/tidy.h> -#include <tidy/buffio.h> +#include <tidy.h> +#include <tidybuffio.h> #include <curl/curl.h> /* curl write callback, to fill tidy's input buffer... */ diff --git a/docs/examples/http2-download.c b/docs/examples/http2-download.c index 3425d302..b4ac7c93 100644 --- a/docs/examples/http2-download.c +++ b/docs/examples/http2-download.c @@ -189,7 +189,7 @@ int main(int argc, char **argv) CURL *easy[NUM_HANDLES]; CURLM *multi_handle; int i; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ if(argc > 1) /* if given a number, do that many transfers */ @@ -215,7 +215,7 @@ int main(int argc, char **argv) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -284,7 +284,7 @@ int main(int argc, char **argv) curl_multi_perform(multi_handle, &still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/http2-pushinmemory.c b/docs/examples/http2-pushinmemory.c new file mode 100644 index 00000000..00406a8a --- /dev/null +++ b/docs/examples/http2-pushinmemory.c @@ -0,0 +1,188 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* <DESC> + * HTTP/2 server push. Receive all data in memory. + * </DESC> + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* somewhat unix-specific */ +#include <sys/time.h> +#include <unistd.h> + +/* curl stuff */ +#include <curl/curl.h> + +struct Memory { + char *memory; + size_t size; +}; + +static size_t +write_cb(void *contents, size_t size, size_t nmemb, void *userp) +{ + size_t realsize = size * nmemb; + struct Memory *mem = (struct Memory *)userp; + char *ptr = realloc(mem->memory, mem->size + realsize + 1); + if(!ptr) { + /* out of memory! */ + printf("not enough memory (realloc returned NULL)\n"); + return 0; + } + + mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +#define MAX_FILES 10 +static struct Memory files[MAX_FILES]; +static int pushindex = 1; + +static void init_memory(struct Memory *chunk) +{ + chunk->memory = malloc(1); /* grown as needed with realloc */ + chunk->size = 0; /* no data at this point */ +} + +static void setup(CURL *hnd) +{ + /* set the same URL */ + curl_easy_setopt(hnd, CURLOPT_URL, "https://localhost:8443/index.html"); + + /* HTTP/2 please */ + curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); + + /* we use a self-signed test server, skip verification during debugging */ + curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L); + + /* write data to a struct */ + curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_cb); + init_memory(&files[0]); + curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &files[0]); + + /* wait for pipe connection to confirm */ + curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L); +} + +/* called when there's an incoming push */ +static int server_push_callback(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp) +{ + char *headp; + int *transfers = (int *)userp; + (void)parent; /* we have no use for this */ + (void)num_headers; /* unused */ + + if(pushindex == MAX_FILES) + /* can't fit anymore */ + return CURL_PUSH_DENY; + + /* write to this buffer */ + init_memory(&files[pushindex]); + curl_easy_setopt(easy, CURLOPT_WRITEDATA, &files[pushindex]); + pushindex++; + + headp = curl_pushheader_byname(headers, ":path"); + if(headp) + fprintf(stderr, "* Pushed :path '%s'\n", headp /* skip :path + colon */); + + (*transfers)++; /* one more */ + return CURL_PUSH_OK; +} + + +/* + * Download a file over HTTP/2, take care of server push. + */ +int main(void) +{ + CURL *easy; + CURLM *multi; + int still_running; /* keep number of running handles */ + int transfers = 1; /* we start with one */ + int i; + struct CURLMsg *m; + + /* init a multi stack */ + multi = curl_multi_init(); + + easy = curl_easy_init(); + + /* set options */ + setup(easy); + + /* add the easy transfer */ + curl_multi_add_handle(multi, easy); + + curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); + curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback); + curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers); + + while(transfers) { + int rc; + CURLMcode mcode = curl_multi_perform(multi, &still_running); + if(mcode) + break; + + mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc); + if(mcode) + break; + + + /* + * When doing server push, libcurl itself created and added one or more + * easy handles but *we* need to clean them up when they are done. + */ + do { + int msgq = 0;; + m = curl_multi_info_read(multi, &msgq); + if(m && (m->msg == CURLMSG_DONE)) { + CURL *e = m->easy_handle; + transfers--; + curl_multi_remove_handle(multi, e); + curl_easy_cleanup(e); + } + } while(m); + + } + + + curl_multi_cleanup(multi); + + /* 'pushindex' is now the number of received transfers */ + for(i = 0; i < pushindex; i++) { + /* do something fun with the data, and then free it when done */ + free(files[i].memory); + } + + return 0; +} diff --git a/docs/examples/http2-upload.c b/docs/examples/http2-upload.c index 06ff0409..2717998c 100644 --- a/docs/examples/http2-upload.c +++ b/docs/examples/http2-upload.c @@ -245,7 +245,7 @@ int main(int argc, char **argv) CURL *easy[NUM_HANDLES]; CURLM *multi_handle; int i; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ const char *filename = "index.html"; if(argc > 1) @@ -279,7 +279,7 @@ int main(int argc, char **argv) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -348,7 +348,7 @@ int main(int argc, char **argv) curl_multi_perform(multi_handle, &still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index af761130..17d93ab8 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -53,4 +53,3 @@ clean vclean realclean: - rm -f $(PROGRAMS) depend.dj -include depend.dj - diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 74b2a942..78867d83 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -48,7 +48,7 @@ int main(void) CURL *handles[HANDLECOUNT]; CURLM *multi_handle; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ int i; CURLMsg *msg; /* for picking up messages with the transfer status */ @@ -59,7 +59,7 @@ int main(void) handles[i] = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ - curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "http://example.com"); + curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "https://example.com"); curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_URL, "ftp://example.com"); curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, 1L); @@ -74,7 +74,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -142,7 +142,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } while(still_running); + } /* See how the transfers went */ while((msg = curl_multi_info_read(multi_handle, &msgs_left))) { diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 11ab74b7..59f72442 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -131,12 +131,12 @@ int main(void) CURL *http_handle; CURLM *multi_handle; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ http_handle = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/"); curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace); curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L); @@ -150,7 +150,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -221,7 +221,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 34345393..644e64b1 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -42,13 +42,13 @@ int main(void) CURL *http_handle2; CURLM *multi_handle; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ http_handle = curl_easy_init(); http_handle2 = curl_easy_init(); /* set options */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/"); /* set options */ curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/"); @@ -63,7 +63,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -132,7 +132,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-formadd.c b/docs/examples/multi-formadd.c index bd85cc64..c1bb1355 100644 --- a/docs/examples/multi-formadd.c +++ b/docs/examples/multi-formadd.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,7 +35,7 @@ int main(void) CURL *curl; CURLM *multi_handle; - int still_running; + int still_running = 0; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; @@ -73,7 +73,7 @@ int main(void) if(curl && multi_handle) { /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/upload.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/upload.cgi"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); @@ -83,7 +83,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -154,7 +154,7 @@ int main(void) printf("running: %d!\n", still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 95d71bea..fe66ca90 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -35,7 +35,7 @@ int main(void) CURL *curl; CURLM *multi_handle; - int still_running; + int still_running = 0; curl_mime *form = NULL; curl_mimepart *field = NULL; @@ -69,7 +69,7 @@ int main(void) headerlist = curl_slist_append(headerlist, buf); /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/upload.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/upload.cgi"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); @@ -79,7 +79,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { struct timeval timeout; int rc; /* select() return code */ CURLMcode mc; /* curl_multi_fdset() return code */ @@ -150,7 +150,7 @@ int main(void) printf("running: %d!\n", still_running); break; } - } while(still_running); + } curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 70b6d24b..530a5f50 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -51,7 +51,7 @@ int main(void) CURL *http_handle; CURLM *multi_handle; - int still_running; /* keep number of running handles */ + int still_running = 0; /* keep number of running handles */ int repeats = 0; curl_global_init(CURL_GLOBAL_DEFAULT); @@ -59,7 +59,7 @@ int main(void) http_handle = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/"); /* init a multi stack */ multi_handle = curl_multi_init(); @@ -70,7 +70,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - do { + while(still_running) { CURLMcode mc; /* curl_multi_wait() return code */ int numfds; @@ -97,7 +97,7 @@ int main(void) repeats = 0; curl_multi_perform(multi_handle, &still_running); - } while(still_running); + } curl_multi_remove_handle(multi_handle, http_handle); diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 1d8c96f5..8ca4b909 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -29,7 +29,7 @@ Requires libuv and (of course) libcurl. - See https://nikhilm.github.com/uvbook/ for more information on libuv. + See https://nikhilm.github.io/uvbook/ for more information on libuv. */ #include <stdio.h> diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index e3ae8e67..83ed3f58 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -42,7 +42,7 @@ const char * const urls[NUMT]= { "https://curl.haxx.se/", "ftp://cool.haxx.se/", - "http://www.contactor.se/", + "https://www.cag.se/", "www.haxx.se" }; diff --git a/docs/examples/parseurl.c b/docs/examples/parseurl.c new file mode 100644 index 00000000..ee427768 --- /dev/null +++ b/docs/examples/parseurl.c @@ -0,0 +1,78 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* <DESC> + * Basic URL API use. + * </DESC> + */ +#include <stdio.h> +#include <curl/curl.h> + +#if !CURL_AT_LEAST_VERSION(7, 62, 0) +#error "this example requires curl 7.62.0 or later" +#endif + +int main(void) +{ + CURLU *h; + CURLUcode uc; + char *host; + char *path; + + h = curl_url(); /* get a handle to work with */ + if(!h) + return 1; + + /* parse a full URL */ + uc = curl_url_set(h, CURLUPART_URL, "http://example.com/path/index.html", 0); + if(uc) + goto fail; + + /* extract host name from the parsed URL */ + uc = curl_url_get(h, CURLUPART_HOST, &host, 0); + if(!uc) { + printf("Host name: %s\n", host); + curl_free(host); + } + + /* extract the path from the parsed URL */ + uc = curl_url_get(h, CURLUPART_PATH, &path, 0); + if(!uc) { + printf("Path: %s\n", path); + curl_free(path); + } + + /* redirect with a relative URL */ + uc = curl_url_set(h, CURLUPART_URL, "../another/second.html", 0); + if(uc) + goto fail; + + /* extract the new, updated path */ + uc = curl_url_get(h, CURLUPART_PATH, &path, 0); + if(!uc) { + printf("Path: %s\n", path); + curl_free(path); + } + + fail: + curl_url_cleanup(h); /* free url handle */ + return 0; +} diff --git a/docs/examples/persistant.c b/docs/examples/persistent.c index a1e614bd..723b68b8 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistent.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -40,7 +40,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* get the first document */ - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); @@ -51,7 +51,7 @@ int main(void) /* get another document from the same server using the same connection */ - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/docs/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/docs/"); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index 488d227b..25a1e8ea 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -39,13 +39,14 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)userp; - mem->memory = realloc(mem->memory, mem->size + realsize + 1); - if(mem->memory == NULL) { + char *ptr = realloc(mem->memory, mem->size + realsize + 1); + if(!ptr) { /* out of memory! */ printf("not enough memory (realloc returned NULL)\n"); return 0; } + mem->memory = ptr; memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; @@ -67,7 +68,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.org/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.org/"); /* send all data to this function */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); diff --git a/docs/examples/postit2-formadd.c b/docs/examples/postit2-formadd.c index 0ac09f25..a501ce96 100644 --- a/docs/examples/postit2-formadd.c +++ b/docs/examples/postit2-formadd.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/examplepost.cgi"); if((argc == 2) && (!strcmp(argv[1], "noexpectheader"))) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 49391e1c..2808f7a4 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) wanted */ headerlist = curl_slist_append(headerlist, buf); /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/examplepost.cgi"); if((argc == 2) && (!strcmp(argv[1], "noexpectheader"))) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c index 51d75366..86ad0d9c 100644 --- a/docs/examples/progressfunc.c +++ b/docs/examples/progressfunc.c @@ -108,7 +108,7 @@ int main(void) prog.lastruntime = 0; prog.curl = curl; - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); #if LIBCURL_VERSION_NUM >= 0x072000 /* xferinfo was introduced in 7.32.0, no earlier libcurl versions will diff --git a/docs/examples/resolve.c b/docs/examples/resolve.c index 15e343f9..c3b52d6f 100644 --- a/docs/examples/resolve.c +++ b/docs/examples/resolve.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -38,12 +38,12 @@ int main(void) PORT is the port number of the service where libcurl wants to connect to the HOST and ADDRESS is the numerical IP address */ - host = curl_slist_append(NULL, "example.com:80:127.0.0.1"); + host = curl_slist_append(NULL, "example.com:443:127.0.0.1"); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_RESOLVE, host); - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); res = curl_easy_perform(curl); /* always cleanup */ diff --git a/docs/examples/rtsp.c b/docs/examples/rtsp.c index 32084e9e..75b5d396 100644 --- a/docs/examples/rtsp.c +++ b/docs/examples/rtsp.c @@ -192,7 +192,8 @@ int main(int argc, char * const argv[]) char *base_name = NULL; printf("\nRTSP request %s\n", VERSION_STR); - printf(" Project web site: http://code.google.com/p/rtsprequest/\n"); + printf(" Project web site: " + "https://github.com/BackupGGCode/rtsprequest\n"); printf(" Requires curl V7.20 or greater\n\n"); /* check command line */ diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index 96eff466..7bfaa51c 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -94,7 +94,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); /* use platform-specific functions for codeset conversions */ curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION, diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index eedaf4cd..cf764be4 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -76,7 +76,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); /* Do not do the transfer - only connect to host */ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); res = curl_easy_perform(curl); diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index a865d579..8f3a5ff0 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -49,7 +49,7 @@ int main(void) curl_handle = curl_easy_init(); /* set URL to get */ - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "https://example.com"); /* no progress meter please */ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 7226f4b9..c6122705 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -33,7 +33,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index e366f001..8ec537b5 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -36,7 +36,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 8451743a..5a4f18fd 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -64,7 +64,7 @@ size_t write_file(void *ptr, size_t size, size_t nmemb, FILE *stream) return fwrite(ptr, size, nmemb, stream); } -/* http://xoap.weather.com/weather/local/46214?cc=*&dayf=5&unit=i */ +/* https://weather.com/weather/today/l/46214?cc=*&dayf=5&unit=i */ void *pull_one_url(void *NaN) { CURL *curl; diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index e5cdfed3..d84cea91 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -30,11 +30,11 @@ * Set proxy as according to your network, but beware of proxy Cache-Control. * * To set your system clock, root access is required. - * # date -s "`curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0 \ + * # date -s "`curl -sI https://nist.time.gov/timezone.cgi?UTC/s/0 \ * | awk -F': ' '/Date: / {print $2}'`" * * To view remote webserver date and time. - * $ curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0 \ + * $ curl -sI https://nist.time.gov/timezone.cgi?UTC/s/0 \ * | awk -F': ' '/Date: / {print $2}' * * Synchronising your computer clock via Internet time server usually relies @@ -63,8 +63,10 @@ * webserver provide Cache-Control to prevent caching. * * References: - * http://tf.nist.gov/timefreq/service/its.htm - * http://tf.nist.gov/timefreq/service/firewall.htm + * https://web.archive.org/web/20100228012139/ \ + * tf.nist.gov/timefreq/service/its.htm + * https://web.archive.org/web/20100409024302/ \ + * tf.nist.gov/timefreq/service/firewall.htm * * Usage: * This software will synchronise your computer clock only when you issue @@ -88,6 +90,7 @@ #include <stdio.h> #include <time.h> #ifndef __CYGWIN__ +#include <winsock2.h> #include <windows.h> #endif #include <curl/curl.h> @@ -107,9 +110,8 @@ typedef struct const char DefaultTimeServer[3][MAX_STRING1] = { - "http://pool.ntp.org/", - "http://nist.time.gov/", - "http://www.google.com/" + "https://nist.time.gov/", + "https://www.google.com/" }; const char *DayStr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; @@ -138,6 +140,8 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, int i, RetVal; char TmpStr1[26], TmpStr2[26]; + (void)stream; + if(ShowAllHeader == 1) fprintf(stderr, "%s", (char *)(ptr)); diff --git a/docs/examples/version-check.pl b/docs/examples/version-check.pl index 074e50d8..8f734fc7 100755 --- a/docs/examples/version-check.pl +++ b/docs/examples/version-check.pl @@ -101,5 +101,3 @@ for my $w (@recent) { } last; } - - diff --git a/docs/examples/xmlstream.c b/docs/examples/xmlstream.c index 9ee4a2e8..8036e480 100644 --- a/docs/examples/xmlstream.c +++ b/docs/examples/xmlstream.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -25,7 +25,7 @@ */ /* Written by David Strauss * - * Expat => http://www.libexpat.org/ + * Expat => https://libexpat.github.io/ * * gcc -Wall -I/usr/local/include xmlstream.c -lcurl -lexpat -o xmlstream * @@ -69,14 +69,15 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len) struct ParserStruct *state = (struct ParserStruct *) userData; struct MemoryStruct *mem = &state->characters; - mem->memory = realloc(mem->memory, mem->size + len + 1); - if(mem->memory == NULL) { + char *ptr = realloc(mem->memory, mem->size + len + 1); + if(!ptr) { /* Out of memory. */ fprintf(stderr, "Not enough memory (realloc returned NULL).\n"); state->ok = 0; return; } + mem->memory = ptr; memcpy(&(mem->memory[mem->size]), s, len); mem->size += len; mem->memory[mem->size] = 0; @@ -130,7 +131,7 @@ int main(void) curl_global_init(CURL_GLOBAL_DEFAULT); curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_URL, - "http://www.w3schools.com/xml/simple.xml"); + "https://www.w3schools.com/xml/simple.xml"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser); |