simple webserver (PoC)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1010 B

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "configfile.h"
#include "event.h"
#include "http.h"
#include "logging.h"
#include "sockaddr.h"
#include "tcpsocket.h"
static int listen_init(const char *value, void *privdata)
struct sockaddr_in addr;
if (parse_sockaddr(value, &addr) == -1) {
log_print(LOG_WARN, "invalid listen addr: '%s'", value);
return -1;
int sock = tcp_listen(&addr);
if (sock < 0)
return -1;
event_add_readfd(NULL, sock, http_listen_handler, NULL);
log_print(LOG_INFO, "listen on %s", get_sockaddr_buf(&addr));
return 0;
int main(int argc, char *argv[])
if (config_parse("simpleweb.conf") == -1)
return -1;
int cnt = config_get_strings("global", "listen", listen_init, NULL);
if (cnt <= 0) {
log_print(LOG_ERROR, "no listen sockets defined!");
return -1;
http_add_cb("/", 0, http_file_cb, (void *)"/tmp");
return 0;