Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Jan 14, 2025
1 parent a504b07 commit 39b2d7d
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 111 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ add_executable(
src/errors.c
src/argparser.c
src/main.c
src/m3u8httpclient.c
src/httpclient.c
src/m3u8sizeof.c
src/m3u8parser.c
src/m3u8stream.c
Expand Down
4 changes: 2 additions & 2 deletions src/clioptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int clioptions_parse(
struct CLIOptions* const options,
struct ArgumentParser* const argparser,
const struct Argument** argument,
struct M3U8HTTPClient* client
struct HTTPClient* client
) {

int err = M3U8ERR_SUCCESS;
Expand All @@ -45,7 +45,7 @@ int clioptions_parse(
size_t index = 0;
size_t select_media_index = 0;

struct M3U8HTTPClientError* cerror = m3u8httpclient_geterror(client);
struct HTTPClientError* cerror = httpclient_geterror(client);

ssize_t nproc = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/clioptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int clioptions_parse(
struct CLIOptions* const options,
struct ArgumentParser* const argparser,
const struct Argument** argument,
struct M3U8HTTPClient* client
struct HTTPClient* client
);

void clioptions_free(struct CLIOptions* const options);
Expand Down
26 changes: 13 additions & 13 deletions src/m3u8httpclient.c → src/httpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <string.h>

#include "errors.h"
#include "m3u8httpclient.h"
#include "httpclient.h"
#include "sslcerts.h"

int m3u8httpclient_init(struct M3U8HTTPClient* const client) {
int httpclient_init(struct HTTPClient* const client) {

int err = M3U8ERR_SUCCESS;
CURLcode code = CURLE_OK;
Expand Down Expand Up @@ -133,14 +133,14 @@ int m3u8httpclient_init(struct M3U8HTTPClient* const client) {
}

if (err != M3U8ERR_SUCCESS) {
m3u8httpclient_free(client);
httpclient_free(client);
}

return err;

}

void m3u8httpclient_errfree(struct M3U8HTTPClientError* const error) {
void httpclient_error_free(struct HTTPClientError* const error) {

if (error == NULL) {
return;
Expand All @@ -153,26 +153,26 @@ void m3u8httpclient_errfree(struct M3U8HTTPClientError* const error) {

}

void m3u8httpclient_free(struct M3U8HTTPClient* const client) {
void httpclient_free(struct HTTPClient* const client) {

curl_easy_cleanup(client->curl);
client->curl = NULL;

}

struct M3U8HTTPClientError* m3u8httpclient_geterror(struct M3U8HTTPClient* const client) {
struct HTTPClientError* httpclient_geterror(struct HTTPClient* const client) {

return &client->error;

}

CURL* m3u8httpclient_getclient(struct M3U8HTTPClient* const client) {
CURL* httpclient_getclient(struct HTTPClient* const client) {

return client->curl;

}

int m3u8httpclient_retryable(CURL* const curl, const CURLcode code) {
int httpclient_retryable(CURL* const curl, const CURLcode code) {

switch (code) {
case CURLE_HTTP_RETURNED_ERROR: {
Expand All @@ -199,7 +199,7 @@ int m3u8httpclient_retryable(CURL* const curl, const CURLcode code) {

}

int m3u8httpclient_perform(struct M3U8HTTPClient* const client) {
int httpclient_perform(struct HTTPClient* const client) {

int err = M3U8ERR_SUCCESS;
int retryable = 0;
Expand All @@ -213,7 +213,7 @@ int m3u8httpclient_perform(struct M3U8HTTPClient* const client) {
break;
}

retryable = m3u8httpclient_retryable(client->curl, client->error.code);
retryable = httpclient_retryable(client->curl, client->error.code);

if (!retryable) {
break;
Expand All @@ -233,7 +233,7 @@ int m3u8httpclient_perform(struct M3U8HTTPClient* const client) {

}

int m3u8mhttpclient_init(struct M3U8MultiHTTPClient* const client, const size_t concurrency) {
int multihttpclient_init(struct MultiHTTPClient* const client, const size_t concurrency) {

int err = M3U8ERR_SUCCESS;
CURLMcode code = CURLM_OK;
Expand Down Expand Up @@ -292,14 +292,14 @@ int m3u8mhttpclient_init(struct M3U8MultiHTTPClient* const client, const size_t
end:;

if (err != M3U8ERR_SUCCESS) {
m3u8mhttpclient_free(client);
multihttpclient_free(client);
}

return err;

}

void m3u8mhttpclient_free(struct M3U8MultiHTTPClient* const client) {
void multihttpclient_free(struct MultiHTTPClient* const client) {

curl_multi_cleanup(client->curl_multi);
client->curl_multi = NULL;
Expand Down
36 changes: 36 additions & 0 deletions src/httpclient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#if !defined(HTTPCLIENT_H)
#define HTTPCLIENT_H

#include <curl/curl.h>

struct HTTPClientError {
CURLcode code;
char* message;
};

struct HTTPClient {
CURL* curl;
struct HTTPClientError error;
size_t retry;
};

struct MultiHTTPClient {
CURLM* curl_multi;
CURLSH* curl_share;
};

int httpclient_init(struct HTTPClient* const client);

void httpclient_error_free(struct HTTPClientError* const error);
void httpclient_free(struct HTTPClient* const client);

struct HTTPClientError* httpclient_geterror(struct HTTPClient* const client);
CURL* httpclient_getclient(struct HTTPClient* const client);

int httpclient_retryable(CURL* const curl, const CURLcode code);
int httpclient_perform(struct HTTPClient* const client);

int multihttpclient_init(struct MultiHTTPClient* const client, const size_t concurrency);
void multihttpclient_free(struct MultiHTTPClient* const client);

#endif
22 changes: 6 additions & 16 deletions src/m3u8.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "fstream.h"
#include "filesystem.h"
#include "readlines.h"
#include "m3u8httpclient.h"
#include "httpclient.h"
#include "hex.h"
#include "sutils.h"
#include "guess_uri.h"
Expand Down Expand Up @@ -2759,8 +2759,8 @@ void m3u8playlist_free(struct M3U8Playlist* const playlist) {
playlist->suburi.uri = NULL;

if (!playlist->subresource) {
m3u8httpclient_free(&playlist->client);
m3u8mhttpclient_free(&playlist->multi_client);
httpclient_free(&playlist->client);
multihttpclient_free(&playlist->multi_client);
}

playlist->subresource = 0;
Expand Down Expand Up @@ -3599,16 +3599,6 @@ int m3u8_dump_file(

}

const struct M3U8BaseURI* m3u8playlist_geturi(const struct M3U8Playlist* const playlist) {
/*
Get the base URI of the M3U8 playlist.
*/

const struct M3U8BaseURI* const base_uri = (playlist->suburi.uri == NULL) ? &playlist->uri : &playlist->suburi;
return base_uri;

}

static int m3u8playlist_seturi(
struct M3U8Playlist* const playlist,
const enum M3U8BaseURIType type,
Expand Down Expand Up @@ -3824,13 +3814,13 @@ int m3u8playlist_load_url(

buffer[0] = '\0';

err = m3u8httpclient_init(&playlist->client);
err = httpclient_init(&playlist->client);

if (err != M3U8ERR_SUCCESS) {
goto end;
}

curl = m3u8httpclient_getclient(&playlist->client);
curl = httpclient_getclient(&playlist->client);

code = curl_easy_setopt(curl, CURLOPT_URL, url);

Expand All @@ -3853,7 +3843,7 @@ int m3u8playlist_load_url(
goto end;
}

err = m3u8httpclient_perform(&playlist->client);
err = httpclient_perform(&playlist->client);

if (err != M3U8ERR_SUCCESS) {
goto end;
Expand Down
6 changes: 4 additions & 2 deletions src/m3u8.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ struct M3U8Tag* m3u8playlist_igettag(
enum M3U8TagType type
);

const struct M3U8BaseURI* m3u8playlist_geturi(const struct M3U8Playlist* const playlist);

int m3u8playlist_tagexists(
const struct M3U8Playlist* const playlist,
enum M3U8TagType type
Expand Down Expand Up @@ -115,3 +113,7 @@ int m3u8_dump_file(
const struct M3U8Playlist* const playlist,
const char* const filename
);

#define m3u8playlist_geturi(playlist) (((playlist)->suburi.uri == NULL) ? &(playlist)->uri : &(playlist)->suburi)
#define m3u8playlist_getclient(playlist) (&(playlist)->client)
#define m3u8playlist_get_mclient(playlist) (&(playlist)->multi_client)
Loading

0 comments on commit 39b2d7d

Please sign in to comment.