From 8eb31ad2e11038a17f66c84f48befda6b3b807d2 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 18 Jun 2015 22:30:18 +0200 Subject: degesch: fix /invite --- common.c | 11 +++++++++++ degesch.c | 29 ++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/common.c b/common.c index 52e737a..fab0205 100644 --- a/common.c +++ b/common.c @@ -70,6 +70,17 @@ str_vector_find (const struct str_vector *v, const char *s) return -1; } +static char * +str_vector_steal (struct str_vector *self, size_t i) +{ + // TODO: str_vector_remove() is then just free(str_vector_steal()) + hard_assert (i < self->len); + char *tmp = self->vector[i]; + memmove (self->vector + i, self->vector + i + 1, + (self->len-- - i) * sizeof *self->vector); + return tmp; +} + static int strncasecmp_ascii (const char *a, const char *b, size_t n) { diff --git a/degesch.c b/degesch.c index 4bdaaba..e525e3d 100644 --- a/degesch.c +++ b/degesch.c @@ -6502,18 +6502,33 @@ handle_command_invite (struct app_context *ctx, char *arguments) if (!server_command_check (ctx, "invite", true)) return true; - // XXX: the order of arguments should probably be reverse struct server *s = ctx->current_buffer->server; - char *channel_name = try_get_channel (ctx, &arguments); + + struct str_vector v; + str_vector_init (&v); + split_str_ignore_empty (arguments, ' ', &v); + + char *channel_name = NULL; + size_t last = v.len - 1; + if (v.len && irc_is_channel (s, v.vector[last])) + channel_name = str_vector_steal (&v, last); + else if (ctx->current_buffer->type == BUFFER_CHANNEL) + channel_name = xstrdup (ctx->current_buffer->channel->name); + + bool result = true; if (!channel_name) buffer_send_error (ctx, ctx->current_buffer, "%s: %s", "Can't invite", "no channel name given and this buffer is not a channel"); - else if (*arguments) - irc_send (s, "INVITE %s %s", arguments, channel_name); + else if (v.len) + for (size_t i = 0; i < v.len; i++) + irc_send (s, "INVITE %s %s", v.vector[i], channel_name); else - return false; - return true; + result = false; + + str_vector_free (&v); + free (channel_name); + return result; } static bool @@ -6807,7 +6822,7 @@ g_command_handlers[] = "[] ...", handle_command_unban }, { "invite", "Invite user to channel", - "[] ", + "... []", handle_command_invite }, { "connect", "Connect to the server", -- cgit v1.2.3-70-g09d2