escape the document header. fix HTTP 400 when uploading

pull/40/head
Nestal Wan 2012-06-07 18:26:57 +08:00
parent 3d27b1af69
commit 271dd95b24
5 changed files with 85 additions and 8 deletions

View File

@ -146,7 +146,6 @@ int Main( int argc, char **argv )
}
catch ( Exception& e )
{
Trace( "cannot read config: %1%", boost::diagnostic_information(e) ) ;
Log(
"Please run grive with the \"-a\" option if this is the "
"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 ) ;
return -1 ;
}
catch ( ... )
{
return -1 ;
}
}

View File

@ -69,8 +69,8 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
// get metadata
http::XmlResponse xrsp ;
http::ResponseLog log( "meta-", ".xml", &xrsp ) ;
http.Get( "https://docs.google.com/feeds/metadata/default", &log, m_http_hdr ) ;
// http::ResponseLog log( "meta-", ".xml", &xrsp ) ;
http.Get( "https://docs.google.com/feeds/metadata/default", &xrsp, m_http_hdr ) ;
Trace( "return %1%", xrsp.Response()["docs:largestChangestamp"] ) ;
m_state.ChangeStamp(
std::atoi(xrsp.Response()["docs:largestChangestamp"]["@value"].front().Value().c_str()) ) ;

View File

@ -33,6 +33,7 @@
#include "util/StdioFile.hh"
#include "xml/Node.hh"
#include "xml/NodeSet.hh"
#include "xml/String.hh"
#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 ) ;
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 ) ;
}
break ;
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 ) )
m_state = sync ;
break ;
case remote_new :
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 ) ;
m_state = sync ;
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 ) ;
else
{
Log( "sync %1% deleted in remote. deleting local", Path(), log::verbose ) ;
Log( "sync %1% deleted in remote. deleting local", Path(), log::info ) ;
DeleteLocal() ;
}
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( "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 ;
if ( post )

View File

@ -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( "&quot;" ) ; break ;
case '\'': result.append( "&apos;" ) ; break ;
case '<': result.append( "&lt;" ) ; break ;
case '>': result.append( "&gt;" ) ; break ;
case '&': result.append( "&amp;" ) ; break ;
default: result.push_back( *i ) ; break ;
}
}
return result ;
}
} } // end of namespace

View File

@ -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