aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c129
1 files changed, 67 insertions, 62 deletions
diff --git a/degesch.c b/degesch.c
index 58fd303..2295006 100644
--- a/degesch.c
+++ b/degesch.c
@@ -4904,7 +4904,7 @@ on_irc_autojoin_timeout (void *user_data)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split (autojoin, ",", &v);
+ cstr_split (autojoin, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
irc_send (s, "JOIN :%s", v.vector[i]);
@@ -5060,28 +5060,20 @@ on_irc_ready (const struct pollfd *pfd, struct server *s)
static enum socket_io_result
transport_plain_try_read (struct server *s)
{
- struct error *e = NULL;
enum socket_io_result result =
- socket_io_try_read (s->socket, &s->read_buffer, &e);
- if (e)
- {
- print_debug ("%s: %s", __func__, e->message);
- error_free (e);
- }
+ socket_io_try_read (s->socket, &s->read_buffer);
+ if (result == SOCKET_IO_ERROR)
+ print_debug ("%s: %s", __func__, strerror (errno));
return result;
}
static enum socket_io_result
transport_plain_try_write (struct server *s)
{
- struct error *e = NULL;
enum socket_io_result result =
- socket_io_try_write (s->socket, &s->write_buffer, &e);
- if (e)
- {
- print_debug ("%s: %s", __func__, e->message);
- error_free (e);
- }
+ socket_io_try_write (s->socket, &s->write_buffer);
+ if (result == SOCKET_IO_ERROR)
+ print_debug ("%s: %s", __func__, strerror (errno));
return result;
}
@@ -5152,12 +5144,14 @@ transport_tls_init_ca_set (SSL_CTX *ssl_ctx, const char *file, const char *path,
if (SSL_CTX_load_verify_locations (ssl_ctx, file, path))
return true;
- FAIL ("%s: %s", "Failed to set locations for the CA certificate bundle",
+ return error_set (e, "%s: %s",
+ "Failed to set locations for the CA certificate bundle",
ERR_reason_error_string (ERR_get_error ()));
}
if (!SSL_CTX_set_default_verify_paths (ssl_ctx))
- FAIL ("%s: %s", "Couldn't load the default CA certificate bundle",
+ return error_set (e, "%s: %s",
+ "Couldn't load the default CA certificate bundle",
ERR_reason_error_string (ERR_get_error ()));
return true;
}
@@ -5445,7 +5439,10 @@ irc_autofill_user_info (struct server *s, struct error **e)
// Read POSIX user info and fill the configuration if needed
struct passwd *pwd = getpwuid (geteuid ());
if (!pwd)
- FAIL ("cannot retrieve user information: %s", strerror (errno));
+ {
+ return error_set (e,
+ "cannot retrieve user information: %s", strerror (errno));
+ }
// FIXME: set_config_strings() writes errors on its own
if (!nicks || !*nicks)
@@ -5474,7 +5471,7 @@ irc_fetch_next_nickname (struct server *s)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (get_config_string (s->config, "nicks"), ',', &v);
+ cstr_split (get_config_string (s->config, "nicks"), ",", true, &v);
char *result = NULL;
if (s->nick_counter >= 0 && (size_t) s->nick_counter < v.len)
@@ -5565,6 +5562,7 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
static void
irc_split_host_port (char *s, char **host, char **port)
{
+ // FIXME: this won't work if this is an IPv6 address w/o a port
char *colon = strrchr (s, ':');
if (colon)
{
@@ -5689,7 +5687,7 @@ irc_setup_connector_socks (struct server *s,
// The SOCKS connector can have already failed; we mustn't return true then
if (!s->socks_conn)
- FAIL ("SOCKS connection failed");
+ return error_set (e, "SOCKS connection failed");
return true;
}
@@ -5711,7 +5709,7 @@ irc_initiate_connect (struct server *s)
struct str_vector servers;
str_vector_init (&servers);
- cstr_split_ignore_empty (addresses, ',', &servers);
+ cstr_split (addresses, ",", true, &servers);
struct error *e = NULL;
if (!irc_setup_connector_socks (s, &servers, &e) && !e)
@@ -6292,7 +6290,7 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
const char *args = "";
if (msg->params.len > 2)
- cstr_split_ignore_empty ((args = msg->params.vector[2]), ' ', &v);
+ cstr_split ((args = msg->params.vector[2]), " ", true, &v);
const char *subcommand = msg->params.vector[1];
if (!strcasecmp_ascii (subcommand, "ACK"))
@@ -6327,8 +6325,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
struct str_vector chosen; str_vector_init (&chosen);
struct str_vector use; str_vector_init (&use);
- cstr_split_ignore_empty
- (get_config_string (s->config, "capabilities"), ',', &use);
+ cstr_split (get_config_string (s->config, "capabilities"),
+ ",", true, &use);
// Filter server capabilities for ones we can make use of
for (size_t i = 0; i < v.len; i++)
@@ -7027,7 +7025,7 @@ irc_try_parse_welcome_for_userhost (struct server *s, const char *m)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (m, ' ', &v);
+ cstr_split (m, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
if (irc_try_parse_word_for_userhost (s, v.vector[i]))
break;
@@ -7077,7 +7075,7 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
const char *response = msg->params.vector[1];
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (response, ' ', &v);
+ cstr_split (response, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -7134,7 +7132,7 @@ irc_handle_rpl_namreply (struct server *s, const struct irc_message *msg)
// Just push the nicknames to a string vector to process later
struct channel *channel = str_map_find (&s->irc_channels, channel_name);
if (channel)
- cstr_split_ignore_empty (nicks, ' ', &channel->names_buf);
+ cstr_split (nicks, " ", true, &channel->names_buf);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -7483,7 +7481,7 @@ irc_handle_isupport_idchan (struct server *s, char *value)
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (value, ',', &v);
+ cstr_split (value, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
// Not using or validating the numeric part
@@ -7510,7 +7508,7 @@ irc_handle_isupport_chanmodes (struct server *s, char *value)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (value, ',', &v);
+ cstr_split (value, ",", true, &v);
if (v.len >= 4)
{
free (s->irc_chanmodes_list);
@@ -8250,7 +8248,7 @@ lua_plugin_process_error (struct lua_plugin *self, const char *message,
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (message, '\n', &v);
+ cstr_split (message, "\n", true, &v);
if (v.len < 2)
error_set (e, "%s", message);
@@ -8303,12 +8301,12 @@ lua_plugin_handle_string_filter_result (struct lua_plugin *self,
return true;
}
if (!lua_isstring (L, -1))
- FAIL ("must return either a string or nil");
+ return error_set (e, "must return either a string or nil");
size_t len;
const char *processed = lua_tolstring (L, -1, &len);
if (utf8 && !utf8_validate (processed, len))
- FAIL ("must return valid UTF-8");
+ return error_set (e, "must return valid UTF-8");
// Only replace the string if it's different
if (strcmp (processed, *original))
@@ -8837,12 +8835,15 @@ lua_completion_hook_process_value (lua_State *L, struct str_vector *output,
struct error **e)
{
if (lua_type (L, -1) != LUA_TSTRING)
- FAIL ("%s: %s", "invalid type", lua_typename (L, lua_type (L, -1)));
+ {
+ return error_set (e,
+ "%s: %s", "invalid type", lua_typename (L, lua_type (L, -1)));
+ }
size_t len;
const char *value = lua_tolstring (L, -1, &len);
if (!utf8_validate (value, len))
- FAIL ("must be valid UTF-8");
+ return error_set (e, "must be valid UTF-8");
str_vector_add (output, value);
return true;
@@ -8855,7 +8856,7 @@ lua_completion_hook_process (lua_State *L, struct str_vector *output,
if (lua_isnil (L, -1))
return true;
if (!lua_istable (L, -1))
- FAIL ("must return either a table or nil");
+ return error_set (e, "must return either a table or nil");
bool success = true;
for (lua_Integer i = 1; success && lua_rawgeti (L, -1, i); i++)
@@ -9415,16 +9416,15 @@ lua_connection_invoke_on_eof (struct lua_connection *self, struct error **e)
static bool
lua_connection_invoke_on_error (struct lua_connection *self,
- struct error *error, struct error **e)
+ const char *error, struct error **e)
{
if (!self->closing
&& lua_connection_cb_lookup (self, "on_error", e)
&& !lua_connection_eat_nil (self))
{
- lua_pushstring (self->plugin->L, error->message);
+ lua_pushstring (self->plugin->L, error);
lua_plugin_call (self->plugin, 1, 0, e);
}
- error_free (error);
return false;
}
@@ -9436,19 +9436,15 @@ lua_connection_try_read (struct lua_connection *self, struct error **e)
if (self->closing || self->got_eof)
return true;
- struct error *error = NULL;
enum socket_io_result read_result =
- socket_io_try_read (self->socket_fd, &self->read_buffer, &error);
+ socket_io_try_read (self->socket_fd, &self->read_buffer);
+ const char *error = strerror (errno);
// Dispatch any data that we got before an EOF or any error
if (self->read_buffer.len)
{
if (!lua_connection_invoke_on_data (self, e))
- {
- if (error)
- error_free (error);
return false;
- }
str_reset (&self->read_buffer);
}
@@ -9466,9 +9462,9 @@ lua_connection_try_read (struct lua_connection *self, struct error **e)
static bool
lua_connection_try_write (struct lua_connection *self, struct error **e)
{
- struct error *error = NULL;
enum socket_io_result write_result =
- socket_io_try_write (self->socket_fd, &self->write_buffer, &error);
+ socket_io_try_write (self->socket_fd, &self->write_buffer);
+ const char *error = strerror (errno);
if (write_result == SOCKET_IO_ERROR)
return lua_connection_invoke_on_error (self, error, e);
@@ -9853,7 +9849,10 @@ plugin_load_from_filename (struct app_context *ctx, const char *filename,
if (error)
error_propagate (e, error);
else if (!plugin)
- FAIL ("no plugin handler for \"%s\"", filename);
+ {
+ error_set (e, "no plugin handler for \"%s\"", filename);
+ return NULL;
+ }
return plugin;
}
@@ -9884,14 +9883,20 @@ plugin_load_by_name (struct app_context *ctx, const char *name,
{
struct plugin *plugin = plugin_find (ctx, name);
if (plugin)
- FAIL ("plugin already loaded");
+ {
+ error_set (e, "plugin already loaded");
+ return NULL;
+ }
// As a side effect, a plugin can be loaded multiple times by giving
// various relative or non-relative paths to the function; this is not
// supposed to be fool-proof though, that requires other mechanisms
char *filename = resolve_filename (name, plugin_resolve_relative_filename);
if (!filename)
- FAIL ("file not found");
+ {
+ error_set (e, "file not found");
+ return NULL;
+ }
plugin = plugin_load_from_filename (ctx, filename, e);
free (filename);
@@ -9944,7 +9949,7 @@ load_plugins (struct app_context *ctx)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (plugins, ',', &v);
+ cstr_split (plugins, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
plugin_load (ctx, v.vector[i]);
str_vector_free (&v);
@@ -10230,7 +10235,7 @@ handle_command_set_add
struct str_vector items;
str_vector_init (&items);
if (item->type != CONFIG_ITEM_NULL)
- cstr_split (item->value.string.str, ",", &items);
+ cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
@@ -10255,7 +10260,7 @@ handle_command_set_remove
struct str_vector items;
str_vector_init (&items);
if (item->type != CONFIG_ITEM_NULL)
- cstr_split (item->value.string.str, ",", &items);
+ cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
@@ -10623,7 +10628,7 @@ handle_command_part (struct handler_args *a)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (cut_word (&a->arguments), ' ', &v);
+ cstr_split (cut_word (&a->arguments), ",", true, &v);
for (size_t i = 0; i < v.len; i++)
part_channel (a->s, v.vector[i], a->arguments);
str_vector_free (&v);
@@ -10666,7 +10671,7 @@ handle_command_cycle (struct handler_args *a)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (cut_word (&a->arguments), ' ', &v);
+ cstr_split (cut_word (&a->arguments), ",", true, &v);
for (size_t i = 0; i < v.len; i++)
cycle_channel (a->s, v.vector[i], a->arguments);
str_vector_free (&v);
@@ -10790,7 +10795,7 @@ mass_channel_mode_mask_list
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (a->arguments, ' ', &v);
+ cstr_split (a->arguments, " ", true, &v);
// XXX: this may be a bit too trivial; we could also map nicknames
// to information from WHO polling or userhost-in-names
@@ -10833,7 +10838,7 @@ handle_command_invite (struct handler_args *a)
{
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (a->arguments, ' ', &v);
+ cstr_split (a->arguments, " ", true, &v);
bool result = !!v.len;
for (size_t i = 0; i < v.len; i++)
@@ -11088,7 +11093,7 @@ handle_command_channel_mode
struct str_vector v;
str_vector_init (&v);
- cstr_split_ignore_empty (a->arguments, ' ', &v);
+ cstr_split (a->arguments, " ", true, &v);
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
str_vector_free (&v);
return true;
@@ -11428,7 +11433,7 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
{
struct str_vector words;
str_vector_init (&words);
- cstr_split_ignore_empty (arguments, ' ', &words);
+ cstr_split (arguments, " ", true, &words);
// TODO: eventually also add support for argument ranges
if (*p >= '1' && *p <= '9')
@@ -11619,7 +11624,7 @@ process_input (struct app_context *ctx, char *user_input)
str_vector_init (&lines);
// XXX: this interprets commands in pasted text
- cstr_split (input, "\r\n", &lines);
+ cstr_split (input, "\r\n", false, &lines);
for (size_t i = 0; i < lines.len; i++)
(void) process_input_utf8 (ctx,
ctx->current_buffer, lines.vector[i], 0);
@@ -12098,7 +12103,7 @@ dump_input_to_file (struct app_context *ctx, char *template, struct error **e)
(void) umask (mask);
if (fd < 0)
- FAIL ("%s", strerror (errno));
+ return error_set (e, "%s", strerror (errno));
char *input = CALL (ctx->input, get_line);
bool success = xwrite (fd, input, strlen (input), e);
@@ -12803,14 +12808,14 @@ load_configuration (struct app_context *ctx)
char *filename = resolve_filename
(PROGRAM_NAME ".conf", resolve_relative_config_filename);
if (filename)
- root = load_configuration_file (filename, &e);
+ root = config_read_from_file (filename, &e);
else
log_global_error (ctx, "Configuration file not found");
free (filename);
if (e)
{
- log_global_error (ctx, "#s", e->message);
+ log_global_error (ctx, "Cannot load configuration: #s", e->message);
log_global_error (ctx,
"Please either fix the configuration file or remove it", filename);
error_free (e);