new: implement pool info for client/server
This commit is contained in:
@ -1,4 +1,28 @@
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
|
||||
* libmp | MatterLinux package management library
|
||||
* MatterLinux 2023-2024 (https://matterlinux.xyz)
|
||||
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
// clang-format on
|
||||
|
||||
#include "ctx.h"
|
||||
#include "error.h"
|
||||
#include "libmp.h"
|
||||
#include "pool.h"
|
||||
#include "types.h"
|
||||
|
@ -1,7 +1,13 @@
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*lm_ctx_pools_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data);
|
||||
|
||||
void lm_ctx_init(lm_ctx_t *ctx);
|
||||
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);
|
||||
void lm_ctx_free(lm_ctx_t *ctx);
|
||||
|
||||
lm_pool_t *lm_ctx_pools_add(lm_ctx_t *ctx, char *name, char *url);
|
||||
@ -9,3 +15,4 @@ bool lm_ctx_pools_del(lm_ctx_t *ctx, char *name);
|
||||
void lm_ctx_pools_clear(lm_ctx_t *ctx);
|
||||
void lm_ctx_pools_test(lm_ctx_t *ctx);
|
||||
bool lm_ctx_pools_serve(lm_ctx_t *ctx, char *addr, uint8_t threads);
|
||||
bool lm_ctx_pools_load(lm_ctx_t *ctx, bool force_update, lm_ctx_pools_callback_t callback, void *data);
|
@ -1,46 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum lm_error {
|
||||
LM_ERR_NoError = 0,
|
||||
LM_ERR_URLBadChar = 1,
|
||||
LM_ERR_URLBadProtocol = 2,
|
||||
LM_ERR_URLTooLarge = 3,
|
||||
LM_ERR_URLHostLarge = 4,
|
||||
LM_ERR_URLPathLarge = 5,
|
||||
LM_ERR_URLBadHost = 6,
|
||||
LM_ERR_URLBadPort = 7,
|
||||
LM_ERR_URLBadPath = 8,
|
||||
LM_ERR_URLPortUnknown = 9,
|
||||
LM_ERR_BadPort = 10,
|
||||
LM_ERR_BadHost = 11,
|
||||
LM_ERR_PoolNoSupport = 12,
|
||||
LM_ERR_URLEnd = 13,
|
||||
LM_ERR_MPTPBadVersion = 14,
|
||||
LM_ERR_MPTPBadCode = 15,
|
||||
LM_ERR_MPTPBadUrl = 16,
|
||||
LM_ERR_MPTPHostFail = 17,
|
||||
LM_ERR_MPTPSocketFail = 18,
|
||||
LM_ERR_MPTPConnectFail = 19,
|
||||
LM_ERR_MPTPRecvFail = 20,
|
||||
LM_ERR_MPTPSendFail = 21,
|
||||
LM_ERR_MPTPBadData = 22,
|
||||
LM_ERR_MPTPBadHost = 23,
|
||||
LM_ERR_MPTPSetsockopt = 24,
|
||||
LM_ERR_MPTPTimeout = 25,
|
||||
LM_ERR_MPTPBindFail = 26,
|
||||
LM_ERR_ArgNULL = 27,
|
||||
LM_ERR_MPTPNotResponse = 28,
|
||||
LM_ERR_MPTPNotRequest = 29,
|
||||
LM_ERR_MPTPNotLast = 30,
|
||||
LM_ERR_NoPort = 31,
|
||||
LM_ERR_PoolInfoBad = 32,
|
||||
LM_ERR_ArcWBlockFail = 33,
|
||||
LM_ERR_ArcRBlockFail = 34,
|
||||
LM_ERR_ArcOpenFail = 35,
|
||||
LM_ERR_ArcWHeaderFail = 36,
|
||||
LM_ERR_ArcWEntryFail = 37,
|
||||
LM_ERR_GetCwdFail = 38,
|
||||
LM_ERR_PoolListDirFail = 39,
|
||||
LM_ERR_NoError = 0,
|
||||
LM_ERR_URLBadChar = 1,
|
||||
LM_ERR_URLBadProtocol = 2,
|
||||
LM_ERR_URLTooLarge = 3,
|
||||
LM_ERR_URLHostLarge = 4,
|
||||
LM_ERR_URLPathLarge = 5,
|
||||
LM_ERR_URLBadHost = 6,
|
||||
LM_ERR_URLBadPort = 7,
|
||||
LM_ERR_URLBadPath = 8,
|
||||
LM_ERR_URLPortUnknown = 9,
|
||||
LM_ERR_BadPort = 10,
|
||||
LM_ERR_BadHost = 11,
|
||||
LM_ERR_PoolNoSupport = 12,
|
||||
LM_ERR_URLEnd = 13,
|
||||
LM_ERR_MPTPBadVersion = 14,
|
||||
LM_ERR_MPTPBadCode = 15,
|
||||
LM_ERR_MPTPBadUrl = 16,
|
||||
LM_ERR_MPTPHostFail = 17,
|
||||
LM_ERR_MPTPSocketFail = 18,
|
||||
LM_ERR_MPTPConnectFail = 19,
|
||||
LM_ERR_MPTPRecvFail = 20,
|
||||
LM_ERR_MPTPSendFail = 21,
|
||||
LM_ERR_MPTPBadData = 22,
|
||||
LM_ERR_MPTPBadHost = 23,
|
||||
LM_ERR_MPTPSetsockopt = 24,
|
||||
LM_ERR_MPTPTimeout = 25,
|
||||
LM_ERR_MPTPBindFail = 26,
|
||||
LM_ERR_ArgNULL = 27,
|
||||
LM_ERR_MPTPNotResponse = 28,
|
||||
LM_ERR_MPTPNotRequest = 29,
|
||||
LM_ERR_MPTPNotLast = 30,
|
||||
LM_ERR_NoPort = 31,
|
||||
LM_ERR_PoolInfoBad = 32,
|
||||
LM_ERR_ArcWBlockFail = 33,
|
||||
LM_ERR_ArcRBlockFail = 34,
|
||||
LM_ERR_ArcOpenFail = 35,
|
||||
LM_ERR_ArcWHeaderFail = 36,
|
||||
LM_ERR_ArcWEntryFail = 37,
|
||||
LM_ERR_GetCwdFail = 38,
|
||||
LM_ERR_PoolListDirFail = 39,
|
||||
LM_ERR_PoolListCantRead = 40,
|
||||
LM_ERR_PoolInfoCantRead = 41,
|
||||
LM_ERR_PkgBadName = 42,
|
||||
LM_ERR_PkgDataBad = 43,
|
||||
LM_ERR_CtxDataNULL = 44,
|
||||
LM_ERR_CtxTempFail = 45,
|
||||
LM_ERR_CtxTempNotDir = 46,
|
||||
LM_ERR_CtxTempNoWrite = 47,
|
||||
LM_ERR_CtxRootFail = 48,
|
||||
LM_ERR_CtxRootNotDir = 49,
|
||||
LM_ERR_CtxRootNoWrite = 50,
|
||||
LM_ERR_CtxDataNotDir = 51,
|
||||
LM_ERR_CtxDataNoWrite = 52,
|
||||
LM_ERR_CtxDataFailMkdir = 53,
|
||||
|
||||
} lm_error_t;
|
||||
|
||||
|
@ -2,7 +2,13 @@
|
||||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PKG_DATA_SIZE "size"
|
||||
#define PKG_DATA_DESC "desc"
|
||||
#define PKG_DATA_VERSION "version"
|
||||
#define PKG_DATA_DEPENDS "depends"
|
||||
|
||||
lm_pkg_t *lm_pkg_new();
|
||||
void lm_pkg_free(lm_pkg_t *pkg);
|
||||
|
||||
bool lm_pkg_data_load(lm_pkg_t *pkg, char *file);
|
||||
void lm_pkg_data_free(lm_pkg_t *pkg);
|
||||
|
@ -5,6 +5,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define POOL_INFO_SIZE "size"
|
||||
#define POOL_INFO_PUBKEY "pubkey"
|
||||
#define POOL_INFO_MAINTAINER "maintainer"
|
||||
|
||||
typedef struct lm_pool_thread_arg {
|
||||
int sock;
|
||||
struct sockaddr addr;
|
||||
@ -21,5 +25,8 @@ bool lm_pool_info_load(lm_pool_t *pool, char *file);
|
||||
bool lm_pool_info_get(lm_pool_t *pool, char *file);
|
||||
void lm_pool_info_free(lm_pool_t *pool);
|
||||
|
||||
bool lm_pool_list_load(lm_pool_t *pool, char *file);
|
||||
bool lm_pool_list_get(lm_pool_t *pool, char *file);
|
||||
|
||||
void lm_pool_serve(lm_pool_t *pool, lm_mptp_t *packet, int sock, struct sockaddr *addr);
|
||||
void lm_pool_serve_thread(void *arg);
|
||||
|
@ -15,3 +15,9 @@ bool is_digit(char c);
|
||||
bool copy_to_buffer(void *buffer, void *src, size_t size, ssize_t *total, ssize_t *used);
|
||||
bool copy_from_buffer(void *dst, void *buffer, size_t size, ssize_t *total, ssize_t *used);
|
||||
bool extract_archive(char *dst, char *src);
|
||||
bool is_pkg_name_valid(char *name);
|
||||
bool exists(char *path);
|
||||
bool is_file(char *path);
|
||||
bool is_dir(char *path);
|
||||
bool can_read(char *path);
|
||||
bool can_write(char *path);
|
||||
|
Reference in New Issue
Block a user