commit 16583646ecfddbe6bef5999075c7f758bbd8abb2
parent 815d19ea9ec417f53492bc6511dd94450b6845d7
Author: libredev <libredev@ircforever.org>
Date: Wed, 4 Jan 2023 18:59:01 +0530
improve url handling
Diffstat:
4 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/Makefile b/Makefile
@@ -4,31 +4,26 @@
# This work is provided 'as-is', without any express or implied warranty.
# See COPYING file for details.
+INSTALL_DIR=/var/www/htdocs/radio.ircforever.org
+
CC = cc
CFLAGS =\
-g -std=c99 -Wall -Wextra -Wpedantic -Wfatal-errors\
-Wstrict-prototypes -Wold-style-definition\
-D_DEFAULT_SOURCE
-INSTALL_DIR=/var/www/htdocs/radio.ircforever.org
-
-install: index.cgi header.html footer.html style.css music.svg
- doas rm -R -f $(INSTALL_DIR)
- doas mkdir -p $(INSTALL_DIR)
- doas cp index.cgi $(INSTALL_DIR)
- doas cp index.cgi $(INSTALL_DIR)/about.cgi
- doas cp header.html $(INSTALL_DIR)
- doas cp footer.html $(INSTALL_DIR)
- doas cp style.css $(INSTALL_DIR)
- doas cp music.svg $(INSTALL_DIR)
-
index.cgi: main.c http.h pdjson/pdjson.c
$(CC) $(CFLAGS) -o $@ main.c pdjson/pdjson.c
run: index.cgi
- SCRIPT_NAME="/index.cgi" valgrind --leak-check=full --show-leak-kinds=all ./index.cgi
+ REQUEST_URI="" valgrind --leak-check=full --show-leak-kinds=all ./index.cgi
clean:
rm -f index.cgi
-.PHONY: install run clean
+install: index.cgi header.html footer.html style.css music.svg
+ rm -R -f $(INSTALL_DIR)
+ mkdir -p $(INSTALL_DIR)
+ cp index.cgi header.html footer.html style.css music.svg $(INSTALL_DIR)
+
+.PHONY: run clean install
diff --git a/header.html b/header.html
@@ -5,6 +5,6 @@
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> IRCNow Radio | Free Culture Media Streaming </title>
- <link rel="stylesheet" type="text/css" href="style.css"/>
+ <link rel="stylesheet" type="text/css" href="/style.css"/>
</head>
diff --git a/main.c b/main.c
@@ -118,7 +118,7 @@ icestats_set(struct icestats *s, json_stream *json, const char *key)
void
icestats_print(struct icestats *s)
{
- puts("<table class=\"about\">");
+ puts("<table class='about'>");
printf("<tr><td> Admin </td><td> %s </td></tr>\n", s->admin);
printf("<tr><td> Host </td><td> %s </td></tr>\n", s->host);
printf("<tr><td> Location </td><td> %s </td></tr>\n", s->location);
@@ -184,7 +184,7 @@ source_print(struct source *s)
/* thumbnail and player */
puts("<div class='player'>");
- puts("<video controls poster='music.svg'>");
+ puts("<video controls poster='/music.svg'>");
puts("<source src='https://theinterlude.live/autodj' type='application/ogg'>");
puts("Your browser does not support the video tag.");
puts("</video>");
@@ -251,17 +251,17 @@ source_free(struct source *s)
void
print_navigation_bar(int index)
{
- char *names[] = { "Stream", "Music", "Contact", "About", "Login" };
- char *scripts[] = { "index.cgi", "music.cgi", "contact.cgi", "about.cgi", "login.cgi" };
+ char *names[] = { "Stream", "Music", "Contact", "About", "Login" };
+ char *scripts[] = { "/stream/", "/music/", "/contact/", "/about/", "/login/" };
puts("<ul>");
- puts("<li><a href=\"index.cgi\">IRCNow Radio</a></li>");
+ puts("<li><a href='/'>IRCNow Radio</a></li>");
for (int i = 0; i < 5; i++) {
printf("<li><a ");
if (i == index)
- printf("class=\"active\" ");
- printf("href=\"%s\">%s</a></li>\n", scripts[i], names[i]);
+ printf("class='active' ");
+ printf("href='%s'>%s</a></li>\n", scripts[i], names[i]);
}
puts("</ul>");
@@ -376,19 +376,25 @@ main(int argc, char *argv[])
/*
* body
*/
- script_name = getenv("SCRIPT_NAME");
+ script_name = getenv("REQUEST_URI");
if (script_name == NULL) {
- printf("ERROR: environment variable \"SCRIPT_NAME\" is not set.\n");
+ printf("ERROR: environment variable 'REQUEST_URI' is not set.\n");
return 1;
}
+ if (script_name[strlen(script_name)-1] == '/')
+ script_name[strlen(script_name)-1] = '\0';
- if (strcmp(script_name, "/index.cgi") == 0) {
+ if ((strlen(script_name) == 0) || (strcmp(script_name, "/stream") == 0)) {
print_navigation_bar(0);
for (int i = 0; i < sources_length; i++)
source_print(&sources[i]);
- } else if (strcmp(script_name, "/about.cgi") == 0) {
+ } else if (strcmp(script_name, "/about") == 0) {
print_navigation_bar(3);
icestats_print(&icestats);
+ } else {
+ puts("<h1>404 Not Found</h1>");
+ puts("<p>This is not a joke.</p>");
+ return 1;
}
/*
diff --git a/style.css b/style.css
@@ -75,6 +75,9 @@ tr:nth-child(odd) {
hr {
margin: 20px 0px;
+ border: none;
+ height: 1px;
+ background-color: darkgrey;
}
@media screen and (max-width: 600px) {