Permalink
Browse files

using DataStream instead of Receiveable

  • Loading branch information...
1 parent 443a85d commit 738435837be79feff43e6674672fc91185fad049 @nestal nestal committed Apr 28, 2013
@@ -613,7 +613,7 @@ bool Resource::Upload(
std::string uplink = http->RedirLocation() ;
http::XmlResponse xml ;
- http->Put( uplink, file, &xml, uphdr ) ;
+ http->Put( uplink, &file, &xml, uphdr ) ;
AssignIDs( Entry( xml.Response() ) ) ;
m_mtime = Entry(xml.Response()).MTime();
View
@@ -23,12 +23,12 @@
namespace gr {
+class DataStream ;
class File ;
namespace http {
class Header ;
-class Receivable ;
class Agent
{
@@ -38,30 +38,30 @@ public :
virtual long Put(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) = 0 ;
virtual long Put(
const std::string& url,
- File& file,
- Receivable *dest,
+ File *file,
+ DataStream *dest,
const Header& hdr ) = 0 ;
virtual long Get(
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) = 0 ;
virtual long Post(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) = 0 ;
virtual long Custom(
const std::string& method,
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) = 0 ;
virtual std::string RedirLocation() const = 0 ;
@@ -19,12 +19,11 @@
#include "CurlAgent.hh"
-#include "Download.hh"
#include "Error.hh"
#include "Header.hh"
-#include "Receivable.hh"
#include "util/log/Log.hh"
+#include "util/DataStream.hh"
#include "util/File.hh"
#include <boost/throw_exception.hpp>
@@ -47,7 +46,7 @@ namespace {
using namespace gr::http ;
using namespace gr ;
-size_t ReadStringCallback( void *ptr, std::size_t size, std::size_t nmemb, std::string *data )
+std::size_t ReadStringCallback( void *ptr, std::size_t size, std::size_t nmemb, std::string *data )
{
assert( ptr != 0 ) ;
assert( data != 0 ) ;
@@ -62,14 +61,14 @@ size_t ReadStringCallback( void *ptr, std::size_t size, std::size_t nmemb, std::
return count ;
}
-size_t ReadFileCallback( void *ptr, std::size_t size, std::size_t nmemb, File *file )
+std::size_t ReadFileCallback( void *ptr, std::size_t size, std::size_t nmemb, File *file )
{
assert( ptr != 0 ) ;
assert( file != 0 ) ;
- u64_t count = std::min(
- static_cast<u64_t>(size * nmemb),
- static_cast<u64_t>(file->Size() - file->Tell()) ) ;
+ std::size_t count = std::min(
+ static_cast<std::size_t>(size * nmemb),
+ static_cast<std::size_t>(file->Size() - file->Tell()) ) ;
assert( count <= std::numeric_limits<std::size_t>::max() ) ;
if ( count > 0 )
@@ -125,15 +124,15 @@ std::size_t CurlAgent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Cur
return size*nmemb ;
}
-std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, Receivable *recv )
+std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, DataStream *recv )
{
assert( recv != 0 ) ;
- return recv->OnData( ptr, size * nmemb ) ;
+ return recv->Write( static_cast<char*>(ptr), size * nmemb ) ;
}
long CurlAgent::ExecCurl(
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const http::Header& hdr )
{
CURL *curl = m_pimpl->curl ;
@@ -147,7 +146,7 @@ long CurlAgent::ExecCurl(
SetHeader( hdr ) ;
- dest->Clear() ;
+// dest->Clear() ;
CURLcode curl_code = ::curl_easy_perform(curl);
// get the HTTP response code
@@ -176,7 +175,7 @@ long CurlAgent::ExecCurl(
long CurlAgent::Put(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr )
{
Trace("HTTP PUT \"%1%\"", url ) ;
@@ -197,10 +196,12 @@ long CurlAgent::Put(
long CurlAgent::Put(
const std::string& url,
- File& file,
- Receivable *dest,
+ File *file,
+ DataStream *dest,
const Header& hdr )
{
+ assert( file != 0 ) ;
+
Trace("HTTP PUT \"%1%\"", url ) ;
Init() ;
@@ -209,15 +210,15 @@ long CurlAgent::Put(
// set common options
::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L ) ;
::curl_easy_setopt(curl, CURLOPT_READFUNCTION, &ReadFileCallback ) ;
- ::curl_easy_setopt(curl, CURLOPT_READDATA , &file ) ;
- ::curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(file.Size()) ) ;
+ ::curl_easy_setopt(curl, CURLOPT_READDATA , file ) ;
+ ::curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(file->Size()) ) ;
return ExecCurl( url, dest, hdr ) ;
}
long CurlAgent::Get(
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr )
{
Trace("HTTP GET \"%1%\"", url ) ;
@@ -232,7 +233,7 @@ long CurlAgent::Get(
long CurlAgent::Post(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr )
{
Trace("HTTP POST \"%1%\" with \"%2%\"", url, data ) ;
@@ -254,7 +255,7 @@ long CurlAgent::Post(
long CurlAgent::Custom(
const std::string& method,
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr )
{
Trace("HTTP %2% \"%1%\"", url, method ) ;
@@ -24,9 +24,11 @@
#include <memory>
#include <string>
-namespace gr { namespace http {
+namespace gr {
-class Receivable ;
+class DataStream ;
+
+namespace http {
/*! \brief agent to provide HTTP access
@@ -42,30 +44,30 @@ public :
long Put(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) ;
long Put(
const std::string& url,
- File& file,
- Receivable *dest,
+ File *file,
+ DataStream *dest,
const Header& hdr ) ;
long Get(
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) ;
long Post(
const std::string& url,
const std::string& data,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) ;
long Custom(
const std::string& method,
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) ;
std::string RedirLocation() const ;
@@ -75,12 +77,12 @@ public :
private :
static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;
- static std::size_t Receive( void* ptr, size_t size, size_t nmemb, Receivable *recv ) ;
+ static std::size_t Receive( void* ptr, size_t size, size_t nmemb, DataStream *recv ) ;
void SetHeader( const Header& hdr ) ;
long ExecCurl(
const std::string& url,
- Receivable *dest,
+ DataStream *dest,
const Header& hdr ) ;
void Init() ;
@@ -65,14 +65,20 @@ std::string Download::Finish() const
return m_crypt.get() != 0 ? m_crypt->Get() : "" ;
}
-std::size_t Download::OnData( void *data, std::size_t count )
+std::size_t Download::Write( const char *data, std::size_t count )
{
assert( data != 0 ) ;
if ( m_crypt.get() != 0 )
m_crypt->Write( data, count ) ;
- return m_file.Write( static_cast<char*>(data), count ) ;
+ return m_file.Write( data, count ) ;
+}
+
+
+std::size_t Download::Read( char *data, std::size_t count )
+{
+ return count ;
}
} } // end of namespace
@@ -19,7 +19,6 @@
#pragma once
-#include "Receivable.hh"
#include "util/File.hh"
#include <string>
@@ -33,7 +32,7 @@ namespace crypt
namespace http {
-class Download : public http::Receivable
+class Download : public DataStream
{
public :
struct NoChecksum {} ;
@@ -44,7 +43,8 @@ public :
std::string Finish() const ;
void Clear() ;
- std::size_t OnData( void *data, std::size_t count ) ;
+ std::size_t Write( const char *data, std::size_t count ) ;
+ std::size_t Read( char *, std::size_t ) ;
private :
File m_file ;
@@ -1,39 +0,0 @@
-/*
- 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"
-
-namespace gr { namespace http {
-
-class HttpRequest ;
-
-/*! \brief An marshaller for HTTP agent
-
- This agent will marshal the HTTP requests to a request objects containing the arguments
- of the request and the response.
-*/
-class MarshalAgent : public Agent
-{
-public :
- MarshalAgent( std::auto_ptr<Agent> real_agent ) ;
-} ;
-
-}} // end of namespace
@@ -1,34 +0,0 @@
-/*
- 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 <cstddef>
-
-namespace gr { namespace http {
-
-class Receivable
-{
-public :
- virtual ~Receivable() {}
- virtual std::size_t OnData( void *data, std::size_t count ) = 0 ;
- virtual void Clear() = 0 ;
-} ;
-
-} } // end of namespace
Oops, something went wrong.

0 comments on commit 7384358

Please sign in to comment.