update: add host info to the MPTP packets
This commit is contained in:
@ -11,8 +11,8 @@ typedef enum lm_error {
|
||||
LM_ERR_URLBadPort = 7,
|
||||
LM_ERR_URLBadPath = 8,
|
||||
LM_ERR_URLPortUnknown = 9,
|
||||
LM_ERR_BadPort = 10,
|
||||
LM_ERR_BadHost = 11,
|
||||
LM_ERR_BadPort = 10,
|
||||
LM_ERR_BadHost = 11,
|
||||
LM_ERR_PoolNoSupport = 12,
|
||||
LM_ERR_URLEnd = 13,
|
||||
LM_ERR_MPTPBadVersion = 14,
|
||||
@ -23,15 +23,17 @@ typedef enum lm_error {
|
||||
LM_ERR_MPTPConnectFail = 19,
|
||||
LM_ERR_MPTPRecvFail = 20,
|
||||
LM_ERR_MPTPSendFail = 21,
|
||||
LM_ERR_MPTPBadChunk = 22,
|
||||
LM_ERR_MPTPSetsockopt = 23,
|
||||
LM_ERR_MPTPTimeout = 24,
|
||||
LM_ERR_MPTPBindFail = 25,
|
||||
LM_ERR_ArgNULL = 26,
|
||||
LM_ERR_MPTPNotResponse = 27,
|
||||
LM_ERR_MPTPNotRequest = 28,
|
||||
LM_ERR_MPTPNotLast = 29,
|
||||
LM_ERR_NoPort = 30,
|
||||
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_error_t;
|
||||
|
||||
typedef struct lm_error_desc {
|
||||
|
@ -3,3 +3,9 @@
|
||||
|
||||
void lm_ctx_init(lm_ctx_t *ctx);
|
||||
void lm_ctx_free(lm_ctx_t *ctx);
|
||||
|
||||
lm_pool_t *lm_ctx_pools_add(lm_ctx_t *ctx, char *name, char *url);
|
||||
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);
|
||||
|
@ -12,8 +12,9 @@
|
||||
#####################################
|
||||
# FLAGS #
|
||||
#####################################
|
||||
# SIZE #
|
||||
# HOST SIZE | DATA SIZE #
|
||||
#####################################
|
||||
# HOST #
|
||||
# DATA #
|
||||
#...................................#
|
||||
|
||||
@ -51,17 +52,26 @@
|
||||
---------------------------------------------------------
|
||||
|
||||
|
||||
[16 bits] SIZE
|
||||
[8 bits] HOST SIZE
|
||||
=========================================================
|
||||
| All bits used for specifying the DATA size, in bytes
|
||||
| All bits used for specifying HOST size
|
||||
---------------------------------------------------------
|
||||
|
||||
[8 bits] DATA SIZE
|
||||
=========================================================
|
||||
| 8 bits used for specifying DATA size
|
||||
---------------------------------------------------------
|
||||
|
||||
[...] HOST
|
||||
---------------------------------------------------------
|
||||
| Plaintext server hostname, max size is 255 octets
|
||||
| see the SIZE section
|
||||
---------------------------------------------------------
|
||||
|
||||
[...] DATA
|
||||
---------------------------------------------------------
|
||||
| Plaintext data used for that specific request/response,
|
||||
| max value for SIZE is 65535, so this section may have
|
||||
| 65535 bytes total
|
||||
| max size is 255 octets, see the SIZE section
|
||||
---------------------------------------------------------
|
||||
|
||||
*/
|
||||
@ -69,8 +79,9 @@
|
||||
// clang-format on
|
||||
|
||||
#define MPTP_VERSION_SUPPORTED 0
|
||||
#define MPTP_CODE_MAX 3 // 2 bits
|
||||
#define MPTP_CHUNK_MAX 256
|
||||
#define MPTP_CODE_MAX 3
|
||||
#define MPTP_DATA_MAX UINT8_MAX
|
||||
#define MPTP_HOST_MAX UINT8_MAX
|
||||
#define MPTP_TIMEOUT 10
|
||||
|
||||
#define MPTP_REQUEST 0
|
||||
@ -92,12 +103,14 @@ typedef enum lm_mptp_response {
|
||||
|
||||
typedef struct lm_mptp_header {
|
||||
uint16_t flags;
|
||||
uint16_t size;
|
||||
uint8_t host_size;
|
||||
uint8_t data_size;
|
||||
} lm_mptp_header_t;
|
||||
|
||||
typedef struct lm_mptp {
|
||||
lm_mptp_header_t header;
|
||||
char data[MPTP_CHUNK_MAX];
|
||||
char host[MPTP_DATA_MAX];
|
||||
char data[MPTP_DATA_MAX];
|
||||
} lm_mptp_t;
|
||||
|
||||
#define MPTP_FLAGS_VERSION(m) (((m)->header.flags & 0xFF00) >> 8)
|
||||
@ -108,7 +121,11 @@ typedef struct lm_mptp {
|
||||
#define MPTP_IS_REQUEST(m) (MPTP_FLAGS_TYPE(m) == 0)
|
||||
#define MPTP_IS_LAST(m) (MPTP_FLAGS_LAST(m) == 1)
|
||||
|
||||
bool lm_mptp_packet_init(lm_mptp_t *packet, bool is_request, uint8_t code, bool is_last);
|
||||
bool lm_mptp_init(lm_mptp_t *packet, bool is_request, uint8_t code, bool is_last);
|
||||
bool lm_mptp_set_data(lm_mptp_t *packet, char *data, size_t size);
|
||||
bool lm_mptp_set_host(lm_mptp_t *packet, char *host);
|
||||
bool lm_mptp_get_host(lm_mptp_t *packet, char *host);
|
||||
|
||||
int lm_mptp_socket(char *addr, uint16_t port, struct sockaddr *saddr);
|
||||
bool lm_mptp_verify(lm_mptp_t *packet);
|
||||
void lm_mptp_close(int sock);
|
||||
|
@ -2,8 +2,8 @@
|
||||
#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);
|
||||
void lm_ctx_pool_clear(lm_ctx_t *ctx);
|
||||
void lm_ctx_pool_test(lm_ctx_t *ctx);
|
||||
bool lm_ctx_pool_serve(lm_ctx_t *ctx, char *addr);
|
||||
lm_pool_t *lm_pool_new(char *name, char *url);
|
||||
void lm_pool_test(lm_pool_t *pool);
|
||||
bool lm_pool_info_file(lm_pool_t *pool, char *file);
|
||||
bool lm_pool_info(lm_pool_t *pool, char *info);
|
||||
void lm_pool_free(lm_pool_t *pool);
|
||||
|
@ -1,9 +1,17 @@
|
||||
#pragma once
|
||||
#include "url.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct lm_pool_info {
|
||||
char *maintainer;
|
||||
char *pubkey;
|
||||
size_t size;
|
||||
} lm_pool_info_t;
|
||||
|
||||
typedef struct lm_pool {
|
||||
struct lm_pool *next;
|
||||
lm_pool_info_t info;
|
||||
lm_url_t url;
|
||||
bool available;
|
||||
char *name;
|
||||
|
@ -11,7 +11,6 @@ typedef struct lm_url {
|
||||
char protocol[URL_PROTOCOL_MAX + 1];
|
||||
char *host;
|
||||
char *path;
|
||||
bool empty;
|
||||
} lm_url_t;
|
||||
|
||||
bool lm_url_init(lm_url_t *url, char *str);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "types.h"
|
||||
#include <libintl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define _(x) gettext(x)
|
||||
|
||||
@ -11,3 +12,5 @@ bool contains(char *str, char s);
|
||||
bool eq(char *s1, char *s2);
|
||||
bool is_letter(char c);
|
||||
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);
|
||||
|
Reference in New Issue
Block a user