void oauth2_request_set_headers(struct oauth2_request *req, const struct oauth2_request_input *input) { if (!req->set->send_auth_headers) return; if (input->service != NULL) { http_client_request_add_header(req->req, "X-Dovecot-Auth-Service", input->service); } if (input->local_ip.family != 0) { const char *addr; if (net_ipport2str(&input->local_ip, input->local_port, &addr) == 0) http_client_request_add_header(req->req, "X-Dovecot-Auth-Local", addr); } if (input->remote_ip.family != 0) { const char *addr; if (net_ipport2str(&input->remote_ip, input->remote_port, &addr) == 0) http_client_request_add_header(req->req, "X-Dovecot-Auth-Remote", addr); } }
int stats_carbon_send(const char *endpoint, const char *data, void (*callback)(void *), void *cb_ctx, struct stats_send_ctx **ctx_r) { const char *host; in_port_t port; struct ip_addr ip; if (net_str2hostport(endpoint, CARBON_SERVER_DEFAULT_PORT, &host, &port) < 0 || net_addr2ip(host, &ip) < 0) { i_error("stats_submit: Cannot parse endpoint '%s'", endpoint); return -1; } pool_t pool = pool_alloconly_create("stats carbon send", 1024); struct stats_send_ctx *ctx = p_new(pool, struct stats_send_ctx, 1); ctx->pool = pool; ctx->str = p_strdup(ctx->pool, data); ctx->fd = net_connect_ip(&ip, port, NULL); if (ctx->fd < 0) { i_error("connect(%s) failed: %m", endpoint); stats_carbon_callback(ctx); return -1; } ctx->io = io_add(ctx->fd, IO_WRITE, stats_carbon_connected, ctx); /* give time for almost until next update this is to ensure we leave a little pause between attempts. Multiplier 800 gives us 20% window, and ensures the number stays positive. */ ctx->to_msecs = stats_settings->carbon_interval*800; ctx->to = timeout_add(ctx->to_msecs, stats_carbon_timeout, ctx); if (net_ipport2str(&ip, port, &host) < 0) i_unreached(); ctx->endpoint = p_strdup(ctx->pool, host); ctx->callback = callback; ctx->ctx = cb_ctx; *ctx_r = ctx; return 0; }