diff --git a/src/http.c b/src/http.c index c1b575d4..3084e642 100644 --- a/src/http.c +++ b/src/http.c @@ -319,7 +319,7 @@ http_stream_setup(char **stream, const char *url) line = pos; } - if (strncasecmp(line, "http://", strlen("http://")) == 0) + if (net_is_http_or_https(line)) { DPRINTF(E_DBG, L_HTTP, "Found internet playlist stream (line %d): %s\n", n, line); diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index b1c500c3..c94802a3 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -2184,9 +2184,7 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle) safe_json_add_string(item, "uri", queue_item->path); } - if (queue_item->artwork_url - && (strncmp(queue_item->artwork_url, "http://", strlen("http://")) == 0 - || strncmp(queue_item->artwork_url, "https://", strlen("https://")) == 0)) + if (queue_item->artwork_url && net_is_http_or_https(queue_item->artwork_url)) { // The queue item contains a valid http url for an artwork image, there is no need // for the client to request the image through the server artwork handler. diff --git a/src/library/filescanner.c b/src/library/filescanner.c index 77b5d32e..a72c7f80 100644 --- a/src/library/filescanner.c +++ b/src/library/filescanner.c @@ -1775,7 +1775,7 @@ queue_item_stream_add(const char *path, int position, char reshuffle, uint32_t i static int queue_item_add(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id) { - if (strncasecmp(uri, "http://", strlen("http://")) == 0 || strncasecmp(uri, "https://", strlen("https://")) == 0) + if (net_is_http_or_https(uri)) { queue_item_stream_add(uri, position, reshuffle, item_id, count, new_item_id); return LIBRARY_OK; @@ -1941,7 +1941,7 @@ playlist_add_files(FILE *fp, int pl_id, const char *virtual_path) DPRINTF(E_DBG, L_SCAN, "Item '%s' added to playlist (id = %d)\n", dbmfi.path, pl_id); } } - else if (strncasecmp(virtual_path, "/http://", strlen("/http://")) == 0 || strncasecmp(virtual_path, "/https://", strlen("/https://")) == 0) + else if (virtual_path[0] != '\0' && net_is_http_or_https(virtual_path + 1)) { path = (virtual_path + 1); diff --git a/src/library/filescanner_playlist.c b/src/library/filescanner_playlist.c index 8eab96cc..cb985838 100644 --- a/src/library/filescanner_playlist.c +++ b/src/library/filescanner_playlist.c @@ -485,7 +485,7 @@ scan_playlist(const char *file, time_t mtime, int dir_id) continue; // URLs and playlists will be added to library, tracks should already be there - if (strncasecmp(path, "http://", 7) == 0 || strncasecmp(path, "https://", 8) == 0) + if (net_is_http_or_https(path)) ret = process_url(pl_id, path, &mfi); else if (playlist_type(path) != PLAYLIST_UNKNOWN) ret = process_nested_playlist(pl_id, path); diff --git a/src/library/rssscanner.c b/src/library/rssscanner.c index 8f035c7e..88b63dbb 100644 --- a/src/library/rssscanner.c +++ b/src/library/rssscanner.c @@ -622,7 +622,7 @@ rss_add(const char *path) { int ret; - if (strncmp(path, "http://", 7) != 0 && strncmp(path, "https://", 8) != 0) + if (!net_is_http_or_https(path)) { DPRINTF(E_SPAM, L_LIB, "Invalid RSS path '%s'\n", path); return LIBRARY_PATH_INVALID; diff --git a/src/misc.c b/src/misc.c index 4511dabe..2a3f04d4 100644 --- a/src/misc.c +++ b/src/misc.c @@ -363,6 +363,11 @@ net_evhttp_bind(struct evhttp *evhttp, short unsigned port, const char *log_serv } */ +bool +net_is_http_or_https(const char *url) +{ + return (strncasecmp(url, "http://", strlen("http://")) == 0 || strncasecmp(url, "https://", strlen("https://")) == 0); +} /* ----------------------- Conversion/hashing/sanitizers -------------------- */ diff --git a/src/misc.h b/src/misc.h index 893f7362..56d0f404 100644 --- a/src/misc.h +++ b/src/misc.h @@ -54,6 +54,9 @@ net_bind(short unsigned *port, int type, const char *log_service_name); int net_evhttp_bind(struct evhttp *evhttp, short unsigned port, const char *log_service_name); +// Just checks if the protocol is http or https +bool +net_is_http_or_https(const char *url); /* ----------------------- Conversion/hashing/sanitizers -------------------- */