45 name_len = strlen(
name) + 1;
47 f =
calloc_a(
sizeof(*f) + len, &new_name, name_len);
80 if (file->
seq == call->
seq) {
128 expr_tuple[1].
type = t1;
129 expr_tuple[2].
type = t2;
147 if (!tb[1] || !tb[2])
170 if (!tb[1] || !tb[2])
214 static int eq_regex_cmp(
const char *str,
const char *pattern,
bool regex)
220 return !strcmp(str, pattern);
222 if (regcomp(®, pattern, REG_EXTENDED | REG_NOSUB))
225 ret = !regexec(®, str, 0, NULL, 0);
239 if (!tb[1] || !tb[2])
261 ctx->
handle_error(ctx,
"Unexpected element type", tb[2]);
301 ctx->
handle_error(ctx,
"Unexpected element type", tb[1]);
357 const char *pattern, *path;
371 ret = stat(path, &s);
374 return S_ISDIR(s.st_mode);
394 for (i = 0; i < n; i++) {
399 return h[i].
cb(call, cur);
429 char *dest, *next, *str;
438 next = alloca(strlen(pattern) + 1);
439 strcpy(next, pattern);
441 for (str = next; str; str = next) {
447 end = strchr(str,
'%');
453 end = str + strlen(str);
463 cur_len = strlen(cur);
484 memcpy(dest + len, cur, cur_len);
536 ctx->
handle_error(ctx,
"Unterminated variable reference in string", attr);
582 ctx->
handle_error(ctx,
"Unexpected element type", block);
610 static unsigned int _seq = 0;
int avl_strcmp(const void *k1, const void *k2, void *ptr)
int avl_insert(struct avl_tree *tree, struct avl_node *new)
void avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr)
#define avl_find_element(tree, key, element, node_element)
#define avl_remove_all_elements(tree, element, node_member, ptr)
void blob_buf_free(struct blob_buf *buf)
int blob_buf_init(struct blob_buf *buf, int id)
static void * blob_data(const struct blob_attr *attr)
void * blobmsg_alloc_string_buffer(struct blob_buf *buf, const char *name, unsigned int maxlen)
void blobmsg_add_string_buffer(struct blob_buf *buf)
int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
void * blobmsg_realloc_string_buffer(struct blob_buf *buf, unsigned int maxlen)
static size_t blobmsg_data_len(const struct blob_attr *attr)
static int blobmsg_add_blob(struct blob_buf *buf, struct blob_attr *attr)
static const char * blobmsg_name(const struct blob_attr *attr)
static void blobmsg_close_array(struct blob_buf *buf, void *cookie)
#define blobmsg_for_each_attr(pos, attr, rem)
static void * blobmsg_open_array(struct blob_buf *buf, const char *name)
static void * blobmsg_data(const struct blob_attr *attr)
static int handle_return(struct json_call *call, struct blob_attr *expr)
static int cmd_add_string(struct json_call *call, const char *pattern)
static int __json_process_cmd(struct json_call *call, struct blob_attr *cur)
static const struct json_handler cmd[]
void json_script_init(struct json_script_ctx *ctx)
static int __default_handle_expr(struct json_script_ctx *ctx, const char *name, struct blob_attr *expr, struct blob_attr *vars)
static struct json_script_file * json_script_get_file(struct json_script_ctx *ctx, const char *filename)
static int expr_eq_regex(struct json_call *call, struct blob_attr *expr, bool regex)
void json_script_free(struct json_script_ctx *ctx)
static int handle_if(struct json_call *call, struct blob_attr *expr)
static void __json_script_run(struct json_call *call, struct json_script_file *file, struct blob_attr *context)
static int handle_expr_regex(struct json_call *call, struct blob_attr *expr)
struct json_script_file * json_script_file_from_blobmsg(const char *name, void *data, int len)
static int handle_expr_and(struct json_call *call, struct blob_attr *expr)
static const struct json_handler expr[]
static const char * __default_handle_var(struct json_script_ctx *ctx, const char *name, struct blob_attr *vars)
static int json_process_expr(struct json_call *call, struct blob_attr *cur)
static int handle_expr_or(struct json_call *call, struct blob_attr *expr)
static int expr_and_or(struct json_call *call, struct blob_attr *expr, bool and)
static void __default_handle_error(struct json_script_ctx *ctx, const char *msg, struct blob_attr *context)
static int json_process_cmd(struct json_call *call, struct blob_attr *cur)
static int __json_process_type(struct json_call *call, struct blob_attr *cur, const struct json_handler *h, int n, bool *found)
static const char * msg_find_var(struct json_call *call, const char *name)
static struct json_script_file * __default_handle_file(struct json_script_ctx *ctx, const char *name)
static int handle_expr_has(struct json_call *call, struct blob_attr *expr)
static int handle_expr_isdir(struct json_call *call, struct blob_attr *expr)
int json_script_eval_string(struct json_script_ctx *ctx, struct blob_attr *vars, struct blob_buf *buf, const char *name, const char *pattern)
static void json_get_tuple(struct blob_attr *cur, struct blob_attr **tb, int t1, int t2)
void json_script_run(struct json_script_ctx *ctx, const char *name, struct blob_attr *vars)
static int handle_case(struct json_call *call, struct blob_attr *expr)
void json_script_run_file(struct json_script_ctx *ctx, struct json_script_file *file, struct blob_attr *vars)
static int cmd_process_strings(struct json_call *call, struct blob_attr *attr)
const char * json_script_find_var(struct json_script_ctx *ctx, struct blob_attr *vars, const char *name)
static int handle_expr_eq(struct json_call *call, struct blob_attr *expr)
static int eval_string(struct json_call *call, struct blob_buf *buf, const char *name, const char *pattern)
static int handle_include(struct json_call *call, struct blob_attr *expr)
static void __json_script_file_free(struct json_script_file *f)
static int handle_expr_not(struct json_call *call, struct blob_attr *expr)
static int eq_regex_cmp(const char *str, const char *pattern, bool regex)
struct json_script_ctx * ctx
int(* cb)(struct json_call *call, struct blob_attr *cur)
const char *(* handle_var)(struct json_script_ctx *ctx, const char *name, struct blob_attr *vars)
int(* handle_expr)(struct json_script_ctx *ctx, const char *name, struct blob_attr *expr, struct blob_attr *vars)
void(* handle_error)(struct json_script_ctx *ctx, const char *msg, struct blob_attr *context)
void(* handle_command)(struct json_script_ctx *ctx, const char *name, struct blob_attr *cmd, struct blob_attr *vars)
struct json_script_file *(* handle_file)(struct json_script_ctx *ctx, const char *name)
struct json_script_file * next
struct udebug_client_msg * msg
#define calloc_a(len,...)