summaryrefslogtreecommitdiff
path: root/libubus.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-03-27 20:03:18 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-03-27 20:03:18 +0200
commite49b34f91267449e89d3f482b7c16bbf84bf90fd (patch)
tree9a2546e4d7655a574c74e52f63871c8dda156566 /libubus.c
parent7cd569acc8ecff9d75a722200b1a52d9d400edfc (diff)
downloadubus-e49b34f91267449e89d3f482b7c16bbf84bf90fd.tar.gz
simplify object signatures by reusing the parser policy to define them
Diffstat (limited to 'libubus.c')
-rw-r--r--libubus.c62
1 files changed, 16 insertions, 46 deletions
diff --git a/libubus.c b/libubus.c
index d84e970..049aac9 100644
--- a/libubus.c
+++ b/libubus.c
@@ -615,59 +615,29 @@ static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_a
avl_insert(&req->ctx->objects, &obj->avl);
}
-static bool ubus_push_table_data(const struct ubus_signature **sig, int *rem, bool array)
-{
- const struct ubus_signature *cur;
- bool nest_type;
- void *nest;
-
- while (rem) {
- cur = (*sig)++;
- (*rem)--;
- switch(cur->type) {
- case UBUS_SIGNATURE_END:
- return !array;
- case BLOBMSG_TYPE_INT32:
- case BLOBMSG_TYPE_STRING:
- blobmsg_add_u32(&b, cur->name, cur->type);
- break;
- case BLOBMSG_TYPE_TABLE:
- case BLOBMSG_TYPE_ARRAY:
- nest_type = cur->type == BLOBMSG_TYPE_ARRAY;
- nest = blobmsg_open_nested(&b, cur->name, nest_type);
- if (!ubus_push_table_data(sig, rem, nest_type))
- return false;
- blobmsg_close_table(&b, nest);
- break;
- default:
- return false;
- }
- if (array)
- return true;
- }
- return false;
+static void ubus_push_method_data(const struct ubus_method *m)
+{
+ void *mtbl;
+ int i;
+
+ mtbl = blobmsg_open_table(&b, m->name);
+
+ for (i = 0; i < m->n_policy; i++)
+ blobmsg_add_u32(&b, m->policy[i].name, m->policy[i].type);
+
+ blobmsg_close_table(&b, mtbl);
}
-static bool ubus_push_object_type(struct ubus_object_type *type)
+static bool ubus_push_object_type(const struct ubus_object_type *type)
{
- void *s, *m;
- int rem = type->n_signature;
- const struct ubus_signature *sig = type->signature;
+ void *s;
+ int i;
s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE);
- while (rem) {
- if (sig->type != UBUS_SIGNATURE_METHOD)
- return false;
- m = blobmsg_open_table(&b, sig->name);
+ for (i = 0; i < type->n_methods; i++)
+ ubus_push_method_data(&type->methods[i]);
- sig++;
- rem--;
- if (!ubus_push_table_data(&sig, &rem, false))
- return false;
-
- blobmsg_close_table(&b, m);
- }
blob_nest_end(&b, s);
return true;