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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include "project.h"
json_object *
_json_object_object_get (json_object * obj, const char *name)
{
json_object *sub;
return json_object_object_get_ex (obj, name, &sub) ? sub : NULL;
}
static void
dump_manifest (struct manifest *m)
{
printf ("Manifest:\n");
printf (" type : %s\n", m->type);
printf (" dfu_version: %s\n", m->dfu_version);
printf (" dat_file : %s\n", m->dat_file);
printf (" bin_file : %s\n", m->bin_file);
}
struct manifest *
parse_manifest (const char *str)
{
json_object *json, *manifest;
enum json_tokener_error jerr = json_tokener_success;
struct manifest *m;
m = xmalloc (sizeof (*m));
memset (m, 0, sizeof (*m));
json = json_tokener_parse_verbose (str, &jerr);
manifest = _json_object_object_get (json, "manifest");
m->dfu_version =
json_object_get_string (_json_object_object_get
(manifest, "dfu_version"));
json_object_object_foreach (manifest, key, val)
{
if (!strcmp (key, "dfu_version"))
continue;
m->type = key;
m->bin_file =
json_object_get_string (_json_object_object_get (val, "bin_file"));
m->dat_file =
json_object_get_string (_json_object_object_get (val, "dat_file"));
break;
}
dump_manifest (m);
if (!m->dfu_version || !m->type || !m->bin_file || !m->dat_file)
{
fprintf (stderr, "Failed to process manifest\n");
exit (EXIT_FAILURE);
}
return m;
}
|