eca3580b86343effc434f3e54a381bf5baf60d4f
[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 #define UH_LIMIT_AUTHREALMS     8
46
47 #define UH_HTTP_MSG_GET         0
48 #define UH_HTTP_MSG_HEAD        1
49 #define UH_HTTP_MSG_POST        2
50
51
52 struct config {
53         char docroot[PATH_MAX];
54         char *realm;
55         char *file;
56 #ifdef HAVE_CGI
57         char *cgi_prefix;
58 #endif
59 #ifdef HAVE_LUA
60         char *lua_prefix;
61         char *lua_handler;
62 #endif
63 #ifdef HAVE_TLS
64         char *cert;
65         char *key;
66         SSL_CTX *tls;
67 #endif
68 };
69
70 struct listener {
71         int socket;
72         struct sockaddr_in6 addr;
73         struct config *conf;
74 #ifdef HAVE_TLS
75         SSL_CTX *tls;
76 #endif
77 };
78
79 struct client {
80         int socket;
81         int peeklen;
82         char peekbuf[UH_LIMIT_MSGHEAD];
83         struct listener *server;
84         struct sockaddr_in6 servaddr;
85         struct sockaddr_in6 peeraddr;
86 #ifdef HAVE_TLS
87         SSL *tls;
88 #endif
89 };
90
91 struct auth_realm {
92         char path[PATH_MAX];
93         char user[32];
94         char pass[128];
95 };
96
97 struct http_request {
98         int     method;
99         float version;
100         char *url;
101         char *headers[UH_LIMIT_HEADERS];
102         struct auth_realm *realm;
103 };
104
105 struct http_response {
106         int statuscode;
107         char *statusmsg;
108         char *headers[UH_LIMIT_HEADERS];
109 };
110
111 #endif
112