1 /*
2   Copyright 2021 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_JSON_YAML_H
26 #define CFENGINE_JSON_YAML_H
27 
28 #include <json.h>
29 
30 #ifdef HAVE_LIBYAML
31 #include <yaml.h>
32 #endif
33 
34 /**
35   @brief Parse a YAML string to create a JsonElement
36   @param data [in Pointer to the string to parse
37   @param json_out Resulting JSON object
38   @returns See JsonParseError and JsonParseErrorToString
39   */
40 JsonParseError JsonParseYamlString(const char **data, JsonElement **json_out);
41 
42 /**
43  * @brief Convenience function to parse JSON from a YAML file
44  * @param path Path to the file
45  * @param size_max Maximum size to read in memory
46  * @param json_out Resulting JSON object
47  * @return See JsonParseError and JsonParseErrorToString
48  */
49 JsonParseError JsonParseYamlFile(const char *path, size_t size_max, JsonElement **json_out);
50 
51 #endif // CFENGINE_JSON_YAML_H
52