diff --git a/inc/lektor/internal/config.def b/inc/lektor/internal/config.def index d26bce7781428ee525a98b50327fdfca3cfd9067..40a9e847407296a767f091fbd1986c0096cc95dd 100644 --- a/inc/lektor/internal/config.def +++ b/inc/lektor/internal/config.def @@ -63,11 +63,12 @@ value("id_json", "https://kurisu.iiens.net/api/%ld") value("id_kara", "https://kurisu.iiens.net/api/download/%ld") value("fav_json", "https://kurisu.iiens.net/api/fav/") value("plt_json", "https://kurisu.iiens.net/api/plt/") +value("token", "") /* MODULE: PLAYER */ section("player") comment("The player module, so that people can 'sing' when using lektor.") -comment("By default it's sdl, but one can create any module, for audio support") +comment("By default it's qt (was sdl before), but one can create any module, for audio support") comment("only for example.") value("module", "qt") value("autoclear", "true") diff --git a/src/module/module_repo.c b/src/module/module_repo.c index 2472e3a8eea730f5d950ba2ac81e25e2f9e954ed..dd8466efc5002538faa98d66dfe567f2afdc65fb 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -8,6 +8,7 @@ #define REPO_UPDATE_KARA ((unsigned int)(1 << 1)) /* Downloading or rescanning the bakabase */ #define REPO_UPDATE_FAV ((unsigned int)(1 << 2)) /* Downloading the favorites */ #define REPO_UPDATE_ALL (REPO_UPDATE_FAV | REPO_UPDATE_KARA) /* Update all flag */ +#define REPO_TOKEN_MAX 128 /* max length of repo download token. Doit respecter LKT_LINE_MAX-len("X-Token-Authorization" > REPO_TOKEN_MAX */ /*********** * Globals * @@ -45,6 +46,7 @@ struct kara { struct json_parse_arg { void *worker; void *real_arg; + struct module_repo_internal *repo; }; struct module_repo_internal { @@ -56,6 +58,7 @@ struct module_repo_internal { char get_id_json[LKT_LINE_MAX]; char get_id_file[LKT_LINE_MAX]; char get_fav_json[LKT_LINE_MAX]; + char download_token[REPO_TOKEN_MAX]; const uint64_t version; /* The database and the queue */ @@ -273,7 +276,7 @@ err: } PRIVATE_FUNCTION int -___download_kara(const char *url, const char *path, int override) +___download_kara(const char *url, const char *path, int override, struct module_repo_internal *repo) { struct curl_slist *headers = NULL; CURL *curl_handle; @@ -312,10 +315,10 @@ retest: }; memset(file.magic, 0, sizeof(file.magic)); - static const char *const token = "49duf300b8nmm469uzvz6dxwfarb05x3"; + static const char header_name[] = "X-Token-Authorization: "; char author_token[LKT_LINE_MAX]; memset(author_token, 0, LKT_LINE_MAX); - snprintf(author_token, LKT_LINE_MAX - 1, "X-Token-Authorization: %s", token); + snprintf(author_token, sizeof(header_name) + REPO_TOKEN_MAX, "%s%s", header_name, repo->download_token); headers = curl_slist_append(headers, "Accept: video/x-matroska"); headers = curl_slist_append(headers, "Content-Type: video/x-matroska"); @@ -347,7 +350,7 @@ err: } PRIVATE_FUNCTION void -___handle_got_json_dl(struct kara *kara) +___handle_got_json_dl(struct kara *kara, struct module_repo_internal *repo) { /* Download the kara */ int current_id; @@ -364,7 +367,7 @@ ___handle_got_json_dl(struct kara *kara) safe_snprintf(kara->url, LKT_LINE_MAX, kara->repo->get_id_file, kara->id); LOG_INFO("REPO", "Start downloading kara %ld to: %s", kara->id, kara->filename); - if (___download_kara(kara->url, kara->filename, true)) { + if (___download_kara(kara->url, kara->filename, true, repo)) { LOG_WARN("REPO", "Could not download kara %ld at path '%s'", kara->id, kara->filename); return; } @@ -421,6 +424,7 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp, { struct json_parse_arg *arg = (struct json_parse_arg *)user; struct kara *kara = (struct kara *)arg->real_arg; + struct module_repo_internal *repo = (struct module_repo_internal*)arg->repo; const struct lkt_uri *filter = (const struct lkt_uri *)kara->filter_uri; /* Check if interrupt was asked */ @@ -551,7 +555,7 @@ ___handle_got_json_internal_callback(const char *key, const char *val, int comp, return 0; } - ___handle_got_json_dl(kara); + ___handle_got_json_dl(kara, repo); lkt_queue_send(kara->repo->queue, LKT_EVENT_DB_UPDATE_TICK, NULL); } @@ -576,6 +580,7 @@ ___json_dl_and_handle_for_id(struct module_repo_internal *repo, struct kara *kar struct json_parse_arg arg = { .worker = &repo->workers, .real_arg = (void *)kara, + .repo = repo, }; lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATE_TOTAL, (void *)1lu); const int ret = json_parse(json, 1, ___handle_got_json_internal_callback, &arg); @@ -638,6 +643,7 @@ ___handle_got_json(struct module_repo_internal *repo, const char *json, struct l struct json_parse_arg arg = { .worker = &repo->workers, .real_arg = (void *)&kara, + .repo = repo, }; const int ret = json_parse(json, 2, ___handle_got_json_internal_callback, &arg); LOG_INFO("REPO", "Updated %u karas, ignored %u karas, total is %d karas", kara.update_count, @@ -929,6 +935,7 @@ ___handle_fav_list(struct module_repo_internal *repo, char *fav, size_t fav_size struct json_parse_arg arg = { .worker = &repo->workers, .real_arg = (void *)&uri, + .repo = repo, }; json_parse(json, 2, ___handle_fav_list_internal, (void *)&arg); @@ -969,6 +976,7 @@ ___worker_import_favorites(void *worker, void *___repo) struct json_parse_arg arg = { .worker = worker, .real_arg = (void *)repo, + .repo = repo, }; char *json; @@ -1049,6 +1057,13 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, lkt_db LOG_ERROR("REPO", "Configuration invalid, but it should not be at this point"); exit(EXIT_FAILURE); } + + /* Check token config separately, as it's empty by default, and the error should ask the user to add it to the config */ + if (!database_config_get_text(db, "repo", "token", repo.download_token, REPO_TOKEN_MAX)) { + LOG_ERROR("REPO", "No download token in repo configuration, please add it"); + exit(EXIT_FAILURE); + } + memcpy(repo_, &repo, sizeof(struct module_repo_internal)); /* Init the worker only now ! */