1 | #ifndef _OG_JSON_H |
---|
2 | #define _OG_JSON_H |
---|
3 | |
---|
4 | #include <jansson.h> |
---|
5 | #include "schedule.h" |
---|
6 | |
---|
7 | int og_json_parse_string(json_t *element, const char **str); |
---|
8 | int og_json_parse_string_copy(json_t *element, char *str, size_t size); |
---|
9 | int og_json_parse_uint64(json_t *element, uint64_t *integer); |
---|
10 | int og_json_parse_uint(json_t *element, uint32_t *integer); |
---|
11 | int og_json_parse_bool(json_t *element, bool *value); |
---|
12 | |
---|
13 | #define OG_PARAM_PART_NUMBER (1UL << 0) |
---|
14 | #define OG_PARAM_PART_CODE (1UL << 1) |
---|
15 | #define OG_PARAM_PART_FILESYSTEM (1UL << 2) |
---|
16 | #define OG_PARAM_PART_SIZE (1UL << 3) |
---|
17 | #define OG_PARAM_PART_FORMAT (1UL << 4) |
---|
18 | #define OG_PARAM_PART_DISK (1UL << 5) |
---|
19 | #define OG_PARAM_PART_OS (1UL << 6) |
---|
20 | #define OG_PARAM_PART_USED_SIZE (1UL << 7) |
---|
21 | #define OG_PARAM_PART_DISK_TYPE (1UL << 8) |
---|
22 | |
---|
23 | struct og_partition { |
---|
24 | const char *disk; |
---|
25 | const char *disk_type; |
---|
26 | const char *number; |
---|
27 | const char *code; |
---|
28 | const char *size; |
---|
29 | const char *filesystem; |
---|
30 | const char *format; |
---|
31 | const char *os; |
---|
32 | const char *used_size; |
---|
33 | }; |
---|
34 | |
---|
35 | #define OG_DISK_MAX 4 |
---|
36 | #define OG_PARTITION_MAX (4 * OG_DISK_MAX) |
---|
37 | |
---|
38 | int og_json_parse_partition(json_t *element, struct og_partition *part, |
---|
39 | uint64_t required_flags); |
---|
40 | |
---|
41 | #define OG_CLIENTS_MAX 4096 |
---|
42 | |
---|
43 | struct og_sync_params { |
---|
44 | const char *sync; |
---|
45 | const char *diff; |
---|
46 | const char *remove; |
---|
47 | const char *compress; |
---|
48 | const char *cleanup; |
---|
49 | const char *cache; |
---|
50 | const char *cleanup_cache; |
---|
51 | const char *remove_dst; |
---|
52 | const char *diff_id; |
---|
53 | const char *diff_name; |
---|
54 | const char *path; |
---|
55 | const char *method; |
---|
56 | }; |
---|
57 | |
---|
58 | #define OG_PARAM_SCOPE_ID (1UL << 0) |
---|
59 | #define OG_PARAM_SCOPE_TYPE (1UL << 1) |
---|
60 | |
---|
61 | struct og_scope { |
---|
62 | uint32_t id; |
---|
63 | const char *type; |
---|
64 | }; |
---|
65 | |
---|
66 | int og_json_parse_scope(json_t *element, struct og_scope *scope, |
---|
67 | const uint64_t required_flags); |
---|
68 | |
---|
69 | struct og_msg_params { |
---|
70 | const char *ips_array[OG_CLIENTS_MAX]; |
---|
71 | const char *mac_array[OG_CLIENTS_MAX]; |
---|
72 | const char *netmask_array[OG_CLIENTS_MAX]; |
---|
73 | unsigned int ips_array_len; |
---|
74 | const char *wol_type; |
---|
75 | char run_cmd[4096]; |
---|
76 | const char *disk; |
---|
77 | const char *partition; |
---|
78 | const char *repository; |
---|
79 | const char *name; |
---|
80 | const char *id; |
---|
81 | const char *code; |
---|
82 | const char *type; |
---|
83 | const char *profile; |
---|
84 | const char *cache; |
---|
85 | const char *cache_size; |
---|
86 | const char *comment; |
---|
87 | bool echo; |
---|
88 | struct og_partition partition_setup[OG_PARTITION_MAX]; |
---|
89 | struct og_sync_params sync_setup; |
---|
90 | struct og_schedule_time time; |
---|
91 | const char *task_id; |
---|
92 | uint64_t flags; |
---|
93 | }; |
---|
94 | |
---|
95 | int og_json_parse_partition_setup(json_t *element, struct og_msg_params *params); |
---|
96 | int og_json_parse_create_image(json_t *element, struct og_msg_params *params); |
---|
97 | int og_json_parse_restore_image(json_t *element, struct og_msg_params *params); |
---|
98 | |
---|
99 | struct og_cmd_json { |
---|
100 | const char *type; |
---|
101 | json_t *json; |
---|
102 | uint32_t flags; |
---|
103 | }; |
---|
104 | |
---|
105 | enum og_procedure_step_type { |
---|
106 | OG_STEP_COMMAND = 0, |
---|
107 | OG_STEP_PROCEDURE, |
---|
108 | }; |
---|
109 | |
---|
110 | #define OG_PROCEDURE_STEPS_MAX 256 |
---|
111 | |
---|
112 | struct og_procedure_step { |
---|
113 | enum og_procedure_step_type type; |
---|
114 | uint32_t position; |
---|
115 | |
---|
116 | union { |
---|
117 | struct og_cmd_json cmd; |
---|
118 | struct { |
---|
119 | uint64_t id; |
---|
120 | } procedure; |
---|
121 | }; |
---|
122 | }; |
---|
123 | |
---|
124 | struct og_procedure { |
---|
125 | uint64_t id; |
---|
126 | struct og_procedure_step steps[OG_PROCEDURE_STEPS_MAX]; |
---|
127 | uint32_t num_steps; |
---|
128 | }; |
---|
129 | |
---|
130 | int og_json_parse_procedure(json_t *element, struct og_procedure *proc); |
---|
131 | |
---|
132 | #endif |
---|