[package] uhttpd:
[openwrt/svn-archive/archive.git] / 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 <sys/wait.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <linux/limits.h>
33 #include <netdb.h>
34 #include <ctype.h>
35 #include <errno.h>
36 #include <dlfcn.h>
37
38
39 #ifdef HAVE_LUA
40 #include <lua.h>
41 #endif
42
43 #ifdef HAVE_TLS
44 #include <openssl/ssl.h>
45 #endif
46
47
48 #define UH_LIMIT_MSGHEAD 4096
49 #define UH_LIMIT_HEADERS 64
50
51 #define UH_LIMIT_CLIENTS 64
52
53 #define UH_HTTP_MSG_GET 0
54 #define UH_HTTP_MSG_HEAD 1
55 #define UH_HTTP_MSG_POST 2
56
57 struct listener;
58 struct client;
59 struct interpreter;
60 struct http_request;
61
62 struct config {
63 char docroot[PATH_MAX];
64 char *realm;
65 char *file;
66 char *index_file;
67 char *error_handler;
68 int no_symlinks;
69 int no_dirlists;
70 int network_timeout;
71 int rfc1918_filter;
72 #ifdef HAVE_CGI
73 char *cgi_prefix;
74 #endif
75 #ifdef HAVE_LUA
76 char *lua_prefix;
77 char *lua_handler;
78 lua_State *lua_state;
79 lua_State * (*lua_init) (const char *handler);
80 void (*lua_close) (lua_State *L);
81 void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
82 #endif
83 #if defined(HAVE_CGI) || defined(HAVE_LUA)
84 int script_timeout;
85 #endif
86 #ifdef HAVE_TLS
87 char *cert;
88 char *key;
89 SSL_CTX *tls;
90 SSL_CTX * (*tls_init) (void);
91 int (*tls_cert) (SSL_CTX *c, const char *file);
92 int (*tls_key) (SSL_CTX *c, const char *file);
93 void (*tls_free) (struct listener *l);
94 void (*tls_accept) (struct client *c);
95 void (*tls_close) (struct client *c);
96 int (*tls_recv) (struct client *c, void *buf, int len);
97 int (*tls_send) (struct client *c, void *buf, int len);
98 #endif
99 };
100
101 struct listener {
102 int socket;
103 struct sockaddr_in6 addr;
104 struct config *conf;
105 #ifdef HAVE_TLS
106 SSL_CTX *tls;
107 #endif
108 struct listener *next;
109 };
110
111 struct client {
112 int socket;
113 int peeklen;
114 char peekbuf[UH_LIMIT_MSGHEAD];
115 struct listener *server;
116 struct sockaddr_in6 servaddr;
117 struct sockaddr_in6 peeraddr;
118 #ifdef HAVE_TLS
119 SSL *tls;
120 #endif
121 struct client *next;
122 };
123
124 struct auth_realm {
125 char path[PATH_MAX];
126 char user[32];
127 char pass[128];
128 struct auth_realm *next;
129 };
130
131 struct http_request {
132 int method;
133 float version;
134 int redirect_status;
135 char *url;
136 char *headers[UH_LIMIT_HEADERS];
137 struct auth_realm *realm;
138 };
139
140 struct http_response {
141 int statuscode;
142 char *statusmsg;
143 char *headers[UH_LIMIT_HEADERS];
144 };
145
146 #ifdef HAVE_CGI
147 struct interpreter {
148 char path[PATH_MAX];
149 char extn[32];
150 struct interpreter *next;
151 };
152 #endif
153
154 #endif
155