2012-07-19 20:39:36 +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 "http/Agent.hh"
|
|
|
|
#include "OAuth2.hh"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace gr {
|
|
|
|
|
|
|
|
/*! \brief An HTTP agent with support OAuth2
|
|
|
|
|
|
|
|
This is a HTTP agent that provide support for OAuth2. It will also perform retries on
|
|
|
|
certain HTTP errors.
|
|
|
|
*/
|
|
|
|
class AuthAgent : public http::Agent
|
|
|
|
{
|
|
|
|
public :
|
2015-10-07 01:57:28 +03:00
|
|
|
AuthAgent( OAuth2& auth, http::Agent* real_agent ) ;
|
2015-09-30 15:01:50 +03:00
|
|
|
|
|
|
|
http::ResponseLog* GetLog() const ;
|
|
|
|
void SetLog( http::ResponseLog *log ) ;
|
2012-07-19 20:39:36 +04:00
|
|
|
|
2015-10-09 12:31:19 +03:00
|
|
|
long Request(
|
2012-07-19 20:39:36 +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,
|
2016-08-05 20:29:48 +03:00
|
|
|
const http::Header& hdr,
|
|
|
|
const long downloadFileBytes = 0) ;
|
2012-07-19 20:39:36 +04:00
|
|
|
|
2015-06-27 22:58:01 +03:00
|
|
|
std::string LastError() const ;
|
|
|
|
std::string LastErrorHeaders() const ;
|
|
|
|
|
2012-07-19 20:39:36 +04:00
|
|
|
std::string RedirLocation() const ;
|
|
|
|
|
|
|
|
std::string Escape( const std::string& str ) ;
|
|
|
|
std::string Unescape( const std::string& str ) ;
|
|
|
|
|
2016-05-15 23:05:25 +03:00
|
|
|
void SetUploadSpeed( unsigned kbytes ) ;
|
|
|
|
void SetDownloadSpeed( unsigned kbytes ) ;
|
|
|
|
|
2016-08-05 20:29:48 +03:00
|
|
|
void SetProgressBar( ProgressBar *progressbar ) ;
|
|
|
|
|
2012-07-19 20:39:36 +04:00
|
|
|
private :
|
|
|
|
http::Header AppendHeader( const http::Header& hdr ) const ;
|
2012-07-19 20:50:40 +04:00
|
|
|
bool CheckRetry( long response ) ;
|
2012-07-25 21:23:20 +04:00
|
|
|
long CheckHttpResponse(
|
|
|
|
long response,
|
|
|
|
const std::string& url,
|
|
|
|
const http::Header& hdr ) ;
|
2012-07-19 20:39:36 +04:00
|
|
|
|
|
|
|
private :
|
2015-09-30 15:01:50 +03:00
|
|
|
OAuth2& m_auth ;
|
2015-10-07 01:57:28 +03:00
|
|
|
http::Agent* m_agent ;
|
2012-07-19 20:39:36 +04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
} // end of namespace
|