ekg2
|
00001 /* $Id: plugins.h 4592 2008-09-01 19:12:07Z peres $ */ 00002 00003 /* 00004 * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License Version 2 as 00008 * published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __EKG_PLUGINS_H 00021 #define __EKG_PLUGINS_H 00022 00023 #include <sys/types.h> 00024 #include <stdarg.h> 00025 00026 #include "dynstuff.h" 00027 #include "sessions.h" 00028 00029 #define EKG_ABI_VER 4921 00030 00031 #define EXPORT __attribute__ ((visibility("default"))) 00032 00033 typedef enum { 00034 PLUGIN_ANY = 0, 00035 PLUGIN_GENERIC, 00036 PLUGIN_PROTOCOL, 00037 PLUGIN_UI, 00038 PLUGIN_LOG, 00039 PLUGIN_SCRIPTING, 00040 PLUGIN_AUDIO, 00041 PLUGIN_CODEC, 00042 PLUGIN_CRYPT 00043 } plugin_class_t; 00044 00045 typedef int (*plugin_destroy_func_t)(void); 00046 typedef int (*plugin_theme_init_func_t)(void); 00047 typedef void (plugin_notify_func_t)(session_t *, const char *); 00048 00049 #define PLUGIN_VAR_ADD(name, type, value, secret, notify) { name, value, secret, type, notify } 00050 #define PLUGIN_VAR_END() { NULL, NULL, 0, -1, NULL } 00051 extern int plugin_abi_version(int plugin_abi_ver, const char * plugin_name); 00052 #define PLUGIN_CHECK_VER(name) { if (!plugin_abi_version(EKG_ABI_VER, name)) return -1; } 00053 00054 typedef struct { 00055 char *key; /* ekg2-remote: OK */ 00056 char *value; /* ekg2-remote: OK, NULL */ 00057 int secret; /* ekg2-remote: OK, 0 */ 00058 int type; /* ekg2-remote: OK, 0 */ 00059 plugin_notify_func_t *notify; /* ekg2-remote: OK, NULL */ 00060 } plugins_params_t; 00061 00062 typedef struct plugin { 00063 struct plugin *next; 00064 00065 char *name; /* ekg2-remote: OK */ 00066 int prio; /* ekg2-remote: OK, (but not used) */ 00067 plugin_class_t pclass; /* ekg2-remote: OK, PLUGIN_ANY */ 00068 plugin_destroy_func_t destroy; /* ekg2-remote: OK, NULL */ 00069 void *__dl; /* ekg2-remote: OK, NULL */ 00070 plugins_params_t *params; /* ekg2-remote: OK */ 00071 plugin_theme_init_func_t theme_init; /* ekg2-remote: OK, NULL */ 00072 00073 const void *priv; 00074 } plugin_t; 00075 00076 void plugin_load(const char *name); 00077 void plugin_unload(plugin_t *p); 00078 plugin_t *remote_plugin_load(const char *name, int prio); 00079 int plugin_register(plugin_t *, int prio); 00080 int plugin_unregister(plugin_t *); 00081 void remote_plugins_destroy(); 00082 plugin_t *plugin_find(const char *name); 00083 00084 #define PLUGIN_DEFINE(x, y, z)\ 00085 static int x##_plugin_destroy(); \ 00086 \ 00087 plugin_t x##_plugin = { \ 00088 .name = #x, \ 00089 .pclass = y, \ 00090 .destroy = x##_plugin_destroy, \ 00091 .theme_init = z \ 00092 } 00093 00094 #define QUERY(x) int x(void *data, va_list ap) 00095 typedef QUERY(query_handler_func_t); 00096 00097 typedef struct queryx { 00098 struct queryx *next; 00099 00100 int id; 00101 plugin_t *plugin; 00102 void *data; 00103 query_handler_func_t *handler; 00104 int __count; /* ekg2-remote: OK, 0 */ 00105 } query_t; 00106 00107 query_t *query_connect_id(plugin_t *plugin, const int id, query_handler_func_t *handler, void *data); 00108 int query_emit_id(plugin_t *, const int, ...); 00109 void queries_destroy(); 00110 00111 typedef enum { 00112 WATCH_NONE = 0, 00113 WATCH_WRITE = 1, 00114 WATCH_READ = 2, 00115 WATCH_READ_LINE = 4, 00116 WATCH_WRITE_LINE = 8, 00117 } watch_type_t; 00118 00119 #define WATCHER(x) int x(int type, int fd, watch_type_t watch, void *data) 00120 #define WATCHER_LINE(x) int x(int type, int fd, const char *watch, void *data) 00121 00122 typedef WATCHER(watcher_handler_func_t); 00123 00124 typedef struct watch { 00125 int fd; /* obserwowany deskryptor */ 00126 watch_type_t type; /* co sprawdzamy */ 00127 plugin_t *plugin; /* wtyczka obsługująca deskryptor */ 00128 void *handler; /* funkcja wywoływana jeśli są dane itp. */ 00129 void *data; /* dane przekazywane powyższym funkcjom. */ 00130 string_t buf; /* bufor na linię */ 00131 time_t __timeout; /* ekg2-remote: NONE */ 00132 time_t __started; /* ekg2-remote: NONE */ 00133 int removed; /* wywołano już watch_remove() */ 00134 00135 int transfer_limit; /* XXX, requested by GiM to limit data transmitted to ircd server... currently only to send all data 00136 done by serveral calls of watch_write() in one packet... by setting it to -1 and than changing it back to 0 00137 if we really want to send packet in that function we ought to do by calling watch_handle_write() 00138 [PLEASE NOTE, THAT YOU CANNOT DO watch_write().. cause it will check if there is somethink in write buffor... 00139 and if it is, it won't call watch_handle_write()] 00140 or it will be 00141 executed in next ekg_loop() loop. 00142 */ 00143 int __is_session; /* if set, this watch belongs to session specified in data */ 00144 } watch_t; 00145 00146 int watch_write(watch_t *w, const char *buf, int len); 00147 00148 void watch_free(watch_t *w); 00149 00150 typedef void *watch_handler_func_t; 00151 00152 watch_t *watch_add(plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data); 00153 #define watch_add_line(p, fd, type, handler, data) watch_add(p, fd, type, (watcher_handler_func_t *) (handler), data) 00154 00155 int watch_remove(plugin_t *plugin, int fd, watch_type_t type); 00156 00157 void watch_handle(watch_t *w); 00158 void watches_destroy(); 00159 00160 extern plugin_t *plugins; 00161 extern list_t watches; 00162 00163 extern plugin_t *ui_plugin; 00164 00165 extern int ekg_watches_removed; 00166 00167 #endif /* __EKG_PLUGINS_H */ 00168 00169 /* 00170 * Local Variables: 00171 * mode: c 00172 * c-file-style: "k&r" 00173 * c-basic-offset: 8 00174 * indent-tabs-mode: t 00175 * End: 00176 */