#include <syslog.h>
#include <wordexp.h>
+#include <curl/curl.h>
#include <magic.h>
#include <pakfire/config.h>
void* data;
} pick_solution;
+ // cURL share handle
+ CURLSH* share;
+
// Magic Context
magic_t magic;
};
}
static void pakfire_ctx_free(struct pakfire_ctx* ctx) {
+ // Release cURL Share Handle
+ if (ctx->share)
+ curl_share_cleanup(ctx->share);
+
// Release Magic Context
if (ctx->magic)
magic_close(ctx->magic);
+
if (ctx->config)
pakfire_config_unref(ctx->config);
free(ctx);
return ctx->pick_solution.callback(ctx, pakfire, ctx->pick_solution.data, transaction);
}
+// cURL
+
+CURLSH* pakfire_ctx_curl_share(struct pakfire_ctx* ctx) {
+ int r;
+
+ // Setup a new handle
+ if (!ctx->share) {
+ ctx->share = curl_share_init();
+ if (!ctx->share) {
+ CTX_ERROR(ctx, "Could not setup cURL share handle\n");
+ goto ERROR;
+ }
+
+ // Share connections between handles
+ r = curl_share_setopt(ctx->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
+ if (r) {
+ CTX_ERROR(ctx, "Could not configure the share handle: %s\n", curl_share_strerror(r));
+ goto ERROR;
+ }
+ }
+
+ return ctx->share;
+
+ERROR:
+ if (ctx->share) {
+ curl_share_cleanup(ctx->share);
+ ctx->share = NULL;
+ }
+
+ return NULL;
+}
+
// Magic
magic_t pakfire_ctx_magic(struct pakfire_ctx* ctx) {
// How many transfers in parallel?
long max_parallel;
- // cURL share handle
- CURLSH* share;
-
// cURL multi handle
CURLM* curl;
return r;
}
- // Create a new share handle
- client->share = curl_share_init();
- if (!client->share) {
- CTX_ERROR(client->ctx, "Could not setup cURL share handle\n");
- return 1;
- }
-
// Create a new multi handle
client->curl = curl_multi_init();
if (!client->curl) {
return 1;
}
- // Share connections between handles
- r = curl_share_setopt(client->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
- if (r) {
- CTX_ERROR(client->ctx, "Could not configure the share handle: %s\n",
- curl_share_strerror(r));
- return r;
- }
-
// Register with the event loop
r = curl_multi_setopt(client->curl, CURLMOPT_TIMERFUNCTION, pakfire_httpclient_timer);
if (r) {
static void pakfire_httpclient_free(struct pakfire_httpclient* client) {
if (client->progress)
pakfire_progress_unref(client->progress);
- if (client->share)
- curl_share_cleanup(client->share);
if (client->curl)
curl_multi_cleanup(client->curl);
if (client->timer)
return sd_event_ref(client->loop);
}
-CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* client) {
- return client->share;
-}
-
const char* pakfire_httpclient_get_baseurl(struct pakfire_httpclient* client) {
if (*client->baseurl)
return client->baseurl;
int pakfire_ctx_pick_solution(struct pakfire_ctx* ctx, struct pakfire* pakfire,
struct pakfire_transaction* transaction);
+// cURL
+
+#include <curl/curl.h>
+
+CURLSH* pakfire_ctx_curl_share(struct pakfire_ctx* ctx);
+
// Magic
#include <magic.h>
magic_t pakfire_ctx_magic(struct pakfire_ctx* ctx);
#endif /* PAKFIRE_PRIVATE */
-
#endif /* PAKFIRE_CTX_H */
const char* proxy = NULL;
int r;
- CURLSH* share = pakfire_httpclient_share(xfer->client);
+ CURLSH* share = pakfire_ctx_curl_share(xfer->ctx);
// Configure the share handle
r = curl_easy_setopt(xfer->handle, CURLOPT_SHARE, share);