mirror of
https://github.com/irssi/irssi.git
synced 2025-04-26 13:01:11 -05:00
fix something
This commit is contained in:
parent
82f8ee57c3
commit
bee057ff21
@ -47,7 +47,7 @@ int chat_protocol_lookup(const char *name)
|
|||||||
g_return_val_if_fail(name != NULL, -1);
|
g_return_val_if_fail(name != NULL, -1);
|
||||||
|
|
||||||
rec = chat_protocol_find(name);
|
rec = chat_protocol_find(name);
|
||||||
return rec == NULL ? -1 : rec->id;
|
return rec == NULL ? -1 : rec->not_initialized ? CHAT_PROTOCOL_NOT_INITIALIZED : rec->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHAT_PROTOCOL_REC *chat_protocol_find(const char *name)
|
CHAT_PROTOCOL_REC *chat_protocol_find(const char *name)
|
||||||
@ -99,6 +99,22 @@ CHAT_PROTOCOL_REC *chat_protocol_find_net(GHashTable *optlist)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* Register new chat protocol. */
|
/* Register new chat protocol. */
|
||||||
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
||||||
{
|
{
|
||||||
@ -108,6 +124,10 @@ CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
|||||||
g_return_val_if_fail(rec != NULL, NULL);
|
g_return_val_if_fail(rec != NULL, NULL);
|
||||||
|
|
||||||
newrec = chat_protocol_find(rec->name);
|
newrec = chat_protocol_find(rec->name);
|
||||||
|
if (newrec != NULL && newrec->not_initialized) {
|
||||||
|
chat_protocol_destroy(newrec);
|
||||||
|
newrec = NULL;
|
||||||
|
}
|
||||||
created = newrec == NULL;
|
created = newrec == NULL;
|
||||||
if (newrec == NULL) {
|
if (newrec == NULL) {
|
||||||
newrec = g_new0(CHAT_PROTOCOL_REC, 1);
|
newrec = g_new0(CHAT_PROTOCOL_REC, 1);
|
||||||
@ -131,23 +151,6 @@ CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec)
|
|||||||
return newrec;
|
return newrec;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unregister chat protocol. */
|
/* Unregister chat protocol. */
|
||||||
void chat_protocol_unregister(const char *name)
|
void chat_protocol_unregister(const char *name)
|
||||||
{
|
{
|
||||||
@ -218,8 +221,10 @@ CHAT_PROTOCOL_REC *chat_protocol_get_unknown(const char *name)
|
|||||||
rec->create_chatnet = create_chatnet;
|
rec->create_chatnet = create_chatnet;
|
||||||
rec->create_server_setup = create_server_setup;
|
rec->create_server_setup = create_server_setup;
|
||||||
rec->create_channel_setup = create_channel_setup;
|
rec->create_channel_setup = create_channel_setup;
|
||||||
|
/*
|
||||||
rec->create_server_connect = create_server_connect;
|
rec->create_server_connect = create_server_connect;
|
||||||
rec->destroy_server_connect = destroy_server_connect;
|
rec->destroy_server_connect = destroy_server_connect;
|
||||||
|
*/
|
||||||
|
|
||||||
newrec = chat_protocol_register(rec);
|
newrec = chat_protocol_register(rec);
|
||||||
g_free(rec);
|
g_free(rec);
|
||||||
|
@ -35,6 +35,8 @@ void *chat_protocol_check_cast(void *object, int type_pos, const char *id);
|
|||||||
((object) == NULL ? chat_protocol_get_default() : \
|
((object) == NULL ? chat_protocol_get_default() : \
|
||||||
chat_protocol_find_id((object)->chat_type))
|
chat_protocol_find_id((object)->chat_type))
|
||||||
|
|
||||||
|
#define CHAT_PROTOCOL_NOT_INITIALIZED -2
|
||||||
|
|
||||||
/* Register new chat protocol. */
|
/* Register new chat protocol. */
|
||||||
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec);
|
CHAT_PROTOCOL_REC *chat_protocol_register(CHAT_PROTOCOL_REC *rec);
|
||||||
|
|
||||||
|
@ -24,12 +24,13 @@
|
|||||||
#include <irssi/src/core/special-vars.h>
|
#include <irssi/src/core/special-vars.h>
|
||||||
#include <irssi/src/lib-config/iconfig.h>
|
#include <irssi/src/lib-config/iconfig.h>
|
||||||
#include <irssi/src/core/settings.h>
|
#include <irssi/src/core/settings.h>
|
||||||
|
#include <irssi/src/core/misc.h>
|
||||||
|
|
||||||
#include <irssi/src/core/chat-protocols.h>
|
#include <irssi/src/core/chat-protocols.h>
|
||||||
#include <irssi/src/core/chatnets.h>
|
#include <irssi/src/core/chatnets.h>
|
||||||
#include <irssi/src/core/servers.h>
|
#include <irssi/src/core/servers.h>
|
||||||
|
|
||||||
GSList *chatnets; /* list of available chat networks */
|
GSList *chatnets, *chatnets_unavailable; /* list of available chat networks */
|
||||||
|
|
||||||
static void chatnet_config_save(CHATNET_REC *chatnet)
|
static void chatnet_config_save(CHATNET_REC *chatnet)
|
||||||
{
|
{
|
||||||
@ -60,6 +61,7 @@ static void chatnet_config_remove(CHATNET_REC *chatnet)
|
|||||||
void chatnet_create(CHATNET_REC *chatnet)
|
void chatnet_create(CHATNET_REC *chatnet)
|
||||||
{
|
{
|
||||||
g_return_if_fail(chatnet != NULL);
|
g_return_if_fail(chatnet != NULL);
|
||||||
|
g_return_if_fail(!CHAT_PROTOCOL(chatnet)->not_initialized);
|
||||||
|
|
||||||
chatnet->type = module_get_uniq_id("CHATNET", 0);
|
chatnet->type = module_get_uniq_id("CHATNET", 0);
|
||||||
if (g_slist_find(chatnets, chatnet) == NULL)
|
if (g_slist_find(chatnets, chatnet) == NULL)
|
||||||
@ -112,6 +114,21 @@ CHATNET_REC *chatnet_find(const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean chatnet_find_unavailable(const char *name)
|
||||||
|
{
|
||||||
|
CHAT_PROTOCOL_REC *proto;
|
||||||
|
|
||||||
|
if (i_slist_find_icase_string(chatnets_unavailable, name) != NULL)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
proto = CHAT_PROTOCOL(chatnet_find(name));
|
||||||
|
|
||||||
|
if (proto == NULL || proto->not_initialized)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void sig_connected(SERVER_REC *server)
|
static void sig_connected(SERVER_REC *server)
|
||||||
{
|
{
|
||||||
CHATNET_REC *rec;
|
CHATNET_REC *rec;
|
||||||
@ -136,14 +153,22 @@ static void chatnet_read(CONFIG_NODE *node)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
type = config_node_get_str(node, "type", NULL);
|
type = config_node_get_str(node, "type", NULL);
|
||||||
proto = type == NULL ? NULL : chat_protocol_find(type);
|
if (type == NULL) {
|
||||||
if (proto == NULL) {
|
proto = chat_protocol_get_default();
|
||||||
proto = type == NULL ? chat_protocol_get_default() :
|
} else {
|
||||||
chat_protocol_get_unknown(type);
|
proto = chat_protocol_find(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == NULL)
|
if (proto == NULL) {
|
||||||
|
/* protocol not loaded */
|
||||||
|
if (i_slist_find_icase_string(chatnets_unavailable, node->key) == NULL)
|
||||||
|
chatnets_unavailable =
|
||||||
|
g_slist_append(chatnets_unavailable, g_strdup(node->key));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (type == NULL) {
|
||||||
iconfig_node_set_str(node, "type", proto->name);
|
iconfig_node_set_str(node, "type", proto->name);
|
||||||
|
}
|
||||||
|
|
||||||
rec = proto->create_chatnet();
|
rec = proto->create_chatnet();
|
||||||
rec->type = module_get_uniq_id("CHATNET", 0);
|
rec->type = module_get_uniq_id("CHATNET", 0);
|
||||||
@ -167,6 +192,12 @@ static void read_chatnets(void)
|
|||||||
while (chatnets != NULL)
|
while (chatnets != NULL)
|
||||||
chatnet_destroy(chatnets->data);
|
chatnet_destroy(chatnets->data);
|
||||||
|
|
||||||
|
while (chatnets_unavailable != NULL) {
|
||||||
|
char *name = chatnets_unavailable->data;
|
||||||
|
chatnets_unavailable = g_slist_remove(chatnets_unavailable, name);
|
||||||
|
g_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
node = iconfig_node_traverse("chatnets", FALSE);
|
node = iconfig_node_traverse("chatnets", FALSE);
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
tmp = config_node_first(node->value);
|
tmp = config_node_first(node->value);
|
||||||
|
@ -25,6 +25,8 @@ void chatnet_destroy(CHATNET_REC *chatnet);
|
|||||||
|
|
||||||
/* Find the chat network by name */
|
/* Find the chat network by name */
|
||||||
CHATNET_REC *chatnet_find(const char *name);
|
CHATNET_REC *chatnet_find(const char *name);
|
||||||
|
/* Check if this chatnet is unavailable because the protocol is not loaded */
|
||||||
|
gboolean chatnet_find_unavailable(const char *name);
|
||||||
|
|
||||||
void chatnets_init(void);
|
void chatnets_init(void);
|
||||||
void chatnets_deinit(void);
|
void chatnets_deinit(void);
|
||||||
|
@ -305,6 +305,8 @@ static SERVER_CONNECT_REC *create_addr_conn(int chat_type, const char *address,
|
|||||||
proto = chat_type >= 0 ? chat_protocol_find_id(chat_type) :
|
proto = chat_type >= 0 ? chat_protocol_find_id(chat_type) :
|
||||||
chat_protocol_get_default();
|
chat_protocol_get_default();
|
||||||
|
|
||||||
|
g_return_val_if_fail(proto != NULL, NULL);
|
||||||
|
|
||||||
conn = proto->create_server_connect();
|
conn = proto->create_server_connect();
|
||||||
server_connect_ref(conn);
|
server_connect_ref(conn);
|
||||||
|
|
||||||
@ -469,6 +471,10 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
|
|||||||
chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
|
chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
|
||||||
if (chatnetrec == NULL && chatnet != NULL) {
|
if (chatnetrec == NULL && chatnet != NULL) {
|
||||||
/* chat network not found, create it. */
|
/* chat network not found, create it. */
|
||||||
|
if (chatnet_find_unavailable(chatnet)) {
|
||||||
|
/* no protocols loaded, skip loading servers */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
chatnetrec = chat_protocol_get_default()->create_chatnet();
|
chatnetrec = chat_protocol_get_default()->create_chatnet();
|
||||||
chatnetrec->chat_type = chat_protocol_get_default()->id;
|
chatnetrec->chat_type = chat_protocol_get_default()->id;
|
||||||
chatnetrec->name = g_strdup(chatnet);
|
chatnetrec->name = g_strdup(chatnet);
|
||||||
|
@ -583,6 +583,10 @@ static void perl_register_protocol(CHAT_PROTOCOL_REC *rec)
|
|||||||
SV *sv;
|
SV *sv;
|
||||||
|
|
||||||
chat_type = chat_protocol_lookup(rec->name);
|
chat_type = chat_protocol_lookup(rec->name);
|
||||||
|
if (chat_type == CHAT_PROTOCOL_NOT_INITIALIZED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_if_fail(chat_type >= 0);
|
g_return_if_fail(chat_type >= 0);
|
||||||
|
|
||||||
name = g_ascii_strdown(rec->name,-1);
|
name = g_ascii_strdown(rec->name,-1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user