From 6936df76e752e42ef99179eeacf887941910b9bd Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 13 Jan 2022 14:57:02 +0000 Subject: [PATCH] Move some functions around to reduce diff with an upcoming change. OK tb@ --- usr.sbin/rpki-client/repo.c | 156 ++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 162f31117ca..fb05e375791 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.23 2022/01/13 13:46:03 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.24 2022/01/13 14:57:02 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -336,47 +336,6 @@ ta_filename(const struct tarepo *tr, int temp) return nfile; } -/* - * Build local file name base on the URI and the rrdprepo info. - */ -static char * -rrdp_filename(const struct rrdprepo *rr, const char *uri, int temp) -{ - char *nfile; - char *dir = rr->basedir; - - if (temp) - dir = rr->temp; - - if (!valid_uri(uri, strlen(uri), "rsync://")) { - warnx("%s: bad URI %s", rr->basedir, uri); - return NULL; - } - - uri += strlen("rsync://"); /* skip proto */ - if (asprintf(&nfile, "%s/%s", dir, uri) == -1) - err(1, NULL); - return nfile; -} - -/* - * Build RRDP state file name based on the repo info. - * If temp is set add Xs for mkostemp. - */ -static char * -rrdp_state_filename(const struct rrdprepo *rr, int temp) -{ - char *nfile; - - if (asprintf(&nfile, "%s/.state%s", rr->basedir, - temp ? ".XXXXXXXX": "") == -1) - err(1, NULL); - - return nfile; -} - - - static void ta_fetch(struct tarepo *tr) { @@ -556,51 +515,43 @@ rsync_free(void) static int rrdprepo_fetch(struct rrdprepo *); -static struct rrdprepo * -rrdp_get(const char *uri, int nofetch) +/* + * Build local file name base on the URI and the rrdprepo info. + */ +static char * +rrdp_filename(const struct rrdprepo *rr, const char *uri, int temp) { - struct rrdprepo *rr; - - SLIST_FOREACH(rr, &rrdprepos, entry) - if (strcmp(rr->notifyuri, uri) == 0) { - if (rr->state == REPO_FAILED) - return NULL; - return rr; - } + char *nfile; + char *dir = rr->basedir; - if ((rr = calloc(1, sizeof(*rr))) == NULL) - err(1, NULL); + if (temp) + dir = rr->temp; - rr->id = ++repoid; - SLIST_INSERT_HEAD(&rrdprepos, rr, entry); + if (!valid_uri(uri, strlen(uri), "rsync://")) { + warnx("%s: bad URI %s", rr->basedir, uri); + return NULL; + } - if ((rr->notifyuri = strdup(uri)) == NULL) + uri += strlen("rsync://"); /* skip proto */ + if (asprintf(&nfile, "%s/%s", dir, uri) == -1) err(1, NULL); - rr->basedir = repo_dir(uri, "rrdp", 1); - - RB_INIT(&rr->added); - RB_INIT(&rr->deleted); + return nfile; +} - if (noop || nofetch) { - rr->state = REPO_DONE; - logx("%s: using cache", rr->notifyuri); - repo_done(rr, 0); - } else { - /* create base directory */ - if (mkpath(rr->basedir) == -1) { - warn("mkpath %s", rr->basedir); - rrdp_finish(rr->id, 0); - return rr; - } - if (rrdprepo_fetch(rr) == -1) { - rrdp_finish(rr->id, 0); - return rr; - } +/* + * Build RRDP state file name based on the repo info. + * If temp is set add Xs for mkostemp. + */ +static char * +rrdp_state_filename(const struct rrdprepo *rr, int temp) +{ + char *nfile; - logx("%s: pulling from %s", rr->notifyuri, "network"); - } + if (asprintf(&nfile, "%s/.state%s", rr->basedir, + temp ? ".XXXXXXXX": "") == -1) + err(1, NULL); - return rr; + return nfile; } static struct rrdprepo * @@ -788,6 +739,53 @@ fail: free(file); } +static struct rrdprepo * +rrdp_get(const char *uri, int nofetch) +{ + struct rrdprepo *rr; + + SLIST_FOREACH(rr, &rrdprepos, entry) + if (strcmp(rr->notifyuri, uri) == 0) { + if (rr->state == REPO_FAILED) + return NULL; + return rr; + } + + if ((rr = calloc(1, sizeof(*rr))) == NULL) + err(1, NULL); + + rr->id = ++repoid; + SLIST_INSERT_HEAD(&rrdprepos, rr, entry); + + if ((rr->notifyuri = strdup(uri)) == NULL) + err(1, NULL); + rr->basedir = repo_dir(uri, "rrdp", 1); + + RB_INIT(&rr->added); + RB_INIT(&rr->deleted); + + if (noop || nofetch) { + rr->state = REPO_DONE; + logx("%s: using cache", rr->notifyuri); + repo_done(rr, 0); + } else { + /* create base directory */ + if (mkpath(rr->basedir) == -1) { + warn("mkpath %s", rr->basedir); + rrdp_finish(rr->id, 0); + return rr; + } + if (rrdprepo_fetch(rr) == -1) { + rrdp_finish(rr->id, 0); + return rr; + } + + logx("%s: pulling from %s", rr->notifyuri, "network"); + } + + return rr; +} + /* * Remove RRDP repo and start over. */ -- 2.20.1