mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
Revert "sd-json: add new sd_json_variant_unset_field() call"
This reverts commit b6a2df6307.
The functionality is entirely redundant, we already have
sd_json_variant_filter() which does the same, and is in fact even more
powerful, since it takes a list instead of a single field to remove.
This commit is contained in:
committed by
Luca Boccassi
parent
5bc576225a
commit
f2b1de6f5b
@@ -806,7 +806,6 @@ manpages = [
|
||||
'sd_journal_seek_tail'],
|
||||
''],
|
||||
['sd_journal_stream_fd', '3', ['sd_journal_stream_fd_with_namespace'], ''],
|
||||
['sd_json_variant_unset_field', '3', [], ''],
|
||||
['sd_listen_fds',
|
||||
'3',
|
||||
['SD_LISTEN_FDS_START', 'sd_listen_fds_with_names'],
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
||||
|
||||
<refentry id="sd_json_variant_unset_field" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
|
||||
<refentryinfo>
|
||||
<title>sd_json_variant_unset_field</title>
|
||||
<productname>systemd</productname>
|
||||
</refentryinfo>
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>sd_json_variant_unset_field</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>sd_json_variant_unset_field</refname>
|
||||
<refpurpose>Remove a specific field from a JSON object</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<funcsynopsis>
|
||||
<funcsynopsisinfo>#include <systemd/sd-json.h></funcsynopsisinfo>
|
||||
|
||||
<funcprototype>
|
||||
<funcdef>int <function>sd_json_variant_unset_field</function></funcdef>
|
||||
<paramdef>sd_json_variant **<parameter>object</parameter></paramdef>
|
||||
<paramdef>const char *<parameter>field</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para><function>sd_json_variant_unset_field()</function> takes a pointer to a pointer to a JSON object
|
||||
and a field name. If the object contains a field under the specified name, a new JSON object is allocated
|
||||
that is a copy of the original one, however the specified field is removed. The object parameter is
|
||||
updated to point to the new object, which has an initial reference counter of one. The reference counter
|
||||
of the original object is decremented by one. Or in other words: the specified object is replaced by one
|
||||
with the field removed.</para>
|
||||
|
||||
<para>If the referenced object does not contain a field matching the specified name, no operation is
|
||||
executed.</para>
|
||||
|
||||
<para>Similar, if a <constant>NULL</constant> pointer is referenced, no operation is executed.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>On success, and if a field was removed <function>sd_json_variant_unset_field()</function> returns a
|
||||
positive non-zero integer. If no matching field was found it returns zero. On failure, it returns a
|
||||
negative errno-style error code.</para>
|
||||
|
||||
<refsect2>
|
||||
<title>Errors</title>
|
||||
|
||||
<para>Returned errors may indicate the following problems:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><constant>-EINVAL</constant></term>
|
||||
|
||||
<listitem><para>An argument is invalid.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><constant>-ENOMEM</constant></term>
|
||||
|
||||
<listitem><para>Memory allocation failed.</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
<xi:include href="libsystemd-pkgconfig.xml" />
|
||||
|
||||
<refsect1>
|
||||
<title>History</title>
|
||||
<para><function>sd_json_variant_unset_field()</function> was added in version 258.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>See Also</title>
|
||||
|
||||
<para><simplelist type="inline">
|
||||
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
|
||||
<member><citerefentry><refentrytitle>sd-json</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
|
||||
</simplelist></para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
@@ -1065,7 +1065,6 @@ global:
|
||||
sd_device_enumerator_add_all_parents;
|
||||
sd_json_variant_type_from_string;
|
||||
sd_json_variant_type_to_string;
|
||||
sd_json_variant_unset_field;
|
||||
sd_varlink_get_current_method;
|
||||
sd_varlink_get_description;
|
||||
sd_varlink_get_input_fd;
|
||||
|
||||
@@ -2129,56 +2129,6 @@ _public_ int sd_json_variant_set_field_strv(sd_json_variant **v, const char *fie
|
||||
return sd_json_variant_set_field(v, field, m);
|
||||
}
|
||||
|
||||
_public_ int sd_json_variant_unset_field(sd_json_variant **v, const char *field) {
|
||||
int r;
|
||||
|
||||
assert_return(v, -EINVAL);
|
||||
assert_return(field, -EINVAL);
|
||||
|
||||
if (sd_json_variant_is_blank_object(*v))
|
||||
return 0;
|
||||
if (!sd_json_variant_is_object(*v))
|
||||
return -EINVAL;
|
||||
|
||||
_cleanup_free_ sd_json_variant **array = NULL;
|
||||
size_t k = 0;
|
||||
for (size_t i = 0, n = sd_json_variant_elements(*v); i < n; i += 2) {
|
||||
sd_json_variant *p;
|
||||
|
||||
p = sd_json_variant_by_index(*v, i);
|
||||
if (!sd_json_variant_is_string(p))
|
||||
return -EINVAL;
|
||||
|
||||
if (streq(sd_json_variant_string(p), field)) {
|
||||
if (!array) {
|
||||
assert(n >= 2);
|
||||
array = new(sd_json_variant*, n - 2);
|
||||
if (!array)
|
||||
return -ENOMEM;
|
||||
|
||||
for (k = 0; k < i; k++)
|
||||
array[k] = sd_json_variant_by_index(*v, k);
|
||||
}
|
||||
} else if (array) {
|
||||
array[k++] = p;
|
||||
array[k++] = sd_json_variant_by_index(*v, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!array)
|
||||
return 0;
|
||||
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
r = sd_json_variant_new_object(&w, array, k);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
json_variant_propagate_sensitive(*v, w);
|
||||
JSON_VARIANT_REPLACE(*v, TAKE_PTR(w));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ int sd_json_variant_merge_object(sd_json_variant **v, sd_json_variant *m) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL;
|
||||
_cleanup_free_ sd_json_variant **array = NULL;
|
||||
|
||||
@@ -168,8 +168,6 @@ int sd_json_variant_set_field_unsigned(sd_json_variant **v, const char *field, u
|
||||
int sd_json_variant_set_field_boolean(sd_json_variant **v, const char *field, int b);
|
||||
int sd_json_variant_set_field_strv(sd_json_variant **v, const char *field, char **l);
|
||||
|
||||
int sd_json_variant_unset_field(sd_json_variant **v, const char *field);
|
||||
|
||||
sd_json_variant* sd_json_variant_find(sd_json_variant *haystack, sd_json_variant *needle);
|
||||
|
||||
int sd_json_variant_append_array(sd_json_variant **v, sd_json_variant *element);
|
||||
|
||||
@@ -1419,42 +1419,4 @@ TEST(fd_info) {
|
||||
pidref_done(&pidref);
|
||||
}
|
||||
|
||||
TEST(json_variant_unset_field) {
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
|
||||
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_is_blank_object(v));
|
||||
ASSERT_OK_ZERO(sd_json_variant_unset_field(&v, "foo"));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_is_blank_object(v));
|
||||
|
||||
ASSERT_NULL(v);
|
||||
|
||||
ASSERT_OK(sd_json_buildo(&v,
|
||||
SD_JSON_BUILD_PAIR_STRING("foo", "bar"),
|
||||
SD_JSON_BUILD_PAIR_STRING("quux", "waldo"),
|
||||
SD_JSON_BUILD_PAIR_STRING("piff", "paff")));
|
||||
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *w = sd_json_variant_ref(v);
|
||||
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_equal(v, w));
|
||||
ASSERT_OK_ZERO(sd_json_variant_unset_field(&v, "fooxxx"));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_equal(v, w));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_unset_field(&v, "foo"));
|
||||
ASSERT_OK_ZERO(sd_json_variant_equal(v, w));
|
||||
|
||||
_cleanup_(sd_json_variant_unrefp) sd_json_variant *x = NULL;
|
||||
ASSERT_OK(sd_json_buildo(&x,
|
||||
SD_JSON_BUILD_PAIR_STRING("quux", "waldo"),
|
||||
SD_JSON_BUILD_PAIR_STRING("piff", "paff")));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_equal(v, x));
|
||||
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_unset_field(&v, "piff"));
|
||||
x = sd_json_variant_unref(x);
|
||||
ASSERT_OK(sd_json_buildo(&x,
|
||||
SD_JSON_BUILD_PAIR_STRING("quux", "waldo")));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_equal(x, v));
|
||||
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_unset_field(&v, "quux"));
|
||||
ASSERT_OK_POSITIVE(sd_json_variant_is_blank_object(v));
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
||||
Reference in New Issue
Block a user