static int service_update(struct service *s, struct blob_attr **tb, bool add) { struct blob_attr *cur; int rem; if (s->trigger) { trigger_del(s); free(s->trigger); s->trigger = NULL; } service_validate_del(s); if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) { s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]); if (!s->trigger) return -1; trigger_add(s->trigger, s); } if (tb[SERVICE_SET_VALIDATE] && blobmsg_data_len(tb[SERVICE_SET_VALIDATE])) { blobmsg_for_each_attr(cur, tb[SERVICE_SET_VALIDATE], rem) service_validate_add(s, cur); } if (tb[SERVICE_SET_INSTANCES]) { if (!add) vlist_update(&s->instances); blobmsg_for_each_attr(cur, tb[SERVICE_SET_INSTANCES], rem) { service_instance_add(s, cur); } if (!add) vlist_flush(&s->instances); }
static bool rpc_plugin_parse_signature(struct blob_attr *sig, struct ubus_method *method) { int rem, n_attr; enum blobmsg_type type; struct blob_attr *attr; struct blobmsg_policy *policy = NULL; if (!sig || blobmsg_type(sig) != BLOBMSG_TYPE_TABLE) return false; n_attr = 0; blobmsg_for_each_attr(attr, sig, rem) n_attr++; if (n_attr) { policy = calloc(n_attr, sizeof(*policy)); if (!policy) return false; n_attr = 0; blobmsg_for_each_attr(attr, sig, rem) { type = blobmsg_type(attr); if (type == BLOBMSG_TYPE_INT32) { switch (blobmsg_get_u32(attr)) { case 8: type = BLOBMSG_TYPE_INT8; break; case 16: type = BLOBMSG_TYPE_INT16; break; case 64: type = BLOBMSG_TYPE_INT64; break; default: type = BLOBMSG_TYPE_INT32; break; } } policy[n_attr].name = strdup(blobmsg_name(attr)); policy[n_attr].type = type; n_attr++; } }
static void handle_command(struct json_script_ctx *ctx, const char *name, struct blob_attr *data, struct blob_attr *vars) { struct blob_attr *cur; int rem; fprintf(stderr, "Command: %s", name); blobmsg_for_each_attr(cur, data, rem) fprintf(stderr, " %s", (char *) blobmsg_data(cur)); fprintf(stderr, "\n"); }