2 * uhttpd - Tiny single-threaded httpd
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.
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
29 #include <libubox/usock.h>
34 static int run_server(void)
43 static void add_listener_arg(char *arg, bool tls)
49 s = strrchr(arg, ':');
55 uh_socket_bind(host, port, tls);
58 static int usage(const char *name)
60 fprintf(stderr, "Usage: %s -p <port>\n", name);
64 static void init_defaults(void)
66 conf.network_timeout = 30;
67 conf.http_keepalive = 0; /* fixme */
68 conf.max_requests = 3;
70 uh_index_add("index.html");
71 uh_index_add("index.htm");
72 uh_index_add("default.html");
73 uh_index_add("default.htm");
76 int main(int argc, char **argv)
81 signal(SIGPIPE, SIG_IGN);
83 while ((ch = getopt(argc, argv, "sp:h:")) != -1) {
89 add_listener_arg(optarg, tls);
94 if (!realpath(optarg, conf.docroot)) {
95 fprintf(stderr, "Error: Invalid directory %s: %s\n",
96 optarg, strerror(errno));
101 return usage(argv[0]);