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#ifdef HAVE_CGI
79    char *cgi_prefix;
80#endif
81#ifdef HAVE_LUA
82    char *lua_prefix;
83    char *lua_handler;
84    lua_State *lua_state;
85    lua_State * (*lua_init) (const char *handler);
86    void (*lua_close) (lua_State *L);
87    void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
88#endif
89#if defined(HAVE_CGI) || defined(HAVE_LUA)
90    int script_timeout;
91#endif
92#ifdef HAVE_TLS
93    char *cert;
94    char *key;
95    SSL_CTX *tls;
96    SSL_CTX * (*tls_init) (void);
97    int (*tls_cert) (SSL_CTX *c, const char *file);
98    int (*tls_key) (SSL_CTX *c, const char *file);
99    void (*tls_free) (struct listener *l);
100    void (*tls_accept) (struct client *c);
101    void (*tls_close) (struct client *c);
102    int (*tls_recv) (struct client *c, void *buf, int len);
103    int (*tls_send) (struct client *c, void *buf, int len);
104#endif
105};
106
107struct listener {
108    int socket;
109    struct sockaddr_in6 addr;
110    struct config *conf;
111#ifdef HAVE_TLS
112    SSL_CTX *tls;
113#endif
114    struct listener *next;
115};
116
117struct client {
118    int socket;
119    int peeklen;
120    char peekbuf[UH_LIMIT_MSGHEAD];
121    struct listener *server;
122    struct sockaddr_in6 servaddr;
123    struct sockaddr_in6 peeraddr;
124#ifdef HAVE_TLS
125    SSL *tls;
126#endif
127    struct client *next;
128};
129
130struct auth_realm {
131    char path[PATH_MAX];
132    char user[32];
133    char pass[128];
134    struct auth_realm *next;
135};
136
137struct http_request {
138    int method;
139    float version;
140    int redirect_status;
141    char *url;
142    char *headers[UH_LIMIT_HEADERS];
143    struct auth_realm *realm;
144};
145
146struct http_response {
147    int statuscode;
148    char *statusmsg;
149    char *headers[UH_LIMIT_HEADERS];
150};
151
152#ifdef HAVE_CGI
153struct interpreter {
154    char path[PATH_MAX];
155    char extn[32];
156    struct interpreter *next;
157};
158#endif
159
160#endif
161
162

Archive Download this file



interactive