From 804231e15c98246bb09d8b6635b88cf0730c666a Mon Sep 17 00:00:00 2001 From: Kartatz <105828205+Kartatz@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:36:48 -0300 Subject: [PATCH] Update to GCC 14.1.0 --- src/m3u8errors.c | 2 ++ src/m3u8errors.h | 1 + src/main.c | 27 +++++++++++++++++++++++++++ src/program_help.h | 4 +++- tools/program_help.h.py | 8 ++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/m3u8errors.c b/src/m3u8errors.c index 524aeb5..f53701a 100644 --- a/src/m3u8errors.c +++ b/src/m3u8errors.c @@ -97,6 +97,8 @@ const char* m3u8err_getmessage(const int code) { return "HTTP request failure"; case M3U8ERR_CURL_SETOPT_FAILURE: return "Could not set options on HTTP client"; + case M3U8ERR_CURL_SLIST_FAILURE: + return "Could not append item to list"; case M3U8ERR_FSTREAM_LOCK_FAILURE: return "Could not lock file"; case M3U8ERR_FSTREAM_OPEN_FAILURE: diff --git a/src/m3u8errors.h b/src/m3u8errors.h index efaf278..0192e2b 100644 --- a/src/m3u8errors.h +++ b/src/m3u8errors.h @@ -52,6 +52,7 @@ #define M3U8ERR_CURL_INIT_FAILURE -41 /* Could not initialize the HTTP client due to an unexpected error */ #define M3U8ERR_CURL_REQUEST_FAILURE -42 /* HTTP request failure */ #define M3U8ERR_CURL_SETOPT_FAILURE -43 /* Could not set options on HTTP client */ +#define M3U8ERR_CURL_SLIST_FAILURE -779 /* Could not append item to list */ #define M3U8ERR_CURLM_ADD_FAILURE -44 /* Could not initialize the HTTP client due to an unexpected error */ #define M3U8ERR_CURLM_REMOVE_FAILURE -45 /* Could not initialize the HTTP client due to an unexpected error */ diff --git a/src/main.c b/src/main.c index 3d4f72a..60d383f 100644 --- a/src/main.c +++ b/src/main.c @@ -177,6 +177,8 @@ int main(int argc, argv_t* argv[]) { char* directory = NULL; char* name = NULL; + struct curl_slist* headers = NULL; + const char* file_extension = NULL; size_t select_media_index = 0; @@ -576,6 +578,29 @@ int main(int argc, argv_t* argv[]) { } download_options.retry = (size_t) value; + } else if (strcmp(argument->key, "H") == 0 || strcmp(argument->key, "header") == 0) { + struct curl_slist* tmp = NULL; + + if (argument->value == NULL) { + err = M3U8ERR_CLI_ARGUMENT_VALUE_MISSING; + goto end; + } + + tmp = curl_slist_append(headers, argument->value); + + if (tmp == NULL) { + err = M3U8ERR_CURL_SLIST_FAILURE; + goto end; + } + + headers = tmp; + + cerror->code = curl_easy_setopt(client->curl, CURLOPT_HTTPHEADER, headers); + + if (cerror->code != CURLE_OK) { + err = M3U8ERR_CURL_SETOPT_FAILURE; + goto end; + } } else if (strcmp(argument->key, "o") == 0 || strcmp(argument->key, "output") == 0) { if (argument->value == NULL) { err = M3U8ERR_CLI_ARGUMENT_VALUE_MISSING; @@ -1093,6 +1118,8 @@ int main(int argc, argv_t* argv[]) { free(directory); free(name); + curl_slist_free_all(headers); + sslcerts_unload_certificates(); show_cursor(); diff --git a/src/program_help.h b/src/program_help.h index e7b571c..017e42a 100644 --- a/src/program_help.h +++ b/src/program_help.h @@ -6,7 +6,7 @@ This file is auto-generated. Use the ../tools/program_help.h.py tool to regenera #define PROGRAM_HELP_H #define PROGRAM_HELP \ - "usage: kai [-h] [-v] -u URL [-k] [-A USER_AGENT] [-x URI] [--doh-url URL] [-e URL] [-r COUNT] [--debug] [-S] [--select-media MEDIA] [--select-stream VARIANT_STREAM] [--disable-autoselection] [--disable-progress-meter] [--prefer-ffmpegc] [-c CONCURRENCY] -o FILENAME\n" \ + "usage: kai [-h] [-v] -u URL [-k] [-A USER_AGENT] [-x URI] [--doh-url URL] [-e URL] [-r COUNT] [-H HEADER] [--debug] [-S] [--select-media MEDIA] [--select-stream VARIANT_STREAM] [--disable-autoselection] [--disable-progress-meter] [--prefer-ffmpegc] [-c CONCURRENCY] -o FILENAME\n" \ "\n" \ "A command-line utility to download contents from M3U8 playlists.\n" \ "\n" \ @@ -23,6 +23,8 @@ This file is auto-generated. Use the ../tools/program_help.h.py tool to regenera " Send a custom Referer header to server.\n" \ " -r COUNT, --retry COUNT\n" \ " Specify how many times a failed HTTP request should be retried. Defaults to 0 (no retries).\n" \ + " -H HEADER, --header HEADER\n" \ + " Send a custom header to server. This argument can be specified multiple times.\n" \ " --debug Enable verbose logging of network requests for debugging purposes.\n" \ " -S, --list-streams List all available streams of the M3U8 playlist.\n" \ " --select-media MEDIA Select which media stream to download. By default, no additional media streams are downloaded.\n" \ diff --git a/tools/program_help.h.py b/tools/program_help.h.py index 783822c..4d4cefb 100644 --- a/tools/program_help.h.py +++ b/tools/program_help.h.py @@ -80,6 +80,14 @@ help = "Specify how many times a failed HTTP request should be retried. Defaults to 0 (no retries)." ) +parser.add_argument( + "-H", + "--header", + metavar = "HEADER", + required = False, + help = "Send a custom header to server. This argument can be specified multiple times." +) + parser.add_argument( "--debug", required = False,