# ifdef WITH_YAJL2
# define yajl_size_t size_t
+# define VIR_YAJL_STATUS_OK(status) ((status) == yajl_status_ok)
# else
# define yajl_size_t unsigned int
# define yajl_complete_parse yajl_parse_complete
+# define VIR_YAJL_STATUS_OK(status) \
+ ((status) == yajl_status_ok || (status) == yajl_status_insufficient_data)
# endif
#endif
yajl_handle hand;
virJSONParser parser = { NULL, NULL, 0 };
virJSONValuePtr ret = NULL;
+ int rc;
+ size_t len = strlen(jsonstring);
# ifndef WITH_YAJL2
yajl_parser_config cfg = { 1, 1 };
# endif
goto cleanup;
}
- if (yajl_parse(hand,
- (const unsigned char *)jsonstring,
- strlen(jsonstring)) != yajl_status_ok ||
+ rc = yajl_parse(hand, (const unsigned char *)jsonstring, len);
+ if (!VIR_YAJL_STATUS_OK(rc) ||
yajl_complete_parse(hand) != yajl_status_ok) {
unsigned char *errstr = yajl_get_error(hand, 1,
(const unsigned char*)jsonstring,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse json %s: %s"),
jsonstring, (const char*) errstr);
- VIR_FREE(errstr);
+ yajl_free_error(hand, errstr);
virJSONValueFree(parser.head);
goto cleanup;
}
DO_TEST_PARSE("boolean", "true");
DO_TEST_PARSE("null", "null");
DO_TEST_PARSE_FAIL("incomplete keyword", "tr");
- DO_TEST_PARSE_FAIL("overdone keyword", "truest");
+ DO_TEST_PARSE_FAIL("overdone keyword", "[ truest ]");
DO_TEST_PARSE_FAIL("unknown keyword", "huh");
DO_TEST_PARSE_FAIL("object with numeric keys", "{ 1:1, 2:1, 3:2 }");