| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_YAML_H |
| 4 | #define NETDATA_YAML_H |
| 5 | |
| 6 | #include "../libnetdata.h" |
| 7 | #include <yaml.h> |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
| 13 | // Flags for YAML parsing behavior |
| 14 | typedef enum yaml_to_json_flags { |
| 15 | YAML2JSON_DEFAULT = 0, |
| 16 | YAML2JSON_ALL_VALUES_AS_STRINGS = (1 << 0), // Parse all scalar values as strings (no type conversion) |
| 17 | } YAML2JSON_FLAGS; |
| 18 | |
| 19 | // Parse YAML from various sources and convert to json-c object |
| 20 | struct json_object *yaml_parse_string(const char *yaml_string, BUFFER *error, YAML2JSON_FLAGS flags); |
| 21 | struct json_object *yaml_parse_filename(const char *filename, BUFFER *error, YAML2JSON_FLAGS flags); |
| 22 | struct json_object *yaml_parse_fd(int fd, BUFFER *error, YAML2JSON_FLAGS flags); |
| 23 | |
| 24 | // Generate YAML from json-c object to various destinations |
| 25 | bool yaml_generate_to_buffer(BUFFER *dst, struct json_object *json, BUFFER *error); |
| 26 | bool yaml_generate_to_filename(const char *filename, struct json_object *json, BUFFER *error); |
| 27 | bool yaml_generate_to_fd(int fd, struct json_object *json, BUFFER *error); |
| 28 | |
| 29 | // Test functions |
| 30 | int yaml_unittest(void); |
| 31 | int yaml_comprehensive_unittest(void); |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | #endif // NETDATA_YAML_H |