X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fevent.c;h=cced6588d8b88aed85683668c93a9a19ddcc0178;hp=a05ce2752f42325fb9efd7c52bfeb44c092e9bae;hb=c11bcba9a99e858e618f4d872a5be7d52dcaaa5a;hpb=19dab336ae13f0476bfbf0db34f1329a802eeb8e diff --git a/discover/event.c b/discover/event.c index a05ce27..cced658 100644 --- a/discover/event.c +++ b/discover/event.c @@ -80,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); } } @@ -134,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); +}