#include <string.h>
#include <syslog.h>
+#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
#include <pakfire/private.h>
// Reference counter
int nrefs;
+ // Config
+ struct pakfire_config* config;
+
// Logging
struct pakfire_ctx_log {
int level;
return 0;
}
+static int pakfire_ctx_load_config(struct pakfire_ctx* ctx, const char* path) {
+ FILE* f = NULL;
+ int r;
+
+ // Load some default configuration if not path was provided
+ if (!path)
+ path = "/etc/pakfire/pakfire.conf";
+
+ // Open the configuration file
+ f = fopen(path, "r");
+ if (!f)
+ return -errno;
+
+ // Read the configuration file
+ r = pakfire_config_read(ctx->config, f);
+
+ // Cleanup
+ fclose(f);
+
+ return r;
+}
+
static void pakfire_ctx_free(struct pakfire_ctx* ctx) {
+ if (ctx->config)
+ pakfire_config_unref(ctx->config);
free(ctx);
}
-PAKFIRE_EXPORT int pakfire_ctx_create(struct pakfire_ctx** ctx) {
+PAKFIRE_EXPORT int pakfire_ctx_create(struct pakfire_ctx** ctx, const char* path) {
struct pakfire_ctx* c = NULL;
int r;
// Initialize the reference counter
c->nrefs = 1;
+ // Initialize the configuration
+ r = pakfire_config_create(&c->config);
+ if (r)
+ goto ERROR;
+
+ // Load configuration
+ r = pakfire_ctx_load_config(c, path);
+ if (r)
+ goto ERROR;
+
// Setup logging
r = pakfire_ctx_setup_logging(c);
if (r)
return NULL;
}
+// Config
+
+struct pakfire_config* pakfire_ctx_get_config(struct pakfire_ctx* ctx) {
+ if (!ctx->config)
+ return NULL;
+
+ return pakfire_config_ref(ctx->config);
+}
+
// Logging
PAKFIRE_EXPORT int pakfire_ctx_get_log_level(struct pakfire_ctx* ctx) {
struct pakfire_ctx;
+#include <pakfire/config.h>
#include <pakfire/logging.h>
#include <pakfire/pakfire.h>
#include <pakfire/progress.h>
#include <pakfire/transaction.h>
-int pakfire_ctx_create(struct pakfire_ctx** ctx);
+int pakfire_ctx_create(struct pakfire_ctx** ctx, const char* path);
struct pakfire_ctx* pakfire_ctx_ref(struct pakfire_ctx* ctx);
struct pakfire_ctx* pakfire_ctx_unref(struct pakfire_ctx* ctx);
+// Config
+
+struct pakfire_config* pakfire_ctx_get_config(struct pakfire_ctx* ctx);
+
// Logging
int pakfire_ctx_get_log_level(struct pakfire_ctx* ctx);
LOG("running %s (%s)\n", t->name, root);
// Create a new context
- r = pakfire_ctx_create(&ctx);
+ r = pakfire_ctx_create(&ctx, NULL);
if (r) {
LOG("Could not create context: %m\n");
goto ERROR;