5 struct ubus_auto_conn conn
;
7 static struct ubus_object udebug_object
;
17 static const struct blobmsg_policy list_policy
[__LIST_ATTR_MAX
] = {
18 [LIST_ATTR_PROCNAME
] = { "proc_name", BLOBMSG_TYPE_ARRAY
},
19 [LIST_ATTR_RINGNAME
] = { "ring_name", BLOBMSG_TYPE_ARRAY
},
20 [LIST_ATTR_PID
] = { "pid", BLOBMSG_TYPE_ARRAY
},
21 [LIST_ATTR_UID
] = { "uid", BLOBMSG_TYPE_ARRAY
},
25 string_array_match(const char *val
, struct blob_attr
*match
)
27 struct blob_attr
*cur
;
30 if (!match
|| !blobmsg_len(match
))
33 if (blobmsg_check_array(match
, BLOBMSG_TYPE_STRING
) < 0)
36 blobmsg_for_each_attr(cur
, match
, rem
) {
37 if (fnmatch(blobmsg_get_string(cur
), val
, 0) == 0)
45 int_array_match(unsigned int val
, struct blob_attr
*match
)
47 struct blob_attr
*cur
;
50 if (!match
|| !blobmsg_len(match
))
53 if (blobmsg_check_array(match
, BLOBMSG_TYPE_INT32
) < 0)
56 blobmsg_for_each_attr(cur
, match
, rem
) {
57 if (val
== blobmsg_get_u32(cur
))
65 udebug_list_match(struct client_ring
*r
, struct blob_attr
**tb
)
67 return string_array_match(r
->cl
->proc_name
, tb
[LIST_ATTR_PROCNAME
]) &&
68 string_array_match(r
->name
, tb
[LIST_ATTR_RINGNAME
]) &&
69 int_array_match(r
->cl
->pid
, tb
[LIST_ATTR_PID
]) &&
70 int_array_match(r
->cl
->uid
, tb
[LIST_ATTR_UID
]);
74 udebug_list_add_ring_data(struct client_ring
*r
)
76 blobmsg_add_u32(&b
, "id", ring_id(r
));
77 blobmsg_add_string(&b
, "proc_name", r
->cl
->proc_name
);
78 blobmsg_add_string(&b
, "ring_name", r
->name
);
79 blobmsg_add_u32(&b
, "pid", r
->cl
->pid
);
80 blobmsg_add_u32(&b
, "uid", r
->cl
->uid
);
82 blobmsg_add_blob(&b
, r
->flags
);
85 void udebug_ubus_ring_notify(struct client_ring
*r
, bool add
)
88 udebug_list_add_ring_data(r
);
89 ubus_notify(&conn
.ctx
, &udebug_object
, add
? "add" : "remove", b
.head
, -1);
93 udebug_list_add_ring(struct client_ring
*r
)
97 c
= blobmsg_open_table(&b
, NULL
);
98 udebug_list_add_ring_data(r
);
99 blobmsg_close_table(&b
, c
);
103 udebug_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
104 struct ubus_request_data
*req
, const char *method
,
105 struct blob_attr
*msg
)
107 struct blob_attr
*tb
[__LIST_ATTR_MAX
];
108 struct client_ring
*r
;
111 blobmsg_parse_attr(list_policy
, __LIST_ATTR_MAX
, tb
, msg
);
113 blob_buf_init(&b
, 0);
114 c
= blobmsg_open_array(&b
, "results");
115 avl_for_each_element(&rings
, r
, node
)
116 if (udebug_list_match(r
, tb
))
117 udebug_list_add_ring(r
);
118 blobmsg_close_array(&b
, c
);
119 ubus_send_reply(ctx
, req
, b
.head
);
124 static const struct ubus_method udebug_methods
[] = {
125 UBUS_METHOD("list", udebug_list
, list_policy
),
128 static struct ubus_object_type udebug_object_type
=
129 UBUS_OBJECT_TYPE("udebug", udebug_methods
);
131 static struct ubus_object udebug_object
= {
133 .type
= &udebug_object_type
,
134 .methods
= udebug_methods
,
135 .n_methods
= ARRAY_SIZE(udebug_methods
),
138 static void ubus_connect_cb(struct ubus_context
*ctx
)
140 ubus_add_object(ctx
, &udebug_object
);
143 void udebug_ubus_init(void)
145 conn
.cb
= ubus_connect_cb
;
146 ubus_auto_connect(&conn
);
149 void udebug_ubus_free(void)
151 ubus_auto_shutdown(&conn
);