if (bs->exact_filename[0]) {
pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename);
} else {
- QString *json = qobject_to_json(QOBJECT(bs->full_open_options));
+ GString *json = qobject_to_json(QOBJECT(bs->full_open_options));
if (snprintf(bs->filename, sizeof(bs->filename), "json:%s",
- qstring_get_str(json)) >= sizeof(bs->filename)) {
+ json->str) >= sizeof(bs->filename)) {
/* Give user a hint if we truncated things. */
strcpy(bs->filename + sizeof(bs->filename) - 4, "...");
}
- qobject_unref(json);
+ g_string_free(json, true);
}
}
if (keypairs) {
qdict_put(options, "=keyvalue-pairs",
- qobject_to_json(QOBJECT(keypairs)));
+ qstring_from_gstring(qobject_to_json(QOBJECT(keypairs))));
}
done:
QDict *qdict_from_jsonf_nofail(const char *string, ...)
GCC_FMT_ATTR(1, 2);
-QString *qobject_to_json(const QObject *obj);
-QString *qobject_to_json_pretty(const QObject *obj, bool pretty);
+GString *qobject_to_json(const QObject *obj);
+GString *qobject_to_json_pretty(const QObject *obj, bool pretty);
#endif /* QJSON_H */
void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
{
const QObject *data = QOBJECT(rsp);
- QString *json;
+ GString *json;
json = qobject_to_json_pretty(data, mon->pretty);
assert(json != NULL);
- qstring_append_chr(json, '\n');
- monitor_puts(&mon->common, qstring_get_str(json));
+ g_string_append_c(json, '\n');
+ monitor_puts(&mon->common, json->str);
- qobject_unref(json);
+ g_string_free(json, true);
}
/*
} /* else will fail qmp_dispatch() */
if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) {
- QString *req_json = qobject_to_json(req);
- trace_handle_qmp_command(mon, qstring_get_str(req_json));
- qobject_unref(req_json);
+ GString *req_json = qobject_to_json(req);
+ trace_handle_qmp_command(mon, req_json->str);
+ g_string_free(req_json, true);
}
if (qdict && qmp_is_oob(qdict)) {
#include "qapi/qobject-output-visitor.h"
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
#include "qemu/cutils.h"
#include "qemu/config-file.h"
#include "qemu/option.h"
static void dump_json_image_check(ImageCheck *check, bool quiet)
{
- QString *str;
+ GString *str;
QObject *obj;
Visitor *v = qobject_output_visitor_new(&obj);
visit_complete(v, &obj);
str = qobject_to_json_pretty(obj, true);
assert(str != NULL);
- qprintf(quiet, "%s\n", qstring_get_str(str));
+ qprintf(quiet, "%s\n", str->str);
qobject_unref(obj);
visit_free(v);
- qobject_unref(str);
+ g_string_free(str, true);
}
static void dump_human_image_check(ImageCheck *check, bool quiet)
static void dump_json_image_info_list(ImageInfoList *list)
{
- QString *str;
+ GString *str;
QObject *obj;
Visitor *v = qobject_output_visitor_new(&obj);
visit_complete(v, &obj);
str = qobject_to_json_pretty(obj, true);
assert(str != NULL);
- printf("%s\n", qstring_get_str(str));
+ printf("%s\n", str->str);
qobject_unref(obj);
visit_free(v);
- qobject_unref(str);
+ g_string_free(str, true);
}
static void dump_json_image_info(ImageInfo *info)
{
- QString *str;
+ GString *str;
QObject *obj;
Visitor *v = qobject_output_visitor_new(&obj);
visit_complete(v, &obj);
str = qobject_to_json_pretty(obj, true);
assert(str != NULL);
- printf("%s\n", qstring_get_str(str));
+ printf("%s\n", str->str);
qobject_unref(obj);
visit_free(v);
- qobject_unref(str);
+ g_string_free(str, true);
}
static void dump_human_image_info_list(ImageInfoList *list)
static void dump_json_block_measure_info(BlockMeasureInfo *info)
{
- QString *str;
+ GString *str;
QObject *obj;
Visitor *v = qobject_output_visitor_new(&obj);
visit_complete(v, &obj);
str = qobject_to_json_pretty(obj, true);
assert(str != NULL);
- printf("%s\n", qstring_get_str(str));
+ printf("%s\n", str->str);
qobject_unref(obj);
visit_free(v);
- qobject_unref(str);
+ g_string_free(str, true);
}
static int img_measure(int argc, char **argv)
#include "qapi/qmp/json-parser.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
-#include "qapi/qmp/qstring.h"
#include "guest-agent-core.h"
#include "qga-qapi-init-commands.h"
#include "qapi/qmp/qerror.h"
static int send_response(GAState *s, const QDict *rsp)
{
- const char *buf;
- QString *payload_qstr, *response_qstr;
+ GString *response;
GIOStatus status;
g_assert(s->channel);
return 0;
}
- payload_qstr = qobject_to_json(QOBJECT(rsp));
- if (!payload_qstr) {
+ response = qobject_to_json(QOBJECT(rsp));
+ if (!response) {
return -EINVAL;
}
if (s->delimit_response) {
s->delimit_response = false;
- response_qstr = qstring_new();
- qstring_append_chr(response_qstr, QGA_SENTINEL_BYTE);
- qstring_append(response_qstr, qstring_get_str(payload_qstr));
- qobject_unref(payload_qstr);
- } else {
- response_qstr = payload_qstr;
+ g_string_prepend_c(response, QGA_SENTINEL_BYTE);
}
- qstring_append_chr(response_qstr, '\n');
- buf = qstring_get_str(response_qstr);
- status = ga_channel_write_all(s->channel, buf, strlen(buf));
- qobject_unref(response_qstr);
+ g_string_append_c(response, '\n');
+ status = ga_channel_write_all(s->channel, response->str, response->len);
+ g_string_free(response, true);
if (status != G_IO_STATUS_NORMAL) {
return -EIO;
}
}
}
-QString *qobject_to_json_pretty(const QObject *obj, bool pretty)
+GString *qobject_to_json_pretty(const QObject *obj, bool pretty)
{
GString *accu = g_string_new(NULL);
to_json(obj, accu, pretty, 0);
- return qstring_from_gstring(accu);
+ return accu;
}
-QString *qobject_to_json(const QObject *obj)
+GString *qobject_to_json(const QObject *obj)
{
return qobject_to_json_pretty(obj, false);
}
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qjson.h"
-#include "qapi/qmp/qstring.h"
#include "qapi/qobject-input-visitor.h"
#include "qom/object_interfaces.h"
#include "qemu/help_option.h"
g_string_append(str, description);
}
if (defval) {
- g_autofree char *def_json = qstring_free(qobject_to_json(defval), TRUE);
+ g_autofree char *def_json = g_string_free(qobject_to_json(defval),
+ true);
g_string_append_printf(str, " (default: %s)", def_json);
}
#include "qapi/qapi-commands-qom.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
-#include "qapi/qmp/qstring.h"
#include "qom/object.h"
void hmp_qom_list(Monitor *mon, const QDict *qdict)
QObject *obj = qmp_qom_get(path, property, &err);
if (err == NULL) {
- QString *str = qobject_to_json_pretty(obj, true);
- monitor_printf(mon, "%s\n", qstring_get_str(str));
- qobject_unref(str);
+ GString *str = qobject_to_json_pretty(obj, true);
+ monitor_printf(mon, "%s\n", str->str);
+ g_string_free(str, true);
}
qobject_unref(obj);
static char *to_json_str(QString *str)
{
- QString *json = qobject_to_json(QOBJECT(str));
- char *jstr;
+ GString *json = qobject_to_json(QOBJECT(str));
if (!json) {
return NULL;
}
/* peel off double quotes */
- jstr = g_strndup(qstring_get_str(json) + 1,
- qstring_get_length(json) - 2);
- qobject_unref(json);
- return jstr;
+ g_string_truncate(json, json->len - 1);
+ g_string_erase(json, 0, 1);
+ return g_string_free(json, false);
}
static void escaped_string(void)
QNum *qnum;
int64_t ival;
uint64_t uval;
- QString *str;
+ GString *str;
for (i = 0; test_cases[i].encoded; i++) {
qnum = qobject_to(QNum,
(double)test_cases[i].decoded);
str = qobject_to_json(QOBJECT(qnum));
- g_assert_cmpstr(qstring_get_str(str), ==,
+ g_assert_cmpstr(str->str, ==,
test_cases[i].reencoded ?: test_cases[i].encoded);
- qobject_unref(str);
+ g_string_free(str, true);
qobject_unref(qnum);
}
QNum *qnum;
int64_t ival;
uint64_t uval;
- QString *str;
+ GString *str;
for (i = 0; test_cases[i].encoded; i++) {
qnum = qobject_to(QNum,
(double)test_cases[i].decoded);
str = qobject_to_json(QOBJECT(qnum));
- g_assert_cmpstr(qstring_get_str(str), ==,
+ g_assert_cmpstr(str->str, ==,
test_cases[i].reencoded ?: test_cases[i].encoded);
- qobject_unref(str);
+ g_string_free(str, true);
qobject_unref(qnum);
}
QNum *qnum;
int64_t ival;
uint64_t uval;
- QString *str;
+ GString *str;
for (i = 0; test_cases[i].encoded; i++) {
qnum = qobject_to(QNum,
g_assert(!qnum_get_try_uint(qnum, &uval));
str = qobject_to_json(QOBJECT(qnum));
- g_assert_cmpstr(qstring_get_str(str), ==,
+ g_assert_cmpstr(str->str, ==,
test_cases[i].reencoded ?: test_cases[i].encoded);
- qobject_unref(str);
+ g_string_free(str, true);
qobject_unref(qnum);
}
QObject *obj;
QBool *qbool;
QNull *null;
- QString *str;
+ GString *str;
obj = qobject_from_json("true", &error_abort);
qbool = qobject_to(QBool, obj);
g_assert(qbool_get_bool(qbool) == true);
str = qobject_to_json(obj);
- g_assert(strcmp(qstring_get_str(str), "true") == 0);
- qobject_unref(str);
+ g_assert_cmpstr(str->str, ==, "true");
+ g_string_free(str, true);
qobject_unref(qbool);
g_assert(qbool_get_bool(qbool) == false);
str = qobject_to_json(obj);
- g_assert(strcmp(qstring_get_str(str), "false") == 0);
- qobject_unref(str);
+ g_assert_cmpstr(str->str, ==, "false");
+ g_string_free(str, true);
qobject_unref(qbool);
for (i = 0; test_cases[i].encoded; i++) {
QObject *obj;
- QString *str;
+ GString *str;
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
str = qobject_to_json(obj);
qobject_unref(obj);
- obj = qobject_from_json(qstring_get_str(str), &error_abort);
+ obj = qobject_from_json(str->str, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
qobject_unref(obj);
- qobject_unref(str);
+ g_string_free(str, true);
}
}
for (i = 0; test_cases[i].encoded; i++) {
QObject *obj;
- QString *str;
+ GString *str;
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
str = qobject_to_json(obj);
qobject_unref(obj);
- obj = qobject_from_json(qstring_get_str(str), &error_abort);
+ obj = qobject_from_json(str->str, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
qobject_unref(obj);
- qobject_unref(str);
+ g_string_free(str, true);
}
}
for (i = 0; test_cases[i].encoded; i++) {
QObject *obj;
- QString *str;
+ GString *str;
obj = qobject_from_json(test_cases[i].encoded, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
str = qobject_to_json(obj);
qobject_unref(obj);
- obj = qobject_from_json(qstring_get_str(str), &error_abort);
+ obj = qobject_from_json(str->str, &error_abort);
g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj));
qobject_unref(obj);
- qobject_unref(str);
+ g_string_free(str, true);
}
}
/* No need to send anything for an empty QObject. */
if (qobj) {
int log = getenv("QTEST_LOG") != NULL;
- QString *qstr = qobject_to_json(qobj);
- const char *str;
+ GString *str = qobject_to_json(qobj);
/*
* BUG: QMP doesn't react to input until it sees a newline, an
* object, or an array. Work-around: give it a newline.
*/
- qstring_append_chr(qstr, '\n');
- str = qstring_get_str(qstr);
+ g_string_append_c(str, '\n');
if (log) {
- fprintf(stderr, "%s", str);
+ fprintf(stderr, "%s", str->str);
}
/* Send QMP request */
if (fds && fds_num > 0) {
- socket_send_fds(fd, fds, fds_num, str, qstring_get_length(qstr));
+ socket_send_fds(fd, fds, fds_num, str->str, str->len);
} else {
- socket_send(fd, str, qstring_get_length(qstr));
+ socket_send(fd, str->str, str->len);
}
- qobject_unref(qstr);
+ g_string_free(str, true);
qobject_unref(qobj);
}
}
g_assert(response);
if (!qdict_haskey(response, "return")) {
- QString *s = qobject_to_json_pretty(QOBJECT(response), true);
- g_test_message("%s", qstring_get_str(s));
- qobject_unref(s);
+ GString *s = qobject_to_json_pretty(QOBJECT(response), true);
+ g_test_message("%s", s->str);
+ g_string_free(s, true);
}
g_assert(qdict_haskey(response, "return"));
qobject_unref(response);
VisitorFunc visit, Error **errp)
{
QmpSerializeData *d = datap;
- QString *output_json;
+ GString *output_json;
QObject *obj_orig, *obj;
visit_complete(d->qov, &d->obj);
obj_orig = d->obj;
output_json = qobject_to_json(obj_orig);
- obj = qobject_from_json(qstring_get_str(output_json), &error_abort);
+ obj = qobject_from_json(output_json->str, &error_abort);
- qobject_unref(output_json);
+ g_string_free(output_json, true);
d->qiv = qobject_input_visitor_new(obj);
qobject_unref(obj_orig);
qobject_unref(obj);