diff --git a/libgrive/src/drive/File.cc b/libgrive/src/drive/File.cc index 5403ba0..71777b0 100644 --- a/libgrive/src/drive/File.cc +++ b/libgrive/src/drive/File.cc @@ -21,10 +21,12 @@ #include "http/Download.hh" #include "http/StringResponse.hh" +#include "http/XmlResponse.hh" #include "protocol/Json.hh" #include "protocol/OAuth2.hh" #include "util/OS.hh" #include "util/Path.hh" +#include "xml/Node.hh" #include #include @@ -161,7 +163,11 @@ bool File::Upload( std::streambuf *file, const http::Headers& auth ) uphdr.push_back( "Expect:" ) ; uphdr.push_back( "Accept:" ) ; - http.Put( uplink, data, &str, uphdr ) ; + http::XmlResponse xml ; + http.Put( uplink, data, &xml, uphdr ) ; + +std::cout << xml.Response() << std::endl ; + return true ; } diff --git a/libgrive/src/http/XmlResponse.cc b/libgrive/src/http/XmlResponse.cc new file mode 100644 index 0000000..88ea082 --- /dev/null +++ b/libgrive/src/http/XmlResponse.cc @@ -0,0 +1,46 @@ +/* + 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 "XmlResponse.hh" + +#include "xml/Node.hh" + +namespace gr { namespace http { + +XmlResponse::XmlResponse() +{ +} + +std::size_t XmlResponse::OnData( void *data, std::size_t count ) +{ + m_tb.ParseData( reinterpret_cast(data), count ) ; + return count ; +} + +void XmlResponse::Finish() +{ + m_tb.ParseData( 0, 0, true ) ; +} + +xml::Node XmlResponse::Response() const +{ + return m_tb.Result() ; +} + +} } // end of namespace diff --git a/libgrive/src/http/XmlResponse.hh b/libgrive/src/http/XmlResponse.hh new file mode 100644 index 0000000..aba7cce --- /dev/null +++ b/libgrive/src/http/XmlResponse.hh @@ -0,0 +1,47 @@ +/* + 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 "Receivable.hh" + +#include "xml/TreeBuilder.hh" + +namespace gr { namespace xml +{ + class Node ; +} } + +namespace gr { namespace http { + +class XmlResponse : public Receivable +{ +public : + XmlResponse() ; + + std::size_t OnData( void *data, std::size_t count ) ; + void Finish() ; + + xml::Node Response() const ; + +private : + xml::TreeBuilder m_tb ; +} ; + +} } // end of namespace diff --git a/libgrive/src/xml/Node.cc b/libgrive/src/xml/Node.cc index b155b34..ee3553c 100644 --- a/libgrive/src/xml/Node.cc +++ b/libgrive/src/xml/Node.cc @@ -22,9 +22,12 @@ #include #include #include -#include +#include #include +// debugging +#include + namespace gr { namespace xml { class Node::Impl @@ -281,4 +284,23 @@ std::string Node::Value() const return m_ptr->Value() ; } +std::vector Node::Children() const +{ + std::vector result ; + for ( Impl::iterator i = m_ptr->Begin() ; i != m_ptr->End() ; ++i ) + result.push_back( Node( (*i)->AddRef() ) ) ; + + return result ; +} + +std::ostream& operator<<( std::ostream& os, const Node& node ) +{ + os << '<' << node.Name() << '>' ; + + std::vector c = node.Children() ; + + std::copy( c.begin(), c.end(), std::ostream_iterator(os, "\n") ) ; + return os ; +} + } } // end namespace diff --git a/libgrive/src/xml/Node.hh b/libgrive/src/xml/Node.hh index 544608c..7454bc1 100644 --- a/libgrive/src/xml/Node.hh +++ b/libgrive/src/xml/Node.hh @@ -53,6 +53,8 @@ public : Type GetType() const ; static bool IsCompatible( Type parent, Type child ) ; + + std::vector Children() const ; private : class Impl ; @@ -64,4 +66,6 @@ private : Impl *m_ptr ; } ; +std::ostream& operator<<( std::ostream& os, const Node& node ) ; + } } // end of namespace