aa9186782d46b37ed1c669a25a83dd0c1e7cc2e9
[project/luci.git] / contrib / package / uhttpd / src / uhttpd.h
1 /*
2  * uhttpd - Tiny non-forking 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 #ifdef HAVE_TLS
36 #include <openssl/ssl.h>
37 #endif
38
39
40 #define UH_LIMIT_MSGHEAD        4096
41 #define UH_LIMIT_HEADERS        64
42
43 #define UH_LIMIT_LISTENERS      16
44 #define UH_LIMIT_CLIENTS        64
45
46 #define UH_HTTP_MSG_GET         0
47 #define UH_HTTP_MSG_HEAD        1
48 #define UH_HTTP_MSG_POST        2
49
50
51 struct config {
52         char docroot[PATH_MAX];
53 #ifdef HAVE_CGI
54         char *cgi_prefix;
55 #endif
56 #ifdef HAVE_LUA
57         char *lua_prefix;
58         char *lua_handler;
59 #endif
60 #ifdef HAVE_TLS
61         char *cert;
62         char *key;
63         SSL_CTX *tls;
64 #endif
65 };
66
67 struct listener {
68         int socket;
69         struct sockaddr_in6 addr;
70         struct config *conf;
71 #ifdef HAVE_TLS
72         SSL_CTX *tls;
73 #endif
74 };
75
76 struct client {
77         int socket;
78         int peeklen;
79         char peekbuf[UH_LIMIT_MSGHEAD];
80         struct listener *server;
81         struct sockaddr_in6 servaddr;
82         struct sockaddr_in6 peeraddr;
83 #ifdef HAVE_TLS
84         SSL *tls;
85 #endif
86 };
87
88 struct http_request {
89         int     method;
90         float version;
91         char *url;
92         char *headers[UH_LIMIT_HEADERS];
93 };
94
95 struct http_response {
96         int statuscode;
97         char *statusmsg;
98         char *headers[UH_LIMIT_HEADERS];
99 };
100
101 #endif
102