diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/facebook_10.vcxproj | 9 | ||||
-rw-r--r-- | protocols/FacebookRM/facebook_10.vcxproj.filters | 26 | ||||
-rw-r--r-- | protocols/FacebookRM/facebook_11.vcxproj | 9 | ||||
-rw-r--r-- | protocols/FacebookRM/facebook_11.vcxproj.filters | 26 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/Readme.txt | 14 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/ReleaseNotes.txt | 35 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/elements.h | 272 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/elements.inl | 412 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/reader.h | 125 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/reader.inl | 524 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/visitor.h | 44 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/writer.h | 57 | ||||
-rw-r--r-- | protocols/FacebookRM/src/JSON_CAJUN/writer.inl | 153 | ||||
-rw-r--r-- | protocols/FacebookRM/src/common.h | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 807 |
15 files changed, 395 insertions, 2120 deletions
diff --git a/protocols/FacebookRM/facebook_10.vcxproj b/protocols/FacebookRM/facebook_10.vcxproj index 3d9900b8ea..6da66bbf2a 100644 --- a/protocols/FacebookRM/facebook_10.vcxproj +++ b/protocols/FacebookRM/facebook_10.vcxproj @@ -194,10 +194,6 @@ <ClCompile Include="src\utils.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\JSON_CAJUN\elements.h" />
- <ClInclude Include="src\JSON_CAJUN\reader.h" />
- <ClInclude Include="src\JSON_CAJUN\visitor.h" />
- <ClInclude Include="src\JSON_CAJUN\writer.h" />
<ClInclude Include="src\client.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\constants.h" />
@@ -215,11 +211,6 @@ <ClInclude Include="src\version.h" />
</ItemGroup>
<ItemGroup>
- <None Include="src\JSON_CAJUN\elements.inl" />
- <None Include="src\JSON_CAJUN\reader.inl" />
- <None Include="src\JSON_CAJUN\writer.inl" />
- </ItemGroup>
- <ItemGroup>
<ResourceCompile Include="res\facebook.rc" />
<ResourceCompile Include="res\version.rc" />
</ItemGroup>
diff --git a/protocols/FacebookRM/facebook_10.vcxproj.filters b/protocols/FacebookRM/facebook_10.vcxproj.filters index 0723d8bb3d..cea7e77751 100644 --- a/protocols/FacebookRM/facebook_10.vcxproj.filters +++ b/protocols/FacebookRM/facebook_10.vcxproj.filters @@ -5,9 +5,6 @@ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
- <Filter Include="Source Files\JSON_CAJUN">
- <UniqueIdentifier>{7cc935fb-209f-455a-93b3-d3346104ae5b}</UniqueIdentifier>
- </Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
@@ -71,18 +68,6 @@ </ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\JSON_CAJUN\elements.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\reader.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\visitor.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\writer.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
<ClInclude Include="src\client.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -130,17 +115,6 @@ </ClInclude>
</ItemGroup>
<ItemGroup>
- <None Include="src\JSON_CAJUN\elements.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- <None Include="src\JSON_CAJUN\reader.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- <None Include="src\JSON_CAJUN\writer.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- </ItemGroup>
- <ItemGroup>
<ResourceCompile Include="res\facebook.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
diff --git a/protocols/FacebookRM/facebook_11.vcxproj b/protocols/FacebookRM/facebook_11.vcxproj index 8db31e285c..27f8a250be 100644 --- a/protocols/FacebookRM/facebook_11.vcxproj +++ b/protocols/FacebookRM/facebook_11.vcxproj @@ -197,10 +197,6 @@ <ClCompile Include="src\utils.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\JSON_CAJUN\elements.h" />
- <ClInclude Include="src\JSON_CAJUN\reader.h" />
- <ClInclude Include="src\JSON_CAJUN\visitor.h" />
- <ClInclude Include="src\JSON_CAJUN\writer.h" />
<ClInclude Include="src\client.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\constants.h" />
@@ -218,11 +214,6 @@ <ClInclude Include="src\version.h" />
</ItemGroup>
<ItemGroup>
- <None Include="src\JSON_CAJUN\elements.inl" />
- <None Include="src\JSON_CAJUN\reader.inl" />
- <None Include="src\JSON_CAJUN\writer.inl" />
- </ItemGroup>
- <ItemGroup>
<ResourceCompile Include="res\facebook.rc" />
<ResourceCompile Include="res\version.rc" />
</ItemGroup>
diff --git a/protocols/FacebookRM/facebook_11.vcxproj.filters b/protocols/FacebookRM/facebook_11.vcxproj.filters index 0723d8bb3d..cea7e77751 100644 --- a/protocols/FacebookRM/facebook_11.vcxproj.filters +++ b/protocols/FacebookRM/facebook_11.vcxproj.filters @@ -5,9 +5,6 @@ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
- <Filter Include="Source Files\JSON_CAJUN">
- <UniqueIdentifier>{7cc935fb-209f-455a-93b3-d3346104ae5b}</UniqueIdentifier>
- </Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
@@ -71,18 +68,6 @@ </ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\JSON_CAJUN\elements.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\reader.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\visitor.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
- <ClInclude Include="src\JSON_CAJUN\writer.h">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </ClInclude>
<ClInclude Include="src\client.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -130,17 +115,6 @@ </ClInclude>
</ItemGroup>
<ItemGroup>
- <None Include="src\JSON_CAJUN\elements.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- <None Include="src\JSON_CAJUN\reader.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- <None Include="src\JSON_CAJUN\writer.inl">
- <Filter>Source Files\JSON_CAJUN</Filter>
- </None>
- </ItemGroup>
- <ItemGroup>
<ResourceCompile Include="res\facebook.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/Readme.txt b/protocols/FacebookRM/src/JSON_CAJUN/Readme.txt deleted file mode 100644 index 8b9505cebf..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/Readme.txt +++ /dev/null @@ -1,14 +0,0 @@ -CAJUN* is a C++ API for the JSON object interchange format. JSON is like XML, except it doesn't suck**. It is specifically designed for representing (in plain text format) structures familiar to software engineers: booleans, numerics, strings, arrays, and objects (i.e. name/value pairs, associative array, etc.); it humbly leaves text markup to XML. It is ideal for storing persistent application data, such as configuration or user data files.
-
-Too many JSON parsers I've seen suffer from overly complex designs and confusing interfaces, so in true software engineer form, I thought I could do better. The goal of JSON was to create an simple, "minimalist" interface while sacrificing absolutely no power or flexibility. The STL containers, while not without their violations of that spirit, served as an inspiration. The end result is (IMHO) an interface that should be immediately intuitive to anyone familiar with C++ and the Standard Library containers. It can best be described as working with an "element", where an element may consist of:
-* String (mimics std::string)
-* Numeric (double)
-* Boolean (bool)
-* Array (std::vector<UnknownElement>)
-* Object (unsorted std::map<std::string, UnknownElement>)
-* UnknownElement - like boost::any, but restricted to types below. Used to aggregate elements within Objects & Arrays, and for reading documents of unknown structure
-
-As with any design, sacrifices were made with CAJUN. Most situations I've encountered where JSON is well-suited (reading & writing application configuration and data files) are not typically performance bottlenecks, so simplicity, safety & flexibility were favored over raw speed. The end result is a library with simple, typesafe classes, no memory-management burden on the user, and exception-based error reporting.
-
-* C++ API for JSON. A pint on me for who ever comes up with a good meaning for "UN".
-** To be fair, XML doesn't suck intentionally, it is just often used inappropriately.
\ No newline at end of file diff --git a/protocols/FacebookRM/src/JSON_CAJUN/ReleaseNotes.txt b/protocols/FacebookRM/src/JSON_CAJUN/ReleaseNotes.txt deleted file mode 100644 index 8e43b6f928..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/ReleaseNotes.txt +++ /dev/null @@ -1,35 +0,0 @@ -2.0.1 (11/17/2009)
-* A couple of Reader functions not inlined, sometimes resulting in linker duplicate symbols. Oops.
-
-
-2.0.0 (11/14/2009)
-* Redesign/simplicification of the element class relationships:
- * Element/Element_T base class or *Imp classes eliminated. Originally necessary for aggregation by Object/Array, but now unnecessary with UnknownElement type
- * json_cast<> functions eliminated. Static type safety relaxed, allowing more concise document data extraction code (dynamic type safety still completely maintained).
- * Quick-Interpreter/-Builder classes eliminated. Equivalent functionality now in "UnknownElement", but now more accessible
- In summary, simpler design, less code in library, less code necessary to utilize library. See test app for many more new examples.
-* Entire library is now inlined. Bound to be controversial, but...
- * Modern compilers should eliminate redundant object code
- * Fixes problems associated with different runtime libraries, library debug information, security & debug iterator compile-time options under MSVC++, among other things.
- * Simply include the appropriate file & go - no linker settings to mess with.
-* Added 64-bit build targets for MSVC 8/9 test app, just because.
-* Scan/Parse exceptions moved into Reader class scope, and Parse exceptions fixed to always include bad token string
-* A few more random bug fixes
-* Tested under:
- * MSVC++ 2005
- * MSVC++ 2008
- * GCC 4.4.0
-
-1.1.0 (08/30/2009)
-* Implemented operator == for all element types
-* Added makefile for building with g++ (thanks George Morgan).
-* Fixed a few compiler errors on non-Visual Studio compilers (my C++ wasn't as ANSI as I thought...)
-* Support for (non-standard) comments REMOVED
-* Support for Visual Studio 7.1 (2003) REMOVED
-* Fixed the "Unexpected token..." exception string (was gibberish)
-* Improvements to the QuickInterpreter & QuickBuilder interfaces
-* Elements now sanity-check themselves during operations and throw an exception accordingly, for example if an Object gets tricked into thinking it's an Array (reinterpret_cast, reading a document with an Array root element into an Object, etc)
-* Other random minor bug fixes & general cleanup
-
-1.0.0 (01/31/2009)
-* Initial release! Remaining work: better documentation, better test/sample app, yada yada
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/elements.h b/protocols/FacebookRM/src/JSON_CAJUN/elements.h deleted file mode 100644 index f255dcd9a5..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/elements.h +++ /dev/null @@ -1,272 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#pragma once
-
-#include <deque>
-#include <list>
-#include <string>
-#include <stdexcept>
-
-/*
-
-TODO:
-* better documentation (doxygen?)
-* Unicode support
-* parent element accessors
-
-*/
-
-namespace json
-{
-
-
-/////////////////////////////////////////////////
-// forward declarations (more info further below)
-
-
-class Visitor;
-class ConstVisitor;
-
-template <typename ValueTypeT>
-class TrivialType_T;
-
-typedef TrivialType_T<double> Number;
-typedef TrivialType_T<bool> Boolean;
-typedef TrivialType_T<std::string> String;
-
-class Object;
-class Array;
-class Null;
-
-
-
-/////////////////////////////////////////////////////////////////////////
-// Exception - base class for all JSON-related runtime errors
-
-class Exception : public std::runtime_error
-{
-public:
- Exception(const std::string& sMessage);
-};
-
-
-
-
-/////////////////////////////////////////////////////////////////////////
-// UnknownElement - provides a typesafe surrogate for any of the JSON-
-// sanctioned element types. This class allows the Array and Object
-// class to effectively contain a heterogeneous set of child elements.
-// The cast operators provide convenient implicit downcasting, while
-// preserving dynamic type safety by throwing an exception during a
-// a bad cast.
-// The object & array element index operators (operators [std::string]
-// and [size_t]) provide convenient, quick access to child elements.
-// They are a logical extension of the cast operators. These child
-// element accesses can be chained together, allowing the following
-// (when document structure is well-known):
-// String str = objInvoices[1]["Customer"]["Company"];
-
-
-class UnknownElement
-{
-public:
- UnknownElement();
- UnknownElement(const UnknownElement& unknown);
- UnknownElement(const Object& object);
- UnknownElement(const Array& array);
- UnknownElement(const Number& number);
- UnknownElement(const Boolean& boolean);
- UnknownElement(const String& string);
- UnknownElement(const Null& null);
-
- ~UnknownElement();
-
- UnknownElement& operator = (const UnknownElement& unknown);
-
- // implicit cast to actual element type. throws on failure
- operator const Object& () const;
- operator const Array& () const;
- operator const Number& () const;
- operator const Boolean& () const;
- operator const String& () const;
- operator const Null& () const;
-
- // implicit cast to actual element type. *converts* on failure, and always returns success
- operator Object& ();
- operator Array& ();
- operator Number& ();
- operator Boolean& ();
- operator String& ();
- operator Null& ();
-
- // provides quick access to children when real element type is object
- UnknownElement& operator[] (const std::string& key);
- const UnknownElement& operator[] (const std::string& key) const;
-
- // provides quick access to children when real element type is array
- UnknownElement& operator[] (size_t index);
- const UnknownElement& operator[] (size_t index) const;
-
- // implements visitor pattern
- void Accept(ConstVisitor& visitor) const;
- void Accept(Visitor& visitor);
-
- // tests equality. first checks type, then value if possible
- bool operator == (const UnknownElement& element) const;
-
-private:
- class Imp;
-
- template <typename ElementTypeT>
- class Imp_T;
-
- class CastVisitor;
- class ConstCastVisitor;
-
- template <typename ElementTypeT>
- class CastVisitor_T;
-
- template <typename ElementTypeT>
- class ConstCastVisitor_T;
-
- template <typename ElementTypeT>
- const ElementTypeT& CastTo() const;
-
- template <typename ElementTypeT>
- ElementTypeT& ConvertTo();
-
- Imp* m_pImp;
-};
-
-
-/////////////////////////////////////////////////////////////////////////////////
-// Array - mimics std::deque<UnknownElement>. The array contents are effectively
-// heterogeneous thanks to the ElementUnknown class. push_back has been replaced
-// by more generic insert functions.
-
-class Array
-{
-public:
- typedef std::deque<UnknownElement> Elements;
- typedef Elements::iterator iterator;
- typedef Elements::const_iterator const_iterator;
-
- iterator Begin();
- iterator End();
- const_iterator Begin() const;
- const_iterator End() const;
-
- iterator Insert(const UnknownElement& element, iterator itWhere);
- iterator Insert(const UnknownElement& element);
- iterator Erase(iterator itWhere);
- void Resize(size_t newSize);
- void Clear();
-
- size_t Size() const;
- bool Empty() const;
-
- UnknownElement& operator[] (size_t index);
- const UnknownElement& operator[] (size_t index) const;
-
- bool operator == (const Array& array) const;
-
-private:
- Elements m_Elements;
-};
-
-
-/////////////////////////////////////////////////////////////////////////////////
-// Object - mimics std::map<std::string, UnknownElement>. The member value
-// contents are effectively heterogeneous thanks to the UnknownElement class
-
-class Object
-{
-public:
- struct Member {
- Member(const std::string& nameIn = std::string(), const UnknownElement& elementIn = UnknownElement());
-
- bool operator == (const Member& member) const;
-
- std::string name;
- UnknownElement element;
- };
-
- typedef std::list<Member> Members; // map faster, but does not preserve order
- typedef Members::iterator iterator;
- typedef Members::const_iterator const_iterator;
-
- bool operator == (const Object& object) const;
-
- iterator Begin();
- iterator End();
- const_iterator Begin() const;
- const_iterator End() const;
-
- size_t Size() const;
- bool Empty() const;
-
- iterator Find(const std::string& name);
- const_iterator Find(const std::string& name) const;
-
- iterator Insert(const Member& member);
- iterator Insert(const Member& member, iterator itWhere);
- iterator Erase(iterator itWhere);
- void Clear();
-
- UnknownElement& operator [](const std::string& name);
- const UnknownElement& operator [](const std::string& name) const;
-
-private:
- class Finder;
-
- Members m_Members;
-};
-
-
-/////////////////////////////////////////////////////////////////////////////////
-// TrivialType_T - class template for encapsulates a simple data type, such as
-// a string, number, or boolean. Provides implicit const & noncost cast operators
-// for that type, allowing "DataTypeT type = trivialType;"
-
-
-template <typename DataTypeT>
-class TrivialType_T
-{
-public:
- TrivialType_T(const DataTypeT& t = DataTypeT());
-
- operator DataTypeT&();
- operator const DataTypeT&() const;
-
- DataTypeT& Value();
- const DataTypeT& Value() const;
-
- bool operator == (const TrivialType_T<DataTypeT>& trivial) const;
-
-private:
- DataTypeT m_tValue;
-};
-
-
-
-/////////////////////////////////////////////////////////////////////////////////
-// Null - doesn't do much of anything but satisfy the JSON spec. It is the default
-// element type of UnknownElement
-
-class Null
-{
-public:
- bool operator == (const Null& trivial) const;
-};
-
-
-} // End namespace
-
-
-#include "elements.inl"
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/elements.inl b/protocols/FacebookRM/src/JSON_CAJUN/elements.inl deleted file mode 100644 index 7febabc3a2..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/elements.inl +++ /dev/null @@ -1,412 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#include "visitor.h"
-#include "reader.h"
-#include <cassert>
-#include <algorithm>
-#include <map>
-
-/*
-
-TODO:
-* better documentation
-
-*/
-
-namespace json
-{
-
-
-inline Exception::Exception(const std::string& sMessage) :
- std::runtime_error(sMessage) {}
-
-
-/////////////////////////
-// UnknownElement members
-
-class UnknownElement::Imp
-{
-public:
- virtual ~Imp() {}
- virtual Imp* Clone() const = 0;
-
- virtual bool Compare(const Imp& imp) const = 0;
-
- virtual void Accept(ConstVisitor& visitor) const = 0;
- virtual void Accept(Visitor& visitor) = 0;
-};
-
-
-template <typename ElementTypeT>
-class UnknownElement::Imp_T : public UnknownElement::Imp
-{
-public:
- Imp_T(const ElementTypeT& element) : m_Element(element) {}
- virtual Imp* Clone() const { return new Imp_T<ElementTypeT>(*this); }
-
- virtual void Accept(ConstVisitor& visitor) const { visitor.Visit(m_Element); }
- virtual void Accept(Visitor& visitor) { visitor.Visit(m_Element); }
-
- virtual bool Compare(const Imp& imp) const
- {
- ConstCastVisitor_T<ElementTypeT> castVisitor;
- imp.Accept(castVisitor);
- return castVisitor.m_pElement &&
- m_Element == *castVisitor.m_pElement;
- }
-
-private:
- ElementTypeT m_Element;
-};
-
-
-class UnknownElement::ConstCastVisitor : public ConstVisitor
-{
- virtual void Visit(const Array& array) {}
- virtual void Visit(const Object& object) {}
- virtual void Visit(const Number& number) {}
- virtual void Visit(const String& string) {}
- virtual void Visit(const Boolean& boolean) {}
- virtual void Visit(const Null& null) {}
-};
-
-template <typename ElementTypeT>
-class UnknownElement::ConstCastVisitor_T : public ConstCastVisitor
-{
-public:
- ConstCastVisitor_T() : m_pElement(0) {}
- virtual void Visit(const ElementTypeT& element) { m_pElement = &element; } // we don't know what this is, but it overrides one of the base's no-op functions
- const ElementTypeT* m_pElement;
-};
-
-
-class UnknownElement::CastVisitor : public Visitor
-{
- virtual void Visit(Array& array) {}
- virtual void Visit(Object& object) {}
- virtual void Visit(Number& number) {}
- virtual void Visit(String& string) {}
- virtual void Visit(Boolean& boolean) {}
- virtual void Visit(Null& null) {}
-};
-
-template <typename ElementTypeT>
-class UnknownElement::CastVisitor_T : public CastVisitor
-{
-public:
- CastVisitor_T() : m_pElement(0) {}
- virtual void Visit(ElementTypeT& element) { m_pElement = &element; } // we don't know what this is, but it overrides one of the base's no-op functions
- ElementTypeT* m_pElement;
-};
-
-
-
-
-inline UnknownElement::UnknownElement() : m_pImp( new Imp_T<Null>( Null()) ) {}
-inline UnknownElement::UnknownElement(const UnknownElement& unknown) : m_pImp( unknown.m_pImp->Clone()) {}
-inline UnknownElement::UnknownElement(const Object& object) : m_pImp( new Imp_T<Object>(object)) {}
-inline UnknownElement::UnknownElement(const Array& array) : m_pImp( new Imp_T<Array>(array)) {}
-inline UnknownElement::UnknownElement(const Number& number) : m_pImp( new Imp_T<Number>(number)) {}
-inline UnknownElement::UnknownElement(const Boolean& boolean) : m_pImp( new Imp_T<Boolean>(boolean)) {}
-inline UnknownElement::UnknownElement(const String& string) : m_pImp( new Imp_T<String>(string)) {}
-inline UnknownElement::UnknownElement(const Null& null) : m_pImp( new Imp_T<Null>(null)) {}
-
-inline UnknownElement::~UnknownElement() { delete m_pImp; }
-
-inline UnknownElement::operator const Object& () const { return CastTo<Object>(); }
-inline UnknownElement::operator const Array& () const { return CastTo<Array>(); }
-inline UnknownElement::operator const Number& () const { return CastTo<Number>(); }
-inline UnknownElement::operator const Boolean& () const { return CastTo<Boolean>(); }
-inline UnknownElement::operator const String& () const { return CastTo<String>(); }
-inline UnknownElement::operator const Null& () const { return CastTo<Null>(); }
-
-inline UnknownElement::operator Object& () { return ConvertTo<Object>(); }
-inline UnknownElement::operator Array& () { return ConvertTo<Array>(); }
-inline UnknownElement::operator Number& () { return ConvertTo<Number>(); }
-inline UnknownElement::operator Boolean& () { return ConvertTo<Boolean>(); }
-inline UnknownElement::operator String& () { return ConvertTo<String>(); }
-inline UnknownElement::operator Null& () { return ConvertTo<Null>(); }
-
-inline UnknownElement& UnknownElement::operator = (const UnknownElement& unknown)
-{
- delete m_pImp;
- m_pImp = unknown.m_pImp->Clone();
- return *this;
-}
-
-inline UnknownElement& UnknownElement::operator[] (const std::string& key)
-{
- // the people want an object. make us one if we aren't already
- Object& object = ConvertTo<Object>();
- return object[key];
-}
-
-inline const UnknownElement& UnknownElement::operator[] (const std::string& key) const
-{
- // throws if we aren't an object
- const Object& object = CastTo<Object>();
- return object[key];
-}
-
-inline UnknownElement& UnknownElement::operator[] (size_t index)
-{
- // the people want an array. make us one if we aren't already
- Array& array = ConvertTo<Array>();
- return array[index];
-}
-
-inline const UnknownElement& UnknownElement::operator[] (size_t index) const
-{
- // throws if we aren't an array
- const Array& array = CastTo<Array>();
- return array[index];
-}
-
-
-template <typename ElementTypeT>
-const ElementTypeT& UnknownElement::CastTo() const
-{
- ConstCastVisitor_T<ElementTypeT> castVisitor;
- m_pImp->Accept(castVisitor);
- if (castVisitor.m_pElement == 0)
- throw Exception("Bad cast");
- return *castVisitor.m_pElement;
-}
-
-
-
-template <typename ElementTypeT>
-ElementTypeT& UnknownElement::ConvertTo()
-{
- CastVisitor_T<ElementTypeT> castVisitor;
- m_pImp->Accept(castVisitor);
- if (castVisitor.m_pElement == 0)
- {
- // we're not the right type. fix it & try again
- *this = ElementTypeT();
- m_pImp->Accept(castVisitor);
- }
-
- return *castVisitor.m_pElement;
-}
-
-
-inline void UnknownElement::Accept(ConstVisitor& visitor) const { m_pImp->Accept(visitor); }
-inline void UnknownElement::Accept(Visitor& visitor) { m_pImp->Accept(visitor); }
-
-
-inline bool UnknownElement::operator == (const UnknownElement& element) const
-{
- return m_pImp->Compare(*element.m_pImp);
-}
-
-
-
-//////////////////
-// Object members
-
-
-inline Object::Member::Member(const std::string& nameIn, const UnknownElement& elementIn) :
- name(nameIn), element(elementIn) {}
-
-inline bool Object::Member::operator == (const Member& member) const
-{
- return name == member.name &&
- element == member.element;
-}
-
-class Object::Finder : public std::unary_function<Object::Member, bool>
-{
-public:
- Finder(const std::string& name) : m_name(name) {}
- bool operator () (const Object::Member& member) {
- return member.name == m_name;
- }
-
-private:
- std::string m_name;
-};
-
-
-
-inline Object::iterator Object::Begin() { return m_Members.begin(); }
-inline Object::iterator Object::End() { return m_Members.end(); }
-inline Object::const_iterator Object::Begin() const { return m_Members.begin(); }
-inline Object::const_iterator Object::End() const { return m_Members.end(); }
-
-inline size_t Object::Size() const { return m_Members.size(); }
-inline bool Object::Empty() const { return m_Members.empty(); }
-
-inline Object::iterator Object::Find(const std::string& name)
-{
- return std::find_if(m_Members.begin(), m_Members.end(), Finder(name));
-}
-
-inline Object::const_iterator Object::Find(const std::string& name) const
-{
- return std::find_if(m_Members.begin(), m_Members.end(), Finder(name));
-}
-
-inline Object::iterator Object::Insert(const Member& member)
-{
- return Insert(member, End());
-}
-
-inline Object::iterator Object::Insert(const Member& member, iterator itWhere)
-{
- iterator it = Find(member.name);
- if (it != m_Members.end())
- throw Exception("Object member already exists: " + member.name);
-
- it = m_Members.insert(itWhere, member);
- return it;
-}
-
-inline Object::iterator Object::Erase(iterator itWhere)
-{
- return m_Members.erase(itWhere);
-}
-
-inline UnknownElement& Object::operator [](const std::string& name)
-{
-
- iterator it = Find(name);
- if (it == m_Members.end())
- {
- Member member(name);
- it = Insert(member, End());
- }
- return it->element;
-}
-
-inline const UnknownElement& Object::operator [](const std::string& name) const
-{
- const_iterator it = Find(name);
- if (it == End())
- throw Exception("Object member not found: " + name);
- return it->element;
-}
-
-inline void Object::Clear()
-{
- m_Members.clear();
-}
-
-inline bool Object::operator == (const Object& object) const
-{
- return m_Members == object.m_Members;
-}
-
-
-/////////////////
-// Array members
-
-inline Array::iterator Array::Begin() { return m_Elements.begin(); }
-inline Array::iterator Array::End() { return m_Elements.end(); }
-inline Array::const_iterator Array::Begin() const { return m_Elements.begin(); }
-inline Array::const_iterator Array::End() const { return m_Elements.end(); }
-
-inline Array::iterator Array::Insert(const UnknownElement& element, iterator itWhere)
-{
- return m_Elements.insert(itWhere, element);
-}
-
-inline Array::iterator Array::Insert(const UnknownElement& element)
-{
- return Insert(element, End());
-}
-
-inline Array::iterator Array::Erase(iterator itWhere)
-{
- return m_Elements.erase(itWhere);
-}
-
-inline void Array::Resize(size_t newSize)
-{
- m_Elements.resize(newSize);
-}
-
-inline size_t Array::Size() const { return m_Elements.size(); }
-inline bool Array::Empty() const { return m_Elements.empty(); }
-
-inline UnknownElement& Array::operator[] (size_t index)
-{
- size_t nMinSize = index + 1; // zero indexed
- if (m_Elements.size() < nMinSize)
- m_Elements.resize(nMinSize);
- return m_Elements[index];
-}
-
-inline const UnknownElement& Array::operator[] (size_t index) const
-{
- if (index >= m_Elements.size())
- throw Exception("Array out of bounds");
- return m_Elements[index];
-}
-
-inline void Array::Clear() {
- m_Elements.clear();
-}
-
-inline bool Array::operator == (const Array& array) const
-{
- return m_Elements == array.m_Elements;
-}
-
-
-////////////////////////
-// TrivialType_T members
-
-template <typename DataTypeT>
-TrivialType_T<DataTypeT>::TrivialType_T(const DataTypeT& t) :
- m_tValue(t) {}
-
-template <typename DataTypeT>
-TrivialType_T<DataTypeT>::operator DataTypeT&()
-{
- return Value();
-}
-
-template <typename DataTypeT>
-TrivialType_T<DataTypeT>::operator const DataTypeT&() const
-{
- return Value();
-}
-
-template <typename DataTypeT>
-DataTypeT& TrivialType_T<DataTypeT>::Value()
-{
- return m_tValue;
-}
-
-template <typename DataTypeT>
-const DataTypeT& TrivialType_T<DataTypeT>::Value() const
-{
- return m_tValue;
-}
-
-template <typename DataTypeT>
-bool TrivialType_T<DataTypeT>::operator == (const TrivialType_T<DataTypeT>& trivial) const
-{
- return m_tValue == trivial.m_tValue;
-}
-
-
-
-//////////////////
-// Null members
-
-inline bool Null::operator == (const Null& trivial) const
-{
- return true;
-}
-
-
-
-} // End namespace
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/reader.h b/protocols/FacebookRM/src/JSON_CAJUN/reader.h deleted file mode 100644 index 2f576c752e..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/reader.h +++ /dev/null @@ -1,125 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#pragma once
-
-#include "elements.h"
-#include <iostream>
-#include <vector>
-
-namespace json
-{
-
-class Reader
-{
-public:
- // this structure will be reported in one of the exceptions defined below
- struct Location
- {
- Location();
-
- unsigned int m_nLine; // document line, zero-indexed
- unsigned int m_nLineOffset; // character offset from beginning of line, zero indexed
- unsigned int m_nDocOffset; // character offset from entire document, zero indexed
- };
-
- // thrown during the first phase of reading. generally catches low-level problems such
- // as errant characters or corrupt/incomplete documents
- class ScanException : public Exception
- {
- public:
- ScanException(const std::string& sMessage, const Reader::Location& locError) :
- Exception(sMessage),
- m_locError(locError) {}
-
- Reader::Location m_locError;
- };
-
- // thrown during the second phase of reading. generally catches higher-level problems such
- // as missing commas or brackets
- class ParseException : public Exception
- {
- public:
- ParseException(const std::string& sMessage, const Reader::Location& locTokenBegin, const Reader::Location& locTokenEnd) :
- Exception(sMessage),
- m_locTokenBegin(locTokenBegin),
- m_locTokenEnd(locTokenEnd) {}
-
- Reader::Location m_locTokenBegin;
- Reader::Location m_locTokenEnd;
- };
-
-
- // if you know what the document looks like, call one of these...
- static void Read(Object& object, std::istream& istr);
- static void Read(Array& array, std::istream& istr);
- static void Read(String& string, std::istream& istr);
- static void Read(Number& number, std::istream& istr);
- static void Read(Boolean& boolean, std::istream& istr);
- static void Read(Null& null, std::istream& istr);
-
- // ...otherwise, if you don't know, call this & visit it
- static void Read(UnknownElement& elementRoot, std::istream& istr);
-
-private:
- struct Token
- {
- enum Type
- {
- TOKEN_OBJECT_BEGIN, // {
- TOKEN_OBJECT_END, // }
- TOKEN_ARRAY_BEGIN, // [
- TOKEN_ARRAY_END, // ]
- TOKEN_NEXT_ELEMENT, // ,
- TOKEN_MEMBER_ASSIGN, // :
- TOKEN_STRING, // "xxx"
- TOKEN_NUMBER, // [+/-]000.000[e[+/-]000]
- TOKEN_BOOLEAN, // true -or- false
- TOKEN_NULL // null
- };
-
- Type nType;
- std::string sValue;
-
- // for malformed file debugging
- Reader::Location locBegin;
- Reader::Location locEnd;
- };
-
- class InputStream;
- class TokenStream;
- typedef std::vector<Token> Tokens;
-
- template <typename ElementTypeT>
- static void Read_i(ElementTypeT& element, std::istream& istr);
-
- // scanning istream into token sequence
- void Scan(Tokens& tokens, InputStream& inputStream);
-
- void EatWhiteSpace(InputStream& inputStream);
- void MatchString(std::string& sValue, InputStream& inputStream);
- void MatchNumber(std::string& sNumber, InputStream& inputStream);
- void MatchExpectedString(const std::string& sExpected, InputStream& inputStream);
-
- // parsing token sequence into element structure
- void Parse(UnknownElement& element, TokenStream& tokenStream);
- void Parse(Object& object, TokenStream& tokenStream);
- void Parse(Array& array, TokenStream& tokenStream);
- void Parse(String& string, TokenStream& tokenStream);
- void Parse(Number& number, TokenStream& tokenStream);
- void Parse(Boolean& boolean, TokenStream& tokenStream);
- void Parse(Null& null, TokenStream& tokenStream);
-
- const std::string& MatchExpectedToken(Token::Type nExpected, TokenStream& tokenStream);
-};
-
-
-} // End namespace
-
-
-#include "reader.inl"
\ No newline at end of file diff --git a/protocols/FacebookRM/src/JSON_CAJUN/reader.inl b/protocols/FacebookRM/src/JSON_CAJUN/reader.inl deleted file mode 100644 index 26339497a0..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/reader.inl +++ /dev/null @@ -1,524 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#include <cassert>
-#include <set>
-#include <sstream>
-
-/*
-
-TODO:
-* better documentation
-* unicode character decoding
-
-*/
-
-namespace json
-{
-
-
- inline std::istream& operator >> (std::istream& istr, UnknownElement& elementRoot) {
- Reader::Read(elementRoot, istr);
- return istr;
-}
-
-inline Reader::Location::Location() :
- m_nLine(0),
- m_nLineOffset(0),
- m_nDocOffset(0)
-{}
-
-
-//////////////////////
-// Reader::InputStream
-
-class Reader::InputStream // would be cool if we could inherit from std::istream & override "get"
-{
-public:
- InputStream(std::istream& iStr) :
- m_iStr(iStr) {}
-
- // protect access to the input stream, so we can keeep track of document/line offsets
- char Get(); // big, define outside
- char Peek() {
- assert(m_iStr.eof() == false); // enforce reading of only valid stream data
- return m_iStr.peek();
- }
-
- bool EOS() {
- m_iStr.peek(); // apparently eof flag isn't set until a character read is attempted. whatever.
- return m_iStr.eof();
- }
-
- const Location& GetLocation() const { return m_Location; }
-
-private:
- std::istream& m_iStr;
- Location m_Location;
-};
-
-
-inline char Reader::InputStream::Get()
-{
- assert(m_iStr.eof() == false); // enforce reading of only valid stream data
- char c = m_iStr.get();
-
- ++m_Location.m_nDocOffset;
- if (c == '\n') {
- ++m_Location.m_nLine;
- m_Location.m_nLineOffset = 0;
- }
- else {
- ++m_Location.m_nLineOffset;
- }
-
- return c;
-}
-
-
-
-//////////////////////
-// Reader::TokenStream
-
-class Reader::TokenStream
-{
-public:
- TokenStream(const Tokens& tokens);
-
- const Token& Peek();
- const Token& Get();
-
- bool EOS() const;
-
-private:
- const Tokens& m_Tokens;
- Tokens::const_iterator m_itCurrent;
-};
-
-
-inline Reader::TokenStream::TokenStream(const Tokens& tokens) :
- m_Tokens(tokens),
- m_itCurrent(tokens.begin())
-{}
-
-inline const Reader::Token& Reader::TokenStream::Peek() {
- assert(m_itCurrent != m_Tokens.end());
- return *(m_itCurrent);
-}
-
-inline const Reader::Token& Reader::TokenStream::Get() {
- assert(m_itCurrent != m_Tokens.end());
- return *(m_itCurrent++);
-}
-
-inline bool Reader::TokenStream::EOS() const {
- return m_itCurrent == m_Tokens.end();
-}
-
-///////////////////
-// Reader (finally)
-
-
-inline void Reader::Read(Object& object, std::istream& istr) { Read_i(object, istr); }
-inline void Reader::Read(Array& array, std::istream& istr) { Read_i(array, istr); }
-inline void Reader::Read(String& string, std::istream& istr) { Read_i(string, istr); }
-inline void Reader::Read(Number& number, std::istream& istr) { Read_i(number, istr); }
-inline void Reader::Read(Boolean& boolean, std::istream& istr) { Read_i(boolean, istr); }
-inline void Reader::Read(Null& null, std::istream& istr) { Read_i(null, istr); }
-inline void Reader::Read(UnknownElement& unknown, std::istream& istr) { Read_i(unknown, istr); }
-
-
-template <typename ElementTypeT>
-void Reader::Read_i(ElementTypeT& element, std::istream& istr)
-{
- Reader reader;
-
- Tokens tokens;
- InputStream inputStream(istr);
- reader.Scan(tokens, inputStream);
-
- TokenStream tokenStream(tokens);
- reader.Parse(element, tokenStream);
-
- if (tokenStream.EOS() == false)
- {
- const Token& token = tokenStream.Peek();
- std::string sMessage = "Expected End of token stream; found " + token.sValue;
- throw ParseException(sMessage, token.locBegin, token.locEnd);
- }
-}
-
-
-inline void Reader::Scan(Tokens& tokens, InputStream& inputStream)
-{
- while (EatWhiteSpace(inputStream), // ignore any leading white space...
- inputStream.EOS() == false) // ...before checking for EOS
- {
- // if all goes well, we'll create a token each pass
- Token token;
- token.locBegin = inputStream.GetLocation();
-
- // gives us null-terminated string
- std::string sChar;
- sChar.push_back(inputStream.Peek());
-
- switch (sChar[0])
- {
- case '{':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_OBJECT_BEGIN;
- break;
-
- case '}':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_OBJECT_END;
- break;
-
- case '[':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_ARRAY_BEGIN;
- break;
-
- case ']':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_ARRAY_END;
- break;
-
- case ',':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_NEXT_ELEMENT;
- break;
-
- case ':':
- token.sValue = sChar[0];
- MatchExpectedString(sChar, inputStream);
- token.nType = Token::TOKEN_MEMBER_ASSIGN;
- break;
-
- case '"':
- MatchString(token.sValue, inputStream);
- token.nType = Token::TOKEN_STRING;
- break;
-
- case '-':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- MatchNumber(token.sValue, inputStream);
- token.nType = Token::TOKEN_NUMBER;
- break;
-
- case 't':
- token.sValue = "true";
- MatchExpectedString(token.sValue, inputStream);
- token.nType = Token::TOKEN_BOOLEAN;
- break;
-
- case 'f':
- token.sValue = "false";
- MatchExpectedString(token.sValue, inputStream);
- token.nType = Token::TOKEN_BOOLEAN;
- break;
-
- case 'n':
- token.sValue = "null";
- MatchExpectedString(token.sValue, inputStream);
- token.nType = Token::TOKEN_NULL;
- break;
-
- default: {
- std::string sErrorMessage = "Unexpected character in stream: " + sChar;
- throw ScanException(sErrorMessage, inputStream.GetLocation());
- }
- }
-
- token.locEnd = inputStream.GetLocation();
- tokens.push_back(token);
- }
-}
-
-
-inline void Reader::EatWhiteSpace(InputStream& inputStream)
-{
- while (inputStream.EOS() == false &&
- ::isspace(inputStream.Peek()))
- inputStream.Get();
-}
-
-inline void Reader::MatchExpectedString(const std::string& sExpected, InputStream& inputStream)
-{
- std::string::const_iterator it(sExpected.begin()),
- itEnd(sExpected.end());
- for ( ; it != itEnd; ++it) {
- if (inputStream.EOS() || // did we reach the end before finding what we're looking for...
- inputStream.Get() != *it) // ...or did we find something different?
- {
- std::string sMessage = "Expected string: " + sExpected;
- throw ScanException(sMessage, inputStream.GetLocation());
- }
- }
-
- // all's well if we made it here, return quietly
-}
-
-
-inline void Reader::MatchString(std::string& string, InputStream& inputStream)
-{
- MatchExpectedString("\"", inputStream);
-
- while (inputStream.EOS() == false &&
- inputStream.Peek() != '"')
- {
- char c = inputStream.Get();
-
- // escape?
- if (c == '\\' &&
- inputStream.EOS() == false) // shouldn't have reached the end yet
- {
- c = inputStream.Get();
- switch (c) {
- case '/': string.push_back('/'); break;
- case '"': string.push_back('"'); break;
- case '\\': string.push_back('\\'); break;
- case 'b': string.push_back('\b'); break;
- case 'f': string.push_back('\f'); break;
- case 'n': string.push_back('\n'); break;
- case 'r': string.push_back('\r'); break;
- case 't': string.push_back('\t'); break;
-//
-// misacek: Modification due to need
-//
-// case 'u': // TODO: what do we do with this?
- case 'u': string.append("\\u"); break;
-//
- default: {
- std::string sMessage = "Unrecognized escape sequence found in string: \\" + c;
- throw ScanException(sMessage, inputStream.GetLocation());
- }
- }
- }
- else {
- string.push_back(c);
- }
- }
-
- // eat the last '"' that we just peeked
- MatchExpectedString("\"", inputStream);
-}
-
-
-inline void Reader::MatchNumber(std::string& sNumber, InputStream& inputStream)
-{
- const char sNumericChars[] = "0123456789.eE-+";
- std::set<char> numericChars;
- numericChars.insert(sNumericChars, sNumericChars + sizeof(sNumericChars));
-
- while (inputStream.EOS() == false &&
- numericChars.find(inputStream.Peek()) != numericChars.end())
- {
- sNumber.push_back(inputStream.Get());
- }
-}
-
-
-inline void Reader::Parse(UnknownElement& element, Reader::TokenStream& tokenStream)
-{
- if (tokenStream.EOS()) {
- std::string sMessage = "Unexpected end of token stream";
- throw ParseException(sMessage, Location(), Location()); // nowhere to point to
- }
-
- const Token& token = tokenStream.Peek();
- switch (token.nType) {
- case Token::TOKEN_OBJECT_BEGIN:
- {
- // implicit non-const cast will perform conversion for us (if necessary)
- Object& object = element;
- Parse(object, tokenStream);
- break;
- }
-
- case Token::TOKEN_ARRAY_BEGIN:
- {
- Array& array = element;
- Parse(array, tokenStream);
- break;
- }
-
- case Token::TOKEN_STRING:
- {
- String& string = element;
- Parse(string, tokenStream);
- break;
- }
-
- case Token::TOKEN_NUMBER:
- {
- Number& number = element;
- Parse(number, tokenStream);
- break;
- }
-
- case Token::TOKEN_BOOLEAN:
- {
- Boolean& boolean = element;
- Parse(boolean, tokenStream);
- break;
- }
-
- case Token::TOKEN_NULL:
- {
- Null& null = element;
- Parse(null, tokenStream);
- break;
- }
-
- default:
- {
- std::string sMessage = "Unexpected token: " + token.sValue;
- throw ParseException(sMessage, token.locBegin, token.locEnd);
- }
- }
-}
-
-
-inline void Reader::Parse(Object& object, Reader::TokenStream& tokenStream)
-{
- MatchExpectedToken(Token::TOKEN_OBJECT_BEGIN, tokenStream);
-
- bool bContinue = (tokenStream.EOS() == false &&
- tokenStream.Peek().nType != Token::TOKEN_OBJECT_END);
- while (bContinue)
- {
- Object::Member member;
-
- // first the member name. save the token in case we have to throw an exception
- const Token& tokenName = tokenStream.Peek();
- member.name = MatchExpectedToken(Token::TOKEN_STRING, tokenStream);
-
- // ...then the key/value separator...
- MatchExpectedToken(Token::TOKEN_MEMBER_ASSIGN, tokenStream);
-
- // ...then the value itself (can be anything).
- Parse(member.element, tokenStream);
-
- // try adding it to the object (this could throw)
- try
- {
- object.Insert(member);
- }
- catch (Exception&)
- {
- // must be a duplicate name
- std::string sMessage = "Duplicate object member token: " + member.name;
- throw ParseException(sMessage, tokenName.locBegin, tokenName.locEnd);
- }
-
- bContinue = (tokenStream.EOS() == false &&
- tokenStream.Peek().nType == Token::TOKEN_NEXT_ELEMENT);
- if (bContinue)
- MatchExpectedToken(Token::TOKEN_NEXT_ELEMENT, tokenStream);
- }
-
- MatchExpectedToken(Token::TOKEN_OBJECT_END, tokenStream);
-}
-
-
-inline void Reader::Parse(Array& array, Reader::TokenStream& tokenStream)
-{
- MatchExpectedToken(Token::TOKEN_ARRAY_BEGIN, tokenStream);
-
- bool bContinue = (tokenStream.EOS() == false &&
- tokenStream.Peek().nType != Token::TOKEN_ARRAY_END);
- while (bContinue)
- {
- // ...what's next? could be anything
- Array::iterator itElement = array.Insert(UnknownElement());
- UnknownElement& element = *itElement;
- Parse(element, tokenStream);
-
- bContinue = (tokenStream.EOS() == false &&
- tokenStream.Peek().nType == Token::TOKEN_NEXT_ELEMENT);
- if (bContinue)
- MatchExpectedToken(Token::TOKEN_NEXT_ELEMENT, tokenStream);
- }
-
- MatchExpectedToken(Token::TOKEN_ARRAY_END, tokenStream);
-}
-
-
-inline void Reader::Parse(String& string, Reader::TokenStream& tokenStream)
-{
- string = MatchExpectedToken(Token::TOKEN_STRING, tokenStream);
-}
-
-
-inline void Reader::Parse(Number& number, Reader::TokenStream& tokenStream)
-{
- const Token& currentToken = tokenStream.Peek(); // might need this later for throwing exception
- const std::string& sValue = MatchExpectedToken(Token::TOKEN_NUMBER, tokenStream);
-
- std::istringstream iStr(sValue);
- double dValue;
- iStr >> dValue;
-
- // did we consume all characters in the token?
- if (iStr.eof() == false)
- {
- std::string sMessage = "Unexpected character in NUMBER token: " + iStr.peek();
- throw ParseException(sMessage, currentToken.locBegin, currentToken.locEnd);
- }
-
- number = dValue;
-}
-
-
-inline void Reader::Parse(Boolean& boolean, Reader::TokenStream& tokenStream)
-{
- const std::string& sValue = MatchExpectedToken(Token::TOKEN_BOOLEAN, tokenStream);
- boolean = (sValue == "true" ? true : false);
-}
-
-
-inline void Reader::Parse(Null&, Reader::TokenStream& tokenStream)
-{
- MatchExpectedToken(Token::TOKEN_NULL, tokenStream);
-}
-
-
-inline const std::string& Reader::MatchExpectedToken(Token::Type nExpected, Reader::TokenStream& tokenStream)
-{
- if (tokenStream.EOS())
- {
- std::string sMessage = "Unexpected End of token stream";
- throw ParseException(sMessage, Location(), Location()); // nowhere to point to
- }
-
- const Token& token = tokenStream.Get();
- if (token.nType != nExpected)
- {
- std::string sMessage = "Unexpected token: " + token.sValue;
- throw ParseException(sMessage, token.locBegin, token.locEnd);
- }
-
- return token.sValue;
-}
-
-} // End namespace
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/visitor.h b/protocols/FacebookRM/src/JSON_CAJUN/visitor.h deleted file mode 100644 index 8a28d7a64a..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/visitor.h +++ /dev/null @@ -1,44 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#pragma once
-
-#include "elements.h"
-
-namespace json
-{
-
-
-class Visitor
-{
-public:
- virtual ~Visitor() {}
-
- virtual void Visit(Array& array) = 0;
- virtual void Visit(Object& object) = 0;
- virtual void Visit(Number& number) = 0;
- virtual void Visit(String& string) = 0;
- virtual void Visit(Boolean& boolean) = 0;
- virtual void Visit(Null& null) = 0;
-};
-
-class ConstVisitor
-{
-public:
- virtual ~ConstVisitor() {}
-
- virtual void Visit(const Array& array) = 0;
- virtual void Visit(const Object& object) = 0;
- virtual void Visit(const Number& number) = 0;
- virtual void Visit(const String& string) = 0;
- virtual void Visit(const Boolean& boolean) = 0;
- virtual void Visit(const Null& null) = 0;
-};
-
-
-} // End namespace
diff --git a/protocols/FacebookRM/src/JSON_CAJUN/writer.h b/protocols/FacebookRM/src/JSON_CAJUN/writer.h deleted file mode 100644 index c364bcb289..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/writer.h +++ /dev/null @@ -1,57 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#pragma once
-
-#include "elements.h"
-#include "visitor.h"
-
-namespace json
-{
-
-class Writer : private ConstVisitor
-{
-public:
- static void Write(const Object& object, std::ostream& ostr);
- static void Write(const Array& array, std::ostream& ostr);
- static void Write(const String& string, std::ostream& ostr);
- static void Write(const Number& number, std::ostream& ostr);
- static void Write(const Boolean& boolean, std::ostream& ostr);
- static void Write(const Null& null, std::ostream& ostr);
- static void Write(const UnknownElement& elementRoot, std::ostream& ostr);
-
-private:
- Writer(std::ostream& ostr);
-
- template <typename ElementTypeT>
- static void Write_i(const ElementTypeT& element, std::ostream& ostr);
-
- void Write_i(const Object& object);
- void Write_i(const Array& array);
- void Write_i(const String& string);
- void Write_i(const Number& number);
- void Write_i(const Boolean& boolean);
- void Write_i(const Null& null);
- void Write_i(const UnknownElement& unknown);
-
- virtual void Visit(const Array& array);
- virtual void Visit(const Object& object);
- virtual void Visit(const Number& number);
- virtual void Visit(const String& string);
- virtual void Visit(const Boolean& boolean);
- virtual void Visit(const Null& null);
-
- std::ostream& m_ostr;
- int m_nTabDepth;
-};
-
-
-} // End namespace
-
-
-#include "writer.inl"
\ No newline at end of file diff --git a/protocols/FacebookRM/src/JSON_CAJUN/writer.inl b/protocols/FacebookRM/src/JSON_CAJUN/writer.inl deleted file mode 100644 index eeb3db94b9..0000000000 --- a/protocols/FacebookRM/src/JSON_CAJUN/writer.inl +++ /dev/null @@ -1,153 +0,0 @@ -/**********************************************
-
-License: BSD
-Project Webpage: http://cajun-jsonapi.sourceforge.net/
-Author: Terry Caton
-
-***********************************************/
-
-#include "writer.h"
-#include <iostream>
-#include <iomanip>
-
-/*
-
-TODO:
-* better documentation
-* unicode character encoding
-
-*/
-
-namespace json
-{
-
-
-inline void Writer::Write(const UnknownElement& elementRoot, std::ostream& ostr) { Write_i(elementRoot, ostr); }
-inline void Writer::Write(const Object& object, std::ostream& ostr) { Write_i(object, ostr); }
-inline void Writer::Write(const Array& array, std::ostream& ostr) { Write_i(array, ostr); }
-inline void Writer::Write(const Number& number, std::ostream& ostr) { Write_i(number, ostr); }
-inline void Writer::Write(const String& string, std::ostream& ostr) { Write_i(string, ostr); }
-inline void Writer::Write(const Boolean& boolean, std::ostream& ostr) { Write_i(boolean, ostr); }
-inline void Writer::Write(const Null& null, std::ostream& ostr) { Write_i(null, ostr); }
-
-
-inline Writer::Writer(std::ostream& ostr) :
- m_ostr(ostr),
- m_nTabDepth(0)
-{}
-
-template <typename ElementTypeT>
-void Writer::Write_i(const ElementTypeT& element, std::ostream& ostr)
-{
- Writer writer(ostr);
- writer.Write_i(element);
- ostr.flush(); // all done
-}
-
-inline void Writer::Write_i(const Array& array)
-{
- if (array.Empty())
- m_ostr << "[]";
- else
- {
- m_ostr << '[' << std::endl;
- ++m_nTabDepth;
-
- Array::const_iterator it(array.Begin()),
- itEnd(array.End());
- while (it != itEnd) {
- m_ostr << std::string(m_nTabDepth, '\t');
-
- Write_i(*it);
-
- if (++it != itEnd)
- m_ostr << ',';
- m_ostr << std::endl;
- }
-
- --m_nTabDepth;
- m_ostr << std::string(m_nTabDepth, '\t') << ']';
- }
-}
-
-inline void Writer::Write_i(const Object& object)
-{
- if (object.Empty())
- m_ostr << "{}";
- else
- {
- m_ostr << '{' << std::endl;
- ++m_nTabDepth;
-
- Object::const_iterator it(object.Begin()),
- itEnd(object.End());
- while (it != itEnd) {
- m_ostr << std::string(m_nTabDepth, '\t') << '"' << it->name << "\" : ";
- Write_i(it->element);
-
- if (++it != itEnd)
- m_ostr << ',';
- m_ostr << std::endl;
- }
-
- --m_nTabDepth;
- m_ostr << std::string(m_nTabDepth, '\t') << '}';
- }
-}
-
-inline void Writer::Write_i(const Number& numberElement)
-{
- m_ostr << std::setprecision(20) << numberElement.Value();
-}
-
-inline void Writer::Write_i(const Boolean& booleanElement)
-{
- m_ostr << (booleanElement.Value() ? "true" : "false");
-}
-
-inline void Writer::Write_i(const String& stringElement)
-{
- m_ostr << '"';
-
- const std::string& s = stringElement.Value();
- std::string::const_iterator it(s.begin()),
- itEnd(s.end());
- for (; it != itEnd; ++it)
- {
- switch (*it)
- {
- case '"': m_ostr << "\\\""; break;
- case '\\': m_ostr << "\\\\"; break;
- case '\b': m_ostr << "\\b"; break;
- case '\f': m_ostr << "\\f"; break;
- case '\n': m_ostr << "\\n"; break;
- case '\r': m_ostr << "\\r"; break;
- case '\t': m_ostr << "\\t"; break;
- //case '\u': m_ostr << ""; break; ??
- default: m_ostr << *it; break;
- }
- }
-
- m_ostr << '"';
-}
-
-inline void Writer::Write_i(const Null& )
-{
- m_ostr << "null";
-}
-
-inline void Writer::Write_i(const UnknownElement& unknown)
-{
- unknown.Accept(*this);
-}
-
-inline void Writer::Visit(const Array& array) { Write_i(array); }
-inline void Writer::Visit(const Object& object) { Write_i(object); }
-inline void Writer::Visit(const Number& number) { Write_i(number); }
-inline void Writer::Visit(const String& string) { Write_i(string); }
-inline void Writer::Visit(const Boolean& boolean) { Write_i(boolean); }
-inline void Writer::Visit(const Null& null) { Write_i(null); }
-
-
-
-} // End namespace
diff --git a/protocols/FacebookRM/src/common.h b/protocols/FacebookRM/src/common.h index e3074eb5c5..7bf92430af 100644 --- a/protocols/FacebookRM/src/common.h +++ b/protocols/FacebookRM/src/common.h @@ -56,10 +56,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_skin.h>
#include <m_icolib.h>
#include <m_hotkeys.h>
-
#include <m_folders.h>
#include <m_smileyadd.h>
#include <m_toptoolbar.h>
+#include <m_json.h>
class FacebookProto;
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 32909c95b4..d6b7bfb8cd 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -21,197 +21,157 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "common.h"
-#include "JSON_CAJUN/reader.h"
-#include "JSON_CAJUN/writer.h"
-#include "JSON_CAJUN/elements.h"
int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user >* buddy_list)
{
- using namespace json;
-
- try
- {
- facebook_user* current = NULL;
- std::string buddyData = static_cast< std::string* >(data)->substr(9);
- std::istringstream sDocument(buddyData);
- Object objDocument;
- Reader::Read(objDocument, sDocument);
-
- const Object& objRoot = objDocument;
-/* const Array& wasAvailableIDs = objRoot["payload"]["buddy_list"]["wasAvailableIDs"];
-
- for (Array::const_iterator itWasAvailable(wasAvailableIDs.Begin());
- itWasAvailable != wasAvailableIDs.End(); ++itWasAvailable)
- {
- const Number& member = *itWasAvailable;
- char was_id[32];
- lltoa(member.Value(), was_id, 10);
-
- current = buddy_list->find(std::string(was_id));
- if (current != NULL)
- current->status_id = ID_STATUS_OFFLINE;
- }*/ // Facebook removed support for "wasAvailableIDs"
+ facebook_user* current = NULL;
+ std::string jsonData = static_cast< std::string* >(data)->substr(9);
- // Set all contacts in map to offline
- for (List::Item< facebook_user >* i = buddy_list->begin(); i != NULL; i = i->next) {
- i->data->status_id = ID_STATUS_OFFLINE;
- }
+ JSONNODE *root = json_parse(jsonData.c_str());
+ if (root == NULL)
+ return EXIT_FAILURE;
- // Load last active times
- const Object& lastActive = objRoot["payload"]["buddy_list"]["last_active_times"];
- for (Object::const_iterator itLastActive(lastActive.Begin()); itLastActive != lastActive.End(); ++itLastActive)
- {
- const Object::Member& member = *itLastActive;
+ JSONNODE *payload = json_get(root, "payload");
+ if (payload == NULL)
+ return EXIT_FAILURE;
- current = buddy_list->find(member.name);
+ JSONNODE *list = json_get(payload, "buddy_list");
+ if (list == NULL)
+ return EXIT_FAILURE;
+
+ // Set all contacts in map to offline
+ for (List::Item< facebook_user >* i = buddy_list->begin(); i != NULL; i = i->next) {
+ i->data->status_id = ID_STATUS_OFFLINE;
+ }
+
+ // Load last active times
+ JSONNODE *lastActive = json_get(list, "last_active_times");
+ if (lastActive != NULL) {
+ for (unsigned int i = 0; i < json_size(lastActive); i++) {
+ JSONNODE *it = json_at(lastActive, i);
+ char *id = json_name(it);
+
+ current = buddy_list->find(id);
if (current == NULL) {
- buddy_list->insert(std::make_pair(member.name, new facebook_user()));
- current = buddy_list->find(member.name);
- current->user_id = member.name;
+ buddy_list->insert(std::make_pair(id, new facebook_user()));
+ current = buddy_list->find(id);
+ current->user_id = id;
}
- const Number& timestamp = member.element;
- current->last_active = timestamp.Value();
+ current->last_active = json_as_int(it);
}
-
- // Find mobile friends
- const Array& mobileFriends = objRoot["payload"]["buddy_list"]["mobile_friends"];
- for (Array::const_iterator buddy(mobileFriends.Begin()); buddy != mobileFriends.End(); ++buddy) {
- const Number& member = *buddy;
- char was_id[32];
- lltoa(member.Value(), was_id, 10);
-
- std::string id = was_id;
- if (!id.empty()) {
+ }
+
+ // Find mobile friends
+ JSONNODE *mobileFriends = json_get(list, "mobile_friends");
+ if (mobileFriends != NULL) {
+ for (unsigned int i = 0; i < json_size(mobileFriends); i++) {
+ JSONNODE *it = json_at(mobileFriends, i);
+ char *id = json_name(it);
+
+ current = buddy_list->find(id);
+ if (current == NULL) {
+ buddy_list->insert(std::make_pair(id, new facebook_user()));
current = buddy_list->find(id);
-
- if (current == NULL) {
- buddy_list->insert(std::make_pair(id, new facebook_user()));
- current = buddy_list->find(id);
- current->user_id = id;
- }
-
- current->status_id = ID_STATUS_ONTHEPHONE;
+ current->user_id = id;
}
- }
- // Find now awailable contacts
- const Object& nowAvailableList = objRoot["payload"]["buddy_list"]["nowAvailableList"];
- for (Object::const_iterator itAvailable(nowAvailableList.Begin());
- itAvailable != nowAvailableList.End(); ++itAvailable)
- {
- const Object::Member& member = *itAvailable;
- const Object& objMember = member.element;
- const Boolean idle = objMember["i"]; // In new version of Facebook "i" means "offline"
+ current->status_id = ID_STATUS_ONTHEPHONE;
+ }
+ }
- current = buddy_list->find(member.name);
+ // Find now awailable contacts
+ JSONNODE *nowAvailable = json_get(list, "nowAvailableList");
+ if (nowAvailable != NULL) {
+ for (unsigned int i = 0; i < json_size(nowAvailable); i++) {
+ JSONNODE *it = json_at(nowAvailable, i);
+ char *id = json_name(it);
+
+ current = buddy_list->find(id);
if (current == NULL) {
- if (idle) continue; // Just little optimalization
-
- buddy_list->insert(std::make_pair(member.name, new facebook_user()));
- current = buddy_list->find(member.name);
- current->user_id = current->real_name = member.name;
+ buddy_list->insert(std::make_pair(id, new facebook_user()));
+ current = buddy_list->find(id);
+ current->user_id = id;
}
- current->status_id = (idle ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE);
+ current->status_id = ID_STATUS_ONLINE;
+
+ // In new version of Facebook "i" means "offline"
+ JSONNODE *idle = json_get(it, "i");
+ if (idle != NULL && json_as_bool(idle))
+ current->status_id = ID_STATUS_OFFLINE;
}
+ }
- // Get aditional informations about contacts (if available)
- const Object& userInfosList = objRoot["payload"]["buddy_list"]["userInfos"];
- for (Object::const_iterator itUserInfo(userInfosList.Begin());
- itUserInfo != userInfosList.End(); ++itUserInfo)
- {
- const Object::Member& member = *itUserInfo;
-
- current = buddy_list->find(member.name);
+ // Get aditional informations about contacts (if available)
+ JSONNODE *userInfos = json_get(list, "userInfos");
+ if (userInfos != NULL) {
+ for (unsigned int i = 0; i < json_size(userInfos); i++) {
+ JSONNODE *it = json_at(userInfos, i);
+ char *id = json_name(it);
+
+ current = buddy_list->find(id);
if (current == NULL)
continue;
- const Object& objMember = member.element;
- const String& realName = objMember["name"];
- const String& imageUrl = objMember["thumbSrc"];
+ JSONNODE *name = json_get(it, "name");
+ JSONNODE *thumbSrc = json_get(it, "thumbSrc");
- current->real_name = utils::text::slashu_to_utf8(
- utils::text::special_expressions_decode(realName.Value()));
- current->image_url = utils::text::slashu_to_utf8(
- utils::text::special_expressions_decode(imageUrl.Value()));
+ if (name != NULL)
+ current->real_name = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_string(name)));
+ if (thumbSrc != NULL)
+ current->image_url = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_string(thumbSrc)));
}
-
- }
- catch (Reader::ParseException& e)
- {
- proto->Log("!!!!! Caught json::ParseException: %s", e.what());
- proto->Log(" Line/offset: %d/%d", e.m_locTokenBegin.m_nLine + 1, e.m_locTokenBegin.m_nLineOffset + 1);
- }
- catch (const Exception& e)
- {
- proto->Log("!!!!! Caught json::Exception: %s", e.what());
- }
- catch (const std::exception& e)
- {
- proto->Log("!!!!! Caught std::exception: %s", e.what());
}
+ json_delete(root);
+
return EXIT_SUCCESS;
}
int facebook_json_parser::parse_friends(void* data, std::map< std::string, facebook_user* >* friends)
{
- using namespace json;
-
- try
- {
- std::string buddyData = static_cast< std::string* >(data)->substr(9);
- std::istringstream sDocument(buddyData);
- Object objDocument;
- Reader::Read(objDocument, sDocument);
-
- const Object& objRoot = objDocument;
- const Object& payload = objRoot["payload"];
-
- for (Object::const_iterator payload_item(payload.Begin()); payload_item != payload.End(); ++payload_item)
- {
- const Object::Member& member = *payload_item;
-
- const Object& objMember = member.element;
-
- const String& realName = objMember["name"];
- const String& imageUrl = objMember["thumbSrc"];
- //const String& vanity = objMember["vanity"];
- //const String& uri = objMember["uri"];
- const Number& gender = objMember["gender"];
- //const Boolean& isFriend = objMember["is_friend"];
- //const String& type = objMember["type"]; // "friend" = existing classic contact, "user" = contact with disabled/deleted account
-
- facebook_user *fbu = new facebook_user();
-
- fbu->user_id = member.name;
- fbu->real_name = utils::text::slashu_to_utf8(
- utils::text::special_expressions_decode(realName.Value()));
- fbu->image_url = utils::text::slashu_to_utf8(
- utils::text::special_expressions_decode(imageUrl.Value()));
-
- if (gender.Value() == 1) {
- fbu->gender = 70; // female
- } else if (gender.Value() == 2) {
- fbu->gender = 77; // male
+ std::string jsonData = static_cast< std::string* >(data)->substr(9);
+
+ JSONNODE *root = json_parse(jsonData.c_str());
+ if (root == NULL)
+ return EXIT_FAILURE;
+
+ JSONNODE *payload = json_get(root, "payload");
+ if (payload == NULL)
+ return EXIT_FAILURE;
+
+ for (unsigned int i = 0; i < json_size(payload); i++) {
+ JSONNODE *it = json_at(payload, i);
+ char *id = json_name(it);
+
+ JSONNODE *name = json_get(it, "name");
+ JSONNODE *thumbSrc = json_get(it, "thumbSrc");
+ JSONNODE *gender = json_get(it, "gender");
+ //JSONNODE *vanity = json_get(it, "vanity"); // username
+ //JSONNODE *uri = json_get(it, "uri"); // profile url
+ //JSONNODE *is_friend = json_get(it, "is_friend"); // e.g. "True"
+ //JSONNODE *type = json_get(it, "type"); // e.g. "friend" (classic contact) or "user" (disabled/deleted account)
+
+ facebook_user *fbu = new facebook_user();
+
+ fbu->user_id = id;
+ if (name)
+ fbu->real_name = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_string(name)));
+ if (thumbSrc)
+ fbu->image_url = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_string(thumbSrc)));
+
+ if (gender)
+ switch (json_as_int(gender)) {
+ case 1: // female
+ fbu->gender = 70;
+ break;
+ case 2: // male
+ fbu-> gender = 77;
+ break;
}
- friends->insert(std::make_pair(member.name, fbu));
- }
- }
- catch (Reader::ParseException& e)
- {
- proto->Log("!!!!! Caught json::ParseException: %s", e.what());
- proto->Log(" Line/offset: %d/%d", e.m_locTokenBegin.m_nLine + 1, e.m_locTokenBegin.m_nLineOffset + 1);
- }
- catch (const Exception& e)
- {
- proto->Log("!!!!! Caught json::Exception: %s", e.what());
- }
- catch (const std::exception& e)
- {
- proto->Log("!!!!! Caught std::exception: %s", e.what());
+ friends->insert(std::make_pair(id, fbu));
}
return EXIT_SUCCESS;
@@ -220,54 +180,41 @@ int facebook_json_parser::parse_friends(void* data, std::map< std::string, faceb int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_notification* > *notifications)
{
- using namespace json;
+ std::string jsonData = static_cast< std::string* >(data)->substr(9);
+
+ JSONNODE *root = json_parse(jsonData.c_str());
+ if (root == NULL)
+ return EXIT_FAILURE;
- try
- {
- std::string notificationsData = static_cast< std::string* >(data)->substr(9);
- std::istringstream sDocument(notificationsData);
- Object objDocument;
- Reader::Read(objDocument, sDocument);
+ JSONNODE *payload = json_get(root, "payload");
+ if (payload == NULL)
+ return EXIT_FAILURE;
- const Object& objRoot = objDocument;
- const Object& payload = objRoot["payload"]["notifications"];
+ JSONNODE *list = json_get(payload, "notifications");
+ if (list == NULL)
+ return EXIT_FAILURE;
- for (Object::const_iterator payload_item(payload.Begin()); payload_item != payload.End(); ++payload_item)
- {
- const Object::Member& member = *payload_item;
-
- const Object& objMember = member.element;
- const String& content = objMember["markup"];
- const Number& unread = objMember["unread"];
-
- if (unread.Value() == 0) // ignore old notifications
- continue;
-
- std::string text = utils::text::slashu_to_utf8(
- utils::text::special_expressions_decode(content.Value()));
+ for (unsigned int i = 0; i < json_size(list); i++) {
+ JSONNODE *it = json_at(list, i);
+ char *id = json_name(it);
- facebook_notification* notification = new facebook_notification();
-
- notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
- notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
- notification->id = member.name;
+ JSONNODE *markup = json_get(it, "markup");
+ JSONNODE *unread = json_get(it, "unread");
+ //JSONNODE *time = json_get(it, "time");
- notifications->push_back(notification);
- }
+ // Ignore empty and old notifications
+ if (markup == NULL || unread == NULL || json_as_int(unread) == 0)
+ continue;
- }
- catch (Reader::ParseException& e)
- {
- proto->Log("!!!!! Caught json::ParseException: %s", e.what());
- proto->Log(" Line/offset: %d/%d", e.m_locTokenBegin.m_nLine + 1, e.m_locTokenBegin.m_nLineOffset + 1);
- }
- catch (const Exception& e)
- {
- proto->Log("!!!!! Caught json::Exception: %s", e.what());
- }
- catch (const std::exception& e)
- {
- proto->Log("!!!!! Caught std::exception: %s", e.what());
+ std::string text = utils::text::slashu_to_utf8(utils::text::special_expressions_decode(json_as_string(markup)));
+
+ facebook_notification* notification = new facebook_notification();
+
+ notification->id = id;
+ notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
+ notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
+
+ notifications->push_back(notification);
}
return EXIT_SUCCESS;
@@ -290,265 +237,299 @@ bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text) { int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications)
{
- using namespace json;
+ std::string jsonData = static_cast< std::string* >(data)->substr(9);
+
+ JSONNODE *root = json_parse(jsonData.c_str());
+ if (root == NULL)
+ return EXIT_FAILURE;
- try
- {
- std::string messageData = static_cast< std::string* >(data)->substr(9);
- std::istringstream sDocument(messageData);
- Object objDocument;
- Reader::Read(objDocument, sDocument);
+ JSONNODE *ms = json_get(root, "ms");
+ if (ms == NULL)
+ return EXIT_FAILURE;
- const Object& objRoot = objDocument;
- const Array& messagesArray = objRoot["ms"];
+ for (unsigned int i = 0; i < json_size(ms); i++) {
+ JSONNODE *it = json_at(ms, i);
+
+ JSONNODE *type = json_get(it, "type");
+ if (type == NULL)
+ continue;
- for (Array::const_iterator itMessage(messagesArray.Begin()); itMessage != messagesArray.End(); ++itMessage)
- {
- const Object& objMember = *itMessage;
+ std::string t = json_as_string(type);
+ if (t == "msg" || t == "offline_msg") {
+ // direct message
+
+ JSONNODE *from = json_get(it, "from");
+ if (from == NULL)
+ continue;
- const String& type = objMember["type"];
+ char *from_id = json_as_string(from);
- if (type.Value() == "msg" || type.Value() == "offline_msg") // direct message
- {
- const Number& from = objMember["from"];
- char was_id[32];
- lltoa(from.Value(), was_id, 10);
-
- const Object& messageContent = objMember["msg"];
- const String& text = messageContent["text"];
- const String& message_id = messageContent["messageId"];
- //"tab_type":"friend", objMember["tab_type"]
-
- const Number& time_sent = messageContent["time"];
-
- // ignore duplicits or messages sent from miranda
- if (ignore_duplicits(proto, message_id.Value(), text.Value()))
+ JSONNODE *msg = json_get(it, "msg");
+ if (msg == NULL)
+ continue;
+
+ JSONNODE *text = json_get(msg, "text");
+ JSONNODE *messageId = json_get(msg, "messageId");
+ JSONNODE *time = json_get(it, "time");
+ // JSONNODE *tab_type = json_get(it, "tab_type"); // e.g. "friend"
+
+ if (text == NULL || messageId == NULL)
+ continue;
+
+ std::string message_id = json_as_string(messageId);
+ std::string message_text = json_as_string(text);
+
+ // ignore duplicits or messages sent from miranda
+ if (ignore_duplicits(proto, message_id, message_text))
+ continue;
+
+ message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(message_text)), true);
+ if (message_text.empty())
+ continue;
+
+ JSONNODE *truncated = json_get(msg, "truncated");
+ if (truncated != NULL && json_as_int(truncated) == 1) {
+ // If we got truncated message, we can ignore it, because we should get it again as "messaging" type
+ std::string msg = "????? We got truncated message so we ignore it\n";
+ msg += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(message_text));
+ proto->Log(msg.c_str());
+ } else if (from_id == proto->facy.self_.user_id) {
+ // Outgoing message
+ JSONNODE *to = json_get(it, "to");
+ if (to == NULL)
continue;
- std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
- if (message_text.empty())
+ // TODO: put also outgoing messages into messages array and process it elsewhere
+ HANDLE hContact = proto->ContactIDToHContact(json_as_string(to));
+ if (!hContact) // TODO: add this contact?
continue;
- if (was_id == proto->facy.self_.user_id) {
- const Number& to = objMember["to"];
- char to_id[32];
- lltoa(to.Value(), to_id, 10);
+ DBEVENTINFO dbei = {0};
+ dbei.cbSize = sizeof(dbei);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.flags = DBEF_SENT | DBEF_UTF;
+ dbei.szModule = proto->m_szModuleName;
+
+ bool local_time = proto->getByte(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0;
+ dbei.timestamp = local_time || time == NULL ? ::time(NULL) : utils::time::fix_timestamp(json_as_int(time));
+
+ dbei.cbBlob = (DWORD)message_text.length() + 1;
+ dbei.pBlob = (PBYTE)message_text.c_str();
+ db_event_add(hContact, &dbei);
+
+ continue;
+ } else {
+ // Incomming message
+ facebook_message* message = new facebook_message();
+ message->message_text = message_text;
+ message->time = utils::time::fix_timestamp(json_as_int(time));
+ message->user_id = from_id;
+ message->message_id = message_id;
+
+ messages->push_back(message);
+ }
- HANDLE hContact = proto->ContactIDToHContact(to_id);
- if (!hContact)
- continue;
+ } else if (t == "messaging") {
+ // messages
- DBEVENTINFO dbei = {0};
- dbei.cbSize = sizeof(dbei);
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.flags = DBEF_SENT | DBEF_UTF;
- dbei.szModule = proto->m_szModuleName;
+ JSONNODE *type = json_get(it, "event");
+ if (type == NULL)
+ continue;
- bool local_time = proto->getByte(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0;
- dbei.timestamp = local_time ? ::time(NULL) : utils::time::fix_timestamp(time_sent.Value());
+ std::string t = json_as_string(type);
- dbei.cbBlob = (DWORD)message_text.length() + 1;
- dbei.pBlob = (PBYTE)message_text.c_str();
- db_event_add(hContact, &dbei);
+ if (t == "read_receipt") {
+ // user read message
+ JSONNODE *reader = json_get(it, "reader");
+ JSONNODE *time = json_get(it, "time");
+ if (reader == NULL || time == NULL)
continue;
- }
- if ((messageContent.Find("truncated") != messageContent.End())
- && (((const Number &)messageContent["truncated"]).Value() == 1)) {
- // If we got truncated message, we can ignore it, because we should get it again as "messaging" type
- std::string msg = "????? We got truncated message so we ignore it\n";
- msg += utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value()));
- proto->Log(msg.c_str());
- } else {
- facebook_message* message = new facebook_message();
- message->message_text = message_text;
- message->time = utils::time::fix_timestamp(time_sent.Value());
- message->user_id = was_id;
- message->message_id = message_id;
-
- messages->push_back(message);
- }
- }
- else if (type.Value() == "messaging")
- {
- const String& type = objMember["event"];
-
- if (type.Value() == "read_receipt") {
- // user read message
- const Number& reader = objMember["reader"];
- const Number& time = objMember["time"];
-
- char user_id[32];
- lltoa(reader.Value(), user_id, 10);
-
- // TODO: add check for chat contacts
- HANDLE hContact = proto->ContactIDToHContact(user_id);
- if (hContact) {
- TCHAR ttime[64], tstr[100];
- _tcsftime(ttime, SIZEOF(ttime), _T("%X"), utils::conversion::fbtime_to_timeinfo(time.Value()));
- mir_sntprintf(tstr, SIZEOF(tstr), TranslateT("Message read: %s"), ttime);
-
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)tstr);
- }
-
- } else if (type.Value() == "deliver") {
- // inbox message (multiuser or direct)
- const Object& messageContent = objMember["message"];
-
- const Number& sender_fbid = messageContent["sender_fbid"];
- const String& sender_name = messageContent["sender_name"];
- const String& text = messageContent["body"];
- const String& tid = messageContent["tid"];
- const String& mid = messageContent["mid"];
- const Number& time_sent = messageContent["timestamp"];
-
- char was_id[32];
- lltoa(sender_fbid.Value(), was_id, 10);
-
- // Ignore messages from myself
- if (was_id == proto->facy.self_.user_id)
- continue;
-
- // Ignore duplicits or messages sent from miranda
- if (ignore_duplicits(proto, mid.Value(), text.Value()))
- continue;
-
- std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
- if (message_text.empty())
- continue;
-
- facebook_message* message = new facebook_message();
- message->message_text = message_text;
- message->sender_name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(sender_name.Value()));
- message->time = utils::time::fix_timestamp(time_sent.Value());
- message->user_id = was_id; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
- message->message_id = mid.Value();
-
- messages->push_back(message);
+ // TODO: add check for chat contacts
+ HANDLE hContact = proto->ContactIDToHContact(json_as_string(reader));
+ if (hContact) {
+ TCHAR ttime[64], tstr[100];
+ _tcsftime(ttime, SIZEOF(ttime), _T("%X"), utils::conversion::fbtime_to_timeinfo(json_as_int(time)));
+ mir_sntprintf(tstr, SIZEOF(tstr), TranslateT("Message read: %s"), ttime);
+
+ CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)tstr);
}
- }
- else if (type.Value() == "thread_msg") // multiuser message
- {
- const String& from_name = objMember["from_name"];
- const String& to_name = objMember["to_name"]["__html"];
- const String& to_id = objMember["to"];
+ } else if (t == "deliver") {
+ // inbox message (multiuser or direct)
- const Number& from = objMember["from"];
- char was_id[32];
- lltoa(from.Value(), was_id, 10);
+ JSONNODE *msg = json_get(it, "message");
- const Object& messageContent = objMember["msg"];
- const String& text = messageContent["text"];
- const String& mid = messageContent["messageId"];
+ JSONNODE *sender_fbid = json_get(msg, "sender_fbid");
+ JSONNODE *sender_name = json_get(msg, "sender_name");
+ JSONNODE *body = json_get(msg, "body");
+ JSONNODE *tid = json_get(msg, "tid");
+ JSONNODE *mid = json_get(msg, "mid");
+ JSONNODE *timestamp = json_get(msg, "timestamp");
+
+ if (sender_fbid == NULL || body == NULL || mid == NULL)
+ continue;
+
+ std::string id = json_as_string(sender_fbid);
+ std::string message_id = json_as_string(mid);
+ std::string message_text = json_as_string(body);
// Ignore messages from myself
- if (was_id == proto->facy.self_.user_id)
+ if (id == proto->facy.self_.user_id)
continue;
-
+
// Ignore duplicits or messages sent from miranda
- if (ignore_duplicits(proto, mid.Value(), text.Value()))
+ if (body == NULL || ignore_duplicits(proto, message_id, message_text))
continue;
- std::string message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(text.Value())), true);
+ message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(message_text)), true);
if (message_text.empty())
continue;
- std::string title = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(to_name.Value()));
- std::string url = "/?action=read&sk=inbox&page&query&tid=" + to_id.Value();
- std::string popup_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(from_name.Value()));
- popup_text += ": " + message_text;
+ facebook_message* message = new facebook_message();
+ message->message_text = message_text;
+ message->sender_name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(id));
+ message->time = utils::time::fix_timestamp(json_as_int(timestamp));
+ message->user_id = id; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
+ message->message_id = message_id;
- proto->Log(" Got multichat message");
-
- TCHAR* szTitle = mir_utf8decodeT(title.c_str());
- TCHAR* szText = mir_utf8decodeT(popup_text.c_str());
- proto->NotifyEvent(szTitle, szText, NULL, FACEBOOK_EVENT_OTHER, &url);
- mir_free(szTitle);
- mir_free(szText);
+ messages->push_back(message);
}
- else if (type.Value() == "notification_json") // event notification
- {
- if (!proto->getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE))
- continue;
+ } else if (t == "thread_msg") {
+ // multiuser message
+
+ JSONNODE *from_name = json_get(it, "from_name");
+ JSONNODE *to_name_ = json_get(it, "to_name");
+ if (to_name_ == NULL)
+ continue;
+ JSONNODE *to_name = json_get(to_name_, "__html");
+ JSONNODE *to_id = json_get(it, "to");
+ JSONNODE *from_id = json_get(it, "from");
+
+ JSONNODE *msg = json_get(it, "msg");
+ JSONNODE *text = json_get(msg, "text");
+ JSONNODE *messageId = json_get(msg, "messageId");
+
+ if (from_id == NULL || text == NULL || messageId == NULL)
+ continue;
+
+ std::string id = json_as_string(from_id);
+ std::string message_id = json_as_string(messageId);
+ std::string message_text = json_as_string(text);
+
+ // Ignore messages from myself
+ if (id == proto->facy.self_.user_id)
+ continue;
+
+ // Ignore duplicits or messages sent from miranda
+ if (ignore_duplicits(proto, message_id, message_text))
+ continue;
+
+ message_text = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(message_text)), true);
+ if (message_text.empty())
+ continue;
- const Array& notificationsArray = objMember["nodes"];
+ std::string title = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(json_as_string(to_name)));
+ std::string url = "/?action=read&sk=inbox&page&query&tid=" + id;
+ std::string popup_text = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(json_as_string(from_name)));
+ popup_text += ": " + message_text;
- for (Array::const_iterator itNotification(notificationsArray.Begin()); itNotification != notificationsArray.End(); ++itNotification)
- {
- const Object& objNotification = *itNotification;
+ proto->Log(" Got multichat message");
+
+ TCHAR* szTitle = mir_utf8decodeT(title.c_str());
+ TCHAR* szText = mir_utf8decodeT(popup_text.c_str());
+ proto->NotifyEvent(szTitle, szText, NULL, FACEBOOK_EVENT_OTHER, &url);
+ mir_free(szTitle);
+ mir_free(szText);
+ } else if (t == "notification_json") {
+ // event notification
+
+ if (!proto->getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE))
+ continue;
- //const String& text = objNotification["title"]["text"];
- const String& text = objNotification["unaggregatedTitle"]["text"];
- const String& link = objNotification["url"];
- const String& id = objNotification["alert_id"];
+ JSONNODE *nodes = json_get(it, "nodes");
+ for (unsigned int i = 0; i < json_size(nodes); i++) {
+ JSONNODE *itNodes = json_at(nodes, i);
- const Number& time_sent = objNotification["timestamp"]["time"];
- if (time_sent.Value() > proto->facy.last_notification_time_) // Check against duplicit notifications
- {
- proto->facy.last_notification_time_ = time_sent.Value();
+ //JSONNODE *text = json_get(itNodes, "title/text");
+ JSONNODE *text_ = json_get(itNodes, "unaggregatedTitle");
+ if (text_ == NULL)
+ continue;
+ JSONNODE *text = json_get(text_, "text");
+ JSONNODE *url = json_get(itNodes, "url");
+ JSONNODE *alert_id = json_get(itNodes, "alert_id");
+
+ JSONNODE *time_ = json_get(it, "timestamp");
+ if (time_ == NULL)
+ continue;
+ JSONNODE *time = json_get(time_, "time");
+ if (time == NULL || text == NULL || url == NULL || alert_id == NULL)
+ continue;
- facebook_notification* notification = new facebook_notification();
- notification->text = utils::text::slashu_to_utf8(text.Value());
- notification->link = utils::text::special_expressions_decode(link.Value());
-
- std::string::size_type pos = id.Value().find(":");
- notification->id = (pos != std::string::npos) ? id.Value().substr(pos+1) : id.Value();
+ unsigned long timestamp = json_as_int(time);
+ if (timestamp > proto->facy.last_notification_time_) {
+ // Only new notifications
+ proto->facy.last_notification_time_ = timestamp;
- notifications->push_back(notification);
- }
+ facebook_notification* notification = new facebook_notification();
+ notification->text = utils::text::slashu_to_utf8(json_as_string(text));
+ notification->link = utils::text::special_expressions_decode(json_as_string(url));
+ notification->id = json_as_string(alert_id);
+
+ std::string::size_type pos = notification->id.find(":");
+ if (pos != std::string::npos)
+ notification->id = notification->id.substr(pos+1);
+
+ notifications->push_back(notification);
}
}
- else if (type.Value() == "typ") // chat typing notification
- {
- const Number& from = objMember["from"];
- char user_id[32];
- lltoa(from.Value(), user_id, 10);
+ } else if (t == "typ") {
+ // chat typing notification
+
+ JSONNODE *from = json_get(it, "from");
+ if (from == NULL)
+ continue;
- facebook_user fbu;
- fbu.user_id = user_id;
+ facebook_user fbu;
+ fbu.user_id = json_as_string(from);
- HANDLE hContact = proto->AddToContactList(&fbu, CONTACT_FRIEND);
+ HANDLE hContact = proto->AddToContactList(&fbu, CONTACT_FRIEND);
- if (proto->getWord(hContact, "Status", 0) == ID_STATUS_OFFLINE)
- proto->setWord(hContact, "Status", ID_STATUS_ONLINE);
-
- const Number& state = objMember["st"];
- if (state.Value() == 1)
- CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM)60);
- else
- CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF);
- }
- else if (type.Value() == "privacy_changed")
- {
- const String& event_type = objMember["event"];
- const Object& event_data = objMember["data"];
-
- if (event_type.Value() == "visibility_update")
- { // change of chat status
- const Boolean visibility = event_data["visibility"];
- proto->Log(" Requested chat switch to %s", visibility ? "Online" : "Offline");
- proto->SetStatus(visibility ? ID_STATUS_ONLINE : ID_STATUS_INVISIBLE);
- }
- }
+ if (proto->getWord(hContact, "Status", 0) == ID_STATUS_OFFLINE)
+ proto->setWord(hContact, "Status", ID_STATUS_ONLINE);
+
+ JSONNODE *st = json_get(it, "st");
+ if (json_as_int(st) == 1)
+ CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM)60);
else
+ CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF);
+ } else if (t == "privacy_changed") {
+ // settings changed
+
+ JSONNODE *event_type = json_get(it, "event");
+ JSONNODE *event_data = json_get(it, "data");
+
+ if (event_type == NULL || event_data == NULL)
continue;
- }
- // remove received messages from map
- for (std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ++it) {
- if (it->second)
- proto->facy.messages_ignore.erase(it);
+ std::string t = json_as_string(event_type);
+ if (t == "visibility_update") {
+ // change of chat status
+ JSONNODE *visibility = json_get(event_data, "visibility");
+
+ bool isVisible = (visibility != NULL) && json_as_bool(visibility);
+ proto->Log(" Requested chat switch to %s", isVisible ? "Online" : "Offline");
+ proto->SetStatus(isVisible ? ID_STATUS_ONLINE : ID_STATUS_INVISIBLE);
+ }
}
+ else
+ continue;
}
- catch (Reader::ParseException& e)
- {
- proto->Log("!!!!! Caught json::ParseException: %s", e.what());
- proto->Log(" Line/offset: %d/%d", e.m_locTokenBegin.m_nLine + 1, e.m_locTokenBegin.m_nLineOffset + 1);
- }
- catch (const Exception& e)
- {
- proto->Log ("!!!!! Caught json::Exception: %s", e.what());
+
+ // remove received messages from map
+ for (std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ++it) {
+ if (it->second)
+ proto->facy.messages_ignore.erase(it);
}
return EXIT_SUCCESS;
|