diff --git a/include/ctx.h b/include/ctx.h index e3ae446..d38d27f 100644 --- a/include/ctx.h +++ b/include/ctx.h @@ -14,6 +14,13 @@ typedef struct lm_ctx { const char *version; // libmp version (read-only) } lm_ctx_t; +typedef struct lm_ctx_list { + lm_pool_t *head; + lm_pool_t *pool; + lm_pkg_t *pkg; + ssize_t count; +} lm_ctx_list_t; + typedef struct lm_ctx_resolve_list { lm_pkg_t *resolving; lm_pkg_t *packages; @@ -62,6 +69,10 @@ void lm_ctx_free(lm_ctx_t *ctx); /* #################### ## main fucntions ## #################### */ +lm_ctx_list_t *lm_ctx_list(lm_ctx_t *ctx, lm_ctx_list_t *list); // returns the state of package list +lm_pkg_t *lm_ctx_list_next(lm_ctx_list_t *list); // returns the next package in the list +void lm_ctx_list_free(lm_ctx_list_t *list); // frees the package list state + lm_ctx_resolve_list_t *lm_ctx_resolve( lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_resolve_list_t *list); // resolves a package and returns a list of packages lm_pkg_t *lm_ctx_resolve_next(lm_ctx_resolve_list_t *list); // returns the next package in the list diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 3a3bd24..7227ab0 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-04 15:24+0300\n" +"POT-Creation-Date: 2024-08-04 18:59+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/ctx/ctx.c b/src/ctx/ctx.c index 64ce22a..f5548f3 100644 --- a/src/ctx/ctx.c +++ b/src/ctx/ctx.c @@ -102,5 +102,6 @@ void lm_ctx_free(lm_ctx_t *ctx) { lm_database_free(ctx->db); lm_error_clear(); + bzero(ctx, sizeof(lm_ctx_t)); return; } diff --git a/src/ctx/list.c b/src/ctx/list.c new file mode 100644 index 0000000..a915460 --- /dev/null +++ b/src/ctx/list.c @@ -0,0 +1,60 @@ +#include "../../include/package.h" +#include "../../include/error.h" +#include "../../include/ctx.h" + +#include + +lm_ctx_list_t *lm_ctx_list(lm_ctx_t *ctx, lm_ctx_list_t *list){ + if(NULL == ctx || NULL == list){ + lm_error_set(LM_ERR_ArgNULL); + return NULL; + } + + list->pool = ctx->pools; + list->head = ctx->pools; + list->pkg = NULL; + list->count = 0; + + while(NULL != list->pool){ + list->pkg = list->pool->pkg; + while(NULL != list->pkg){ + list->count++; + list->pkg = list->pkg->next; + } + list->pool = list->pool->next; + } + + list->pool = NULL; + list->pkg = NULL; + return list; +} + +lm_pkg_t *lm_ctx_list_next(lm_ctx_list_t *list){ + if(NULL == list){ + lm_error_set(LM_ERR_ArgNULL); + return NULL; + } + + if(NULL == list->pool || NULL == list->pkg){ + if((list->pool = list->head) != NULL) + list->pkg = list->pool->pkg; + return list->pkg; + } + + if((list->pkg = list->pkg->next) && NULL == list->pkg){ + if((list->pool = list->pool->next) != NULL) + list->pkg = list->pool->pkg; + return list->pkg; + } + + return list->pkg; +} + +void lm_ctx_list_free(lm_ctx_list_t *list){ + if(NULL == list){ + lm_error_set(LM_ERR_ArgNULL); + return; + } + + bzero(list, sizeof(lm_ctx_list_t)); +} diff --git a/src/ctx/sync.c b/src/ctx/sync.c index b9d85e6..ccf3c8e 100644 --- a/src/ctx/sync.c +++ b/src/ctx/sync.c @@ -57,12 +57,12 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac } if(!do_update && !lm_pool_info_load(cur)){ - pdebug(__func__, "(%s) failed to load info: %s", cur->name, lm_strerror()); + pdebug(__func__, "(%s) failed to load info: %s", cur->name, lm_strerror()); goto next_info; } else if(do_update && !lm_pool_info_download(cur, __lm_ctx_sync_callback, &cbdata)) { - pdebug(__func__, "(%s) failed to update info: %s", cur->name, lm_strerror()); + pdebug(__func__, "(%s) failed to update info: %s", cur->name, lm_strerror()); goto next_info; } @@ -70,10 +70,15 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac status = true; next_info: - if(NULL != callback && status) - callback(ctx, cur, SYNC_INFO_SUCCESS, 0, 0, data); - else if(NULL != callback && !status) - callback(ctx, cur, SYNC_INFO_FAIL, 0, 0, data); + if(NULL != callback && status){ + if(!callback(ctx, cur, SYNC_INFO_SUCCESS, 0, 0, data)) + goto fail; + } + + else if(NULL != callback && !status){ + if(!callback(ctx, cur, SYNC_INFO_FAIL, 0, 0, data)) + goto fail; + } if(status) cur->loaded = true; @@ -107,12 +112,12 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac } if(!do_update && !lm_pool_list_load(cur, tempdir)){ - pdebug(__func__, "(%s) failed to load list: %s", cur->name, lm_strerror()); + pdebug(__func__, "(%s) failed to load list: %s", cur->name, lm_strerror()); goto next_list; } else if(do_update && !lm_pool_list_download(cur, tempdir, __lm_ctx_sync_callback, &cbdata)) { - pdebug(__func__, "(%s) failed to update list: %s", cur->name, lm_strerror()); + pdebug(__func__, "(%s) failed to update list: %s", cur->name, lm_strerror()); goto next_list; } @@ -123,19 +128,26 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac free(tempdir); tempdir = NULL; - if(NULL != callback && status) - callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data); - else if(NULL != callback && !status) - callback(ctx, cur, SYNC_LIST_FAIL, 0, 0, data); + if(NULL != callback && status){ + if(!callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data)) + goto fail; + } + + else if(NULL != callback && !status){ + if(!callback(ctx, cur, SYNC_LIST_FAIL, 0, 0, data)) + goto fail; + } if(!status) cur->loaded = false; else loaded_count++; - + status = false; cur = cur->next; } return loaded_count; +fail: + return -1; }