]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Rename "rpki_uri" into "cache_mapping"
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 6 Jun 2024 21:54:57 +0000 (15:54 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Thu, 6 Jun 2024 21:54:57 +0000 (15:54 -0600)
Helps visualize where I'm headed.

48 files changed:
src/Makefile.am
src/abbreviations.txt
src/cache/local_cache.c
src/cache/local_cache.h
src/cert_stack.c
src/cert_stack.h
src/certificate_refs.c
src/certificate_refs.h
src/common.c
src/crypto/hash.c
src/crypto/hash.h
src/data_structure/path_builder.h
src/http/http.c
src/http/http.h
src/object/certificate.c
src/object/certificate.h
src/object/crl.c
src/object/crl.h
src/object/ghostbusters.c
src/object/ghostbusters.h
src/object/manifest.c
src/object/manifest.h
src/object/roa.c
src/object/roa.h
src/object/signed_object.c
src/object/signed_object.h
src/object/tal.c
src/object/tal.h
src/print_file.c
src/rpp.c
src/rpp.h
src/rrdp.c
src/rrdp.h
src/state.h
src/thread_var.c
src/thread_var.h
src/types/map.c [moved from src/types/uri.c with 57% similarity]
src/types/map.h [new file with mode: 0644]
src/types/uri.h [deleted file]
test/Makefile.am
test/cache/local_cache_test.c
test/crypto/hash_test.c
test/data_structure/uthash_test.c
test/rrdp_test.c
test/rtr/db/vrps_test.c
test/tal_test.c
test/types/map_test.c [new file with mode: 0644]
test/types/uri_test.c [deleted file]

index ac948798fff1c81451f004c70326587064740360..7bbc61b33cba7a72f7c66dd6b2852781f365b430 100644 (file)
@@ -43,7 +43,7 @@ fort_SOURCES += types/bio_seq.c types/bio_seq.h
 fort_SOURCES += types/delta.c types/delta.h
 fort_SOURCES += types/router_key.c types/router_key.h
 fort_SOURCES += types/serial.h types/serial.c
-fort_SOURCES += types/uri.h types/uri.c
+fort_SOURCES += types/map.h types/map.c
 fort_SOURCES += types/vrp.c types/vrp.h
 
 fort_SOURCES += cache/local_cache.c cache/local_cache.h
index 5024c4d893426ff005f7e23a39dbfea9d8a5f393..effa6d8cec1de7090e3a3c0202253033684819d0 100644 (file)
@@ -12,7 +12,6 @@ dl: download
 eof: end of file
 err: error
 fd: File Descriptor (see `man 2 accept`)
-guri: global URI
 hdr: header
 hh: hash (table) hook
 ht: hash table
index 2d7901b35bd1ce23db8ae9ca71fe5a5b79ea7123..6df1c5a8c2be2c5d78a4c207e112d2a73a9e6df4 100644 (file)
@@ -19,7 +19,7 @@
 #include "rsync/rsync.h"
 
 struct cache_node {
-       struct rpki_uri *url;
+       struct cache_mapping *map;
 
        struct {
                time_t ts; /* Last download attempt's timestamp */
@@ -251,7 +251,7 @@ json2node(json_t *json)
 {
        struct cache_node *node;
        char const *type_str;
-       enum uri_type type;
+       enum map_type type;
        char const *url;
        json_t *notif;
        int error;
@@ -266,13 +266,13 @@ json2node(json_t *json)
        }
 
        if (strcmp(type_str, TYPEVALUE_TA_RSYNC) == 0)
-               type = UT_TA_RSYNC;
+               type = MAP_TA_RSYNC;
        else if (strcmp(type_str, TYPEVALUE_TA_HTTP) == 0)
-               type = UT_TA_HTTP;
+               type = MAP_TA_HTTP;
        else if (strcmp(type_str, TYPEVALUE_RPP) == 0)
-               type = UT_RPP;
+               type = MAP_RPP;
        else if (strcmp(type_str, TYPEVALUE_NOTIF) == 0)
-               type = UT_NOTIF;
+               type = MAP_NOTIF;
        else {
                pr_op_err("Unknown node type: %s", type_str);
                goto fail;
@@ -285,7 +285,7 @@ json2node(json_t *json)
                goto fail;
        }
 
-       if (type == UT_NOTIF) {
+       if (type == MAP_NOTIF) {
                error = json_get_object(json, TAGNAME_NOTIF, &notif);
                switch (error) {
                case 0:
@@ -301,7 +301,7 @@ json2node(json_t *json)
                }
        }
 
-       error = uri_create(&node->url, type, NULL, url);
+       error = map_create(&node->map, type, NULL, url);
        if (error) {
                pr_op_err("Cannot parse '%s' into a URI.", url);
                goto fail;
@@ -327,19 +327,19 @@ json2node(json_t *json)
        return node;
 
 fail:
-       uri_refput(node->url);
+       map_refput(node->map);
        rrdp_notif_free(node->notif);
        free(node);
        return NULL;
 }
 
 static struct cache_node *
-find_node(struct rpki_cache *cache, struct rpki_uri *uri)
+find_node(struct rpki_cache *cache, struct cache_mapping *map)
 {
        char const *key;
        struct cache_node *result;
 
-       key = uri_get_global(uri);
+       key = map_get_url(map);
        HASH_FIND_STR(cache->ht, key, result);
 
        return result;
@@ -348,7 +348,7 @@ find_node(struct rpki_cache *cache, struct rpki_uri *uri)
 static void
 add_node(struct rpki_cache *cache, struct cache_node *node)
 {
-       char const *key = uri_get_global(node->url);
+       char const *key = map_get_url(node->map);
        size_t keylen = strlen(key);
        HASH_ADD_KEYPTR(hh, cache->ht, key, keylen, node);
 }
@@ -421,17 +421,17 @@ node2json(struct cache_node *node)
        if (json == NULL)
                return NULL;
 
-       switch (uri_get_type(node->url)) {
-       case UT_TA_RSYNC:
+       switch (map_get_type(node->map)) {
+       case MAP_TA_RSYNC:
                type = TYPEVALUE_TA_RSYNC;
                break;
-       case UT_TA_HTTP:
+       case MAP_TA_HTTP:
                type = TYPEVALUE_TA_HTTP;
                break;
-       case UT_RPP:
+       case MAP_RPP:
                type = TYPEVALUE_RPP;
                break;
-       case UT_NOTIF:
+       case MAP_NOTIF:
                type = TYPEVALUE_NOTIF;
                break;
        default:
@@ -440,7 +440,7 @@ node2json(struct cache_node *node)
 
        if (json_add_str(json, TAGNAME_TYPE, type))
                goto cancel;
-       if (json_add_str(json, TAGNAME_URL, uri_get_global(node->url)))
+       if (json_add_str(json, TAGNAME_URL, map_get_url(node->map)))
                goto cancel;
        if (node->notif != NULL) {
                notification = rrdp_notif2json(node->notif);
@@ -476,7 +476,7 @@ build_tal_json(struct rpki_cache *cache)
                child = node2json(node);
                if (child != NULL && json_array_append_new(root, child)) {
                        pr_op_err("Cannot push %s json node into json root; unknown cause.",
-                           uri_op_get_printable(node->url));
+                           map_op_get_printable(node->map));
                        continue;
                }
        }
@@ -506,15 +506,15 @@ end:      json_decref(json);
 }
 
 static int
-get_url(struct rpki_uri *uri, struct rpki_uri **url)
+fix_url(struct cache_mapping *map, struct cache_mapping **result)
 {
-       char const *guri, *c;
-       char *gcopy;
+       char const *url, *c;
+       char *dup;
        unsigned int slashes;
        int error;
 
-       if (uri_get_type(uri) != UT_RPP)
-               goto reuse_uri;
+       if (map_get_type(map) != MAP_RPP)
+               goto reuse_mapping;
 
        /*
         * Careful with this code. rsync(1):
@@ -563,39 +563,39 @@ get_url(struct rpki_uri *uri, struct rpki_uri **url)
         * not every RPP separately. The former is much faster.
         */
 
-       guri = uri_get_global(uri);
+       url = map_get_url(map);
        slashes = 0;
-       for (c = guri; *c != '\0'; c++) {
+       for (c = url; *c != '\0'; c++) {
                if (*c == '/') {
                        slashes++;
                        if (slashes == 4) {
                                if (c[1] == '\0')
-                                       goto reuse_uri;
-                               gcopy = pstrndup(guri, c - guri + 1);
-                               goto gcopy2url;
+                                       goto reuse_mapping;
+                               dup = pstrndup(url, c - url + 1);
+                               goto dup2url;
                        }
                }
        }
 
        if (slashes == 3 && c[-1] != '/') {
-               gcopy = pmalloc(c - guri + 2);
-               memcpy(gcopy, guri, c - guri);
-               gcopy[c - guri] = '/';
-               gcopy[c - guri + 1] = '\0';
-               goto gcopy2url;
+               dup = pmalloc(c - url + 2);
+               memcpy(dup, url, c - url);
+               dup[c - url] = '/';
+               dup[c - url + 1] = '\0';
+               goto dup2url;
        }
 
        return pr_val_err("Can't rsync URL '%s': The URL seems to be missing a domain or rsync module.",
-           guri);
+           url);
 
-reuse_uri:
-       uri_refget(uri);
-       *url = uri;
+reuse_mapping:
+       map_refget(map);
+       *result = map;
        return 0;
 
-gcopy2url:
-       error = uri_create(url, UT_RPP, NULL, gcopy);
-       free(gcopy);
+dup2url:
+       error = map_create(result, MAP_RPP, NULL, dup);
+       free(dup);
        return error;
 }
 
@@ -606,11 +606,11 @@ was_recently_downloaded(struct rpki_cache *cache, struct cache_node *node)
 }
 
 static int
-cache_check(struct rpki_uri *url)
+cache_check(struct cache_mapping *url)
 {
        int error;
 
-       error = file_exists(uri_get_local(url));
+       error = file_exists(map_get_path(url));
        switch (error) {
        case 0:
                pr_val_debug("Offline mode, file is cached.");
@@ -632,21 +632,21 @@ cache_check(struct rpki_uri *url)
  * @changed can be NULL.
  */
 int
-cache_download(struct rpki_cache *cache, struct rpki_uri *uri, bool *changed,
-    struct cachefile_notification ***notif)
+cache_download(struct rpki_cache *cache, struct cache_mapping *map,
+    bool *changed, struct cachefile_notification ***notif)
 {
-       struct rpki_uri *url;
+       struct cache_mapping *map2;
        struct cache_node *node;
        int error;
 
        if (changed != NULL)
                *changed = false;
 
-       error = get_url(uri, &url);
+       error = fix_url(map, &map2);
        if (error)
                return error;
 
-       node = find_node(cache, url);
+       node = find_node(cache, map2);
        if (node != NULL) {
                if (was_recently_downloaded(cache, node)) {
                        error = node->attempt.result;
@@ -654,27 +654,27 @@ cache_download(struct rpki_cache *cache, struct rpki_uri *uri, bool *changed,
                }
        } else {
                node = pzalloc(sizeof(struct cache_node));
-               node->url = url;
-               uri_refget(url);
+               node->map = map2;
+               map_refget(map2);
                add_node(cache, node);
        }
 
-       switch (uri_get_type(url)) {
-       case UT_TA_HTTP:
-       case UT_NOTIF:
-       case UT_TMP:
+       switch (map_get_type(map2)) {
+       case MAP_TA_HTTP:
+       case MAP_NOTIF:
+       case MAP_TMP:
                error = config_get_http_enabled()
-                  ? http_download(url, node->success.ts, changed)
-                  : cache_check(url);
+                  ? http_download(map2, node->success.ts, changed)
+                  : cache_check(map2);
                break;
-       case UT_TA_RSYNC:
-       case UT_RPP:
+       case MAP_TA_RSYNC:
+       case MAP_RPP:
                error = config_get_rsync_enabled()
-                   ? rsync_download(uri_get_global(url), uri_get_local(url), true)
-                   : cache_check(url);
+                   ? rsync_download(map_get_url(map2), map_get_path(map2), true)
+                   : cache_check(map2);
                break;
        default:
-               pr_crit("URI type not downloadable: %d", uri_get_type(url));
+               pr_crit("Mapping type not downloadable: %d", map_get_type(map2));
        }
 
        node->attempt.ts = time(NULL);
@@ -687,45 +687,47 @@ cache_download(struct rpki_cache *cache, struct rpki_uri *uri, bool *changed,
        }
 
 end:
-       uri_refput(url);
+       map_refput(map2);
        if (!error && (notif != NULL))
                *notif = &node->notif;
        return error;
 }
 
 static int
-download(struct rpki_cache *cache, struct rpki_uri *uri, uris_dl_cb cb, void *arg)
+download(struct rpki_cache *cache, struct cache_mapping *map, maps_dl_cb cb,
+    void *arg)
 {
        int error;
 
-       pr_val_debug("Trying URL %s...", uri_get_global(uri));
+       pr_val_debug("Trying URL %s...", map_get_url(map));
 
-       switch (uri_get_type(uri)) {
-       case UT_TA_HTTP:
-       case UT_TA_RSYNC:
-       case UT_RPP:
-               error = cache_download(cache, uri, NULL, NULL);
+       switch (map_get_type(map)) {
+       case MAP_TA_HTTP:
+       case MAP_TA_RSYNC:
+       case MAP_RPP:
+               error = cache_download(cache, map, NULL, NULL);
                break;
-       case UT_NOTIF:
-               error = rrdp_update(uri);
+       case MAP_NOTIF:
+               error = rrdp_update(map);
                break;
        default:
-               pr_crit("URI type is not a legal alt candidate: %u", uri_get_type(uri));
+               pr_crit("Mapping type is not a legal alt candidate: %u",
+                   map_get_type(map));
        }
 
-       return error ? 1 : cb(uri, arg);
+       return error ? 1 : cb(map, arg);
 }
 
 static int
-download_uris(struct rpki_cache *cache, struct uri_list *uris,
-    enum uri_type type, uris_dl_cb cb, void *arg)
+download_maps(struct rpki_cache *cache, struct map_list *maps,
+    enum map_type type, maps_dl_cb cb, void *arg)
 {
-       struct rpki_uri **uri;
+       struct cache_mapping **map;
        int error;
 
-       ARRAYLIST_FOREACH(uris, uri) {
-               if (uri_get_type(*uri) == type) {
-                       error = download(cache, *uri, cb, arg);
+       ARRAYLIST_FOREACH(maps, map) {
+               if (map_get_type(*map) == type) {
+                       error = download(cache, *map, cb, arg);
                        if (error <= 0)
                                return error;
                }
@@ -735,11 +737,10 @@ download_uris(struct rpki_cache *cache, struct uri_list *uris,
 }
 
 /**
- * Assumes all the URIs are URLs, and represent different ways to access the
- * same content.
+ * Assumes the mappings represent different ways to access the same content.
  *
  * Sequentially (in the order dictated by their priorities) attempts to update
- * (in the cache) the content pointed by each URL.
+ * (in the cache) the content pointed by each mapping's URL.
  * If a download succeeds, calls cb on it. If cb succeeds, returns without
  * trying more URLs.
  *
@@ -747,38 +748,38 @@ download_uris(struct rpki_cache *cache, struct uri_list *uris,
  * that's already cached, and callbacks it.
  */
 int
-cache_download_alt(struct rpki_cache *cache, struct uri_list *uris,
-    enum uri_type http_type, enum uri_type rsync_type, uris_dl_cb cb, void *arg)
+cache_download_alt(struct rpki_cache *cache, struct map_list *maps,
+    enum map_type http_type, enum map_type rsync_type, maps_dl_cb cb, void *arg)
 {
-       struct rpki_uri **cursor, *uri;
+       struct cache_mapping **cursor, *map;
        int error;
 
        if (config_get_http_priority() > config_get_rsync_priority()) {
-               error = download_uris(cache, uris, http_type, cb, arg);
+               error = download_maps(cache, maps, http_type, cb, arg);
                if (error <= 0)
                        return error;
-               error = download_uris(cache, uris, rsync_type, cb, arg);
+               error = download_maps(cache, maps, rsync_type, cb, arg);
                if (error <= 0)
                        return error;
 
        } else if (config_get_http_priority() < config_get_rsync_priority()) {
-               error = download_uris(cache, uris, rsync_type, cb, arg);
+               error = download_maps(cache, maps, rsync_type, cb, arg);
                if (error <= 0)
                        return error;
-               error = download_uris(cache, uris, http_type, cb, arg);
+               error = download_maps(cache, maps, http_type, cb, arg);
                if (error <= 0)
                        return error;
 
        } else {
-               ARRAYLIST_FOREACH(uris, cursor) {
+               ARRAYLIST_FOREACH(maps, cursor) {
                        error = download(cache, *cursor, cb, arg);
                        if (error <= 0)
                                return error;
                }
        }
 
-       uri = cache_recover(cache, uris);
-       return (uri != NULL) ? cb(uri, arg) : ESRCH;
+       map = cache_recover(cache, maps);
+       return (map != NULL) ? cb(map, arg) : ESRCH;
 }
 
 /*
@@ -814,27 +815,27 @@ choose_better(struct cache_node *old, struct cache_node *new)
        return (difftime(old->success.ts, new->success.ts) < 0) ? new : old;
 }
 
-struct uri_and_node {
-       struct rpki_uri *uri;
+struct map_and_node {
+       struct cache_mapping *map;
        struct cache_node *node;
 };
 
 /* Separated because of unit tests. */
 static void
-__cache_recover(struct rpki_cache *cache, struct uri_list *uris,
-    struct uri_and_node *best)
+__cache_recover(struct rpki_cache *cache, struct map_list *maps,
+    struct map_and_node *best)
 {
-       struct rpki_uri **uri;
-       struct rpki_uri *url;
-       struct uri_and_node cursor;
+       struct cache_mapping **map;
+       struct cache_mapping *fixed;
+       struct map_and_node cursor;
 
-       ARRAYLIST_FOREACH(uris, uri) {
-               cursor.uri = *uri;
+       ARRAYLIST_FOREACH(maps, map) {
+               cursor.map = *map;
 
-               if (get_url(cursor.uri, &url) != 0)
+               if (fix_url(cursor.map, &fixed) != 0)
                        continue;
-               cursor.node = find_node(cache, url);
-               uri_refput(url);
+               cursor.node = find_node(cache, fixed);
+               map_refput(fixed);
                if (cursor.node == NULL)
                        continue;
 
@@ -843,12 +844,12 @@ __cache_recover(struct rpki_cache *cache, struct uri_list *uris,
        }
 }
 
-struct rpki_uri *
-cache_recover(struct rpki_cache *cache, struct uri_list *uris)
+struct cache_mapping *
+cache_recover(struct rpki_cache *cache, struct map_list *maps)
 {
-       struct uri_and_node best = { 0 };
-       __cache_recover(cache, uris, &best);
-       return best.uri;
+       struct map_and_node best = { 0 };
+       __cache_recover(cache, maps, &best);
+       return best.map;
 }
 
 void
@@ -858,8 +859,8 @@ cache_print(struct rpki_cache *cache)
 
        HASH_ITER(hh, cache->ht, node, tmp)
                printf("- %s (%s): %ssuccess error:%d\n",
-                   uri_get_local(node->url),
-                   uri_get_global(node->url),
+                   map_get_path(node->map),
+                   map_get_url(node->map),
                    node->success.happened ? "" : "!",
                    node->attempt.result);
 }
@@ -875,7 +876,7 @@ static void
 delete_node(struct rpki_cache *cache, struct cache_node *node)
 {
        HASH_DEL(cache->ht, node);
-       uri_refput(node->url);
+       map_refput(node->map);
        rrdp_notif_free(node->notif);
        free(node);
 }
@@ -883,13 +884,13 @@ delete_node(struct rpki_cache *cache, struct cache_node *node)
 static void
 delete_node_and_cage(struct rpki_cache *cache, struct cache_node *node)
 {
-       struct rpki_uri *cage;
+       struct cache_mapping *cage;
 
-       if (uri_get_type(node->url) == UT_NOTIF) {
-               if (uri_create_cage(&cage, node->url) == 0) {
-                       pr_op_debug("Deleting cage %s.", uri_get_local(cage));
-                       file_rm_rf(uri_get_local(cage));
-                       uri_refput(cage);
+       if (map_get_type(node->map) == MAP_NOTIF) {
+               if (map_create_cage(&cage, node->map) == 0) {
+                       pr_op_debug("Deleting cage %s.", map_get_path(cage));
+                       file_rm_rf(map_get_path(cage));
+                       map_refput(cage);
                }
        }
 
@@ -922,21 +923,21 @@ get_days_ago(int days)
 static void
 cleanup_tmp(struct rpki_cache *cache, struct cache_node *node)
 {
-       enum uri_type type;
+       enum map_type type;
        char const *path;
        int error;
 
-       type = uri_get_type(node->url);
-       if (type != UT_NOTIF && type != UT_TMP)
+       type = map_get_type(node->map);
+       if (type != MAP_NOTIF && type != MAP_TMP)
                return;
 
-       path = uri_get_local(node->url);
+       path = map_get_path(node->map);
        pr_op_debug("Deleting temporal file '%s'.", path);
        error = file_rm_f(path);
        if (error)
                pr_op_err("Could not delete '%s': %s", path, strerror(error));
 
-       if (type != UT_NOTIF)
+       if (type != MAP_NOTIF)
                delete_node(cache, node);
 }
 
@@ -947,8 +948,8 @@ cleanup_node(struct rpki_cache *cache, struct cache_node *node,
        char const *path;
        int error;
 
-       path = uri_get_local(node->url);
-       if (uri_get_type(node->url) == UT_NOTIF)
+       path = map_get_path(node->map);
+       if (map_get_type(node->map) == MAP_NOTIF)
                goto skip_file;
 
        error = file_exists(path);
@@ -962,7 +963,7 @@ cleanup_node(struct rpki_cache *cache, struct cache_node *node,
                return;
        default:
                pr_op_err("Trouble cleaning '%s'; stat() returned errno %d: %s",
-                   uri_op_get_printable(node->url), error, strerror(error));
+                   map_op_get_printable(node->map), error, strerror(error));
        }
 
 skip_file:
@@ -974,27 +975,27 @@ skip_file:
 }
 
 /*
- * "Do not clean." List of URIs that should not be deleted from the cache.
+ * "Do not clean." List of mappings that should not be deleted from the cache.
  * Global because nftw doesn't have a generic argument.
  */
-static struct uri_list dnc;
+static struct map_list dnc;
 static pthread_mutex_t dnc_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static bool
 is_cached(char const *_fpath)
 {
-       struct rpki_uri **node;
+       struct cache_mapping **node;
        char const *fpath, *npath;
        size_t c;
 
        /*
         * This relies on paths being normalized, which is currently done by the
-        * URI constructors.
+        * struct cache_mapping constructors.
         */
 
        ARRAYLIST_FOREACH(&dnc, node) {
                fpath = _fpath;
-               npath = uri_get_local(*node);
+               npath = map_get_path(*node);
 
                for (c = 0; fpath[c] == npath[c]; c++)
                        if (fpath[c] == '\0')
@@ -1030,7 +1031,7 @@ static void
 delete_unknown_files(struct rpki_cache *cache)
 {
        struct cache_node *node, *tmp;
-       struct rpki_uri *cage;
+       struct cache_mapping *cage;
        struct path_builder pb;
        int error;
 
@@ -1042,22 +1043,22 @@ delete_unknown_files(struct rpki_cache *cache)
        }
 
        mutex_lock(&dnc_lock);
-       uris_init(&dnc);
+       maps_init(&dnc);
 
-       uris_add(&dnc, uri_create_cache(pb.string));
+       maps_add(&dnc, map_create_cache(pb.string));
        HASH_ITER(hh, cache->ht, node, tmp) {
-               uri_refget(node->url);
-               uris_add(&dnc, node->url);
+               map_refget(node->map);
+               maps_add(&dnc, node->map);
 
-               if (uri_get_type(node->url) != UT_NOTIF)
+               if (map_get_type(node->map) != MAP_NOTIF)
                        continue;
 
-               if (uri_create_cage(&cage, node->url) != 0) {
+               if (map_create_cage(&cage, node->map) != 0) {
                        pr_op_err("Cannot generate %s's cage. I'm probably going to end up deleting it from the cache.",
-                           uri_op_get_printable(node->url));
+                           map_op_get_printable(node->map));
                        continue;
                }
-               uris_add(&dnc, cage);
+               maps_add(&dnc, cage);
        }
 
        pb_pop(&pb, true);
@@ -1067,7 +1068,7 @@ delete_unknown_files(struct rpki_cache *cache)
                pr_op_warn("The cache cleanup ended prematurely with error code %d (%s)",
                    error, strerror(error));
 
-       uris_cleanup(&dnc);
+       maps_cleanup(&dnc);
        mutex_unlock(&dnc_lock);
 
        pb_cleanup(&pb);
index 6ed99724e2252eddffa279fb6ec8d8d6f5581e2b..35d18cb286db0549f858bb1605ff9820449a41a5 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SRC_CACHE_LOCAL_CACHE_H_
 #define SRC_CACHE_LOCAL_CACHE_H_
 
-#include "types/uri.h"
+#include "types/map.h"
 
 struct rpki_cache;
 
@@ -16,23 +16,23 @@ void cache_destroy(struct rpki_cache *);
 
 struct cachefile_notification; /* FIXME */
 
-/* Downloads @uri into the cache */
-int cache_download(struct rpki_cache *, struct rpki_uri *uri, bool *,
+/* Downloads @map into the cache */
+int cache_download(struct rpki_cache *, struct cache_mapping *map, bool *,
     struct cachefile_notification ***);
 
 /*
  * The callback should return
  *
- * - 0 on success ("URI handled successfully")
- * - > 0 on soft errors ("Try another URI")
+ * - 0 on success ("Mapping handled successfully")
+ * - > 0 on soft errors ("Try another mapping")
  * - < 0 on hard errors ("Abandon foreach")
  */
-typedef int (*uris_dl_cb)(struct rpki_uri *, void *);
-int cache_download_alt(struct rpki_cache *, struct uri_list *, enum uri_type,
-    enum uri_type, uris_dl_cb, void *);
+typedef int (*maps_dl_cb)(struct cache_mapping *, void *);
+int cache_download_alt(struct rpki_cache *, struct map_list *, enum map_type,
+    enum map_type, maps_dl_cb, void *);
 
-/* Returns the most recent successfully cached URI of the list */
-struct rpki_uri *cache_recover(struct rpki_cache *, struct uri_list *);
+/* Returns the most recent successfully cached mapping of the list */
+struct cache_mapping *cache_recover(struct rpki_cache *, struct map_list *);
 /* Prints the cache in standard output. */
 void cache_print(struct rpki_cache *);
 
index be29978f6e3988302192cd5421344e729273c876..b1a725fb2957012c7246611fa3e230575e76585f 100644 (file)
@@ -41,7 +41,7 @@ STATIC_ARRAY_LIST(serial_numbers, struct serial_number)
  * Cached certificate data.
  */
 struct metadata_node {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        struct resources *resources;
        /*
         * Serial numbers of the children.
@@ -120,7 +120,7 @@ defer_destroy(struct defer_node *defer)
        case DNT_SEPARATOR:
                break;
        case DNT_CERT:
-               uri_refput(defer->deferred.uri);
+               map_refput(defer->deferred.map);
                rpp_refput(defer->deferred.pp);
                break;
        }
@@ -138,7 +138,7 @@ serial_cleanup(struct serial_number *serial)
 static void
 meta_destroy(struct metadata_node *meta)
 {
-       uri_refput(meta->uri);
+       map_refput(meta->map);
        resources_destroy(meta->resources);
        serial_numbers_cleanup(&meta->serials, serial_cleanup);
        free(meta);
@@ -184,7 +184,7 @@ deferstack_push(struct cert_stack *stack, struct deferred_cert *deferred)
 
        node->type = DNT_CERT;
        node->deferred = *deferred;
-       uri_refget(deferred->uri);
+       map_refget(deferred->map);
        rpp_refget(deferred->pp);
        SLIST_INSERT_HEAD(&stack->defers, node, next);
 }
@@ -228,7 +228,7 @@ again:      node = SLIST_FIRST(&stack->defers);
        }
 
        *result = node->deferred;
-       uri_refget(node->deferred.uri);
+       map_refget(node->deferred.map);
        rpp_refget(node->deferred.pp);
 
        SLIST_REMOVE_HEAD(&stack->defers, next);
@@ -288,7 +288,7 @@ create_separator(void)
 
 /** Steals ownership of @x509 on success. */
 int
-x509stack_push(struct cert_stack *stack, struct rpki_uri *uri, X509 *x509,
+x509stack_push(struct cert_stack *stack, struct cache_mapping *map, X509 *x509,
     enum rpki_policy policy, enum cert_type type)
 {
        struct metadata_node *meta;
@@ -298,7 +298,7 @@ x509stack_push(struct cert_stack *stack, struct rpki_uri *uri, X509 *x509,
 
        meta = pmalloc(sizeof(struct metadata_node));
 
-       meta->uri = uri_refget(uri);
+       meta->map = map_refget(map);
        serial_numbers_init(&meta->serials);
 
        error = init_resources(x509, policy, type, &meta->resources);
@@ -324,7 +324,7 @@ destroy_separator:
        resources_destroy(meta->resources);
 cleanup_serial:
        serial_numbers_cleanup(&meta->serials, serial_cleanup);
-       uri_refput(meta->uri);
+       map_refput(meta->map);
        free(meta);
        return error;
 }
@@ -357,11 +357,11 @@ x509stack_peek(struct cert_stack *stack)
 }
 
 /** Does not grab reference. */
-struct rpki_uri *
-x509stack_peek_uri(struct cert_stack *stack)
+struct cache_mapping *
+x509stack_peek_map(struct cert_stack *stack)
 {
        struct metadata_node *meta = SLIST_FIRST(&stack->metas);
-       return (meta != NULL) ? meta->uri : NULL;
+       return (meta != NULL) ? meta->map : NULL;
 }
 
 struct resources *
index 8801ea42d42367c5c4d312564a81c8a9e5fbb301..518b375092e21e03edf4e70ff0a0df238da4fef4 100644 (file)
@@ -6,7 +6,7 @@
 #include "object/certificate.h"
 #include "object/name.h"
 #include "resource.h"
-#include "types/uri.h"
+#include "types/map.h"
 
 /*
  * One certificate stack is allocated per validation cycle, and it is used
@@ -31,7 +31,7 @@
 struct cert_stack;
 
 struct deferred_cert {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        struct rpp *pp;
 };
 
@@ -42,11 +42,11 @@ void deferstack_push(struct cert_stack *, struct deferred_cert *cert);
 int deferstack_pop(struct cert_stack *, struct deferred_cert *cert);
 bool deferstack_is_empty(struct cert_stack *);
 
-int x509stack_push(struct cert_stack *, struct rpki_uri *, X509 *,
+int x509stack_push(struct cert_stack *, struct cache_mapping *, X509 *,
     enum rpki_policy, enum cert_type);
 void x509stack_cancel(struct cert_stack *);
 X509 *x509stack_peek(struct cert_stack *);
-struct rpki_uri *x509stack_peek_uri(struct cert_stack *);
+struct cache_mapping *x509stack_peek_map(struct cert_stack *);
 struct resources *x509stack_peek_resources(struct cert_stack *);
 void x509stack_store_serial(struct cert_stack *, BIGNUM *);
 typedef int (*subject_pk_check_cb)(bool *, char const *, void *);
index acbf3ba761e72d7227c783684709d520c5bb2359..cac3313eeb1e3354fd2b7c30a46817bb8658a549 100644 (file)
@@ -14,15 +14,15 @@ refs_cleanup(struct certificate_refs *refs)
 {
        free(refs->crldp);
        if (refs->caIssuers != NULL)
-               uri_refput(refs->caIssuers);
+               map_refput(refs->caIssuers);
        if (refs->signedObject != NULL)
-               uri_refput(refs->signedObject);
+               map_refput(refs->signedObject);
 }
 
 static int
 validate_cdp(struct certificate_refs *refs, struct rpp const *pp)
 {
-       struct rpki_uri *pp_crl;
+       struct cache_mapping *pp_crl;
 
        if (refs->crldp == NULL)
                pr_crit("Certificate's CRL Distribution Point was not recorded.");
@@ -31,9 +31,9 @@ validate_cdp(struct certificate_refs *refs, struct rpp const *pp)
        if (pp_crl == NULL)
                pr_crit("Manifest's CRL was not recorded.");
 
-       if (strcmp(refs->crldp, uri_get_global(pp_crl)) != 0) {
+       if (strcmp(refs->crldp, map_get_url(pp_crl)) != 0) {
                return pr_val_err("Certificate's CRL Distribution Point ('%s') does not match manifest's CRL ('%s').",
-                   refs->crldp, uri_get_global(pp_crl));
+                   refs->crldp, map_get_url(pp_crl));
        }
 
        return 0;
@@ -41,15 +41,15 @@ validate_cdp(struct certificate_refs *refs, struct rpp const *pp)
 
 static int
 validate_signedObject(struct certificate_refs *refs,
-    struct rpki_uri *signedObject_uri)
+    struct cache_mapping *signedObject_map)
 {
        if (refs->signedObject == NULL)
                pr_crit("Certificate's signedObject was not recorded.");
 
-       if (!uri_equals(refs->signedObject, signedObject_uri)) {
+       if (!map_equals(refs->signedObject, signedObject_map)) {
                return pr_val_err("Certificate's signedObject ('%s') does not match the URI of its own signed object (%s).",
-                   uri_val_get_printable(refs->signedObject),
-                   uri_val_get_printable(signedObject_uri));
+                   map_val_get_printable(refs->signedObject),
+                   map_val_get_printable(signedObject_map));
        }
 
        return 0;
@@ -73,7 +73,7 @@ refs_validate_ca(struct certificate_refs *refs, struct rpp const *pp)
 
        if (refs->signedObject != NULL)
                pr_crit("CA summary has a signedObject ('%s').",
-                   uri_op_get_printable(refs->signedObject));
+                   map_op_get_printable(refs->signedObject));
 
        return 0;
 }
@@ -84,11 +84,11 @@ refs_validate_ca(struct certificate_refs *refs, struct rpp const *pp)
  *
  * @refs: References you want validated.
  * @pp: Repository Publication Point, as described by the Manifest.
- * @uri: URL of the signed object that contains the EE certificate.
+ * @map: Mapping of the signed object that contains the EE certificate.
  */
 int
 refs_validate_ee(struct certificate_refs *refs, struct rpp const *pp,
-    struct rpki_uri *uri)
+    struct cache_mapping *map)
 {
        int error;
 
@@ -96,5 +96,5 @@ refs_validate_ee(struct certificate_refs *refs, struct rpp const *pp,
        if (error)
                return error;
 
-       return validate_signedObject(refs, uri);
+       return validate_signedObject(refs, map);
 }
index 17b8384f5ab852cf98d4a4cdea5708c64149128b..01794d12508fadc6b3b5c3dc23f687d64b1dbb20 100644 (file)
@@ -28,18 +28,18 @@ struct certificate_refs {
         * AIA's caIssuers. Non-TA certificates only.
         * RFC 6487, section 4.8.7.
         */
-       struct rpki_uri *caIssuers;
+       struct cache_mapping *caIssuers;
        /**
         * SIA's signedObject. EE certificates only.
         * RFC 6487, section 4.8.8.2.
         */
-       struct rpki_uri *signedObject;
+       struct cache_mapping *signedObject;
 };
 
 void refs_init(struct certificate_refs *);
 void refs_cleanup(struct certificate_refs *);
 int refs_validate_ca(struct certificate_refs *, struct rpp const *);
 int refs_validate_ee(struct certificate_refs *, struct rpp const *,
-    struct rpki_uri *);
+    struct cache_mapping *);
 
 #endif /* SRC_CERTIFICATE_REFS_H_ */
index 738e2732b83479764a23fbef53c7fc730006a8e5..74e7383131181537b78e6a763f07a8620efe5793 100644 (file)
@@ -282,23 +282,23 @@ create_dir(char const *path)
        return 0;
 }
 
-/* mkdir -p $path */
+/* mkdir -p $_path */
 int
-mkdir_p(char const *path, bool include_basename)
+mkdir_p(char const *_path, bool include_basename)
 {
-       char *localuri, *last_slash;
+       char *path, *last_slash;
        int i, result = 0;
 
-       localuri = pstrdup(path); /* Remove const */
+       path = pstrdup(_path); /* Remove const */
 
        if (!include_basename) {
-               last_slash = strrchr(localuri, '/');
+               last_slash = strrchr(path, '/');
                if (last_slash == NULL)
                        goto end;
                *last_slash = '\0';
        }
 
-       result = dir_exists(localuri); /* short circuit */
+       result = dir_exists(path); /* short circuit */
        if (result > 0) {
                result = 0;
                goto end;
@@ -306,19 +306,19 @@ mkdir_p(char const *path, bool include_basename)
                goto end;
        }
 
-       for (i = 1; localuri[i] != '\0'; i++) {
-               if (localuri[i] == '/') {
-                       localuri[i] = '\0';
-                       result = create_dir(localuri);
-                       localuri[i] = '/';
+       for (i = 1; path[i] != '\0'; i++) {
+               if (path[i] == '/') {
+                       path[i] = '\0';
+                       result = create_dir(path);
+                       path[i] = '/';
                        if (result != 0)
                                goto end; /* error msg already printed */
                }
        }
-       result = create_dir(localuri);
+       result = create_dir(path);
 
 end:
-       free(localuri);
+       free(path);
        return result;
 }
 
index 740621ccd41f940c3fed604906b048868690c56d..1b608f1df467d4bcb87524f885013e489456e3f6 100644 (file)
@@ -156,14 +156,15 @@ end:
 }
 
 int
-hash_validate_file(struct hash_algorithm const *algorithm, struct rpki_uri *uri,
-    unsigned char const *expected, size_t expected_len)
+hash_validate_file(struct hash_algorithm const *algorithm,
+    struct cache_mapping *map, unsigned char const *expected,
+    size_t expected_len)
 {
        unsigned char actual[EVP_MAX_MD_SIZE];
        size_t actual_len;
        int error;
 
-       error = hash_file(algorithm, uri_get_local(uri), actual, &actual_len);
+       error = hash_file(algorithm, map_get_path(map), actual, &actual_len);
        if (error)
                return error;
 
@@ -176,7 +177,7 @@ hash_validate_file(struct hash_algorithm const *algorithm, struct rpki_uri *uri,
 
 fail:
        return pr_val_err("File '%s' does not match its expected hash.",
-           uri_val_get_printable(uri));
+           map_val_get_printable(map));
 }
 
 static int
index 6426b1a36ec2ed6a204d9d4b183d2546d749d170..8d4c6c2ec888474b16b6596dc93fb64bebb1b4c8 100644 (file)
@@ -2,7 +2,7 @@
 #define SRC_HASH_H_
 
 #include <openssl/evp.h>
-#include "types/uri.h"
+#include "types/map.h"
 
 struct hash_algorithm;
 
@@ -15,7 +15,7 @@ struct hash_algorithm const *hash_get_sha256(void);
 int hash_file(struct hash_algorithm const *, char const *, unsigned char *,
     size_t *);
 
-int hash_validate_file(struct hash_algorithm const *, struct rpki_uri *,
+int hash_validate_file(struct hash_algorithm const *, struct cache_mapping *,
     unsigned char const *, size_t);
 int hash_validate(struct hash_algorithm const *, unsigned char const *, size_t,
     unsigned char const *, size_t);
index 4cc9b557300d40e3633ae6bc0dec10f696685eb1..1ddc4bee195ade88b9ff41f893be9cf3bfe9e877 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <netdb.h>
 
-#include "types/uri.h"
+#include "types/map.h"
 
 struct path_builder {
        char *string;
index e901f75c89632d0798b7e5c80aaeea3d522d5f3d..c58e7bc05bb790a70b9ccf03cb45f454298d3044 100644 (file)
@@ -367,7 +367,7 @@ end:        http_easy_cleanup(&handler);
 }
 
 /*
- * Download @uri->global into @uri->local; HTTP assumed.
+ * Download @map->url into @map->path; HTTP assumed.
  *
  * If @changed returns true, the file was downloaded normally.
  * If @changed returns false, the file has not been modified since @ims.
@@ -377,21 +377,21 @@ end:      http_easy_cleanup(&handler);
  * If @changed is not NULL, initialize it to false.
  */
 int
-http_download(struct rpki_uri *uri, curl_off_t ims, bool *changed)
+http_download(struct cache_mapping *map, curl_off_t ims, bool *changed)
 {
        unsigned int r;
        int error;
 
-       pr_val_info("HTTP GET: %s -> %s", uri_get_global(uri), uri_get_local(uri));
+       pr_val_info("HTTP GET: %s -> %s", map_get_url(map), map_get_path(map));
 
-       error = mkdir_p(uri_get_local(uri), false);
+       error = mkdir_p(map_get_path(map), false);
        if (error)
                return error;
 
        for (r = 0; true; r++) {
                pr_val_debug("Download attempt #%u...", r + 1);
 
-               error = http_fetch(uri_get_global(uri), uri_get_local(uri),
+               error = http_fetch(map_get_url(map), map_get_path(map),
                    ims, changed);
                switch (error) {
                case 0:
index 2a446dc86a0caf815d1a3508c2d2f547d76c84c5..c1a0a21effe958d2f4aa4d40b34863e769c721b9 100644 (file)
@@ -2,12 +2,12 @@
 #define SRC_HTTP_HTTP_H_
 
 #include <curl/curl.h>
-#include "types/uri.h"
+#include "types/map.h"
 
 int http_init(void);
 void http_cleanup(void);
 
-int http_download(struct rpki_uri *, curl_off_t, bool *);
+int http_download(struct cache_mapping *, curl_off_t, bool *);
 int http_download_direct(char const *, char const *);
 
 #endif /* SRC_HTTP_HTTP_H_ */
index 411e7866e126e2050a44be2321d7c7eb3059d7b0..cf7294c9014bc9fbc954fe78af2f2a3ffbf47b78 100644 (file)
@@ -47,8 +47,8 @@ struct ski_arguments {
 };
 
 struct sia_uris {
-       struct uri_list rpp;
-       struct rpki_uri *mft;
+       struct map_list rpp;
+       struct cache_mapping *mft;
 };
 
 struct bgpsec_ski {
@@ -62,7 +62,7 @@ typedef int (access_method_exec)(struct sia_uris *);
 struct ad_metadata {
        char const *name;
        char const *ia_name;
-       enum uri_type type;
+       enum map_type type;
        char const *type_str;
        bool required;
 };
@@ -70,7 +70,7 @@ struct ad_metadata {
 static const struct ad_metadata CA_ISSUERS = {
        .name = "caIssuers",
        .ia_name = "AIA",
-       .type = UT_AIA,
+       .type = MAP_AIA,
        .type_str = "rsync",
        .required = true,
 };
@@ -78,7 +78,7 @@ static const struct ad_metadata CA_ISSUERS = {
 static const struct ad_metadata SIGNED_OBJECT = {
        .name = "signedObject",
        .ia_name = "SIA",
-       .type = UT_SO,
+       .type = MAP_SO,
        .type_str = "rsync",
        .required = true,
 };
@@ -86,7 +86,7 @@ static const struct ad_metadata SIGNED_OBJECT = {
 static const struct ad_metadata CA_REPOSITORY = {
        .name = "caRepository",
        .ia_name = "SIA",
-       .type = UT_RPP,
+       .type = MAP_RPP,
        .type_str = "rsync",
        .required = false,
 };
@@ -94,7 +94,7 @@ static const struct ad_metadata CA_REPOSITORY = {
 static const struct ad_metadata RPKI_NOTIFY = {
        .name = "rpkiNotify",
        .ia_name = "SIA",
-       .type = UT_NOTIF,
+       .type = MAP_NOTIF,
        .type_str = "HTTPS",
        .required = false,
 };
@@ -102,7 +102,7 @@ static const struct ad_metadata RPKI_NOTIFY = {
 static const struct ad_metadata RPKI_MANIFEST = {
        .name = "rpkiManifest",
        .ia_name = "SIA",
-       .type = UT_MFT,
+       .type = MAP_MFT,
        .type_str = "rsync",
        .required = true,
 };
@@ -110,15 +110,15 @@ static const struct ad_metadata RPKI_MANIFEST = {
 static void
 sia_uris_init(struct sia_uris *uris)
 {
-       uris_init(&uris->rpp);
+       maps_init(&uris->rpp);
        uris->mft = NULL;
 }
 
 static void
 sia_uris_cleanup(struct sia_uris *uris)
 {
-       uris_cleanup(&uris->rpp);
-       uri_refput(uris->mft);
+       maps_cleanup(&uris->rpp);
+       map_refput(uris->mft);
 }
 
 static void
@@ -807,7 +807,7 @@ end:
 }
 
 static int
-certificate_load(struct rpki_uri *uri, X509 **result)
+certificate_load(struct cache_mapping *map, X509 **result)
 {
        X509 *cert = NULL;
        BIO *bio;
@@ -818,7 +818,7 @@ certificate_load(struct rpki_uri *uri, X509 **result)
        bio = BIO_new(BIO_s_file());
        if (bio == NULL)
                return val_crypto_err("BIO_new(BIO_s_file()) returned NULL");
-       if (BIO_read_filename(bio, uri_get_local(uri)) <= 0) {
+       if (BIO_read_filename(bio, map_get_path(map)) <= 0) {
                error = val_crypto_err("Error reading certificate");
                goto end;
        }
@@ -1199,39 +1199,39 @@ is_rsync(ASN1_IA5STRING *uri)
 }
 
 static int
-handle_rpkiManifest(struct rpki_uri *uri, void *arg)
+handle_rpkiManifest(struct cache_mapping *map, void *arg)
 {
        struct sia_uris *uris = arg;
-       uris->mft = uri_refget(uri);
+       uris->mft = map_refget(map);
        return 0;
 }
 
 static int
-handle_caRepository(struct rpki_uri *uri, void *arg)
+handle_caRepository(struct cache_mapping *map, void *arg)
 {
        struct sia_uris *uris = arg;
-       pr_val_debug("caRepository: %s", uri_val_get_printable(uri));
-       uris_add(&uris->rpp, uri);
-       uri_refget(uri);
+       pr_val_debug("caRepository: %s", map_val_get_printable(map));
+       maps_add(&uris->rpp, map);
+       map_refget(map);
        return 0;
 }
 
 static int
-handle_rpkiNotify(struct rpki_uri *uri, void *arg)
+handle_rpkiNotify(struct cache_mapping *map, void *arg)
 {
        struct sia_uris *uris = arg;
-       pr_val_debug("rpkiNotify: %s", uri_val_get_printable(uri));
-       uris_add(&uris->rpp, uri);
-       uri_refget(uri);
+       pr_val_debug("rpkiNotify: %s", map_val_get_printable(map));
+       maps_add(&uris->rpp, map);
+       map_refget(map);
        return 0;
 }
 
 static int
-handle_signedObject(struct rpki_uri *uri, void *arg)
+handle_signedObject(struct cache_mapping *map, void *arg)
 {
        struct certificate_refs *refs = arg;
-       pr_val_debug("signedObject: %s", uri_val_get_printable(uri));
-       refs->signedObject = uri_refget(uri);
+       pr_val_debug("signedObject: %s", map_val_get_printable(map));
+       refs->signedObject = map_refget(map);
        return 0;
 }
 
@@ -1428,10 +1428,11 @@ dist_point_error:
 }
 
 /*
- * Create @uri from the @ad
+ * Create @map from the @ad
  */
 static int
-uri_create_ad(struct rpki_uri **uri, ACCESS_DESCRIPTION *ad, enum uri_type type)
+map_create_ad(struct cache_mapping **map, ACCESS_DESCRIPTION *ad,
+    enum map_type type)
 {
        ASN1_STRING *asn1str;
        char *str;
@@ -1455,8 +1456,7 @@ uri_create_ad(struct rpki_uri **uri, ACCESS_DESCRIPTION *ad, enum uri_type type)
         * URIs.
         *
         * Also, nobody seems to be using the other types, and handling them
-        * would be a titanic pain in the ass. So this is what I'm committing
-        * to.
+        * would be a titanic pain. So this is what I'm committing to.
         */
        if (ptype != GEN_URI) {
                pr_val_err("Unknown GENERAL_NAME type: %d", ptype);
@@ -1478,7 +1478,7 @@ uri_create_ad(struct rpki_uri **uri, ACCESS_DESCRIPTION *ad, enum uri_type type)
        str = pstrndup((char const *)ASN1_STRING_get0_data(asn1str),
            ASN1_STRING_length(asn1str));
 
-       error = uri_create(uri, type, NULL, str);
+       error = map_create(map, type, NULL, str);
 
        free(str);
        return error;
@@ -1503,10 +1503,10 @@ uri_create_ad(struct rpki_uri **uri, ACCESS_DESCRIPTION *ad, enum uri_type type)
  */
 static int
 handle_ad(int nid, struct ad_metadata const *meta, SIGNATURE_INFO_ACCESS *ia,
-    int (*cb)(struct rpki_uri *, void *), void *arg)
+    int (*cb)(struct cache_mapping *, void *), void *arg)
 {
        ACCESS_DESCRIPTION *ad;
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        bool found;
        unsigned int i;
        int error;
@@ -1515,7 +1515,7 @@ handle_ad(int nid, struct ad_metadata const *meta, SIGNATURE_INFO_ACCESS *ia,
        for (i = 0; i < sk_ACCESS_DESCRIPTION_num(ia); i++) {
                ad = sk_ACCESS_DESCRIPTION_value(ia, i);
                if (OBJ_obj2nid(ad->method) == nid) {
-                       error = uri_create_ad(&uri, ad, meta->type);
+                       error = map_create_ad(&map, ad, meta->type);
                        switch (error) {
                        case 0:
                                break;
@@ -1528,18 +1528,18 @@ handle_ad(int nid, struct ad_metadata const *meta, SIGNATURE_INFO_ACCESS *ia,
                        }
 
                        if (found) {
-                               uri_refput(uri);
+                               map_refput(map);
                                return pr_val_err("Extension '%s' has multiple '%s' %s URIs.",
                                    meta->ia_name, meta->name, meta->type_str);
                        }
 
-                       error = cb(uri, arg);
+                       error = cb(map, arg);
                        if (error) {
-                               uri_refput(uri);
+                               map_refput(map);
                                return error;
                        }
 
-                       uri_refput(uri);
+                       map_refput(map);
                        found = true;
                }
        }
@@ -1554,7 +1554,7 @@ handle_ad(int nid, struct ad_metadata const *meta, SIGNATURE_INFO_ACCESS *ia,
 }
 
 static int
-handle_caIssuers(struct rpki_uri *uri, void *arg)
+handle_caIssuers(struct cache_mapping *map, void *arg)
 {
        struct certificate_refs *refs = arg;
        /*
@@ -1562,7 +1562,7 @@ handle_caIssuers(struct rpki_uri *uri, void *arg)
         * over here is too much trouble, so do the handle_cdp()
         * hack.
         */
-       refs->caIssuers = uri_refget(uri);
+       refs->caIssuers = map_refget(map);
        return 0;
 }
 
@@ -1654,9 +1654,6 @@ handle_cp(void *ext, void *arg)
 
 /**
  * Validates the certificate extensions, Trust Anchor style.
- *
- * Depending on the Access Description preference at SIA, the rpki_uri's at
- * @sia_uris will be allocated.
  */
 static int
 certificate_validate_extensions_ta(X509 *cert, struct sia_uris *sia_uris,
@@ -1685,8 +1682,6 @@ certificate_validate_extensions_ta(X509 *cert, struct sia_uris *sia_uris,
  * Validates the certificate extensions, (intermediate) Certificate Authority
  * style.
  *
- * Depending on the Access Description preference at SIA, the rpki_uri's at
- * @sia_uris will be allocated.
  * Also initializes the fourth argument with the references found in the
  * extensions.
  */
@@ -1815,7 +1810,7 @@ err:
 }
 
 int
-certificate_validate_aia(struct rpki_uri *caIssuers, X509 *cert)
+certificate_validate_aia(struct cache_mapping *caIssuers, X509 *cert)
 {
        /*
         * FIXME Compare the AIA to the parent's URI.
@@ -1826,17 +1821,17 @@ certificate_validate_aia(struct rpki_uri *caIssuers, X509 *cert)
 }
 
 static int
-retrieve_uri(struct rpki_uri *uri, void *arg)
+retrieve_mapping(struct cache_mapping *map, void *arg)
 {
-       struct rpki_uri **result = arg;
-       *result = uri;
+       struct cache_mapping **result = arg;
+       *result = map;
        return 0;
 }
 
-static struct rpki_uri *
+static struct cache_mapping *
 download_rpp(struct sia_uris *uris)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
        if (uris->rpp.len == 0) {
@@ -1845,20 +1840,20 @@ download_rpp(struct sia_uris *uris)
        }
 
        error = cache_download_alt(validation_cache(state_retrieve()),
-           &uris->rpp, UT_NOTIF, UT_RPP, retrieve_uri, &uri);
-       return error ? NULL : uri;
+           &uris->rpp, MAP_NOTIF, MAP_RPP, retrieve_mapping, &map);
+       return error ? NULL : map;
 }
 
 /** Boilerplate code for CA certificate validation and recursive traversal. */
 int
-certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
+certificate_traverse(struct rpp *rpp_parent, struct cache_mapping *cert_map)
 {
        struct validation *state;
        int total_parents;
        STACK_OF(X509_CRL) *rpp_parent_crl;
        X509 *cert;
        struct sia_uris sia_uris;
-       struct rpki_uri *downloaded;
+       struct cache_mapping *downloaded;
        enum rpki_policy policy;
        enum cert_type certype;
        struct rpp *pp;
@@ -1873,19 +1868,19 @@ certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
        /* Debug cert type */
        if (rpp_parent == NULL)
                pr_val_debug("TA Certificate '%s' {",
-                   uri_val_get_printable(cert_uri));
+                   map_val_get_printable(cert_map));
        else
                pr_val_debug("Certificate '%s' {",
-                   uri_val_get_printable(cert_uri));
+                   map_val_get_printable(cert_map));
 
-       fnstack_push_uri(cert_uri);
+       fnstack_push_map(cert_map);
 
        error = rpp_crl(rpp_parent, &rpp_parent_crl);
        if (error)
                goto revert_fnstack_and_debug;
 
        /* -- Validate the certificate (@cert) -- */
-       error = certificate_load(cert_uri, &cert);
+       error = certificate_load(cert_map, &cert);
        if (error)
                goto revert_fnstack_and_debug;
        error = certificate_validate_chain(cert, rpp_parent_crl);
@@ -1931,14 +1926,14 @@ certificate_traverse(struct rpp *rpp_parent, struct rpki_uri *cert_uri)
                goto revert_uris;
        }
 
-       error = x509stack_push(validation_certstack(state), cert_uri, cert,
+       error = x509stack_push(validation_certstack(state), cert_map, cert,
            policy, certype);
        if (error)
                goto revert_uris;
        cert = NULL; /* Ownership stolen */
 
        error = handle_manifest(sia_uris.mft,
-           (uri_get_type(downloaded) == UT_NOTIF) ? downloaded : NULL,
+           (map_get_type(downloaded) == MAP_NOTIF) ? downloaded : NULL,
            &pp);
        if (error) {
                x509stack_cancel(validation_certstack(state));
index 8045425896a03024a811da5eb1201f198e64b36e..b2b68acea795d5e73db9d481bf24a0c280f0510a 100644 (file)
@@ -6,7 +6,7 @@
 #include "certificate_refs.h"
 #include "resource.h"
 #include "rpp.h"
-#include "types/uri.h"
+#include "types/map.h"
 
 /* Certificate types in the RPKI */
 enum cert_type {
@@ -55,8 +55,8 @@ int certificate_validate_extensions_bgpsec(X509 *, unsigned char **,
  * Specific validation of AIA (rfc6487#section-4.8.7) extension, public so that
  * CAs and EEs can access it.
  */
-int certificate_validate_aia(struct rpki_uri *, X509 *);
+int certificate_validate_aia(struct cache_mapping *, X509 *);
 
-int certificate_traverse(struct rpp *, struct rpki_uri *);
+int certificate_traverse(struct rpp *, struct cache_mapping *);
 
 #endif /* SRC_OBJECT_CERTIFICATE_H_ */
index 78e9bfbed22e5bab0ec7ac413de32743a3f196fc..4b0aa8895a2530d4f2ca66dd261d50fe962447df 100644 (file)
@@ -11,7 +11,7 @@
 #include "thread_var.h"
 
 static int
-__crl_load(struct rpki_uri *uri, X509_CRL **result)
+__crl_load(struct cache_mapping *map, X509_CRL **result)
 {
        X509_CRL *crl;
        BIO *bio;
@@ -20,16 +20,16 @@ __crl_load(struct rpki_uri *uri, X509_CRL **result)
        bio = BIO_new(BIO_s_file());
        if (bio == NULL)
                return val_crypto_err("BIO_new(BIO_s_file()) returned NULL");
-       if (BIO_read_filename(bio, uri_get_local(uri)) <= 0) {
+       if (BIO_read_filename(bio, map_get_path(map)) <= 0) {
                error = val_crypto_err("Error reading CRL '%s'",
-                   uri_val_get_printable(uri));
+                   map_val_get_printable(map));
                goto end;
        }
 
        crl = d2i_X509_CRL_bio(bio, NULL);
        if (crl == NULL) {
                error = val_crypto_err("Error parsing CRL '%s'",
-                   uri_val_get_printable(uri));
+                   map_val_get_printable(map));
                goto end;
        }
 
@@ -152,13 +152,13 @@ crl_validate(X509_CRL *crl)
 }
 
 int
-crl_load(struct rpki_uri *uri, X509_CRL **result)
+crl_load(struct cache_mapping *map, X509_CRL **result)
 {
        int error;
 
-       pr_val_debug("CRL '%s' {", uri_val_get_printable(uri));
+       pr_val_debug("CRL '%s' {", map_val_get_printable(map));
 
-       error = __crl_load(uri, result);
+       error = __crl_load(map, result);
        if (error)
                goto end;
 
index 7aacffdf4b362418c093a08fd5b763b131fc5719..6e4915bc6b112a4f1e745734f2a47c957d05c3b6 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <openssl/x509.h>
 
-#include "types/uri.h"
+#include "types/map.h"
 
-int crl_load(struct rpki_uri *uri, X509_CRL **);
+int crl_load(struct cache_mapping *, X509_CRL **);
 
 #endif /* SRC_OBJECT_CRL_H_ */
index b25cc0843506730db80fb22e7d0f861940e3513c..ec8ec64c9a96578391fc226301b10ad36525e236 100644 (file)
@@ -15,7 +15,7 @@ handle_vcard(struct signed_object *sobj)
 }
 
 int
-ghostbusters_traverse(struct rpki_uri *uri, struct rpp *pp)
+ghostbusters_traverse(struct cache_mapping *map, struct rpp *pp)
 {
        static OID oid = OID_GHOSTBUSTERS;
        struct oid_arcs arcs = OID2ARCS("ghostbusters", oid);
@@ -25,11 +25,11 @@ ghostbusters_traverse(struct rpki_uri *uri, struct rpp *pp)
        int error;
 
        /* Prepare */
-       pr_val_debug("Ghostbusters '%s' {", uri_val_get_printable(uri));
-       fnstack_push_uri(uri);
+       pr_val_debug("Ghostbusters '%s' {", map_val_get_printable(map));
+       fnstack_push_map(map);
 
        /* Decode */
-       error = signed_object_decode(&sobj, uri);
+       error = signed_object_decode(&sobj, map);
        if (error)
                goto revert_log;
 
@@ -46,7 +46,7 @@ ghostbusters_traverse(struct rpki_uri *uri, struct rpp *pp)
        error = handle_vcard(&sobj);
        if (error)
                goto revert_args;
-       error = refs_validate_ee(&ee.refs, pp, uri);
+       error = refs_validate_ee(&ee.refs, pp, map);
 
 revert_args:
        eecert_cleanup(&ee);
index f93db38b954f291071fcf6defa4e8d1e67a1d1b8..7f0454d65648900e55398fca47874011a7215e94 100644 (file)
@@ -2,8 +2,8 @@
 #define SRC_OBJECT_GHOSTBUSTERS_H_
 
 #include "rpp.h"
-#include "types/uri.h"
+#include "types/map.h"
 
-int ghostbusters_traverse(struct rpki_uri *, struct rpp *);
+int ghostbusters_traverse(struct cache_mapping *, struct rpp *);
 
 #endif /* SRC_OBJECT_GHOSTBUSTERS_H_ */
index 4de10a8a2fb0fbdb4f4012441ba5bd5cb10f298d..e1ed8575a1e84a023761c5963989d8cdbb8d3fca 100644 (file)
 #include "thread_var.h"
 
 static int
-cage(struct rpki_uri **uri, struct rpki_uri *notif)
+cage(struct cache_mapping **map, struct cache_mapping *notif)
 {
        if (notif == NULL) {
                /* No need to cage */
-               uri_refget(*uri);
+               map_refget(*map);
                return 0;
        }
 
-       return uri_create_caged(uri, notif, uri_get_global(*uri));
+       return map_create_caged(map, notif, map_get_url(*map));
 }
 
 static int
@@ -186,7 +186,7 @@ validate_manifest(struct Manifest *manifest)
 }
 
 /**
- * Computes the hash of the file @uri, and compares it to @expected (The
+ * Computes the hash of the file @map, and compares it to @expected (The
  * "expected" hash).
  *
  * Returns:
@@ -197,7 +197,7 @@ validate_manifest(struct Manifest *manifest)
  *     an incidence to ignore this).
  */
 static int
-hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *expected)
+hash_validate_mft_file(struct cache_mapping *map, BIT_STRING_t const *expected)
 {
        struct hash_algorithm const *algorithm;
        size_t hash_size;
@@ -218,13 +218,13 @@ hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *expected)
         * hash_validate_file().
         */
 
-       error = hash_file(algorithm, uri_get_local(uri), actual, NULL);
+       error = hash_file(algorithm, map_get_path(map), actual, NULL);
        if (error) {
                if (error == EACCES || error == ENOENT) {
                        /* FIXME .................. */
                        if (incidence(INID_MFT_FILE_NOT_FOUND,
                            "File '%s' listed at manifest doesn't exist.",
-                           uri_val_get_printable(uri)))
+                           map_val_get_printable(map)))
                                return -EINVAL;
 
                        return error;
@@ -236,19 +236,19 @@ hash_validate_mft_file(struct rpki_uri *uri, BIT_STRING_t const *expected)
        if (memcmp(expected->buf, actual, hash_size) != 0) {
                return incidence(INID_MFT_FILE_HASH_NOT_MATCH,
                    "File '%s' does not match its manifest hash.",
-                   uri_val_get_printable(uri));
+                   map_val_get_printable(map));
        }
 
        return 0;
 }
 
 static int
-build_rpp(struct Manifest *mft, struct rpki_uri *notif,
-    struct rpki_uri *mft_uri, struct rpp **pp)
+build_rpp(struct Manifest *mft, struct cache_mapping *notif,
+    struct cache_mapping *mft_map, struct rpp **pp)
 {
        int i;
        struct FileAndHash *fah;
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
        *pp = rpp_create();
@@ -256,7 +256,7 @@ build_rpp(struct Manifest *mft, struct rpki_uri *notif,
        for (i = 0; i < mft->fileList.list.count; i++) {
                fah = mft->fileList.list.array[i];
 
-               error = uri_create_mft(&uri, notif, mft_uri, &fah->file);
+               error = map_create_mft(&map, notif, mft_map, &fah->file);
                /*
                 * Not handling ENOTRSYNC is fine because the manifest URL
                 * should have been RSYNC. Something went wrong if an RSYNC URL
@@ -275,29 +275,29 @@ build_rpp(struct Manifest *mft, struct rpki_uri *notif,
                 * - Positive value: file doesn't exist and keep validating
                 *   manifest.
                 */
-               error = hash_validate_mft_file(uri, &fah->hash);
+               error = hash_validate_mft_file(map, &fah->hash);
                if (error < 0) {
-                       uri_refput(uri);
+                       map_refput(map);
                        goto fail;
                }
                if (error > 0) {
-                       uri_refput(uri);
+                       map_refput(map);
                        continue;
                }
 
-               if (uri_has_extension(uri, ".cer"))
-                       rpp_add_cert(*pp, uri);
-               else if (uri_has_extension(uri, ".roa"))
-                       rpp_add_roa(*pp, uri);
-               else if (uri_has_extension(uri, ".crl"))
-                       error = rpp_add_crl(*pp, uri);
-               else if (uri_has_extension(uri, ".gbr"))
-                       rpp_add_ghostbusters(*pp, uri);
+               if (map_has_extension(map, ".cer"))
+                       rpp_add_cert(*pp, map);
+               else if (map_has_extension(map, ".roa"))
+                       rpp_add_roa(*pp, map);
+               else if (map_has_extension(map, ".crl"))
+                       error = rpp_add_crl(*pp, map);
+               else if (map_has_extension(map, ".gbr"))
+                       rpp_add_ghostbusters(*pp, map);
                else
-                       uri_refput(uri); /* ignore it. */
+                       map_refput(map); /* ignore it. */
 
                if (error) {
-                       uri_refput(uri);
+                       map_refput(map);
                        goto fail;
                } /* Otherwise ownership was transferred to @pp. */
        }
@@ -316,11 +316,12 @@ fail:
 }
 
 /**
- * Validates the manifest pointed by @uri, returns the RPP described by it in
+ * Validates the manifest pointed by @map, returns the RPP described by it in
  * @pp.
  */
 int
-handle_manifest(struct rpki_uri *uri, struct rpki_uri *notif, struct rpp **pp)
+handle_manifest(struct cache_mapping *map, struct cache_mapping *notif,
+    struct rpp **pp)
 {
        static OID oid = OID_MANIFEST;
        struct oid_arcs arcs = OID2ARCS("manifest", oid);
@@ -331,14 +332,14 @@ handle_manifest(struct rpki_uri *uri, struct rpki_uri *notif, struct rpp **pp)
        int error;
 
        /* Prepare */
-       error = cage(&uri, notif); /* ref++ */
+       error = cage(&map, notif); /* ref++ */
        if (error)
                return error;
-       pr_val_debug("Manifest '%s' {", uri_val_get_printable(uri));
-       fnstack_push_uri(uri);
+       pr_val_debug("Manifest '%s' {", map_val_get_printable(map));
+       fnstack_push_map(map);
 
        /* Decode */
-       error = signed_object_decode(&sobj, uri);
+       error = signed_object_decode(&sobj, map);
        if (error)
                goto revert_log;
        error = decode_manifest(&sobj, &mft);
@@ -346,7 +347,7 @@ handle_manifest(struct rpki_uri *uri, struct rpki_uri *notif, struct rpp **pp)
                goto revert_sobj;
 
        /* Initialize out parameter (@pp) */
-       error = build_rpp(mft, notif, uri, pp);
+       error = build_rpp(mft, notif, map, pp);
        if (error)
                goto revert_manifest;
 
@@ -363,7 +364,7 @@ handle_manifest(struct rpki_uri *uri, struct rpki_uri *notif, struct rpp **pp)
        error = validate_manifest(mft);
        if (error)
                goto revert_args;
-       error = refs_validate_ee(&ee.refs, *pp, uri);
+       error = refs_validate_ee(&ee.refs, *pp, map);
        if (error)
                goto revert_args;
 
@@ -382,6 +383,6 @@ revert_sobj:
 revert_log:
        pr_val_debug("}");
        fnstack_pop();
-       uri_refput(uri); /* ref-- */
+       map_refput(map); /* ref-- */
        return error;
 }
index fa55a6f32bd6c2f80c6ac2197f50ed10db290681..6ec44118ea3adb9a3ff04ef34709b83526adca0a 100644 (file)
@@ -3,6 +3,6 @@
 
 #include "rpp.h"
 
-int handle_manifest(struct rpki_uri *, struct rpki_uri *, struct rpp **);
+int handle_manifest(struct cache_mapping *, struct cache_mapping *, struct rpp **);
 
 #endif /* SRC_OBJECT_MANIFEST_H_ */
index 42e0379fb39b764ef0dbca72cc2a7b60c9508695..63b810d2300d785c6db6a1230be0e7820b816a26 100644 (file)
@@ -247,7 +247,7 @@ end_error:
 }
 
 int
-roa_traverse(struct rpki_uri *uri, struct rpp *pp)
+roa_traverse(struct cache_mapping *map, struct rpp *pp)
 {
        static OID oid = OID_ROA;
        struct oid_arcs arcs = OID2ARCS("roa", oid);
@@ -258,11 +258,11 @@ roa_traverse(struct rpki_uri *uri, struct rpp *pp)
        int error;
 
        /* Prepare */
-       pr_val_debug("ROA '%s' {", uri_val_get_printable(uri));
-       fnstack_push_uri(uri);
+       pr_val_debug("ROA '%s' {", map_val_get_printable(map));
+       fnstack_push_map(map);
 
        /* Decode */
-       error = signed_object_decode(&sobj, uri);
+       error = signed_object_decode(&sobj, map);
        if (error)
                goto revert_log;
        error = decode_roa(&sobj, &roa);
@@ -282,7 +282,7 @@ roa_traverse(struct rpki_uri *uri, struct rpp *pp)
        error = __handle_roa(roa, ee.res);
        if (error)
                goto revert_args;
-       error = refs_validate_ee(&ee.refs, pp, uri);
+       error = refs_validate_ee(&ee.refs, pp, map);
 
 revert_args:
        eecert_cleanup(&ee);
index e8de49b541f08afe39a06de3282da3aedcdcae07..310930053612e1807d4046d518f4dae26d5e669b 100644 (file)
@@ -3,8 +3,8 @@
 
 #include "rpp.h"
 #include "types/address.h"
-#include "types/uri.h"
+#include "types/map.h"
 
-int roa_traverse(struct rpki_uri *, struct rpp *);
+int roa_traverse(struct cache_mapping *, struct rpp *);
 
 #endif /* SRC_OBJECT_ROA_H_ */
index 0ed8805f3decb60097b99967923f048716334a78..cb80aa81755605d224b6c2ecd4b9ee405c745872 100644 (file)
@@ -4,11 +4,11 @@
 #include "log.h"
 
 int
-signed_object_decode(struct signed_object *sobj, struct rpki_uri *uri)
+signed_object_decode(struct signed_object *sobj, struct cache_mapping *map)
 {
        int error;
 
-       error = content_info_load(uri_get_local(uri), &sobj->cinfo);
+       error = content_info_load(map_get_path(map), &sobj->cinfo);
        if (error)
                return error;
 
index 07cfdf1ab54ce6786a2e705cc63d0e5be50a12d3..e6c2aba9063bfd0e6f19739516222563843ca468 100644 (file)
@@ -9,7 +9,7 @@ struct signed_object {
        struct SignedData *sdata;
 };
 
-int signed_object_decode(struct signed_object *, struct rpki_uri *);
+int signed_object_decode(struct signed_object *, struct cache_mapping *);
 int signed_object_validate(struct signed_object *, struct oid_arcs const *,
     struct ee_cert *);
 void signed_object_cleanup(struct signed_object *);
index a46588ff21b2c02c253db23639193ae7ecced2a3..ee072b935b4a2c8a5740a54527129de7fc073d7b 100644 (file)
 #include "rtr/db/vrps.h"
 #include "cache/local_cache.h"
 
-typedef int (*foreach_uri_cb)(struct tal *, struct rpki_uri *, void *);
+typedef int (*foreach_map_cb)(struct tal *, struct cache_mapping *, void *);
 
 struct tal {
        char const *file_name;
-       struct uri_list uris;
+       struct map_list maps;
        unsigned char *spki; /* Decoded; not base64. */
        size_t spki_len;
 
@@ -71,21 +71,21 @@ is_blank(char const *str)
 }
 
 static int
-add_uri(struct tal *tal, char *uri)
+add_url(struct tal *tal, char *url)
 {
-       struct rpki_uri *new = NULL;
+       struct cache_mapping *new = NULL;
        int error;
 
-       if (str_starts_with(uri, "rsync://"))
-               error = uri_create(&new, UT_TA_RSYNC, NULL, uri);
-       else if (str_starts_with(uri, "https://"))
-               error = uri_create(&new, UT_TA_HTTP, NULL, uri);
+       if (str_starts_with(url, "rsync://"))
+               error = map_create(&new, MAP_TA_RSYNC, NULL, url);
+       else if (str_starts_with(url, "https://"))
+               error = map_create(&new, MAP_TA_HTTP, NULL, url);
        else
-               return pr_op_err("TAL has non-rsync/HTTPS URI: %s", uri);
+               return pr_op_err("TAL has non-rsync/HTTPS URI: %s", url);
        if (error)
                return error;
 
-       uris_add(&tal->uris, new);
+       maps_add(&tal->maps, new);
        return 0;
 }
 
@@ -115,7 +115,7 @@ read_content(char *fc /* File Content */, struct tal *tal)
                if (is_blank(fc))
                        break;
 
-               error = add_uri(tal, fc);
+               error = add_url(tal, fc);
                if (error)
                        return error;
 
@@ -124,7 +124,7 @@ read_content(char *fc /* File Content */, struct tal *tal)
                        return pr_op_err("The TAL seems to be missing the public key.");
        } while (true);
 
-       if (tal->uris.len == 0)
+       if (tal->maps.len == 0)
                return pr_op_err("There seems to be an empty/blank line before the end of the URI section.");
 
        /* subjectPublicKeyInfo section */
@@ -156,10 +156,10 @@ tal_init(struct tal *tal, char const *file_path)
        file_name = (file_name != NULL) ? (file_name + 1) : file_path;
        tal->file_name = file_name;
 
-       uris_init(&tal->uris);
+       maps_init(&tal->maps);
        error = read_content((char *)file.buffer, tal);
        if (error) {
-               uris_cleanup(&tal->uris);
+               maps_cleanup(&tal->maps);
                goto end;
        }
 
@@ -175,7 +175,7 @@ tal_cleanup(struct tal *tal)
 {
        cache_destroy(tal->cache);
        free(tal->spki);
-       uris_cleanup(&tal->uris);
+       maps_cleanup(&tal->maps);
 }
 
 char const *
@@ -198,11 +198,11 @@ tal_get_cache(struct tal *tal)
 }
 
 /**
- * Performs the whole validation walkthrough on uri @uri, which is assumed to
- * have been extracted from TAL @tal.
+ * Performs the whole validation walkthrough on the @map mapping, which is
+ * assumed to have been extracted from TAL @tal.
  */
 static int
-handle_tal_uri(struct tal *tal, struct rpki_uri *uri, struct db_table *db)
+handle_tal_map(struct tal *tal, struct cache_mapping *map, struct db_table *db)
 {
        struct validation_handler validation_handler;
        struct validation *state;
@@ -210,7 +210,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, struct db_table *db)
        struct deferred_cert deferred;
        int error;
 
-       pr_val_debug("TAL URI '%s' {", uri_val_get_printable(uri));
+       pr_val_debug("TAL URI '%s' {", map_val_get_printable(map));
 
        validation_handler.handle_roa_v4 = handle_roa_v4;
        validation_handler.handle_roa_v6 = handle_roa_v6;
@@ -221,15 +221,15 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, struct db_table *db)
        if (error)
                return ENSURE_NEGATIVE(error);
 
-       if (!uri_is_certificate(uri)) {
+       if (!map_is_certificate(map)) {
                pr_op_err("TAL URI does not point to a certificate. (Expected .cer, got '%s')",
-                   uri_op_get_printable(uri));
+                   map_op_get_printable(map));
                error = EINVAL;
                goto end;
        }
 
        /* Handle root certificate. */
-       error = certificate_traverse(NULL, uri);
+       error = certificate_traverse(NULL, map);
        if (error) {
                switch (validation_pubkey_state(state)) {
                case PKS_INVALID:
@@ -267,9 +267,9 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, struct db_table *db)
                 * Ignore result code; remaining certificates are unrelated,
                 * so they should not be affected.
                 */
-               certificate_traverse(deferred.pp, deferred.uri);
+               certificate_traverse(deferred.pp, deferred.map);
 
-               uri_refput(deferred.uri);
+               map_refput(deferred.map);
                rpp_refput(deferred.pp);
        } while (true);
 
@@ -279,10 +279,10 @@ end:      validation_destroy(state);
 }
 
 static int
-__handle_tal_uri(struct rpki_uri *uri, void *arg)
+__handle_tal_map(struct cache_mapping *map, void *arg)
 {
        struct handle_tal_args *args = arg;
-       return handle_tal_uri(&args->tal, uri, args->db);
+       return handle_tal_map(&args->tal, map, args->db);
 }
 
 static void *
@@ -302,8 +302,8 @@ do_file_validation(void *arg)
                goto end;
 
        args.db = db_table_create();
-       thread->error = cache_download_alt(args.tal.cache, &args.tal.uris,
-           UT_TA_HTTP, UT_TA_RSYNC, __handle_tal_uri, &args);
+       thread->error = cache_download_alt(args.tal.cache, &args.tal.maps,
+           MAP_TA_HTTP, MAP_TA_RSYNC, __handle_tal_map, &args);
        if (thread->error) {
                pr_op_err("None of the URIs of the TAL '%s' yielded a successful traversal.",
                    thread->tal_file);
index cd909464789de5942e6352809557d8eaa3a0c335..38becd0c517f56dc29e70544a0b9e8d47fcfd39e 100644 (file)
@@ -4,7 +4,7 @@
 /* This is RFC 8630. */
 
 #include "rtr/db/db_table.h"
-#include "types/uri.h"
+#include "types/map.h"
 
 struct tal;
 
index 4810762d7d39a25dc214c9676015bed1e3aed511..6db8eaaec0106dfbdadc1299f3e9b609be8d16ec 100644 (file)
@@ -12,7 +12,7 @@
 #include "log.h"
 #include "rsync/rsync.h"
 #include "types/bio_seq.h"
-#include "types/uri.h"
+#include "types/map.h"
 
 #define HDRSIZE 32
 
@@ -65,23 +65,23 @@ end:        pb_cleanup(&pb);
 static BIO *
 rsync2bio_cache(char const *src)
 {
-       struct rpki_uri *uri = NULL;
+       struct cache_mapping *map = NULL;
        BIO *bio;
        int error;
 
        /*
-        * TODO (#82) maybe rename UT_TA_RSYNC into single rsync.
+        * TODO (#82) maybe rename MAP_TA_RSYNC into single rsync.
         * If applies and it's going to survive.
         */
-       error = uri_create(&uri, UT_TA_RSYNC, NULL, src);
+       error = map_create(&map, MAP_TA_RSYNC, NULL, src);
        if (error) {
                pr_op_err("Unparseable rsync URI: %s", strerror(abs(error)));
                return NULL;
        }
 
-       bio = __rsync2bio(uri_get_global(uri), uri_get_local(uri));
+       bio = __rsync2bio(map_get_url(map), map_get_path(map));
 
-       uri_refput(uri);
+       map_refput(map);
        return bio;
 }
 
index 42b0e4af88fb9aa61f53e46725e933e3b3a417d5..85d5bb76b1bd545316ea651ada873eaa51699140 100644 (file)
--- a/src/rpp.c
+++ b/src/rpp.c
@@ -9,19 +9,19 @@
 #include "object/ghostbusters.h"
 #include "object/roa.h"
 #include "thread_var.h"
-#include "types/uri.h"
+#include "types/map.h"
 
 /** A Repository Publication Point (RFC 6481), as described by some manifest. */
 struct rpp {
-       struct uri_list certs; /* Certificates */
+       struct map_list certs; /* Certificates */
 
        /*
-        * uri NULL implies stack NULL and error 0.
-        * If uri is set, stack might or might not be set.
-        * error is only relevant when uri is set and stack is unset.
+        * map NULL implies stack NULL and error 0.
+        * If map is set, stack might or might not be set.
+        * error is only relevant when map is set and stack is unset.
         */
        struct { /* Certificate Revocation List */
-               struct rpki_uri *uri;
+               struct cache_mapping *map;
                /*
                 * CRL in libcrypto-friendly form.
                 * Initialized lazily; access via rpp_crl().
@@ -37,9 +37,9 @@ struct rpp {
 
        /* The Manifest is not needed for now. */
 
-       struct uri_list roas; /* Route Origin Attestations */
+       struct map_list roas; /* Route Origin Attestations */
 
-       struct uri_list ghostbusters;
+       struct map_list ghostbusters;
 
        /*
         * Note that the reference counting functions are not prepared for
@@ -55,12 +55,12 @@ rpp_create(void)
 
        result = pmalloc(sizeof(struct rpp));
 
-       uris_init(&result->certs);
-       result->crl.uri = NULL;
+       maps_init(&result->certs);
+       result->crl.map = NULL;
        result->crl.stack = NULL;
        result->crl.error = 0;
-       uris_init(&result->roas);
-       uris_init(&result->ghostbusters);
+       maps_init(&result->roas);
+       maps_init(&result->ghostbusters);
        result->references = 1;
 
        return result;
@@ -77,54 +77,54 @@ rpp_refput(struct rpp *pp)
 {
        pp->references--;
        if (pp->references == 0) {
-               uris_cleanup(&pp->certs);
-               if (pp->crl.uri != NULL)
-                       uri_refput(pp->crl.uri);
+               maps_cleanup(&pp->certs);
+               if (pp->crl.map != NULL)
+                       map_refput(pp->crl.map);
                if (pp->crl.stack != NULL)
                        sk_X509_CRL_pop_free(pp->crl.stack, X509_CRL_free);
-               uris_cleanup(&pp->roas);
-               uris_cleanup(&pp->ghostbusters);
+               maps_cleanup(&pp->roas);
+               maps_cleanup(&pp->ghostbusters);
                free(pp);
        }
 }
 
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
 void
-rpp_add_cert(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_cert(struct rpp *pp, struct cache_mapping *map)
 {
-       uris_add(&pp->certs, uri);
+       maps_add(&pp->certs, map);
 }
 
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
 void
-rpp_add_roa(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_roa(struct rpp *pp, struct cache_mapping *map)
 {
-       uris_add(&pp->roas, uri);
+       maps_add(&pp->roas, map);
 }
 
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
 void
-rpp_add_ghostbusters(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_ghostbusters(struct rpp *pp, struct cache_mapping *map)
 {
-       uris_add(&pp->ghostbusters, uri);
+       maps_add(&pp->ghostbusters, map);
 }
 
-/** Steals ownership of @uri. */
+/** Steals ownership of @map. */
 int
-rpp_add_crl(struct rpp *pp, struct rpki_uri *uri)
+rpp_add_crl(struct rpp *pp, struct cache_mapping *map)
 {
        /* rfc6481#section-2.2 */
-       if (pp->crl.uri)
+       if (pp->crl.map)
                return pr_val_err("Repository Publication Point has more than one CRL.");
 
-       pp->crl.uri = uri;
+       pp->crl.map = map;
        return 0;
 }
 
-struct rpki_uri *
+struct cache_mapping *
 rpp_get_crl(struct rpp const *pp)
 {
-       return pp->crl.uri;
+       return pp->crl.map;
 }
 
 static int
@@ -134,9 +134,9 @@ add_crl_to_stack(struct rpp *pp, STACK_OF(X509_CRL) *crls)
        int error;
        int idx;
 
-       fnstack_push_uri(pp->crl.uri);
+       fnstack_push_map(pp->crl.map);
 
-       error = crl_load(pp->crl.uri, &crl);
+       error = crl_load(pp->crl.map, &crl);
        if (error)
                goto end;
 
@@ -169,7 +169,7 @@ rpp_crl(struct rpp *pp, STACK_OF(X509_CRL) **result)
                *result = NULL;
                return 0;
        }
-       if (pp->crl.uri == NULL) {
+       if (pp->crl.map == NULL) {
                /* rpp_crl() assumes the rpp has been populated already. */
                pr_crit("RPP lacks a CRL.");
        }
@@ -219,7 +219,7 @@ __cert_traverse(struct rpp *pp)
         * intuitive.
         */
        for (i = pp->certs.len - 1; i >= 0; i--) {
-               deferred.uri = pp->certs.array[i];
+               deferred.map = pp->certs.array[i];
                deferstack_push(certstack, &deferred);
        }
 
@@ -232,7 +232,7 @@ __cert_traverse(struct rpp *pp)
 void
 rpp_traverse(struct rpp *pp)
 {
-       struct rpki_uri **uri;
+       struct cache_mapping **map;
 
        /*
         * A subtree should not invalidate the rest of the tree, so error codes
@@ -249,13 +249,13 @@ rpp_traverse(struct rpp *pp)
        __cert_traverse(pp);
 
        /* Validate ROAs, apply validation_handler on them. */
-       ARRAYLIST_FOREACH(&pp->roas, uri)
-               roa_traverse(*uri, pp);
+       ARRAYLIST_FOREACH(&pp->roas, map)
+               roa_traverse(*map, pp);
 
        /*
         * We don't do much with the ghostbusters right now.
         * Just validate them.
         */
-       ARRAYLIST_FOREACH(&pp->ghostbusters, uri)
-               ghostbusters_traverse(*uri, pp);
+       ARRAYLIST_FOREACH(&pp->ghostbusters, map)
+               ghostbusters_traverse(*map, pp);
 }
index f328b911a5fed0c2d36f5efa336eb5779ad28476..5f78a2b5397cc2ce72f5a9b851a8f968e4d5979d 100644 (file)
--- a/src/rpp.h
+++ b/src/rpp.h
@@ -4,7 +4,7 @@
 #include <openssl/safestack.h>
 #include <openssl/x509.h>
 
-#include "types/uri.h"
+#include "types/map.h"
 
 struct rpp;
 
@@ -12,12 +12,12 @@ struct rpp *rpp_create(void);
 void rpp_refget(struct rpp *pp);
 void rpp_refput(struct rpp *pp);
 
-void rpp_add_cert(struct rpp *, struct rpki_uri *);
-int rpp_add_crl(struct rpp *, struct rpki_uri *);
-void rpp_add_roa(struct rpp *, struct rpki_uri *);
-void rpp_add_ghostbusters(struct rpp *, struct rpki_uri *);
+void rpp_add_cert(struct rpp *, struct cache_mapping *);
+int rpp_add_crl(struct rpp *, struct cache_mapping *);
+void rpp_add_roa(struct rpp *, struct cache_mapping *);
+void rpp_add_ghostbusters(struct rpp *, struct cache_mapping *);
 
-struct rpki_uri *rpp_get_crl(struct rpp const *);
+struct cache_mapping *rpp_get_crl(struct rpp const *);
 int rpp_crl(struct rpp *, STACK_OF(X509_CRL) **);
 
 void rpp_traverse(struct rpp *);
index b9a810540bc3e67d150da34bd4339a12695a4944..dc6a7a9401daeaa2952d8e1be3f2ed163db0e93e 100644 (file)
@@ -46,7 +46,7 @@ struct rrdp_session {
 };
 
 struct file_metadata {
-       struct rpki_uri *uri;
+       struct cache_mapping *uri;
        unsigned char *hash; /* Array. Sometimes omitted. */
        size_t hash_len;
 };
@@ -65,7 +65,7 @@ struct update_notification {
        struct rrdp_session session;
        struct file_metadata snapshot;
        struct notification_deltas deltas;
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
 };
 
 /* A deserialized <publish> tag, from a snapshot or delta. */
@@ -82,7 +82,7 @@ struct withdraw {
 
 /* Helpful context while reading a snapshot or delta. */
 struct rrdp_ctx {
-       struct rpki_uri *notif;
+       struct cache_mapping *notif;
        struct rrdp_session session;
 };
 
@@ -143,7 +143,7 @@ static void
 metadata_cleanup(struct file_metadata *meta)
 {
        free(meta->hash);
-       uri_refput(meta->uri);
+       map_refput(meta->uri);
 }
 
 static void
@@ -155,12 +155,12 @@ notification_delta_cleanup(struct notification_delta *delta)
 
 static void
 update_notification_init(struct update_notification *notif,
-    struct rpki_uri *uri)
+    struct cache_mapping *map)
 {
        memset(&notif->session, 0, sizeof(notif->session));
        memset(&notif->snapshot, 0, sizeof(notif->snapshot));
        notification_deltas_init(&notif->deltas);
-       notif->uri = uri_refget(uri);
+       notif->map = map_refget(map);
 }
 
 static void
@@ -168,7 +168,7 @@ __update_notification_cleanup(struct update_notification *notif)
 {
        metadata_cleanup(&notif->snapshot);
        notification_deltas_cleanup(&notif->deltas, notification_delta_cleanup);
-       uri_refput(notif->uri);
+       map_refput(notif->map);
 }
 
 static void
@@ -255,8 +255,8 @@ parse_string(xmlTextReaderPtr reader, char const *attr)
 }
 
 static int
-parse_uri(xmlTextReaderPtr reader, struct rpki_uri *notif,
-    struct rpki_uri **result)
+parse_uri(xmlTextReaderPtr reader, struct cache_mapping *notif,
+    struct cache_mapping **result)
 {
        xmlChar *xmlattr;
        int error;
@@ -265,7 +265,7 @@ parse_uri(xmlTextReaderPtr reader, struct rpki_uri *notif,
        if (xmlattr == NULL)
                return -EINVAL;
 
-       error = uri_create(result, (notif != NULL) ? UT_CAGED : UT_TMP, notif,
+       error = map_create(result, (notif != NULL) ? MAP_CAGED : MAP_TMP, notif,
                           (char const *)xmlattr);
 
        xmlFree(xmlattr);
@@ -455,7 +455,7 @@ end:
  * 2. "hash" (optional, depending on @hr)
  */
 static int
-parse_file_metadata(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_file_metadata(xmlTextReaderPtr reader, struct cache_mapping *notif,
     hash_requirement hr, struct file_metadata *meta)
 {
        int error;
@@ -468,7 +468,7 @@ parse_file_metadata(xmlTextReaderPtr reader, struct rpki_uri *notif,
 
        error = parse_hash(reader, hr, &meta->hash, &meta->hash_len);
        if (error) {
-               uri_refput(meta->uri);
+               map_refput(meta->uri);
                meta->uri = NULL;
                return error;
        }
@@ -477,7 +477,7 @@ parse_file_metadata(xmlTextReaderPtr reader, struct rpki_uri *notif,
 }
 
 static int
-parse_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_publish(xmlTextReaderPtr reader, struct cache_mapping *notif,
     hash_requirement hr, struct publish *tag)
 {
        xmlChar *base64_str;
@@ -491,7 +491,7 @@ parse_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
        if (xmlTextReaderRead(reader) != 1) {
                return pr_val_err(
                    "Couldn't read publish content of element '%s'",
-                   uri_get_global(tag->meta.uri)
+                   map_get_url(tag->meta.uri)
                );
        }
 
@@ -509,7 +509,7 @@ parse_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
 }
 
 static int
-parse_withdraw(xmlTextReaderPtr reader, struct rpki_uri *notif,
+parse_withdraw(xmlTextReaderPtr reader, struct cache_mapping *notif,
     struct withdraw *tag)
 {
        int error;
@@ -522,17 +522,17 @@ parse_withdraw(xmlTextReaderPtr reader, struct rpki_uri *notif,
 }
 
 static int
-write_file(struct rpki_uri *uri, unsigned char *content, size_t content_len)
+write_file(struct cache_mapping *map, unsigned char *content, size_t content_len)
 {
        FILE *out;
        size_t written;
        int error;
 
-       error = mkdir_p(uri_get_local(uri), false);
+       error = mkdir_p(map_get_path(map), false);
        if (error)
                return error;
 
-       error = file_write(uri_get_local(uri), "wb", &out);
+       error = file_write(map_get_path(map), "wb", &out);
        if (error)
                return error;
 
@@ -542,7 +542,7 @@ write_file(struct rpki_uri *uri, unsigned char *content, size_t content_len)
        if (written != content_len) {
                return pr_val_err(
                    "Couldn't write file '%s' (error code not available)",
-                   uri_get_local(uri)
+                   map_get_path(map)
                );
        }
 
@@ -551,14 +551,14 @@ write_file(struct rpki_uri *uri, unsigned char *content, size_t content_len)
 
 /* Remove a local file and its directory tree (if empty) */
 static int
-delete_file(struct rpki_uri *uri)
+delete_file(struct cache_mapping *map)
 {
        /* Delete parent dirs only if empty. */
-       return delete_dir_recursive_bottom_up(uri_get_local(uri));
+       return delete_dir_recursive_bottom_up(map_get_path(map));
 }
 
 static int
-handle_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
+handle_publish(xmlTextReaderPtr reader, struct cache_mapping *notif,
     hash_requirement hr)
 {
        struct publish tag = { 0 };
@@ -574,7 +574,7 @@ handle_publish(xmlTextReaderPtr reader, struct rpki_uri *notif,
 }
 
 static int
-handle_withdraw(xmlTextReaderPtr reader, struct rpki_uri *notif)
+handle_withdraw(xmlTextReaderPtr reader, struct cache_mapping *notif)
 {
        struct withdraw tag = { 0 };
        int error;
@@ -597,9 +597,9 @@ parse_notification_snapshot(xmlTextReaderPtr reader,
        if (error)
                return error;
 
-       if (!uri_same_origin(notif->uri, notif->snapshot.uri))
+       if (!map_same_origin(notif->map, notif->snapshot.uri))
                return pr_val_err("Notification %s and Snapshot %s are not hosted by the same origin.",
-                   uri_get_global(notif->uri), uri_get_global(notif->snapshot.uri));
+                   map_get_url(notif->map), map_get_url(notif->snapshot.uri));
 
        return 0;
 }
@@ -621,9 +621,9 @@ parse_notification_delta(xmlTextReaderPtr reader,
                return error;
        }
 
-       if (!uri_same_origin(notif->uri, delta.meta.uri))
+       if (!map_same_origin(notif->map, delta.meta.uri))
                return pr_val_err("Notification %s and Delta %s are not hosted by the same origin.",
-                   uri_get_global(notif->uri), uri_get_global(delta.meta.uri));
+                   map_get_url(notif->map), map_get_url(delta.meta.uri));
 
        notification_deltas_add(&notif->deltas, &delta);
        return 0;
@@ -747,13 +747,13 @@ xml_read_notif(xmlTextReaderPtr reader, void *arg)
 }
 
 static int
-parse_notification(struct rpki_uri *uri, struct update_notification *result)
+parse_notification(struct cache_mapping *map, struct update_notification *result)
 {
        int error;
 
-       update_notification_init(result, uri);
+       update_notification_init(result, map);
 
-       error = relax_ng_parse(uri_get_local(uri), xml_read_notif, result);
+       error = relax_ng_parse(map_get_path(map), xml_read_notif, result);
        if (error)
                update_notification_cleanup(result);
 
@@ -761,9 +761,9 @@ parse_notification(struct rpki_uri *uri, struct update_notification *result)
 }
 
 static void
-delete_rpp(struct rpki_uri *notif)
+delete_rpp(struct cache_mapping *notif)
 {
-       char *path = uri_get_rrdp_workspace(notif);
+       char *path = map_get_rrdp_workspace(notif);
        pr_val_debug("Snapshot: Deleting cached RPP '%s'.", path);
        file_rm_rf(path);
        free(path);
@@ -802,10 +802,10 @@ parse_snapshot(struct update_notification *notif)
 {
        struct rrdp_ctx ctx;
 
-       ctx.notif = notif->uri;
+       ctx.notif = notif->map;
        ctx.session = notif->session;
 
-       return relax_ng_parse(uri_get_local(notif->snapshot.uri),
+       return relax_ng_parse(map_get_path(notif->snapshot.uri),
            xml_read_snapshot, &ctx);
 }
 
@@ -847,15 +847,15 @@ validate_session_desync(struct cachefile_notification *old_notif,
 static int
 handle_snapshot(struct update_notification *notif)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
-       delete_rpp(notif->uri);
+       delete_rpp(notif->map);
 
-       uri = notif->snapshot.uri;
+       map = notif->snapshot.uri;
 
-       pr_val_debug("Processing snapshot '%s'.", uri_val_get_printable(uri));
-       fnstack_push_uri(uri);
+       pr_val_debug("Processing snapshot '%s'.", map_val_get_printable(map));
+       fnstack_push_map(map);
 
        /*
         * TODO (performance) Is there a point in caching the snapshot?
@@ -863,7 +863,7 @@ handle_snapshot(struct update_notification *notif)
         * Maybe stream it instead.
         * Same for deltas.
         */
-       error = cache_download(validation_cache(state_retrieve()), uri, NULL,
+       error = cache_download(validation_cache(state_retrieve()), map, NULL,
                               NULL);
        if (error)
                goto end;
@@ -871,7 +871,7 @@ handle_snapshot(struct update_notification *notif)
        if (error)
                goto end;
        error = parse_snapshot(notif);
-       delete_file(uri);
+       delete_file(map);
 
 end:
        fnstack_pop();
@@ -918,30 +918,30 @@ parse_delta(struct update_notification *notif, struct notification_delta *delta)
        if (error)
                return error;
 
-       ctx.notif = notif->uri;
+       ctx.notif = notif->map;
        ctx.session.session_id = notif->session.session_id;
        ctx.session.serial = delta->serial;
 
-       return relax_ng_parse(uri_get_local(delta->meta.uri), xml_read_delta,
+       return relax_ng_parse(map_get_path(delta->meta.uri), xml_read_delta,
            &ctx);
 }
 
 static int
 handle_delta(struct update_notification *notif, struct notification_delta *delta)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
-       uri = delta->meta.uri;
+       map = delta->meta.uri;
 
-       pr_val_debug("Processing delta '%s'.", uri_val_get_printable(uri));
-       fnstack_push_uri(uri);
+       pr_val_debug("Processing delta '%s'.", map_val_get_printable(map));
+       fnstack_push_map(map);
 
-       error = cache_download(validation_cache(state_retrieve()), uri, NULL, NULL);
+       error = cache_download(validation_cache(state_retrieve()), map, NULL, NULL);
        if (error)
                goto end;
        error = parse_delta(notif, delta);
-       delete_file(uri);
+       delete_file(map);
 
 end:
        fnstack_pop();
@@ -1084,14 +1084,14 @@ update_notif(struct cachefile_notification *old, struct update_notification *new
 }
 
 /*
- * Downloads the Update Notification pointed by @uri, and updates the cache
+ * Downloads the Update Notification pointed by @map, and updates the cache
  * accordingly.
  *
  * "Updates the cache accordingly" means it downloads the missing deltas or
  * snapshot, and explodes them into the corresponding RPP's local directory.
  */
 int
-rrdp_update(struct rpki_uri *uri)
+rrdp_update(struct cache_mapping *map)
 {
        struct cachefile_notification **cached, *old;
        struct update_notification new;
@@ -1099,10 +1099,10 @@ rrdp_update(struct rpki_uri *uri)
        int serial_cmp;
        int error;
 
-       fnstack_push_uri(uri);
+       fnstack_push_map(map);
        pr_val_debug("Processing notification.");
 
-       error = cache_download(validation_cache(state_retrieve()), uri,
+       error = cache_download(validation_cache(state_retrieve()), map,
            &changed, &cached);
        if (error)
                goto end;
@@ -1111,7 +1111,7 @@ rrdp_update(struct rpki_uri *uri)
                goto end;
        }
 
-       error = parse_notification(uri, &new);
+       error = parse_notification(map, &new);
        if (error)
                goto end;
        pr_val_debug("New session/serial: %s/%s", new.session.session_id,
index 757dd46ce65df9c70fd5f86b4be1a58563ebcc5b..fa7877ffd0185f35e8f857471f880a7d3bb9f8b9 100644 (file)
@@ -1,11 +1,11 @@
 #ifndef SRC_RRDP_H_
 #define SRC_RRDP_H_
 
-#include "types/uri.h"
+#include "types/map.h"
 
 struct cachefile_notification;
 
-int rrdp_update(struct rpki_uri *);
+int rrdp_update(struct cache_mapping *);
 
 json_t *rrdp_notif2json(struct cachefile_notification *);
 int rrdp_json2notif(json_t *, struct cachefile_notification **);
index 1da419a77087dea1c74530ccaebe1704d824c8d4..c11828d1d7dfe338ba2e02f16e93e72d1f3033f8 100644 (file)
@@ -31,6 +31,4 @@ char *validation_get_ip_buffer2(struct validation *);
 struct validation_handler const *
 validation_get_validation_handler(struct validation *);
 
-struct db_rrdp_uri *validation_get_rrdp_uris(struct validation *);
-
 #endif /* SRC_STATE_H_ */
index 1cc35be9e70aa28db89db85a00af43c1a1ab3077..46ac0a1b51d03749a5ccc94bb2d20528ae726630 100644 (file)
@@ -160,13 +160,13 @@ fnstack_push(char const *file)
 /**
  * See fnstack_push().
  *
- * This function cannot claim a reference for @uri, so @uri will have to outlive
+ * This function cannot claim a reference for @map, so @map will have to outlive
  * the push/pop.
  */
 void
-fnstack_push_uri(struct rpki_uri *uri)
+fnstack_push_map(struct cache_mapping *map)
 {
-       fnstack_push(uri_val_get_printable(uri));
+       fnstack_push(map_val_get_printable(map));
 }
 
 /* Returns the file name on the top of the file name stack. */
index 15769964b090d069de0c9f33fc9882acba9aa932..0d5d389c2767c790155a8db2bdbd66c45e062328 100644 (file)
@@ -12,7 +12,7 @@ void fnstack_init(void);
 void fnstack_cleanup(void);
 
 void fnstack_push(char const *);
-void fnstack_push_uri(struct rpki_uri *);
+void fnstack_push_map(struct cache_mapping *);
 char const *fnstack_peek(void);
 void fnstack_pop(void);
 
similarity index 57%
rename from src/types/uri.c
rename to src/types/map.c
index f76f33ad8348747de6ac0ddf523dc609f2bfd827..503087a7f5a1dc6cbc111e6152010156e0ddf155 100644 (file)
@@ -1,4 +1,4 @@
-#include "types/uri.h"
+#include "types/map.h"
 
 #include "alloc.h"
 #include "common.h"
 /**
  * Aside from the reference counter, instances are meant to be immutable.
  *
- * TODO (fine) Needs rebranding. AFAIK, RPKI does not impose significant
- * restrictions to regular URIs (except for schema, I guess), "global URI" is
- * pretty much tautologic, and "local URI" is a misnomer. (Because it doesn't
- * have anything to do with 'interpretation is independent of access'.)
- * I can't even remember if this nomenclature made sense at some point.
- * It's more of a mapping than a URI.
- *
- * TODO (fine) Also, this structure is so intertwined with the cache module,
+ * TODO (fine) This structure is so intertwined with the cache module,
  * nowadays it feels like it should be moved there.
  */
-struct rpki_uri {
+struct cache_mapping {
        /**
-        * "Global URI".
         * The one that always starts with "rsync://" or "https://".
         * Normalized, ASCII-only, NULL-terminated.
         */
-       char *global;
+       char *url;
 
        /**
-        * "Local URI".
-        * The file pointed by @global, but cached in the local filesystem.
+        * Cache location where we downloaded the file.
         * Normalized, ASCII-only, NULL-terminated.
         * Sometimes NULL, depending on @type.
         */
-       char *local;
+       char *path;
 
-       enum uri_type type;
+       enum map_type type;
 
        unsigned int references; /* Reference counter */
 };
@@ -61,8 +52,7 @@ validate_url_character(int character)
         * checking legal characters, anyway.
         *
         * What I really need this validation for is ensure that we won't get
-        * any trouble later, when we attempt to convert the global URI to a
-        * local file.
+        * any trouble later, when we attempt to map the URL to a path.
         *
         * Sample trouble: Getting UTF-8 characters. Why are they trouble?
         * Because we don't have any guarantees that the system's file name
@@ -85,14 +75,13 @@ validate_url_character(int character)
            : pr_val_err("URL has non-printable character code '%d'.", character);
 }
 
-static int append_guri(struct path_builder *, char const *, char const *,
-    int, bool);
+static int normalize_url(struct path_builder *, char const *, char const *, int);
 
 /**
- * Initializes @uri->global by building a normalized version of @str.
+ * Initializes @map->url by building a normalized version of @str.
  */
 static int
-str2global(char const *str, struct rpki_uri *uri)
+init_url(struct cache_mapping *map, char const *str)
 {
 #define SCHEMA_LEN 8 /* strlen("rsync://"), strlen("https://") */
 
@@ -102,7 +91,7 @@ str2global(char const *str, struct rpki_uri *uri)
        struct path_builder pb;
 
        if (str == NULL){
-               uri->global = NULL;
+               map->url = NULL;
                return 0;
        }
 
@@ -115,35 +104,35 @@ str2global(char const *str, struct rpki_uri *uri)
        pfx = NULL;
        error = 0;
 
-       switch (uri->type) {
-       case UT_TA_RSYNC:
-       case UT_RPP:
-       case UT_CAGED:
-       case UT_AIA:
-       case UT_SO:
-       case UT_MFT:
+       switch (map->type) {
+       case MAP_TA_RSYNC:
+       case MAP_RPP:
+       case MAP_CAGED:
+       case MAP_AIA:
+       case MAP_SO:
+       case MAP_MFT:
                pfx = "rsync://";
                error = ENOTRSYNC;
                break;
-       case UT_TA_HTTP:
-       case UT_NOTIF:
-       case UT_TMP:
+       case MAP_TA_HTTP:
+       case MAP_NOTIF:
+       case MAP_TMP:
                pfx = "https://";
                error = ENOTHTTPS;
                break;
        }
 
        if (pfx == NULL)
-               pr_crit("Unknown URI type: %u", uri->type);
+               pr_crit("Unknown mapping type: %u", map->type);
 
        __pb_init(&pb, SCHEMA_LEN - 1);
-       error = append_guri(&pb, str, pfx, error, true);
+       error = normalize_url(&pb, str, pfx, error);
        if (error) {
                pb_cleanup(&pb);
                return error;
        }
 
-       uri->global = strncpy(pb.string, str, SCHEMA_LEN);
+       map->url = strncpy(pb.string, str, SCHEMA_LEN);
        return 0;
 }
 
@@ -185,16 +174,15 @@ validate_mft_file(IA5String_t *ia5)
 }
 
 /**
- * Initializes @uri->global given manifest path @mft and its referenced file
- * @ia5.
+ * Initializes @map->url given manifest path @mft and its referenced file @ia5.
  *
- * ie. if @mft is "rsync://a/b/c.mft" and @ia5 is "d.cer", @uri->global will
- * be "rsync://a/b/d.cer".
+ * ie. if @mft is "rsync://a/b/c.mft" and @ia5 is "d.cer", @map->url will be
+ * "rsync://a/b/d.cer".
  *
- * Assumes that @mft is a "global" URL. (ie. extracted from rpki_uri.global.)
+ * Assumes @mft is already normalized.
  */
 static int
-ia5str2global(struct rpki_uri *uri, char const *mft, IA5String_t *ia5)
+ia5str2url(struct cache_mapping *map, char const *mft, IA5String_t *ia5)
 {
        char *joined;
        char const *slash_pos;
@@ -222,7 +210,7 @@ ia5str2global(struct rpki_uri *uri, char const *mft, IA5String_t *ia5)
        strncpy(joined + dir_len, (char *) ia5->buf, ia5->size);
        joined[dir_len + ia5->size] = '\0';
 
-       uri->global = joined;
+       map->url = joined;
        return 0;
 }
 
@@ -263,37 +251,31 @@ path_is_dotdots(struct path_parser *parser)
 }
 
 static int
-append_guri(struct path_builder *pb, char const *guri, char const *gprefix,
-    int err, bool skip_schema)
+normalize_url(struct path_builder *pb, char const *url, char const *pfx,
+    int errnot)
 {
        struct path_parser parser;
        size_t dot_dot_limit;
        int error;
 
        /* Schema */
-       if (!str_starts_with(guri, gprefix)) {
-               pr_val_err("URI '%s' does not begin with '%s'.", guri, gprefix);
-               return err;
-       }
-
-       if (!skip_schema) {
-               error = pb_appendn(pb, guri, 5);
-               if (error)
-                       return error;
+       if (!str_starts_with(url, pfx)) {
+               pr_val_err("URL '%s' does not begin with '%s'.", url, pfx);
+               return errnot;
        }
 
        /* Domain */
-       parser.slash = guri + 7;
+       parser.slash = url + 7;
        if (!path_next(&parser))
-               return pr_val_err("URI '%s' seems to lack a domain.", guri);
+               return pr_val_err("URL '%s' seems to lack a domain.", url);
        if (path_is_dot(&parser)) {
                /* Dumping files to the cache root is unsafe. */
-               return pr_val_err("URI '%s' employs the root domain. This is not really cacheable, so I'm going to distrust it.",
-                   guri);
+               return pr_val_err("URL '%s' employs the root domain. This is not really cacheable, so I'm going to distrust it.",
+                   url);
        }
        if (path_is_dotdots(&parser)) {
-               return pr_val_err("URI '%s' seems to be dot-dotting past its own schema.",
-                   guri);
+               return pr_val_err("URL '%s' seems to be dot-dotting past its own schema.",
+                   url);
        }
        error = pb_appendn(pb, parser.token, parser.len);
        if (error)
@@ -307,8 +289,8 @@ append_guri(struct path_builder *pb, char const *guri, char const *gprefix,
                        if (error)
                                return error;
                        if (pb->len < dot_dot_limit) {
-                               return pr_val_err("URI '%s' seems to be dot-dotting past its own domain.",
-                                   guri);
+                               return pr_val_err("URL '%s' seems to be dot-dotting past its own domain.",
+                                   url);
                        }
                } else if (!path_is_dot(&parser)) {
                        error = pb_appendn(pb, parser.token, parser.len);
@@ -321,7 +303,7 @@ append_guri(struct path_builder *pb, char const *guri, char const *gprefix,
 }
 
 static int
-get_rrdp_workspace(struct path_builder *pb, struct rpki_uri *notif)
+get_rrdp_workspace(struct path_builder *pb, struct cache_mapping *notif)
 {
        int error;
 
@@ -329,7 +311,7 @@ get_rrdp_workspace(struct path_builder *pb, struct rpki_uri *notif)
        if (error)
                return error;
 
-       error = pb_append(pb, &notif->global[SCHEMA_LEN]);
+       error = pb_append(pb, &notif->url[SCHEMA_LEN]);
        if (error)
                pb_cleanup(pb);
 
@@ -340,7 +322,7 @@ get_rrdp_workspace(struct path_builder *pb, struct rpki_uri *notif)
  * Maps "rsync://a.b.c/d/e.cer" into "<local-repository>/rsync/a.b.c/d/e.cer".
  */
 static int
-map_simple(struct rpki_uri *uri, char const *subdir)
+map_simple(struct cache_mapping *map, char const *subdir)
 {
        struct path_builder pb;
        int error;
@@ -349,13 +331,13 @@ map_simple(struct rpki_uri *uri, char const *subdir)
        if (error)
                return error;
 
-       error = pb_append(&pb, &uri->global[SCHEMA_LEN]);
+       error = pb_append(&pb, &map->url[SCHEMA_LEN]);
        if (error) {
                pb_cleanup(&pb);
                return error;
        }
 
-       uri->local = pb.string;
+       map->path = pb.string;
        return 0;
 }
 
@@ -364,7 +346,7 @@ map_simple(struct rpki_uri *uri, char const *subdir)
  * "<local-repository>/rrdp/<notification-path>/a.b.c/d/e.cer".
  */
 static int
-map_caged(struct rpki_uri *uri, struct rpki_uri *notif)
+map_caged(struct cache_mapping *map, struct cache_mapping *notif)
 {
        struct path_builder pb;
        int error;
@@ -373,73 +355,73 @@ map_caged(struct rpki_uri *uri, struct rpki_uri *notif)
        if (error)
                return error;
 
-       if (uri->global == NULL)
+       if (map->url == NULL)
                goto success; /* Caller is only interested in the cage. */
 
-       error = pb_append(&pb, &uri->global[SCHEMA_LEN]);
+       error = pb_append(&pb, &map->url[SCHEMA_LEN]);
        if (error) {
                pb_cleanup(&pb);
                return error;
        }
 
 success:
-       uri->local = pb.string;
+       map->path = pb.string;
        return 0;
 }
 
 static int
-autocomplete_local(struct rpki_uri *uri, struct rpki_uri *notif)
+init_path(struct cache_mapping *map, struct cache_mapping *notif)
 {
-       switch (uri->type) {
-       case UT_TA_RSYNC:
-       case UT_RPP:
-       case UT_MFT:
-               return map_simple(uri, "rsync");
+       switch (map->type) {
+       case MAP_TA_RSYNC:
+       case MAP_RPP:
+       case MAP_MFT:
+               return map_simple(map, "rsync");
 
-       case UT_TA_HTTP:
-               return map_simple(uri, "https");
+       case MAP_TA_HTTP:
+               return map_simple(map, "https");
 
-       case UT_NOTIF:
-       case UT_TMP:
-               return cache_tmpfile(&uri->local);
+       case MAP_NOTIF:
+       case MAP_TMP:
+               return cache_tmpfile(&map->path);
 
-       case UT_CAGED:
-               return map_caged(uri, notif);
+       case MAP_CAGED:
+               return map_caged(map, notif);
 
-       case UT_AIA:
-       case UT_SO:
-               uri->local = NULL;
+       case MAP_AIA:
+       case MAP_SO:
+               map->path = NULL;
                return 0;
        }
 
-       pr_crit("Unknown URI type: %u", uri->type);
+       pr_crit("Unknown URL type: %u", map->type);
 }
 
 int
-uri_create(struct rpki_uri **result, enum uri_type type, struct rpki_uri *notif,
-          char const *guri)
+map_create(struct cache_mapping **result, enum map_type type,
+    struct cache_mapping *notif, char const *url)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
-       uri = pmalloc(sizeof(struct rpki_uri));
-       uri->type = type;
-       uri->references = 1;
+       map = pmalloc(sizeof(struct cache_mapping));
+       map->type = type;
+       map->references = 1;
 
-       error = str2global(guri, uri);
+       error = init_url(map, url);
        if (error) {
-               free(uri);
+               free(map);
                return error;
        }
 
-       error = autocomplete_local(uri, notif);
+       error = init_path(map, notif);
        if (error) {
-               free(uri->global);
-               free(uri);
+               free(map->url);
+               free(map);
                return error;
        }
 
-       *result = uri;
+       *result = map;
        return 0;
 }
 
@@ -448,93 +430,93 @@ uri_create(struct rpki_uri **result, enum uri_type type, struct rpki_uri *notif,
  * names. This function will infer the rest of the URL.
  */
 int
-uri_create_mft(struct rpki_uri **result, struct rpki_uri *notif,
-              struct rpki_uri *mft, IA5String_t *ia5)
+map_create_mft(struct cache_mapping **result, struct cache_mapping *notif,
+              struct cache_mapping *mft, IA5String_t *ia5)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
        int error;
 
-       uri = pmalloc(sizeof(struct rpki_uri));
-       uri->type = (notif == NULL) ? UT_RPP : UT_CAGED;
-       uri->references = 1;
+       map = pmalloc(sizeof(struct cache_mapping));
+       map->type = (notif == NULL) ? MAP_RPP : MAP_CAGED;
+       map->references = 1;
 
-       error = ia5str2global(uri, mft->global, ia5);
+       error = ia5str2url(map, mft->url, ia5);
        if (error) {
-               free(uri);
+               free(map);
                return error;
        }
 
-       error = autocomplete_local(uri, notif);
+       error = init_path(map, notif);
        if (error) {
-               free(uri->global);
-               free(uri);
+               free(map->url);
+               free(map);
                return error;
        }
 
-       *result = uri;
+       *result = map;
        return 0;
 }
 
-/* Cache-only; global URI and type are meaningless. */
-struct rpki_uri *
-uri_create_cache(char const *path)
+/* Cache-only; url and type are meaningless. */
+struct cache_mapping *
+map_create_cache(char const *path)
 {
-       struct rpki_uri *uri;
+       struct cache_mapping *map;
 
-       uri = pzalloc(sizeof(struct rpki_uri));
-       uri->local = pstrdup(path);
-       uri->references = 1;
+       map = pzalloc(sizeof(struct cache_mapping));
+       map->path = pstrdup(path);
+       map->references = 1;
 
-       return uri;
+       return map;
 }
 
-struct rpki_uri *
-uri_refget(struct rpki_uri *uri)
+struct cache_mapping *
+map_refget(struct cache_mapping *map)
 {
-       uri->references++;
-       return uri;
+       map->references++;
+       return map;
 }
 
 void
-uri_refput(struct rpki_uri *uri)
+map_refput(struct cache_mapping *map)
 {
-       if (uri == NULL)
+       if (map == NULL)
                return;
 
-       uri->references--;
-       if (uri->references == 0) {
-               free(uri->global);
-               free(uri->local);
-               free(uri);
+       map->references--;
+       if (map->references == 0) {
+               free(map->url);
+               free(map->path);
+               free(map);
        }
 }
 
 char const *
-uri_get_global(struct rpki_uri *uri)
+map_get_url(struct cache_mapping *map)
 {
-       return uri->global;
+       return map->url;
 }
 
 char const *
-uri_get_local(struct rpki_uri *uri)
+map_get_path(struct cache_mapping *map)
 {
-       return uri->local;
+       return map->path;
 }
 
 bool
-uri_equals(struct rpki_uri *u1, struct rpki_uri *u2)
+map_equals(struct cache_mapping *m1, struct cache_mapping *m2)
 {
-       return strcmp(u1->global, u2->global) == 0;
+       return strcmp(m1->url, m2->url) == 0;
 }
 
 bool
-str_same_origin(char const *g1, char const *g2)
+str_same_origin(char const *url1, char const *url2)
 {
        size_t c, slashes;
 
        slashes = 0;
-       for (c = 0; g1[c] == g2[c]; c++) {
-               switch (g1[c]) {
+       for (c = 0; url1[c] == url2[c]; c++) {
+               switch (url1[c]) {
                case '/':
                        slashes++;
                        if (slashes == 3)
@@ -545,37 +527,37 @@ str_same_origin(char const *g1, char const *g2)
                }
        }
 
-       if (g1[c] == '\0')
-               return (slashes == 2) && g2[c] == '/';
-       if (g2[c] == '\0')
-               return (slashes == 2) && g1[c] == '/';
+       if (url1[c] == '\0')
+               return (slashes == 2) && url2[c] == '/';
+       if (url2[c] == '\0')
+               return (slashes == 2) && url1[c] == '/';
 
        return false;
 }
 
 bool
-uri_same_origin(struct rpki_uri *u1, struct rpki_uri *u2)
+map_same_origin(struct cache_mapping *m1, struct cache_mapping *m2)
 {
-       return str_same_origin(u1->global, u2->global);
+       return str_same_origin(m1->url, m2->url);
 }
 
 /* @ext must include the period. */
 bool
-uri_has_extension(struct rpki_uri *uri, char const *ext)
+map_has_extension(struct cache_mapping *map, char const *ext)
 {
-       return str_ends_with(uri->global, ext);
+       return str_ends_with(map->url, ext);
 }
 
 bool
-uri_is_certificate(struct rpki_uri *uri)
+map_is_certificate(struct cache_mapping *map)
 {
-       return uri_has_extension(uri, ".cer");
+       return map_has_extension(map, ".cer");
 }
 
-enum uri_type
-uri_get_type(struct rpki_uri *uri)
+enum map_type
+map_get_type(struct cache_mapping *map)
 {
-       return uri->type;
+       return map->type;
 }
 
 static char const *
@@ -586,15 +568,15 @@ get_filename(char const *file_path)
 }
 
 static char const *
-uri_get_printable(struct rpki_uri *uri, enum filename_format format)
+map_get_printable(struct cache_mapping *map, enum filename_format format)
 {
        switch (format) {
        case FNF_GLOBAL:
-               return uri->global;
+               return map->url;
        case FNF_LOCAL:
-               return uri->local;
+               return map->path;
        case FNF_NAME:
-               return get_filename(uri->global);
+               return get_filename(map->url);
        }
 
        pr_crit("Unknown file name format: %u", format);
@@ -602,53 +584,53 @@ uri_get_printable(struct rpki_uri *uri, enum filename_format format)
 }
 
 char const *
-uri_val_get_printable(struct rpki_uri *uri)
+map_val_get_printable(struct cache_mapping *map)
 {
        enum filename_format format;
 
        format = config_get_val_log_filename_format();
-       return uri_get_printable(uri, format);
+       return map_get_printable(map, format);
 }
 
 char const *
-uri_op_get_printable(struct rpki_uri *uri)
+map_op_get_printable(struct cache_mapping *map)
 {
        enum filename_format format;
 
        format = config_get_op_log_filename_format();
-       return uri_get_printable(uri, format);
+       return map_get_printable(map, format);
 }
 
 char *
-uri_get_rrdp_workspace(struct rpki_uri *notif)
+map_get_rrdp_workspace(struct cache_mapping *notif)
 {
        struct path_builder pb;
        return (get_rrdp_workspace(&pb, notif) == 0) ? pb.string : NULL;
 }
 
-DEFINE_ARRAY_LIST_FUNCTIONS(uri_list, struct rpki_uri *, static)
+DEFINE_ARRAY_LIST_FUNCTIONS(map_list, struct cache_mapping *, static)
 
 void
-uris_init(struct uri_list *uris)
+maps_init(struct map_list *maps)
 {
-       uri_list_init(uris);
+       map_list_init(maps);
 }
 
 static void
-__uri_refput(struct rpki_uri **uri)
+__map_refput(struct cache_mapping **map)
 {
-       uri_refput(*uri);
+       map_refput(*map);
 }
 
 void
-uris_cleanup(struct uri_list *uris)
+maps_cleanup(struct map_list *maps)
 {
-       uri_list_cleanup(uris, __uri_refput);
+       map_list_cleanup(maps, __map_refput);
 }
 
-/* Swallows @uri. */
+/* Swallows @map. */
 void
-uris_add(struct uri_list *uris, struct rpki_uri *uri)
+maps_add(struct map_list *maps, struct cache_mapping *map)
 {
-       uri_list_add(uris, &uri);
+       map_list_add(maps, &map);
 }
diff --git a/src/types/map.h b/src/types/map.h
new file mode 100644 (file)
index 0000000..16443a5
--- /dev/null
@@ -0,0 +1,95 @@
+#ifndef SRC_TYPES_MAP_H_
+#define SRC_TYPES_MAP_H_
+
+#include "asn1/asn1c/IA5String.h"
+#include "data_structure/array_list.h"
+
+/*
+ * "Long" time = seven days.
+ * Currently hardcoded, but queued for tweakability.
+ */
+enum map_type {
+       /*
+        * TAL's TA URL.
+        * The file is cached until it's untraversed for a "long" time.
+        */
+       MAP_TA_RSYNC,
+       MAP_TA_HTTP,
+
+       /*
+        * (rsync) Repository Publication Point. RFC 6481.
+        * The directory is cached until it's untraversed for a "long" time.
+        */
+       MAP_RPP,
+
+       /*
+        * An RRDP notification file; downloaded via HTTP.
+        * The file itself is not cached, but we preserve a handful of metadata
+        * that is needed in subsequent iterations.
+        * The metadata is cached until it's untraversed for a "long" time.
+        */
+       MAP_NOTIF,
+
+       /*
+        * RRDP Snapshot or Delta; downloaded via HTTP.
+        * The file itself is not cached, but we preserve some small metadata.
+        * The metadata is destroyed once the iteration finishes.
+        */
+       MAP_TMP,
+
+       /*
+        * Endangered species; bound to be removed once RFC 9286 is implemented.
+        */
+       MAP_CAGED,
+
+       MAP_AIA, /* caIssuers. Not directly downloaded. */
+       MAP_SO, /* signedObject. Not directly downloaded. */
+       MAP_MFT, /* rpkiManifest. Not directly downloaded. */
+};
+
+struct cache_mapping;
+
+int map_create(struct cache_mapping **, enum map_type, struct cache_mapping *,
+              char const *);
+int map_create_mft(struct cache_mapping **, struct cache_mapping *, struct cache_mapping *,
+                  IA5String_t *);
+struct cache_mapping *map_create_cache(char const *);
+
+#define map_create_caged(map, notif, url) \
+       map_create(map, MAP_CAGED, notif, url)
+#define map_create_cage(map, notif) \
+       map_create_caged(map, notif, NULL)
+
+struct cache_mapping *map_refget(struct cache_mapping *);
+void map_refput(struct cache_mapping *);
+
+/*
+ * Note that, if you intend to print some mapping, you're likely supposed to use
+ * map_get_printable() instead.
+ */
+char const *map_get_url(struct cache_mapping *);
+char const *map_get_path(struct cache_mapping *);
+
+bool map_equals(struct cache_mapping *, struct cache_mapping *);
+bool str_same_origin(char const *, char const *);
+bool map_same_origin(struct cache_mapping *, struct cache_mapping *);
+bool map_has_extension(struct cache_mapping *, char const *);
+bool map_is_certificate(struct cache_mapping *);
+
+enum map_type map_get_type(struct cache_mapping *);
+
+char const *map_val_get_printable(struct cache_mapping *);
+char const *map_op_get_printable(struct cache_mapping *);
+
+char *map_get_rrdp_workspace(struct cache_mapping *);
+
+/* Plural */
+
+DEFINE_ARRAY_LIST_STRUCT(map_list, struct cache_mapping *);
+
+void maps_init(struct map_list *);
+void maps_cleanup(struct map_list *);
+
+void maps_add(struct map_list *, struct cache_mapping *);
+
+#endif /* SRC_TYPES_MAP_H_ */
diff --git a/src/types/uri.h b/src/types/uri.h
deleted file mode 100644 (file)
index 4dad424..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-#ifndef SRC_TYPES_URI_H_
-#define SRC_TYPES_URI_H_
-
-#include "asn1/asn1c/IA5String.h"
-#include "data_structure/array_list.h"
-
-/*
- * "Long" time = seven days.
- * Currently hardcoded, but queued for tweakability.
- */
-enum uri_type {
-       /*
-        * TAL's TA URL.
-        * The file is cached until it's untraversed for a "long" time.
-        */
-       UT_TA_RSYNC,
-       UT_TA_HTTP,
-
-       /*
-        * (rsync) Repository Publication Point. RFC 6481.
-        * The directory is cached until it's untraversed for a "long" time.
-        */
-       UT_RPP,
-
-       /*
-        * An RRDP notification file; downloaded via HTTP.
-        * The file itself is not cached, but we preserve a handful of metadata
-        * that is needed in subsequent iterations.
-        * The metadata is cached until it's untraversed for a "long" time.
-        */
-       UT_NOTIF,
-
-       /*
-        * RRDP Snapshot or Delta; downloaded via HTTP.
-        * The file itself is not cached, but we preserve some small metadata.
-        * The metadata is destroyed once the iteration finishes.
-        */
-       UT_TMP,
-
-       /*
-        * Endangered species; bound to be removed once RFC 9286 is implemented.
-        */
-       UT_CAGED,
-
-       UT_AIA, /* caIssuers. Not directly downloaded. */
-       UT_SO, /* signedObject. Not directly downloaded. */
-       UT_MFT, /* rpkiManifest. Not directly downloaded. */
-};
-
-struct rpki_uri;
-
-int uri_create(struct rpki_uri **, enum uri_type, struct rpki_uri *,
-              char const *);
-int uri_create_mft(struct rpki_uri **, struct rpki_uri *, struct rpki_uri *,
-                  IA5String_t *);
-struct rpki_uri *uri_create_cache(char const *);
-
-#define uri_create_caged(uri, notif, guri) \
-       uri_create(uri, UT_CAGED, notif, guri)
-#define uri_create_cage(uri, notif) \
-       uri_create_caged(uri, notif, NULL)
-
-struct rpki_uri *uri_refget(struct rpki_uri *);
-void uri_refput(struct rpki_uri *);
-
-/*
- * Note that, if you intend to print some URI, you're likely supposed to use
- * uri_get_printable() instead.
- */
-char const *uri_get_global(struct rpki_uri *);
-char const *uri_get_local(struct rpki_uri *);
-
-bool uri_equals(struct rpki_uri *, struct rpki_uri *);
-bool str_same_origin(char const *, char const *);
-bool uri_same_origin(struct rpki_uri *, struct rpki_uri *);
-bool uri_has_extension(struct rpki_uri *, char const *);
-bool uri_is_certificate(struct rpki_uri *);
-
-enum uri_type uri_get_type(struct rpki_uri *);
-
-char const *uri_val_get_printable(struct rpki_uri *);
-char const *uri_op_get_printable(struct rpki_uri *);
-
-char *uri_get_rrdp_workspace(struct rpki_uri *);
-
-/* Plural */
-
-DEFINE_ARRAY_LIST_STRUCT(uri_list, struct rpki_uri *);
-
-void uris_init(struct uri_list *);
-void uris_cleanup(struct uri_list *);
-
-void uris_add(struct uri_list *, struct rpki_uri *);
-
-#endif /* SRC_TYPES_URI_H_ */
index 7419fdb3eca2498f95b46830f776518ea459db95..98d84c93d129caf347e193244cbf762a67025c30 100644 (file)
@@ -36,7 +36,7 @@ check_PROGRAMS += rrdp.test
 check_PROGRAMS += serial.test
 check_PROGRAMS += tal.test
 check_PROGRAMS += thread_pool.test
-check_PROGRAMS += uri.test
+check_PROGRAMS += map.test
 check_PROGRAMS += uthash.test
 check_PROGRAMS += vcard.test
 check_PROGRAMS += vrps.test
@@ -85,8 +85,8 @@ tal_test_LDADD = ${MY_LDADD}
 thread_pool_test_SOURCES = thread_pool_test.c
 thread_pool_test_LDADD = ${MY_LDADD}
 
-uri_test_SOURCES = types/uri_test.c
-uri_test_LDADD = ${MY_LDADD}
+map_test_SOURCES = types/map_test.c
+map_test_LDADD = ${MY_LDADD}
 
 uthash_test_SOURCES = data_structure/uthash_test.c
 uthash_test_LDADD = ${MY_LDADD}
index b06ebe5db16348c1b7944a427da476bec08b9e76..71ea72521b53c037ce536763a3e65d3d76577b23 100644 (file)
@@ -11,7 +11,7 @@
 #include "json_util.c"
 #include "mock.c"
 #include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
 
 /* Mocks */
 
@@ -89,17 +89,17 @@ rsync_download(char const *src, char const *dst, bool is_directory)
 }
 
 int
-http_download(struct rpki_uri *uri, curl_off_t ims, bool *changed)
+http_download(struct cache_mapping *map, curl_off_t ims, bool *changed)
 {
        int error;
        https_counter++;
-       error = pretend_download(uri_get_local(uri));
+       error = pretend_download(map_get_path(map));
        if (changed != NULL)
                *changed = error ? false : true;
        return error;
 }
 
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
 __MOCK_ABORT(rrdp_notif2json, json_t *, NULL, struct cachefile_notification *notif)
 MOCK_VOID(rrdp_notif_free, struct cachefile_notification *notif)
 MOCK_ABORT_INT(rrdp_json2notif, json_t *json, struct cachefile_notification **result)
@@ -121,43 +121,43 @@ static void
 run_cache_download(char const *url, int expected_error,
     unsigned int rsync_calls, unsigned int https_calls)
 {
-       struct rpki_uri *uri;
-       enum uri_type type;
+       struct cache_mapping *map;
+       enum map_type type;
 
        if (str_starts_with(url, "https://"))
-               type = UT_TA_HTTP;
+               type = MAP_TA_HTTP;
        else if (str_starts_with(url, "rsync://"))
-               type = UT_RPP;
+               type = MAP_RPP;
        else
                ck_abort_msg("Bad protocol: %s", url);
 
        rsync_counter = 0;
        https_counter = 0;
 
-       ck_assert_int_eq(0, uri_create(&uri, type, NULL, url));
-       ck_assert_int_eq(expected_error, cache_download(cache, uri, NULL, NULL));
+       ck_assert_int_eq(0, map_create(&map, type, NULL, url));
+       ck_assert_int_eq(expected_error, cache_download(cache, map, NULL, NULL));
        ck_assert_uint_eq(rsync_calls, rsync_counter);
        ck_assert_uint_eq(https_calls, https_counter);
 
-       uri_refput(uri);
+       map_refput(map);
 }
 
 static struct cache_node *
 node(char const *url, time_t attempt, int err, bool succeeded, time_t success,
     bool is_notif)
 {
-       enum uri_type type;
+       enum map_type type;
        struct cache_node *result;
 
        if (str_starts_with(url, "https://"))
-               type = is_notif ? UT_NOTIF : UT_TA_HTTP;
+               type = is_notif ? MAP_NOTIF : MAP_TA_HTTP;
        else if (str_starts_with(url, "rsync://"))
-               type = UT_RPP;
+               type = MAP_RPP;
        else
                ck_abort_msg("Bad protocol: %s", url);
 
        result = pzalloc(sizeof(struct cache_node));
-       ck_assert_int_eq(0, uri_create(&result->url, type, NULL, url));
+       ck_assert_int_eq(0, map_create(&result->map, type, NULL, url));
        result->attempt.ts = attempt;
        result->attempt.result = err;
        result->success.happened = succeeded;
@@ -183,7 +183,7 @@ find_downloaded_path(struct cache_node *node)
        struct downloaded_path *path;
 
        SLIST_FOREACH(path, &downloaded, hook)
-               if (strcmp(uri_get_local(node->url), path->path) == 0) {
+               if (strcmp(map_get_path(node->map), path->path) == 0) {
                        if (path->visited)
                                return NULL;
                        else {
@@ -212,7 +212,7 @@ validate_node(struct cache_node *expected, struct cache_node *actual)
                return;
        }
 
-       ck_assert_str_eq(uri_get_global(expected->url), uri_get_global(actual->url));
+       ck_assert_str_eq(map_get_url(expected->map), map_get_url(actual->map));
        /* ck_assert_int_eq(expected->attempt.ts, actual->attempt.ts); */
        ck_assert_int_eq(expected->attempt.result, actual->attempt.result);
        ck_assert_int_eq(expected->success.happened, actual->success.happened);
@@ -234,10 +234,10 @@ validate_cache(int trash, ...)
        va_start(args, trash);
        while ((e = va_arg(args, struct cache_node *)) != NULL) {
                printf("- %s %s error:%u success:%u\n",
-                   uri_get_global(e->url), uri_get_local(e->url),
+                   map_get_url(e->map), map_get_path(e->map),
                    e->attempt.result, e->success.happened);
 
-               key = uri_get_global(e->url);
+               key = map_get_url(e->map);
                HASH_ADD_KEYPTR(hh, expected, key, strlen(key), e);
        }
        va_end(args);
@@ -246,7 +246,7 @@ validate_cache(int trash, ...)
        printf("Actual nodes:\n");
        HASH_ITER(hh, cache->ht, a, tmp)
                printf("- %s %s attempt:%u success:%u\n",
-                   uri_get_global(a->url), uri_get_local(a->url),
+                   map_get_url(a->map), map_get_path(a->map),
                    a->attempt.result, a->success.happened);
        printf("\n");
 
@@ -263,7 +263,7 @@ validate_cache(int trash, ...)
                if (e->attempt.ts) { /* "if should have cache file" */
                        if (path == NULL)
                                ck_abort_msg("Cached file is missing: %s",
-                                   uri_get_local(e->url));
+                                   map_get_path(e->map));
                        path->visited = true;
                } else {
                        if (path != NULL) {
@@ -277,7 +277,7 @@ validate_cache(int trash, ...)
 
        /* Compare expected and actual */
        HASH_ITER(hh, cache->ht, a, tmp) {
-               key = uri_get_global(a->url);
+               key = map_get_url(a->map);
                HASH_FIND_STR(expected, key, e);
                if (e == NULL)
                        ck_abort_msg("Unexpected actual: %s", key);
@@ -285,13 +285,13 @@ validate_cache(int trash, ...)
                validate_node(e, a);
 
                HASH_DEL(expected, e);
-               uri_refput(e->url);
+               map_refput(e->map);
                free(e);
        }
 
        if (HASH_COUNT(expected) != 0)
                ck_abort_msg("Actual node is mising: %s",
-                   uri_get_global(expected->url));
+                   map_get_url(expected->map));
 }
 
 static void
@@ -770,73 +770,73 @@ START_TEST(test_tal_json)
 END_TEST
 
 static void
-prepare_uri_list(struct uri_list *uris, ...)
+prepare_map_list(struct map_list *maps, ...)
 {
        char const *str;
-       enum uri_type type;
-       struct rpki_uri *uri;
+       enum map_type type;
+       struct cache_mapping *map;
        va_list args;
 
-       uris_init(uris);
+       maps_init(maps);
 
-       va_start(args, uris);
+       va_start(args, maps);
        while ((str = va_arg(args, char const *)) != NULL) {
                if (str_starts_with(str, "https://"))
-                       type = UT_TA_HTTP;
+                       type = MAP_TA_HTTP;
                else if (str_starts_with(str, "rsync://"))
-                       type = UT_RPP;
+                       type = MAP_RPP;
                else
                        ck_abort_msg("Bad protocol: %s", str);
-               ck_assert_int_eq(0, uri_create(&uri, type, NULL, str));
-               uris_add(uris, uri);
+               ck_assert_int_eq(0, map_create(&map, type, NULL, str));
+               maps_add(maps, map);
        }
        va_end(args);
 }
 
-#define PREPARE_URI_LIST(uris, ...) prepare_uri_list(uris, ##__VA_ARGS__, NULL)
+#define PREPARE_MAP_LIST(maps, ...) prepare_map_list(maps, ##__VA_ARGS__, NULL)
 
 START_TEST(test_recover)
 {
-       struct uri_list uris;
+       struct map_list maps;
 
        setup_test();
 
        /* Query on empty database */
-       PREPARE_URI_LIST(&uris, "rsync://a.b.c/d", "https://a.b.c/d");
-       ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a.b.c/d", "https://a.b.c/d");
+       ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Only first URI is cached */
        cache_reset(cache);
        run_cache_download("rsync://a/b/c", 0, 1, 0);
 
-       PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
-       ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+       ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Only second URI is cached */
        cache_reset(cache);
        run_cache_download("https://d/e", 0, 0, 1);
 
-       PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
-       ck_assert_ptr_eq(uris.array[1], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+       ck_assert_ptr_eq(maps.array[1], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Only third URI is cached */
        cache_reset(cache);
        run_cache_download("https://f", 0, 0, 1);
 
-       PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
-       ck_assert_ptr_eq(uris.array[2], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+       ck_assert_ptr_eq(maps.array[2], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* None was cached */
        cache_reset(cache);
        run_cache_download("rsync://d/e", 0, 1, 0);
 
-       PREPARE_URI_LIST(&uris, "rsync://a/b/c", "https://d/e", "https://f");
-       ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/b/c", "https://d/e", "https://f");
+       ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /*
         * At present, cache_recover() can only be called after all of a
@@ -861,23 +861,23 @@ START_TEST(test_recover)
        add_node(cache, node("rsync://b/6", 100, 1, 0, 200, 0));
 
        /* Multiple successful caches: Prioritize the most recent one */
-       PREPARE_URI_LIST(&uris, "rsync://a/1", "rsync://a/3", "rsync://a/5");
-       ck_assert_ptr_eq(uris.array[2], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/1", "rsync://a/3", "rsync://a/5");
+       ck_assert_ptr_eq(maps.array[2], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
-       PREPARE_URI_LIST(&uris, "rsync://a/5", "rsync://a/1", "rsync://a/3");
-       ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/5", "rsync://a/1", "rsync://a/3");
+       ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* No successful caches: No viable candidates */
-       PREPARE_URI_LIST(&uris, "rsync://b/2", "rsync://b/4", "rsync://b/6");
-       ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://b/2", "rsync://b/4", "rsync://b/6");
+       ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Status: CNF_SUCCESS is better than 0. */
-       PREPARE_URI_LIST(&uris, "rsync://b/1", "rsync://a/1");
-       ck_assert_ptr_eq(uris.array[1], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://b/1", "rsync://a/1");
+       ck_assert_ptr_eq(maps.array[1], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /*
         * If CNF_SUCCESS && error, Fort will probably run into a problem
@@ -886,24 +886,24 @@ START_TEST(test_recover)
         * But it should still TRY to read it, as there's a chance the
         * outdatedness is not that severe.
         */
-       PREPARE_URI_LIST(&uris, "rsync://a/2", "rsync://b/2");
-       ck_assert_ptr_eq(uris.array[0], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a/2", "rsync://b/2");
+       ck_assert_ptr_eq(maps.array[0], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Parents of downloaded nodes */
-       PREPARE_URI_LIST(&uris, "rsync://a", "rsync://b");
-       ck_assert_ptr_eq(NULL, cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       PREPARE_MAP_LIST(&maps, "rsync://a", "rsync://b");
+       ck_assert_ptr_eq(NULL, cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        /* Try them all at the same time */
-       PREPARE_URI_LIST(&uris,
+       PREPARE_MAP_LIST(&maps,
            "rsync://a", "rsync://a/1", "rsync://a/2", "rsync://a/3",
            "rsync://a/4", "rsync://a/5", "rsync://a/6",
            "rsync://b", "rsync://b/1", "rsync://b/2", "rsync://b/3",
            "rsync://b/4", "rsync://b/5", "rsync://b/6",
            "rsync://e/1");
-       ck_assert_ptr_eq(uris.array[5], cache_recover(cache, &uris));
-       uris_cleanup(&uris);
+       ck_assert_ptr_eq(maps.array[5], cache_recover(cache, &maps));
+       maps_cleanup(&maps);
 
        cleanup_test();
 }
index c870c9afc17f691e5cf107cf9c1d85bb91602073..ec979f57381189850340fa9a51f3d1cff2c69be9 100644 (file)
@@ -6,7 +6,7 @@
 #include "file.c"
 #include "mock.c"
 #include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
 #include "crypto/hash.c"
 
 MOCK_ABORT_INT(cache_tmpfile, char **filename)
@@ -40,14 +40,14 @@ START_TEST(test_hash)
        struct hash_algorithm const *ha;
        char const *name;
        char const *input = "Fort";
-       struct rpki_uri uri = { 0 };
+       struct cache_mapping map = { 0 };
 
        hash_setup();
 
-       uri.global = "https://example.com/resources/lorem-ipsum.txt";
-       uri.local = "resources/lorem-ipsum.txt";
-       uri.type = UT_TA_HTTP;
-       uri.references = 1;
+       map.url = "https://example.com/resources/lorem-ipsum.txt";
+       map.path = "resources/lorem-ipsum.txt";
+       map.type = MAP_TA_HTTP;
+       map.references = 1;
 
        ha = hash_get_sha1();
        ck_assert_uint_eq(20, hash_get_size(ha));
@@ -59,10 +59,10 @@ START_TEST(test_hash)
        FORT_SHA1[1] = 1;
        ck_assert_int_eq(EINVAL, hash_validate(ha, (unsigned char *)input, strlen(input), FORT_SHA1, sizeof(FORT_SHA1)));
 
-       ck_assert_int_eq(0, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1)));
-       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1) - 10));
+       ck_assert_int_eq(0, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1)));
+       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1) - 10));
        FILE_SHA1[19] = 0;
-       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA1, sizeof(FILE_SHA1)));
+       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA1, sizeof(FILE_SHA1)));
 
        ha = hash_get_sha256();
        ck_assert_uint_eq(32, hash_get_size(ha));
@@ -74,10 +74,10 @@ START_TEST(test_hash)
        FORT_SHA256[10] = 0;
        ck_assert_int_eq(EINVAL, hash_validate(ha, (unsigned char *)input, strlen(input), FORT_SHA256, sizeof(FORT_SHA256)));
 
-       ck_assert_int_eq(0, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256)));
-       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256) - 1));
+       ck_assert_int_eq(0, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256)));
+       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256) - 1));
        FILE_SHA256[31] = 10;
-       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &uri, FILE_SHA256, sizeof(FILE_SHA256)));
+       ck_assert_int_eq(-EINVAL, hash_validate_file(ha, &map, FILE_SHA256, sizeof(FILE_SHA256)));
 
        hash_teardown();
 }
index 357536a289f35b8cd81b7fff5d81d198a3898aaa..22f82e970cc6d178d43fcd9dfb0ada12670eb74f 100644 (file)
@@ -119,13 +119,13 @@ START_TEST(test_replace)
 END_TEST
 
 /*
- * To assure myself I can hash nodes using an rpki_uri's global field as key.
+ * To assure myself I can hash nodes using an cache_mapping's url field as key.
  * (Given that they're private.)
  *
  * ie. Neither the node nor the key contains the key, but the key points to it
  * somewhere else.
  */
-START_TEST(test_uri)
+START_TEST(test_map)
 {
        struct test2_key {
                char *outer_string;
@@ -193,17 +193,17 @@ END_TEST
 static Suite *pdu_suite(void)
 {
        Suite *suite;
-       TCase *core, *uri;
+       TCase *core, *map;
 
        core = tcase_create("simple");
        tcase_add_test(core, test_replace);
 
-       uri = tcase_create("uri");
-       tcase_add_test(uri, test_uri);
+       map = tcase_create("map");
+       tcase_add_test(map, test_map);
 
        suite = suite_create("uthash");
        suite_add_tcase(suite, core);
-       suite_add_tcase(suite, uri);
+       suite_add_tcase(suite, map);
        return suite;
 }
 
index f15bcf0effafa350ba640bb0f6ca67ecc5ed0ff2..8622e7d79f99ab6032f0ba35d8fc252374b9dcaa 100644 (file)
@@ -11,7 +11,7 @@
 #include "crypto/base64.c"
 #include "crypto/hash.c"
 #include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
 #include "xml/relax_ng.c"
 
 /* Mocks */
@@ -31,10 +31,11 @@ cache_tmpfile(char **filename)
        return 0;
 }
 
-MOCK_ABORT_INT(cache_download, struct rpki_cache *cache, struct rpki_uri *uri,
-    bool *changed, struct cachefile_notification ***notif)
+MOCK_ABORT_INT(cache_download, struct rpki_cache *cache,
+    struct cache_mapping *map, bool *changed,
+    struct cachefile_notification ***notif)
 MOCK_ABORT_VOID(fnstack_pop, void)
-MOCK_ABORT_VOID(fnstack_push_uri, struct rpki_uri *uri)
+MOCK_ABORT_VOID(fnstack_push_map, struct cache_mapping *map)
 MOCK_ABORT_PTR(validation_cache, rpki_cache, struct validation *state)
 
 MOCK(state_retrieve, struct validation *, NULL, void)
@@ -459,41 +460,41 @@ START_TEST(test_update_notif)
 END_TEST
 
 static void
-init_uri(struct rpki_uri *uri, char *global, char *local, enum uri_type type)
+init_map(struct cache_mapping *map, char *global, char *path, enum map_type type)
 {
-       uri->global = global;
-       uri->local = local;
-       uri->type = type;
-       uri->references = 1;
+       map->url = global;
+       map->path = path;
+       map->type = type;
+       map->references = 1;
 }
 
-#define init_notif_uri(u, g, l) init_uri(u, g, l, UT_NOTIF)
+#define init_notif_map(u, g, l) init_map(u, g, l, MAP_NOTIF)
 
 START_TEST(test_parse_notification_ok)
 {
-       struct rpki_uri uri;
+       struct cache_mapping map;
        struct update_notification notif;
 
        ck_assert_int_eq(0, relax_ng_init());
-       init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-ok.xml");
-       ck_assert_int_eq(0, parse_notification(&uri, &notif));
+       init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-ok.xml");
+       ck_assert_int_eq(0, parse_notification(&map, &notif));
 
        ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
        ck_assert_str_eq("3", (char const *)notif.session.serial.str);
 
-       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
        ck_assert_uint_eq(32, notif.snapshot.hash_len);
        validate_aaaa_hash(notif.snapshot.hash);
 
        ck_assert_uint_eq(2, notif.deltas.len);
 
        ck_assert_str_eq("2", (char const *)notif.deltas.array[0].serial.str);
-       ck_assert_str_eq("https://host/9d-8/2/delta.xml", notif.deltas.array[0].meta.uri->global);
+       ck_assert_str_eq("https://host/9d-8/2/delta.xml", notif.deltas.array[0].meta.uri->url);
        ck_assert_uint_eq(32, notif.deltas.array[0].meta.hash_len);
        validate_01234_hash(notif.deltas.array[0].meta.hash);
 
        ck_assert_str_eq("3", (char const *)notif.deltas.array[1].serial.str);
-       ck_assert_str_eq("https://host/9d-8/3/delta.xml", notif.deltas.array[1].meta.uri->global);
+       ck_assert_str_eq("https://host/9d-8/3/delta.xml", notif.deltas.array[1].meta.uri->url);
        ck_assert_uint_eq(32, notif.deltas.array[1].meta.hash_len);
        validate_01234_hash(notif.deltas.array[0].meta.hash);
 
@@ -504,17 +505,17 @@ END_TEST
 
 START_TEST(test_parse_notification_0deltas)
 {
-       struct rpki_uri uri;
+       struct cache_mapping map;
        struct update_notification notif;
 
        ck_assert_int_eq(0, relax_ng_init());
-       init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-0deltas.xml");
-       ck_assert_int_eq(0, parse_notification(&uri, &notif));
+       init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-0deltas.xml");
+       ck_assert_int_eq(0, parse_notification(&map, &notif));
 
        ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
        ck_assert_str_eq("3", (char const *)notif.session.serial.str);
 
-       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
        ck_assert_uint_eq(32, notif.snapshot.hash_len);
        validate_01234_hash(notif.snapshot.hash);
 
@@ -527,12 +528,12 @@ END_TEST
 
 START_TEST(test_parse_notification_large_serial)
 {
-       struct rpki_uri uri;
+       struct cache_mapping map;
        struct update_notification notif;
 
        ck_assert_int_eq(0, relax_ng_init());
-       init_notif_uri(&uri, "https://host/notification.xml", "resources/rrdp/notif-large-serial.xml");
-       ck_assert_int_eq(0, parse_notification(&uri, &notif));
+       init_notif_map(&map, "https://host/notification.xml", "resources/rrdp/notif-large-serial.xml");
+       ck_assert_int_eq(0, parse_notification(&map, &notif));
 
        ck_assert_str_eq("9df4b597-af9e-4dca-bdda-719cce2c4e28", (char const *)notif.session.session_id);
        /*
@@ -543,7 +544,7 @@ START_TEST(test_parse_notification_large_serial)
         */
        ck_assert_str_eq("999999999999999999999999", (char const *)notif.session.serial.str);
 
-       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->global);
+       ck_assert_str_eq("https://host/9d-8/3/snapshot.xml", notif.snapshot.uri->url);
        ck_assert_uint_eq(32, notif.snapshot.hash_len);
        validate_01234_hash(notif.snapshot.hash);
 
@@ -557,12 +558,12 @@ END_TEST
 static void
 test_parse_notification_error(char *file)
 {
-       struct rpki_uri uri;
+       struct cache_mapping map;
        struct update_notification notif;
 
        ck_assert_int_eq(0, relax_ng_init());
-       init_notif_uri(&uri, "https://host/notification.xml", file);
-       ck_assert_int_eq(-EINVAL, parse_notification(&uri, &notif));
+       init_notif_map(&map, "https://host/notification.xml", file);
+       ck_assert_int_eq(-EINVAL, parse_notification(&map, &notif));
 
        relax_ng_cleanup();
 }
@@ -618,19 +619,19 @@ BN_two(void)
 START_TEST(test_parse_snapshot_bad_publish)
 {
        struct update_notification notif = { 0 };
-       struct rpki_uri notif_uri = { 0 };
-       struct rpki_uri snapshot_uri = { 0 };
+       struct cache_mapping notif_map = { 0 };
+       struct cache_mapping snapshot_map = { 0 };
 
        ck_assert_int_eq(0, relax_ng_init());
 
-       init_notif_uri(&notif_uri, "https://example.com/notification.xml", "cache/example.com/notification.xml");
-       init_uri(&snapshot_uri, "https://example.com/snapshot.xml", "resources/rrdp/snapshot-bad-publish.xml", UT_TMP);
+       init_notif_map(&notif_map, "https://example.com/notification.xml", "cache/example.com/notification.xml");
+       init_map(&snapshot_map, "https://example.com/snapshot.xml", "resources/rrdp/snapshot-bad-publish.xml", MAP_TMP);
 
        notif.session.session_id = "9df4b597-af9e-4dca-bdda-719cce2c4e28";
        notif.session.serial.str = "2";
        notif.session.serial.num = BN_two();
-       notif.snapshot.uri = &snapshot_uri;
-       notif.uri = &notif_uri;
+       notif.snapshot.uri = &snapshot_map;
+       notif.map = &notif_map;
 
        ck_assert_int_eq(-EINVAL, parse_snapshot(&notif));
 
index d8529e059b247f1f78fff227698ec591b61c49d3..403a1eec7b3bc74d16359c5f2853928df4fbcea1 100644 (file)
@@ -70,7 +70,6 @@ static unsigned int deltas_lifetime = 5;
 
 MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void)
 MOCK_ABORT_ENUM(config_get_output_format, output_format, void)
-MOCK_ABORT_INT(hash_local_file, char const *uri, unsigned char *result)
 
 /* Test functions */
 
index 0adf36e8f6718e429110c71e1bb5c6d586a9d8a4..b1e639d83fdd5963992edcd4c8384bf2effd0fbb 100644 (file)
@@ -7,7 +7,7 @@
 #include "file.c"
 #include "mock.c"
 #include "data_structure/path_builder.c"
-#include "types/uri.c"
+#include "types/map.c"
 #include "crypto/base64.c"
 
 /* Mocks */
 MOCK_ABORT_VOID(cache_setup, void)
 MOCK(cache_create, struct rpki_cache *, NULL, void)
 MOCK_VOID(cache_destroy, struct rpki_cache *cache)
-MOCK_ABORT_INT(cache_download, struct rpki_cache *cache, struct rpki_uri *uri,
-    bool *changed, struct cachefile_notification ***notif)
+MOCK_ABORT_INT(cache_download, struct rpki_cache *cache,
+    struct cache_mapping *map, bool *changed,
+    struct cachefile_notification ***notif)
 MOCK_ABORT_INT(cache_download_alt, struct rpki_cache *cache,
-    struct uri_list *uris, enum uri_type http_type, enum uri_type rsync_type,
-    uris_dl_cb cb, void *arg)
-MOCK_ABORT_PTR(cache_recover, rpki_uri, struct rpki_cache *cache,
-    struct uri_list *uris)
+    struct map_list *maps, enum map_type http_type, enum map_type rsync_type,
+    maps_dl_cb cb, void *arg)
+MOCK_ABORT_PTR(cache_recover, cache_mapping, struct rpki_cache *cache,
+    struct map_list *maps)
 MOCK_ABORT_INT(cache_tmpfile, char **filename)
 MOCK_ABORT_VOID(cache_teardown, void)
 MOCK_ABORT_INT(certificate_traverse, struct rpp *rpp_parent,
-    struct rpki_uri *cert_uri)
+    struct cache_mapping *cert_map)
 MOCK_ABORT_PTR(db_table_create, db_table, void)
 MOCK_VOID(db_table_destroy, struct db_table *table)
 MOCK_ABORT_INT(db_table_join, struct db_table *dst, struct db_table *src)
@@ -41,7 +42,7 @@ MOCK_ABORT_INT(handle_roa_v6, uint32_t as, struct ipv6_prefix const *prefix,
 MOCK_ABORT_INT(handle_router_key, unsigned char const *ski,
     struct asn_range const *asns, unsigned char const *spk, void *arg)
 MOCK_ABORT_VOID(rpp_refput, struct rpp *pp)
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
 MOCK(state_retrieve, struct validation *, NULL, void)
 MOCK_ABORT_PTR(validation_certstack, cert_stack, struct validation *state)
 MOCK_ABORT_VOID(validation_destroy, struct validation *state)
@@ -99,8 +100,8 @@ test_1url(char const *file)
 
        ck_assert_int_eq(0, tal_init(&tal, file));
 
-       ck_assert_uint_eq(1, tal.uris.len);
-       ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.uris.array[0]->global);
+       ck_assert_uint_eq(1, tal.maps.len);
+       ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.maps.array[0]->url);
        check_spki(&tal);
 
        tal_cleanup(&tal);
@@ -120,11 +121,11 @@ test_4urls(char const *file)
 
        ck_assert_int_eq(0, tal_init(&tal, file));
 
-       ck_assert_uint_eq(4, tal.uris.len);
-       ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.uris.array[0]->global);
-       ck_assert_str_eq("https://example.com/rpki/ta.cer", tal.uris.array[1]->global);
-       ck_assert_str_eq("rsync://www.example.com/potato/ta.cer", tal.uris.array[2]->global);
-       ck_assert_str_eq("https://wx3.example.com/tomato/ta.cer", tal.uris.array[3]->global);
+       ck_assert_uint_eq(4, tal.maps.len);
+       ck_assert_str_eq("rsync://example.com/rpki/ta.cer", tal.maps.array[0]->url);
+       ck_assert_str_eq("https://example.com/rpki/ta.cer", tal.maps.array[1]->url);
+       ck_assert_str_eq("rsync://www.example.com/potato/ta.cer", tal.maps.array[2]->url);
+       ck_assert_str_eq("https://wx3.example.com/tomato/ta.cer", tal.maps.array[3]->url);
 
        check_spki(&tal);
 
diff --git a/test/types/map_test.c b/test/types/map_test.c
new file mode 100644 (file)
index 0000000..037cf54
--- /dev/null
@@ -0,0 +1,251 @@
+#include <check.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include "alloc.c"
+#include "common.c"
+#include "mock.c"
+#include "types/map.c"
+#include "data_structure/path_builder.c"
+
+/* Mocks */
+
+static struct cache_mapping *notif;
+
+MOCK(state_retrieve, struct validation *, NULL, void)
+MOCK(validation_tal, struct tal *, NULL, struct validation *state)
+MOCK(tal_get_file_name, char const *, NULL, struct tal *tal)
+
+MOCK_ABORT_INT(rrdp_update, struct cache_mapping *map)
+
+int
+cache_tmpfile(char **filename)
+{
+       static unsigned int used = 1;
+
+       if (used > 2) {
+               ck_abort_msg("cache_tmpfile() called a third time!");
+               return -EINVAL;
+       }
+
+       *filename = pstrdup("tmp/tmp/0");
+       used = true;
+       return 0;
+}
+
+/* Tests */
+
+#define MAP_CREATE_HTTP(map, str) map_create(&map, MAP_TA_HTTP, NULL, str)
+#define MAP_CREATE(map, type, str) map_create(&map, type, NULL, str)
+
+START_TEST(test_constructor)
+{
+       struct cache_mapping *map;
+
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, ""));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "h"));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "http"));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https"));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https:"));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "https:/"));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://"));
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c"));
+       ck_assert_str_eq("https://a.b.c", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/"));
+       ck_assert_str_eq("https://a.b.c", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d"));
+       ck_assert_str_eq("https://a.b.c/d", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c/d", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d/e"));
+       ck_assert_str_eq("https://a.b.c/d/e", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c/d/e", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/d/.."));
+       ck_assert_str_eq("https://a.b.c", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/."));
+       ck_assert_str_eq("https://a.b.c", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/././d/././e/./."));
+       ck_assert_str_eq("https://a.b.c/d/e", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c/d/e", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE_HTTP(map, "https://a.b.c/a/b/.././.."));
+       ck_assert_str_eq("https://a.b.c", map_get_url(map));
+       ck_assert_str_eq("tmp/https/a.b.c", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/../.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/d/../.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://a.b.c/d/../../.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://./."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://../.."));
+       ck_assert_int_eq(-EINVAL, MAP_CREATE_HTTP(map, "https://../../.."));
+
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "rsync://a.b.c/d"));
+       ck_assert_int_eq(ENOTHTTPS, MAP_CREATE_HTTP(map, "http://a.b.c/d"));
+       ck_assert_int_eq(ENOTRSYNC, MAP_CREATE(map, MAP_RPP, "https://a.b.c/d"));
+
+       ck_assert_int_eq(0, MAP_CREATE(map, MAP_RPP, "rsync://a.b.c/d"));
+       ck_assert_str_eq("rsync://a.b.c/d", map_get_url(map));
+       ck_assert_str_eq("tmp/rsync/a.b.c/d", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE(map, MAP_TA_RSYNC, "rsync://a.b.c/d.cer"));
+       ck_assert_str_eq("rsync://a.b.c/d.cer", map_get_url(map));
+       ck_assert_str_eq("tmp/rsync/a.b.c/d.cer", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE(map, MAP_NOTIF, "https://a.b.c/notification.xml"));
+       ck_assert_str_eq("https://a.b.c/notification.xml", map_get_url(map));
+       ck_assert_str_eq("tmp/tmp/0", map_get_path(map));
+       map_refput(map);
+
+       ck_assert_int_eq(0, MAP_CREATE(map, MAP_TMP, "https://a.b.c/snapshot.xml"));
+       ck_assert_str_eq("https://a.b.c/snapshot.xml", map_get_url(map));
+       ck_assert_str_eq("tmp/tmp/0", map_get_path(map));
+       map_refput(map);
+}
+END_TEST
+
+#define BUFFER_LEN 128
+static uint8_t buffer[BUFFER_LEN];
+
+static int
+__test_validate(char const *src, size_t len)
+{
+       IA5String_t dst;
+       unsigned int i;
+
+       memcpy(buffer, src, len);
+       for (i = len; i < BUFFER_LEN - 1; i++)
+               buffer[i] = '_';
+       buffer[BUFFER_LEN - 1] = 0;
+
+       dst.buf = buffer;
+       dst.size = len;
+
+       return validate_mft_file(&dst);
+}
+
+#define test_validate(str) __test_validate(str, sizeof(str) - 1)
+
+START_TEST(check_validate_current_directory)
+{
+       ck_assert_int_eq(-EINVAL, test_validate(""));
+       ck_assert_int_eq(-EINVAL, test_validate("."));
+       ck_assert_int_eq(-EINVAL, test_validate(".."));
+
+       ck_assert_int_eq(-EINVAL, test_validate("filename"));
+       ck_assert_int_eq(-EINVAL, test_validate("filename."));
+       ck_assert_int_eq(-EINVAL, test_validate("filename.a"));
+       ck_assert_int_eq(-EINVAL, test_validate("filename.ab"));
+       ck_assert_int_eq(0, test_validate("filename.abc"));
+       ck_assert_int_eq(-EINVAL, test_validate("file.abcd"));
+
+       ck_assert_int_eq(0, test_validate("file-name.ABC"));
+       ck_assert_int_eq(0, test_validate("file_name.123"));
+       ck_assert_int_eq(0, test_validate("file0name.aB2"));
+       ck_assert_int_eq(0, test_validate("file9name.---"));
+       ck_assert_int_eq(0, test_validate("FileName.A3_"));
+       ck_assert_int_eq(-EINVAL, test_validate("file.name.abc"));
+       ck_assert_int_eq(-EINVAL, test_validate("file/name.abc"));
+       ck_assert_int_eq(-EINVAL, test_validate("file\0name.abc"));
+       ck_assert_int_eq(-EINVAL, test_validate("filename.abc\0filename.abc"));
+       ck_assert_int_eq(-EINVAL, test_validate("filenameabc\0filename.abc"));
+       ck_assert_int_eq(0, test_validate("-.---"));
+
+       ck_assert_int_eq(0, test_validate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_.-_-"));
+       ck_assert_int_eq(0, test_validate("vixxBTS_TVXQ-2pmGOT7.cer"));
+}
+END_TEST
+
+START_TEST(check_caged)
+{
+       struct cache_mapping *map;
+
+       ck_assert_int_eq(0, map_create(&notif, MAP_NOTIF, NULL, "https://a.b.c/d/e.xml"));
+       ck_assert_int_eq(0, map_create(&map, MAP_CAGED, notif, "rsync://x.y.z/v/w.cer"));
+       ck_assert_str_eq("tmp/rrdp/a.b.c/d/e.xml/x.y.z/v/w.cer", map_get_path(map));
+       map_refput(map);
+       map_refput(notif);
+
+       ck_assert_int_eq(0, map_create(&notif, MAP_NOTIF, NULL, "https://a.b.c"));
+       ck_assert_int_eq(0, map_create(&map, MAP_CAGED, notif, "rsync://w"));
+       ck_assert_str_eq("tmp/rrdp/a.b.c/w", map_get_path(map));
+       map_refput(map);
+       map_refput(notif);
+}
+END_TEST
+
+START_TEST(test_same_origin)
+{
+       ck_assert_int_eq(true,  str_same_origin("https://a.b.c/d/e/f",  "https://a.b.c/g/h/i"));
+       ck_assert_int_eq(false, str_same_origin("https://a.b.cc/d/e/f", "https://a.b.c/g/h/i"));
+       ck_assert_int_eq(false, str_same_origin("https://a.b.c/d/e/f",  "https://a.b.cc/g/h/i"));
+       ck_assert_int_eq(true,  str_same_origin("https://a.b.c",        "https://a.b.c"));
+       ck_assert_int_eq(true,  str_same_origin("https://a.b.c/",       "https://a.b.c"));
+       ck_assert_int_eq(true,  str_same_origin("https://a.b.c",        "https://a.b.c/"));
+       ck_assert_int_eq(true,  str_same_origin("https://",             "https://"));
+       ck_assert_int_eq(false, str_same_origin("https://",             "https://a"));
+       ck_assert_int_eq(false, str_same_origin("https://a",            "https://b"));
+
+       /* Undefined, but manhandle the code anyway */
+       ck_assert_int_eq(false, str_same_origin("",                     ""));
+       ck_assert_int_eq(false, str_same_origin("ht",                   "ht"));
+       ck_assert_int_eq(false, str_same_origin("https:",               "https:"));
+       ck_assert_int_eq(false, str_same_origin("https:/",              "https:/"));
+       ck_assert_int_eq(false, str_same_origin("https:/a",             "https:/a"));
+       ck_assert_int_eq(true,  str_same_origin("https:/a/",            "https:/a/"));
+}
+END_TEST
+
+static Suite *address_load_suite(void)
+{
+       Suite *suite;
+       TCase *core;
+
+       core = tcase_create("Core");
+       tcase_add_test(core, test_constructor);
+       tcase_add_test(core, check_validate_current_directory);
+       tcase_add_test(core, check_caged);
+       tcase_add_test(core, test_same_origin);
+
+       suite = suite_create("Encoding checking");
+       suite_add_tcase(suite, core);
+       return suite;
+}
+
+int main(void)
+{
+       Suite *suite;
+       SRunner *runner;
+       int tests_failed;
+
+       suite = address_load_suite();
+
+       runner = srunner_create(suite);
+       srunner_run_all(runner, CK_NORMAL);
+       tests_failed = srunner_ntests_failed(runner);
+       srunner_free(runner);
+
+       return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/types/uri_test.c b/test/types/uri_test.c
deleted file mode 100644 (file)
index f71922d..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-#include <check.h>
-#include <errno.h>
-#include <stdint.h>
-
-#include "alloc.c"
-#include "common.c"
-#include "mock.c"
-#include "types/uri.c"
-#include "data_structure/path_builder.c"
-
-/* Mocks */
-
-static struct rpki_uri *notif;
-
-MOCK(state_retrieve, struct validation *, NULL, void)
-MOCK(validation_tal, struct tal *, NULL, struct validation *state)
-MOCK(tal_get_file_name, char const *, NULL, struct tal *tal)
-
-MOCK_ABORT_INT(rrdp_update, struct rpki_uri *uri)
-
-int
-cache_tmpfile(char **filename)
-{
-       static unsigned int used = 1;
-
-       if (used > 2) {
-               ck_abort_msg("cache_tmpfile() called a third time!");
-               return -EINVAL;
-       }
-
-       *filename = pstrdup("tmp/tmp/0");
-       used = true;
-       return 0;
-}
-
-/* Tests */
-
-#define URI_CREATE_HTTP(uri, str) uri_create(&uri, UT_TA_HTTP, NULL, str)
-#define URI_CREATE(uri, type, str) uri_create(&uri, type, NULL, str)
-
-START_TEST(test_constructor)
-{
-       struct rpki_uri *uri;
-
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, ""));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "h"));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "http"));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https"));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https:"));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "https:/"));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://"));
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c"));
-       ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/"));
-       ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d"));
-       ck_assert_str_eq("https://a.b.c/d", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c/d", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d/e"));
-       ck_assert_str_eq("https://a.b.c/d/e", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/d/.."));
-       ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/."));
-       ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/././d/././e/./."));
-       ck_assert_str_eq("https://a.b.c/d/e", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c/d/e", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE_HTTP(uri, "https://a.b.c/a/b/.././.."));
-       ck_assert_str_eq("https://a.b.c", uri_get_global(uri));
-       ck_assert_str_eq("tmp/https/a.b.c", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/../.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/d/../.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://a.b.c/d/../../.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://./."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://../.."));
-       ck_assert_int_eq(-EINVAL, URI_CREATE_HTTP(uri, "https://../../.."));
-
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "rsync://a.b.c/d"));
-       ck_assert_int_eq(ENOTHTTPS, URI_CREATE_HTTP(uri, "http://a.b.c/d"));
-       ck_assert_int_eq(ENOTRSYNC, URI_CREATE(uri, UT_RPP, "https://a.b.c/d"));
-
-       ck_assert_int_eq(0, URI_CREATE(uri, UT_RPP, "rsync://a.b.c/d"));
-       ck_assert_str_eq("rsync://a.b.c/d", uri_get_global(uri));
-       ck_assert_str_eq("tmp/rsync/a.b.c/d", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE(uri, UT_TA_RSYNC, "rsync://a.b.c/d.cer"));
-       ck_assert_str_eq("rsync://a.b.c/d.cer", uri_get_global(uri));
-       ck_assert_str_eq("tmp/rsync/a.b.c/d.cer", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE(uri, UT_NOTIF, "https://a.b.c/notification.xml"));
-       ck_assert_str_eq("https://a.b.c/notification.xml", uri_get_global(uri));
-       ck_assert_str_eq("tmp/tmp/0", uri_get_local(uri));
-       uri_refput(uri);
-
-       ck_assert_int_eq(0, URI_CREATE(uri, UT_TMP, "https://a.b.c/snapshot.xml"));
-       ck_assert_str_eq("https://a.b.c/snapshot.xml", uri_get_global(uri));
-       ck_assert_str_eq("tmp/tmp/0", uri_get_local(uri));
-       uri_refput(uri);
-}
-END_TEST
-
-#define BUFFER_LEN 128
-static uint8_t buffer[BUFFER_LEN];
-
-static int
-__test_validate(char const *src, size_t len)
-{
-       IA5String_t dst;
-       unsigned int i;
-
-       memcpy(buffer, src, len);
-       for (i = len; i < BUFFER_LEN - 1; i++)
-               buffer[i] = '_';
-       buffer[BUFFER_LEN - 1] = 0;
-
-       dst.buf = buffer;
-       dst.size = len;
-
-       return validate_mft_file(&dst);
-}
-
-#define test_validate(str) __test_validate(str, sizeof(str) - 1)
-
-START_TEST(check_validate_current_directory)
-{
-       ck_assert_int_eq(-EINVAL, test_validate(""));
-       ck_assert_int_eq(-EINVAL, test_validate("."));
-       ck_assert_int_eq(-EINVAL, test_validate(".."));
-
-       ck_assert_int_eq(-EINVAL, test_validate("filename"));
-       ck_assert_int_eq(-EINVAL, test_validate("filename."));
-       ck_assert_int_eq(-EINVAL, test_validate("filename.a"));
-       ck_assert_int_eq(-EINVAL, test_validate("filename.ab"));
-       ck_assert_int_eq(0, test_validate("filename.abc"));
-       ck_assert_int_eq(-EINVAL, test_validate("file.abcd"));
-
-       ck_assert_int_eq(0, test_validate("file-name.ABC"));
-       ck_assert_int_eq(0, test_validate("file_name.123"));
-       ck_assert_int_eq(0, test_validate("file0name.aB2"));
-       ck_assert_int_eq(0, test_validate("file9name.---"));
-       ck_assert_int_eq(0, test_validate("FileName.A3_"));
-       ck_assert_int_eq(-EINVAL, test_validate("file.name.abc"));
-       ck_assert_int_eq(-EINVAL, test_validate("file/name.abc"));
-       ck_assert_int_eq(-EINVAL, test_validate("file\0name.abc"));
-       ck_assert_int_eq(-EINVAL, test_validate("filename.abc\0filename.abc"));
-       ck_assert_int_eq(-EINVAL, test_validate("filenameabc\0filename.abc"));
-       ck_assert_int_eq(0, test_validate("-.---"));
-
-       ck_assert_int_eq(0, test_validate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_.-_-"));
-       ck_assert_int_eq(0, test_validate("vixxBTS_TVXQ-2pmGOT7.cer"));
-}
-END_TEST
-
-START_TEST(check_caged)
-{
-       struct rpki_uri *uri;
-
-       ck_assert_int_eq(0, uri_create(&notif, UT_NOTIF, NULL, "https://a.b.c/d/e.xml"));
-       ck_assert_int_eq(0, uri_create(&uri, UT_CAGED, notif, "rsync://x.y.z/v/w.cer"));
-       ck_assert_str_eq("tmp/rrdp/a.b.c/d/e.xml/x.y.z/v/w.cer", uri_get_local(uri));
-       uri_refput(uri);
-       uri_refput(notif);
-
-       ck_assert_int_eq(0, uri_create(&notif, UT_NOTIF, NULL, "https://a.b.c"));
-       ck_assert_int_eq(0, uri_create(&uri, UT_CAGED, notif, "rsync://w"));
-       ck_assert_str_eq("tmp/rrdp/a.b.c/w", uri_get_local(uri));
-       uri_refput(uri);
-       uri_refput(notif);
-}
-END_TEST
-
-START_TEST(test_same_origin)
-{
-       ck_assert_int_eq(true,  str_same_origin("https://a.b.c/d/e/f",  "https://a.b.c/g/h/i"));
-       ck_assert_int_eq(false, str_same_origin("https://a.b.cc/d/e/f", "https://a.b.c/g/h/i"));
-       ck_assert_int_eq(false, str_same_origin("https://a.b.c/d/e/f",  "https://a.b.cc/g/h/i"));
-       ck_assert_int_eq(true,  str_same_origin("https://a.b.c",        "https://a.b.c"));
-       ck_assert_int_eq(true,  str_same_origin("https://a.b.c/",       "https://a.b.c"));
-       ck_assert_int_eq(true,  str_same_origin("https://a.b.c",        "https://a.b.c/"));
-       ck_assert_int_eq(true,  str_same_origin("https://",             "https://"));
-       ck_assert_int_eq(false, str_same_origin("https://",             "https://a"));
-       ck_assert_int_eq(false, str_same_origin("https://a",            "https://b"));
-
-       /* Undefined, but manhandle the code anyway */
-       ck_assert_int_eq(false, str_same_origin("",                     ""));
-       ck_assert_int_eq(false, str_same_origin("ht",                   "ht"));
-       ck_assert_int_eq(false, str_same_origin("https:",               "https:"));
-       ck_assert_int_eq(false, str_same_origin("https:/",              "https:/"));
-       ck_assert_int_eq(false, str_same_origin("https:/a",             "https:/a"));
-       ck_assert_int_eq(true,  str_same_origin("https:/a/",            "https:/a/"));
-}
-END_TEST
-
-static Suite *address_load_suite(void)
-{
-       Suite *suite;
-       TCase *core;
-
-       core = tcase_create("Core");
-       tcase_add_test(core, test_constructor);
-       tcase_add_test(core, check_validate_current_directory);
-       tcase_add_test(core, check_caged);
-       tcase_add_test(core, test_same_origin);
-
-       suite = suite_create("Encoding checking");
-       suite_add_tcase(suite, core);
-       return suite;
-}
-
-int main(void)
-{
-       Suite *suite;
-       SRunner *runner;
-       int tests_failed;
-
-       suite = address_load_suite();
-
-       runner = srunner_create(suite);
-       srunner_run_all(runner, CK_NORMAL);
-       tests_failed = srunner_ntests_failed(runner);
-       srunner_free(runner);
-
-       return (tests_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}