mirror of https://github.com/vitalif/grive2
adding log to http agent
parent
efaa5df229
commit
55fb39cbc1
|
@ -71,7 +71,7 @@ Drive::Drive( OAuth2& auth ) :
|
|||
{
|
||||
if ( !Collection::IsCollection( *i ) )
|
||||
{
|
||||
UpdateFile( *i ) ;
|
||||
UpdateFile( *i, &http ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ abc << xml.Response()["feed"] ;
|
|||
m_root.CreateSubDir( Path() ) ;
|
||||
}
|
||||
|
||||
void Drive::UpdateFile( const Json& entry )
|
||||
void Drive::UpdateFile( const Json& entry, http::Agent *http )
|
||||
{
|
||||
// only handle uploaded files
|
||||
if ( entry.Has( "docs$suggestedFilename" ) )
|
||||
|
@ -204,7 +204,7 @@ void Drive::UpdateFile( const Json& entry )
|
|||
if ( !ifile || remote > local )
|
||||
{
|
||||
std::cout << "downloading " << path << std::endl ;
|
||||
file.Download( path, m_http_hdr ) ;
|
||||
file.Download( http, path, m_http_hdr ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -212,7 +212,7 @@ std::cout << "local " << path << " is newer" << std::endl ;
|
|||
// re-reading the file
|
||||
ifile.seekg(0) ;
|
||||
|
||||
if ( !file.Upload( ifile.rdbuf(), m_http_hdr ) )
|
||||
if ( !file.Upload( http, ifile.rdbuf(), m_http_hdr ) )
|
||||
std::cout << path << " is read only" << std::endl ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public :
|
|||
~Drive( ) ;
|
||||
|
||||
private :
|
||||
void UpdateFile( const Json& entry ) ;
|
||||
void UpdateFile( const Json& entry, http::Agent *http ) ;
|
||||
|
||||
void ConstructDirTree( http::Agent *http ) ;
|
||||
|
||||
|
|
|
@ -133,16 +133,15 @@ std::string Entry::ParentHref() const
|
|||
return m_parent_href ;
|
||||
}
|
||||
|
||||
void Entry::Download( const Path& file, const http::Headers& auth ) const
|
||||
void Entry::Download( gr::http::Agent* http, const Path& file, const http::Headers& auth ) const
|
||||
{
|
||||
gr::Download dl( file.Str(), Download::NoChecksum() ) ;
|
||||
http::Agent http ;
|
||||
long r = http.Get( m_content_src, &dl, auth ) ;
|
||||
long r = http->Get( m_content_src, &dl, auth ) ;
|
||||
if ( r <= 400 )
|
||||
os::SetFileTime( file, m_server_modified ) ;
|
||||
}
|
||||
|
||||
bool Entry::Upload( std::streambuf *file, const http::Headers& auth )
|
||||
bool Entry::Upload( gr::http::Agent* http, std::streambuf *file, const http::Headers& auth )
|
||||
{
|
||||
// upload link missing means that file is read only
|
||||
if ( m_upload_link.empty() )
|
||||
|
@ -171,10 +170,9 @@ bool Entry::Upload( std::streambuf *file, const http::Headers& auth )
|
|||
hdr.push_back( "Expect:" ) ;
|
||||
|
||||
http::StringResponse str ;
|
||||
http::Agent http ;
|
||||
http.Put( m_upload_link, meta, &str, hdr ) ;
|
||||
http->Put( m_upload_link, meta, &str, hdr ) ;
|
||||
|
||||
std::string uplink = http.RedirLocation() ;
|
||||
std::string uplink = http->RedirLocation() ;
|
||||
|
||||
// parse the header and find "Location"
|
||||
http::Headers uphdr ;
|
||||
|
@ -182,7 +180,7 @@ bool Entry::Upload( std::streambuf *file, const http::Headers& auth )
|
|||
uphdr.push_back( "Accept:" ) ;
|
||||
|
||||
http::XmlResponse xml ;
|
||||
http.Put( uplink, data, &xml, uphdr ) ;
|
||||
http->Put( uplink, data, &xml, uphdr ) ;
|
||||
|
||||
std::cout << xml.Response() << std::endl ;
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@ public :
|
|||
std::string SelfHref() const ;
|
||||
std::string ParentHref() const ;
|
||||
|
||||
void Download( const Path& file, const http::Headers& auth ) const ;
|
||||
bool Upload( std::streambuf *file, const http::Headers& auth ) ;
|
||||
void Download( gr::http::Agent* http, const Path& file, const http::Headers& auth ) const ;
|
||||
bool Upload( gr::http::Agent* http, std::streambuf *file, const http::Headers& auth ) ;
|
||||
void Delete( gr::http::Agent* http, const gr::http::Headers& auth ) ;
|
||||
|
||||
void Swap( Entry& e ) ;
|
||||
|
|
|
@ -71,6 +71,8 @@ struct Agent::Impl
|
|||
CURL *curl ;
|
||||
std::string location ;
|
||||
char error[CURL_ERROR_SIZE] ;
|
||||
|
||||
std::string log_prefix ;
|
||||
} ;
|
||||
|
||||
Agent::Agent() :
|
||||
|
@ -90,6 +92,15 @@ Agent::~Agent()
|
|||
::curl_easy_cleanup( m_pimpl->curl );
|
||||
}
|
||||
|
||||
void Agent::SetLogFile( const std::string& prefix )
|
||||
{
|
||||
m_pimpl->log_prefix = prefix ;
|
||||
}
|
||||
|
||||
std::string Agent::LogFilename() const
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t Agent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Agent *pthis )
|
||||
{
|
||||
char *str = reinterpret_cast<char*>(ptr) ;
|
||||
|
|
|
@ -41,7 +41,8 @@ public :
|
|||
Agent() ;
|
||||
~Agent() ;
|
||||
|
||||
// TODO: implement put from file, or some callback interface to pull data
|
||||
void SetLogFile( const std::string& prefix ) ;
|
||||
|
||||
long Put(
|
||||
const std::string& url,
|
||||
const std::string& data,
|
||||
|
@ -75,6 +76,7 @@ private :
|
|||
static std::size_t Receive( void* ptr, size_t size, size_t nmemb, Receivable *recv ) ;
|
||||
|
||||
void SetHeader( const http::Headers& hdr ) ;
|
||||
std::string LogFilename() const ;
|
||||
|
||||
private :
|
||||
struct Impl ;
|
||||
|
|
Loading…
Reference in New Issue