diff --git a/CMakeLists.txt b/CMakeLists.txt index fef2385..87db34a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/common.c b/common.c index 6c5755f..bd5184c 100644 --- a/common.c +++ b/common.c @@ -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; diff --git a/degesch.c b/degesch.c index 81e893c..eb25fd1 100644 --- a/degesch.c +++ b/degesch.c @@ -1356,7 +1356,7 @@ static struct channel_user * channel_user_new (void) { struct channel_user *self = xcalloc (1, sizeof *self); - str_init (&self->prefixes); + self->prefixes = str_make (); return self; } @@ -1407,10 +1407,9 @@ channel_new (void) { struct channel *self = xcalloc (1, sizeof *self); self->ref_count = 1; - str_init (&self->no_param_modes); - str_map_init (&self->param_modes); - self->param_modes.free = free; - strv_init (&self->names_buf); + self->no_param_modes = str_make (); + self->param_modes = str_map_make (free); + self->names_buf = strv_make (); return self; } @@ -1807,34 +1806,34 @@ server_new (struct poller *poller) self->ref_count = 1; self->socket = -1; - str_init (&self->read_buffer); - str_init (&self->write_buffer); + self->read_buffer = str_make (); + self->write_buffer = str_make (); self->state = IRC_DISCONNECTED; - poller_timer_init (&self->timeout_tmr, poller); + self->timeout_tmr = poller_timer_make (poller); self->timeout_tmr.dispatcher = on_irc_timeout; self->timeout_tmr.user_data = self; - poller_timer_init (&self->ping_tmr, poller); + self->ping_tmr = poller_timer_make (poller); self->ping_tmr.dispatcher = on_irc_ping_timeout; self->ping_tmr.user_data = self; - poller_timer_init (&self->reconnect_tmr, poller); + self->reconnect_tmr = poller_timer_make (poller); self->reconnect_tmr.dispatcher = (poller_timer_fn) irc_initiate_connect; self->reconnect_tmr.user_data = self; - poller_timer_init (&self->autojoin_tmr, poller); + self->autojoin_tmr = poller_timer_make (poller); self->autojoin_tmr.dispatcher = on_irc_autojoin_timeout; self->autojoin_tmr.user_data = self; - str_map_init (&self->irc_users); + self->irc_users = str_map_make (NULL); self->irc_users.key_xfrm = irc_strxfrm; - str_map_init (&self->irc_channels); + self->irc_channels = str_map_make (NULL); self->irc_channels.key_xfrm = irc_strxfrm; - str_map_init (&self->irc_buffer_map); + self->irc_buffer_map = str_map_make (NULL); self->irc_buffer_map.key_xfrm = irc_strxfrm; - str_init (&self->irc_user_mode); + self->irc_user_mode = str_make (); server_init_specifics (self); return self; @@ -2133,14 +2132,13 @@ app_context_init (struct app_context *self) { memset (self, 0, sizeof *self); - config_init (&self->config); + self->config = config_make (); poller_init (&self->poller); - str_map_init (&self->servers); - self->servers.free = (str_map_free_fn) server_unref; + self->servers = str_map_make ((str_map_free_fn) server_unref); self->servers.key_xfrm = tolower_ascii_strxfrm; - str_map_init (&self->buffers_by_name); + self->buffers_by_name = str_map_make (NULL); self->buffers_by_name.key_xfrm = tolower_ascii_strxfrm; // So that we don't lose the logo shortly after startup @@ -2155,8 +2153,8 @@ app_context_init (struct app_context *self) self->input = input_new (); self->input->user_data = self; - strv_init (&self->pending_input); - str_init (&self->input_buffer); + self->pending_input = strv_make (); + self->input_buffer = str_make (); self->nick_palette = filter_color_cube_for_acceptable_nick_colors (&self->nick_palette_len); @@ -3020,8 +3018,7 @@ irc_to_utf8 (const char *text) "\xc5\x93", "\xc2\x9d", "\xc5\xbe", "\xc5\xb8", }; - struct str s; - str_init (&s); + struct str s = str_make (); for (const char *p = text; *p; p++) { int c = *(unsigned char *) p; @@ -3159,11 +3156,9 @@ formatter_parse_mirc_color (struct formatter *self, const char *s) static void formatter_parse_mirc (struct formatter *self, const char *s) { - struct str buf; - str_init (&buf); - FORMATTER_ADD_RESET (self); + struct str buf = str_make (); unsigned char c; while ((c = *s++)) { @@ -3341,9 +3336,7 @@ restart: static void formatter_addv (struct formatter *self, const char *format, va_list *ap) { - struct str buf; - str_init (&buf); - + struct str buf = str_make (); while (*format) { if (*format != '#' || *++format == '#') @@ -4010,8 +4003,7 @@ make_log_filename (const char *filename, struct str *output) static char * buffer_get_log_path (struct buffer *buffer) { - struct str path; - str_init (&path); + struct str path = str_make (); get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share"); str_append_printf (&path, "/%s/%s", PROGRAM_NAME, "logs"); @@ -4596,9 +4588,9 @@ irc_rehash_and_fix_conflicts (struct server *s) struct str_map old_channels = s->irc_channels; struct str_map old_buffer_map = s->irc_buffer_map; - str_map_init (&s->irc_users); - str_map_init (&s->irc_channels); - str_map_init (&s->irc_buffer_map); + s->irc_users = str_map_make (NULL); + s->irc_channels = str_map_make (NULL); + s->irc_buffer_map = str_map_make (NULL); s->irc_users .key_xfrm = s->irc_strxfrm; s->irc_channels .key_xfrm = s->irc_strxfrm; @@ -4620,12 +4612,12 @@ irc_rehash_and_fix_conflicts (struct server *s) struct user *user; struct channel *channel; - str_map_iter_init (&iter, &old_users); + iter = str_map_iter_make (&old_users); while ((user = str_map_iter_next (&iter))) irc_try_readd_user (s, user, str_map_find (&old_buffer_map, user->nickname)); - str_map_iter_init (&iter, &old_channels); + iter = str_map_iter_make (&old_channels); while ((channel = str_map_iter_next (&iter))) irc_try_readd_channel (s, channel, str_map_find (&old_buffer_map, channel->name)); @@ -4747,8 +4739,7 @@ irc_send (struct server *s, const char *format, ...) va_list ap; va_start (ap, format); - struct str str; - str_init (&str); + struct str str = str_make (); str_append_vprintf (&str, format, ap); va_end (ap); @@ -4822,10 +4813,8 @@ try_finish_quit (struct app_context *ctx) if (!ctx->quitting) return; - struct str_map_iter iter; - str_map_iter_init (&iter, &ctx->servers); - bool disconnected_all = true; + struct str_map_iter iter = str_map_iter_make (&ctx->servers); struct server *s; while ((s = str_map_iter_next (&iter))) if (irc_is_connected (s)) @@ -4855,8 +4844,7 @@ irc_destroy_transport (struct server *s) static void irc_destroy_state (struct server *s) { - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_channels); + struct str_map_iter iter = str_map_iter_make (&s->irc_channels); struct channel *channel; while ((channel = str_map_iter_next (&iter))) irc_left_channel (channel); @@ -4885,8 +4873,7 @@ irc_disconnect (struct server *s) { hard_assert (irc_is_connected (s)); - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_buffer_map); + struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map); struct buffer *buffer; while ((buffer = str_map_iter_next (&iter))) log_server (s, buffer, BUFFER_LINE_STATUS | BUFFER_LINE_UNIMPORTANT, @@ -4945,8 +4932,7 @@ initiate_quit (struct app_context *ctx, const char *message) CALL (ctx->input, hide); // Initiate a connection close - struct str_map_iter iter; - str_map_iter_init (&iter, &ctx->servers); + struct str_map_iter iter = str_map_iter_make (&ctx->servers); struct server *s; while ((s = str_map_iter_next (&iter))) { @@ -4990,8 +4976,7 @@ on_irc_autojoin_timeout (void *user_data) // Since we may not have information from RPL_ISUPPORT yet, // it's our safest bet to send the channels one at a time - struct str_map joins_sent; - str_map_init (&joins_sent); + struct str_map joins_sent = str_map_make (NULL); // We don't know the casemapping yet either, however ASCII should do joins_sent.key_xfrm = tolower_ascii_strxfrm; @@ -5000,8 +4985,7 @@ on_irc_autojoin_timeout (void *user_data) const char *autojoin = get_config_string (s->config, "autojoin"); if (autojoin) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (autojoin, ",", true, &v); for (size_t i = 0; i < v.len; i++) { @@ -5012,13 +4996,11 @@ on_irc_autojoin_timeout (void *user_data) } // Then also rejoin any channels from the last disconnect - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_channels); + struct str_map_iter iter = str_map_iter_make (&s->irc_channels); struct channel *channel; while ((channel = str_map_iter_next (&iter))) { - struct str target; - str_init (&target); + struct str target = str_make (); str_append (&target, channel->name); const char *key; @@ -5579,8 +5561,7 @@ irc_autofill_user_info (struct server *s, struct error **e) static char * irc_fetch_next_nickname (struct server *s) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (get_config_string (s->config, "nicks"), ",", true, &v); char *result = NULL; @@ -5658,7 +5639,7 @@ irc_finish_connection (struct server *s, int socket, const char *hostname) log_server_status (s, s->buffer, "Connection established"); s->state = IRC_CONNECTED; - poller_fd_init (&s->socket_event, &ctx->poller, s->socket); + s->socket_event = poller_fd_make (&ctx->poller, s->socket); s->socket_event.dispatcher = (poller_fd_fn) on_irc_ready; s->socket_event.user_data = s; @@ -5817,8 +5798,7 @@ irc_initiate_connect (struct server *s) return; } - struct strv servers; - strv_init (&servers); + struct strv servers = strv_make (); cstr_split (addresses, ",", true, &servers); struct error *e = NULL; @@ -5866,9 +5846,7 @@ make_chanmode_postfix (struct channel *channel, struct str *modes) if (channel->no_param_modes.len) str_append (modes, channel->no_param_modes.str); - struct str_map_iter iter; - str_map_iter_init (&iter, &channel->param_modes); - + struct str_map_iter iter = str_map_iter_make (&channel->param_modes); char *param; while ((param = str_map_iter_next (&iter))) str_append_c (modes, iter.link->key[0]); @@ -5924,8 +5902,7 @@ make_prompt (struct app_context *ctx, struct str *output) str_append_c (output, '['); - struct str active_buffers; - str_init (&active_buffers); + struct str active_buffers = str_make (); make_unseen_prefix (ctx, &active_buffers); if (active_buffers.len) str_append_printf (output, "(%s) ", active_buffers.str); @@ -5937,8 +5914,7 @@ make_prompt (struct app_context *ctx, struct str *output) if (buffer->type == BUFFER_CHANNEL && buffer->channel->users_len) { - struct str modes; - str_init (&modes); + struct str modes = str_make (); make_chanmode_postfix (buffer->channel, &modes); if (modes.len) str_append_printf (output, "(+%s)", modes.str); @@ -5973,8 +5949,7 @@ on_refresh_prompt (struct app_context *ctx) poller_idle_reset (&ctx->prompt_event); bool have_attributes = !!get_attribute_printer (stdout); - struct str prompt; - str_init (&prompt); + struct str prompt = str_make (); make_prompt (ctx, &prompt); char *localized = iconv_xstrdup (ctx->term_from_utf8, prompt.str, -1, NULL); str_free (&prompt); @@ -6049,8 +6024,7 @@ irc_is_highlight (struct server *s, const char *message) formatter_init (&f, s->ctx, NULL); formatter_parse_mirc (&f, message); - struct str stripped; - str_init (&stripped); + struct str stripped = str_make (); for (size_t i = 0; i < f.items_len; i++) { if (f.items[i].type == FORMATTER_ITEM_TEXT) @@ -6090,11 +6064,8 @@ irc_is_highlight (struct server *s, const char *message) static char * irc_get_privmsg_prefix (struct server *s, struct user *user, const char *target) { - struct str prefix; - str_init (&prefix); - - target = irc_skip_statusmsg (s, target); - if (user && irc_is_channel (s, target)) + struct str prefix = str_make (); + if (user && irc_is_channel (s, (target = irc_skip_statusmsg (s, target)))) { struct channel *channel; struct channel_user *channel_user; @@ -6205,7 +6176,7 @@ mode_processor_do_user (struct mode_processor *self) { // Add the new mode prefix while retaining the right order char *old_prefixes = str_steal (prefixes); - str_init (prefixes); + *prefixes = str_make (); for (const char *p = all_prefixes; *p; p++) if (*p == prefix || strchr (old_prefixes, *p)) str_append_c (prefixes, *p); @@ -6422,9 +6393,7 @@ irc_handle_cap (struct server *s, const struct irc_message *msg) if (msg->params.len < 2) return; - struct strv v; - strv_init (&v); - + struct strv v = strv_make (); const char *args = ""; if (msg->params.len > 2) cstr_split ((args = msg->params.vector[2]), " ", true, &v); @@ -6459,8 +6428,8 @@ irc_handle_cap (struct server *s, const struct irc_message *msg) log_server_status (s, s->buffer, "#s: #S", "Capabilities supported", args); - struct strv chosen; strv_init (&chosen); - struct strv use; strv_init (&use); + struct strv chosen = strv_make (); + struct strv use = strv_make (); cstr_split (get_config_string (s->config, "capabilities"), ",", true, &use); @@ -6640,8 +6609,7 @@ 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 strv copy; - strv_init (©); + struct strv copy = strv_make (); strv_append_vector (©, msg->params.vector + 1); char *modes = strv_join (©, " "); strv_free (©); @@ -6761,8 +6729,7 @@ irc_handle_nick (struct server *s, const struct irc_message *msg) log_nick_self (s, s->buffer, new_nickname); // Log a message in all open buffers on this server - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_buffer_map); + struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map); struct buffer *buffer; while ((buffer = str_map_iter_next (&iter))) { @@ -6916,8 +6883,7 @@ static void irc_send_ctcp_reply (struct server *s, const char *recipient, const char *format, ...) { - struct str m; - str_init (&m); + struct str m = str_make (); va_list ap; va_start (ap, format); @@ -7163,8 +7129,7 @@ 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 strv v; - strv_init (&v); + struct strv v = strv_make (); 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])) @@ -7213,8 +7178,7 @@ irc_handle_rpl_userhost (struct server *s, const struct irc_message *msg) return; const char *response = msg->params.vector[1]; - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (response, " ", true, &v); for (size_t i = 0; i < v.len; i++) @@ -7328,8 +7292,7 @@ make_channel_users_list (struct server *s, struct channel *channel) qsort (entries, n_users, sizeof *entries, channel_user_sort_entry_cmp); - struct str list; - str_init (&list); + struct str list = str_make (); for (i = 0; i < n_users; i++) { irc_get_channel_user_prefix (s, entries[i].channel_user, &list); @@ -7368,8 +7331,7 @@ irc_sync_channel_user (struct server *s, struct channel *channel, static void irc_process_names (struct server *s, struct channel *channel) { - struct str_map present; - str_map_init (&present); + struct str_map present = str_map_make (NULL); present.key_xfrm = s->irc_strxfrm; struct strv *updates = &channel->names_buf; @@ -7418,8 +7380,7 @@ irc_handle_rpl_endofnames (struct server *s, const struct irc_message *msg) struct channel *channel = str_map_find (&s->irc_channels, channel_name); if (!strcmp (channel_name, "*")) { - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_channels); + struct str_map_iter iter = str_map_iter_make (&s->irc_channels); struct channel *channel; while ((channel = str_map_iter_next (&iter))) irc_process_names (s, channel); @@ -7614,11 +7575,8 @@ irc_handle_isupport_chantypes (struct server *s, char *value) static void irc_handle_isupport_idchan (struct server *s, char *value) { - struct str prefixes; - str_init (&prefixes); - - struct strv v; - strv_init (&v); + struct str prefixes = str_make (); + struct strv v = strv_make (); cstr_split (value, ",", true, &v); for (size_t i = 0; i < v.len; i++) { @@ -7644,8 +7602,7 @@ irc_handle_isupport_statusmsg (struct server *s, char *value) static void irc_handle_isupport_chanmodes (struct server *s, char *value) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (value, ",", true, &v); if (v.len >= 4) { @@ -7721,8 +7678,7 @@ irc_handle_rpl_isupport (struct server *s, const struct irc_message *msg) char *value = param + strcspn (param, "="); if (*value) *value++ = '\0'; - struct str value_unescaped; - str_init (&value_unescaped); + struct str value_unescaped = str_make (); unescape_isupport_value (value, &value_unescaped); dispatch_isupport (s, param, value_unescaped.str); str_free (&value_unescaped); @@ -7739,8 +7695,7 @@ 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 strv copy; - strv_init (©); + struct strv copy = strv_make (); strv_append_vector (©, msg->params.vector + !!msg->params.len); struct buffer *buffer = s->buffer; @@ -7782,10 +7737,12 @@ irc_process_numeric (struct server *s, // Auto-away spams server buffers with activity case IRC_RPL_NOWAWAY: flags |= BUFFER_LINE_UNIMPORTANT; - if (s->irc_user) s->irc_user->away = true; break; + if (s->irc_user) s->irc_user->away = true; + break; case IRC_RPL_UNAWAY: flags |= BUFFER_LINE_UNIMPORTANT; - if (s->irc_user) s->irc_user->away = false; break; + if (s->irc_user) s->irc_user->away = false; + break; case IRC_RPL_LIST: case IRC_RPL_WHOREPLY: @@ -7899,8 +7856,7 @@ wrap_message (const char *message, int message_left = strlen (message); while (message_left > line_max) { - struct str m; - str_init (&m); + struct str m = str_make (); size_t eaten = wrap_text_for_single_line (message, message_left, line_max, &m); @@ -7962,8 +7918,7 @@ 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 strv lines; - strv_init (&lines); + struct strv lines = strv_make (); struct error *e = NULL; if (!irc_autosplit_message (s, message, fixed_part, &lines, &e)) { @@ -8020,8 +7975,7 @@ config_dump_children *data->tail = &level; data->tail = &level.next; - struct str_map_iter iter; - str_map_iter_init (&iter, &object->value.object); + struct str_map_iter iter = str_map_iter_make (&object->value.object); struct config_item *child; while ((child = str_map_iter_next (&iter))) { @@ -8049,9 +8003,7 @@ config_dump_item (struct config_item *item, struct config_dump_data *data) if (!schema) return; - struct str line; - str_init (&line); - + struct str line = str_make (); struct config_dump_level *iter = data->head; if (iter) { @@ -8061,8 +8013,7 @@ config_dump_item (struct config_item *item, struct config_dump_data *data) for (; iter; iter = iter->next) str_append_printf (&line, ".%s", iter->name); - struct str value; - str_init (&value); + struct str value = str_make (); config_item_write (item, false, &value); // Don't bother writing out null values everywhere @@ -8132,8 +8083,7 @@ dump_matching_options static void save_configuration (struct app_context *ctx) { - struct str data; - str_init (&data); + struct str data = str_make (); serialize_configuration (ctx->config.root, &data); struct error *e = NULL; @@ -8234,8 +8184,8 @@ server_remove (struct app_context *ctx, struct server *s) if (s->buffer) buffer_remove_safe (ctx, s->buffer); - struct str_map_unset_iter iter; - str_map_unset_iter_init (&iter, &s->irc_buffer_map); + struct str_map_unset_iter iter = + str_map_unset_iter_make (&s->irc_buffer_map); struct buffer *buffer; while ((buffer = str_map_unset_iter_next (&iter))) buffer_remove_safe (ctx, buffer); @@ -8267,8 +8217,7 @@ server_rename (struct app_context *ctx, struct server *s, const char *new_name) buffer_rename (ctx, s->buffer, new_name); - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_buffer_map); + struct str_map_iter iter = str_map_iter_make (&s->irc_buffer_map); struct buffer *buffer; while ((buffer = str_map_iter_next (&iter))) { @@ -8388,8 +8337,7 @@ static bool lua_plugin_process_error (struct lua_plugin *self, const char *message, struct error **e) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (message, "\n", true, &v); if (v.len < 2) @@ -8502,8 +8450,7 @@ lua_plugin_push_message (lua_State *L, const struct irc_message *msg) lua_createtable (L, 0, 4); lua_createtable (L, msg->tags.len, 0); - struct str_map_iter iter; - str_map_iter_init (&iter, &msg->tags); + struct str_map_iter iter = str_map_iter_make (&msg->tags); const char *value; while ((value = str_map_iter_next (&iter))) lua_plugin_kv (L, iter.link->key, value); @@ -9159,8 +9106,7 @@ lua_plugin_push_config_item (lua_State *L, const struct config_item *item) { lua_createtable (L, 0, item->value.object.len); - struct str_map_iter iter; - str_map_iter_init (&iter, &item->value.object); + struct str_map_iter iter = str_map_iter_make (&item->value.object); struct config_item *child; while ((child = str_map_iter_next (&iter))) { @@ -9591,14 +9537,14 @@ lua_plugin_push_connection (struct lua_plugin *plugin, int socket_fd) self->plugin = plugin; set_blocking (socket_fd, false); - poller_fd_init (&self->socket_event, &plugin->ctx->poller, - (self->socket_fd = socket_fd)); + self->socket_event = poller_fd_make + (&plugin->ctx->poller, (self->socket_fd = socket_fd)); self->socket_event.dispatcher = (poller_fd_fn) lua_connection_on_ready; self->socket_event.user_data = self; poller_fd_set (&self->socket_event, POLLIN); - str_init (&self->read_buffer); - str_init (&self->write_buffer); + self->read_buffer = str_make (); + self->write_buffer = str_make (); // Make sure the connection doesn't get garbage collected and return it lua_cache_store (L, self, -1); @@ -9849,7 +9795,7 @@ lua_plugin_push_wait_timer (struct lua_plugin *plugin, lua_State *L, self->super.check = lua_wait_timer_check; self->super.cleanup = lua_wait_timer_cleanup; - poller_timer_init (&self->timer, &plugin->ctx->poller); + self->timer = poller_timer_make (&plugin->ctx->poller); self->timer.dispatcher = (poller_timer_fn) lua_wait_timer_dispatch; self->timer.user_data = self; @@ -10002,7 +9948,7 @@ lua_async_go (lua_State *L) task->plugin = plugin; task->thread = thread; - poller_idle_init (&task->idle, &plugin->ctx->poller); + task->idle = poller_idle_make (&plugin->ctx->poller); task->idle.dispatcher = (poller_idle_fn) lua_task_check; task->idle.user_data = task; poller_idle_set (&task->idle); @@ -10139,8 +10085,7 @@ lua_plugin_push_struct (lua_State *L, struct lua_plugin *self, } if (type == ISPECT_STR_MAP) { - struct str_map_iter iter; - str_map_iter_init (&iter, value); + struct str_map_iter iter = str_map_iter_make (value); void *value; lua_newtable (L); @@ -10412,8 +10357,7 @@ plugin_find (struct app_context *ctx, const char *name) static char * plugin_resolve_relative_filename (const char *filename) { - struct strv paths; - strv_init (&paths); + struct strv paths = strv_make (); get_xdg_data_dirs (&paths); char *result = resolve_relative_filename_generic (&paths, PROGRAM_NAME "/plugins/", filename); @@ -10491,8 +10435,7 @@ load_plugins (struct app_context *ctx) (ctx->config.root, "behaviour.plugin_autoload"); if (plugins) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (plugins, ",", true, &v); for (size_t i = 0; i < v.len; i++) plugin_load (ctx, v.vector[i]); @@ -10651,9 +10594,7 @@ show_buffers_list (struct app_context *ctx) int i = 1; LIST_FOR_EACH (struct buffer, iter, ctx->buffers) { - struct str s; - str_init (&s); - + struct str s = str_make (); int new = iter->new_messages_count - iter->new_unimportant_count; if (new && iter != ctx->current_buffer) str_append_printf (&s, " (%d%s)", new, &"!"[!iter->highlighted]); @@ -10776,8 +10717,7 @@ static bool handle_command_set_add (struct config_item *item, const char *value, struct error **e) { - struct strv items; - strv_init (&items); + struct strv items = strv_make (); if (item->type != CONFIG_ITEM_NULL) cstr_split (item->value.string.str, ",", false, &items); if (items.len == 1 && !*items.vector[0]) @@ -10801,8 +10741,7 @@ static bool handle_command_set_remove (struct config_item *item, const char *value, struct error **e) { - struct strv items; - strv_init (&items); + struct strv items = strv_make (); if (item->type != CONFIG_ITEM_NULL) cstr_split (item->value.string.str, ",", false, &items); if (items.len == 1 && !*items.vector[0]) @@ -10851,8 +10790,7 @@ handle_command_set_assign_item (struct app_context *ctx, } else { - struct strv tmp; - strv_init (&tmp); + struct strv tmp = strv_make (); dump_matching_options (ctx->config.root, key, &tmp); log_global_status (ctx, "Option changed: #s", tmp.vector[0]); strv_free (&tmp); @@ -10908,8 +10846,7 @@ handle_command_set (struct handler_args *a) if (*a->arguments) option = cut_word (&a->arguments); - struct strv all; - strv_init (&all); + struct strv all = strv_make (); dump_matching_options (ctx->config.root, option, &all); bool result = true; @@ -10985,13 +10922,11 @@ show_aliases_list (struct app_context *ctx) return true; } - struct str_map_iter iter; - str_map_iter_init (&iter, aliases); + struct str_map_iter iter = str_map_iter_make (aliases); struct config_item *alias; while ((alias = str_map_iter_next (&iter))) { - struct str definition; - str_init (&definition); + struct str definition = str_make (); if (config_item_type_is_string (alias->type)) config_item_write_string (&definition, &alias->value.string); else @@ -11015,8 +10950,7 @@ handle_command_alias (struct handler_args *a) struct config_item *alias = config_item_string_from_cstr (a->arguments); - struct str definition; - str_init (&definition); + struct str definition = str_make (); config_item_write_string (&definition, &alias->value.string); str_map_set (get_aliases_config (a->ctx), name, alias); log_global_status (a->ctx, "Created alias /#s: #s", name, definition.str); @@ -11160,8 +11094,7 @@ handle_command_part (struct handler_args *a) { if (irc_is_channel (a->s, a->arguments)) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); 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); @@ -11203,8 +11136,7 @@ handle_command_cycle (struct handler_args *a) { if (irc_is_channel (a->s, a->arguments)) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); 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); @@ -11305,8 +11237,8 @@ mass_channel_mode (struct server *s, const char *channel_name, size_t n; for (size_t i = 0; i < v->len; i += n) { - struct str modes; str_init (&modes); - struct str params; str_init (¶ms); + struct str modes = str_make (); + struct str params = str_make (); n = MIN (v->len - i, s->irc_max_modes); str_append_printf (&modes, "MODE %s %c", channel_name, "-+"[adding]); @@ -11327,8 +11259,7 @@ static void mass_channel_mode_mask_list (struct handler_args *a, bool adding, char mode_char) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (a->arguments, " ", true, &v); // XXX: this may be a bit too trivial; we could also map nicknames @@ -11370,8 +11301,7 @@ handle_command_unban (struct handler_args *a) static bool handle_command_invite (struct handler_args *a) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (a->arguments, " ", true, &v); bool result = !!v.len; @@ -11454,8 +11384,7 @@ show_servers_list (struct app_context *ctx) log_global_indent (ctx, ""); log_global_indent (ctx, "Servers list:"); - struct str_map_iter iter; - str_map_iter_init (&iter, &ctx->servers); + struct str_map_iter iter = str_map_iter_make (&ctx->servers); struct server *s; while ((s = str_map_iter_next (&iter))) log_global_indent (ctx, " #s", s->name); @@ -11625,8 +11554,7 @@ handle_command_channel_mode if (!*a->arguments) return false; - struct strv v; - strv_init (&v); + struct strv v = strv_make (); cstr_split (a->arguments, " ", true, &v); mass_channel_mode (a->s, a->channel_name, adding, mode_char, &v); strv_free (&v); @@ -11834,8 +11762,7 @@ try_handle_command_help_option (struct app_context *ctx, const char *name) log_global_indent (ctx, " Default: #s", schema->default_ ? schema->default_ : "null"); - struct str tmp; - str_init (&tmp); + struct str tmp = str_make (); config_item_write (item, false, &tmp); log_global_indent (ctx, " Current value: #s", tmp.str); str_free (&tmp); @@ -11901,7 +11828,7 @@ handle_command_help (struct handler_args *a) static void init_user_command_map (struct str_map *map) { - str_map_init (map); + *map = str_map_make (NULL); map->key_xfrm = tolower_ascii_strxfrm; for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) @@ -11965,8 +11892,7 @@ 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 strv words; - strv_init (&words); + struct strv words = strv_make (); cstr_split (arguments, " ", true, &words); // TODO: eventually also add support for argument ranges @@ -11991,9 +11917,7 @@ static void expand_alias_definition (const char *definition, const char *arguments, struct strv *commands) { - struct str expanded; - str_init (&expanded); - + struct str expanded = str_make (); bool escape = false; for (const char *p = definition; *p; p++) { @@ -12005,7 +11929,7 @@ expand_alias_definition (const char *definition, const char *arguments, else if (*p == ';') { strv_append_owned (commands, str_steal (&expanded)); - str_init (&expanded); + expanded = str_make (); } else if (*p == '$' && p[1]) escape = true; @@ -12096,9 +12020,7 @@ process_input_utf8_posthook (struct app_context *ctx, struct buffer *buffer, if (process_user_command (ctx, buffer, name, input)) return true; - struct strv commands; - strv_init (&commands); - + struct strv commands = strv_make (); bool result = false; if (!expand_alias (ctx, name, input, &commands)) log_global_error (ctx, "#s: /#s", "No such command or alias", name); @@ -12154,8 +12076,7 @@ process_input (struct app_context *ctx, char *user_input) print_error ("character conversion failed for: %s", "user input"); else { - struct strv lines; - strv_init (&lines); + struct strv lines = strv_make (); // XXX: this interprets commands in pasted text cstr_split (input, "\r\n", false, &lines); @@ -12253,7 +12174,7 @@ utf8_common_prefix (const char **vector, size_t len) struct utf8_iter a[len]; for (size_t i = 0; i < len; i++) - utf8_iter_init (&a[i], vector[i]); + a[i] = utf8_iter_make (vector[i]); size_t ch_len; int32_t ch; @@ -12296,8 +12217,7 @@ complete_command (struct app_context *ctx, struct completion *data, xstrdup_printf ("%s%s", prefix, handler->name)); } - struct str_map_iter iter; - str_map_iter_init (&iter, get_aliases_config (ctx)); + struct str_map_iter iter = str_map_iter_make (get_aliases_config (ctx)); struct config_item *alias; while ((alias = str_map_iter_next (&iter))) { @@ -12313,9 +12233,7 @@ complete_option (struct app_context *ctx, struct completion *data, { (void) data; - struct strv options; - strv_init (&options); - + struct strv options = strv_make (); config_dump (ctx->config.root, &options); strv_sort (&options); @@ -12403,8 +12321,7 @@ complete_word (struct app_context *ctx, struct completion *data, else try_nicknames = true; - struct strv words; - strv_init (&words); + struct strv words = strv_make (); // Add placeholder strv_append_owned (&words, NULL); @@ -12453,8 +12370,8 @@ static char * locale_to_utf8 (struct app_context *ctx, const char *locale, int *indexes[], size_t n_indexes) { - struct str utf8; str_init (&utf8); - mbstate_t state; memset (&state, 0, sizeof state); + mbstate_t state; + memset (&state, 0, sizeof state); size_t remaining = strlen (locale) + 1; const char *p = locale; @@ -12465,6 +12382,7 @@ locale_to_utf8 (struct app_context *ctx, const char *locale, bool fixed[n_indexes]; memset (fixed, 0, sizeof fixed); + struct str utf8 = str_make (); while (true) { size_t len = mbrlen (p, remaining, &state); @@ -12706,9 +12624,7 @@ on_edit_input (int count, int key, void *user_data) static void input_editor_process (struct app_context *ctx) { - struct str input; - str_init (&input); - + struct str input = str_make (); struct error *e = NULL; if (!read_file (ctx->editor_filename, &input, &e)) { @@ -13277,8 +13193,7 @@ load_configuration_file (const char *filename, struct error **e) { struct config_item *root = NULL; - struct str data; - str_init (&data); + struct str data = str_make (); if (!read_file (filename, &data, e)) goto end; @@ -13387,8 +13302,7 @@ load_configuration (struct app_context *ctx) static void load_servers (struct app_context *ctx) { - struct str_map_iter iter; - str_map_iter_init (&iter, get_servers_config (ctx)); + struct str_map_iter iter = str_map_iter_make (get_servers_config (ctx)); struct config_item *subtree; while ((subtree = str_map_iter_next (&iter))) @@ -13658,8 +13572,7 @@ reset_autoaway (struct app_context *ctx) poller_timer_reset (&ctx->autoaway_tmr); // Unset any automated statuses that are active right at this moment - struct str_map_iter iter; - str_map_iter_init (&iter, &ctx->servers); + struct str_map_iter iter = str_map_iter_make (&ctx->servers); struct server *s; while ((s = str_map_iter_next (&iter))) { @@ -13687,8 +13600,7 @@ on_autoaway_timer (struct app_context *ctx) if (!message || !*message) return; - struct str_map_iter iter; - str_map_iter_init (&iter, &ctx->servers); + struct str_map_iter iter = str_map_iter_make (&ctx->servers); struct server *s; while ((s = str_map_iter_next (&iter))) { @@ -13778,35 +13690,35 @@ on_pending_input (struct app_context *ctx) static void init_poller_events (struct app_context *ctx) { - 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); - poller_fd_init (&ctx->tty_event, &ctx->poller, STDIN_FILENO); + ctx->tty_event = poller_fd_make (&ctx->poller, STDIN_FILENO); ctx->tty_event.dispatcher = (poller_fd_fn) on_tty_readable; ctx->tty_event.user_data = ctx; poller_fd_set (&ctx->tty_event, POLLIN); - poller_timer_init (&ctx->flush_timer, &ctx->poller); + ctx->flush_timer = poller_timer_make (&ctx->poller); ctx->flush_timer.dispatcher = (poller_timer_fn) on_flush_timer; ctx->flush_timer.user_data = ctx; rearm_flush_timer (ctx); - poller_timer_init (&ctx->date_chg_tmr, &ctx->poller); + ctx->date_chg_tmr = poller_timer_make (&ctx->poller); ctx->date_chg_tmr.dispatcher = (poller_timer_fn) on_date_change_timer; ctx->date_chg_tmr.user_data = ctx; rearm_date_change_timer (ctx); - poller_timer_init (&ctx->autoaway_tmr, &ctx->poller); + ctx->autoaway_tmr = poller_timer_make (&ctx->poller); ctx->autoaway_tmr.dispatcher = (poller_timer_fn) on_autoaway_timer; ctx->autoaway_tmr.user_data = ctx; - poller_idle_init (&ctx->prompt_event, &ctx->poller); + ctx->prompt_event = poller_idle_make (&ctx->poller); ctx->prompt_event.dispatcher = (poller_idle_fn) on_refresh_prompt; ctx->prompt_event.user_data = ctx; - poller_idle_init (&ctx->input_event, &ctx->poller); + ctx->input_event = poller_idle_make (&ctx->poller); ctx->input_event.dispatcher = (poller_idle_fn) on_pending_input; ctx->input_event.user_data = ctx; } @@ -13850,8 +13762,7 @@ test_config_load (struct config_item *subtree, void *user_data) static void test_config (void) { - struct config config; - config_init (&config); + struct config config = config_make (); bool b = true; config_register_module (&config, "top", test_config_load, &b); @@ -13864,14 +13775,12 @@ test_config (void) "top.bar", NULL), invalid, NULL)); config_item_destroy (invalid); - struct str s; - str_init (&s); + struct str s = str_make (); serialize_configuration (config.root, &s); config_load (&config, config_item_parse (s.str, s.len, false, NULL)); str_free (&s); - struct strv v; - strv_init (&v); + struct strv v = strv_make (); dump_matching_options (config.root, "*foo*", &v); hard_assert (v.len == 2); hard_assert (!strcmp (v.vector[0], "top.foo = off")); @@ -13886,8 +13795,7 @@ test_config (void) static void test_aliases (void) { - struct strv v; - strv_init (&v); + struct strv v = strv_make (); 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")); @@ -13904,8 +13812,7 @@ test_wrapping (void) static const char *split[] = { " foo", "bar", "foob", "ar", "fó", "ób", "árb", "áz" }; - struct strv v; - strv_init (&v); + struct strv v = strv_make (); 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++) @@ -13986,8 +13893,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 client."); + struct opt_handler oh = + opt_handler_make (argc, argv, opts, NULL, "Experimental IRC client."); bool format_mode = false; int c; diff --git a/kike.c b/kike.c index efcb39e..166b541 100644 --- a/kike.c +++ b/kike.c @@ -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); diff --git a/liberty b/liberty index 084e964..3835b6e 160000 --- a/liberty +++ b/liberty @@ -1 +1 @@ -Subproject commit 084e964286bfcd13ee6a25a2ee35dfba9da1072e +Subproject commit 3835b6e49975039a9f72b8920238f3141e7becea diff --git a/zyklonb.c b/zyklonb.c index d3de92d..b1a9282 100644 --- a/zyklonb.c +++ b/zyklonb.c @@ -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);