summaryrefslogtreecommitdiffstats
path: root/discover/event-parser.c
blob: 0cfda9a027af1727a235d571c62b587d641c6304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define _GNU_SOURCE

#include <assert.h>

#include "log/log.h"
#include "talloc/talloc.h"
#include "event.h"
#include "parser-utils.h"

int parse_user_event(struct device *device, struct event *event)
{
	struct boot_option *opt;
	const char *p;

	opt = talloc_zero(device, struct boot_option);

	if (!opt)
		goto fail;

	p = event_get_param(event, "name");

	if (!p) {
		pb_log("%s: no name found\n", __func__);
		goto fail;
	}

	opt->id = talloc_asprintf(opt, "%s#%s", device->id, p);
	opt->name = talloc_strdup(opt, p);

	p = event_get_param(event, "image");
	assert(p);

	if (!p) {
		pb_log("%s: no image found\n", __func__);
		goto fail;
	}

	opt->boot_image_file = talloc_strdup(opt, p);

	p = event_get_param(event, "args");
	assert(p);

	opt->boot_args = talloc_strdup(opt, p);

	opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file,
		opt->boot_args);

	device_add_boot_option(device, opt);

	return 0;

fail:
	talloc_free(opt);
	return -1;
}
OpenPOWER on IntegriCloud