summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-23 23:50:27 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-23 23:50:27 +0100
commit9e5725662f944fe437be7ba1b54acbc5fc18dbe1 (patch)
treee5daa605b91dce014582f35fe0330287c1867775
parent0785a6f417d3a6e43d2d72132e550d517af41bc4 (diff)
downloadxK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.tar.gz
xK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.tar.xz
xK-9e5725662f944fe437be7ba1b54acbc5fc18dbe1.zip
Bump liberty
-rw-r--r--common.c4
-rw-r--r--degesch.c333
-rw-r--r--kike.c170
m---------liberty0
-rw-r--r--zyklonb.c34
5 files changed, 271 insertions, 270 deletions
diff --git a/common.c b/common.c
index 1d6c1f7..6c5755f 100644
--- a/common.c
+++ b/common.c
@@ -52,7 +52,7 @@ init_openssl (void)
// --- To be moved to liberty --------------------------------------------------
static ssize_t
-str_vector_find (const struct str_vector *v, const char *s)
+strv_find (const struct strv *v, const char *s)
{
for (size_t i = 0; i < v->len; i++)
if (!strcmp (v->vector[i], s))
@@ -702,7 +702,7 @@ socks_try_fill_read_buffer (struct socks_connector *self, size_t n)
return true;
ssize_t received;
- str_ensure_space (&self->read_buffer, remains);
+ str_reserve (&self->read_buffer, remains);
do
received = recv (self->socket_fd,
self->read_buffer.str + self->read_buffer.len, remains, 0);
diff --git a/degesch.c b/degesch.c
index b8f7bb1..e7c776e 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1385,7 +1385,7 @@ struct channel
struct str_map param_modes; ///< Parametrized channel modes
struct channel_user *users; ///< Channel users
- struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY
+ struct strv names_buf; ///< Buffer for RPL_NAMREPLY
size_t users_len; ///< User count
bool left_manually; ///< Don't rejoin on reconnect
@@ -1410,7 +1410,7 @@ channel_new (void)
str_init (&self->no_param_modes);
str_map_init (&self->param_modes);
self->param_modes.free = free;
- str_vector_init (&self->names_buf);
+ strv_init (&self->names_buf);
return self;
}
@@ -1423,7 +1423,7 @@ channel_destroy (struct channel *self)
str_map_free (&self->param_modes);
// Owner has to make sure we have no users by now
hard_assert (!self->users && !self->users_len);
- str_vector_free (&self->names_buf);
+ strv_free (&self->names_buf);
free (self);
}
@@ -2004,7 +2004,7 @@ struct completion_hook
/// Tries to add possible completions of "word" to "output"
void (*complete) (struct completion_hook *self,
- struct completion *data, const char *word, struct str_vector *output);
+ struct completion *data, const char *word, struct strv *output);
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2062,7 +2062,7 @@ struct app_context
struct poller_idle prompt_event; ///< Deferred prompt refresh
struct poller_idle input_event; ///< Pending input event
- struct str_vector pending_input; ///< Pending input lines
+ struct strv pending_input; ///< Pending input lines
int *nick_palette; ///< A 256-color palette for nicknames
size_t nick_palette_len; ///< Number of entries in nick_palette
@@ -2156,7 +2156,7 @@ app_context_init (struct app_context *self)
self->input = input_new ();
self->input->user_data = self;
- str_vector_init (&self->pending_input);
+ strv_init (&self->pending_input);
str_init (&self->input_buffer);
self->nick_palette =
@@ -2195,7 +2195,7 @@ app_context_free (struct app_context *self)
iconv_close (self->term_to_utf8);
CALL (self->input, destroy);
- str_vector_free (&self->pending_input);
+ strv_free (&self->pending_input);
str_free (&self->input_buffer);
free (self->editor_filename);
@@ -4991,15 +4991,15 @@ on_irc_autojoin_timeout (void *user_data)
const char *autojoin = get_config_string (s->config, "autojoin");
if (autojoin)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (autojoin, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
irc_send (s, "JOIN %s", v.vector[i]);
str_map_set (&joins_sent, v.vector[i], (void *) 1);
}
- str_vector_free (&v);
+ strv_free (&v);
}
// Then also rejoin any channels from the last disconnect
@@ -5430,7 +5430,7 @@ transport_tls_try_read (struct server *s)
while (true)
{
ERR_clear_error ();
- str_ensure_space (buf, 512);
+ str_reserve (buf, 512);
int n_read = SSL_read (data->ssl, buf->str + buf->len,
buf->alloc - buf->len - 1 /* null byte */);
@@ -5570,8 +5570,8 @@ irc_autofill_user_info (struct server *s, struct error **e)
static char *
irc_fetch_next_nickname (struct server *s)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (get_config_string (s->config, "nicks"), ",", true, &v);
char *result = NULL;
@@ -5581,7 +5581,7 @@ irc_fetch_next_nickname (struct server *s)
// Exhausted all nicknames
s->nick_counter = -1;
- str_vector_free (&v);
+ strv_free (&v);
return result;
}
@@ -5716,7 +5716,7 @@ irc_on_connector_connected (void *user_data, int socket, const char *hostname)
}
static void
-irc_setup_connector (struct server *s, const struct str_vector *addresses)
+irc_setup_connector (struct server *s, const struct strv *addresses)
{
struct connector *connector = xmalloc (sizeof *connector);
connector_init (connector, &s->ctx->poller);
@@ -5752,8 +5752,8 @@ irc_on_socks_connecting (void *user_data,
}
static bool
-irc_setup_connector_socks (struct server *s,
- const struct str_vector *addresses, struct error **e)
+irc_setup_connector_socks (struct server *s, const struct strv *addresses,
+ struct error **e)
{
const char *socks_host = get_config_string (s->config, "socks_host");
int64_t socks_port_int = get_config_integer (s->config, "socks_port");
@@ -5808,15 +5808,15 @@ irc_initiate_connect (struct server *s)
return;
}
- struct str_vector servers;
- str_vector_init (&servers);
+ struct strv servers;
+ strv_init (&servers);
cstr_split (addresses, ",", true, &servers);
struct error *e = NULL;
if (!irc_setup_connector_socks (s, &servers, &e) && !e)
irc_setup_connector (s, &servers);
- str_vector_free (&servers);
+ strv_free (&servers);
if (e)
{
@@ -6413,8 +6413,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
if (msg->params.len < 2)
return;
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
const char *args = "";
if (msg->params.len > 2)
@@ -6450,8 +6450,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
log_server_status (s, s->buffer,
"#s: #S", "Capabilities supported", args);
- struct str_vector chosen; str_vector_init (&chosen);
- struct str_vector use; str_vector_init (&use);
+ struct strv chosen; strv_init (&chosen);
+ struct strv use; strv_init (&use);
cstr_split (get_config_string (s->config, "capabilities"),
",", true, &use);
@@ -6462,18 +6462,18 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
const char *cap = v.vector[i];
for (size_t k = 0; k < use.len; k++)
if (!strcasecmp_ascii (use.vector[k], cap))
- str_vector_add (&chosen, cap);
+ strv_append (&chosen, cap);
}
- char *chosen_str = join_str_vector (&chosen, ' ');
- str_vector_free (&chosen);
- str_vector_free (&use);
+ char *chosen_str = strv_join (&chosen, " ");
+ strv_free (&chosen);
+ strv_free (&use);
irc_send (s, "CAP REQ :%s", chosen_str);
free (chosen_str);
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -6631,11 +6631,11 @@ irc_handle_mode (struct server *s, const struct irc_message *msg)
const char *context = msg->params.vector[0];
// Join the modes back to a single string
- struct str_vector copy;
- str_vector_init (&copy);
- str_vector_add_vector (&copy, msg->params.vector + 1);
- char *modes = join_str_vector (&copy, ' ');
- str_vector_free (&copy);
+ struct strv copy;
+ strv_init (&copy);
+ strv_append_vector (&copy, msg->params.vector + 1);
+ char *modes = strv_join (&copy, " ");
+ strv_free (&copy);
if (irc_is_channel (s, context))
{
@@ -7154,13 +7154,13 @@ irc_try_parse_word_for_userhost (struct server *s, const char *word)
static void
irc_try_parse_welcome_for_userhost (struct server *s, const char *m)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&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;
- str_vector_free (&v);
+ strv_free (&v);
}
static bool process_input_utf8
@@ -7204,8 +7204,8 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
return;
const char *response = msg->params.vector[1];
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (response, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
@@ -7235,7 +7235,7 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg)
}
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -7363,7 +7363,7 @@ irc_process_names (struct server *s, struct channel *channel)
str_map_init (&present);
present.key_xfrm = s->irc_strxfrm;
- struct str_vector *updates = &channel->names_buf;
+ struct strv *updates = &channel->names_buf;
for (size_t i = 0; i < updates->len; i++)
{
const char *item = updates->vector[i];
@@ -7384,7 +7384,7 @@ irc_process_names (struct server *s, struct channel *channel)
irc_channel_unlink_user (channel, iter);
str_map_free (&present);
- str_vector_reset (&channel->names_buf);
+ strv_reset (&channel->names_buf);
char *all_users = make_channel_users_list (s, channel);
struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel->name);
@@ -7608,8 +7608,8 @@ irc_handle_isupport_idchan (struct server *s, char *value)
struct str prefixes;
str_init (&prefixes);
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (value, ",", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -7619,7 +7619,7 @@ irc_handle_isupport_idchan (struct server *s, char *value)
if (colon)
str_append_data (&prefixes, pair, colon - pair);
}
- str_vector_free (&v);
+ strv_free (&v);
free (s->irc_idchan_prefixes);
s->irc_idchan_prefixes = str_steal (&prefixes);
@@ -7635,8 +7635,8 @@ irc_handle_isupport_statusmsg (struct server *s, char *value)
static void
irc_handle_isupport_chanmodes (struct server *s, char *value)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (value, ",", true, &v);
if (v.len >= 4)
{
@@ -7649,7 +7649,7 @@ irc_handle_isupport_chanmodes (struct server *s, char *value)
free (s->irc_chanmodes_param_never);
s->irc_chanmodes_param_never = xstrdup (v.vector[3]);
}
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -7730,9 +7730,9 @@ irc_process_numeric (struct server *s,
// Get rid of the first parameter, if there's any at all,
// as it contains our nickname and is of no practical use to the user
- struct str_vector copy;
- str_vector_init (&copy);
- str_vector_add_vector (&copy, msg->params.vector + !!msg->params.len);
+ struct strv copy;
+ strv_init (&copy);
+ strv_append_vector (&copy, msg->params.vector + !!msg->params.len);
struct buffer *buffer = s->buffer;
int flags = BUFFER_LINE_STATUS;
@@ -7805,10 +7805,10 @@ irc_process_numeric (struct server *s,
if (buffer)
{
// Join the parameter vector back and send it to the server buffer
- log_server (s, buffer, flags, "#&m", join_str_vector (&copy, ' '));
+ log_server (s, buffer, flags, "#&m", strv_join (&copy, " "));
}
- str_vector_free (&copy);
+ strv_free (&copy);
}
static void
@@ -7882,7 +7882,7 @@ wrap_text_for_single_line (const char *text, size_t text_len,
static bool
wrap_message (const char *message,
- int line_max, struct str_vector *output, struct error **e)
+ int line_max, struct strv *output, struct error **e)
{
if (line_max <= 0)
goto error;
@@ -7901,13 +7901,13 @@ wrap_message (const char *message,
goto error;
}
- str_vector_add_owned (output, str_steal (&m));
+ strv_append_owned (output, str_steal (&m));
message += eaten;
message_left -= eaten;
}
if (message_left)
- str_vector_add (output, message);
+ strv_append (output, message);
return true;
@@ -7923,7 +7923,7 @@ error:
/// so that they don't arrive cut off by the server
static bool
irc_autosplit_message (struct server *s, const char *message,
- int fixed_part, struct str_vector *output, struct error **e)
+ int fixed_part, struct strv *output, struct error **e)
{
// :<nick>!<user>@<host> <fixed-part><message>
int space_in_one_message = 0;
@@ -7935,7 +7935,7 @@ irc_autosplit_message (struct server *s, const char *message,
// However we don't always have the full info for message splitting
if (!space_in_one_message)
- str_vector_add (output, message);
+ strv_append (output, message);
else if (!wrap_message (message, space_in_one_message, output, e))
return false;
return true;
@@ -7953,8 +7953,8 @@ send_autosplit_message (struct server *s,
// We might also want to preserve attributes across splits but
// that would make this code a lot more complicated
- struct str_vector lines;
- str_vector_init (&lines);
+ struct strv lines;
+ strv_init (&lines);
struct error *e = NULL;
if (!irc_autosplit_message (s, message, fixed_part, &lines, &e))
{
@@ -7967,7 +7967,7 @@ send_autosplit_message (struct server *s,
irc_send (s, "%s %s :%s%s%s", command, target,
prefix, lines.vector[i], suffix);
}
- str_vector_free (&lines);
+ strv_free (&lines);
}
#define SEND_AUTOSPLIT_ACTION(s, target, message) \
@@ -7992,7 +7992,7 @@ struct config_dump_data
{
struct config_dump_level *head; ///< The first level
struct config_dump_level **tail; ///< Where to place further levels
- struct str_vector *output; ///< Where to place new entries
+ struct strv *output; ///< Where to place new entries
};
static void config_dump_item
@@ -8072,11 +8072,11 @@ config_dump_item (struct config_item *item, struct config_dump_data *data)
str_append_printf (&line, " (default: %s)", "null");
str_free (&value);
- str_vector_add_owned (data->output, str_steal (&line));
+ strv_append_owned (data->output, str_steal (&line));
}
static void
-config_dump (struct config_item *root, struct str_vector *output)
+config_dump (struct config_item *root, struct strv *output)
{
struct config_dump_data data;
data.head = NULL;
@@ -8089,23 +8089,23 @@ config_dump (struct config_item *root, struct str_vector *output)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int
-str_vector_sort_cb (const void *a, const void *b)
+strv_sort_cb (const void *a, const void *b)
{
return strcmp (*(const char **) a, *(const char **) b);
}
static void
-str_vector_sort (struct str_vector *self)
+strv_sort (struct strv *self)
{
- qsort (self->vector, self->len, sizeof *self->vector, str_vector_sort_cb);
+ qsort (self->vector, self->len, sizeof *self->vector, strv_sort_cb);
}
static void
dump_matching_options
- (struct config_item *root, const char *mask, struct str_vector *output)
+ (struct config_item *root, const char *mask, struct strv *output)
{
config_dump (root, output);
- str_vector_sort (output);
+ strv_sort (output);
// Filter out results by wildcard matching
for (size_t i = 0; i < output->len; i++)
@@ -8113,7 +8113,7 @@ dump_matching_options
// Yeah, I know
char *key = cstr_cut_until (output->vector[i], " ");
if (fnmatch (mask, key, 0))
- str_vector_remove (output, i--);
+ strv_remove (output, i--);
free (key);
}
}
@@ -8379,8 +8379,8 @@ static bool
lua_plugin_process_error (struct lua_plugin *self, const char *message,
struct error **e)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (message, "\n", true, &v);
if (v.len < 2)
@@ -8394,7 +8394,7 @@ lua_plugin_process_error (struct lua_plugin *self, const char *message,
log_global_debug (self->ctx, " #s", v.vector[i]);
}
- str_vector_free (&v);
+ strv_free (&v);
return false;
}
@@ -8946,7 +8946,7 @@ lua_plugin_push_completion (lua_State *L, struct completion *data)
}
static bool
-lua_completion_hook_process_value (lua_State *L, struct str_vector *output,
+lua_completion_hook_process_value (lua_State *L, struct strv *output,
struct error **e)
{
if (lua_type (L, -1) != LUA_TSTRING)
@@ -8960,12 +8960,12 @@ lua_completion_hook_process_value (lua_State *L, struct str_vector *output,
if (!utf8_validate (value, len))
return error_set (e, "must be valid UTF-8");
- str_vector_add (output, value);
+ strv_append (output, value);
return true;
}
static bool
-lua_completion_hook_process (lua_State *L, struct str_vector *output,
+lua_completion_hook_process (lua_State *L, struct strv *output,
struct error **e)
{
if (lua_isnil (L, -1))
@@ -8983,7 +8983,7 @@ lua_completion_hook_process (lua_State *L, struct str_vector *output,
static void
lua_completion_hook_complete (struct completion_hook *self,
- struct completion *data, const char *word, struct str_vector *output)
+ struct completion *data, const char *word, struct strv *output)
{
struct lua_hook *hook =
CONTAINER_OF (self, struct lua_hook, data.c_hook);
@@ -10403,12 +10403,12 @@ plugin_find (struct app_context *ctx, const char *name)
static char *
plugin_resolve_relative_filename (const char *filename)
{
- struct str_vector paths;
- str_vector_init (&paths);
+ struct strv paths;
+ strv_init (&paths);
get_xdg_data_dirs (&paths);
char *result = resolve_relative_filename_generic
(&paths, PROGRAM_NAME "/plugins/", filename);
- str_vector_free (&paths);
+ strv_free (&paths);
return result;
}
@@ -10482,12 +10482,12 @@ load_plugins (struct app_context *ctx)
(ctx->config.root, "behaviour.plugin_autoload");
if (plugins)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&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);
+ strv_free (&v);
}
}
@@ -10753,9 +10753,9 @@ handle_command_buffer (struct handler_args *a)
static bool
replace_string_array
- (struct config_item *item, struct str_vector *array, struct error **e)
+ (struct config_item *item, struct strv *array, struct error **e)
{
- char *changed = join_str_vector (array, ',');
+ char *changed = strv_join (array, ",");
struct str tmp = { .str = changed, .len = strlen (changed) };
bool result = config_item_set_from (item,
config_item_string_array (&tmp), e);
@@ -10767,24 +10767,24 @@ static bool
handle_command_set_add
(struct config_item *item, const char *value, struct error **e)
{
- struct str_vector items;
- str_vector_init (&items);
+ struct strv items;
+ strv_init (&items);
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
- str_vector_reset (&items);
+ strv_reset (&items);
// FIXME: handle multiple items properly
bool result = false;
- if (str_vector_find (&items, value) != -1)
+ if (strv_find (&items, value) != -1)
error_set (e, "already present in the array: %s", value);
else
{
- str_vector_add (&items, value);
+ strv_append (&items, value);
result = replace_string_array (item, &items, e);
}
- str_vector_free (&items);
+ strv_free (&items);
return result;
}
@@ -10792,25 +10792,25 @@ static bool
handle_command_set_remove
(struct config_item *item, const char *value, struct error **e)
{
- struct str_vector items;
- str_vector_init (&items);
+ struct strv items;
+ strv_init (&items);
if (item->type != CONFIG_ITEM_NULL)
cstr_split (item->value.string.str, ",", false, &items);
if (items.len == 1 && !*items.vector[0])
- str_vector_reset (&items);
+ strv_reset (&items);
// FIXME: handle multiple items properly
bool result = false;
- ssize_t i = str_vector_find (&items, value);
+ ssize_t i = strv_find (&items, value);
if (i == -1)
error_set (e, "not present in the array: %s", value);
else
{
- str_vector_remove (&items, i);
+ strv_remove (&items, i);
result = replace_string_array (item, &items, e);
}
- str_vector_free (&items);
+ strv_free (&items);
return result;
}
@@ -10842,17 +10842,17 @@ handle_command_set_assign_item (struct app_context *ctx,
}
else
{
- struct str_vector tmp;
- str_vector_init (&tmp);
+ struct strv tmp;
+ strv_init (&tmp);
dump_matching_options (ctx->config.root, key, &tmp);
log_global_status (ctx, "Option changed: #s", tmp.vector[0]);
- str_vector_free (&tmp);
+ strv_free (&tmp);
}
}
static bool
handle_command_set_assign
- (struct app_context *ctx, struct str_vector *all, char *arguments)
+ (struct app_context *ctx, struct strv *all, char *arguments)
{
char *op = cut_word (&arguments);
bool add = false;
@@ -10899,8 +10899,8 @@ handle_command_set (struct handler_args *a)
if (*a->arguments)
option = cut_word (&a->arguments);
- struct str_vector all;
- str_vector_init (&all);
+ struct strv all;
+ strv_init (&all);
dump_matching_options (ctx->config.root, option, &all);
bool result = true;
@@ -10915,7 +10915,7 @@ handle_command_set (struct handler_args *a)
else
result = handle_command_set_assign (ctx, &all, a->arguments);
- str_vector_free (&all);
+ strv_free (&all);
return result;
}
@@ -11161,12 +11161,12 @@ handle_command_part (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&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);
+ strv_free (&v);
}
else if (a->buffer->type != BUFFER_CHANNEL)
log_server_error (a->s, a->buffer, "#s: #s", "Can't part",
@@ -11204,12 +11204,12 @@ handle_command_cycle (struct handler_args *a)
{
if (irc_is_channel (a->s, a->arguments))
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&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);
+ strv_free (&v);
}
else if (a->buffer->type != BUFFER_CHANNEL)
log_server_error (a->s, a->buffer, "#s: #s", "Can't cycle",
@@ -11301,7 +11301,7 @@ handle_command_kickban (struct handler_args *a)
static void
mass_channel_mode (struct server *s, const char *channel_name,
- bool adding, char mode_char, struct str_vector *v)
+ bool adding, char mode_char, struct strv *v)
{
size_t n;
for (size_t i = 0; i < v->len; i += n)
@@ -11328,8 +11328,8 @@ static void
mass_channel_mode_mask_list
(struct handler_args *a, bool adding, char mode_char)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
// XXX: this may be a bit too trivial; we could also map nicknames
@@ -11345,7 +11345,7 @@ mass_channel_mode_mask_list
}
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
- str_vector_free (&v);
+ strv_free (&v);
}
static bool
@@ -11371,15 +11371,15 @@ handle_command_unban (struct handler_args *a)
static bool
handle_command_invite (struct handler_args *a)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
bool result = !!v.len;
for (size_t i = 0; i < v.len; i++)
irc_send (a->s, "INVITE %s %s", v.vector[i], a->channel_name);
- str_vector_free (&v);
+ strv_free (&v);
return result;
}
@@ -11626,11 +11626,11 @@ handle_command_channel_mode
if (!*a->arguments)
return false;
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
cstr_split (a->arguments, " ", true, &v);
mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v);
- str_vector_free (&v);
+ strv_free (&v);
return true;
}
@@ -11966,8 +11966,8 @@ process_user_command (struct app_context *ctx, struct buffer *buffer,
static const char *
expand_alias_escape (const char *p, const char *arguments, struct str *output)
{
- struct str_vector words;
- str_vector_init (&words);
+ struct strv words;
+ strv_init (&words);
cstr_split (arguments, " ", true, &words);
// TODO: eventually also add support for argument ranges
@@ -11984,13 +11984,13 @@ expand_alias_escape (const char *p, const char *arguments, struct str *output)
else
str_append_printf (output, "$%c", *p);
- str_vector_free (&words);
+ strv_free (&words);
return ++p;
}
static void
expand_alias_definition (const char *definition, const char *arguments,
- struct str_vector *commands)
+ struct strv *commands)
{
struct str expanded;
str_init (&expanded);
@@ -12005,7 +12005,7 @@ expand_alias_definition (const char *definition, const char *arguments,
}
else if (*p == ';')
{
- str_vector_add_owned (commands, str_steal (&expanded));
+ strv_append_owned (commands, str_steal (&expanded));
str_init (&expanded);
}
else if (*p == '$' && p[1])
@@ -12013,12 +12013,12 @@ expand_alias_definition (const char *definition, const char *arguments,
else
str_append_c (&expanded, *p);
}
- str_vector_add_owned (commands, str_steal (&expanded));
+ strv_append_owned (commands, str_steal (&expanded));
}
static bool
expand_alias (struct app_context *ctx,
- const char *alias_name, char *input, struct str_vector *commands)
+ const char *alias_name, char *input, struct strv *commands)
{
struct config_item *entry =
str_map_find (get_aliases_config (ctx), alias_name);
@@ -12072,7 +12072,7 @@ send_message_to_buffer (struct app_context *ctx, struct buffer *buffer,
static bool
process_alias (struct app_context *ctx, struct buffer *buffer,
- struct str_vector *commands, int level)
+ struct strv *commands, int level)
{
for (size_t i = 0; i < commands->len; i++)
log_global_debug (ctx, "Alias expanded to: ###d: \"#s\"",
@@ -12097,8 +12097,8 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
if (process_user_command (ctx, buffer, name, input))
return true;
- struct str_vector commands;
- str_vector_init (&commands);
+ struct strv commands;
+ strv_init (&commands);
bool result = false;
if (!expand_alias (ctx, name, input, &commands))
@@ -12108,7 +12108,7 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer,
else
result = process_alias (ctx, buffer, &commands, alias_level);
- str_vector_free (&commands);
+ strv_free (&commands);
return result;
}
@@ -12155,8 +12155,8 @@ process_input (struct app_context *ctx, char *user_input)
print_error ("character conversion failed for: %s", "user input");
else
{
- struct str_vector lines;
- str_vector_init (&lines);
+ struct strv lines;
+ strv_init (&lines);
// XXX: this interprets commands in pasted text
cstr_split (input, "\r\n", false, &lines);
@@ -12164,7 +12164,7 @@ process_input (struct app_context *ctx, char *user_input)
(void) process_input_utf8 (ctx,
ctx->current_buffer, lines.vector[i], 0);
- str_vector_free (&lines);
+ strv_free (&lines);
}
free (input);
}
@@ -12277,7 +12277,7 @@ utf8_common_prefix (const char **vector, size_t len)
static void
complete_command (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
@@ -12293,7 +12293,7 @@ complete_command (struct app_context *ctx, struct completion *data,
{
struct command_handler *handler = &g_command_handlers[i];
if (!strncasecmp_ascii (word, handler->name, word_len))
- str_vector_add_owned (output,
+ strv_append_owned (output,
xstrdup_printf ("%s%s", prefix, handler->name));
}
@@ -12303,22 +12303,22 @@ complete_command (struct app_context *ctx, struct completion *data,
while ((alias = str_map_iter_next (&iter)))
{
if (!strncasecmp_ascii (word, iter.link->key, word_len))
- str_vector_add_owned (output,
+ strv_append_owned (output,
xstrdup_printf ("%s%s", prefix, iter.link->key));
}
}
static void
complete_option (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
- struct str_vector options;
- str_vector_init (&options);
+ struct strv options;
+ strv_init (&options);
config_dump (ctx->config.root, &options);
- str_vector_sort (&options);
+ strv_sort (&options);
// Wildcard expansion is an interesting side-effect
char *mask = xstrdup_printf ("%s*", word);
@@ -12326,17 +12326,17 @@ complete_option (struct app_context *ctx, struct completion *data,
{
char *key = cstr_cut_until (options.vector[i], " ");
if (!fnmatch (mask, key, 0))
- str_vector_add_owned (output, key);
+ strv_append_owned (output, key);
else
free (key);
}
free (mask);
- str_vector_free (&options);
+ strv_free (&options);
}
static void
complete_topic (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
(void) data;
@@ -12351,7 +12351,7 @@ complete_topic (struct app_context *ctx, struct completion *data,
{
// We must prepend the channel name if the topic itself starts
// with something that could be regarded as a channel name
- str_vector_add_owned (output, irc_is_channel (buffer->server, topic)
+ strv_append_owned (output, irc_is_channel (buffer->server, topic)
? xstrdup_printf ("%s %s", buffer->channel->name, topic)
: xstrdup (topic));
}
@@ -12359,14 +12359,14 @@ complete_topic (struct app_context *ctx, struct completion *data,
static void
complete_nicknames (struct app_context *ctx, struct completion *data,
- const char *word, struct str_vector *output)
+ const char *word, struct strv *output)
{
struct buffer *buffer = ctx->current_buffer;
if (buffer->type == BUFFER_SERVER)
{
struct user *self_user = buffer->server->irc_user;
if (self_user)
- str_vector_add (output, self_user->nickname);
+ strv_append (output, self_user->nickname);
}
if (buffer->type != BUFFER_CHANNEL)
return;
@@ -12377,7 +12377,7 @@ complete_nicknames (struct app_context *ctx, struct completion *data,
const char *nickname = iter->user->nickname;
if (irc_server_strncmp (buffer->server, word, nickname, word_len))
continue;
- str_vector_add_owned (output, data->location == 0
+ strv_append_owned (output, data->location == 0
? xstrdup_printf ("%s:", nickname)
: xstrdup (nickname));
}
@@ -12404,11 +12404,11 @@ complete_word (struct app_context *ctx, struct completion *data,
else
try_nicknames = true;
- struct str_vector words;
- str_vector_init (&words);
+ struct strv words;
+ strv_init (&words);
// Add placeholder
- str_vector_add_owned (&words, NULL);
+ strv_append_owned (&words, NULL);
if (try_commands) complete_command (ctx, data, word, &words);
if (try_options) complete_option (ctx, data, word, &words);
@@ -12424,7 +12424,7 @@ complete_word (struct app_context *ctx, struct completion *data,
if (words.len == 1)
{
// Nothing matched
- str_vector_free (&words);
+ strv_free (&words);
return NULL;
}
@@ -13086,7 +13086,7 @@ on_readline_input (char *line)
// readline always erases the input line after returning from here,
// but we don't want that in order to allow correct buffer switching
- str_vector_add_owned (&ctx->pending_input, line);
+ strv_append_owned (&ctx->pending_input, line);
poller_idle_set (&ctx->input_event);
}
else
@@ -13229,7 +13229,7 @@ on_editline_return (EditLine *editline, int key)
// process_input() expects a multibyte string
const LineInfo *info_mb = el_line (editline);
- str_vector_add_owned (&ctx->pending_input,
+ strv_append_owned (&ctx->pending_input,
xstrndup (info_mb->buffer, info_mb->lastchar - info_mb->buffer));
poller_idle_set (&ctx->input_event);
@@ -13574,7 +13574,7 @@ process_mirc_escape (const struct pollfd *fd, struct app_context *ctx)
// There's no other way with libedit, as both el_getc() in a function
// handler and CC_ARGHACK would block execution
struct str *buf = &ctx->input_buffer;
- str_ensure_space (buf, 1);
+ str_reserve (buf, 1);
if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;
buf->str[++buf->len] = '\0';
@@ -13626,7 +13626,7 @@ static void
process_bracketed_paste (const struct pollfd *fd, struct app_context *ctx)
{
struct str *buf = &ctx->input_buffer;
- str_ensure_space (buf, 1);
+ str_reserve (buf, 1);
if (read (fd->fd, buf->str + buf->len, 1) != 1)
goto error;
buf->str[++buf->len] = '\0';
@@ -13736,6 +13736,7 @@ rearm_flush_timer (struct app_context *ctx)
static void
on_flush_timer (struct app_context *ctx)
{
+ // TODO: maybe also garbage collect all plugins?
// I guess we don't need to do anything more complicated
fflush (NULL);
rearm_flush_timer (ctx);
@@ -13777,7 +13778,7 @@ on_pending_input (struct app_context *ctx)
poller_idle_reset (&ctx->input_event);
for (size_t i = 0; i < ctx->pending_input.len; i++)
process_input (ctx, ctx->pending_input.vector[i]);
- str_vector_reset (&ctx->pending_input);
+ strv_reset (&ctx->pending_input);
}
static void
@@ -13875,13 +13876,13 @@ test_config (void)
config_load (&config, config_item_parse (s.str, s.len, false, NULL));
str_free (&s);
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
dump_matching_options (config.root, "*foo*", &v);
hard_assert (v.len == 2);
hard_assert (!strcmp (v.vector[0], "top.foo = off"));
hard_assert (!strcmp (v.vector[1], "top.foobar = \"qux\""));
- str_vector_free (&v);
+ strv_free (&v);
config_free (&config);
}
@@ -13891,15 +13892,15 @@ test_config (void)
static void
test_aliases (void)
{
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
expand_alias_definition ("/foo; /bar $* $$$;;;$1$2$3$4", "foo bar baz", &v);
hard_assert (v.len == 4);
hard_assert (!strcmp (v.vector[0], "/foo"));
hard_assert (!strcmp (v.vector[1], " /bar foo bar baz $;"));
hard_assert (!strcmp (v.vector[2], ""));
hard_assert (!strcmp (v.vector[3], "foobarbaz"));
- str_vector_free (&v);
+ strv_free (&v);
}
static void
@@ -13909,13 +13910,13 @@ test_wrapping (void)
static const char *split[] =
{ " foo", "bar", "foob", "ar", "fó", "ób", "árb", "áz" };
- struct str_vector v;
- str_vector_init (&v);
+ struct strv v;
+ strv_init (&v);
hard_assert (wrap_message (message, 4, &v, NULL));
hard_assert (v.len == N_ELEMENTS (split));
for (size_t i = 0; i < N_ELEMENTS (split); i++)
hard_assert (!strcmp (v.vector[i], split[i]));
- str_vector_free (&v);
+ strv_free (&v);
}
static void
diff --git a/kike.c b/kike.c
index aba5bba..4772c29 100644
--- a/kike.c
+++ b/kike.c
@@ -456,9 +456,9 @@ struct channel
struct channel_user *users; ///< Channel users
- struct str_vector ban_list; ///< Ban list
- struct str_vector exception_list; ///< Exceptions from bans
- struct str_vector invite_list; ///< Exceptions from +I
+ struct strv ban_list; ///< Ban list
+ struct strv exception_list; ///< Exceptions from bans
+ struct strv invite_list; ///< Exceptions from +I
};
static struct channel *
@@ -469,9 +469,9 @@ channel_new (void)
self->user_limit = -1;
self->topic = xstrdup ("");
- str_vector_init (&self->ban_list);
- str_vector_init (&self->exception_list);
- str_vector_init (&self->invite_list);
+ strv_init (&self->ban_list);
+ strv_init (&self->exception_list);
+ strv_init (&self->invite_list);
return self;
}
@@ -490,9 +490,9 @@ channel_delete (struct channel *self)
free (link);
}
- str_vector_free (&self->ban_list);
- str_vector_free (&self->exception_list);
- str_vector_free (&self->invite_list);
+ strv_free (&self->ban_list);
+ strv_free (&self->exception_list);
+ strv_free (&self->invite_list);
free (self);
}
@@ -633,7 +633,7 @@ struct server_context
char *server_name; ///< Our server name
unsigned ping_interval; ///< Ping interval in seconds
unsigned max_connections; ///< Max. connections allowed or 0
- struct str_vector motd; ///< MOTD (none if empty)
+ struct strv motd; ///< MOTD (none if empty)
nl_catd catalog; ///< Message catalog for server msgs
struct str_map operators; ///< TLS cert. fingerprints for IRCops
};
@@ -679,7 +679,7 @@ server_context_init (struct server_context *self)
self->config.free = free;
simple_config_load_defaults (&self->config, g_config_table);
- str_vector_init (&self->motd);
+ strv_init (&self->motd);
self->catalog = (nl_catd) -1;
str_map_init (&self->operators);
// The regular irc_strxfrm() is sufficient for fingerprints
@@ -712,7 +712,7 @@ server_context_free (struct server_context *self)
str_map_free (&self->whowas);
poller_free (&self->poller);
- str_vector_free (&self->motd);
+ strv_free (&self->motd);
if (self->catalog != (nl_catd) -1)
catclose (self->catalog);
str_map_free (&self->operators);
@@ -972,7 +972,7 @@ client_close_link (struct client *c, const char *reason)
}
static bool
-client_in_mask_list (const struct client *c, const struct str_vector *mask)
+client_in_mask_list (const struct client *c, const struct strv *mask)
{
char *client = xstrdup_printf ("%s!%s@%s",
c->nickname, c->username, c->hostname);
@@ -1250,7 +1250,7 @@ struct irc_cap_args
{
const char *subcommand; ///< The subcommand being processed
const char *full_params; ///< Whole parameter string
- struct str_vector params; ///< Split parameters
+ struct strv params; ///< Split parameters
const char *target; ///< Target parameter for replies
};
@@ -1284,15 +1284,15 @@ irc_handle_cap_ls (struct client *c, struct irc_cap_args *a)
static void
irc_handle_cap_list (struct client *c, struct irc_cap_args *a)
{
- struct str_vector caps;
- str_vector_init (&caps);
+ struct strv caps;
+ strv_init (&caps);
for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
if (c->caps_enabled & irc_cap_table[i].flag)
- str_vector_add (&caps, irc_cap_table[i].name);
+ strv_append (&caps, irc_cap_table[i].name);
- char *caps_str = join_str_vector (&caps, ' ');
- str_vector_free (&caps);
+ char *caps_str = strv_join (&caps, " ");
+ strv_free (&caps);
client_send (c, ":%s CAP %s LIST :%s",
c->ctx->server_name, a->target, caps_str);
free (caps_str);
@@ -1398,7 +1398,7 @@ irc_handle_cap (const struct irc_message *msg, struct client *c)
args.target = c->nickname ? c->nickname : "*";
args.subcommand = msg->params.vector[0];
args.full_params = "";
- str_vector_init (&args.params);
+ strv_init (&args.params);
if (msg->params.len > 1)
{
@@ -1414,7 +1414,7 @@ irc_handle_cap (const struct irc_message *msg, struct client *c)
else
cmd->handler (c, &args);
- str_vector_free (&args.params);
+ strv_free (&args.params);
}
static void
@@ -1699,7 +1699,7 @@ irc_handle_user_mode_change (struct client *c, const char *mode_string)
static void
irc_send_channel_list (struct client *c, const char *channel_name,
- const struct str_vector *list, int reply, int end_reply)
+ const struct strv *list, int reply, int end_reply)
{
for (size_t i = 0; i < list->len; i++)
irc_send_reply (c, reply, channel_name, list->vector[i]);
@@ -1751,11 +1751,11 @@ struct mode_processor
struct str added; ///< Added modes
struct str removed; ///< Removed modes
- struct str_vector added_params; ///< Params for added modes
- struct str_vector removed_params; ///< Params for removed modes
+ struct strv added_params; ///< Params for added modes
+ struct strv removed_params; ///< Params for removed modes
struct str *output; ///< "added" or "removed"
- struct str_vector *output_params; ///< Similarly for "*_params"
+ struct strv *output_params; ///< Similarly for "*_params"
};
static void
@@ -1766,8 +1766,8 @@ mode_processor_init (struct mode_processor *self)
str_init (&self->added);
str_init (&self->removed);
- str_vector_init (&self->added_params);
- str_vector_init (&self->removed_params);
+ strv_init (&self->added_params);
+ strv_init (&self->removed_params);
}
static void
@@ -1776,8 +1776,8 @@ mode_processor_free (struct mode_processor *self)
str_free (&self->added);
str_free (&self->removed);
- str_vector_free (&self->added_params);
- str_vector_free (&self->removed_params);
+ strv_free (&self->added_params);
+ strv_free (&self->removed_params);
}
static const char *
@@ -1816,7 +1816,7 @@ mode_processor_do_user (struct mode_processor *self, int mode)
else if (irc_modify_mode (&target_user->modes, mode, self->adding))
{
str_append_c (self->output, self->mode_char);
- str_vector_add (self->output_params, client->nickname);
+ strv_append (self->output_params, client->nickname);
}
}
@@ -1842,7 +1842,7 @@ mode_processor_do_chan_remove
static void
mode_processor_do_list (struct mode_processor *self,
- struct str_vector *list, int list_msg, int end_msg)
+ struct strv *list, int list_msg, int end_msg)
{
const char *target = mode_processor_next_param (self);
if (!target)
@@ -1869,12 +1869,12 @@ mode_processor_do_list (struct mode_processor *self,
if ((found ^ self->adding))
{
if (self->adding)
- str_vector_add (list, mask);
+ strv_append (list, mask);
else
- str_vector_remove (list, i);
+ strv_remove (list, i);
str_append_c (self->output, self->mode_char);
- str_vector_add (self->output_params, mask);
+ strv_append (self->output_params, mask);
}
free (mask);
}
@@ -1892,7 +1892,7 @@ mode_processor_do_key (struct mode_processor *self)
return;
str_append_c (&self->removed, self->mode_char);
- str_vector_add (&self->removed_params, self->channel->key);
+ strv_append (&self->removed_params, self->channel->key);
free (self->channel->key);
self->channel->key = NULL;
}
@@ -1905,7 +1905,7 @@ mode_processor_do_key (struct mode_processor *self)
{
self->channel->key = xstrdup (target);
str_append_c (&self->added, self->mode_char);
- str_vector_add (&self->added_params, self->channel->key);
+ strv_append (&self->added_params, self->channel->key);
}
}
@@ -1931,7 +1931,7 @@ mode_processor_do_limit (struct mode_processor *self)
{
self->channel->user_limit = x;
str_append_c (&self->added, self->mode_char);
- str_vector_add (&self->added_params, target);
+ strv_append (&self->added_params, target);
}
}
}
@@ -2184,15 +2184,15 @@ irc_handle_list (const struct irc_message *msg, struct client *c)
}
else
{
- struct str_vector channels;
- str_vector_init (&channels);
+ struct strv channels;
+ strv_init (&channels);
cstr_split (msg->params.vector[0], ",", true, &channels);
for (size_t i = 0; i < channels.len; i++)
if ((chan = str_map_find (&c->ctx->channels, channels.vector[i]))
&& (!(chan->modes & IRC_CHAN_MODE_SECRET)
|| channel_get_user (chan, c)))
irc_send_rpl_list (c, chan);
- str_vector_free (&channels);
+ strv_free (&channels);
}
irc_send_reply (c, IRC_RPL_LISTEND);
}
@@ -2238,8 +2238,8 @@ static void
irc_send_rpl_namreply (struct client *c, const struct channel *chan,
struct str_map *used_nicks)
{
- struct str_vector nicks;
- str_vector_init (&nicks);
+ struct strv nicks;
+ strv_init (&nicks);
char type = '=';
if (chan->modes & IRC_CHAN_MODE_SECRET)
@@ -2254,20 +2254,20 @@ irc_send_rpl_namreply (struct client *c, const struct channel *chan,
continue;
if (used_nicks)
str_map_set (used_nicks, iter->c->nickname, (void *) 1);
- str_vector_add_owned (&nicks,
+ strv_append_owned (&nicks,
irc_make_rpl_namreply_item (c, iter->c, iter));
}
irc_send_reply_vector (c, IRC_RPL_NAMREPLY,
nicks.vector, type, chan->name, "");
- str_vector_free (&nicks);
+ strv_free (&nicks);
}
static void
irc_send_disassociated_names (struct client *c, struct str_map *used)
{
- struct str_vector nicks;
- str_vector_init (&nicks);
+ struct strv nicks;
+ strv_init (&nicks);
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->users);
@@ -2277,14 +2277,14 @@ irc_send_disassociated_names (struct client *c, struct str_map *used)
if ((target->mode & IRC_USER_MODE_INVISIBLE)
|| str_map_find (used, target->nickname))
continue;
- str_vector_add_owned (&nicks,
+ strv_append_owned (&nicks,
irc_make_rpl_namreply_item (c, target, NULL));
}
if (nicks.len)
irc_send_reply_vector (c, IRC_RPL_NAMREPLY,
nicks.vector, '*', "*", "");
- str_vector_free (&nicks);
+ strv_free (&nicks);
}
static void
@@ -2315,8 +2315,8 @@ irc_handle_names (const struct irc_message *msg, struct client *c)
}
else
{
- struct str_vector channels;
- str_vector_init (&channels);
+ struct strv channels;
+ strv_init (&channels);
cstr_split (msg->params.vector[0], ",", true, &channels);
for (size_t i = 0; i < channels.len; i++)
if ((chan = str_map_find (&c->ctx->channels, channels.vector[i]))
@@ -2326,7 +2326,7 @@ irc_handle_names (const struct irc_message *msg, struct client *c)
irc_send_rpl_namreply (c, chan, NULL);
irc_send_reply (c, IRC_RPL_ENDOFNAMES, channels.vector[i]);
}
- str_vector_free (&channels);
+ strv_free (&channels);
}
}
@@ -2441,8 +2441,8 @@ irc_send_whois_reply (struct client *c, const struct client *target)
if (target->away_message)
irc_send_reply (c, IRC_RPL_AWAY, nick, target->away_message);
- struct str_vector channels;
- str_vector_init (&channels);
+ struct strv channels;
+ strv_init (&channels);
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
@@ -2460,11 +2460,11 @@ irc_send_whois_reply (struct client *c, const struct client *target)
else if (channel_user->modes & IRC_CHAN_MODE_VOICE)
str_append_c (&item, '+');
str_append (&item, chan->name);
- str_vector_add_owned (&channels, str_steal (&item));
+ strv_append_owned (&channels, str_steal (&item));
}
irc_send_reply_vector (c, IRC_RPL_WHOISCHANNELS, channels.vector, nick, "");
- str_vector_free (&channels);
+ strv_free (&channels);
irc_send_reply (c, IRC_RPL_ENDOFWHOIS, nick);
}
@@ -2477,8 +2477,8 @@ irc_handle_whois (const struct irc_message *msg, struct client *c)
if (msg->params.len > 1 && !irc_is_this_me (c->ctx, msg->params.vector[0]))
RETURN_WITH_REPLY (c, IRC_ERR_NOSUCHSERVER, msg->params.vector[0]);
- struct str_vector masks;
- str_vector_init (&masks);
+ struct strv masks;
+ strv_init (&masks);
const char *masks_str = msg->params.vector[msg->params.len > 1];
cstr_split (masks_str, ",", true, &masks);
for (size_t i = 0; i < masks.len; i++)
@@ -2507,7 +2507,7 @@ irc_handle_whois (const struct irc_message *msg, struct client *c)
irc_send_reply (c, IRC_ERR_NOSUCHNICK, mask);
}
}
- str_vector_free (&masks);
+ strv_free (&masks);
}
static void
@@ -2519,8 +2519,8 @@ irc_handle_whowas (const struct irc_message *msg, struct client *c)
RETURN_WITH_REPLY (c, IRC_ERR_NOSUCHSERVER, msg->params.vector[2]);
// The "count" parameter is ignored, we only store one entry for a nick
- struct str_vector nicks;
- str_vector_init (&nicks);
+ struct strv nicks;
+ strv_init (&nicks);
cstr_split (msg->params.vector[0], ",", true, &nicks);
for (size_t i = 0; i < nicks.len; i++)
@@ -2538,7 +2538,7 @@ irc_handle_whowas (const struct irc_message *msg, struct client *c)
}
irc_send_reply (c, IRC_RPL_ENDOFWHOWAS, nick);
}
- str_vector_free (&nicks);
+ strv_free (&nicks);
}
static void
@@ -2639,12 +2639,12 @@ irc_handle_part (const struct irc_message *msg, struct client *c)
RETURN_WITH_REPLY (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
const char *reason = msg->params.len > 1 ? msg->params.vector[1] : NULL;
- struct str_vector channels;
- str_vector_init (&channels);
+ struct strv channels;
+ strv_init (&channels);
cstr_split (msg->params.vector[0], ",", true, &channels);
for (size_t i = 0; i < channels.len; i++)
irc_try_part (c, channels.vector[i], reason);
- str_vector_free (&channels);
+ strv_free (&channels);
}
static void
@@ -2688,10 +2688,10 @@ irc_handle_kick (const struct irc_message *msg, struct client *c)
if (msg->params.len > 2)
reason = msg->params.vector[2];
- struct str_vector channels;
- struct str_vector users;
- str_vector_init (&channels);
- str_vector_init (&users);
+ struct strv channels;
+ struct strv users;
+ strv_init (&channels);
+ strv_init (&users);
cstr_split (msg->params.vector[0], ",", true, &channels);
cstr_split (msg->params.vector[1], ",", true, &users);
@@ -2702,8 +2702,8 @@ irc_handle_kick (const struct irc_message *msg, struct client *c)
for (size_t i = 0; i < channels.len && i < users.len; i++)
irc_try_kick (c, channels.vector[i], users.vector[i], reason);
- str_vector_free (&channels);
- str_vector_free (&users);
+ strv_free (&channels);
+ strv_free (&users);
}
static void
@@ -2817,10 +2817,10 @@ irc_handle_join (const struct irc_message *msg, struct client *c)
return;
}
- struct str_vector channels;
- struct str_vector keys;
- str_vector_init (&channels);
- str_vector_init (&keys);
+ struct strv channels;
+ struct strv keys;
+ strv_init (&channels);
+ strv_init (&keys);
cstr_split (msg->params.vector[0], ",", true, &channels);
if (msg->params.len > 1)
cstr_split (msg->params.vector[1], ",", true, &keys);
@@ -2829,8 +2829,8 @@ irc_handle_join (const struct irc_message *msg, struct client *c)
irc_try_join (c, channels.vector[i],
i < keys.len ? keys.vector[i] : NULL);
- str_vector_free (&channels);
- str_vector_free (&keys);
+ strv_free (&channels);
+ strv_free (&keys);
}
static void
@@ -3113,7 +3113,7 @@ irc_try_read (struct client *c)
while (true)
{
- str_ensure_space (buf, 512);
+ str_reserve (buf, 512);
n_read = recv (c->socket_fd, buf->str + buf->len,
buf->alloc - buf->len - 1 /* null byte */, 0);
@@ -3151,7 +3151,7 @@ irc_try_read_tls (struct client *c)
c->ssl_rx_want_tx = false;
while (true)
{
- str_ensure_space (buf, 512);
+ str_reserve (buf, 512);
ERR_clear_error ();
int n_read = SSL_read (c->ssl, buf->str + buf->len,
buf->alloc - buf->len - 1 /* null byte */);
@@ -3711,7 +3711,7 @@ irc_initialize_motd (struct server_context *ctx, struct error **e)
struct str line;
str_init (&line);
while (read_line (fp, &line))
- str_vector_add_owned (&ctx->motd, str_steal (&line));
+ strv_append_owned (&ctx->motd, str_steal (&line));
str_free (&line);
fclose (fp);
@@ -3740,8 +3740,8 @@ irc_parse_config (struct server_context *ctx, struct error **e)
PARSE_UNSIGNED (max_connections, 0, UINT_MAX);
bool result = true;
- struct str_vector fingerprints;
- str_vector_init (&fingerprints);
+ struct strv fingerprints;
+ strv_init (&fingerprints);
const char *operators = str_map_find (&ctx->config, "operators");
if (operators)
cstr_split (operators, ",", true, &fingerprints);
@@ -3757,7 +3757,7 @@ irc_parse_config (struct server_context *ctx, struct error **e)
}
str_map_set (&ctx->operators, key, (void *) 1);
}
- str_vector_free (&fingerprints);
+ strv_free (&fingerprints);
return result;
}
@@ -3903,14 +3903,14 @@ irc_setup_listen_fds (struct server_context *ctx, struct error **e)
gai_hints.ai_socktype = SOCK_STREAM;
gai_hints.ai_flags = AI_PASSIVE;
- struct str_vector ports;
- str_vector_init (&ports);
+ struct strv ports;
+ strv_init (&ports);
cstr_split (bind_port, ",", true, &ports);
ctx->listen_fds = xcalloc (ports.len, sizeof *ctx->listen_fds);
ctx->listen_events = xcalloc (ports.len, sizeof *ctx->listen_events);
for (size_t i = 0; i < ports.len; i++)
irc_listen_resolve (ctx, bind_host, ports.vector[i], &gai_hints);
- str_vector_free (&ports);
+ strv_free (&ports);
if (!ctx->n_listen_fds)
{
diff --git a/liberty b/liberty
-Subproject f53b717f3bba27ca1c42486d3742c91967f3fe9
+Subproject 084e964286bfcd13ee6a25a2ee35dfba9da1072
diff --git a/zyklonb.c b/zyklonb.c
index e84134c..fd0c80a 100644
--- a/zyklonb.c
+++ b/zyklonb.c
@@ -509,7 +509,7 @@ irc_establish_connection (struct bot_context *ctx,
static int g_signal_pipe[2]; ///< A pipe used to signal... signals
-static struct str_vector
+static struct strv
g_original_argv, ///< Original program arguments
g_recovery_env; ///< Environment for re-exec recovery
@@ -684,8 +684,8 @@ recovery_handler (int signum, siginfo_t *info, void *context)
static void
prepare_recovery_environment (void)
{
- str_vector_init (&g_recovery_env);
- str_vector_add_vector (&g_recovery_env, environ);
+ strv_init (&g_recovery_env);
+ strv_append_vector (&g_recovery_env, environ);
// Prepare a location within the environment where we will put the startup
// (or maybe rather restart) reason in case of an irrecoverable error.
@@ -702,7 +702,7 @@ prepare_recovery_environment (void)
else
{
g_startup_reason_location = g_recovery_env.vector + g_recovery_env.len;
- str_vector_add (&g_recovery_env, "");
+ strv_append (&g_recovery_env, "");
}
}
@@ -964,7 +964,7 @@ on_plugin_readable (const struct pollfd *fd, struct plugin *plugin)
struct str *buf = &plugin->read_buffer;
while (true)
{
- str_ensure_space (buf, 512 + 1);
+ str_reserve (buf, 512 + 1);
ssize_t n_read = read (fd->fd, buf->str + buf->len,
buf->alloc - buf->len - 1);
@@ -1173,8 +1173,8 @@ plugin_load_all_from_config (struct bot_context *ctx)
if (!plugin_list)
return;
- struct str_vector plugins;
- str_vector_init (&plugins);
+ struct strv plugins;
+ strv_init (&plugins);
cstr_split (plugin_list, ",", true, &plugins);
for (size_t i = 0; i < plugins.len; i++)
@@ -1189,7 +1189,7 @@ plugin_load_all_from_config (struct bot_context *ctx)
}
}
- str_vector_free (&plugins);
+ strv_free (&plugins);
}
// --- Main program ------------------------------------------------------------
@@ -1214,13 +1214,13 @@ parse_bot_command (const char *s, const char *command, const char **following)
}
static void
-split_bot_command_argument_list (const char *arguments, struct str_vector *out)
+split_bot_command_argument_list (const char *arguments, struct strv *out)
{
cstr_split (arguments, ",", true, out);
for (size_t i = 0; i < out->len; )
{
if (!*cstr_strip_in_place (out->vector[i], " \t"))
- str_vector_remove (out, i);
+ strv_remove (out, i);
else
i++;
}
@@ -1367,8 +1367,8 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
return;
const char *following;
- struct str_vector list;
- str_vector_init (&list);
+ struct strv list;
+ strv_init (&list);
if (parse_bot_command (text, "quote", &following))
// This seems to replace tons of random stupid commands
@@ -1408,7 +1408,7 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
process_plugin_unload (ctx, msg, list.vector[i]);
}
- str_vector_free (&list);
+ strv_free (&list);
}
static void
@@ -1646,7 +1646,7 @@ on_irc_readable (const struct pollfd *fd, struct bot_context *ctx)
bool disconnected = false;
while (true)
{
- str_ensure_space (buf, 512);
+ str_reserve (buf, 512);
switch (fill_buffer (ctx, buf))
{
case IRC_READ_AGAIN:
@@ -1967,8 +1967,8 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
int
main (int argc, char *argv[])
{
- str_vector_init (&g_original_argv);
- str_vector_add_vector (&g_original_argv, argv);
+ strv_init (&g_original_argv);
+ strv_append_vector (&g_original_argv, argv);
static const struct opt opts[] =
{
@@ -2056,7 +2056,7 @@ main (int argc, char *argv[])
poller_run (&ctx.poller);
bot_context_free (&ctx);
- str_vector_free (&g_original_argv);
+ strv_free (&g_original_argv);
return EXIT_SUCCESS;
}