2 * uhttpd - Tiny single-threaded httpd
4 * Copyright (C) 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
5 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <libubox/blobmsg.h>
22 #include <libubox/blobmsg_json.h>
23 #include <libubox/avl.h>
24 #include <libubox/avl-cmp.h>
33 static const struct uhttpd_ops
*ops
;
34 static struct config
*_conf
;
37 static struct ubus_context
*ctx
;
38 static struct avl_tree sessions
;
39 static struct blob_buf buf
;
41 static const struct blobmsg_policy new_policy
= {
42 .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
45 static const struct blobmsg_policy sid_policy
= {
46 .name
= "sid", .type
= BLOBMSG_TYPE_STRING
54 static const struct blobmsg_policy set_policy
[__UH_UBUS_SS_MAX
] = {
55 [UH_UBUS_SS_SID
] = { .name
= "sid", .type
= BLOBMSG_TYPE_STRING
},
56 [UH_UBUS_SS_VALUES
] = { .name
= "values", .type
= BLOBMSG_TYPE_TABLE
},
64 static const struct blobmsg_policy get_policy
[__UH_UBUS_SG_MAX
] = {
65 [UH_UBUS_SG_SID
] = { .name
= "sid", .type
= BLOBMSG_TYPE_STRING
},
66 [UH_UBUS_SG_KEYS
] = { .name
= "keys", .type
= BLOBMSG_TYPE_ARRAY
},
74 static const struct blobmsg_policy acl_policy
[__UH_UBUS_SA_MAX
] = {
75 [UH_UBUS_SA_SID
] = { .name
= "sid", .type
= BLOBMSG_TYPE_STRING
},
76 [UH_UBUS_SA_OBJECTS
] = { .name
= "objects", .type
= BLOBMSG_TYPE_ARRAY
},
80 * Keys in the AVL tree contain all pattern characters up to the first wildcard.
81 * To look up entries, start with the last entry that has a key less than or
82 * equal to the method name, then work backwards as long as the AVL key still
83 * matches its counterpart in the object name
85 #define uh_foreach_matching_acl_prefix(_acl, _ses, _obj, _func) \
86 for (_acl = avl_find_le_element(&(_ses)->acls, _obj, _acl, avl); \
87 _acl && !strncmp((_acl)->object, _obj, (_acl)->sort_len); \
88 _acl = avl_is_first(&(ses)->acls, &(_acl)->avl) ? NULL : \
89 avl_prev_element((_acl), avl))
91 #define uh_foreach_matching_acl(_acl, _ses, _obj, _func) \
92 uh_foreach_matching_acl_prefix(_acl, _ses, _obj, _func) \
93 if (!fnmatch((_acl)->object, (_obj), FNM_NOESCAPE) && \
94 !fnmatch((_acl)->function, (_func), FNM_NOESCAPE))
97 uh_ubus_random(char *dest
)
99 unsigned char buf
[16] = { 0 };
103 f
= fopen("/dev/urandom", "r");
107 fread(buf
, 1, sizeof(buf
), f
);
110 for (i
= 0; i
< sizeof(buf
); i
++)
111 sprintf(dest
+ (i
<<1), "%02x", buf
[i
]);
115 uh_ubus_session_dump_data(struct uh_ubus_session
*ses
, struct blob_buf
*b
)
117 struct uh_ubus_session_data
*d
;
119 avl_for_each_element(&ses
->data
, d
, avl
) {
120 blobmsg_add_field(b
, blobmsg_type(d
->attr
), blobmsg_name(d
->attr
),
121 blobmsg_data(d
->attr
), blobmsg_data_len(d
->attr
));
126 uh_ubus_session_dump_acls(struct uh_ubus_session
*ses
, struct blob_buf
*b
)
128 struct uh_ubus_session_acl
*acl
;
129 const char *lastobj
= NULL
;
132 avl_for_each_element(&ses
->acls
, acl
, avl
) {
133 if (!lastobj
|| strcmp(acl
->object
, lastobj
))
135 if (c
) blobmsg_close_array(b
, c
);
136 c
= blobmsg_open_array(b
, acl
->object
);
139 blobmsg_add_string(b
, NULL
, acl
->function
);
140 lastobj
= acl
->object
;
143 if (c
) blobmsg_close_array(b
, c
);
147 uh_ubus_session_dump(struct uh_ubus_session
*ses
,
148 struct ubus_context
*ctx
,
149 struct ubus_request_data
*req
)
154 memset(&b
, 0, sizeof(b
));
155 blob_buf_init(&b
, 0);
157 blobmsg_add_string(&b
, "sid", ses
->id
);
158 blobmsg_add_u32(&b
, "timeout", ses
->timeout
);
160 c
= blobmsg_open_table(&b
, "acls");
161 uh_ubus_session_dump_acls(ses
, &b
);
162 blobmsg_close_table(&b
, c
);
164 c
= blobmsg_open_table(&b
, "data");
165 uh_ubus_session_dump_data(ses
, &b
);
166 blobmsg_close_table(&b
, c
);
168 ubus_send_reply(ctx
, req
, b
.head
);
173 uh_ubus_touch_session(struct uh_ubus_session
*ses
)
175 uloop_timeout_set(&ses
->t
, ses
->timeout
* 1000);
179 uh_ubus_session_destroy(struct uh_ubus_session
*ses
)
181 struct uh_ubus_session_acl
*acl
, *nacl
;
182 struct uh_ubus_session_data
*data
, *ndata
;
184 uloop_timeout_cancel(&ses
->t
);
185 avl_remove_all_elements(&ses
->acls
, acl
, avl
, nacl
)
188 avl_remove_all_elements(&ses
->data
, data
, avl
, ndata
)
191 avl_delete(&sessions
, &ses
->avl
);
195 static void uh_ubus_session_timeout(struct uloop_timeout
*t
)
197 struct uh_ubus_session
*ses
;
199 ses
= container_of(t
, struct uh_ubus_session
, t
);
200 uh_ubus_session_destroy(ses
);
203 static struct uh_ubus_session
*
204 uh_ubus_session_create(int timeout
)
206 struct uh_ubus_session
*ses
;
208 ses
= calloc(1, sizeof(*ses
));
212 ses
->timeout
= timeout
;
213 ses
->avl
.key
= ses
->id
;
214 uh_ubus_random(ses
->id
);
216 avl_insert(&sessions
, &ses
->avl
);
217 avl_init(&ses
->acls
, avl_strcmp
, true, NULL
);
218 avl_init(&ses
->data
, avl_strcmp
, false, NULL
);
220 ses
->t
.cb
= uh_ubus_session_timeout
;
221 uh_ubus_touch_session(ses
);
226 static struct uh_ubus_session
*
227 uh_ubus_session_get(const char *id
)
229 struct uh_ubus_session
*ses
;
231 ses
= avl_find_element(&sessions
, id
, ses
, avl
);
235 uh_ubus_touch_session(ses
);
240 uh_ubus_handle_create(struct ubus_context
*ctx
, struct ubus_object
*obj
,
241 struct ubus_request_data
*req
, const char *method
,
242 struct blob_attr
*msg
)
244 struct uh_ubus_session
*ses
;
245 struct blob_attr
*tb
;
246 int timeout
= conf
.script_timeout
;
248 blobmsg_parse(&new_policy
, 1, &tb
, blob_data(msg
), blob_len(msg
));
250 timeout
= blobmsg_get_u32(tb
);
252 ses
= uh_ubus_session_create(timeout
);
254 uh_ubus_session_dump(ses
, ctx
, req
);
260 uh_ubus_handle_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
261 struct ubus_request_data
*req
, const char *method
,
262 struct blob_attr
*msg
)
264 struct uh_ubus_session
*ses
;
265 struct blob_attr
*tb
;
267 blobmsg_parse(&sid_policy
, 1, &tb
, blob_data(msg
), blob_len(msg
));
270 avl_for_each_element(&sessions
, ses
, avl
)
271 uh_ubus_session_dump(ses
, ctx
, req
);
275 ses
= uh_ubus_session_get(blobmsg_data(tb
));
277 return UBUS_STATUS_NOT_FOUND
;
279 uh_ubus_session_dump(ses
, ctx
, req
);
285 uh_id_len(const char *str
)
287 return strcspn(str
, "*?[");
291 uh_ubus_session_grant(struct uh_ubus_session
*ses
, struct ubus_context
*ctx
,
292 const char *object
, const char *function
)
294 struct uh_ubus_session_acl
*acl
;
295 char *new_obj
, *new_func
, *new_id
;
298 if (!object
|| !function
)
299 return UBUS_STATUS_INVALID_ARGUMENT
;
301 uh_foreach_matching_acl_prefix(acl
, ses
, object
, function
) {
302 if (!strcmp(acl
->object
, object
) &&
303 !strcmp(acl
->function
, function
))
307 id_len
= uh_id_len(object
);
308 acl
= calloc_a(sizeof(*acl
),
309 &new_obj
, strlen(object
) + 1,
310 &new_func
, strlen(function
) + 1,
311 &new_id
, id_len
+ 1);
314 return UBUS_STATUS_UNKNOWN_ERROR
;
316 acl
->object
= strcpy(new_obj
, object
);
317 acl
->function
= strcpy(new_func
, function
);
318 acl
->avl
.key
= strncpy(new_id
, object
, id_len
);
319 avl_insert(&ses
->acls
, &acl
->avl
);
325 uh_ubus_session_revoke(struct uh_ubus_session
*ses
, struct ubus_context
*ctx
,
326 const char *object
, const char *function
)
328 struct uh_ubus_session_acl
*acl
, *next
;
332 if (!object
&& !function
) {
333 avl_remove_all_elements(&ses
->acls
, acl
, avl
, next
)
338 id_len
= uh_id_len(object
);
339 id
= alloca(id_len
+ 1);
340 strncpy(id
, object
, id_len
);
343 acl
= avl_find_element(&ses
->acls
, id
, acl
, avl
);
345 if (!avl_is_last(&ses
->acls
, &acl
->avl
))
346 next
= avl_next_element(acl
, avl
);
350 if (strcmp(id
, acl
->avl
.key
) != 0)
353 if (!strcmp(acl
->object
, object
) &&
354 !strcmp(acl
->function
, function
)) {
355 avl_delete(&ses
->acls
, &acl
->avl
);
366 uh_ubus_handle_acl(struct ubus_context
*ctx
, struct ubus_object
*obj
,
367 struct ubus_request_data
*req
, const char *method
,
368 struct blob_attr
*msg
)
370 struct uh_ubus_session
*ses
;
371 struct blob_attr
*tb
[__UH_UBUS_SA_MAX
];
372 struct blob_attr
*attr
, *sattr
;
373 const char *object
, *function
;
376 int (*cb
)(struct uh_ubus_session
*ses
, struct ubus_context
*ctx
,
377 const char *object
, const char *function
);
379 blobmsg_parse(acl_policy
, __UH_UBUS_SA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
381 if (!tb
[UH_UBUS_SA_SID
])
382 return UBUS_STATUS_INVALID_ARGUMENT
;
384 ses
= uh_ubus_session_get(blobmsg_data(tb
[UH_UBUS_SA_SID
]));
386 return UBUS_STATUS_NOT_FOUND
;
388 if (!strcmp(method
, "grant"))
389 cb
= uh_ubus_session_grant
;
391 cb
= uh_ubus_session_revoke
;
393 if (!tb
[UH_UBUS_SA_OBJECTS
])
394 return cb(ses
, ctx
, NULL
, NULL
);
396 blobmsg_for_each_attr(attr
, tb
[UH_UBUS_SA_OBJECTS
], rem1
) {
397 if (blob_id(attr
) != BLOBMSG_TYPE_ARRAY
)
403 blobmsg_for_each_attr(sattr
, attr
, rem2
) {
404 if (blob_id(sattr
) != BLOBMSG_TYPE_STRING
)
408 object
= blobmsg_data(sattr
);
410 function
= blobmsg_data(sattr
);
415 if (object
&& function
)
416 cb(ses
, ctx
, object
, function
);
423 uh_ubus_handle_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
424 struct ubus_request_data
*req
, const char *method
,
425 struct blob_attr
*msg
)
427 struct uh_ubus_session
*ses
;
428 struct uh_ubus_session_data
*data
;
429 struct blob_attr
*tb
[__UH_UBUS_SA_MAX
];
430 struct blob_attr
*attr
;
433 blobmsg_parse(set_policy
, __UH_UBUS_SS_MAX
, tb
, blob_data(msg
), blob_len(msg
));
435 if (!tb
[UH_UBUS_SS_SID
] || !tb
[UH_UBUS_SS_VALUES
])
436 return UBUS_STATUS_INVALID_ARGUMENT
;
438 ses
= uh_ubus_session_get(blobmsg_data(tb
[UH_UBUS_SS_SID
]));
440 return UBUS_STATUS_NOT_FOUND
;
442 blobmsg_for_each_attr(attr
, tb
[UH_UBUS_SS_VALUES
], rem
) {
443 if (!blobmsg_name(attr
)[0])
446 data
= avl_find_element(&ses
->data
, blobmsg_name(attr
), data
, avl
);
448 avl_delete(&ses
->data
, &data
->avl
);
452 data
= calloc(1, sizeof(*data
) + blob_pad_len(attr
));
456 memcpy(data
->attr
, attr
, blob_pad_len(attr
));
457 data
->avl
.key
= blobmsg_name(data
->attr
);
458 avl_insert(&ses
->data
, &data
->avl
);
465 uh_ubus_handle_get(struct ubus_context
*ctx
, struct ubus_object
*obj
,
466 struct ubus_request_data
*req
, const char *method
,
467 struct blob_attr
*msg
)
469 struct uh_ubus_session
*ses
;
470 struct uh_ubus_session_data
*data
;
471 struct blob_attr
*tb
[__UH_UBUS_SA_MAX
];
472 struct blob_attr
*attr
;
477 blobmsg_parse(get_policy
, __UH_UBUS_SG_MAX
, tb
, blob_data(msg
), blob_len(msg
));
479 if (!tb
[UH_UBUS_SG_SID
])
480 return UBUS_STATUS_INVALID_ARGUMENT
;
482 ses
= uh_ubus_session_get(blobmsg_data(tb
[UH_UBUS_SG_SID
]));
484 return UBUS_STATUS_NOT_FOUND
;
486 memset(&b
, 0, sizeof(b
));
487 blob_buf_init(&b
, 0);
488 c
= blobmsg_open_table(&b
, "values");
490 if (!tb
[UH_UBUS_SG_KEYS
]) {
491 uh_ubus_session_dump_data(ses
, &b
);
495 blobmsg_for_each_attr(attr
, tb
[UH_UBUS_SG_KEYS
], rem
) {
496 if (blob_id(attr
) != BLOBMSG_TYPE_STRING
)
499 data
= avl_find_element(&ses
->data
, blobmsg_data(attr
), data
, avl
);
503 blobmsg_add_field(&b
, blobmsg_type(data
->attr
),
504 blobmsg_name(data
->attr
),
505 blobmsg_data(data
->attr
),
506 blobmsg_data_len(data
->attr
));
509 blobmsg_close_table(&b
, c
);
510 ubus_send_reply(ctx
, req
, b
.head
);
517 uh_ubus_handle_unset(struct ubus_context
*ctx
, struct ubus_object
*obj
,
518 struct ubus_request_data
*req
, const char *method
,
519 struct blob_attr
*msg
)
521 struct uh_ubus_session
*ses
;
522 struct uh_ubus_session_data
*data
, *ndata
;
523 struct blob_attr
*tb
[__UH_UBUS_SA_MAX
];
524 struct blob_attr
*attr
;
527 blobmsg_parse(get_policy
, __UH_UBUS_SG_MAX
, tb
, blob_data(msg
), blob_len(msg
));
529 if (!tb
[UH_UBUS_SG_SID
])
530 return UBUS_STATUS_INVALID_ARGUMENT
;
532 ses
= uh_ubus_session_get(blobmsg_data(tb
[UH_UBUS_SG_SID
]));
534 return UBUS_STATUS_NOT_FOUND
;
536 if (!tb
[UH_UBUS_SG_KEYS
]) {
537 avl_remove_all_elements(&ses
->data
, data
, avl
, ndata
)
542 blobmsg_for_each_attr(attr
, tb
[UH_UBUS_SG_KEYS
], rem
) {
543 if (blob_id(attr
) != BLOBMSG_TYPE_STRING
)
546 data
= avl_find_element(&ses
->data
, blobmsg_data(attr
), data
, avl
);
550 avl_delete(&ses
->data
, &data
->avl
);
558 uh_ubus_handle_destroy(struct ubus_context
*ctx
, struct ubus_object
*obj
,
559 struct ubus_request_data
*req
, const char *method
,
560 struct blob_attr
*msg
)
562 struct uh_ubus_session
*ses
;
563 struct blob_attr
*tb
;
565 blobmsg_parse(&sid_policy
, 1, &tb
, blob_data(msg
), blob_len(msg
));
568 return UBUS_STATUS_INVALID_ARGUMENT
;
570 ses
= uh_ubus_session_get(blobmsg_data(tb
));
572 return UBUS_STATUS_NOT_FOUND
;
574 uh_ubus_session_destroy(ses
);
579 static char *split_str(char *str
)
582 str
= strchr(str
, '/');
584 while (str
&& *str
== '/') {
592 uh_ubus_request_parse_url(struct client
*cl
, char *url
, char **sid
, char **obj
, char **fun
)
594 url
+= strlen(conf
.ubus_prefix
);
595 while (url
&& *url
== '/')
600 url
= split_str(url
);
603 url
= split_str(url
);
606 return *sid
&& *obj
&& *fun
;
610 uh_ubus_request_data_cb(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
612 struct dispatch_ubus
*du
= container_of(req
, struct dispatch_ubus
, req
);
613 struct client
*cl
= container_of(du
, struct client
, dispatch
.ubus
);
616 if (!du
->header_sent
) {
617 ops
->http_header(cl
, 200, "OK");
618 ustream_printf(cl
->us
, "Content-Type: application/json\r\n\r\n");
619 du
->header_sent
= true;
622 str
= blobmsg_format_json_indent(msg
, true, 0);
623 ops
->chunk_write(cl
, str
, strlen(str
));
628 uh_ubus_request_cb(struct ubus_request
*req
, int ret
)
630 struct dispatch_ubus
*du
= container_of(req
, struct dispatch_ubus
, req
);
631 struct client
*cl
= container_of(du
, struct client
, dispatch
.ubus
);
633 if (!du
->header_sent
)
634 return ops
->client_error(cl
, 204, "No content", "Function did not return data");
636 ops
->request_done(cl
);
639 static void uh_ubus_close_fds(struct client
*cl
)
641 if (ctx
->sock
.fd
< 0)
648 static void uh_ubus_request_free(struct client
*cl
)
650 struct dispatch_ubus
*du
= &cl
->dispatch
.ubus
;
653 json_object_put(du
->jsobj
);
656 json_tokener_free(du
->jstok
);
659 ubus_abort_request(ctx
, &du
->req
);
662 static void uh_ubus_json_error(struct client
*cl
)
664 ops
->client_error(cl
, 400, "Bad Request", "Invalid JSON data");
667 static void uh_ubus_send_request(struct client
*cl
, json_object
*obj
)
669 struct dispatch
*d
= &cl
->dispatch
;
670 struct dispatch_ubus
*du
= &d
->ubus
;
673 blob_buf_init(&buf
, 0);
675 if (obj
&& !blobmsg_add_object(&buf
, obj
))
676 return uh_ubus_json_error(cl
);
678 ret
= ubus_invoke_async(ctx
, du
->obj
, du
->func
, buf
.head
, &du
->req
);
680 return ops
->client_error(cl
, 500, "Internal Error",
681 "Error sending ubus request: %s", ubus_strerror(ret
));
683 du
->req
.data_cb
= uh_ubus_request_data_cb
;
684 du
->req
.complete_cb
= uh_ubus_request_cb
;
685 ubus_complete_request_async(ctx
, &du
->req
);
687 du
->req_pending
= true;
690 static void uh_ubus_data_done(struct client
*cl
)
692 struct dispatch_ubus
*du
= &cl
->dispatch
.ubus
;
693 struct json_object
*obj
= du
->jsobj
;
695 if (!obj
|| json_object_get_type(obj
) != json_type_object
)
696 return uh_ubus_json_error(cl
);
698 uh_ubus_send_request(cl
, obj
);
701 static int uh_ubus_data_send(struct client
*cl
, const char *data
, int len
)
703 struct dispatch_ubus
*du
= &cl
->dispatch
.ubus
;
706 uh_ubus_json_error(cl
);
711 if (du
->post_len
> UH_UBUS_MAX_POST_SIZE
) {
712 ops
->client_error(cl
, 413, "Too Large", "Message too big");
716 du
->jsobj
= json_tokener_parse_ex(du
->jstok
, data
, len
);
720 static void uh_ubus_defer_post(struct client
*cl
)
722 struct dispatch
*d
= &cl
->dispatch
;
724 d
->ubus
.jstok
= json_tokener_new();
726 return ops
->client_error(cl
, 500, "Internal Error", "Internal Error");
728 d
->data_send
= uh_ubus_data_send
;
729 d
->data_done
= uh_ubus_data_done
;
732 static void uh_ubus_handle_request(struct client
*cl
, char *url
, struct path_info
*pi
)
734 struct uh_ubus_session_acl
*acl
;
735 struct uh_ubus_session
*ses
;
736 struct dispatch
*d
= &cl
->dispatch
;
737 char *sid
, *obj
, *fun
;
740 blob_buf_init(&buf
, 0);
742 if (!uh_ubus_request_parse_url(cl
, url
, &sid
, &obj
, &fun
))
743 return ops
->client_error(cl
, 400, "Bad Request", "Invalid Request");
745 ses
= uh_ubus_session_get(sid
);
747 return ops
->client_error(cl
, 404, "Not Found", "No such session %s", sid
);
749 uh_foreach_matching_acl(acl
, ses
, obj
, fun
) {
755 return ops
->client_error(cl
, 403, "Denied", "Access to object denied");
757 if (ubus_lookup_id(ctx
, obj
, &d
->ubus
.obj
))
758 return ops
->client_error(cl
, 500, "Not Found", "No such object");
760 d
->close_fds
= uh_ubus_close_fds
;
761 d
->free
= uh_ubus_request_free
;
764 if (cl
->request
.method
== UH_HTTP_MSG_POST
)
765 uh_ubus_defer_post(cl
);
767 uh_ubus_send_request(cl
, NULL
);
771 uh_ubus_check_url(const char *url
)
773 return ops
->path_match(conf
.ubus_prefix
, url
);
779 static struct dispatch_handler ubus_dispatch
= {
780 .check_url
= uh_ubus_check_url
,
781 .handle_request
= uh_ubus_handle_request
,
784 static const struct ubus_method session_methods
[] = {
785 UBUS_METHOD("create", uh_ubus_handle_create
, &new_policy
),
786 UBUS_METHOD("list", uh_ubus_handle_list
, &sid_policy
),
787 UBUS_METHOD("grant", uh_ubus_handle_acl
, acl_policy
),
788 UBUS_METHOD("revoke", uh_ubus_handle_acl
, acl_policy
),
789 UBUS_METHOD("set", uh_ubus_handle_set
, set_policy
),
790 UBUS_METHOD("get", uh_ubus_handle_get
, get_policy
),
791 UBUS_METHOD("unset", uh_ubus_handle_unset
, get_policy
),
792 UBUS_METHOD("destroy", uh_ubus_handle_destroy
, &sid_policy
),
795 static struct ubus_object_type session_type
=
796 UBUS_OBJECT_TYPE("uhttpd", session_methods
);
798 static struct ubus_object obj
= {
800 .type
= &session_type
,
801 .methods
= session_methods
,
802 .n_methods
= ARRAY_SIZE(session_methods
),
807 ctx
= ubus_connect(conf
.ubus_socket
);
809 fprintf(stderr
, "Unable to connect to ubus socket\n");
813 ret
= ubus_add_object(ctx
, &obj
);
815 fprintf(stderr
, "Unable to publish ubus object: %s\n",
820 avl_init(&sessions
, avl_strcmp
, false, NULL
);
821 ops
->dispatch_add(&ubus_dispatch
);
828 static int uh_ubus_plugin_init(const struct uhttpd_ops
*o
, struct config
*c
)
832 return uh_ubus_init();
835 static void uh_ubus_post_init(void)
840 const struct uhttpd_plugin uhttpd_plugin
= {
841 .init
= uh_ubus_plugin_init
,
842 .post_init
= uh_ubus_post_init
,