Bump liberty

This commit is contained in:
Přemysl Eric Janouch 2017-06-22 22:39:39 +02:00
parent 933760c2a2
commit 68bc297809
Signed by: p
GPG Key ID: B715679E3A361BE6
6 changed files with 256 additions and 418 deletions

View File

@ -8,8 +8,8 @@ option (WANT_LIBEDIT "Use BSD libedit for the UI" OFF)
# Moar warnings
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
# -Wunused-function is pretty annoying here, as everything is static
set (CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wno-unused-function")
set (wdisabled "-Wno-unused-function -Wno-implicit-fallthrough")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra ${wdisabled}")
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
# Version

View File

@ -81,11 +81,10 @@ unixtime_msec (long *msec)
static char *
resolve_relative_runtime_unique_filename (const char *filename)
{
struct str path;
str_init (&path);
const char *runtime_dir = getenv ("XDG_RUNTIME_DIR");
const char *tmpdir = getenv ("TMPDIR");
struct str path = str_make ();
if (runtime_dir && *runtime_dir == '/')
str_append (&path, runtime_dir);
else if (tmpdir && *tmpdir == '/')
@ -726,8 +725,8 @@ socks_call_on_data (struct socks_connector *self)
if (self->read_buffer.len < to_consume)
return true;
struct msg_unpacker unpacker;
msg_unpacker_init (&unpacker, self->read_buffer.str, self->read_buffer.len);
struct msg_unpacker unpacker =
msg_unpacker_make (self->read_buffer.str, self->read_buffer.len);
bool result = self->on_data (self, &unpacker);
str_remove_slice (&self->read_buffer, 0, to_consume);
return result;
@ -792,16 +791,16 @@ socks_connector_init (struct socks_connector *self, struct poller *poller)
{
memset (self, 0, sizeof *self);
poller_fd_init (&self->socket_event, poller, (self->socket_fd = -1));
self->socket_event = poller_fd_make (poller, (self->socket_fd = -1));
self->socket_event.dispatcher = (poller_fd_fn) socks_connector_on_ready;
self->socket_event.user_data = self;
poller_timer_init (&self->timeout, poller);
self->timeout = poller_timer_make (poller);
self->timeout.dispatcher = (poller_timer_fn) socks_connector_on_timeout;
self->timeout.user_data = self;
str_init (&self->read_buffer);
str_init (&self->write_buffer);
self->read_buffer = str_make ();
self->write_buffer = str_make ();
}
static void
@ -902,8 +901,8 @@ static struct ctcp_chunk *
ctcp_chunk_new (void)
{
struct ctcp_chunk *self = xcalloc (1, sizeof *self);
str_init (&self->tag);
str_init (&self->text);
self->tag = str_make ();
self->text = str_make ();
return self;
}
@ -992,8 +991,7 @@ ctcp_parse_tagged (const char *chunk, size_t len, struct ctcp_chunk *output)
static struct ctcp_chunk *
ctcp_parse (const char *message)
{
struct str m;
str_init (&m);
struct str m = str_make ();
ctcp_low_level_decode (message, &m);
struct ctcp_chunk *result = NULL, *result_tail = NULL;

369
degesch.c

File diff suppressed because it is too large Load Diff

219
kike.c
View File

@ -170,7 +170,7 @@ irc_regex_match (const char *regex, const char *s)
if (!initialized)
{
regex_cache_init (&cache);
cache = regex_cache_make ();
initialized = true;
}
@ -368,12 +368,12 @@ client_new (void)
{
struct client *self = xcalloc (1, sizeof *self);
self->socket_fd = -1;
str_init (&self->read_buffer);
str_init (&self->write_buffer);
self->read_buffer = str_make ();
self->write_buffer = str_make ();
self->cap_version = 301;
// TODO: make this configurable and more fine-grained
flood_detector_init (&self->antiflood, 10, 20);
str_map_init (&self->invites);
self->invites = str_map_make (NULL);
self->invites.key_xfrm = irc_strxfrm;
return self;
}
@ -470,9 +470,9 @@ channel_new (void)
self->user_limit = -1;
self->topic = xstrdup ("");
strv_init (&self->ban_list);
strv_init (&self->exception_list);
strv_init (&self->invite_list);
self->ban_list = strv_make ();
self->exception_list = strv_make ();
self->invite_list = strv_make ();
return self;
}
@ -501,9 +501,7 @@ channel_delete (struct channel *self)
static char *
channel_get_mode (struct channel *self, bool disclose_secrets)
{
struct str mode;
str_init (&mode);
struct str mode = str_make ();
unsigned m = self->modes;
if (m & IRC_CHAN_MODE_INVITE_ONLY) str_append_c (&mode, 'i');
if (m & IRC_CHAN_MODE_MODERATED) str_append_c (&mode, 'm');
@ -657,32 +655,29 @@ server_context_init (struct server_context *self)
{
memset (self, 0, sizeof *self);
str_map_init (&self->users);
self->users = str_map_make (NULL);
self->users.key_xfrm = irc_strxfrm;
str_map_init (&self->channels);
self->channels = str_map_make ((str_map_free_fn) channel_delete);
self->channels.key_xfrm = irc_strxfrm;
self->channels.free = (void (*) (void *)) channel_delete;
str_map_init (&self->handlers);
self->handlers = str_map_make (NULL);
self->handlers.key_xfrm = irc_strxfrm;
str_map_init (&self->cap_handlers);
self->cap_handlers = str_map_make (NULL);
self->cap_handlers.key_xfrm = irc_strxfrm;
str_map_init (&self->whowas);
self->whowas = str_map_make ((str_map_free_fn) whowas_info_destroy);
self->whowas.key_xfrm = irc_strxfrm;
self->whowas.free = (void (*) (void *)) whowas_info_destroy;
poller_init (&self->poller);
poller_timer_init (&self->quit_timer, &self->poller);
self->quit_timer = poller_timer_make (&self->poller);
self->quit_timer.dispatcher = on_irc_quit_timeout;
self->quit_timer.user_data = self;
str_map_init (&self->config);
self->config.free = free;
self->config = str_map_make (free);
simple_config_load_defaults (&self->config, g_config_table);
strv_init (&self->motd);
self->motd = strv_make ();
self->catalog = (nl_catd) -1;
str_map_init (&self->operators);
self->operators = str_map_make (NULL);
// The regular irc_strxfrm() is sufficient for fingerprints
self->operators.key_xfrm = irc_strxfrm;
}
@ -780,12 +775,10 @@ irc_channel_destroy_if_empty (struct server_context *ctx, struct channel *chan)
static void
irc_send_to_roommates (struct client *c, const char *message)
{
struct str_map targets;
str_map_init (&targets);
struct str_map targets = str_map_make (NULL);
targets.key_xfrm = irc_strxfrm;
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
struct channel *chan;
while ((chan = str_map_iter_next (&iter)))
{
@ -796,7 +789,7 @@ irc_send_to_roommates (struct client *c, const char *message)
str_map_set (&targets, iter->c->nickname, iter->c);
}
str_map_iter_init (&iter, &targets);
iter = str_map_iter_make (&targets);
struct client *target;
while ((target = str_map_iter_next (&iter)))
if (target != c)
@ -819,8 +812,7 @@ client_mode_to_str (unsigned m, struct str *out)
static char *
client_get_mode (struct client *self)
{
struct str mode;
str_init (&mode);
struct str mode = str_make ();
if (self->away_message)
str_append_c (&mode, 'a');
client_mode_to_str (self->mode, &mode);
@ -862,8 +854,7 @@ client_send_str (struct client *c, const struct str *s)
static void
client_send (struct client *c, const char *format, ...)
{
struct str tmp;
str_init (&tmp);
struct str tmp = str_make ();
va_list ap;
va_start (ap, format);
@ -894,8 +885,8 @@ client_unregister (struct client *c, const char *reason)
irc_send_to_roommates (c, message);
free (message);
struct str_map_unset_iter iter;
str_map_unset_iter_init (&iter, &c->ctx->channels);
struct str_map_unset_iter iter =
str_map_unset_iter_make (&c->ctx->channels);
struct channel *chan;
while ((chan = str_map_unset_iter_next (&iter)))
{
@ -1009,8 +1000,7 @@ client_get_ssl_cert_fingerprint (struct client *c)
unsigned char hash[SHA_DIGEST_LENGTH];
SHA1 (cert, cert_len, hash);
struct str fingerprint;
str_init (&fingerprint);
struct str fingerprint = str_make ();
for (size_t i = 0; i < sizeof hash; i++)
str_append_printf (&fingerprint, "%02x", hash[i]);
return str_steal (&fingerprint);
@ -1086,8 +1076,7 @@ irc_make_reply (struct client *c, int id, va_list ap, struct str *output)
static void
irc_send_reply (struct client *c, int id, ...)
{
struct str reply;
str_init (&reply);
struct str reply = str_make ();
va_list ap;
va_start (ap, id);
@ -1102,8 +1091,7 @@ irc_send_reply (struct client *c, int id, ...)
static void
irc_send_reply_vector (struct client *c, int id, char **items, ...)
{
struct str common;
str_init (&common);
struct str common = str_make ();
va_list ap;
va_start (ap, items);
@ -1114,8 +1102,7 @@ irc_send_reply_vector (struct client *c, int id, char **items, ...)
// expects us to send this message at least once)
do
{
struct str reply;
str_init (&reply);
struct str reply = str_make ();
str_append_str (&reply, &common);
// If not even a single item fits in the limit (which may happen,
@ -1169,8 +1156,7 @@ irc_send_lusers (struct client *c)
}
int n_channels = 0;
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
struct channel *chan;
while ((chan = str_map_iter_next (&iter)))
if (!(chan->modes & IRC_CHAN_MODE_SECRET)
@ -1285,9 +1271,7 @@ 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 strv caps;
strv_init (&caps);
struct strv caps = strv_make ();
for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
if (c->caps_enabled & irc_cap_table[i].flag)
strv_append (&caps, irc_cap_table[i].name);
@ -1399,7 +1383,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 = "";
strv_init (&args.params);
args.params = strv_make ();
if (msg->params.len > 1)
{
@ -1506,8 +1490,7 @@ irc_handle_userhost (const struct irc_message *msg, struct client *c)
if (msg->params.len < 1)
RETURN_WITH_REPLY (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
struct str reply;
str_init (&reply);
struct str reply = str_make ();
for (size_t i = 0; i < 5 && i < msg->params.len; i++)
{
const char *nick = msg->params.vector[i];
@ -1632,9 +1615,7 @@ irc_update_user_mode (struct client *c, unsigned new_mode)
unsigned added = new_mode & ~old_mode;
unsigned removed = old_mode & ~new_mode;
struct str diff;
str_init (&diff);
struct str diff = str_make ();
if (added)
{
str_append_c (&diff, '+');
@ -1710,8 +1691,7 @@ irc_send_channel_list (struct client *c, const char *channel_name,
static char *
irc_check_expand_user_mask (const char *mask)
{
struct str result;
str_init (&result);
struct str result = str_make ();
str_append (&result, mask);
// Make sure it is a complete mask
@ -1764,11 +1744,11 @@ mode_processor_init (struct mode_processor *self)
{
memset (self, 0, sizeof *self);
str_init (&self->added);
str_init (&self->removed);
self->added = str_make ();
self->removed = str_make ();
strv_init (&self->added_params);
strv_init (&self->removed_params);
self->added_params = strv_make ();
self->removed_params = strv_make ();
}
static void
@ -2030,8 +2010,7 @@ irc_handle_chan_mode_change
// TODO: limit to three changes with parameter per command
if (p.added.len || p.removed.len)
{
struct str message;
str_init (&message);
struct str message = str_make ();
str_append_printf (&message, ":%s!%s@%s MODE %s ",
p.c->nickname, p.c->username, p.c->hostname,
p.channel->name);
@ -2176,8 +2155,7 @@ irc_handle_list (const struct irc_message *msg, struct client *c)
struct channel *chan;
if (msg->params.len == 0)
{
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
while ((chan = str_map_iter_next (&iter)))
if (!(chan->modes & (IRC_CHAN_MODE_PRIVATE | IRC_CHAN_MODE_SECRET))
|| channel_get_user (chan, c))
@ -2185,8 +2163,7 @@ irc_handle_list (const struct irc_message *msg, struct client *c)
}
else
{
struct strv channels;
strv_init (&channels);
struct strv channels = strv_make ();
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]))
@ -2202,9 +2179,7 @@ static void
irc_append_prefixes (struct client *c, struct channel_user *user,
struct str *output)
{
struct str prefixes;
str_init (&prefixes);
struct str prefixes = str_make ();
if (user->modes & IRC_CHAN_MODE_OPERATOR) str_append_c (&prefixes, '@');
if (user->modes & IRC_CHAN_MODE_VOICE) str_append_c (&prefixes, '+');
@ -2222,8 +2197,7 @@ static char *
irc_make_rpl_namreply_item
(struct client *c, struct client *target, struct channel_user *user)
{
struct str result;
str_init (&result);
struct str result = str_make ();
if (user)
irc_append_prefixes (c, user, &result);
@ -2239,9 +2213,6 @@ static void
irc_send_rpl_namreply (struct client *c, const struct channel *chan,
struct str_map *used_nicks)
{
struct strv nicks;
strv_init (&nicks);
char type = '=';
if (chan->modes & IRC_CHAN_MODE_SECRET)
type = '@';
@ -2249,6 +2220,7 @@ irc_send_rpl_namreply (struct client *c, const struct channel *chan,
type = '*';
bool on_channel = channel_get_user (chan, c);
struct strv nicks = strv_make ();
for (struct channel_user *iter = chan->users; iter; iter = iter->next)
{
if (!on_channel && (iter->c->mode & IRC_USER_MODE_INVISIBLE))
@ -2267,11 +2239,8 @@ irc_send_rpl_namreply (struct client *c, const struct channel *chan,
static void
irc_send_disassociated_names (struct client *c, struct str_map *used)
{
struct strv nicks;
strv_init (&nicks);
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->users);
struct strv nicks = strv_make ();
struct str_map_iter iter = str_map_iter_make (&c->ctx->users);
struct client *target;
while ((target = str_map_iter_next (&iter)))
{
@ -2297,12 +2266,10 @@ irc_handle_names (const struct irc_message *msg, struct client *c)
struct channel *chan;
if (msg->params.len == 0)
{
struct str_map used;
str_map_init (&used);
struct str_map used = str_map_make (NULL);
used.key_xfrm = irc_strxfrm;
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
while ((chan = str_map_iter_next (&iter)))
if (!(chan->modes & (IRC_CHAN_MODE_PRIVATE | IRC_CHAN_MODE_SECRET))
|| channel_get_user (chan, c))
@ -2316,8 +2283,7 @@ irc_handle_names (const struct irc_message *msg, struct client *c)
}
else
{
struct strv channels;
strv_init (&channels);
struct strv channels = strv_make ();
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]))
@ -2335,9 +2301,7 @@ static void
irc_send_rpl_whoreply (struct client *c, const struct channel *chan,
const struct client *target)
{
struct str chars;
str_init (&chars);
struct str chars = str_make ();
str_append_c (&chars, target->away_message ? 'G' : 'H');
if (target->mode & IRC_USER_MODE_OPERATOR)
str_append_c (&chars, '*');
@ -2357,8 +2321,7 @@ irc_match_send_rpl_whoreply (struct client *c, struct client *target,
const char *mask)
{
bool is_roommate = false;
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
struct channel *chan;
while ((chan = str_map_iter_next (&iter)))
if (channel_get_user (chan, target) && channel_get_user (chan, c))
@ -2377,7 +2340,7 @@ irc_match_send_rpl_whoreply (struct client *c, struct client *target,
// Try to find a channel they're on that's visible to us
struct channel *user_chan = NULL;
str_map_iter_init (&iter, &c->ctx->channels);
iter = str_map_iter_make (&c->ctx->channels);
while ((chan = str_map_iter_next (&iter)))
if (channel_get_user (chan, target)
&& (!(chan->modes & (IRC_CHAN_MODE_PRIVATE | IRC_CHAN_MODE_SECRET))
@ -2417,8 +2380,7 @@ irc_handle_who (const struct irc_message *msg, struct client *c)
}
else
{
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->users);
struct str_map_iter iter = str_map_iter_make (&c->ctx->users);
struct client *target;
while ((target = str_map_iter_next (&iter)))
if (!only_ops || (target->mode & IRC_USER_MODE_OPERATOR))
@ -2442,11 +2404,9 @@ 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 strv channels;
strv_init (&channels);
struct strv channels = strv_make ();
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->channels);
struct str_map_iter iter = str_map_iter_make (&c->ctx->channels);
struct channel *chan;
struct channel_user *channel_user;
while ((chan = str_map_iter_next (&iter)))
@ -2454,8 +2414,7 @@ irc_send_whois_reply (struct client *c, const struct client *target)
&& (!(chan->modes & (IRC_CHAN_MODE_PRIVATE | IRC_CHAN_MODE_SECRET))
|| channel_get_user (chan, c)))
{
struct str item;
str_init (&item);
struct str item = str_make ();
if (channel_user->modes & IRC_CHAN_MODE_OPERATOR)
str_append_c (&item, '@');
else if (channel_user->modes & IRC_CHAN_MODE_VOICE)
@ -2478,8 +2437,7 @@ 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 strv masks;
strv_init (&masks);
struct strv masks = strv_make ();
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++)
@ -2495,8 +2453,7 @@ irc_handle_whois (const struct irc_message *msg, struct client *c)
}
else
{
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->users);
struct str_map_iter iter = str_map_iter_make (&c->ctx->users);
bool found = false;
while ((target = str_map_iter_next (&iter))
&& !irc_fnmatch (mask, target->nickname))
@ -2520,8 +2477,7 @@ 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 strv nicks;
strv_init (&nicks);
struct strv nicks = strv_make ();
cstr_split (msg->params.vector[0], ",", true, &nicks);
for (size_t i = 0; i < nicks.len; i++)
@ -2623,8 +2579,8 @@ static void
irc_part_all_channels (struct client *c)
{
// We have to be careful here, the channel might get destroyed
struct str_map_unset_iter iter;
str_map_unset_iter_init (&iter, &c->ctx->channels);
struct str_map_unset_iter iter =
str_map_unset_iter_make (&c->ctx->channels);
struct channel *chan;
while ((chan = str_map_unset_iter_next (&iter)))
@ -2640,8 +2596,7 @@ 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 strv channels;
strv_init (&channels);
struct strv channels = strv_make ();
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);
@ -2689,11 +2644,9 @@ irc_handle_kick (const struct irc_message *msg, struct client *c)
if (msg->params.len > 2)
reason = msg->params.vector[2];
struct strv channels;
struct strv users;
strv_init (&channels);
strv_init (&users);
struct strv channels = strv_make ();
cstr_split (msg->params.vector[0], ",", true, &channels);
struct strv users = strv_make ();
cstr_split (msg->params.vector[1], ",", true, &users);
if (channels.len == 1)
@ -2818,11 +2771,9 @@ irc_handle_join (const struct irc_message *msg, struct client *c)
return;
}
struct strv channels;
struct strv keys;
strv_init (&channels);
strv_init (&keys);
struct strv channels = strv_make ();
cstr_split (msg->params.vector[0], ",", true, &channels);
struct strv keys = strv_make ();
if (msg->params.len > 1)
cstr_split (msg->params.vector[1], ",", true, &keys);
@ -2871,9 +2822,7 @@ irc_handle_ison (const struct irc_message *msg, struct client *c)
if (msg->params.len < 1)
RETURN_WITH_REPLY (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
struct str result;
str_init (&result);
struct str result = str_make ();
const char *nick;
if (str_map_find (&c->ctx->users, (nick = msg->params.vector[0])))
str_append (&result, nick);
@ -2918,8 +2867,7 @@ irc_handle_stats_links (struct client *c, const struct irc_message *msg)
static void
irc_handle_stats_commands (struct client *c)
{
struct str_map_iter iter;
str_map_iter_init (&iter, &c->ctx->handlers);
struct str_map_iter iter = str_map_iter_make (&c->ctx->handlers);
struct irc_command *handler;
while ((handler = str_map_iter_next (&iter)))
{
@ -3489,19 +3437,19 @@ irc_try_fetch_client (struct server_context *ctx, int listen_fd)
LIST_PREPEND (ctx->clients, c);
ctx->n_clients++;
poller_fd_init (&c->socket_event, &c->ctx->poller, c->socket_fd);
c->socket_event = poller_fd_make (&c->ctx->poller, c->socket_fd);
c->socket_event.dispatcher = (poller_fd_fn) on_client_ready;
c->socket_event.user_data = c;
poller_timer_init (&c->kill_timer, &c->ctx->poller);
c->kill_timer = poller_timer_make (&c->ctx->poller);
c->kill_timer.dispatcher = (poller_timer_fn) on_client_kill_timer;
c->kill_timer.user_data = c;
poller_timer_init (&c->timeout_timer, &c->ctx->poller);
c->timeout_timer = poller_timer_make (&c->ctx->poller);
c->timeout_timer.dispatcher = (poller_timer_fn) on_client_timeout_timer;
c->timeout_timer.user_data = c;
poller_timer_init (&c->ping_timer, &c->ctx->poller);
c->ping_timer = poller_timer_make (&c->ctx->poller);
c->ping_timer.dispatcher = (poller_timer_fn) on_client_ping_timer;
c->ping_timer.user_data = c;
@ -3512,7 +3460,7 @@ irc_try_fetch_client (struct server_context *ctx, int listen_fd)
c->gni->dispatcher = on_client_gni_resolved;
c->gni->user_data = c;
poller_timer_init (&c->gni_timer, &c->ctx->poller);
c->gni_timer = poller_timer_make (&c->ctx->poller);
c->gni_timer.dispatcher = (poller_timer_fn) on_client_gni_timer;
c->gni_timer.user_data = c;
@ -3546,9 +3494,7 @@ irc_ssl_info_callback (const SSL *ssl, int where, int ret)
{
// For debugging only; provides us with the most important information
struct str s;
str_init (&s);
struct str s = str_make ();
if (where & SSL_CB_LOOP)
str_append_printf (&s, "loop (%s) ",
SSL_state_string_long (ssl));
@ -3709,8 +3655,7 @@ irc_initialize_motd (struct server_context *ctx, struct error **e)
return false;
}
struct str line;
str_init (&line);
struct str line = str_make ();
while (read_line (fp, &line))
strv_append_owned (&ctx->motd, str_steal (&line));
str_free (&line);
@ -3741,8 +3686,7 @@ irc_parse_config (struct server_context *ctx, struct error **e)
PARSE_UNSIGNED (max_connections, 0, UINT_MAX);
bool result = true;
struct strv fingerprints;
strv_init (&fingerprints);
struct strv fingerprints = strv_make ();
const char *operators = str_map_find (&ctx->config, "operators");
if (operators)
cstr_split (operators, ",", true, &fingerprints);
@ -3880,7 +3824,7 @@ irc_listen_resolve (struct server_context *ctx,
set_blocking (fd, false);
struct poller_fd *event = &ctx->listen_events[ctx->n_listen_fds];
poller_fd_init (event, &ctx->poller, fd);
*event = poller_fd_make (&ctx->poller, fd);
event->dispatcher = (poller_fd_fn) on_irc_client_available;
event->user_data = ctx;
@ -3904,8 +3848,7 @@ irc_setup_listen_fds (struct server_context *ctx, struct error **e)
gai_hints.ai_socktype = SOCK_STREAM;
gai_hints.ai_flags = AI_PASSIVE;
struct strv ports;
strv_init (&ports);
struct strv ports = strv_make ();
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);
@ -4015,8 +3958,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
struct opt_handler oh;
opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC daemon.");
struct opt_handler oh =
opt_handler_make (argc, argv, opts, NULL, "Experimental IRC daemon.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@ -4060,7 +4003,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
poller_fd_init (&ctx.signal_event, &ctx.poller, g_signal_pipe[0]);
ctx.signal_event = poller_fd_make (&ctx.poller, g_signal_pipe[0]);
ctx.signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
ctx.signal_event.user_data = &ctx;
poller_fd_set (&ctx.signal_event, POLLIN);

@ -1 +1 @@
Subproject commit 084e964286bfcd13ee6a25a2ee35dfba9da1072e
Subproject commit 3835b6e49975039a9f72b8920238f3141e7becea

View File

@ -89,12 +89,12 @@ plugin_init (struct plugin *self)
memset (self, 0, sizeof *self);
self->pid = -1;
str_init (&self->queued_output);
self->queued_output = str_make ();
self->read_fd = -1;
str_init (&self->read_buffer);
self->read_buffer = str_make ();
self->write_fd = -1;
str_init (&self->write_buffer);
self->write_buffer = str_make ();
}
static void
@ -152,34 +152,33 @@ static void on_irc_reconnect_timeout (void *user_data);
static void
bot_context_init (struct bot_context *self)
{
str_map_init (&self->config);
self->config.free = free;
self->config = str_map_make (free);
simple_config_load_defaults (&self->config, g_config_table);
self->admin_re = NULL;
self->irc_fd = -1;
str_init (&self->read_buffer);
self->read_buffer = str_make ();
self->irc_registered = false;
self->ssl = NULL;
self->ssl_ctx = NULL;
self->plugins = NULL;
str_map_init (&self->plugins_by_name);
self->plugins_by_name = str_map_make (NULL);
poller_init (&self->poller);
self->quitting = false;
self->polling = false;
poller_timer_init (&self->timeout_tmr, &self->poller);
self->timeout_tmr = poller_timer_make (&self->poller);
self->timeout_tmr.dispatcher = on_irc_timeout;
self->timeout_tmr.user_data = self;
poller_timer_init (&self->ping_tmr, &self->poller);
self->ping_tmr = poller_timer_make (&self->poller);
self->ping_tmr.dispatcher = on_irc_ping_timeout;
self->ping_tmr.user_data = self;
poller_timer_init (&self->reconnect_tmr, &self->poller);
self->reconnect_tmr = poller_timer_make (&self->poller);
self->reconnect_tmr.dispatcher = on_irc_reconnect_timeout;
self->reconnect_tmr.user_data = self;
}
@ -272,8 +271,7 @@ irc_send (struct bot_context *ctx, const char *format, ...)
return false;
va_start (ap, format);
struct str str;
str_init (&str);
struct str str = str_make ();
str_append_vprintf (&str, format, ap);
str_append (&str, "\r\n");
va_end (ap);
@ -684,7 +682,7 @@ recovery_handler (int signum, siginfo_t *info, void *context)
static void
prepare_recovery_environment (void)
{
strv_init (&g_recovery_env);
g_recovery_env = strv_make ();
strv_append_vector (&g_recovery_env, environ);
// Prepare a location within the environment where we will put the startup
@ -1047,8 +1045,7 @@ plugin_launch (struct bot_context *ctx, const char *name, struct error **e)
goto fail_1;
}
struct str work_dir;
str_init (&work_dir);
struct str work_dir = str_make ();
get_xdg_home_dir (&work_dir, "XDG_DATA_HOME", ".local/share");
str_append_printf (&work_dir, "/%s", PROGRAM_NAME);
@ -1136,11 +1133,11 @@ plugin_load (struct bot_context *ctx, const char *name, struct error **e)
set_blocking (plugin->read_fd, false);
set_blocking (plugin->write_fd, false);
poller_fd_init (&plugin->read_event, &ctx->poller, plugin->read_fd);
plugin->read_event = poller_fd_make (&ctx->poller, plugin->read_fd);
plugin->read_event.dispatcher = (poller_fd_fn) on_plugin_readable;
plugin->read_event.user_data = plugin;
poller_fd_init (&plugin->write_event, &ctx->poller, plugin->write_fd);
plugin->write_event = poller_fd_make (&ctx->poller, plugin->write_fd);
plugin->write_event.dispatcher = (poller_fd_fn) on_plugin_writable;
plugin->write_event.user_data = plugin;
@ -1173,9 +1170,7 @@ plugin_load_all_from_config (struct bot_context *ctx)
if (!plugin_list)
return;
struct strv plugins;
strv_init (&plugins);
struct strv plugins = strv_make ();
cstr_split (plugin_list, ",", true, &plugins);
for (size_t i = 0; i < plugins.len; i++)
{
@ -1256,10 +1251,8 @@ respond_to_user (struct bot_context *ctx, const struct irc_message *msg,
strncpy (nick, msg->prefix, sizeof nick - 1);
nick[sizeof nick - 1] = '\0';
struct str text;
va_list ap;
str_init (&text);
struct str text = str_make ();
va_start (ap, format);
str_append_vprintf (&text, format, ap);
va_end (ap);
@ -1320,9 +1313,7 @@ process_plugin_reload (struct bot_context *ctx,
static char *
make_status_report (struct bot_context *ctx)
{
struct str report;
str_init (&report);
struct str report = str_make ();
const char *reason = getenv (g_startup_reason_str);
if (!reason)
reason = "launched normally";
@ -1367,8 +1358,7 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
return;
const char *following;
struct strv list;
strv_init (&list);
struct strv list = strv_make ();
if (parse_bot_command (text, "quote", &following))
// This seems to replace tons of random stupid commands
@ -1805,7 +1795,7 @@ irc_connect (struct bot_context *ctx, struct error **e)
}
print_status ("connection established");
poller_fd_init (&ctx->irc_event, &ctx->poller, ctx->irc_fd);
ctx->irc_event = poller_fd_make (&ctx->poller, ctx->irc_fd);
ctx->irc_event.dispatcher = (poller_fd_fn) on_irc_readable;
ctx->irc_event.user_data = ctx;
@ -1965,7 +1955,7 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
int
main (int argc, char *argv[])
{
strv_init (&g_original_argv);
g_original_argv = strv_make ();
strv_append_vector (&g_original_argv, argv);
static const struct opt opts[] =
@ -1979,8 +1969,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
struct opt_handler oh;
opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC bot.");
struct opt_handler oh =
opt_handler_make (argc, argv, opts, NULL, "Experimental IRC bot.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@ -2022,7 +2012,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
poller_fd_init (&ctx.signal_event, &ctx.poller, g_signal_pipe[0]);
ctx.signal_event = poller_fd_make (&ctx.poller, g_signal_pipe[0]);
ctx.signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
ctx.signal_event.user_data = &ctx;
poller_fd_set (&ctx.signal_event, POLLIN);