applications/luci-samba: forgot to commit a change of #117
[project/luci.git] / contrib / package / uhttpd / src / uhttpd.h
1 /*
2  * uhttpd - Tiny single-threaded httpd - Main header
3  *
4  *   Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #ifndef _UHTTPD_
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <signal.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <sys/select.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <linux/limits.h>
32 #include <netdb.h>
33 #include <ctype.h>
34
35 #include <dlfcn.h>
36
37
38 #ifdef HAVE_LUA
39 #include <lua.h>
40 #endif
41
42 #ifdef HAVE_TLS
43 #include <openssl/ssl.h>
44 #endif
45
46
47 #define UH_LIMIT_MSGHEAD        4096
48 #define UH_LIMIT_HEADERS        64
49
50 #define UH_LIMIT_LISTENERS      16
51 #define UH_LIMIT_CLIENTS        64
52 #define UH_LIMIT_AUTHREALMS     8
53
54 #define UH_HTTP_MSG_GET         0
55 #define UH_HTTP_MSG_HEAD        1
56 #define UH_HTTP_MSG_POST        2
57
58 struct listener;
59 struct client;
60 struct http_request;
61
62 struct config {
63         char docroot[PATH_MAX];
64         char *realm;
65         char *file;
66 #ifdef HAVE_CGI
67         char *cgi_prefix;
68 #endif
69 #ifdef HAVE_LUA
70         char *lua_prefix;
71         char *lua_handler;
72         lua_State * (*lua_init) (const char *handler);
73         void (*lua_close) (lua_State *L);
74         void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
75 #endif
76 #ifdef HAVE_TLS
77         char *cert;
78         char *key;
79         SSL_CTX *tls;
80         SSL_CTX * (*tls_init) (void);
81         int (*tls_cert) (SSL_CTX *c, const char *file);
82         int (*tls_key) (SSL_CTX *c, const char *file);
83         void (*tls_free) (struct listener *l);
84         void (*tls_accept) (struct client *c);
85         void (*tls_close) (struct client *c);
86         int (*tls_recv) (struct client *c, void *buf, int len);
87         int (*tls_send) (struct client *c, void *buf, int len);
88 #endif
89 };
90
91 struct listener {
92         int socket;
93         struct sockaddr_in6 addr;
94         struct config *conf;
95 #ifdef HAVE_TLS
96         SSL_CTX *tls;
97 #endif
98 };
99
100 struct client {
101         int socket;
102         int peeklen;
103         char peekbuf[UH_LIMIT_MSGHEAD];
104         struct listener *server;
105         struct sockaddr_in6 servaddr;
106         struct sockaddr_in6 peeraddr;
107 #ifdef HAVE_TLS
108         SSL *tls;
109 #endif
110 };
111
112 struct auth_realm {
113         char path[PATH_MAX];
114         char user[32];
115         char pass[128];
116 };
117
118 struct http_request {
119         int     method;
120         float version;
121         char *url;
122         char *headers[UH_LIMIT_HEADERS];
123         struct auth_realm *realm;
124 };
125
126 struct http_response {
127         int statuscode;
128         char *statusmsg;
129         char *headers[UH_LIMIT_HEADERS];
130 };
131
132 #endif
133