aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-05-06 01:27:03 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-05-06 01:27:03 +0000
commit3e056f675f51f14a5209efe1b491ba897e7873ce (patch)
tree8843997030eac9382a2d817c44b96a5cbe2d391f
parentd7f5140b8b84eb9e27509a1c0fb6872a782b1fe8 (diff)
downloadsg3_utils-3e056f675f51f14a5209efe1b491ba897e7873ce.tar.gz
sg_inq: add support for Hitachi/HP open-v ldev names; sg_rep_zone: more json work
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@951 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog3
-rw-r--r--include/sg_pr2serr.h225
-rw-r--r--lib/sg_pr2serr.c189
-rw-r--r--src/sg_inq.c14
-rw-r--r--src/sg_opcodes.c24
-rw-r--r--src/sg_rep_zones.c175
-rw-r--r--testing/sg_tst_json_builder.c95
7 files changed, 431 insertions, 294 deletions
diff --git a/ChangeLog b/ChangeLog
index ee2df240..29b4b258 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for pre-release sg3_utils-1.48 [20220501] [svn: r950]
+Changelog for pre-release sg3_utils-1.48 [20220505] [svn: r951]
- sg_z_act_query: new utility for sending either a
Zone activate or Zone query command
- sg_rep_density: new utility for decoding the response of
@@ -41,6 +41,7 @@ Changelog for pre-release sg3_utils-1.48 [20220501] [svn: r950]
- sg_modes: improve handling of zbc disks with pdt=0x14
- sg_inq, sg_vpd: Device Identication VPD page, change
"IEEE Company_id" to "AOI" as per spc6r06.pdf
+ - add support for Hitachi/HP open-v ldev names
- sg_opcodes: cleanup error reporting
- add --inhex=FN to process earlier -HHH
- add experimental --json[=JO] option and generation
diff --git a/include/sg_pr2serr.h b/include/sg_pr2serr.h
index b13432fc..b29c7e34 100644
--- a/include/sg_pr2serr.h
+++ b/include/sg_pr2serr.h
@@ -10,12 +10,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-/* These are convenience functions that replace the somewhat long-winded
- * fprintf(stderr, ....). The second form (i.e. pr2ws() ) is for internal
- * library use and may place its output somewhere other than stderr; it
- * depends on the external variable sg_warnings_strm which can be set
- * with sg_set_warnings_strm(). By default it uses stderr. */
-
#include <inttypes.h>
#include <stdio.h>
#include <stdbool.h>
@@ -24,40 +18,11 @@
extern "C" {
#endif
-#if 1
-enum sg_json_separator_t {
- SG_JSON_SEP_NONE = 0,
- SG_JSON_SEP_SPACE_1,
- SG_JSON_SEP_SPACE_2,
- SG_JSON_SEP_SPACE_3,
- SG_JSON_SEP_SPACE_4,
- SG_JSON_SEP_EQUAL_NO_SPACE,
- SG_JSON_SEP_EQUAL_1_SPACE,
- SG_JSON_SEP_COLON_NO_SPACE,
- SG_JSON_SEP_COLON_1_SPACE,
-};
-#endif
-
-typedef void * sg_json_opaque_p;
-
-typedef struct sg_json_state_t {
- bool pr_as_json;
- bool pr_pretty;
- bool pr_header;
- bool pr_sorted;
- bool pr_output;
- bool pr_implemented;
- bool pr_unimplemented;
- char pr_format;
- int pr_indent_size;
- int first_bad_char;
- int verbose;
- /* the following hold state information */
- sg_json_opaque_p basep; /* base JSON object pointer */
- sg_json_opaque_p outputp; /* 'output' named JSON array pointer */
- sg_json_opaque_p userp; /* for temporary usage */
-} sg_json_state;
-
+/* pr2serr and pr2ws are convenience functions that replace the somewhat
+ * long-winded fprintf(stderr, ....). The second form (i.e. pr2ws() ) is for
+ * internal library use and may place its output somewhere other than stderr;
+ * it depends on the external variable sg_warnings_strm which can be set
+ * with sg_set_warnings_strm(). By default it uses stderr. */
#if __USE_MINGW_ANSI_STDIO -0 == 1
#define __printf(a, b) __attribute__((__format__(gnu_printf, a, b)))
@@ -80,66 +45,148 @@ int pr2ws(const char * fmt, ...) __printf(1, 2);
* 0). Linux kernel has a similar function called scnprintf(). */
int sg_scnpr(char * cp, int cp_max_len, const char * fmt, ...) __printf(3, 4);
-void sgj_pr_hr(sg_json_state * jsp, const char * fmt, ...) __printf(2, 3);
-
-bool sgj_init_state(sg_json_state * jstp, const char * j_optarg);
-
-sg_json_opaque_p sgj_start(const char * util_name, const char * ver_str,
- int argc, char *argv[], sg_json_state * jstp);
-
-/* Newly created object is un-attached */
-sg_json_opaque_p sgj_new_object(sg_json_state * jsp);
-
-sg_json_opaque_p sgj_new_named_object(sg_json_state * jsp,
- sg_json_opaque_p jop,
- const char * name);
-
-sg_json_opaque_p sgj_add_array_element(sg_json_state * jsp,
- sg_json_opaque_p jap,
- sg_json_opaque_p ejop);
-
-sg_json_opaque_p sgj_new_named_array(sg_json_state * jsp,
- sg_json_opaque_p jop,
- const char * name);
-
-sg_json_opaque_p sgj_add_name_vs(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name, const char * value);
-
-sg_json_opaque_p sgj_add_name_vi(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name, int64_t value);
-
-sg_json_opaque_p sgj_add_name_vb(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name, bool value);
-
-void sgj_pr_simple_vs(sg_json_state * jsp, sg_json_opaque_p jop,
- int leadin_sp, const char * name,
- enum sg_json_separator_t sep, const char * value);
-
-void sgj_pr_simple_vi(sg_json_state * jsp, sg_json_opaque_p jop,
- int leadin_sp, const char * name,
- enum sg_json_separator_t sep, int64_t value);
-
-void sgj_pr_simple_vb(sg_json_state * jsp, sg_json_opaque_p jop,
- int leadin_sp, const char * name,
- enum sg_json_separator_t sep, bool value);
+/* JSON support functions and structures follow. The prefix "sgj_" is used
+ * for sg3_utils JSON functions, types and values. */
+
+enum sgj_separator_t {
+ SGJ_SEP_NONE = 0,
+ SGJ_SEP_SPACE_1,
+ SGJ_SEP_SPACE_2,
+ SGJ_SEP_SPACE_3,
+ SGJ_SEP_SPACE_4,
+ SGJ_SEP_EQUAL_NO_SPACE,
+ SGJ_SEP_EQUAL_1_SPACE,
+ SGJ_SEP_COLON_NO_SPACE,
+ SGJ_SEP_COLON_1_SPACE,
+};
-void sgj_add_name_pair_ihex(sg_json_state * jsp, sg_json_opaque_p jop,
+typedef void * sgj_opaque_p;
+
+/* Apart from the pointers at the end the other fields are initialized
+ * from the argument given to --json= . If there is no argument then
+ * they initialized as shown. */
+typedef struct sgj_state_t {
+ bool pr_as_json; /* = false */
+ bool pr_pretty; /* = true */
+ bool pr_header; /* = true */
+ bool pr_sorted; /* = false (ignored) */
+ bool pr_output; /* = false */
+ bool pr_implemented;
+ bool pr_unimplemented;
+ char pr_format; /* = '\0' */
+ int pr_indent_size; /* = 4 */
+ int first_bad_char; /* = '\0' */
+ int verbose; /* = 0 */
+ /* the following hold state information */
+ sgj_opaque_p basep; /* base JSON object pointer */
+ sgj_opaque_p outputp; /* 'output' named JSON array pointer */
+ sgj_opaque_p userp; /* for temporary usage */
+} sgj_state;
+
+/* Prints to stdout like printf(fmt, ...). Further if --json=o option is
+ * given that output line is also placed in the JSON 'output' array. */
+void sgj_pr_hr(sgj_state * jsp, const char * fmt, ...) __printf(2, 3);
+
+/* Initializes the state object pointed to by jsp based on the argument
+ * given to the right of --json= pointed to by j_optarg. If it is NULL
+ * then state object gets its default values. Returns true if argument
+ * to --json= is decoded properly, else returns false and places the
+ * first "bad" character in jsp->first_bad_char . Note that no JSON
+ * in-core tree needs to exist when this function is called. */
+bool sgj_init_state(sgj_state * jsp, const char * j_optarg);
+
+/* sgj_start() creates a JSON in-core tree and returns a pointer to it (or
+ * NULL if the associated heap allocation fails). It should be paired with
+ * sgj_finish() to clean up (i.e. remove all heap allocations) all the
+ * elements (i.e. JSON objects and arrays) that have been placed in that
+ * in-core tree. If jsp is NULL nothing further happens. Otherwise the pointer
+ * to be returned is placed in jsp->basep. If jsp->pr_header is true and
+ * util_name is non-NULL then a "utility_invoked" JSON object is made with
+ * "name", and "version_date" object fields. If the jsp->pr_output field is
+ * true a named array called "output" is added to the "utility_invoked" object
+ * (creating it in the case when jsp->pr_header is false) and a pointer to
+ * that array object is placed in jsp->objectp . The returned pointer is not
+ * usually needed but if it is NULL then a heap allocation has failed. */
+sgj_opaque_p sgj_start(const char * util_name, const char * ver_str,
+ int argc, char *argv[], sgj_state * jsp);
+
+/* These are low level functions returning a pointer to a newly created JSON
+ * object or array. If jsp is NULL or jsp->pr_as_json is false nothing happens
+ * and NULL is returned. Note that this JSON object is _not_ placed in the
+ * in-core tree controlled by jsp (jsp->basep); it may be added later as the
+ * third argument to sgj_add_array_element(), for example. */
+sgj_opaque_p sgj_new_unattached_object(sgj_state * jsp);
+sgj_opaque_p sgj_new_unattached_array(sgj_state * jsp);
+
+/* If jsp is NULL or jsp->pr_as_json is false nothing happens and NULL is
+ * returned. Otherwise it creates a new named object (whose name is what
+ * 'name' points to) at 'jop' with an empty object as its value; a pointer
+ * to that empty object is returned. If 'jop' is NULL then jsp->basep is
+ * used instead. The returned value should always be checked (for NULL)
+ * and if not, used. */
+sgj_opaque_p sgj_new_named_object(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name);
+
+/* If jsp is NULL or jsp->pr_as_json is false nothing happens and NULL is
+ * returned. Otherwise it creates a new named object (whose name is what
+ * 'name' points to) at 'jop' with an empty array as its value; a pointer
+ * to that empty array is returned. If 'jop' is NULL then jsp->basep is
+ * used instead. The returned value should always * be checked (for NULL)
+ * and if not, used. */
+sgj_opaque_p sgj_new_named_array(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name);
+
+/* If jsp is NULL or jsp->pr_as_json is false or ua_jop is NULL nothing
+ * happens and NULL is returned. Otherwise it adds a new array element
+ * (ua_jop) to the array ('jap') that was returned by sgj_new_named_array().
+ * ua_jop is assumed to not been part of the main JSON in-core tree before
+ * this call, and it is after this call. This means that ua_jop must have
+ * been created by sgj_new_unattached_object() or similar. */
+sgj_opaque_p sgj_add_array_element(sgj_state * jsp, sgj_opaque_p jap,
+ sgj_opaque_p ua_jop);
+
+sgj_opaque_p sgj_add_name_vs(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, const char * value);
+
+sgj_opaque_p sgj_add_name_vi(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, int64_t value);
+
+sgj_opaque_p sgj_add_name_vb(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, bool value);
+
+sgj_opaque_p sgj_add_name_obj(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, sgj_opaque_p ua_jop);
+
+void sgj_pr_twin_vs(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep,
+ const char * value);
+
+void sgj_pr_twin_vi(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep,
+ int64_t value);
+
+void sgj_pr_twin_vb(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep, bool value);
+
+void sgj_add_name_pair_ihex(sgj_state * jsp, sgj_opaque_p jop,
const char * name, uint64_t value);
-void sgj_add_name_pair_istr(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name, int64_t value,
- const char * str);
+void sgj_add_name_pair_istr(sgj_state * jsp, sgj_opaque_p jop,
+ const char * name, int64_t val_i,
+ const char * val_s);
#if 0
-void sgj_pr_hr_line_vs(sg_json_state * jsp, sg_json_opaque_p jop,
+void sgj_pr_hr_line_vs(sgj_state * jsp, sgj_opaque_p jop,
const char * hr_line, const char * name,
const char * value);
#endif
-void sgj_pr2file(sg_json_state * jsp, sg_json_opaque_p jop, int exit_status,
+void sgj_pr2file(sgj_state * jsp, sgj_opaque_p jop, int exit_status,
FILE * fp);
-void sgj_finish(sg_json_state * jstp);
+void sgj_free_unattached(sgj_opaque_p jop);
+
+void sgj_finish(sgj_state * jsp);
#ifdef __cplusplus
diff --git a/lib/sg_pr2serr.c b/lib/sg_pr2serr.c
index 91fd9907..70807671 100644
--- a/lib/sg_pr2serr.c
+++ b/lib/sg_pr2serr.c
@@ -67,7 +67,7 @@ scnpr(char * cp, int cp_max_len, const char * fmt, ...)
}
bool
-sgj_init_state(sg_json_state * jstp, const char * j_optarg)
+sgj_init_state(sgj_state * jstp, const char * j_optarg)
{
bool bad_arg = false;
bool prev_exclam = false;
@@ -155,18 +155,20 @@ sgj_init_state(sg_json_state * jstp, const char * j_optarg)
return ! bad_arg;
}
-sg_json_opaque_p
+sgj_opaque_p
sgj_start(const char * util_name, const char * ver_str, int argc,
- char *argv[], sg_json_state * jstp)
+ char *argv[], sgj_state * jstp)
{
int k;
json_value * jvp = json_object_new(0);
- json_value * jv2p;
+ json_value * jv2p = NULL;
json_value * jap = NULL;
if (NULL == jvp)
return NULL;
+ if (NULL == jstp)
+ return jvp;
jstp->basep = jvp;
if (jstp->pr_header) {
@@ -175,30 +177,36 @@ sgj_start(const char * util_name, const char * ver_str, int argc,
json_builder_free(jvp);
return NULL;
}
+ /* assume rest of json_*_new() calls succeed */
json_array_push(jap, json_integer_new(1));
json_array_push(jap, json_integer_new(0));
json_object_push(jvp, "json_format_version", jap);
- jap = json_array_new(0);
- for (k = 0; k < argc; ++k)
- json_array_push(jap, json_string_new(argv[k]));
- jv2p = json_object_push(jvp, util_name, json_object_new(0));
- if (ver_str)
- json_object_push(jv2p, "version_date", json_string_new(ver_str));
- else
- json_object_push(jv2p, "version_date", json_string_new("0.0"));
- json_object_push(jv2p, "argv", jap);
+ if (util_name) {
+ jap = json_array_new(0);
+ for (k = 0; k < argc; ++k)
+ json_array_push(jap, json_string_new(argv[k]));
+ jv2p = json_object_push(jvp, "utility_invoked",
+ json_object_new(0));
+ json_object_push(jv2p, "name", json_string_new(util_name));
+ if (ver_str)
+ json_object_push(jv2p, "version_date",
+ json_string_new(ver_str));
+ else
+ json_object_push(jv2p, "version_date", json_string_new("0.0"));
+ json_object_push(jv2p, "argv", jap);
+ }
+ } else {
+ if (jstp->pr_output && util_name)
+ jv2p = json_object_push(jvp, "utility_invoked",
+ json_object_new(0));
}
- if (jstp->pr_output) {
- if (! jstp->pr_header)
- jv2p = json_object_push(jvp, util_name, json_object_new(0));
+ if (jstp->pr_output && jv2p)
jstp->outputp = json_object_push(jv2p, "output", json_array_new(0));
- }
return jvp;
}
void
-sgj_pr2file(sg_json_state * jstp, sg_json_opaque_p jop, int exit_status,
- FILE * fp)
+sgj_pr2file(sgj_state * jstp, sgj_opaque_p jop, int exit_status, FILE * fp)
{
size_t len;
char * b;
@@ -236,7 +244,7 @@ sgj_pr2file(sg_json_state * jstp, sg_json_opaque_p jop, int exit_status,
}
void
-sgj_finish(sg_json_state * jsp)
+sgj_finish(sgj_state * jsp)
{
if (jsp && jsp->basep) {
json_builder_free(jsp->basep);
@@ -247,7 +255,14 @@ sgj_finish(sg_json_state * jsp)
}
void
-sgj_pr_hr(sg_json_state * jsp, const char * fmt, ...)
+sgj_free_unattached(sgj_opaque_p jop)
+{
+ if (jop)
+ json_builder_free(jop);
+}
+
+void
+sgj_pr_hr(sgj_state * jsp, const char * fmt, ...)
{
va_list args;
@@ -283,88 +298,105 @@ sgj_pr_hr(sg_json_state * jsp, const char * fmt, ...)
}
}
-sg_json_opaque_p
-sgj_new_named_object(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name)
+/* jop will 'own' returned value (if non-NULL) */
+sgj_opaque_p
+sgj_new_named_object(sgj_state * jsp, sgj_opaque_p jop, const char * name)
{
- sg_json_opaque_p resp = NULL;
+ sgj_opaque_p resp = NULL;
- if (jsp->pr_as_json)
+ if (jsp && jsp->pr_as_json)
resp = json_object_push((jop ? jop : jsp->basep), name,
json_object_new(0));
return resp;
}
-sg_json_opaque_p
-sgj_new_named_array(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name)
+/* jop will 'own' returned value (if non-NULL) */
+sgj_opaque_p
+sgj_new_named_array(sgj_state * jsp, sgj_opaque_p jop, const char * name)
{
- sg_json_opaque_p resp = NULL;
+ sgj_opaque_p resp = NULL;
- if (jsp->pr_as_json)
+ if (jsp && jsp->pr_as_json)
resp = json_object_push((jop ? jop : jsp->basep), name,
json_array_new(0));
return resp;
}
-sg_json_opaque_p
-sgj_add_array_element(sg_json_state * jsp, sg_json_opaque_p jap,
- sg_json_opaque_p ejop)
+/* jap will 'own' ua_jop (if returned value is non-NULL) */
+sgj_opaque_p
+sgj_add_array_element(sgj_state * jsp, sgj_opaque_p jap, sgj_opaque_p ua_jop)
{
- if (jsp->pr_as_json)
- return json_array_push(jap, ejop);
+ if (jsp && ua_jop && jsp->pr_as_json)
+ return json_array_push(jap, ua_jop);
else
return NULL;
}
-/* Newly created object is un-attached */
-sg_json_opaque_p
-sgj_new_object(sg_json_state * jsp)
+/* Newly created object is un-attached to jsp->basep tree */
+sgj_opaque_p
+sgj_new_unattached_object(sgj_state * jsp)
{
- return jsp->pr_as_json ? json_object_new(0) : NULL;
+ return (jsp && jsp->pr_as_json) ? json_object_new(0) : NULL;
}
-sg_json_opaque_p
-sgj_add_name_vs(sg_json_state * jsp, sg_json_opaque_p jop, const char * name,
+/* Newly created array is un-attached to jsp->basep tree */
+sgj_opaque_p
+sgj_new_unattached_array(sgj_state * jsp)
+{
+ return (jsp && jsp->pr_as_json) ? json_array_new(0) : NULL;
+}
+
+sgj_opaque_p
+sgj_add_name_vs(sgj_state * jsp, sgj_opaque_p jop, const char * name,
const char * value)
{
- if (jsp->pr_as_json)
+ if (jsp && jsp->pr_as_json)
return json_object_push((jop ? jop : jsp->basep), name,
json_string_new(value));
else
return NULL;
}
-sg_json_opaque_p
-sgj_add_name_vi(sg_json_state * jsp, sg_json_opaque_p jop, const char * name,
+sgj_opaque_p
+sgj_add_name_vi(sgj_state * jsp, sgj_opaque_p jop, const char * name,
int64_t value)
{
- if (jsp->pr_as_json)
+ if (jsp && jsp->pr_as_json)
return json_object_push((jop ? jop : jsp->basep), name,
json_integer_new(value));
else
return NULL;
}
-sg_json_opaque_p
-sgj_add_name_vb(sg_json_state * jsp, sg_json_opaque_p jop, const char * name,
+sgj_opaque_p
+sgj_add_name_vb(sgj_state * jsp, sgj_opaque_p jop, const char * name,
bool value)
{
- if (jsp->pr_as_json)
+ if (jsp && jsp->pr_as_json)
return json_object_push((jop ? jop : jsp->basep), name,
json_boolean_new(value));
else
return NULL;
}
+sgj_opaque_p
+sgj_add_name_obj(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+ sgj_opaque_p ua_jop)
+{
+ if (jsp && jsp->pr_as_json && ua_jop)
+ return json_object_push((jop ? jop : jsp->basep), name, ua_jop);
+ else
+ return NULL;
+}
+
void
-sgj_add_name_pair_ihex(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * name, uint64_t value)
+sgj_add_name_pair_ihex(sgj_state * jsp, sgj_opaque_p jop, const char * name,
+ uint64_t value)
{
if ((NULL == jsp) || (! jsp->pr_as_json))
return;
else {
- sg_json_opaque_p jo2p =
+ sgj_opaque_p jo2p =
sgj_new_named_object(jsp, (jop ? jop : jsp->basep), name);
char b[64];
@@ -377,13 +409,13 @@ sgj_add_name_pair_ihex(sg_json_state * jsp, sg_json_opaque_p jop,
}
void
-sgj_add_name_pair_istr(sg_json_state * jsp, sg_json_opaque_p jop,
+sgj_add_name_pair_istr(sgj_state * jsp, sgj_opaque_p jop,
const char * name, int64_t value, const char * str)
{
if ((NULL == jsp) || (! jsp->pr_as_json))
return;
else {
- sg_json_opaque_p jo2p =
+ sgj_opaque_p jo2p =
sgj_new_named_object(jsp, (jop ? jop : jsp->basep), name);
if (NULL == jo2p)
return;
@@ -433,9 +465,8 @@ sgj_jsonify_name(const char * in, char * out, int maxlen_out)
}
static void
-sgj_pr_simple_xx(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
- const char * name, enum sg_json_separator_t sep,
- json_value * jvp)
+sgj_pr_twin_xx(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep, json_value * jvp)
{
bool eaten = false;
bool as_json = (jsp && jsp->pr_as_json);
@@ -495,30 +526,30 @@ sgj_pr_simple_xx(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
}
if (jvp && ((as_json && jsp->pr_output) || (! as_json))) {
switch (sep) {
- case SG_JSON_SEP_NONE:
+ case SGJ_SEP_NONE:
break;
- case SG_JSON_SEP_SPACE_1:
+ case SGJ_SEP_SPACE_1:
n += scnpr(b + n, blen - n, " ");
break;
- case SG_JSON_SEP_SPACE_2:
+ case SGJ_SEP_SPACE_2:
n += scnpr(b + n, blen - n, " ");
break;
- case SG_JSON_SEP_SPACE_3:
+ case SGJ_SEP_SPACE_3:
n += scnpr(b + n, blen - n, " ");
break;
- case SG_JSON_SEP_SPACE_4:
+ case SGJ_SEP_SPACE_4:
n += scnpr(b + n, blen - n, " ");
break;
- case SG_JSON_SEP_EQUAL_NO_SPACE:
+ case SGJ_SEP_EQUAL_NO_SPACE:
n += scnpr(b + n, blen - n, "=");
break;
- case SG_JSON_SEP_EQUAL_1_SPACE:
+ case SGJ_SEP_EQUAL_1_SPACE:
n += scnpr(b + n, blen - n, "= ");
break;
- case SG_JSON_SEP_COLON_NO_SPACE:
+ case SGJ_SEP_COLON_NO_SPACE:
n += scnpr(b + n, blen - n, ":");
break;
- case SG_JSON_SEP_COLON_1_SPACE:
+ case SGJ_SEP_COLON_1_SPACE:
n += scnpr(b + n, blen - n, ": ");
break;
default:
@@ -549,43 +580,41 @@ sgj_pr_simple_xx(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
}
void
-sgj_pr_simple_vs(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
- const char * name, enum sg_json_separator_t sep,
- const char * value)
+sgj_pr_twin_vs(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep,
+ const char * value)
{
json_value * jvp;
/* make json_value even if jsp->pr_as_json is false */
jvp = value ? json_string_new(value) : NULL;
- sgj_pr_simple_xx(jsp, jop, leadin_sp, name, sep, jvp);
+ sgj_pr_twin_xx(jsp, jop, leadin_sp, name, sep, jvp);
}
void
-sgj_pr_simple_vi(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
- const char * name, enum sg_json_separator_t sep,
- int64_t value)
+sgj_pr_twin_vi(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep, int64_t value)
{
json_value * jvp;
jvp = json_integer_new(value);
- sgj_pr_simple_xx(jsp, jop, leadin_sp, name, sep, jvp);
+ sgj_pr_twin_xx(jsp, jop, leadin_sp, name, sep, jvp);
}
void
-sgj_pr_simple_vb(sg_json_state * jsp, sg_json_opaque_p jop, int leadin_sp,
- const char * name, enum sg_json_separator_t sep,
- bool value)
+sgj_pr_twin_vb(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
+ const char * name, enum sgj_separator_t sep, bool value)
{
json_value * jvp;
jvp = json_boolean_new(value);
- sgj_pr_simple_xx(jsp, jop, leadin_sp, name, sep, jvp);
+ sgj_pr_twin_xx(jsp, jop, leadin_sp, name, sep, jvp);
}
#if 0
void
-sgj_pr_hr_line_vs(sg_json_state * jsp, sg_json_opaque_p jop,
- const char * hr_line, const char * name, const char * value)
+sgj_pr_hr_line_vs(sgj_state * jsp, sgj_opaque_p jop, const char * hr_line,
+ const char * name, const char * value)
{
}
#endif
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 92333975..8e3b8c6f 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -51,7 +51,7 @@
#include "sg_pt_nvme.h"
#endif
-static const char * version_str = "2.16 20220217"; /* spc6r06 */
+static const char * version_str = "2.17 20220504"; /* spc6r06 */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -2029,7 +2029,7 @@ decode_softw_inf_id(uint8_t * buff, int len, int do_hex)
buff += 4;
for ( ; len > 5; len -= 6, buff += 6)
printf(" IEEE identifier: 0x%" PRIx64 "\n",
- sg_get_unaligned_be48(buff + 0));
+ sg_get_unaligned_be48(buff + 0));
}
/* VPD_ATA_INFO [0x89] */
@@ -2928,6 +2928,16 @@ std_inq_decode(const struct opts_t * op, int act_len)
} else
printf(" Vendor specific: %s\n", xtra_buff);
}
+ if (op->do_vendor && (act_len > 243) &&
+ (0 == strncmp("OPEN-V", (const char *)&rp[16], 6))) {
+ memcpy(xtra_buff, &rp[212], 32);
+ if (op->do_export) {
+ len = encode_whitespaces((uint8_t *)xtra_buff, 32);
+ if (len > 0)
+ printf("VENDOR_SPECIFIC_OPEN-V_LDEV_NAME=%s\n", xtra_buff);
+ } else
+ printf(" Vendor specific OPEN-V LDEV Name: %s\n", xtra_buff);
+ }
}
if (! op->do_export) {
if ((0 == op->resp_len) && usn_buff[0])
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index f0615612..cf343a18 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -33,7 +33,7 @@
#include "sg_pt.h"
-static const char * version_str = "0.78 20220428"; /* spc6r06 */
+static const char * version_str = "0.80 20220505"; /* spc6r06 */
#define MY_NAME "sg_opcodes"
@@ -104,7 +104,7 @@ struct opts_t {
int verbose;
const char * device_name;
const char * inhex_fn;
- sg_json_state json_st;
+ sgj_state json_st;
};
@@ -712,9 +712,9 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
unsigned int timeout;
uint8_t * bp;
uint8_t ** sort_arr = NULL;
- sg_json_state * jsp = &op->json_st;
- sg_json_opaque_p jap = NULL;
- sg_json_opaque_p jop = NULL;
+ sgj_state * jsp = &op->json_st;
+ sgj_opaque_p jap = NULL;
+ sgj_opaque_p jop = NULL;
char name_buff[NAME_BUFF_SZ];
char sa_buff[8];
char b[192];
@@ -781,7 +781,7 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
jap = sgj_new_named_array(jsp, jsp->basep, "all_command_descriptor");
for (k = 0, j = 0; k < cd_len; ++j, k += len) {
- jop = sgj_new_object(jsp);
+ jop = sgj_new_unattached_object(jsp);
bp = op->do_unsorted ? (rsoc_buff + 4 + k) : sort_arr[j];
byt5 = bp[5];
@@ -897,7 +897,7 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op,
if (jsp->pr_as_json) {
int l;
char *b2p = b + nn;
- sg_json_opaque_p jo2p = sgj_new_named_object(jsp, jop,
+ sgj_opaque_p jo2p = sgj_new_named_object(jsp, jop,
"one_command_descriptor");
l = strlen(b2p);
@@ -924,7 +924,7 @@ decode_cmd_timeout_desc(uint8_t * dp, int max_b_len, char * b,
{
int len;
unsigned int timeout;
- sg_json_state * jsp = &op->json_st;
+ sgj_state * jsp = &op->json_st;
if ((max_b_len < 2) || (NULL == dp))
return;
@@ -973,8 +973,8 @@ list_one(uint8_t * rsoc_buff, int cd_len, int rep_opts,
const char * cp;
const char * dlp;
const char * mlu_p;
- sg_json_state * jsp = &op->json_st;
- sg_json_opaque_p jop = NULL;
+ sgj_state * jsp = &op->json_st;
+ sgj_opaque_p jop = NULL;
char name_buff[NAME_BUFF_SZ];
char d[64];
char b[192];
@@ -1115,8 +1115,8 @@ main(int argc, char * argv[])
uint8_t * rsoc_buff = NULL;
uint8_t * free_rsoc_buff = NULL;
struct sg_pt_base * ptvp = NULL;
- sg_json_state * jsp;
- sg_json_opaque_p jop = NULL;
+ sgj_state * jsp;
+ sgj_opaque_p jop = NULL;
char buff[48];
char b[80];
struct sg_simple_inquiry_resp inq_resp;
diff --git a/src/sg_rep_zones.c b/src/sg_rep_zones.c
index 353c1eda..faa89d29 100644
--- a/src/sg_rep_zones.c
+++ b/src/sg_rep_zones.c
@@ -40,7 +40,7 @@
* Based on zbc2r12.pdf
*/
-static const char * version_str = "1.35 20220501";
+static const char * version_str = "1.36 20220505";
#define MY_NAME "sg_rep_zones"
@@ -84,7 +84,7 @@ struct opts_t {
int vb;
uint64_t st_lba;
const char * in_fn;
- sg_json_state json_st;
+ sgj_state json_st;
};
struct zt_num2abbrev_t {
@@ -382,7 +382,7 @@ static const char * same_desc_arr[16] = {
static uint64_t
prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op,
- sg_json_state * jsp, sg_json_opaque_p jop)
+ sgj_state * jsp, sgj_opaque_p jop)
{
uint8_t zt, zc;
uint64_t lba, len, wp;
@@ -397,12 +397,12 @@ prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op,
zone_condition_str(zc, b, sizeof(b), op->vb);
sgj_pr_hr(jsp, " Zone condition: %s\n", b);
sgj_add_name_pair_istr(jsp, jop, "zone_condition", zc, b);
- sgj_pr_simple_vi(jsp, jop, 3, "PUEP", SG_JSON_SEP_COLON_1_SPACE,
- !!(bp[1] & 0x4));
- sgj_pr_simple_vi(jsp, jop, 3, "NON_SEQ", SG_JSON_SEP_COLON_1_SPACE,
- !!(bp[1] & 0x2));
- sgj_pr_simple_vi(jsp, jop, 3, "RESET", SG_JSON_SEP_COLON_1_SPACE,
- !!(bp[1] & 0x1));
+ sgj_pr_twin_vi(jsp, jop, 3, "PUEP", SGJ_SEP_COLON_1_SPACE,
+ !!(bp[1] & 0x4));
+ sgj_pr_twin_vi(jsp, jop, 3, "NON_SEQ", SGJ_SEP_COLON_1_SPACE,
+ !!(bp[1] & 0x2));
+ sgj_pr_twin_vi(jsp, jop, 3, "RESET", SGJ_SEP_COLON_1_SPACE,
+ !!(bp[1] & 0x1));
len = sg_get_unaligned_be64(bp + 8);
sgj_pr_hr(jsp, " Zone Length: 0x%" PRIx64 "\n", len);
sgj_add_name_pair_ihex(jsp, jop, "zone_length", (int64_t)len);
@@ -420,13 +420,13 @@ prt_a_zn_desc(const uint8_t *bp, const struct opts_t * op,
static int
decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
- const struct opts_t * op, sg_json_state * jsp)
+ const struct opts_t * op, sgj_state * jsp)
{
bool as_json = jsp ? jsp->pr_as_json : false;
int k, same, num_zd;
uint64_t wp, ul, mx_lba;
- sg_json_opaque_p jop = jsp ? jsp->basep : NULL;
- sg_json_opaque_p jap = NULL;
+ sgj_opaque_p jop = jsp ? jsp->basep : NULL;
+ sgj_opaque_p jap = NULL;
const uint8_t * bp;
if ((uint32_t)act_len < decod_len) {
@@ -478,20 +478,22 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
hex2stdout(bp, 64, -1);
return 0;
}
- printf("From last descriptor in this response:\n");
- printf(" %s%d\n", zn_dnum_s, num_zd - 1);
+ sgj_pr_hr(jsp, "From last descriptor in this response:\n");
+ sgj_pr_hr(jsp, " %s%d\n", zn_dnum_s, num_zd - 1);
+ sgj_add_name_vi(jsp, jop, "zone_descriptor_index", num_zd - 1);
ul = prt_a_zn_desc(bp, op, jsp, jop);
if (ul > mx_lba)
- printf(" >> This zone seems to be the last one\n");
+ sgj_pr_hr(jsp, " >> This zone seems to be the last one\n");
else
- printf(" >> Probable next Zone start LBA: 0x%" PRIx64 "\n", ul);
+ sgj_pr_hr(jsp, " >> Probable next Zone start LBA: 0x%" PRIx64
+ "\n", ul);
return 0;
}
if (as_json)
- jap = sgj_new_named_array(jsp, NULL, "zone_descriptor_list");
+ jap = sgj_new_named_array(jsp, NULL, "zone_descriptors_list");
for (k = 0, bp = rzBuff + 64; k < num_zd;
++k, bp += REPORT_ZONES_DESC_LEN) {
- sg_json_opaque_p jo2p;
+ sgj_opaque_p jo2p;
if (! op->wp_only)
sgj_pr_hr(jsp, " %s%d\n", zn_dnum_s, k);
@@ -505,33 +507,39 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
else {
wp = sg_get_unaligned_be64(bp + 24);
if (sg_all_ffs((const uint8_t *)&wp, sizeof(wp)))
- printf("-1\n");
+ sgj_pr_hr(jsp, "-1\n");
else
- printf("0x%" PRIx64 "\n", wp);
+ sgj_pr_hr(jsp, "0x%" PRIx64 "\n", wp);
+ jo2p = sgj_new_unattached_object(jsp);
+ sgj_add_name_pair_ihex(jsp, jo2p, "write_pointer_lba",
+ (int64_t)wp);
+ sgj_add_array_element(jsp, jap, jo2p);
}
continue;
}
- jo2p = as_json ? sgj_new_object(jsp) : NULL;
+ jo2p = sgj_new_unattached_object(jsp);
prt_a_zn_desc(bp, op, jsp, jo2p);
- if (jo2p)
- sgj_add_array_element(jsp, jap, jo2p);
+ sgj_add_array_element(jsp, jap, jo2p);
}
if ((op->do_num == 0) && (! op->wp_only) && (! op->do_hex)) {
if ((64 + (REPORT_ZONES_DESC_LEN * (uint32_t)num_zd)) < decod_len)
- printf("\n>>> Beware: Zone list truncated, may need another "
- "call\n");
+ sgj_pr_hr(jsp, "\n>>> Beware: Zone list truncated, may need "
+ "another call\n");
}
return 0;
}
static int
decode_rep_realms(const uint8_t * rzBuff, int act_len,
- const struct opts_t * op)
+ const struct opts_t * op, sgj_state * jsp)
{
uint32_t k, realms_count, derived_realms_count, r_desc_len,
zdomains_count;
uint64_t nr_locator;
const uint8_t * bp;
+ sgj_opaque_p jop = jsp ? jsp->basep : NULL;
+ sgj_opaque_p jap = NULL;
+ sgj_opaque_p ja2p = NULL;
if (act_len < 12) {
pr2serr("need more than 12 bytes to decode, got %u\n", act_len);
@@ -543,9 +551,12 @@ decode_rep_realms(const uint8_t * rzBuff, int act_len,
nr_locator = sg_get_unaligned_be64(rzBuff + 12);
else
nr_locator = 0;
- printf("Realms_count=%u\n", realms_count);
- printf("realms_descriptor_length=%u\n", r_desc_len);
- printf("next_realm_locator=0x%" PRIx64 "\n", nr_locator);
+ sgj_pr_twin_vi(jsp, jop, 0, "Realms_count", SGJ_SEP_EQUAL_NO_SPACE,
+ realms_count);
+ sgj_pr_twin_vi(jsp, jop, 0, "Realms_descriptor_length",
+ SGJ_SEP_EQUAL_NO_SPACE, r_desc_len);
+ sgj_pr_hr(jsp, "Next_realm_locator=0x%" PRIx64 "\n", nr_locator);
+ sgj_add_name_pair_ihex(jsp, jop, "Next_realm_locator", nr_locator);
if ((realms_count < 1) || (act_len < (64 + 16)) || (r_desc_len < 16)) {
if (op->vb) {
pr2serr("%s: exiting early because ", __func__);
@@ -575,37 +586,60 @@ decode_rep_realms(const uint8_t * rzBuff, int act_len,
if (op->do_num > 0)
realms_count = (realms_count > (uint32_t)op->do_num) ?
(uint32_t)op->do_num : realms_count;
+ jap = sgj_new_named_array(jsp, jop, "realm_descriptors_list");
for (k = 0, bp = rzBuff + 64; k < realms_count; ++k, bp += r_desc_len) {
uint32_t j;
+ uint16_t restrictions;
const uint8_t * zp;
+ sgj_opaque_p jo2p;
- printf(" Realm_id=%u\n", sg_get_unaligned_be32(bp + 0));
+ jo2p = sgj_new_unattached_object(jsp);
+ sgj_pr_twin_vi(jsp, jo2p, 1, "Realms_id", SGJ_SEP_EQUAL_NO_SPACE,
+ sg_get_unaligned_be32(bp + 0));
if (op->do_hex) {
hex2stdout(bp, r_desc_len, -1);
continue;
}
- printf(" realm_restrictions=0x%hu\n",
- sg_get_unaligned_be16(bp + 4));
- printf(" active_zone_domain_id=%u\n", (uint32_t)bp[7]);
+ restrictions = sg_get_unaligned_be16(bp + 4);
+ sgj_pr_hr(jsp, " realm_restrictions=0x%hu\n", restrictions);
+ sgj_add_name_pair_ihex(jsp, jo2p, "realm_restrictions", restrictions);
+ sgj_pr_twin_vi(jsp, jo2p, 3, "active_zone_domain_id",
+ SGJ_SEP_EQUAL_NO_SPACE, bp[7]);
+
+ ja2p = sgj_new_named_array(jsp, jo2p,
+ "realm_start_end_descriptors_list");
for (j = 0, zp = bp + 16; j < zdomains_count; ++j, zp += 16) {
- printf(" zone_domain=%u\n", j);
- printf(" starting_lba=0x%" PRIx64 "\n",
- sg_get_unaligned_be64(zp + 0));
- printf(" ending_lba=0x%" PRIx64 "\n",
- sg_get_unaligned_be64(zp + 8));
+ uint64_t lba;
+ sgj_opaque_p jo3p;
+
+ jo3p = sgj_new_unattached_object(jsp);
+ sgj_pr_hr(jsp, " zone_domain=%u\n", j);
+ sgj_add_name_vi(jsp, jo3p, "corresponding_zone_domain_id", j);
+ lba = sg_get_unaligned_be64(zp + 0);
+ sgj_pr_hr(jsp, " starting_lba=0x%" PRIx64 "\n", lba);
+ sgj_add_name_pair_ihex(jsp, jo3p, "realm_starting_lba",
+ (int64_t)lba);
+ lba = sg_get_unaligned_be64(zp + 8);
+ sgj_pr_hr(jsp, " ending_lba=0x%" PRIx64 "\n", lba);
+ sgj_add_name_pair_ihex(jsp, jo3p, "realm_ending_lba",
+ (int64_t)lba);
+ sgj_add_array_element(jsp, ja2p, jo3p);
}
+ sgj_add_array_element(jsp, jap, jo2p);
}
return 0;
}
static int
decode_rep_zdomains(const uint8_t * rzBuff, int act_len,
- const struct opts_t * op)
+ const struct opts_t * op, sgj_state * jsp)
{
uint32_t k, zd_len, zd_ret_len, zdoms_sup, zdoms_rep, zd_rep_opts;
uint32_t num, der_zdoms;
uint64_t zd_locator;
+ sgj_opaque_p jop = jsp ? jsp->basep : NULL;
+ sgj_opaque_p jap = NULL;
const uint8_t * bp;
if (act_len < 12) {
@@ -621,34 +655,53 @@ decode_rep_zdomains(const uint8_t * rzBuff, int act_len,
zd_locator = sg_get_unaligned_be64(rzBuff + 16);
else
zd_locator = 0;
- printf("Zone_domains_returned_list_length=%u\n", zd_ret_len);
- printf("Zone_domains_supported=%u\n", zdoms_sup);
- printf("Zone_domains_reported=%u\n", zdoms_rep);
- printf("Reporting_options=0x%x\n", zd_rep_opts);
- printf("Zone_domain_locator=0x%" PRIx64 "\n", zd_locator);
+ sgj_pr_twin_vi(jsp, jop, 0, "Zone_domains_returned_list_length=",
+ SGJ_SEP_EQUAL_NO_SPACE, zd_ret_len);
+ sgj_pr_twin_vi(jsp, jop, 0, "Zone_domains_supported",
+ SGJ_SEP_EQUAL_NO_SPACE, zdoms_sup);
+ sgj_pr_twin_vi(jsp, jop, 0, "Zone_domains_reported",
+ SGJ_SEP_EQUAL_NO_SPACE, zdoms_rep);
+ sgj_pr_hr(jsp, "Reporting_options=0x%x\n", zd_rep_opts);
+ sgj_add_name_pair_ihex(jsp, jop, "Reporting_options", zd_rep_opts);
+ sgj_pr_hr(jsp, "Zone_domain_locator=0x%" PRIx64 "\n", zd_locator);
+ sgj_add_name_pair_ihex(jsp, jop, "Zone_domain_locator", zd_locator);
der_zdoms = zd_len / 96;
- if (op->vb)
+ if (op->vb > 1)
pr2serr("Derived zdomains=%u\n", der_zdoms);
num = ((der_zdoms < zdoms_rep) ? der_zdoms : zdoms_rep) * 96;
+ jap = sgj_new_named_array(jsp, jop, "zone_domain_descriptors_list");
+
for (k = 0, bp = rzBuff + 64; k < num; k += 96, bp += 96) {
- printf(" zone_domain=%u\n", bp[0]);
- printf(" zone_count=%" PRIu64 "\n",
- sg_get_unaligned_be64(bp + 16));
- printf(" starting_lba=0x%" PRIx64 "\n",
- sg_get_unaligned_be64(bp + 24));
- printf(" ending_lba=0x%" PRIx64 "\n",
- sg_get_unaligned_be64(bp + 32));
- printf(" zone_domain_zone_type=0x%x\n", bp[40]);
- printf(" VZDZT=%u\n", !!(0x2 & bp[42]));
- printf(" SRB=%u\n", !!(0x1 & bp[42]));
+ uint64_t lba;
+ sgj_opaque_p jo2p;
+
+ jo2p = sgj_new_unattached_object(jsp);
+ sgj_pr_twin_vi(jsp, jo2p, 3, "zone_domain",
+ SGJ_SEP_EQUAL_NO_SPACE, bp[0]);
+ lba = sg_get_unaligned_be64(bp + 16);
+ sgj_pr_hr(jsp, " zone_count=%" PRIu64 "\n", lba);
+ sgj_add_name_pair_ihex(jsp, jo2p, "zone_count", lba);
+ lba = sg_get_unaligned_be64(bp + 24);
+ sgj_pr_hr(jsp, " starting_lba=0x%" PRIx64 "\n", lba);
+ sgj_add_name_pair_ihex(jsp, jo2p, "starting_lba", lba);
+ lba = sg_get_unaligned_be64(bp + 32);
+ sgj_pr_hr(jsp, " ending_lba=0x%" PRIx64 "\n", lba);
+ sgj_add_name_pair_ihex(jsp, jo2p, "ending_lba", lba);
+ sgj_pr_hr(jsp, " zone_domain_zone_type=0x%x\n", bp[40]);
+ sgj_add_name_pair_ihex(jsp, jo2p, "zone_domain_zone_type", bp[40]);
+ sgj_pr_twin_vi(jsp, jo2p, 5, "VZDZT", SGJ_SEP_EQUAL_NO_SPACE,
+ !!(0x2 & bp[42]));
+ sgj_pr_twin_vi(jsp, jo2p, 5, "SRB", SGJ_SEP_EQUAL_NO_SPACE,
+ !!(0x1 & bp[42]));
+ sgj_add_array_element(jsp, jap, jo2p);
}
return 0;
}
static int
find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name,
- struct opts_t * op, sg_json_state * jsp)
+ struct opts_t * op, sgj_state * jsp)
{
bool as_json = (jsp && (0 == op->do_hex)) ? jsp->pr_as_json : false;
bool found = false;
@@ -707,7 +760,7 @@ find_report_zones(int sg_fd, uint8_t * rzBuff, const char * cmd_name,
break;
} /* end of outer for loop */
if (res == 0) {
- sg_json_opaque_p jo2p = as_json ?
+ sgj_opaque_p jo2p = as_json ?
sgj_new_named_object(jsp, NULL, "find_condition") : NULL;
if (found) {
@@ -1096,8 +1149,8 @@ main(int argc, char * argv[])
uint8_t * rzBuff = NULL;
uint8_t * free_rzbp = NULL;
const char * cmd_name = "Report zones";
- sg_json_state * jsp;
- sg_json_opaque_p jop = NULL;
+ sgj_state * jsp;
+ sgj_opaque_p jop = NULL;
char b[80];
struct opts_t opts = {0};
struct opts_t * op = &opts;
@@ -1430,9 +1483,9 @@ start_response:
if (REPORT_ZONES_SA == op->serv_act)
ret = decode_rep_zones(rzBuff, act_len, decod_len, op, jsp);
else if (op->do_realms)
- ret = decode_rep_realms(rzBuff, act_len, op);
+ ret = decode_rep_realms(rzBuff, act_len, op, jsp);
else if (op->do_zdomains)
- ret = decode_rep_zdomains(rzBuff, act_len, op);
+ ret = decode_rep_zdomains(rzBuff, act_len, op, jsp);
} else if (SG_LIB_CAT_INVALID_OP == res)
pr2serr("%s command not supported\n", cmd_name);
else {
diff --git a/testing/sg_tst_json_builder.c b/testing/sg_tst_json_builder.c
index d887ff6e..039c10fe 100644
--- a/testing/sg_tst_json_builder.c
+++ b/testing/sg_tst_json_builder.c
@@ -5,7 +5,7 @@
* This takes care of the annoying bits of JSON syntax like the commas
* after elements
*
- * Authors: Stephen Hemminger <stephen@networkplumber.org>
+ * Authors: Stephen Hemminger <stephen@networkplumber.org>
*
* Borrowed from Linux kernel [5.17.0]: tools/bpf/bpftool/json_writer.[hc]
*/
@@ -34,8 +34,8 @@ int
main(int argc, char * argv[])
{
size_t len;
- sg_json_state jstate;
- sg_json_state * jstp = &jstate;
+ sgj_state jstate;
+ sgj_state * jstp = &jstate;
json_value * jv1p;
json_value * jv2p;
json_value * jv3p = json_object_new(0);
@@ -52,15 +52,15 @@ main(int argc, char * argv[])
json_value * js12 = json_string_new("duplicate name 1");
char b[8192];
- sg_json_init_state(jstp);
- jvp = sg_json_start(MY_NAME, "0.01 20220421", argc, argv, jstp);
+ sgj_init_state(jstp, NULL);
+ jvp = sgj_start(MY_NAME, "0.02 20220503", argc, argv, jstp);
jv1p = json_object_push(jvp, "contents", jsp);
if (jvp == jv1p)
printf("jvp == jv1p\n");
else
printf("jvp != jv1p\n");
-
+
#if 1
json_array_push(ja1p, js2p);
jv2p = json_object_push(jvp, "extra", js3p);
@@ -89,8 +89,6 @@ main(int argc, char * argv[])
#endif
jv5p = jvp;
- jv1p = json_string_new("boo");
-
len = json_measure_ex(jv5p, out_settings);
printf("jvp length: %zu bytes\n", len);
if (len < sizeof(b)) {
@@ -109,54 +107,53 @@ main(int argc, char * argv[])
#if 0
int main(int argc, char **argv)
{
- json_writer_t *wr = jsonw_new(stdout);
-
- jsonw_start_object(wr);
- jsonw_pretty(wr, true);
- jsonw_name(wr, "Vyatta");
- jsonw_start_object(wr);
- jsonw_string_field(wr, "url", "http://vyatta.com");
- jsonw_uint_field(wr, "downloads", 2000000ul);
- jsonw_float_field(wr, "stock", 8.16);
-
- jsonw_name(wr, "ARGV");
- jsonw_start_array(wr);
- while (--argc)
- jsonw_string(wr, *++argv);
- jsonw_end_array(wr);
-
- jsonw_name(wr, "empty");
- jsonw_start_array(wr);
- jsonw_end_array(wr);
-
- jsonw_name(wr, "NIL");
- jsonw_start_object(wr);
- jsonw_end_object(wr);
-
- jsonw_null_field(wr, "my_null");
-
- jsonw_name(wr, "special chars");
- jsonw_start_array(wr);
- jsonw_string_field(wr, "slash", "/");
- jsonw_string_field(wr, "newline", "\n");
- jsonw_string_field(wr, "tab", "\t");
- jsonw_string_field(wr, "ff", "\f");
- jsonw_string_field(wr, "quote", "\"");
- jsonw_string_field(wr, "tick", "\'");
- jsonw_string_field(wr, "backslash", "\\");
- jsonw_end_array(wr);
+ json_writer_t *wr = jsonw_new(stdout);
+
+ jsonw_start_object(wr);
+ jsonw_pretty(wr, true);
+ jsonw_name(wr, "Vyatta");
+ jsonw_start_object(wr);
+ jsonw_string_field(wr, "url", "http://vyatta.com");
+ jsonw_uint_field(wr, "downloads", 2000000ul);
+ jsonw_float_field(wr, "stock", 8.16);
+
+ jsonw_name(wr, "ARGV");
+ jsonw_start_array(wr);
+ while (--argc)
+ jsonw_string(wr, *++argv);
+ jsonw_end_array(wr);
+
+ jsonw_name(wr, "empty");
+ jsonw_start_array(wr);
+ jsonw_end_array(wr);
+
+ jsonw_name(wr, "NIL");
+ jsonw_start_object(wr);
+ jsonw_end_object(wr);
+
+ jsonw_null_field(wr, "my_null");
+
+ jsonw_name(wr, "special chars");
+ jsonw_start_array(wr);
+ jsonw_string_field(wr, "slash", "/");
+ jsonw_string_field(wr, "newline", "\n");
+ jsonw_string_field(wr, "tab", "\t");
+ jsonw_string_field(wr, "ff", "\f");
+ jsonw_string_field(wr, "quote", "\"");
+ jsonw_string_field(wr, "tick", "\'");
+ jsonw_string_field(wr, "backslash", "\\");
+ jsonw_end_array(wr);
jsonw_name(wr, "ARGV");
jsonw_start_array(wr);
jsonw_string(wr, "boo: appended or new entry?");
jsonw_end_array(wr);
- jsonw_end_object(wr);
+ jsonw_end_object(wr);
- jsonw_end_object(wr);
- jsonw_destroy(&wr);
- return 0;
+ jsonw_end_object(wr);
+ jsonw_destroy(&wr);
+ return 0;
}
#endif
-