Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ PROGNAME=dump1090

all: dump1090

gmap.c: gmap.html
xxd -i $^ > $@
sed -i "s/^unsigned/const unsigned/" $@

%.o: %.c
$(CC) $(CFLAGS) -c $<

dump1090: dump1090.o anet.o
$(CC) -g -o dump1090 dump1090.o anet.o $(LDFLAGS) $(LDLIBS)
dump1090: dump1090.o anet.o gmap.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)

clean:
rm -f *.o dump1090
40 changes: 15 additions & 25 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include "rtl-sdr.h"
#include "anet.h"

extern const unsigned char gmap_html[];
extern const unsigned gmap_html_len;

#define MODES_DEFAULT_RATE 2000000
#define MODES_DEFAULT_FREQ 1090000000
#define MODES_DEFAULT_WIDTH 1000
Expand Down Expand Up @@ -2250,26 +2253,8 @@ int handleHTTPRequest(struct client *c) {
content = aircraftsToJson(&clen);
ctype = MODES_CONTENT_TYPE_JSON;
} else {
struct stat sbuf;
int fd = -1;

if (stat("gmap.html",&sbuf) != -1 &&
(fd = open("gmap.html",O_RDONLY)) != -1)
{
content = malloc(sbuf.st_size);
if (read(fd,content,sbuf.st_size) == -1) {
snprintf(content,sbuf.st_size,"Error reading from file: %s",
strerror(errno));
}
clen = sbuf.st_size;
} else {
char buf[128];

clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s",
strerror(errno));
content = strdup(buf);
}
if (fd != -1) close(fd);
content = (char*) gmap_html;
clen = gmap_html_len;
ctype = MODES_CONTENT_TYPE_HTML;
}

Expand All @@ -2289,16 +2274,21 @@ int handleHTTPRequest(struct client *c) {
if (Modes.debug & MODES_DEBUG_NET)
printf("HTTP Reply header:\n%s", hdr);

int ret;
/* Send header and content. */
if (write(c->fd, hdr, hdrlen) != hdrlen ||
write(c->fd, content, clen) != clen)
{
free(content);
return 1;
ret = 1;
} else {
Modes.stat_http_requests++;
ret = !keepalive;
}
free(content);
Modes.stat_http_requests++;
return !keepalive;

if (content != (char*)gmap_html)
free(content);

return ret;
}

/* This function polls the clients using read() in order to receive new
Expand Down