diff options
author | Frédéric Danis <frederic.danis@collabora.com> | 2023-01-13 10:01:41 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2023-04-26 07:31:41 +0100 |
commit | eba81f9866d0814a6c3d6fe47b27d74e3111136c (patch) | |
tree | 032824b249fae2c97e83f42b96dc4246d1ce982a /gusb/gusb-json-common.c | |
parent | 235fec31874a90b346f1c44b3234bf43a6c06355 (diff) | |
download | gusb-eba81f9866d0814a6c3d6fe47b27d74e3111136c.tar.gz |
Add json_object_get_*_member_with_default() helpers
json library previous to version 1.6.0 doesn't provide the
json_object_get_*_member_with_default() functions.
Diffstat (limited to 'gusb/gusb-json-common.c')
-rw-r--r-- | gusb/gusb-json-common.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gusb/gusb-json-common.c b/gusb/gusb-json-common.c new file mode 100644 index 0000000..32d385f --- /dev/null +++ b/gusb/gusb-json-common.c @@ -0,0 +1,27 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2023 Collabora Ltd. + * @author Frédéric Danis <frederic.danis@collabora.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include "config.h" + +#include "gusb-json-common.h" + +#if ! JSON_CHECK_VERSION(1, 6, 0) +const char *json_object_get_string_member_with_default(JsonObject *json_object, const char* member_name, const char* default_value) +{ + if (!json_object_has_member(json_object, member_name)) + return default_value; + return json_object_get_string_member(json_object, member_name); +} + +gint64 json_object_get_int_member_with_default(JsonObject *json_object, const char* member_name, gint64 default_value) +{ + if (!json_object_has_member(json_object, member_name)) + return default_value; + return json_object_get_int_member(json_object, member_name); +} +#endif |