summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-02-17 19:44:22 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-02-17 19:44:22 +0000
commitbe6ba53fa47bc546279a2575523281845fe80da9 (patch)
tree2f08f6281cfbd38a1df2abe4fe69ccfd6f208f51 /src/irc
parent513e140bcebce617d6078a9532ab9976437c3ef6 (diff)
downloadirssi-be6ba53fa47bc546279a2575523281845fe80da9.zip
Config file: ircnets -> chatnets, added type = "chat protocol" to
chatnet config. Moved reading chatnets to core. Lots of other multiprotocol updates. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1237 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/core/irc-channels.c33
-rw-r--r--src/irc/core/irc-chatnets.c87
-rw-r--r--src/irc/core/irc-commands.c2
-rw-r--r--src/irc/core/irc-core.c38
-rw-r--r--src/irc/core/irc-queries.c17
-rw-r--r--src/irc/core/irc-servers-setup.c37
-rw-r--r--src/irc/core/irc-servers.c13
7 files changed, 71 insertions, 156 deletions
diff --git a/src/irc/core/irc-channels.c b/src/irc/core/irc-channels.c
index bdef9468..a083c9d0 100644
--- a/src/irc/core/irc-channels.c
+++ b/src/irc/core/irc-channels.c
@@ -62,22 +62,6 @@ IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server,
return rec;
}
-static void sig_channel_create(IRC_CHANNEL_REC **channel,
- void *chat_type, IRC_SERVER_REC *server,
- const char *name, void *automatic)
-{
- if (chat_protocol_lookup("IRC") != GPOINTER_TO_INT(chat_type))
- return;
-
- g_return_if_fail(server == NULL || IS_IRC_SERVER(server));
- g_return_if_fail(channel != NULL);
- g_return_if_fail(name != NULL);
-
- *channel = irc_channel_create(server, name,
- GPOINTER_TO_INT(automatic));
- signal_stop();
-}
-
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
{
if (!IS_IRC_CHANNEL(channel))
@@ -93,11 +77,11 @@ static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
#define get_join_key(key) \
(((key) == NULL || *(key) == '\0') ? "x" : (key))
-static void irc_channels_join(SERVER_REC *server, const char *data,
+static void irc_channels_join(IRC_SERVER_REC *server, const char *data,
int automatic)
{
CHANNEL_SETUP_REC *schannel;
- CHANNEL_REC *chanrec;
+ IRC_CHANNEL_REC *chanrec;
GString *outchans, *outkeys;
char *channels, *keys, *key;
char **chanlist, **keylist, **tmp, **tmpkey, *channel, *channame;
@@ -124,9 +108,9 @@ static void irc_channels_join(SERVER_REC *server, const char *data,
channel = ischannel(**tmp) ? g_strdup(*tmp) :
g_strdup_printf("#%s", *tmp);
- chanrec = channel_find(server, channel);
+ chanrec = irc_channel_find(server, channel);
if (chanrec == NULL) {
- schannel = channels_setup_find(channel, server->connrec->chatnet);
+ schannel = channel_setup_find(channel, server->connrec->chatnet);
g_string_sprintfa(outchans, "%s,", channel);
if (*tmpkey != NULL && **tmpkey != '\0')
@@ -140,8 +124,8 @@ static void irc_channels_join(SERVER_REC *server, const char *data,
g_string_sprintfa(outkeys, "%s,", get_join_key(key));
channame = channel + (channel[0] == '!' &&
channel[1] == '!');
- chanrec = channel_create(server->chat_type, server,
- channame, automatic);
+ chanrec = irc_channel_create(server, channame,
+ automatic);
if (key != NULL) chanrec->key = g_strdup(key);
}
g_free(channel);
@@ -197,12 +181,12 @@ static void sig_server_looking(SERVER_REC *server)
return;
server->channel_find_func = irc_channel_find_server;
- server->channels_join = irc_channels_join;
+ server->channels_join = (void (*) (SERVER_REC *, const char *, int))
+ irc_channels_join;
}
void irc_channels_init(void)
{
- signal_add("channel create", (SIGNAL_FUNC) sig_channel_create);
signal_add("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
@@ -220,7 +204,6 @@ void irc_channels_init(void)
void irc_channels_deinit(void)
{
- signal_remove("channel create", (SIGNAL_FUNC) sig_channel_create);
signal_remove("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
diff --git a/src/irc/core/irc-chatnets.c b/src/irc/core/irc-chatnets.c
index 40c4cae1..4ebf71f6 100644
--- a/src/irc/core/irc-chatnets.c
+++ b/src/irc/core/irc-chatnets.c
@@ -20,23 +20,23 @@
#include "module.h"
#include "signals.h"
-#include "servers.h"
-#include "chatnets.h"
-#include "special-vars.h"
#include "lib-config/iconfig.h"
#include "settings.h"
#include "irc-chatnets.h"
-static void ircnet_read(CONFIG_NODE *node)
+void ircnet_create(IRC_CHATNET_REC *rec)
{
- IRC_CHATNET_REC *rec;
-
- if (node == NULL || node->key == NULL)
- return;
+ g_return_if_fail(rec != NULL);
- rec = g_new0(IRC_CHATNET_REC, 1);
rec->chat_type = IRC_PROTOCOL;
+ chatnet_create(CHATNET(rec));
+}
+
+static void sig_chatnet_read(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
+{
+ if (!IS_IRC_CHATNET(rec))
+ return;
rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
@@ -46,18 +46,12 @@ static void ircnet_read(CONFIG_NODE *node)
rec->max_msgs = config_node_get_int(node, "max_msgs", 0);
rec->max_modes = config_node_get_int(node, "max_modes", 0);
rec->max_whois = config_node_get_int(node, "max_whois", 0);
-
- chatnet_read((CHATNET_REC *) rec, node);
}
-static void ircnet_save(IRC_CHATNET_REC *rec)
+static void sig_chatnet_saved(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
{
- CONFIG_NODE *node;
-
- g_return_if_fail(rec != NULL);
-
- node = iconfig_node_traverse("ircnets", TRUE);
- node = chatnet_save((CHATNET_REC *) rec, node);
+ if (!IS_IRC_CHATNET(rec))
+ return;
if (rec->max_cmds_at_once > 0)
iconfig_node_set_int(node, "cmdmax", rec->max_cmds_at_once);
@@ -76,63 +70,14 @@ static void ircnet_save(IRC_CHATNET_REC *rec)
iconfig_node_set_int(node, "max_whois", rec->max_whois);
}
-static void ircnet_remove(IRC_CHATNET_REC *rec)
-{
- CONFIG_NODE *node;
-
- g_return_if_fail(IS_IRC_CHATNET(rec));
-
- node = iconfig_node_traverse("ircnets", FALSE);
- if (node != NULL) iconfig_node_set_str(node, rec->name, NULL);
-}
-
-void ircnet_create(IRC_CHATNET_REC *rec)
-{
- g_return_if_fail(rec != NULL);
-
- rec->chat_type = IRC_PROTOCOL;
-
- ircnet_save(rec);
- chatnet_create((CHATNET_REC *) rec);
-}
-
-static void read_ircnets(void)
-{
- CONFIG_NODE *node;
- GSList *tmp, *next;
-
- for (tmp = chatnets; tmp != NULL; tmp = next) {
- CHATNET_REC *rec = tmp->data;
-
- next = tmp->next;
- if (IS_IRCNET(rec))
- chatnet_destroy(rec);
- }
-
- /* read ircnets */
- node = iconfig_node_traverse("ircnets", FALSE);
- if (node != NULL) {
- for (tmp = node->value; tmp != NULL; tmp = tmp->next)
- ircnet_read(tmp->data);
- }
-}
-
-static void sig_chatnet_removed(IRC_CHATNET_REC *rec)
-{
- if (IS_IRC_CHATNET(rec))
- ircnet_remove(rec);
-}
-
void irc_chatnets_init(void)
{
- read_ircnets();
-
- signal_add("chatnet removed", (SIGNAL_FUNC) sig_chatnet_removed);
- signal_add("setup reread", (SIGNAL_FUNC) read_ircnets);
+ signal_add("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
+ signal_add("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
}
void irc_chatnets_deinit(void)
{
- signal_remove("chatnet removed", (SIGNAL_FUNC) sig_chatnet_removed);
- signal_remove("setup reread", (SIGNAL_FUNC) read_ircnets);
+ signal_remove("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
+ signal_remove("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
}
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index 3c32b3ec..44abb416 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -78,7 +78,7 @@ static SERVER_REC *irc_connect_server(const char *data)
*password = '\0';
/* connect to server */
- conn = server_create_conn(addr, atoi(portstr), password, nick);
+ conn = server_create_conn(-1, addr, atoi(portstr), password, nick);
if (g_hash_table_lookup(optlist, "6") != NULL)
conn->family = AF_INET6;
else if (g_hash_table_lookup(optlist, "4") != NULL)
diff --git a/src/irc/core/irc-core.c b/src/irc/core/irc-core.c
index 0dc19443..6671c33a 100644
--- a/src/irc/core/irc-core.c
+++ b/src/irc/core/irc-core.c
@@ -26,6 +26,9 @@
#include "irc-channels.h"
#include "irc-queries.h"
+#include "irc-servers-setup.h"
+#include "channels-setup.h"
+
#include "ctcp.h"
#include "irc.h"
#include "netsplit.h"
@@ -45,6 +48,26 @@ void irc_log_deinit(void);
void lag_init(void);
void lag_deinit(void);
+static CHATNET_REC *create_chatnet(void)
+{
+ return g_malloc0(sizeof(IRC_CHATNET_REC));
+}
+
+static SERVER_SETUP_REC *create_server_setup(void)
+{
+ return g_malloc0(sizeof(IRC_SERVER_SETUP_REC));
+}
+
+static CHANNEL_SETUP_REC *create_channel_setup(void)
+{
+ return g_malloc0(sizeof(CHANNEL_SETUP_REC));
+}
+
+static SERVER_CONNECT_REC *create_server_connect(void)
+{
+ return g_malloc0(sizeof(IRC_SERVER_CONNECT_REC));
+}
+
void irc_core_init(void)
{
CHAT_PROTOCOL_REC *rec;
@@ -54,7 +77,22 @@ void irc_core_init(void)
rec->fullname = "Internet Relay Chat";
rec->chatnet = "ircnet";
+ rec->create_chatnet = create_chatnet;
+ rec->create_server_setup = create_server_setup;
+ rec->create_channel_setup = create_channel_setup;
+ rec->create_server_connect = create_server_connect;
+
+ rec->server_connect = (SERVER_REC *(*) (SERVER_CONNECT_REC *))
+ irc_server_connect;
+ rec->channel_create =
+ (CHANNEL_REC *(*) (SERVER_REC *, const char *, int))
+ irc_channel_create;
+ rec->query_create =
+ (QUERY_REC *(*) (const char *, const char *, int))
+ irc_query_create;
+
chat_protocol_register(rec);
+ g_free(rec);
irc_chatnets_init();
irc_servers_init();
diff --git a/src/irc/core/irc-queries.c b/src/irc/core/irc-queries.c
index 2204f2c3..87aed832 100644
--- a/src/irc/core/irc-queries.c
+++ b/src/irc/core/irc-queries.c
@@ -40,21 +40,6 @@ QUERY_REC *irc_query_create(const char *server_tag,
return rec;
}
-static void sig_query_create(QUERY_REC **query,
- void *chat_type, const char *server_tag,
- const char *nick, void *automatic)
-{
- if (chat_protocol_lookup("IRC") != GPOINTER_TO_INT(chat_type))
- return;
-
- g_return_if_fail(query != NULL);
- g_return_if_fail(nick != NULL);
-
- *query = irc_query_create(server_tag, nick,
- GPOINTER_TO_INT(automatic));
- signal_stop();
-}
-
static void event_privmsg(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *address)
{
@@ -92,14 +77,12 @@ static void event_nick(SERVER_REC *server, const char *data,
void irc_queries_init(void)
{
- signal_add("query create", (SIGNAL_FUNC) sig_query_create);
signal_add_last("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add("event nick", (SIGNAL_FUNC) event_nick);
}
void irc_queries_deinit(void)
{
- signal_remove("query create", (SIGNAL_FUNC) sig_query_create);
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_remove("event nick", (SIGNAL_FUNC) event_nick);
}
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index ec07420e..536ea310 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -45,23 +45,12 @@ static void sig_server_setup_fill_reconn(IRC_SERVER_CONNECT_REC *conn,
conn->max_query_chans = sserver->max_query_chans;
}
-/* Create server connection record. `address' is required, rest can be NULL */
-static void sig_server_create_conn(SERVER_CONNECT_REC **conn,
- IRC_CHATNET_REC *ircnet)
+static void sig_server_setup_fill_connect(IRC_SERVER_CONNECT_REC *conn)
{
- IRC_SERVER_CONNECT_REC *rec;
-
- g_return_if_fail(conn != NULL);
-
- if (ircnet != NULL && !IS_IRCNET(ircnet))
+ if (!IS_IRC_SERVER_CONNECT(conn))
return;
- rec = g_new0(IRC_SERVER_CONNECT_REC, 1);
- rec->chat_type = IRC_PROTOCOL;
- rec->alternate_nick = g_strdup(settings_get_str("alternate_nick"));
-
- *conn = (SERVER_CONNECT_REC *) rec;
- signal_stop();
+ conn->alternate_nick = g_strdup(settings_get_str("alternate_nick"));
}
static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
@@ -140,27 +129,17 @@ static void init_userinfo(void)
}
}
-static void sig_server_setup_read(SERVER_SETUP_REC **setuprec,
- CONFIG_NODE *node,
- IRC_CHATNET_REC *chatnet)
+static void sig_server_setup_read(IRC_SERVER_SETUP_REC *rec, CONFIG_NODE *node)
{
- IRC_SERVER_SETUP_REC *rec;
-
- g_return_if_fail(setuprec != NULL);
+ g_return_if_fail(rec != NULL);
g_return_if_fail(node != NULL);
- if (chatnet != NULL && !IS_IRCNET(chatnet))
+ if (!IS_IRC_SERVER_SETUP(rec))
return;
- rec = g_new0(IRC_SERVER_SETUP_REC, 1);
- rec->chat_type = IRC_PROTOCOL;
-
rec->max_cmds_at_once = config_node_get_int(node, "cmds_max_at_once", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmd_queue_speed", 0);
rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0);
-
- *setuprec = (SERVER_SETUP_REC *) rec;
- signal_stop();
}
static void sig_server_setup_saved(IRC_SERVER_SETUP_REC *rec,
@@ -184,7 +163,7 @@ void irc_servers_setup_init(void)
init_userinfo();
signal_add("server setup fill reconn", (SIGNAL_FUNC) sig_server_setup_fill_reconn);
- signal_add("server setup connect", (SIGNAL_FUNC) sig_server_create_conn);
+ signal_add("server setup fill connect", (SIGNAL_FUNC) sig_server_setup_fill_connect);
signal_add("server setup fill chatnet", (SIGNAL_FUNC) sig_server_setup_fill_chatnet);
signal_add("server setup read", (SIGNAL_FUNC) sig_server_setup_read);
signal_add("server setup saved", (SIGNAL_FUNC) sig_server_setup_saved);
@@ -193,7 +172,7 @@ void irc_servers_setup_init(void)
void irc_servers_setup_deinit(void)
{
signal_remove("server setup fill reconn", (SIGNAL_FUNC) sig_server_setup_fill_reconn);
- signal_remove("server setup connect", (SIGNAL_FUNC) sig_server_create_conn);
+ signal_remove("server setup fill connect", (SIGNAL_FUNC) sig_server_setup_fill_connect);
signal_remove("server setup fill chatnet", (SIGNAL_FUNC) sig_server_setup_fill_chatnet);
signal_remove("server setup read", (SIGNAL_FUNC) sig_server_setup_read);
signal_remove("server setup saved", (SIGNAL_FUNC) sig_server_setup_saved);
diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c
index 680f0c68..fd212a7d 100644
--- a/src/irc/core/irc-servers.c
+++ b/src/irc/core/irc-servers.c
@@ -177,17 +177,6 @@ IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn)
return server;
}
-static void sig_server_connect(IRC_SERVER_REC **server,
- IRC_SERVER_CONNECT_REC *conn)
-{
- g_return_if_fail(server != NULL);
- if (!IS_IRC_SERVER_CONNECT(conn))
- return;
-
- *server = irc_server_connect(conn);
- signal_stop();
-}
-
static void sig_connected(IRC_SERVER_REC *server)
{
if (!IS_IRC_SERVER(server))
@@ -452,7 +441,6 @@ void irc_servers_init(void)
cmd_tag = g_timeout_add(500, (GSourceFunc) servers_cmd_timeout, NULL);
signal_add("server connect free", (SIGNAL_FUNC) sig_server_connect_free);
- signal_add("server connect", (SIGNAL_FUNC) sig_server_connect);
signal_add_first("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
@@ -480,7 +468,6 @@ void irc_servers_deinit(void)
g_source_remove(cmd_tag);
signal_remove("server connect free", (SIGNAL_FUNC) sig_server_connect_free);
- signal_remove("server connect", (SIGNAL_FUNC) sig_server_connect);
signal_remove("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);