fix cgi/lua header parsing
[project/uhttpd.git] / uhttpd.h
index 93046701765efd991962d1ecce8e24aa68e6dbb3..9dba44d4ee9a0ba440a44eb259f666b646871156 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
 #include <libubox/ustream.h>
 #include <libubox/blob.h>
 #include <libubox/utils.h>
+#ifdef HAVE_UBUS
+#include <libubus.h>
+#include <json/json.h>
+#endif
 #ifdef HAVE_TLS
 #include <libubox/ustream-ssl.h>
 #endif
@@ -37,8 +41,8 @@
 
 #define UH_LIMIT_CLIENTS       64
 
-#define __enum_header(_name) HDR_##_name,
-#define __blobmsg_header(_name) [HDR_##_name] = { .name = #_name, .type = BLOBMSG_TYPE_STRING },
+#define __enum_header(_name, _val) HDR_##_name,
+#define __blobmsg_header(_name, _val) [HDR_##_name] = { .name = #_val, .type = BLOBMSG_TYPE_STRING },
 
 struct client;
 
@@ -51,6 +55,8 @@ struct config {
        const char *cgi_path;
        const char *lua_handler;
        const char *lua_prefix;
+       const char *ubus_prefix;
+       const char *ubus_socket;
        int no_symlinks;
        int no_dirlists;
        int network_timeout;
@@ -151,6 +157,27 @@ struct dispatch_handler {
        void (*handle_request)(struct client *cl, char *url, struct path_info *pi);
 };
 
+#ifdef HAVE_UBUS
+struct dispatch_ubus {
+       struct ubus_request req;
+
+       struct uloop_timeout timeout;
+       struct json_tokener *jstok;
+       struct json_object *jsobj;
+       struct json_object *jsobj_cur;
+       int post_len;
+
+       const char *sid;
+       uint32_t obj;
+       const char *func;
+
+       struct blob_buf buf;
+       bool req_pending;
+       bool array;
+       int array_idx;
+};
+#endif
+
 struct dispatch {
        int (*data_send)(struct client *cl, const char *data, int len);
        void (*data_done)(struct client *cl);
@@ -165,6 +192,9 @@ struct dispatch {
                        int fd;
                } file;
                struct dispatch_proc proc;
+#ifdef HAVE_UBUS
+               struct dispatch_ubus ubus;
+#endif
        };
 };
 
@@ -241,5 +271,6 @@ bool uh_create_process(struct client *cl, struct path_info *pi, char *url,
                       void (*cb)(struct client *cl, struct path_info *pi, char *url));
 
 int uh_plugin_init(const char *name);
+void uh_plugin_post_init(void);
 
 #endif