mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
libdm: report: remove double quotes around numeric values in JSON_STD output
In JSON format, we print numeric values this way: "key" = "N" while in JSON_STD format, we print numeric value this way: "key" = N (Where N is a numeric value.)
This commit is contained in:
parent
02f015990b
commit
99299eb728
@ -4382,6 +4382,11 @@ static int _is_json_report(struct dm_report *rh)
|
|||||||
rh->group_item->group->type == DM_REPORT_GROUP_JSON_STD);
|
rh->group_item->group->type == DM_REPORT_GROUP_JSON_STD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _is_pure_numeric_field(struct dm_report_field *field)
|
||||||
|
{
|
||||||
|
return field->props->flags & (DM_REPORT_FIELD_TYPE_NUMBER | DM_REPORT_FIELD_TYPE_PERCENT);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Produce report output
|
* Produce report output
|
||||||
*/
|
*/
|
||||||
@ -4401,10 +4406,16 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
|||||||
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
||||||
!dm_pool_grow_object(rh->mem, fields[field->props->field_num].id, 0) ||
|
!dm_pool_grow_object(rh->mem, fields[field->props->field_num].id, 0) ||
|
||||||
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
||||||
!dm_pool_grow_object(rh->mem, JSON_PAIR, 1) ||
|
!dm_pool_grow_object(rh->mem, JSON_PAIR, 1)) {
|
||||||
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
log_error("dm_report: Unable to extend output line");
|
goto bad;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
if (!(_is_json_std_report(rh) && _is_pure_numeric_field(field))) {
|
||||||
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
||||||
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
|
} else if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
|
||||||
if (!(field_id = strdup(fields[field->props->field_num].id))) {
|
if (!(field_id = strdup(fields[field->props->field_num].id))) {
|
||||||
@ -4513,11 +4524,13 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (_is_json_report(rh)) {
|
} else if (_is_json_report(rh)) {
|
||||||
|
if (!(_is_json_std_report(rh) && _is_pure_numeric_field(field))) {
|
||||||
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
||||||
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -4381,6 +4381,11 @@ static int _is_json_report(struct dm_report *rh)
|
|||||||
rh->group_item->group->type == DM_REPORT_GROUP_JSON_STD);
|
rh->group_item->group->type == DM_REPORT_GROUP_JSON_STD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _is_pure_numeric_field(struct dm_report_field *field)
|
||||||
|
{
|
||||||
|
return field->props->flags & (DM_REPORT_FIELD_TYPE_NUMBER | DM_REPORT_FIELD_TYPE_PERCENT);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Produce report output
|
* Produce report output
|
||||||
*/
|
*/
|
||||||
@ -4400,10 +4405,16 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
|||||||
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
||||||
!dm_pool_grow_object(rh->mem, fields[field->props->field_num].id, 0) ||
|
!dm_pool_grow_object(rh->mem, fields[field->props->field_num].id, 0) ||
|
||||||
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1) ||
|
||||||
!dm_pool_grow_object(rh->mem, JSON_PAIR, 1) ||
|
!dm_pool_grow_object(rh->mem, JSON_PAIR, 1)) {
|
||||||
!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
log_error("dm_report: Unable to extend output line");
|
goto bad;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
if (!(_is_json_std_report(rh) && _is_pure_numeric_field(field))) {
|
||||||
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
||||||
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
|
} else if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
|
||||||
if (!(field_id = dm_strdup(fields[field->props->field_num].id))) {
|
if (!(field_id = dm_strdup(fields[field->props->field_num].id))) {
|
||||||
@ -4512,11 +4523,13 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (_is_json_report(rh)) {
|
} else if (_is_json_report(rh)) {
|
||||||
|
if (!(_is_json_std_report(rh) && _is_pure_numeric_field(field))) {
|
||||||
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
if (!dm_pool_grow_object(rh->mem, JSON_QUOTE, 1)) {
|
||||||
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
log_error(UNABLE_TO_EXTEND_OUTPUT_LINE_MSG);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user