2010-03-25 15:46:16 +00:00
|
|
|
/*
|
|
|
|
* uhttpd - Tiny single-threaded httpd - Main header
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _UHTTPD_
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/select.h>
|
2010-03-27 00:00:33 +00:00
|
|
|
#include <sys/wait.h>
|
2010-03-25 15:46:16 +00:00
|
|
|
#include <netinet/in.h>
|
2010-08-18 00:04:52 +00:00
|
|
|
#include <netinet/tcp.h>
|
2010-03-25 15:46:16 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <linux/limits.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <ctype.h>
|
2010-04-15 19:46:35 +00:00
|
|
|
#include <errno.h>
|
2010-03-25 15:46:16 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
#include <lua.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#endif
|
|
|
|
|
2010-08-18 00:04:52 +00:00
|
|
|
/* uClibc... */
|
|
|
|
#ifndef SOL_TCP
|
|
|
|
#define SOL_TCP 6
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 15:46:16 +00:00
|
|
|
|
|
|
|
#define UH_LIMIT_MSGHEAD 4096
|
|
|
|
#define UH_LIMIT_HEADERS 64
|
|
|
|
|
|
|
|
#define UH_LIMIT_CLIENTS 64
|
|
|
|
|
|
|
|
#define UH_HTTP_MSG_GET 0
|
|
|
|
#define UH_HTTP_MSG_HEAD 1
|
|
|
|
#define UH_HTTP_MSG_POST 2
|
|
|
|
|
|
|
|
struct listener;
|
|
|
|
struct client;
|
2010-08-14 00:54:24 +00:00
|
|
|
struct interpreter;
|
2010-03-25 15:46:16 +00:00
|
|
|
struct http_request;
|
|
|
|
|
|
|
|
struct config {
|
|
|
|
char docroot[PATH_MAX];
|
|
|
|
char *realm;
|
|
|
|
char *file;
|
2010-07-23 13:15:22 +00:00
|
|
|
char *index_file;
|
|
|
|
char *error_handler;
|
2010-04-15 19:46:35 +00:00
|
|
|
int no_symlinks;
|
2010-07-23 13:15:22 +00:00
|
|
|
int no_dirlists;
|
2010-04-15 19:46:35 +00:00
|
|
|
int network_timeout;
|
2010-08-11 00:05:34 +00:00
|
|
|
int rfc1918_filter;
|
2011-01-09 23:35:45 +00:00
|
|
|
int tcp_keepalive;
|
2010-03-25 15:46:16 +00:00
|
|
|
#ifdef HAVE_CGI
|
|
|
|
char *cgi_prefix;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
char *lua_prefix;
|
|
|
|
char *lua_handler;
|
2010-08-14 00:54:24 +00:00
|
|
|
lua_State *lua_state;
|
2010-03-25 15:46:16 +00:00
|
|
|
lua_State * (*lua_init) (const char *handler);
|
|
|
|
void (*lua_close) (lua_State *L);
|
|
|
|
void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
|
|
|
|
#endif
|
2010-03-27 00:00:33 +00:00
|
|
|
#if defined(HAVE_CGI) || defined(HAVE_LUA)
|
|
|
|
int script_timeout;
|
|
|
|
#endif
|
2010-03-25 15:46:16 +00:00
|
|
|
#ifdef HAVE_TLS
|
|
|
|
char *cert;
|
|
|
|
char *key;
|
|
|
|
SSL_CTX *tls;
|
|
|
|
SSL_CTX * (*tls_init) (void);
|
|
|
|
int (*tls_cert) (SSL_CTX *c, const char *file);
|
|
|
|
int (*tls_key) (SSL_CTX *c, const char *file);
|
|
|
|
void (*tls_free) (struct listener *l);
|
|
|
|
void (*tls_accept) (struct client *c);
|
|
|
|
void (*tls_close) (struct client *c);
|
|
|
|
int (*tls_recv) (struct client *c, void *buf, int len);
|
|
|
|
int (*tls_send) (struct client *c, void *buf, int len);
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct listener {
|
|
|
|
int socket;
|
|
|
|
struct sockaddr_in6 addr;
|
|
|
|
struct config *conf;
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
SSL_CTX *tls;
|
|
|
|
#endif
|
2010-08-14 00:54:24 +00:00
|
|
|
struct listener *next;
|
2010-03-25 15:46:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct client {
|
|
|
|
int socket;
|
|
|
|
int peeklen;
|
|
|
|
char peekbuf[UH_LIMIT_MSGHEAD];
|
|
|
|
struct listener *server;
|
|
|
|
struct sockaddr_in6 servaddr;
|
|
|
|
struct sockaddr_in6 peeraddr;
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
SSL *tls;
|
|
|
|
#endif
|
2010-08-14 00:54:24 +00:00
|
|
|
struct client *next;
|
2010-03-25 15:46:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct auth_realm {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char user[32];
|
|
|
|
char pass[128];
|
2010-08-14 00:54:24 +00:00
|
|
|
struct auth_realm *next;
|
2010-03-25 15:46:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct http_request {
|
|
|
|
int method;
|
|
|
|
float version;
|
2010-07-23 13:15:22 +00:00
|
|
|
int redirect_status;
|
2010-03-25 15:46:16 +00:00
|
|
|
char *url;
|
|
|
|
char *headers[UH_LIMIT_HEADERS];
|
|
|
|
struct auth_realm *realm;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct http_response {
|
|
|
|
int statuscode;
|
|
|
|
char *statusmsg;
|
|
|
|
char *headers[UH_LIMIT_HEADERS];
|
|
|
|
};
|
|
|
|
|
2010-08-14 00:54:24 +00:00
|
|
|
#ifdef HAVE_CGI
|
|
|
|
struct interpreter {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char extn[32];
|
|
|
|
struct interpreter *next;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 15:46:16 +00:00
|
|
|
#endif
|
|
|
|
|