2012-06-10 19:11:32 +04:00
|
|
|
/*
|
|
|
|
grive: an GPL program to sync a local directory with Google Drive
|
|
|
|
Copyright (C) 2012 Wan Wai Ho
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation version 2
|
|
|
|
of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Agent.hh"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2013-04-28 21:25:34 +04:00
|
|
|
namespace gr {
|
2012-06-10 19:11:32 +04:00
|
|
|
|
2013-04-28 21:25:34 +04:00
|
|
|
class DataStream ;
|
|
|
|
|
|
|
|
namespace http {
|
2012-06-10 19:11:32 +04:00
|
|
|
|
2012-06-17 12:33:38 +04:00
|
|
|
/*! \brief agent to provide HTTP access
|
2012-06-10 19:11:32 +04:00
|
|
|
|
|
|
|
This class provides functions to send HTTP request in many methods (e.g. get, post and put).
|
|
|
|
Normally the HTTP response is returned in a Receivable.
|
|
|
|
*/
|
|
|
|
class CurlAgent : public Agent
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
CurlAgent() ;
|
|
|
|
~CurlAgent() ;
|
2015-09-30 15:01:50 +03:00
|
|
|
|
|
|
|
ResponseLog* GetLog() const ;
|
|
|
|
void SetLog( ResponseLog *log ) ;
|
|
|
|
|
2015-10-09 12:31:19 +03:00
|
|
|
long Request(
|
2012-06-10 19:11:32 +04:00
|
|
|
const std::string& method,
|
|
|
|
const std::string& url,
|
2015-10-09 12:31:19 +03:00
|
|
|
SeekStream *in,
|
2013-04-28 21:25:34 +04:00
|
|
|
DataStream *dest,
|
2012-06-10 19:11:32 +04:00
|
|
|
const Header& hdr ) ;
|
2015-10-09 12:31:19 +03:00
|
|
|
|
2015-06-27 22:58:01 +03:00
|
|
|
std::string LastError() const ;
|
|
|
|
std::string LastErrorHeaders() const ;
|
|
|
|
|
2012-06-10 19:11:32 +04:00
|
|
|
std::string RedirLocation() const ;
|
|
|
|
|
|
|
|
std::string Escape( const std::string& str ) ;
|
|
|
|
std::string Unescape( const std::string& str ) ;
|
|
|
|
|
|
|
|
private :
|
|
|
|
static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;
|
2015-06-27 22:58:01 +03:00
|
|
|
static std::size_t Receive( void* ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;
|
2015-10-09 12:31:19 +03:00
|
|
|
|
2012-06-10 19:11:32 +04:00
|
|
|
long ExecCurl(
|
|
|
|
const std::string& url,
|
2013-04-28 21:25:34 +04:00
|
|
|
DataStream *dest,
|
2012-06-10 19:11:32 +04:00
|
|
|
const Header& hdr ) ;
|
|
|
|
|
|
|
|
void Init() ;
|
2015-10-09 12:31:19 +03:00
|
|
|
|
2012-06-10 19:11:32 +04:00
|
|
|
private :
|
|
|
|
struct Impl ;
|
2016-09-01 16:19:14 +03:00
|
|
|
std::unique_ptr<Impl> m_pimpl ;
|
|
|
|
std::unique_ptr<ResponseLog> m_log ;
|
2012-06-10 19:11:32 +04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
} } // end of namespace
|