commit 1e8413b2675132122779e77caf57e80929ff500f
parent 6e58fb19843fbba2125cc6f05be69aa6143ee56d
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Sun, 14 Sep 2014 12:17:28 +0200
Removed link and moved includes into subdirectory EGong instead.
Diffstat:
47 files changed, 650 insertions(+), 652 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,3 @@
build/
*.o
-include/Util/Config_Compiletime.h
+include/EGong/Util/Config_Compiletime.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -30,8 +30,8 @@ set(EGONG_DATADIR data/)
set(EGONG_EXT_LIBS)
include_directories("${PROJECT_SOURCE_DIR}/include")
configure_file(
- "${PROJECT_SOURCE_DIR}/include/Util/Config_Compiletime.h.in"
- "${PROJECT_SOURCE_DIR}/include/Util/Config_Compiletime.h"
+ "${PROJECT_SOURCE_DIR}/include/EGong/Util/Config_Compiletime.h.in"
+ "${PROJECT_SOURCE_DIR}/include/EGong/Util/Config_Compiletime.h"
)
set(CMAKE_CFLAGS, ${CMAKE_CFLAGS} -std=gnu99)
if(CMAKE_FIND_ROOT_PATH)
diff --git a/include/CNC.h b/include/CNC.h
@@ -1,8 +0,0 @@
-#pragma once
-#include <EGong/Util/Misc.h>
-extern int EGong_cnc_sendmessage(const String *msg, const char *dest);
-extern int EGong_cnc_getmessage(String *msg);
-extern void EGong_cnc_freemessage(String *msg);
-extern void EGong_cnc_deinit(void);
-extern int EGong_cnc_sendmessage_broad(const String *msg);
-
diff --git a/include/EGong b/include/EGong
@@ -1 +0,0 @@
-./-
\ No newline at end of file
diff --git a/include/EGong/CNC.h b/include/EGong/CNC.h
@@ -0,0 +1,8 @@
+#pragma once
+#include <EGong/Util/Misc.h>
+extern int EGong_cnc_sendmessage(const String *msg, const char *dest);
+extern int EGong_cnc_getmessage(String *msg);
+extern void EGong_cnc_freemessage(String *msg);
+extern void EGong_cnc_deinit(void);
+extern int EGong_cnc_sendmessage_broad(const String *msg);
+
diff --git a/include/EGong/Interfaces.h b/include/EGong/Interfaces.h
@@ -0,0 +1,67 @@
+#pragma once
+#include <EGong/CNC.h>
+#include <EGong/Util/Misc.h>
+
+
+enum EGONG_INTERFACE_STATE{
+ EGONG_INTERFACE_ACTIVE=(1<<0),
+ EGONG_INTERFACE_SETUP=(1<<1)
+};
+struct EGong_interface;
+struct EGong_if_ptrtbl{
+ int (*setup) (struct EGong_interface *interface);
+ int (*cmd) (char *msg);
+ int (*cycle) (struct EGong_interface *interface, String *msg, char **dest);
+ int (*display) (struct EGong_interface *interface, const String *msg);
+ int (*shutdown) (struct EGong_interface *interface);
+
+ int(*sock_watch)(int socket, unsigned short int type);
+ int(*loop)(void);
+};
+struct EGong_interface{
+ char *name;
+ char identifier;
+ unsigned int requirements;
+ unsigned short int state;
+ struct EGong_if_ptrtbl *funcs;
+};
+extern unsigned short int EGong_interfaces_userstreams;
+extern int EGong_interface_init(unsigned int requirement_mask);
+extern int EGong_interface_cycle(void);
+extern int EGong_interface_deinit(void);
+extern struct EGong_interface EGong_interfaces[];
+extern int EGong_interface_setup(struct EGong_interface *interface);
+extern int EGong_interface_activate(struct EGong_interface *interface);
+extern int EGong_interface_shutdown(struct EGong_interface *interface);
+extern int EGong_interface_deactivate(struct EGong_interface *interface);
+extern struct EGong_interface *EGong_interface_get_from_id(char identifier);
+#define IF_ACTIVE(INTERFACE) (((INTERFACE).state&EGONG_INTERFACE_ACTIVE)>0)
+#define IF_SETUP(INTERFACE) (((INTERFACE).state&EGONG_INTERFACE_SETUP)>0)
+#define IF_CAN_SHUTDOWN(INTERFACE) ((INTERFACE).funcs->shutdown!=NULL)
+#define IF_CAN_CYCLE(INTERFACE) ((INTERFACE).funcs->cycle!=NULL)
+#define IF_CAN_DISPLAY(INTERFACE) ((INTERFACE).funcs->display!=NULL)
+#define IF_CAN_SETUP(INTERFACE) ((INTERFACE).funcs->setup!=NULL)
+#define IF_TRY_SETUP(INTERFACE) ((IF_SETUP(INTERFACE)&&IF_CAN_SETUP(INTERFACE)) ? (INTERFACE).funcs->setup(&INTERFACE) : EGONG_INTERFACE_RETURN_OK)
+#define EGONG_INTERFACE_INTERPRET_RET(RET, INTERFACE)\
+if(RET==EGONG_INTERFACE_RETURN_FATAL){\
+ do_log("Couldn't run interface function, exiting", LOG_TYPE_NORMAL, LOG_LEVEL_FATAL);\
+ return -1;\
+}\
+else if(RET==EGONG_INTERFACE_RETURN_ERROR){\
+ do_log("Couldn't run interface function, skipping", LOG_TYPE_NORMAL, LOG_LEVEL_WARNING);\
+}\
+else if(RET==EGONG_INTERFACE_RETURN_EXIT){\
+ do_log_call_composite(LOG_COMPOSE_SRC, LOG_TYPE_NORMAL, LOG_LEVEL_INFO, EGong_global_configuration.log.destinations, "Interface ", (INTERFACE).name, " requested exit", NULL);\
+ return 1;\
+}\
+else if(RET==EGONG_INTERFACE_RETURN_BREAK){\
+ do_log("Interface function requested queueabortion", LOG_TYPE_NORMAL, LOG_LEVEL_INFO);\
+ break;\
+}
+enum EGONG_INTERFACE_RETURN{
+ EGONG_INTERFACE_RETURN_FATAL=-2,
+ EGONG_INTERFACE_RETURN_ERROR=-1,
+ EGONG_INTERFACE_RETURN_OK=0,
+ EGONG_INTERFACE_RETURN_EXIT=1,
+ EGONG_INTERFACE_RETURN_BREAK=2
+};
diff --git a/include/EGong/Interfaces/Audio.h b/include/EGong/Interfaces/Audio.h
@@ -0,0 +1,6 @@
+#pragma once
+
+
+int EGong_if_audio_setup(struct EGong_interface *interface);
+int EGong_if_audio_display(struct EGong_interface *interface, const String *msg);
+int EGong_if_audio_shutdown(struct EGong_interface *interface);
diff --git a/include/EGong/Interfaces/CMD.h b/include/EGong/Interfaces/CMD.h
@@ -0,0 +1,26 @@
+#pragma once
+#include <EGong/Util/Command.h>
+#include <EGong/Interfaces.h>
+
+
+enum EGONG_IF_CMD_EXEC{
+ EGONG_IF_CMD_SETUP=(1<<0),
+ EGONG_IF_CMD_CYCLE=(1<<1),
+ EGONG_IF_CMD_SHUTDOWN=(1<<2)
+};
+
+struct EGong_command_if_cmd{
+ struct EGong_command command;
+ unsigned int execute;
+};
+
+extern int EGong_if_cmd_interfaceselect(const char *data);
+extern struct EGong_command_if_cmd *EGong_if_cmd_get_from_char(const char *commandline);
+extern int EGong_if_cmd_exec(unsigned int execution, struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_cmd_setup(struct EGong_interface *interface);
+extern int EGong_if_cmd_cycle(struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_cmd_shutdown(struct EGong_interface *interface);
+
+extern int EGong_if_cmd_gui_msg(void);
+extern int EGong_if_cmd_send_message(char *msg);
+extern int EGong_if_cmd_help(void);
diff --git a/include/EGong/Interfaces/GTK.h b/include/EGong/Interfaces/GTK.h
@@ -0,0 +1,25 @@
+#pragma once
+#include <EGong/Interfaces.h>
+#include <EGong/Interfaces/GUI.h>
+#include <gtk/gtk.h>
+
+extern GtkWidget *Egong_if_gtk_root;
+extern int EGong_if_gtk_int_setup(unsigned int what);
+
+extern int EGong_if_gtk_setup(struct EGong_interface *interface);
+extern int EGong_if_gtk_cycle(struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_gtk_display(struct EGong_interface *interface, const String *msg);
+extern int EGong_if_gtk_shutdown(struct EGong_interface *interface);
+extern GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
+extern void *EGong_gtk_get_item_value(struct EGong_GUI_item *itm);
+extern int EGong_gtk_waiter_add(int sock, unsigned short int type);
+extern void EGong_if_gtk_show_element(struct EGong_GUI_item *itm);
+extern void EGong_if_gtk_free_item_value(struct EGong_GUI_item *itm, void *element);
+extern int EGong_if_gtk_main(void);
+
+extern struct EGong_if_ptrtbl EGong_if_gtk_ptrtbl;
+enum EGONG_IF_GTK_INIT{
+ EGONG_IF_GTK_INIT_ROOT=(1<<0),
+ EGONG_IF_GTK_INIT_TRAY=(1<<1),
+ EGONG_IF_GTK_INIT_ALL=(~0)
+};
diff --git a/include/EGong/Interfaces/GUI.h b/include/EGong/Interfaces/GUI.h
@@ -0,0 +1,111 @@
+#pragma once
+
+#include <EGong/Util/Command.h>
+#include <EGong/Util/Config_Compiletime.h>
+#include <EGong/Interfaces.h>
+
+#ifdef USE_WINGUI
+typedef wchar_t guichar;
+#define GUIT(TEXT) L##TEXT
+#else
+typedef char guichar;
+#define GUIT(TEXT) TEXT
+#endif
+
+enum EGONG_GUI_TYPE{
+ EGONG_GUI_TYPE_NONE,
+ EGONG_GUI_TYPE_GTK,
+ EGONG_GUI_TYPE_WINGUI,
+};
+enum EGONG_GUI_EVSRC{
+ EGONG_GUI_EVSRC_ELEMENT,
+ EGONG_GUI_EVSRC_STATIC,
+};
+enum EGONG_GUI_MENUITEM_IMAGES{
+ EGUI_MIMG_EXIT,
+};
+enum EGONG_GUI_ITEM{
+ EGONG_GUI_WINDOW,
+ EGONG_GUI_BUTTON,
+ EGONG_GUI_LABEL,
+ EGONG_GUI_TEXT,
+ EGONG_GUI_MENU,
+ EGONG_GUI_MENUITEM,
+ EGONG_GUI_MENUITEM_IMAGE,
+ EGONG_GUI_MENUITEM_SEPARATOR,
+ EGONG_GUI_SYSTRAY,
+ EGONG_GUI_HBOX,
+ EGONG_GUI_VBOX,
+ EGONG_GUI_DIALOG,
+};
+struct EGong_GUI_item{
+ unsigned short int type;
+ guichar *text;
+ guichar *tooltip;
+ void *extra;
+ void *itemptr;
+ void *userdata;
+ struct EGong_GUI_item **child;
+ struct EGong_GUI_event **events;
+};
+
+struct EGong_GUI_event_source{
+ unsigned int type;
+ void *data;
+};
+struct EGong_GUI_event{
+ guichar *type;
+ struct EGong_command command;
+ struct EGong_GUI_event_source **sources;
+};
+extern void EGong_GUI_event_hide(void *gui_element);
+extern void *EGong_GUI_create(struct EGong_GUI_item *gui);
+extern void EGong_GUI_event_callback(struct EGong_GUI_event *event);
+extern int EGong_GUI_exit(void);
+
+#ifdef USE_GTK
+static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_GTK;
+#else
+#ifdef USE_WINGUI
+static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_WINGUI;
+#else
+static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_NONE;
+#endif
+#endif
+
+#define EGUI_ARR (struct EGong_GUI_item **)&(struct EGong_GUI_item *[])
+#define EGUI_EL &(struct EGong_GUI_item)
+#define EGUI_ELX(ELEMENT) (struct EGong_GUI_item*)&ELEMENT
+#define EGUI_FIN (struct EGong_GUI_item*)NULL
+
+#define EEV_ARR (struct EGong_GUI_event **)&(struct EGong_GUI_event *[])
+#define EEV_EL &(struct EGong_GUI_event)
+#define EEV_ELX(ELEMENT) (struct EGong_GUI_event*)&ELEMENT
+#define EEV_FIN (struct EGong_GUI_event*)NULL
+
+#define EES_ARR (struct EGong_GUI_event_source **)&(struct EGong_GUI_event_source *[])
+#define EES_EL &(struct EGong_GUI_event_source)
+#define EES_ELX(ELEMENT) (struct EGong_GUI_event_source*)&ELEMENT
+#define EES_FIN (struct EGong_GUI_event_source*)NULL
+
+struct EGong_if_gui_ptrtbl{
+ struct EGong_if_ptrtbl *ifptrtbl;
+ void *(*create)(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
+ void *(*get_value)(struct EGong_GUI_item *itm);
+ void (*free_value)(struct EGong_GUI_item *itm, void *value);
+ void (*show)(struct EGong_GUI_item *itm);
+};
+
+extern int EGong_if_gui_setup(struct EGong_interface *interface);
+extern int EGong_if_gui_cmd(char *msg);
+extern int EGong_if_gui_cycle(struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_gui_display(struct EGong_interface *interface, const String *msg);
+extern int EGong_if_gui_shutdown(struct EGong_interface *interface);
+extern int EGong_if_gui_sockwatch(int sock, unsigned short int type);
+extern int EGong_if_gui_loop(void);
+
+
+extern char *EGong_GUI_item_names[];
+
+extern struct EGong_GUI_item EGong_GUI_newmessage;
+extern struct EGong_GUI_item EGong_GUI_systray;
diff --git a/include/EGong/Interfaces/STDIO.h b/include/EGong/Interfaces/STDIO.h
@@ -0,0 +1,7 @@
+#pragma once
+#include <EGong/Interfaces.h>
+
+
+extern int EGong_if_stdio_setup(struct EGong_interface *interface);
+extern int EGong_if_stdio_cycle(struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_stdio_display(struct EGong_interface *interface, const String *msg);
diff --git a/include/EGong/Interfaces/Windows.h b/include/EGong/Interfaces/Windows.h
@@ -0,0 +1,35 @@
+#pragma once
+#define UNICODE
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <EGong/Interfaces.h>
+#include <EGong/Interfaces/GUI.h>
+#include <EGong/Util/Misc.h>
+
+#define WM_TRAY_ACTION WM_USER+1
+#define WM_SOCKET WM_USER+2
+
+extern struct EGong_if_ptrtbl EGong_if_win_ptrtbl;
+extern WNDCLASSW EGong_if_win_getmsg;
+extern HWND EGong_if_win_getmsg_editfield;
+extern struct EGong_GUI_item *EGong_if_win_global_systray;
+extern struct Array EGong_if_win_menus;
+extern struct Array EGong_if_win_windows;
+extern HWND EGong_if_win_create_wrapper(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
+extern HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *this, unsigned int child);
+extern void EGong_if_win_show_element(struct EGong_GUI_item *itm);
+extern void EGong_if_win_show_item(HWND item);
+extern void EGong_if_win_free_item_value(struct EGong_GUI_item *item, void *value);
+extern void *EGong_if_win_get_item_value(struct EGong_GUI_item *item);
+extern void EGong_if_win_trayhandler(struct EGong_GUI_item *item, unsigned short int type, int x, int y, HWND hwnd);
+extern void EGong_if_win_actionhandler(struct EGong_GUI_item *item);
+extern int EGong_if_win_setup(struct EGong_interface *interface);
+extern int EGong_if_win_cmd(char *msg);
+extern int EGong_if_win_cycle(struct EGong_interface *interface, String *msg, char **dest);
+extern int EGong_if_win_display(struct EGong_interface *interface, const String *msg);
+extern void EGong_if_win_destroy(struct EGong_GUI_item *item);
+extern int EGong_if_win_waiter_add(int sock, unsigned short int type);
+extern void EGong_if_win_destroy_wrapper(struct EGong_GUI_item **item);
+extern int EGong_if_win_shutdown(struct EGong_interface *interface);
+extern int EGong_if_win_loop(void);
+extern HINSTANCE EGong_if_win_instance;
diff --git a/include/EGong/Main.h b/include/EGong/Main.h
@@ -0,0 +1,8 @@
+#pragma once
+extern int(*Egong_main_loop_ptr)(void);
+extern int EGong_main_do(void);
+extern int EGong_main_init(void);
+extern int EGong_main_loop_default(void);
+extern void EGong_main_deinit(void);
+
+extern int EGong_main_loop();
diff --git a/include/EGong/Packet.h b/include/EGong/Packet.h
@@ -0,0 +1,32 @@
+#pragma once
+#include <stdint.h>
+#include <stddef.h>
+#include <EGong/Util/Hash.h>
+#include <EGong/Util/Socket.h>
+#include <EGong/Util/Misc.h>
+
+
+#define EGONG_PACKET_RAND_LENGTH 10
+#define EGONG_PACKET_HASH_LENGTH SHA256_DIGEST_LENGTH
+#define EGONG_PACKET_LENGTH_LENGTH sizeof(((struct EGong_packet*) 0)->message.length)
+
+#define EGONG_PACKET_MSGHEADLEN EGONG_PACKET_RAND_LENGTH+EGONG_PACKET_HASH_LENGTH+EGONG_PACKET_LENGTH_LENGTH
+#define EGONG_PACKET_MSGLEN(MSGSIZE) EGONG_PACKET_MSGHEADLEN+MSGSIZE
+
+struct EGong_packet{
+ char rand[EGONG_PACKET_RAND_LENGTH];
+ unsigned char hash[EGONG_PACKET_HASH_LENGTH];
+ struct {
+ uint16_t length;
+ char *data;
+ } message;
+};
+
+
+extern int EGong_calculate_package_hash(struct EGong_packet *packet, unsigned char *dest, String *cookie);
+extern int EGong_generate_packet(struct EGong_packet *packet, const String *msg);
+extern int EGong_send_packet(struct EGong_packet *packet, const char *dest);
+extern void EGong_packet_free(struct EGong_packet *packet);
+extern int EGong_packet_alloc(struct EGong_packet *packet, char **dest, unsigned int additional);
+extern int EGong_get_packet(SOCKET *sock, struct EGong_packet *packet);
+extern int EGong_packet_verify(struct EGong_packet *packet, String *cookie);
diff --git a/include/EGong/Util/Array.h b/include/EGong/Util/Array.h
@@ -0,0 +1,16 @@
+#pragma once
+#include <EGong/Util/SAlloc.h>
+
+
+struct Array{
+ struct SAlloc memory;
+ unsigned int element_count;
+ size_t element_size;
+};
+
+extern void Array_init(struct Array *array, size_t element_size, size_t chunks);
+extern int Array_add(struct Array *array, void *element);
+extern void *Array_get(struct Array *array, unsigned int id);
+extern int Array_delete(struct Array *array, unsigned int id);
+extern void Array_destroy(struct Array *array);
+extern void Array_foreach(struct Array *array, void(*func)(void*));
diff --git a/include/EGong/Util/Command.h b/include/EGong/Util/Command.h
@@ -0,0 +1,54 @@
+#pragma once
+#include <stddef.h>
+#include <stdint.h>
+#include <EGong/Util/Misc.h>
+struct EGong_command_type{
+ unsigned int type;
+ unsigned int args;
+};
+
+enum EGONG_COMMAND_TYPE{
+ EGONG_COMMAND_ARG0,
+ EGONG_COMMAND_UINT_INC,
+ EGONG_COMMAND_UINT_DEC,
+ EGONG_COMMAND_BOOL_TRUE,
+ EGONG_COMMAND_BOOL_FALSE,
+ EGONG_COMMAND_FUNC_VOID,
+ EGONG_COMMAND_ARG1,
+ EGONG_COMMAND_BOOL_SET,
+ EGONG_COMMAND_BIT_SET,
+ EGONG_COMMAND_UINT_SET,
+ EGONG_COMMAND_STREX_SET,
+ EGONG_COMMAND_FUNC_UINT,
+ EGONG_COMMAND_FUNC_CHAR,
+ EGONG_COMMAND_FUNC_STRING,
+ EGONG_COMMAND_FUNC_POINTER,
+ EGONG_COMMAND_ARG2,
+ EGONG_COMMAND_FUNC_2CHAR
+};
+enum EGONG_COMMAND_MATCH{
+ EGONG_COMMAND_MATCH_SHORT=(1<<0),
+ EGONG_COMMAND_MATCH_LONG=(1<<0),
+ EGONG_COMMAND_MATCH_ANY=~0
+};
+
+struct EGong_command{
+ char *longname;
+ char *shortname;
+ char *description;
+
+ struct EGong_command_type type;
+ void *pointer;
+};
+
+struct EGong_command_array{
+ struct EGong_static_array array;
+};
+
+extern struct EGong_command *EGong_command_match(struct EGong_command_array *commands, const char *data, unsigned int match_type);
+extern int EGong_command_exec(struct EGong_command *command, void **data);
+extern void EGong_command_print_help(struct EGong_command_array *commands, int destination, char *appendix);
+extern unsigned int EGong_command_argc(struct EGong_command *command);
+
+extern void *EGong_command_exec_from_char(struct EGong_command *command, char **args);
+extern void *EGong_command_convert_from_char(struct EGong_command *command, char *arg);
diff --git a/include/EGong/Util/Config.h b/include/EGong/Util/Config.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <EGong/Util/Config_Compiletime.h>
+#include <EGong/Util/Misc.h>
+
+struct EGong_config_log{
+ unsigned short int level;
+ unsigned short int color;
+ unsigned int destinations;
+};
+struct EGong_config_packet{
+ size_t packet_maxlen;
+ String_Ex cookie;
+};
+struct EGong_config_gui{
+ unsigned int destinations;
+};
+struct EGong_config_server{
+ unsigned int port;
+ String_Ex bind_ip;
+};
+struct EGong_config{
+ struct EGong_config_log log;
+ struct EGong_config_server server;
+ struct EGong_config_packet packet;
+ struct EGong_config_gui gui;
+};
+
+struct EGong_config_file_entry{
+ char *name;
+ unsigned short int type;
+ uintptr_t data_offset;
+};
+enum EGONG_CONFIG_FILE_ENTRY{
+ EGONG_CONFIG_FILE_LOG_LEVEL,
+ EGONG_CONFIG_FILE_LOG_COLOR,
+ EGONG_CONFIG_FILE_LOG_DEST,
+ EGONG_CONFIG_FILE_PACKET_LEN,
+ EGONG_CONFIG_FILE_PACKET_COOKIE,
+ EGONG_CONFIG_FILE_SERVER_PORT,
+ EGONG_CONFIG_FILE_SERVER_BINDIP,
+ EGONG_CONFIG_FILE_ENTRYCOUNT,
+};
+enum EGONG_CONFIG_FILE_TYPE{
+ EGONG_CONFIG_TYPE_STRING,
+ EGONG_CONFIG_TYPE_UINT,
+ EGONG_CONFIG_TYPE_BITMASK,
+ EGONG_CONFIG_TYPE_BOOL,
+};
+enum EGONG_CONFIG_GUI_DEST{
+ EGONG_CONFIG_GUI_DEST_NONE=0,
+ EGONG_CONFIG_GUI_DEST_WINDOW=(1<<0),
+ EGONG_CONFIG_GUI_DEST_NOTIFY=(1<<1),
+ EGONG_CONFIG_GUI_DEST_ALL=~0,
+};
+extern struct EGong_config_file_entry EGong_configuration_file_interface[EGONG_CONFIG_FILE_ENTRYCOUNT];
+
+extern struct EGong_config EGong_global_configuration;
+
+extern void EGong_config_set_defaults(struct EGong_config *conf);
+extern void EGong_config_init(struct EGong_config *conf);
+
diff --git a/include/EGong/Util/Config_Compiletime.h.in b/include/EGong/Util/Config_Compiletime.h.in
@@ -0,0 +1,7 @@
+#pragma once
+#cmakedefine USE_GTK
+#cmakedefine USE_LIBNOTIFY
+#cmakedefine USE_AO
+#cmakedefine USE_WINGUI
+
+#define EGONG_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
diff --git a/include/EGong/Util/Dependencies.h b/include/EGong/Util/Dependencies.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#define DEP_REQ(NAME, DEPS) ((NAME&(DEPS)&~EGong_dep_status)>0)
+#define DEP_STOP(NAME, DEPS) ((NAME&(DEPS)&EGong_dep_status)>0)
+#define DEP_AVAIL(DEPS) ((EGong_dep_status&DEPS)>0)
+
+enum EGONG_DEPENDENCIES{
+ EGONG_DEP_NONE=(0),
+ EGONG_DEP_LISTENER=(1<<0),
+ EGONG_DEP_SOCKETS=(1<<1),
+ EGONG_DEP_ALL=(~0)
+};
+
+extern int EGong_deps_init(unsigned int dependencies);
+extern int EGong_deps_deinit(unsigned int dependencies);
+
+extern unsigned int EGong_dep_status;
diff --git a/include/EGong/Util/File.h b/include/EGong/Util/File.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/include/EGong/Util/Hash.h b/include/EGong/Util/Hash.h
@@ -0,0 +1,21 @@
+/* Crypto/Sha256.h -- SHA-256 Hash function
+2008-10-04 : Igor Pavlov : Public domain */
+
+#pragma once
+#include <stdint.h>
+#include <stdlib.h>
+
+#define SHA256_DIGEST_LENGTH 32
+
+struct CSHA256_s
+{
+ uint32_t state[8];
+ uint64_t count;
+ char buffer[64];
+};
+typedef struct CSHA256_s CSHA256;
+typedef struct CSHA256_s SHA256_CTX;
+
+void SHA256_Init(CSHA256 *p);
+void SHA256_Update(CSHA256 *p, const char *data, size_t size);
+void SHA256_Final(char *digest, CSHA256 *p);
diff --git a/include/EGong/Util/Log.h b/include/EGong/Util/Log.h
@@ -0,0 +1,55 @@
+#pragma once
+#define WIDEN2(x) # x
+#define WIDEN(x) WIDEN2(x)
+
+#define LOG_COMPOSE_SRC (const struct log_source){.file={.v=__FILE__, .l=sizeof(__FILE__)}, .line={.v=WIDEN(__LINE__), .l=sizeof(WIDEN(__LINE__))}, .func={.v=__func__, .l=sizeof(__func__)}}
+
+#include <string.h>
+#include <EGong/Util/Config.h>
+struct log_source_string{
+ const char *v;
+ unsigned int l;
+};
+struct log_source{
+ struct log_source_string file;
+ struct log_source_string line;
+ struct log_source_string func;
+};
+enum LOG_LEVELS{
+ LOG_LEVEL_DEBUG,
+ LOG_LEVEL_INFO,
+ LOG_LEVEL_WARNING,
+ LOG_LEVEL_ERROR,
+ LOG_LEVEL_FATAL,
+ LOG_LEVEL_COUNT
+};
+enum LOG_DESTINATIONS{
+ LOG_DEST_STDIO=(1<<0),
+ LOG_DEST_FILE=(1<<1),
+ LOG_DEST_GTK=(1<<2)
+};
+enum LOG_TYPES{
+ LOG_TYPE_NORMAL,
+ LOG_TYPE_RESULT,
+ LOG_TYPE_RAW,
+ LOG_TYPE_SIGNAL
+ #ifdef _WIN32
+ ,LOG_TYPE_SOCKET
+ #endif
+};
+#ifndef _WIN32
+ #define LOG_TYPE_SOCKET LOG_TYPE_SIGNAL
+#endif
+struct log_level{
+ const char *name;
+ char color[10];
+};
+
+
+extern void do_log_call(const struct log_source src, const char *msg, unsigned int msglength, unsigned int type, unsigned int level, unsigned int destmask);
+extern void do_log_call_composite(const struct log_source src, unsigned int type, unsigned int level, unsigned int destmask, ...);
+extern struct log_level log_levels[LOG_LEVEL_COUNT];
+
+#define do_log(MSG, TYPE, LEVEL) do_log_call(LOG_COMPOSE_SRC,MSG,sizeof(MSG),TYPE,LEVEL,EGong_global_configuration.log.destinations)
+#define do_log_comp(TYPE, LEVEL, MSGS) do_log_call_composite(LOG_COMPOSE_SRC,TYPE,LEVEL,EGong_global_configuration.log.destinations, #MSGS, NULL)
+#define do_log_dynamic(MSG, TYPE, LEVEL) do_log_call(LOG_COMPOSE_SRC,MSG,strlen(MSG),TYPE,LEVEL,EGong_global_configuration.log.destinations)
diff --git a/include/EGong/Util/Misc.h b/include/EGong/Util/Misc.h
@@ -0,0 +1,35 @@
+#pragma once
+#include <stddef.h>
+#include <unistd.h>
+#define CSIZEOF(VAR) (sizeof(VAR))/(sizeof(*(VAR)))
+extern void EGong_misc_rand_init(void);
+extern int EGong_global_argc;
+extern char **EGong_global_argv;
+extern int EGong_misc_get_rand(char *dest, int length);
+
+#define STDNWRITE(str,len) (void)write(STDOUT_FILENO, str, len)
+#define STDWRITE(str) STDNWRITE(str,sizeof(str))
+#define STDWRITED(str) STDNWRITE(str,strlen(str))
+#define STRNCAT(dest,str,len) strncpy(dest,str,len); dest+=len;
+#define STRCAT(dest,str) STRNCAT(dest,str,sizeof(str)-1)
+
+struct EGong_static_array{
+ void *elements;
+ ssize_t element_count;
+ ssize_t element_size;
+};
+
+struct String{
+ char *data;
+ size_t length;
+};
+struct String_Ex{
+ struct String str;
+ unsigned short int allocd:1;
+};
+typedef struct String String;
+typedef struct String_Ex String_Ex;
+#define STRING_STATIC(STRING, VALUE) STRING.data=VALUE; STRING.length=sizeof(VALUE);
+#define STRING_STATIC_INIT(VALUE){.data=VALUE, .length=sizeof(VALUE)}
+
+#define STRING_EX_STATIC(STRING, VALUE) STRING_STATIC(STRING.str, VALUE); STRING.allocd=0;
diff --git a/include/EGong/Util/SAlloc.h b/include/EGong/Util/SAlloc.h
@@ -0,0 +1,17 @@
+#pragma once
+#include <stdint.h>
+#include <stddef.h>
+
+#define EGONG_SALLOC_DEFAULT_CHUNK 500
+
+struct SAlloc{
+ void *data;
+ size_t m_allocd;
+ size_t s_allocd;
+ size_t chunk_size;
+};
+
+extern void SAlloc_init(struct SAlloc *salloc, size_t chunk);
+extern void *SAlloc_alloc(struct SAlloc *salloc, size_t size);
+extern int SAlloc_rewind(struct SAlloc *salloc, size_t size);
+extern void *SAlloc_destroy(struct SAlloc *salloc);
diff --git a/include/EGong/Util/Socket.h b/include/EGong/Util/Socket.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <EGong/Util/Config.h>
+#ifdef _WIN32
+ #include <winsock2.h>
+ #define MSG_DONTWAIT (1<<5)
+ typedef short sa_family_t;
+#else
+ #include <sys/socket.h>
+ typedef int SOCKET;
+#endif
+extern SOCKET EGong_listen_sock;
+
+extern int EGong_sockets_setup(void);
+extern int EGong_sockets_shutdown(void);
+extern void EGong_socket_close(SOCKET *sock);
+extern int EGong_listener_init(SOCKET *sock, struct EGong_config_server *config);
+extern int EGong_listener_get(SOCKET *sock, char *dest, int length, struct sockaddr *source, int flags);
+extern int EGong_socket_open(SOCKET *sock);
+extern int EGong_sendto(SOCKET *sock, const char *dest, const char *msg, size_t msg_len, struct EGong_config_server *config);
+extern void EGong_listener_close(SOCKET *sock);
+extern int EGong_socket_cmp_ip(SOCKET *sock, struct sockaddr *sockaddr);
diff --git a/include/EGong/Util/Waiter.h b/include/EGong/Util/Waiter.h
@@ -0,0 +1,13 @@
+#pragma once
+
+extern unsigned int EGong_waiter_highest_fd;
+extern int EGong_waiter_init(void);
+extern int EGong_waiter_add_default(int sock, unsigned short int type);
+extern int EGong_waiter_del(int sock);
+extern int EGong_waiter_wait(void);
+extern int(*EGong_waiter_add)(int, unsigned short int);
+
+enum EGONG_WAITER_TYPE{
+ EGONG_WAITER_FD,
+ EGONG_WAITER_SOCKET
+};
diff --git a/include/Interfaces.h b/include/Interfaces.h
@@ -1,67 +0,0 @@
-#pragma once
-#include <EGong/CNC.h>
-#include <EGong/Util/Misc.h>
-
-
-enum EGONG_INTERFACE_STATE{
- EGONG_INTERFACE_ACTIVE=(1<<0),
- EGONG_INTERFACE_SETUP=(1<<1)
-};
-struct EGong_interface;
-struct EGong_if_ptrtbl{
- int (*setup) (struct EGong_interface *interface);
- int (*cmd) (char *msg);
- int (*cycle) (struct EGong_interface *interface, String *msg, char **dest);
- int (*display) (struct EGong_interface *interface, const String *msg);
- int (*shutdown) (struct EGong_interface *interface);
-
- int(*sock_watch)(int socket, unsigned short int type);
- int(*loop)(void);
-};
-struct EGong_interface{
- char *name;
- char identifier;
- unsigned int requirements;
- unsigned short int state;
- struct EGong_if_ptrtbl *funcs;
-};
-extern unsigned short int EGong_interfaces_userstreams;
-extern int EGong_interface_init(unsigned int requirement_mask);
-extern int EGong_interface_cycle(void);
-extern int EGong_interface_deinit(void);
-extern struct EGong_interface EGong_interfaces[];
-extern int EGong_interface_setup(struct EGong_interface *interface);
-extern int EGong_interface_activate(struct EGong_interface *interface);
-extern int EGong_interface_shutdown(struct EGong_interface *interface);
-extern int EGong_interface_deactivate(struct EGong_interface *interface);
-extern struct EGong_interface *EGong_interface_get_from_id(char identifier);
-#define IF_ACTIVE(INTERFACE) (((INTERFACE).state&EGONG_INTERFACE_ACTIVE)>0)
-#define IF_SETUP(INTERFACE) (((INTERFACE).state&EGONG_INTERFACE_SETUP)>0)
-#define IF_CAN_SHUTDOWN(INTERFACE) ((INTERFACE).funcs->shutdown!=NULL)
-#define IF_CAN_CYCLE(INTERFACE) ((INTERFACE).funcs->cycle!=NULL)
-#define IF_CAN_DISPLAY(INTERFACE) ((INTERFACE).funcs->display!=NULL)
-#define IF_CAN_SETUP(INTERFACE) ((INTERFACE).funcs->setup!=NULL)
-#define IF_TRY_SETUP(INTERFACE) ((IF_SETUP(INTERFACE)&&IF_CAN_SETUP(INTERFACE)) ? (INTERFACE).funcs->setup(&INTERFACE) : EGONG_INTERFACE_RETURN_OK)
-#define EGONG_INTERFACE_INTERPRET_RET(RET, INTERFACE)\
-if(RET==EGONG_INTERFACE_RETURN_FATAL){\
- do_log("Couldn't run interface function, exiting", LOG_TYPE_NORMAL, LOG_LEVEL_FATAL);\
- return -1;\
-}\
-else if(RET==EGONG_INTERFACE_RETURN_ERROR){\
- do_log("Couldn't run interface function, skipping", LOG_TYPE_NORMAL, LOG_LEVEL_WARNING);\
-}\
-else if(RET==EGONG_INTERFACE_RETURN_EXIT){\
- do_log_call_composite(LOG_COMPOSE_SRC, LOG_TYPE_NORMAL, LOG_LEVEL_INFO, EGong_global_configuration.log.destinations, "Interface ", (INTERFACE).name, " requested exit", NULL);\
- return 1;\
-}\
-else if(RET==EGONG_INTERFACE_RETURN_BREAK){\
- do_log("Interface function requested queueabortion", LOG_TYPE_NORMAL, LOG_LEVEL_INFO);\
- break;\
-}
-enum EGONG_INTERFACE_RETURN{
- EGONG_INTERFACE_RETURN_FATAL=-2,
- EGONG_INTERFACE_RETURN_ERROR=-1,
- EGONG_INTERFACE_RETURN_OK=0,
- EGONG_INTERFACE_RETURN_EXIT=1,
- EGONG_INTERFACE_RETURN_BREAK=2
-};
diff --git a/include/Interfaces/Audio.h b/include/Interfaces/Audio.h
@@ -1,6 +0,0 @@
-#pragma once
-
-
-int EGong_if_audio_setup(struct EGong_interface *interface);
-int EGong_if_audio_display(struct EGong_interface *interface, const String *msg);
-int EGong_if_audio_shutdown(struct EGong_interface *interface);
diff --git a/include/Interfaces/CMD.h b/include/Interfaces/CMD.h
@@ -1,26 +0,0 @@
-#pragma once
-#include <EGong/Util/Command.h>
-#include <EGong/Interfaces.h>
-
-
-enum EGONG_IF_CMD_EXEC{
- EGONG_IF_CMD_SETUP=(1<<0),
- EGONG_IF_CMD_CYCLE=(1<<1),
- EGONG_IF_CMD_SHUTDOWN=(1<<2)
-};
-
-struct EGong_command_if_cmd{
- struct EGong_command command;
- unsigned int execute;
-};
-
-extern int EGong_if_cmd_interfaceselect(const char *data);
-extern struct EGong_command_if_cmd *EGong_if_cmd_get_from_char(const char *commandline);
-extern int EGong_if_cmd_exec(unsigned int execution, struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_cmd_setup(struct EGong_interface *interface);
-extern int EGong_if_cmd_cycle(struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_cmd_shutdown(struct EGong_interface *interface);
-
-extern int EGong_if_cmd_gui_msg(void);
-extern int EGong_if_cmd_send_message(char *msg);
-extern int EGong_if_cmd_help(void);
diff --git a/include/Interfaces/GTK.h b/include/Interfaces/GTK.h
@@ -1,25 +0,0 @@
-#pragma once
-#include <EGong/Interfaces.h>
-#include <EGong/Interfaces/GUI.h>
-#include <gtk/gtk.h>
-
-extern GtkWidget *Egong_if_gtk_root;
-extern int EGong_if_gtk_int_setup(unsigned int what);
-
-extern int EGong_if_gtk_setup(struct EGong_interface *interface);
-extern int EGong_if_gtk_cycle(struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_gtk_display(struct EGong_interface *interface, const String *msg);
-extern int EGong_if_gtk_shutdown(struct EGong_interface *interface);
-extern GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
-extern void *EGong_gtk_get_item_value(struct EGong_GUI_item *itm);
-extern int EGong_gtk_waiter_add(int sock, unsigned short int type);
-extern void EGong_if_gtk_show_element(struct EGong_GUI_item *itm);
-extern void EGong_if_gtk_free_item_value(struct EGong_GUI_item *itm, void *element);
-extern int EGong_if_gtk_main(void);
-
-extern struct EGong_if_ptrtbl EGong_if_gtk_ptrtbl;
-enum EGONG_IF_GTK_INIT{
- EGONG_IF_GTK_INIT_ROOT=(1<<0),
- EGONG_IF_GTK_INIT_TRAY=(1<<1),
- EGONG_IF_GTK_INIT_ALL=(~0)
-};
diff --git a/include/Interfaces/GUI.h b/include/Interfaces/GUI.h
@@ -1,111 +0,0 @@
-#pragma once
-
-#include <EGong/Util/Command.h>
-#include <EGong/Util/Config_Compiletime.h>
-#include <EGong/Interfaces.h>
-
-#ifdef USE_WINGUI
-typedef wchar_t guichar;
-#define GUIT(TEXT) L##TEXT
-#else
-typedef char guichar;
-#define GUIT(TEXT) TEXT
-#endif
-
-enum EGONG_GUI_TYPE{
- EGONG_GUI_TYPE_NONE,
- EGONG_GUI_TYPE_GTK,
- EGONG_GUI_TYPE_WINGUI,
-};
-enum EGONG_GUI_EVSRC{
- EGONG_GUI_EVSRC_ELEMENT,
- EGONG_GUI_EVSRC_STATIC,
-};
-enum EGONG_GUI_MENUITEM_IMAGES{
- EGUI_MIMG_EXIT,
-};
-enum EGONG_GUI_ITEM{
- EGONG_GUI_WINDOW,
- EGONG_GUI_BUTTON,
- EGONG_GUI_LABEL,
- EGONG_GUI_TEXT,
- EGONG_GUI_MENU,
- EGONG_GUI_MENUITEM,
- EGONG_GUI_MENUITEM_IMAGE,
- EGONG_GUI_MENUITEM_SEPARATOR,
- EGONG_GUI_SYSTRAY,
- EGONG_GUI_HBOX,
- EGONG_GUI_VBOX,
- EGONG_GUI_DIALOG,
-};
-struct EGong_GUI_item{
- unsigned short int type;
- guichar *text;
- guichar *tooltip;
- void *extra;
- void *itemptr;
- void *userdata;
- struct EGong_GUI_item **child;
- struct EGong_GUI_event **events;
-};
-
-struct EGong_GUI_event_source{
- unsigned int type;
- void *data;
-};
-struct EGong_GUI_event{
- guichar *type;
- struct EGong_command command;
- struct EGong_GUI_event_source **sources;
-};
-extern void EGong_GUI_event_hide(void *gui_element);
-extern void *EGong_GUI_create(struct EGong_GUI_item *gui);
-extern void EGong_GUI_event_callback(struct EGong_GUI_event *event);
-extern int EGong_GUI_exit(void);
-
-#ifdef USE_GTK
-static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_GTK;
-#else
-#ifdef USE_WINGUI
-static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_WINGUI;
-#else
-static const unsigned int EGong_GUI_type=EGONG_GUI_TYPE_NONE;
-#endif
-#endif
-
-#define EGUI_ARR (struct EGong_GUI_item **)&(struct EGong_GUI_item *[])
-#define EGUI_EL &(struct EGong_GUI_item)
-#define EGUI_ELX(ELEMENT) (struct EGong_GUI_item*)&ELEMENT
-#define EGUI_FIN (struct EGong_GUI_item*)NULL
-
-#define EEV_ARR (struct EGong_GUI_event **)&(struct EGong_GUI_event *[])
-#define EEV_EL &(struct EGong_GUI_event)
-#define EEV_ELX(ELEMENT) (struct EGong_GUI_event*)&ELEMENT
-#define EEV_FIN (struct EGong_GUI_event*)NULL
-
-#define EES_ARR (struct EGong_GUI_event_source **)&(struct EGong_GUI_event_source *[])
-#define EES_EL &(struct EGong_GUI_event_source)
-#define EES_ELX(ELEMENT) (struct EGong_GUI_event_source*)&ELEMENT
-#define EES_FIN (struct EGong_GUI_event_source*)NULL
-
-struct EGong_if_gui_ptrtbl{
- struct EGong_if_ptrtbl *ifptrtbl;
- void *(*create)(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
- void *(*get_value)(struct EGong_GUI_item *itm);
- void (*free_value)(struct EGong_GUI_item *itm, void *value);
- void (*show)(struct EGong_GUI_item *itm);
-};
-
-extern int EGong_if_gui_setup(struct EGong_interface *interface);
-extern int EGong_if_gui_cmd(char *msg);
-extern int EGong_if_gui_cycle(struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_gui_display(struct EGong_interface *interface, const String *msg);
-extern int EGong_if_gui_shutdown(struct EGong_interface *interface);
-extern int EGong_if_gui_sockwatch(int sock, unsigned short int type);
-extern int EGong_if_gui_loop(void);
-
-
-extern char *EGong_GUI_item_names[];
-
-extern struct EGong_GUI_item EGong_GUI_newmessage;
-extern struct EGong_GUI_item EGong_GUI_systray;
diff --git a/include/Interfaces/STDIO.h b/include/Interfaces/STDIO.h
@@ -1,7 +0,0 @@
-#pragma once
-#include <EGong/Interfaces.h>
-
-
-extern int EGong_if_stdio_setup(struct EGong_interface *interface);
-extern int EGong_if_stdio_cycle(struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_stdio_display(struct EGong_interface *interface, const String *msg);
diff --git a/include/Interfaces/Windows.h b/include/Interfaces/Windows.h
@@ -1,35 +0,0 @@
-#pragma once
-#define UNICODE
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <EGong/Interfaces.h>
-#include <EGong/Interfaces/GUI.h>
-#include <EGong/Util/Misc.h>
-
-#define WM_TRAY_ACTION WM_USER+1
-#define WM_SOCKET WM_USER+2
-
-extern struct EGong_if_ptrtbl EGong_if_win_ptrtbl;
-extern WNDCLASSW EGong_if_win_getmsg;
-extern HWND EGong_if_win_getmsg_editfield;
-extern struct EGong_GUI_item *EGong_if_win_global_systray;
-extern struct Array EGong_if_win_menus;
-extern struct Array EGong_if_win_windows;
-extern HWND EGong_if_win_create_wrapper(struct EGong_GUI_item *parent, struct EGong_GUI_item *this);
-extern HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *this, unsigned int child);
-extern void EGong_if_win_show_element(struct EGong_GUI_item *itm);
-extern void EGong_if_win_show_item(HWND item);
-extern void EGong_if_win_free_item_value(struct EGong_GUI_item *item, void *value);
-extern void *EGong_if_win_get_item_value(struct EGong_GUI_item *item);
-extern void EGong_if_win_trayhandler(struct EGong_GUI_item *item, unsigned short int type, int x, int y, HWND hwnd);
-extern void EGong_if_win_actionhandler(struct EGong_GUI_item *item);
-extern int EGong_if_win_setup(struct EGong_interface *interface);
-extern int EGong_if_win_cmd(char *msg);
-extern int EGong_if_win_cycle(struct EGong_interface *interface, String *msg, char **dest);
-extern int EGong_if_win_display(struct EGong_interface *interface, const String *msg);
-extern void EGong_if_win_destroy(struct EGong_GUI_item *item);
-extern int EGong_if_win_waiter_add(int sock, unsigned short int type);
-extern void EGong_if_win_destroy_wrapper(struct EGong_GUI_item **item);
-extern int EGong_if_win_shutdown(struct EGong_interface *interface);
-extern int EGong_if_win_loop(void);
-extern HINSTANCE EGong_if_win_instance;
diff --git a/include/Main.h b/include/Main.h
@@ -1,8 +0,0 @@
-#pragma once
-extern int(*Egong_main_loop_ptr)(void);
-extern int EGong_main_do(void);
-extern int EGong_main_init(void);
-extern int EGong_main_loop_default(void);
-extern void EGong_main_deinit(void);
-
-extern int EGong_main_loop();
diff --git a/include/Packet.h b/include/Packet.h
@@ -1,32 +0,0 @@
-#pragma once
-#include <stdint.h>
-#include <stddef.h>
-#include <EGong/Util/Hash.h>
-#include <EGong/Util/Socket.h>
-#include <EGong/Util/Misc.h>
-
-
-#define EGONG_PACKET_RAND_LENGTH 10
-#define EGONG_PACKET_HASH_LENGTH SHA256_DIGEST_LENGTH
-#define EGONG_PACKET_LENGTH_LENGTH sizeof(((struct EGong_packet*) 0)->message.length)
-
-#define EGONG_PACKET_MSGHEADLEN EGONG_PACKET_RAND_LENGTH+EGONG_PACKET_HASH_LENGTH+EGONG_PACKET_LENGTH_LENGTH
-#define EGONG_PACKET_MSGLEN(MSGSIZE) EGONG_PACKET_MSGHEADLEN+MSGSIZE
-
-struct EGong_packet{
- char rand[EGONG_PACKET_RAND_LENGTH];
- unsigned char hash[EGONG_PACKET_HASH_LENGTH];
- struct {
- uint16_t length;
- char *data;
- } message;
-};
-
-
-extern int EGong_calculate_package_hash(struct EGong_packet *packet, unsigned char *dest, String *cookie);
-extern int EGong_generate_packet(struct EGong_packet *packet, const String *msg);
-extern int EGong_send_packet(struct EGong_packet *packet, const char *dest);
-extern void EGong_packet_free(struct EGong_packet *packet);
-extern int EGong_packet_alloc(struct EGong_packet *packet, char **dest, unsigned int additional);
-extern int EGong_get_packet(SOCKET *sock, struct EGong_packet *packet);
-extern int EGong_packet_verify(struct EGong_packet *packet, String *cookie);
diff --git a/include/Util/Array.h b/include/Util/Array.h
@@ -1,16 +0,0 @@
-#pragma once
-#include <EGong/Util/SAlloc.h>
-
-
-struct Array{
- struct SAlloc memory;
- unsigned int element_count;
- size_t element_size;
-};
-
-extern void Array_init(struct Array *array, size_t element_size, size_t chunks);
-extern int Array_add(struct Array *array, void *element);
-extern void *Array_get(struct Array *array, unsigned int id);
-extern int Array_delete(struct Array *array, unsigned int id);
-extern void Array_destroy(struct Array *array);
-extern void Array_foreach(struct Array *array, void(*func)(void*));
diff --git a/include/Util/Command.h b/include/Util/Command.h
@@ -1,54 +0,0 @@
-#pragma once
-#include <stddef.h>
-#include <stdint.h>
-#include <EGong/Util/Misc.h>
-struct EGong_command_type{
- unsigned int type;
- unsigned int args;
-};
-
-enum EGONG_COMMAND_TYPE{
- EGONG_COMMAND_ARG0,
- EGONG_COMMAND_UINT_INC,
- EGONG_COMMAND_UINT_DEC,
- EGONG_COMMAND_BOOL_TRUE,
- EGONG_COMMAND_BOOL_FALSE,
- EGONG_COMMAND_FUNC_VOID,
- EGONG_COMMAND_ARG1,
- EGONG_COMMAND_BOOL_SET,
- EGONG_COMMAND_BIT_SET,
- EGONG_COMMAND_UINT_SET,
- EGONG_COMMAND_STREX_SET,
- EGONG_COMMAND_FUNC_UINT,
- EGONG_COMMAND_FUNC_CHAR,
- EGONG_COMMAND_FUNC_STRING,
- EGONG_COMMAND_FUNC_POINTER,
- EGONG_COMMAND_ARG2,
- EGONG_COMMAND_FUNC_2CHAR
-};
-enum EGONG_COMMAND_MATCH{
- EGONG_COMMAND_MATCH_SHORT=(1<<0),
- EGONG_COMMAND_MATCH_LONG=(1<<0),
- EGONG_COMMAND_MATCH_ANY=~0
-};
-
-struct EGong_command{
- char *longname;
- char *shortname;
- char *description;
-
- struct EGong_command_type type;
- void *pointer;
-};
-
-struct EGong_command_array{
- struct EGong_static_array array;
-};
-
-extern struct EGong_command *EGong_command_match(struct EGong_command_array *commands, const char *data, unsigned int match_type);
-extern int EGong_command_exec(struct EGong_command *command, void **data);
-extern void EGong_command_print_help(struct EGong_command_array *commands, int destination, char *appendix);
-extern unsigned int EGong_command_argc(struct EGong_command *command);
-
-extern void *EGong_command_exec_from_char(struct EGong_command *command, char **args);
-extern void *EGong_command_convert_from_char(struct EGong_command *command, char *arg);
diff --git a/include/Util/Config.h b/include/Util/Config.h
@@ -1,64 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-#include <EGong/Util/Config_Compiletime.h>
-#include <EGong/Util/Misc.h>
-
-struct EGong_config_log{
- unsigned short int level;
- unsigned short int color;
- unsigned int destinations;
-};
-struct EGong_config_packet{
- size_t packet_maxlen;
- String_Ex cookie;
-};
-struct EGong_config_gui{
- unsigned int destinations;
-};
-struct EGong_config_server{
- unsigned int port;
- String_Ex bind_ip;
-};
-struct EGong_config{
- struct EGong_config_log log;
- struct EGong_config_server server;
- struct EGong_config_packet packet;
- struct EGong_config_gui gui;
-};
-
-struct EGong_config_file_entry{
- char *name;
- unsigned short int type;
- uintptr_t data_offset;
-};
-enum EGONG_CONFIG_FILE_ENTRY{
- EGONG_CONFIG_FILE_LOG_LEVEL,
- EGONG_CONFIG_FILE_LOG_COLOR,
- EGONG_CONFIG_FILE_LOG_DEST,
- EGONG_CONFIG_FILE_PACKET_LEN,
- EGONG_CONFIG_FILE_PACKET_COOKIE,
- EGONG_CONFIG_FILE_SERVER_PORT,
- EGONG_CONFIG_FILE_SERVER_BINDIP,
- EGONG_CONFIG_FILE_ENTRYCOUNT,
-};
-enum EGONG_CONFIG_FILE_TYPE{
- EGONG_CONFIG_TYPE_STRING,
- EGONG_CONFIG_TYPE_UINT,
- EGONG_CONFIG_TYPE_BITMASK,
- EGONG_CONFIG_TYPE_BOOL,
-};
-enum EGONG_CONFIG_GUI_DEST{
- EGONG_CONFIG_GUI_DEST_NONE=0,
- EGONG_CONFIG_GUI_DEST_WINDOW=(1<<0),
- EGONG_CONFIG_GUI_DEST_NOTIFY=(1<<1),
- EGONG_CONFIG_GUI_DEST_ALL=~0,
-};
-extern struct EGong_config_file_entry EGong_configuration_file_interface[EGONG_CONFIG_FILE_ENTRYCOUNT];
-
-extern struct EGong_config EGong_global_configuration;
-
-extern void EGong_config_set_defaults(struct EGong_config *conf);
-extern void EGong_config_init(struct EGong_config *conf);
-
diff --git a/include/Util/Config_Compiletime.h.in b/include/Util/Config_Compiletime.h.in
@@ -1,7 +0,0 @@
-#pragma once
-#cmakedefine USE_GTK
-#cmakedefine USE_LIBNOTIFY
-#cmakedefine USE_AO
-#cmakedefine USE_WINGUI
-
-#define EGONG_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
diff --git a/include/Util/Dependencies.h b/include/Util/Dependencies.h
@@ -1,17 +0,0 @@
-#pragma once
-
-#define DEP_REQ(NAME, DEPS) ((NAME&(DEPS)&~EGong_dep_status)>0)
-#define DEP_STOP(NAME, DEPS) ((NAME&(DEPS)&EGong_dep_status)>0)
-#define DEP_AVAIL(DEPS) ((EGong_dep_status&DEPS)>0)
-
-enum EGONG_DEPENDENCIES{
- EGONG_DEP_NONE=(0),
- EGONG_DEP_LISTENER=(1<<0),
- EGONG_DEP_SOCKETS=(1<<1),
- EGONG_DEP_ALL=(~0)
-};
-
-extern int EGong_deps_init(unsigned int dependencies);
-extern int EGong_deps_deinit(unsigned int dependencies);
-
-extern unsigned int EGong_dep_status;
diff --git a/include/Util/File.h b/include/Util/File.h
@@ -1 +0,0 @@
-#pragma once
diff --git a/include/Util/Hash.h b/include/Util/Hash.h
@@ -1,21 +0,0 @@
-/* Crypto/Sha256.h -- SHA-256 Hash function
-2008-10-04 : Igor Pavlov : Public domain */
-
-#pragma once
-#include <stdint.h>
-#include <stdlib.h>
-
-#define SHA256_DIGEST_LENGTH 32
-
-struct CSHA256_s
-{
- uint32_t state[8];
- uint64_t count;
- char buffer[64];
-};
-typedef struct CSHA256_s CSHA256;
-typedef struct CSHA256_s SHA256_CTX;
-
-void SHA256_Init(CSHA256 *p);
-void SHA256_Update(CSHA256 *p, const char *data, size_t size);
-void SHA256_Final(char *digest, CSHA256 *p);
diff --git a/include/Util/Log.h b/include/Util/Log.h
@@ -1,55 +0,0 @@
-#pragma once
-#define WIDEN2(x) # x
-#define WIDEN(x) WIDEN2(x)
-
-#define LOG_COMPOSE_SRC (const struct log_source){.file={.v=__FILE__, .l=sizeof(__FILE__)}, .line={.v=WIDEN(__LINE__), .l=sizeof(WIDEN(__LINE__))}, .func={.v=__func__, .l=sizeof(__func__)}}
-
-#include <string.h>
-#include <EGong/Util/Config.h>
-struct log_source_string{
- const char *v;
- unsigned int l;
-};
-struct log_source{
- struct log_source_string file;
- struct log_source_string line;
- struct log_source_string func;
-};
-enum LOG_LEVELS{
- LOG_LEVEL_DEBUG,
- LOG_LEVEL_INFO,
- LOG_LEVEL_WARNING,
- LOG_LEVEL_ERROR,
- LOG_LEVEL_FATAL,
- LOG_LEVEL_COUNT
-};
-enum LOG_DESTINATIONS{
- LOG_DEST_STDIO=(1<<0),
- LOG_DEST_FILE=(1<<1),
- LOG_DEST_GTK=(1<<2)
-};
-enum LOG_TYPES{
- LOG_TYPE_NORMAL,
- LOG_TYPE_RESULT,
- LOG_TYPE_RAW,
- LOG_TYPE_SIGNAL
- #ifdef _WIN32
- ,LOG_TYPE_SOCKET
- #endif
-};
-#ifndef _WIN32
- #define LOG_TYPE_SOCKET LOG_TYPE_SIGNAL
-#endif
-struct log_level{
- const char *name;
- char color[10];
-};
-
-
-extern void do_log_call(const struct log_source src, const char *msg, unsigned int msglength, unsigned int type, unsigned int level, unsigned int destmask);
-extern void do_log_call_composite(const struct log_source src, unsigned int type, unsigned int level, unsigned int destmask, ...);
-extern struct log_level log_levels[LOG_LEVEL_COUNT];
-
-#define do_log(MSG, TYPE, LEVEL) do_log_call(LOG_COMPOSE_SRC,MSG,sizeof(MSG),TYPE,LEVEL,EGong_global_configuration.log.destinations)
-#define do_log_comp(TYPE, LEVEL, MSGS) do_log_call_composite(LOG_COMPOSE_SRC,TYPE,LEVEL,EGong_global_configuration.log.destinations, #MSGS, NULL)
-#define do_log_dynamic(MSG, TYPE, LEVEL) do_log_call(LOG_COMPOSE_SRC,MSG,strlen(MSG),TYPE,LEVEL,EGong_global_configuration.log.destinations)
diff --git a/include/Util/Misc.h b/include/Util/Misc.h
@@ -1,35 +0,0 @@
-#pragma once
-#include <stddef.h>
-#include <unistd.h>
-#define CSIZEOF(VAR) (sizeof(VAR))/(sizeof(*(VAR)))
-extern void EGong_misc_rand_init(void);
-extern int EGong_global_argc;
-extern char **EGong_global_argv;
-extern int EGong_misc_get_rand(char *dest, int length);
-
-#define STDNWRITE(str,len) (void)write(STDOUT_FILENO, str, len)
-#define STDWRITE(str) STDNWRITE(str,sizeof(str))
-#define STDWRITED(str) STDNWRITE(str,strlen(str))
-#define STRNCAT(dest,str,len) strncpy(dest,str,len); dest+=len;
-#define STRCAT(dest,str) STRNCAT(dest,str,sizeof(str)-1)
-
-struct EGong_static_array{
- void *elements;
- ssize_t element_count;
- ssize_t element_size;
-};
-
-struct String{
- char *data;
- size_t length;
-};
-struct String_Ex{
- struct String str;
- unsigned short int allocd:1;
-};
-typedef struct String String;
-typedef struct String_Ex String_Ex;
-#define STRING_STATIC(STRING, VALUE) STRING.data=VALUE; STRING.length=sizeof(VALUE);
-#define STRING_STATIC_INIT(VALUE){.data=VALUE, .length=sizeof(VALUE)}
-
-#define STRING_EX_STATIC(STRING, VALUE) STRING_STATIC(STRING.str, VALUE); STRING.allocd=0;
diff --git a/include/Util/SAlloc.h b/include/Util/SAlloc.h
@@ -1,17 +0,0 @@
-#pragma once
-#include <stdint.h>
-#include <stddef.h>
-
-#define EGONG_SALLOC_DEFAULT_CHUNK 500
-
-struct SAlloc{
- void *data;
- size_t m_allocd;
- size_t s_allocd;
- size_t chunk_size;
-};
-
-extern void SAlloc_init(struct SAlloc *salloc, size_t chunk);
-extern void *SAlloc_alloc(struct SAlloc *salloc, size_t size);
-extern int SAlloc_rewind(struct SAlloc *salloc, size_t size);
-extern void *SAlloc_destroy(struct SAlloc *salloc);
diff --git a/include/Util/Socket.h b/include/Util/Socket.h
@@ -1,22 +0,0 @@
-#pragma once
-
-#include <EGong/Util/Config.h>
-#ifdef _WIN32
- #include <winsock2.h>
- #define MSG_DONTWAIT (1<<5)
- typedef short sa_family_t;
-#else
- #include <sys/socket.h>
- typedef int SOCKET;
-#endif
-extern SOCKET EGong_listen_sock;
-
-extern int EGong_sockets_setup(void);
-extern int EGong_sockets_shutdown(void);
-extern void EGong_socket_close(SOCKET *sock);
-extern int EGong_listener_init(SOCKET *sock, struct EGong_config_server *config);
-extern int EGong_listener_get(SOCKET *sock, char *dest, int length, struct sockaddr *source, int flags);
-extern int EGong_socket_open(SOCKET *sock);
-extern int EGong_sendto(SOCKET *sock, const char *dest, const char *msg, size_t msg_len, struct EGong_config_server *config);
-extern void EGong_listener_close(SOCKET *sock);
-extern int EGong_socket_cmp_ip(SOCKET *sock, struct sockaddr *sockaddr);
diff --git a/include/Util/Waiter.h b/include/Util/Waiter.h
@@ -1,13 +0,0 @@
-#pragma once
-
-extern unsigned int EGong_waiter_highest_fd;
-extern int EGong_waiter_init(void);
-extern int EGong_waiter_add_default(int sock, unsigned short int type);
-extern int EGong_waiter_del(int sock);
-extern int EGong_waiter_wait(void);
-extern int(*EGong_waiter_add)(int, unsigned short int);
-
-enum EGONG_WAITER_TYPE{
- EGONG_WAITER_FD,
- EGONG_WAITER_SOCKET
-};