summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2008-04-20 00:11:08 +0000
committerAlasdair Kergon <agk@redhat.com>2008-04-20 00:11:08 +0000
commita6362996800277fc72061bafbf077591dafa5040 (patch)
tree4124efc08ace563c3a46c1d80f37e1d87f2d5415
parent08e5bd5b725de9a8437952b0a9673c7b969df405 (diff)
downloadlvm2-a6362996800277fc72061bafbf077591dafa5040.tar.gz
Add field name prefix option to reporting functions.v1_02_28v1_02_27v1_02_26old-v1_02_28old-v1_02_27old-v1_02_26
-rw-r--r--WHATS_NEW_DM1
-rw-r--r--libdm/.exported_symbols1
-rw-r--r--libdm/libdevmapper.h15
-rw-r--r--libdm/libdm-report.c59
4 files changed, 72 insertions, 4 deletions
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 852fbdb56..cfc45a29f 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.26 -
=================================
+ Add field name prefix option to reporting functions.
Calculate string size within dm_pool_grow_object.
Version 1.02.25 - 10th April 2008
diff --git a/libdm/.exported_symbols b/libdm/.exported_symbols
index da932b390..6815560f7 100644
--- a/libdm/.exported_symbols
+++ b/libdm/.exported_symbols
@@ -132,5 +132,6 @@ dm_report_field_int32
dm_report_field_uint32
dm_report_field_uint64
dm_report_field_set_value
+dm_report_set_output_field_name_prefix
dm_regex_create
dm_regex_match
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 8d55d477f..6988ccded 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -735,10 +735,11 @@ struct dm_report_field_type {
/*
* dm_report_init output_flags
*/
-#define DM_REPORT_OUTPUT_MASK 0x000000FF
-#define DM_REPORT_OUTPUT_ALIGNED 0x00000001
-#define DM_REPORT_OUTPUT_BUFFERED 0x00000002
-#define DM_REPORT_OUTPUT_HEADINGS 0x00000004
+#define DM_REPORT_OUTPUT_MASK 0x000000FF
+#define DM_REPORT_OUTPUT_ALIGNED 0x00000001
+#define DM_REPORT_OUTPUT_BUFFERED 0x00000002
+#define DM_REPORT_OUTPUT_HEADINGS 0x00000004
+#define DM_REPORT_OUTPUT_FIELD_NAME_PREFIX 0x00000008
struct dm_report *dm_report_init(uint32_t *report_types,
const struct dm_report_object_type *types,
@@ -753,6 +754,12 @@ int dm_report_output(struct dm_report *rh);
void dm_report_free(struct dm_report *rh);
/*
+ * Prefix added to each field name with DM_REPORT_OUTPUT_FIELD_NAME_PREFIX
+ */
+int dm_report_set_output_field_name_prefix(struct dm_report *rh,
+ const char *report_prefix);
+
+/*
* Report functions are provided for simple data types.
* They take care of allocating copies of the data.
*/
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 71004dd1f..f5758b63d 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -17,6 +17,8 @@
#include "list.h"
#include "log.h"
+#include <ctype.h>
+
/*
* Internal flags
*/
@@ -27,6 +29,7 @@ struct dm_report {
struct dm_pool *mem;
uint32_t report_types;
+ const char *output_field_name_prefix;
const char *field_prefix;
uint32_t flags;
const char *separator;
@@ -551,6 +554,31 @@ void dm_report_free(struct dm_report *rh)
dm_free(rh);
}
+static char *_toupperstr(char *str)
+{
+ char *u = str;
+
+ do
+ *u = toupper(*u);
+ while (*u++);
+
+ return str;
+}
+
+int dm_report_set_output_field_name_prefix(struct dm_report *rh, const char *output_field_name_prefix)
+{
+ char *prefix;
+
+ if (!(prefix = dm_pool_strdup(rh->mem, output_field_name_prefix))) {
+ log_error("dm_report_set_output_field_name_prefix: dm_pool_strdup failed");
+ return 0;
+ }
+
+ rh->output_field_name_prefix = _toupperstr(prefix);
+
+ return 1;
+}
+
/*
* Create a row of data for an object
*/
@@ -771,6 +799,7 @@ int dm_report_output(struct dm_report *rh)
struct row *row = NULL;
struct dm_report_field *field;
const char *repstr;
+ char *field_id;
char buf[4096];
int32_t width;
uint32_t align;
@@ -798,6 +827,30 @@ int dm_report_output(struct dm_report *rh)
if (field->props->flags & FLD_HIDDEN)
continue;
+ if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
+ if (!(field_id = strdup(rh->fields[field->props->field_num].id))) {
+ log_error("dm_report: Failed to copy field name");
+ goto bad;
+ }
+
+ if (!dm_pool_grow_object(rh->mem, rh->output_field_name_prefix, 0)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
+ if (!dm_pool_grow_object(rh->mem, _toupperstr(field_id), 0)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
+ free(field_id);
+
+ if (!dm_pool_grow_object(rh->mem, "=\"", 2)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+ }
+
repstr = field->report_string;
width = field->props->width;
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
@@ -832,6 +885,12 @@ int dm_report_output(struct dm_report *rh)
}
}
+ if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX)
+ if (!dm_pool_grow_object(rh->mem, "\"", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
if (!list_end(&row->fields, fh))
if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Unable to extend output line");