From d750068523341c73c0c4aee77b7a81ecc0d68dc2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Barrette-LaPierre Date: Sun, 26 Aug 2007 10:22:24 -0400 Subject: [PATCH] fixed HttpPost Proglem --- CHANGES | 4 +++ curlpp/Form.cpp | 15 ++++++++ curlpp/Form.hpp | 5 +++ curlpp/Info.cpp | 6 ++-- curlpp/OptionContainer.hpp | 48 +++++++++++++++++++++++++ curlpp/OptionContainer.inl | 2 +- curlpp/OptionContainerType.hpp | 16 ++++----- curlpp/OptionSetter.hpp | 4 +-- examples/Makefile.am | 4 ++- examples/example19.cpp | 66 ++++++++++++++++++++++++++++++++++ 10 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 examples/example19.cpp diff --git a/CHANGES b/CHANGES index 8652d21..7665bd0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +Changes from version 0.7.0-pre1 to 0.7.1-pre2 +- Fixed HttpPost problem (https://www.rrette.com/pipermail/curlpp/2007-February/000273.html) + (Thanks to Gazi Alankus) + Changes from version 0.7.0 to 0.7.1-pre1 - Fixed Functor arguments binding. - Enabled example 10. diff --git a/curlpp/Form.cpp b/curlpp/Form.cpp index 0224747..f310e9e 100644 --- a/curlpp/Form.cpp +++ b/curlpp/Form.cpp @@ -74,6 +74,21 @@ cURLpp::HttpPost::clear() mForms.clear(); } +std::list< cURLpp::FormPart *> cURLpp::HttpPost::getList() +{ + //I'm not sure cloning is absolutely necessary. + std::list< cURLpp::FormPart * > newForm; + + cURLpp::FormPart *form; + std::list< cURLpp::FormPart * >::const_iterator pos; + for(pos = mForms.begin(); pos != mForms.end(); pos++) { + form = (*pos)->clone(); + newForm.push_back(form); +// form->add(&mFirst, &mLast); + } + return newForm; +} + cURLpp::FormPart::FormPart(const char *name) : mName(name) {} diff --git a/curlpp/Form.hpp b/curlpp/Form.hpp index 4ba856d..eba76e8 100644 --- a/curlpp/Form.hpp +++ b/curlpp/Form.hpp @@ -64,6 +64,11 @@ namespace cURLpp */ void clear(); + /** + * Get the list. + */ + std::list< cURLpp::FormPart *> getList(); + private: ::curl_httppost *mFirst; ::curl_httppost *mLast; diff --git a/curlpp/Info.cpp b/curlpp/Info.cpp index 126d3d0..9a64d90 100644 --- a/curlpp/Info.cpp +++ b/curlpp/Info.cpp @@ -20,9 +20,9 @@ InfoTypeConverter< std::string >::get(cURLpp::Easy &handle, template< > void -cURLpp::InfoTypeConverter< std::list< std::string > >::get(cURLpp::Easy & handle, - CURLINFO info, - std::list< std::string > &value) +InfoTypeConverter< std::list< std::string > >::get(cURLpp::Easy & handle, + CURLINFO info, + std::list< std::string > &value) { curl_slist * tmpList = NULL; InfoGetter::get(handle, info, tmpList); diff --git a/curlpp/OptionContainer.hpp b/curlpp/OptionContainer.hpp index e7ba9e6..26adcf0 100644 --- a/curlpp/OptionContainer.hpp +++ b/curlpp/OptionContainer.hpp @@ -84,6 +84,54 @@ namespace cURLpp typename OptionContainer< OptionType >::ValueType mValue; }; + template< > + class CURLPPAPI OptionContainer < std::list > + { + public: + typedef OptionContainerType< std::list >::ParamType ParamType; + typedef OptionContainerType< std::list >::ReturnType ReturnType; + typedef OptionContainerType< std::list >::ValueType ValueType; + typedef OptionContainerType< std::list >::HandleOptionType HandleOptionType; + + /** + * Contructor. We pass the value of the option. + */ + OptionContainer(OptionContainer< std::list >::ParamType value); + + OptionContainer(OptionContainer< std::list > &other); + + /** + * This function set the argument that will be passed to the + * option call for a handle. It will use the argument passed to + * this function. + */ + void setValue(OptionContainer< std::list >::ParamType value); + + /** + * This function get the argument that is set on the handle. + */ + OptionContainer< std::list >::ReturnType getValue(); + + /** + * We call this function to have the value passed to the curl_easy_setopt. + * + * Note: DO NOT USE THIS FUNCTION! It's for internal use only. + */ + OptionContainer< std::list >::HandleOptionType getHandleOptionValue(); + + + private: + /** + * We cannot call this constructor. We absolutely need an initial value. + */ + OptionContainer(); + + /** + * Current value of the option. + */ + OptionContainer< std::list >::ValueType mValue; + }; + } #include "OptionContainer.inl" diff --git a/curlpp/OptionContainer.inl b/curlpp/OptionContainer.inl index b8b83d2..7bb99e9 100644 --- a/curlpp/OptionContainer.inl +++ b/curlpp/OptionContainer.inl @@ -25,7 +25,7 @@ #define OPTION_CONTAINER_INL template< class OptionType > -cURLpp::OptionContainer< OptionType >::OptionContainer(typename cURLpp::OptionContainer< OptionType >::ParamType value) +cURLpp::OptionContainer< OptionType >::OptionContainer(typename cURLpp::OptionContainer< OptionType >::ParamType value) : mValue(value) {} diff --git a/curlpp/OptionContainerType.hpp b/curlpp/OptionContainerType.hpp index 310c7be..0b958df 100644 --- a/curlpp/OptionContainerType.hpp +++ b/curlpp/OptionContainerType.hpp @@ -100,14 +100,14 @@ namespace cURLpp typedef const cURLpp::HttpPost &HandleOptionType; }; - template< > - struct OptionContainerType< std::ostream * > - { - typedef const std::list< cURLpp::FormPart * > &ParamType; - typedef cURLpp::HttpPost ValueType; - typedef std::list< cURLpp::FormPart * > ReturnType; - typedef const cURLpp::HttpPost &HandleOptionType; - }; +// template< > +// struct OptionContainerType< std::ostream * > +// { +// typedef const std::list< cURLpp::FormPart * > &ParamType; +// typedef cURLpp::HttpPost ValueType; +// typedef std::list< cURLpp::FormPart * > ReturnType; +// typedef const cURLpp::HttpPost &HandleOptionType; +// }; } diff --git a/curlpp/OptionSetter.hpp b/curlpp/OptionSetter.hpp index bf3817c..074788f 100644 --- a/curlpp/OptionSetter.hpp +++ b/curlpp/OptionSetter.hpp @@ -26,7 +26,7 @@ #include "dllfct.h" -#include "OptionContainer.hpp" +#include "OptionContainerType.hpp" #include "CurlHandle.hpp" #include "Types.hpp" @@ -39,7 +39,7 @@ namespace cURLpp class CURLPPAPI OptionSetter { public: - typedef typename OptionContainer< OptionValueType >::HandleOptionType ParamType; + typedef typename OptionContainerType< OptionValueType >::HandleOptionType ParamType; static void setOpt(cURLpp::CurlHandle *handle, ParamType value); }; diff --git a/examples/Makefile.am b/examples/Makefile.am index c344fd5..2d84644 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -8,7 +8,7 @@ endif EXTRA_DIST = Makefile.msvc -noinst_PROGRAMS = example01 example02 example03 example04 example05 example06 example07 example08 example09 example10 example11 example12 example13 example14 example15 example16 example17 ${maintener_programs} ${boost_programs} +noinst_PROGRAMS = example01 example02 example03 example04 example05 example06 example07 example08 example09 example10 example11 example12 example13 example14 example15 example16 example17 example19 ${maintener_programs} ${boost_programs} @@ -48,6 +48,8 @@ example17_SOURCES = example17.cpp example18_SOURCES = example18.cpp +example19_SOURCES = example19.cpp + AM_LDFLAGS = -L../curlpp/ -lcurlpp -static AM_CXXFLAGS=-I../ diff --git a/examples/example19.cpp b/examples/example19.cpp new file mode 100644 index 0000000..de1e1a5 --- /dev/null +++ b/examples/example19.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) <2002-2005> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (cURLpp), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + if(argc < 2) { + std::cerr << argv[0] << ": Wrong number of arguments" << std::endl + << "Usage: " << argv[0] << " url" + << std::endl; + return EXIT_FAILURE; + } + + char *url = argv[1]; + + try { + cURLpp::Cleanup cleaner; + cURLpp::Easy request; + + request.setOpt(new cURLpp::Options::Url(url)); + request.setOpt(new cURLpp::Options::Verbose(true)); + + std::list formParts; + formParts.push_back(new cURLpp::FormParts::Content("name1", "value1")); + formParts.push_back(new cURLpp::FormParts::Content("name2", "value2")); + + request.setOpt(new cURLpp::Options::HttpPost(formParts)); + + request.perform(); + } + catch ( cURLpp::LogicError & e ) { + std::cout << e.what() << std::endl; + } + catch ( cURLpp::RuntimeError & e ) { + std::cout << e.what() << std::endl; + } + + return EXIT_SUCCESS; +}