From fd81cc1fe40f00cd6e65a1cc9930bad6b268712d Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Fri, 27 Jul 2012 00:17:44 +0800 Subject: [PATCH] added --log-xml for debugging (#80) --- grive/src/main.cc | 4 ++++ libgrive/src/drive/Drive.cc | 14 +++++++++----- libgrive/src/drive/Drive.hh | 5 ++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/grive/src/main.cc b/grive/src/main.cc index 47947f3..b017558 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -82,6 +82,7 @@ int Main( int argc, char **argv ) ( "version,v", "Display Grive version" ) ( "auth,a", "Request authorization token" ) ( "verbose,V", "Verbose mode. Enable more messages than normal.") + ( "log-xml", "Log more HTTP responses as XML for debugging.") ( "debug,d", "Enable debug level messages. Implies -v.") ( "log,l", po::value(), "Set log output filename." ) ( "force,f", "Force grive to always download a file from Google Drive " @@ -146,6 +147,9 @@ int Main( int argc, char **argv ) { console_log->Enable( log::verbose ) ; } + + options.Add( "log-xml", Json(vm.count("log-xml") > 0) ) ; + if ( vm.count( "debug" ) ) { console_log->Enable( log::verbose ) ; diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index daf0a72..5151369 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -27,7 +27,6 @@ #include "http/ResponseLog.hh" #include "http/XmlResponse.hh" #include "protocol/Json.hh" -// #include "protocol/OAuth2.hh" #include "util/Destroy.hh" #include "util/log/Log.hh" #include "xml/Node.hh" @@ -54,8 +53,9 @@ namespace } Drive::Drive( http::Agent *http, const Json& options ) : - m_http( http ), - m_state( state_file, options ) + m_http ( http ), + m_state ( state_file, options ), + m_log_xml ( options["log-xml"].Bool() ) { assert( m_http != 0 ) ; } @@ -137,7 +137,9 @@ void Drive::DetectChanges() Log( "Reading remote server file list", log::info ) ; Feed feed ; -// feed.EnableLog( "/tmp/file", ".xml" ) ; + if ( m_log_xml ) + feed.EnableLog( "/tmp/file", ".xml" ) ; + feed.Start( m_http, http::Header(), feed_base + "?showfolders=true&showroot=true" ) ; m_resume_link = feed.Root()["link"]. @@ -156,7 +158,9 @@ void Drive::DetectChanges() { Log( "Detecting changes from last sync", log::info ) ; Feed changes ; -// feed.EnableLog( "/tmp/changes", ".xml" ) ; + if ( m_log_xml ) + feed.EnableLog( "/tmp/changes", ".xml" ) ; + feed.Start( m_http, http::Header(), ChangesFeed(prev_stamp+1) ) ; std::for_each( diff --git a/libgrive/src/drive/Drive.hh b/libgrive/src/drive/Drive.hh index 3641500..11830b5 100644 --- a/libgrive/src/drive/Drive.hh +++ b/libgrive/src/drive/Drive.hh @@ -58,11 +58,10 @@ private : private : http::Agent *m_http ; -// OAuth2& m_auth ; -// http::Header m_http_hdr ; - std::string m_resume_link ; State m_state ; + + bool m_log_xml ; } ; } // end of namespace