#ifndef __JSON_SCRIPT_H
#define __JSON_SCRIPT_H
#include "avl.h"
#include "blob.h"
#include "blobmsg.h"
#include "utils.h"
struct json_script_file;
struct json_script_ctx {
struct avl_tree files;
struct blob_buf buf;
uint32_t run_seq;
bool abort;
void (*handle_command)(struct json_script_ctx *ctx, const char *name,
struct blob_attr *cmd, struct blob_attr *vars);
int (*handle_expr)(struct json_script_ctx *ctx, const char *name,
struct blob_attr *expr, struct blob_attr *vars);
const char *(*handle_var)(struct json_script_ctx *ctx, const char *name,
struct blob_attr *vars);
struct json_script_file *(*handle_file)(struct json_script_ctx *ctx,
const char *name);
void (*handle_error)(struct json_script_ctx *ctx, const char *msg,
struct blob_attr *context);
};
struct json_script_file {
struct avl_node avl;
struct json_script_file *next;
unsigned int seq;
struct blob_attr data[];
};
void json_script_init(struct json_script_ctx *ctx);
void json_script_free(struct json_script_ctx *ctx);
void json_script_run(struct json_script_ctx *ctx, const char *filename,
struct blob_attr *vars);
void json_script_run_file(struct json_script_ctx *ctx, struct json_script_file *file,
struct blob_attr *vars);
static inline void
json_script_abort(struct json_script_ctx *ctx)
{
ctx->abort = true;
}
int json_script_eval_string(struct json_script_ctx *ctx, struct blob_attr *vars,
struct blob_buf *buf, const char *name,
const char *pattern);
struct json_script_file *
json_script_file_from_blobmsg(const char *name, void *data, int len);
const char *json_script_find_var(struct json_script_ctx *ctx, struct blob_attr *vars,
const char *name);
#endif