summaryrefslogtreecommitdiff
path: root/src/core/include
diff options
context:
space:
mode:
authorsss <sss@dark-alexandr.net>2023-01-17 00:38:19 +0300
committersss <sss@dark-alexandr.net>2023-01-17 00:38:19 +0300
commitcc3f33db7a8d3c4ad373e646b199808e01bc5d9b (patch)
treeec09d690c7656ab5f2cc72607e05fb359c24d8b2 /src/core/include
added webrdp public code
Diffstat (limited to 'src/core/include')
l---------src/core/include/.clang-format1
-rw-r--r--src/core/include/webrdp_api_shared_structures.h222
-rw-r--r--src/core/include/webrdp_api_utils.h43
-rw-r--r--src/core/include/webrdp_core_api.h185
-rw-r--r--src/core/include/webrdp_module_api.h109
5 files changed, 560 insertions, 0 deletions
diff --git a/src/core/include/.clang-format b/src/core/include/.clang-format
new file mode 120000
index 0000000..3260daf
--- /dev/null
+++ b/src/core/include/.clang-format
@@ -0,0 +1 @@
+../../../.clang-format \ No newline at end of file
diff --git a/src/core/include/webrdp_api_shared_structures.h b/src/core/include/webrdp_api_shared_structures.h
new file mode 100644
index 0000000..c5ffbef
--- /dev/null
+++ b/src/core/include/webrdp_api_shared_structures.h
@@ -0,0 +1,222 @@
+#pragma once
+
+/* generic structures */
+
+typedef struct
+{
+ char *name, *value;
+} backend_setting_str;
+
+typedef struct
+{
+ char *name;
+ int64_t value;
+} backend_setting_int;
+
+typedef enum
+{
+ ws_keycomb_ctrlaltdel_press,
+ ws_keycomb_alttab_press,
+ ws_keycomb_alttab_release,
+ ws_keycomb_unused
+} ws_input_keycomb;
+
+/* user input structures */
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t x, y, flags;
+} ws_input_mouse;
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t code;
+ bool down;
+} ws_input_kupdown;
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t code, shiftstate;
+} ws_input_kpress;
+
+typedef struct __attribute__((__packed__))
+{
+ const uint32_t *input;
+ size_t length;
+} ws_input_unicode;
+
+/* display output structures */
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t x; /* Destination X */
+ uint32_t y; /* Destination Y */
+ uint32_t width; /* Width */
+ uint32_t height; /* Height */
+ uint32_t dest_width; /* Destination Width */
+ uint32_t dest_height; /* Destination Height */
+ uint32_t bpp; /* Bits per Pixel */
+ uint32_t compressed; /* Flag: Compressed */
+ uint32_t size; /* DataSize */
+} wrdp_core_display_bmp;
+
+typedef struct __attribute__((__packed__))
+{
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+} wrdp_core_display_bounds;
+
+typedef struct __attribute__((__packed__))
+{
+ int32_t nLeftRect;
+ int32_t nTopRect;
+ int32_t nWidth;
+ int32_t nHeight;
+ uint32_t color;
+} wrdp_core_display_opaque_rect_order;
+
+typedef struct __attribute__((__packed__))
+{
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ uint32_t fg;
+ uint32_t rop;
+} wrdp_core_display_patblt_order;
+
+typedef struct __attribute__((__packed__))
+{
+ int32_t left;
+ int32_t top;
+ int32_t width;
+ int32_t height;
+} wrdp_core_display_delta_rect;
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t color;
+ uint32_t num_rect;
+ wrdp_core_display_delta_rect *rects;
+} wrdp_core_display_m_opaque_rect;
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t rop;
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+ int32_t sx;
+ int32_t sy;
+} wrdp_core_display_scr_blt;
+
+typedef struct __attribute__((__packed__))
+{
+ uint8_t resL; /* 2 bytes reserved must always be 0 */
+ uint8_t resH;
+ uint8_t imgTypeL; /* 2 bytes image type. 1 = ICO, 2 = CUR */
+ uint8_t imgTypeH;
+ uint8_t nbImgL; /* 2 bytes number of images */
+ uint8_t nbImgH;
+ uint8_t width; /* 1 byte image width in pixels */
+ uint8_t height; /* 1 byte image height in pixels */
+ uint8_t nbColors; /* 1 bytenumber of colors. 0 if not using a color
+ pallete */
+ uint8_t res; /* 1 byte reserved, should be 0 */
+ uint8_t
+ xPosL; /* 2 bytes of hot spot x (for ICO, color planes, 0 or 1) */
+ uint8_t xPosH;
+ uint8_t yPosL; /* 2 bytes of hot spot y (for ICO bits per pixel) */
+ uint8_t yPosH;
+ uint8_t sizeLL; /* 4 bytes of image size */
+ uint8_t sizeLH;
+ uint8_t sizeHL;
+ uint8_t sizeHH;
+ uint8_t offsetLL; /* 4 bytes of offset of the data */
+ uint8_t offsetLH;
+ uint8_t offsetHL;
+ uint8_t offsetHH;
+ uint8_t *data;
+} wrdp_core_display_cursor;
+
+typedef struct
+{
+ uint32_t id;
+ uint32_t hx;
+ uint32_t hy;
+ uint32_t data_size;
+ wrdp_core_display_cursor *cur;
+} wrdp_core_display_cursor_info;
+
+/* clipboard structures */
+
+typedef enum
+{
+ clip_format_unsupported = -1,
+ clip_format_raw,
+ clip_format_text,
+ clip_format_unicode,
+ clip_format_file_list
+} wrdp_enum_clip_format;
+
+typedef struct __attribute__((__packed__))
+{
+ /* DRAFT! */
+ wrdp_enum_clip_format format;
+} wrdp_backend_clipbrd_data_request;
+
+typedef struct __attribute__((__packed__))
+{
+ /* DRAFT! */
+ uint8_t count, *formats;
+} wrdp_backend_clipbrd_fmts;
+
+typedef struct __attribute__((__packed__))
+{
+ /* DRAFT! */
+ /* TODO: */
+ uint32_t size;
+ uint8_t *data;
+} wrdp_backend_clipbrd_data;
+
+/* filetransfer structures */
+
+typedef struct __attribute__((__packed__))
+{
+ uint16_t filename_len;
+ uint32_t file_id;
+ uint64_t file_size;
+} wrdp_backend_ft_list_entry;
+
+typedef struct __attribute__((__packed__))
+{
+ uint32_t file_id;
+ uint64_t req_size;
+ uint64_t file_offset;
+} wrdp_backend_ft_file_request;
+
+typedef enum
+{
+ ft_status_success = 0,
+ ft_status_failure,
+ ft_status_already_runing
+} wrdp_backend_enum_ft_init_status;
+
+typedef struct __attribute__((__packed__))
+{
+ /* DRAFT! */
+ /* TODO: */
+ uint32_t file_id, transfer_id;
+ uint8_t status;
+} wrdp_backend_ft_status;
+
+typedef struct __attribute__((__packed__))
+{
+ /* DRAFT! */
+ /* TODO: */
+ uint32_t transfer_id;
+ uint32_t size;
+} wrdp_backend_ft_chunk;
diff --git a/src/core/include/webrdp_api_utils.h b/src/core/include/webrdp_api_utils.h
new file mode 100644
index 0000000..170ca2b
--- /dev/null
+++ b/src/core/include/webrdp_api_utils.h
@@ -0,0 +1,43 @@
+#pragma once
+
+typedef enum
+{
+ wrdp_log_level_error,
+ wrdp_log_level_warning,
+ wrdp_log_level_info,
+ wrdp_log_level_debug,
+ wrdp_log_level_trace
+} wrdp_log_level_e;
+
+static const uint16_t wrdp_log_flag_binary = 0x0001;
+
+typedef struct _log_msg_info
+{
+ /* message buffer:
+ * containing message which will be displayed
+ *
+ * mandatory parameter */
+ const uint8_t *buf;
+
+ /* message size:
+ * size of message in buiffer which must be displayed
+ *
+ * optional in case of null terminated string, mandatory otherwise */
+ size_t buf_size;
+
+ /* log level for this message
+ *
+ * optional, default is 'wrdp_log_level_error' */
+ wrdp_log_level_e level;
+
+ /* message flags:
+ * currently supported flags is:
+ * 'wrdp_log_flag_binary': print message as hex data
+ * optional, default is plain text */
+ uint16_t flags;
+
+ /* pointers to various data structures which may be usefule
+ * during debugging
+ * optional */
+ void *task_info, *wrdp_thpool_task, *ws_session;
+} log_msg_info;
diff --git a/src/core/include/webrdp_core_api.h b/src/core/include/webrdp_core_api.h
new file mode 100644
index 0000000..36ef948
--- /dev/null
+++ b/src/core/include/webrdp_core_api.h
@@ -0,0 +1,185 @@
+#pragma once
+/* API functions exported by core which can be used in backend modules will
+ * be defined here.
+ */
+
+#include "webrdp_api_shared_structures.h"
+#include "webrdp_api_utils.h"
+
+typedef struct
+{
+ /* Send text message */
+ void (*send_text_msg)(const char *msg, void *task_info);
+
+ /* Send text info message */
+ void (*send_text_info_msg)(const char *msg, void *task_info);
+
+ /* Send text warning message */
+ void (*send_text_warning_msg)(const char *msg, void *task_info);
+
+ /* Send text debug message */
+ void (*send_text_debug_msg)(const char *msg, void *task_info);
+
+ /* Send error message, this also causing disconnect
+ * TODO: do not send termination message on errors, use this instead
+ * OR disable automatic disconnect on errors
+ */
+ void (*send_error_msg)(const char *msg, void *task_info);
+
+ /* Send control message to js client
+ * TODO: do we need to provide it for backend modules ?
+ */
+ void (*send_ctl_msg)(const char *msg, void *task_info);
+
+ /* Send session termination message on quit */
+ void (*send_termination_msg)(void *task_info);
+} wrdp_core_cb_msgs;
+
+typedef struct
+{
+ void (*send_begin_paint)(void *task_info);
+ void (*send_end_paint)(void *task_info);
+
+ /* Single bitmap */
+ void (*send_bitmap)(const wrdp_core_display_bmp *bmp, uint8_t *bmp_data,
+ void *task_info);
+
+ /* Primary: OPAQUE_RECT_ORDER */
+ void (*send_opaque_rect_order)(
+ const wrdp_core_display_opaque_rect_order *oro, void *task_info);
+
+ /* SetBounds */
+ void (*send_set_bounds)(
+ const wrdp_core_display_bounds *bounds, void *task_info);
+
+ /* PatBlt */
+ void (*send_pat_blt)(
+ const wrdp_core_display_patblt_order *patblt, void *task_info);
+
+ /* Multi Opaque rect */
+ void (*send_multi_opaque_rect)(
+ const wrdp_core_display_m_opaque_rect *mrect, void *task_info);
+
+ /* ScrBlt */
+ void (*send_scr_blt)(
+ const wrdp_core_display_scr_blt *scr_blt, void *task_info);
+
+ /* PTR_NEW
+ * uint32_t id, xhot, yhot
+ */
+ void (*send_ptr_new)(
+ const wrdp_core_display_cursor_info *ptr, void *task_info);
+
+ /* PTR_FREE
+ * uint32_t id
+ */
+ void (*send_ptr_free)(uint32_t ptr_id, void *task_info);
+
+ /* PTR_SET
+ * uint32_t id
+ */
+ void (*send_ptr_set)(uint32_t ptr_id, void *task_info);
+
+ /* PTR_SETNULL
+ */
+ void (*send_ptr_set_null)(void *task_info);
+
+ /* PTR_SETDEFAULT
+ */
+ void (*send_ptr_set_default)(void *task_info);
+
+} wrdp_core_cb_paint;
+
+typedef struct
+{
+ /* DRAFT! */
+ /* TODO: */
+
+ /*
+ * uint8_t* wrdp_enum_clip_format array
+ */
+ void (*clipboard_changed)(
+ uint8_t *fmts, size_t fmts_count, void *task_info);
+
+ /*
+ * clipboard data array
+ */
+ void (*send_data)(uint8_t *buf, size_t buf_size, void *task_info);
+
+ /*
+ * request clipboard data from client
+ */
+ void (*request_data)(uint8_t data_fmt, void *task_info);
+
+} wrdp_core_cb_clipboard;
+
+typedef struct
+{
+ /* DRAFT! */
+
+ /*
+ * TODO:
+ */
+
+ void (*ft_request)(
+ const wrdp_backend_ft_file_request *req, void *task_info);
+
+ /*
+ * TODO:
+ */
+ void (*ft_send_chunk)(
+ const wrdp_backend_ft_chunk *chunk, uint8_t *data, void *task_info);
+
+ /*
+ * TODO:
+ */
+ void (*ft_finish)(
+ const wrdp_backend_ft_status *status, void *task_info);
+
+} wrdp_core_cb_filetransfer;
+
+typedef struct
+{
+ /* access to variables allocated by core: */
+
+ /* get libev ev_loop* for calling thread */
+ void *(*get_libev_loop)(void *task_info);
+
+ /* task runtime state functions: */
+
+ /* inform core about task is finished */
+ void (*task_finished)(bool success, void *task_info);
+
+ /* reset task idle time to 0 */
+ void (*reset_idle)();
+} wrdp_core_cb_core;
+
+typedef struct
+{
+ /* print raw data buffer to stdout */
+ void (*hex_print)(const uint8_t *buf, size_t buf_len);
+
+ /* print log message, currently only stdout is supported */
+ void (*log_msg)(const uint8_t *buf, size_t buf_len,
+ wrdp_log_level_e type, uint16_t flags);
+ /* print log message extended, currently only stdout is supported */
+ void (*log_msg_ex)(log_msg_info *i);
+} wrdp_core_cb_utils;
+
+typedef struct
+{
+ /* client<>server protocol functions: */
+ wrdp_core_cb_msgs *api_msgs;
+
+ /* Painting functions: */
+ wrdp_core_cb_paint *api_paint;
+
+ wrdp_core_cb_core *api_core;
+
+ wrdp_core_cb_clipboard *api_clipboard;
+
+ wrdp_core_cb_filetransfer *api_filetransfers;
+
+ wrdp_core_cb_utils *api_utils;
+
+} wrdp_core_exports;
diff --git a/src/core/include/webrdp_module_api.h b/src/core/include/webrdp_module_api.h
new file mode 100644
index 0000000..7f2d635
--- /dev/null
+++ b/src/core/include/webrdp_module_api.h
@@ -0,0 +1,109 @@
+#pragma once
+
+/* Short api usage brief...
+ * each backend module must export:
+ * 1. bool <backend_name>_create(wrdp_core_exports*, wrdp_backend_module*)
+ * which initialize passed wrdp_backend_module* instance
+ * with all required callbacks.
+ * wrdp_core_exports* ptr should be stored by backend,
+ * for example in "internals" structure.
+ * return "true" on success
+ */
+
+#include <stdint.h>
+
+#include "webrdp_api_shared_structures.h"
+
+//#include "webrdp_core_api.h"
+
+/* API used by backend modules defined here */
+
+typedef struct
+{
+ /* Init function exported by backend, this function should fully
+ * initialize backend.
+ * retrun false on failure
+ * required. */
+ bool (*init)(void *backend_internals);
+
+ /* Destroy backend function should deinitialize backend
+ * and free used memory
+ * required. */
+ void (*destroy)(void *backend_internals);
+
+ /* Pass task_info internal structure ptr to the backend.
+ * must be stored and suplied to core on need
+ * required. */
+ void (*set_task_info)(void *task_info, void *internals);
+
+ /* Backend settings related functions
+ * return false on failure.
+ * required. */
+ bool (*set_setting_str)(backend_setting_str *setting, void *internals);
+ bool (*set_setting_int)(backend_setting_int *setting, void *internals);
+} wrdp_backend_cb_module;
+
+typedef struct
+{
+ /* Backend ws-protocol handlers callbacks
+ * return false on failure
+ * at least one of the following is required*/
+ bool (*mouse)(ws_input_mouse input, void *internals);
+ bool (*kupdown)(ws_input_kupdown input, void *internals);
+ bool (*kpress)(ws_input_kpress input, void *internals);
+ bool (*kcomb)(ws_input_keycomb input, void *internals);
+ bool (*unicode)(ws_input_unicode input, void *internals);
+} wrdp_backend_cb_input;
+
+typedef struct
+{
+ /* DRAFT! */
+ /* TODO: */
+
+ bool (*request_data)(
+ const wrdp_backend_clipbrd_data_request *, void *backend_internals);
+ bool (*data_changed)(
+ const wrdp_backend_clipbrd_fmts *, void *backend_internals);
+ bool (*send_data)(
+ const wrdp_backend_clipbrd_data *, void *backend_internals);
+
+} wrdp_backend_cb_clipboard;
+
+typedef struct
+{
+ /* DRAFT! */
+ /* TODO: */
+
+ bool (*request)(
+ const wrdp_backend_ft_file_request *, void *backend_internals);
+ bool (*chunk)(const wrdp_backend_ft_chunk *, const uint8_t *data,
+ void *backend_internals);
+ bool (*finish)(const wrdp_backend_ft_status *, void *backend_internals);
+} wrdp_backend_cb_filetransfer;
+
+typedef struct
+{
+
+ /* Backend internal data, does not touched by core. */
+ void *backend_internals;
+
+ /* pointer to wrdp_thpool_task* used by some internals */
+ void *wrdp_thpool_task;
+
+ /* Variable indicate what task destruction is in progress,
+ * task should not use any of core exports anymore */
+ bool stopped;
+
+ /* Information about task used by core,
+ * must be passed to functions which require it */
+ void *task_info;
+
+ /* ws_session list */
+ void *sessions_list_head;
+
+ wrdp_backend_cb_module *callbacks_module;
+ wrdp_backend_cb_input *callbacks_input;
+ wrdp_backend_cb_clipboard *callbacks_clipbrd;
+ wrdp_backend_cb_filetransfer *callbacks_ft;
+
+} wrdp_backend_module;