summaryrefslogtreecommitdiff
path: root/libdm/libdm-report.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdm/libdm-report.c')
-rw-r--r--libdm/libdm-report.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 9b8e3c1..0bafa86 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -102,7 +102,7 @@ static const struct dm_report_object_type *_find_type(struct dm_report *rh,
*/
int dm_report_field_string(struct dm_report *rh,
- struct dm_report_field *field, const char **data)
+ struct dm_report_field *field, const char *const *data)
{
char *repstr;
@@ -139,7 +139,7 @@ int dm_report_field_int(struct dm_report *rh,
return 0;
}
- *sortval = (const uint64_t) value;
+ *sortval = (uint64_t) value;
field->sort_value = sortval;
field->report_string = repstr;
@@ -168,7 +168,7 @@ int dm_report_field_uint32(struct dm_report *rh,
return 0;
}
- *sortval = (const uint64_t) value;
+ *sortval = (uint64_t) value;
field->sort_value = sortval;
field->report_string = repstr;
@@ -197,7 +197,7 @@ int dm_report_field_int32(struct dm_report *rh,
return 0;
}
- *sortval = (const uint64_t) value;
+ *sortval = (uint64_t) value;
field->sort_value = sortval;
field->report_string = repstr;
@@ -367,33 +367,32 @@ static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
{
size_t prefix_len;
const struct dm_report_object_type *t;
- char prefixed_all[32];
+ uint32_t report_types = 0;
+ unsigned unprefixed_all_matched = 0;
if (!strncasecmp(field, "all", 3) && flen == 3) {
- if (strlen(rh->field_prefix)) {
- strcpy(prefixed_all, rh->field_prefix);
- strcat(prefixed_all, "all");
- /*
- * Add also prefix to receive all attributes
- * (e.g.LABEL/PVS use the same prefix)
- */
- return rh->report_types |
- _all_match(rh, prefixed_all,
- strlen(prefixed_all));
- } else
- return (rh->report_types)
- ? rh->report_types : REPORT_TYPES_ALL;
+ /* If there's no report prefix, match all report types */
+ if (!(flen = strlen(rh->field_prefix)))
+ return rh->report_types ? : REPORT_TYPES_ALL;
+
+ /* otherwise include all fields beginning with the report prefix. */
+ unprefixed_all_matched = 1;
+ field = rh->field_prefix;
+ report_types = rh->report_types;
}
+ /* Combine all report types that have a matching prefix. */
for (t = rh->types; t->data_fn; t++) {
prefix_len = strlen(t->prefix);
+
if (!strncasecmp(t->prefix, field, prefix_len) &&
- !strncasecmp(field + prefix_len, "all", 3) &&
- flen == prefix_len + 3)
- return t->id;
+ ((unprefixed_all_matched && (flen == prefix_len)) ||
+ (!strncasecmp(field + prefix_len, "all", 3) &&
+ (flen == prefix_len + 3))))
+ report_types |= t->id;
}
- return 0;
+ return report_types;
}
/*
@@ -542,6 +541,9 @@ static int _parse_keys(struct dm_report *rh, const char *keys,
const char *ws; /* Word start */
const char *we = keys; /* Word end */
+ if (!keys)
+ return 1;
+
while (*we) {
/* Allow consecutive commas */
while (*we && *we == ',')
@@ -675,15 +677,15 @@ int dm_report_set_output_field_name_prefix(struct dm_report *rh, const char *out
/*
* Create a row of data for an object
*/
-static void * _report_get_field_data(struct dm_report *rh,
- struct field_properties *fp, void *object)
+static void *_report_get_field_data(struct dm_report *rh,
+ struct field_properties *fp, void *object)
{
- void *ret = fp->type->data_fn(object);
+ char *ret = fp->type->data_fn(object);
if (!ret)
return NULL;
- return ret + rh->fields[fp->field_num].offset;
+ return (void *)(ret + rh->fields[fp->field_num].offset);
}
int dm_report_object(struct dm_report *rh, void *object)
@@ -693,6 +695,11 @@ int dm_report_object(struct dm_report *rh, void *object)
struct dm_report_field *field;
void *data = NULL;
+ if (!rh) {
+ log_error(INTERNAL_ERROR "dm_report handler is NULL.");
+ return 0;
+ }
+
if (!(row = dm_pool_zalloc(rh->mem, sizeof(*row)))) {
log_error("dm_report_object: struct row allocation failed");
return 0;
@@ -734,8 +741,8 @@ int dm_report_object(struct dm_report *rh, void *object)
return 0;
}
- if ((strlen(field->report_string) > field->props->width))
- field->props->width = strlen(field->report_string);
+ if (((int) strlen(field->report_string) > field->props->width))
+ field->props->width = (int) strlen(field->report_string);
if ((rh->flags & RH_SORT_REQUIRED) &&
(field->props->flags & FLD_SORT_KEY)) {
@@ -775,8 +782,8 @@ static int _report_headings(struct dm_report *rh)
}
dm_list_iterate_items(fp, &rh->field_props) {
- if (buf_size < fp->width)
- buf_size = fp->width;
+ if ((int) buf_size < fp->width)
+ buf_size = (size_t) fp->width;
}
/* Including trailing '\0'! */
buf_size++;
@@ -1006,11 +1013,6 @@ static int _output_as_rows(struct dm_report *rh)
struct dm_report_field *field;
struct row *row;
- if (!dm_pool_begin_object(rh->mem, 512)) {
- log_error("dm_report: Unable to allocate output line");
- return 0;
- }
-
dm_list_iterate_items(fp, &rh->field_props) {
if (fp->flags & FLD_HIDDEN) {
dm_list_iterate_items(row, &rh->rows) {
@@ -1020,6 +1022,11 @@ static int _output_as_rows(struct dm_report *rh)
continue;
}
+ if (!dm_pool_begin_object(rh->mem, 512)) {
+ log_error("dm_report: Unable to allocate output line");
+ return 0;
+ }
+
if ((rh->flags & DM_REPORT_OUTPUT_HEADINGS)) {
if (!dm_pool_grow_object(rh->mem, rh->fields[fp->field_num].heading, 0)) {
log_error("dm_report: Failed to extend row for field name");