setup mptp headers and types
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#include "types.h"
|
||||
#include "pool.h"
|
||||
#include "error.h"
|
||||
#include "libmp.h"
|
||||
#include "pool.h"
|
||||
#include "types.h"
|
||||
|
@ -2,24 +2,24 @@
|
||||
|
||||
typedef enum lm_error {
|
||||
LM_ERR_NoError = 0,
|
||||
LM_ERR_URLBadChar = 1,
|
||||
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_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_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;
|
||||
char *desc;
|
||||
} lm_error_desc_t;
|
||||
|
||||
void lm_error_set(lm_error_t code);
|
||||
void lm_error_set(lm_error_t code);
|
||||
lm_error_t lm_error();
|
||||
char *lm_strerror();
|
||||
char *lm_strerror();
|
||||
|
93
include/mptp.h
Normal file
93
include/mptp.h
Normal file
@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "types.h"
|
||||
|
||||
/*
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
||||
#####################################
|
||||
# FLAGS #
|
||||
#####################################
|
||||
# SIZE #
|
||||
# #
|
||||
#####################################
|
||||
# DATA #
|
||||
#...................................#
|
||||
|
||||
[8 bits] FLAGS
|
||||
---------------------------------------------------------
|
||||
4 bits used for specifying the version
|
||||
---------------------------------------------------------
|
||||
1 bit used to specify if this is a request or response
|
||||
|
||||
0- it's a request
|
||||
1- it's a response
|
||||
---------------------------------------------------------
|
||||
2 bits used for request/response codes
|
||||
|
||||
We have 4 types of different requests
|
||||
1- PING: checks if the server is avaliable
|
||||
2- INFO: gets information about the pool(s) the server is hosting
|
||||
3- LIST: requests the package list for certain pool
|
||||
4- PULL: requests a certain package from a certain pool
|
||||
|
||||
And 4 types of responses
|
||||
1- PONG: response for the ping request
|
||||
2- COOL: everything is fine, here's the data you requested
|
||||
3- BRUH: cannot access to the data you requested, or version mismatch
|
||||
4- WHAT: bad request
|
||||
---------------------------------------------------------
|
||||
1 bit used to specify if this the last request/response
|
||||
|
||||
0- no stay connected, im not done responsing/requesting yet
|
||||
1- yes, im done, disconnect
|
||||
---------------------------------------------------------
|
||||
|
||||
[16 bits] SIZE
|
||||
---------------------------------------------------------
|
||||
All bits used for specifying the DATA size, in bytes
|
||||
---------------------------------------------------------
|
||||
|
||||
[...] DATA
|
||||
---------------------------------------------------------
|
||||
Plaintext data used for that specific request/response,
|
||||
max value for SIZE is 65535, so this section may have
|
||||
65535 bytes total
|
||||
---------------------------------------------------------
|
||||
|
||||
*/
|
||||
|
||||
#define MPTP_VERSION_SUPPORTED 0
|
||||
#define MPTP_VERSION_MAX 15 // 4 bits
|
||||
#define MPTP_CODE_MAX 4 // 2 bits
|
||||
|
||||
typedef enum lm_mptp_request{
|
||||
MPTP_C2S_PING = 0,
|
||||
MPTP_C2S_INFO = 1,
|
||||
MPTP_C2S_LIST = 2,
|
||||
MPTP_C2S_PULL = 3,
|
||||
} lm_mptp_request_t;
|
||||
|
||||
typedef enum lm_mptp_response{
|
||||
MPTP_S2C_PONG = 0,
|
||||
MPTP_S2C_COOL = 1,
|
||||
MPTP_S2C_BRUH = 2,
|
||||
MPTP_S2C_WHAT = 3,
|
||||
} lm_mptp_response_t;
|
||||
|
||||
typedef struct lm_mptp {
|
||||
uint8_t flags;
|
||||
uint16_t size;
|
||||
char *data;
|
||||
} lm_mptp_t;
|
||||
|
||||
void lm_mptp_flags_set(lm_mptp_t *packet, uint8_t version, bool is_request, uint8_t code, bool is_last);
|
||||
#define MPTP_FLAGS_VERSION(m) (m->flags >> 4) & 15
|
||||
#define MPTP_FLAGS_IS_REQUEST(m) ((m->flags >> 3) & 1) == 0
|
||||
#define MPTP_FLAGS_TYPE(m) (m->flags >> 1) & 3
|
||||
#define MPTP_FLAGS_IS_LAST(m) (m->flags & 1) == 1
|
||||
|
||||
int lm_mptp_connect(lm_url_t *url);
|
||||
bool lm_mptp_recv(int socket, lm_mptp_t *packet);
|
||||
bool lm_mptp_send(int socket, lm_mptp_t *packet);
|
||||
void lm_mptp_disconnect(int socket);
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include "types.h"
|
||||
#include <stdbool.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);
|
||||
|
@ -4,17 +4,16 @@
|
||||
|
||||
typedef struct lm_pool {
|
||||
struct lm_pool *next;
|
||||
lm_url_t url;
|
||||
bool available;
|
||||
char *name;
|
||||
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?
|
||||
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;
|
||||
|
||||
|
@ -3,14 +3,14 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define URL_PROTOCOL_MAX 20
|
||||
#define URL_PATH_MAX 2000
|
||||
#define URL_HOST_MAX 260
|
||||
#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;
|
||||
char protocol[URL_PROTOCOL_MAX + 1];
|
||||
char *host;
|
||||
char *path;
|
||||
} lm_url_t;
|
||||
|
||||
bool lm_url_parse(lm_url_t *url, char *str);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <libintl.h>
|
||||
#include "types.h"
|
||||
#include <libintl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define _(x) gettext(x)
|
||||
|
||||
|
Reference in New Issue
Block a user