mirror of https://github.com/vitalif/grive2
Remove JSON-C json wrappers, use YAJL for everything
parent
ac1763f2c7
commit
5bc503279a
@ -1,527 +0,0 @@
|
||||
/*
|
||||
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 "Json.hh"
|
||||
|
||||
#include "util/DataStream.hh"
|
||||
|
||||
// needs to include stdint.h before json-c to avoid macro re-def warning
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
// disable macro re-def warning for json-c headers
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4005)
|
||||
#endif
|
||||
#include <json_tokener.h>
|
||||
#include <linkhash.h>
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace gr {
|
||||
|
||||
Json::Json( ) :
|
||||
m_json( ::json_object_new_object() )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_object" )
|
||||
) ;
|
||||
}
|
||||
|
||||
Json::Json( const char *str ) :
|
||||
m_json( ::json_object_new_string( str ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_string" )
|
||||
<< ValueErr( str )
|
||||
) ;
|
||||
}
|
||||
|
||||
/** Note that json_object_new_string_len() is not used.
|
||||
*/
|
||||
struct json_object* Json::InitStr( const char *str, std::size_t n )
|
||||
{
|
||||
struct json_object *j = ::json_object_new_string( str ) ;
|
||||
if ( j == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_string_len" )
|
||||
<< ValueErr( std::string(str, n) )
|
||||
) ;
|
||||
return j ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const std::string& str ) :
|
||||
m_json( InitStr( str.c_str(), str.size() ) )
|
||||
{
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const double& val ) :
|
||||
m_json( ::json_object_new_double( val ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_double" )
|
||||
<< ValueErr( val )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const boost::int32_t& l ) :
|
||||
m_json( ::json_object_new_int( l ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_int" )
|
||||
<< ValueErr( l )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const boost::int64_t& l ) :
|
||||
m_json( ::json_object_new_int64( l ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_int64" )
|
||||
<< ValueErr( l )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const boost::uint32_t& l ) :
|
||||
m_json( ::json_object_new_int( static_cast<int>(l) ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_int" )
|
||||
<< ValueErr( l )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const boost::uint64_t& l ) :
|
||||
m_json( ::json_object_new_int64( l ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_int64" )
|
||||
<< ValueErr( l )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const std::vector<Json>& arr ) :
|
||||
m_json( ::json_object_new_array( ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION( Error() << JsonCApi_( "json_object_new_array" ) ) ;
|
||||
|
||||
for ( std::vector<Json>::const_iterator i = arr.begin() ; i != arr.end() ; ++i )
|
||||
Add( *i ) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const bool& b ) :
|
||||
m_json( ::json_object_new_boolean( b ) )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_new_boolean" )
|
||||
<< ValueErr( b )
|
||||
) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Json( const Object& obj ) :
|
||||
m_json( ::json_object_new_object() )
|
||||
{
|
||||
if ( m_json == 0 )
|
||||
BOOST_THROW_EXCEPTION( Error() << JsonCApi_( "json_object_new_object" ) ) ;
|
||||
|
||||
for ( Object::const_iterator i = obj.begin() ; i != obj.end() ; ++i )
|
||||
Add( i->first, i->second ) ;
|
||||
}
|
||||
|
||||
Json::Json( struct json_object *json, NotOwned ) :
|
||||
m_json( json )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
}
|
||||
|
||||
Json::Json( struct json_object *json ) :
|
||||
m_json( json )
|
||||
{
|
||||
assert( json != 0 ) ;
|
||||
::json_object_get( m_json ) ;
|
||||
}
|
||||
|
||||
Json::Json( const Json& rhs ) :
|
||||
m_json( rhs.m_json )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
::json_object_get( m_json ) ;
|
||||
}
|
||||
|
||||
Json::~Json( )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
if ( m_json != 0 )
|
||||
::json_object_put( m_json ) ;
|
||||
}
|
||||
|
||||
Json& Json::operator=( const Json& rhs )
|
||||
{
|
||||
Json tmp( rhs ) ;
|
||||
Swap( tmp ) ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
void Json::Swap( Json& other )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
assert( other.m_json != 0 ) ;
|
||||
std::swap( m_json, other.m_json ) ;
|
||||
}
|
||||
|
||||
Json Json::operator[]( const std::string& key ) const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
|
||||
struct json_object *j = 0 ;
|
||||
if ( !::json_object_object_get_ex( m_json, key.c_str(), &j ) )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_object_get" )
|
||||
<< KeyNotFound_( key )
|
||||
<< Json_( ::json_object_to_json_string(m_json) ) ) ;
|
||||
|
||||
assert( j != 0 ) ;
|
||||
return Json( j ) ;
|
||||
}
|
||||
|
||||
Json Json::operator[]( const std::size_t& idx ) const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
|
||||
struct json_object *j = ::json_object_array_get_idx( m_json, idx ) ;
|
||||
if ( j == 0 )
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_object_array_get_idx" )
|
||||
<< OutOfRange_( idx )
|
||||
<< Json_( ::json_object_to_json_string(m_json) ) ) ;
|
||||
}
|
||||
|
||||
return Json( j ) ;
|
||||
}
|
||||
|
||||
bool Json::Has( const std::string& key ) const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_object_get_ex( m_json, key.c_str(), 0 ) == TRUE ;
|
||||
}
|
||||
|
||||
bool Json::Get( const std::string& key, Json& json ) const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
struct json_object *j = 0 ;
|
||||
if ( ::json_object_object_get_ex( m_json, key.c_str(), &j ) )
|
||||
{
|
||||
assert( j != 0 ) ;
|
||||
|
||||
Json tmp( j ) ;
|
||||
json.Swap( tmp ) ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
void Json::Add( const std::string& key, const Json& json )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
assert( json.m_json != 0 ) ;
|
||||
|
||||
::json_object_get( json.m_json ) ;
|
||||
::json_object_object_add( m_json, key.c_str(), json.m_json ) ;
|
||||
}
|
||||
|
||||
void Json::Add( const Json& json )
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
assert( json.m_json != 0 ) ;
|
||||
|
||||
::json_object_get( json.m_json ) ;
|
||||
::json_object_array_add( m_json, json.m_json ) ;
|
||||
}
|
||||
|
||||
bool Json::Bool() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_get_boolean( m_json ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::Is<bool>() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_is_type( m_json, json_type_boolean ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::As<bool>() const
|
||||
{
|
||||
return Bool() ;
|
||||
}
|
||||
|
||||
std::string Json::Str() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_get_string( m_json ) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::Is<std::string>() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_is_type( m_json, json_type_string ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string Json::As<std::string>() const
|
||||
{
|
||||
return Str() ;
|
||||
}
|
||||
|
||||
int Json::Int() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_get_int( m_json ) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::Is<int>() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_is_type( m_json, json_type_int ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
boost::int32_t Json::As<boost::int32_t>() const
|
||||
{
|
||||
return Int() ;
|
||||
}
|
||||
|
||||
template <>
|
||||
boost::uint32_t Json::As<boost::uint32_t>() const
|
||||
{
|
||||
return static_cast<boost::uint32_t>(Int()) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
boost::int64_t Json::As<boost::int64_t>() const
|
||||
{
|
||||
return ::json_object_get_int64( m_json ) ;
|
||||
}
|
||||
|
||||
template <>
|
||||
boost::uint64_t Json::As<boost::uint64_t>() const
|
||||
{
|
||||
return ::json_object_get_int64( m_json ) ;
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, const Json& json )
|
||||
{
|
||||
assert( json.m_json != 0 ) ;
|
||||
return os << ::json_object_to_json_string( json.m_json ) ;
|
||||
}
|
||||
|
||||
void Json::Write( DataStream *out ) const
|
||||
{
|
||||
assert( out != 0 ) ;
|
||||
|
||||
const char *str = ::json_object_to_json_string( m_json ) ;
|
||||
out->Write( str, std::strlen(str) ) ;
|
||||
}
|
||||
|
||||
Json::Type Json::DataType() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return static_cast<Type>( ::json_object_get_type( m_json ) ) ;
|
||||
}
|
||||
|
||||
Json::Object Json::AsObject() const
|
||||
{
|
||||
Object result ;
|
||||
|
||||
json_object_object_foreach( m_json, key, val )
|
||||
{
|
||||
result.insert( Object::value_type( key, Json( val ) ) ) ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::Is<Json::Object>() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_is_type( m_json, json_type_object ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Object Json::As<Json::Object>() const
|
||||
{
|
||||
return AsObject() ;
|
||||
}
|
||||
|
||||
Json::Array Json::AsArray() const
|
||||
{
|
||||
std::size_t count = ::json_object_array_length( m_json ) ;
|
||||
Array result ;
|
||||
|
||||
for ( std::size_t i = 0 ; i < count ; ++i )
|
||||
result.push_back( Json( ::json_object_array_get_idx( m_json, i ) ) ) ;
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool Json::Is<Json::Array>() const
|
||||
{
|
||||
assert( m_json != 0 ) ;
|
||||
return ::json_object_is_type( m_json, json_type_array ) == TRUE ;
|
||||
}
|
||||
|
||||
template <>
|
||||
Json::Array Json::As<Json::Array>() const
|
||||
{
|
||||
return AsArray() ;
|
||||
}
|
||||
|
||||
/// Finds an element in the array.
|
||||
/// \pre "this" is an array
|
||||
/// \return *this[i] if *this[i][key] == value
|
||||
Json Json::FindInArray( const std::string& key, const std::string& value ) const
|
||||
{
|
||||
std::size_t count = ::json_object_array_length( m_json ) ;
|
||||
|
||||
for ( std::size_t i = 0 ; i < count ; ++i )
|
||||
{
|
||||
Json item( ::json_object_array_get_idx( m_json, i ) ) ;
|
||||
if ( item.Has(key) && item[key].Str() == value )
|
||||
return item ;
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "Json::FindInArray" )
|
||||
<< KeyNotFound_( key )
|
||||
<< Value_(value)
|
||||
) ;
|
||||
|
||||
// shut off compiler warnings
|
||||
return Json() ;
|
||||
}
|
||||
|
||||
bool Json::FindInArray( const std::string& key, const std::string& value, Json& result ) const
|
||||
{
|
||||
try
|
||||
{
|
||||
result = FindInArray( key, value ) ;
|
||||
return true ;
|
||||
}
|
||||
catch ( Error& )
|
||||
{
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
Json Json::Parse( const std::string& str )
|
||||
{
|
||||
struct json_object *json = ::json_tokener_parse( str.c_str() ) ;
|
||||
if ( json == 0 )
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_tokener_parse" )
|
||||
<< ValueErr( str )
|
||||
) ;
|
||||
|
||||
return Json( json, NotOwned() ) ;
|
||||
}
|
||||
|
||||
/// Parse a file. The file is loaded from file system.
|
||||
/// \throw Error expt::ErrMsg contains a human-readable message describing the
|
||||
/// error.
|
||||
Json Json::Parse( DataStream *in )
|
||||
{
|
||||
assert( in != 0 ) ;
|
||||
|
||||
struct json_tokener *tok = ::json_tokener_new() ;
|
||||
struct json_object *json = 0 ;
|
||||
|
||||
char buf[1024] ;
|
||||
std::size_t count = 0 ;
|
||||
|
||||
while ( (count = in->Read( buf, sizeof(buf) ) ) > 0 )
|
||||
{
|
||||
json = ::json_tokener_parse_ex( tok, buf, count ) ;
|
||||
|
||||
// check for parse error
|
||||
if ( ::json_tokener_get_error(tok) == ::json_tokener_continue )
|
||||
break ;
|
||||
}
|
||||
|
||||
// save the error code and free the tokener before throwing exceptions
|
||||
::json_tokener_error err = ::json_tokener_get_error(tok) ;
|
||||
::json_tokener_free( tok ) ; tok = 0 ;
|
||||
|
||||
if ( err != json_tokener_success || json == 0 )
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(
|
||||
Error()
|
||||
<< JsonCApi_( "json_tokener_parse" )
|
||||
<< ErrMsg_( ::json_tokener_error_desc(err) )
|
||||
) ;
|
||||
}
|
||||
|
||||
return Json( json, NotOwned() ) ;
|
||||
}
|
||||
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
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 "util/Exception.hh"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
struct json_object ;
|
||||
|
||||
namespace gr {
|
||||
|
||||
class DataStream ;
|
||||
|
||||
/*! \brief Simple wrapper around JSON-C objects.
|
||||
|
||||
This class represents JSON-C objects, which can be integers, booleans, strings
|
||||
double, arrays and object.
|
||||
*/
|
||||
class Json
|
||||
{
|
||||
public :
|
||||
typedef std::map<std::string, Json> Object ;
|
||||
typedef std::vector<Json> Array ;
|
||||
|
||||
struct Error : virtual Exception {} ;
|
||||
typedef boost::error_info<struct JsonTag, std::string> Json_ ;
|
||||
typedef boost::error_info<struct OutOfRange, std::size_t> OutOfRange_ ;
|
||||
typedef boost::error_info<struct KeyNotFound, std::string> KeyNotFound_ ;
|
||||
typedef boost::error_info<struct JsonCApi, std::string> JsonCApi_ ;
|
||||
typedef boost::error_info<struct Value, std::string> Value_ ;
|
||||
typedef boost::error_info<struct ErrMsg, std::string> ErrMsg_ ;
|
||||
|
||||
template <typename T>
|
||||
struct Val_
|
||||
{
|
||||
typedef boost::error_info<struct Value, T> Err ;
|
||||
} ;
|
||||
|
||||
public :
|
||||
template <typename T>
|
||||
explicit Json( const T& val ) ;
|
||||
|
||||
template <std::size_t n>
|
||||
explicit Json( const char (&str)[n] ) :
|
||||
m_json( InitStr( str, n ) )
|
||||
{
|
||||
}
|
||||
|
||||
Json() ;
|
||||
Json( const Json& rhs ) ;
|
||||
Json( const char *str ) ;
|
||||
~Json() ;
|
||||
|
||||
static Json Parse( const std::string& str ) ;
|
||||
static Json Parse( DataStream *in ) ;
|
||||
|
||||
Json operator[]( const std::string& key ) const ;
|
||||
Json operator[]( const std::size_t& idx ) const ;
|
||||
Json& operator=( const Json& rhs ) ;
|
||||
|
||||
void Swap( Json& other ) ;
|
||||
|
||||
std::string Str() const ;
|
||||
int Int() const ;
|
||||
double Double() const ;
|
||||
bool Bool() const ;
|
||||
Array AsArray() const ;
|
||||
Object AsObject() const ;
|
||||
|
||||
template <typename T>
|
||||
bool Is() const ;
|
||||
|
||||
template <typename T>
|
||||
T As() const ;
|
||||
|
||||
bool Has( const std::string& key ) const ;
|
||||
bool Get( const std::string& key, Json& json ) const ;
|
||||
void Add( const std::string& key, const Json& json ) ;
|
||||
void Add( const Json& json ) ;
|
||||
Json FindInArray( const std::string& key, const std::string& value ) const ;
|
||||
bool FindInArray( const std::string& key, const std::string& value, Json& result ) const ;
|
||||
|
||||
/** Expect *this is a JSON array of objects. Select all "key" values inside each
|
||||
objects in the array and copies them in the output iterator \a out.
|
||||
*/
|
||||
template <typename T, typename Out>
|
||||
Out Select( const std::string& key, Out out )
|
||||
{
|
||||
Array a = AsArray() ;
|
||||
for ( Array::iterator i = a.begin() ; i != a.end() ; ++i )
|
||||
{
|
||||
Json value;
|
||||
if ( i->Get( key, value ) )
|
||||
*out++ = value.As<T>() ;
|
||||
}
|
||||
return out ;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& os, const Json& json ) ;
|
||||
void Write( DataStream *out ) const ;
|
||||
|
||||
enum Type { null_type, bool_type, double_type, int_type, object_type, array_type, string_type } ;
|
||||
|
||||
Type DataType() const ;
|
||||
|
||||
private :
|
||||
Json( struct json_object *json ) ;
|
||||
|
||||
struct NotOwned {} ;
|
||||
Json( struct json_object *json, NotOwned ) ;
|
||||
|
||||
static struct json_object* InitStr( const char *str, std::size_t n ) ;
|
||||
|
||||
// helper for throwing exception
|
||||
template <typename T> static typename Val_<T>::Err ValueErr( const T& t )
|
||||
{
|
||||
return typename Val_<T>::Err(t);
|
||||
}
|
||||
|
||||
private :
|
||||
struct json_object *m_json ;
|
||||
} ;
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
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 "JsonResponse.hh"
|
||||
|
||||
#include "protocol/Json.hh"
|
||||
|
||||
namespace gr { namespace http {
|
||||
|
||||
JsonResponse::JsonResponse()
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t JsonResponse::Write( const char *data, std::size_t count )
|
||||
{
|
||||
return m_resp.Write( data, count ) ;
|
||||
}
|
||||
|
||||
std::size_t JsonResponse::Read( char *data, std::size_t count )
|
||||
{
|
||||
return count ;
|
||||
}
|
||||
|
||||
Json JsonResponse::Response() const
|
||||
{
|
||||
return Json::Parse( m_resp.Response() ) ;
|
||||
}
|
||||
|
||||
} } // end of namespace
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
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 "util/DataStream.hh"
|
||||
#include "http/StringResponse.hh"
|
||||
|
||||
namespace gr
|
||||
{
|
||||
class Json ;
|
||||
}
|
||||
|
||||
namespace gr { namespace http {
|
||||
|
||||
class JsonResponse : public DataStream
|
||||
{
|
||||
public :
|
||||
JsonResponse() ;
|
||||
|
||||
std::size_t Write( const char *data, std::size_t count ) ;
|
||||
std::size_t Read( char *data, std::size_t count ) ;
|
||||
|
||||
Json Response() const ;
|
||||
|
||||
private :
|
||||
StringResponse m_resp ;
|
||||
} ;
|
||||
|
||||
} } // end of namespace
|
Loading…
Reference in New Issue