This make this all more re-usable in other places.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// Upload all packages
#include <limits.h>
#include <pakfire/build.h>
+#include <pakfire/buildservice.h>
#include <pakfire/config.h>
#include <pakfire/pakfire.h>
#include <pakfire/repo.h>
return r;
}
+
+int cli_setup_buildservice(struct pakfire_buildservice** service, struct cli_global_args* args) {
+ struct pakfire_config* config = NULL;
+ const char* url = NULL;
+ int r;
+
+ // Setup the configuration
+ r = cli_setup_config(&config, args);
+ if (r < 0)
+ goto ERROR;
+
+ // Fetch the URL
+ url = pakfire_config_get(config, "client", "url", "https://pakfire.ipfire.org/");
+
+ // Connect to the build service
+ r = pakfire_buildservice_create(service, args->ctx, url);
+ if (r < 0) {
+ fprintf(stderr, "Could not setup the build service: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ERROR:
+ if (config)
+ pakfire_config_unref(config);
+
+ return r;
+}
#define PAKFIRE_CLI_PAKFIRE_H
#include <pakfire/build.h>
+#include <pakfire/buildservice.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/pakfire.h>
int cli_setup_config(struct pakfire_config** config, struct cli_global_args* args);
int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args);
int cli_setup_build(struct pakfire_build** build, struct cli_global_args* args, int flags);
+int cli_setup_buildservice(struct pakfire_buildservice** service, struct cli_global_args* args);
#endif /* PAKFIRE_CLI_PAKFIRE_H */
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// List repos
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// Delete the repository
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// List repos
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// List repos
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// List uploads
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// Delete uploads
goto ERROR;
// Connect to the build service
- r = pakfire_buildservice_create(&service, global_args->ctx);
- if (r)
+ r = cli_setup_buildservice(&service, global_args);
+ if (r < 0)
goto ERROR;
// List uploads
return r;
}
-static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
- struct pakfire_config* config = NULL;
- const char* url = NULL;
- const char* keytab = NULL;
- int r;
-
- // Fetch the configuration
- config = pakfire_ctx_get_config(service->ctx);
- if (!config) {
- r = 1;
- goto ERROR;
- }
-
- // Fetch the URL
- url = pakfire_config_get(config, "client", "url", NULL);
- if (!url) {
- ERROR(service->ctx, "Build Service URL is not configured\n");
- r = 1;
- goto ERROR;
- }
-
- // Store the URL
- r = pakfire_string_set(service->url, url);
- if (r < 0)
- goto ERROR;
-
- // Fetch the keytab
- keytab = pakfire_config_get(config, "client", "keytab", DEFAULT_KEYTAB);
-
- // Store the keytab
- r = pakfire_string_set(service->keytab, keytab);
- if (r)
- goto ERROR;
-
- // Setup authentication
- r = pakfire_buildservice_setup_auth(service);
- if (r)
- goto ERROR;
-
-ERROR:
- if (config)
- pakfire_config_unref(config);
-
- return r;
-}
-
static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
if (service->krb5_ctx)
krb5_free_context(service->krb5_ctx);
}
int pakfire_buildservice_create(
- struct pakfire_buildservice** service, struct pakfire_ctx* ctx) {
+ struct pakfire_buildservice** service, struct pakfire_ctx* ctx, const char* url) {
struct pakfire_buildservice* s = NULL;
int r;
// Initialize the reference counter
s->nrefs = 1;
- // Setup everything
- r = pakfire_buildservice_setup(s);
- if (r)
+ // Store the URL
+ r = pakfire_string_set(s->url, url);
+ if (r < 0)
goto ERROR;
- DEBUG(s->ctx,
- "Pakfire Build Service initialized for %s\n", pakfire_buildservice_get_url(s));
+ DEBUG(s->ctx, "Pakfire Build Service initialized for %s\n",
+ pakfire_buildservice_get_url(s));
// Return the pointer
*service = s;
#include <pakfire/ctx.h>
int pakfire_buildservice_create(struct pakfire_buildservice** service,
- struct pakfire_ctx* ctx);
+ struct pakfire_ctx* ctx, const char* url);
struct pakfire_buildservice* pakfire_buildservice_ref(struct pakfire_buildservice* service);
struct pakfire_buildservice* pakfire_buildservice_unref(struct pakfire_buildservice* service);