Remove internal webserver code entirely.

This commit is contained in:
Oliver Jowett 2016-12-29 18:35:35 +00:00
parent 64fd61cffc
commit 52464b97c1
5 changed files with 0 additions and 240 deletions

View file

@ -136,9 +136,6 @@ void modesInitConfig(void) {
Modes.net_output_sbs_ports = strdup("30003");
Modes.net_input_beast_ports = strdup("30004,30104");
Modes.net_output_beast_ports = strdup("30005");
#ifdef ENABLE_WEBSERVER
Modes.net_http_ports = strdup("8080");
#endif
Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
Modes.html_dir = HTMLPATH;
Modes.json_interval = 1000;
@ -670,9 +667,6 @@ void showHelp(void) {
"--no-modeac-auto Don't enable Mode A/C if requested by a Beast connection\n"
"--net-only Enable just networking, no RTL device or file used\n"
"--net-bind-address <ip> IP address to bind to (default: Any; Use 127.0.0.1 for private)\n"
#ifdef ENABLE_WEBSERVER
"--net-http-port <ports> HTTP server ports (default: 8080)\n"
#endif
"--net-ri-port <ports> TCP raw input listen ports (default: 30001)\n"
"--net-ro-port <ports> TCP raw output listen ports (default: 30002)\n"
"--net-sbs-port <ports> TCP BaseStation output listen ports (default: 30003)\n"
@ -988,14 +982,9 @@ int main(int argc, char **argv) {
free(Modes.net_bind_address);
Modes.net_bind_address = strdup(argv[++j]);
} else if (!strcmp(argv[j],"--net-http-port") && more) {
#ifdef ENABLE_WEBSERVER
free(Modes.net_http_ports);
Modes.net_http_ports = strdup(argv[++j]);
#else
if (strcmp(argv[++j], "0")) {
fprintf(stderr, "warning: --net-http-port not supported in this build, option ignored.\n");
}
#endif
} else if (!strcmp(argv[j],"--net-sbs-port") && more) {
free(Modes.net_output_sbs_ports);
Modes.net_output_sbs_ports = strdup(argv[++j]);

View file

@ -325,9 +325,6 @@ struct { // Internal state
char *net_output_sbs_ports; // List of SBS output TCP ports
char *net_input_beast_ports; // List of Beast input TCP ports
char *net_output_beast_ports; // List of Beast output TCP ports
#ifdef ENABLE_WEBSERVER
char *net_http_ports; // List of HTTP ports
#endif
char *net_bind_address; // Bind address
int net_sndbuf_size; // TCP output buffer size (64Kb * 2^n)
int net_verbatim; // if true, send the original message, not the CRC-corrected one

211
net_io.c
View file

@ -70,9 +70,6 @@
static int handleBeastCommand(struct client *c, char *p);
static int decodeBinMessage(struct client *c, char *p);
static int decodeHexMessage(struct client *c, char *hex);
#ifdef ENABLE_WEBSERVER
static int handleHTTPRequest(struct client *c, char *p);
#endif
static void send_raw_heartbeat(struct net_service *service);
static void send_beast_heartbeat(struct net_service *service);
@ -267,11 +264,6 @@ void modesInitNet(void) {
s = makeBeastInputService();
serviceListen(s, Modes.net_bind_address, Modes.net_input_beast_ports);
#ifdef ENABLE_WEBSERVER
s = serviceInit("HTTP server", NULL, NULL, READ_MODE_ASCII, "\r\n\r\n", handleHTTPRequest);
serviceListen(s, Modes.net_bind_address, Modes.net_http_ports);
#endif
}
//
//=========================================================================
@ -1279,10 +1271,6 @@ static char * appendStatsJson(char *p,
}
p += snprintf(p, end-p, "]}");
#ifdef ENABLE_WEBSERVER
p += snprintf(p, end-p, ",\"http_requests\":%u", st->http_requests);
#endif
}
{
@ -1474,205 +1462,6 @@ void writeJsonToFile(const char *file, char * (*generator) (const char *,int*))
}
#ifdef ENABLE_WEBSERVER
//
//=========================================================================
//
#define MODES_CONTENT_TYPE_HTML "text/html;charset=utf-8"
#define MODES_CONTENT_TYPE_CSS "text/css;charset=utf-8"
#define MODES_CONTENT_TYPE_JSON "application/json;charset=utf-8"
#define MODES_CONTENT_TYPE_JS "application/javascript;charset=utf-8"
#define MODES_CONTENT_TYPE_GIF "image/gif"
static struct {
char *path;
char * (*handler)(const char*,int*);
char *content_type;
int prefix;
} url_handlers[] = {
{ "/data/aircraft.json", generateAircraftJson, MODES_CONTENT_TYPE_JSON, 0 },
{ "/data/receiver.json", generateReceiverJson, MODES_CONTENT_TYPE_JSON, 0 },
{ "/data/stats.json", generateStatsJson, MODES_CONTENT_TYPE_JSON, 0 },
{ "/data/history_", generateHistoryJson, MODES_CONTENT_TYPE_JSON, 1 },
{ NULL, NULL, NULL, 0 }
};
//
// Get an HTTP request header and write the response to the client.
// gain here we assume that the socket buffer is enough without doing
// any kind of userspace buffering.
//
// Returns 1 on error to signal the caller the client connection should
// be closed.
//
static int handleHTTPRequest(struct client *c, char *p) {
char hdr[512];
int clen, hdrlen;
int httpver, keepalive;
int statuscode = 500;
const char *statusmsg = "Internal Server Error";
char *url, *content = NULL;
char *ext;
char *content_type = NULL;
int i;
if (Modes.debug & MODES_DEBUG_NET)
printf("\nHTTP request: %s\n", c->buf);
// Minimally parse the request.
httpver = (strstr(p, "HTTP/1.1") != NULL) ? 11 : 10;
if (httpver == 10) {
// HTTP 1.0 defaults to close, unless otherwise specified.
//keepalive = strstr(p, "Connection: keep-alive") != NULL;
} else if (httpver == 11) {
// HTTP 1.1 defaults to keep-alive, unless close is specified.
//keepalive = strstr(p, "Connection: close") == NULL;
}
keepalive = 0;
// Identify he URL.
p = strchr(p,' ');
if (!p) return 1; // There should be the method and a space
url = ++p; // Now this should point to the requested URL
p = strchr(p, ' ');
if (!p) return 1; // There should be a space before HTTP/
*p = '\0';
if (Modes.debug & MODES_DEBUG_NET) {
printf("\nHTTP keep alive: %d\n", keepalive);
printf("HTTP requested URL: %s\n\n", url);
}
// Ditch any trailing query part (AJAX might add one to avoid caching)
p = strchr(url, '?');
if (p) *p = 0;
statuscode = 404;
statusmsg = "Not Found";
for (i = 0; url_handlers[i].path; ++i) {
if ((url_handlers[i].prefix && !strncmp(url, url_handlers[i].path, strlen(url_handlers[i].path))) ||
(!url_handlers[i].prefix && !strcmp(url, url_handlers[i].path))) {
content_type = url_handlers[i].content_type;
content = url_handlers[i].handler(url, &clen);
if (!content)
continue;
statuscode = 200;
statusmsg = "OK";
if (Modes.debug & MODES_DEBUG_NET) {
printf("HTTP: 200: %s -> internal (%d bytes, %s)\n", url, clen, content_type);
}
break;
}
}
if (!content) {
struct stat sbuf;
int fd = -1;
char rp[PATH_MAX], hrp[PATH_MAX];
char getFile[1024];
if (strlen(url) < 2) {
snprintf(getFile, sizeof getFile, "%s/gmap.html", Modes.html_dir); // Default file
} else {
snprintf(getFile, sizeof getFile, "%s/%s", Modes.html_dir, url);
}
if (!realpath(getFile, rp))
rp[0] = 0;
if (!realpath(Modes.html_dir, hrp))
strcpy(hrp, Modes.html_dir);
clen = -1;
content = strdup("Server error occured");
if (!strncmp(hrp, rp, strlen(hrp))) {
if (stat(getFile, &sbuf) != -1 && (fd = open(getFile, O_RDONLY)) != -1) {
content = (char *) realloc(content, sbuf.st_size);
if (read(fd, content, sbuf.st_size) == sbuf.st_size) {
clen = sbuf.st_size;
statuscode = 200;
statusmsg = "OK";
}
}
} else {
errno = ENOENT;
}
if (clen < 0) {
content = realloc(content, 128);
clen = snprintf(content, 128, "Error opening HTML file: %s", strerror(errno));
statuscode = 404;
statusmsg = "Not Found";
}
if (fd != -1) {
close(fd);
}
// Get file extension and content type
content_type = MODES_CONTENT_TYPE_HTML; // Default content type
ext = strrchr(getFile, '.');
if (ext) {
if (!strcmp(ext, ".json")) {
content_type = MODES_CONTENT_TYPE_JSON;
} else if (!strcmp(ext, ".css")) {
content_type = MODES_CONTENT_TYPE_CSS;
} else if (!strcmp(ext, ".js")) {
content_type = MODES_CONTENT_TYPE_JS;
} else if (!strcmp(ext, ".gif")) {
content_type = MODES_CONTENT_TYPE_GIF;
}
}
if (Modes.debug & MODES_DEBUG_NET) {
printf("HTTP: %d %s: %s -> %s (%d bytes, %s)\n", statuscode, statusmsg, url, rp, clen, content_type);
}
}
// Create the header and send the reply
hdrlen = snprintf(hdr, sizeof(hdr),
"HTTP/1.1 %d %s\r\n"
"Server: Dump1090\r\n"
"Content-Type: %s\r\n"
"Connection: %s\r\n"
"Content-Length: %d\r\n"
"Cache-Control: no-cache, must-revalidate\r\n"
"Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
"\r\n",
statuscode, statusmsg,
content_type,
keepalive ? "keep-alive" : "close",
clen);
if (Modes.debug & MODES_DEBUG_NET) {
printf("HTTP Reply header:\n%s", hdr);
}
/* hack hack hack. try to deal with large content */
anetSetSendBuffer(Modes.aneterr, c->fd, clen + hdrlen);
// Send header and content.
#ifndef _WIN32
if ( (write(c->fd, hdr, hdrlen) != hdrlen)
|| (write(c->fd, content, clen) != clen) )
#else
if ( (send(c->fd, hdr, hdrlen, 0) != hdrlen)
|| (send(c->fd, content, clen, 0) != clen) )
#endif
{
free(content);
return 1;
}
free(content);
Modes.stats_current.http_requests++;
return !keepalive;
}
#endif
//
//=========================================================================
//

10
stats.c
View file

@ -155,11 +155,6 @@ void display_stats(struct stats *st) {
printf("%u unique aircraft tracks\n", st->unique_aircraft);
printf("%u aircraft tracks where only one message was seen\n", st->single_message_aircraft);
#ifdef ENABLE_WEBSERVER
if (Modes.net)
printf("%d HTTP requests\n", st->http_requests);
#endif
{
uint64_t demod_cpu_millis = (uint64_t)st->demod_cpu.tv_sec*1000UL + st->demod_cpu.tv_nsec/1000000UL;
uint64_t reader_cpu_millis = (uint64_t)st->reader_cpu.tv_sec*1000UL + st->reader_cpu.tv_nsec/1000000UL;
@ -309,11 +304,6 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t
// total messages:
target->messages_total = st1->messages_total + st2->messages_total;
#ifdef ENABLE_WEBSERVER
// network:
target->http_requests = st1->http_requests + st2->http_requests;
#endif
// CPR decoding:
target->cpr_surface = st1->cpr_surface + st2->cpr_surface;
target->cpr_airborne = st1->cpr_airborne + st2->cpr_airborne;

View file

@ -95,11 +95,6 @@ struct stats {
// total messages:
uint32_t messages_total;
#ifdef ENABLE_WEBSERVER
// network:
uint32_t http_requests;
#endif
// CPR decoding:
unsigned int cpr_surface;
unsigned int cpr_airborne;