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

Archive Download this file



interactive