Add libpcp headers to git
This commit is contained in:
parent
dfe99de383
commit
a811632720
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,6 @@ srcdir/
|
||||
.vscode/
|
||||
|
||||
# Don't distribute the libpcp sources
|
||||
src/micetools/lib/libpcp/
|
||||
src/micetools/lib/libpcp/*.c
|
||||
# And keep build artifacts out of git!
|
||||
src/libpcp.lib
|
||||
|
7
src/micetools/lib/libpcp/libpcp.h
Normal file
7
src/micetools/lib/libpcp/libpcp.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "pcpa.h"
|
||||
|
||||
void pcptPrint(pcpt_t* stream, char* name);
|
||||
void pcppPrint(pcpp_t* stream);
|
||||
void pcpaPrint(pcpa_t* stream);
|
23
src/micetools/lib/libpcp/meson.build
Normal file
23
src/micetools/lib/libpcp/meson.build
Normal file
@ -0,0 +1,23 @@
|
||||
compiler = meson.get_compiler('c')
|
||||
ws2 = compiler.find_library('ws2_32', required: true)
|
||||
|
||||
sources = [
|
||||
'libpcp.c',
|
||||
'pcpt.c',
|
||||
'pcpp.c',
|
||||
'pcpa.c',
|
||||
'pcp.c',
|
||||
'util.c',
|
||||
]
|
||||
|
||||
libpcp = static_library(
|
||||
'pcp',
|
||||
name_suffix: 'lib',
|
||||
sources: sources,
|
||||
dependencies: [
|
||||
ws2,
|
||||
],
|
||||
link_with: [
|
||||
amlib,
|
||||
],
|
||||
)
|
77
src/micetools/lib/libpcp/pcp.h
Normal file
77
src/micetools/lib/libpcp/pcp.h
Normal file
@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#define PCP_LOG(fmt, ...) printf("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__)
|
||||
#define ZERO(x) memset(&(x), 0, sizeof(x))
|
||||
#define ZERO_BUF(x) memset((x), 0, sizeof(*x))
|
||||
|
||||
#include <Winsock2.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../am/amtimer.h"
|
||||
|
||||
#define PCP_CHAR_PROMPT '>'
|
||||
#define PCP_CHAR_BINACK '$'
|
||||
#define PCP_CHAR_HASH '#'
|
||||
#define PCP_CHAR_UNKNOWN '?'
|
||||
#define PCP_CHAR_SEP '&'
|
||||
#define PCP_CHAR_EQU '='
|
||||
#define PCP_CHAR_CR '\r'
|
||||
#define PCP_CHAR_LF '\n'
|
||||
#define PCP_CHAR_EOF '\0'
|
||||
#define PCP_WHITESPACE(x) ((x) == ' ' || (x) == '\t')
|
||||
|
||||
extern char* LIBPCP_VERSION;
|
||||
|
||||
typedef unsigned int undefined4;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
|
||||
typedef int timeout_t;
|
||||
|
||||
#define PCP_BUF_MAX 256
|
||||
#define PCP_CMDS_MAX 64
|
||||
#define PCP_KEYWORD_MAX 32
|
||||
#define PCP_SEND_BUF_MAX 8
|
||||
|
||||
typedef struct pcp_parse_data {
|
||||
char strings[PCP_BUF_MAX];
|
||||
byte keywords[PCP_CMDS_MAX];
|
||||
byte values[PCP_CMDS_MAX];
|
||||
uint cmd_count;
|
||||
} pcp_parse_data_t;
|
||||
typedef struct pcp_send_data {
|
||||
char data[PCP_BUF_MAX];
|
||||
size_t length;
|
||||
} pcp_send_data_t;
|
||||
|
||||
// Error helpers
|
||||
int _pcpaGetErrorFromPcpp(int err);
|
||||
int _pcppGetErrorFromPcpt(int err);
|
||||
#define _errP2A(err) _pcpaGetErrorFromPcpp(err)
|
||||
#define _errT2P(err) _pcppGetErrorFromPcpt(err)
|
||||
|
||||
// Errors
|
||||
#define OPEN_MODE_GLOBAL 0
|
||||
#define OPEN_MODE_1 1
|
||||
// #define OPEN_MODE_2 2
|
||||
|
||||
typedef enum binary_mode {
|
||||
binary_mode_none = 0,
|
||||
binary_mode_send = 1,
|
||||
binary_mode_recv = 2,
|
||||
} binary_mode_t;
|
||||
|
||||
#define PCPT_CONFIG_0 0
|
||||
#define PCPT_CONFIG_1 1
|
||||
#define PCPT_SO_LINGER 2
|
||||
#define PCPT_TCP_NODELAY 3
|
||||
|
||||
#define HANDLE_INVAL -1
|
||||
#define TIMEOUT_NONE -1
|
||||
|
||||
#define PCPT_CLOSED 0
|
||||
#define PCPT_LISTENING 1
|
||||
#define PCPT_CONNECTED 2
|
69
src/micetools/lib/libpcp/pcpa.h
Normal file
69
src/micetools/lib/libpcp/pcpa.h
Normal file
@ -0,0 +1,69 @@
|
||||
#include "pcpp.h"
|
||||
|
||||
typedef enum e_pcpa {
|
||||
e_pcpa_ok = 0,
|
||||
e_pcpa_to = 1,
|
||||
e_pcpa_closed = 2,
|
||||
e_pcpa_no_client = 3,
|
||||
e_pcpa_not_open = -1,
|
||||
e_pcpa_cannot_open = -2,
|
||||
e_pcpa_generic = -3,
|
||||
e_pcpa_param_invalid = -4,
|
||||
e_pcpa_timeout_closed = -5, // TODO: This is wrong (see: pcpaSetCallbackFuncBuffer)
|
||||
e_pcpa_cb_table_full = -9,
|
||||
e_pcpa_stream_unset = -10,
|
||||
e_pcpa_cb_table_unset = -11,
|
||||
e_pcpa_timeout_open = -14,
|
||||
e_pcpa_inval_addr = -17,
|
||||
e_pcpa_already_open = -18,
|
||||
e_pcpa_wsa_noinit = -20,
|
||||
e_pcpa_unknown = -21,
|
||||
} e_pcpa_t;
|
||||
|
||||
struct pcpa;
|
||||
typedef void(pcpa_callback)(struct pcpa* stream, void* data);
|
||||
|
||||
typedef struct pcpa_cb_table {
|
||||
char keyword[PCP_KEYWORD_MAX];
|
||||
void* data;
|
||||
pcpa_callback* callback;
|
||||
} pcpa_cb_table_t;
|
||||
|
||||
typedef struct pcpa {
|
||||
pcpp_t pcpp;
|
||||
e_pcpa_t err;
|
||||
uint state;
|
||||
pcpa_cb_table_t* callback_table;
|
||||
uint callback_max;
|
||||
uint callback_count;
|
||||
char* recv_buffer;
|
||||
size_t recv_buffer_len;
|
||||
char* send_buffer;
|
||||
size_t send_buffer_len;
|
||||
binary_mode_t binary_mode;
|
||||
pcpa_callback* binary_mode_before_cb;
|
||||
void* binary_mode_before_data;
|
||||
pcpa_callback* binary_mode_after_cb;
|
||||
void* binary_mode_after_data;
|
||||
// char* field_0x254;
|
||||
pcp_parse_data_t recv_data;
|
||||
pcp_send_data_t send_data;
|
||||
} pcpa_t;
|
||||
|
||||
void pcpaClose(pcpa_t* stream);
|
||||
void pcpaCloseBinary(pcpa_t* stream);
|
||||
char* pcpaGetKeyword(pcpa_t* stream, uint keyword_num);
|
||||
e_pcpa_t pcpaInitStream(pcpa_t* stream);
|
||||
e_pcpa_t pcpaOpenServerWithBinary(pcpa_t* stream, int open_mode, ushort port, ushort binary_port, undefined4 param_5);
|
||||
e_pcpa_t pcpaRecvBinary(pcpa_t* stream, undefined4 something);
|
||||
e_pcpa_t pcpaSendBinary(pcpa_t* stream, undefined4 something);
|
||||
e_pcpa_t pcpaServer(pcpa_t* stream, timeout_t timeout_ms);
|
||||
e_pcpa_t pcpaSetAfterBinaryModeCallBackFunc(pcpa_t* stream, pcpa_callback* callback, void* data);
|
||||
e_pcpa_t pcpaSetBeforeBinaryModeCallBackFunc(pcpa_t* stream, pcpa_callback* callback, void* data);
|
||||
e_pcpa_t pcpaSetBinaryMode(pcpa_t* stream, binary_mode_t binary_mode);
|
||||
e_pcpa_t pcpaSetCallbackFunc(pcpa_t* stream, char* keyword, pcpa_callback* callback, void* data);
|
||||
e_pcpa_t pcpaSetCallbackFuncBuffer(pcpa_t* stream, pcpa_cb_table_t* callback_table, uint callbacks_max);
|
||||
e_pcpa_t pcpaSetRecvBinaryBuffer(pcpa_t* stream, byte* recv_buffer, size_t len);
|
||||
e_pcpa_t pcpaSetSendBinaryBuffer(pcpa_t* stream, byte* send_buffer, size_t len);
|
||||
pcp_send_data_t* pcpaSetSendPacket(pcpa_t* stream, char* keyword, char* value);
|
||||
char* pcpaGetCommand(pcpa_t* pcpa, char* command);
|
87
src/micetools/lib/libpcp/pcpp.h
Normal file
87
src/micetools/lib/libpcp/pcpp.h
Normal file
@ -0,0 +1,87 @@
|
||||
#include "pcpt.h"
|
||||
|
||||
#define PCPP_CLOSED 0
|
||||
#define PCPP_OPEN 1
|
||||
|
||||
typedef enum e_pcpp {
|
||||
e_pcpp_ok = 0,
|
||||
e_pcpp_to = 1,
|
||||
e_pcpp_closed = 2,
|
||||
e_pcpp_no_client = 3,
|
||||
|
||||
e_pcpp_not_open = -1,
|
||||
e_pcpp_cannot_open = -2,
|
||||
e_pcpp_already_open = -3,
|
||||
e_pcpp_param_invalid = -5,
|
||||
e_pcpp_timeout_closed = -6,
|
||||
e_pcpp_recv_unset = -10,
|
||||
e_pcpp_timeout_open = -12,
|
||||
e_pcpp_inval_addr = -15,
|
||||
e_pcpp_wsa_noinit = -16,
|
||||
e_pcpp_unknown = -17,
|
||||
} e_pcpp_t;
|
||||
|
||||
e_pcpp_t _pcppGetErrorFromPcpt(int err);
|
||||
#define _errT2P(err) _pcppGetErrorFromPcpt(err)
|
||||
|
||||
typedef struct pcpp {
|
||||
pcpt_t sock;
|
||||
pcpt_t data_sock;
|
||||
uint field_0xb8; // Some sort of timeout
|
||||
int last_active;
|
||||
uint state;
|
||||
e_pcpp_t err;
|
||||
pcp_parse_data_t* recv_data_buffer;
|
||||
char read_bytes_buf[PCP_BUF_MAX];
|
||||
uint read_bytes_size;
|
||||
uint read_bytes_num;
|
||||
pcp_send_data_t* resp_buffer;
|
||||
uint resp_buffer_len;
|
||||
char send_buf[PCP_SEND_BUF_MAX];
|
||||
size_t send_buf_len;
|
||||
uint field_0x1e8;
|
||||
char* send_binary_buf;
|
||||
uint field_0x1f0;
|
||||
char* recv_binary_buf;
|
||||
size_t field_0x1f8;
|
||||
uint field_0x1fc;
|
||||
size_t recv_binary_buf_len;
|
||||
// All some sort of timeout I think
|
||||
uint field_0x204;
|
||||
uint field_0x208;
|
||||
uint field_0x20c;
|
||||
uint field_0x210;
|
||||
int field_0x214;
|
||||
int open;
|
||||
} pcpp_t;
|
||||
|
||||
pcp_send_data_t* pcppAddSendPacket(pcp_send_data_t* stream, char* key, char* value);
|
||||
pcp_parse_data_t* pcppChangeRequest(pcpp_t* stream, int* lenout);
|
||||
bool pcppCheckPrompt(pcpp_t* stream);
|
||||
e_pcpp_t pcppCheckRecvMsg(char* recv_data, size_t buf_len, int param_3);
|
||||
uint pcppCheckStr(char* param_1, uint* pcp_len, int* pcp_overflow);
|
||||
void pcppClose(pcpp_t* stream);
|
||||
void pcppCloseBinary(pcpp_t* stream);
|
||||
e_pcpp_t pcppGetBlockingTime(uint param_1, int param_2, pcpp_t* stream, int param_4, uint* blocking_time);
|
||||
char* pcppGetCommand(pcp_parse_data_t* pcpa, char* command);
|
||||
char* pcppGetKeyword(pcp_parse_data_t* recvData, uint keyword_num);
|
||||
SOCKET pcppGetServerSocket(pcpp_t* stream, int which);
|
||||
e_pcpp_t pcppInitStream(pcpp_t* stream);
|
||||
e_pcpp_t pcppIsBusy(pcpp_t* stream, timeout_t timeout);
|
||||
e_pcpp_t pcppOpenBinaryServer(pcpp_t* stream, int open_mode, ushort port);
|
||||
e_pcpp_t pcppOpenServer(pcpp_t* stream, int open_mode, ushort port, undefined4 param_4);
|
||||
e_pcpp_t pcppRecvAllMsg(uint param_1, pcpp_t* stream, bool* bReRecv);
|
||||
e_pcpp_t pcppRecvBinary(pcpp_t* stream, char* recv_buf, size_t buf_len, uint param_4);
|
||||
uint pcppRecvCheck(char* buf, int* found_at);
|
||||
e_pcpp_t pcppRecvPrompt(pcpp_t* stream, undefined4 param_2, int param_3);
|
||||
e_pcpp_t pcppRecvRequest(pcpp_t* stream, pcp_parse_data_t* recv_data, timeout_t timeout);
|
||||
e_pcpp_t pcppRecvRequestMain(pcpp_t* stream, bool* bReRecv, undefined4 param_3);
|
||||
e_pcpp_t pcppSendBinary(pcpp_t* stream, char* send_binary_buffer, size_t param_3, uint param_4);
|
||||
e_pcpp_t pcppSendPrompt(pcpp_t* stream, uint param_2, int param_3);
|
||||
e_pcpp_t pcppSendRequestMain(pcpp_t* stream, undefined4 param_2, int param_3);
|
||||
e_pcpp_t pcppSendResponse(pcpp_t* stream, pcp_send_data_t* resp_buffer, size_t buf_len, timeout_t timeout_ms);
|
||||
e_pcpp_t pcppSendResponseTable(pcpp_t* stream, pcp_send_data_t* data, timeout_t timeout_ms);
|
||||
pcp_send_data_t* pcppSetSendPacket(pcp_send_data_t* send_data, char* keyword, char* value);
|
||||
e_pcpp_t pcpp_something(amtime_t* now, timeout_t timeout, pcpp_t* stream, pcpt_t* sock, char* send_buf,
|
||||
size_t* send_len, undefined4 param_7, undefined4 param_8, e_pcpp_t fallback_err);
|
||||
void pcppResetRead(pcpp_t* param_1);
|
65
src/micetools/lib/libpcp/pcpt.h
Normal file
65
src/micetools/lib/libpcp/pcpt.h
Normal file
@ -0,0 +1,65 @@
|
||||
#include "pcp.h"
|
||||
|
||||
typedef enum e_pcpt {
|
||||
e_pcpt_ok = 0,
|
||||
e_pcpt_to = 1,
|
||||
e_pcpt_closed = 2,
|
||||
e_pcpt_no_client = 3,
|
||||
|
||||
e_pcpt_not_open = -1,
|
||||
// TODO: Check if these two are the wrong way round!
|
||||
e_pcpt_already_open = -2,
|
||||
e_pcpt_already_connected = -3,
|
||||
e_pcpt_pointer_unset = -4,
|
||||
|
||||
e_pcpt_cannot_open = -8,
|
||||
e_pcpt_nobufs = -9,
|
||||
e_pcpt_wsa2_generic = -10,
|
||||
e_pcpt_inval_addr = -12,
|
||||
|
||||
e_pcpt_NO_IDEA_WHAT_THIS_IS = -13,
|
||||
|
||||
e_pcpt_recv_unset = -15,
|
||||
e_pcpt_wsa_noinit = -16,
|
||||
e_pcpt_unknown = -17,
|
||||
} e_pcpt_t;
|
||||
|
||||
e_pcpt_t _pcptGetErrorFromWin(int err);
|
||||
#define _errW2T(err) _pcptGetErrorFromWin(err)
|
||||
|
||||
typedef struct pcpt {
|
||||
SOCKET server_sock;
|
||||
SOCKET client_sock;
|
||||
int client_open;
|
||||
int open;
|
||||
e_pcpt_t err;
|
||||
uint field_0x14;
|
||||
uint config_0;
|
||||
uint config_1;
|
||||
uint so_linger;
|
||||
uint tcp_nodelay;
|
||||
WSAEVENT client_event;
|
||||
WSAEVENT server_event;
|
||||
char* send_buf;
|
||||
size_t* send_buf_count;
|
||||
char* recv_buf;
|
||||
size_t* recv_buf_count;
|
||||
uint field_0x40;
|
||||
SOCKADDR client_addr;
|
||||
int field_0x54;
|
||||
int field_0x58;
|
||||
} pcpt_t;
|
||||
|
||||
e_pcpt_t pcptInitStream(pcpt_t* sock);
|
||||
void pcptClose(pcpt_t* sock);
|
||||
void pcptCloseDataSock(pcpt_t* sock);
|
||||
e_pcpt_t pcptAcceptServer(pcpt_t* stream, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptCheckConnectAble(pcpt_t* sock, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptCheckEvent(HANDLE event, timeout_t timeout_ms, SOCKET socket, uint event_mask);
|
||||
e_pcpt_t pcptIsBusy(pcpt_t* sock, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptOpenDataSockServer(pcpt_t* sock, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptOpenServer(pcpt_t* sock, int open_mode, ushort port);
|
||||
e_pcpt_t pcptRecv(pcpt_t* sock, char* recv_buf, size_t* recv_buf_len, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptSend(pcpt_t* sock, char* send_buf, size_t* send_len, uint param_4, timeout_t timeout_ms);
|
||||
e_pcpt_t pcptSendAllMsg(pcpt_t* sock, timeout_t timeout_ms);
|
||||
void pcptSetConfig(pcpt_t* sock, uint config, uint value);
|
@ -6,7 +6,7 @@ subdir('json')
|
||||
|
||||
fs = import('fs')
|
||||
# Handle the fact we aren't distributing the libpcp source
|
||||
if fs.is_dir('libpcp')
|
||||
if fs.exists('libpcp/libpcp.c')
|
||||
subdir('libpcp')
|
||||
libpcp_is_static = true
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user