struct http_client_request * http_client_request(struct http_client *client, const char *method, const char *host, const char *target, http_client_request_callback_t *callback, void *context) { struct http_client_request *req; req = http_client_request_new(client, method, callback, context); req->origin_url.host.name = p_strdup(req->pool, host); req->target = (target == NULL ? "/" : p_strdup(req->pool, target)); return req; }
struct http_client_request * http_client_request_url(struct http_client *client, const char *method, const struct http_url *target_url, http_client_request_callback_t *callback, void *context) { struct http_client_request *req; req = http_client_request_new(client, method, callback, context); http_url_copy_authority(req->pool, &req->origin_url, target_url); req->target = p_strdup(req->pool, http_url_create_target(target_url)); return req; }
struct http_client_request * http_client_request_connect(struct http_client *client, const char *host, in_port_t port, http_client_request_callback_t *callback, void *context) { struct http_client_request *req; req = http_client_request_new(client, "CONNECT", callback, context); req->origin_url.host.name = p_strdup(req->pool, host); req->origin_url.port = port; req->connect_tunnel = TRUE; req->target = req->origin_url.host.name; return req; }
struct http_client_request * http_client_request_url(struct http_client *client, const char *method, const struct http_url *target_url, http_client_request_callback_t *callback, void *context) { struct http_client_request *req; req = http_client_request_new(client, method, callback, context); http_url_copy_authority(req->pool, &req->origin_url, target_url); req->target = p_strdup(req->pool, http_url_create_target(target_url)); if (target_url->user != NULL && *target_url->user != '\0' && target_url->password != NULL) { req->username = p_strdup(req->pool, target_url->user); req->password = p_strdup(req->pool, target_url->password); } return req; }
/* Queue: pairing */ static int send_pairing_request(struct remote_info *ri, char *req_uri, int family) { struct http_connection *c; struct http_request *req; char *address; unsigned short port; int ret; switch (family) { case AF_INET: if (!ri->v4_address) return -1; address = ri->v4_address; port = ri->v4_port; break; case AF_INET6: if (!ri->v6_address) return -1; address = ri->v6_address; port = ri->v6_port; break; default: return -1; } c = http_client_new(L_REMOTE, address, port, pairing_fail_cb, pairing_free_cb, ri); if (!c) { DPRINTF(E_LOG, L_REMOTE, "Could not create HTTP client for pairing with %s\n", ri->pi.name); return -1; } req = http_client_request_new(HTTP_GET, P_VER_1_1, req_uri, pairing_request_cb); if (!req) { DPRINTF(E_WARN, L_REMOTE, "Could not create HTTP request for pairing\n"); goto request_fail; } ret = http_request_add_header(req, "Connection", "close"); if (ret < 0) DPRINTF(E_WARN, L_REMOTE, "Could not add Connection: close header\n"); ret = http_client_request_run(c, req); if (ret < 0) { DPRINTF(E_WARN, L_REMOTE, "Could not run pairing request\n"); goto run_fail; } return 0; run_fail: http_request_free(req); request_fail: http_client_free(c); return -1; }