From 6745dd6159afc6ff220d09d7adc1923218fa756b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 18 Mar 2016 20:18:58 +0100 Subject: [PATCH 1/3] Throw an error when a chatnet has no available url If you type /connect and the chatnet has no url available let's just throw an error instead of trying to process as a url. --- src/core/chat-commands.c | 7 +++++++ src/core/commands.h | 3 ++- src/core/servers-setup.c | 2 ++ src/fe-common/core/fe-core-commands.c | 3 ++- src/fe-common/core/module-formats.c | 1 + src/fe-common/core/module-formats.h | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 7f000cf5..a9404fa3 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -73,6 +73,13 @@ static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr, conn = server_create_conn(proto != NULL ? proto->id : -1, addr, atoi(portstr), chatnet, password, nick); + if (conn == NULL) { + signal_emit("error command", 1, + GINT_TO_POINTER(CMDERR_NO_SERVER_DEFINED)); + cmd_params_free(free_arg); + return NULL; + } + if (proto == NULL) proto = chat_protocol_find_id(conn->chat_type); diff --git a/src/core/commands.h b/src/core/commands.h index 72105ad3..93d6276b 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -41,7 +41,8 @@ enum { CMDERR_INVALID_TIME, /* invalid time specification */ CMDERR_INVALID_CHARSET, /* invalid charset specification */ CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */ - CMDERR_PROGRAM_NOT_FOUND /* program not found */ + CMDERR_PROGRAM_NOT_FOUND, /* program not found */ + CMDERR_NO_SERVER_DEFINED, /* no server has been defined for a given chatnet */ }; /* Return the full command for `alias' */ diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index 4a048282..990d2d4b 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -323,6 +323,8 @@ server_create_conn(int chat_type, const char *dest, int port, rec = create_chatnet_conn(chatrec->name, port, password, nick); if (rec != NULL) return rec; + /* The chatnet has no url to connect to */ + return NULL; } chatrec = chatnet == NULL ? NULL : chatnet_find(chatnet); diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 7b1d7b94..97a246ec 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -51,7 +51,8 @@ static int ret_texts[] = { TXT_INVALID_TIME, TXT_INVALID_CHARSET, TXT_EVAL_MAX_RECURSE, - TXT_PROGRAM_NOT_FOUND + TXT_PROGRAM_NOT_FOUND, + TXT_NO_SERVER_DEFINED, }; int command_hide_output; diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index e6d32b6d..b897b0c6 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -223,6 +223,7 @@ FORMAT_REC fecommon_core_formats[] = { { "invalid_charset", "Invalid charset: $0", 1, { 0 } }, { "eval_max_recurse", "/eval hit maximum recursion limit", 0 }, { "program_not_found", "Could not find file or file is not executable", 0 }, + { "no_server_defined", "No servers defined for this network, see /help server for how to add one", 0 }, /* ---- */ { NULL, "Themes", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 3f06bb97..de1e13f2 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -192,6 +192,7 @@ enum { TXT_INVALID_CHARSET, TXT_EVAL_MAX_RECURSE, TXT_PROGRAM_NOT_FOUND, + TXT_NO_SERVER_DEFINED, TXT_FILL_11, From 8394973d5a3f37523e95fb5b51620de9284d743f Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 20 Mar 2016 12:16:48 +0100 Subject: [PATCH 2/3] Bump the ABI version Since a new format has been added. --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 729049ab..33dbd481 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 2 +#define IRSSI_ABI_VERSION 3 #define DEFAULT_SERVER_ADD_PORT 6667 From e5ee243ab6ff7f640bdd45a232ad81ed97520a46 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 22 Mar 2016 15:45:08 +0100 Subject: [PATCH 3/3] Simplify some logic in server_create_conn --- src/core/servers-setup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index 990d2d4b..0cecfece 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -321,10 +321,8 @@ server_create_conn(int chat_type, const char *dest, int port, chatrec = chatnet_find(dest); if (chatrec != NULL) { rec = create_chatnet_conn(chatrec->name, port, password, nick); - if (rec != NULL) - return rec; - /* The chatnet has no url to connect to */ - return NULL; + /* If rec is NULL the chatnet has no url to connect to */ + return rec; } chatrec = chatnet == NULL ? NULL : chatnet_find(chatnet);