validate JSON before loading

This commit also introduces slurp() which reads a file in its entirety. Using
this function instead of doing IO in the functions in load_layout.c again and
again makes the code cleaner (fixing at least two memory leaks) and avoids
re-reading the same file 3 times.

related to #2755
This commit is contained in:
Michael Stapelberg
2017-09-13 17:14:51 +02:00
parent 72c972a36c
commit c45c002bad
6 changed files with 131 additions and 83 deletions

View File

@ -31,6 +31,12 @@ typedef enum {
* determine whether the file contains workspaces or regular containers, which
* is important to know when deciding where (and how) to append the contents.
* */
json_content_t json_determine_content(const char *filename);
json_content_t json_determine_content(const char *buf, const size_t len);
void tree_append_json(Con *con, const char *filename, char **errormsg);
/**
* Returns true if the provided JSON could be parsed by yajl.
*
*/
bool json_validate(const char *buf, const size_t len);
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg);