first commit

This commit is contained in:
ngn
2024-06-20 03:34:32 +03:00
commit 637b8c02e6
19 changed files with 949 additions and 0 deletions

4
include/all.h Normal file
View File

@ -0,0 +1,4 @@
#include "types.h"
#include "pool.h"
#include "error.h"
#include "libmp.h"

25
include/error.h Normal file
View File

@ -0,0 +1,25 @@
#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_URLBadPath = 7,
LM_ERR_URLPortUnknown = 8,
LM_ERR_URLBadPort = 9,
LM_ERR_PoolNoSupport = 10,
LM_ERR_URLEnd = 11,
} lm_error_t;
typedef struct lm_error_desc {
lm_error_t code;
char *desc;
} lm_error_desc_t;
void lm_error_set(lm_error_t code);
lm_error_t lm_error();
char *lm_strerror();

5
include/libmp.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include "types.h"
void lm_ctx_init(lm_ctx_t *ctx);
void lm_ctx_free(lm_ctx_t *ctx);

8
include/pool.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <stdbool.h>
#include "types.h"
bool lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url);
bool lm_ctx_pool_del(lm_ctx_t *ctx, char *name);
void lm_ctx_pool_clear(lm_ctx_t *ctx);
void lm_ctx_pool_test(lm_ctx_t *ctx);

20
include/types.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "url.h"
#include <stdbool.h>
typedef struct lm_pool {
struct lm_pool *next;
lm_url_t url;
bool available;
char *name;
} lm_pool_t;
typedef struct lm_ctx {
lm_pool_t *pools; // pool list
char *root; // root path for package installtion
char *temp; // temp path
char *data; // package database path
bool debug; // is debug output enabled?
} lm_ctx_t;

17
include/url.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#define URL_PROTOCOL_MAX 20
#define URL_PATH_MAX 2000
#define URL_HOST_MAX 260
typedef struct lm_url {
uint16_t port;
char protocol[URL_PROTOCOL_MAX+1];
char *host;
char *path;
} lm_url_t;
bool lm_url_parse(lm_url_t *url, char *str);
void lm_url_free(lm_url_t *url);

12
include/util.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <stdbool.h>
#include <libintl.h>
#include "types.h"
#define _(x) gettext(x)
void pdebug(lm_ctx_t *ctx, const char *func, const char *fmt, ...);
bool contains(char *str, char s);
bool eq(char *s1, char *s2);
bool is_letter(char c);
bool is_digit(char c);