summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-05-08 20:36:14 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-05-09 08:35:53 +0800
commit0a4cb93c1c7c7e6f8c5324314457b96072158975 (patch)
tree6ed2b0f100ae5274b2916c385b64bc91ea2465f2
parent25a7c442028ed3d2d75a554cfa5da7b1ac4724bb (diff)
downloadtalos-petitboot-0a4cb93c1c7c7e6f8c5324314457b96072158975.tar.gz
talos-petitboot-0a4cb93c1c7c7e6f8c5324314457b96072158975.zip
discover/event: Add event_set_param
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--discover/event.c24
-rw-r--r--discover/event.h5
2 files changed, 27 insertions, 2 deletions
diff --git a/discover/event.c b/discover/event.c
index a05ce27..7cb128f 100644
--- a/discover/event.c
+++ b/discover/event.c
@@ -134,3 +134,27 @@ const char *event_get_param(const struct event *event, const char *name)
return NULL;
}
+
+void event_set_param(struct event *event, const char *name, const char *value)
+{
+ struct param *param;
+ int i;
+
+ /* if it's already present, replace the value of the old param */
+ for (i = 0; i < event->n_params; i++) {
+ param = &event->params[i];
+ if (!strcasecmp(param->name, name)) {
+ talloc_free(param->value);
+ param->value = talloc_strdup(event, value);
+ return;
+ }
+ }
+
+ /* not found - create a new param */
+ event->params = talloc_realloc(event, event->params,
+ struct param, ++event->n_params);
+ param = &event->params[event->n_params - 1];
+
+ param->name = talloc_strdup(event, name);
+ param->value = talloc_strdup(event, value);
+}
diff --git a/discover/event.h b/discover/event.h
index 70cc8fc..adba336 100644
--- a/discover/event.h
+++ b/discover/event.h
@@ -20,13 +20,14 @@ struct event {
const char *device;
struct param {
- const char *name;
- const char *value;
+ char *name;
+ char *value;
} *params;
int n_params;
};
int event_parse_ad_message(struct event *event, char *buf, int len);
const char *event_get_param(const struct event *event, const char *name);
+void event_set_param(struct event *event, const char *name, const char *value);
#endif /* _PB_EVENT_H */
OpenPOWER on IntegriCloud