From nobody Sat Nov 23 17:11:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723674072326385.1124540158395; Wed, 14 Aug 2024 15:21:12 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 20474B03; Wed, 14 Aug 2024 18:21:11 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AA68D15DD; Wed, 14 Aug 2024 17:44:24 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2827815CA; Wed, 14 Aug 2024 17:44:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D145212BE for ; Wed, 14 Aug 2024 17:43:29 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-2DD1S0vYM_WZPxD2YwEgYQ-1; Wed, 14 Aug 2024 17:43:28 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 528301955F03 for ; Wed, 14 Aug 2024 21:43:27 +0000 (UTC) Received: from hjs.brq.redhat.com (unknown [10.43.3.187]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 65B6F1955E8C for ; Wed, 14 Aug 2024 21:43:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723671809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m3shasuFL6oGSarCOedGxF+wwwkl8KSR8Ru4KZdQbM0=; b=ey/uPi+8rdn5B330XmnJezNpjWsxgRsG/VS5yJReA+qYVqZ4bwtlW4CRrtkD80eu2Hnhy2 RMzPmrZOpjtGUivvN75kkeOJt04mALIYyDdV0klOKE3eqxatI69aHFS45hVjD0lp98CxAo AgRVqM73MTd4unoo4f5XTKG5V6xua+o= X-MC-Unique: 2DD1S0vYM_WZPxD2YwEgYQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: devel@lists.libvirt.org Subject: [libvirt PATCH 19/20] util: drop dead code Date: Wed, 14 Aug 2024 23:40:34 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZYACKQODNRU7DWQNBEO452IQ3F4WZXDF X-Message-ID-Hash: ZYACKQODNRU7DWQNBEO452IQ3F4WZXDF X-MailFrom: jtomko@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723674073231116600 Content-Type: text/plain; charset="utf-8" Now that WITH_YAJL can never be set, we can remove some more code. Signed-off-by: J=C3=A1n Tomko --- src/util/virjson.c | 416 --------------------------------------------- 1 file changed, 416 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 7a22c54f03..98011759fb 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -34,10 +34,6 @@ =20 #if WITH_JSON_C # include -#elif WITH_YAJL -# include -# include - #endif =20 /* XXX fixme */ @@ -1563,418 +1559,6 @@ virJSONValueToBuffer(virJSONValue *object, return ret; } =20 -#elif WITH_YAJL -static int -virJSONParserInsertValue(virJSONParser *parser, - virJSONValue **value) -{ - if (!parser->head) { - parser->head =3D g_steal_pointer(value); - } else { - virJSONParserState *state; - if (!parser->nstate) { - VIR_DEBUG("got a value to insert without a container"); - return -1; - } - - state =3D &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 =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewNull(); - - VIR_DEBUG("parser=3D%p", parser); - - if (virJSONParserInsertValue(parser, &value) < 0) - return 0; - - return 1; -} - - -static int -virJSONParserHandleBoolean(void *ctx, - int boolean_) -{ - virJSONParser *parser =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewBoolean(boolean_); - - VIR_DEBUG("parser=3D%p boolean=3D%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 =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewNumber(g_strndup(s, l= )); - - VIR_DEBUG("parser=3D%p str=3D%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 =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewString(g_strndup((con= st char *)stringVal, stringLen)); - - VIR_DEBUG("parser=3D%p str=3D%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 =3D ctx; - virJSONParserState *state; - - VIR_DEBUG("parser=3D%p key=3D%p", parser, (const char *)stringVal); - - if (!parser->nstate) - return 0; - - state =3D &parser->state[parser->nstate-1]; - if (state->key) - return 0; - state->key =3D g_strndup((const char *)stringVal, stringLen); - return 1; -} - - -static int -virJSONParserHandleStartMap(void *ctx) -{ - virJSONParser *parser =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewObject(); - virJSONValue *tmp =3D value; - - VIR_DEBUG("parser=3D%p", parser); - - if (virJSONParserInsertValue(parser, &value) < 0) - return 0; - - VIR_REALLOC_N(parser->state, parser->nstate + 1); - - parser->state[parser->nstate].value =3D tmp; - parser->state[parser->nstate].key =3D NULL; - parser->nstate++; - - return 1; -} - - -static int -virJSONParserHandleEndMap(void *ctx) -{ - virJSONParser *parser =3D ctx; - virJSONParserState *state; - - VIR_DEBUG("parser=3D%p", parser); - - if (!parser->nstate) - return 0; - - state =3D &(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 =3D ctx; - g_autoptr(virJSONValue) value =3D virJSONValueNewArray(); - virJSONValue *tmp =3D value; - - VIR_DEBUG("parser=3D%p", parser); - - if (virJSONParserInsertValue(parser, &value) < 0) - return 0; - - VIR_REALLOC_N(parser->state, parser->nstate + 1); - - parser->state[parser->nstate].value =3D tmp; - parser->state[parser->nstate].key =3D NULL; - parser->nstate++; - - return 1; -} - - -static int -virJSONParserHandleEndArray(void *ctx) -{ - virJSONParser *parser =3D ctx; - virJSONParserState *state; - - VIR_DEBUG("parser=3D%p", parser); - - if (!(parser->nstate - parser->wrap)) - return 0; - - state =3D &(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 =3D { - 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 =3D { NULL, NULL, 0, 0 }; - virJSONValue *ret =3D NULL; - int rc; - size_t len =3D strlen(jsonstring); - - VIR_DEBUG("string=3D%s", jsonstring); - - hand =3D 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 =3D yajl_parse(hand, (const unsigned char *)jsonstring, len); - if (rc !=3D yajl_status_ok || - yajl_complete_parse(hand) !=3D yajl_status_ok) { - unsigned char *errstr =3D yajl_get_error(hand, 1, - (const unsigned char*)jsons= tring, - 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 !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse json %1$s: unterminated string/map/= array"), - jsonstring); - virJSONValueFree(parser.head); - } else { - ret =3D parser.head; - } - - cleanup: - yajl_free(hand); - - if (parser.nstate) { - size_t i; - for (i =3D 0; i < parser.nstate; i++) - VIR_FREE(parser.state[i].key); - VIR_FREE(parser.state); - } - - VIR_DEBUG("result=3D%p", ret); - - return ret; -} - - -static int -virJSONValueToStringOne(virJSONValue *object, - yajl_gen g) -{ - size_t i; - - VIR_DEBUG("object=3D%p type=3D%d gen=3D%p", object, object->type, g); - - switch (object->type) { - case VIR_JSON_TYPE_OBJECT: - if (yajl_gen_map_open(g) !=3D yajl_gen_status_ok) - return -1; - for (i =3D 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)) - !=3D yajl_gen_status_ok) - return -1; - if (virJSONValueToStringOne(object->data.object.pairs[i].value= , g) < 0) - return -1; - } - if (yajl_gen_map_close(g) !=3D yajl_gen_status_ok) - return -1; - break; - case VIR_JSON_TYPE_ARRAY: - if (yajl_gen_array_open(g) !=3D yajl_gen_status_ok) - return -1; - for (i =3D 0; i < object->data.array.nvalues; i++) { - if (virJSONValueToStringOne(object->data.array.values[i], g) <= 0) - return -1; - } - if (yajl_gen_array_close(g) !=3D 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)) !=3D yajl_gen_sta= tus_ok) - return -1; - break; - - case VIR_JSON_TYPE_NUMBER: - if (yajl_gen_number(g, object->data.number, - strlen(object->data.number)) !=3D yajl_gen_sta= tus_ok) - return -1; - break; - - case VIR_JSON_TYPE_BOOLEAN: - if (yajl_gen_bool(g, object->data.boolean) !=3D yajl_gen_status_ok) - return -1; - break; - - case VIR_JSON_TYPE_NULL: - if (yajl_gen_null(g) !=3D 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 =3D -1; - - VIR_DEBUG("object=3D%p", object); - - g =3D 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) !=3D yajl_gen_status_ok) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to format JSON")); - goto cleanup; - } - - virBufferAdd(buf, (const char *) str, len); - ret =3D 0; - - cleanup: - yajl_gen_free(g); - - return ret; -} - - #else virJSONValue * virJSONValueFromString(const char *jsonstring G_GNUC_UNUSED) --=20 2.45.2