#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/digest.h>
-#include <pakfire/httpclient.h>
#include <pakfire/logging.h>
#include <pakfire/os.h>
#include <pakfire/path.h>
struct pakfire_ctx* ctx;
int nrefs;
+ // URL
+ char url[PATH_MAX];
+
// Configuration
char keytab[PATH_MAX];
- // A HTTP Client
- struct pakfire_httpclient* httpclient;
-
// Kerberos Context
krb5_context krb5_ctx;
};
+static int pakfire_buildservice_xfer_create(struct pakfire_xfer** xfer,
+ struct pakfire_buildservice* service, const char* url, ...) {
+ struct pakfire_xfer* x = NULL;
+ va_list args;
+ int r;
+
+ va_start(args, url);
+
+ // Create a new xfer
+ r = __pakfire_xfer_create(&x, service->ctx, url, args);
+ if (r < 0)
+ goto ERROR;
+
+ // Set the base URL
+ r = pakfire_xfer_set_baseurl(x, service->url);
+ if (r < 0)
+ goto ERROR;
+
+ // Success
+ *xfer = pakfire_xfer_ref(x);
+
+ERROR:
+ if (x)
+ pakfire_xfer_unref(x);
+ va_end(args);
+
+ return r;
+}
+
static int pakfire_buildservice_setup_auth(struct pakfire_buildservice* service) {
const char* error = NULL;
int r;
goto ERROR;
}
- // Setup the HTTP client
- r = pakfire_httpclient_create(&service->httpclient, service->ctx, NULL);
- if (r)
- goto ERROR;
-
- // Set the URL
- r = pakfire_httpclient_set_baseurl(service->httpclient, url);
- if (r)
+ // Store the URL
+ r = pakfire_string_set(service->url, url);
+ if (r < 0)
goto ERROR;
// Fetch the keytab
static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
if (service->krb5_ctx)
krb5_free_context(service->krb5_ctx);
- if (service->httpclient)
- pakfire_httpclient_unref(service->httpclient);
if (service->ctx)
pakfire_ctx_unref(service->ctx);
}
PAKFIRE_EXPORT const char* pakfire_buildservice_get_url(struct pakfire_buildservice* service) {
- return pakfire_httpclient_get_baseurl(service->httpclient);
+ return service->url;
}
// Build
int r;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/builds");
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/builds");
if (r)
goto ERROR;
goto ERROR;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/uploads");
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/uploads");
if (r)
goto ERROR;
int r;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/uploads/%s", uuid);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/uploads/%s", uuid);
if (r)
goto ERROR;
int r;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/uploads");
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/uploads");
if (r)
goto ERROR;
int r;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/uploads/%s", uuid);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/uploads/%s", uuid);
if (r)
goto ERROR;
return -EINVAL;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/repos/%s", distro);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/repos/%s", distro);
if (r)
goto ERROR;
return -EINVAL;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/repos/%s/%s", distro, name);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/repos/%s/%s", distro, name);
if (r)
goto ERROR;
return -EINVAL;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/repos/%s", distro);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/repos/%s", distro);
if (r)
goto ERROR;
int r;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/repos/%s/%s", distro, name);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/repos/%s/%s", distro, name);
if (r)
goto ERROR;
num_packages++;
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, service->httpclient, "/api/v1/jobs/%s", uuid);
+ r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/jobs/%s", uuid);
if (r)
goto ERROR;
#include <pakfire/daemon.h>
#include <pakfire/httpclient.h>
#include <pakfire/job.h>
+#include <pakfire/string.h>
#include <pakfire/util.h>
#define MAX_JOBS 64
// HTTP Client
struct pakfire_httpclient* client;
+ // URL
+ char url[PATH_MAX];
+
// Event Loop
sd_event* loop;
return 0;
}
+static int pakfire_daemon_xfer_create(struct pakfire_xfer** xfer,
+ struct pakfire_daemon* daemon, const char* url) {
+ struct pakfire_xfer* x = NULL;
+ int r;
+
+ // Create a new xfer
+ r = pakfire_xfer_create(&x, daemon->ctx, "%s", url);
+ if (r < 0)
+ goto ERROR;
+
+ // Set the base URL
+ r = pakfire_xfer_set_baseurl(x, daemon->url);
+ if (r < 0)
+ goto ERROR;
+
+ // Success
+ *xfer = pakfire_xfer_ref(x);
+
+ERROR:
+ if (x)
+ pakfire_xfer_unref(x);
+
+ return r;
+}
+
static int pakfire_daemon_connected(struct pakfire_xfer* xfer, void* data) {
struct pakfire_daemon* daemon = data;
int r;
CTX_INFO(daemon->ctx, "Connecting...\n");
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, daemon->client, "/api/v1/builders/control");
+ r = pakfire_daemon_xfer_create(&xfer, daemon, "/api/v1/builders/control");
if (r)
goto ERROR;
return 0;
}
-static int pakfire_daemon_setup_httpclient(struct pakfire_daemon* daemon) {
+static int pakfire_daemon_configure(struct pakfire_daemon* daemon) {
struct pakfire_config* config = NULL;
+ const char* url = NULL;
int r;
// Fetch the configuration
}
// Fetch the URL
- const char* url = pakfire_config_get(config, "daemon", "url", "https://pakfire.ipfire.org");
+ url = pakfire_config_get(config, "daemon", "url", "https://pakfire.ipfire.org");
- // Create the HTTP client
- r = pakfire_httpclient_create(&daemon->client, daemon->ctx, daemon->loop);
- if (r)
+ // Store the URL
+ r = pakfire_string_set(daemon->url, url);
+ if (r < 0)
goto ERROR;
- // Configure the base URL
- r = pakfire_httpclient_set_baseurl(daemon->client, url);
- if (r) {
- CTX_ERROR(daemon->ctx, "Could not configure the URL\n");
- goto ERROR;
- }
-
ERROR:
if (config)
pakfire_config_unref(config);
// Initialize the reference counter
d->nrefs = 1;
+ // Read configuration
+ r = pakfire_daemon_configure(d);
+ if (r < 0)
+ goto ERROR;
+
// Setup the event loop
r = pakfire_daemon_setup_loop(d);
if (r)
goto ERROR;
- // Setup the HTTP client
- r = pakfire_daemon_setup_httpclient(d);
- if (r)
+ // Create the HTTP client
+ r = pakfire_httpclient_create(&d->client, d->ctx, d->loop);
+ if (r < 0)
goto ERROR;
// Reconnect after one second
return pakfire_httpclient_ref(daemon->client);
}
+const char* pakfire_daemon_url(struct pakfire_daemon* daemon) {
+ return daemon->url;
+}
+
int pakfire_daemon_main(struct pakfire_daemon* daemon) {
int r;
#include <pakfire/arch.h>
#include <pakfire/dist.h>
-#include <pakfire/httpclient.h>
#include <pakfire/i18n.h>
#include <pakfire/linter.h>
#include <pakfire/logging.h>
return r;
}
-static int pakfire_dist_download_source(struct pakfire_httpclient* httpclient,
+static int pakfire_dist_download_source(struct pakfire_ctx* ctx,
struct pakfire_mirrorlist* mirrorlist, const char* filename, const char* cache_path) {
struct pakfire_xfer* xfer = NULL;
int r;
return 0;
// Create a new transfer
- r = pakfire_httpclient_create_xfer(&xfer, httpclient, "%s", filename);
+ r = pakfire_xfer_create(&xfer, ctx, "%s", filename);
if (r)
goto ERROR;
}
static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packager* packager,
- struct pakfire_package* pkg, struct pakfire_httpclient* httpclient,
+ struct pakfire_package* pkg, struct pakfire_ctx* ctx,
struct pakfire_mirrorlist* mirrorlist, const char* filename) {
char archive_path[PATH_MAX];
char cache_path[PATH_MAX];
return r;
// Download the source file
- r = pakfire_dist_download_source(httpclient, mirrorlist, filename, cache_path);
+ r = pakfire_dist_download_source(ctx, mirrorlist, filename, cache_path);
if (r)
return r;
static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_packager* packager,
struct pakfire_package* pkg, struct pakfire_parser* makefile) {
- struct pakfire_httpclient* httpclient = NULL;
struct pakfire_mirrorlist* mirrorlist = NULL;
char* sources = NULL;
char* p = NULL;
struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
- // Create a HTTP client
- r = pakfire_httpclient_create(&httpclient, ctx, NULL);
- if (r)
- goto ERROR;
-
// Fetch the mirrorlist
r = pakfire_dist_get_mirrorlist(pakfire, makefile, &mirrorlist);
if (r)
while (source) {
DEBUG(pakfire, "Adding source file %s\n", source);
- r = pakfire_dist_add_source(pakfire, packager, pkg, httpclient, mirrorlist, source);
+ r = pakfire_dist_add_source(pakfire, packager, pkg, ctx, mirrorlist, source);
if (r) {
ERROR(pakfire, "Could not add '%s' to package: %m\n", source);
goto ERROR;
r = 0;
ERROR:
- if (httpclient)
- pakfire_httpclient_unref(httpclient);
if (mirrorlist)
pakfire_mirrorlist_unref(mirrorlist);
if (ctx)
return sd_event_ref(client->loop);
}
-const char* pakfire_httpclient_get_baseurl(struct pakfire_httpclient* client) {
- if (*client->baseurl)
- return client->baseurl;
-
- return NULL;
-}
-
-int pakfire_httpclient_set_baseurl(struct pakfire_httpclient* client, const char* baseurl) {
- return pakfire_string_set(client->baseurl, baseurl);
-}
-
-int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer,
- struct pakfire_httpclient* client, const char* url, ...) {
- struct pakfire_xfer* x = NULL;
- va_list args;
- int r;
-
- // Create a new transfer
- va_start(args, url);
- r = __pakfire_xfer_create(&x, client->ctx, client, url, args);
- va_end(args);
- if (r)
- goto ERROR;
-
- // Configure the base URL
- if (*client->baseurl) {
- r = pakfire_xfer_set_baseurl(x, client->baseurl);
- if (r)
- goto ERROR;
- }
-
- // Return the result
- *xfer = x;
-
- return 0;
-
-ERROR:
- if (x)
- pakfire_xfer_unref(x);
-
- return r;
-}
-
int pakfire_httpclient_enqueue_xfer(struct pakfire_httpclient* client,
struct pakfire_xfer* xfer) {
int r;
return r;
}
- return 0;
+ // Transfer enqueued
+ return pakfire_xfer_enqueued(xfer, client);
}
int pakfire_httpclient_remove_xfer(struct pakfire_httpclient* client,
sd_event* pakfire_daemon_loop(struct pakfire_daemon* daemon);
struct pakfire_httpclient* pakfire_daemon_httpclient(struct pakfire_daemon* daemon);
+const char* pakfire_daemon_url(struct pakfire_daemon* daemon);
+
int pakfire_daemon_main(struct pakfire_daemon* daemon);
int pakfire_daemon_job_finished(struct pakfire_daemon* daemon, struct pakfire_job* job);
struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* downloader);
sd_event* pakfire_httpclient_loop(struct pakfire_httpclient* client);
-CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* downloader);
-
-const char* pakfire_httpclient_get_baseurl(struct pakfire_httpclient* client);
-int pakfire_httpclient_set_baseurl(struct pakfire_httpclient* client, const char* baseurl);
-
-int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer,
- struct pakfire_httpclient* downloader, const char* url, ...)
- __attribute__((format(printf, 3, 4)));
int pakfire_httpclient_enqueue_xfer(
struct pakfire_httpclient* downloader, struct pakfire_xfer* xfer);
} pakfire_xfer_method_t;
int pakfire_xfer_create(struct pakfire_xfer** transfer, struct pakfire_ctx* ctx,
- struct pakfire_httpclient* httpclient, const char* url, ...)
- __attribute__((format(printf, 4, 5)));
+ const char* url, ...) __attribute__((format(printf, 3, 4)));
int __pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx,
- struct pakfire_httpclient* client, const char* url, va_list args)
- __attribute__((format(printf, 4, 0)));
+ const char* url, va_list args) __attribute__((format(printf, 3, 0)));
struct pakfire_xfer* pakfire_xfer_ref(struct pakfire_xfer* xfer);
struct pakfire_xfer* pakfire_xfer_unref(struct pakfire_xfer* xfer);
CURL* pakfire_xfer_handle(struct pakfire_xfer* xfer);
+int pakfire_xfer_enqueued(struct pakfire_xfer* xfer, struct pakfire_httpclient* client);
+
int pakfire_xfer_set_method(struct pakfire_xfer* xfer,
const pakfire_xfer_method_t method);
// Event Loop
sd_event* loop;
- // HTTP Client
- struct pakfire_httpclient* client;
-
uuid_t job_id;
char name[NAME_MAX];
if (job->log.stderr)
pakfire_log_stream_unref(job->log.stderr);
- if (job->client)
- pakfire_httpclient_unref(job->client);
if (job->loop)
sd_event_unref(job->loop);
if (job->daemon)
return 0;
}
+static int pakfire_job_xfer_create(struct pakfire_xfer** xfer,
+ struct pakfire_job* job, const char* url, ...) {
+ struct pakfire_xfer* x = NULL;
+ va_list args;
+ int r;
+
+ va_start(args, url);
+
+ // Create a new xfer
+ r = __pakfire_xfer_create(&x, job->ctx, url, args);
+ if (r < 0)
+ goto ERROR;
+
+ // Set the base URL
+ r = pakfire_xfer_set_baseurl(x, pakfire_daemon_url(job->daemon));
+ if (r < 0)
+ goto ERROR;
+
+ // Success
+ *xfer = pakfire_xfer_ref(x);
+
+ERROR:
+ if (x)
+ pakfire_xfer_unref(x);
+ va_end(args);
+
+ return r;
+}
+
static int pakfire_job_connected(struct pakfire_xfer* xfer, void* data) {
struct pakfire_job* job = data;
static int pakfire_job_connect(sd_event_source* s, uint64_t usec, void* data) {
struct pakfire_job* job = data;
+ struct pakfire_httpclient* client = NULL;
struct pakfire_xfer* xfer = NULL;
char job_id[UUID_STR_LEN];
int r;
CTX_INFO(job->ctx, "Connecting to job %s...\n", job_id);
+ // Fetch a reference to the HTTP client
+ client = pakfire_daemon_httpclient(job->daemon);
+ if (!client) {
+ r = -errno;
+ goto ERROR;
+ }
+
// Create a new xfer
- r = pakfire_httpclient_create_xfer(&xfer, job->client, "/api/v1/jobs/%s", job_id);
+ r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s", job_id);
if (r)
goto ERROR;
goto ERROR;
// Enqueue the transfer
- r = pakfire_httpclient_enqueue_xfer(job->client, xfer);
+ r = pakfire_httpclient_enqueue_xfer(client, xfer);
if (r)
goto ERROR;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
+ if (client)
+ pakfire_httpclient_unref(client);
return r;
}
goto ERROR;
}
- // Fetch a reference to the HTTP client
- j->client = pakfire_daemon_httpclient(daemon);
- if (!j->client) {
- CTX_ERROR(j->ctx, "Could not fetch the HTTP client: %m\n");
- r = -errno;
- goto ERROR;
- }
-
// Initialize the PID file descriptor
j->pidfd = -1;
This is a convenience function to create a xfer with the
settings of this repository.
*/
-static int pakfire_repo_create_xfer(struct pakfire_xfer** xfer,
- struct pakfire_repo* repo, struct pakfire_httpclient* httpclient, const char* url) {
+static int pakfire_repo_xfer_create(
+ struct pakfire_xfer** xfer, struct pakfire_repo* repo, const char* url) {
struct pakfire_mirrorlist* mirrorlist = NULL;
- struct pakfire_xfer* x = NULL;
const char* baseurl = NULL;
int r;
// Create a new transfer
- r = pakfire_httpclient_create_xfer(&x, httpclient, "%s", url);
- if (r)
+ r = pakfire_xfer_create(xfer, repo->ctx, "%s", url);
+ if (r < 0)
goto ERROR;
// Set the baseurl
baseurl = pakfire_repo_get_expanded_baseurl(repo);
if (baseurl) {
- r = pakfire_xfer_set_baseurl(x, baseurl);
- if (r)
+ r = pakfire_xfer_set_baseurl(*xfer, baseurl);
+ if (r < 0)
goto ERROR;
}
// Set the mirrorlist
mirrorlist = pakfire_repo_get_mirrorlist(repo);
if (mirrorlist) {
- r = pakfire_xfer_set_mirrorlist(x, mirrorlist);
- if (r)
+ r = pakfire_xfer_set_mirrorlist(*xfer, mirrorlist);
+ if (r < 0)
goto ERROR;
}
- // Success
- *xfer = x;
- r = 0;
-
- goto CLEANUP;
-
ERROR:
- if (x)
- pakfire_xfer_unref(x);
-
-CLEANUP:
if (mirrorlist)
pakfire_mirrorlist_unref(mirrorlist);
+ // Destroy the xfer on error
+ if (r) {
+ if (*xfer)
+ pakfire_xfer_unref(*xfer);
+ }
+
return r;
}
static int pakfire_repo_download_database(struct pakfire_repo* repo,
const char* filename, const char* path) {
- struct pakfire_httpclient* httpclient = NULL;
struct pakfire_xfer* xfer = NULL;
char title[NAME_MAX];
char url[PATH_MAX];
if (r)
return r;
- // Create a HTTP client
- r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
- if (r)
- goto ERROR;
-
// Create a new transfer
- r = pakfire_repo_create_xfer(&xfer, repo, httpclient, url);
+ r = pakfire_repo_xfer_create(&xfer, repo, url);
if (r)
goto ERROR;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (httpclient)
- pakfire_httpclient_unref(httpclient);
return r;
}
}
static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int force) {
- struct pakfire_httpclient* httpclient = NULL;
struct pakfire_xfer* xfer = NULL;
char* url = NULL;
int r;
goto ERROR;
}
- // Create a new HTTP client
- r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
- if (r)
- goto ERROR;
-
// Create a new xfer
- r = pakfire_repo_create_xfer(&xfer, repo, httpclient, url);
+ r = pakfire_repo_xfer_create(&xfer, repo, url);
if (r)
goto ERROR;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (httpclient)
- pakfire_httpclient_unref(httpclient);
if (url)
free(url);
}
static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* path, int force) {
- struct pakfire_httpclient* httpclient = NULL;
struct pakfire_xfer* xfer = NULL;
int r;
}
}
- // Create a HTTP client
- r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
- if (r)
- goto ERROR;
-
// Create a new transfer
- r = pakfire_repo_create_xfer(&xfer, repo, httpclient, "repodata/repomd.json");
+ r = pakfire_repo_xfer_create(&xfer, repo, "repodata/repomd.json");
if (r)
goto ERROR;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (httpclient)
- pakfire_httpclient_unref(httpclient);
return r;
}
}
// Create a new transfer
- r = pakfire_repo_create_xfer(&x, repo, httpclient, url);
+ r = pakfire_repo_xfer_create(&x, repo, url);
if (r)
goto ERROR;
static int pakfire_repo_download(struct pakfire_repo* repo, const char* url,
struct pakfire_package** package) {
- struct pakfire_httpclient* httpclient = NULL;
struct pakfire_xfer* xfer = NULL;
FILE* f = NULL;
int r;
goto ERROR;
}
- // Create the HTTP client
- r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
- if (r)
- goto ERROR;
-
// Create a new transfer
- r = pakfire_httpclient_create_xfer(&xfer, httpclient, "%s", url);
+ r = pakfire_repo_xfer_create(&xfer, repo, url);
if (r)
goto ERROR;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (httpclient)
- pakfire_httpclient_unref(httpclient);
if (f)
fclose(f);
return r;
}
-int pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx,
- struct pakfire_httpclient* client, const char* url, ...) {
+int pakfire_xfer_create(struct pakfire_xfer** xfer,
+ struct pakfire_ctx* ctx, const char* url, ...) {
va_list args;
int r;
va_start(args, url);
- r = __pakfire_xfer_create(xfer, ctx, client, url, args);
+ r = __pakfire_xfer_create(xfer, ctx, url, args);
va_end(args);
return r;
}
-int __pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx,
- struct pakfire_httpclient* client, const char* url, va_list args) {
+int __pakfire_xfer_create(struct pakfire_xfer** xfer,
+ struct pakfire_ctx* ctx, const char* url, va_list args) {
struct pakfire_xfer* x = NULL;
char buffer[PATH_MAX];
int r;
// Initialize the reference counter
x->nrefs = 1;
- // Store a reference to the HTTP client
- x->client = pakfire_httpclient_ref(client);
-
// Store the URL
r = pakfire_string_set(x->url, buffer);
if (r)
return xfer->handle;
}
+int pakfire_xfer_enqueued(struct pakfire_xfer* xfer, struct pakfire_httpclient* client) {
+ // Remove the reference to the old client
+ if (xfer->client) {
+ pakfire_httpclient_unref(xfer->client);
+ xfer->client = NULL;
+ }
+
+ // Store the new client
+ xfer->client = pakfire_httpclient_ref(client);
+
+ return 0;
+}
+
int pakfire_xfer_set_method(struct pakfire_xfer* xfer,
const pakfire_xfer_method_t method) {
const char* m = NULL;