aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-14 06:50:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-14 06:50:39 +0200
commitc57343599620435235c12c5a91f768e987687e79 (patch)
tree4fd14a4f35446fd665016e7f22c57143e85cca77
parent880a8ef080e812614a55a80fb882291e8f072f9b (diff)
downloadxK-c57343599620435235c12c5a91f768e987687e79.tar.gz
xK-c57343599620435235c12c5a91f768e987687e79.tar.xz
xK-c57343599620435235c12c5a91f768e987687e79.zip
degesch: implement /server remove
-rw-r--r--degesch.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/degesch.c b/degesch.c
index 5b2177d..00e50a1 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1269,6 +1269,10 @@ server_free (struct server *self)
str_free (&self->read_buffer);
str_free (&self->write_buffer);
+ poller_timer_reset (&self->ping_tmr);
+ poller_timer_reset (&self->timeout_tmr);
+ poller_timer_reset (&self->reconnect_tmr);
+
str_map_free (&self->irc_users);
str_map_free (&self->irc_channels);
str_map_free (&self->irc_buffer_map);
@@ -2917,7 +2921,6 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
{
hard_assert (buffer != ctx->current_buffer);
hard_assert (buffer != ctx->global_buffer);
- hard_assert (buffer->type != BUFFER_SERVER);
input_destroy_buffer (&ctx->input, buffer->input_data);
buffer->input_data = NULL;
@@ -2931,6 +2934,8 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
if (buffer == ctx->last_buffer)
ctx->last_buffer = NULL;
+ if (buffer->type == BUFFER_SERVER)
+ buffer->server->buffer = NULL;
str_map_set (&ctx->buffers_by_name, buffer->name, NULL);
LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
@@ -6557,6 +6562,35 @@ server_add_new (struct app_context *ctx, const char *name)
}
}
+static void
+server_remove (struct app_context *ctx, struct server *s)
+{
+ hard_assert (!irc_is_connected (s));
+
+ if (s->buffer)
+ buffer_remove_safe (ctx, s->buffer);
+
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, &s->irc_buffer_map);
+ struct buffer *buffer, *next = str_map_iter_next (&iter);
+ for (buffer = next; buffer; buffer = next)
+ {
+ next = str_map_iter_next (&iter);
+ buffer_remove_safe (ctx, buffer);
+ }
+
+ hard_assert (!s->buffer);
+ hard_assert (!s->irc_buffer_map.len);
+ hard_assert (!s->irc_channels.len);
+ soft_assert (!s->irc_users.len);
+
+ str_map_set (get_servers_config (ctx), s->name, NULL);
+ s->config = NULL;
+
+ // This actually destroys the server as it's owned by the map
+ str_map_set (&ctx->servers, s->name, NULL);
+}
+
// --- User input handling -----------------------------------------------------
// HANDLER_NEEDS_REG is primarily for message sending commands,
@@ -7478,7 +7512,30 @@ handle_server_add (struct handler_args *a)
struct app_context *ctx = a->ctx;
char *name = cut_word (&a->arguments);
if (check_server_name_for_addition (ctx, name))
+ {
server_add_new (ctx, name);
+ log_global_status (ctx, "Server added: #s", name);
+ }
+ return true;
+}
+
+static bool
+handle_server_remove (struct handler_args *a)
+{
+ struct app_context *ctx = a->ctx;
+ struct server *s = NULL;
+ if (!(s = resolve_server (ctx, a, "server")))
+ return true;
+
+ if (irc_is_connected (s))
+ log_server_error (s, s->buffer, "Can't remove a connected server");
+ else
+ {
+ char *name = xstrdup (s->name);
+ server_remove (ctx, s);
+ log_global_status (ctx, "Server removed: #s", name);
+ free (name);
+ }
return true;
}
@@ -7496,7 +7553,7 @@ handle_command_server (struct handler_args *a)
else if (!strcasecmp_ascii (action, "add"))
result = handle_server_add (a);
else if (!strcasecmp_ascii (action, "remove"))
- ; // TODO: <name>
+ result = handle_server_remove (a);
else if (!strcasecmp_ascii (action, "rename"))
; // TODO: <old> <new>
else