diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-02 17:09:38 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-02 17:09:38 +0400 |
commit | f3ad9c6f1e91c9912dbe730fdec350b5fc908672 (patch) | |
tree | 005e5568431db09becaa9b67a33dfc11f80bba7f /src/json | |
parent | e6a1d22de250c10992b484635fd95a03f197f779 (diff) | |
download | rspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.tar.gz rspamd-f3ad9c6f1e91c9912dbe730fdec350b5fc908672.zip |
* Retab, no functional changes
Diffstat (limited to 'src/json')
-rw-r--r-- | src/json/dump.c | 65 | ||||
-rw-r--r-- | src/json/hashtable.c | 84 | ||||
-rw-r--r-- | src/json/load.c | 155 | ||||
-rw-r--r-- | src/json/strbuffer.c | 11 | ||||
-rw-r--r-- | src/json/utf.c | 13 | ||||
-rw-r--r-- | src/json/value.c | 99 |
6 files changed, 201 insertions, 226 deletions
diff --git a/src/json/dump.c b/src/json/dump.c index 31ad41586..f384760c5 100644 --- a/src/json/dump.c +++ b/src/json/dump.c @@ -8,12 +8,12 @@ #include "jansson.h" #include "strbuffer.h" -typedef int (*dump_func) (const char *buffer, int size, void *data); +typedef int (*dump_func) (const char *buffer, int size, void *data); struct string { - char *buffer; - int length; - int size; + char *buffer; + int length; + int size; }; static int @@ -25,21 +25,21 @@ dump_to_strbuffer (const char *buffer, int size, void *data) static int dump_to_file (const char *buffer, int size, void *data) { - FILE *dest = (FILE *) data; + FILE *dest = (FILE *) data; if (fwrite (buffer, size, 1, dest) != 1) return -1; return 0; } /* 256 spaces (the maximum indentation size) */ -static char whitespace[] = +static char whitespace[] = " "; static int dump_indent (uint32_t flags, int depth, dump_func dump, void *data) { if (JSON_INDENT (flags) > 0) { - int i, ws_count = JSON_INDENT (flags); + int i, ws_count = JSON_INDENT (flags); if (dump ("\n", 1, data)) return -1; @@ -55,16 +55,16 @@ dump_indent (uint32_t flags, int depth, dump_func dump, void *data) static int dump_string (const char *str, dump_func dump, void *data) { - const char *end; + const char *end; if (dump ("\"", 1, data)) return -1; end = str; while (1) { - const char *text; - char seq[7]; - int length; + const char *text; + char seq[7]; + int length; while (*end && *end != '\\' && *end != '"' && (*end < 0 || *end > 0x1F)) end++; @@ -121,8 +121,7 @@ dump_string (const char *str, dump_func dump, void *data) } static int -do_dump (const json_t * json, uint32_t flags, int depth, - dump_func dump, void *data) +do_dump (const json_t * json, uint32_t flags, int depth, dump_func dump, void *data) { switch (json_typeof (json)) { case JSON_NULL: @@ -136,8 +135,8 @@ do_dump (const json_t * json, uint32_t flags, int depth, case JSON_INTEGER: { - char *buffer; - int size, ret; + char *buffer; + int size, ret; size = asprintf (&buffer, "%d", json_integer_value (json)); if (size == -1) @@ -150,8 +149,8 @@ do_dump (const json_t * json, uint32_t flags, int depth, case JSON_REAL: { - char *buffer; - int size, ret; + char *buffer; + int size, ret; size = asprintf (&buffer, "%.17f", json_real_value (json)); if (size == -1) @@ -167,8 +166,8 @@ do_dump (const json_t * json, uint32_t flags, int depth, case JSON_ARRAY: { - int i; - int n = json_array_size (json); + int i; + int n = json_array_size (json); if (dump ("[", 1, data)) return -1; @@ -178,13 +177,11 @@ do_dump (const json_t * json, uint32_t flags, int depth, return -1; for (i = 0; i < n; ++i) { - if (do_dump (json_array_get (json, i), flags, depth + 1, - dump, data)) + if (do_dump (json_array_get (json, i), flags, depth + 1, dump, data)) return -1; if (i < n - 1) { - if (dump (",", 1, data) || - dump_indent (flags, depth + 1, dump, data)) + if (dump (",", 1, data) || dump_indent (flags, depth + 1, dump, data)) return -1; } else { @@ -197,7 +194,7 @@ do_dump (const json_t * json, uint32_t flags, int depth, case JSON_OBJECT: { - void *iter = json_object_iter ((json_t *) json); + void *iter = json_object_iter ((json_t *) json); if (dump ("{", 1, data)) return -1; @@ -207,18 +204,14 @@ do_dump (const json_t * json, uint32_t flags, int depth, return -1; while (iter) { - void *next = - json_object_iter_next ((json_t *) json, iter); + void *next = json_object_iter_next ((json_t *) json, iter); dump_string (json_object_iter_key (iter), dump, data); - if (dump (": ", 2, data) || - do_dump (json_object_iter_value (iter), flags, depth + 1, - dump, data)) + if (dump (": ", 2, data) || do_dump (json_object_iter_value (iter), flags, depth + 1, dump, data)) return -1; if (next) { - if (dump (",", 1, data) || - dump_indent (flags, depth + 1, dump, data)) + if (dump (",", 1, data) || dump_indent (flags, depth + 1, dump, data)) return -1; } else { @@ -238,11 +231,11 @@ do_dump (const json_t * json, uint32_t flags, int depth, } -char * +char * json_dumps (const json_t * json, uint32_t flags) { - strbuffer_t strbuff; - char *result; + strbuffer_t strbuff; + char *result; if (!json_is_array (json) && !json_is_object (json)) return NULL; @@ -276,9 +269,9 @@ json_dumpf (const json_t * json, FILE * output, uint32_t flags) int json_dump_file (const json_t * json, const char *path, uint32_t flags) { - int result; + int result; - FILE *output = fopen (path, "w"); + FILE *output = fopen (path, "w"); if (!output) return -1; diff --git a/src/json/hashtable.c b/src/json/hashtable.c index 43e851382..14a59aff1 100644 --- a/src/json/hashtable.c +++ b/src/json/hashtable.c @@ -8,8 +8,8 @@ #include "../config.h" #include "hashtable.h" -typedef struct hashtable_list list_t; -typedef struct hashtable_pair pair_t; +typedef struct hashtable_list list_t; +typedef struct hashtable_pair pair_t; typedef struct hashtable_bucket bucket_t; #define container_of(ptr_, type_, member_) \ @@ -59,14 +59,14 @@ insert_to_bucket (hashtable_t * hashtable, bucket_t * bucket, list_t * list) } } -static unsigned int primes[] = { +static unsigned int primes[] = { 5, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 }; -static const unsigned int num_primes = sizeof (primes) / sizeof (unsigned int); +static const unsigned int num_primes = sizeof (primes) / sizeof (unsigned int); static inline unsigned int num_buckets (hashtable_t * hashtable) @@ -75,12 +75,11 @@ num_buckets (hashtable_t * hashtable) } -static pair_t * -hashtable_find_pair (hashtable_t * hashtable, bucket_t * bucket, - const void *key, unsigned int hash) +static pair_t * +hashtable_find_pair (hashtable_t * hashtable, bucket_t * bucket, const void *key, unsigned int hash) { - list_t *list; - pair_t *pair; + list_t *list; + pair_t *pair; if (bucket_is_empty (hashtable, bucket)) return NULL; @@ -104,9 +103,9 @@ hashtable_find_pair (hashtable_t * hashtable, bucket_t * bucket, static int hashtable_do_del (hashtable_t * hashtable, const void *key, unsigned int hash) { - pair_t *pair; - bucket_t *bucket; - unsigned int index; + pair_t *pair; + bucket_t *bucket; + unsigned int index; index = hash % num_buckets (hashtable); bucket = &hashtable->buckets[index]; @@ -140,9 +139,9 @@ hashtable_do_del (hashtable_t * hashtable, const void *key, unsigned int hash) static int hashtable_do_rehash (hashtable_t * hashtable) { - list_t *list, *next; - pair_t *pair; - unsigned int i, index, new_size; + list_t *list, *next; + pair_t *pair; + unsigned int i, index, new_size; g_free (hashtable->buckets); @@ -154,8 +153,7 @@ hashtable_do_rehash (hashtable_t * hashtable) return -1; for (i = 0; i < num_buckets (hashtable); i++) { - hashtable->buckets[i].first = hashtable->buckets[i].last = - &hashtable->list; + hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list; } list = hashtable->list.next; @@ -172,11 +170,10 @@ hashtable_do_rehash (hashtable_t * hashtable) } -hashtable_t * -hashtable_create (key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value) +hashtable_t * +hashtable_create (key_hash_fn hash_key, key_cmp_fn cmp_keys, free_fn free_key, free_fn free_value) { - hashtable_t *hashtable = g_malloc (sizeof (hashtable_t)); + hashtable_t *hashtable = g_malloc (sizeof (hashtable_t)); if (!hashtable) return NULL; @@ -196,11 +193,9 @@ hashtable_destroy (hashtable_t * hashtable) } int -hashtable_init (hashtable_t * hashtable, - key_hash_fn hash_key, key_cmp_fn cmp_keys, - free_fn free_key, free_fn free_value) +hashtable_init (hashtable_t * hashtable, key_hash_fn hash_key, key_cmp_fn cmp_keys, free_fn free_key, free_fn free_value) { - unsigned int i; + unsigned int i; hashtable->size = 0; hashtable->num_buckets = 0; /* index to primes[] */ @@ -216,8 +211,7 @@ hashtable_init (hashtable_t * hashtable, hashtable->free_value = free_value; for (i = 0; i < num_buckets (hashtable); i++) { - hashtable->buckets[i].first = hashtable->buckets[i].last = - &hashtable->list; + hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list; } return 0; @@ -226,8 +220,8 @@ hashtable_init (hashtable_t * hashtable, void hashtable_close (hashtable_t * hashtable) { - list_t *list, *next; - pair_t *pair; + list_t *list, *next; + pair_t *pair; for (list = hashtable->list.next; list != &hashtable->list; list = next) { next = list->next; pair = list_to_pair (list); @@ -235,7 +229,7 @@ hashtable_close (hashtable_t * hashtable) hashtable->free_key (pair->key); if (hashtable->free_value) hashtable->free_value (pair->value); - g_free (pair); + g_free (pair); } g_free (hashtable->buckets); @@ -244,9 +238,9 @@ hashtable_close (hashtable_t * hashtable) int hashtable_set (hashtable_t * hashtable, void *key, void *value) { - pair_t *pair; - bucket_t *bucket; - unsigned int hash, index; + pair_t *pair; + bucket_t *bucket; + unsigned int hash, index; hash = hashtable->hash_key (key); @@ -276,12 +270,12 @@ hashtable_set (hashtable_t * hashtable, void *key, void *value) return 0; } -void * +void * hashtable_get (hashtable_t * hashtable, const void *key) { - pair_t *pair; - unsigned int hash; - bucket_t *bucket; + pair_t *pair; + unsigned int hash; + bucket_t *bucket; hash = hashtable->hash_key (key); bucket = &hashtable->buckets[hash % num_buckets (hashtable)]; @@ -296,35 +290,35 @@ hashtable_get (hashtable_t * hashtable, const void *key) int hashtable_del (hashtable_t * hashtable, const void *key) { - unsigned int hash = hashtable->hash_key (key); + unsigned int hash = hashtable->hash_key (key); return hashtable_do_del (hashtable, key, hash); } -void * +void * hashtable_iter (hashtable_t * hashtable) { return hashtable_iter_next (hashtable, &hashtable->list); } -void * +void * hashtable_iter_next (hashtable_t * hashtable, void *iter) { - list_t *list = (list_t *) iter; + list_t *list = (list_t *) iter; if (list->next == &hashtable->list) return NULL; return list->next; } -void * +void * hashtable_iter_key (void *iter) { - pair_t *pair = list_to_pair ((list_t *) iter); + pair_t *pair = list_to_pair ((list_t *) iter); return pair->key; } -void * +void * hashtable_iter_value (void *iter) { - pair_t *pair = list_to_pair ((list_t *) iter); + pair_t *pair = list_to_pair ((list_t *) iter); return pair->value; } diff --git a/src/json/load.c b/src/json/load.c index 6c6cda59e..07d0b9f8b 100644 --- a/src/json/load.c +++ b/src/json/load.c @@ -20,30 +20,30 @@ #define TOKEN_NULL 261 /* read one byte from stream, return EOF on end of file */ -typedef int (*get_func) (void *data); +typedef int (*get_func) (void *data); /* return non-zero if end of file has been reached */ -typedef int (*eof_func) (void *data); +typedef int (*eof_func) (void *data); typedef struct { - get_func get; - eof_func eof; - void *data; - int stream_pos; - char buffer[5]; - int buffer_pos; + get_func get; + eof_func eof; + void *data; + int stream_pos; + char buffer[5]; + int buffer_pos; } stream_t; typedef struct { - stream_t stream; - strbuffer_t saved_text; - int token; - int line, column; + stream_t stream; + strbuffer_t saved_text; + int token; + int line, column; union { - char *string; - int integer; - double real; + char *string; + int integer; + double real; } value; } lex_t; @@ -62,8 +62,8 @@ error_init (json_error_t * error) static void error_set (json_error_t * error, const lex_t * lex, const char *msg, ...) { - va_list ap; - char text[JSON_ERROR_TEXT_LENGTH]; + va_list ap; + char text[JSON_ERROR_TEXT_LENGTH]; if (!error || error->text[0] != '\0') { /* error already set */ @@ -75,19 +75,17 @@ error_set (json_error_t * error, const lex_t * lex, const char *msg, ...) va_end (ap); if (lex) { - const char *saved_text = strbuffer_value (&lex->saved_text); + const char *saved_text = strbuffer_value (&lex->saved_text); error->line = lex->line; if (saved_text && saved_text[0]) { if (lex->saved_text.length <= 20) { - snprintf (error->text, JSON_ERROR_TEXT_LENGTH, - "%s near '%s'", text, saved_text); + snprintf (error->text, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", text, saved_text); } else snprintf (error->text, JSON_ERROR_TEXT_LENGTH, "%s", text); } else { - snprintf (error->text, JSON_ERROR_TEXT_LENGTH, - "%s near end of file", text); + snprintf (error->text, JSON_ERROR_TEXT_LENGTH, "%s near end of file", text); } } else { @@ -113,7 +111,7 @@ stream_init (stream_t * stream, get_func get, eof_func eof, void *data) static char stream_get (stream_t * stream, json_error_t * error) { - char c; + char c; if (!stream->buffer[stream->buffer_pos]) { stream->buffer[0] = stream->get (stream->data); @@ -126,7 +124,7 @@ stream_get (stream_t * stream, json_error_t * error) if (c < 0) { /* multi-byte UTF-8 sequence */ - int i, count; + int i, count; count = utf8_check_first (c); if (!count) @@ -152,8 +150,7 @@ stream_get (stream_t * stream, json_error_t * error) return stream->buffer[stream->buffer_pos++]; out: - error_set (error, NULL, "unable to decode byte 0x%x at position %d", - (unsigned char)c, stream->stream_pos); + error_set (error, NULL, "unable to decode byte 0x%x at position %d", (unsigned char)c, stream->stream_pos); stream->buffer[0] = EOF; stream->buffer[1] = '\0'; @@ -192,7 +189,7 @@ lex_save (lex_t * lex, char c) static int lex_get_save (lex_t * lex, json_error_t * error) { - char c = stream_get (&lex->stream, error); + char c = stream_get (&lex->stream, error); lex_save (lex, c); return c; } @@ -200,7 +197,7 @@ lex_get_save (lex_t * lex, json_error_t * error) static void lex_unget_unsave (lex_t * lex, char c) { - char d; + char d; stream_unget (&lex->stream, c); d = strbuffer_pop (&lex->saved_text); g_assert (c == d); @@ -219,13 +216,13 @@ lex_save_cached (lex_t * lex) static int decode_unicode_escape (const char *str) { - int i; - int value = 0; + int i; + int value = 0; g_assert (str[0] == 'u'); for (i = 1; i <= 4; i++) { - char c = str[i]; + char c = str[i]; value <<= 4; if (g_ascii_isdigit (c)) value += c - '0'; @@ -243,10 +240,10 @@ decode_unicode_escape (const char *str) static void lex_scan_string (lex_t * lex, json_error_t * error) { - char c; - const char *p; - char *t; - int i; + char c; + const char *p; + char *t; + int i; lex->value.string = NULL; lex->token = TOKEN_INVALID; @@ -284,8 +281,7 @@ lex_scan_string (lex_t * lex, json_error_t * error) c = lex_get_save (lex, error); } } - else if (c == '"' || c == '\\' || c == '/' || c == 'b' || - c == 'f' || c == 'n' || c == 'r' || c == 't') + else if (c == '"' || c == '\\' || c == '/' || c == 'b' || c == 'f' || c == 'n' || c == 'r' || c == 't') c = lex_get_save (lex, error); else { lex_unget_unsave (lex, c); @@ -320,9 +316,9 @@ lex_scan_string (lex_t * lex, json_error_t * error) if (*p == '\\') { p++; if (*p == 'u') { - char buffer[4]; - int length; - int value; + char buffer[4]; + int length; + int value; value = decode_unicode_escape (p); p += 5; @@ -330,26 +326,22 @@ lex_scan_string (lex_t * lex, json_error_t * error) if (0xD800 <= value && value <= 0xDBFF) { /* surrogate pair */ if (*p == '\\' && *(p + 1) == 'u') { - int value2 = decode_unicode_escape (++p); + int value2 = decode_unicode_escape (++p); p += 5; if (0xDC00 <= value2 && value2 <= 0xDFFF) { /* valid second surrogate */ - value = ((value - 0xD800) << 10) + - (value2 - 0xDC00) + 0x10000; + value = ((value - 0xD800) << 10) + (value2 - 0xDC00) + 0x10000; } else { /* invalid second surrogate */ - error_set (error, lex, - "invalid Unicode '\\u%04X\\u%04X'", - value, value2); + error_set (error, lex, "invalid Unicode '\\u%04X\\u%04X'", value, value2); goto out; } } else { /* no second surrogate */ - error_set (error, lex, "invalid Unicode '\\u%04X'", - value); + error_set (error, lex, "invalid Unicode '\\u%04X'", value); goto out; } } @@ -411,8 +403,8 @@ lex_scan_string (lex_t * lex, json_error_t * error) static void lex_scan_number (lex_t * lex, char c, json_error_t * error) { - const char *saved_text; - char *end; + const char *saved_text; + char *end; lex->token = TOKEN_INVALID; @@ -484,7 +476,7 @@ lex_scan_number (lex_t * lex, char c, json_error_t * error) static int lex_scan (lex_t * lex, json_error_t * error) { - char c; + char c; strbuffer_clear (&lex->saved_text); @@ -522,7 +514,7 @@ lex_scan (lex_t * lex, json_error_t * error) else if (g_ascii_isupper (c) || g_ascii_islower (c)) { /* eat up the whole identifier for clearer error messages */ - const char *saved_text; + const char *saved_text; c = lex_get_save (lex, error); while (g_ascii_isupper (c) || g_ascii_islower (c)) @@ -552,10 +544,10 @@ lex_scan (lex_t * lex, json_error_t * error) return lex->token; } -static char * +static char * lex_steal_string (lex_t * lex) { - char *result = NULL; + char *result = NULL; if (lex->token == TOKEN_STRING) { result = lex->value.string; lex->value.string = NULL; @@ -587,12 +579,12 @@ lex_close (lex_t * lex) /*** parser ***/ -static json_t *parse_value (lex_t * lex, json_error_t * error); +static json_t *parse_value (lex_t * lex, json_error_t * error); -static json_t * +static json_t * parse_object (lex_t * lex, json_error_t * error) { - json_t *object = json_object (); + json_t *object = json_object (); if (!object) return NULL; @@ -601,8 +593,8 @@ parse_object (lex_t * lex, json_error_t * error) return object; while (1) { - char *key; - json_t *value; + char *key; + json_t *value; if (lex->token != TOKEN_STRING) { error_set (error, lex, "string or '}' expected"); @@ -655,10 +647,10 @@ parse_object (lex_t * lex, json_error_t * error) return NULL; } -static json_t * +static json_t * parse_array (lex_t * lex, json_error_t * error) { - json_t *array = json_array (); + json_t *array = json_array (); if (!array) return NULL; @@ -667,7 +659,7 @@ parse_array (lex_t * lex, json_error_t * error) return array; while (lex->token) { - json_t *elem = parse_value (lex, error); + json_t *elem = parse_value (lex, error); if (!elem) goto error; @@ -696,10 +688,10 @@ parse_array (lex_t * lex, json_error_t * error) return NULL; } -static json_t * +static json_t * parse_value (lex_t * lex, json_error_t * error) { - json_t *json; + json_t *json; switch (lex->token) { case TOKEN_STRING:{ @@ -752,7 +744,7 @@ parse_value (lex_t * lex, json_error_t * error) return json; } -json_t * +json_t * parse_json (lex_t * lex, json_error_t * error) { error_init (error); @@ -767,15 +759,15 @@ parse_json (lex_t * lex, json_error_t * error) } typedef struct { - const char *data; - int pos; + const char *data; + int pos; } string_data_t; static int string_get (void *data) { - char c; - string_data_t *stream = (string_data_t *) data; + char c; + string_data_t *stream = (string_data_t *) data; c = stream->data[stream->pos]; if (c == '\0') return EOF; @@ -788,17 +780,17 @@ string_get (void *data) static int string_eof (void *data) { - string_data_t *stream = (string_data_t *) data; + string_data_t *stream = (string_data_t *) data; return (stream->data[stream->pos] == '\0'); } -json_t * +json_t * json_loads (const char *string, json_error_t * error) { - lex_t lex; - json_t *result; + lex_t lex; + json_t *result; - string_data_t stream_data = { + string_data_t stream_data = { .data = string, .pos = 0 }; @@ -822,11 +814,11 @@ json_loads (const char *string, json_error_t * error) return result; } -json_t * +json_t * json_loadf (FILE * input, json_error_t * error) { - lex_t lex; - json_t *result; + lex_t lex; + json_t *result; if (lex_init (&lex, (get_func) fgetc, (eof_func) feof, input)) return NULL; @@ -847,16 +839,15 @@ json_loadf (FILE * input, json_error_t * error) return result; } -json_t * +json_t * json_load_file (const char *path, json_error_t * error) { - json_t *result; - FILE *fp; + json_t *result; + FILE *fp; fp = fopen (path, "r"); if (!fp) { - error_set (error, NULL, "unable to open %s: %s", - path, strerror (errno)); + error_set (error, NULL, "unable to open %s: %s", path, strerror (errno)); return NULL; } diff --git a/src/json/strbuffer.c b/src/json/strbuffer.c index 8ba7faa9a..b6afcc248 100644 --- a/src/json/strbuffer.c +++ b/src/json/strbuffer.c @@ -43,16 +43,16 @@ strbuffer_clear (strbuffer_t * strbuff) strbuff->value[0] = '\0'; } -const char * +const char * strbuffer_value (const strbuffer_t * strbuff) { return strbuff->value; } -char * +char * strbuffer_steal_value (strbuffer_t * strbuff) { - char *result = strbuff->value; + char *result = strbuff->value; strbuffer_init (strbuff); return result; } @@ -73,8 +73,7 @@ int strbuffer_append_bytes (strbuffer_t * strbuff, const char *data, int size) { if (strbuff->length + size >= strbuff->size) { - strbuff->size = max (strbuff->size * STRBUFFER_FACTOR, - strbuff->length + size + 1); + strbuff->size = max (strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1); strbuff->value = realloc (strbuff->value, strbuff->size); if (!strbuff->value) @@ -92,7 +91,7 @@ char strbuffer_pop (strbuffer_t * strbuff) { if (strbuff->length > 0) { - char c = strbuff->value[--strbuff->length]; + char c = strbuff->value[--strbuff->length]; strbuff->value[strbuff->length] = '\0'; return c; } diff --git a/src/json/utf.c b/src/json/utf.c index c9cfeaaef..b02630812 100644 --- a/src/json/utf.c +++ b/src/json/utf.c @@ -43,7 +43,7 @@ utf8_encode (int codepoint, char *buffer, int *size) int utf8_check_first (char byte) { - unsigned char u = (unsigned char)byte; + unsigned char u = (unsigned char)byte; if (u < 0x80) return 1; @@ -80,8 +80,8 @@ utf8_check_first (char byte) int utf8_check_full (const char *buffer, int size) { - int i, value = 0; - unsigned char u = (unsigned char)buffer[0]; + int i, value = 0; + unsigned char u = (unsigned char)buffer[0]; if (size == 2) { value = u & 0x1F; @@ -116,8 +116,7 @@ utf8_check_full (const char *buffer, int size) return 0; } - else if ((size == 2 && value < 0x80) || - (size == 3 && value < 0x800) || (size == 4 && value < 0x10000)) { + else if ((size == 2 && value < 0x80) || (size == 3 && value < 0x800) || (size == 4 && value < 0x10000)) { /* overlong encoding */ return 0; } @@ -128,13 +127,13 @@ utf8_check_full (const char *buffer, int size) int utf8_check_string (const char *string, int length) { - int i; + int i; if (length == -1) length = strlen (string); for (i = 0; i < length; i++) { - int count = utf8_check_first (string[i]); + int count = utf8_check_first (string[i]); if (count == 0) return 0; else if (count > 1) { diff --git a/src/json/value.c b/src/json/value.c index 9270f1f76..bb1bb9631 100644 --- a/src/json/value.c +++ b/src/json/value.c @@ -16,30 +16,30 @@ ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) typedef struct { - json_t json; - hashtable_t hashtable; + json_t json; + hashtable_t hashtable; } json_object_t; typedef struct { - json_t json; - unsigned int size; - unsigned int entries; - json_t **table; + json_t json; + unsigned int size; + unsigned int entries; + json_t **table; } json_array_t; typedef struct { - json_t json; - char *value; + json_t json; + char *value; } json_string_t; typedef struct { - json_t json; - double value; + json_t json; + double value; } json_real_t; typedef struct { - json_t json; - int value; + json_t json; + int value; } json_integer_t; #define json_to_object(json_) container_of(json_, json_object_t, json) @@ -61,9 +61,9 @@ json_init (json_t * json, json_type type) static unsigned int hash_string (const void *key) { - const char *str = (const char *)key; - unsigned int hash = 5381; - unsigned int c; + const char *str = (const char *)key; + unsigned int hash = 5381; + unsigned int c; while ((c = (unsigned int)*str)) { hash = ((hash << 5) + hash) + c; @@ -85,16 +85,15 @@ value_decref (void *value) json_decref ((json_t *) value); } -json_t * +json_t * json_object (void) { - json_object_t *object = g_malloc (sizeof (json_object_t)); + json_object_t *object = g_malloc (sizeof (json_object_t)); if (!object) return NULL; json_init (&object->json, JSON_OBJECT); - if (hashtable_init (&object->hashtable, hash_string, string_equal, - g_free, value_decref)) { + if (hashtable_init (&object->hashtable, hash_string, string_equal, g_free, value_decref)) { g_free (object); return NULL; } @@ -108,10 +107,10 @@ json_delete_object (json_object_t * object) g_free (object); } -json_t * +json_t * json_object_get (const json_t * json, const char *key) { - json_object_t *object; + json_object_t *object; if (!json_is_object (json)) return NULL; @@ -123,7 +122,7 @@ json_object_get (const json_t * json, const char *key) int json_object_set_new_nocheck (json_t * json, const char *key, json_t * value) { - json_object_t *object; + json_object_t *object; if (!key || !value) return -1; @@ -162,7 +161,7 @@ json_object_set_new (json_t * json, const char *key, json_t * value) int json_object_del (json_t * json, const char *key) { - json_object_t *object; + json_object_t *object; if (!json_is_object (json)) return -1; @@ -171,10 +170,10 @@ json_object_del (json_t * json, const char *key) return hashtable_del (&object->hashtable, key); } -void * +void * json_object_iter (json_t * json) { - json_object_t *object; + json_object_t *object; if (!json_is_object (json)) return NULL; @@ -183,10 +182,10 @@ json_object_iter (json_t * json) return hashtable_iter (&object->hashtable); } -void * +void * json_object_iter_next (json_t * json, void *iter) { - json_object_t *object; + json_object_t *object; if (!json_is_object (json) || iter == NULL) return NULL; @@ -195,7 +194,7 @@ json_object_iter_next (json_t * json, void *iter) return hashtable_iter_next (&object->hashtable, iter); } -const char * +const char * json_object_iter_key (void *iter) { if (!iter) @@ -204,7 +203,7 @@ json_object_iter_key (void *iter) return (const char *)hashtable_iter_key (iter); } -json_t * +json_t * json_object_iter_value (void *iter) { if (!iter) @@ -216,10 +215,10 @@ json_object_iter_value (void *iter) /*** array ***/ -json_t * +json_t * json_array (void) { - json_array_t *array = g_malloc (sizeof (json_array_t)); + json_array_t *array = g_malloc (sizeof (json_array_t)); if (!array) return NULL; json_init (&array->json, JSON_ARRAY); @@ -234,7 +233,7 @@ json_array (void) static void json_delete_array (json_array_t * array) { - unsigned int i; + unsigned int i; for (i = 0; i < array->entries; i++) json_decref (array->table[i]); @@ -252,10 +251,10 @@ json_array_size (const json_t * json) return json_to_array (json)->entries; } -json_t * +json_t * json_array_get (const json_t * json, unsigned int index) { - json_array_t *array; + json_array_t *array; if (!json_is_array (json)) return NULL; array = json_to_array (json); @@ -269,7 +268,7 @@ json_array_get (const json_t * json, unsigned int index) int json_array_set_new (json_t * json, unsigned int index, json_t * value) { - json_array_t *array; + json_array_t *array; if (!value) return -1; @@ -294,7 +293,7 @@ json_array_set_new (json_t * json, unsigned int index, json_t * value) int json_array_append_new (json_t * json, json_t * value) { - json_array_t *array; + json_array_t *array; if (!value) return -1; @@ -323,10 +322,10 @@ json_array_append_new (json_t * json, json_t * value) /*** string ***/ -json_t * +json_t * json_string_nocheck (const char *value) { - json_string_t *string; + json_string_t *string; if (!value) return NULL; @@ -345,7 +344,7 @@ json_string_nocheck (const char *value) return &string->json; } -json_t * +json_t * json_string (const char *value) { if (!value || !utf8_check_string (value, -1)) @@ -354,7 +353,7 @@ json_string (const char *value) return json_string_nocheck (value); } -const char * +const char * json_string_value (const json_t * json) { if (!json_is_string (json)) @@ -373,10 +372,10 @@ json_delete_string (json_string_t * string) /*** integer ***/ -json_t * +json_t * json_integer (int value) { - json_integer_t *integer = g_malloc (sizeof (json_integer_t)); + json_integer_t *integer = g_malloc (sizeof (json_integer_t)); if (!integer) return NULL; json_init (&integer->json, JSON_INTEGER); @@ -403,10 +402,10 @@ json_delete_integer (json_integer_t * integer) /*** real ***/ -json_t * +json_t * json_real (double value) { - json_real_t *real = g_malloc (sizeof (json_real_t)); + json_real_t *real = g_malloc (sizeof (json_real_t)); if (!real) return NULL; json_init (&real->json, JSON_REAL); @@ -447,10 +446,10 @@ json_number_value (const json_t * json) /*** simple values ***/ -json_t * +json_t * json_true (void) { - static json_t the_true = { + static json_t the_true = { .type = JSON_TRUE, .refcount = 1 }; @@ -458,10 +457,10 @@ json_true (void) } -json_t * +json_t * json_false (void) { - static json_t the_false = { + static json_t the_false = { .type = JSON_FALSE, .refcount = 1 }; @@ -469,10 +468,10 @@ json_false (void) } -json_t * +json_t * json_null (void) { - static json_t the_null = { + static json_t the_null = { .type = JSON_NULL, .refcount = 1 }; |