2 * uhttpd - Tiny single-threaded httpd - Main header
4 * Copyright (C) 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
5 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <netinet/in.h>
27 #include <libubox/list.h>
28 #include <libubox/uloop.h>
29 #include <libubox/ustream.h>
30 #include <libubox/blob.h>
31 #include <libubox/utils.h>
35 #define UH_LIMIT_CLIENTS 64
36 #define UH_LIMIT_HEADERS 64
42 const char *error_handler;
43 const char *cgi_prefix;
66 struct list_head list;
85 enum http_method method;
86 enum http_version version;
89 const struct auth_realm *realm;
92 struct http_response {
95 char *headers[UH_LIMIT_HEADERS];
107 struct list_head list;
111 struct ustream_fd sfd;
113 struct ustream_ssl stream_ssl;
115 struct uloop_timeout timeout;
117 enum client_state state;
119 struct http_request request;
120 struct http_response response;
121 struct sockaddr_in6 servaddr;
122 struct sockaddr_in6 peeraddr;
127 void (*write_cb)(struct client *cl);
128 void (*close_fds)(struct client *cl);
129 void (*free)(struct client *cl);
132 struct blob_attr **hdr;
139 extern char uh_buf[4096];
140 extern int n_clients;
141 extern struct config conf;
142 extern const char * const http_versions[];
143 extern const char * const http_methods[];
145 void uh_index_add(const char *filename);
147 void uh_accept_client(int fd);
149 void uh_unblock_listeners(void);
150 void uh_setup_listeners(void);
151 int uh_socket_bind(const char *host, const char *port, bool tls);
153 bool uh_use_chunked(struct client *cl);
154 void uh_chunk_write(struct client *cl, const void *data, int len);
155 void uh_chunk_vprintf(struct client *cl, const char *format, va_list arg);
158 uh_chunk_printf(struct client *cl, const char *format, ...);
160 void uh_chunk_eof(struct client *cl);
161 void uh_request_done(struct client *cl);
163 void uh_http_header(struct client *cl, int code, const char *summary);
165 uh_client_error(struct client *cl, int code, const char *summary, const char *fmt, ...);
167 void uh_handle_file_request(struct client *cl);
169 void uh_auth_add(const char *path, const char *user, const char *pass);
171 void uh_close_listen_fds(void);
172 void uh_close_fds(void);