aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-07-03 22:31:01 +1200
committerArslaan Pathan <[email protected]>2026-07-03 22:31:01 +1200
commit1c3dbaac4daa848d4292737d7b9f8ad037fde6f4 (patch)
tree4755284413183dc339640d45f18509733584c620
parent4522aa13bc8287ee56c548fbde5755ac022fb249 (diff)
downloadmbpk-1c3dbaac4daa848d4292737d7b9f8ad037fde6f4.tar.xz
mbpk-1c3dbaac4daa848d4292737d7b9f8ad037fde6f4.zip
Make it save the repository information to a file and parse the INI
-rw-r--r--src/libmbpk.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/libmbpk.c b/src/libmbpk.c
index ef745c8..e0a377d 100644
--- a/src/libmbpk.c
+++ b/src/libmbpk.c
@@ -103,17 +103,33 @@ static int repo_conf_handler(void* user, const char* section, const char* name,
return 1;
}
+static int repo_ini_handler(void *user, const char *section, const char *name, const char *value) {
+ mbpk_repository *repo;
+
+ repo = (mbpk_repository*)user;
+
+ if (strcmp(name, "desc") == 0) {
+ repo->desc = strdup(value);
+ } else if (strcmp(name, "packages") == 0) {
+ /* Do stuff here */
+ }
+
+ return 1;
+}
+
int mbpk_update_repositories(void) {
/* Declarations */
struct stat st;
int i;
mbpk_repository *repo;
- CURL* curl;
+ CURL *curl;
CURLcode result;
char *repo_ini_url;
char *repo_ini_path;
char *repo_dir;
size_t dir_len;
+ size_t repo_ini_path_len;
+ FILE *fp;
struct curl_memory chunk;
repo_count = 0;
@@ -164,8 +180,48 @@ int mbpk_update_repositories(void) {
dir_len = strlen(MBPK_REPO_DIR) + 1 + strlen(repo->name) + 1;
repo_dir = malloc(dir_len);
+ if (!repo_dir) {
+ free(chunk.memory);
+ return MBPK_OUT_OF_MEMORY;
+ }
+ sprintf(repo_dir, "%s/%s", MBPK_REPO_DIR, repo->name);
+
+ repo_ini_path_len = strlen(repo_dir) + 1 + strlen("repo.ini") + 1;
+ repo_ini_path = malloc(repo_ini_path_len);
+ if (!repo_ini_path) {
+ free(chunk.memory);
+ free(repo_dir);
+ return MBPK_OUT_OF_MEMORY;
+ }
+ sprintf(repo_ini_path, "%s/repo.ini", repo_dir);
+
+ if (stat(repo_dir, &st) == -1) {
+ if (mkdir(repo_dir, 0755) == -1) {
+ free(chunk.memory);
+ free(repo_ini_path);
+ free(repo_dir);
+ return MBPK_REPO_FAIL;
+ }
+ }
+ fp = fopen(repo_ini_path, "w");
+ if (!fp) {
+ free(repo_ini_path);
+ free(repo_dir);
+ free(chunk.memory);
+ return MBPK_REPO_FAIL;
+ }
+ fwrite(chunk.memory, 1, chunk.size, fp);
+ fclose(fp);
free(chunk.memory);
+ free(repo_dir);
+
+ if (ini_parse(repo_ini_path, repo_ini_handler, (void*)repo) < 0) {
+ free(repo_ini_path);
+ return MBPK_REPO_FAIL;
+ }
+ free(repo_ini_path);
+ printf("[libmbpk debug] repo %s desc: %s\n", repo->name, repo->desc);
}
return MBPK_OK;