ekg2  GIT master
plugins.h
Idź do dokumentacji tego pliku.
1 /* $Id: plugins.h 4592 2008-09-01 19:12:07Z peres $ */
2 
3 /*
4  * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef __EKG_PLUGINS_H
21 #define __EKG_PLUGINS_H
22 
23 #include <sys/types.h>
24 #include <stdarg.h>
25 
26 #include "dynstuff.h"
27 #include "sessions.h"
28 
29 #define EKG_ABI_VER 4921
30 
31 #define EXPORT __attribute__ ((visibility("default")))
32 
33 typedef enum {
44 
45 typedef int (*plugin_destroy_func_t)(void);
46 typedef int (*plugin_theme_init_func_t)(void);
47 typedef void (plugin_notify_func_t)(session_t *, const char *);
48 
49 #define PLUGIN_VAR_ADD(name, type, value, secret, notify) { name, value, secret, type, notify }
50 #define PLUGIN_VAR_END() { NULL, NULL, 0, -1, NULL }
51 extern int plugin_abi_version(int plugin_abi_ver, const char * plugin_name);
52 #define PLUGIN_CHECK_VER(name) { if (!plugin_abi_version(EKG_ABI_VER, name)) return -1; }
53 
54 typedef struct {
55  char *key; /* ekg2-remote: OK */
56  char *value; /* ekg2-remote: OK, NULL */
57  int secret; /* ekg2-remote: OK, 0 */
58  int type; /* ekg2-remote: OK, 0 */
59  plugin_notify_func_t *notify; /* ekg2-remote: OK, NULL */
61 
62 typedef struct plugin {
63  struct plugin *next;
64 
65  char *name; /* ekg2-remote: OK */
66  int prio; /* ekg2-remote: OK, (but not used) */
67  plugin_class_t pclass; /* ekg2-remote: OK, PLUGIN_ANY */
68  plugin_destroy_func_t destroy; /* ekg2-remote: OK, NULL */
69  void *__dl; /* ekg2-remote: OK, NULL */
70  plugins_params_t *params; /* ekg2-remote: OK */
71  plugin_theme_init_func_t theme_init; /* ekg2-remote: OK, NULL */
72 
73  const void *priv;
74 } plugin_t;
75 
76 void plugin_load(const char *name);
77 void plugin_unload(plugin_t *p);
78 plugin_t *remote_plugin_load(const char *name, int prio);
79 int plugin_register(plugin_t *, int prio);
82 plugin_t *plugin_find(const char *name);
83 
84 #define PLUGIN_DEFINE(x, y, z)\
85  static int x##_plugin_destroy(); \
86  \
87  plugin_t x##_plugin = { \
88  .name = #x, \
89  .pclass = y, \
90  .destroy = x##_plugin_destroy, \
91  .theme_init = z \
92  }
93 
94 #define QUERY(x) int x(void *data, va_list ap)
96 
97 typedef struct queryx {
98  struct queryx *next;
99 
100  int id;
102  void *data;
104  int __count; /* ekg2-remote: OK, 0 */
105 } query_t;
106 
108 int query_emit_idXXX(plugin_t *, const int, ...);
109 void queries_destroy();
110 
111 typedef enum {
117 } watch_type_t;
118 
119 #define WATCHER(x) int x(int type, int fd, watch_type_t watch, void *data)
120 #define WATCHER_LINE(x) int x(int type, int fd, const char *watch, void *data)
121 
123 
124 typedef struct watch {
125  int fd; /* obserwowany deskryptor */
126  watch_type_t type; /* co sprawdzamy */
127  plugin_t *plugin; /* wtyczka obsługująca deskryptor */
128  void *handler; /* funkcja wywoływana jeśli są dane itp. */
129  void *data; /* dane przekazywane powyższym funkcjom. */
130  string_t buf; /* bufor na linię */
131  time_t __timeout; /* ekg2-remote: NONE */
132  time_t __started; /* ekg2-remote: NONE */
133  int removed; /* wywołano już watch_remove() */
134 
135  int transfer_limit; /* XXX, requested by GiM to limit data transmitted to ircd server... currently only to send all data
136  done by serveral calls of watch_write() in one packet... by setting it to -1 and than changing it back to 0
137  if we really want to send packet in that function we ought to do by calling watch_handle_write()
138  [PLEASE NOTE, THAT YOU CANNOT DO watch_write().. cause it will check if there is somethink in write buffor...
139  and if it is, it won't call watch_handle_write()]
140  or it will be
141  executed in next ekg_loop() loop.
142  */
143  int __is_session; /* if set, this watch belongs to session specified in data */
144 } watch_t;
145 
146 int watch_write(watch_t *w, const char *buf, int len);
147 
148 void watch_free(watch_t *w);
149 
150 typedef void *watch_handler_func_t;
151 
153 #define watch_add_line(p, fd, type, handler, data) watch_add(p, fd, type, (watcher_handler_func_t *) (handler), data)
154 
155 int watch_remove(plugin_t *plugin, int fd, watch_type_t type);
156 
157 void watch_handle(watch_t *w);
158 void watches_destroy();
159 
160 extern plugin_t *plugins;
161 extern list_t watches;
162 
163 extern plugin_t *ui_plugin;
164 
165 extern int ekg_watches_removed;
166 
167 #endif /* __EKG_PLUGINS_H */
168 
169 /*
170  * Local Variables:
171  * mode: c
172  * c-file-style: "k&r"
173  * c-basic-offset: 8
174  * indent-tabs-mode: t
175  * End:
176  */
struct watch watch_t
int watcher_handler_func_t(int type, int fd, watch_type_t watch, void *data)
Definition: plugins.h:122
time_t __timeout
Definition: plugins.h:131
void * data
Definition: plugins.h:145
GString * string_t
Definition: dynstuff.h:147
int plugin_unload(plugin_t *)
Definition: plugins.c:374
int query_emit_idXXX(plugin_t *, const int,...)
Definition: plugins.c:343
Definition: plugins.h:114
Definition: sessions.h:127
int watch_write(watch_t *w, const char *buf, int len)
Definition: plugins.h:41
plugin_t * plugin_find(const char *name)
Definition: plugins.c:329
void watches_destroy()
Definition: plugins.h:47
int ekg_watches_removed
static plugin_t p
Definition: static-aborts.c:4
void watch_handle(watch_t *w)
plugin_t * ui_plugin
char * name
Definition: plugins.h:142
int(* plugin_theme_init_func_t)(void)
Definition: plugins.h:53
Definition: plugins.h:45
watch_type_t
Definition: plugins.h:111
int __count
Definition: plugins.h:104
int(* plugin_destroy_func_t)(void)
Definition: plugins.h:52
Definition: plugins.h:76
struct queryx * next
Definition: plugins.h:98
Definition: plugins.h:48
Definition: plugins.h:46
query_handler_func_t * handler
Definition: plugins.h:146
int __is_session
Definition: plugins.h:143
void remote_plugins_destroy()
query_t * query_connect_idXXX(plugin_t *plugin, const int id, query_handler_func_t *handler, void *data)
Definition: plugins.c:323
int removed
Definition: plugins.h:133
plugin_t * remote_plugin_load(const char *name, int prio)
void watch_free(watch_t *w)
Definition: sources.c:1482
int query_handler_func_t(void *data, va_list ap)
Definition: plugins.h:135
Definition: plugins.h:97
plugin_t * plugin
Definition: plugins.h:101
#define WATCHER(x)
Definition: plugins.h:119
#define params(x)
Definition: irc.c:1893
watch_type_t
Definition: sources.h:61
int watch_remove(plugin_t *plugin, int fd, watch_type_t type)
Definition: sources.c:1572
int id
Definition: plugins.h:100
int plugin_register(plugin_t *, int prio)
Definition: plugins.c:440
plugin_class_t
Definition: plugins.h:40
void * __dl
Definition: plugins.h:69
Definition: plugins.h:49
Definition: plugins.h:42
struct plugin plugin_t
time_t __started
Definition: plugins.h:132
int plugin_abi_version(int plugin_abi_ver, const char *plugin_name)
Definition: plugins.c:797
plugin_destroy_func_t destroy
Definition: plugins.h:80
plugin_t * plugin
Definition: plugins.h:144
query_handler_func_t * handler
Definition: plugins.h:103
watch_t * watch_add(plugin_t *plugin, int fd, watch_type_t type, watcher_handler_func_t *handler, void *data)
Definition: sources.c:1509
Definition: plugins.h:113
void queries_destroy()
Definition: ekg_hash_benchmark.c:14
Definition: plugins.h:116
int plugin_unregister(plugin_t *)
Definition: plugins.c:475
struct plugin * next
Definition: plugins.h:63
void theme_init()
Definition: themes.c:1447
Definition: plugins.h:140
Definition: plugins.h:44
Definition: plugins.h:112
struct query_node query_t
const void * priv
Definition: plugins.h:85
Definition: sources.h:78
GSList * plugins
Definition: plugins.c:33
int prio
Definition: plugins.h:78
void() plugin_notify_func_t(session_t *, const char *)
Definition: plugins.h:54
void * data
Definition: plugins.h:102
list_t watches
Definition: plugins.c:52
#define QUERY(x)
Definition: plugins.h:94
Definition: plugins.h:62
void * watch_handler_func_t
Definition: plugins.h:150
Definition: plugins.h:115
plugin_class_t pclass
Definition: plugins.h:79
Definition: plugins.h:43
int plugin_load(const char *name, int prio, int quiet)
Definition: plugins.c:169