mirror of https://github.com/vitalif/grive2
escape the document header. fix HTTP 400 when uploading
parent
3d27b1af69
commit
271dd95b24
|
@ -146,7 +146,6 @@ int Main( int argc, char **argv )
|
||||||
}
|
}
|
||||||
catch ( Exception& e )
|
catch ( Exception& e )
|
||||||
{
|
{
|
||||||
Trace( "cannot read config: %1%", boost::diagnostic_information(e) ) ;
|
|
||||||
Log(
|
Log(
|
||||||
"Please run grive with the \"-a\" option if this is the "
|
"Please run grive with the \"-a\" option if this is the "
|
||||||
"first time you're accessing your Google Drive!",
|
"first time you're accessing your Google Drive!",
|
||||||
|
@ -177,4 +176,8 @@ int main( int argc, char **argv )
|
||||||
Log( "exception: %1%", boost::diagnostic_information(e), log::critical ) ;
|
Log( "exception: %1%", boost::diagnostic_information(e), log::critical ) ;
|
||||||
return -1 ;
|
return -1 ;
|
||||||
}
|
}
|
||||||
|
catch ( ... )
|
||||||
|
{
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,8 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
|
||||||
|
|
||||||
// get metadata
|
// get metadata
|
||||||
http::XmlResponse xrsp ;
|
http::XmlResponse xrsp ;
|
||||||
http::ResponseLog log( "meta-", ".xml", &xrsp ) ;
|
// http::ResponseLog log( "meta-", ".xml", &xrsp ) ;
|
||||||
http.Get( "https://docs.google.com/feeds/metadata/default", &log, m_http_hdr ) ;
|
http.Get( "https://docs.google.com/feeds/metadata/default", &xrsp, m_http_hdr ) ;
|
||||||
Trace( "return %1%", xrsp.Response()["docs:largestChangestamp"] ) ;
|
Trace( "return %1%", xrsp.Response()["docs:largestChangestamp"] ) ;
|
||||||
m_state.ChangeStamp(
|
m_state.ChangeStamp(
|
||||||
std::atoi(xrsp.Response()["docs:largestChangestamp"]["@value"].front().Value().c_str()) ) ;
|
std::atoi(xrsp.Response()["docs:largestChangestamp"]["@value"].front().Value().c_str()) ) ;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "util/StdioFile.hh"
|
#include "util/StdioFile.hh"
|
||||||
#include "xml/Node.hh"
|
#include "xml/Node.hh"
|
||||||
#include "xml/NodeSet.hh"
|
#include "xml/NodeSet.hh"
|
||||||
|
#include "xml/String.hh"
|
||||||
|
|
||||||
#include <boost/exception/all.hpp>
|
#include <boost/exception/all.hpp>
|
||||||
|
|
||||||
|
@ -327,20 +328,20 @@ void Resource::Sync( http::Agent *http, const http::Header& auth )
|
||||||
Log( "sync %1% parent deleted in local.", Path(), log::verbose ) ;
|
Log( "sync %1% parent deleted in local.", Path(), log::verbose ) ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log( "sync %1% deleted in local. deleting remote", Path(), log::verbose ) ;
|
Log( "sync %1% deleted in local. deleting remote", Path(), log::info ) ;
|
||||||
DeleteRemote( http, auth ) ;
|
DeleteRemote( http, auth ) ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case local_changed :
|
case local_changed :
|
||||||
Log( "sync %1% changed in local. uploading", Path(), log::verbose ) ;
|
Log( "sync %1% changed in local. uploading", Path(), log::info ) ;
|
||||||
if ( EditContent( http, auth ) )
|
if ( EditContent( http, auth ) )
|
||||||
m_state = sync ;
|
m_state = sync ;
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case remote_new :
|
case remote_new :
|
||||||
case remote_changed :
|
case remote_changed :
|
||||||
Log( "sync %1% changed in remote. downloading", Path(), log::verbose ) ;
|
Log( "sync %1% changed in remote. downloading", Path(), log::info ) ;
|
||||||
Download( http, Path(), auth ) ;
|
Download( http, Path(), auth ) ;
|
||||||
m_state = sync ;
|
m_state = sync ;
|
||||||
break ;
|
break ;
|
||||||
|
@ -350,7 +351,7 @@ void Resource::Sync( http::Agent *http, const http::Header& auth )
|
||||||
Log( "sync %1% parent deleted in remote.", Path(), log::verbose ) ;
|
Log( "sync %1% parent deleted in remote.", Path(), log::verbose ) ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log( "sync %1% deleted in remote. deleting local", Path(), log::verbose ) ;
|
Log( "sync %1% deleted in remote. deleting local", Path(), log::info ) ;
|
||||||
DeleteLocal() ;
|
DeleteLocal() ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
|
@ -502,7 +503,10 @@ bool Resource::Upload( http::Agent* http, const std::string& link, const http::H
|
||||||
hdr.Add( "If-Match: " + m_entry.ETag() ) ;
|
hdr.Add( "If-Match: " + m_entry.ETag() ) ;
|
||||||
hdr.Add( "Expect:" ) ;
|
hdr.Add( "Expect:" ) ;
|
||||||
|
|
||||||
std::string meta = (boost::format( xml_meta ) % m_entry.Kind() % Name()).str() ;
|
std::string meta = (boost::format( xml_meta )
|
||||||
|
% m_entry.Kind()
|
||||||
|
% xml::Escape(Name())
|
||||||
|
).str() ;
|
||||||
|
|
||||||
http::StringResponse str ;
|
http::StringResponse str ;
|
||||||
if ( post )
|
if ( post )
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "String.hh"
|
||||||
|
|
||||||
|
namespace gr { namespace xml {
|
||||||
|
|
||||||
|
std::string Escape( const std::string& str )
|
||||||
|
{
|
||||||
|
std::string result ;
|
||||||
|
for ( std::string::const_iterator i = str.begin() ; i != str.end() ; ++i )
|
||||||
|
{
|
||||||
|
switch ( *i )
|
||||||
|
{
|
||||||
|
case '\"': result.append( """ ) ; break ;
|
||||||
|
case '\'': result.append( "'" ) ; break ;
|
||||||
|
case '<': result.append( "<" ) ; break ;
|
||||||
|
case '>': result.append( ">" ) ; break ;
|
||||||
|
case '&': result.append( "&" ) ; break ;
|
||||||
|
default: result.push_back( *i ) ; break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result ;
|
||||||
|
}
|
||||||
|
|
||||||
|
} } // end of namespace
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
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 <string>
|
||||||
|
|
||||||
|
namespace gr { namespace xml {
|
||||||
|
|
||||||
|
std::string Escape( const std::string& str ) ;
|
||||||
|
|
||||||
|
}} // end of namespace
|
Loading…
Reference in New Issue