2 * uhttpd - Tiny single-threaded httpd - Main header
4 * Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <sys/select.h>
31 #include <netinet/in.h>
32 #include <netinet/tcp.h>
33 #include <arpa/inet.h>
34 #include <linux/limits.h>
40 #include <libubox/list.h>
41 #include <libubox/uloop.h>
49 #include <openssl/ssl.h>
58 #define D(...) fprintf(stderr, __VA_ARGS__)
64 #define UH_LIMIT_MSGHEAD 4096
65 #define UH_LIMIT_HEADERS 64
67 #define UH_LIMIT_CLIENTS 64
69 #define UH_HTTP_MSG_GET 0
70 #define UH_HTTP_MSG_HEAD 1
71 #define UH_HTTP_MSG_POST 2
73 #define UH_SOCK_CLIENT 0
74 #define UH_SOCK_SERVER 1
83 char docroot[PATH_MAX];
100 lua_State *lua_state;
101 lua_State * (*lua_init) (const struct config *conf);
102 void (*lua_close) (lua_State *L);
103 bool (*lua_request) (struct client *cl, lua_State *L);
109 struct uh_ubus_state * (*ubus_init) (const struct config *conf);
110 void (*ubus_close) (struct uh_ubus_state *state);
111 bool (*ubus_request) (struct client *cl, struct uh_ubus_state *state);
113 #if defined(HAVE_CGI) || defined(HAVE_LUA) || defined(HAVE_UBUS)
120 SSL_CTX * (*tls_init) (void);
121 int (*tls_cert) (SSL_CTX *c, const char *file);
122 int (*tls_key) (SSL_CTX *c, const char *file);
123 void (*tls_free) (struct listener *l);
124 int (*tls_accept) (struct client *c);
125 void (*tls_close) (struct client *c);
126 int (*tls_recv) (struct client *c, char *buf, int len);
127 int (*tls_send) (struct client *c, const char *buf, int len);
131 struct http_request {
136 char *headers[UH_LIMIT_HEADERS];
137 struct auth_realm *realm;
140 struct http_response {
143 char *headers[UH_LIMIT_HEADERS];
150 struct sockaddr_in6 addr;
155 struct listener *next;
163 struct uloop_process proc;
164 struct uloop_timeout timeout;
165 bool (*cb)(struct client *);
170 char buf[UH_LIMIT_MSGHEAD];
174 struct listener *server;
175 struct http_request request;
176 struct http_response response;
177 struct sockaddr_in6 servaddr;
178 struct sockaddr_in6 peeraddr;
182 struct client_light {
193 struct auth_realm *next;
200 struct interpreter *next;