2
ctrlproxy: A modular IRC proxy
3
(c) 2003 Jelmer Vernooij <jelmer@nl.linux.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
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.
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.
20
#include "internals.h"
23
static GList *transports = NULL;
26
void register_transport(struct transport *functions)
28
struct transport *functions1 = malloc(sizeof(struct transport));
29
memcpy(functions1, functions, sizeof(struct transport));
30
functions1->reference_count = 0;
31
transports = g_list_append(transports, functions1);
34
gboolean unregister_transport(char *name)
36
GList *gl = transports;
38
struct transport *t = (struct transport *)gl->data;
39
if(!strcmp(t->name, name)) {
40
if(t->reference_count == 0) {
41
transports = g_list_remove(transports, gl->data);
45
return FALSE; /* Transport is still in use */
53
struct transport_context *transport_connect(const char *name, xmlNodePtr p, receive_handler r_h, disconnect_handler d_h, void *d)
55
struct transport_context *ret;
57
GList *g = transports;
60
t = (struct transport *)g->data;
61
if(!strcmp(t->name, name))break;
69
ret = malloc(sizeof(struct transport_context));
70
ret->configuration = p;
74
ret->on_new_client = NULL;
75
ret->on_disconnect = d_h;
76
ret->on_receive = r_h;
78
if(!ret->functions->connect || ret->functions->connect(ret) == -1)
87
struct transport_context *transport_listen(const char *name, xmlNodePtr p, newclient_handler n_h, void *d)
89
struct transport_context *ret;
91
GList *g = transports;
94
t = (struct transport *)g->data;
95
if(!strcmp(t->name, name))break;
101
t->reference_count++;
103
ret = malloc(sizeof(struct transport_context));
104
ret->configuration = p;
107
ret->caller_data = d;
108
ret->on_new_client = n_h;
109
ret->on_disconnect = NULL;
110
ret->on_receive = NULL;
112
if(!ret->functions->listen || ret->functions->listen(ret) == -1)
121
void transport_free(struct transport_context *t)
124
t->functions->reference_count++;
125
if(t->functions->close) t->functions->close(t);
129
int transport_write(struct transport_context *t, char *l)
131
if(debugfd)fprintf(debugfd, "[TO] %s\n", l);
132
if(!t->functions->write)return -1;
133
return t->functions->write(t, l);
136
void transport_set_disconnect_handler(struct transport_context *t, disconnect_handler d_h)
138
t->on_disconnect = d_h;
141
void transport_set_receive_handler(struct transport_context *t, receive_handler r_h)
146
void transport_set_newclient_handler(struct transport_context *t, newclient_handler n_h)
148
t->on_new_client = n_h;
151
void transport_set_data(struct transport_context *t, void *data)
153
t->caller_data = data;