gui_p gui_create(char *ressource_name) { ressource_p ressource = RESSOURCE_FIND(ressource_name); if (!ressource) { LOGF("Can't find image ressource %s", ressource_name); return 0; } json_parser_init(); json_node_p gui_config = JSON_NODE_ROOT(json_parse_ressource(ressource)); if (!gui_config) { LOGF("Can't find image config %s", ressource_name); return 0; } gui_p gui = (gui_p)malloc(sizeof(gui_t)); gui->image = 0; gui->frame.array_count = 0; gui->frame.child = 0; gui->frame.parent = 0; gui->frame.state = 0; gui->name = ressource_name; gui_set_config(gui, gui_config); return gui; }
virtual StringResultBase* SaxRoundtrip(const char* json, size_t length) const { VinenthzStringResult* sr = new VinenthzStringResult(); json_printer printer; json_print_init(&printer, string_buffer_append, &sr->sb); json_config config; memset(&config, 0, sizeof(json_config)); config.max_nesting = 0; config.max_data = 0; config.allow_c_comments = 0; config.allow_yaml_comments = 0; json_parser parser; json_parser_init(&parser, &config, (json_parser_callback)json_print_raw, &printer); uint32_t processed; if (json_parser_string(&parser, json, (uint32_t)length, &processed) == 0) sr->AppendEnds(); else { delete sr; sr = 0; } json_parser_free(&parser); json_print_free(&printer); return sr; }
static int do_parse(json_config *config, const char *filename) { FILE *input; json_parser parser; int ret; int col, lines; input = open_filename(filename, "r", 1); if (!input) return 2; /* initialize the parser structure. we don't need a callback in verify */ ret = json_parser_init(&parser, config, NULL, NULL); if (ret) { fprintf(stderr, "error: initializing parser failed (code=%d): %s\n", ret, string_of_errors[ret]); return ret; } ret = process_file(&parser, input, &lines, &col); if (ret) { fprintf(stderr, "line %d, col %d: [code=%d] %s\n", lines, col, ret, string_of_errors[ret]); return 1; } ret = json_parser_is_done(&parser); if (!ret) { fprintf(stderr, "syntax error\n"); return 1; } close_filename(filename, input); return 0; }
virtual ParseResultBase* Parse(const char* json, size_t length) const { VinenthzParseResult* pr = new VinenthzParseResult; json_config config; memset(&config, 0, sizeof(json_config)); config.max_nesting = 0; config.max_data = 0; config.allow_c_comments = 0; config.allow_yaml_comments = 0; json_parser parser; json_parser_dom dom; json_parser_dom_init(&dom, tree_create_structure, tree_create_data, tree_append); json_parser_init(&parser, &config, json_parser_dom_callback, &dom); uint32_t processed; if (!json_parser_string(&parser, json, (uint32_t)length, &processed)) pr->root = (json_val_t*)dom.root_structure; else { delete pr; pr = 0; } json_parser_free(&parser); json_parser_dom_free(&dom); return pr; }
void benchmarkFile(char *filename) { clock_t begin, end; double time_spent; json_token *tokens = calloc(sizeof(json_token), 3000000); json_parser parser; json_parser_init(&parser); parser.tokens = tokens; parser.maxTokens = 3000000; parser_from_file(&parser, filename); begin = clock(); /* parse the json document */ parse_json(&parser, RFC4627); end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printResults(&parser, filename, time_spent); file_parser_free(&parser); free(tokens); }
parser_context(Value& obj) : top_level(true) { stack_.reserve(32); stack_.push_back(&obj); memset(&config_, 0, sizeof(config_)); config_.max_nesting = 1024; config_.max_data = 1 << 27; config_.allow_c_comments = 1; err_code_ = json_parser_init(&parser_, &config_, &parser_callback, this); }
static void test_json_parser_success(bool full_size) { struct json_parser *parser; struct istream *input, *jsoninput = NULL; enum json_type type; const char *value, *error; unsigned int i, pos, json_input_len = strlen(json_input); int ret = 0; test_begin(full_size ? "json parser" : "json parser (nonblocking)"); input = test_istream_create_data(json_input, json_input_len); test_istream_set_allow_eof(input, FALSE); parser = json_parser_init(input); i = full_size ? json_input_len : 0; for (pos = 0; i <= json_input_len; i++) { test_istream_set_size(input, i); for (;;) { value = NULL; if (pos < N_ELEMENTS(json_output) && json_output[pos].type == (enum json_type)TYPE_SKIP) { json_parse_skip_next(parser); pos++; continue; } else if (pos == N_ELEMENTS(json_output) || json_output[pos].type != (enum json_type)TYPE_STREAM) { ret = json_parse_next(parser, &type, &value); } else { ret = jsoninput != NULL ? 1 : json_parse_next_stream(parser, &jsoninput); if (jsoninput != NULL) ret = stream_read_value(&jsoninput, &value); type = TYPE_STREAM; } if (ret <= 0) break; i_assert(pos < N_ELEMENTS(json_output)); test_assert(json_output[pos].type == type); test_assert(null_strcmp(json_output[pos].value, value) == 0); pos++; } test_assert(ret == 0); } test_assert(pos == N_ELEMENTS(json_output)); test_istream_set_allow_eof(input, TRUE); test_assert(json_parse_next(parser, &type, &value) == -1); i_stream_unref(&input); test_assert(json_parser_deinit(&parser, &error) == 0); test_end(); }
static int do_format(json_config *config, const char *filename, const char *outputfile) { FILE *input, *output; json_parser parser; json_printer printer; int ret; int col, lines; input = open_filename(filename, "r", 1); if (!input) return 2; output = open_filename(outputfile, "a+", 0); if (!output) return 2; /* initialize printer and parser structures */ ret = json_print_init(&printer, printchannel, stdout); if (ret) { fprintf(stderr, "error: initializing printer failed: [code=%d] %s\n", ret, string_of_errors[ret]); return ret; } if (indent_string) printer.indentstr = indent_string; ret = json_parser_init(&parser, config, &prettyprint, &printer); if (ret) { fprintf(stderr, "error: initializing parser failed: [code=%d] %s\n", ret, string_of_errors[ret]); return ret; } ret = process_file(&parser, input, &lines, &col); if (ret) { fprintf(stderr, "line %d, col %d: [code=%d] %s\n", lines, col, ret, string_of_errors[ret]); return 1; } ret = json_parser_is_done(&parser); if (!ret) { fprintf(stderr, "syntax error\n"); return 1; } /* cleanup */ json_parser_free(&parser); json_print_free(&printer); fwrite("\n", 1, 1, stdout); close_filename(filename, input); return 0; }
xmmsv_t * xmmsv_from_json (const char *spec) { json_config conf = { 0, /* buffer_initial_size (0=default) */ 0, /* max_nesting (0=no limit) */ 0, /* max_data (0=no limit) */ 1, /* allow_c_comments */ 0, /* allow_yaml_comments */ NULL, /* user_calloc */ NULL /* user_realloc */ }; json_parser_dom dom; json_parser parser; xmmsv_t *value; int error; json_parser_dom_init (&dom, (json_parser_dom_create_structure) create_structure, (json_parser_dom_create_data) create_data, (json_parser_dom_append) append); json_parser_init (&parser, &conf, json_parser_dom_callback, &dom); error = json_parser_string (&parser, spec, strlen (spec), NULL); if (error != 0) { switch (error) { case JSON_ERROR_BAD_CHAR: fprintf (stderr, "Failed to parse due to bad character!\n"); break; case JSON_ERROR_UNEXPECTED_CHAR: fprintf (stderr, "Failed to parse due to unexpected character!\n"); break; case JSON_ERROR_NO_MEMORY: fprintf (stderr, "Failed to parse (%d)!\n", error); break; } return NULL; } assert (dom.root_structure != NULL); assert (dom.stack_offset == 0); value = (xmmsv_t *) dom.root_structure; json_parser_dom_free (&dom); json_parser_free (&parser); return value; }
static int parse_clfjson(void *ctx, str_t *str, logmeta_t *meta) { clfjson_state_t state = {0, 0, 0, str, meta}; json_parser parser; size_t processed = 0; logmeta_clear(meta); logmeta_hash(meta, str); json_parser_init(&parser, NULL, clfjson_state, &state); json_parser_string(&parser, (const char *)str->ptr, str->len, &processed); str_ptime_rfc1123(logmeta_field(meta, LOGPIPE_TIMESTAMP), &meta->utc_timestamp); json_parser_free(&parser); return ! logmeta_field_isempty(meta, LOGPIPE_C_IP) && ! logmeta_field_isempty(meta, LOGPIPE_TIMESTAMP) && ! logmeta_field_isempty(meta, LOGPIPE_CS_METHOD) && ! logmeta_field_isempty(meta, LOGPIPE_CS_URI_STEM) && ! logmeta_field_isempty(meta, LOGPIPE_SC_STATUS); }
static int do_tree(json_config *config, const char *filename, json_val_t **root_structure) { FILE *input; json_parser parser; json_parser_dom dom; int ret; int col, lines; input = open_filename(filename, "r", 1); if (!input) return 2; ret = json_parser_dom_init(&dom, tree_create_structure, tree_create_data, tree_append); if (ret) { fprintf(stderr, "error: initializing helper failed: [code=%d] %s\n", ret, string_of_errors[ret]); return ret; } ret = json_parser_init(&parser, config, json_parser_dom_callback, &dom); if (ret) { fprintf(stderr, "error: initializing parser failed: [code=%d] %s\n", ret, string_of_errors[ret]); return ret; } ret = process_file(&parser, input, &lines, &col); if (ret) { fprintf(stderr, "line %d, col %d: [code=%d] %s\n", lines, col, ret, string_of_errors[ret]); return 1; } ret = json_parser_is_done(&parser); if (!ret) { fprintf(stderr, "syntax error\n"); return 1; } if (root_structure) *root_structure = dom.root_structure; /* cleanup */ json_parser_free(&parser); close_filename(filename, input); return 0; }
virtual bool SaxStatistics(const char* json, size_t length, Stat* stat) const { json_config config; memset(&config, 0, sizeof(json_config)); config.max_nesting = 0; config.max_data = 0; config.allow_c_comments = 0; config.allow_yaml_comments = 0; memset(stat, 0, sizeof(Stat)); StatContext context; context.stat = stat; context.after_key = true; json_parser parser; json_parser_init(&parser, &config, (json_parser_callback)stat_callback, &context); uint32_t processed; bool ret = (json_parser_string(&parser, json, (uint32_t)length, &processed) == 0); json_parser_free(&parser); return ret; }
jobj * jobj_parse(const char * json_str) { int res; jobj * o = NULL; json_parser_dom dom; json_parser p; json_config config; memset(&config, 0, sizeof(json_config)); res = json_parser_dom_init(&dom, dom_mknode, dom_mkval, dom_append); if(res) return NULL; res = json_parser_init(&p, &config, json_parser_dom_callback, &dom); if(res) return NULL; res = json_parser_string(&p, json_str, strlen(json_str), NULL); if(!res && json_parser_is_done(&p)) o = dom.root_structure; json_parser_free(&p); json_parser_dom_free(&dom); return o; }
static int jsonParseInit(json_parser *parser, json_printer *printer) { json_config config; //printf("jsonParseInit Start...\n"); memset(&config, 0, sizeof(json_config)); config.max_nesting = 0; config.max_data = 0; config.allow_c_comments = 1; config.allow_yaml_comments = 1; int ret; /* initialize printer and parser structures */ ret = json_print_init(printer, printchannel, NULL); if (ret) { printf("error: initializing printer failed: [code=%d]\n", ret); return ret; } ret = json_parser_init(parser, &config, &prettyprint, printer); if (ret) { printf("error: initializing parser failed: [code=%d]\n", ret); return ret; } return 0; }
void requestInit() override { json_parser_init(); }