]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - lib/json_writer.c
ip: add support for seg6local End.BPF action
[mirror_iproute2.git] / lib / json_writer.c
index 6b77d288cce2b3f1dfeb46d55c9a8ad81afd26a1..aa9ce1c65e513567f1160248772b7ea4a9caa18b 100644 (file)
@@ -1,14 +1,10 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
 /*
  * Simple streaming JSON writer
  *
  * This takes care of the annoying bits of JSON syntax like the commas
  * after elements
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
  * Authors:    Stephen Hemminger <stephen@networkplumber.org>
  */
 
@@ -180,10 +176,15 @@ void jsonw_end_object(json_writer_t *self)
 void jsonw_start_array(json_writer_t *self)
 {
        jsonw_begin(self, '[');
+       if (self->pretty)
+               putc(' ', self->out);
 }
 
 void jsonw_end_array(json_writer_t *self)
 {
+       if (self->pretty && self->sep)
+               putc(' ', self->out);
+       self->sep = '\0';
        jsonw_end(self, ']');
 }
 
@@ -209,29 +210,47 @@ void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
        jsonw_printf(self, fmt, num);
 }
 
-#ifdef notused
 void jsonw_float(json_writer_t *self, double num)
 {
        jsonw_printf(self, "%g", num);
 }
-#endif
 
 void jsonw_hu(json_writer_t *self, unsigned short num)
 {
        jsonw_printf(self, "%hu", num);
 }
 
-void jsonw_uint(json_writer_t *self, uint64_t num)
+void jsonw_uint(json_writer_t *self, unsigned int num)
+{
+       jsonw_printf(self, "%u", num);
+}
+
+void jsonw_u64(json_writer_t *self, uint64_t num)
 {
        jsonw_printf(self, "%"PRIu64, num);
 }
 
+void jsonw_xint(json_writer_t *self, uint64_t num)
+{
+       jsonw_printf(self, "%"PRIx64, num);
+}
+
+void jsonw_luint(json_writer_t *self, unsigned long int num)
+{
+       jsonw_printf(self, "%lu", num);
+}
+
 void jsonw_lluint(json_writer_t *self, unsigned long long int num)
 {
        jsonw_printf(self, "%llu", num);
 }
 
-void jsonw_int(json_writer_t *self, int64_t num)
+void jsonw_int(json_writer_t *self, int num)
+{
+       jsonw_printf(self, "%d", num);
+}
+
+void jsonw_s64(json_writer_t *self, int64_t num)
 {
        jsonw_printf(self, "%"PRId64, num);
 }
@@ -249,13 +268,11 @@ void jsonw_bool_field(json_writer_t *self, const char *prop, bool val)
        jsonw_bool(self, val);
 }
 
-#ifdef notused
 void jsonw_float_field(json_writer_t *self, const char *prop, double val)
 {
        jsonw_name(self, prop);
        jsonw_float(self, val);
 }
-#endif
 
 void jsonw_float_field_fmt(json_writer_t *self,
                           const char *prop,
@@ -266,18 +283,38 @@ void jsonw_float_field_fmt(json_writer_t *self,
        jsonw_float_fmt(self, fmt, val);
 }
 
-void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num)
+void jsonw_uint_field(json_writer_t *self, const char *prop, unsigned int num)
 {
        jsonw_name(self, prop);
        jsonw_uint(self, num);
 }
 
+void jsonw_u64_field(json_writer_t *self, const char *prop, uint64_t num)
+{
+       jsonw_name(self, prop);
+       jsonw_u64(self, num);
+}
+
+void jsonw_xint_field(json_writer_t *self, const char *prop, uint64_t num)
+{
+       jsonw_name(self, prop);
+       jsonw_xint(self, num);
+}
+
 void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num)
 {
        jsonw_name(self, prop);
        jsonw_hu(self, num);
 }
 
+void jsonw_luint_field(json_writer_t *self,
+                       const char *prop,
+                       unsigned long int num)
+{
+       jsonw_name(self, prop);
+       jsonw_luint(self, num);
+}
+
 void jsonw_lluint_field(json_writer_t *self,
                        const char *prop,
                        unsigned long long int num)
@@ -286,12 +323,18 @@ void jsonw_lluint_field(json_writer_t *self,
        jsonw_lluint(self, num);
 }
 
-void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num)
+void jsonw_int_field(json_writer_t *self, const char *prop, int num)
 {
        jsonw_name(self, prop);
        jsonw_int(self, num);
 }
 
+void jsonw_s64_field(json_writer_t *self, const char *prop, int64_t num)
+{
+       jsonw_name(self, prop);
+       jsonw_s64(self, num);
+}
+
 void jsonw_null_field(json_writer_t *self, const char *prop)
 {
        jsonw_name(self, prop);