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
66 #define UH_LIMIT_CLIENTS 64
76 char docroot
[PATH_MAX
];
94 lua_State
* (*lua_init
) (const struct config
*conf
);
95 void (*lua_close
) (lua_State
*L
);
96 bool (*lua_request
) (struct client
*cl
, lua_State
*L
);
102 struct uh_ubus_state
* (*ubus_init
) (const struct config
*conf
);
103 void (*ubus_close
) (struct uh_ubus_state
*state
);
104 bool (*ubus_request
) (struct client
*cl
, struct uh_ubus_state
*state
);
106 #if defined(HAVE_CGI) || defined(HAVE_LUA) || defined(HAVE_UBUS)
113 SSL_CTX
* (*tls_init
) (void);
114 int (*tls_cert
) (SSL_CTX
*c
, const char *file
);
115 int (*tls_key
) (SSL_CTX
*c
, const char *file
);
116 void (*tls_free
) (struct listener
*l
);
117 int (*tls_accept
) (struct client
*c
);
118 void (*tls_close
) (struct client
*c
);
119 int (*tls_recv
) (struct client
*c
, char *buf
, int len
);
120 int (*tls_send
) (struct client
*c
, const char *buf
, int len
);
130 extern const char *http_methods
[];
138 extern const char *http_versions
[];
140 struct http_request
{
141 enum http_method method
;
142 enum http_version version
;
145 char *headers
[UH_LIMIT_HEADERS
];
146 struct auth_realm
*realm
;
149 struct http_response
{
152 char *headers
[UH_LIMIT_HEADERS
];
159 struct sockaddr_in6 addr
;
164 struct listener
*next
;
172 struct uloop_fd rpipe
;
173 struct uloop_fd wpipe
;
174 struct uloop_process proc
;
175 struct uloop_timeout timeout
;
176 bool (*cb
)(struct client
*);
180 char buf
[UH_LIMIT_MSGHEAD
];
184 struct listener
*server
;
185 struct http_request request
;
186 struct http_response response
;
187 struct sockaddr_in6 servaddr
;
188 struct sockaddr_in6 peeraddr
;
192 struct client_light
{
203 struct auth_realm
*next
;
210 struct interpreter
*next
;