3030#include "md_http.h"
3131#include "md_log.h"
3232#include "md_store.h"
33+ #include "md_result.h"
3334#include "md_util.h"
3435#include "md_version.h"
3536
@@ -327,24 +328,24 @@ static apr_status_t md_acme_req_send(md_acme_req_t *req)
327328{
328329 apr_status_t rv ;
329330 md_acme_t * acme = req -> acme ;
330- const char * body = NULL , * error ;
331+ const char * body = NULL ;
332+ md_result_t * result ;
331333
332334 assert (acme -> url );
333335
334336 md_log_perror (MD_LOG_MARK , MD_LOG_DEBUG , 0 , req -> p ,
335337 "sending req: %s %s" , req -> method , req -> url );
338+ result = md_result_make (req -> p , APR_SUCCESS );
339+
336340 if (strcmp ("GET" , req -> method ) && strcmp ("HEAD" , req -> method )) {
337341 if (acme -> version == MD_ACME_VERSION_UNKNOWN ) {
338- if (APR_SUCCESS != (rv = md_acme_setup (acme , & error ))) {
339- return rv ;
340- }
342+ rv = md_acme_setup (acme , result );
343+ if (APR_SUCCESS != rv ) goto leave ;
341344 }
342- if (!acme -> nonce ) {
343- if (APR_SUCCESS != (rv = acme -> new_nonce_fn (acme ))) {
344- md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , rv , req -> p ,
345- "error retrieving new nonce from ACME server" );
346- return rv ;
347- }
345+ if (!acme -> nonce && (APR_SUCCESS != (rv = acme -> new_nonce_fn (acme )))) {
346+ md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , rv , req -> p ,
347+ "error retrieving new nonce from ACME server" );
348+ goto leave ;
348349 }
349350
350351 apr_table_set (req -> prot_hdrs , "nonce" , acme -> nonce );
@@ -355,51 +356,49 @@ static apr_status_t md_acme_req_send(md_acme_req_t *req)
355356 }
356357
357358 rv = req -> on_init ? req -> on_init (req , req -> baton ) : APR_SUCCESS ;
359+ if (APR_SUCCESS != rv ) goto leave ;
358360
359- if (( rv == APR_SUCCESS ) && req -> req_json ) {
361+ if (req -> req_json ) {
360362 body = md_json_writep (req -> req_json , req -> p , MD_JSON_FMT_INDENT );
361363 if (!body ) {
362- rv = APR_EINVAL ;
364+ rv = APR_EINVAL ; goto leave ;
363365 }
364366 }
365367
366- if (rv == APR_SUCCESS ) {
367- if (body && md_log_is_level (req -> p , MD_LOG_TRACE2 )) {
368- md_log_perror (MD_LOG_MARK , MD_LOG_TRACE2 , 0 , req -> p ,
369- "req: %s %s, body:\n%s" , req -> method , req -> url , body );
370- }
371- else {
372- md_log_perror (MD_LOG_MARK , MD_LOG_DEBUG , 0 , req -> p ,
373- "req: %s %s" , req -> method , req -> url );
374- }
375-
376- if (!strcmp ("GET" , req -> method )) {
377- rv = md_http_GET (req -> acme -> http , req -> url , NULL , on_response , req );
378- }
379- else if (!strcmp ("POST" , req -> method )) {
380- rv = md_http_POSTd (req -> acme -> http , req -> url , NULL , "application/jose+json" ,
381- body , body ? strlen (body ) : 0 , on_response , req );
382- }
383- else if (!strcmp ("HEAD" , req -> method )) {
384- rv = md_http_HEAD (req -> acme -> http , req -> url , NULL , on_response , req );
385- }
386- else {
387- md_log_perror (MD_LOG_MARK , MD_LOG_ERR , 0 , req -> p ,
388- "HTTP method %s against: %s" , req -> method , req -> url );
389- rv = APR_ENOTIMPL ;
390- }
391- md_log_perror (MD_LOG_MARK , MD_LOG_DEBUG , rv , req -> p , "req sent" );
392-
393- if (APR_EAGAIN == rv && req -> max_retries > 0 ) {
394- -- req -> max_retries ;
395- return md_acme_req_send (req );
396- }
397- req = NULL ;
368+ if (body && md_log_is_level (req -> p , MD_LOG_TRACE2 )) {
369+ md_log_perror (MD_LOG_MARK , MD_LOG_TRACE2 , 0 , req -> p ,
370+ "req: %s %s, body:\n%s" , req -> method , req -> url , body );
398371 }
399-
400- if (req ) {
401- md_acme_req_done (req );
372+ else {
373+ md_log_perror (MD_LOG_MARK , MD_LOG_DEBUG , 0 , req -> p ,
374+ "req: %s %s" , req -> method , req -> url );
375+ }
376+
377+ if (!strcmp ("GET" , req -> method )) {
378+ rv = md_http_GET (req -> acme -> http , req -> url , NULL , on_response , req );
402379 }
380+ else if (!strcmp ("POST" , req -> method )) {
381+ rv = md_http_POSTd (req -> acme -> http , req -> url , NULL , "application/jose+json" ,
382+ body , body ? strlen (body ) : 0 , on_response , req );
383+ }
384+ else if (!strcmp ("HEAD" , req -> method )) {
385+ rv = md_http_HEAD (req -> acme -> http , req -> url , NULL , on_response , req );
386+ }
387+ else {
388+ md_log_perror (MD_LOG_MARK , MD_LOG_ERR , 0 , req -> p ,
389+ "HTTP method %s against: %s" , req -> method , req -> url );
390+ rv = APR_ENOTIMPL ;
391+ }
392+ md_log_perror (MD_LOG_MARK , MD_LOG_DEBUG , rv , req -> p , "req sent" );
393+
394+ if (APR_EAGAIN == rv && req -> max_retries > 0 ) {
395+ -- req -> max_retries ;
396+ rv = md_acme_req_send (req );
397+ }
398+ req = NULL ;
399+
400+ leave :
401+ if (req ) md_acme_req_done (req );
403402 return rv ;
404403}
405404
@@ -599,14 +598,13 @@ apr_status_t md_acme_create(md_acme_t **pacme, apr_pool_t *p, const char *url,
599598}
600599
601600
602- apr_status_t md_acme_setup (md_acme_t * acme , const char * * perror )
601+ apr_status_t md_acme_setup (md_acme_t * acme , md_result_t * result )
603602{
604603 apr_status_t rv ;
605604 md_json_t * json ;
606605 const char * s ;
607606
608607 assert (acme -> url );
609- * perror = NULL ;
610608 acme -> version = MD_ACME_VERSION_UNKNOWN ;
611609
612610 if (!acme -> http && APR_SUCCESS != (rv = md_http_create (& acme -> http , acme -> p ,
@@ -619,15 +617,15 @@ apr_status_t md_acme_setup(md_acme_t *acme, const char **perror)
619617
620618 rv = md_acme_get_json (& json , acme , acme -> url , acme -> p );
621619 if (APR_SUCCESS != rv ) {
622- * perror = apr_psprintf ( acme -> p ,
620+ md_result_printf ( result , rv ,
623621 "Unsuccessful in contacting ACME server at <%s>. If this problem persists, "
624622 "please check your network connectivity from your Apache server to the "
625623 "ACME server. Also, older servers might have trouble verifying the certificates "
626624 "of the ACME server. You can check if you are able to contact it manually via the "
627625 "curl command. Sometimes, the ACME server might be down for maintenance, "
628626 "so failing to contact it is not an immediate problem. Apache will "
629627 "continue retrying this." , acme -> url );
630- md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , 0 , acme -> p , "%s" , * perror );
628+ md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , rv , acme -> p , "%s" , result -> detail );
631629 goto out ;
632630 }
633631
@@ -663,11 +661,11 @@ apr_status_t md_acme_setup(md_acme_t *acme, const char **perror)
663661 }
664662
665663 if (MD_ACME_VERSION_UNKNOWN == acme -> version ) {
666- * perror = apr_psprintf ( acme -> p ,
664+ md_result_printf ( result , APR_EINVAL ,
667665 "Unable to understand ACME server response from <%s>. "
668666 "Wrong ACME protocol version or link?" , acme -> url );
669- md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , 0 , acme -> p , "%s" , * perror );
670- rv = APR_EINVAL ;
667+ md_log_perror (MD_LOG_MARK , MD_LOG_WARNING , 0 , acme -> p , "%s" , result -> detail );
668+ rv = result -> status ;
671669 }
672670out :
673671 return rv ;
0 commit comments