Skip to content

Commit de43a56

Browse files
committed
Add error callbacks to the async resolver code where indicated.
* src/resolve.c (create_resolve_context, resolve_convert, resolve_callback, resolve_address_async, run_async_resolver_loop[unbound]): Replace placeholder comments with calls to the context error callback. Keep loggin in place. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1931129 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5ec118a commit de43a56

1 file changed

Lines changed: 75 additions & 41 deletions

File tree

src/resolve.c

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ static apr_status_t create_resolve_context(serf_context_t *ctx)
253253

254254
if (err) {
255255
const apr_status_t status = err_to_status(err);
256-
/* TODO: Error callback */
257-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, ctx->config,
258-
"unbound ctx init: %s\n", ub_strerror(err));
256+
const char *message = apr_psprintf(ctx->pool, "unbound ctx init: %s",
257+
ub_strerror(err));
258+
serf__context_error(ctx, status, message);
259+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
260+
ctx->config, "%s\n", message);
259261
cleanup_resolve_context(rctx);
260262
return status;
261263
}
@@ -331,13 +333,15 @@ static apr_status_t resolve_convert(apr_sockaddr_t **host_address,
331333
for (i = 0; ub_result->data[i]; ++i)
332334
{
333335
if (ub_result->len[i] != ipaddr_len) {
334-
/* TODO: Error callback */
335-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
336-
task->ctx->config,
337-
"unbound resolve: [%s] invalid address: "
338-
" length %d, expected %d\n",
339-
result->qtype, ub_result->len[i], ipaddr_len);
336+
const char *message = apr_psprintf(
337+
resolve_pool,
338+
"unbound resolve: [%s] invalid address: "
339+
" length %d, expected %d",
340+
result->qtype, ub_result->len[i], ipaddr_len);
340341
status = APR_EINVAL;
342+
serf__context_error(task->ctx, status, message);
343+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
344+
task->ctx->config, "%s\n", message);
341345
goto cleanup;
342346
}
343347
}
@@ -431,48 +435,64 @@ static void resolve_callback(void* baton, int err,
431435

432436
if (err)
433437
{
434-
/* TODO: Error callback */
435-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, task->ctx->config,
436-
"unbound resolve: [%s] error %s\n",
437-
resolve_result->qtype, ub_strerror(err));
438+
const char *message = apr_psprintf(
439+
task->resolve_pool,
440+
"unbound resolve: [%s] error %s",
441+
resolve_result->qtype, ub_strerror(err));
442+
serf__context_error(task->ctx, status, message);
443+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
444+
task->ctx->config, "%s\n", message);
438445
}
439446
else if (!ub_result->havedata)
440447
{
448+
const char *message;
441449
if (ub_result->nxdomain) {
442-
/* TODO: Error callback */
443-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, task->ctx->config,
444-
"unbound resolve: [%s] NXDOMAIN [%d]\n",
445-
resolve_result->qtype, ub_result->rcode);
446450
if (status == APR_SUCCESS)
447451
status = APR_ENOENT;
452+
message = apr_psprintf(
453+
task->resolve_pool,
454+
"unbound resolve: [%s] NXDOMAIN [%d]",
455+
resolve_result->qtype, ub_result->rcode);
456+
serf__context_error(task->ctx, status, message);
457+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
458+
task->ctx->config, "%s\n", message);
448459
}
449460
if (ub_result->bogus) {
450-
/* TODO: Error callback */
451-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, task->ctx->config,
452-
"unbound resolve: [%s] BOGUS [%d]%s%s\n",
453-
resolve_result->qtype, ub_result->rcode,
454-
ub_result->why_bogus ? " " : "",
455-
ub_result->why_bogus ? ub_result->why_bogus : "");
456461
if (status == APR_SUCCESS)
457462
status = APR_EINVAL;
463+
message = apr_psprintf(
464+
task->resolve_pool,
465+
"unbound resolve: [%s] BOGUS [%d]%s%s",
466+
resolve_result->qtype, ub_result->rcode,
467+
ub_result->why_bogus ? " " : "",
468+
ub_result->why_bogus ? ub_result->why_bogus : "");
469+
serf__context_error(task->ctx, status, message);
470+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
471+
task->ctx->config, "%s\n", message);
458472
}
459473
if (ub_result->was_ratelimited) {
460-
/* TODO: Error callback */
461-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, task->ctx->config,
462-
"unbound resolve: [%s] SERVFAIL [%d]\n",
463-
resolve_result->qtype, ub_result->rcode);
464474
if (status == APR_SUCCESS)
465475
status = APR_EAGAIN;
476+
message = apr_psprintf(
477+
task->resolve_pool,
478+
"unbound resolve: [%s] SERVFAIL [%d]",
479+
resolve_result->qtype, ub_result->rcode);
480+
serf__context_error(task->ctx, status, message);
481+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
482+
task->ctx->config, "%s\n", message);
466483
}
467484

468485
/* This shouldn't happen, one of the previous checks should
469486
have caught an error. */
470487
if (status == APR_SUCCESS) {
471-
/* TODO: Error callback */
472-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, task->ctx->config,
473-
"unbound resolve: [%s] no data [%d]\n",
474-
resolve_result->qtype, ub_result->rcode);
475488
status = APR_ENOENT;
489+
message = apr_psprintf(
490+
task->resolve_pool,
491+
"unbound resolve: [%s] no data [%d]\n",
492+
resolve_result->qtype, ub_result->rcode);
493+
serf__context_error(task->ctx, status, message);
494+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
495+
task->ctx->config, "%s\n", message);
476496
}
477497
}
478498

@@ -618,24 +638,32 @@ static apr_status_t resolve_address_async(serf_context_t *ctx,
618638
if (err4 || err6)
619639
{
620640
apr_uint32_t pending_results = -1;
641+
const char *message;
621642

622643
if (err4) {
623644
pending_results = apr_atomic_dec32(&task->pending_results);
624-
/* TODO: Error callback */
625-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, ctx->config,
626-
"unbound resolve start: [v4] %s\n", ub_strerror(err4));
645+
message = apr_psprintf(resolve_pool,
646+
"unbound resolve start: [v4] %s",
647+
ub_strerror(err4));
627648
status = err_to_status(err4);
649+
serf__context_error(ctx, status, message);
650+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
651+
ctx->config, "%s\n", message);
628652
}
629653

630654
#if APR_HAVE_IPV6
631655
if (err6) {
656+
const apr_status_t status6 = err_to_status(err6);
632657
pending_results = apr_atomic_dec32(&task->pending_results);
633-
/* TODO: Error callback */
634-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, ctx->config,
635-
"unbound resolve start: [v6] %s\n", ub_strerror(err6));
658+
message = apr_psprintf(resolve_pool,
659+
"unbound resolve start: [v6] %s",
660+
ub_strerror(err6));
661+
serf__context_error(ctx, status6, message);
662+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
663+
ctx->config, "%s\n", message);
636664
/* We have only one status to report. */
637665
if (!err4)
638-
status = err_to_status(err6);
666+
status = status6;
639667
}
640668
#endif /* APR_HAVE_IPV6 */
641669

@@ -660,9 +688,15 @@ static apr_status_t run_async_resolver_loop(serf_context_t *ctx)
660688
const int err = ub_process(rctx->ub_ctx);
661689
if (err) {
662690
const apr_status_t status = err_to_status(err);
663-
/* TODO: Error callback */
664-
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__, ctx->config,
665-
"unbound process: %s\n", ub_strerror(err));
691+
apr_pool_t *error_pool;
692+
const char *message;
693+
apr_pool_create(&error_pool, ctx->pool);
694+
message = apr_psprintf(error_pool, "unbound process: %s",
695+
ub_strerror(err));
696+
serf__context_error(ctx, status, message);
697+
serf__log(LOGLVL_ERROR, LOGCOMP_CONN, __FILE__,
698+
ctx->config, "%s\n", message);
699+
apr_pool_destroy(error_pool);
666700
return status;
667701
}
668702
}

0 commit comments

Comments
 (0)