2015-08-29 05:09:35 +00:00
|
|
|
/*
|
2015-10-22 05:13:26 +00:00
|
|
|
* Apple // emulator for *ix
|
2015-08-29 05:09:35 +00:00
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
2015-10-22 05:13:26 +00:00
|
|
|
* version 3 or later (your choice) as published by the Free Software
|
2015-08-29 05:09:35 +00:00
|
|
|
* Foundation.
|
|
|
|
*
|
2016-02-27 21:46:02 +00:00
|
|
|
* Copyright 2015-2016 Aaron Culliney
|
2015-08-29 05:09:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
#ifndef _JSON_PARSE_H_
|
|
|
|
#define _JSON_PARSE_H_ 1
|
|
|
|
|
2015-08-29 05:09:35 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "../externals/jsmn/jsmn.h"
|
|
|
|
|
2016-02-27 21:46:02 +00:00
|
|
|
// opaque type
|
|
|
|
typedef const struct JSON_s *JSON_ref;
|
2015-08-29 05:09:35 +00:00
|
|
|
|
2016-03-05 21:43:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constructors
|
|
|
|
|
2016-03-10 06:21:15 +00:00
|
|
|
// parses string into tokens. returns positive token count or negative jsmnerr error code.
|
2016-02-27 21:46:02 +00:00
|
|
|
int json_createFromString(const char *jsonString, INOUT JSON_ref *jsonRef);
|
2016-02-13 22:02:35 +00:00
|
|
|
|
2016-03-10 06:21:15 +00:00
|
|
|
// parses file into string and tokens. returns positive token count or negative jsmnerr error code.
|
2016-02-27 21:46:02 +00:00
|
|
|
int json_createFromFile(const char *filePath, INOUT JSON_ref *jsonRef);
|
|
|
|
|
2016-03-10 06:21:15 +00:00
|
|
|
// parses FD into string and tokens. returns positive token count or negative jsmnerr error code.
|
2016-02-27 21:46:02 +00:00
|
|
|
int json_createFromFD(int fd, INOUT JSON_ref *jsonRef);
|
2015-08-29 05:09:35 +00:00
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// map functions
|
|
|
|
|
2016-03-05 21:43:09 +00:00
|
|
|
// get JSON_ref value for key in map JSON, returns true upon success and allocated JSON_ref
|
|
|
|
int json_mapCopyJSON(const JSON_ref map, const char *key, INOUT JSON_ref *val);
|
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
// get string value for key in map JSON, returns true upon success and strdup()'d value in *val
|
2016-02-27 21:46:02 +00:00
|
|
|
bool json_mapCopyStringValue(const JSON_ref map, const char *key, INOUT char **val);
|
2016-02-13 22:02:35 +00:00
|
|
|
|
2016-02-26 05:04:23 +00:00
|
|
|
// get long value for key in map JSON, returns true upon success
|
2016-02-27 21:46:02 +00:00
|
|
|
bool json_mapParseLongValue(const JSON_ref map, const char *key, INOUT long *val, const long base);
|
2016-02-13 22:02:35 +00:00
|
|
|
|
2016-03-05 21:43:09 +00:00
|
|
|
// get bool value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapParseBoolValue(const JSON_ref map, const char *key, INOUT bool *val);
|
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
// get float value for key in map JSON, returns true upon success
|
2016-02-27 21:46:02 +00:00
|
|
|
bool json_mapParseFloatValue(const JSON_ref map, const char *key, INOUT float *val);
|
2016-02-13 22:02:35 +00:00
|
|
|
|
2016-03-05 21:43:09 +00:00
|
|
|
// set string value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetStringValue(const JSON_ref map, const char *key, const char *val);
|
|
|
|
|
|
|
|
// set raw string (does not add quotes) value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetRawStringValue(const JSON_ref map, const char *key, const char *val);
|
|
|
|
|
|
|
|
// set JSON_ref value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetJSONValue(const JSON_ref map, const char *key, const JSON_ref val);
|
|
|
|
|
|
|
|
// set long value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetLongValue(const JSON_ref map, const char *key, long val);
|
|
|
|
|
|
|
|
// set bool value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetBoolValue(const JSON_ref map, const char *key, bool val);
|
|
|
|
|
|
|
|
// set float value for key in map JSON, returns true upon success
|
|
|
|
bool json_mapSetFloatValue(const JSON_ref map, const char *key, float val);
|
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// array functions
|
|
|
|
|
2016-02-27 21:46:02 +00:00
|
|
|
//bool json_arrayCopyStringValueAtIndex(const JSON_ref array, unsigned long index, INOUT const char **val);
|
|
|
|
//bool json_arrayParseLongValueAtIndex(const JSON_ref array, unsigned long index, INOUT const long *val, const long base);
|
|
|
|
//bool json_arrayParseFloatValueAtIndex(const JSON_ref array, unsigned long index, INOUT const float *val);
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// serialization
|
2016-03-05 21:43:09 +00:00
|
|
|
|
|
|
|
// serialize to file descriptor
|
2016-02-27 21:46:02 +00:00
|
|
|
bool json_serialize(JSON_ref json, int fd, bool pretty);
|
2016-02-13 22:02:35 +00:00
|
|
|
|
2016-02-26 05:04:23 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2016-03-05 21:43:09 +00:00
|
|
|
// destructor
|
2016-02-27 21:46:02 +00:00
|
|
|
void json_destroy(JSON_ref *jsonRef);
|
2015-08-29 05:09:35 +00:00
|
|
|
|
2016-02-13 22:02:35 +00:00
|
|
|
#endif
|