New upstream version 24.0.1+dfsg1
This commit is contained in:
parent
b14f9eae6d
commit
5a730d6ec3
842 changed files with 42245 additions and 33385 deletions
90
deps/file-updater/file-updater/file-updater.c
vendored
90
deps/file-updater/file-updater/file-updater.c
vendored
|
|
@ -7,9 +7,9 @@
|
|||
#include "file-updater.h"
|
||||
|
||||
#define warn(msg, ...) \
|
||||
blog(LOG_WARNING, "%s"msg, info->log_prefix, ##__VA_ARGS__)
|
||||
blog(LOG_WARNING, "%s" msg, info->log_prefix, ##__VA_ARGS__)
|
||||
#define info(msg, ...) \
|
||||
blog(LOG_WARNING, "%s"msg, info->log_prefix, ##__VA_ARGS__)
|
||||
blog(LOG_WARNING, "%s" msg, info->log_prefix, ##__VA_ARGS__)
|
||||
|
||||
struct update_info {
|
||||
char error[CURL_ERROR_SIZE];
|
||||
|
|
@ -70,7 +70,7 @@ void update_info_destroy(struct update_info *info)
|
|||
}
|
||||
|
||||
static size_t http_write(uint8_t *ptr, size_t size, size_t nmemb,
|
||||
struct update_info *info)
|
||||
struct update_info *info)
|
||||
{
|
||||
size_t total = size * nmemb;
|
||||
if (total)
|
||||
|
|
@ -80,10 +80,9 @@ static size_t http_write(uint8_t *ptr, size_t size, size_t nmemb,
|
|||
}
|
||||
|
||||
static size_t http_header(char *buffer, size_t size, size_t nitems,
|
||||
struct update_info *info)
|
||||
struct update_info *info)
|
||||
{
|
||||
if (!strncmp(buffer, "ETag: ", 6))
|
||||
{
|
||||
if (!strncmp(buffer, "ETag: ", 6)) {
|
||||
char *etag = buffer + 6;
|
||||
if (*etag) {
|
||||
char *etag_clean, *p;
|
||||
|
|
@ -105,7 +104,7 @@ static size_t http_header(char *buffer, size_t size, size_t nitems,
|
|||
}
|
||||
|
||||
static bool do_http_request(struct update_info *info, const char *url,
|
||||
long *response_code)
|
||||
long *response_code)
|
||||
{
|
||||
CURLcode code;
|
||||
uint8_t null_terminator = 0;
|
||||
|
|
@ -118,10 +117,12 @@ static bool do_http_request(struct update_info *info, const char *url,
|
|||
curl_easy_setopt(info->curl, CURLOPT_WRITEDATA, info);
|
||||
curl_easy_setopt(info->curl, CURLOPT_FAILONERROR, true);
|
||||
curl_easy_setopt(info->curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(info->curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||
|
||||
if (!info->remote_url) {
|
||||
// We only care about headers from the main package file
|
||||
curl_easy_setopt(info->curl, CURLOPT_HEADERFUNCTION, http_header);
|
||||
curl_easy_setopt(info->curl, CURLOPT_HEADERFUNCTION,
|
||||
http_header);
|
||||
curl_easy_setopt(info->curl, CURLOPT_HEADERDATA, info);
|
||||
}
|
||||
|
||||
|
|
@ -133,17 +134,17 @@ static bool do_http_request(struct update_info *info, const char *url,
|
|||
code = curl_easy_perform(info->curl);
|
||||
if (code != CURLE_OK) {
|
||||
warn("Remote update of URL \"%s\" failed: %s", url,
|
||||
info->error);
|
||||
info->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (curl_easy_getinfo(info->curl, CURLINFO_RESPONSE_CODE,
|
||||
response_code) != CURLE_OK)
|
||||
response_code) != CURLE_OK)
|
||||
return false;
|
||||
|
||||
if (*response_code >= 400) {
|
||||
warn("Remote update of URL \"%s\" failed: HTTP/%ld", url,
|
||||
*response_code);
|
||||
*response_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -190,14 +191,14 @@ static bool init_update(struct update_info *info)
|
|||
if (metadata) {
|
||||
const char *etag = obs_data_get_string(metadata, "etag");
|
||||
if (etag) {
|
||||
struct dstr if_none_match = { 0 };
|
||||
struct dstr if_none_match = {0};
|
||||
dstr_copy(&if_none_match, "If-None-Match: ");
|
||||
dstr_cat(&if_none_match, etag);
|
||||
|
||||
info->etag_local = bstrdup(etag);
|
||||
|
||||
info->header = curl_slist_append(info->header,
|
||||
if_none_match.array);
|
||||
if_none_match.array);
|
||||
|
||||
dstr_free(&if_none_match);
|
||||
}
|
||||
|
|
@ -218,7 +219,7 @@ static void copy_local_to_cache(struct update_info *info, const char *file)
|
|||
{
|
||||
char *local_file_path = get_path(info->local, file);
|
||||
char *cache_file_path = get_path(info->cache, file);
|
||||
char *temp_file_path = get_path(info->temp, file);
|
||||
char *temp_file_path = get_path(info->temp, file);
|
||||
|
||||
os_copyfile(local_file_path, temp_file_path);
|
||||
os_unlink(cache_file_path);
|
||||
|
|
@ -230,8 +231,8 @@ static void copy_local_to_cache(struct update_info *info, const char *file)
|
|||
}
|
||||
|
||||
static void enum_files(obs_data_t *package,
|
||||
bool (*enum_func)(void *param, obs_data_t *file),
|
||||
void *param)
|
||||
bool (*enum_func)(void *param, obs_data_t *file),
|
||||
void *param)
|
||||
{
|
||||
obs_data_array_t *array = obs_data_get_array(package, "files");
|
||||
size_t num;
|
||||
|
|
@ -280,8 +281,7 @@ static bool update_files_to_local(void *param, obs_data_t *local_file)
|
|||
struct update_info *info = param;
|
||||
struct file_update_data data = {
|
||||
.name = obs_data_get_string(local_file, "name"),
|
||||
.version = (int)obs_data_get_int(local_file, "version")
|
||||
};
|
||||
.version = (int)obs_data_get_int(local_file, "version")};
|
||||
|
||||
enum_files(info->cache_package, newer_than_cache, &data);
|
||||
if (data.newer || !data.found)
|
||||
|
|
@ -314,7 +314,7 @@ static int update_local_version(struct update_info *info)
|
|||
}
|
||||
|
||||
static inline bool do_relative_http_request(struct update_info *info,
|
||||
const char *url, const char *file)
|
||||
const char *url, const char *file)
|
||||
{
|
||||
long response_code;
|
||||
char *full_url = get_path(url, file);
|
||||
|
|
@ -324,17 +324,16 @@ static inline bool do_relative_http_request(struct update_info *info,
|
|||
}
|
||||
|
||||
static inline void write_file_data(struct update_info *info,
|
||||
const char *base_path, const char *file)
|
||||
const char *base_path, const char *file)
|
||||
{
|
||||
char *full_path = get_path(base_path, file);
|
||||
os_quick_write_utf8_file(full_path,
|
||||
(char*)info->file_data.array,
|
||||
info->file_data.num - 1, false);
|
||||
os_quick_write_utf8_file(full_path, (char *)info->file_data.array,
|
||||
info->file_data.num - 1, false);
|
||||
bfree(full_path);
|
||||
}
|
||||
|
||||
static inline void replace_file(const char *src_base_path,
|
||||
const char *dst_base_path, const char *file)
|
||||
const char *dst_base_path, const char *file)
|
||||
{
|
||||
char *src_path = get_path(src_base_path, file);
|
||||
char *dst_path = get_path(dst_base_path, file);
|
||||
|
|
@ -354,8 +353,7 @@ static bool update_remote_files(void *param, obs_data_t *remote_file)
|
|||
|
||||
struct file_update_data data = {
|
||||
.name = obs_data_get_string(remote_file, "name"),
|
||||
.version = (int)obs_data_get_int(remote_file, "version")
|
||||
};
|
||||
.version = (int)obs_data_get_int(remote_file, "version")};
|
||||
|
||||
enum_files(info->cache_package, newer_than_cache, &data);
|
||||
if (!data.newer && data.found)
|
||||
|
|
@ -378,7 +376,7 @@ static bool update_remote_files(void *param, obs_data_t *remote_file)
|
|||
|
||||
if (!confirm) {
|
||||
info("Update file '%s' (version %d) rejected",
|
||||
data.name, data.version);
|
||||
data.name, data.version);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -386,14 +384,14 @@ static bool update_remote_files(void *param, obs_data_t *remote_file)
|
|||
write_file_data(info, info->temp, data.name);
|
||||
replace_file(info->temp, info->cache, data.name);
|
||||
|
||||
info("Successfully updated file '%s' (version %d)",
|
||||
data.name, data.version);
|
||||
info("Successfully updated file '%s' (version %d)", data.name,
|
||||
data.version);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void update_save_metadata(struct update_info *info)
|
||||
{
|
||||
struct dstr path = { 0 };
|
||||
struct dstr path = {0};
|
||||
|
||||
if (!info->etag_remote)
|
||||
return;
|
||||
|
|
@ -428,8 +426,8 @@ static void update_remote_version(struct update_info *info, int cur_version)
|
|||
|
||||
update_save_metadata(info);
|
||||
|
||||
info->remote_package = obs_data_create_from_json(
|
||||
(char*)info->file_data.array);
|
||||
info->remote_package =
|
||||
obs_data_create_from_json((char *)info->file_data.array);
|
||||
if (!info->remote_package) {
|
||||
warn("Failed to initialize remote package json");
|
||||
return;
|
||||
|
|
@ -476,14 +474,12 @@ static void *update_thread(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
update_info_t *update_info_create(
|
||||
const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *update_url,
|
||||
const char *local_dir,
|
||||
const char *cache_dir,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param)
|
||||
update_info_t *update_info_create(const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *update_url, const char *local_dir,
|
||||
const char *cache_dir,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param)
|
||||
{
|
||||
struct update_info *info;
|
||||
struct dstr dir = {0};
|
||||
|
|
@ -493,7 +489,7 @@ update_info_t *update_info_create(
|
|||
|
||||
if (os_mkdir(cache_dir) < 0) {
|
||||
blog(LOG_WARNING, "%sCould not create cache directory %s",
|
||||
log_prefix, cache_dir);
|
||||
log_prefix, cache_dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -504,7 +500,7 @@ update_info_t *update_info_create(
|
|||
|
||||
if (os_mkdir(dir.array) < 0) {
|
||||
blog(LOG_WARNING, "%sCould not create temp directory %s",
|
||||
log_prefix, cache_dir);
|
||||
log_prefix, cache_dir);
|
||||
dstr_free(&dir);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -550,12 +546,10 @@ static void *single_file_thread(void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
update_info_t *update_info_create_single(
|
||||
const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *file_url,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param)
|
||||
update_info_t *
|
||||
update_info_create_single(const char *log_prefix, const char *user_agent,
|
||||
const char *file_url,
|
||||
confirm_file_callback_t confirm_callback, void *param)
|
||||
{
|
||||
struct update_info *info;
|
||||
|
||||
|
|
|
|||
23
deps/file-updater/file-updater/file-updater.h
vendored
23
deps/file-updater/file-updater/file-updater.h
vendored
|
|
@ -13,20 +13,15 @@ struct file_download_data {
|
|||
};
|
||||
|
||||
typedef bool (*confirm_file_callback_t)(void *param,
|
||||
struct file_download_data *file);
|
||||
struct file_download_data *file);
|
||||
|
||||
update_info_t *update_info_create(
|
||||
const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *update_url,
|
||||
const char *local_dir,
|
||||
const char *cache_dir,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param);
|
||||
update_info_t *update_info_create(const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *update_url, const char *local_dir,
|
||||
const char *cache_dir,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param);
|
||||
update_info_t *update_info_create_single(
|
||||
const char *log_prefix,
|
||||
const char *user_agent,
|
||||
const char *file_url,
|
||||
confirm_file_callback_t confirm_callback,
|
||||
void *param);
|
||||
const char *log_prefix, const char *user_agent, const char *file_url,
|
||||
confirm_file_callback_t confirm_callback, void *param);
|
||||
void update_info_destroy(update_info_t *info);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue