X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fevent.c;h=cced6588d8b88aed85683668c93a9a19ddcc0178;hp=1314561c9eda23e19cfc016604ae71d207d9ae09;hb=9933fe75fd5f7f6a281a67deb3a8d919f5617f89;hpb=d7ce19907ff585e7fb6b950a40bd638d49c96a27 diff --git a/discover/event.c b/discover/event.c index 1314561..cced658 100644 --- a/discover/event.c +++ b/discover/event.c @@ -42,6 +42,8 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, *action = EVENT_ACTION_ADD; else if (streq(buf, "remove")) *action = EVENT_ACTION_REMOVE; + else if (streq(buf, "conf")) + *action = EVENT_ACTION_CONF; else { pb_log("%s: unknown action: %s\n", __func__, buf); return -1; @@ -78,21 +80,23 @@ static void event_parse_params(struct event *event, const char *buf, int len) continue; } - /* find the separator */ - sep = memchr(buf, '=', param_len); - if (!sep) - continue; - - name_len = sep - buf; - value_len = param_len - name_len - 1; - /* update the params array */ event->params = talloc_realloc(event, event->params, struct param, ++event->n_params); param = &event->params[event->n_params - 1]; + sep = memchr(buf, '=', param_len); + if (!sep) { + name_len = param_len; + value_len = 0; + param->value = ""; + } else { + name_len = sep - buf; + value_len = param_len - name_len - 1; + param->value = talloc_strndup(event, sep + 1, + value_len); + } param->name = talloc_strndup(event, buf, name_len); - param->value = talloc_strndup(event, sep + 1, value_len); } } @@ -132,3 +136,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); +}