1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-15 04:28:09 -04:00

fix crash when loading server without chatnet

This commit is contained in:
Ailin Nemui 2022-07-24 19:31:52 +02:00
parent 722d3c4c3d
commit 252656cad4

View File

@ -448,6 +448,7 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
{ {
SERVER_SETUP_REC *rec; SERVER_SETUP_REC *rec;
CHATNET_REC *chatnetrec; CHATNET_REC *chatnetrec;
CHAT_PROTOCOL_REC *proto;
char *server, *chatnet, *family; char *server, *chatnet, *family;
int port; int port;
char *value = NULL; char *value = NULL;
@ -468,26 +469,39 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
rec = NULL; rec = NULL;
chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet); if (chatnet != NULL) {
if (chatnetrec == NULL && chatnet != NULL) { chatnetrec = chatnet_find(chatnet);
if (chatnetrec != NULL) {
proto = CHAT_PROTOCOL(chatnetrec);
} else {
/* chat network not found, create it. */ /* chat network not found, create it. */
if (chatnet_find_unavailable(chatnet)) { if (chatnet_find_unavailable(chatnet)) {
/* no protocols loaded, skip loading servers */ /* no protocols loaded, skip loading servers */
return NULL; return NULL;
} }
chatnetrec = chat_protocol_get_default()->create_chatnet(); proto = chat_protocol_get_default();
chatnetrec = proto->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);
chatnet_create(chatnetrec); chatnet_create(chatnetrec);
} }
} else {
chatnetrec = NULL;
proto = chat_protocol_get_default();
if (proto == NULL) {
/* no protocols loaded, skip loading servers */
return NULL;
}
}
family = config_node_get_str(node, "family", ""); family = config_node_get_str(node, "family", "");
rec = CHAT_PROTOCOL(chatnetrec)->create_server_setup(); rec = proto->create_server_setup();
rec->type = module_get_uniq_id("SERVER SETUP", 0); rec->type = module_get_uniq_id("SERVER SETUP", 0);
rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id; rec->chat_type = proto->id;
rec->chatnet = chatnetrec == NULL ? NULL : g_strdup(chatnetrec->name); rec->chatnet = chatnetrec == NULL ? NULL : g_strdup(chatnetrec->name);
rec->family = g_ascii_strcasecmp(family, "inet6") == 0 ? AF_INET6 : rec->family = g_ascii_strcasecmp(family, "inet6") == 0 ?
AF_INET6 :
(g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0); (g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0);
rec->address = g_strdup(server); rec->address = g_strdup(server);
rec->password = g_strdup(config_node_get_str(node, "password", NULL)); rec->password = g_strdup(config_node_get_str(node, "password", NULL));