From: William Lallemand Date: Thu, 25 Sep 2025 13:14:31 +0000 (+0200) Subject: CLEANUP: acme: acme_will_expire() uses acme_schedule_date() X-Git-Tag: v3.3-dev9~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c325e34e6d506aa50471e56d97b31697df3d7a5f;p=thirdparty%2Fhaproxy.git CLEANUP: acme: acme_will_expire() uses acme_schedule_date() Date computation between acme_will_expire() and acme_schedule_date() are the same. Call acme_schedule_date() from acme_will_expire() and put the functions as static. The patch also move the functions in the right order. --- diff --git a/src/acme.c b/src/acme.c index d02163838..abf79b846 100644 --- a/src/acme.c +++ b/src/acme.c @@ -2346,16 +2346,20 @@ wait: MT_LIST_UNLOCK_FULL(&ctx->el, tmp); return task; } + /* - * Return 1 if the certificate must be regenerated - * Check if the notAfter date will append in (validity period / 12) or 7 days per default + * Return when the next task is scheduled + * Check if the notAfter date will happen in (validity period / 12) or 7 days per default */ -int acme_will_expire(struct ckch_store *store) +static time_t acme_schedule_date(struct ckch_store *store) { time_t diff = 0; time_t notAfter = 0; time_t notBefore = 0; + if (!global_ssl.acme_scheduler) + return 0; + /* compute the validity period of the leaf certificate */ if (!store->data || !store->data->cert) return 0; @@ -2370,40 +2374,27 @@ int acme_will_expire(struct ckch_store *store) diff = 7 * 24 * 60 * 60; /* default to 7 days */ } - if (notAfter - diff <= date.tv_sec) - return 1; - - return 0; + return (notAfter - diff); } /* - * Return when the next task is scheduled - * Check if the notAfter date will happen in (validity period / 12) or 7 days per default + * Return 1 if the certificate must be regenerated + * Check if the notAfter date will append in (validity period / 12) or 7 days per default */ -time_t acme_schedule_date(struct ckch_store *store) +static int acme_will_expire(struct ckch_store *store) { - time_t diff = 0; time_t notAfter = 0; - time_t notBefore = 0; - - if (!global_ssl.acme_scheduler) - return 0; /* compute the validity period of the leaf certificate */ if (!store->data || !store->data->cert) return 0; - notAfter = x509_get_notafter_time_t(store->data->cert); - notBefore = x509_get_notbefore_time_t(store->data->cert); + notAfter = acme_schedule_date(store); - if ((notAfter >= 0 && notBefore >= 0) - && (notAfter > notBefore)) { - diff = (notAfter - notBefore) / 12; /* validity period / 12 */ - } else { - diff = 7 * 24 * 60 * 60; /* default to 7 days */ - } + if (notAfter <= date.tv_sec) + return 1; - return (notAfter - diff); + return 0; } /* Does the scheduling of the ACME tasks