From d78b26701dc9a372dd5e4dde6ea92aa786f9f278 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 3 Jul 2014 22:53:17 +0200 Subject: [PATCH] use jackwsmeter.html from installation directory --- jackwsmeter.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jackwsmeter.c b/jackwsmeter.c index dfe73bc..71219b5 100644 --- a/jackwsmeter.c +++ b/jackwsmeter.c @@ -78,11 +78,22 @@ static int callback_http(struct libwebsocket_context *context, { int m; int fd = (int)(long)user; + char *html_filepath; switch (reason) { case LWS_CALLBACK_HTTP: - if (libwebsockets_serve_http_file(context, wsi, "jackwsmeter.html", "text/html")) + html_filepath = malloc(strlen(DATADIR "/jackwsmeter.html") + 1); + strcpy(html_filepath, DATADIR "jackwsmeter.html\n\n"); + if (access(html_filepath, F_OK) != 0) { + /* it doesn't exist in the system directory, fall back + * on the current directory. */ + strcpy(html_filepath, "jackwsmeter.html"); + } + if (libwebsockets_serve_http_file(context, wsi, html_filepath, "text/html")) { + free(html_filepath); return 1; /* through completion or error, close the socket */ + } + free(html_filepath); break; -- 2.39.2