Skip to content

Commit

Permalink
fixed HttpPost Proglem
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbarrette committed Aug 26, 2007
1 parent 21dc2e4 commit d750068
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 15 additions & 0 deletions curlpp/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}
Expand Down
5 changes: 5 additions & 0 deletions curlpp/Form.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ namespace cURLpp
*/
void clear();

/**
* Get the list.
*/
std::list< cURLpp::FormPart *> getList();

private:
::curl_httppost *mFirst;
::curl_httppost *mLast;
Expand Down
6 changes: 3 additions & 3 deletions curlpp/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 48 additions & 0 deletions curlpp/OptionContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,54 @@ namespace cURLpp
typename OptionContainer< OptionType >::ValueType mValue;
};

template< >
class CURLPPAPI OptionContainer < std::list<cURLpp::FormPart *> >
{
public:
typedef OptionContainerType< std::list<cURLpp::FormPart *> >::ParamType ParamType;
typedef OptionContainerType< std::list<cURLpp::FormPart *> >::ReturnType ReturnType;
typedef OptionContainerType< std::list<cURLpp::FormPart *> >::ValueType ValueType;
typedef OptionContainerType< std::list<cURLpp::FormPart *> >::HandleOptionType HandleOptionType;

/**
* Contructor. We pass the value of the option.
*/
OptionContainer(OptionContainer< std::list<cURLpp::FormPart *> >::ParamType value);

OptionContainer(OptionContainer< std::list<cURLpp::FormPart *> > &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<cURLpp::FormPart *> >::ParamType value);

/**
* This function get the argument that is set on the handle.
*/
OptionContainer< std::list<cURLpp::FormPart *> >::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<cURLpp::FormPart *> >::HandleOptionType getHandleOptionValue();


private:
/**
* We cannot call this constructor. We absolutely need an initial value.
*/
OptionContainer();

/**
* Current value of the option.
*/
OptionContainer< std::list<cURLpp::FormPart *> >::ValueType mValue;
};

}

#include "OptionContainer.inl"
Expand Down
2 changes: 1 addition & 1 deletion curlpp/OptionContainer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}

Expand Down
16 changes: 8 additions & 8 deletions curlpp/OptionContainerType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// };

}

Expand Down
4 changes: 2 additions & 2 deletions curlpp/OptionSetter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "dllfct.h"

#include "OptionContainer.hpp"
#include "OptionContainerType.hpp"
#include "CurlHandle.hpp"
#include "Types.hpp"

Expand All @@ -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);
};
Expand Down
4 changes: 3 additions & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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}



Expand Down Expand Up @@ -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../
Expand Down
66 changes: 66 additions & 0 deletions examples/example19.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) <2002-2005> <Gazihan Alankus>
*
* 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 <stdlib.h>
#include <errno.h>

#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>

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<cURLpp::FormPart *> 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;
}

0 comments on commit d750068

Please sign in to comment.