mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 12:53:42 +02:00
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:
parent
513e140bce
commit
be6ba53fa4
35 changed files with 539 additions and 448 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue