mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 12:40:04 +00:00
Refactoring: reorganized files
This commit is contained in:
parent
169313ee39
commit
b23057b219
@ -17,7 +17,7 @@ Looking for some simple tasks that need to get done for that sweet 'contributor'
|
||||
- Change `lib/lin/linshell.c` to use openpty() instead of forkpty() for BSD support
|
||||
- Fix address sanitizer for CMake DEBUG builds
|
||||
- Change laikaT_getTime in `lib/src/ltask.c` to not use C11 features
|
||||
- Implement more LAIKA_BOX_* VMs in `lib/include/lbox.h`
|
||||
- Implement more LAIKA_BOX_* VMs in `lib/include/core/lbox.h`
|
||||
- Import more WinAPI manually using the method listed below
|
||||
|
||||
## Bot: Windows API Imports Obfuscation
|
||||
@ -63,7 +63,7 @@ If the `real` & `hashed` match, that means our manual runtime import and the imp
|
||||
Now just replace all of the calls to the raw WinAPI (in our case, ShellExecuteA) with our new manually imported oShellExecuteA function pointer. Format & commit your changes, and open a PR and I'll merge your changes. Thanks!
|
||||
|
||||
## Lib: Error Handling
|
||||
Error handling in Laika is done via the 'lerror.h' header library. It's a small and simple error handling solution written for laika, however can be stripped and used as a simple error handling library. Error handling in Laika is used similarly to other languages, implementing a try & catch block and is achieved using setjmp(). The LAIKA_ERROR(...) is used to throw errors.
|
||||
Error handling in Laika is done via the 'core/lerror.h' header library. It's a small and simple error handling solution written for laika, however can be stripped and used as a simple error handling library. Error handling in Laika is used similarly to other languages, implementing a try & catch block and is achieved using setjmp(). The LAIKA_ERROR(...) is used to throw errors.
|
||||
|
||||
Example:
|
||||
```C
|
||||
@ -85,13 +85,13 @@ Some minor inconveniences include:
|
||||
|
||||
## Lib: Packet Handlers
|
||||
|
||||
Laika has a simple binary protocol & a small backend (see `lib/src/lpeer.c`) to handle packets to/from peers. `lib/include/lpacket.h` includes descriptions for each packet type. For an example of proper packet handler definitions see `bot/src/bot.c`. It boils down to passing a sLaika_peerPacketInfo table to laikaS_newPeer. To add packet handlers to the bot, add your handler info to laikaB_pktTbl in `bot/src/bot.c`. To add packet handlers to the shell, add your handler info to shellC_pktTbl in `shell/src/sclient.c`. For adding packet handlers to cnc, make sure you add them to the corresponding table in `cnc/src/cnc.c`, laikaC_botPktTbl for packets being received from a bot peer, laikaC_authPktTbl for packets being received from an auth peer (shell), or DEFAULT_PKT_TBL if it's received by all peer types (things like handshakes, keep-alive, etc.)
|
||||
Laika has a simple binary protocol & a small backend (see `lib/src/lpeer.c`) to handle packets to/from peers. `lib/include/net/lpacket.h` includes descriptions for each packet type. For an example of proper packet handler definitions see `bot/src/bot.c`. It boils down to passing a sLaika_peerPacketInfo table to laikaS_newPeer. To add packet handlers to the bot, add your handler info to laikaB_pktTbl in `bot/src/bot.c`. To add packet handlers to the shell, add your handler info to shellC_pktTbl in `shell/src/sclient.c`. For adding packet handlers to cnc, make sure you add them to the corresponding table in `cnc/src/cnc.c`, laikaC_botPktTbl for packets being received from a bot peer, laikaC_authPktTbl for packets being received from an auth peer (shell), or DEFAULT_PKT_TBL if it's received by all peer types (things like handshakes, keep-alive, etc.)
|
||||
|
||||
## Lib: Task Service
|
||||
Tasks can be scheduled on a delta-period (call X function every approximate N seconds). laikaT_pollTasks() is used to check & run any currently queued tasks. This is useful for sending keep-alive packets, polling shell pipes, or other repeatably scheduled tasks. Most laikaT_pollTasks() calls are done in the peerHandler for each client/server.
|
||||
|
||||
## Lib: VM Boxes
|
||||
Laika has a tiny VM for decrypting sensitive information. For details on the ISA read `lib/include/lvm.h`, for information on how to use them read `lib/include/lbox.h`. Feel free to write your own boxes and contribute them :D
|
||||
Laika has a tiny VM for decrypting sensitive information. For details on the ISA read `lib/include/core/lvm.h`, for information on how to use them read `lib/include/core/lbox.h`. Feel free to write your own boxes and contribute them :D
|
||||
|
||||
## Bot: Platform-specific backends
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#ifndef LAIKA_BOT_H
|
||||
#define LAIKA_BOT_H
|
||||
|
||||
#include "core/lsodium.h"
|
||||
#include "core/ltask.h"
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
#include "lpeer.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsocket.h"
|
||||
#include "lsodium.h"
|
||||
#include "ltask.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "net/lpeer.h"
|
||||
#include "net/lpolllist.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
struct sLaika_shell;
|
||||
struct sLaika_bot
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define LAIKA_SHELL_H
|
||||
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
#include "net/lpacket.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
/* platform specific code for achieving persistence on linux */
|
||||
|
||||
#include "lbox.h"
|
||||
#include "core/lbox.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "lconfig.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lsocket.h"
|
||||
#include "net/lsocket.h"
|
||||
#include "persist.h"
|
||||
|
||||
#include <pwd.h>
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* platform specific code for opening shells in linux */
|
||||
|
||||
#include "bot.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "ltask.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/ltask.h"
|
||||
#include "shell.h"
|
||||
|
||||
#include <pty.h>
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "bot.h"
|
||||
|
||||
#include "lbox.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lsodium.h"
|
||||
#include "core/lbox.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "shell.h"
|
||||
|
||||
void laikaB_handleHandshakeResponse(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData)
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "bot.h"
|
||||
#include "lbox.h"
|
||||
#include "core/lbox.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/ltask.h"
|
||||
#include "lconfig.h"
|
||||
#include "lerror.h"
|
||||
#include "ltask.h"
|
||||
#include "lobf.h"
|
||||
#include "persist.h"
|
||||
#include "shell.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "shell.h"
|
||||
|
||||
#include "bot.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
@ -6,11 +6,11 @@
|
||||
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
|
||||
#include "lbox.h"
|
||||
#include "core/lbox.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lvm.h"
|
||||
#include "lconfig.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lvm.h"
|
||||
#include "lobf.h"
|
||||
#include "persist.h"
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* platform specific code for opening shells (pseudo consoles) on windows */
|
||||
#include "bot.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "lobf.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "shell.h"
|
||||
|
||||
#include <process.h>
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef LAIKA_CNC_H
|
||||
#define LAIKA_CNC_H
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "core/hashmap.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/ltask.h"
|
||||
#include "laika.h"
|
||||
#include "lmem.h"
|
||||
#include "lpacket.h"
|
||||
#include "lpeer.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsocket.h"
|
||||
#include "ltask.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "net/lpeer.h"
|
||||
#include "net/lpolllist.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
/* kill peers if they haven't ping'd within a minute */
|
||||
#define LAIKA_PEER_TIMEOUT 60 * 1000
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define LAIKA_CNC_PANEL_H
|
||||
|
||||
#include "cnc.h"
|
||||
#include "lpeer.h"
|
||||
#include "net/lpeer.h"
|
||||
|
||||
void laikaC_sendPeerList(struct sLaika_cnc *cnc, struct sLaika_peer *authPeer);
|
||||
void laikaC_sendNewPeer(struct sLaika_peer *authPeer, struct sLaika_peer *bot);
|
||||
|
@ -2,10 +2,10 @@
|
||||
#define LAIKA_CNC_PEER_H
|
||||
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
#include "lpeer.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsocket.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "net/lpeer.h"
|
||||
#include "net/lpolllist.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
struct sLaika_peerInfo
|
||||
{
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "cnc.h"
|
||||
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "core/ltask.h"
|
||||
#include "cpanel.h"
|
||||
#include "cpeer.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lsocket.h"
|
||||
#include "lsodium.h"
|
||||
#include "ltask.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
/* ======================================[[ PeerHashMap ]]======================================= */
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "cpanel.h"
|
||||
|
||||
#include "cnc.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "cpeer.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
|
||||
void laikaC_sendPeerList(struct sLaika_cnc *cnc, struct sLaika_peer *authPeer)
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "cpeer.h"
|
||||
|
||||
#include "cnc.h"
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
/* =======================================[[ Peer Info ]]======================================= */
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "cnc.h"
|
||||
#include "ini.h"
|
||||
#include "core/ini.h"
|
||||
#include "core/ltask.h"
|
||||
#include "lconfig.h"
|
||||
#include "ltask.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -8,7 +8,7 @@ project(LaikaLib VERSION ${LAIKA_VERSION_MAJOR}.${LAIKA_VERSION_MINOR})
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# compile LaikaLib library
|
||||
file(GLOB_RECURSE LIBSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c ${CMAKE_CURRENT_SOURCE_DIR}/vendor/**.c)
|
||||
file(GLOB_RECURSE LIBSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c)
|
||||
file(GLOB_RECURSE LIBHEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/**.h)
|
||||
|
||||
# include platform specific backends
|
||||
|
@ -16,129 +16,127 @@ https://github.com/benhoyt/inih
|
||||
|
||||
/* Make this header file easier to include in C++ code */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Nonzero if ini_handler callback should accept lineno parameter. */
|
||||
#ifndef INI_HANDLER_LINENO
|
||||
#define INI_HANDLER_LINENO 0
|
||||
# define INI_HANDLER_LINENO 0
|
||||
#endif
|
||||
|
||||
/* Typedef for prototype of handler function. */
|
||||
#if INI_HANDLER_LINENO
|
||||
typedef int (*ini_handler)(void* user, const char* section,
|
||||
const char* name, const char* value,
|
||||
int lineno);
|
||||
typedef int (*ini_handler)(void *user, const char *section, const char *name, const char *value,
|
||||
int lineno);
|
||||
#else
|
||||
typedef int (*ini_handler)(void* user, const char* section,
|
||||
const char* name, const char* value);
|
||||
typedef int (*ini_handler)(void *user, const char *section, const char *name, const char *value);
|
||||
#endif
|
||||
|
||||
/* Typedef for prototype of fgets-style reader function. */
|
||||
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
||||
/* Typedef for prototype of fgets-style reader function. */
|
||||
typedef char *(*ini_reader)(char *str, int num, void *stream);
|
||||
|
||||
/* Parse given INI-style file. May have [section]s, name=value pairs
|
||||
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
||||
is "" if name=value pair parsed before any section heading. name:value
|
||||
pairs are also supported as a concession to Python's configparser.
|
||||
/* Parse given INI-style file. May have [section]s, name=value pairs
|
||||
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
||||
is "" if name=value pair parsed before any section heading. name:value
|
||||
pairs are also supported as a concession to Python's configparser.
|
||||
|
||||
For each name=value pair parsed, call handler function with given user
|
||||
pointer as well as section, name, and value (data only valid for duration
|
||||
of handler call). Handler should return nonzero on success, zero on error.
|
||||
For each name=value pair parsed, call handler function with given user
|
||||
pointer as well as section, name, and value (data only valid for duration
|
||||
of handler call). Handler should return nonzero on success, zero on error.
|
||||
|
||||
Returns 0 on success, line number of first error on parse error (doesn't
|
||||
stop on first error), -1 on file open error, or -2 on memory allocation
|
||||
error (only when INI_USE_STACK is zero).
|
||||
*/
|
||||
int ini_parse(const char* filename, ini_handler handler, void* user);
|
||||
Returns 0 on success, line number of first error on parse error (doesn't
|
||||
stop on first error), -1 on file open error, or -2 on memory allocation
|
||||
error (only when INI_USE_STACK is zero).
|
||||
*/
|
||||
int ini_parse(const char *filename, ini_handler handler, void *user);
|
||||
|
||||
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
||||
close the file when it's finished -- the caller must do that. */
|
||||
int ini_parse_file(FILE* file, ini_handler handler, void* user);
|
||||
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
||||
close the file when it's finished -- the caller must do that. */
|
||||
int ini_parse_file(FILE *file, ini_handler handler, void *user);
|
||||
|
||||
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
||||
filename. Used for implementing custom or string-based I/O (see also
|
||||
ini_parse_string). */
|
||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
void* user);
|
||||
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
||||
filename. Used for implementing custom or string-based I/O (see also
|
||||
ini_parse_string). */
|
||||
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user);
|
||||
|
||||
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
|
||||
instead of a file. Useful for parsing INI data from a network socket or
|
||||
already in memory. */
|
||||
int ini_parse_string(const char* string, ini_handler handler, void* user);
|
||||
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
|
||||
instead of a file. Useful for parsing INI data from a network socket or
|
||||
already in memory. */
|
||||
int ini_parse_string(const char *string, ini_handler handler, void *user);
|
||||
|
||||
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
||||
configparser. If allowed, ini_parse() will call the handler with the same
|
||||
name for each subsequent line parsed. */
|
||||
#ifndef INI_ALLOW_MULTILINE
|
||||
#define INI_ALLOW_MULTILINE 1
|
||||
# define INI_ALLOW_MULTILINE 1
|
||||
#endif
|
||||
|
||||
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
||||
the file. See https://github.com/benhoyt/inih/issues/21 */
|
||||
#ifndef INI_ALLOW_BOM
|
||||
#define INI_ALLOW_BOM 1
|
||||
# define INI_ALLOW_BOM 1
|
||||
#endif
|
||||
|
||||
/* Chars that begin a start-of-line comment. Per Python configparser, allow
|
||||
both ; and # comments at the start of a line by default. */
|
||||
#ifndef INI_START_COMMENT_PREFIXES
|
||||
#define INI_START_COMMENT_PREFIXES ";#"
|
||||
# define INI_START_COMMENT_PREFIXES ";#"
|
||||
#endif
|
||||
|
||||
/* Nonzero to allow inline comments (with valid inline comment characters
|
||||
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
|
||||
Python 3.2+ configparser behaviour. */
|
||||
#ifndef INI_ALLOW_INLINE_COMMENTS
|
||||
#define INI_ALLOW_INLINE_COMMENTS 1
|
||||
# define INI_ALLOW_INLINE_COMMENTS 1
|
||||
#endif
|
||||
#ifndef INI_INLINE_COMMENT_PREFIXES
|
||||
#define INI_INLINE_COMMENT_PREFIXES ";"
|
||||
# define INI_INLINE_COMMENT_PREFIXES ";"
|
||||
#endif
|
||||
|
||||
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
|
||||
#ifndef INI_USE_STACK
|
||||
#define INI_USE_STACK 1
|
||||
# define INI_USE_STACK 1
|
||||
#endif
|
||||
|
||||
/* Maximum line length for any line in INI file (stack or heap). Note that
|
||||
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
|
||||
#ifndef INI_MAX_LINE
|
||||
#define INI_MAX_LINE 200
|
||||
# define INI_MAX_LINE 200
|
||||
#endif
|
||||
|
||||
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
|
||||
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
|
||||
zero. */
|
||||
#ifndef INI_ALLOW_REALLOC
|
||||
#define INI_ALLOW_REALLOC 0
|
||||
# define INI_ALLOW_REALLOC 0
|
||||
#endif
|
||||
|
||||
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
|
||||
is zero. */
|
||||
#ifndef INI_INITIAL_ALLOC
|
||||
#define INI_INITIAL_ALLOC 200
|
||||
# define INI_INITIAL_ALLOC 200
|
||||
#endif
|
||||
|
||||
/* Stop parsing on first error (default is to keep parsing). */
|
||||
#ifndef INI_STOP_ON_FIRST_ERROR
|
||||
#define INI_STOP_ON_FIRST_ERROR 0
|
||||
# define INI_STOP_ON_FIRST_ERROR 0
|
||||
#endif
|
||||
|
||||
/* Nonzero to call the handler at the start of each new section (with
|
||||
name and value NULL). Default is to only call the handler on
|
||||
each name=value pair. */
|
||||
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
|
||||
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
|
||||
# define INI_CALL_HANDLER_ON_NEW_SECTION 0
|
||||
#endif
|
||||
|
||||
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
|
||||
call the handler with value NULL in this case. Default is to treat
|
||||
no-value lines as an error. */
|
||||
#ifndef INI_ALLOW_NO_VALUE
|
||||
#define INI_ALLOW_NO_VALUE 0
|
||||
# define INI_ALLOW_NO_VALUE 0
|
||||
#endif
|
||||
|
||||
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
|
||||
@ -146,10 +144,9 @@ int ini_parse_string(const char* string, ini_handler handler, void* user);
|
||||
have the same signatures as malloc/free/realloc and behave in a similar
|
||||
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
|
||||
#ifndef INI_CUSTOM_ALLOCATOR
|
||||
#define INI_CUSTOM_ALLOCATOR 0
|
||||
# define INI_CUSTOM_ALLOCATOR 0
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,10 +1,10 @@
|
||||
#ifndef LAIKA_BOX_H
|
||||
#define LAIKA_BOX_H
|
||||
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "core/lvm.h"
|
||||
#include "laika.h"
|
||||
#include "lmem.h"
|
||||
#include "lsodium.h"
|
||||
#include "lvm.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
@ -14,8 +14,8 @@
|
||||
# define ENDVLA(var) ((void)0) /* no op */
|
||||
#endif
|
||||
|
||||
#define laikaM_malloc(sz) laikaM_realloc(NULL, sz)
|
||||
#define laikaM_free(buf) laikaM_realloc(buf, 0)
|
||||
#define laikaM_malloc(sz) laikaM_realloc(NULL, sz)
|
||||
#define laikaM_free(buf) laikaM_realloc(buf, 0)
|
||||
|
||||
/* ========================================[[ Vectors ]]======================================== */
|
||||
|
@ -9,8 +9,8 @@
|
||||
fit this specific use case.
|
||||
*/
|
||||
|
||||
#include "core/lerror.h"
|
||||
#include "laika.h"
|
||||
#include "lerror.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef LAIKA_PEER_H
|
||||
#define LAIKA_PEER_H
|
||||
|
||||
#include "core/lsodium.h"
|
||||
#include "laika.h"
|
||||
#include "lpacket.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsocket.h"
|
||||
#include "lsodium.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "net/lpolllist.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
typedef enum
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
#ifndef LAIKA_POLLLIST_H
|
||||
#define LAIKA_POLLLIST_H
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "core/hashmap.h"
|
||||
#include "core/lmem.h"
|
||||
#include "laika.h"
|
||||
#include "lmem.h"
|
||||
#include "lsocket.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
/* clang-format will change the order of the included windows headers, this BREAKS THINGS.
|
||||
for now, make clang ignore this section */
|
||||
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/* socket/winsock headers */
|
||||
@ -54,8 +54,8 @@ typedef void buffer_t;
|
||||
# define SOCKETERROR(x) (x == -1)
|
||||
#endif
|
||||
#include "laika.h"
|
||||
#include "lsodium.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
@ -79,7 +79,7 @@ struct sLaika_socket
|
||||
pollFailEvent onPollFail;
|
||||
pollEvent onPollIn;
|
||||
pollEvent onPollOut;
|
||||
void *uData; /* passed to onPollFail */
|
||||
void *uData; /* passed to onPollFail */
|
||||
laikaM_newVector(uint8_t, outBuf); /* raw data to be sent() */
|
||||
laikaM_newVector(uint8_t, inBuf); /* raw data we recv()'d */
|
||||
bool flipEndian;
|
File diff suppressed because it is too large
Load Diff
@ -12,59 +12,60 @@ https://github.com/benhoyt/inih
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "core/ini.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ini.h"
|
||||
|
||||
#if !INI_USE_STACK
|
||||
#if INI_CUSTOM_ALLOCATOR
|
||||
#include <stddef.h>
|
||||
void* ini_malloc(size_t size);
|
||||
void ini_free(void* ptr);
|
||||
void* ini_realloc(void* ptr, size_t size);
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define ini_malloc malloc
|
||||
#define ini_free free
|
||||
#define ini_realloc realloc
|
||||
#endif
|
||||
# if INI_CUSTOM_ALLOCATOR
|
||||
# include <stddef.h>
|
||||
void *ini_malloc(size_t size);
|
||||
void ini_free(void *ptr);
|
||||
void *ini_realloc(void *ptr, size_t size);
|
||||
# else
|
||||
# include <stdlib.h>
|
||||
# define ini_malloc malloc
|
||||
# define ini_free free
|
||||
# define ini_realloc realloc
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define MAX_SECTION 50
|
||||
#define MAX_NAME 50
|
||||
#define MAX_NAME 50
|
||||
|
||||
/* Used by ini_parse_string() to keep track of string parsing state. */
|
||||
typedef struct {
|
||||
const char* ptr;
|
||||
typedef struct
|
||||
{
|
||||
const char *ptr;
|
||||
size_t num_left;
|
||||
} ini_parse_string_ctx;
|
||||
|
||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||
static char* rstrip(char* s)
|
||||
static char *rstrip(char *s)
|
||||
{
|
||||
char* p = s + strlen(s);
|
||||
char *p = s + strlen(s);
|
||||
while (p > s && isspace((unsigned char)(*--p)))
|
||||
*p = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Return pointer to first non-whitespace char in given string. */
|
||||
static char* lskip(const char* s)
|
||||
static char *lskip(const char *s)
|
||||
{
|
||||
while (*s && isspace((unsigned char)(*s)))
|
||||
s++;
|
||||
return (char*)s;
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
/* Return pointer to first char (of chars) or inline comment in given string,
|
||||
or pointer to NUL at end of string if neither found. Inline comment must
|
||||
be prefixed by a whitespace character to register as a comment. */
|
||||
static char* find_chars_or_comment(const char* s, const char* chars)
|
||||
static char *find_chars_or_comment(const char *s, const char *chars)
|
||||
{
|
||||
#if INI_ALLOW_INLINE_COMMENTS
|
||||
int was_space = 0;
|
||||
@ -78,12 +79,12 @@ static char* find_chars_or_comment(const char* s, const char* chars)
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
return (char*)s;
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
/* Similar to strncpy, but ensures dest (size bytes) is
|
||||
NUL-terminated, and doesn't pad with NULs. */
|
||||
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||
static char *strncpy0(char *dest, const char *src, size_t size)
|
||||
{
|
||||
/* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
|
||||
size_t i;
|
||||
@ -94,42 +95,41 @@ static char* strncpy0(char* dest, const char* src, size_t size)
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
void* user)
|
||||
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user)
|
||||
{
|
||||
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||
#if INI_USE_STACK
|
||||
char line[INI_MAX_LINE];
|
||||
int max_line = INI_MAX_LINE;
|
||||
#else
|
||||
char* line;
|
||||
char *line;
|
||||
size_t max_line = INI_INITIAL_ALLOC;
|
||||
#endif
|
||||
#if INI_ALLOW_REALLOC && !INI_USE_STACK
|
||||
char* new_line;
|
||||
char *new_line;
|
||||
size_t offset;
|
||||
#endif
|
||||
char section[MAX_SECTION] = "";
|
||||
char prev_name[MAX_NAME] = "";
|
||||
|
||||
char* start;
|
||||
char* end;
|
||||
char* name;
|
||||
char* value;
|
||||
char *start;
|
||||
char *end;
|
||||
char *name;
|
||||
char *value;
|
||||
int lineno = 0;
|
||||
int error = 0;
|
||||
|
||||
#if !INI_USE_STACK
|
||||
line = (char*)ini_malloc(INI_INITIAL_ALLOC);
|
||||
line = (char *)ini_malloc(INI_INITIAL_ALLOC);
|
||||
if (!line) {
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if INI_HANDLER_LINENO
|
||||
#define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
|
||||
# define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
|
||||
#else
|
||||
#define HANDLER(u, s, n, v) handler(u, s, n, v)
|
||||
# define HANDLER(u, s, n, v) handler(u, s, n, v)
|
||||
#endif
|
||||
|
||||
/* Scan through stream line by line */
|
||||
@ -158,9 +158,8 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
|
||||
start = line;
|
||||
#if INI_ALLOW_BOM
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||
(unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
if (lineno == 1 && (unsigned char)start[0] == 0xEF && (unsigned char)start[1] == 0xBB &&
|
||||
(unsigned char)start[2] == 0xBF) {
|
||||
start += 3;
|
||||
}
|
||||
#endif
|
||||
@ -188,13 +187,11 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
if (!HANDLER(user, section, NULL, NULL) && !error)
|
||||
error = lineno;
|
||||
#endif
|
||||
}
|
||||
else if (!error) {
|
||||
} else if (!error) {
|
||||
/* No ']' found on section line */
|
||||
error = lineno;
|
||||
}
|
||||
}
|
||||
else if (*start) {
|
||||
} else if (*start) {
|
||||
/* Not a comment, must be a name[=:]value pair */
|
||||
end = find_chars_or_comment(start, "=:");
|
||||
if (*end == '=' || *end == ':') {
|
||||
@ -213,8 +210,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!HANDLER(user, section, name, value) && !error)
|
||||
error = lineno;
|
||||
}
|
||||
else if (!error) {
|
||||
} else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
#if INI_ALLOW_NO_VALUE
|
||||
*end = '\0';
|
||||
@ -241,15 +237,15 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_file(FILE* file, ini_handler handler, void* user)
|
||||
int ini_parse_file(FILE *file, ini_handler handler, void *user)
|
||||
{
|
||||
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse(const char* filename, ini_handler handler, void* user)
|
||||
int ini_parse(const char *filename, ini_handler handler, void *user)
|
||||
{
|
||||
FILE* file;
|
||||
FILE *file;
|
||||
int error;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
@ -262,11 +258,12 @@ int ini_parse(const char* filename, ini_handler handler, void* user)
|
||||
|
||||
/* An ini_reader function to read the next line from a string buffer. This
|
||||
is the fgets() equivalent used by ini_parse_string(). */
|
||||
static char* ini_reader_string(char* str, int num, void* stream) {
|
||||
ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream;
|
||||
const char* ctx_ptr = ctx->ptr;
|
||||
static char *ini_reader_string(char *str, int num, void *stream)
|
||||
{
|
||||
ini_parse_string_ctx *ctx = (ini_parse_string_ctx *)stream;
|
||||
const char *ctx_ptr = ctx->ptr;
|
||||
size_t ctx_num_left = ctx->num_left;
|
||||
char* strp = str;
|
||||
char *strp = str;
|
||||
char c;
|
||||
|
||||
if (ctx_num_left == 0 || num < 2)
|
||||
@ -288,11 +285,11 @@ static char* ini_reader_string(char* str, int num, void* stream) {
|
||||
}
|
||||
|
||||
/* See documentation in header file. */
|
||||
int ini_parse_string(const char* string, ini_handler handler, void* user) {
|
||||
int ini_parse_string(const char *string, ini_handler handler, void *user)
|
||||
{
|
||||
ini_parse_string_ctx ctx;
|
||||
|
||||
ctx.ptr = string;
|
||||
ctx.num_left = strlen(string);
|
||||
return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler,
|
||||
user);
|
||||
return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler, user);
|
||||
}
|
4
lib/src/core/lerror.c
Normal file
4
lib/src/core/lerror.c
Normal file
@ -0,0 +1,4 @@
|
||||
#include "core/lerror.h"
|
||||
|
||||
jmp_buf eLaika_errStack[LAIKA_MAXERRORS];
|
||||
int eLaika_errIndx = -1;
|
@ -1,6 +1,6 @@
|
||||
#include "lmem.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "core/lerror.h"
|
||||
|
||||
void *laikaM_realloc(void *buf, size_t sz)
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
#include "lsodium.h"
|
||||
#include "core/lsodium.h"
|
||||
|
||||
#include <string.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "ltask.h"
|
||||
#include "core/ltask.h"
|
||||
|
||||
#include "lmem.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
/* this is the only reason C11 support is needed, i cba to write windows/linux specific stuff to get
|
||||
the current time in ms also side note: microsoft? more like micropenis */
|
1
lib/src/core/lvm.c
Normal file
1
lib/src/core/lvm.c
Normal file
@ -0,0 +1 @@
|
||||
#include "core/lvm.h"
|
@ -1,4 +0,0 @@
|
||||
#include "lerror.h"
|
||||
|
||||
jmp_buf eLaika_errStack[LAIKA_MAXERRORS];
|
||||
int eLaika_errIndx = -1;
|
@ -1 +0,0 @@
|
||||
#include "lvm.h"
|
@ -1,4 +1,4 @@
|
||||
#include "lpacket.h"
|
||||
#include "net/lpacket.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
const char *laikaD_getPacketName(LAIKAPKT_ID id)
|
@ -1,7 +1,7 @@
|
||||
#include "lpeer.h"
|
||||
#include "net/lpeer.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
struct sLaika_peer *laikaS_newPeer(struct sLaika_peerPacketInfo *pktTbl,
|
||||
struct sLaika_pollList *pList, pollFailEvent onPollFail,
|
@ -1,7 +1,7 @@
|
||||
#include "lpolllist.h"
|
||||
#include "net/lpolllist.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
|
||||
/* ===================================[[ Helper Functions ]]==================================== */
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "lsocket.h"
|
||||
#include "net/lsocket.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lpacket.h"
|
||||
#include "lpolllist.h"
|
||||
#include "lsodium.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "net/lpolllist.h"
|
||||
|
||||
static int _LNSetup = 0;
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef SHELLCLIENT_H
|
||||
#define SHELLCLIENT_H
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "lmem.h"
|
||||
#include "lpeer.h"
|
||||
#include "lsodium.h"
|
||||
#include "ltask.h"
|
||||
#include "core/hashmap.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "core/ltask.h"
|
||||
#include "net/lpeer.h"
|
||||
#include "speer.h"
|
||||
|
||||
typedef struct sShell_client
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef SHELLPEER_H
|
||||
#define SHELLPEER_H
|
||||
|
||||
#include "lpeer.h"
|
||||
#include "lsodium.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "net/lpeer.h"
|
||||
|
||||
typedef struct sShell_peer
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "ini.h"
|
||||
#include "core/ini.h"
|
||||
#include "sclient.h"
|
||||
#include "sterm.h"
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "sclient.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "lpacket.h"
|
||||
#include "lsodium.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "core/lsodium.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "sterm.h"
|
||||
|
||||
void shell_pingTask(struct sLaika_taskService *service, struct sLaika_task *task, clock_t currTick,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "scmd.h"
|
||||
|
||||
#include "lerror.h"
|
||||
#include "lmem.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lmem.h"
|
||||
#include "sclient.h"
|
||||
#include "speer.h"
|
||||
#include "sterm.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "speer.h"
|
||||
|
||||
#include "lmem.h"
|
||||
#include "lpacket.h"
|
||||
#include "core/lmem.h"
|
||||
#include "net/lpacket.h"
|
||||
#include "sterm.h"
|
||||
|
||||
tShell_peer *shellP_newPeer(PEERTYPE type, OSTYPE osType, uint8_t *pubKey, char *hostname,
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "sterm.h"
|
||||
|
||||
#include "lmem.h"
|
||||
#include "core/lmem.h"
|
||||
#include "scmd.h"
|
||||
|
||||
#define KEY_ESCAPE 0x001b
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "lerror.h"
|
||||
#include "lsodium.h"
|
||||
#include "core/lerror.h"
|
||||
#include "core/lsodium.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "lbox.h"
|
||||
#include "lvm.h"
|
||||
#include "core/lbox.h"
|
||||
#include "core/lvm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
Loading…
Reference in New Issue
Block a user