mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
changing {} style to match majority of previous style
This commit is contained in:
parent
da6cdf014b
commit
961d929f4d
320 changed files with 5502 additions and 10485 deletions
|
@ -35,13 +35,11 @@ struct buffer {
|
|||
char *data;
|
||||
};
|
||||
|
||||
static int dump_to_strbuffer(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
static int dump_to_strbuffer(const char *buffer, size_t size, void *data) {
|
||||
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
|
||||
}
|
||||
|
||||
static int dump_to_buffer(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
static int dump_to_buffer(const char *buffer, size_t size, void *data) {
|
||||
struct buffer *buf = (struct buffer *)data;
|
||||
|
||||
if (buf->used + size <= buf->size)
|
||||
|
@ -51,16 +49,14 @@ static int dump_to_buffer(const char *buffer, size_t size, void *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dump_to_file(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
static int dump_to_file(const char *buffer, size_t size, void *data) {
|
||||
FILE *dest = (FILE *)data;
|
||||
if (fwrite(buffer, size, 1, dest) != 1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dump_to_fd(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
static int dump_to_fd(const char *buffer, size_t size, void *data) {
|
||||
#ifdef HAVE_UNISTD_H
|
||||
int *dest = (int *)data;
|
||||
if (write(*dest, buffer, size) == (ssize_t)size)
|
||||
|
@ -72,8 +68,7 @@ static int dump_to_fd(const char *buffer, size_t size, void *data)
|
|||
/* 32 spaces (the maximum indentation size) */
|
||||
static const char whitespace[] = " ";
|
||||
|
||||
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data)
|
||||
{
|
||||
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data) {
|
||||
if (FLAGS_TO_INDENT(flags) > 0) {
|
||||
unsigned int ws_count = FLAGS_TO_INDENT(flags), n_spaces = depth * ws_count;
|
||||
|
||||
|
@ -94,8 +89,7 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data, size_t flags)
|
||||
{
|
||||
static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data, size_t flags) {
|
||||
const char *pos, *end, *lim;
|
||||
int32_t codepoint = 0;
|
||||
|
||||
|
@ -197,13 +191,11 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump, v
|
|||
return dump("\"", 1, data);
|
||||
}
|
||||
|
||||
static int compare_keys(const void *key1, const void *key2)
|
||||
{
|
||||
static int compare_keys(const void *key1, const void *key2) {
|
||||
return strcmp(*(const char **)key1, *(const char **)key2);
|
||||
}
|
||||
|
||||
static int loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size)
|
||||
{
|
||||
static int loop_check(hashtable_t *parents, const json_t *json, char *key, size_t key_size) {
|
||||
snprintf(key, key_size, "%p", json);
|
||||
if (hashtable_get(parents, key))
|
||||
return -1;
|
||||
|
@ -212,8 +204,7 @@ static int loop_check(hashtable_t *parents, const json_t *json, char *key, size_
|
|||
}
|
||||
|
||||
static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
hashtable_t *parents, json_dump_callback_t dump, void *data)
|
||||
{
|
||||
hashtable_t *parents, json_dump_callback_t dump, void *data) {
|
||||
int embed = flags & JSON_EMBED;
|
||||
|
||||
flags &= ~JSON_EMBED;
|
||||
|
@ -288,7 +279,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
|
||||
if (i < n - 1) {
|
||||
if (dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
return -1;
|
||||
} else {
|
||||
if (dump_indent(flags, depth, 0, dump, data))
|
||||
|
@ -359,14 +350,14 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
|
||||
dump_string(key, strlen(key), dump, data, flags);
|
||||
if (dump(separator, separator_length, data) ||
|
||||
do_dump(value, flags, depth + 1, parents, dump, data)) {
|
||||
do_dump(value, flags, depth + 1, parents, dump, data)) {
|
||||
jsonp_free(keys);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (i < size - 1) {
|
||||
if (dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data)) {
|
||||
dump_indent(flags, depth + 1, 1, dump, data)) {
|
||||
jsonp_free(keys);
|
||||
return -1;
|
||||
}
|
||||
|
@ -388,13 +379,13 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
|
||||
dump_string(key, strlen(key), dump, data, flags);
|
||||
if (dump(separator, separator_length, data) ||
|
||||
do_dump(json_object_iter_value(iter), flags, depth + 1,
|
||||
parents, dump, data))
|
||||
do_dump(json_object_iter_value(iter), flags, depth + 1,
|
||||
parents, dump, data))
|
||||
return -1;
|
||||
|
||||
if (next) {
|
||||
if (dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
return -1;
|
||||
} else {
|
||||
if (dump_indent(flags, depth, 0, dump, data))
|
||||
|
@ -415,8 +406,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
}
|
||||
}
|
||||
|
||||
char *json_dumps(const json_t *json, size_t flags)
|
||||
{
|
||||
char *json_dumps(const json_t *json, size_t flags) {
|
||||
strbuffer_t strbuff;
|
||||
char *result;
|
||||
|
||||
|
@ -432,8 +422,7 @@ char *json_dumps(const json_t *json, size_t flags)
|
|||
return result;
|
||||
}
|
||||
|
||||
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
|
||||
{
|
||||
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags) {
|
||||
struct buffer buf = { size, 0, buffer };
|
||||
|
||||
if (json_dump_callback(json, dump_to_buffer, (void *)&buf, flags))
|
||||
|
@ -442,18 +431,15 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
|
|||
return buf.used;
|
||||
}
|
||||
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags)
|
||||
{
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags) {
|
||||
return json_dump_callback(json, dump_to_file, (void *)output, flags);
|
||||
}
|
||||
|
||||
int json_dumpfd(const json_t *json, int output, size_t flags)
|
||||
{
|
||||
int json_dumpfd(const json_t *json, int output, size_t flags) {
|
||||
return json_dump_callback(json, dump_to_fd, (void *)&output, flags);
|
||||
}
|
||||
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags)
|
||||
{
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags) {
|
||||
int result;
|
||||
|
||||
FILE *output = fopen(path, "w");
|
||||
|
@ -468,8 +454,7 @@ int json_dump_file(const json_t *json, const char *path, size_t flags)
|
|||
return result;
|
||||
}
|
||||
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags)
|
||||
{
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags) {
|
||||
int res;
|
||||
hashtable_t parents_set;
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include <string.h>
|
||||
#include "jansson_private.h"
|
||||
|
||||
void jsonp_error_init(json_error_t *error, const char *source)
|
||||
{
|
||||
void jsonp_error_init(json_error_t *error, const char *source) {
|
||||
if (error) {
|
||||
error->text[0] = '\0';
|
||||
error->line = -1;
|
||||
|
@ -15,8 +14,7 @@ void jsonp_error_init(json_error_t *error, const char *source)
|
|||
}
|
||||
}
|
||||
|
||||
void jsonp_error_set_source(json_error_t *error, const char *source)
|
||||
{
|
||||
void jsonp_error_set_source(json_error_t *error, const char *source) {
|
||||
size_t length;
|
||||
|
||||
if (!error || !source)
|
||||
|
@ -34,8 +32,7 @@ void jsonp_error_set_source(json_error_t *error, const char *source)
|
|||
|
||||
void jsonp_error_set(json_error_t *error, int line, int column,
|
||||
size_t position, enum json_error_code code,
|
||||
const char *msg, ...)
|
||||
{
|
||||
const char *msg, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
jsonp_error_vset(error, line, column, position, code, msg, ap);
|
||||
|
@ -44,8 +41,7 @@ void jsonp_error_set(json_error_t *error, int line, int column,
|
|||
|
||||
void jsonp_error_vset(json_error_t *error, int line, int column,
|
||||
size_t position, enum json_error_code code,
|
||||
const char *msg, va_list ap)
|
||||
{
|
||||
const char *msg, va_list ap) {
|
||||
if (!error)
|
||||
return;
|
||||
|
||||
|
|
|
@ -37,34 +37,29 @@ extern volatile uint32_t hashtable_seed;
|
|||
#define ordered_list_to_pair(list_) container_of(list_, pair_t, ordered_list)
|
||||
#define hash_str(key) ((size_t)hashlittle((key), strlen(key), hashtable_seed))
|
||||
|
||||
static JSON_INLINE void list_init(list_t *list)
|
||||
{
|
||||
static JSON_INLINE void list_init(list_t *list) {
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static JSON_INLINE void list_insert(list_t *list, list_t *node)
|
||||
{
|
||||
static JSON_INLINE void list_insert(list_t *list, list_t *node) {
|
||||
node->next = list;
|
||||
node->prev = list->prev;
|
||||
list->prev->next = node;
|
||||
list->prev = node;
|
||||
}
|
||||
|
||||
static JSON_INLINE void list_remove(list_t *list)
|
||||
{
|
||||
static JSON_INLINE void list_remove(list_t *list) {
|
||||
list->prev->next = list->next;
|
||||
list->next->prev = list->prev;
|
||||
}
|
||||
|
||||
static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
|
||||
{
|
||||
static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket) {
|
||||
return bucket->first == &hashtable->list && bucket->first == bucket->last;
|
||||
}
|
||||
|
||||
static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
|
||||
list_t *list)
|
||||
{
|
||||
list_t *list) {
|
||||
if (bucket_is_empty(hashtable, bucket)) {
|
||||
list_insert(&hashtable->list, list);
|
||||
bucket->first = bucket->last = list;
|
||||
|
@ -75,8 +70,7 @@ static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
|
|||
}
|
||||
|
||||
static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
|
||||
const char *key, size_t hash)
|
||||
{
|
||||
const char *key, size_t hash) {
|
||||
list_t *list;
|
||||
pair_t *pair;
|
||||
|
||||
|
@ -100,8 +94,7 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
|
|||
|
||||
/* returns 0 on success, -1 if key was not found */
|
||||
static int hashtable_do_del(hashtable_t *hashtable,
|
||||
const char *key, size_t hash)
|
||||
{
|
||||
const char *key, size_t hash) {
|
||||
pair_t *pair;
|
||||
bucket_t *bucket;
|
||||
size_t index;
|
||||
|
@ -132,8 +125,7 @@ static int hashtable_do_del(hashtable_t *hashtable,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void hashtable_do_clear(hashtable_t *hashtable)
|
||||
{
|
||||
static void hashtable_do_clear(hashtable_t *hashtable) {
|
||||
list_t *list, *next;
|
||||
pair_t *pair;
|
||||
|
||||
|
@ -145,8 +137,7 @@ static void hashtable_do_clear(hashtable_t *hashtable)
|
|||
}
|
||||
}
|
||||
|
||||
static int hashtable_do_rehash(hashtable_t *hashtable)
|
||||
{
|
||||
static int hashtable_do_rehash(hashtable_t *hashtable) {
|
||||
list_t *list, *next;
|
||||
pair_t *pair;
|
||||
size_t i, index, new_size, new_order;
|
||||
|
@ -182,8 +173,7 @@ static int hashtable_do_rehash(hashtable_t *hashtable)
|
|||
}
|
||||
|
||||
|
||||
int hashtable_init(hashtable_t *hashtable)
|
||||
{
|
||||
int hashtable_init(hashtable_t *hashtable) {
|
||||
size_t i;
|
||||
|
||||
hashtable->size = 0;
|
||||
|
@ -203,14 +193,12 @@ int hashtable_init(hashtable_t *hashtable)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void hashtable_close(hashtable_t *hashtable)
|
||||
{
|
||||
void hashtable_close(hashtable_t *hashtable) {
|
||||
hashtable_do_clear(hashtable);
|
||||
jsonp_free(hashtable->buckets);
|
||||
}
|
||||
|
||||
int hashtable_set(hashtable_t *hashtable, const char *key, json_t *value)
|
||||
{
|
||||
int hashtable_set(hashtable_t *hashtable, const char *key, json_t *value) {
|
||||
pair_t *pair;
|
||||
bucket_t *bucket;
|
||||
size_t hash, index;
|
||||
|
@ -257,8 +245,7 @@ int hashtable_set(hashtable_t *hashtable, const char *key, json_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *hashtable_get(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
void *hashtable_get(hashtable_t *hashtable, const char *key) {
|
||||
pair_t *pair;
|
||||
size_t hash;
|
||||
bucket_t *bucket;
|
||||
|
@ -273,14 +260,12 @@ void *hashtable_get(hashtable_t *hashtable, const char *key)
|
|||
return pair->value;
|
||||
}
|
||||
|
||||
int hashtable_del(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
int hashtable_del(hashtable_t *hashtable, const char *key) {
|
||||
size_t hash = hash_str(key);
|
||||
return hashtable_do_del(hashtable, key, hash);
|
||||
}
|
||||
|
||||
void hashtable_clear(hashtable_t *hashtable)
|
||||
{
|
||||
void hashtable_clear(hashtable_t *hashtable) {
|
||||
size_t i;
|
||||
|
||||
hashtable_do_clear(hashtable);
|
||||
|
@ -295,13 +280,11 @@ void hashtable_clear(hashtable_t *hashtable)
|
|||
hashtable->size = 0;
|
||||
}
|
||||
|
||||
void *hashtable_iter(hashtable_t *hashtable)
|
||||
{
|
||||
void *hashtable_iter(hashtable_t *hashtable) {
|
||||
return hashtable_iter_next(hashtable, &hashtable->ordered_list);
|
||||
}
|
||||
|
||||
void *hashtable_iter_at(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
void *hashtable_iter_at(hashtable_t *hashtable, const char *key) {
|
||||
pair_t *pair;
|
||||
size_t hash;
|
||||
bucket_t *bucket;
|
||||
|
@ -316,28 +299,24 @@ void *hashtable_iter_at(hashtable_t *hashtable, const char *key)
|
|||
return &pair->ordered_list;
|
||||
}
|
||||
|
||||
void *hashtable_iter_next(hashtable_t *hashtable, void *iter)
|
||||
{
|
||||
void *hashtable_iter_next(hashtable_t *hashtable, void *iter) {
|
||||
list_t *list = (list_t *)iter;
|
||||
if (list->next == &hashtable->ordered_list)
|
||||
return NULL;
|
||||
return list->next;
|
||||
}
|
||||
|
||||
void *hashtable_iter_key(void *iter)
|
||||
{
|
||||
void *hashtable_iter_key(void *iter) {
|
||||
pair_t *pair = ordered_list_to_pair((list_t *)iter);
|
||||
return pair->key;
|
||||
}
|
||||
|
||||
void *hashtable_iter_value(void *iter)
|
||||
{
|
||||
void *hashtable_iter_value(void *iter) {
|
||||
pair_t *pair = ordered_list_to_pair((list_t *)iter);
|
||||
return pair->value;
|
||||
}
|
||||
|
||||
void hashtable_iter_set(void *iter, json_t *value)
|
||||
{
|
||||
void hashtable_iter_set(void *iter, json_t *value) {
|
||||
pair_t *pair = ordered_list_to_pair((list_t *)iter);
|
||||
|
||||
json_decref(pair->value);
|
||||
|
|
|
@ -45,8 +45,7 @@
|
|||
#include "jansson.h"
|
||||
|
||||
|
||||
static uint32_t buf_to_uint32(char *data)
|
||||
{
|
||||
static uint32_t buf_to_uint32(char *data) {
|
||||
size_t i;
|
||||
uint32_t result = 0;
|
||||
|
||||
|
@ -60,8 +59,7 @@ static uint32_t buf_to_uint32(char *data)
|
|||
|
||||
/* /dev/urandom */
|
||||
#if !defined(_WIN32) && defined(USE_URANDOM)
|
||||
static int seed_from_urandom(uint32_t *seed)
|
||||
{
|
||||
static int seed_from_urandom(uint32_t *seed) {
|
||||
/* Use unbuffered I/O if we have open(), close() and read(). Otherwise
|
||||
fall back to fopen() */
|
||||
|
||||
|
@ -103,8 +101,7 @@ typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContai
|
|||
typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
|
||||
typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV hProv, DWORD dwFlags);
|
||||
|
||||
static int seed_from_windows_cryptoapi(uint32_t *seed)
|
||||
{
|
||||
static int seed_from_windows_cryptoapi(uint32_t *seed) {
|
||||
HINSTANCE hAdvAPI32 = NULL;
|
||||
CRYPTACQUIRECONTEXTA pCryptAcquireContext = NULL;
|
||||
CRYPTGENRANDOM pCryptGenRandom = NULL;
|
||||
|
@ -144,8 +141,7 @@ static int seed_from_windows_cryptoapi(uint32_t *seed)
|
|||
#endif
|
||||
|
||||
/* gettimeofday() and getpid() */
|
||||
static int seed_from_timestamp_and_pid(uint32_t *seed)
|
||||
{
|
||||
static int seed_from_timestamp_and_pid(uint32_t *seed) {
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
/* XOR of seconds and microseconds */
|
||||
struct timeval tv;
|
||||
|
@ -166,8 +162,7 @@ static int seed_from_timestamp_and_pid(uint32_t *seed)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t generate_seed()
|
||||
{
|
||||
static uint32_t generate_seed() {
|
||||
uint32_t seed = 0;
|
||||
int done = 0;
|
||||
|
||||
|
@ -200,8 +195,7 @@ volatile uint32_t hashtable_seed = 0;
|
|||
#if defined(HAVE_ATOMIC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
|
||||
static volatile char seed_initialized = 0;
|
||||
|
||||
void json_object_seed(size_t seed)
|
||||
{
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
|
@ -222,8 +216,7 @@ void json_object_seed(size_t seed)
|
|||
}
|
||||
}
|
||||
#elif defined(HAVE_SYNC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
|
||||
void json_object_seed(size_t seed)
|
||||
{
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
|
@ -250,8 +243,7 @@ void json_object_seed(size_t seed)
|
|||
}
|
||||
#elif defined(_WIN32)
|
||||
static long seed_initialized = 0;
|
||||
void json_object_seed(size_t seed)
|
||||
{
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
|
@ -271,8 +263,7 @@ void json_object_seed(size_t seed)
|
|||
}
|
||||
#else
|
||||
/* Fall back to a thread-unsafe version */
|
||||
void json_object_seed(size_t seed)
|
||||
{
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
|
|
|
@ -118,8 +118,7 @@ json_t *json_null(void);
|
|||
#endif
|
||||
|
||||
static JSON_INLINE
|
||||
json_t *json_incref(json_t *json)
|
||||
{
|
||||
json_t *json_incref(json_t *json) {
|
||||
if (json && json->refcount != (size_t) -1)
|
||||
JSON_INTERNAL_INCREF(json);
|
||||
return json;
|
||||
|
@ -129,16 +128,14 @@ json_t *json_incref(json_t *json)
|
|||
void json_delete(json_t *json);
|
||||
|
||||
static JSON_INLINE
|
||||
void json_decref(json_t *json)
|
||||
{
|
||||
void json_decref(json_t *json) {
|
||||
if (json && json->refcount != (size_t) -1 && JSON_INTERNAL_DECREF(json) == 0)
|
||||
json_delete(json);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
static JSON_INLINE
|
||||
void json_decrefp(json_t **json)
|
||||
{
|
||||
void json_decrefp(json_t **json) {
|
||||
if (json) {
|
||||
json_decref(*json);
|
||||
*json = NULL;
|
||||
|
@ -183,8 +180,7 @@ enum json_error_code {
|
|||
json_error_index_out_of_range
|
||||
};
|
||||
|
||||
static JSON_INLINE enum json_error_code json_error_code(const json_error_t *e)
|
||||
{
|
||||
static JSON_INLINE enum json_error_code json_error_code(const json_error_t *e) {
|
||||
return (enum json_error_code)e->text[JSON_ERROR_TEXT_LENGTH - 1];
|
||||
}
|
||||
|
||||
|
@ -210,36 +206,33 @@ int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
|
|||
|
||||
#define json_object_foreach(object, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))))
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))))
|
||||
|
||||
#define json_object_foreach_safe(object, n, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(n), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)))
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(n), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)))
|
||||
|
||||
#define json_array_foreach(array, index, value) \
|
||||
for(index = 0; \
|
||||
index < json_array_size(array) && (value = json_array_get(array, index)); \
|
||||
index++)
|
||||
index < json_array_size(array) && (value = json_array_get(array, index)); \
|
||||
index++)
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
int json_object_set(json_t *object, const char *key, json_t *value) {
|
||||
return json_object_set_new(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set_nocheck(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
int json_object_set_nocheck(json_t *object, const char *key, json_t *value) {
|
||||
return json_object_set_new_nocheck(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_iter_set(json_t *object, void *iter, json_t *value)
|
||||
{
|
||||
int json_object_iter_set(json_t *object, void *iter, json_t *value) {
|
||||
return json_object_iter_set_new(object, iter, json_incref(value));
|
||||
}
|
||||
|
||||
|
@ -253,20 +246,17 @@ int json_array_clear(json_t *array);
|
|||
int json_array_extend(json_t *array, json_t *other);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_set(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
int json_array_set(json_t *array, size_t ind, json_t *value) {
|
||||
return json_array_set_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_append(json_t *array, json_t *value)
|
||||
{
|
||||
int json_array_append(json_t *array, json_t *value) {
|
||||
return json_array_append_new(array, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_insert(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
int json_array_insert(json_t *array, size_t ind, json_t *value) {
|
||||
return json_array_insert_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
|
@ -316,8 +306,7 @@ json_t *json_path_get(const json_t *json, const char *path);
|
|||
int json_path_set_new(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_path_set(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error)
|
||||
{
|
||||
int json_path_set(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error) {
|
||||
return json_path_set_new(json, path, json_incref(value), flags, error);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ typedef struct {
|
|||
|
||||
static void error_set(json_error_t *error, const lex_t *lex,
|
||||
enum json_error_code code,
|
||||
const char *msg, ...)
|
||||
{
|
||||
const char *msg, ...) {
|
||||
va_list ap;
|
||||
char msg_text[JSON_ERROR_TEXT_LENGTH];
|
||||
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
|
||||
|
@ -139,8 +138,7 @@ static void error_set(json_error_t *error, const lex_t *lex,
|
|||
/*** lexical analyzer ***/
|
||||
|
||||
static void
|
||||
stream_init(stream_t *stream, get_func get, void *data)
|
||||
{
|
||||
stream_init(stream_t *stream, get_func get, void *data) {
|
||||
stream->get = get;
|
||||
stream->data = data;
|
||||
stream->buffer[0] = '\0';
|
||||
|
@ -152,8 +150,7 @@ stream_init(stream_t *stream, get_func get, void *data)
|
|||
stream->position = 0;
|
||||
}
|
||||
|
||||
static int stream_get(stream_t *stream, json_error_t *error)
|
||||
{
|
||||
static int stream_get(stream_t *stream, json_error_t *error) {
|
||||
int c;
|
||||
|
||||
if (stream->state != STREAM_STATE_OK)
|
||||
|
@ -211,8 +208,7 @@ out:
|
|||
return STREAM_STATE_ERROR;
|
||||
}
|
||||
|
||||
static void stream_unget(stream_t *stream, int c)
|
||||
{
|
||||
static void stream_unget(stream_t *stream, int c) {
|
||||
if (c == STREAM_STATE_EOF || c == STREAM_STATE_ERROR)
|
||||
return;
|
||||
|
||||
|
@ -229,31 +225,26 @@ static void stream_unget(stream_t *stream, int c)
|
|||
}
|
||||
|
||||
|
||||
static int lex_get(lex_t *lex, json_error_t *error)
|
||||
{
|
||||
static int lex_get(lex_t *lex, json_error_t *error) {
|
||||
return stream_get(&lex->stream, error);
|
||||
}
|
||||
|
||||
static void lex_save(lex_t *lex, int c)
|
||||
{
|
||||
static void lex_save(lex_t *lex, int c) {
|
||||
strbuffer_append_byte(&lex->saved_text, c);
|
||||
}
|
||||
|
||||
static int lex_get_save(lex_t *lex, json_error_t *error)
|
||||
{
|
||||
static int lex_get_save(lex_t *lex, json_error_t *error) {
|
||||
int c = stream_get(&lex->stream, error);
|
||||
if (c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR)
|
||||
lex_save(lex, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
static void lex_unget(lex_t *lex, int c)
|
||||
{
|
||||
static void lex_unget(lex_t *lex, int c) {
|
||||
stream_unget(&lex->stream, c);
|
||||
}
|
||||
|
||||
static void lex_unget_unsave(lex_t *lex, int c)
|
||||
{
|
||||
static void lex_unget_unsave(lex_t *lex, int c) {
|
||||
if (c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) {
|
||||
/* Since we treat warnings as errors, when assertions are turned
|
||||
* off the "d" variable would be set but never used. Which is
|
||||
|
@ -271,8 +262,7 @@ static void lex_unget_unsave(lex_t *lex, int c)
|
|||
}
|
||||
}
|
||||
|
||||
static void lex_save_cached(lex_t *lex)
|
||||
{
|
||||
static void lex_save_cached(lex_t *lex) {
|
||||
while (lex->stream.buffer[lex->stream.buffer_pos] != '\0') {
|
||||
lex_save(lex, lex->stream.buffer[lex->stream.buffer_pos]);
|
||||
lex->stream.buffer_pos++;
|
||||
|
@ -280,16 +270,14 @@ static void lex_save_cached(lex_t *lex)
|
|||
}
|
||||
}
|
||||
|
||||
static void lex_free_string(lex_t *lex)
|
||||
{
|
||||
static void lex_free_string(lex_t *lex) {
|
||||
jsonp_free(lex->value.string.val);
|
||||
lex->value.string.val = NULL;
|
||||
lex->value.string.len = 0;
|
||||
}
|
||||
|
||||
/* assumes that str points to 'u' plus at least 4 valid hex digits */
|
||||
static int32_t decode_unicode_escape(const char *str)
|
||||
{
|
||||
static int32_t decode_unicode_escape(const char *str) {
|
||||
int i;
|
||||
int32_t value = 0;
|
||||
|
||||
|
@ -311,8 +299,7 @@ static int32_t decode_unicode_escape(const char *str)
|
|||
return value;
|
||||
}
|
||||
|
||||
static void lex_scan_string(lex_t *lex, json_error_t *error)
|
||||
{
|
||||
static void lex_scan_string(lex_t *lex, json_error_t *error) {
|
||||
int c;
|
||||
const char *p;
|
||||
char *t;
|
||||
|
@ -485,8 +472,7 @@ out:
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
|
||||
{
|
||||
static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
|
||||
const char *saved_text;
|
||||
char *end;
|
||||
double doubleval;
|
||||
|
@ -512,7 +498,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
|
|||
}
|
||||
|
||||
if (!(lex->flags & JSON_DECODE_INT_AS_REAL) &&
|
||||
c != '.' && c != 'E' && c != 'e') {
|
||||
c != '.' && c != 'E' && c != 'e') {
|
||||
json_int_t intval;
|
||||
|
||||
lex_unget_unsave(lex, c);
|
||||
|
@ -579,8 +565,7 @@ out:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int lex_scan(lex_t *lex, json_error_t *error)
|
||||
{
|
||||
static int lex_scan(lex_t *lex, json_error_t *error) {
|
||||
int c;
|
||||
|
||||
strbuffer_clear(&lex->saved_text);
|
||||
|
@ -647,8 +632,7 @@ out:
|
|||
return lex->token;
|
||||
}
|
||||
|
||||
static char *lex_steal_string(lex_t *lex, size_t *out_len)
|
||||
{
|
||||
static char *lex_steal_string(lex_t *lex, size_t *out_len) {
|
||||
char *result = NULL;
|
||||
if (lex->token == TOKEN_STRING) {
|
||||
result = lex->value.string.val;
|
||||
|
@ -659,8 +643,7 @@ static char *lex_steal_string(lex_t *lex, size_t *out_len)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int lex_init(lex_t *lex, get_func get, size_t flags, void *data)
|
||||
{
|
||||
static int lex_init(lex_t *lex, get_func get, size_t flags, void *data) {
|
||||
stream_init(&lex->stream, get, data);
|
||||
if (strbuffer_init(&lex->saved_text))
|
||||
return -1;
|
||||
|
@ -670,8 +653,7 @@ static int lex_init(lex_t *lex, get_func get, size_t flags, void *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void lex_close(lex_t *lex)
|
||||
{
|
||||
static void lex_close(lex_t *lex) {
|
||||
if (lex->token == TOKEN_STRING)
|
||||
lex_free_string(lex);
|
||||
strbuffer_close(&lex->saved_text);
|
||||
|
@ -682,8 +664,7 @@ static void lex_close(lex_t *lex)
|
|||
|
||||
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error);
|
||||
|
||||
static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error)
|
||||
{
|
||||
static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
|
||||
json_t *object = json_object();
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
@ -759,8 +740,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error)
|
||||
{
|
||||
static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error) {
|
||||
json_t *array = json_array();
|
||||
if (!array)
|
||||
return NULL;
|
||||
|
@ -797,8 +777,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
|
||||
{
|
||||
static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
|
||||
json_t *json;
|
||||
|
||||
lex->depth++;
|
||||
|
@ -871,8 +850,7 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
|
|||
return json;
|
||||
}
|
||||
|
||||
static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error)
|
||||
{
|
||||
static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error) {
|
||||
json_t *result;
|
||||
|
||||
lex->depth = 0;
|
||||
|
@ -911,8 +889,7 @@ typedef struct {
|
|||
size_t pos;
|
||||
} string_data_t;
|
||||
|
||||
static int string_get(void *data)
|
||||
{
|
||||
static int string_get(void *data) {
|
||||
char c;
|
||||
string_data_t *stream = (string_data_t *)data;
|
||||
c = stream->data[stream->pos];
|
||||
|
@ -924,8 +901,7 @@ static int string_get(void *data)
|
|||
}
|
||||
}
|
||||
|
||||
json_t *json_loads(const char *string, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_loads(const char *string, size_t flags, json_error_t *error) {
|
||||
lex_t lex;
|
||||
json_t *result;
|
||||
string_data_t stream_data;
|
||||
|
@ -955,8 +931,7 @@ typedef struct {
|
|||
size_t pos;
|
||||
} buffer_data_t;
|
||||
|
||||
static int buffer_get(void *data)
|
||||
{
|
||||
static int buffer_get(void *data) {
|
||||
char c;
|
||||
buffer_data_t *stream = data;
|
||||
if (stream->pos >= stream->len)
|
||||
|
@ -967,8 +942,7 @@ static int buffer_get(void *data)
|
|||
return (unsigned char)c;
|
||||
}
|
||||
|
||||
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error) {
|
||||
lex_t lex;
|
||||
json_t *result;
|
||||
buffer_data_t stream_data;
|
||||
|
@ -993,8 +967,7 @@ json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t
|
|||
return result;
|
||||
}
|
||||
|
||||
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) {
|
||||
lex_t lex;
|
||||
const char *source;
|
||||
json_t *result;
|
||||
|
@ -1020,8 +993,7 @@ json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int fd_get_func(int *fd)
|
||||
{
|
||||
static int fd_get_func(int *fd) {
|
||||
#ifdef HAVE_UNISTD_H
|
||||
uint8_t c;
|
||||
if (read(*fd, &c, 1) == 1)
|
||||
|
@ -1030,8 +1002,7 @@ static int fd_get_func(int *fd)
|
|||
return EOF;
|
||||
}
|
||||
|
||||
json_t *json_loadfd(int input, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_loadfd(int input, size_t flags, json_error_t *error) {
|
||||
lex_t lex;
|
||||
const char *source;
|
||||
json_t *result;
|
||||
|
@ -1059,8 +1030,7 @@ json_t *json_loadfd(int input, size_t flags, json_error_t *error)
|
|||
return result;
|
||||
}
|
||||
|
||||
json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_load_file(const char *path, size_t flags, json_error_t *error) {
|
||||
json_t *result;
|
||||
FILE *fp;
|
||||
|
||||
|
@ -1094,8 +1064,7 @@ typedef struct {
|
|||
void *arg;
|
||||
} callback_data_t;
|
||||
|
||||
static int callback_get(void *data)
|
||||
{
|
||||
static int callback_get(void *data) {
|
||||
char c;
|
||||
callback_data_t *stream = data;
|
||||
|
||||
|
@ -1111,8 +1080,7 @@ static int callback_get(void *data)
|
|||
return (unsigned char)c;
|
||||
}
|
||||
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error)
|
||||
{
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error) {
|
||||
lex_t lex;
|
||||
json_t *result;
|
||||
|
||||
|
|
|
@ -193,8 +193,7 @@ acceptable. Do NOT use for cryptographic purposes.
|
|||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
|
||||
{
|
||||
static uint32_t hashlittle(const void *key, size_t length, uint32_t initval) {
|
||||
uint32_t a, b, c; /* internal state */
|
||||
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
|
||||
|
||||
|
|
|
@ -20,29 +20,25 @@
|
|||
static json_malloc_t do_malloc = malloc;
|
||||
static json_free_t do_free = free;
|
||||
|
||||
void *jsonp_malloc(size_t size)
|
||||
{
|
||||
void *jsonp_malloc(size_t size) {
|
||||
if (!size)
|
||||
return NULL;
|
||||
|
||||
return (*do_malloc)(size);
|
||||
}
|
||||
|
||||
void jsonp_free(void *ptr)
|
||||
{
|
||||
void jsonp_free(void *ptr) {
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
(*do_free)(ptr);
|
||||
}
|
||||
|
||||
char *jsonp_strdup(const char *str)
|
||||
{
|
||||
char *jsonp_strdup(const char *str) {
|
||||
return jsonp_strndup(str, strlen(str));
|
||||
}
|
||||
|
||||
char *jsonp_strndup(const char *str, size_t len)
|
||||
{
|
||||
char *jsonp_strndup(const char *str, size_t len) {
|
||||
char *new_str;
|
||||
|
||||
new_str = jsonp_malloc(len + 1);
|
||||
|
@ -54,14 +50,12 @@ char *jsonp_strndup(const char *str, size_t len)
|
|||
return new_str;
|
||||
}
|
||||
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn)
|
||||
{
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) {
|
||||
do_malloc = malloc_fn;
|
||||
do_free = free_fn;
|
||||
}
|
||||
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn)
|
||||
{
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn) {
|
||||
if (malloc_fn)
|
||||
*malloc_fn = do_malloc;
|
||||
if (free_fn)
|
||||
|
|
|
@ -50,8 +50,7 @@ static const char *const type_names[] = {
|
|||
static const char unpack_value_starters[] = "{[siIbfFOon";
|
||||
|
||||
static void scanner_init(scanner_t *s, json_error_t *error,
|
||||
size_t flags, const char *fmt)
|
||||
{
|
||||
size_t flags, const char *fmt) {
|
||||
s->error = error;
|
||||
s->flags = flags;
|
||||
s->fmt = s->start = fmt;
|
||||
|
@ -64,8 +63,7 @@ static void scanner_init(scanner_t *s, json_error_t *error,
|
|||
s->has_error = 0;
|
||||
}
|
||||
|
||||
static void next_token(scanner_t *s)
|
||||
{
|
||||
static void next_token(scanner_t *s) {
|
||||
const char *t;
|
||||
s->prev_token = s->token;
|
||||
|
||||
|
@ -103,15 +101,13 @@ static void next_token(scanner_t *s)
|
|||
s->fmt = t;
|
||||
}
|
||||
|
||||
static void prev_token(scanner_t *s)
|
||||
{
|
||||
static void prev_token(scanner_t *s) {
|
||||
s->next_token = s->token;
|
||||
s->token = s->prev_token;
|
||||
}
|
||||
|
||||
static void set_error(scanner_t *s, const char *source, enum json_error_code code,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
|
@ -129,8 +125,7 @@ static json_t *pack(scanner_t *s, va_list *ap);
|
|||
/* ours will be set to 1 if jsonp_free() must be called for the result
|
||||
afterwards */
|
||||
static char *read_string(scanner_t *s, va_list *ap,
|
||||
const char *purpose, size_t *out_len, int *ours, int optional)
|
||||
{
|
||||
const char *purpose, size_t *out_len, int *ours, int optional) {
|
||||
char t;
|
||||
strbuffer_t strbuff;
|
||||
const char *str;
|
||||
|
@ -222,8 +217,7 @@ static char *read_string(scanner_t *s, va_list *ap,
|
|||
return strbuffer_steal_value(&strbuff);
|
||||
}
|
||||
|
||||
static json_t *pack_object(scanner_t *s, va_list *ap)
|
||||
{
|
||||
static json_t *pack_object(scanner_t *s, va_list *ap) {
|
||||
json_t *object = json_object();
|
||||
next_token(s);
|
||||
|
||||
|
@ -288,8 +282,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *pack_array(scanner_t *s, va_list *ap)
|
||||
{
|
||||
static json_t *pack_array(scanner_t *s, va_list *ap) {
|
||||
json_t *array = json_array();
|
||||
next_token(s);
|
||||
|
||||
|
@ -336,8 +329,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *pack_string(scanner_t *s, va_list *ap)
|
||||
{
|
||||
static json_t *pack_string(scanner_t *s, va_list *ap) {
|
||||
char *str;
|
||||
char t;
|
||||
size_t len;
|
||||
|
@ -366,8 +358,7 @@ static json_t *pack_string(scanner_t *s, va_list *ap)
|
|||
return json_stringn_nocheck(str, len);
|
||||
}
|
||||
|
||||
static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref)
|
||||
{
|
||||
static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref) {
|
||||
json_t *json;
|
||||
char ntoken;
|
||||
|
||||
|
@ -396,8 +387,7 @@ static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *pack_integer(scanner_t *s, json_int_t value)
|
||||
{
|
||||
static json_t *pack_integer(scanner_t *s, json_int_t value) {
|
||||
json_t *json = json_integer(value);
|
||||
|
||||
if (!json) {
|
||||
|
@ -408,8 +398,7 @@ static json_t *pack_integer(scanner_t *s, json_int_t value)
|
|||
return json;
|
||||
}
|
||||
|
||||
static json_t *pack_real(scanner_t *s, double value)
|
||||
{
|
||||
static json_t *pack_real(scanner_t *s, double value) {
|
||||
/* Allocate without setting value so we can identify OOM error. */
|
||||
json_t *json = json_real(0.0);
|
||||
|
||||
|
@ -432,8 +421,7 @@ static json_t *pack_real(scanner_t *s, double value)
|
|||
return json;
|
||||
}
|
||||
|
||||
static json_t *pack(scanner_t *s, va_list *ap)
|
||||
{
|
||||
static json_t *pack(scanner_t *s, va_list *ap) {
|
||||
switch (token(s)) {
|
||||
case '{':
|
||||
return pack_object(s, ap);
|
||||
|
@ -475,8 +463,7 @@ static json_t *pack(scanner_t *s, va_list *ap)
|
|||
|
||||
static int unpack(scanner_t *s, json_t *root, va_list *ap);
|
||||
|
||||
static int unpack_object(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
|
||||
int ret = -1;
|
||||
int strict = 0;
|
||||
int gotopt = 0;
|
||||
|
@ -604,8 +591,7 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int unpack_array(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
|
||||
size_t i = 0;
|
||||
int strict = 0;
|
||||
|
||||
|
@ -673,8 +659,7 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int unpack(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
static int unpack(scanner_t *s, json_t *root, va_list *ap) {
|
||||
switch (token(s)) {
|
||||
case '{':
|
||||
return unpack_object(s, root, ap);
|
||||
|
@ -824,8 +809,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap)
|
|||
}
|
||||
|
||||
json_t *json_vpack_ex(json_error_t *error, size_t flags,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
const char *fmt, va_list ap) {
|
||||
scanner_t s;
|
||||
va_list ap_copy;
|
||||
json_t *value;
|
||||
|
@ -858,8 +842,7 @@ json_t *json_vpack_ex(json_error_t *error, size_t flags,
|
|||
return value;
|
||||
}
|
||||
|
||||
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...)
|
||||
{
|
||||
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...) {
|
||||
json_t *value;
|
||||
va_list ap;
|
||||
|
||||
|
@ -870,8 +853,7 @@ json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...)
|
|||
return value;
|
||||
}
|
||||
|
||||
json_t *json_pack(const char *fmt, ...)
|
||||
{
|
||||
json_t *json_pack(const char *fmt, ...) {
|
||||
json_t *value;
|
||||
va_list ap;
|
||||
|
||||
|
@ -883,8 +865,7 @@ json_t *json_pack(const char *fmt, ...)
|
|||
}
|
||||
|
||||
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
const char *fmt, va_list ap) {
|
||||
scanner_t s;
|
||||
va_list ap_copy;
|
||||
|
||||
|
@ -920,8 +901,7 @@ int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...)
|
||||
{
|
||||
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...) {
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
|
@ -932,8 +912,7 @@ int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *
|
|||
return ret;
|
||||
}
|
||||
|
||||
int json_unpack(json_t *root, const char *fmt, ...)
|
||||
{
|
||||
int json_unpack(json_t *root, const char *fmt, ...) {
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
#include <jansson.h>
|
||||
#include "jansson_private.h"
|
||||
|
||||
json_t *json_path_get(const json_t *json, const char *path)
|
||||
{
|
||||
json_t *json_path_get(const json_t *json, const char *path) {
|
||||
static const char root_chr = '$', array_open = '[';
|
||||
static const char *path_delims = ".[", *array_close = "]";
|
||||
const json_t *cursor;
|
||||
|
@ -68,8 +67,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int json_path_set_new(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error)
|
||||
{
|
||||
int json_path_set_new(json_t *json, const char *path, json_t *value, size_t flags, json_error_t *error) {
|
||||
static const char root_chr = '$', array_open = '[', object_delim = '.';
|
||||
static const char *const path_delims = ".[", *array_close = "]";
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
#define STRBUFFER_FACTOR 2
|
||||
#define STRBUFFER_SIZE_MAX ((size_t)-1)
|
||||
|
||||
int strbuffer_init(strbuffer_t *strbuff)
|
||||
{
|
||||
int strbuffer_init(strbuffer_t *strbuff) {
|
||||
strbuff->size = STRBUFFER_MIN_SIZE;
|
||||
strbuff->length = 0;
|
||||
|
||||
|
@ -32,8 +31,7 @@ int strbuffer_init(strbuffer_t *strbuff)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void strbuffer_close(strbuffer_t *strbuff)
|
||||
{
|
||||
void strbuffer_close(strbuffer_t *strbuff) {
|
||||
if (strbuff->value)
|
||||
jsonp_free(strbuff->value);
|
||||
|
||||
|
@ -42,39 +40,34 @@ void strbuffer_close(strbuffer_t *strbuff)
|
|||
strbuff->value = NULL;
|
||||
}
|
||||
|
||||
void strbuffer_clear(strbuffer_t *strbuff)
|
||||
{
|
||||
void strbuffer_clear(strbuffer_t *strbuff) {
|
||||
strbuff->length = 0;
|
||||
strbuff->value[0] = '\0';
|
||||
}
|
||||
|
||||
const char *strbuffer_value(const strbuffer_t *strbuff)
|
||||
{
|
||||
const char *strbuffer_value(const strbuffer_t *strbuff) {
|
||||
return strbuff->value;
|
||||
}
|
||||
|
||||
char *strbuffer_steal_value(strbuffer_t *strbuff)
|
||||
{
|
||||
char *strbuffer_steal_value(strbuffer_t *strbuff) {
|
||||
char *result = strbuff->value;
|
||||
strbuff->value = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
int strbuffer_append_byte(strbuffer_t *strbuff, char byte)
|
||||
{
|
||||
int strbuffer_append_byte(strbuffer_t *strbuff, char byte) {
|
||||
return strbuffer_append_bytes(strbuff, &byte, 1);
|
||||
}
|
||||
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
||||
{
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) {
|
||||
if (size >= strbuff->size - strbuff->length) {
|
||||
size_t new_size;
|
||||
char *new_value;
|
||||
|
||||
/* avoid integer overflow */
|
||||
if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR
|
||||
|| size > STRBUFFER_SIZE_MAX - 1
|
||||
|| strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
|
||||
|| size > STRBUFFER_SIZE_MAX - 1
|
||||
|| strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
|
||||
return -1;
|
||||
|
||||
new_size = max(strbuff->size * STRBUFFER_FACTOR,
|
||||
|
@ -98,8 +91,7 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
char strbuffer_pop(strbuffer_t *strbuff)
|
||||
{
|
||||
char strbuffer_pop(strbuffer_t *strbuff) {
|
||||
if (strbuff->length > 0) {
|
||||
char c = strbuff->value[--strbuff->length];
|
||||
strbuff->value[strbuff->length] = '\0';
|
||||
|
|
|
@ -31,8 +31,7 @@
|
|||
this way. Multi-threaded programs should use uselocale() instead.
|
||||
*/
|
||||
|
||||
static void to_locale(strbuffer_t *strbuffer)
|
||||
{
|
||||
static void to_locale(strbuffer_t *strbuffer) {
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
|
@ -47,8 +46,7 @@ static void to_locale(strbuffer_t *strbuffer)
|
|||
*pos = *point;
|
||||
}
|
||||
|
||||
static void from_locale(char *buffer)
|
||||
{
|
||||
static void from_locale(char *buffer) {
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
|
@ -64,8 +62,7 @@ static void from_locale(char *buffer)
|
|||
}
|
||||
#endif
|
||||
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out)
|
||||
{
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out) {
|
||||
double value;
|
||||
char *end;
|
||||
|
||||
|
@ -86,8 +83,7 @@ int jsonp_strtod(strbuffer_t *strbuffer, double *out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
|
||||
{
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value, int precision) {
|
||||
int ret;
|
||||
char *start, *end;
|
||||
size_t length;
|
||||
|
@ -110,7 +106,7 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
|
|||
/* Make sure there's a dot or 'e' in the output. Otherwise
|
||||
a real is converted to an integer when decoding */
|
||||
if (strchr(buffer, '.') == NULL &&
|
||||
strchr(buffer, 'e') == NULL) {
|
||||
strchr(buffer, 'e') == NULL) {
|
||||
if (length + 3 >= size) {
|
||||
/* No space to append ".0" */
|
||||
return -1;
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#include <string.h>
|
||||
#include "utf.h"
|
||||
|
||||
int utf8_encode(int32_t codepoint, char *buffer, size_t *size)
|
||||
{
|
||||
int utf8_encode(int32_t codepoint, char *buffer, size_t *size) {
|
||||
if (codepoint < 0)
|
||||
return -1;
|
||||
else if (codepoint < 0x80) {
|
||||
|
@ -36,8 +35,7 @@ int utf8_encode(int32_t codepoint, char *buffer, size_t *size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t utf8_check_first(char byte)
|
||||
{
|
||||
size_t utf8_check_first(char byte) {
|
||||
unsigned char u = (unsigned char)byte;
|
||||
|
||||
if (u < 0x80)
|
||||
|
@ -68,8 +66,7 @@ size_t utf8_check_first(char byte)
|
|||
}
|
||||
}
|
||||
|
||||
size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint)
|
||||
{
|
||||
size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint) {
|
||||
size_t i;
|
||||
int32_t value = 0;
|
||||
unsigned char u = (unsigned char)buffer[0];
|
||||
|
@ -117,8 +114,7 @@ size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint)
|
|||
return 1;
|
||||
}
|
||||
|
||||
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint)
|
||||
{
|
||||
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint) {
|
||||
size_t count;
|
||||
int32_t value;
|
||||
|
||||
|
@ -142,8 +138,7 @@ const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint)
|
|||
return buffer + count;
|
||||
}
|
||||
|
||||
int utf8_check_string(const char *string, size_t length)
|
||||
{
|
||||
int utf8_check_string(const char *string, size_t length) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
|
|
|
@ -37,8 +37,7 @@ static JSON_INLINE int isnan(double x) { return x != x; }
|
|||
static JSON_INLINE int isinf(double x) { return !isnan(x) && isnan(x - x); }
|
||||
#endif
|
||||
|
||||
static JSON_INLINE void json_init(json_t *json, json_type type)
|
||||
{
|
||||
static JSON_INLINE void json_init(json_t *json, json_type type) {
|
||||
json->type = type;
|
||||
json->refcount = 1;
|
||||
}
|
||||
|
@ -48,8 +47,7 @@ static JSON_INLINE void json_init(json_t *json, json_type type)
|
|||
|
||||
extern volatile uint32_t hashtable_seed;
|
||||
|
||||
json_t *json_object(void)
|
||||
{
|
||||
json_t *json_object(void) {
|
||||
json_object_t *object = jsonp_malloc(sizeof(json_object_t));
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
@ -69,14 +67,12 @@ json_t *json_object(void)
|
|||
return &object->json;
|
||||
}
|
||||
|
||||
static void json_delete_object(json_object_t *object)
|
||||
{
|
||||
static void json_delete_object(json_object_t *object) {
|
||||
hashtable_close(&object->hashtable);
|
||||
jsonp_free(object);
|
||||
}
|
||||
|
||||
size_t json_object_size(const json_t *json)
|
||||
{
|
||||
size_t json_object_size(const json_t *json) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!json_is_object(json))
|
||||
|
@ -86,8 +82,7 @@ size_t json_object_size(const json_t *json)
|
|||
return object->hashtable.size;
|
||||
}
|
||||
|
||||
json_t *json_object_get(const json_t *json, const char *key)
|
||||
{
|
||||
json_t *json_object_get(const json_t *json, const char *key) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!key || !json_is_object(json))
|
||||
|
@ -97,8 +92,7 @@ json_t *json_object_get(const json_t *json, const char *key)
|
|||
return hashtable_get(&object->hashtable, key);
|
||||
}
|
||||
|
||||
int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value)
|
||||
{
|
||||
int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!value)
|
||||
|
@ -118,8 +112,7 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_object_set_new(json_t *json, const char *key, json_t *value)
|
||||
{
|
||||
int json_object_set_new(json_t *json, const char *key, json_t *value) {
|
||||
if (!key || !utf8_check_string(key, strlen(key))) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
|
@ -128,8 +121,7 @@ int json_object_set_new(json_t *json, const char *key, json_t *value)
|
|||
return json_object_set_new_nocheck(json, key, value);
|
||||
}
|
||||
|
||||
int json_object_del(json_t *json, const char *key)
|
||||
{
|
||||
int json_object_del(json_t *json, const char *key) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!key || !json_is_object(json))
|
||||
|
@ -139,8 +131,7 @@ int json_object_del(json_t *json, const char *key)
|
|||
return hashtable_del(&object->hashtable, key);
|
||||
}
|
||||
|
||||
int json_object_clear(json_t *json)
|
||||
{
|
||||
int json_object_clear(json_t *json) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!json_is_object(json))
|
||||
|
@ -152,8 +143,7 @@ int json_object_clear(json_t *json)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_object_update(json_t *object, json_t *other)
|
||||
{
|
||||
int json_object_update(json_t *object, json_t *other) {
|
||||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
|
@ -168,8 +158,7 @@ int json_object_update(json_t *object, json_t *other)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_object_update_existing(json_t *object, json_t *other)
|
||||
{
|
||||
int json_object_update_existing(json_t *object, json_t *other) {
|
||||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
|
@ -184,8 +173,7 @@ int json_object_update_existing(json_t *object, json_t *other)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_object_update_missing(json_t *object, json_t *other)
|
||||
{
|
||||
int json_object_update_missing(json_t *object, json_t *other) {
|
||||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
|
@ -200,8 +188,7 @@ int json_object_update_missing(json_t *object, json_t *other)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *json_object_iter(json_t *json)
|
||||
{
|
||||
void *json_object_iter(json_t *json) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!json_is_object(json))
|
||||
|
@ -211,8 +198,7 @@ void *json_object_iter(json_t *json)
|
|||
return hashtable_iter(&object->hashtable);
|
||||
}
|
||||
|
||||
void *json_object_iter_at(json_t *json, const char *key)
|
||||
{
|
||||
void *json_object_iter_at(json_t *json, const char *key) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!key || !json_is_object(json))
|
||||
|
@ -222,8 +208,7 @@ void *json_object_iter_at(json_t *json, const char *key)
|
|||
return hashtable_iter_at(&object->hashtable, key);
|
||||
}
|
||||
|
||||
void *json_object_iter_next(json_t *json, void *iter)
|
||||
{
|
||||
void *json_object_iter_next(json_t *json, void *iter) {
|
||||
json_object_t *object;
|
||||
|
||||
if (!json_is_object(json) || iter == NULL)
|
||||
|
@ -233,24 +218,21 @@ void *json_object_iter_next(json_t *json, void *iter)
|
|||
return hashtable_iter_next(&object->hashtable, iter);
|
||||
}
|
||||
|
||||
const char *json_object_iter_key(void *iter)
|
||||
{
|
||||
const char *json_object_iter_key(void *iter) {
|
||||
if (!iter)
|
||||
return NULL;
|
||||
|
||||
return hashtable_iter_key(iter);
|
||||
}
|
||||
|
||||
json_t *json_object_iter_value(void *iter)
|
||||
{
|
||||
json_t *json_object_iter_value(void *iter) {
|
||||
if (!iter)
|
||||
return NULL;
|
||||
|
||||
return (json_t *)hashtable_iter_value(iter);
|
||||
}
|
||||
|
||||
int json_object_iter_set_new(json_t *json, void *iter, json_t *value)
|
||||
{
|
||||
int json_object_iter_set_new(json_t *json, void *iter, json_t *value) {
|
||||
if (!json_is_object(json) || !iter || !value) {
|
||||
json_decref(value);
|
||||
return -1;
|
||||
|
@ -260,16 +242,14 @@ int json_object_iter_set_new(json_t *json, void *iter, json_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *json_object_key_to_iter(const char *key)
|
||||
{
|
||||
void *json_object_key_to_iter(const char *key) {
|
||||
if (!key)
|
||||
return NULL;
|
||||
|
||||
return hashtable_key_to_iter(key);
|
||||
}
|
||||
|
||||
static int json_object_equal(const json_t *object1, const json_t *object2)
|
||||
{
|
||||
static int json_object_equal(const json_t *object1, const json_t *object2) {
|
||||
const char *key;
|
||||
const json_t *value1, *value2;
|
||||
|
||||
|
@ -286,8 +266,7 @@ static int json_object_equal(const json_t *object1, const json_t *object2)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static json_t *json_object_copy(json_t *object)
|
||||
{
|
||||
static json_t *json_object_copy(json_t *object) {
|
||||
json_t *result;
|
||||
|
||||
const char *key;
|
||||
|
@ -303,8 +282,7 @@ static json_t *json_object_copy(json_t *object)
|
|||
return result;
|
||||
}
|
||||
|
||||
static json_t *json_object_deep_copy(const json_t *object)
|
||||
{
|
||||
static json_t *json_object_deep_copy(const json_t *object) {
|
||||
json_t *result;
|
||||
void *iter;
|
||||
|
||||
|
@ -331,8 +309,7 @@ static json_t *json_object_deep_copy(const json_t *object)
|
|||
|
||||
/*** array ***/
|
||||
|
||||
json_t *json_array(void)
|
||||
{
|
||||
json_t *json_array(void) {
|
||||
json_array_t *array = jsonp_malloc(sizeof(json_array_t));
|
||||
if (!array)
|
||||
return NULL;
|
||||
|
@ -350,8 +327,7 @@ json_t *json_array(void)
|
|||
return &array->json;
|
||||
}
|
||||
|
||||
static void json_delete_array(json_array_t *array)
|
||||
{
|
||||
static void json_delete_array(json_array_t *array) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < array->entries; i++)
|
||||
|
@ -361,16 +337,14 @@ static void json_delete_array(json_array_t *array)
|
|||
jsonp_free(array);
|
||||
}
|
||||
|
||||
size_t json_array_size(const json_t *json)
|
||||
{
|
||||
size_t json_array_size(const json_t *json) {
|
||||
if (!json_is_array(json))
|
||||
return 0;
|
||||
|
||||
return json_to_array(json)->entries;
|
||||
}
|
||||
|
||||
json_t *json_array_get(const json_t *json, size_t index)
|
||||
{
|
||||
json_t *json_array_get(const json_t *json, size_t index) {
|
||||
json_array_t *array;
|
||||
if (!json_is_array(json))
|
||||
return NULL;
|
||||
|
@ -382,8 +356,7 @@ json_t *json_array_get(const json_t *json, size_t index)
|
|||
return array->table[index];
|
||||
}
|
||||
|
||||
int json_array_set_new(json_t *json, size_t index, json_t *value)
|
||||
{
|
||||
int json_array_set_new(json_t *json, size_t index, json_t *value) {
|
||||
json_array_t *array;
|
||||
|
||||
if (!value)
|
||||
|
@ -407,22 +380,19 @@ int json_array_set_new(json_t *json, size_t index, json_t *value)
|
|||
}
|
||||
|
||||
static void array_move(json_array_t *array, size_t dest,
|
||||
size_t src, size_t count)
|
||||
{
|
||||
size_t src, size_t count) {
|
||||
memmove(&array->table[dest], &array->table[src], count * sizeof(json_t *));
|
||||
}
|
||||
|
||||
static void array_copy(json_t **dest, size_t dpos,
|
||||
json_t **src, size_t spos,
|
||||
size_t count)
|
||||
{
|
||||
size_t count) {
|
||||
memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *));
|
||||
}
|
||||
|
||||
static json_t **json_array_grow(json_array_t *array,
|
||||
size_t amount,
|
||||
int copy)
|
||||
{
|
||||
int copy) {
|
||||
size_t new_size;
|
||||
json_t **old_table, **new_table;
|
||||
|
||||
|
@ -448,8 +418,7 @@ static json_t **json_array_grow(json_array_t *array,
|
|||
return old_table;
|
||||
}
|
||||
|
||||
int json_array_append_new(json_t *json, json_t *value)
|
||||
{
|
||||
int json_array_append_new(json_t *json, json_t *value) {
|
||||
json_array_t *array;
|
||||
|
||||
if (!value)
|
||||
|
@ -472,8 +441,7 @@ int json_array_append_new(json_t *json, json_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_array_insert_new(json_t *json, size_t index, json_t *value)
|
||||
{
|
||||
int json_array_insert_new(json_t *json, size_t index, json_t *value) {
|
||||
json_array_t *array;
|
||||
json_t **old_table;
|
||||
|
||||
|
@ -511,8 +479,7 @@ int json_array_insert_new(json_t *json, size_t index, json_t *value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_array_remove(json_t *json, size_t index)
|
||||
{
|
||||
int json_array_remove(json_t *json, size_t index) {
|
||||
json_array_t *array;
|
||||
|
||||
if (!json_is_array(json))
|
||||
|
@ -533,8 +500,7 @@ int json_array_remove(json_t *json, size_t index)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_array_clear(json_t *json)
|
||||
{
|
||||
int json_array_clear(json_t *json) {
|
||||
json_array_t *array;
|
||||
size_t i;
|
||||
|
||||
|
@ -549,8 +515,7 @@ int json_array_clear(json_t *json)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_array_extend(json_t *json, json_t *other_json)
|
||||
{
|
||||
int json_array_extend(json_t *json, json_t *other_json) {
|
||||
json_array_t *array, *other;
|
||||
size_t i;
|
||||
|
||||
|
@ -571,8 +536,7 @@ int json_array_extend(json_t *json, json_t *other_json)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int json_array_equal(const json_t *array1, const json_t *array2)
|
||||
{
|
||||
static int json_array_equal(const json_t *array1, const json_t *array2) {
|
||||
size_t i, size;
|
||||
|
||||
size = json_array_size(array1);
|
||||
|
@ -592,8 +556,7 @@ static int json_array_equal(const json_t *array1, const json_t *array2)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static json_t *json_array_copy(json_t *array)
|
||||
{
|
||||
static json_t *json_array_copy(json_t *array) {
|
||||
json_t *result;
|
||||
size_t i;
|
||||
|
||||
|
@ -607,8 +570,7 @@ static json_t *json_array_copy(json_t *array)
|
|||
return result;
|
||||
}
|
||||
|
||||
static json_t *json_array_deep_copy(const json_t *array)
|
||||
{
|
||||
static json_t *json_array_deep_copy(const json_t *array) {
|
||||
json_t *result;
|
||||
size_t i;
|
||||
|
||||
|
@ -624,8 +586,7 @@ static json_t *json_array_deep_copy(const json_t *array)
|
|||
|
||||
/*** string ***/
|
||||
|
||||
static json_t *string_create(const char *value, size_t len, int own)
|
||||
{
|
||||
static json_t *string_create(const char *value, size_t len, int own) {
|
||||
char *v;
|
||||
json_string_t *string;
|
||||
|
||||
|
@ -652,67 +613,58 @@ static json_t *string_create(const char *value, size_t len, int own)
|
|||
return &string->json;
|
||||
}
|
||||
|
||||
json_t *json_string_nocheck(const char *value)
|
||||
{
|
||||
json_t *json_string_nocheck(const char *value) {
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
return string_create(value, strlen(value), 0);
|
||||
}
|
||||
|
||||
json_t *json_stringn_nocheck(const char *value, size_t len)
|
||||
{
|
||||
json_t *json_stringn_nocheck(const char *value, size_t len) {
|
||||
return string_create(value, len, 0);
|
||||
}
|
||||
|
||||
/* this is private; "steal" is not a public API concept */
|
||||
json_t *jsonp_stringn_nocheck_own(const char *value, size_t len)
|
||||
{
|
||||
json_t *jsonp_stringn_nocheck_own(const char *value, size_t len) {
|
||||
return string_create(value, len, 1);
|
||||
}
|
||||
|
||||
json_t *json_string(const char *value)
|
||||
{
|
||||
json_t *json_string(const char *value) {
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
return json_stringn(value, strlen(value));
|
||||
}
|
||||
|
||||
json_t *json_stringn(const char *value, size_t len)
|
||||
{
|
||||
json_t *json_stringn(const char *value, size_t len) {
|
||||
if (!value || !utf8_check_string(value, len))
|
||||
return NULL;
|
||||
|
||||
return json_stringn_nocheck(value, len);
|
||||
}
|
||||
|
||||
const char *json_string_value(const json_t *json)
|
||||
{
|
||||
const char *json_string_value(const json_t *json) {
|
||||
if (!json_is_string(json))
|
||||
return NULL;
|
||||
|
||||
return json_to_string(json)->value;
|
||||
}
|
||||
|
||||
size_t json_string_length(const json_t *json)
|
||||
{
|
||||
size_t json_string_length(const json_t *json) {
|
||||
if (!json_is_string(json))
|
||||
return 0;
|
||||
|
||||
return json_to_string(json)->length;
|
||||
}
|
||||
|
||||
int json_string_set_nocheck(json_t *json, const char *value)
|
||||
{
|
||||
int json_string_set_nocheck(json_t *json, const char *value) {
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
return json_string_setn_nocheck(json, value, strlen(value));
|
||||
}
|
||||
|
||||
int json_string_setn_nocheck(json_t *json, const char *value, size_t len)
|
||||
{
|
||||
int json_string_setn_nocheck(json_t *json, const char *value, size_t len) {
|
||||
char *dup;
|
||||
json_string_t *string;
|
||||
|
||||
|
@ -731,30 +683,26 @@ int json_string_setn_nocheck(json_t *json, const char *value, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int json_string_set(json_t *json, const char *value)
|
||||
{
|
||||
int json_string_set(json_t *json, const char *value) {
|
||||
if (!value)
|
||||
return -1;
|
||||
|
||||
return json_string_setn(json, value, strlen(value));
|
||||
}
|
||||
|
||||
int json_string_setn(json_t *json, const char *value, size_t len)
|
||||
{
|
||||
int json_string_setn(json_t *json, const char *value, size_t len) {
|
||||
if (!value || !utf8_check_string(value, len))
|
||||
return -1;
|
||||
|
||||
return json_string_setn_nocheck(json, value, len);
|
||||
}
|
||||
|
||||
static void json_delete_string(json_string_t *string)
|
||||
{
|
||||
static void json_delete_string(json_string_t *string) {
|
||||
jsonp_free(string->value);
|
||||
jsonp_free(string);
|
||||
}
|
||||
|
||||
static int json_string_equal(const json_t *string1, const json_t *string2)
|
||||
{
|
||||
static int json_string_equal(const json_t *string1, const json_t *string2) {
|
||||
json_string_t *s1, *s2;
|
||||
|
||||
s1 = json_to_string(string1);
|
||||
|
@ -762,16 +710,14 @@ static int json_string_equal(const json_t *string1, const json_t *string2)
|
|||
return s1->length == s2->length && !memcmp(s1->value, s2->value, s1->length);
|
||||
}
|
||||
|
||||
static json_t *json_string_copy(const json_t *string)
|
||||
{
|
||||
static json_t *json_string_copy(const json_t *string) {
|
||||
json_string_t *s;
|
||||
|
||||
s = json_to_string(string);
|
||||
return json_stringn_nocheck(s->value, s->length);
|
||||
}
|
||||
|
||||
json_t *json_vsprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
json_t *json_vsprintf(const char *fmt, va_list ap) {
|
||||
json_t *json = NULL;
|
||||
int length;
|
||||
char *buf;
|
||||
|
@ -801,8 +747,7 @@ out:
|
|||
return json;
|
||||
}
|
||||
|
||||
json_t *json_sprintf(const char *fmt, ...)
|
||||
{
|
||||
json_t *json_sprintf(const char *fmt, ...) {
|
||||
json_t *result;
|
||||
va_list ap;
|
||||
|
||||
|
@ -816,8 +761,7 @@ json_t *json_sprintf(const char *fmt, ...)
|
|||
|
||||
/*** integer ***/
|
||||
|
||||
json_t *json_integer(json_int_t value)
|
||||
{
|
||||
json_t *json_integer(json_int_t value) {
|
||||
json_integer_t *integer = jsonp_malloc(sizeof(json_integer_t));
|
||||
if (!integer)
|
||||
return NULL;
|
||||
|
@ -827,16 +771,14 @@ json_t *json_integer(json_int_t value)
|
|||
return &integer->json;
|
||||
}
|
||||
|
||||
json_int_t json_integer_value(const json_t *json)
|
||||
{
|
||||
json_int_t json_integer_value(const json_t *json) {
|
||||
if (!json_is_integer(json))
|
||||
return 0;
|
||||
|
||||
return json_to_integer(json)->value;
|
||||
}
|
||||
|
||||
int json_integer_set(json_t *json, json_int_t value)
|
||||
{
|
||||
int json_integer_set(json_t *json, json_int_t value) {
|
||||
if (!json_is_integer(json))
|
||||
return -1;
|
||||
|
||||
|
@ -845,26 +787,22 @@ int json_integer_set(json_t *json, json_int_t value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void json_delete_integer(json_integer_t *integer)
|
||||
{
|
||||
static void json_delete_integer(json_integer_t *integer) {
|
||||
jsonp_free(integer);
|
||||
}
|
||||
|
||||
static int json_integer_equal(const json_t *integer1, const json_t *integer2)
|
||||
{
|
||||
static int json_integer_equal(const json_t *integer1, const json_t *integer2) {
|
||||
return json_integer_value(integer1) == json_integer_value(integer2);
|
||||
}
|
||||
|
||||
static json_t *json_integer_copy(const json_t *integer)
|
||||
{
|
||||
static json_t *json_integer_copy(const json_t *integer) {
|
||||
return json_integer(json_integer_value(integer));
|
||||
}
|
||||
|
||||
|
||||
/*** real ***/
|
||||
|
||||
json_t *json_real(double value)
|
||||
{
|
||||
json_t *json_real(double value) {
|
||||
json_real_t *real;
|
||||
|
||||
if (isnan(value) || isinf(value))
|
||||
|
@ -879,16 +817,14 @@ json_t *json_real(double value)
|
|||
return &real->json;
|
||||
}
|
||||
|
||||
double json_real_value(const json_t *json)
|
||||
{
|
||||
double json_real_value(const json_t *json) {
|
||||
if (!json_is_real(json))
|
||||
return 0;
|
||||
|
||||
return json_to_real(json)->value;
|
||||
}
|
||||
|
||||
int json_real_set(json_t *json, double value)
|
||||
{
|
||||
int json_real_set(json_t *json, double value) {
|
||||
if (!json_is_real(json) || isnan(value) || isinf(value))
|
||||
return -1;
|
||||
|
||||
|
@ -897,26 +833,22 @@ int json_real_set(json_t *json, double value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void json_delete_real(json_real_t *real)
|
||||
{
|
||||
static void json_delete_real(json_real_t *real) {
|
||||
jsonp_free(real);
|
||||
}
|
||||
|
||||
static int json_real_equal(const json_t *real1, const json_t *real2)
|
||||
{
|
||||
static int json_real_equal(const json_t *real1, const json_t *real2) {
|
||||
return json_real_value(real1) == json_real_value(real2);
|
||||
}
|
||||
|
||||
static json_t *json_real_copy(const json_t *real)
|
||||
{
|
||||
static json_t *json_real_copy(const json_t *real) {
|
||||
return json_real(json_real_value(real));
|
||||
}
|
||||
|
||||
|
||||
/*** number ***/
|
||||
|
||||
double json_number_value(const json_t *json)
|
||||
{
|
||||
double json_number_value(const json_t *json) {
|
||||
if (json_is_integer(json))
|
||||
return (double)json_integer_value(json);
|
||||
else if (json_is_real(json))
|
||||
|
@ -928,22 +860,19 @@ double json_number_value(const json_t *json)
|
|||
|
||||
/*** simple values ***/
|
||||
|
||||
json_t *json_true(void)
|
||||
{
|
||||
json_t *json_true(void) {
|
||||
static json_t the_true = {JSON_TRUE, (size_t) -1};
|
||||
return &the_true;
|
||||
}
|
||||
|
||||
|
||||
json_t *json_false(void)
|
||||
{
|
||||
json_t *json_false(void) {
|
||||
static json_t the_false = {JSON_FALSE, (size_t) -1};
|
||||
return &the_false;
|
||||
}
|
||||
|
||||
|
||||
json_t *json_null(void)
|
||||
{
|
||||
json_t *json_null(void) {
|
||||
static json_t the_null = {JSON_NULL, (size_t) -1};
|
||||
return &the_null;
|
||||
}
|
||||
|
@ -951,8 +880,7 @@ json_t *json_null(void)
|
|||
|
||||
/*** deletion ***/
|
||||
|
||||
void json_delete(json_t *json)
|
||||
{
|
||||
void json_delete(json_t *json) {
|
||||
if (!json)
|
||||
return;
|
||||
|
||||
|
@ -982,8 +910,7 @@ void json_delete(json_t *json)
|
|||
|
||||
/*** equality ***/
|
||||
|
||||
int json_equal(const json_t *json1, const json_t *json2)
|
||||
{
|
||||
int json_equal(const json_t *json1, const json_t *json2) {
|
||||
if (!json1 || !json2)
|
||||
return 0;
|
||||
|
||||
|
@ -1013,8 +940,7 @@ int json_equal(const json_t *json1, const json_t *json2)
|
|||
|
||||
/*** copying ***/
|
||||
|
||||
json_t *json_copy(json_t *json)
|
||||
{
|
||||
json_t *json_copy(json_t *json) {
|
||||
if (!json)
|
||||
return NULL;
|
||||
|
||||
|
@ -1038,8 +964,7 @@ json_t *json_copy(json_t *json)
|
|||
}
|
||||
}
|
||||
|
||||
json_t *json_deep_copy(const json_t *json)
|
||||
{
|
||||
json_t *json_deep_copy(const json_t *json) {
|
||||
if (!json)
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue