}
/*
- * @uri is either a caRepository or a rpkiNotify
- * By contract, only sets @result on return 0.
- * By contract, @result->state will be DLS_FRESH on return 0.
+ * By contract, only sets @result on return VV_CONTINUE.
+ * By contract, @result->state will be DLS_FRESH on return VV_CONTINUE.
*/
static validation_verdict
-do_refresh(struct cache_table *tbl, struct uri const *uri,
+do_refresh(struct cache_table *tbl, struct uri const *uri, bool single,
struct cache_node **result)
{
struct uri module;
}
if (tbl == &cache.rsync) {
- if (!get_rsync_module(uri, &module))
+ if (single)
+ module = *uri;
+ else if (!get_rsync_module(uri, &module))
return VV_FAIL;
mutex_lock(&tbl->lock);
node = provide_node(tbl, NULL, &module);
return (difftime(rsync->success_ts, rrdp->success_ts) > 0) ? rsync : rrdp;
}
-validation_verdict
-cache_refresh_by_url(struct uri const *url, char **result)
+static validation_verdict
+cache_refresh_url(struct cache_table *table, struct uri const *url,
+ char const **result)
{
- struct cache_node *node = NULL;
+ struct cache_node *node;
validation_verdict vv;
- if (uri_is_https(url)) {
- vv = do_refresh(&cache.https, url, &node);
- if (vv != VV_CONTINUE)
- goto oops;
- *result = node ? pstrdup(node->path) : NULL;
- return VV_CONTINUE;
+ vv = do_refresh(table, url, true, &node);
+ if (vv != VV_CONTINUE) {
+ *result = NULL;
+ return vv;
}
- if (uri_is_rsync(url)) {
- vv = do_refresh(&cache.rsync, url, &node);
- if (vv != VV_CONTINUE)
- goto oops;
- *result = path_join(node->path, strip_rsync_module(uri_str(url)));
- return VV_CONTINUE;
- }
+ *result = node->path;
+ return VV_CONTINUE;
+}
- vv = VV_FAIL;
-oops: *result = NULL;
- return vv;
+validation_verdict
+cache_refresh_url_https(struct uri const *url, char const **result)
+{
+ return cache_refresh_url(&cache.https, url, result);
+}
+
+validation_verdict
+cache_refresh_url_rsync(struct uri const *url, char const **result)
+{
+ return cache_refresh_url(&cache.rsync, url, result);
}
/* HTTPS (TAs) and rsync only; don't use this for RRDP. */
validation_verdict
-cache_get_fallback(struct uri const *url, char **result)
+cache_get_fallback(struct uri const *url, char const **result)
{
struct cache_node *node;
return VV_CONTINUE;
}
- *result = pstrdup(node->path);
+ *result = node->path;
return VV_CONTINUE;
}
/* Try RRDP + optional fallback */
if (uri_str(&uris->rpkiNotify) != NULL) {
- vv = do_refresh(&cache.rrdp, &uris->rpkiNotify, &node);
+ vv = do_refresh(&cache.rrdp, &uris->rpkiNotify, false, &node);
if (vv == VV_CONTINUE)
goto refresh_success;
if (vv == VV_BUSY)
}
/* Try rsync + optional fallback */
- vv = do_refresh(&cache.rsync, &uris->caRepository, &node);
+ vv = do_refresh(&cache.rsync, &uris->caRepository, false, &node);
if (vv == VV_CONTINUE)
goto refresh_success;
if (vv == VV_BUSY)
void exturis_init(struct extension_uris *);
void exturis_cleanup(struct extension_uris *);
-validation_verdict cache_refresh_by_url(struct uri const *, char **);
-validation_verdict cache_get_fallback(struct uri const *, char **);
+validation_verdict cache_refresh_url_https(struct uri const *, char const **);
+validation_verdict cache_refresh_url_rsync(struct uri const *, char const **);
+validation_verdict cache_get_fallback(struct uri const *, char const **);
struct cache_cage;
validation_verdict cache_refresh_by_uris(struct extension_uris *,
}
static validation_verdict
-try_urls(struct tal *tal, bool (*url_is_protocol)(struct uri const *),
- validation_verdict (*get_path)(struct uri const *, char **))
+try_urls(struct tal *tal, char const *proto,
+ validation_verdict (*get_path)(struct uri const *, char const **))
{
struct uri *url;
- char *path;
+ char const *path;
struct cache_mapping map;
validation_verdict vv;
ARRAYLIST_FOREACH(&tal->urls, url) {
- if (!url_is_protocol(url))
+ if (!uri_is_proto(url, proto))
continue;
vv = get_path(url, &path);
continue;
map.url = *url;
- map.path = path;
+ map.path = (char *)path;
vv = validate_ta(tal, &map);
- if (vv == VV_BUSY) {
- free(path);
+ if (vv == VV_BUSY)
return VV_BUSY;
- }
- if (vv == VV_FAIL) {
- free(path);
+ if (vv == VV_FAIL)
continue;
- }
cache_commit_file(&map);
- free(path);
return VV_CONTINUE;
}
+ pr_trc("No URIs match the protocol.");
return VV_FAIL;
}
/* Online attempts */
pr_trc("Trying HTTP refresh.");
- vv = try_urls(tal, uri_is_https, cache_refresh_by_url);
+ vv = try_urls(tal, "https:", cache_refresh_url_https);
if (vv != VV_FAIL)
goto end2;
pr_trc("Trying rsync refresh.");
- vv = try_urls(tal, uri_is_rsync, cache_refresh_by_url);
+ vv = try_urls(tal, "rsync:", cache_refresh_url_rsync);
if (vv != VV_FAIL)
goto end2;
/* Offline fallback attempts */
pr_trc("Trying HTTP fallback.");
- vv = try_urls(tal, uri_is_https, cache_get_fallback);
+ vv = try_urls(tal, "https:", cache_get_fallback);
if (vv != VV_FAIL)
goto end2;
pr_trc("Trying rsync fallback.");
- vv = try_urls(tal, uri_is_rsync, cache_get_fallback);
+ vv = try_urls(tal, "rsync:", cache_get_fallback);
if (vv != VV_FAIL)
goto end2;
url->_str = NULL;
}
+bool
+uri_is_proto(struct uri const *url, char const *proto)
+{
+ return str_starts_with(url->_str, proto);
+}
+
bool
uri_is_rsync(struct uri const *url)
{
- return str_starts_with(url->_str, "rsync:");
+ return uri_is_proto(url, "rsync:");
}
bool
uri_is_https(struct uri const *url)
{
- return str_starts_with(url->_str, "https:");
+ return uri_is_proto(url, "https:");
}
bool
#define uri_str(u) ((char const *)((u)->_str))
#define uri_len(u) ((size_t const)((u)->_len))
+bool uri_is_proto(struct uri const *, char const *);
bool uri_is_rsync(struct uri const *);
bool uri_is_https(struct uri const *);