summaryrefslogtreecommitdiff
path: root/xC.c
diff options
context:
space:
mode:
Diffstat (limited to 'xC.c')
-rw-r--r--xC.c136
1 files changed, 112 insertions, 24 deletions
diff --git a/xC.c b/xC.c
index a378421..0da1fea 100644
--- a/xC.c
+++ b/xC.c
@@ -3109,6 +3109,28 @@ relay_prepare_buffer_update (struct app_context *ctx, struct buffer *buffer)
e->event = RELAY_EVENT_BUFFER_UPDATE;
e->buffer_name = str_from_cstr (buffer->name);
e->hide_unimportant = buffer->hide_unimportant;
+
+ struct str *server_name = NULL;
+ switch (buffer->type)
+ {
+ case BUFFER_GLOBAL:
+ e->context.kind = RELAY_BUFFER_KIND_GLOBAL;
+ break;
+ case BUFFER_SERVER:
+ e->context.kind = RELAY_BUFFER_KIND_SERVER;
+ server_name = &e->context.server.server_name;
+ break;
+ case BUFFER_CHANNEL:
+ e->context.kind = RELAY_BUFFER_KIND_CHANNEL;
+ server_name = &e->context.channel.server_name;
+ break;
+ case BUFFER_PM:
+ e->context.kind = RELAY_BUFFER_KIND_PRIVATE_MESSAGE;
+ server_name = &e->context.private_message.server_name;
+ break;
+ }
+ if (server_name)
+ *server_name = str_from_cstr (buffer->server->name);
}
static void
@@ -3248,6 +3270,51 @@ relay_prepare_buffer_clear (struct app_context *ctx,
e->buffer_name = str_from_cstr (buffer->name);
}
+enum relay_server_state
+relay_server_state_for_server (struct server *s)
+{
+ switch (s->state)
+ {
+ case IRC_DISCONNECTED: return RELAY_SERVER_STATE_DISCONNECTED;
+ case IRC_CONNECTING: return RELAY_SERVER_STATE_CONNECTING;
+ case IRC_CONNECTED: return RELAY_SERVER_STATE_CONNECTED;
+ case IRC_REGISTERED: return RELAY_SERVER_STATE_REGISTERED;
+ case IRC_CLOSING:
+ case IRC_HALF_CLOSED: return RELAY_SERVER_STATE_DISCONNECTING;
+ }
+ return 0;
+}
+
+static void
+relay_prepare_server_update (struct app_context *ctx, struct server *s)
+{
+ struct relay_event_message *m = relay_prepare (ctx);
+ struct relay_event_data_server_update *e = &m->data.server_update;
+ e->event = RELAY_EVENT_SERVER_UPDATE;
+ e->server_name = str_from_cstr (s->name);
+ e->state = relay_server_state_for_server (s);
+}
+
+static void
+relay_prepare_server_rename (struct app_context *ctx, struct server *s,
+ const char *new_name)
+{
+ struct relay_event_message *m = relay_prepare (ctx);
+ struct relay_event_data_server_rename *e = &m->data.server_rename;
+ e->event = RELAY_EVENT_SERVER_RENAME;
+ e->server_name = str_from_cstr (s->name);
+ e->new = str_from_cstr (new_name);
+}
+
+static void
+relay_prepare_server_remove (struct app_context *ctx, struct server *s)
+{
+ struct relay_event_message *m = relay_prepare (ctx);
+ struct relay_event_data_server_remove *e = &m->data.server_remove;
+ e->event = RELAY_EVENT_SERVER_REMOVE;
+ e->server_name = str_from_cstr (s->name);
+}
+
static void
relay_prepare_error (struct app_context *ctx, uint32_t seq, const char *message)
{
@@ -4890,14 +4957,14 @@ buffer_add (struct app_context *ctx, struct buffer *buffer)
{
hard_assert (!buffer_by_name (ctx, buffer->name));
+ relay_prepare_buffer_update (ctx, buffer);
+ relay_broadcast (ctx);
+
str_map_set (&ctx->buffers_by_name, buffer->name, buffer);
LIST_APPEND_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
buffer_open_log_file (ctx, buffer);
- relay_prepare_buffer_update (ctx, buffer);
- relay_broadcast (ctx);
-
// Normally this doesn't cause changes in the prompt but a prompt hook
// could decide to show some information for all buffers nonetheless
refresh_prompt (ctx);
@@ -4909,6 +4976,9 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
hard_assert (buffer != ctx->current_buffer);
hard_assert (buffer != ctx->global_buffer);
+ relay_prepare_buffer_remove (ctx, buffer);
+ relay_broadcast (ctx);
+
CALL_ (ctx->input, buffer_destroy, buffer->input_data);
buffer->input_data = NULL;
@@ -4924,9 +4994,6 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
if (buffer->type == BUFFER_SERVER)
buffer->server->buffer = NULL;
- relay_prepare_buffer_remove (ctx, buffer);
- relay_broadcast (ctx);
-
str_map_set (&ctx->buffers_by_name, buffer->name, NULL);
LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
buffer_unref (buffer);
@@ -5040,6 +5107,9 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
if (ctx->current_buffer == buffer)
return;
+ relay_prepare_buffer_activate (ctx, buffer);
+ relay_broadcast (ctx);
+
// This is the only place where the unread messages marker
// and highlight indicator are reset
if (ctx->current_buffer)
@@ -5056,9 +5126,6 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
ctx->last_buffer = ctx->current_buffer;
ctx->current_buffer = buffer;
- relay_prepare_buffer_activate (ctx, buffer);
- relay_broadcast (ctx);
-
refresh_prompt (ctx);
}
@@ -5146,14 +5213,14 @@ buffer_rename (struct app_context *ctx,
static void
buffer_clear (struct app_context *ctx, struct buffer *buffer)
{
+ relay_prepare_buffer_clear (ctx, buffer);
+ relay_broadcast (ctx);
+
LIST_FOR_EACH (struct buffer_line, iter, buffer->lines)
buffer_line_destroy (iter);
buffer->lines = buffer->lines_tail = NULL;
buffer->lines_count = 0;
-
- relay_prepare_buffer_clear (ctx, buffer);
- relay_broadcast (ctx);
}
static struct buffer *
@@ -5666,6 +5733,17 @@ irc_send (struct server *s, const char *format, ...)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void
+irc_set_state (struct server *s, enum server_state state)
+{
+ s->state = state;
+
+ relay_prepare_server_update (s->ctx, s);
+ relay_broadcast (s->ctx);
+
+ refresh_prompt (s->ctx);
+}
+
+static void
irc_real_shutdown (struct server *s)
{
hard_assert (irc_is_connected (s) && s->state != IRC_HALF_CLOSED);
@@ -5680,7 +5758,7 @@ irc_real_shutdown (struct server *s)
if (!soft_assert (errno == EINTR))
break;
- s->state = IRC_HALF_CLOSED;
+ irc_set_state (s, IRC_HALF_CLOSED);
}
static void
@@ -5691,7 +5769,7 @@ irc_shutdown (struct server *s)
return;
// TODO: set a timer to cut the connection if we don't receive an EOF
- s->state = IRC_CLOSING;
+ irc_set_state (s, IRC_CLOSING);
// Either there's still some data in the write buffer and we wait
// until they're sent, or we send an EOF to the server right away
@@ -5713,7 +5791,7 @@ irc_destroy_connector (struct server *s)
s->socks_conn = NULL;
// Not connecting anymore
- s->state = IRC_DISCONNECTED;
+ irc_set_state (s, IRC_DISCONNECTED);
}
static void
@@ -5744,7 +5822,7 @@ irc_destroy_transport (struct server *s)
poller_fd_reset (&s->socket_event);
xclose (s->socket);
s->socket = -1;
- s->state = IRC_DISCONNECTED;
+ irc_set_state (s, IRC_DISCONNECTED);
str_reset (&s->read_buffer);
str_reset (&s->write_buffer);
@@ -5805,8 +5883,6 @@ irc_disconnect (struct server *s)
s->reconnect_attempt = 0;
irc_queue_reconnect (s);
}
-
- refresh_prompt (s->ctx);
}
static void
@@ -6558,7 +6634,7 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
}
log_server_status (s, s->buffer, "Connection established");
- s->state = IRC_CONNECTED;
+ irc_set_state (s, IRC_CONNECTED);
s->socket_event = poller_fd_make (&ctx->poller, s->socket);
s->socket_event.dispatcher = (poller_fd_fn) on_irc_ready;
@@ -6567,8 +6643,6 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
irc_update_poller (s, NULL);
irc_reset_connection_timeouts (s);
irc_register (s);
-
- refresh_prompt (s->ctx);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -6715,7 +6789,7 @@ irc_initiate_connect (struct server *s)
irc_queue_reconnect (s);
}
else if (s->state != IRC_CONNECTED)
- s->state = IRC_CONNECTING;
+ irc_set_state (s, IRC_CONNECTING);
}
// --- Input prompt ------------------------------------------------------------
@@ -8263,8 +8337,7 @@ irc_on_registered (struct server *s, const char *nickname)
str_reset (&s->irc_user_mode);
cstr_set (&s->irc_user_host, NULL);
- s->state = IRC_REGISTERED;
- refresh_prompt (s->ctx);
+ irc_set_state (s, IRC_REGISTERED);
// XXX: we can also use WHOIS if it's not supported (optional by RFC 2812)
// TODO: maybe rather always use RPL_ISUPPORT NICKLEN & USERLEN & HOSTLEN
@@ -9422,6 +9495,9 @@ server_remove (struct app_context *ctx, struct server *s)
if (s->buffer)
buffer_remove_safe (ctx, s->buffer);
+ relay_prepare_server_remove (ctx, s);
+ relay_broadcast (ctx);
+
struct str_map_unset_iter iter =
str_map_unset_iter_make (&s->irc_buffer_map);
struct buffer *buffer;
@@ -9445,6 +9521,10 @@ static void
server_rename (struct app_context *ctx, struct server *s, const char *new_name)
{
hard_assert (!str_map_find (&ctx->servers, new_name));
+
+ relay_prepare_server_rename (ctx, s, new_name);
+ relay_broadcast (ctx);
+
str_map_set (&ctx->servers, new_name,
str_map_steal (&ctx->servers, s->name));
@@ -15319,6 +15399,14 @@ init_poller_events (struct app_context *ctx)
static void
client_resync (struct client *c)
{
+ struct str_map_iter iter = str_map_iter_make (&c->ctx->servers);
+ struct server *s;
+ while ((s = str_map_iter_next (&iter)))
+ {
+ relay_prepare_server_update (c->ctx, s);
+ relay_send (c);
+ }
+
LIST_FOR_EACH (struct buffer, buffer, c->ctx->buffers)
{
relay_prepare_buffer_update (c->ctx, buffer);