[04ca20e] | 1 | #ifndef _OG_JSON_H |
---|
| 2 | #define _OG_JSON_H |
---|
| 3 | |
---|
| 4 | #include <jansson.h> |
---|
| 5 | #include "schedule.h" |
---|
| 6 | |
---|
[87774ab] | 7 | int og_json_parse_string(const json_t *element, const char **str); |
---|
| 8 | int og_json_parse_string_copy(const json_t *element, char *str, size_t size); |
---|
| 9 | int og_json_parse_uint64(const json_t *element, uint64_t *integer); |
---|
| 10 | int og_json_parse_uint(const json_t *element, uint32_t *integer); |
---|
| 11 | int og_json_parse_bool(const json_t *element, bool *value); |
---|
[04ca20e] | 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) |
---|
[12d8fff] | 21 | #define OG_PARAM_PART_DISK_TYPE (1UL << 8) |
---|
[04ca20e] | 22 | |
---|
| 23 | struct og_partition { |
---|
| 24 | const char *disk; |
---|
[12d8fff] | 25 | const char *disk_type; |
---|
[04ca20e] | 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 | |
---|
[24e6fbf] | 35 | #define OG_DISK_MAX 4 |
---|
| 36 | #define OG_PARTITION_MAX (4 * OG_DISK_MAX) |
---|
[04ca20e] | 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 | |
---|
[33b0c6f] | 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 | |
---|
[04ca20e] | 69 | struct og_msg_params { |
---|
| 70 | const char *ips_array[OG_CLIENTS_MAX]; |
---|
| 71 | const char *mac_array[OG_CLIENTS_MAX]; |
---|
[06af0c2] | 72 | const char *netmask_array[OG_CLIENTS_MAX]; |
---|
[04ca20e] | 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; |
---|
[0212091] | 86 | const char *comment; |
---|
[04ca20e] | 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 | |
---|
[88c8b52] | 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 | |
---|
[141b079] | 99 | struct og_cmd_json { |
---|
| 100 | const char *type; |
---|
| 101 | json_t *json; |
---|
| 102 | uint32_t flags; |
---|
| 103 | }; |
---|
| 104 | |
---|
[1fdb7e6] | 105 | enum og_procedure_step_type { |
---|
| 106 | OG_STEP_COMMAND = 0, |
---|
| 107 | OG_STEP_PROCEDURE, |
---|
[7325a86] | 108 | OG_STEP_TASK, |
---|
[1fdb7e6] | 109 | }; |
---|
| 110 | |
---|
| 111 | #define OG_PROCEDURE_STEPS_MAX 256 |
---|
| 112 | |
---|
| 113 | struct og_procedure_step { |
---|
| 114 | enum og_procedure_step_type type; |
---|
| 115 | uint32_t position; |
---|
| 116 | |
---|
| 117 | union { |
---|
| 118 | struct og_cmd_json cmd; |
---|
| 119 | struct { |
---|
| 120 | uint64_t id; |
---|
| 121 | } procedure; |
---|
| 122 | }; |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | struct og_procedure { |
---|
| 126 | uint64_t id; |
---|
| 127 | struct og_procedure_step steps[OG_PROCEDURE_STEPS_MAX]; |
---|
| 128 | uint32_t num_steps; |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | int og_json_parse_procedure(json_t *element, struct og_procedure *proc); |
---|
| 132 | |
---|
[04ca20e] | 133 | #endif |
---|