aboutsummaryrefslogtreecommitdiff
path: root/src/fallback.h
blob: cfca2334049263529043c872c9633b93905c63ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 <stdbool.h>

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 */