2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@file
|
|
|
|
@brief `spec.json` validator.
|
|
|
|
*/
|
2023-11-24 17:27:44 +00:00
|
|
|
#ifndef _BOOTSTRAP_VALIDATOR_H
|
|
|
|
#define _BOOTSTRAP_VALIDATOR_H
|
|
|
|
|
|
|
|
#include "cJSON.h"
|
2023-11-26 13:30:44 +00:00
|
|
|
#include "config.h"
|
2023-11-24 17:27:44 +00:00
|
|
|
#include "dyn_array.h"
|
2023-11-25 16:15:30 +00:00
|
|
|
#include "error.h"
|
2023-11-24 17:27:44 +00:00
|
|
|
|
2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@brief The types of fields `bootstrap` can handle.
|
|
|
|
*/
|
2023-11-25 02:29:14 +00:00
|
|
|
enum FieldType {
|
2023-11-25 22:25:01 +00:00
|
|
|
FT_TEXT = 1,
|
2023-11-24 17:27:44 +00:00
|
|
|
};
|
|
|
|
|
2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@brief A container for relevant fields of a `cJSON`-parsed field.
|
|
|
|
|
|
|
|
A @ref Field refers to the top-level key-value pairs found in the `spec.json`
|
|
|
|
file. For instance, the fields of:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"abc": {
|
2023-11-25 22:25:01 +00:00
|
|
|
"type": "text",
|
|
|
|
"prompt": "ABC> "
|
2023-11-25 19:18:36 +00:00
|
|
|
},
|
|
|
|
"def": {
|
2023-11-25 22:25:01 +00:00
|
|
|
"type": "text",
|
|
|
|
"prompt": "DEF> "
|
2023-11-25 19:18:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
are `abc` and `def`.
|
|
|
|
*/
|
2023-11-25 02:29:14 +00:00
|
|
|
struct Field {
|
2023-11-25 19:18:36 +00:00
|
|
|
/// @brief The type of field. Denotes what prompt should be displayed prior to
|
|
|
|
/// evaluation.
|
2023-11-25 02:29:14 +00:00
|
|
|
enum FieldType type;
|
2023-11-25 19:18:36 +00:00
|
|
|
/// @brief A reference to the name of the field. Does not take ownership of
|
|
|
|
/// this value.
|
2023-11-24 17:27:44 +00:00
|
|
|
const char *key;
|
2023-11-25 19:18:36 +00:00
|
|
|
/// @brief A reference to the supplied prompt. Does not take ownership of this
|
|
|
|
/// value.
|
2023-11-25 02:29:14 +00:00
|
|
|
const char *prompt;
|
2023-11-24 17:27:44 +00:00
|
|
|
};
|
|
|
|
|
2023-11-25 19:18:36 +00:00
|
|
|
/**
|
|
|
|
@brief Verify the `spec.json` file is formatted correctly.
|
|
|
|
|
2023-11-26 13:30:44 +00:00
|
|
|
@param config
|
|
|
|
A reference to the parameters describing the desired spec.
|
2023-11-25 19:18:36 +00:00
|
|
|
@param parsed
|
|
|
|
A possible null pointer to the parsed `spec.json` file. If null, this method
|
|
|
|
simply sets *fields to a null pointer.
|
|
|
|
@param fields
|
|
|
|
The array of `Field`s defined in the top-level `spec.json` file, provided
|
|
|
|
validation was successful.
|
|
|
|
@return
|
|
|
|
A null pointer if no error occurs. Otherwise an @ref Error pointer.
|
|
|
|
*/
|
2023-11-25 16:15:30 +00:00
|
|
|
struct Error *validate_spec_json(
|
2023-11-26 13:30:44 +00:00
|
|
|
const struct Config *const config,
|
|
|
|
const cJSON *const parsed,
|
|
|
|
struct DynArray **fields
|
2023-11-25 02:35:22 +00:00
|
|
|
);
|
2023-11-24 17:27:44 +00:00
|
|
|
|
|
|
|
#endif /* _BOOTSTRAP_VALIDATOR_H */
|