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>
34 #define UH_LIMIT_CLIENTS 64
35 #define UH_LIMIT_HEADERS 64
36 #define UH_LIMIT_MSGHEAD 4096
39 char docroot
[PATH_MAX
];
53 struct list_head list
;
72 enum http_method method
;
73 enum http_version version
;
76 struct auth_realm
*realm
;
79 struct http_response
{
82 char *headers
[UH_LIMIT_HEADERS
];
94 struct list_head list
;
98 struct ustream_fd sfd
;
100 struct ustream_ssl stream_ssl
;
102 struct uloop_fd rpipe
;
103 struct uloop_fd wpipe
;
104 struct uloop_process proc
;
105 struct uloop_timeout timeout
;
106 bool (*cb
)(struct client
*);
109 enum client_state state
;
111 struct http_request request
;
112 struct http_response response
;
113 struct sockaddr_in6 servaddr
;
114 struct sockaddr_in6 peeraddr
;
118 void (*dispatch_write_cb
)(struct client
*cl
);
119 void (*dispatch_free
)(struct client
*cl
);
123 struct blob_attr
**hdr
;
129 extern int n_clients
;
130 extern struct config conf
;
132 void uh_index_add(const char *filename
);
134 void uh_accept_client(int fd
);
136 void uh_unblock_listeners(void);
137 void uh_setup_listeners(void);
138 int uh_socket_bind(const char *host
, const char *port
, bool tls
);
140 bool uh_use_chunked(struct client
*cl
);
141 void uh_chunk_write(struct client
*cl
, const void *data
, int len
);
142 void uh_chunk_vprintf(struct client
*cl
, const char *format
, va_list arg
);
145 uh_chunk_printf(struct client
*cl
, const char *format
, ...);
147 void uh_chunk_eof(struct client
*cl
);
148 void uh_request_done(struct client
*cl
);
150 void uh_http_header(struct client
*cl
, int code
, const char *summary
);
152 uh_client_error(struct client
*cl
, int code
, const char *summary
, const char *fmt
, ...);
154 void uh_handle_file_request(struct client
*cl
);
156 void uh_auth_add(const char *path
, const char *user
, const char *pass
);