summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-20 23:30:05 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-20 23:30:05 +0200
commit3c982c7077bf32034d3931c256be586026c95c72 (patch)
treebc91a9c2248acee73b2c90ece4a8d1d22a748196 /degesch.c
parent7bd0eefea88109df24f77531e712c8872642eec2 (diff)
downloadxK-3c982c7077bf32034d3931c256be586026c95c72.tar.gz
xK-3c982c7077bf32034d3931c256be586026c95c72.tar.xz
xK-3c982c7077bf32034d3931c256be586026c95c72.zip
degesch: make buffer_send_*() accept a NULL buffer
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/degesch.c b/degesch.c
index 8e28ce8..e829fb0 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2507,6 +2507,9 @@ buffer_send_internal (struct app_context *ctx, struct buffer *buffer,
enum buffer_line_type type, int flags,
struct buffer_line_args a)
{
+ if (!buffer)
+ buffer = ctx->global_buffer;
+
struct buffer_line *line = buffer_line_new ();
line->type = type;
line->flags = flags;
@@ -2990,12 +2993,12 @@ irc_initialize_ssl (struct server *s, struct error **e)
{
char *path = resolve_config_filename (ssl_cert);
if (!path)
- buffer_send_error (s->ctx, s->ctx->global_buffer,
+ buffer_send_error (s->ctx, NULL,
"%s: %s", "Cannot open file", ssl_cert);
// XXX: perhaps we should read the file ourselves for better messages
else if (!SSL_use_certificate_file (s->ssl, path, SSL_FILETYPE_PEM)
|| !SSL_use_PrivateKey_file (s->ssl, path, SSL_FILETYPE_PEM))
- buffer_send_error (s->ctx, s->ctx->global_buffer,
+ buffer_send_error (s->ctx, NULL,
"%s: %s", "Setting the SSL client certificate failed",
ERR_error_string (ERR_get_error (), NULL));
free (path);
@@ -3155,7 +3158,7 @@ try_finish_quit (struct app_context *ctx)
static void
initiate_quit (struct app_context *ctx)
{
- buffer_send_status (ctx, ctx->global_buffer, "Shutting down");
+ buffer_send_status (ctx, NULL, "Shutting down");
// Destroy the user interface
input_stop (&ctx->input);
@@ -5862,8 +5865,7 @@ try_handle_buffer_goto (struct app_context *ctx, const char *word)
return false;
if (n > INT_MAX || !buffer_goto (ctx, n))
- buffer_send_error (ctx, ctx->global_buffer,
- "%s: %s", "No such buffer", word);
+ buffer_send_error (ctx, NULL, "%s: %s", "No such buffer", word);
return true;
}
@@ -5883,13 +5885,12 @@ try_decode_buffer (struct app_context *ctx, const char *word)
static void
show_buffers_list (struct app_context *ctx)
{
- buffer_send_status (ctx, ctx->global_buffer, "%s", "");
- buffer_send_status (ctx, ctx->global_buffer, "Buffers list:");
+ buffer_send_status (ctx, NULL, "%s", "");
+ buffer_send_status (ctx, NULL, "Buffers list:");
int i = 1;
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
- buffer_send_status (ctx, ctx->global_buffer,
- " [%d] %s", i++, iter->name);
+ buffer_send_status (ctx, NULL, " [%d] %s", i++, iter->name);
}
static void
@@ -5903,14 +5904,11 @@ handle_buffer_close (struct app_context *ctx, char *arguments)
buffer = try_decode_buffer (ctx, (which = cut_word (&arguments)));
if (!buffer)
- buffer_send_error (ctx, ctx->global_buffer,
- "%s: %s", "No such buffer", which);
+ buffer_send_error (ctx, NULL, "%s: %s", "No such buffer", which);
else if (buffer == ctx->global_buffer)
- buffer_send_error (ctx, ctx->global_buffer,
- "Can't close the global buffer");
+ buffer_send_error (ctx, NULL, "Can't close the global buffer");
else if (buffer->type == BUFFER_SERVER)
- buffer_send_error (ctx, ctx->global_buffer,
- "Can't close a server buffer");
+ buffer_send_error (ctx, NULL, "Can't close a server buffer");
else
{
if (buffer == ctx->current_buffer)
@@ -6029,7 +6027,7 @@ handle_command_set_assign_item (struct app_context *ctx,
if (e)
{
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"Failed to set option \"%s\": %s", key, e->message);
error_free (e);
}
@@ -6038,8 +6036,7 @@ handle_command_set_assign_item (struct app_context *ctx,
struct str_vector tmp;
str_vector_init (&tmp);
dump_matching_options (ctx, key, &tmp);
- buffer_send_status (ctx, ctx->global_buffer,
- "Option changed: %s", tmp.vector[0]);
+ buffer_send_status (ctx, NULL, "Option changed: %s", tmp.vector[0]);
str_vector_free (&tmp);
}
}
@@ -6064,15 +6061,14 @@ handle_command_set_assign
config_item_parse (arguments, strlen (arguments), true, &e);
if (e)
{
- buffer_send_error (ctx, ctx->global_buffer,
- "Invalid value: %s", e->message);
+ buffer_send_error (ctx, NULL, "Invalid value: %s", e->message);
error_free (e);
return true;
}
if ((add | remove) && !config_item_type_is_string (new_->type))
{
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"+= / -= operators need a string argument");
config_item_destroy (new_);
return true;
@@ -6100,12 +6096,12 @@ handle_command_set (struct app_context *ctx, struct handler_args *a)
bool result = true;
if (!all.len)
- buffer_send_error (ctx, ctx->global_buffer, "No matches: %s", option);
+ buffer_send_error (ctx, NULL, "No matches: %s", option);
else if (!*a->arguments)
{
- buffer_send_status (ctx, ctx->global_buffer, "%s", "");
+ buffer_send_status (ctx, NULL, "%s", "");
for (size_t i = 0; i < all.len; i++)
- buffer_send_status (ctx, ctx->global_buffer, "%s", all.vector[i]);
+ buffer_send_status (ctx, NULL, "%s", all.vector[i]);
}
else
result = handle_command_set_assign (ctx, &all, a->arguments);
@@ -6130,12 +6126,12 @@ handle_command_save (struct app_context *ctx, struct handler_args *a)
if (!filename)
{
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"%s: %s", "Saving configuration failed", e->message);
error_free (e);
}
else
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL,
"Configuration written to `%s'", filename);
free (filename);
return true;
@@ -6528,11 +6524,11 @@ resolve_server (struct app_context *ctx, struct handler_args *a,
{
char *server_name = cut_word (&a->arguments);
if (!(s = str_map_find (&ctx->servers, server_name)))
- buffer_send_error (ctx, ctx->global_buffer, "/%s: %s: %s",
+ buffer_send_error (ctx, NULL, "/%s: %s: %s",
command_name, "no such server", server_name);
}
else if (a->buffer->type == BUFFER_GLOBAL)
- buffer_send_error (ctx, a->buffer, "/%s: %s",
+ buffer_send_error (ctx, NULL, "/%s: %s",
command_name, "no server name given and this buffer is global");
else
s = a->buffer->server;
@@ -6828,25 +6824,24 @@ try_handle_command_help_option (struct app_context *ctx, const char *name)
struct config_schema *schema = item->schema;
if (!schema)
{
- buffer_send_error (ctx, ctx->global_buffer,
- "%s: %s", "Option not recognized", name);
+ buffer_send_error (ctx, NULL, "%s: %s", "Option not recognized", name);
return true;
}
- buffer_send_status (ctx, ctx->global_buffer, "%s", "");
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL, "%s", "");
+ buffer_send_status (ctx, NULL,
"Option \"%s\":", name);
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL,
" Description: %s", schema->comment);
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL,
" Type: %s", config_item_type_name (schema->type));
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL,
" Default: %s", schema->default_ ? schema->default_ : "null");
struct str tmp;
str_init (&tmp);
config_item_write (item, false, &tmp);
- buffer_send_status (ctx, ctx->global_buffer,
+ buffer_send_status (ctx, NULL,
" Current value: %s", tmp.str);
str_free (&tmp);
return true;
@@ -6857,8 +6852,8 @@ handle_command_help (struct app_context *ctx, struct handler_args *a)
{
if (!*a->arguments)
{
- buffer_send_status (ctx, ctx->global_buffer, "%s", "");
- buffer_send_status (ctx, ctx->global_buffer, "Commands:");
+ buffer_send_status (ctx, NULL, "%s", "");
+ buffer_send_status (ctx, NULL, "Commands:");
int longest = 0;
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
@@ -6869,8 +6864,8 @@ handle_command_help (struct app_context *ctx, struct handler_args *a)
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
{
struct command_handler *handler = &g_command_handlers[i];
- buffer_send_status (ctx, ctx->global_buffer, " %-*s %s",
- longest, handler->name, handler->description);
+ buffer_send_status (ctx, NULL,
+ " %-*s %s", longest, handler->name, handler->description);
}
return true;
}
@@ -6882,16 +6877,16 @@ handle_command_help (struct app_context *ctx, struct handler_args *a)
if (strcasecmp_ascii (command, handler->name))
continue;
- buffer_send_status (ctx, ctx->global_buffer, "%s", "");
- buffer_send_status (ctx, ctx->global_buffer, "%s: %s",
+ buffer_send_status (ctx, NULL, "%s", "");
+ buffer_send_status (ctx, NULL, "%s: %s",
handler->name, handler->description);
- buffer_send_status (ctx, ctx->global_buffer, " Arguments: %s",
+ buffer_send_status (ctx, NULL, " Arguments: %s",
handler->usage ? handler->usage : "(none)");
return true;
}
if (!try_handle_command_help_option (ctx, command))
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"%s: %s", "No such command or option", command);
return true;
}
@@ -6954,11 +6949,11 @@ process_user_command (struct app_context *ctx, char *input)
struct command_handler *handler = str_map_find (&partial, command_name);
if (!handler)
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"%s: %s", "No such command", command_name);
else if ((handler->flags & HANDLER_SERVER)
&& args.buffer->type == BUFFER_GLOBAL)
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"/%s: %s", command_name, "can't do this from a global buffer");
else if ((handler->flags & HANDLER_SERVER)
&& !irc_is_connected ((args.s = args.buffer->server)))
@@ -6975,7 +6970,7 @@ process_user_command (struct app_context *ctx, char *input)
buffer_send_error (ctx, args.buffer, "/%s: %s", command_name,
"no channel name given and this buffer is not a channel");
else if (!handler->handler (ctx, &args))
- buffer_send_error (ctx, ctx->global_buffer,
+ buffer_send_error (ctx, NULL,
"%s: /%s %s", "Usage", handler->name, handler->usage);
}