discover/event: Add event_set_param
authorJeremy Kerr <jk@ozlabs.org>
Wed, 8 May 2013 12:36:14 +0000 (20:36 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 9 May 2013 00:35:53 +0000 (08:35 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/event.c
discover/event.h

index a05ce2752f42325fb9efd7c52bfeb44c092e9bae..7cb128f6dfb45afbea395d4f49649433b0775712 100644 (file)
@@ -134,3 +134,27 @@ const char *event_get_param(const struct event *event, const char *name)
 
        return NULL;
 }
 
        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);
+}
index 70cc8fc3c15d3da7e39436e0c527696de7d1eced..adba336067ad3bf0b97361ed3a68259d992a909e 100644 (file)
@@ -20,13 +20,14 @@ struct event {
        const char *device;
 
        struct param {
        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);
        } *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 */
 
 #endif /* _PB_EVENT_H */