After this commit, WITH_YAJL can no longer be set.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
meson.build | 43 -----
src/util/virjson.c | 416 ---------------------------------------------
2 files changed, 459 deletions(-)
diff --git a/meson.build b/meson.build
index 9605d58537..a7c62d8bcc 100644
--- a/meson.build
+++ b/meson.build
@@ -1378,48 +1378,6 @@ if wireshark_dep.found()
endif
endif
-yajl_version = '2.0.3'
-yajl_dep = dependency('yajl', version: '>=' + yajl_version, required:
false)
-if yajl_dep.found()
- # Kludge for yajl include path on non-Linux
- #
- # As of 2.1.0, upstream yajl.pc has -I${includedir}/yajl among
- # its Cflags, which is clearly wrong. This does not affect Linux
- # because ${includedir} is already part of the default include path,
- # but on other platforms that's not the case and the result is that
- # <yajl/yajl.h> can't be located, causing the build to fail.
- #
- # Since upstream development for yajl has stopped years ago, there's
- # little hope of this issue getting fixed by a new upstream release.
- # Some non-Linux operating systems such as FreeBSD have elected to
- # carry a small downstream patch, but in the case of Homebrew on
- # macOS this approach has been rejected[1] and so we're left with no
- # choice but to work around the issue ourselves.
- #
- # [1]
https://github.com/Homebrew/homebrew-core/pull/74516
- if host_machine.system() != 'linux'
- yajl_includedir = yajl_dep.get_variable(pkgconfig : 'includedir')
- if yajl_includedir.contains('include/yajl')
- rc = run_command(
- 'python3', '-c',
- 'print("@0@".replace("@1(a)",
"@2(a)"))'.format(
- yajl_includedir, 'include/yajl', 'include',
- ),
- check: true,
- )
- yajl_includedir = rc.stdout().strip()
- yajl_dep = declare_dependency(
- compile_args: [ '-I' + yajl_includedir ],
- dependencies: [ yajl_dep ],
- )
- endif
- endif
-
- conf.set('WITH_YAJL', 1)
- conf.set('WITH_JSON', 1)
-endif
-
-
# generic build dependencies checks
if bash_completion_dep.found() and not readline_dep.found()
@@ -2374,7 +2332,6 @@ libs_summary = {
'selinux': selinux_dep.found(),
'udev': udev_dep.found(),
'xdr': xdr_dep.found(),
- 'yajl': yajl_dep.found(),
}
summary(libs_summary, section: 'Libraries', bool_yn: true)
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 8e0ba47fc9..0378adf00e 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -34,10 +34,6 @@
#if WITH_JSON_C
# include <json.h>
-#elif WITH_YAJL
-# include <yajl/yajl_gen.h>
-# include <yajl/yajl_parse.h>
-
#endif
/* XXX fixme */
@@ -1553,418 +1549,6 @@ virJSONValueToBuffer(virJSONValue *object,
}
-#elif WITH_YAJL
-static int
-virJSONParserInsertValue(virJSONParser *parser,
- virJSONValue **value)
-{
- if (!parser->head) {
- parser->head = g_steal_pointer(value);
- } else {
- virJSONParserState *state;
- if (!parser->nstate) {
- VIR_DEBUG("got a value to insert without a container");
- return -1;
- }
-
- state = &parser->state[parser->nstate-1];
-
- switch (state->value->type) {
- case VIR_JSON_TYPE_OBJECT: {
- if (!state->key) {
- VIR_DEBUG("missing key when inserting object value");
- return -1;
- }
-
- if (virJSONValueObjectAppend(state->value,
- state->key,
- value) < 0)
- return -1;
-
- VIR_FREE(state->key);
- } break;
-
- case VIR_JSON_TYPE_ARRAY: {
- if (state->key) {
- VIR_DEBUG("unexpected key when inserting array value");
- return -1;
- }
-
- if (virJSONValueArrayAppend(state->value,
- value) < 0)
- return -1;
- } break;
-
- default:
- VIR_DEBUG("unexpected value type, not a container");
- return -1;
- }
- }
-
- return 0;
-}
-
-
-static int
-virJSONParserHandleNull(void *ctx)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewNull();
-
- VIR_DEBUG("parser=%p", parser);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleBoolean(void *ctx,
- int boolean_)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewBoolean(boolean_);
-
- VIR_DEBUG("parser=%p boolean=%d", parser, boolean_);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleNumber(void *ctx,
- const char *s,
- size_t l)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewNumber(g_strndup(s, l));
-
- VIR_DEBUG("parser=%p str=%s", parser, value->data.number);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleString(void *ctx,
- const unsigned char *stringVal,
- size_t stringLen)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewString(g_strndup((const char
*)stringVal, stringLen));
-
- VIR_DEBUG("parser=%p str=%p", parser, (const char *)stringVal);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleMapKey(void *ctx,
- const unsigned char *stringVal,
- size_t stringLen)
-{
- virJSONParser *parser = ctx;
- virJSONParserState *state;
-
- VIR_DEBUG("parser=%p key=%p", parser, (const char *)stringVal);
-
- if (!parser->nstate)
- return 0;
-
- state = &parser->state[parser->nstate-1];
- if (state->key)
- return 0;
- state->key = g_strndup((const char *)stringVal, stringLen);
- return 1;
-}
-
-
-static int
-virJSONParserHandleStartMap(void *ctx)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewObject();
- virJSONValue *tmp = value;
-
- VIR_DEBUG("parser=%p", parser);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- VIR_REALLOC_N(parser->state, parser->nstate + 1);
-
- parser->state[parser->nstate].value = tmp;
- parser->state[parser->nstate].key = NULL;
- parser->nstate++;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleEndMap(void *ctx)
-{
- virJSONParser *parser = ctx;
- virJSONParserState *state;
-
- VIR_DEBUG("parser=%p", parser);
-
- if (!parser->nstate)
- return 0;
-
- state = &(parser->state[parser->nstate-1]);
- if (state->key) {
- VIR_FREE(state->key);
- return 0;
- }
-
- VIR_DELETE_ELEMENT(parser->state, parser->nstate - 1, parser->nstate);
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleStartArray(void *ctx)
-{
- virJSONParser *parser = ctx;
- g_autoptr(virJSONValue) value = virJSONValueNewArray();
- virJSONValue *tmp = value;
-
- VIR_DEBUG("parser=%p", parser);
-
- if (virJSONParserInsertValue(parser, &value) < 0)
- return 0;
-
- VIR_REALLOC_N(parser->state, parser->nstate + 1);
-
- parser->state[parser->nstate].value = tmp;
- parser->state[parser->nstate].key = NULL;
- parser->nstate++;
-
- return 1;
-}
-
-
-static int
-virJSONParserHandleEndArray(void *ctx)
-{
- virJSONParser *parser = ctx;
- virJSONParserState *state;
-
- VIR_DEBUG("parser=%p", parser);
-
- if (!(parser->nstate - parser->wrap))
- return 0;
-
- state = &(parser->state[parser->nstate-1]);
- if (state->key) {
- VIR_FREE(state->key);
- return 0;
- }
-
- VIR_DELETE_ELEMENT(parser->state, parser->nstate - 1, parser->nstate);
-
- return 1;
-}
-
-
-static const yajl_callbacks parserCallbacks = {
- virJSONParserHandleNull,
- virJSONParserHandleBoolean,
- NULL,
- NULL,
- virJSONParserHandleNumber,
- virJSONParserHandleString,
- virJSONParserHandleStartMap,
- virJSONParserHandleMapKey,
- virJSONParserHandleEndMap,
- virJSONParserHandleStartArray,
- virJSONParserHandleEndArray
-};
-
-
-/* XXX add an incremental streaming parser - yajl trivially supports it */
-virJSONValue *
-virJSONValueFromString(const char *jsonstring)
-{
- yajl_handle hand;
- virJSONParser parser = { NULL, NULL, 0, 0 };
- virJSONValue *ret = NULL;
- int rc;
- size_t len = strlen(jsonstring);
-
- VIR_DEBUG("string=%s", jsonstring);
-
- hand = yajl_alloc(&parserCallbacks, NULL, &parser);
- if (!hand) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to create JSON parser"));
- return NULL;
- }
-
- /* Yajl 2 is nice enough to default to rejecting trailing garbage. */
- rc = yajl_parse(hand, (const unsigned char *)jsonstring, len);
- if (rc != yajl_status_ok ||
- yajl_complete_parse(hand) != yajl_status_ok) {
- unsigned char *errstr = yajl_get_error(hand, 1,
- (const unsigned char*)jsonstring,
- strlen(jsonstring));
-
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot parse json %1$s: %2$s"),
- jsonstring, (const char*) errstr);
- yajl_free_error(hand, errstr);
- virJSONValueFree(parser.head);
- goto cleanup;
- }
-
- if (parser.nstate != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot parse json %1$s: unterminated
string/map/array"),
- jsonstring);
- virJSONValueFree(parser.head);
- } else {
- ret = parser.head;
- }
-
- cleanup:
- yajl_free(hand);
-
- if (parser.nstate) {
- size_t i;
- for (i = 0; i < parser.nstate; i++)
- VIR_FREE(parser.state[i].key);
- VIR_FREE(parser.state);
- }
-
- VIR_DEBUG("result=%p", ret);
-
- return ret;
-}
-
-
-static int
-virJSONValueToStringOne(virJSONValue *object,
- yajl_gen g)
-{
- size_t i;
-
- VIR_DEBUG("object=%p type=%d gen=%p", object, object->type, g);
-
- switch (object->type) {
- case VIR_JSON_TYPE_OBJECT:
- if (yajl_gen_map_open(g) != yajl_gen_status_ok)
- return -1;
- for (i = 0; i < object->data.object.npairs; i++) {
- if (yajl_gen_string(g,
- (unsigned char *)object->data.object.pairs[i].key,
- strlen(object->data.object.pairs[i].key))
- != yajl_gen_status_ok)
- return -1;
- if (virJSONValueToStringOne(object->data.object.pairs[i].value, g) <
0)
- return -1;
- }
- if (yajl_gen_map_close(g) != yajl_gen_status_ok)
- return -1;
- break;
- case VIR_JSON_TYPE_ARRAY:
- if (yajl_gen_array_open(g) != yajl_gen_status_ok)
- return -1;
- for (i = 0; i < object->data.array.nvalues; i++) {
- if (virJSONValueToStringOne(object->data.array.values[i], g) < 0)
- return -1;
- }
- if (yajl_gen_array_close(g) != yajl_gen_status_ok)
- return -1;
- break;
-
- case VIR_JSON_TYPE_STRING:
- if (yajl_gen_string(g, (unsigned char *)object->data.string,
- strlen(object->data.string)) != yajl_gen_status_ok)
- return -1;
- break;
-
- case VIR_JSON_TYPE_NUMBER:
- if (yajl_gen_number(g, object->data.number,
- strlen(object->data.number)) != yajl_gen_status_ok)
- return -1;
- break;
-
- case VIR_JSON_TYPE_BOOLEAN:
- if (yajl_gen_bool(g, object->data.boolean) != yajl_gen_status_ok)
- return -1;
- break;
-
- case VIR_JSON_TYPE_NULL:
- if (yajl_gen_null(g) != yajl_gen_status_ok)
- return -1;
- break;
-
- default:
- return -1;
- }
-
- return 0;
-}
-
-
-int
-virJSONValueToBuffer(virJSONValue *object,
- virBuffer *buf,
- bool pretty)
-{
- yajl_gen g;
- const unsigned char *str;
- size_t len;
- int ret = -1;
-
- VIR_DEBUG("object=%p", object);
-
- g = yajl_gen_alloc(NULL);
- if (!g) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to create JSON formatter"));
- goto cleanup;
- }
- yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
- yajl_gen_config(g, yajl_gen_indent_string, pretty ? " " : " ");
- yajl_gen_config(g, yajl_gen_validate_utf8, 1);
-
- if (virJSONValueToStringOne(object, g) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to convert virJSONValue to yajl data"));
- goto cleanup;
- }
-
- if (yajl_gen_get_buf(g, &str, &len) != yajl_gen_status_ok) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to format JSON"));
- goto cleanup;
- }
-
- virBufferAdd(buf, (const char *) str, len);
- ret = 0;
-
- cleanup:
- yajl_gen_free(g);
-
- return ret;
-}
-
-
#else
virJSONValue *
virJSONValueFromString(const char *jsonstring G_GNUC_UNUSED)
--
2.46.0