commit 520bdd531eb6136d69c95778ea4eb56dbba30f41
parent b782f0aa99048d1baf000432e38363cd17b74524
Author: libredev <libredev@ircforever.org>
Date: Wed, 15 Mar 2023 16:01:41 +0530
fix https
Diffstat:
M | config.mk | | | 3 | +-- |
M | main.c | | | 45 | ++++++++++++++++++++++++++------------------- |
2 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/config.mk b/config.mk
@@ -9,7 +9,6 @@ HTTPD_GROUP=httpd
CFLAGS = -g -std=c99 -Wall -Wextra -Wpedantic -Wfatal-errors\
-Wstrict-prototypes -Wold-style-definition\
- -D_DEFAULT_SOURCE -DICECAST_URL=\"$(ICECAST_URL)\" -DNAME=\""$(NAME)"\"\
- -DSTREAM_URL_REMOVE_PORT
+ -D_DEFAULT_SOURCE -DICECAST_URL=\"$(ICECAST_URL)\" -DNAME=\""$(NAME)"\"
LDFLAGS =
diff --git a/main.c b/main.c
@@ -164,25 +164,32 @@ source_set(struct source *s, json_stream *json, const char *key)
if (var == NULL) {
fatal("failed to handle source key: %s", key);
-#ifdef STREAM_URL_REMOVE_PORT
- /* } else if (var == &s->listenurl) {
- char *tmp = json_get_value(json);
- char *port_start, *port_end;
- char *new_url;
-
- port_start = strchr(tmp, ':'); *//* ignore the colon after http */
- /* if ((port_start = strchr(++port_start, ':')) == NULL)
- *var = tmp;
- else {
- if ((port_end = strchr(port_start, '/')) == NULL)
- fatal("No mount point");
- new_url = emalloc(port_start - tmp + strlen(port_end) + 1);
- strncpy(new_url, tmp, port_start - tmp);
- strcat(new_url, port_end);
- free(tmp);
- *var = new_url;
- } */
-#endif
+ } else if (var == &s->listenurl) {
+ /* change http to https and remove port */
+ /* syntax: http://radio.theinterlude.live:8000/autodj */
+ char *tmp, *host, *port, *mount;
+ size_t len;
+
+ tmp = json_get_value(json);
+ if ((host = strchr(tmp, '/')) == NULL || *(++host) != '/')
+ goto err;
+ host++;
+ if ((port = strchr(host, ':')) == NULL)
+ goto err;
+ *port++ = '\0';
+ if ((mount = strchr(port, '/')) == NULL)
+ goto err;
+ *mount++ = '\0';
+
+ len = 8 /* https:// */ + strlen(host) + 1 /* slash */ +
+ strlen(mount) + 1 /* NULL */;
+ *var = emalloc(len);
+ snprintf(*var, len, "https://%s/%s", host, mount);
+ free(tmp);
+ return;
+
+err:
+ fatal("syntax error in stream URL");
} else {
*var = json_get_value(json);
if (var == &s->server_name) {