mirror of
https://github.com/tstack/lnav
synced 2024-11-01 21:40:34 +00:00
[yajl] bump to version 2.1.0
This commit is contained in:
parent
e05d42dc3f
commit
ccee7caa32
@ -311,7 +311,10 @@ void log_format::check_for_new_year(std::vector<logline> &dst,
|
||||
* XXX This needs some cleanup.
|
||||
*/
|
||||
struct json_log_userdata {
|
||||
json_log_userdata() : jlu_sub_line_count(1) { };
|
||||
json_log_userdata(shared_buffer_ref &sbr)
|
||||
: jlu_sub_line_count(1), jlu_shared_buffer(sbr) {
|
||||
|
||||
};
|
||||
|
||||
external_log_format *jlu_format;
|
||||
const logline *jlu_line;
|
||||
@ -321,6 +324,7 @@ struct json_log_userdata {
|
||||
const char *jlu_line_value;
|
||||
size_t jlu_line_size;
|
||||
size_t jlu_sub_start;
|
||||
shared_buffer_ref &jlu_shared_buffer;
|
||||
};
|
||||
|
||||
struct json_field_cmp {
|
||||
@ -565,13 +569,13 @@ bool external_log_format::scan(std::vector<logline> &dst,
|
||||
auto_mem<yajl_handle_t> handle(yajl_free);
|
||||
yajlpp_parse_context &ypc = *(this->jlf_parse_context);
|
||||
logline ll(offset, 0, 0, logline::LEVEL_INFO);
|
||||
json_log_userdata jlu;
|
||||
json_log_userdata jlu(sbr);
|
||||
bool retval = false;
|
||||
|
||||
handle = yajl_alloc(&this->jlf_parse_context->ypc_callbacks,
|
||||
NULL,
|
||||
this->jlf_parse_context.get());
|
||||
yajl_config(handle, yajl_dont_validate_strings, 0);
|
||||
yajl_config(handle, yajl_dont_validate_strings, 1);
|
||||
ypc.set_static_handler(json_log_handlers[0]);
|
||||
ypc.ypc_userdata = &jlu;
|
||||
ypc.ypc_ignore_unused = true;
|
||||
@ -808,11 +812,25 @@ static int rewrite_json_field(yajlpp_parse_context *ypc, const unsigned char *st
|
||||
if (jlu->jlu_format->lf_timestamp_field == field_name) {
|
||||
char time_buf[64];
|
||||
|
||||
// TODO add a timeval kind to logline_value
|
||||
sql_strftime(time_buf, sizeof(time_buf),
|
||||
jlu->jlu_line->get_timeval(), 'T');
|
||||
tmp_shared_buffer tsb(time_buf);
|
||||
jlu->jlu_format->jlf_line_values.push_back(logline_value(field_name, tsb.tsb_ref));
|
||||
}
|
||||
else if (jlu->jlu_shared_buffer.contains((const char *)str)) {
|
||||
shared_buffer_ref sbr;
|
||||
|
||||
sbr.subset(jlu->jlu_shared_buffer,
|
||||
(off_t) ((const char *)str - jlu->jlu_line_value),
|
||||
len);
|
||||
if (field_name == jlu->jlu_format->elf_body_field) {
|
||||
jlu->jlu_format->jlf_line_values.push_back(logline_value(body_name,
|
||||
sbr));
|
||||
}
|
||||
jlu->jlu_format->jlf_line_values.push_back(logline_value(field_name,
|
||||
sbr));
|
||||
}
|
||||
else {
|
||||
tmp_shared_buffer tsb((const char *)str, len);
|
||||
|
||||
@ -835,7 +853,7 @@ void external_log_format::get_subline(const logline &ll, shared_buffer_ref &sbr)
|
||||
auto_mem<yajl_handle_t> handle(yajl_free);
|
||||
yajlpp_parse_context &ypc = *(this->jlf_parse_context);
|
||||
view_colors &vc = view_colors::singleton();
|
||||
json_log_userdata jlu;
|
||||
json_log_userdata jlu(sbr);
|
||||
|
||||
this->jlf_share_manager.invalidate_refs();
|
||||
this->jlf_cached_line.clear();
|
||||
@ -846,7 +864,7 @@ void external_log_format::get_subline(const logline &ll, shared_buffer_ref &sbr)
|
||||
handle = yajl_alloc(&this->jlf_parse_context->ypc_callbacks,
|
||||
NULL,
|
||||
this->jlf_parse_context.get());
|
||||
yajl_config(handle, yajl_dont_validate_strings, 0);
|
||||
yajl_config(handle, yajl_dont_validate_strings, 1);
|
||||
ypc.set_static_handler(json_log_rewrite_handlers[0]);
|
||||
ypc.ypc_userdata = &jlu;
|
||||
ypc.ypc_ignore_unused = true;
|
||||
|
@ -45,7 +45,7 @@ struct exttm {
|
||||
};
|
||||
|
||||
#define PTIME_CONSUME(amount, block) \
|
||||
if (off_inout + amount > len) { \
|
||||
if ((off_inout + amount) > len) { \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
|
@ -74,6 +74,12 @@ public:
|
||||
|
||||
size_t length() const { return this->sb_length; };
|
||||
|
||||
bool contains(const char *ptr) const {
|
||||
const char *buffer_end = this->sb_data + this->sb_length;
|
||||
|
||||
return (this->sb_data <= ptr && ptr < buffer_end);
|
||||
};
|
||||
|
||||
char *get_writable_data() {
|
||||
if (this->take_ownership()) {
|
||||
return this->sb_data;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -21,14 +21,14 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YAJL_MAX_DEPTH 128
|
||||
|
||||
/* msft dll export gunk. To build a DLL on windows, you
|
||||
* must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
|
||||
* DLL, you must define YAJL_SHARED and WIN32 */
|
||||
#if defined(WIN32) && defined(YAJL_SHARED)
|
||||
#if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED)
|
||||
# ifdef YAJL_BUILD
|
||||
# define YAJL_API __declspec(dllexport)
|
||||
# else
|
||||
@ -40,7 +40,7 @@ extern "C" {
|
||||
# else
|
||||
# define YAJL_API
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** pointer to a malloc function, supporting client overriding memory
|
||||
* allocation routines */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -43,7 +43,7 @@ extern "C" {
|
||||
* state */
|
||||
yajl_gen_in_error_state,
|
||||
/** A complete JSON document has been generated */
|
||||
yajl_gen_generation_complete,
|
||||
yajl_gen_generation_complete,
|
||||
/** yajl_gen_double was passed an invalid floating point value
|
||||
* (infinity or NaN). */
|
||||
yajl_gen_invalid_number,
|
||||
@ -150,8 +150,16 @@ extern "C" {
|
||||
* intended to enable incremental JSON outputing. */
|
||||
YAJL_API void yajl_gen_clear(yajl_gen hand);
|
||||
|
||||
/** Reset the generator state. Allows a client to generate multiple
|
||||
* json entities in a stream. The "sep" string will be inserted to
|
||||
* separate the previously generated entity from the current,
|
||||
* NULL means *no separation* of entites (clients beware, generating
|
||||
* multiple JSON numbers, for instance, will result in inscrutable
|
||||
* output) */
|
||||
YAJL_API void yajl_gen_reset(yajl_gen hand, const char * sep);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -33,6 +33,10 @@
|
||||
|
||||
#include <yajl/yajl_common.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** possible data types that a yajl_val_s can hold */
|
||||
typedef enum {
|
||||
yajl_t_string = 1,
|
||||
@ -63,7 +67,7 @@ typedef struct yajl_val_s * yajl_val;
|
||||
*/
|
||||
struct yajl_val_s
|
||||
{
|
||||
/** Type of the value contained. Use the "YAJL_IS_*" macors to check for a
|
||||
/** Type of the value contained. Use the "YAJL_IS_*" macros to check for a
|
||||
* specific type. */
|
||||
yajl_type type;
|
||||
/** Type-specific data. You may use the "YAJL_GET_*" macros to access these
|
||||
@ -74,10 +78,10 @@ struct yajl_val_s
|
||||
struct {
|
||||
long long i; /*< integer value, if representable. */
|
||||
double d; /*< double value, if representable. */
|
||||
char *r; /*< unparsed number in string form. */
|
||||
/** Signals whether the \em i and \em d members are
|
||||
* valid. See \c YAJL_NUMBER_INT_VALID and
|
||||
* \c YAJL_NUMBER_DOUBLE_VALID. */
|
||||
char *r; /*< unparsed number in string form. */
|
||||
unsigned int flags;
|
||||
} number;
|
||||
struct {
|
||||
@ -117,6 +121,7 @@ struct yajl_val_s
|
||||
YAJL_API yajl_val yajl_tree_parse (const char *input,
|
||||
char *error_buffer, size_t error_buffer_size);
|
||||
|
||||
|
||||
/**
|
||||
* Free a parse tree returned by "yajl_tree_parse".
|
||||
*
|
||||
@ -133,7 +138,7 @@ YAJL_API void yajl_tree_free (yajl_val v);
|
||||
* \param type the yajl_type of the object you seek, or yajl_t_any if any will do.
|
||||
*
|
||||
* \returns a pointer to the found value, or NULL if we came up empty.
|
||||
*
|
||||
*
|
||||
* Future Ideas: it'd be nice to move path to a string and implement support for
|
||||
* a teeny tiny micro language here, so you can extract array elements, do things
|
||||
* like .first and .last, even .length. Inspiration from JSONPath and css selectors?
|
||||
@ -144,8 +149,8 @@ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type t
|
||||
/* Various convenience macros to check the type of a `yajl_val` */
|
||||
#define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
|
||||
#define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
|
||||
#define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.flags & YAJL_NUMBER_INT_VALID))
|
||||
#define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.flags & YAJL_NUMBER_DOUBLE_VALID))
|
||||
#define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
|
||||
#define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
|
||||
#define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
|
||||
#define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
|
||||
#define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
|
||||
@ -174,4 +179,8 @@ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type t
|
||||
/** Get a pointer to a yajl_val_array or NULL if the value is not an object. */
|
||||
#define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* YAJL_TREE_H */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -25,17 +25,20 @@
|
||||
|
||||
static void * yajl_internal_malloc(void *ctx, size_t sz)
|
||||
{
|
||||
(void)ctx;
|
||||
return malloc(sz);
|
||||
}
|
||||
|
||||
static void * yajl_internal_realloc(void *ctx, void * previous,
|
||||
size_t sz)
|
||||
{
|
||||
(void)ctx;
|
||||
return realloc(previous, sz);
|
||||
}
|
||||
|
||||
static void yajl_internal_free(void *ctx, void * ptr)
|
||||
{
|
||||
(void)ctx;
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -57,6 +57,7 @@ yajl_gen_config(yajl_gen g, yajl_gen_option opt, ...)
|
||||
switch(opt) {
|
||||
case yajl_gen_beautify:
|
||||
case yajl_gen_validate_utf8:
|
||||
case yajl_gen_escape_solidus:
|
||||
if (va_arg(ap, int)) g->flags |= opt;
|
||||
else g->flags &= ~opt;
|
||||
break;
|
||||
@ -124,6 +125,14 @@ yajl_gen_alloc(const yajl_alloc_funcs * afs)
|
||||
return g;
|
||||
}
|
||||
|
||||
void
|
||||
yajl_gen_reset(yajl_gen g, const char * sep)
|
||||
{
|
||||
g->depth = 0;
|
||||
memset((void *) &(g->state), 0, sizeof(g->state));
|
||||
if (sep != NULL) g->print(g->ctx, sep, strlen(sep));
|
||||
}
|
||||
|
||||
void
|
||||
yajl_gen_free(yajl_gen g)
|
||||
{
|
||||
@ -139,7 +148,7 @@ yajl_gen_free(yajl_gen g)
|
||||
} else if (g->state[g->depth] == yajl_gen_map_val) { \
|
||||
g->print(g->ctx, ":", 1); \
|
||||
if ((g->flags & yajl_gen_beautify)) g->print(g->ctx, " ", 1); \
|
||||
}
|
||||
}
|
||||
|
||||
#define INSERT_WHITESPACE \
|
||||
if ((g->flags & yajl_gen_beautify)) { \
|
||||
@ -171,7 +180,7 @@ yajl_gen_free(yajl_gen g)
|
||||
if (++(g->depth) >= YAJL_MAX_DEPTH) return yajl_max_depth_exceeded;
|
||||
|
||||
#define DECREMENT_DEPTH \
|
||||
if (--(g->depth) >= YAJL_MAX_DEPTH) return yajl_gen_error;
|
||||
if (--(g->depth) >= YAJL_MAX_DEPTH) return yajl_gen_generation_complete;
|
||||
|
||||
#define APPENDED_ATOM \
|
||||
switch (g->state[g->depth]) { \
|
||||
@ -208,7 +217,7 @@ yajl_gen_integer(yajl_gen g, long long int number)
|
||||
return yajl_gen_status_ok;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#include <float.h>
|
||||
#define isnan _isnan
|
||||
#define isinf !_finite
|
||||
@ -218,10 +227,13 @@ yajl_gen_status
|
||||
yajl_gen_double(yajl_gen g, double number)
|
||||
{
|
||||
char i[32];
|
||||
ENSURE_VALID_STATE; ENSURE_NOT_KEY;
|
||||
ENSURE_VALID_STATE; ENSURE_NOT_KEY;
|
||||
if (isnan(number) || isinf(number)) return yajl_gen_invalid_number;
|
||||
INSERT_SEP; INSERT_WHITESPACE;
|
||||
sprintf(i, "%.20g", number);
|
||||
if (strspn(i, "0123456789-") == strlen(i)) {
|
||||
strcat(i, ".0");
|
||||
}
|
||||
g->print(g->ctx, i, (unsigned int)strlen(i));
|
||||
APPENDED_ATOM;
|
||||
FINAL_NEWLINE;
|
||||
@ -285,8 +297,8 @@ yajl_gen_status
|
||||
yajl_gen_map_open(yajl_gen g)
|
||||
{
|
||||
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
||||
INCREMENT_DEPTH;
|
||||
|
||||
INCREMENT_DEPTH;
|
||||
|
||||
g->state[g->depth] = yajl_gen_map_start;
|
||||
g->print(g->ctx, "{", 1);
|
||||
if ((g->flags & yajl_gen_beautify)) g->print(g->ctx, "\n", 1);
|
||||
@ -297,9 +309,9 @@ yajl_gen_map_open(yajl_gen g)
|
||||
yajl_gen_status
|
||||
yajl_gen_map_close(yajl_gen g)
|
||||
{
|
||||
ENSURE_VALID_STATE;
|
||||
ENSURE_VALID_STATE;
|
||||
DECREMENT_DEPTH;
|
||||
|
||||
|
||||
if ((g->flags & yajl_gen_beautify)) g->print(g->ctx, "\n", 1);
|
||||
APPENDED_ATOM;
|
||||
INSERT_WHITESPACE;
|
||||
@ -312,7 +324,7 @@ yajl_gen_status
|
||||
yajl_gen_array_open(yajl_gen g)
|
||||
{
|
||||
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
||||
INCREMENT_DEPTH;
|
||||
INCREMENT_DEPTH;
|
||||
g->state[g->depth] = yajl_gen_array_start;
|
||||
g->print(g->ctx, "[", 1);
|
||||
if ((g->flags & yajl_gen_beautify)) g->print(g->ctx, "\n", 1);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
#ifdef YAJL_LEXER_DEBUG
|
||||
static const char *
|
||||
tokToStr(yajl_tok tok)
|
||||
tokToStr(yajl_tok tok)
|
||||
{
|
||||
switch (tok) {
|
||||
case yajl_tok_bool: return "bool";
|
||||
@ -53,13 +53,13 @@ tokToStr(yajl_tok tok)
|
||||
* the network or disk). This makes the lexer more complex. The
|
||||
* responsibility of the lexer is to handle transparently the case where
|
||||
* a chunk boundary falls in the middle of a token. This is
|
||||
* accomplished is via a buffer and a character reading abstraction.
|
||||
* accomplished is via a buffer and a character reading abstraction.
|
||||
*
|
||||
* Overview of implementation
|
||||
*
|
||||
* When we lex to end of input string before end of token is hit, we
|
||||
* copy all of the input text composing the token into our lexBuf.
|
||||
*
|
||||
*
|
||||
* Every time we read a character, we do so through the readChar function.
|
||||
* readChar's responsibility is to handle pulling all chars from the buffer
|
||||
* before pulling chars from input text
|
||||
@ -74,7 +74,7 @@ struct yajl_lexer_t {
|
||||
yajl_lex_error error;
|
||||
|
||||
/* a input buffer to handle the case where a token is spread over
|
||||
* multiple chunks */
|
||||
* multiple chunks */
|
||||
yajl_buf buf;
|
||||
|
||||
/* in the case where we have data in the lexBuf, bufOff holds
|
||||
@ -186,7 +186,7 @@ static const char charLookupTable[256] =
|
||||
* yajl_tok_eof - if end of input was hit before validation could
|
||||
* complete
|
||||
* yajl_tok_error - if invalid utf8 was encountered
|
||||
*
|
||||
*
|
||||
* NOTE: on error the offset will point to the first char of the
|
||||
* invalid utf8 */
|
||||
#define UTF8_CHECK_EOF if (*offset >= jsonTextLen) { return yajl_tok_eof; }
|
||||
@ -200,7 +200,7 @@ yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
/* single byte */
|
||||
return yajl_tok_string;
|
||||
} else if ((curChar >> 5) == 0x6) {
|
||||
/* two byte */
|
||||
/* two byte */
|
||||
UTF8_CHECK_EOF;
|
||||
curChar = readChar(lexer, jsonText, offset);
|
||||
if ((curChar >> 6) == 0x2) return yajl_tok_string;
|
||||
@ -226,7 +226,7 @@ yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
if ((curChar >> 6) == 0x2) return yajl_tok_string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return yajl_tok_error;
|
||||
}
|
||||
@ -279,7 +279,7 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
{
|
||||
const unsigned char * p;
|
||||
size_t len;
|
||||
|
||||
|
||||
if ((lexer->bufInUse && yajl_buf_len(lexer->buf) &&
|
||||
lexer->bufOff < yajl_buf_len(lexer->buf)))
|
||||
{
|
||||
@ -287,8 +287,8 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
(lexer->bufOff));
|
||||
len = yajl_buf_len(lexer->buf) - lexer->bufOff;
|
||||
lexer->bufOff += yajl_string_scan(p, len, lexer->validateUTF8);
|
||||
}
|
||||
else if (*offset < jsonTextLen)
|
||||
}
|
||||
else if (*offset < jsonTextLen)
|
||||
{
|
||||
p = jsonText + *offset;
|
||||
len = jsonTextLen - *offset;
|
||||
@ -316,8 +316,8 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
unsigned int i = 0;
|
||||
|
||||
for (i=0;i<4;i++) {
|
||||
STR_CHECK_EOF;
|
||||
curChar = readChar(lexer, jsonText, offset);
|
||||
STR_CHECK_EOF;
|
||||
curChar = readChar(lexer, jsonText, offset);
|
||||
if (!(charLookupTable[curChar] & VHC)) {
|
||||
/* back up to offending char */
|
||||
unreadChar(lexer, offset);
|
||||
@ -329,8 +329,8 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
/* back up to offending char */
|
||||
unreadChar(lexer, offset);
|
||||
lexer->error = yajl_lex_string_invalid_escaped_char;
|
||||
goto finish_string_lex;
|
||||
}
|
||||
goto finish_string_lex;
|
||||
}
|
||||
}
|
||||
/* when not validating UTF8 it's a simple table lookup to determine
|
||||
* if the present character is invalid */
|
||||
@ -338,29 +338,29 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
/* back up to offending char */
|
||||
unreadChar(lexer, offset);
|
||||
lexer->error = yajl_lex_string_invalid_json_char;
|
||||
goto finish_string_lex;
|
||||
goto finish_string_lex;
|
||||
}
|
||||
/* when in validate UTF8 mode we need to do some extra work */
|
||||
else if (lexer->validateUTF8) {
|
||||
yajl_tok t = yajl_lex_utf8_char(lexer, jsonText, jsonTextLen,
|
||||
offset, curChar);
|
||||
|
||||
|
||||
if (t == yajl_tok_eof) {
|
||||
tok = yajl_tok_eof;
|
||||
goto finish_string_lex;
|
||||
} else if (t == yajl_tok_error) {
|
||||
lexer->error = yajl_lex_string_invalid_utf8;
|
||||
goto finish_string_lex;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* accept it, and move on */
|
||||
/* accept it, and move on */
|
||||
}
|
||||
finish_string_lex:
|
||||
/* tell our buddy, the parser, wether he needs to process this string
|
||||
* again */
|
||||
if (hasEscapes && tok == yajl_tok_string) {
|
||||
tok = yajl_tok_string_with_escapes;
|
||||
}
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
@ -379,23 +379,23 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
|
||||
yajl_tok tok = yajl_tok_integer;
|
||||
|
||||
RETURN_IF_EOF;
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
|
||||
/* optional leading minus */
|
||||
if (c == '-') {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
}
|
||||
|
||||
/* a single zero, or a series of integers */
|
||||
if (c == '0') {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
} else if (c >= '1' && c <= '9') {
|
||||
do {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
} while (c >= '0' && c <= '9');
|
||||
} else {
|
||||
unreadChar(lexer, offset);
|
||||
@ -406,15 +406,15 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
/* optional fraction (indicates this is floating point) */
|
||||
if (c == '.') {
|
||||
int numRd = 0;
|
||||
|
||||
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
|
||||
while (c >= '0' && c <= '9') {
|
||||
numRd++;
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
}
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
}
|
||||
|
||||
if (!numRd) {
|
||||
unreadChar(lexer, offset);
|
||||
@ -427,18 +427,18 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
/* optional exponent (indicates this is floating point) */
|
||||
if (c == 'e' || c == 'E') {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
|
||||
/* optional sign */
|
||||
if (c == '+' || c == '-') {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
}
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
do {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
} while (c >= '0' && c <= '9');
|
||||
} else {
|
||||
unreadChar(lexer, offset);
|
||||
@ -447,10 +447,10 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
}
|
||||
tok = yajl_tok_double;
|
||||
}
|
||||
|
||||
|
||||
/* we always go "one too far" */
|
||||
unreadChar(lexer, offset);
|
||||
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
@ -462,24 +462,24 @@ yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
|
||||
yajl_tok tok = yajl_tok_comment;
|
||||
|
||||
RETURN_IF_EOF;
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
|
||||
/* either slash or star expected */
|
||||
if (c == '/') {
|
||||
/* now we throw away until end of line */
|
||||
do {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
} while (c != '\n');
|
||||
} else if (c == '*') {
|
||||
/* now we throw away until end of comment */
|
||||
/* now we throw away until end of comment */
|
||||
for (;;) {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
if (c == '*') {
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
RETURN_IF_EOF;
|
||||
c = readChar(lexer, jsonText, offset);
|
||||
if (c == '/') {
|
||||
break;
|
||||
} else {
|
||||
@ -491,7 +491,7 @@ yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
lexer->error = yajl_lex_invalid_char;
|
||||
tok = yajl_tok_error;
|
||||
}
|
||||
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
@ -599,7 +599,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
goto lexed;
|
||||
}
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9': {
|
||||
/* integer parsing wants to start from the beginning */
|
||||
unreadChar(lexer, offset);
|
||||
@ -626,11 +626,11 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
jsonTextLen, offset);
|
||||
if (tok == yajl_tok_comment) {
|
||||
/* "error" is silly, but that's the initial
|
||||
* state of tok. guilty until proven innocent. */
|
||||
* state of tok. guilty until proven innocent. */
|
||||
tok = yajl_tok_error;
|
||||
yajl_buf_clear(lexer->buf);
|
||||
lexer->bufInUse = 0;
|
||||
startOffset = *offset;
|
||||
startOffset = *offset;
|
||||
break;
|
||||
}
|
||||
/* hit error or eof, bail */
|
||||
@ -651,7 +651,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
lexer->bufInUse = 1;
|
||||
yajl_buf_append(lexer->buf, jsonText + startOffset, *offset - startOffset);
|
||||
lexer->bufOff = 0;
|
||||
|
||||
|
||||
if (tok != yajl_tok_eof) {
|
||||
*outBuf = yajl_buf_data(lexer->buf);
|
||||
*outLen = yajl_buf_len(lexer->buf);
|
||||
@ -667,7 +667,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
{
|
||||
assert(*outLen >= 2);
|
||||
(*outBuf)++;
|
||||
*outLen -= 2;
|
||||
*outLen -= 2;
|
||||
}
|
||||
|
||||
|
||||
@ -698,7 +698,7 @@ yajl_lex_error_to_string(yajl_lex_error error)
|
||||
case yajl_lex_string_invalid_escaped_char:
|
||||
return "inside a string, '\\' occurs before a character "
|
||||
"which it may not.";
|
||||
case yajl_lex_string_invalid_json_char:
|
||||
case yajl_lex_string_invalid_json_char:
|
||||
return "invalid character inside string.";
|
||||
case yajl_lex_string_invalid_hex_char:
|
||||
return "invalid (non-hex) character occurs after '\\u' inside "
|
||||
@ -751,13 +751,13 @@ yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
|
||||
size_t bufOff = lexer->bufOff;
|
||||
unsigned int bufInUse = lexer->bufInUse;
|
||||
yajl_tok tok;
|
||||
|
||||
|
||||
tok = yajl_lex_lex(lexer, jsonText, jsonTextLen, &offset,
|
||||
&outBuf, &outLen);
|
||||
|
||||
lexer->bufOff = bufOff;
|
||||
lexer->bufInUse = bufInUse;
|
||||
yajl_buf_truncate(lexer->buf, bufLen);
|
||||
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -20,21 +20,21 @@
|
||||
#include "api/yajl_common.h"
|
||||
|
||||
typedef enum {
|
||||
yajl_tok_bool,
|
||||
yajl_tok_bool,
|
||||
yajl_tok_colon,
|
||||
yajl_tok_comma,
|
||||
yajl_tok_comma,
|
||||
yajl_tok_eof,
|
||||
yajl_tok_error,
|
||||
yajl_tok_left_brace,
|
||||
yajl_tok_left_brace,
|
||||
yajl_tok_left_bracket,
|
||||
yajl_tok_null,
|
||||
yajl_tok_right_brace,
|
||||
yajl_tok_null,
|
||||
yajl_tok_right_brace,
|
||||
yajl_tok_right_bracket,
|
||||
|
||||
/* we differentiate between integers and doubles to allow the
|
||||
* parser to interpret the number without re-scanning */
|
||||
yajl_tok_integer,
|
||||
yajl_tok_double,
|
||||
yajl_tok_integer,
|
||||
yajl_tok_double,
|
||||
|
||||
/* we differentiate between strings which require further processing,
|
||||
* and strings that do not */
|
||||
@ -61,11 +61,11 @@ void yajl_lex_free(yajl_lexer lexer);
|
||||
*
|
||||
* the client may be interested in the value of offset when an error is
|
||||
* returned from the lexer. This allows the client to render useful
|
||||
n * error messages.
|
||||
* error messages.
|
||||
*
|
||||
* When you pass the next chunk of data, context should be reinitialized
|
||||
* to zero.
|
||||
*
|
||||
*
|
||||
* Finally, the output buffer is usually just a pointer into the jsonText,
|
||||
* however in cases where the entity being lexed spans multiple chunks,
|
||||
* the lexer will buffer the entity and the data returned will be
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -51,6 +51,10 @@ yajl_parse_integer(const unsigned char *number, unsigned int length)
|
||||
errno = ERANGE;
|
||||
return sign == 1 ? LLONG_MAX : LLONG_MIN;
|
||||
}
|
||||
if (*pos < '0' || *pos > '9') {
|
||||
errno = ERANGE;
|
||||
return sign == 1 ? LLONG_MAX : LLONG_MIN;
|
||||
}
|
||||
ret += (*pos++ - '0');
|
||||
}
|
||||
|
||||
@ -279,6 +283,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
|
||||
hand->ctx,(const char *) buf, bufLen));
|
||||
} else if (hand->callbacks->yajl_integer) {
|
||||
long long int i = 0;
|
||||
errno = 0;
|
||||
i = yajl_parse_integer(buf, bufLen);
|
||||
if ((i == LLONG_MIN || i == LLONG_MAX) &&
|
||||
errno == ERANGE)
|
||||
@ -306,6 +311,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
|
||||
yajl_buf_clear(hand->decodeBuf);
|
||||
yajl_buf_append(hand->decodeBuf, buf, bufLen);
|
||||
buf = yajl_buf_data(hand->decodeBuf);
|
||||
errno = 0;
|
||||
d = strtod((char *) buf, NULL);
|
||||
if ((d == HUGE_VAL || d == -HUGE_VAL) &&
|
||||
errno == ERANGE)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
|
||||
* Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include "yajl_parser.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
|
||||
@ -194,7 +194,7 @@ static int array_add_value (context_t *ctx,
|
||||
|
||||
/* "context_add_value" will only call us with array values. */
|
||||
assert(YAJL_IS_ARRAY(array));
|
||||
|
||||
|
||||
tmp = realloc(array->u.array.values,
|
||||
sizeof(*(array->u.array.values)) * (array->u.array.len + 1));
|
||||
if (tmp == NULL)
|
||||
@ -309,11 +309,10 @@ static int handle_number (void *ctx, const char *string, size_t string_length)
|
||||
|
||||
v->u.number.flags = 0;
|
||||
|
||||
endptr = NULL;
|
||||
errno = 0;
|
||||
v->u.number.i = yajl_parse_integer((const unsigned char *) v->u.number.r,
|
||||
strlen(v->u.number.r));
|
||||
if ((errno == 0) && (endptr != NULL) && (*endptr == 0))
|
||||
if (errno == 0)
|
||||
v->u.number.flags |= YAJL_NUMBER_INT_VALID;
|
||||
|
||||
endptr = NULL;
|
||||
@ -421,6 +420,7 @@ yajl_val yajl_tree_parse (const char *input,
|
||||
|
||||
yajl_handle handle;
|
||||
yajl_status status;
|
||||
char * internal_err_str;
|
||||
context_t ctx = { NULL, NULL, NULL, 0 };
|
||||
|
||||
ctx.errbuf = error_buffer;
|
||||
@ -438,11 +438,11 @@ yajl_val yajl_tree_parse (const char *input,
|
||||
status = yajl_complete_parse (handle);
|
||||
if (status != yajl_status_ok) {
|
||||
if (error_buffer != NULL && error_buffer_size > 0) {
|
||||
snprintf(
|
||||
error_buffer, error_buffer_size, "%s",
|
||||
(char *) yajl_get_error(handle, 1,
|
||||
(const unsigned char *) input,
|
||||
strlen(input)));
|
||||
internal_err_str = (char *) yajl_get_error(handle, 1,
|
||||
(const unsigned char *) input,
|
||||
strlen(input));
|
||||
snprintf(error_buffer, error_buffer_size, "%s", internal_err_str);
|
||||
YA_FREE(&(handle->alloc), internal_err_str);
|
||||
}
|
||||
yajl_free (handle);
|
||||
return NULL;
|
||||
@ -456,16 +456,18 @@ yajl_val yajl_tree_get(yajl_val n, const char ** path, yajl_type type)
|
||||
{
|
||||
if (!path) return NULL;
|
||||
while (n && *path) {
|
||||
unsigned int i;
|
||||
size_t i;
|
||||
size_t len;
|
||||
|
||||
if (n->type != yajl_t_object) return NULL;
|
||||
for (i = 0; i < n->u.object.len; i++) {
|
||||
len = n->u.object.len;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!strcmp(*path, n->u.object.keys[i])) {
|
||||
n = n->u.object.values[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == n->u.object.len) return NULL;
|
||||
if (i == len) return NULL;
|
||||
path++;
|
||||
}
|
||||
if (n && type != yajl_t_any && type != n->type) n = NULL;
|
||||
|
@ -70,7 +70,9 @@ int yajlpp_parse_context::map_key(void *ctx,
|
||||
retval = ypc->ypc_alt_callbacks.yajl_map_key(ctx, key, len);
|
||||
}
|
||||
|
||||
ypc->update_callbacks();
|
||||
if (ypc->ypc_handlers != NULL) {
|
||||
ypc->update_callbacks();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user