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
This commit is contained in:
Timo Sirainen 2001-02-17 19:44:22 +00:00 committed by cras
commit be6ba53fa4
35 changed files with 539 additions and 448 deletions

View file

@ -50,8 +50,9 @@ libcore_a_SOURCES = \
write-buffer.c
structure_headers = \
chatnet-rec.h \
channel-rec.h \
channel-setup-rec.h \
chatnet-rec.h \
query-rec.h \
server-rec.h \
server-setup-rec.h \

View file

@ -0,0 +1,12 @@
int type; /* module_get_uniq_id("CHANNEL SETUP", 0) */
int chat_type; /* chat_protocol_lookup(xx) */
char *name;
char *chatnet;
char *password;
char *botmasks;
char *autosendcmd;
unsigned int autojoin:1;
GHashTable *module_data;

View file

@ -23,49 +23,13 @@
#include "lib-config/iconfig.h"
#include "settings.h"
#include "channels.h"
#include "channels-setup.h"
#include "chat-protocols.h"
#include "chatnets.h"
#include "servers-setup.h"
#include "channels-setup.h"
GSList *setupchannels;
static CHANNEL_SETUP_REC *channel_setup_read(CONFIG_NODE *node)
{
CHANNEL_SETUP_REC *rec;
char *channel, *password, *botmasks, *autosendcmd;
g_return_val_if_fail(node != NULL, NULL);
channel = config_node_get_str(node, "name", NULL);
if (channel == NULL) {
/* missing information.. */
return NULL;
}
password = config_node_get_str(node, "password", NULL);
botmasks = config_node_get_str(node, "botmasks", NULL);
autosendcmd = config_node_get_str(node, "autosendcmd", NULL);
rec = g_new(CHANNEL_SETUP_REC, 1);
rec->autojoin = config_node_get_bool(node, "autojoin", FALSE);
rec->name = g_strdup(channel);
rec->chatnet = g_strdup(config_node_get_str(node, "chatnet", NULL));
if (rec->chatnet == NULL) /* FIXME: remove this after .98... */ {
rec->chatnet = g_strdup(config_node_get_str(node, "ircnet", NULL));
if (rec->chatnet != NULL) {
iconfig_node_set_str(node, "chatnet", rec->chatnet);
iconfig_node_set_str(node, "ircnet", NULL);
}
}
rec->password = (password == NULL || *password == '\0') ? NULL : g_strdup(password);
rec->botmasks = (botmasks == NULL || *botmasks == '\0') ? NULL : g_strdup(botmasks);
rec->autosendcmd = (autosendcmd == NULL || *autosendcmd == '\0') ? NULL : g_strdup(autosendcmd);
setupchannels = g_slist_append(setupchannels, rec);
signal_emit("channel setup created", 2, rec, node);
return rec;
}
static void channel_setup_save(CHANNEL_SETUP_REC *channel)
{
CONFIG_NODE *parentnode, *node;
@ -88,15 +52,7 @@ static void channel_setup_save(CHANNEL_SETUP_REC *channel)
iconfig_node_set_str(node, "autosendcmd", channel->autosendcmd);
}
static void channel_config_remove(CHANNEL_SETUP_REC *channel)
{
CONFIG_NODE *node;
node = iconfig_node_traverse("channels", FALSE);
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
}
void channels_setup_create(CHANNEL_SETUP_REC *channel)
void channel_setup_create(CHANNEL_SETUP_REC *channel)
{
if (g_slist_find(setupchannels, channel) == NULL)
setupchannels = g_slist_append(setupchannels, channel);
@ -105,28 +61,37 @@ void channels_setup_create(CHANNEL_SETUP_REC *channel)
signal_emit("channel setup created", 1, channel);
}
static void channels_setup_destroy_rec(CHANNEL_SETUP_REC *channel)
static void channel_config_remove(CHANNEL_SETUP_REC *channel)
{
CONFIG_NODE *node;
node = iconfig_node_traverse("channels", FALSE);
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
}
static void channel_setup_destroy(CHANNEL_SETUP_REC *channel)
{
g_return_if_fail(channel != NULL);
setupchannels = g_slist_remove(setupchannels, channel);
signal_emit("channel setup destroyed", 1, channel);
g_free(channel->name);
g_free_not_null(channel->chatnet);
g_free_not_null(channel->password);
g_free_not_null(channel->botmasks);
g_free_not_null(channel->autosendcmd);
g_free(channel->name);
g_free(channel);
}
void channels_setup_destroy(CHANNEL_SETUP_REC *channel)
void channel_setup_remove(CHANNEL_SETUP_REC *channel)
{
channel_config_remove(channel);
channels_setup_destroy_rec(channel);
channel_setup_destroy(channel);
}
CHANNEL_SETUP_REC *channels_setup_find(const char *channel, const char *chatnet)
CHANNEL_SETUP_REC *channel_setup_find(const char *channel,
const char *chatnet)
{
GSList *tmp;
@ -143,13 +108,52 @@ CHANNEL_SETUP_REC *channels_setup_find(const char *channel, const char *chatnet)
return NULL;
}
static CHANNEL_SETUP_REC *channel_setup_read(CONFIG_NODE *node)
{
CHANNEL_SETUP_REC *rec;
CHATNET_REC *chatnetrec;
char *channel, *chatnet;
g_return_val_if_fail(node != NULL, NULL);
channel = config_node_get_str(node, "name", NULL);
chatnet = config_node_get_str(node, "chatnet", NULL);
if (chatnet == NULL) /* FIXME: remove this after .98... */ {
chatnet = g_strdup(config_node_get_str(node, "ircnet", NULL));
if (chatnet != NULL) {
iconfig_node_set_str(node, "chatnet", chatnet);
iconfig_node_set_str(node, "ircnet", NULL);
}
}
chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
if (channel == NULL || chatnetrec == NULL) {
/* missing information.. */
return NULL;
}
rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
rec->type = module_get_uniq_id("CHANNEL SETUP", 0);
rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id;
rec->autojoin = config_node_get_bool(node, "autojoin", FALSE);
rec->name = g_strdup(channel);
rec->chatnet = g_strdup(chatnetrec != NULL ? chatnetrec->name : chatnet);
rec->password = g_strdup(config_node_get_str(node, "password", NULL));
rec->botmasks = g_strdup(config_node_get_str(node, "botmasks", NULL));
rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));
setupchannels = g_slist_append(setupchannels, rec);
signal_emit("channel setup created", 2, rec, node);
return rec;
}
static void channels_read_config(void)
{
CONFIG_NODE *node;
GSList *tmp;
while (setupchannels != NULL)
channels_setup_destroy_rec(setupchannels->data);
channel_setup_destroy(setupchannels->data);
/* Read channels */
node = iconfig_node_traverse("channels", FALSE);
@ -161,6 +165,7 @@ static void channels_read_config(void)
void channels_setup_init(void)
{
setupchannels = NULL;
source_host_ok = FALSE;
signal_add("setup reread", (SIGNAL_FUNC) channels_read_config);
@ -170,7 +175,7 @@ void channels_setup_init(void)
void channels_setup_deinit(void)
{
while (setupchannels != NULL)
channels_setup_destroy(setupchannels->data);
channel_setup_destroy(setupchannels->data);
signal_remove("setup reread", (SIGNAL_FUNC) channels_read_config);
signal_remove("irssi init read settings", (SIGNAL_FUNC) channels_read_config);

View file

@ -3,16 +3,14 @@
#include "modules.h"
#define CHANNEL_SETUP(server) \
MODULE_CHECK_CAST(server, CHANNEL_SETUP_REC, type, "CHANNEL SETUP")
#define IS_CHANNEL_SETUP(server) \
(CHANNEL_SETUP(server) ? TRUE : FALSE)
struct _CHANNEL_SETUP_REC {
char *name;
char *chatnet;
char *password;
char *botmasks;
char *autosendcmd;
unsigned int autojoin:1;
GHashTable *module_data;
#include "channel-setup-rec.h"
};
extern GSList *setupchannels;
@ -20,11 +18,11 @@ extern GSList *setupchannels;
void channels_setup_init(void);
void channels_setup_deinit(void);
void channels_setup_create(CHANNEL_SETUP_REC *channel);
void channels_setup_destroy(CHANNEL_SETUP_REC *channel);
void channel_setup_create(CHANNEL_SETUP_REC *channel);
void channel_setup_remove(CHANNEL_SETUP_REC *channel);
CHANNEL_SETUP_REC *channels_setup_find(const char *channel,
const char *chatnet);
CHANNEL_SETUP_REC *channel_setup_find(const char *channel,
const char *chatnet);
#define channel_chatnet_match(rec, chatnet) \
((rec) == NULL || (rec)[0] == '\0' || \

View file

@ -30,21 +30,6 @@
GSList *channels; /* List of all channels */
/* Create a new channel */
CHANNEL_REC *channel_create(int chat_type, SERVER_REC *server,
const char *name, int automatic)
{
CHANNEL_REC *channel;
g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
g_return_val_if_fail(name != NULL, NULL);
channel = NULL;
signal_emit("channel create", 5, &channel, GINT_TO_POINTER(chat_type),
server, name, GINT_TO_POINTER(automatic));
return channel;
}
void channel_init(CHANNEL_REC *channel, int automatic)
{
g_return_if_fail(channel != NULL);
@ -173,7 +158,7 @@ void channel_send_autocommands(CHANNEL_REC *channel)
g_return_if_fail(IS_CHANNEL(channel));
rec = channels_setup_find(channel->name, channel->server->connrec->chatnet);
rec = channel_setup_find(channel->name, channel->server->connrec->chatnet);
if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd)
return;

View file

@ -18,10 +18,6 @@ struct _CHANNEL_REC {
extern GSList *channels;
/* Create a new channel */
CHANNEL_REC *channel_create(int chat_type, SERVER_REC *server,
const char *name, int automatic);
/* Create new channel record */
void channel_init(CHANNEL_REC *channel, int automatic);
void channel_destroy(CHANNEL_REC *channel);

View file

@ -19,12 +19,19 @@
*/
#include "module.h"
#include "modules.h"
#include "signals.h"
#include "chat-protocols.h"
static int id_counter;
#include "chatnets.h"
#include "servers.h"
#include "servers-setup.h"
#include "channels-setup.h"
GSList *chat_protocols;
static CHAT_PROTOCOL_REC *default_proto;
void *chat_protocol_check_cast(void *object, int type_pos, const char *id)
{
return object == NULL ||
@ -75,18 +82,48 @@ CHAT_PROTOCOL_REC *chat_protocol_find_id(int id)
return NULL;
}
/* Register new chat protocol. */
void chat_protocol_register(CHAT_PROTOCOL_REC *rec)
CHAT_PROTOCOL_REC *chat_protocol_find_net(GHashTable *optlist)
{
g_return_if_fail(rec != NULL);
GSList *tmp;
if (chat_protocol_find(rec->name) != NULL)
return;
g_return_val_if_fail(optlist != NULL, NULL);
rec->id = ++id_counter;
chat_protocols = g_slist_append(chat_protocols, rec);
for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) {
CHAT_PROTOCOL_REC *rec = tmp->data;
signal_emit("chat protocol created", 1, rec);
if (g_hash_table_lookup(optlist, rec->chatnet) != NULL)
return rec;
}
return NULL;
}
/* Register new chat protocol. */
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec)
{
CHAT_PROTOCOL_REC *newrec;
g_return_val_if_fail(rec != NULL, NULL);
newrec = chat_protocol_find(rec->name);
if (newrec == NULL)
newrec = g_new0(CHAT_PROTOCOL_REC, 1);
else if (rec->fullname != NULL) {
/* already registered */
return newrec;
}
memcpy(newrec, rec, sizeof(CHAT_PROTOCOL_REC));
newrec->id = module_get_uniq_id_str("PROTOCOL", rec->name);
newrec->name = g_strdup(rec->name);
chat_protocols = g_slist_append(chat_protocols, newrec);
if (default_proto == NULL)
chat_protocol_set_default(newrec);
signal_emit("chat protocol created", 1, newrec);
return newrec;
}
static void chat_protocol_destroy(CHAT_PROTOCOL_REC *rec)
@ -94,7 +131,15 @@ static void chat_protocol_destroy(CHAT_PROTOCOL_REC *rec)
g_return_if_fail(rec != NULL);
chat_protocols = g_slist_remove(chat_protocols, rec);
if (default_proto == rec) {
chat_protocol_set_default(chat_protocols == NULL ? NULL :
chat_protocols->data);
}
signal_emit("chat protocol destroyed", 1, rec);
g_free(rec->name);
g_free(rec);
}
@ -109,9 +154,64 @@ void chat_protocol_unregister(const char *name)
if (rec != NULL) chat_protocol_destroy(rec);
}
/* Default chat protocol to use */
void chat_protocol_set_default(CHAT_PROTOCOL_REC *rec)
{
default_proto = rec;
}
CHAT_PROTOCOL_REC *chat_protocol_get_default(void)
{
return default_proto;
}
static CHATNET_REC *create_chatnet(void)
{
return g_new0(CHATNET_REC, 1);
}
static SERVER_SETUP_REC *create_server_setup(void)
{
return g_new0(SERVER_SETUP_REC, 1);
}
static CHANNEL_SETUP_REC *create_channel_setup(void)
{
return g_new0(CHANNEL_SETUP_REC, 1);
}
static SERVER_CONNECT_REC *create_server_connect(void)
{
return g_new0(SERVER_CONNECT_REC, 1);
}
/* Return "unknown chat protocol" record. Used when protocol name is
specified but it isn't registered yet. */
CHAT_PROTOCOL_REC *chat_protocol_get_unknown(const char *name)
{
CHAT_PROTOCOL_REC *rec, *newrec;
g_return_val_if_fail(name != NULL, NULL);
rec = chat_protocol_find(name);
if (rec != NULL)
return rec;
rec = g_new0(CHAT_PROTOCOL_REC, 1);
rec->name = (char *) name;
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;
newrec = chat_protocol_register(rec);
g_free(rec);
return newrec;
}
void chat_protocols_init(void)
{
id_counter = 0;
default_proto = NULL;
chat_protocols = NULL;
}

View file

@ -7,6 +7,15 @@ typedef struct {
char *name;
char *fullname;
char *chatnet;
CHATNET_REC *(*create_chatnet) (void);
SERVER_SETUP_REC *(*create_server_setup) (void);
CHANNEL_SETUP_REC *(*create_channel_setup) (void);
SERVER_CONNECT_REC *(*create_server_connect) (void);
SERVER_REC *(*server_connect) (SERVER_CONNECT_REC *);
CHANNEL_REC *(*channel_create) (SERVER_REC *, const char *, int);
QUERY_REC *(*query_create) (const char *, const char *, int);
} CHAT_PROTOCOL_REC;
extern GSList *chat_protocols;
@ -16,8 +25,12 @@ extern GSList *chat_protocols;
offsetof(cast, type_field), id))
void *chat_protocol_check_cast(void *object, int type_pos, const char *id);
#define CHAT_PROTOCOL(object) \
((object) == NULL ? chat_protocol_get_default() : \
chat_protocol_find_id((object)->chat_type))
/* Register new chat protocol. */
void chat_protocol_register(CHAT_PROTOCOL_REC *rec);
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec);
/* Unregister chat protocol. */
void chat_protocol_unregister(const char *name);
@ -26,6 +39,15 @@ void chat_protocol_unregister(const char *name);
int chat_protocol_lookup(const char *name);
CHAT_PROTOCOL_REC *chat_protocol_find(const char *name);
CHAT_PROTOCOL_REC *chat_protocol_find_id(int id);
CHAT_PROTOCOL_REC *chat_protocol_find_net(GHashTable *optlist);
/* Default chat protocol to use */
void chat_protocol_set_default(CHAT_PROTOCOL_REC *rec);
CHAT_PROTOCOL_REC *chat_protocol_get_default(void);
/* Return "unknown chat protocol" record. Used when protocol name is
specified but it isn't registered yet. */
CHAT_PROTOCOL_REC *chat_protocol_get_unknown(const char *name);
void chat_protocols_init(void);
void chat_protocols_deinit(void);

View file

@ -25,42 +25,36 @@
#include "lib-config/iconfig.h"
#include "settings.h"
#include "chat-protocols.h"
#include "chatnets.h"
#include "servers.h"
GSList *chatnets; /* list of available chat networks */
void chatnet_read(CHATNET_REC *chatnet, CONFIG_NODE *node)
static void chatnet_config_save(CHATNET_REC *chatnet)
{
g_return_if_fail(chatnet != NULL);
g_return_if_fail(node != NULL);
g_return_if_fail(node->key != NULL);
chatnet->type = module_get_uniq_id("CHATNET", 0);
chatnet->name = g_strdup(node->key);
chatnet->nick = g_strdup(config_node_get_str(node, "nick", NULL));
chatnet->username = g_strdup(config_node_get_str(node, "username", NULL));
chatnet->realname = g_strdup(config_node_get_str(node, "realname", NULL));
chatnet->own_host = g_strdup(config_node_get_str(node, "host", NULL));
chatnet->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));
chatnets = g_slist_append(chatnets, chatnet);
}
CONFIG_NODE *chatnet_save(CHATNET_REC *chatnet, CONFIG_NODE *node)
{
g_return_val_if_fail(node != NULL, NULL);
g_return_val_if_fail(chatnet != NULL, NULL);
CONFIG_NODE *node;
node = iconfig_node_traverse("chatnets", TRUE);
node = config_node_section(node, chatnet->name, NODE_TYPE_BLOCK);
iconfig_node_clear(node);
iconfig_node_set_str(node, "type", chat_protocol_find_id(chatnet->chat_type)->name);
iconfig_node_set_str(node, "nick", chatnet->nick);
iconfig_node_set_str(node, "username", chatnet->username);
iconfig_node_set_str(node, "realname", chatnet->realname);
iconfig_node_set_str(node, "host", chatnet->own_host);
iconfig_node_set_str(node, "autosendcmd", chatnet->autosendcmd);
return node;
signal_emit("chatnet saved", 2, chatnet, node);
}
static void chatnet_config_remove(CHATNET_REC *chatnet)
{
CONFIG_NODE *node;
node = iconfig_node_traverse("chatnets", FALSE);
if (node != NULL) iconfig_node_set_str(node, chatnet->name, NULL);
}
void chatnet_create(CHATNET_REC *chatnet)
@ -71,6 +65,7 @@ void chatnet_create(CHATNET_REC *chatnet)
if (g_slist_find(chatnets, chatnet) == NULL)
chatnets = g_slist_append(chatnets, chatnet);
chatnet_config_save(chatnet);
signal_emit("chatnet created", 1, chatnet);
}
@ -79,6 +74,8 @@ void chatnet_remove(CHATNET_REC *chatnet)
g_return_if_fail(IS_CHATNET(chatnet));
signal_emit("chatnet removed", 1, chatnet);
chatnet_config_remove(chatnet);
chatnet_destroy(chatnet);
}
@ -89,16 +86,16 @@ void chatnet_destroy(CHATNET_REC *chatnet)
chatnets = g_slist_remove(chatnets, chatnet);
signal_emit("chatnet destroyed", 1, chatnet);
g_free(chatnet->name);
g_free_not_null(chatnet->nick);
g_free_not_null(chatnet->username);
g_free_not_null(chatnet->realname);
g_free_not_null(chatnet->own_host);
g_free_not_null(chatnet->autosendcmd);
g_free(chatnet->name);
g_free(chatnet);
}
/* Find the irc network by name */
/* Find the chat network by name */
CHATNET_REC *chatnet_find(const char *name)
{
GSList *tmp;
@ -129,17 +126,78 @@ static void sig_connected(SERVER_REC *server)
eval_special_string(rec->autosendcmd, "", server, NULL);
}
static void chatnet_read(CONFIG_NODE *node)
{
CHAT_PROTOCOL_REC *proto;
CHATNET_REC *rec;
char *type;
if (node == NULL || node->key == NULL)
return;
type = config_node_get_str(node, "type", NULL);
proto = type == NULL ? NULL : chat_protocol_find(type);
if (proto == NULL) {
proto = type == NULL ? chat_protocol_get_default() :
chat_protocol_get_unknown(type);
}
if (type == NULL)
iconfig_node_set_str(node, "type", proto->name);
rec = proto->create_chatnet();
rec->type = module_get_uniq_id("CHATNET", 0);
rec->chat_type = proto->id;
rec->name = g_strdup(node->key);
rec->nick = g_strdup(config_node_get_str(node, "nick", NULL));
rec->username = g_strdup(config_node_get_str(node, "username", NULL));
rec->realname = g_strdup(config_node_get_str(node, "realname", NULL));
rec->own_host = g_strdup(config_node_get_str(node, "host", NULL));
rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));
chatnets = g_slist_append(chatnets, rec);
signal_emit("chatnet read", 2, rec, node);
}
static void read_chatnets(void)
{
CONFIG_NODE *node;
while (chatnets != NULL)
chatnet_destroy(chatnets->data);
node = iconfig_node_traverse("chatnets", FALSE);
if (node == NULL) {
/* FIXME: remove after .98 */
node = iconfig_node_traverse("ircnets", FALSE);
if (node != NULL) {
/* very dirty method - doesn't update hashtables
but this will do temporarily.. */
g_free(node->key);
node->key = g_strdup("chatnets");
}
}
if (node != NULL)
g_slist_foreach(node->value, (GFunc) chatnet_read, NULL);
}
void chatnets_init(void)
{
chatnets = NULL;
signal_add("event connected", (SIGNAL_FUNC) sig_connected);
signal_add("setup reread", (SIGNAL_FUNC) read_chatnets);
signal_add_first("irssi init read settings", (SIGNAL_FUNC) read_chatnets);
}
void chatnets_deinit(void)
{
while (chatnets != NULL)
chatnet_destroy(chatnets->data);
module_uniq_destroy("CHATNET");
signal_remove("event connected", (SIGNAL_FUNC) sig_connected);
module_uniq_destroy("CHATNET");
signal_remove("setup reread", (SIGNAL_FUNC) read_chatnets);
signal_remove("irssi init read settings", (SIGNAL_FUNC) read_chatnets);
}

View file

@ -16,10 +16,6 @@ struct _CHATNET_REC {
extern GSList *chatnets; /* list of available chat networks */
/* read/save to configuration file */
void chatnet_read(CHATNET_REC *chatnet, CONFIG_NODE *node);
CONFIG_NODE *chatnet_save(CHATNET_REC *chatnet, CONFIG_NODE *parentnode);
/* add the chatnet to chat networks list */
void chatnet_create(CHATNET_REC *chatnet);
/* remove the chatnet from chat networks list */
@ -27,7 +23,7 @@ void chatnet_remove(CHATNET_REC *chatnet);
/* destroy the chatnet structure. doesn't remove from config file */
void chatnet_destroy(CHATNET_REC *chatnet);
/* Find the irc network by name */
/* Find the chat network by name */
CHATNET_REC *chatnet_find(const char *name);
void chatnets_init(void);

View file

@ -224,7 +224,7 @@ void log_write_rec(LOG_REC *log, const char *str, int level)
}
LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
SERVER_REC *server)
const char *servertag)
{
GSList *tmp;
@ -235,8 +235,8 @@ LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
LOG_ITEM_REC *rec = tmp->data;
if (rec->type == type && g_strcasecmp(rec->name, item) == 0 &&
(rec->servertag == NULL || (server != NULL &&
g_strcasecmp(rec->servertag, server->tag) == 0)))
(rec->servertag == NULL || (servertag != NULL &&
g_strcasecmp(rec->servertag, servertag) == 0)))
return rec;
}
@ -268,8 +268,9 @@ void log_file_write(SERVER_REC *server, const char *item, int level,
if (rec->items == NULL)
fallbacks = g_slist_append(fallbacks, rec);
else if (item != NULL && log_item_find(rec, LOG_ITEM_TARGET,
item, server) != NULL)
else if (item != NULL &&
log_item_find(rec, LOG_ITEM_TARGET, item,
server->tag) != NULL)
log_write_rec(rec, str, level);
}
@ -367,20 +368,20 @@ LOG_REC *log_create_rec(const char *fname, int level)
}
void log_item_add(LOG_REC *log, int type, const char *name,
SERVER_REC *server)
const char *servertag)
{
LOG_ITEM_REC *rec;
g_return_if_fail(log != NULL);
g_return_if_fail(name != NULL);
if (log_item_find(log, type, name, server))
if (log_item_find(log, type, name, servertag))
return;
rec = g_new0(LOG_ITEM_REC, 1);
rec->type = type;
rec->name = g_strdup(name);
rec->servertag = server == NULL ? NULL : g_strdup(server->tag);
rec->servertag = g_strdup(servertag);
log->items = g_slist_append(log->items, rec);
}

View file

@ -38,10 +38,10 @@ void log_close(LOG_REC *log);
LOG_REC *log_find(const char *fname);
void log_item_add(LOG_REC *log, int type, const char *name,
SERVER_REC *server);
const char *servertag);
void log_item_destroy(LOG_REC *log, LOG_ITEM_REC *item);
LOG_ITEM_REC *log_item_find(LOG_REC *log, int type, const char *item,
SERVER_REC *server);
const char *servertag);
void log_file_write(SERVER_REC *server, const char *item, int level,
const char *str, int no_fallbacks);

View file

@ -27,20 +27,6 @@
GSList *queries;
/* Create a new query */
QUERY_REC *query_create(int chat_type, const char *server_tag,
const char *nick, int automatic)
{
QUERY_REC *query;
g_return_val_if_fail(nick != NULL, NULL);
query = NULL;
signal_emit("query create", 5, &query, GINT_TO_POINTER(chat_type),
server_tag, nick, GINT_TO_POINTER(automatic));
return query;
}
void query_init(QUERY_REC *query, int automatic)
{
g_return_if_fail(query != NULL);

View file

@ -21,10 +21,6 @@ extern GSList *queries;
void query_init(QUERY_REC *query, int automatic);
void query_destroy(QUERY_REC *query);
/* Create a new query */
QUERY_REC *query_create(int chat_type, const char *server_tag,
const char *nick, int automatic);
/* Find query by name, if `server' is NULL, search from all servers */
QUERY_REC *query_find(SERVER_REC *server, const char *nick);

View file

@ -24,9 +24,10 @@
#include "lib-config/iconfig.h"
#include "settings.h"
#include "chat-protocols.h"
#include "chatnets.h"
#include "servers.h"
#include "servers-setup.h"
#include "chatnets.h"
GSList *setupservers;
@ -164,9 +165,10 @@ static void server_setup_fill_chatnet(SERVER_CONNECT_REC *conn,
}
static SERVER_CONNECT_REC *
create_addr_conn(const char *address, int port,
create_addr_conn(int chat_type, const char *address, int port,
const char *password, const char *nick)
{
CHAT_PROTOCOL_REC *proto;
SERVER_CONNECT_REC *conn;
SERVER_SETUP_REC *sserver;
CHATNET_REC *chatnet;
@ -174,19 +176,20 @@ create_addr_conn(const char *address, int port,
g_return_val_if_fail(address != NULL, NULL);
sserver = server_setup_find(address, port);
chatnet = sserver == NULL || sserver->chatnet == NULL ? NULL :
chatnet_find(sserver->chatnet);
conn = NULL;
signal_emit("server setup connect", 2, &conn, chatnet);
if (conn == NULL) {
/* no chat protocol wanted this server? */
return NULL;
}
if (sserver != NULL) chat_type = sserver->chat_type;
proto = chat_type >= 0 ? chat_protocol_find_id(chat_type) :
chat_protocol_get_default();
conn = proto->create_server_connect();
conn->chat_type = proto->id;
/* fill in the defaults */
server_setup_fill(conn, address, port);
/* fill the rest from chat network settings */
chatnet = sserver == NULL || sserver->chatnet == NULL ? NULL :
chatnet_find(sserver->chatnet);
if (chatnet != NULL)
server_setup_fill_chatnet(conn, chatnet);
@ -204,6 +207,7 @@ create_addr_conn(const char *address, int port,
conn->nick = g_strdup(nick);
}
signal_emit("server setup fill connect", 1, conn);
return conn;
}
@ -239,26 +243,27 @@ create_chatnet_conn(const char *dest, int port,
}
return bestrec == NULL ? NULL :
create_addr_conn(bestrec->address, 0, NULL, nick);
create_addr_conn(bestrec->chat_type,
bestrec->address, 0, NULL, nick);
}
/* Create server connection record. `dest' is required, rest can be NULL.
`dest' is either a server address or chat network */
SERVER_CONNECT_REC *
server_create_conn(const char *dest, int port,
server_create_conn(int chat_type, const char *dest, int port,
const char *password, const char *nick)
{
SERVER_CONNECT_REC *rec;
g_return_val_if_fail(dest != NULL, NULL);
if (chatnet_find(dest)) {
if (chatnet_find(dest) != NULL) {
rec = create_chatnet_conn(dest, port, password, nick);
if (rec != NULL)
return rec;
}
return create_addr_conn(dest, port, password, nick);
return create_addr_conn(chat_type, dest, port, password, nick);
}
/* Find matching server from setup. Try to find record with a same port,
@ -296,6 +301,7 @@ SERVER_SETUP_REC *server_setup_find_port(const char *address, int port)
static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
{
SERVER_SETUP_REC *rec;
CHATNET_REC *chatnetrec;
char *server, *chatnet;
int port;
@ -322,21 +328,28 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
chatnet = config_node_get_str(node, "chatnet", NULL);
}
}
signal_emit("server setup read", 3, &rec, node,
chatnet == NULL ? NULL : chatnet_find(chatnet));
if (rec == NULL) {
/* no chat protocol wanted this server? */
return NULL;
chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
if (chatnetrec == NULL && chatnet != NULL) {
/* chat network not found, create it. */
chatnetrec = chat_protocol_get_default()->create_chatnet();
chatnetrec->chat_type = chat_protocol_get_default()->id;
chatnetrec->name = g_strdup(chatnet);
chatnet_create(chatnetrec);
}
rec = CHAT_PROTOCOL(chatnetrec)->create_server_setup();
rec->type = module_get_uniq_id("SERVER SETUP", 0);
rec->chatnet = g_strdup(chatnet);
rec->chat_type = chatnetrec->chat_type;
rec->chatnet = g_strdup(chatnetrec->name);
rec->address = g_strdup(server);
rec->password = g_strdup(config_node_get_str(node, "password", NULL));
rec->port = port;
rec->autoconnect = config_node_get_bool(node, "autoconnect", FALSE);
rec->own_host = g_strdup(config_node_get_str(node, "own_host", NULL));
signal_emit("server setup read", 2, rec, node);
setupservers = g_slist_append(setupservers, rec);
return rec;
}
@ -387,8 +400,8 @@ static void server_setup_destroy(SERVER_SETUP_REC *rec)
g_free_not_null(rec->own_host);
g_free_not_null(rec->own_ip);
g_free_not_null(rec->chatnet);
g_free(rec->address);
g_free_not_null(rec->password);
g_free(rec->address);
g_free(rec);
}
@ -443,6 +456,7 @@ void servers_setup_init(void)
settings_add_int("proxy", "proxy_port", 6667);
settings_add_str("proxy", "proxy_string", "CONNECT %s %d");
setupservers = NULL;
source_host_ip = NULL;
read_settings();

View file

@ -27,7 +27,7 @@ void server_setup_fill_reconn(SERVER_CONNECT_REC *conn,
/* Create server connection record. `dest' is required, rest can be NULL.
`dest' is either a server address or chat network */
SERVER_CONNECT_REC *
server_create_conn(const char *dest, int port,
server_create_conn(int chat_type, const char *dest, int port,
const char *password, const char *nick);
/* Find matching server from setup. Try to find record with a same port,

View file

@ -281,13 +281,9 @@ int server_start_connect(SERVER_REC *server)
/* Connect to server */
SERVER_REC *server_connect(SERVER_CONNECT_REC *conn)
{
SERVER_REC *server;
g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL);
server = NULL;
signal_emit("server connect", 2, &server, conn);
return server;
return CHAT_PROTOCOL(conn)->server_connect(conn);
}
static int server_remove_channels(SERVER_REC *server)