├── .hgignore ├── .hgtags ├── AUTHORS ├── CHANGES ├── CMakeLists.txt ├── COPYING ├── ChangeLog ├── Doxyfile ├── FEATURES ├── INSTALL ├── KNOWN_BUGS ├── Makefile.am ├── Makefile.msvc ├── NEWS ├── PACKAGE ├── README ├── README.win32 ├── TODO ├── VERSION ├── autogen.sh ├── configure.ac ├── cross-configure.sh ├── cross-make.sh ├── cscope.files ├── curlpp-config.in ├── curlpp.VC8.sln ├── curlpp.VC8.vcproj ├── curlpp.m4 ├── curlpp.pc.in ├── curlpp.spec.in ├── doc ├── CMakeLists.txt ├── Makefile.am ├── guide.pdf └── guide.tex ├── examples ├── CMakeLists.txt ├── Makefile.am ├── Makefile.msvc ├── README ├── curlpp.examples.VC8.vcproj ├── example00.cpp ├── example01.cpp ├── example02.cpp ├── example03.cpp ├── example04.cpp ├── example05.cpp ├── example06.cpp ├── example07.cpp ├── example08.cpp ├── example09.cpp ├── example10.cpp ├── example11.cpp ├── example12.cpp ├── example13.cpp ├── example14.cpp ├── example15.cpp ├── example16.cpp ├── example17.cpp ├── example18.cpp ├── example19.cpp ├── example20.cpp ├── example21.cpp ├── example22.cpp ├── example23.cpp └── example24.cpp ├── include ├── CMakeLists.txt ├── Makefile.am ├── curlpp │ ├── CMakeLists.txt │ ├── Easy.hpp │ ├── Easy.inl │ ├── Exception.hpp │ ├── Form.hpp │ ├── Info.hpp │ ├── Info.inl │ ├── Infos.hpp │ ├── Makefile.am │ ├── Multi.hpp │ ├── Option.hpp │ ├── Option.inl │ ├── OptionBase.hpp │ ├── Options.hpp │ ├── Types.hpp │ ├── cURLpp.hpp │ ├── config.h.sample │ ├── config.win32.h │ └── internal │ │ ├── CMakeLists.txt │ │ ├── CurlHandle.hpp │ │ ├── CurlHandle.inl │ │ ├── Makefile.am │ │ ├── OptionContainer.hpp │ │ ├── OptionContainer.inl │ │ ├── OptionContainerType.hpp │ │ ├── OptionList.hpp │ │ ├── OptionSetter.hpp │ │ ├── OptionSetter.inl │ │ ├── SList.hpp │ │ ├── buildconfig.h │ │ └── global.h └── utilspp │ ├── CMakeLists.txt │ ├── EmptyType.hpp │ ├── Functors.hpp │ ├── Makefile.am │ ├── NonCopyable.hpp │ ├── NullType.hpp │ ├── Singleton.hpp │ ├── SmartPtr.hpp │ ├── ThreadingFactoryMutex.hpp │ ├── ThreadingFactoryMutex.inl │ ├── ThreadingSingle.hpp │ ├── ThreadingSingle.inl │ ├── TypeList.hpp │ ├── TypeTrait.hpp │ ├── clone_ptr.hpp │ ├── functor │ ├── Binder.hpp │ ├── CMakeLists.txt │ ├── Functor.hpp │ ├── FunctorHandler.hpp │ ├── FunctorImpl.hpp │ ├── Makefile.am │ └── MemFunHandler.hpp │ └── singleton │ ├── CMakeLists.txt │ ├── CreationStatic.hpp │ ├── CreationStatic.inl │ ├── CreationUsingNew.hpp │ ├── CreationUsingNew.inl │ ├── LifetimeDefault.hpp │ ├── LifetimeDefault.inl │ ├── LifetimeLibrary.hpp │ ├── LifetimeLibrary.inl │ ├── LifetimeWithLongevity.hpp │ ├── LifetimeWithLongevity.inl │ ├── Makefile.am │ ├── PrivateMembers.hpp │ ├── PrivateMembers.inl │ ├── SingletonHolder.hpp │ └── SingletonHolder.inl ├── m4 ├── ax_boost.m4 ├── ax_boost_base.m4 └── boost.m4 ├── src ├── CMakeLists.txt ├── Makefile.am ├── curlpp │ ├── CMakeLists.txt │ ├── Easy.cpp │ ├── Easy.custom.ins │ ├── Easy.ins │ ├── Exception.cpp │ ├── Exception.ins │ ├── Form.cpp │ ├── Info.cpp │ ├── Infos.cpp │ ├── Infos.ins │ ├── Makefile.am │ ├── Makefile.msvc │ ├── Multi.cpp │ ├── Option.cpp │ ├── Option.ins │ ├── OptionBase.cpp │ ├── Options.cpp │ ├── Options.custom.ins │ ├── Options.ins │ ├── autolink.h │ ├── cURLpp.cpp │ └── internal │ │ ├── CMakeLists.txt │ │ ├── CurlHandle.cpp │ │ ├── Makefile.am │ │ ├── OptionList.cpp │ │ ├── OptionSetter.cpp │ │ └── SList.cpp └── utilspp │ ├── CMakeLists.txt │ ├── LifetimeLibrary.cpp │ ├── Makefile.am │ └── PrivateMembers.cpp └── win32 ├── create-vc-solution.bat ├── curlpp.common.vsprops.stub ├── curlpp.examples.vcproj.stub ├── curlpp.examples.vsprops.stub ├── curlpp.lib.vcproj.stub ├── curlpp.lib.vsprops.stub └── curlpp.sln.stub /.hgignore: -------------------------------------------------------------------------------- 1 | (^|/)\.svn($|/) 2 | (^|/)\.hg($|/) 3 | (^|/)\.hgtags($|/) 4 | ^curlpp-svn.log$ 5 | ^tailor.state$ 6 | ^tailor.state.old$ 7 | ^tailor.state.journal$ 8 | .*\.o 9 | .*\.lo 10 | .*\.a 11 | .*\.la 12 | .*\.Plo 13 | .*\.Po 14 | #.*#$ 15 | Makefile$ 16 | Makefile.in$ 17 | include/curlpp/config.h.in 18 | include/curlpp/config.h 19 | ^examples/example[0-9]*$ 20 | aclocal.m4$ 21 | .dylib$ 22 | curlpp.pc$ 23 | curlpp.spec$ 24 | -------------------------------------------------------------------------------- /.hgtags: -------------------------------------------------------------------------------- 1 | 312e2bf680b62de804ce6158f6a8b169181d3b3c version-0.7.1 2 | 3164c5fc2cb7221dc816160892b891c2e9f96d2a curlpp-version-0.7.2 3 | 2f09ee2b35771930efabdcad14915dbef5c12c30 curlpp-version-0.7.2 4 | bb8f53532e8770e7b8e2f995d76b776e35a20cde curlpp-0.7.3 5 | bb8f53532e8770e7b8e2f995d76b776e35a20cde curlpp-0.7.3 6 | d0773a3556d8514afaec74861c1573a9aa60fdb8 curlpp-0.7.3 7 | d0773a3556d8514afaec74861c1573a9aa60fdb8 curlpp-0.7.3 8 | 207d97c9bc6f356d822f4b745dc2534ce487f8dd curlpp-0.7.3 9 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Eric Lavigne (erlavigne at wanadoo.fr) 2 | Jean-Philippe Barrette-LaPierre (jpb at rrette.com) 3 | 4 | A special thanks from Jean-Philippe to Thomas Boutry(tboutry at ygingras.net) for helping me to fix some C++ errors. 5 | 6 | Thanks to some patch providers: 7 | Jonathan Wakely 8 | Peter Krumins 9 | Ben Golding 10 | Glenn 11 | Hoef Jan 12 | Gisle Vanem 13 | Paul Lacy 14 | Nicolas Le Goff 15 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #find_package(boost REQUIRED) 3 | 4 | #include(MacroLibrary) 5 | 6 | #include(ConvenienceLibs.cmake) 7 | 8 | #include(ManualStuff.cmake) 9 | 10 | #include(ConfigureChecks.cmake) 11 | 12 | #include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 13 | 14 | add_subdirectory(src) 15 | add_subdirectory(include) 16 | add_subdirectory(examples) 17 | add_subdirectory(doc) 18 | 19 | 20 | ########### install files ############### 21 | 22 | install(FILES curlpp-config DESTINATION ) 23 | install(FILES curlpp.pc DESTINATION ) 24 | 25 | 26 | #original Makefile.am contents follow: 27 | 28 | #ACLOCAL_AMFLAGS = -I m4 29 | #SUBDIRS = src include examples doc 30 | #EXTRA_DIST = curlpp.vcproj curlpp.sln CHANGES curlpp.spec 31 | # 32 | #pkgconfigdir = $(libdir)/pkgconfig 33 | #pkgconfig_DATA = curlpp.pc 34 | # 35 | #bin_SCRIPTS = curlpp-config 36 | # 37 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) <2002-2004> 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files 5 | (cURLpp), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, 8 | and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | For ChangeLog, check look at curlpp's source repository. 2 | -------------------------------------------------------------------------------- /FEATURES: -------------------------------------------------------------------------------- 1 | - pkg-config support. 2 | - option value retreiving. 3 | - exception safe. 4 | 5 | -------------------------------------------------------------------------------- /KNOWN_BUGS: -------------------------------------------------------------------------------- 1 | autogen.sh doesn't work properly on Mac OS X. It creates invalid Makefiles that can't compile utilspp. -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | SUBDIRS = src include examples doc 3 | EXTRA_DIST = curlpp.VC8.vcproj curlpp.VC8.sln CHANGES curlpp.spec README.win32 win32/* 4 | 5 | pkgconfigdir = $(libdir)/pkgconfig 6 | pkgconfig_DATA = curlpp.pc 7 | 8 | bin_SCRIPTS = curlpp-config 9 | 10 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacratic/curlpp/81c296629a930de10e0024b507696d73e0f50a83/NEWS -------------------------------------------------------------------------------- /PACKAGE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacratic/curlpp/81c296629a930de10e0024b507696d73e0f50a83/PACKAGE -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README 2 | Study the COPYING file for distribution terms and similar. 3 | 4 | Visit the cURLpp web site or mirrors for the latest news: 5 | 6 | http://rrette.com/curlpp.html 7 | 8 | To download the very latest source off the CVS server do this: 9 | 10 | cvs -d :pserver:anonymous@cvs.curlpp.sourceforge.net:/cvsroot/curlpp login 11 | 12 | (just press enter when asked for password) 13 | 14 | cvs -d :pserver:anonymous@cvs.curlpp.sourceforge.net:/cvsroot/curlpp co curlpp 15 | 16 | (you'll get a directory named curl created, filled with the source code) 17 | 18 | cvs -d :pserver:anonymous@cvs.curlpp.sourceforge.net:/cvsroot/curlpp logout 19 | 20 | (you're off the hook!) 21 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Need to fix the OptionList::print function. 2 | - Need to put WriteStream and ReadStream to be exception safe. -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.7.2 -------------------------------------------------------------------------------- /cross-configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CONFIG_SHELL=/bin/sh 4 | export CONFIG_SHELL 5 | PREFIX=/usr/i586-mingw32msvc 6 | TARGET=i586-mingw32msvc 7 | PATH="$PREFIX/bin:$PREFIX/$TARGET/bin:$PATH" 8 | export PATH 9 | cache=cross-config.cache 10 | sh configure --cache-file="$cache" --prefix=$PREFIX \ 11 | --target=$TARGET --host=$TARGET --build=i386-linux \ 12 | $* 13 | status=$? 14 | rm -f "$cache" 15 | exit $status 16 | -------------------------------------------------------------------------------- /cross-make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec make $* 4 | -------------------------------------------------------------------------------- /cscope.files: -------------------------------------------------------------------------------- 1 | ./curlpp/CurlHandle.hpp 2 | ./curlpp/Easy.hpp 3 | ./curlpp/Exception.hpp 4 | ./curlpp/FileTrait.hpp 5 | ./curlpp/Form.hpp 6 | ./curlpp/Handle.hpp 7 | ./curlpp/NonCopyable.hpp 8 | ./curlpp/Option.hpp 9 | ./curlpp/OptionBase.hpp 10 | ./curlpp/OptionContainer.hpp 11 | ./curlpp/OptionContainerType.hpp 12 | ./curlpp/OptionList.hpp 13 | ./curlpp/OptionSetter.hpp 14 | ./curlpp/Options.hpp 15 | ./curlpp/SList.hpp 16 | ./curlpp/Storage.hpp 17 | ./curlpp/StorageOptions.hpp 18 | ./curlpp/StorageTrait.hpp 19 | ./curlpp/StreamTrait.hpp 20 | ./curlpp/TypeTrait.hpp 21 | ./curlpp/cURL.hpp 22 | ./curlpp/cURLpp.hpp 23 | -------------------------------------------------------------------------------- /curlpp-config.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # The idea to this kind of setup info script was stolen from numerous 4 | # other packages, such as neon, libxml and gnome. 5 | # 6 | # $Id: curlpp-config.in,v 1.4 2004/10/05 01:48:40 jpbl Exp $ 7 | # 8 | prefix=@prefix@ 9 | exec_prefix=@exec_prefix@ 10 | includedir=@includedir@ 11 | 12 | usage() 13 | { 14 | cat <= 7.10.0 11 | 12 | 13 | %package devel 14 | Summary: The includes and libs to develop with cURLpp 15 | Group: Development/Libraries 16 | Requires: curl >= 7.10.0 17 | Provides: curlpp-devel 18 | 19 | %description 20 | cURLpp is a libcurl C++ wrapper. There is the libcurl description: "libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. libcurl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunneling and more! 21 | 22 | libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, Net/Free/Open BSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS and more... " 23 | 24 | %description devel 25 | This packages contains all the libs and headers to develop applications using cURLpp. 26 | 27 | 28 | %prep 29 | %setup -qn curlpp-@VERSION@ 30 | 31 | 32 | %build 33 | %configure 34 | make 35 | 36 | %install 37 | [ "%{buildroot}" != "/" ] && rm -rf %{buildroot} 38 | make DESTDIR=%{buildroot} install 39 | 40 | %clean 41 | rm -rf %{buildroot} 42 | 43 | %post 44 | /sbin/ldconfig 45 | 46 | %postun 47 | /sbin/ldconfig 48 | 49 | %files 50 | %defattr(-,root,root) 51 | %{_libdir}/libcurlpp.so* 52 | 53 | 54 | %files devel 55 | %defattr(-,root,root) 56 | %attr(0755,root,root) %{_bindir}/curlpp-config 57 | %dir %{_includedir}/curlpp 58 | %{_includedir}/curlpp/*.hpp 59 | %{_includedir}/curlpp/*.inl 60 | %{_includedir}/curlpp/*.h 61 | %dir %{_includedir}/curlpp/utilspp 62 | %dir %{_includedir}/curlpp/utilspp/singleton 63 | %{_includedir}/curlpp/utilspp/singleton/*.hpp 64 | %{_includedir}/curlpp/utilspp/singleton/*.inl 65 | %dir %{_includedir}/utilspp 66 | %{_includedir}/utilspp/*.hpp 67 | %{_includedir}/utilspp/*.inl 68 | %dir %{_includedir}/utilspp/functor 69 | %{_includedir}/utilspp/functor/*.hpp 70 | %{_libdir}/libcurlpp.la 71 | %{_libdir}/libcurlpp.a 72 | %{_libdir}/pkgconfig/curlpp.pc 73 | %dir 74 | 75 | 76 | %changelog 77 | 78 | * Sun Jul 17 2005 Jean-Philippe Barrette-LaPierre - 0.5.1-1 79 | - removed {%name} use 80 | 81 | * Wed Jan 5 2005 Jean-Philippe Barrette-LaPierre - 0.3.2-rc1-1 82 | - Version depends now on configure script 83 | 84 | * Thu Sep 30 2004 Jean-Philippe Barrette-LaPierre 0.3.1-1 85 | - Removed any utilspp reference. (Not used anymore) 86 | 87 | * Thu Jun 17 2004 Jean-Philippe Barrette-LaPierre 0.3.1-1 88 | - Removed the unusefull BuildRequires 89 | 90 | * Mon Oct 20 2003 Jean-Philippe Barrette-LaPierre - 0.3.0-2 91 | - Added the devel package 92 | 93 | * Wed Oct 15 2003 Jean-Philippe Barrette-LaPierre - 0.3.0-1 94 | - Initial build. 95 | 96 | 97 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### install files ############### 6 | 7 | 8 | 9 | 10 | #original Makefile.am contents follow: 11 | 12 | #EXTRA_DIST = guide.pdf -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = guide.pdf -------------------------------------------------------------------------------- /doc/guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datacratic/curlpp/81c296629a930de10e0024b507696d73e0f50a83/doc/guide.pdf -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | if MAINTENER_CODE 2 | maintener_programs = 3 | endif 4 | 5 | if HAVE_BOOST 6 | boost_programs = example18 example20 7 | endif 8 | 9 | EXTRA_DIST = Makefile.msvc 10 | 11 | noinst_PROGRAMS = \ 12 | example01 \ 13 | example02 \ 14 | example03 \ 15 | example04 \ 16 | example05 \ 17 | example06 \ 18 | example07 \ 19 | example08 \ 20 | example09 \ 21 | example10 \ 22 | example11 \ 23 | example12 \ 24 | example13 \ 25 | example14 \ 26 | example15 \ 27 | example16 \ 28 | example17 \ 29 | example19 \ 30 | example21 \ 31 | example22 \ 32 | example23 \ 33 | example24 \ 34 | ${maintener_programs} ${boost_programs} 35 | 36 | 37 | 38 | example01_SOURCES = example01.cpp 39 | 40 | example02_SOURCES = example02.cpp 41 | 42 | example03_SOURCES = example03.cpp 43 | 44 | example04_SOURCES = example04.cpp 45 | 46 | example05_SOURCES = example05.cpp 47 | 48 | example06_SOURCES = example06.cpp 49 | 50 | example07_SOURCES = example07.cpp 51 | 52 | example08_SOURCES = example08.cpp 53 | 54 | example09_SOURCES = example09.cpp 55 | 56 | example10_SOURCES = example10.cpp 57 | 58 | example11_SOURCES = example11.cpp 59 | 60 | example12_SOURCES = example12.cpp 61 | 62 | example13_SOURCES = example13.cpp 63 | 64 | example14_SOURCES = example14.cpp 65 | 66 | example15_SOURCES = example15.cpp 67 | 68 | example16_SOURCES = example16.cpp 69 | 70 | example17_SOURCES = example17.cpp 71 | 72 | example18_SOURCES = example18.cpp 73 | 74 | example19_SOURCES = example19.cpp 75 | 76 | example20_SOURCES = example20.cpp 77 | 78 | example21_SOURCES = example21.cpp 79 | 80 | example22_SOURCES = example22.cpp 81 | 82 | example23_SOURCES = example23.cpp 83 | 84 | example24_SOURCES = example24.cpp 85 | 86 | AM_LDFLAGS = -L../src/curlpp/ -lcurlpp -static 87 | 88 | INCLUDES = -I$(top_builddir)/include 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /examples/Makefile.msvc: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # 3 | # Makefile for building libcurlpp examples with MSVC 4 | # All examples are linked against curlpp release static library 5 | # Giuseppe "Cowo" Corbelli - cowo at lugbs dot linux dot it 6 | # 7 | # Usage: nmake -f Makefile.msvc all 8 | # Should be invoked from examples/ directory 9 | # Edit the LIBCURL_PATH/BOOST_PATH or set LIBCURL_PATH/BOOST_PATH env vars 10 | # 11 | ############################################################## 12 | 13 | CURLPP_LIB_NAME = curlpp.lib 14 | CURL_LIB_NAME = libcurl.lib 15 | 16 | ############################################################# 17 | 18 | !IFNDEF LIBCURL_PATH 19 | LIBCURL_PATH = ../../curl/include 20 | !ENDIF 21 | 22 | !IF "$(cfg)"=="DebugStatic" || "$(cfg)"=="DebugDynamic" 23 | CC = cl.exe /MDd /Od /Gm /Zi /D_DEBUG /GR /EHsc 24 | !ELSE 25 | CC = cl.exe /MD /O2 /DNDEBUG /GR /Y- /EHsc 26 | !ENDIF 27 | 28 | CFLAGS = /I ../include /I ../include/curlpp /I "$(LIBCURL_PATH)/include" /DCURLPP_STATICLIB /D_CRT_SECURE_NO_DEPRECATE /nologo /W3 /DWIN32 /FD /c 29 | !IFDEF BOOST_PATH 30 | CFLAGS = /I $(BOOST_PATH) $(CFLAGS) 31 | !ENDIF 32 | 33 | LNKLIB = link.exe /INCREMENTAL:NO /OPT:NOREF 34 | LFLAGS = /nologo /LIBPATH:"$(LIBCURL_PATH)\lib" /LIBPATH:"..\$(cfg)" $(CURLPP_LIB_NAME) $(CURL_LIB_NAME) 35 | 36 | LNK = $(LNKLIB) $(LFLAGS) 37 | 38 | example01 : $$(@B).o 39 | $(LNK) /out:$@.exe $** 40 | 41 | example02 : $$(@B).o 42 | $(LNK) /out:$@.exe $** 43 | 44 | example03 : $$(@B).o 45 | $(LNK) /out:$@.exe $** 46 | 47 | example04 : $$(@B).o 48 | $(LNK) /out:$@.exe $** 49 | 50 | example05 : $$(@B).o 51 | $(LNK) /out:$@.exe $** 52 | 53 | example06 : $$(@B).o 54 | $(LNK) /out:$@.exe $** 55 | 56 | example07 : $$(@B).o 57 | $(LNK) /out:$@.exe $** 58 | 59 | example08 : $$(@B).o 60 | $(LNK) /out:$@.exe $** 61 | 62 | example09 : $$(@B).o 63 | $(LNK) /out:$@.exe $** 64 | 65 | example10 : $$(@B).o 66 | $(LNK) /out:$@.exe $** 67 | 68 | example11 : $$(@B).o 69 | $(LNK) /out:$@.exe $** 70 | 71 | example12 : $$(@B).o 72 | $(LNK) /out:$@.exe $** 73 | 74 | example13 : $$(@B).o 75 | $(LNK) Ws2_32.lib /out:$@.exe $** 76 | 77 | example14 : $$(@B).o 78 | $(LNK) Ws2_32.lib /out:$@.exe $** 79 | 80 | example15 : $$(@B).o 81 | $(LNK) /out:$@.exe $** 82 | 83 | example16 : $$(@B).o 84 | $(LNK) /out:$@.exe $** 85 | 86 | example17 : $$(@B).o 87 | $(LNK) /out:$@.exe $** 88 | 89 | example18 : $$(@B).o 90 | $(LNK) /out:$@.exe $** 91 | 92 | example19 : $$(@B).o 93 | $(LNK) /out:$@.exe $** 94 | 95 | example20 : $$(@B).o 96 | $(LNK) /out:$@.exe $** 97 | 98 | example21 : $$(@B).o 99 | $(LNK) /out:$@.exe $** 100 | 101 | example22 : $$(@B).o 102 | $(LNK) /out:$@.exe $** 103 | 104 | 105 | TARGET = \ 106 | example01 \ 107 | example02 \ 108 | example03 \ 109 | example04 \ 110 | example05 \ 111 | example06 \ 112 | example07 \ 113 | example08 \ 114 | example09 \ 115 | example10 \ 116 | example11 \ 117 | example12 \ 118 | example13 \ 119 | example14 \ 120 | example15 \ 121 | example16 \ 122 | example17 \ 123 | example18 \ 124 | example19 \ 125 | example20 \ 126 | example21 \ 127 | example22 128 | 129 | all : $(TARGET) copy_curlpp 130 | 131 | rebuild: clean all 132 | 133 | clean: 134 | @echo Cleaning... 135 | del *.o *.exe >NUL 2>&1 136 | 137 | copy_curlpp: 138 | !IF "$(cfg)"=="DebugDynamic" || "$(cfg)"=="ReleaseDynamic" 139 | copy ..\$(cfg)\curlpp.dll .\ 140 | !ENDIF 141 | 142 | .SUFFIXES: .cpp .o 143 | 144 | .cpp.o: 145 | $(CC) $(CFLAGS) /Fo"$@" $< 146 | 147 | 148 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | configure.in is a good example to add curlpp to your project 2 | 3 | Note that example 22 is contains the easiest and shorter examples of cURLpp 4 | usage. 5 | 6 | Example 01: This example is made to show you how you can use the Options. 7 | Example 02: an upload example. 8 | Example 03: verbose callback example. 9 | Example 04: GetInfo example. 10 | Example 05: Function functor for WriteFunction example. 11 | Example 06: Method functor for WriteFunction example. 12 | Example 07: Cookie interface example via getInfo. 13 | Demonstrates usage of Infos::CookieList which example04 did not. 14 | Example 08: verbose callback example, with exception safe handling. 15 | Example 09: verbose callback example, with exception safe handling, 16 | but without raiseException function. 17 | Example 10: Binded function functor for WriteFunction example. 18 | Example 11: Plain write function example. 19 | Example 12: HTTP POST example. 20 | Example 13: Simple Multi interface example. 21 | Example 14: Multi interface example with info function example. 22 | Example 15: Simple example for demonstrating the NoValueOptionTrait. 23 | (SslEngineDefault) 24 | Example 16: HTTP POST example with HTTP Authentification. 25 | Example 17: Binded method functor for WriteFunction example. 26 | Example 18: Boost binded method for WriteFunction example. 27 | Example 19: Multipart/formdata HTTP POST example. 28 | Example 20: std::ostream usage. 29 | Example 21: upload example with std::istream. 30 | Example 22: Real easy and quick examples. 31 | Example 23: Setting request options using iterators to custom container 32 | of curlpp options. 33 | Example 24: Binded method functor for DebugFunction example. 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/example00.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * The most simple example. 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | using namespace curlpp::options; 13 | 14 | int main(int, char **) 15 | { 16 | try 17 | { 18 | // That's all that is needed to do cleanup of used resources (RAII style). 19 | curlpp::Cleanup myCleanup; 20 | 21 | // Our request to be sent. 22 | curlpp::Easy myRequest; 23 | 24 | // Set the URL. 25 | myRequest.setOpt("http://example.com"); 26 | 27 | // Send request and get a result. 28 | // By default the result goes to standard output. 29 | myRequest.perform(); 30 | } 31 | 32 | catch(curlpp::RuntimeError & e) 33 | { 34 | std::cout << e.what() << std::endl; 35 | } 36 | 37 | catch(curlpp::LogicError & e) 38 | { 39 | std::cout << e.what() << std::endl; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /examples/example02.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Uploading of string. 27 | * ReadFunction option using functor. 28 | * Setting custom headers. 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | /* 42 | anonymous namespace to prevent name clash in case other examples using the same global entities 43 | would be compiled in the same project 44 | */ 45 | namespace 46 | { 47 | 48 | char *data = NULL; 49 | 50 | size_t readData(char *buffer, size_t size, size_t nitems) 51 | { 52 | strncpy(buffer, data, size * nitems); 53 | return size * nitems; 54 | } 55 | 56 | } // namespace 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | if(argc != 3) 61 | { 62 | std::cerr << "Example 2: Missing argument" << std::endl 63 | << "Example 2: Usage: example02 url string-to-send" 64 | << std::endl; 65 | return EXIT_FAILURE; 66 | } 67 | 68 | char *url = argv[1]; 69 | data = argv[2]; 70 | int size = strlen(data); 71 | 72 | char buf[50]; 73 | try 74 | { 75 | curlpp::Cleanup cleaner; 76 | curlpp::Easy request; 77 | 78 | std::list headers; 79 | headers.push_back("Content-Type: text/*"); 80 | sprintf(buf, "Content-Length: %d", size); 81 | headers.push_back(buf); 82 | 83 | using namespace curlpp::Options; 84 | request.setOpt(new Verbose(true)); 85 | request.setOpt(new ReadFunction(curlpp::types::ReadFunctionFunctor(readData))); 86 | request.setOpt(new InfileSize(size)); 87 | request.setOpt(new Upload(true)); 88 | request.setOpt(new HttpHeader(headers)); 89 | request.setOpt(new Url(url)); 90 | 91 | request.perform(); 92 | } 93 | catch (curlpp::LogicError & e) 94 | { 95 | std::cout << e.what() << std::endl; 96 | } 97 | catch (curlpp::RuntimeError & e) 98 | { 99 | std::cout << e.what() << std::endl; 100 | } 101 | 102 | return 0; 103 | } 104 | 105 | -------------------------------------------------------------------------------- /examples/example03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * DebugFunction option using functor as a callback. 27 | */ 28 | 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | class MyWindow 38 | { 39 | public: 40 | int writeDebug(curl_infotype, char *data, size_t size) 41 | { 42 | fprintf(stderr, "Debug: "); 43 | fwrite(data, size, 1, stderr); 44 | return size; 45 | } 46 | }; 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | 51 | if(argc != 2) 52 | { 53 | std::cerr << "Example 3: Wrong number of arguments" << std::endl 54 | << "Example 3: Usage: example3 url" 55 | << std::endl; 56 | return EXIT_FAILURE; 57 | } 58 | char *url = argv[1]; 59 | 60 | MyWindow myWindow; 61 | 62 | try 63 | { 64 | curlpp::Cleanup cleaner; 65 | curlpp::Easy request; 66 | 67 | using namespace curlpp::Options; 68 | request.setOpt(Verbose(true)); 69 | request.setOpt(DebugFunction(curlpp::types::DebugFunctionFunctor(&myWindow, 70 | &MyWindow::writeDebug))); 71 | request.setOpt(Url(url)); 72 | 73 | request.perform(); 74 | } 75 | 76 | catch ( curlpp::LogicError & e ) 77 | { 78 | std::cout << e.what() << std::endl; 79 | } 80 | 81 | catch ( curlpp::RuntimeError & e ) 82 | { 83 | std::cout << e.what() << std::endl; 84 | } 85 | 86 | return 0; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /examples/example04.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Getting options using curlpp::infos. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | if(argc != 2) 43 | { 44 | std::cerr << "Example 04: Wrong number of arguments" << std::endl 45 | << "Example 04: Usage: example04 url" 46 | << std::endl; 47 | return EXIT_FAILURE; 48 | } 49 | char *url = argv[1]; 50 | 51 | try 52 | { 53 | curlpp::Cleanup cleaner; 54 | curlpp::Easy request; 55 | 56 | using namespace curlpp::Options; 57 | request.setOpt(Verbose(true)); 58 | request.setOpt(Url(url)); 59 | 60 | request.perform(); 61 | 62 | std::string effURL; 63 | curlpp::infos::EffectiveUrl::get(request, effURL); 64 | std::cout << "Effective URL: " << effURL << std::endl; 65 | 66 | //other way to retreive URL 67 | std::cout << std::endl 68 | << "Effective URL: " 69 | << curlpp::infos::EffectiveUrl::get(request) 70 | << std::endl; 71 | 72 | std::cout << "Response code: " 73 | << curlpp::infos::ResponseCode::get(request) 74 | << std::endl; 75 | 76 | std::cout << "SSL engines: " 77 | << curlpp::infos::SslEngines::get(request) 78 | << std::endl; 79 | } 80 | catch ( curlpp::LogicError & e ) { 81 | std::cout << e.what() << std::endl; 82 | } 83 | catch ( curlpp::RuntimeError & e ) { 84 | std::cout << e.what() << std::endl; 85 | } 86 | 87 | return 0; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /examples/example05.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Write function using free function as a callback. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #define MAX_FILE_LENGTH 20000 40 | 41 | char *m_pBuffer = NULL; 42 | size_t m_Size = 0; 43 | 44 | void* Realloc(void* ptr, size_t size) 45 | { 46 | if(ptr) 47 | return realloc(ptr, size); 48 | else 49 | return malloc(size); 50 | }; 51 | 52 | // Callback must be declared static, otherwise it won't link... 53 | size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb) 54 | { 55 | // Calculate the real size of the incoming buffer 56 | size_t realsize = size * nmemb; 57 | 58 | // (Re)Allocate memory for the buffer 59 | m_pBuffer = (char*) Realloc(m_pBuffer, m_Size + realsize); 60 | 61 | // Test if Buffer is initialized correctly & copy memory 62 | if (m_pBuffer == NULL) { 63 | realsize = 0; 64 | } 65 | 66 | memcpy(&(m_pBuffer[m_Size]), ptr, realsize); 67 | m_Size += realsize; 68 | 69 | // return the real size of the buffer... 70 | return realsize; 71 | }; 72 | 73 | 74 | void print() 75 | { 76 | std::cout << "Size: " << m_Size << std::endl; 77 | std::cout << "Content: " << std::endl << m_pBuffer << std::endl; 78 | } 79 | 80 | 81 | int main(int argc, char *argv[]) 82 | { 83 | m_pBuffer = (char*) malloc(MAX_FILE_LENGTH * sizeof(char)); 84 | 85 | if(argc != 2) 86 | { 87 | std::cerr << "Example 05: Wrong number of arguments" << std::endl 88 | << "Example 05: Usage: example05 url" 89 | << std::endl; 90 | return EXIT_FAILURE; 91 | } 92 | char *url = argv[1]; 93 | 94 | try 95 | { 96 | curlpp::Cleanup cleaner; 97 | curlpp::Easy request; 98 | 99 | // Set the writer callback to enable cURL 100 | // to write result in a memory area 101 | curlpp::types::WriteFunctionFunctor functor(WriteMemoryCallback); 102 | curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); 103 | request.setOpt(test); 104 | 105 | // Setting the URL to retrive. 106 | request.setOpt(new curlpp::options::Url(url)); 107 | request.setOpt(new curlpp::options::Verbose(true)); 108 | request.perform(); 109 | 110 | print(); 111 | } 112 | catch ( curlpp::LogicError & e ) 113 | { 114 | std::cout << e.what() << std::endl; 115 | } 116 | catch ( curlpp::RuntimeError & e ) 117 | { 118 | std::cout << e.what() << std::endl; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /examples/example08.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * DebugFunction option using functor. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | 40 | class MyWindow 41 | { 42 | 43 | public: 44 | 45 | int writeDebug(curl_infotype, char *, size_t) 46 | { 47 | curlpp::raiseException(std::runtime_error("This is our exception.")); 48 | std::cout << "We never reach this line." << std::endl; 49 | return 0; 50 | } 51 | }; 52 | 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | if(argc != 2) 57 | { 58 | std::cerr << "Example 8: Wrong number of arguments" << std::endl 59 | << "Example 8: Usage: example8 url" 60 | << std::endl; 61 | return EXIT_FAILURE; 62 | } 63 | char *url = argv[1]; 64 | 65 | MyWindow myWindow; 66 | 67 | try 68 | { 69 | curlpp::Cleanup cleaner; 70 | curlpp::Easy request; 71 | 72 | using namespace curlpp::Options; 73 | request.setOpt(Verbose(true)); 74 | request.setOpt(DebugFunction(curlpp::types::DebugFunctionFunctor(&myWindow, 75 | &MyWindow::writeDebug))); 76 | request.setOpt(Url(url)); 77 | 78 | request.perform(); 79 | } 80 | 81 | catch ( curlpp::LogicError & e ) 82 | { 83 | std::cout << e.what() << std::endl; 84 | } 85 | 86 | catch ( curlpp::RuntimeError & e ) 87 | { 88 | std::cout << e.what() << std::endl; 89 | } 90 | 91 | catch ( std::runtime_error &e ) 92 | { 93 | std::cout << e.what() << std::endl; 94 | } 95 | 96 | return 0; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /examples/example09.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * DebugFunction option using functor. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | class MyWindow 40 | { 41 | 42 | public: 43 | 44 | int writeDebug(curl_infotype, char *, size_t) 45 | { 46 | throw std::runtime_error("This is the unknown exception."); 47 | std::cout << "We never reach this line." << std::endl; 48 | return 0; 49 | } 50 | }; 51 | 52 | 53 | int main(int argc, char *argv[]) 54 | { 55 | if(argc != 2) 56 | { 57 | std::cerr << "Example 9: Wrong number of arguments" << std::endl 58 | << "Example 9: Usage: example9 url" 59 | << std::endl; 60 | return EXIT_FAILURE; 61 | } 62 | char *url = argv[1]; 63 | 64 | MyWindow myWindow; 65 | try 66 | { 67 | curlpp::Cleanup cleaner; 68 | curlpp::Easy request; 69 | 70 | using namespace curlpp::Options; 71 | request.setOpt(Verbose(true)); 72 | request.setOpt(DebugFunction(curlpp::types::DebugFunctionFunctor(&myWindow, 73 | &MyWindow::writeDebug))); 74 | request.setOpt(Url(url)); 75 | 76 | request.perform(); 77 | } 78 | 79 | catch ( curlpp::LogicError & e ) 80 | { 81 | std::cout << e.what() << std::endl; 82 | } 83 | 84 | catch ( curlpp::RuntimeError & e ) 85 | { 86 | std::cout << e.what() << std::endl; 87 | } 88 | 89 | catch ( std::runtime_error &e ) 90 | { 91 | std::cout << e.what() << std::endl; 92 | } 93 | 94 | return 0; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /examples/example10.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * WriteFunction option using functor. 27 | * Writing to FILE* 28 | * 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #define MAX_FILE_LENGTH 20000 42 | 43 | size_t 44 | FileCallback(FILE *f, char* ptr, size_t size, size_t nmemb) 45 | { 46 | return fwrite(ptr, size, nmemb, f); 47 | }; 48 | 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | if(argc != 3) 53 | { 54 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 55 | << argv[0] << ": Usage: " << " url file" 56 | << std::endl; 57 | 58 | return EXIT_FAILURE; 59 | } 60 | 61 | char *url = argv[1]; 62 | char *filename = argv[2]; 63 | FILE * file = fopen(filename, "w"); 64 | if (!file) 65 | { 66 | std::cerr << "Error opening " << filename << std::endl; 67 | return EXIT_FAILURE; 68 | } 69 | 70 | try 71 | { 72 | curlpp::Cleanup cleaner; 73 | curlpp::Easy request; 74 | 75 | // Set the writer callback to enable cURL to write result in a memory area 76 | curlpp::types::WriteFunctionFunctor functor(utilspp::BindFirst(utilspp::make_functor(&FileCallback), file)); 77 | curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); 78 | request.setOpt(test); 79 | 80 | // Setting the URL to retrive. 81 | request.setOpt(new curlpp::options::Url(url)); 82 | request.setOpt(new curlpp::options::Verbose(true)); 83 | request.perform(); 84 | 85 | return EXIT_SUCCESS; 86 | } 87 | 88 | catch ( curlpp::LogicError & e ) 89 | { 90 | std::cout << e.what() << std::endl; 91 | } 92 | 93 | catch ( curlpp::RuntimeError & e ) 94 | { 95 | std::cout << e.what() << std::endl; 96 | } 97 | 98 | return EXIT_FAILURE; 99 | } 100 | -------------------------------------------------------------------------------- /examples/example11.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * WriteFunction option using free function. 27 | * Writing to FILE* 28 | * 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | /// Callback must be declared static, otherwise it won't link... 43 | size_t WriteCallback(char* ptr, size_t size, size_t nmemb, void *f) 44 | { 45 | FILE *file = (FILE *)f; 46 | return fwrite(ptr, size, nmemb, file); 47 | }; 48 | 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | if(argc < 2) 53 | { 54 | std::cerr << "Example 11: Wrong number of arguments" << std::endl 55 | << "Example 11: Usage: example11 url [file]" 56 | << std::endl; 57 | return EXIT_FAILURE; 58 | } 59 | char *url = argv[1]; 60 | char *filename = NULL; 61 | if(argc >= 3) 62 | { 63 | filename = argv[2]; 64 | } 65 | 66 | try 67 | { 68 | curlpp::Cleanup cleaner; 69 | curlpp::Easy request; 70 | 71 | /// Set the writer callback to enable cURL to write result in a memory area 72 | curlpp::options::WriteFunctionCurlFunction 73 | myFunction(WriteCallback); 74 | 75 | FILE *file = stdout; 76 | if(filename != NULL) 77 | { 78 | file = fopen(filename, "wb"); 79 | if(file == NULL) 80 | { 81 | fprintf(stderr, "%s/n", strerror(errno)); 82 | return EXIT_FAILURE; 83 | } 84 | } 85 | 86 | curlpp::OptionTrait 87 | myData(file); 88 | 89 | request.setOpt(myFunction); 90 | request.setOpt(myData); 91 | 92 | /// Setting the URL to retrive. 93 | request.setOpt(new curlpp::options::Url(url)); 94 | request.setOpt(new curlpp::options::Verbose(true)); 95 | request.perform(); 96 | } 97 | 98 | catch (curlpp::LogicError & e) 99 | { 100 | std::cout << e.what() << std::endl; 101 | } 102 | 103 | catch (curlpp::RuntimeError & e) 104 | { 105 | std::cout << e.what() << std::endl; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/example12.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Simple POST demo. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | if(argc < 2) { 42 | std::cerr << "Example 11: Wrong number of arguments" << std::endl 43 | << "Example 11: Usage: example12 url" 44 | << std::endl; 45 | return EXIT_FAILURE; 46 | } 47 | 48 | char *url = argv[1]; 49 | 50 | try { 51 | curlpp::Cleanup cleaner; 52 | curlpp::Easy request; 53 | 54 | request.setOpt(new curlpp::options::Url(url)); 55 | request.setOpt(new curlpp::options::Verbose(true)); 56 | 57 | std::list header; 58 | header.push_back("Content-Type: application/octet-stream"); 59 | 60 | request.setOpt(new curlpp::options::HttpHeader(header)); 61 | 62 | request.setOpt(new curlpp::options::PostFields("abcd")); 63 | request.setOpt(new curlpp::options::PostFieldSize(5)); 64 | 65 | request.perform(); 66 | } 67 | catch ( curlpp::LogicError & e ) { 68 | std::cout << e.what() << std::endl; 69 | } 70 | catch ( curlpp::RuntimeError & e ) { 71 | std::cout << e.what() << std::endl; 72 | } 73 | 74 | return EXIT_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /examples/example13.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Simple Multi demo. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | if(argc < 3) { 45 | std::cerr << "Example 13: Wrong number of arguments" << std::endl 46 | << "Example 13: Usage: example13 url1 url2" 47 | << std::endl; 48 | return EXIT_FAILURE; 49 | } 50 | 51 | char *url1 = argv[1]; 52 | char *url2 = argv[2]; 53 | 54 | try { 55 | curlpp::Cleanup cleaner; 56 | 57 | curlpp::Easy request1; 58 | curlpp::Easy request2; 59 | 60 | request1.setOpt(new curlpp::options::Url(url1)); 61 | request1.setOpt(new curlpp::options::Verbose(true)); 62 | 63 | request2.setOpt(new curlpp::options::Url(url2)); 64 | request2.setOpt(new curlpp::options::Verbose(true)); 65 | 66 | int nbLeft; 67 | curlpp::Multi requests; 68 | requests.add(&request1); 69 | requests.add(&request2); 70 | 71 | /* we start some action by calling perform right away */ 72 | while(!requests.perform(&nbLeft)) {}; 73 | 74 | while(nbLeft) { 75 | struct timeval timeout; 76 | int rc; /* select() return code */ 77 | 78 | fd_set fdread; 79 | fd_set fdwrite; 80 | fd_set fdexcep; 81 | int maxfd; 82 | 83 | FD_ZERO(&fdread); 84 | FD_ZERO(&fdwrite); 85 | FD_ZERO(&fdexcep); 86 | 87 | /* set a suitable timeout to play around with */ 88 | timeout.tv_sec = 1; 89 | timeout.tv_usec = 0; 90 | 91 | /* get file descriptors from the transfers */ 92 | requests.fdset(&fdread, &fdwrite, &fdexcep, &maxfd); 93 | 94 | rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); 95 | 96 | switch(rc) { 97 | case -1: 98 | /* select error */ 99 | nbLeft = 0; 100 | printf("select() returns error, this is badness\n"); 101 | break; 102 | case 0: 103 | default: 104 | /* timeout or readable/writable sockets */ 105 | while(!requests.perform(&nbLeft)) {}; 106 | break; 107 | } 108 | } 109 | 110 | std::cout << "NB lefts: " << nbLeft << std::endl; 111 | } 112 | catch ( curlpp::LogicError & e ) { 113 | std::cout << e.what() << std::endl; 114 | } 115 | catch ( curlpp::RuntimeError & e ) { 116 | std::cout << e.what() << std::endl; 117 | } 118 | 119 | return EXIT_SUCCESS; 120 | } 121 | 122 | 123 | -------------------------------------------------------------------------------- /examples/example15.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Using options. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | int main(int, char **) 40 | { 41 | try 42 | { 43 | curlpp::Cleanup myCleanup; 44 | 45 | // Creation of the URL option. 46 | curlpp::Easy myRequest; 47 | myRequest.setOpt(new curlpp::options::Url(std::string("https://example.com"))); 48 | myRequest.setOpt(new curlpp::options::SslEngineDefault()); 49 | myRequest.perform(); 50 | } 51 | catch( curlpp::RuntimeError &e ) 52 | { 53 | std::cout << e.what() << std::endl; 54 | } 55 | catch( curlpp::LogicError &e ) 56 | { 57 | std::cout << e.what() << std::endl; 58 | } 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /examples/example16.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Simple POST demo. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | if(argc < 2) { 43 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 44 | << "Usage: " << argv[0] << " url" 45 | << std::endl; 46 | return EXIT_FAILURE; 47 | } 48 | 49 | char *url = argv[1]; 50 | 51 | try { 52 | curlpp::Cleanup cleaner; 53 | curlpp::Easy request; 54 | 55 | request.setOpt(new curlpp::options::Url(url)); 56 | request.setOpt(new curlpp::options::Verbose(true)); 57 | 58 | std::list header; 59 | header.push_back("Content-Type: application/octet-stream"); 60 | 61 | request.setOpt(new curlpp::options::HttpHeader(header)); 62 | 63 | request.setOpt(new curlpp::options::PostFields("abcd")); 64 | request.setOpt(new curlpp::options::PostFieldSize(5)); 65 | 66 | request.setOpt(new curlpp::options::UserPwd("user:password")); 67 | 68 | request.perform(); 69 | } 70 | catch ( curlpp::LogicError & e ) { 71 | std::cout << e.what() << std::endl; 72 | } 73 | catch ( curlpp::RuntimeError & e ) { 74 | std::cout << e.what() << std::endl; 75 | } 76 | 77 | return EXIT_SUCCESS; 78 | } 79 | -------------------------------------------------------------------------------- /examples/example17.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | 33 | struct MethodClass 34 | { 35 | private: 36 | MethodClass(); 37 | 38 | public: 39 | MethodClass(std::ostream * stream) 40 | : mStream(stream) 41 | , writeRound(0) 42 | {} 43 | 44 | // Helper Class for reading result from remote host 45 | size_t write(curlpp::Easy *handle, char* ptr, size_t size, size_t nmemb) 46 | { 47 | ++writeRound; 48 | 49 | curlpp::options::Url url; 50 | handle->getOpt(url); 51 | 52 | // Calculate the real size of the incoming buffer 53 | size_t realsize = size * nmemb; 54 | std::cerr << "write round: " << writeRound << ", url: " << url.getValue() << std::endl; 55 | mStream->write(ptr, realsize); 56 | // return the real size of the buffer... 57 | return realsize; 58 | }; 59 | 60 | // Public member vars 61 | std::ostream * mStream; 62 | unsigned writeRound; 63 | }; 64 | 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | if(argc != 2) { 69 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 70 | << argv[0] << ": Usage: " << " url " 71 | << std::endl; 72 | return EXIT_FAILURE; 73 | } 74 | 75 | char *url = argv[1]; 76 | 77 | try { 78 | curlpp::Cleanup cleaner; 79 | curlpp::Easy request; 80 | 81 | MethodClass mObject(&std::cout); 82 | 83 | // Set the writer callback to enable cURL 84 | // to write result in a memory area 85 | curlpp::types::WriteFunctionFunctor functor(utilspp::BindFirst(utilspp::make_functor(&mObject, &MethodClass::write), &request)); 86 | curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); 87 | request.setOpt(test); 88 | 89 | // Setting the URL to retrive. 90 | request.setOpt(new curlpp::options::Url(url)); 91 | request.perform(); 92 | 93 | return EXIT_SUCCESS; 94 | } 95 | catch ( curlpp::LogicError & e ) { 96 | std::cout << e.what() << std::endl; 97 | } 98 | catch ( curlpp::RuntimeError & e ) { 99 | std::cout << e.what() << std::endl; 100 | } 101 | 102 | return EXIT_FAILURE; 103 | } 104 | -------------------------------------------------------------------------------- /examples/example18.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * WriteFunction using streams. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | struct MethodClass 43 | { 44 | private: 45 | MethodClass(); 46 | 47 | public: 48 | MethodClass(std::ostream * stream) 49 | : mStream(stream) 50 | , writeRound(0) 51 | {} 52 | 53 | // Helper Class for reading result from remote host 54 | size_t write(curlpp::Easy *handle, char* ptr, size_t size, size_t nmemb) 55 | { 56 | ++writeRound; 57 | 58 | curlpp::options::Url url; 59 | handle->getOpt(url); 60 | 61 | // Calculate the real size of the incoming buffer 62 | size_t realsize = size * nmemb; 63 | std::cerr << "write round: " << writeRound << ", url: " << url.getValue() << std::endl; 64 | mStream->write(ptr, realsize); 65 | // return the real size of the buffer... 66 | return realsize; 67 | }; 68 | 69 | // Public member vars 70 | std::ostream * mStream; 71 | unsigned writeRound; 72 | }; 73 | 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | if(argc != 2) { 78 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 79 | << argv[0] << ": Usage: " << " url " 80 | << std::endl; 81 | return EXIT_FAILURE; 82 | } 83 | 84 | char *url = argv[1]; 85 | 86 | try { 87 | curlpp::Cleanup cleaner; 88 | curlpp::Easy request; 89 | 90 | std::ostringstream myStream; 91 | MethodClass mObject(&myStream); 92 | 93 | 94 | // Set the writer callback to enable cURL 95 | // to write result in a memory area 96 | #ifdef HAVE_BOOST 97 | curlpp::options::BoostWriteFunction *test = new curlpp::options::BoostWriteFunction(boost::bind(&MethodClass::write, &mObject, &request, _1, _2, _3)); 98 | request.setOpt(test); 99 | #endif /* HAVE_BOOST */ 100 | 101 | // Setting the URL to retrive. 102 | request.setOpt(new curlpp::options::Url(url)); 103 | 104 | request.perform(); 105 | 106 | return EXIT_SUCCESS; 107 | } 108 | catch ( curlpp::LogicError & e ) { 109 | std::cout << e.what() << std::endl; 110 | } 111 | catch ( curlpp::RuntimeError & e ) { 112 | std::cout << e.what() << std::endl; 113 | } 114 | 115 | return EXIT_FAILURE; 116 | } 117 | -------------------------------------------------------------------------------- /examples/example19.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Forms demo. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | if(argc < 2) { 44 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 45 | << "Usage: " << argv[0] << " url" 46 | << std::endl; 47 | return EXIT_FAILURE; 48 | } 49 | 50 | char *url = argv[1]; 51 | 52 | try { 53 | curlpp::Cleanup cleaner; 54 | curlpp::Easy request; 55 | 56 | request.setOpt(new curlpp::options::Url(url)); 57 | //request.setOpt(new curlpp::options::Verbose(true)); 58 | 59 | { 60 | // Forms takes ownership of pointers! 61 | curlpp::Forms formParts; 62 | formParts.push_back(new curlpp::FormParts::Content("name1", "value1")); 63 | formParts.push_back(new curlpp::FormParts::Content("name2", "value2")); 64 | 65 | request.setOpt(new curlpp::options::HttpPost(formParts)); 66 | } 67 | 68 | // The forms have been cloned and are valid for the request, even 69 | // if the original forms are out of scope. 70 | std::ofstream myfile("/dev/null"); 71 | myfile << request << std::endl << request << std::endl; 72 | } 73 | catch ( curlpp::LogicError & e ) { 74 | std::cout << e.what() << std::endl; 75 | } 76 | catch ( curlpp::RuntimeError & e ) { 77 | std::cout << e.what() << std::endl; 78 | } 79 | 80 | return EXIT_SUCCESS; 81 | } 82 | -------------------------------------------------------------------------------- /examples/example20.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Using WriteStream option. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | if(argc != 2) { 44 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 45 | << argv[0] << ": Usage: " << " url " 46 | << std::endl; 47 | return EXIT_FAILURE; 48 | } 49 | 50 | char *url = argv[1]; 51 | 52 | try { 53 | curlpp::Cleanup cleaner; 54 | curlpp::Easy request; 55 | 56 | // Set the writer callback to enable cURL 57 | // to write result in a memory area 58 | request.setOpt(new curlpp::options::WriteStream(&std::cout)); 59 | 60 | // Setting the URL to retrive. 61 | request.setOpt(new curlpp::options::Url(url)); 62 | 63 | request.perform(); 64 | 65 | return EXIT_SUCCESS; 66 | } 67 | catch ( curlpp::LogicError & e ) { 68 | std::cout << e.what() << std::endl; 69 | } 70 | catch ( curlpp::RuntimeError & e ) { 71 | std::cout << e.what() << std::endl; 72 | } 73 | 74 | return EXIT_FAILURE; 75 | } 76 | -------------------------------------------------------------------------------- /examples/example21.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Using ReadStream option. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | /* 43 | anonymous namespace to prevent name clash in case other examples using the same global entities 44 | would be compiled in the same project 45 | */ 46 | namespace 47 | { 48 | 49 | char *data = NULL; 50 | 51 | size_t readData(char *buffer, size_t size, size_t nitems) 52 | { 53 | strncpy(buffer, data, size * nitems); 54 | return size * nitems; 55 | } 56 | 57 | } // namespace 58 | 59 | int main(int argc, char *argv[]) 60 | { 61 | if(argc != 3) { 62 | std::cerr << "Example 2: Missing argument" << std::endl 63 | << "Example 2: Usage: example02 url string-to-send" 64 | << std::endl; 65 | return EXIT_FAILURE; 66 | } 67 | char *url = argv[1]; 68 | 69 | std::istringstream myStream(argv[2]); 70 | int size = myStream.str().size(); 71 | 72 | char buf[50]; 73 | try 74 | { 75 | curlpp::Cleanup cleaner; 76 | curlpp::Easy request; 77 | 78 | std::list< std::string > headers; 79 | headers.push_back("Content-Type: text/*"); 80 | sprintf(buf, "Content-Length: %d", size); 81 | headers.push_back(buf); 82 | 83 | using namespace curlpp::Options; 84 | request.setOpt(new Verbose(true)); 85 | request.setOpt(new ReadStream(&myStream)); 86 | request.setOpt(new InfileSize(size)); 87 | request.setOpt(new Upload(true)); 88 | request.setOpt(new HttpHeader(headers)); 89 | request.setOpt(new Url(url)); 90 | 91 | request.perform(); 92 | } 93 | catch ( curlpp::LogicError & e ) 94 | { 95 | std::cout << e.what() << std::endl; 96 | } 97 | catch ( curlpp::RuntimeError & e ) 98 | { 99 | std::cout << e.what() << std::endl; 100 | } 101 | 102 | return 0; 103 | } 104 | 105 | -------------------------------------------------------------------------------- /examples/example22.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * \file 26 | * Using options::Url as stream input. 27 | * 28 | */ 29 | 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | if(argc != 2) { 43 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 44 | << argv[0] << ": Usage: " << " url " 45 | << std::endl; 46 | return EXIT_FAILURE; 47 | } 48 | 49 | char *url = argv[1]; 50 | 51 | try { 52 | curlpp::Cleanup cleaner; 53 | curlpp::Easy request; 54 | 55 | // Setting the URL to retrive. 56 | request.setOpt(new curlpp::options::Url(url)); 57 | 58 | std::cout << request << std::endl; 59 | 60 | // Even easier version. It does the same thing 61 | // but if you need to download only an url, 62 | // this is the easiest way to do it. 63 | std::cout << curlpp::options::Url(url) << std::endl; 64 | 65 | return EXIT_SUCCESS; 66 | } 67 | catch ( curlpp::LogicError & e ) { 68 | std::cout << e.what() << std::endl; 69 | } 70 | catch ( curlpp::RuntimeError & e ) { 71 | std::cout << e.what() << std::endl; 72 | } 73 | 74 | return EXIT_FAILURE; 75 | } 76 | -------------------------------------------------------------------------------- /examples/example23.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Setting request options using iterators to custom container of curlpp options. 4 | * 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | using namespace curlpp::options; 15 | 16 | int main(int, char **) 17 | { 18 | 19 | try 20 | { 21 | 22 | // That's all that is needed to do cleanup of used resources (RAII style). 23 | curlpp::Cleanup myCleanup; 24 | 25 | // Our request to be sent. 26 | curlpp::Easy myRequest; 27 | 28 | // Container of our choice with pointers to curlpp options. 29 | std::vector options; 30 | 31 | options.push_back(new Url("http://example.com")); 32 | options.push_back(new Port(80)); 33 | 34 | // Set all options in range to the Easy handle. 35 | myRequest.setOpt(options.begin(), options.end()); 36 | 37 | // Send request and get a result. 38 | // By default the result goes to standard output. 39 | myRequest.perform(); 40 | 41 | } 42 | 43 | 44 | catch(curlpp::RuntimeError & e) 45 | { 46 | std::cout << e.what() << std::endl; 47 | } 48 | 49 | catch(curlpp::LogicError & e) 50 | { 51 | std::cout << e.what() << std::endl; 52 | } 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /examples/example24.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | 33 | struct MethodClass 34 | { 35 | private: 36 | MethodClass(); 37 | 38 | public: 39 | MethodClass(std::ostream * stream) 40 | : mStream(stream) 41 | , writeRound(0) 42 | {} 43 | 44 | // Helper Class for reading result from remote host 45 | size_t debug(curlpp::Easy *handle, curl_infotype type, char* ptr, size_t size) 46 | { 47 | ++writeRound; 48 | 49 | curlpp::options::Url url; 50 | handle->getOpt(url); 51 | 52 | // Calculate the real size of the incoming buffer 53 | std::cerr << "write round: " << writeRound << ", url: " << url.getValue() << ", type: " << type << std::endl; 54 | mStream->write(ptr, size); 55 | 56 | // return the real size of the buffer... 57 | return size; 58 | }; 59 | 60 | // Public member vars 61 | std::ostream * mStream; 62 | unsigned writeRound; 63 | }; 64 | 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | if(argc != 2) { 69 | std::cerr << argv[0] << ": Wrong number of arguments" << std::endl 70 | << argv[0] << ": Usage: " << " url " 71 | << std::endl; 72 | return EXIT_FAILURE; 73 | } 74 | 75 | char *url = argv[1]; 76 | 77 | try { 78 | curlpp::Cleanup cleaner; 79 | curlpp::Easy request; 80 | 81 | MethodClass mObject(&std::cerr); 82 | 83 | // Set the debug callback to enable cURL 84 | // to write result in a stream 85 | curlpp::types::DebugFunctionFunctor functor(utilspp::BindFirst(utilspp::make_functor(&mObject, &MethodClass::debug), &request)); 86 | curlpp::options::DebugFunction * test = new curlpp::options::DebugFunction(functor); 87 | request.setOpt(test); 88 | 89 | // Setting the URL to retrive. 90 | request.setOpt(new curlpp::options::Url(url)); 91 | request.setOpt(new curlpp::options::Verbose(true)); 92 | request.perform(); 93 | 94 | return EXIT_SUCCESS; 95 | } 96 | catch ( curlpp::LogicError & e ) { 97 | std::cout << e.what() << std::endl; 98 | } 99 | catch ( curlpp::RuntimeError & e ) { 100 | std::cout << e.what() << std::endl; 101 | } 102 | 103 | return EXIT_FAILURE; 104 | } 105 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | add_subdirectory(curlpp) 5 | add_subdirectory(utilspp) 6 | 7 | 8 | ########### install files ############### 9 | 10 | 11 | 12 | 13 | #original Makefile.am contents follow: 14 | 15 | #SUBDIRS = curlpp utilspp -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = curlpp utilspp -------------------------------------------------------------------------------- /include/curlpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) 5 | 6 | 7 | ########### install files ############### 8 | 9 | install(FILES Easy.hpp Easy.inl Exception.hpp Form.hpp Info.hpp Info.inl Infos.hpp Multi.hpp Option.hpp Option.inl OptionBase.hpp Options.hpp Types.hpp cURLpp.hpp config.h.in config.h.sample config.win32.h DESTINATION /include/curlpp) 10 | 11 | 12 | 13 | #original Makefile.am contents follow: 14 | 15 | #pkginclude_HEADERS = \ 16 | # Easy.hpp Easy.inl \ 17 | # Exception.hpp \ 18 | # Form.hpp \ 19 | # Info.hpp Info.inl \ 20 | # Infos.hpp \ 21 | # Multi.hpp \ 22 | # Option.hpp Option.inl \ 23 | # OptionBase.hpp \ 24 | # Options.hpp \ 25 | # Types.hpp \ 26 | # cURLpp.hpp \ 27 | # config.h.in \ 28 | # config.h.sample \ 29 | # config.win32.h 30 | # 31 | #pkgincludedir=$(includedir)/curlpp 32 | -------------------------------------------------------------------------------- /include/curlpp/Easy.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | template 26 | void curlpp::Easy::getInfo(CURLINFO info, T & value) const 27 | { 28 | mCurl->getInfo(info, value); 29 | } 30 | 31 | 32 | template 33 | void 34 | curlpp::Easy::setOpt(typename OptionTrait::ParamType value) 35 | { 36 | setOpt(curlpp::OptionTrait(value)); 37 | } 38 | 39 | 40 | template 41 | void 42 | curlpp::Easy::setOpt(InputIterator first, InputIterator last) 43 | { 44 | for(InputIterator it=first; it != last; ++it) 45 | { 46 | setOpt(*it); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /include/curlpp/Info.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_INFO_INL 25 | #define CURLPP_INFO_INL 26 | 27 | template 28 | void 29 | curlpp::Info::get(const curlpp::Easy & handle, T & value) 30 | { 31 | curlpp::InfoTypeConverter::get(handle, info, value); 32 | } 33 | 34 | template 35 | T 36 | curlpp::Info::get(const curlpp::Easy & handle) 37 | { 38 | T value; 39 | curlpp::InfoTypeConverter::get(handle, info, value); 40 | return value; 41 | } 42 | 43 | template 44 | void 45 | curlpp::NotAvailableInfo::get(const curlpp::Easy &, T &) 46 | { 47 | throw curlpp::NotAvailable(); 48 | } 49 | 50 | template 51 | T 52 | curlpp::NotAvailableInfo::get(const curlpp::Easy &) 53 | { 54 | throw curlpp::NotAvailable(); 55 | } 56 | 57 | 58 | 59 | template 60 | void 61 | curlpp::InfoGetter::get(const curlpp::Easy & handle, 62 | CURLINFO info, 63 | T & value) 64 | { 65 | handle.getInfo(info, value); 66 | } 67 | 68 | 69 | template 70 | void 71 | curlpp::InfoTypeConverter::get(const curlpp::Easy & handle, 72 | CURLINFO info, 73 | T & value) 74 | { 75 | InfoGetter::get(handle, info, value); 76 | } 77 | 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/curlpp/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = internal 2 | 3 | pkginclude_HEADERS = \ 4 | Easy.hpp Easy.inl \ 5 | Exception.hpp \ 6 | Form.hpp \ 7 | Info.hpp Info.inl \ 8 | Infos.hpp \ 9 | Multi.hpp \ 10 | Option.hpp Option.inl \ 11 | OptionBase.hpp \ 12 | Options.hpp \ 13 | Types.hpp \ 14 | cURLpp.hpp \ 15 | config.h.in \ 16 | config.h.sample \ 17 | config.win32.h 18 | 19 | pkgincludedir=$(includedir)/curlpp 20 | -------------------------------------------------------------------------------- /include/curlpp/Multi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_MULTI_HPP 25 | #define CURLPP_MULTI_HPP 26 | 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | 34 | namespace curlpp 35 | { 36 | 37 | 38 | class Easy; 39 | 40 | class CURLPPAPI Multi 41 | { 42 | 43 | public: 44 | 45 | struct Info 46 | { 47 | CURLcode code; 48 | CURLMSG msg; 49 | }; 50 | 51 | public: 52 | 53 | Multi(); 54 | ~Multi(); 55 | 56 | void add(const curlpp::Easy * handle); 57 | void remove(const curlpp::Easy * handle); 58 | 59 | bool perform(int * nbHandles); 60 | void fdset(fd_set * read_fd_set, 61 | fd_set * write_fd_set, 62 | fd_set * exc_fd_set, 63 | int * max_fd); 64 | 65 | typedef std::list > 66 | Msgs; 67 | 68 | Msgs info(); 69 | 70 | private: 71 | 72 | CURLM * mMultiHandle; 73 | std::map mHandles; 74 | }; 75 | 76 | 77 | } // namespace curlpp 78 | 79 | namespace cURLpp = curlpp; 80 | 81 | 82 | #endif // #ifndef CURLPP_MULTI_HPP 83 | -------------------------------------------------------------------------------- /include/curlpp/OptionBase.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_OPTION_BASE_HPP 25 | #define CURLPP_OPTION_BASE_HPP 26 | 27 | 28 | #include "internal/buildconfig.h" 29 | 30 | #include 31 | 32 | 33 | namespace curlpp 34 | { 35 | 36 | 37 | namespace internal 38 | { 39 | 40 | 41 | class CurlHandle; 42 | 43 | 44 | } 45 | 46 | /** 47 | * This is the parent of the curlpp::option class. 48 | * 49 | * This is only used to be able to stock a list of options. 50 | */ 51 | 52 | class CURLPPAPI OptionBase 53 | { 54 | 55 | public: 56 | 57 | OptionBase(CURLoption option); 58 | 59 | /** 60 | * Base class needs virtual destructor. 61 | */ 62 | virtual ~OptionBase(); 63 | 64 | /** 65 | * See curlpp::option::operator< for documentation. 66 | */ 67 | virtual bool operator<(const OptionBase & rhs) const; 68 | 69 | /** 70 | * return a copy of the current option. 71 | */ 72 | virtual OptionBase * clone() const = 0; 73 | 74 | /** 75 | * return the libcurl option. 76 | */ 77 | CURLoption getOption() const; 78 | 79 | /** 80 | * will update the value of the option with the value of the 81 | * option passed is argument. 82 | */ 83 | virtual void updateMeToOption(const OptionBase & other) = 0; 84 | 85 | /** 86 | * will call the actual libcurl option function with the value we got 87 | * on the handle. 88 | */ 89 | virtual void updateHandleToMe(internal::CurlHandle * handle) const = 0; 90 | 91 | /** 92 | * this function will reset the option value. 93 | */ 94 | virtual void clear() = 0; 95 | 96 | private: 97 | 98 | CURLoption mOption; 99 | 100 | }; 101 | 102 | 103 | } // namespace curlpp 104 | 105 | namespace cURLpp = curlpp; 106 | 107 | 108 | #endif // #ifndef CURLPP_OPTION_BASE_HPP 109 | -------------------------------------------------------------------------------- /include/curlpp/Types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_TYPES_HPP 25 | #define CURLPP_TYPES_HPP 26 | 27 | 28 | #include "internal/global.h" 29 | 30 | #ifdef HAVE_BOOST 31 | #include 32 | #endif 33 | 34 | #include 35 | 36 | 37 | namespace curlpp 38 | { 39 | 40 | 41 | namespace types 42 | { 43 | 44 | 45 | typedef utilspp::Functor< 46 | size_t, 47 | TYPE_LIST_3(char*, size_t, size_t)> WriteFunctionFunctor; 48 | 49 | typedef utilspp::Functor< 50 | size_t, 51 | TYPE_LIST_3(char*, size_t, size_t)> ReadFunctionFunctor; 52 | 53 | /// DebugFunctor related typedefs 54 | typedef utilspp::Functor< 55 | int, 56 | TYPE_LIST_3(curl_infotype, 57 | char *, 58 | size_t)> DebugFunctionFunctor; 59 | 60 | typedef utilspp::Functor< 61 | CURLcode, 62 | TYPE_LIST_1(void *)> SslCtxFunctionFunctor; 63 | 64 | typedef utilspp::Functor< 65 | int, 66 | TYPE_LIST_4(double, double, double, double)> ProgressFunctionFunctor; 67 | 68 | #ifdef HAVE_BOOST 69 | typedef boost::function3 BoostWriteFunction; 70 | typedef boost::function3 BoostReadFunction; 71 | typedef boost::function3 BoostDebugFunction; 72 | typedef boost::function1 BoostSslCtxFunction; 73 | typedef boost::function4 BoostProgressFunction; 74 | #endif 75 | 76 | 77 | } // namespace types 78 | 79 | namespace Types = types; 80 | 81 | 82 | } // namespace curlpp 83 | 84 | namespace cURLpp = curlpp; 85 | 86 | 87 | #endif // #ifndef CURLPP_TYPES_HPP 88 | -------------------------------------------------------------------------------- /include/curlpp/config.h.sample: -------------------------------------------------------------------------------- 1 | /* curlpp/config.h. Generated from config.h.in by configure. */ 2 | /* curlpp/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* when building cURLpp itself */ 5 | /* #undef BUILDING_CURLPP */ 6 | 7 | /* when not building a shared library */ 8 | /* #undef CURLPP_STATICLIB */ 9 | 10 | /* define if the Boost library is available */ 11 | /* #undef HAVE_BOOST */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_CURL_CURL_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_DLFCN_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_INTTYPES_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_MEMORY_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_OSTREAM 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_STDINT_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDLIB_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STRINGS_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STRING_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_STAT_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_TYPES_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_UNISTD_H 1 48 | 49 | /* Name of package */ 50 | #define PACKAGE "curlpp" 51 | 52 | /* Define to the address where bug reports for this package should be sent. */ 53 | #define PACKAGE_BUGREPORT "" 54 | 55 | /* Define to the full name of this package. */ 56 | #define PACKAGE_NAME "" 57 | 58 | /* Define to the full name and version of this package. */ 59 | #define PACKAGE_STRING "" 60 | 61 | /* Define to the one symbol short name of this package. */ 62 | #define PACKAGE_TARNAME "" 63 | 64 | /* Define to the version of this package. */ 65 | #define PACKAGE_VERSION "" 66 | 67 | /* Define to 1 if you have the ANSI C header files. */ 68 | /* #undef STDC_HEADERS */ 69 | 70 | /* Version number of package */ 71 | #define VERSION "0.7.2" 72 | -------------------------------------------------------------------------------- /include/curlpp/config.win32.h: -------------------------------------------------------------------------------- 1 | /* config.win32.h Config for Win32 platform. See configure.ac */ 2 | /* config.h.in Generated from configure.ac by autoheader. */ 3 | 4 | /* Define when building curlpp itself */ 5 | /* DO NOT define or undefine this symbol if you are building from the IDE 6 | /* using solution files for VC9. Project files define or undefine this from within the IDE */ 7 | //#define BUILDING_CURLPP 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #define HAVE_CURL_CURL_H 1 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_DLFCN_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #define HAVE_MEMORY_H 1 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #define HAVE_OSTREAM 1 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STDINT_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #define HAVE_STDLIB_H 1 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_STRINGS_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #define HAVE_STRING_H 1 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #define HAVE_SYS_STAT_H 1 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #define HAVE_SYS_TYPES_H 1 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_UNISTD_H 44 | 45 | /* Name of package */ 46 | #define PACKAGE "curlpp" 47 | 48 | /* Define to the address where bug reports for this package should be sent. */ 49 | #undef PACKAGE_BUGREPORT 50 | 51 | /* Define to the full name of this package. */ 52 | #define PACKAGE_NAME "CurlPP" 53 | 54 | /* Define to the full name and version of this package. */ 55 | #undef PACKAGE_STRING 56 | 57 | /* Define to the one symbol short name of this package. */ 58 | #undef PACKAGE_TARNAME 59 | 60 | /* Define to the version of this package. */ 61 | #undef PACKAGE_VERSION 62 | 63 | /* Define to 1 if you have the ANSI C header files. */ 64 | #define STDC_HEADERS 65 | 66 | /* Version number of package */ 67 | #define VERSION 0.7.2 68 | -------------------------------------------------------------------------------- /include/curlpp/internal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### install files ############### 6 | 7 | install(FILES CurlHandle.hpp CurlHandle.inl OptionContainer.hpp OptionContainer.inl OptionContainerType.hpp OptionList.hpp OptionSetter.hpp OptionSetter.inl SList.hpp buildconfig.h global.h DESTINATION /include/curlpp/internal) 8 | 9 | 10 | 11 | #original Makefile.am contents follow: 12 | 13 | #pkginclude_HEADERS = \ 14 | # CurlHandle.hpp CurlHandle.inl \ 15 | # OptionContainer.hpp OptionContainer.inl OptionContainerType.hpp \ 16 | # OptionList.hpp \ 17 | # OptionSetter.hpp OptionSetter.inl \ 18 | # SList.hpp \ 19 | # buildconfig.h \ 20 | # global.h 21 | # 22 | #pkgincludedir=$(includedir)/curlpp/internal 23 | -------------------------------------------------------------------------------- /include/curlpp/internal/CurlHandle.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | #ifndef CURLPP_CURLHANDLE_INL 26 | #define CURLPP_CURLHANDLE_INL 27 | 28 | 29 | #include "../Exception.hpp" 30 | 31 | 32 | namespace curlpp 33 | { 34 | 35 | 36 | namespace internal 37 | { 38 | 39 | 40 | template 41 | void 42 | CurlHandle::option(CURLoption optionType, 43 | OptionType value) 44 | { 45 | CURLcode code; 46 | code = curl_easy_setopt(mCurl, optionType, value); 47 | libcurlRuntimeAssert(mErrorBuffer, code); 48 | } 49 | 50 | 51 | template 52 | void 53 | CurlHandle::option(OptionType value) 54 | { 55 | option(optionType, value); 56 | } 57 | 58 | 59 | template 60 | void 61 | CurlHandle::getInfo(CURLINFO info, T & value) const 62 | { 63 | CURLcode code; 64 | code = curl_easy_getinfo(mCurl, info, & value); 65 | libcurlRuntimeAssert(mErrorBuffer, code); 66 | } 67 | 68 | 69 | } // namespace internal 70 | 71 | 72 | } // namespace curlpp 73 | 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /include/curlpp/internal/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | pkginclude_HEADERS = \ 3 | CurlHandle.hpp CurlHandle.inl \ 4 | OptionContainer.hpp OptionContainer.inl OptionContainerType.hpp \ 5 | OptionList.hpp \ 6 | OptionSetter.hpp OptionSetter.inl \ 7 | SList.hpp \ 8 | buildconfig.h \ 9 | global.h 10 | 11 | pkgincludedir=$(includedir)/curlpp/internal 12 | -------------------------------------------------------------------------------- /include/curlpp/internal/OptionContainer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_OPTION_CONTAINER_HPP 25 | #define CURLPP_OPTION_CONTAINER_HPP 26 | 27 | 28 | #include "buildconfig.h" 29 | #include "OptionContainerType.hpp" 30 | 31 | 32 | namespace curlpp 33 | { 34 | 35 | 36 | namespace internal 37 | { 38 | 39 | 40 | template 41 | class Option; 42 | 43 | /** 44 | * This class is used to set an option to a handle and to keep it's value. 45 | */ 46 | template 47 | class CURLPPAPI OptionContainer 48 | { 49 | 50 | public: 51 | 52 | typedef typename OptionContainerType::ParamType ParamType; 53 | typedef typename OptionContainerType::ReturnType ReturnType; 54 | typedef typename OptionContainerType::ValueType ValueType; 55 | typedef typename OptionContainerType::HandleOptionType HandleOptionType; 56 | 57 | /** 58 | * Contructor. We pass the value of the option. 59 | */ 60 | OptionContainer(typename OptionContainer::ParamType value); 61 | 62 | OptionContainer(OptionContainer & other); 63 | 64 | /** 65 | * This function set the argument that will be passed to the 66 | * option call for a handle. It will use the argument passed to 67 | * this function. 68 | */ 69 | void setValue(typename OptionContainer::ParamType value); 70 | 71 | /** 72 | * This function get the argument that is set on the handle. 73 | */ 74 | typename OptionContainer::ReturnType getValue(); 75 | 76 | /** 77 | * We call this function to have the value passed to the curl_easy_setopt. 78 | * 79 | * Note: DO NOT USE THIS FUNCTION! It's for internal use only. 80 | */ 81 | typename OptionContainer::HandleOptionType getHandleOptionValue(); 82 | 83 | 84 | private: 85 | /** 86 | * We cannot call this constructor. We absolutely need an initial value. 87 | */ 88 | OptionContainer(); 89 | 90 | /** 91 | * Current value of the option. 92 | */ 93 | typename OptionContainer::ValueType mValue; 94 | }; 95 | 96 | 97 | } // namespace internal 98 | 99 | 100 | } // namespace curlpp 101 | 102 | namespace cURLpp = curlpp; 103 | 104 | 105 | #ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 106 | #include "OptionContainer.inl" 107 | #endif 108 | 109 | 110 | #endif // #ifndef CURLPP_OPTION_CONTAINER_HPP 111 | 112 | -------------------------------------------------------------------------------- /include/curlpp/internal/OptionContainer.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef OPTION_CONTAINER_INL 25 | #define OPTION_CONTAINER_INL 26 | 27 | 28 | namespace curlpp 29 | { 30 | 31 | 32 | namespace internal 33 | { 34 | 35 | 36 | template 37 | OptionContainer::OptionContainer(typename OptionContainer::ParamType value) 38 | : mValue(value) 39 | {} 40 | 41 | 42 | template 43 | OptionContainer::OptionContainer(OptionContainer & other) 44 | : mValue(other.mValue) 45 | {} 46 | 47 | 48 | template 49 | void 50 | OptionContainer::setValue(typename OptionContainer::ParamType value) 51 | { 52 | mValue = value; 53 | } 54 | 55 | template 56 | typename OptionContainer::ReturnType 57 | OptionContainer::getValue() 58 | { 59 | return mValue; 60 | } 61 | 62 | template 63 | typename OptionContainer::HandleOptionType 64 | OptionContainer::getHandleOptionValue() 65 | { 66 | return mValue; 67 | } 68 | 69 | #endif 70 | 71 | } // namespace internal 72 | 73 | } // namespace curlpp 74 | -------------------------------------------------------------------------------- /include/curlpp/internal/OptionSetter.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | 25 | #ifndef CURLPP_OPTIONSETTER_INL 26 | #define CURLPP_OPTIONSETTER_INL 27 | 28 | #include 29 | 30 | template 31 | void 32 | curlpp::internal::OptionSetter 33 | ::setOpt(internal::CurlHandle * handle, ParamType value) 34 | { 35 | handle->option(optionType, value); 36 | } 37 | 38 | 39 | template 40 | void 41 | curlpp::internal::OptionSetter 42 | ::setOpt(internal::CurlHandle * handle, ParamType value) 43 | { 44 | handle->option(optionType, (void *)value.c_str()); 45 | } 46 | 47 | 48 | template 49 | void 50 | curlpp::internal::OptionSetter, optionType> 51 | ::setOpt(internal::CurlHandle * handle, ParamType value) 52 | { 53 | handle->option(optionType, (void *)value.cslist()); 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/curlpp/internal/SList.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_SLIST_HPP 25 | #define CURLPP_SLIST_HPP 26 | 27 | 28 | #include "buildconfig.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | namespace curlpp 36 | { 37 | 38 | 39 | namespace internal 40 | { 41 | 42 | 43 | /** 44 | * This class is binding the curl_slist struct. 45 | */ 46 | 47 | class CURLPPAPI SList 48 | { 49 | 50 | public: 51 | 52 | SList(); 53 | SList(const SList & rhs); 54 | 55 | /** 56 | * The list passed in as an argument is now possessed by the class. 57 | */ 58 | SList(curl_slist * list); 59 | 60 | explicit SList(const std::list & list); 61 | ~SList(); 62 | 63 | SList & operator=(const std::list & list); 64 | operator std::list(); 65 | 66 | curl_slist * cslist() const; 67 | std::list list(); 68 | 69 | private: 70 | 71 | void set(const std::list & list); 72 | void update(); 73 | void clear(); 74 | void constructFrom(curl_slist * list); 75 | 76 | curl_slist * mList; 77 | std::list mData; 78 | 79 | }; 80 | 81 | 82 | } // namespace internal 83 | 84 | 85 | } // namespace curlpp 86 | 87 | namespace cURLpp = curlpp; 88 | 89 | 90 | std::ostream CURLPPAPI & operator<<(std::ostream & stream, const std::list & value); 91 | 92 | 93 | #endif // #ifndef CURLPP_SLIST_HPP 94 | -------------------------------------------------------------------------------- /include/curlpp/internal/buildconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2004> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_BUILDCONFIG_H 25 | #define CURLPP_BUILDCONFIG_H 26 | 27 | /* 28 | * Decorate exportable functions for Win32 DLL linking. 29 | * This avoids using a .def file for building curlpp.dll. 30 | */ 31 | #if !defined(CURLPP_STATICLIB) 32 | #if defined(BUILDING_CURLPP) 33 | #if (defined(WIN32) || defined(_WIN32)) 34 | #define CURLPPAPI __declspec(dllexport) 35 | #else 36 | #define CURLPPAPI 37 | #endif 38 | 39 | #define CURLPP_LIB_EXPORT 40 | #undef CURLPP_LIB_IMPORT 41 | #else 42 | #if (defined(WIN32) || defined(_WIN32)) 43 | #define CURLPPAPI __declspec(dllimport) 44 | #else 45 | #define CURLPPAPI 46 | #endif 47 | 48 | #define CURLPP_LIB_IMPORT 49 | #undef CURLPP_LIB_EXPORT 50 | #endif 51 | #else 52 | #define CURLPPAPI 53 | 54 | #undef CURLPP_LIB_IMPORT 55 | #undef CURLPP_LIB_EXPORT 56 | #endif 57 | 58 | #if defined (CURLPP_SELF_CONTAINED) 59 | #if defined(BUILDING_CURLPP) 60 | #define CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 61 | #define CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION 62 | #else 63 | #undef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 64 | #undef CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION 65 | #endif 66 | #else 67 | #if defined(BUILDING_CURLPP) 68 | #define CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 69 | #undef CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION 70 | #else 71 | #define CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 72 | #undef CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION 73 | #endif 74 | #endif 75 | 76 | 77 | #endif // #ifndef CURLPP_BUILDCONFIG_H 78 | -------------------------------------------------------------------------------- /include/curlpp/internal/global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CURLPP_GLOBAL_H 25 | #define CURLPP_GLOBAL_H 26 | 27 | #ifndef HAVE_CONFIG_H 28 | #include "curlpp/config.win32.h" 29 | #else 30 | #include "curlpp/config.h" 31 | #endif 32 | 33 | #endif // #ifndef CURLPP_GLOBAL_H 34 | -------------------------------------------------------------------------------- /include/utilspp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### install files ############### 6 | 7 | install(FILES EmptyType.hpp Functors.hpp NonCopyable.hpp NullType.hpp Singleton.hpp SmartPtr.hpp ThreadingFactoryMutex.hpp ThreadingFactoryMutex.inl ThreadingSingle.hpp ThreadingSingle.inl TypeList.hpp TypeTrait.hpp clone_ptr.hpp DESTINATION /include/utilspp) 8 | 9 | 10 | 11 | #original Makefile.am contents follow: 12 | 13 | #pkginclude_HEADERS = \ 14 | # EmptyType.hpp \ 15 | # Functors.hpp \ 16 | # NonCopyable.hpp \ 17 | # NullType.hpp \ 18 | # Singleton.hpp \ 19 | # SmartPtr.hpp \ 20 | # ThreadingFactoryMutex.hpp ThreadingFactoryMutex.inl \ 21 | # ThreadingSingle.hpp ThreadingSingle.inl \ 22 | # TypeList.hpp \ 23 | # TypeTrait.hpp \ 24 | # clone_ptr.hpp 25 | # 26 | #pkgincludedir=$(includedir)/utilspp 27 | -------------------------------------------------------------------------------- /include/utilspp/EmptyType.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef UTILSPP_EMPTYTYPE_HPP 25 | #define UTILSPP_EMPTYTYPE_HPP 26 | 27 | namespace utilspp 28 | { 29 | struct EmptyType {}; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/utilspp/Functors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef UTILSPP_FUNCTORS_HPP 25 | #define UTILSPP_FUNCTORS_HPP 26 | 27 | #include "functor/Functor.hpp" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/utilspp/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = functor singleton 2 | 3 | pkginclude_HEADERS = \ 4 | EmptyType.hpp \ 5 | Functors.hpp \ 6 | NonCopyable.hpp \ 7 | NullType.hpp \ 8 | Singleton.hpp \ 9 | SmartPtr.hpp \ 10 | ThreadingFactoryMutex.hpp ThreadingFactoryMutex.inl \ 11 | ThreadingSingle.hpp ThreadingSingle.inl \ 12 | TypeList.hpp \ 13 | TypeTrait.hpp \ 14 | clone_ptr.hpp 15 | 16 | pkgincludedir=$(includedir)/utilspp 17 | -------------------------------------------------------------------------------- /include/utilspp/NonCopyable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef UTILSPP_NONCOPYABLE_HPP 25 | #define UTILSPP_NONCOPYABLE_HPP 26 | 27 | namespace utilspp 28 | { 29 | class NonCopyable 30 | { 31 | public: 32 | NonCopyable() 33 | {} 34 | 35 | private: 36 | NonCopyable(const NonCopyable & r) 37 | {} 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/utilspp/NullType.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef UTILSPP_NULLTYPE_HPP 25 | #define UTILSPP_NULLTYPE_HPP 26 | 27 | namespace utilspp 28 | { 29 | struct NullType; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/utilspp/Singleton.hpp: -------------------------------------------------------------------------------- 1 | #include "ThreadingSingle.hpp" 2 | #include "singleton/SingletonHolder.hpp" 3 | #include "singleton/LifetimeLibrary.hpp" 4 | -------------------------------------------------------------------------------- /include/utilspp/ThreadingFactoryMutex.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef THREADING_FACTORY_MUTEX_HPP 25 | #define THREADING_FACTORY_MUTEX_HPP 26 | 27 | //#include "curlpp/internal/buildconfig.h" 28 | 29 | namespace utilspp 30 | { 31 | template 32 | struct ThreadingFactoryMutex 33 | { 34 | struct lock 35 | { 36 | lock(); 37 | lock(const T &); 38 | }; 39 | 40 | typedef T VolatileType; 41 | }; 42 | } 43 | 44 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 45 | #include "utilspp/ThreadingFactoryMutex.inl" 46 | //#endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/utilspp/ThreadingFactoryMutex.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef THREADING_FACTORY_MUTEX_INL 25 | #define THREADING_FACTORY_MUTEX_INL 26 | 27 | template 28 | inline 29 | utilspp::ThreadingSingle::lock::lock() 30 | {}; 31 | 32 | template 33 | inline 34 | utilspp::ThreadingSingle::lock::lock(const T &) 35 | {}; 36 | 37 | #endif -------------------------------------------------------------------------------- /include/utilspp/ThreadingSingle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef SINGLE_THREADED_HPP 25 | #define SINGLE_THREADED_HPP 26 | 27 | //#include "curlpp/internal/buildconfig.h" 28 | #include "utilspp/NullType.hpp" 29 | 30 | namespace utilspp 31 | { 32 | template 33 | struct ThreadingSingle 34 | { 35 | struct mutex 36 | { 37 | void lock(); 38 | void unlock(); 39 | }; 40 | 41 | struct lock 42 | { 43 | lock(); 44 | lock(mutex & m); 45 | }; 46 | 47 | typedef T VolatileType; 48 | }; 49 | } 50 | 51 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 52 | #include "utilspp/ThreadingSingle.inl" 53 | //#endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/utilspp/ThreadingSingle.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef SINGLE_THREADED_INL 25 | #define SINGLE_THREADED_INL 26 | 27 | template 28 | inline 29 | utilspp::ThreadingSingle::lock::lock() 30 | {}; 31 | 32 | template 33 | inline 34 | utilspp::ThreadingSingle::lock::lock( 35 | typename utilspp::ThreadingSingle::mutex & ) 36 | {} 37 | 38 | template 39 | inline 40 | void 41 | utilspp::ThreadingSingle::mutex::lock() 42 | {}; 43 | 44 | template 45 | inline 46 | void 47 | utilspp::ThreadingSingle::mutex::unlock() 48 | {}; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/utilspp/clone_ptr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef UTILSPP_CLONEPTR_HPP 25 | #define UTILSPP_CLONEPTR_HPP 26 | 27 | #include 28 | #include 29 | 30 | namespace utilspp 31 | { 32 | // This class is meant to manage a pointer. This class will 33 | // ensure that when we go out of scope, it will delete the 34 | // pointer. 35 | // 36 | // However, contrary to the std::auto_ptr, instead of 37 | // transfering the ownership on copy construction, it clones 38 | // the content. This means that we can have STL containers 39 | // that uses that class for managing the pointers. 40 | // 41 | // So, it means that the class we stores, needs a "clone" 42 | // member. 43 | template 44 | class clone_ptr 45 | { 46 | public: 47 | clone_ptr() : value_(NULL) {} 48 | 49 | // This constructor takes ownership of the pointer. 50 | // 51 | // Note that it isn't explicit. This might be a 52 | // problem. 53 | clone_ptr(T * value) : value_(value) {} 54 | 55 | ~clone_ptr() {if (value_) delete value_;} 56 | 57 | // This is the default constructor that takes his 58 | // value from cloning the content of the other 59 | // clone_ptr. 60 | clone_ptr(const clone_ptr & other) 61 | {value_ = other->clone();} 62 | 63 | T * operator->() 64 | { 65 | if (value_) 66 | return value_; 67 | 68 | throw std::runtime_error("using a null clone_ptr"); 69 | } 70 | 71 | const T * operator->() const 72 | { 73 | assert(value_); 74 | 75 | return value_; 76 | } 77 | 78 | T * get() { return value_; } 79 | const T * get() const { return value_; } 80 | 81 | // This just releases the pointer. It means that the 82 | // pointer is no longer owned by the smart pointer. 83 | T * release() 84 | { 85 | T * r = value_; 86 | value_ = NULL; 87 | 88 | return r; 89 | } 90 | 91 | private: 92 | T * value_; 93 | }; 94 | } 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/utilspp/functor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### install files ############### 6 | 7 | install(FILES Binder.hpp FunctorHandler.hpp Functor.hpp FunctorImpl.hpp MemFunHandler.hpp DESTINATION /include/utilspp/functor) 8 | 9 | 10 | 11 | #original Makefile.am contents follow: 12 | 13 | #pkginclude_HEADERS = \ 14 | # Binder.hpp \ 15 | # FunctorHandler.hpp \ 16 | # Functor.hpp \ 17 | # FunctorImpl.hpp \ 18 | # MemFunHandler.hpp 19 | # 20 | #pkgincludedir=$(includedir)/utilspp/functor 21 | -------------------------------------------------------------------------------- /include/utilspp/functor/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = \ 2 | Binder.hpp \ 3 | FunctorHandler.hpp \ 4 | Functor.hpp \ 5 | FunctorImpl.hpp \ 6 | MemFunHandler.hpp 7 | 8 | pkgincludedir=$(includedir)/utilspp/functor 9 | -------------------------------------------------------------------------------- /include/utilspp/singleton/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### install files ############### 6 | 7 | install(FILES CreationStatic.hpp CreationStatic.inl CreationUsingNew.hpp CreationUsingNew.inl LifetimeDefault.hpp LifetimeDefault.inl LifetimeLibrary.hpp LifetimeLibrary.inl LifetimeWithLongevity.hpp LifetimeWithLongevity.inl PrivateMembers.hpp PrivateMembers.inl SingletonHolder.hpp SingletonHolder.inl DESTINATION /include/utilspp/singleton) 8 | 9 | 10 | 11 | #original Makefile.am contents follow: 12 | 13 | #pkginclude_HEADERS = \ 14 | # CreationStatic.hpp CreationStatic.inl \ 15 | # CreationUsingNew.hpp CreationUsingNew.inl \ 16 | # LifetimeDefault.hpp LifetimeDefault.inl \ 17 | # LifetimeLibrary.hpp LifetimeLibrary.inl \ 18 | # LifetimeWithLongevity.hpp LifetimeWithLongevity.inl \ 19 | # PrivateMembers.hpp PrivateMembers.inl \ 20 | # SingletonHolder.hpp SingletonHolder.inl 21 | # 22 | #pkgincludedir=$(includedir)/utilspp/singleton 23 | # 24 | # 25 | -------------------------------------------------------------------------------- /include/utilspp/singleton/CreationStatic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CREATION_STATIC_HPP 25 | #define CREATION_STATIC_HPP 26 | 27 | /** 28 | * This class is a creation policy for the utilspp::singleton_holder. The 29 | * policy is creating the singleton by a static memory. The constructor is 30 | * called the first time we call the utilspp::creation_static::create() 31 | * function. 32 | * 33 | * This creation policy is very usefull since it rely on static allocation. 34 | * It means that the creation is automatically thread-safe, since compilers 35 | * static ensures that static allocation is thread-safe. 36 | * 37 | * Note don't use this class with a lifetime policy that allows revivals. 38 | * Be carefull with this policy since it won't respect the lifetime policy. 39 | * It will eventually be destroyed, but at the end of the program. 40 | */ 41 | namespace utilspp 42 | { 43 | template 44 | class CreationStatic 45 | { 46 | public: 47 | static T* create(); 48 | static void destroy(T* obj); 49 | }; 50 | } 51 | 52 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 53 | #include "CreationStatic.inl" 54 | //#endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/utilspp/singleton/CreationStatic.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CREATION_STATIC_INL 25 | #define CREATION_STATIC_INL 26 | 27 | 28 | template 29 | T* 30 | utilspp::CreationStatic::create() 31 | { 32 | static T mObj; 33 | return &mObj; 34 | } 35 | 36 | template 37 | void 38 | utilspp::CreationStatic::destroy(T*) 39 | {} 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/utilspp/singleton/CreationUsingNew.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CREATION_USING_NEW_HPP 25 | #define CREATION_USING_NEW_HPP 26 | 27 | /** 28 | * This class is a creation policy for the utilspp::singleton_holder. The 29 | * policy is creating the singleton by a "new" call. 30 | */ 31 | namespace utilspp 32 | { 33 | template 34 | struct CreationUsingNew 35 | { 36 | static T * create(); 37 | static void destroy(T * obj); 38 | }; 39 | } 40 | 41 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 42 | #include "CreationUsingNew.inl" 43 | //#endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/utilspp/singleton/CreationUsingNew.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef CREATION_USING_NEW_INL 25 | #define CREATION_USING_NEW_INL 26 | 27 | template 28 | T * 29 | utilspp::CreationUsingNew::create() 30 | { 31 | return new T; 32 | } 33 | 34 | template 35 | void 36 | utilspp::CreationUsingNew::destroy(T * obj) 37 | { 38 | delete obj; 39 | } 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeDefault.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (cURLpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef LIFETIME_DEFAULT_HPP 25 | #define LIFETIME_DEFAULT_HPP 26 | 27 | #include 28 | #include 29 | 30 | namespace utilspp 31 | { 32 | template< typename T > 33 | class LifetimeDefault 34 | { 35 | public: 36 | static void scheduleDestruction( T *obj, void (*func)() ); 37 | static void onDeadReference(); 38 | }; 39 | } 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeDefault.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef LIFETIME_DEFAULT_INL 25 | #define LIFETIME_DEFAULT_INL 26 | 27 | template 28 | void 29 | utilspp::LifetimeDefault::scheduleDestruction(T *, void (* func)()) 30 | { 31 | std::atexit(func); 32 | } 33 | 34 | template 35 | void 36 | utilspp::LifetimeDefault::onDeadReference() 37 | { 38 | throw std::logic_error("Dead reference detected"); 39 | } 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeLibrary.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef LIFETIME_LIBRARY_HPP 25 | #define LIFETIME_LIBRARY_HPP 26 | 27 | #include 28 | 29 | #include "PrivateMembers.hpp" 30 | #include "CreationUsingNew.hpp" 31 | 32 | namespace utilspp 33 | { 34 | 35 | template 36 | unsigned int getLongevity(T * p); 37 | 38 | /** 39 | * Assigns an object a longevity. Ensures ordered destructions of objects 40 | * registered thusly during the exit sequence of the application. 41 | */ 42 | template 43 | void setLibraryLongevity( 44 | T * obj, 45 | unsigned int longevity, 46 | TDestroyer d = utilspp::PrivateMembers::Deleter::deleteObject 47 | ); 48 | 49 | /** 50 | * This class is a lifetime policy for the singleton. This 51 | * class allow you to terminate the singleton explicitly. 52 | * You can terminate by calling: 53 | * 54 | * LifetimeLibrarySingleton::instance().terminate() 55 | * 56 | * This singleton use the utilspp::LifetimeWithLongevity policy. 57 | */ 58 | template 59 | struct LifetimeLibrary 60 | { 61 | static void scheduleDestruction(T * obj, void (* func)()); 62 | static void onDeadReference(); 63 | }; 64 | 65 | class LifetimeLibraryImpl 66 | { 67 | public: 68 | LifetimeLibraryImpl(); 69 | ~LifetimeLibraryImpl(); 70 | 71 | void add(utilspp::PrivateMembers::LifetimeTracker * tracker); 72 | void terminate(); 73 | 74 | private: 75 | utilspp::PrivateMembers::TrackerArray mTrackerArray; 76 | int mNbElements; 77 | }; 78 | 79 | unsigned int getLongevity(utilspp::LifetimeLibraryImpl * p); 80 | 81 | typedef utilspp::SingletonHolder< 82 | utilspp::LifetimeLibraryImpl, 83 | utilspp::CreationUsingNew, 84 | utilspp::LifetimeWithLongevity 85 | > LifetimeLibrarySingleton; 86 | 87 | /** 88 | * This class will ensure that 89 | * 90 | * LifetimeLibraryImpl::terminate() 91 | * 92 | * is called. 93 | */ 94 | template 95 | class LifetimeLibraryGuard 96 | { 97 | public: 98 | ~LifetimeLibraryGuard(); 99 | }; 100 | } 101 | 102 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 103 | #include "LifetimeLibrary.inl" 104 | //#endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeLibrary.inl: -------------------------------------------------------------------------------- 1 | template 2 | void 3 | utilspp::setLibraryLongevity(T * obj, unsigned int longevity, TDestroyer d) 4 | { 5 | using namespace utilspp::PrivateMembers; 6 | 7 | LifetimeTracker * p = new ConcreteLifetimeTracker( 8 | obj, longevity, d); 9 | 10 | utilspp::LifetimeLibrarySingleton::instance().add(p); 11 | }; 12 | 13 | template 14 | void 15 | utilspp::LifetimeLibrary::scheduleDestruction(T *obj, void (* func)()) 16 | { 17 | utilspp::PrivateMembers::adapter adapter = { func }; 18 | utilspp::setLibraryLongevity(obj, getLongevity( obj ), adapter); 19 | } 20 | 21 | template 22 | void 23 | utilspp::LifetimeLibrary::onDeadReference() 24 | { 25 | throw std::logic_error("Dead reference detected"); 26 | } 27 | 28 | template 29 | utilspp::LifetimeLibraryGuard::~LifetimeLibraryGuard() 30 | { 31 | T::instance().terminate(); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeWithLongevity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef LIFETIME_WITH_LONGEVITY_HPP 25 | #define LIFETIME_WITH_LONGEVITY_HPP 26 | 27 | #include 28 | #include 29 | #include "PrivateMembers.hpp" 30 | 31 | namespace utilspp 32 | { 33 | 34 | template 35 | unsigned int getLongevity(T * p); 36 | 37 | /** 38 | * Assigns an object a longevity. Ensures ordered destructions of objects 39 | * registered thusly during the exit sequence of the application. 40 | */ 41 | template 42 | void setLongevity(T * obj, 43 | unsigned int longevity, 44 | TDestroyer d = utilspp::PrivateMembers::Deleter::deleteObject); 45 | 46 | template 47 | struct LifetimeWithLongevity 48 | { 49 | static void scheduleDestruction(T * obj, void (* func)()); 50 | static void onDeadReference(); 51 | }; 52 | } 53 | 54 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 55 | #include "LifetimeWithLongevity.inl" 56 | //#endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/utilspp/singleton/LifetimeWithLongevity.inl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void 5 | utilspp::setLongevity(T * obj, unsigned int longevity, TDestroyer d) 6 | { 7 | using namespace utilspp::PrivateMembers; 8 | 9 | TrackerArray newArray = static_cast( 10 | std::realloc(mTrackerArray, mNbElements + 1)); 11 | if(newArray == NULL) 12 | { 13 | throw std::bad_alloc(); 14 | } 15 | 16 | LifetimeTracker * p = 17 | new ConcreteLifetimeTracker(obj, longevity, d); 18 | 19 | mTrackerArray = newArray; 20 | 21 | TrackerArray pos = std::upper_bound( 22 | mTrackerArray, 23 | mTrackerArray + mNbElements, 24 | p, 25 | &LifetimeTracker::compare); 26 | std::copy_backward( 27 | pos, 28 | mTrackerArray + mNbElements, 29 | mTrackerArray + mNbElements + 1); 30 | 31 | *pos = p; 32 | mNbElements++; 33 | std::atexit(&atExitFunc); 34 | }; 35 | 36 | template 37 | void 38 | utilspp::LifetimeWithLongevity::scheduleDestruction(T * obj, void (* func)()) 39 | { 40 | utilspp::PrivateMembers::adapter adapter = { func }; 41 | utilspp::setLongevity(obj, getLongevity( obj ), adapter); 42 | } 43 | 44 | template 45 | void 46 | utilspp::LifetimeWithLongevity::onDeadReference() 47 | { 48 | throw std::logic_error("Dead reference detected"); 49 | } 50 | 51 | template 52 | unsigned int 53 | utilspp::getLongevity(T *) 54 | { 55 | return 1000; 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /include/utilspp/singleton/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = \ 2 | CreationStatic.hpp CreationStatic.inl \ 3 | CreationUsingNew.hpp CreationUsingNew.inl \ 4 | LifetimeDefault.hpp LifetimeDefault.inl \ 5 | LifetimeLibrary.hpp LifetimeLibrary.inl \ 6 | LifetimeWithLongevity.hpp LifetimeWithLongevity.inl \ 7 | PrivateMembers.hpp PrivateMembers.inl \ 8 | SingletonHolder.hpp SingletonHolder.inl 9 | 10 | pkgincludedir=$(includedir)/utilspp/singleton 11 | 12 | 13 | -------------------------------------------------------------------------------- /include/utilspp/singleton/PrivateMembers.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef PRIVATE_MEMBERS_HPP 25 | #define PRIVATE_MEMBERS_HPP 26 | 27 | #include 28 | 29 | namespace utilspp 30 | { 31 | namespace PrivateMembers 32 | { 33 | /** 34 | * Helper class for utils::setLongevity 35 | */ 36 | class LifetimeTracker 37 | { 38 | public: 39 | LifetimeTracker(unsigned int longevity); 40 | virtual ~LifetimeTracker(); 41 | static bool compare( 42 | const LifetimeTracker * l, 43 | const LifetimeTracker * r 44 | ); 45 | 46 | private: 47 | unsigned int mLongevity; 48 | }; 49 | 50 | typedef LifetimeTracker** TrackerArray; 51 | 52 | extern TrackerArray mTrackerArray; 53 | extern int mNbElements; 54 | 55 | /** 56 | * Helper class for Destroyer 57 | */ 58 | template 59 | struct Deleter 60 | { 61 | void deleteObject(T * obj); 62 | }; 63 | 64 | /** 65 | * Concrete lifetime tracker for objects of type T 66 | */ 67 | template 68 | class ConcreteLifetimeTracker : public LifetimeTracker 69 | { 70 | public: 71 | ConcreteLifetimeTracker(T * obj, unsigned int longevity, TDestroyer d); 72 | 73 | ~ConcreteLifetimeTracker(); 74 | 75 | private: 76 | T* mTracked; 77 | TDestroyer mDestroyer; 78 | }; 79 | 80 | void atExitFunc(); 81 | 82 | template 83 | struct adapter 84 | { 85 | void operator()(T*); 86 | void (* mFunc)(); 87 | }; 88 | } 89 | } 90 | 91 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 92 | #include "PrivateMembers.inl" 93 | //#endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /include/utilspp/singleton/PrivateMembers.inl: -------------------------------------------------------------------------------- 1 | 2 | template 3 | void 4 | utilspp::PrivateMembers::Deleter::deleteObject(T * obj) 5 | { 6 | delete obj; 7 | } 8 | 9 | template 10 | utilspp::PrivateMembers::ConcreteLifetimeTracker::ConcreteLifetimeTracker( 11 | T * obj, unsigned int longevity, TDestroyer d) 12 | : LifetimeTracker(longevity) 13 | , mTracked(obj) 14 | , mDestroyer(d) 15 | {} 16 | 17 | template 18 | utilspp::PrivateMembers::ConcreteLifetimeTracker::~ConcreteLifetimeTracker() 19 | { 20 | mDestroyer(mTracked); 21 | } 22 | 23 | 24 | template 25 | void 26 | utilspp::PrivateMembers::adapter::operator()(T*) 27 | { 28 | return (*mFunc)(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /include/utilspp/singleton/SingletonHolder.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef SINGLETON_HOLDER_HPP 25 | #define SINGLETON_HOLDER_HPP 26 | 27 | #include 28 | 29 | #include "CreationUsingNew.hpp" 30 | #include "LifetimeDefault.hpp" 31 | #include "LifetimeWithLongevity.hpp" 32 | #include "../ThreadingSingle.hpp" 33 | 34 | namespace utilspp 35 | { 36 | template 37 | class CreationPolicy = utilspp::CreationUsingNew, 39 | template class LifetimePolicy = utilspp::LifetimeDefault, 40 | template class ThreadingModel = utilspp::ThreadingSingle> 41 | class SingletonHolder 42 | { 43 | public: 44 | //the accessor method. 45 | static T & instance(); 46 | static void makeInstance(); 47 | static void terminate(); 48 | 49 | protected: 50 | //protected to be sure that nobody may create one by himself. 51 | SingletonHolder(); 52 | 53 | private: 54 | static void destroySingleton(); 55 | 56 | private: 57 | typedef typename ThreadingModel::VolatileType InstanceType; 58 | static InstanceType mInstance; 59 | static bool mDestroyed; 60 | }; 61 | 62 | } 63 | 64 | //#ifdef CURLPP_INCLUDE_TEMPLATE_DEFINITIONS 65 | #include "SingletonHolder.inl" 66 | //#endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/utilspp/singleton/SingletonHolder.inl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef SINGLETON_HOLDER_INL 25 | #define SINGLETON_HOLDER_INL 26 | 27 | template 28 | < 29 | class T, 30 | template class CreationPolicy, 31 | template class LifetimePolicy, 32 | template class ThreadingModel 33 | > 34 | T& 35 | utilspp::SingletonHolder 36 | < 37 | T, 38 | CreationPolicy, 39 | LifetimePolicy, 40 | ThreadingModel 41 | > 42 | ::instance() 43 | { 44 | if (mInstance == NULL) 45 | { 46 | makeInstance(); 47 | } 48 | 49 | return (*mInstance); 50 | }; 51 | 52 | template 53 | < 54 | class T, 55 | template class CreationPolicy, 56 | template class LifetimePolicy, 57 | template class ThreadingModel 58 | > 59 | void 60 | utilspp::SingletonHolder 61 | < 62 | T, 63 | CreationPolicy, 64 | LifetimePolicy, 65 | ThreadingModel 66 | >::makeInstance() 67 | { 68 | if (mInstance == NULL) 69 | { 70 | typename ThreadingModel::lock guard; 71 | (void)guard; 72 | 73 | if (mInstance == NULL) { 74 | if (mDestroyed) 75 | { 76 | LifetimePolicy::onDeadReference(); 77 | mDestroyed = false; 78 | } 79 | 80 | mInstance = CreationPolicy::create(); 81 | LifetimePolicy::scheduleDestruction(mInstance, & destroySingleton); 82 | } 83 | } 84 | } 85 | 86 | template 87 | < 88 | class T, 89 | template class CreationPolicy, 90 | template class LifetimePolicy, 91 | template class ThreadingModel 92 | > 93 | void 94 | utilspp::SingletonHolder 95 | < 96 | T, 97 | CreationPolicy, 98 | LifetimePolicy, 99 | ThreadingModel 100 | > 101 | ::destroySingleton() 102 | { 103 | assert(!mDestroyed); 104 | CreationPolicy::destroy(mInstance); 105 | mInstance = NULL; 106 | mDestroyed = true; 107 | } 108 | 109 | template class C, 111 | template class L, 112 | template class M 113 | > 114 | typename utilspp::SingletonHolder::InstanceType 115 | utilspp::SingletonHolder::mInstance; 116 | 117 | template 118 | < 119 | class T, 120 | template class C, 121 | template class L, 122 | template class M 123 | > 124 | bool utilspp::SingletonHolder::mDestroyed; 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | add_subdirectory(utilspp) 5 | add_subdirectory(curlpp) 6 | 7 | 8 | ########### install files ############### 9 | 10 | 11 | 12 | 13 | #original Makefile.am contents follow: 14 | 15 | #ACLOCAL_AMFLAGS = -I m4 16 | #SUBDIRS = utilspp curlpp 17 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | SUBDIRS = utilspp curlpp 3 | -------------------------------------------------------------------------------- /src/curlpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | add_subdirectory(internal) 5 | 6 | 7 | ########### next target ############### 8 | 9 | set(curlpp_LIB_SRCS ${sources}) 10 | 11 | add_library(curlpp SHARED ${curlpp_LIB_SRCS}) 12 | 13 | target_link_libraries(curlpp ${KDE4_KDECORE_LIBS} internal) 14 | 15 | set_target_properties(curlpp PROPERTIES VERSION 1.0.0 SOVERSION 1) 16 | install(TARGETS curlpp ${INSTALL_TARGETS_DEFAULT_ARGS}) 17 | 18 | 19 | ########### install files ############### 20 | 21 | 22 | 23 | 24 | #original Makefile.am contents follow: 25 | 26 | #SUBDIRS = internal 27 | #lib_LTLIBRARIES = libcurlpp.la 28 | #EXTRA_DIST = Makefile.msvc 29 | # 30 | #if MAINTENER_CODE 31 | #maintener_source = 32 | #endif 33 | # 34 | #INCLUDES = -I$(top_builddir)/include/curlpp -I$(top_builddir)/include 35 | # 36 | #sources = \ 37 | # cURLpp.cpp cURLpp.hpp \ 38 | # Exception.cpp Exception.hpp \ 39 | # Easy.cpp Easy.hpp Easy.inl \ 40 | # Form.cpp Form.hpp \ 41 | # Info.cpp Info.hpp Info.inl \ 42 | # Infos.hpp \ 43 | # Multi.cpp Multi.hpp \ 44 | # NonCopyable.hpp \ 45 | # OptionBase.cpp OptionBase.hpp \ 46 | # OptionContainer.hpp OptionContainer.inl \ 47 | # OptionContainerType.hpp \ 48 | # Option.hpp Option.inl \ 49 | # Options.cpp Options.hpp \ 50 | # StorageOptions.hpp StorageOptions.inl \ 51 | # Types.hpp \ 52 | # TypeTrait.hpp \ 53 | # autolink.h \ 54 | # ${maintener_source} 55 | # 56 | #libcurlpp_la_LIBADD = internal/libinternal.la 57 | #libcurlpp_la_SOURCES = ${sources} 58 | #VERSION=-version-info 0:2:0 59 | # 60 | #AM_CXXFLAGS= -I../ 61 | # 62 | ## This flag accepts an argument of the form current[:revision[:age]]. So, 63 | ## passing -version-info 3:12:1 sets current to 3, revision to 12, and age to 64 | ## 1. 65 | ## 66 | ## If either revision or age are omitted, they default to 0. Also note that age 67 | ## must be less than or equal to the current interface number. 68 | ### Here are a set of rules to help you update your library version information: 69 | ## 70 | ## 1.Start with version information of 0:0:0 for each libtool library. 71 | ## 72 | ## 2.Update the version information only immediately before a public release of 73 | ## your software. More frequent updates are unnecessary, and only guarantee 74 | ## that the current interface number gets larger faster. 75 | ## 76 | ## 3.If the library source code has changed at all since the last update, then 77 | ## increment revision (c:r:a becomes c:r+1:a). 78 | ## 79 | ## 4.If any interfaces have been added, removed, or changed since the last 80 | ## update, increment current, and set revision to 0. 81 | ## 82 | ## 5.If any interfaces have been added since the last public release, then 83 | ## increment age. 84 | ## 85 | ## 6.If any interfaces have been removed since the last public release, then 86 | ## set age to 0. 87 | ## 88 | # 89 | #if NO_UNDEFINED 90 | ## The -no-undefined flag is CRUCIAL for this to build fine on Cygwin. If we 91 | ## find a case in which we need to remove this flag, we should most likely 92 | ## write a configure check that detects when this flag is needed and when its 93 | ## not. 94 | #libcurlpp_la_LDFLAGS = -no-undefined -Wno-inline-dllimport $(VERSION) 95 | #else 96 | #libcurlpp_la_LDFLAGS = $(VERSION) 97 | #endif 98 | -------------------------------------------------------------------------------- /src/curlpp/Easy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2009> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "curlpp/Easy.hpp" 25 | #include "curlpp/Options.hpp" 26 | 27 | #include "curlpp/internal/global.h" 28 | #include "curlpp/internal/buildconfig.h" 29 | 30 | 31 | curlpp::Easy::Easy() 32 | : mCurl(new internal::CurlHandle()) 33 | {} 34 | 35 | 36 | curlpp::Easy::Easy(std::auto_ptr handle) 37 | : mCurl(handle) 38 | {} 39 | 40 | 41 | curlpp::Easy::~Easy() 42 | {} 43 | 44 | 45 | void 46 | curlpp::Easy::perform() 47 | { 48 | mCurl->perform(); 49 | } 50 | 51 | 52 | CURL * 53 | curlpp::Easy::getHandle() const 54 | { 55 | return mCurl->getHandle(); 56 | } 57 | 58 | 59 | void 60 | curlpp::Easy::setOpt(const OptionBase & option) 61 | { 62 | setOpt(option.clone()); 63 | } 64 | 65 | 66 | void 67 | curlpp::Easy::setOpt(std::auto_ptr option) 68 | { 69 | option->updateHandleToMe(mCurl.get()); 70 | mOptions.setOpt(option.release()); 71 | } 72 | 73 | 74 | void 75 | curlpp::Easy::setOpt(OptionBase * option) 76 | { 77 | option->updateHandleToMe(mCurl.get()); 78 | mOptions.setOpt(option); 79 | } 80 | 81 | 82 | void 83 | curlpp::Easy::getOpt(OptionBase * option) const 84 | { 85 | mOptions.getOpt(option); 86 | } 87 | 88 | 89 | void 90 | curlpp::Easy::getOpt(OptionBase & option) const 91 | { 92 | mOptions.getOpt(&option); 93 | } 94 | 95 | 96 | void 97 | curlpp::Easy::setOpt(const internal::OptionList & options) 98 | { 99 | mOptions.setOpt(options); 100 | } 101 | 102 | 103 | void 104 | curlpp::Easy::reset () 105 | { 106 | mCurl->reset(); 107 | mOptions.setOpt(internal::OptionList()); 108 | } 109 | 110 | 111 | std::ostream & operator<<(std::ostream & stream, const curlpp::Easy & request) 112 | { 113 | // Quick clone that doesn't copy options, only the curl handle. 114 | curlpp::Easy r(request.getCurlHandle().clone()); 115 | r.setOpt(new curlpp::options::WriteStream(& stream)); 116 | r.perform(); 117 | 118 | return stream; 119 | } 120 | 121 | 122 | #if defined(CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION) 123 | #include "./Easy.ins" 124 | #endif 125 | -------------------------------------------------------------------------------- /src/curlpp/Easy.custom.ins: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Custom (user) specializations of methods of Easy class. 4 | * 5 | * IMPORTANT !!! 6 | * Users should add explicit specializations for types 7 | * they use in their applications when building library with 8 | * SELF_CONTAINED set. Otherwise there will be linker errors when 9 | * _using_ the library which has been built without these specializations. 10 | * 11 | */ 12 | 13 | #include "curlpp/Easy.hpp" 14 | 15 | #include 16 | 17 | 18 | using namespace curlpp::options; 19 | 20 | 21 | namespace curlpp 22 | { 23 | 24 | 25 | /** 26 | * Custom specializations for... 27 | * 28 | * template 29 | * void curlpp::Easy::setOpt(InputIterator first, InputIterator last) 30 | */ 31 | 32 | /// Used in example23. 33 | 34 | typedef std::vector::iterator EasyCustomType1; 35 | 36 | template 37 | CURLPPAPI void Easy::setOpt(EasyCustomType1 first, EasyCustomType1 last); 38 | 39 | /// Add more here... 40 | 41 | 42 | } // namespace curlpp -------------------------------------------------------------------------------- /src/curlpp/Exception.ins: -------------------------------------------------------------------------------- 1 | #include "curlpp/Exception.hpp" 2 | 3 | #include 4 | 5 | namespace curlpp 6 | { 7 | 8 | template 9 | void curlpp::raiseException(const std::exception &); 10 | 11 | template 12 | void raiseException(const std::logic_error &); 13 | 14 | template 15 | void raiseException(const std::domain_error &); 16 | 17 | template 18 | void raiseException(const std::invalid_argument &); 19 | 20 | template 21 | void raiseException(const std::length_error &); 22 | 23 | template 24 | void raiseException(const std::out_of_range &); 25 | 26 | template 27 | void raiseException(const std::runtime_error &); 28 | 29 | template 30 | void raiseException(const std::overflow_error &); 31 | 32 | template 33 | void raiseException(const std::underflow_error &); 34 | 35 | template 36 | void raiseException(const std::range_error &); 37 | 38 | } // namespace curlpp -------------------------------------------------------------------------------- /src/curlpp/Info.cpp: -------------------------------------------------------------------------------- 1 | #include "curlpp/internal/global.h" 2 | #include "curlpp/internal/SList.hpp" 3 | 4 | #include "curlpp/Info.hpp" 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace curlpp 11 | { 12 | 13 | 14 | template<> 15 | void 16 | InfoTypeConverter::get(const curlpp::Easy & handle, 17 | CURLINFO info, 18 | std::string & value) 19 | { 20 | char * tmp; 21 | InfoGetter::get(handle, info, tmp); 22 | value = tmp; 23 | } 24 | 25 | 26 | template<> 27 | void 28 | InfoTypeConverter >::get(const curlpp::Easy & handle, 29 | CURLINFO info, 30 | std::list & value) 31 | { 32 | curl_slist * tmpList = NULL; 33 | InfoGetter::get(handle, info, tmpList); 34 | internal::SList slist(tmpList); 35 | value = slist.list(); 36 | } 37 | 38 | 39 | template<> 40 | void 41 | InfoTypeConverter::get(const curlpp::Easy & handle, 42 | CURLINFO info, 43 | long & value) 44 | { 45 | InfoGetter::get(handle, info, value); 46 | } 47 | 48 | 49 | template<> 50 | void 51 | InfoTypeConverter::get(const curlpp::Easy & handle, 52 | CURLINFO info, 53 | double & value) 54 | { 55 | curl_off_t tmp; 56 | InfoGetter::get(handle, info, tmp); 57 | value = (double)tmp; 58 | } 59 | 60 | 61 | } // namespace curlpp 62 | -------------------------------------------------------------------------------- /src/curlpp/Infos.cpp: -------------------------------------------------------------------------------- 1 | #include "curlpp/internal/buildconfig.h" 2 | 3 | #if defined(CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION) 4 | #include "./Infos.ins" 5 | #endif 6 | -------------------------------------------------------------------------------- /src/curlpp/Infos.ins: -------------------------------------------------------------------------------- 1 | #include "curlpp/Infos.hpp" 2 | 3 | #include 4 | #include 5 | 6 | /* 7 | * Use Find what: "typedef.*\> {.*}$" regular expression and Replace with: "template \1" 8 | * to generate most of this file from its corresponding header file. 9 | */ 10 | 11 | namespace curlpp 12 | { 13 | 14 | namespace infos 15 | { 16 | template EffectiveUrl; 17 | template ResponseCode; 18 | template HttpConnectCode; 19 | template FileTime; 20 | template TotalTime; 21 | template NameLookupTime; 22 | template ConnectTime; 23 | template PreTransferTime; 24 | template StartTransferTime; 25 | template RedirectTime; 26 | template RedirectCount; 27 | template SizeUpload; 28 | template SizeDownload; 29 | template SpeedDownload; 30 | template SpeedUpload; 31 | template HeaderSize; 32 | template RequestSize; 33 | template SslVerifyResult; 34 | #if LIBCURL_VERSION_NUM >= 0x070c03 35 | template SslEngines; 36 | #endif 37 | template ContentLengthDownload; 38 | template ContentLengthUpload; 39 | template ContentType; 40 | template HttpAuthAvail; 41 | template ProxyAuthAvail; 42 | #if LIBCURL_VERSION_NUM >= 0x070c02 43 | template OsErrno; 44 | #endif 45 | #if LIBCURL_VERSION_NUM >= 0x070c03 46 | template NumConnects; 47 | #endif 48 | 49 | #if LIBCURL_VERSION_NUM >= 0x070e01 50 | template CookieList; 51 | #else 52 | #ifdef CURLPP_ALLOW_NOT_AVAILABLE 53 | // This curlinfo text must be specified, so we specify something 54 | // that we know will be there. 55 | template CookieList; 56 | #endif 57 | #endif 58 | 59 | } // namespace infos 60 | 61 | } // namespace curlpp -------------------------------------------------------------------------------- /src/curlpp/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = internal 2 | lib_LTLIBRARIES = libcurlpp.la 3 | EXTRA_DIST = Makefile.msvc 4 | 5 | if MAINTENER_CODE 6 | maintener_source = 7 | endif 8 | 9 | INCLUDES = -I$(top_builddir)/include/curlpp -I$(top_builddir)/include 10 | 11 | sources = \ 12 | cURLpp.cpp \ 13 | Exception.cpp \ 14 | Easy.cpp \ 15 | Form.cpp \ 16 | Info.cpp \ 17 | Multi.cpp \ 18 | OptionBase.cpp \ 19 | Options.cpp \ 20 | autolink.h \ 21 | ${maintener_source} 22 | 23 | libcurlpp_la_LIBADD = internal/libinternal.la -lcurl 24 | libcurlpp_la_SOURCES = ${sources} 25 | VERSION=-version-info 0:2:0 26 | 27 | AM_CXXFLAGS= -I../ 28 | 29 | # This flag accepts an argument of the form current[:revision[:age]]. So, 30 | # passing -version-info 3:12:1 sets current to 3, revision to 12, and age to 31 | # 1. 32 | # 33 | # If either revision or age are omitted, they default to 0. Also note that age 34 | # must be less than or equal to the current interface number. 35 | ## Here are a set of rules to help you update your library version information: 36 | # 37 | # 1.Start with version information of 0:0:0 for each libtool library. 38 | # 39 | # 2.Update the version information only immediately before a public release of 40 | # your software. More frequent updates are unnecessary, and only guarantee 41 | # that the current interface number gets larger faster. 42 | # 43 | # 3.If the library source code has changed at all since the last update, then 44 | # increment revision (c:r:a becomes c:r+1:a). 45 | # 46 | # 4.If any interfaces have been added, removed, or changed since the last 47 | # update, increment current, and set revision to 0. 48 | # 49 | # 5.If any interfaces have been added since the last public release, then 50 | # increment age. 51 | # 52 | # 6.If any interfaces have been removed since the last public release, then 53 | # set age to 0. 54 | # 55 | 56 | if NO_UNDEFINED 57 | # The -no-undefined flag is CRUCIAL for this to build fine on Cygwin. If we 58 | # find a case in which we need to remove this flag, we should most likely 59 | # write a configure check that detects when this flag is needed and when its 60 | # not. 61 | libcurlpp_la_LDFLAGS = -no-undefined -Wno-inline-dllimport $(VERSION) 62 | else 63 | libcurlpp_la_LDFLAGS = $(VERSION) 64 | endif 65 | -------------------------------------------------------------------------------- /src/curlpp/Makefile.msvc: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # 3 | # Makefile for building libcurlpp with MSVC 4 | # Based heavily on libcurl Makefile 5 | # Giuseppe "Cowo" Corbelli - cowo at lugbs dot linux dot it 6 | # 7 | # Usage: see usage message below 8 | # Should be invoked from curlpp/ directory 9 | # Edit the LIBCURL_PATH or set LIBCURL_PATH envvar 10 | # 11 | ############################################################## 12 | 13 | LIB_NAME = libcurlpp 14 | LIB_NAME_DEBUG = libcurlppd 15 | 16 | ############################################################# 17 | 18 | !IFNDEF LIBCURL_PATH 19 | LIBCURL_PATH = ../../curl/include 20 | !ENDIF 21 | 22 | CCNODBG = cl.exe /MD /O2 /DNDEBUG /GR 23 | CCDEBUG = cl.exe /MDd /Od /Gm /Zi /D_DEBUG /GZ /GR 24 | CFLAGS = /I ../ /I "$(LIBCURL_PATH)/include" /nologo /W3 /GX /DWIN32 /YX /FD /c 25 | CFLAGSLIB = /DCURLPP_STATICLIB 26 | CFLAGSDLL = /UCURLPP_STATICLIB 27 | LNKDLL = link.exe /DLL /INCREMENTAL:NO /OPT:NOREF 28 | LNKLIB = link.exe /lib 29 | LFLAGS = /nologo /LIBPATH:"$(LIBCURL_PATH)/lib" 30 | CURLLIB = libcurl_imp.lib 31 | CFGSET = FALSE 32 | 33 | ###################### 34 | # release 35 | 36 | !IF "$(CFG)" == "release" 37 | TARGET = $(LIB_NAME).lib 38 | DIROBJ = $(CFG) 39 | LNK = $(LNKLIB) /out:$(DIROBJ)/$(TARGET) 40 | CC = $(CCNODBG) $(CFLAGSLIB) 41 | CFGSET = TRUE 42 | !ENDIF 43 | 44 | ###################### 45 | # release-dll 46 | 47 | !IF "$(CFG)" == "release-dll" 48 | TARGET = $(LIB_NAME).dll 49 | DIROBJ = $(CFG) 50 | LNK = $(LNKDLL) $(CURLLIB) /out:$(DIROBJ)/$(TARGET) 51 | CC = $(CCNODBG) $(CFLAGSDLL) 52 | CFGSET = TRUE 53 | !ENDIF 54 | 55 | ###################### 56 | # debug 57 | 58 | !IF "$(CFG)" == "debug" 59 | TARGET = $(LIB_NAME_DEBUG).lib 60 | DIROBJ = $(CFG) 61 | LNK = $(LNKLIB) /out:$(DIROBJ)/$(TARGET) 62 | CC = $(CCDEBUG) $(CFLAGSLIB) 63 | CFGSET = TRUE 64 | !ENDIF 65 | 66 | ###################### 67 | # debug-dll 68 | 69 | !IF "$(CFG)" == "debug-dll" 70 | TARGET = $(LIB_NAME_DEBUG).dll 71 | DIROBJ = $(CFG) 72 | LNK = $(LNKDLL) $(CURLLIB) /DEBUG /out:$(DIROBJ)/$(TARGET) /PDB:$(DIROBJ)/$(LIB_NAME_DEBUG).pdb 73 | CC = $(CCDEBUG) 74 | CFGSET = TRUE 75 | !ENDIF 76 | 77 | 78 | ####################### 79 | # Usage 80 | # 81 | !IF "$(CFGSET)" == "FALSE" && "$(CFG)" != "" 82 | !MESSAGE Usage: nmake /f makefile.msvc CFG= 83 | !MESSAGE where is one of: 84 | !MESSAGE release - release static library 85 | !MESSAGE release-dll - release dynamic library 86 | !MESSAGE debug - debug static library 87 | !MESSAGE debug-dll - debug dynamic library 88 | !ERROR please choose a valid configuration "$(CFG)" 89 | !ENDIF 90 | 91 | ####################### 92 | # Only the clean target can be used if a config was not provided. 93 | # 94 | !IF "$(CFGSET)" == "FALSE" 95 | clean: 96 | @-erase /s *.dll 2> NUL 97 | @-erase /s *.exp 2> NUL 98 | @-erase /s *.idb 2> NUL 99 | @-erase /s *.lib 2> NUL 100 | @-erase /s *.o 2> NUL 101 | @-erase /s *.pch 2> NUL 102 | @-erase /s *.pdb 2> NUL 103 | @-erase /s *.res 2> NUL 104 | !ELSE 105 | # A config was provided, so the library can be built. 106 | # 107 | X_OBJS= \ 108 | $(DIROBJ)/CurlHandle.o \ 109 | $(DIROBJ)/cURLpp.o \ 110 | $(DIROBJ)/Exception.o \ 111 | $(DIROBJ)/Easy.o \ 112 | $(DIROBJ)/Form.o \ 113 | $(DIROBJ)/Info.o \ 114 | $(DIROBJ)/Multi.o \ 115 | $(DIROBJ)/OptionBase.o \ 116 | $(DIROBJ)/OptionList.o \ 117 | $(DIROBJ)/OptionSetter.o \ 118 | $(DIROBJ)/SList.o \ 119 | 120 | all : $(TARGET) 121 | 122 | $(TARGET): $(X_OBJS) 123 | $(LNK) $(LFLAGS) $(X_OBJS) 124 | 125 | $(X_OBJS): $(DIROBJ) 126 | 127 | $(DIROBJ): 128 | @if not exist "$(DIROBJ)" mkdir $(DIROBJ) 129 | 130 | .SUFFIXES: .cpp .obj 131 | 132 | {.\}.cpp{$(DIROBJ)\}.o: 133 | $(CC) $(CFLAGS) /Fo"$@" $< 134 | 135 | !ENDIF # End of case where a config was provided. 136 | -------------------------------------------------------------------------------- /src/curlpp/Option.cpp: -------------------------------------------------------------------------------- 1 | #include "curlpp/Option.hpp" 2 | #include "curlpp/internal/OptionSetter.hpp" 3 | 4 | template 5 | const CURLoption curlpp::OptionTrait::option; 6 | 7 | #if defined(CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION) 8 | #include "./Option.ins" 9 | #endif 10 | -------------------------------------------------------------------------------- /src/curlpp/OptionBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "curlpp/internal/global.h" 25 | 26 | #include "curlpp/OptionBase.hpp" 27 | 28 | curlpp::OptionBase::OptionBase(CURLoption option) 29 | : mOption(option) 30 | {}; 31 | 32 | curlpp::OptionBase::~OptionBase() 33 | {}; 34 | 35 | bool curlpp::OptionBase::operator<(const curlpp::OptionBase & rhs) const 36 | { 37 | return mOption < rhs.mOption; 38 | } 39 | 40 | CURLoption curlpp::OptionBase::getOption() const 41 | { 42 | return mOption; 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/curlpp/Options.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "curlpp/internal/global.h" 25 | 26 | #include "curlpp/Options.hpp" 27 | #include "curlpp/Easy.hpp" 28 | 29 | std::ostream & operator<<(std::ostream & stream, const curlpp::options::Url & url) 30 | { 31 | curlpp::Easy request; 32 | request.setOpt(url); 33 | 34 | stream << request; 35 | 36 | return stream; 37 | } 38 | 39 | #if defined(CURLPP_TEMPLATE_EXPLICIT_INSTANTIATION) 40 | #include "./Options.ins" 41 | #endif 42 | -------------------------------------------------------------------------------- /src/curlpp/Options.custom.ins: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Custom (user) specializations of options with user types. 4 | * 5 | * IMPORTANT !!! 6 | * Users should add explicit specializations for types 7 | * they use in their applications when building library with 8 | * SELF_CONTAINED set. Otherwise there will be linker errors when 9 | * _using_ the library which has been built without these specializations. 10 | * 11 | */ 12 | 13 | #include "curlpp/Options.hpp" 14 | 15 | 16 | namespace curlpp 17 | { 18 | 19 | 20 | namespace options 21 | { 22 | 23 | 24 | /// Used in example11. 25 | 26 | typedef OptionTrait OptionsCustomType1; 27 | 28 | template 29 | CURLPPAPI OptionsCustomType1; 30 | 31 | /// Add more here... 32 | 33 | 34 | } // namespace options 35 | 36 | 37 | } // namespace curlpp -------------------------------------------------------------------------------- /src/curlpp/autolink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2005> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (cURLpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef __AUTOLINK__H_ 25 | #define __AUTOLINK__H_ 26 | 27 | /* 28 | * Auto-link feature on win32 supported compilers. Reading boost sources it seems 29 | * that _MSC_VER definition does not guarantee a ms compiler. However this should 30 | * not be a problem for autolink. 31 | */ 32 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 33 | 34 | #if defined(_MSC_VER ) || defined(__INTEL_COMPILER) || defined(__ICL) || \ 35 | defined(__ICC) || defined(__ECC) || defined(__MWERKS__) || defined(__BORLANDC__) 36 | 37 | #if defined(_DEBUG) || defined(DEBUG) 38 | #pragma comment(lib, "libcurlppd.lib") 39 | #else //DEBUG 40 | #pragma comment(lib, "libcurlpp.lib") 41 | #endif //DEBUG 42 | 43 | #endif //Supported compilers 44 | 45 | #endif //Windows 46 | 47 | #endif //__AUTOLINK__H_ 48 | -------------------------------------------------------------------------------- /src/curlpp/cURLpp.cpp: -------------------------------------------------------------------------------- 1 | #include "utilspp/singleton/SingletonHolder.hpp" 2 | #include "utilspp/singleton/CreationStatic.hpp" 3 | 4 | #include "curlpp/internal/global.h" 5 | 6 | #include "curlpp/cURLpp.hpp" 7 | #include "curlpp/Exception.hpp" 8 | 9 | #include 10 | 11 | 12 | namespace 13 | { 14 | 15 | 16 | struct libcURLInstance 17 | { 18 | libcURLInstance(); 19 | 20 | ~libcURLInstance() 21 | { curlpp::terminate(); } 22 | }; 23 | } 24 | 25 | 26 | void curlpp::initialize(long flags) 27 | { 28 | CURLcode code; 29 | code = curl_global_init(flags); 30 | libcurlRuntimeAssert("cannot initialize curlpp", code); 31 | } 32 | 33 | 34 | void curlpp::terminate() 35 | { 36 | curl_global_cleanup(); 37 | } 38 | 39 | 40 | curlpp::Cleanup::Cleanup() 41 | { 42 | curlpp::initialize(); 43 | } 44 | 45 | 46 | curlpp::Cleanup::~Cleanup() 47 | {} 48 | 49 | 50 | std::string 51 | curlpp::escape(const std::string & url) 52 | { 53 | std::string buffer; 54 | char* p = curl_escape(url.c_str(), (int)url.size()); 55 | if(!p) { 56 | throw std::runtime_error("unable to escape the string"); //we got an error 57 | } 58 | else { 59 | buffer = p; 60 | curl_free(p); 61 | } 62 | return buffer; 63 | } 64 | 65 | 66 | std::string 67 | curlpp::unescape(const std::string & url) 68 | { 69 | std::string buffer; 70 | char* p = curl_unescape(url.c_str(), (int)url.size()); 71 | if (!p) 72 | { 73 | throw RuntimeError("unable to escape the string"); //we got an error 74 | } 75 | else 76 | { 77 | buffer = p; 78 | curl_free(p); 79 | } 80 | return buffer; 81 | } 82 | 83 | 84 | std::string 85 | curlpp::getenv(const std::string & name) 86 | { 87 | std::string buffer; 88 | char* p = curl_getenv(name.c_str()); 89 | if (!p) 90 | { 91 | throw RuntimeError("unable to get the environnement string"); //we got an error 92 | } 93 | else 94 | { 95 | buffer = p; 96 | free(p); 97 | } 98 | return buffer; 99 | } 100 | 101 | 102 | std::string 103 | curlpp::libcurlVersion() 104 | { 105 | char* p = curl_version(); 106 | if (!p) 107 | { 108 | throw RuntimeError("unable to get the libcurl version"); //we got an error 109 | } 110 | 111 | return std::string(p); 112 | } 113 | 114 | 115 | time_t 116 | curlpp::getdate(const std::string & date, time_t * now) 117 | { 118 | time_t return_value = curl_getdate(date.c_str(), now); 119 | if(!return_value) 120 | { 121 | throw RuntimeError("unable to get the date"); 122 | } 123 | 124 | return return_value; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/curlpp/internal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | 5 | ########### next target ############### 6 | 7 | set(internal_STAT_SRCS ${sources}) 8 | 9 | add_library(internal STATIC ${internal_STAT_SRCS}) 10 | 11 | 12 | ########### install files ############### 13 | 14 | 15 | 16 | 17 | #original Makefile.am contents follow: 18 | 19 | #noinst_LTLIBRARIES = libinternal.la 20 | #EXTRA_DIST = Makefile.msvc 21 | # 22 | #if MAINTENER_CODE 23 | #maintener_source = 24 | #endif 25 | # 26 | #INCLUDES = -I$(top_builddir)/include/curlpp -I$(top_builddir)/include/curlpp/internal -I$(top_builddir)/include 27 | # 28 | #sources = \ 29 | # CurlHandle.cpp \ 30 | # OptionList.cpp \ 31 | # OptionSetter.cpp \ 32 | # SList.cpp \ 33 | # StorageOptions.hpp \ 34 | # autolink.h \ 35 | # ${maintener_source} 36 | # 37 | # 38 | #libinternal_la_SOURCES = ${sources} 39 | # 40 | #VERSION=-version-info 0:2:0 41 | # 42 | #AM_CXXFLAGS= -I../ 43 | # 44 | #if NO_UNDEFINED 45 | ## The -no-undefined flag is CRUCIAL for this to build fine on Cygwin. If we 46 | ## find a case in which we need to remove this flag, we should most likely 47 | ## write a configure check that detects when this flag is needed and when its 48 | ## not. 49 | #libinternal_la_LDFLAGS = -no-undefined -Wno-inline-dllimport $(VERSION) 50 | #else 51 | #libinternal_la_LDFLAGS = $(VERSION) 52 | #endif 53 | # 54 | # 55 | -------------------------------------------------------------------------------- /src/curlpp/internal/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libinternal.la 2 | 3 | if MAINTENER_CODE 4 | maintener_source = 5 | endif 6 | 7 | INCLUDES = -I$(top_builddir)/include/curlpp -I$(top_builddir)/include/curlpp/internal -I$(top_builddir)/include 8 | 9 | sources = \ 10 | CurlHandle.cpp \ 11 | OptionList.cpp \ 12 | OptionSetter.cpp \ 13 | SList.cpp \ 14 | ${maintener_source} 15 | 16 | 17 | libinternal_la_SOURCES = ${sources} 18 | 19 | VERSION=-version-info 0:2:0 20 | 21 | AM_CXXFLAGS= -I../ 22 | 23 | if NO_UNDEFINED 24 | # The -no-undefined flag is CRUCIAL for this to build fine on Cygwin. If we 25 | # find a case in which we need to remove this flag, we should most likely 26 | # write a configure check that detects when this flag is needed and when its 27 | # not. 28 | libinternal_la_LDFLAGS = -no-undefined -Wno-inline-dllimport $(VERSION) 29 | else 30 | libinternal_la_LDFLAGS = $(VERSION) 31 | endif 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/curlpp/internal/OptionList.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) <2002-2006> 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files 6 | * (curlpp), to deal in the Software without restriction, 7 | * including without limitation the rights to use, copy, modify, merge, 8 | * publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include "curlpp/internal/global.h" 25 | #include "curlpp/internal/OptionList.hpp" 26 | 27 | #include 28 | 29 | 30 | namespace curlpp 31 | { 32 | 33 | 34 | namespace internal 35 | { 36 | 37 | 38 | OptionList::OptionList() 39 | {} 40 | 41 | OptionList::OptionList(const OptionList & rhs) 42 | { 43 | insert(rhs.mOptions); 44 | } 45 | 46 | OptionList::~OptionList() 47 | { 48 | mapType::iterator pos = mOptions.begin(); 49 | while (pos != mOptions.end()) { 50 | delete (*pos).second; 51 | pos++; 52 | } 53 | } 54 | 55 | 56 | void OptionList::setOpt(curlpp::OptionBase * option) 57 | { 58 | mapType::iterator pos = mOptions.find(option->getOption()); 59 | if(pos != mOptions.end()) 60 | { 61 | delete (*pos).second; 62 | mOptions.erase(pos); 63 | } 64 | mOptions.insert(std::make_pair(option->getOption(), option)); 65 | } 66 | 67 | 68 | void OptionList::setOpt(const OptionList & options) 69 | { 70 | for(mapType::const_iterator pos = options.mOptions.begin(); 71 | pos != options.mOptions.end(); 72 | pos++) 73 | { 74 | setOpt(pos->second->clone()); 75 | } 76 | } 77 | 78 | 79 | void OptionList::setOpt(const curlpp::OptionBase & option) 80 | { 81 | setOpt(option.clone()); 82 | } 83 | 84 | 85 | void OptionList::getOpt(curlpp::OptionBase * option) const 86 | { 87 | mapType::const_iterator pos = mOptions.find(option->getOption()); 88 | if(pos != mOptions.end()) 89 | { 90 | option->updateMeToOption((*(*pos).second)); 91 | } 92 | else 93 | { 94 | option->clear(); 95 | } 96 | } 97 | 98 | 99 | void OptionList::insert(const OptionList::mapType & other) 100 | { 101 | for( mapType::const_iterator pos = other.begin(); 102 | pos != other.end(); 103 | pos++) 104 | { 105 | mOptions.insert(std::make_pair(pos->second->getOption(), pos->second->clone())); 106 | } 107 | } 108 | 109 | 110 | } // namespace curlpp 111 | 112 | 113 | } // namespace internal 114 | -------------------------------------------------------------------------------- /src/curlpp/internal/SList.cpp: -------------------------------------------------------------------------------- 1 | #include "curlpp/internal/SList.hpp" 2 | #include "curlpp/internal/global.h" 3 | 4 | #if HAVE_OSTREAM 5 | # include 6 | #else 7 | # include 8 | #endif 9 | 10 | #include 11 | 12 | 13 | namespace curlpp 14 | { 15 | 16 | 17 | namespace internal 18 | { 19 | 20 | 21 | SList::SList(const SList & rhs) 22 | : mList(0) 23 | , mData(rhs.mData) 24 | { 25 | update(); 26 | } 27 | 28 | 29 | SList::SList(curl_slist * list) 30 | : mList(NULL) 31 | { 32 | constructFrom(list); 33 | } 34 | 35 | 36 | SList::SList(const std::list & rhs) 37 | : mList(0) 38 | , mData(rhs) 39 | { 40 | update(); 41 | } 42 | 43 | 44 | SList::SList() 45 | : mList(0) 46 | {} 47 | 48 | 49 | SList::~SList() 50 | { 51 | clear(); 52 | } 53 | 54 | 55 | void 56 | SList::clear() 57 | { 58 | if(mList != 0) 59 | { 60 | curl_slist_free_all(mList); 61 | mList = 0; 62 | } 63 | } 64 | 65 | 66 | void 67 | SList::constructFrom(curl_slist * list) 68 | { 69 | mData.clear(); 70 | 71 | curl_slist * c = list; 72 | while(c) 73 | { 74 | mData.push_back(c->data); 75 | c = c->next; 76 | } 77 | 78 | update(); 79 | } 80 | 81 | 82 | void 83 | SList::set(const std::list & list) 84 | { 85 | mData = list; 86 | update(); 87 | } 88 | 89 | 90 | void 91 | SList::update() 92 | { 93 | clear(); 94 | 95 | for(std::list::const_iterator pos = mData.begin(); 96 | pos != mData.end(); 97 | pos++) 98 | { 99 | mList = curl_slist_append(mList, (*pos).c_str()); 100 | } 101 | } 102 | 103 | 104 | SList::operator std::list () 105 | { 106 | return list(); 107 | } 108 | 109 | 110 | SList & 111 | SList::operator=(const std::list & list) 112 | { 113 | set(list); 114 | return (*this); 115 | } 116 | 117 | 118 | curl_slist * 119 | SList::cslist() const 120 | { 121 | return mList; 122 | } 123 | 124 | 125 | std::list 126 | SList::list() 127 | { 128 | return mData; 129 | } 130 | 131 | 132 | 133 | 134 | } // namespace internal 135 | 136 | 137 | } // namespace curlpp 138 | 139 | 140 | std::ostream & operator<<(std::ostream & stream, const std::list & value) 141 | { 142 | for(std::list::const_iterator pos = value.begin(); 143 | pos != value.end(); 144 | pos++) 145 | { 146 | if(pos != value.begin()) 147 | { 148 | stream << ", "; 149 | } 150 | stream << (*pos); 151 | } 152 | 153 | return stream; 154 | } 155 | -------------------------------------------------------------------------------- /src/utilspp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ) 3 | 4 | add_subdirectory(singleton) 5 | 6 | 7 | ########### next target ############### 8 | 9 | set(utilspp_STAT_SRCS 10 | clone_ptr.hpp 11 | EmptyType.hpp 12 | Functors.hpp 13 | NonCopyable.hpp 14 | NullType.hpp 15 | Singleton.hpp 16 | SmartPtr.hpp 17 | ThreadingFactoryMutex.hpp 18 | ThreadingFactoryMutex.inl 19 | ThreadingSingle.hpp 20 | ThreadingSingle.inl 21 | TypeList.hpp 22 | TypeTrait.hpp) 23 | 24 | add_library(utilspp STATIC ${utilspp_STAT_SRCS}) 25 | 26 | 27 | ########### install files ############### 28 | 29 | 30 | 31 | 32 | #original Makefile.am contents follow: 33 | 34 | #SUBDIRS = singleton 35 | # 36 | #noinst_LTLIBRARIES = libutilspp.la 37 | # 38 | #libutilspp_la_SOURCES = \ 39 | # clone_ptr.hpp \ 40 | # EmptyType.hpp \ 41 | # Functors.hpp \ 42 | # NonCopyable.hpp \ 43 | # NullType.hpp \ 44 | # Singleton.hpp \ 45 | # SmartPtr.hpp \ 46 | # ThreadingFactoryMutex.hpp ThreadingFactoryMutex.inl \ 47 | # ThreadingSingle.hpp ThreadingSingle.inl \ 48 | # TypeList.hpp \ 49 | # TypeTrait.hpp 50 | # 51 | #libutilspp_la_LIBADD = ./singleton/libsingleton.la 52 | # 53 | -------------------------------------------------------------------------------- /src/utilspp/LifetimeLibrary.cpp: -------------------------------------------------------------------------------- 1 | #include "utilspp/singleton/SingletonHolder.hpp" 2 | #include "utilspp/singleton/LifetimeLibrary.hpp" 3 | 4 | utilspp::LifetimeLibraryImpl::LifetimeLibraryImpl() 5 | : 6 | mTrackerArray(NULL), 7 | mNbElements(0) 8 | {} 9 | 10 | utilspp::LifetimeLibraryImpl::~LifetimeLibraryImpl() 11 | { 12 | terminate(); 13 | } 14 | 15 | void 16 | utilspp::LifetimeLibraryImpl::add(utilspp::PrivateMembers::LifetimeTracker * tracker) 17 | { 18 | utilspp::PrivateMembers::TrackerArray newArray = static_cast< 19 | utilspp::PrivateMembers::TrackerArray>(std::realloc(mTrackerArray, 20 | mNbElements + 1)); 21 | if(newArray == NULL) 22 | { 23 | throw std::bad_alloc(); 24 | } 25 | 26 | mTrackerArray = newArray; 27 | 28 | utilspp::PrivateMembers::TrackerArray pos = 29 | std::upper_bound(mTrackerArray, 30 | mTrackerArray + mNbElements, 31 | tracker, 32 | &utilspp::PrivateMembers::LifetimeTracker::compare); 33 | std::copy_backward(pos, 34 | mTrackerArray + mNbElements, 35 | mTrackerArray + mNbElements + 1); 36 | 37 | *pos = tracker; 38 | mNbElements++; 39 | }; 40 | 41 | void 42 | utilspp::LifetimeLibraryImpl::terminate() 43 | { 44 | //The number of elements MUST always be equal or over zero. 45 | assert(mNbElements >= 0); 46 | 47 | while(mNbElements > 0) 48 | { 49 | //At this point the mTrackerArray MUST not be NULL. 50 | assert(mTrackerArray != NULL); 51 | 52 | //Pick the element at the top of the stack. 53 | utilspp::PrivateMembers::LifetimeTracker* top = 54 | mTrackerArray[mNbElements - 1]; 55 | 56 | //Remove that object off the stack. 57 | //Don't check errors-realloc with less memory, cause that can't fail. 58 | mTrackerArray = 59 | static_cast 60 | (std::realloc(mTrackerArray, --mNbElements)); 61 | 62 | //Destroy the element. 63 | delete top; 64 | } 65 | } 66 | 67 | unsigned int 68 | utilspp::getLongevity(utilspp::LifetimeLibraryImpl *) 69 | { 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/utilspp/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libutilspp.la 2 | 3 | INCLUDES = -I$(top_builddir)/include 4 | 5 | libutilspp_la_SOURCES = \ 6 | LifetimeLibrary.cpp \ 7 | PrivateMembers.cpp 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/utilspp/PrivateMembers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "utilspp/singleton/PrivateMembers.hpp" 4 | 5 | utilspp::PrivateMembers::TrackerArray 6 | utilspp::PrivateMembers::mTrackerArray = NULL; 7 | 8 | int utilspp::PrivateMembers::mNbElements = 0; 9 | 10 | utilspp::PrivateMembers::LifetimeTracker::LifetimeTracker( unsigned int 11 | longevity ) 12 | : 13 | mLongevity(longevity) 14 | {} 15 | 16 | utilspp::PrivateMembers::LifetimeTracker::~LifetimeTracker() 17 | {} 18 | 19 | bool 20 | utilspp::PrivateMembers::LifetimeTracker::compare( 21 | const LifetimeTracker * l, 22 | const LifetimeTracker * r 23 | ) 24 | { 25 | return l->mLongevity < r->mLongevity; 26 | } 27 | 28 | void 29 | utilspp::PrivateMembers::atExitFunc() 30 | { 31 | assert((mTrackerArray != NULL) && 32 | (mNbElements> 0)); 33 | 34 | //Pick the element at the top of the stack. 35 | LifetimeTracker* top = mTrackerArray[mNbElements - 1]; 36 | 37 | //Remove that object off the stack. 38 | //Don't check errors-realloc with less memory, cause that can't fail. 39 | mTrackerArray = static_cast< 40 | utilspp::PrivateMembers::TrackerArray>(std::realloc(mTrackerArray, 41 | --mNbElements)); 42 | 43 | //Destroy the element. 44 | delete top; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /win32/create-vc-solution.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set OUTPUT_DIR=.. 4 | 5 | REM VC_VERSION = 7.1 | 8 | 9 6 | REM 7.1 - MS Visual C++ 2003, 8 - MS Visual C++ 2005, 9 - MS Visual C++ 2008 7 | set VC_VERSION=%1 8 | set RESTORE=%2 9 | 10 | if "%VC_VERSION%" == "" ( 11 | @echo on 12 | @echo Usage: 13 | @echo create-vc-solution.bat vc_version [/restore] 14 | @echo 15 | @echo vc_version - Visual C++ version for the target solution and project files. Valid values are 8 and 9. 16 | @echo ???please add doc for restore 17 | pause 18 | exit /b 1) 19 | 20 | if "%VC_VERSION%" == "7.1" ( 21 | set VC_NAME=Visual Studio 2003 22 | set VC_FORMAT=??? 23 | set SLN_FORMAT=??? 24 | set PRJ_VERSION=??? 25 | set VSPROPS_VERSION=???) 26 | 27 | if "%VC_VERSION%" == "8" ( 28 | set MSVS_NAME=Visual Studio 2005 29 | set SLN_FORMAT=9.00 30 | set PRJ_VERSION=8,00 31 | set VSPROPS_VERSION=8.00) 32 | 33 | if "%VC_VERSION%" == "9" ( 34 | set MSVS_NAME=Visual Studio 2008 35 | set SLN_FORMAT=10.00 36 | set PRJ_VERSION=9,00 37 | set VSPROPS_VERSION=8.00) 38 | 39 | REM curlpp solution 40 | set FILE1=curlpp.sln 41 | if "%RESTORE%" == "restore" ( 42 | sed -T -e s/"%MSVS_NAME%"/MSVS_NAME/ -e s/"%SLN_FORMAT%"/SLN_FORMAT/ %OUTPUT_DIR%\%FILE1% > %FILE1%.stub ) else ( 43 | sed -T -e s/MSVS_NAME/"%MSVS_NAME%"/ -e s/SLN_FORMAT/"%SLN_FORMAT%"/ %FILE1%.stub > %OUTPUT_DIR%\%FILE1%) 44 | 45 | REM curlpp.common 46 | set FILE2=curlpp.common.vsprops 47 | if "%RESTORE%" == "restore" ( 48 | sed -T -e s/"%VSPROPS_VERSION%"/VSPROPS_VERSION/ %OUTPUT_DIR%\%FILE2% > %FILE2%.stub) else ( 49 | sed -T -e s/VSPROPS_VERSION/"%VSPROPS_VERSION%"/ %FILE2%.stub > %OUTPUT_DIR%\%FILE2%) 50 | 51 | REM curlpp.lib 52 | set FILE3=curlpp.lib.vcproj 53 | set FILE3b=curlpp.lib.vsprops 54 | if "%RESTORE%" == "restore" ( 55 | sed -T -e s/"%PRJ_VERSION%"/PRJ_VERSION/ %OUTPUT_DIR%\%FILE3% > %FILE3%.stub 56 | sed -T -e s/"%VSPROPS_VERSION%"/VSPROPS_VERSION/ %OUTPUT_DIR%\%FILE3b% > %FILE3b%.stub) else ( 57 | sed -T -e s/PRJ_VERSION/"%PRJ_VERSION%"/ %FILE3%.stub > %OUTPUT_DIR%\%FILE3% 58 | sed -T -e s/VSPROPS_VERSION/"%VSPROPS_VERSION%"/ %FILE3b%.stub > %OUTPUT_DIR%\%FILE3b%) 59 | 60 | 61 | REM curlpp.examples 62 | set FILE4=curlpp.examples.vcproj 63 | set FILE4b=curlpp.examples.vsprops 64 | if "%RESTORE%" == "restore" ( 65 | sed -T -e s/"%PRJ_VERSION%"/PRJ_VERSION/ %OUTPUT_DIR%\%FILE4% > %FILE4%.stub 66 | sed -T -e s/"%VSPROPS_VERSION%"/VSPROPS_VERSION/ %OUTPUT_DIR%\%FILE4b% > %FILE4b%.stub) else ( 67 | sed -T -e s/PRJ_VERSION/"%PRJ_VERSION%"/ %FILE4%.stub > %OUTPUT_DIR%\%FILE4% 68 | sed -T -e s/VSPROPS_VERSION/"%VSPROPS_VERSION%"/ %FILE4b%.stub > %OUTPUT_DIR%\%FILE4b%) 69 | -------------------------------------------------------------------------------- /win32/curlpp.common.vsprops.stub: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 17 | 21 | 25 | 29 | 33 | 37 | 38 | -------------------------------------------------------------------------------- /win32/curlpp.examples.vsprops.stub: -------------------------------------------------------------------------------- 1 | 2 | 9 | 16 | 20 | 25 | 29 | 33 | 34 | -------------------------------------------------------------------------------- /win32/curlpp.lib.vsprops.stub: -------------------------------------------------------------------------------- 1 | 2 | 9 | 17 | 22 | 29 | 30 | --------------------------------------------------------------------------------