2024-06-20 00:34:32 +00:00
|
|
|
#pragma once
|
2024-07-02 01:44:07 +00:00
|
|
|
#include "database.h"
|
2024-06-20 00:34:32 +00:00
|
|
|
#include "types.h"
|
2024-07-04 22:44:42 +00:00
|
|
|
|
2024-06-27 20:05:39 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2024-07-04 00:12:33 +00:00
|
|
|
typedef struct lm_ctx {
|
2024-07-04 22:44:42 +00:00
|
|
|
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)
|
2024-07-04 00:12:33 +00:00
|
|
|
} lm_ctx_t;
|
|
|
|
|
2024-07-04 22:44:42 +00:00
|
|
|
typedef struct lm_ctx_resolve_list {
|
|
|
|
lm_pkg_t *resolving;
|
|
|
|
lm_pkg_t *packages;
|
|
|
|
lm_pkg_t *cur;
|
|
|
|
size_t count;
|
|
|
|
} lm_ctx_resolve_list_t;
|
|
|
|
|
|
|
|
typedef struct lm_ctx_update_list {
|
|
|
|
lm_pkg_t **packages;
|
|
|
|
size_t count;
|
|
|
|
size_t index;
|
|
|
|
} lm_ctx_update_list_t;
|
|
|
|
|
|
|
|
/* ###################
|
|
|
|
## ctx callbacks ##
|
|
|
|
################### */
|
2024-07-04 00:12:33 +00:00
|
|
|
typedef bool (*lm_ctx_database_callback_t)(lm_ctx_t *ctx, lm_pkg_t *pkg, void *data);
|
2024-07-04 22:44:42 +00:00
|
|
|
typedef bool (*lm_ctx_download_callback_t)(lm_ctx_t *ctx, lm_pkg_t *pkg, 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, bool status, size_t current, size_t total, void *data);
|
|
|
|
typedef lm_ctx_install_callback_t lm_ctx_remove_callback_t;
|
|
|
|
typedef lm_ctx_install_callback_t lm_ctx_check_callback_t;
|
2024-06-20 00:34:32 +00:00
|
|
|
|
2024-07-04 22:44:42 +00:00
|
|
|
/* ###############
|
|
|
|
## ctx stuff ##
|
|
|
|
############### */
|
2024-06-20 00:34:32 +00:00
|
|
|
void lm_ctx_init(lm_ctx_t *ctx);
|
2024-06-27 20:05:39 +00:00
|
|
|
bool lm_ctx_set_data(lm_ctx_t *ctx, char *dir);
|
|
|
|
bool lm_ctx_set_root(lm_ctx_t *ctx, char *dir);
|
|
|
|
bool lm_ctx_set_temp(lm_ctx_t *ctx, char *dir);
|
2024-06-20 00:34:32 +00:00
|
|
|
void lm_ctx_free(lm_ctx_t *ctx);
|
2024-06-22 22:55:01 +00:00
|
|
|
|
2024-07-04 22:44:42 +00:00
|
|
|
/* ####################
|
|
|
|
## main fucntions ##
|
|
|
|
#################### */
|
|
|
|
lm_pkg_t *lm_ctx_find(lm_ctx_t *ctx, char *name, char *version); // find package by name (and version)
|
|
|
|
|
|
|
|
lm_ctx_resolve_list_t *lm_ctx_resolve(
|
|
|
|
lm_ctx_t *ctx, lm_pkg_t *pkg); // resolves a package and returns a list of packages to install
|
|
|
|
lm_pkg_t *lm_ctx_resolve_next(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list); // returns the next package in the list
|
|
|
|
void lm_ctx_resolve_free(
|
|
|
|
lm_ctx_t *ctx, lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve
|
|
|
|
|
|
|
|
lm_ctx_update_list_t *lm_ctx_update(lm_ctx_t *ctx); // returns a list of packages to update
|
|
|
|
lm_pkg_t *lm_ctx_update_next(lm_ctx_t *ctx, lm_ctx_update_list_t *list); // returns the next package in the list
|
|
|
|
void lm_ctx_update_free(lm_ctx_t *ctx, lm_ctx_update_list_t *list); // frees the update list returned by lm_ctx_update
|
|
|
|
|
|
|
|
bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t callback,
|
|
|
|
void *data); // downloads a single package if its not already downloaded
|
|
|
|
bool lm_ctx_install(
|
|
|
|
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t callback, void *data); // installs/updates a single package
|
|
|
|
bool lm_ctx_remove(
|
|
|
|
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callback, void *data); // removes a single package
|
|
|
|
bool lm_ctx_check(
|
|
|
|
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback, void *data); // checks a single package
|
|
|
|
bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools
|
|
|
|
bool lm_ctx_serve(lm_ctx_t *ctx, char *add, uint8_t threads); // serves all the pools
|
|
|
|
|
|
|
|
/* ####################
|
|
|
|
## pool fucntions ##
|
|
|
|
#################### */
|
|
|
|
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url); // 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
|
|
|
|
bool lm_ctx_pool_serve(
|
|
|
|
lm_ctx_t *ctx, char *addr, uint8_t threads); // serve all the pools on a MPTP server hosted at the given address
|
|
|
|
void lm_ctx_pool_test(lm_ctx_t *ctx); // test (ping) all the pool connetions
|
|
|
|
void lm_ctx_pool_get_info(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
|
|
|
|
void *data); // get pool info of all the pools in the ctx list
|
|
|
|
void lm_ctx_pool_get_list(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
|
|
|
|
void *data); // get pool list of all the pools in the ctx list
|
|
|
|
|
|
|
|
/* ########################
|
|
|
|
## 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, lm_pkg_t *pkg, bool check_version); // check if a package is installed
|
|
|
|
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_pkg_t *pkg, char *name); // find a package by name
|
|
|
|
bool lm_ctx_database_foreach(
|
|
|
|
lm_ctx_t *ctx, lm_ctx_database_callback_t callback, void *data); // loop for each package in the database
|