1 |
#include "freehttpd.h" |
#include "freehttpd.h" |
2 |
#include <errno.h> |
#include <errno.h> |
3 |
#include <getopt.h> |
#include <getopt.h> |
4 |
|
#include <magic.h> |
5 |
#include <stdbool.h> |
#include <stdbool.h> |
6 |
#include <stdio.h> |
#include <stdio.h> |
7 |
#include <stdlib.h> |
#include <stdlib.h> |
90 |
if (!validate_settings ()) |
if (!validate_settings ()) |
91 |
exit (EXIT_FAILURE); |
exit (EXIT_FAILURE); |
92 |
|
|
93 |
freehttpd_t *freehttpd = freehttpd_init (); |
magic_t magic = magic_open (MAGIC_MIME); |
94 |
unsigned int port = 8080; |
unsigned int port = 8080; |
95 |
size_t uri_len = 1024; |
size_t uri_len = 1024; |
96 |
ecode_t code = E_OK; |
ecode_t code = E_OK; |
97 |
|
|
98 |
|
if (magic == NULL) |
99 |
|
{ |
100 |
|
fprintf (stderr, "%s: failed to initialize magic\n", |
101 |
|
config.progname); |
102 |
|
exit (EXIT_FAILURE); |
103 |
|
} |
104 |
|
|
105 |
|
if (magic_load (magic, NULL) != 0) |
106 |
|
{ |
107 |
|
fprintf (stderr, "%s: failed to load magic database\n", |
108 |
|
config.progname); |
109 |
|
magic_close (magic); |
110 |
|
exit (EXIT_FAILURE); |
111 |
|
} |
112 |
|
|
113 |
|
freehttpd_t *freehttpd = freehttpd_init (magic); |
114 |
|
|
115 |
code = freehttpd_setopt (freehttpd, FREEHTTPD_CONFIG_PORT, &port); |
code = freehttpd_setopt (freehttpd, FREEHTTPD_CONFIG_PORT, &port); |
116 |
|
|
117 |
if (code != E_OK) |
if (code != E_OK) |
127 |
if (code != E_OK) |
if (code != E_OK) |
128 |
goto error; |
goto error; |
129 |
|
|
130 |
|
char *docroot = getenv ("FREEHTTPD_DOCROOT"); |
131 |
|
code = freehttpd_setopt (freehttpd, FREEHTTPD_CONFIG_DOCROOT, |
132 |
|
docroot ? docroot : "/var/www"); |
133 |
|
|
134 |
|
if (code != E_OK) |
135 |
|
goto error; |
136 |
|
|
137 |
code = freehttpd_start (freehttpd); |
code = freehttpd_start (freehttpd); |
138 |
|
|
139 |
if (code != E_OK) |
if (code != E_OK) |
146 |
} |
} |
147 |
|
|
148 |
freehttpd_free (freehttpd); |
freehttpd_free (freehttpd); |
149 |
|
magic_close (magic); |
150 |
return 0; |
return 0; |
151 |
} |
} |