1
<chapter id="functions">
2
<!--FIXME: Needs a rather large update - robodoc or synopsis? -->
5
<para>This chapter describes the functions that are available for
6
third-party plugin writers.</para>
8
<sect1><title>Main structs</title>
11
<imageobject role="html">
12
<imagedata format="PNG" align="center" fileref="overview.png"/>
14
<imageobject role="fo">
15
<imagedata format="EPS" align="center" fileref="overview.eps"/>
19
<sect2><title>struct client</title>
23
struct network *network;
25
struct transport_context *incoming;
30
<para>Describes one single client connection to ctrlproxy. </para>
33
<varlistentry><term>struct network *network</term>
34
<listitem><para>Pointer to network struct this client belongs to. </para></listitem>
37
<varlistentry><term>char authenticated</term>
38
<listitem><para>Indicates whether the client has been authenticated
39
by ctrlproxy. (By sending the correct <quote>PASS ...</quote> line). If set to 0, the client has not been authenticated, if set to 1, the client has been successfully authenticated. A value of 2 means the client has disconnected.</para></listitem>
42
<varlistentry><term>struct transport_context *incoming</term>
43
<listitem><para>Transport context to be used to communicate with the client.</para></listitem>
46
<varlistentry><term>time_t connect_time</term>
47
<listitem><para>Contains unix timestamp of the moment the client
48
did its initial connect. This field is used to kick clients that have not authenticated after one minute.</para></listitem>
54
<sect2><title>struct network</title>
65
xmlNodePtr current_server;
67
char *supported_modes[2];
69
struct transport_context *outgoing;
70
struct transport_context **incoming;
74
<para>Describes an IRC network that ctrlproxy is connected to.</para>
77
<varlistentry><term>xmlNodePtr xmlConf;</term>
78
<listitem><para>Points to XML node with configuration for this network.</para></listitem>
81
<varlistentry><term>char modes[255];</term>
82
<listitem><para>Array with modes of the user on this network. For modes that have been set, the index in this array has been set to 1. The rest of the array is set to 0. </para>
84
<para>For example, if mode <quote>i</quote>(invisible) is set on this user, <quote>modes['i']</quote> is set to 1.</para>
85
</listitem></varlistentry>
87
<varlistentry><term>xmlNodePtr servers;</term>
88
<listitem><para>Pointer to XML node <servers> for this server.</para></listitem></varlistentry>
90
<varlistentry><term>char *hostmask;</term>
91
<listitem><para>Hostmask that ctrlproxy uses to communicate to the server.</para></listitem>
94
<varlistentry><term>GList *channels;</term>
95
<listitem><para>List of <quote>struct channel</quote> pointers
96
with channels the user has joined on this network.</para></listitem>
99
<varlistentry><term>char authenticated;</term>
100
<listitem><para>Indicates whether the connection to this network is
101
established. It is set to true after a 004 message has been
102
received.</para></listitem>
105
<varlistentry><term>GList *clients;</term>
106
<listitem><para>List of <quote>struct client</quote> pointers
107
with all the clients that have connected to ctrlproxy
108
for this network.</para></listitem>
111
<varlistentry><term>xmlNodePtr current_server;</term>
112
<listitem><para>Pointer to XML node that contains the configuration
113
data of the current server ctrlproxy is connected to for
114
this network.</para></listitem>
116
<varlistentry><term>xmlNodePtr listen;</term>
117
<listitem><para>Pointer to XML node <listen>.</para></listitem>
120
<varlistentry><term>char *supported_modes[2];</term>
121
<listitem><para>Contains 2 arrays of modes that is supported by the remote server. This list is sent by the server after the connection has just been set-up.</para></listitem>
124
<varlistentry><term>char **features;</term>
125
<listitem><para>Array of options supported by the server. Same format as unix environment variables, though a value is not required.</para></listitem>
128
<varlistentry><term>struct transport_context *outgoing;</term>
129
<listitem><para>Transport context to use to communicate with the remote
130
server.</para></listitem>
133
<varlistentry><term>struct transport_context **incoming;</term>
134
<listitem><para>List with transport contexts for the clients that
135
are currently connected to ctrlproxy for this server.</para></listitem>
142
<sect1><title>State data</title>
144
<para>This section covers everything related to the current (known) state information of the network the user is on.</para>
146
<sect2><title>struct nick</title>
155
<para>Covers one nick in a certain channel. Mode is either a space, indicating
156
the user has no special rights, a '@' if the user is an operator or a '+' if
157
the user has voice.</para>
161
<sect2><title>struct channel</title>
176
<para>Covers one channel at a certain network that the user is currently on. Here is a small list with explanation of the various fields.</para>
179
<varlistentry><term>xmlNodePtr xmlConf</term>
180
<listitem><para>Pointer to XML node describing this channel.</para></listitem>
183
<varlistentry><term>char mode</term>
184
<listitem><para>Indicates whether the channel is private or secret. </para></listitem>
187
<varlistentry><term>char *topic</term>
188
<listitem><para>Pointer to string containing the topic of this channel. NULL if no topic has been set or if the topic is unknown.</para></listitem></varlistentry>
190
<varlistentry><term>char *modes[255]</term>
191
<listitem><para>Modes that have been set on this channel. FIXME</para></listitem></varlistentry>
192
<varlistentry><term>char introduced</term>
193
<listitem><para>Reserved for use by replication functions. Private. Do not use.</para></listitem></varlistentry>
194
<varlistentry><term>long limit</term>
195
<listitem><para>Maximum number of users on the channel. 0 means no limit has been set.</para></listitem></varlistentry>
196
<varlistentry><term>char *key</term>
197
<listitem><para>Key users have to enter to enter the channel. If no key is required, this field is set to NULL.</para></listitem></varlistentry>
198
<varlistentry><term>GList *nicks</term>
199
<listitem><para>List of <quote>struct nick</quote>, one for each user that is joined to the channel.</para></listitem></varlistentry>
203
<sect2><title>find_channel()</title>
206
struct channel *find_channel(struct network *st, char *name);
209
<para>Returns a pointer to the struct of the channel with the specified name on the specified network. Returns NULL if no channel struct was found.</para>
211
<para>Note that this function only works for channels the user has currently used.</para>
215
<sect2><title>find_nick()</title>
218
struct nick *find_nick(struct channel *c, char *name);
221
<para>Find data pointer to <quote>struct nick</quote> of the user with the specified name on the specified channel.</para>
223
<para>If the user was not found, NULL is returned.</para>
227
<sect2><title>gen_replication_network()</title>
230
GSList *gen_replication_network(struct network *s);
233
<para>Generates double-linked list of strings that need to be send
234
to a client to give it a good view of the channels that have been joined, the users on those channels and the modes of those channels. </para>
238
<sect2><title>gen_replication_channel()</title>
241
GSList *gen_replication_channel(struct channel *s, char *hostmask, char *nick);
244
<para>Generates double-linked list of strings that need to be send
245
to a client to give it a good view of a channel that ctrlproxy has joined. hostmask should be the name of the server the messages are coming from and nick the name of the user the replication is sent to.</para>
249
<sect2><title>default_replicate_function</title>
252
void default_replicate_function (struct network *, struct transport_context *);
253
extern void (*replicate_function) (struct network *, struct transport_context *);
256
<para>Default replication function. What this basically does is sending
257
the strings returned by gen_replication() to the specified transport_context.</para>
262
<sect1><title>Maintaining the main process</title>
265
extern GList *networks;
266
extern xmlNodePtr xmlNode_networks, xmlNode_plugins;
267
extern GList *plugins;
268
extern xmlDocPtr configuration;
269
extern GHookList data_hook;
272
<para>Pointers to various useful varables. The <parameter>xmlNode_*</parameter> variables point to
273
the <networks> and <plugins> elements in the rc file.</para>
275
<para><parameter>configuration</parameter> points to the top level XML document.</para>
277
<para><parameter>data_hook</parameter> can be used to register a function that should be called whenever ctrlproxy receives or sends IRC messages.</para>
279
<para><parameter>plugins</parameter> and <parameter>networks</parameter> contain
280
lists to all <quote>struct plugin</quote>s and <quote>struct network</quote>s, respectively.</para>
282
<sect2><title>network_add_listen()</title>
285
void network_add_listen(struct network *, xmlNodePtr);
288
<para>Add listener to specified network with configuration specified
289
in xmlNodePtr.</para>
293
<sect2><title>save_configuration()</title>
296
void save_configuration();
299
<para>Save the current state of the XML configuration of ctrlproxy
300
to the same file it was loaded from.</para>
304
<sect2><title>load_plugin()</title>
307
gboolean load_plugin(xmlNodePtr);
310
<para>Load plugin with specified configuration. xmlNodePtr should
311
point to a <plugin> element.</para>
315
<sect2><title>unload_plugin()</title>
318
gboolean unload_plugin(struct plugin *);
321
<para>Try to unload the specified plugin. Not all plugins support this at the moment. Returns TRUE if the unloading succeeded, FALSE otherwise. Failure of unloading may be caused by resources that are still in use.</para>
324
<sect2><title>plugin_loaded()</title>
327
gboolean plugin_loaded(char *name);
330
<para>Returns TRUE if a plugin with the specified name was loaded.</para>
334
<sect1><title>Line parsing/creation/handling</title>
336
<para>These functions all have to do with manipulating line structs.
337
Pretty much all internal functions of ctrlproxy work with these
338
instead of manipulating plain strings.</para>
342
enum data_direction direction;
344
struct network *network;
345
struct client *client;
347
char **args; /* NULL terminated */
351
/* for the options fields */
352
#define LINE_IS_PRIVATE 1
353
#define LINE_DONT_SEND 2
354
#define LINE_STOP_PROCESSING 4
356
enum data_direction { UNKNOWN = 0, TO_SERVER = 1, FROM_SERVER = 2 };
360
<varlistentry><term>enum data_direction direction;</term>
361
<listitem><para>Direction of this line. A value of TO_SERVER means it's going to the server, FROM_SERVER means it's coming from a remote IRC server. UNKNOWN is used in cases where the direction is not known.</para></listitem>
363
<varlistentry><term>int options;</term>
364
<listitem><para>Sum of one of LINE_IS_PRIVATE, LINE_DONT_SEND and LINE_STOP_PROCESSING. LINE_IS_PRIVATE means this line was send by a client and should not be sent to the other clients. LINE_DONT_SEND should be used to tell ctrlproxy to not send this line to its destination (either client or server). LINE_STOP_PROCESSING will stop further filtering of the line.</para>
367
<varlistentry><term>struct network *network;</term>
368
<listitem><para>Points to the network this line came from or is going to.</para></listitem>
370
<varlistentry><term>struct client *client;</term>
371
<listitem><para>Points to the client this line came from, if any. Set to NULL if unknown.</para></listitem>
373
<varlistentry><term>const char *origin;</term>
374
<listitem><para>Hostmask of the user who sent the message. NULL if unknown.</para></listitem>
376
<varlistentry><term>char **args;</term>
377
<listitem><para>IRC arguments/commands in an array. Last element is set to NULL.</para></listitem>
379
<varlistentry><term>size_t argc;</term>
380
<listitem><para>Contains number of arguments/commands in <parameter>args</parameter>.</para></listitem>
384
<sect2><title>linedup()</title>
387
struct line *linedup(struct line *l);
389
<para>Duplicate the given line struct.</para>
393
<sect2><title>irc_parse_line()</title>
396
struct line * irc_parse_line(char *data);
398
<para>Takes a string as sent by an IRC client or an IRC server and generates
399
a struct line.</para>
402
<sect2><title>virc_parse_line()</title>
405
struct line * virc_parse_line(char *origin, va_list ap);
406
struct line *irc_parse_line_args( char *origin, ... );
407
gboolean irc_send_args(struct transport_context *, ...);
409
<para>Generates a line struct with the hostmask specified in <parameter>origin</parameter> or NULL if none should be set.</para>
411
<para>For virc_parse_line(), the <parameter>ap</parameter> should be a list of strings
412
that are each that are a seperate part of the IRC line. The last argument
413
should be NULL to indicate the end of the list.</para>
415
<para>irc_parse_line_args() is similar to virc_parse_line(), except that now the commands don't need to be passed in a <parameter>va_list</parameter>, but can be passed as arguments.</para>
417
<para>irc_send_args() sends the specified commands, terminated by a NULL to the specified transport_context.</para>
421
<sect2><title>irc_line_string()</title>
424
char *irc_line_string(struct line *l);
425
char *irc_line_string_nl(struct line *l);
427
<para>Generate a string representation of a line struct in the format used
428
by IRC clients and servers.</para>
430
<para>irc_Line_string_nl() is similar to irc_line_string(), except that it
431
adds a newline and a carriage-return to the string (\r\n).</para>
435
<sect2><title>line_get_nick()</title>
438
char *line_get_nick(struct line *l);
440
<para>Get the nick name of the user that sent <parameter>l</parameter> or
441
NULL if the nick name was unknown.</para>
445
<sect2><title>free_line()</title>
448
void free_line(struct line *l);
450
<para>Free all data associated with <parameter>l</parameter>.</para>
454
<sect2><title>irc_sendf()</title>
457
gboolean irc_sendf(struct transport_context *, char *fmt, ...);
458
struct line *irc_parse_linef( char *fmt, ... );
460
<para>irc_sendf() sends the specified transport_context a IRC line. fmt
461
is a printf-like string and the remaining arguments correspond to
462
the data in <parameter>fmt</parameter>. See the printf manpage for details.</para>
464
<para>irc_parse_linef() is similar, but instead of sending the string it generates a struct line and returns it.</para>
468
<sect2><title>irc_send_line()</title>
471
int irc_send_line(struct transport_context *, struct line *l);
473
<para>Send the specified line to the specified transport_context. </para>
477
<sect2><title>clients_send()</title>
480
void clients_send(struct network *, struct line *, struct transport_context *exception);
482
<para>Send the specified line to all clients on the specified network, except for the client with transport_context <parameter>exception</parameter>. <parameter>exception</parameter> can be NULL.</para>
488
<sect1><title>General purpose functions</title>
489
<sect2><title>list_make_string()</title>
492
char *list_make_string(char **l);
494
<para>Creates a string with all the elements in string array <parameter>l</parameter>, seperated by spaces. The last element in <parameter>l</parameter> should be NULL.</para>
498
<sect2><title>xmLFindChildByName()</title>
501
xmlNodePtr xmlFindChildByName(xmlNodePtr parent, const xmlChar *name);
503
<para>Find a child node of the XML node <parameter>parent</parameter> that is an element with name <parameter>name</parameter> and return the xml Node pointer of it. </para>
505
<para>Returns NULL if no such child was found.</para>