3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include <yajl/yajl_parse.h>
26 #include <yajl/yajl_gen.h>
27 #ifdef HAVE_YAJL_YAJL_VERSION_H
28 #include <yajl/yajl_version.h>
34 virtual ~IParseCallback() { }
36 virtual void onParsed(CVariant *variant) = 0;
39 class CSimpleParseCallback : public IParseCallback
42 virtual void onParsed(CVariant *variant) { m_parsed = *variant; }
43 CVariant &GetOutput() { return m_parsed; }
49 class CJSONVariantParser
52 CJSONVariantParser(IParseCallback *callback);
53 ~CJSONVariantParser();
55 void push_buffer(const unsigned char *buffer, unsigned int length);
57 static CVariant Parse(const unsigned char *json, unsigned int length);
60 static int ParseNull(void * ctx);
61 static int ParseBoolean(void * ctx, int boolean);
63 static int ParseInteger(void * ctx, long long integerVal);
65 static int ParseInteger(void * ctx, long integerVal);
67 static int ParseDouble(void * ctx, double doubleVal);
69 static int ParseString(void * ctx, const unsigned char * stringVal, size_t stringLen);
71 static int ParseString(void * ctx, const unsigned char * stringVal, unsigned int stringLen);
73 static int ParseMapStart(void * ctx);
75 static int ParseMapKey(void * ctx, const unsigned char * stringVal, size_t stringLen);
77 static int ParseMapKey(void * ctx, const unsigned char * stringVal, unsigned int stringLen);
79 static int ParseMapEnd(void * ctx);
80 static int ParseArrayStart(void * ctx);
81 static int ParseArrayEnd(void * ctx);
83 void PushObject(CVariant variant);
86 static yajl_callbacks callbacks;
88 IParseCallback *m_callback;
89 yajl_handle m_handler;
91 CVariant m_parsedObject;
92 std::vector<CVariant *> m_parse;
101 PARSE_STATUS m_status;