From 8757c35934c40a38412a69e0fa2ac38446836c35 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Tue, 30 Jun 2026 13:25:30 +1200 Subject: fetch the repo --- include/libmbpk.h | 2 ++ src/libmbpk.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/libmbpk.h b/include/libmbpk.h index 73a5806..3e849bd 100644 --- a/include/libmbpk.h +++ b/include/libmbpk.h @@ -6,6 +6,8 @@ #define MBPK_REPO_FAIL 2 #define MBPK_DL_FAIL 3 #define MBPK_EXTRACT_FAIL 4 +#define MBPK_CURL_INIT_FAIL 5 +#define MBPK_CURL_PERFORM_FAIL 6 typedef struct mbpk_pkg mbpk_pkg; diff --git a/src/libmbpk.c b/src/libmbpk.c index 477dd97..4045fe2 100644 --- a/src/libmbpk.c +++ b/src/libmbpk.c @@ -5,6 +5,7 @@ #include "ini.h" #include #include +#include #define MBPK_DB_DIR "/var/lib/mbpk" #define MBPK_REPO_DIR "/var/lib/mbpk-repo" @@ -73,10 +74,13 @@ static int repo_conf_handler(void* user, const char* section, const char* name, int mbpk_update_repositories(void) { /* Declarations */ - int i; struct stat st; + int i; + mbpk_repository *repo; + CURL* curl; + CURLcode result; + char* repo_ini_url; - /* Parse repo config */ repo_count = 0; if (ini_parse(MBPK_REPO_CONFIG, repo_conf_handler, NULL) < 0) { return MBPK_REPO_FAIL; @@ -89,7 +93,31 @@ int mbpk_update_repositories(void) { } for (i = 0; i < repo_count; i++) { - printf("Debug\n"); + repo = repos[i]; + printf("[libmbpk debug] processing repo %s\n", repo->name); + result = curl_global_init(CURL_GLOBAL_ALL); + if (result != CURLE_OK) { + return MBPK_CURL_INIT_FAIL; + } + + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, repo->url); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); /* follow redirects */ + + result = curl_easy_perform(curl); + + if (result != CURLE_OK) { + printf("[libmbpk debug] perform cURL failed\n"); + return MBPK_CURL_PERFORM_FAIL; + } + + curl_easy_cleanup(curl); + } else { + curl_global_cleanup(); + return MBPK_CURL_INIT_FAIL; + } + curl_global_cleanup(); } return MBPK_OK; -- cgit v1.2.3