From cfc9ef1cade470f6d2a7ba67c625eb8c11ff2743 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 16 Jul 2024 20:27:53 +0200 Subject: Add fallback urls for rss (right now, fallback nyaa.si to nyaa.land) --- src/fallback.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/fallback.h (limited to 'src/fallback.h') diff --git a/src/fallback.h b/src/fallback.h new file mode 100644 index 0000000..cfca233 --- /dev/null +++ b/src/fallback.h @@ -0,0 +1,37 @@ +#ifndef FALLBACK_H +#define FALLBACK_H + +/* + Fallback reads the fallback.json to get fallbacks for downloads (currently only for rss). + If the regular download fails then the download is retried with fallbacks until one succeeds. + That fallback is then used for all downloads for the current sync for that domain. +*/ + +#include "buffer.h" +#include + +typedef struct { + char *source; + /* If this is NULL (default) then |source| is used. This is set to the first fallback that succeeds if |source| fails and is reset to NULL the next sync. This is a reference. */ + const char *source_to_use; + /* list of char* (malloced) */ + Buffer fallbacks; +} fallback_item; + +typedef struct fallback fallback; +struct fallback { + /* list of fallback_item */ + Buffer fallbacks; +}; + +bool fallback_load_from_file(fallback *self, const char *filepath); +void fallback_deinit(fallback *self); + +/* Given an url, look for a fallback item that has a matching source or source_to_use (matching by host). If no match found, return NULL */ +fallback_item* fallback_get_from_url(fallback *self, const char *url); +void fallback_clear_sources_to_use(fallback *self); +void fallback_replace_url_with_fallback_url(const char *url, const char *fallback_url, char *new_url, size_t new_url_len); +void fallback_replace_active_fallback_url_with_source_url(fallback *self, const char *url, char *new_url, size_t new_url_len); +void fallback_item_replace_url_with_fallback_url(fallback_item *self, const char *url, char *new_url, size_t new_url_len); + +#endif /* FALLBACK_H */ -- cgit v1.2.3