#pragma once #include "database.h" #include "mptp.h" #include "pool.h" #include #include typedef struct lm_ctx { lm_database_t *db; // package database lm_pool_t *pools; // pool list char *root; // root path for package installtion char *temp; // temp path char *data; // package database path 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 **packages; lm_pkg_t *cur; ssize_t count, index; } lm_ctx_resolve_list_t; typedef struct lm_ctx_update_list { lm_entry_t **entries; ssize_t index, count; } lm_ctx_update_list_t; typedef enum lm_ctx_sync_state { SYNC_DOWNLOADING_INFO = 0, SYNC_INFO_SUCCESS = 1, SYNC_INFO_FAIL = 2, SYNC_DOWNLOADING_LIST = 3, SYNC_LIST_SUCCESS = 4, SYNC_LIST_FAIL = 5, } lm_ctx_sync_state_t; /* ################### ## ctx callbacks ## ################### */ typedef bool (*lm_ctx_database_callback_t)(lm_ctx_t *ctx, lm_pkg_t *pkg, void *data); typedef bool (*lm_ctx_download_callback_t)( lm_ctx_t *ctx, lm_pkg_t *pkg, bool is_archive, size_t current, size_t total, void *data); typedef bool (*lm_ctx_install_callback_t)( lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data); typedef bool (*lm_ctx_sync_callback_t)( lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data); typedef bool (*lm_ctx_serve_callback_t)(lm_pool_t *pool, lm_mptp_t *packet, struct sockaddr *addr, void *data); typedef bool (*lm_ctx_ping_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data); typedef bool (*lm_ctx_remove_callback_t)( lm_ctx_t *ctx, lm_entry_t *pkg, char *file, size_t current, size_t total, void *data); typedef bool (*lm_ctx_check_callback_t)( lm_ctx_t *ctx, lm_entry_t *pkg, char *file, bool success, size_t current, size_t total, void *data); /* ############### ## ctx stuff ## ############### */ bool lm_ctx_init(lm_ctx_t *ctx); bool lm_ctx_new(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir); 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, bool resolve_depends, 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 void lm_ctx_resolve_free(lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx); // get a list of entries to update lm_entry_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list); // get the next entry in the update list void lm_ctx_update_list_free(lm_ctx_update_list_t *list); // free the update list lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_entry_t *pkg); // returns the updated version of a entry bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry); // checks if a package is available for removal bool lm_ctx_remove( lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_remove_callback_t callback, void *data); // removes a single package bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t callback, void *data); // downloads a single package bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_install_callback_t callback, void *data); // installs/updates a single package bool lm_ctx_check( lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_check_callback_t callback, void *data); // checks a single package ssize_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads, __sighandler_t handler, lm_ctx_serve_callback_t callback, void *data); // serves all the pools /* ############################## ## temp directory fucntions ## ############################## */ char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir); bool lm_ctx_temp_clear(lm_ctx_t *ctx); /* #################### ## pool fucntions ## #################### */ lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version); // find a package in ctx pool list lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url, char *dir); // add a pool to the ctx pool list bool lm_ctx_pool_del(lm_ctx_t *ctx, char *name); // remove a pool from the ctx pool list void lm_ctx_pool_clear(lm_ctx_t *ctx); // clear all the pools in the ctx pool list lm_pool_t *lm_ctx_pool_by_name(lm_ctx_t *ctx, char *name); // find pool by name lm_pool_t *lm_ctx_pool_by_url(lm_ctx_t *ctx, char *host, char *path); // find pool by URL /* ######################## ## database fucntions ## ######################## */ bool lm_ctx_database_init(lm_ctx_t *ctx); // init ctx database (if not already present) bool lm_ctx_database_is_installed(lm_ctx_t *ctx, char *name, char *version); // check if a package is installed bool lm_ctx_database_find(lm_ctx_t *ctx, lm_entry_t *entry, char *name, char *version); // find a package by name bool lm_ctx_database_next(lm_ctx_t *ctx, lm_entry_t *entry); // load the next package into pkg pointer bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_entry_t *entry); // free the used next pointers char *lm_ctx_database_changes( lm_ctx_t *ctx, lm_entry_t *entry); // get changes file path for a package, FREE THE RETURNED POINTER /* ####################### ## package fucntions ## ####################### */ bool lm_ctx_package_from(lm_ctx_t *ctx, lm_pkg_t *pkg, char *archive); void lm_ctx_package_from_free(lm_pkg_t *pkg);