degesch: make buffer_send_*() accept a NULL buffer
This commit is contained in:
parent
7bd0eefea8
commit
3c982c7077
89
degesch.c
89
degesch.c
|
@ -2507,6 +2507,9 @@ buffer_send_internal (struct app_context *ctx, struct buffer *buffer,
|
||||||
enum buffer_line_type type, int flags,
|
enum buffer_line_type type, int flags,
|
||||||
struct buffer_line_args a)
|
struct buffer_line_args a)
|
||||||
{
|
{
|
||||||
|
if (!buffer)
|
||||||
|
buffer = ctx->global_buffer;
|
||||||
|
|
||||||
struct buffer_line *line = buffer_line_new ();
|
struct buffer_line *line = buffer_line_new ();
|
||||||
line->type = type;
|
line->type = type;
|
||||||
line->flags = flags;
|
line->flags = flags;
|
||||||
|
@ -2990,12 +2993,12 @@ irc_initialize_ssl (struct server *s, struct error **e)
|
||||||
{
|
{
|
||||||
char *path = resolve_config_filename (ssl_cert);
|
char *path = resolve_config_filename (ssl_cert);
|
||||||
if (!path)
|
if (!path)
|
||||||
buffer_send_error (s->ctx, s->ctx->global_buffer,
|
buffer_send_error (s->ctx, NULL,
|
||||||
"%s: %s", "Cannot open file", ssl_cert);
|
"%s: %s", "Cannot open file", ssl_cert);
|
||||||
// XXX: perhaps we should read the file ourselves for better messages
|
// XXX: perhaps we should read the file ourselves for better messages
|
||||||
else if (!SSL_use_certificate_file (s->ssl, path, SSL_FILETYPE_PEM)
|
else if (!SSL_use_certificate_file (s->ssl, path, SSL_FILETYPE_PEM)
|
||||||
|| !SSL_use_PrivateKey_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",
|
"%s: %s", "Setting the SSL client certificate failed",
|
||||||
ERR_error_string (ERR_get_error (), NULL));
|
ERR_error_string (ERR_get_error (), NULL));
|
||||||
free (path);
|
free (path);
|
||||||
|
@ -3155,7 +3158,7 @@ try_finish_quit (struct app_context *ctx)
|
||||||
static void
|
static void
|
||||||
initiate_quit (struct app_context *ctx)
|
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
|
// Destroy the user interface
|
||||||
input_stop (&ctx->input);
|
input_stop (&ctx->input);
|
||||||
|
@ -5862,8 +5865,7 @@ try_handle_buffer_goto (struct app_context *ctx, const char *word)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (n > INT_MAX || !buffer_goto (ctx, n))
|
if (n > INT_MAX || !buffer_goto (ctx, n))
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "%s: %s", "No such buffer", word);
|
||||||
"%s: %s", "No such buffer", word);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5883,13 +5885,12 @@ try_decode_buffer (struct app_context *ctx, const char *word)
|
||||||
static void
|
static void
|
||||||
show_buffers_list (struct app_context *ctx)
|
show_buffers_list (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
buffer_send_status (ctx, NULL, "%s", "");
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "Buffers list:");
|
buffer_send_status (ctx, NULL, "Buffers list:");
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
|
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL, " [%d] %s", i++, iter->name);
|
||||||
" [%d] %s", i++, iter->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -5903,14 +5904,11 @@ handle_buffer_close (struct app_context *ctx, char *arguments)
|
||||||
buffer = try_decode_buffer (ctx, (which = cut_word (&arguments)));
|
buffer = try_decode_buffer (ctx, (which = cut_word (&arguments)));
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "%s: %s", "No such buffer", which);
|
||||||
"%s: %s", "No such buffer", which);
|
|
||||||
else if (buffer == ctx->global_buffer)
|
else if (buffer == ctx->global_buffer)
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "Can't close the global buffer");
|
||||||
"Can't close the global buffer");
|
|
||||||
else if (buffer->type == BUFFER_SERVER)
|
else if (buffer->type == BUFFER_SERVER)
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "Can't close a server buffer");
|
||||||
"Can't close a server buffer");
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (buffer == ctx->current_buffer)
|
if (buffer == ctx->current_buffer)
|
||||||
|
@ -6029,7 +6027,7 @@ handle_command_set_assign_item (struct app_context *ctx,
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL,
|
||||||
"Failed to set option \"%s\": %s", key, e->message);
|
"Failed to set option \"%s\": %s", key, e->message);
|
||||||
error_free (e);
|
error_free (e);
|
||||||
}
|
}
|
||||||
|
@ -6038,8 +6036,7 @@ handle_command_set_assign_item (struct app_context *ctx,
|
||||||
struct str_vector tmp;
|
struct str_vector tmp;
|
||||||
str_vector_init (&tmp);
|
str_vector_init (&tmp);
|
||||||
dump_matching_options (ctx, key, &tmp);
|
dump_matching_options (ctx, key, &tmp);
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL, "Option changed: %s", tmp.vector[0]);
|
||||||
"Option changed: %s", tmp.vector[0]);
|
|
||||||
str_vector_free (&tmp);
|
str_vector_free (&tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6064,15 +6061,14 @@ handle_command_set_assign
|
||||||
config_item_parse (arguments, strlen (arguments), true, &e);
|
config_item_parse (arguments, strlen (arguments), true, &e);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "Invalid value: %s", e->message);
|
||||||
"Invalid value: %s", e->message);
|
|
||||||
error_free (e);
|
error_free (e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((add | remove) && !config_item_type_is_string (new_->type))
|
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");
|
"+= / -= operators need a string argument");
|
||||||
config_item_destroy (new_);
|
config_item_destroy (new_);
|
||||||
return true;
|
return true;
|
||||||
|
@ -6100,12 +6096,12 @@ handle_command_set (struct app_context *ctx, struct handler_args *a)
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
if (!all.len)
|
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)
|
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++)
|
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
|
else
|
||||||
result = handle_command_set_assign (ctx, &all, a->arguments);
|
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)
|
if (!filename)
|
||||||
{
|
{
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL,
|
||||||
"%s: %s", "Saving configuration failed", e->message);
|
"%s: %s", "Saving configuration failed", e->message);
|
||||||
error_free (e);
|
error_free (e);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL,
|
||||||
"Configuration written to `%s'", filename);
|
"Configuration written to `%s'", filename);
|
||||||
free (filename);
|
free (filename);
|
||||||
return true;
|
return true;
|
||||||
|
@ -6528,11 +6524,11 @@ resolve_server (struct app_context *ctx, struct handler_args *a,
|
||||||
{
|
{
|
||||||
char *server_name = cut_word (&a->arguments);
|
char *server_name = cut_word (&a->arguments);
|
||||||
if (!(s = str_map_find (&ctx->servers, server_name)))
|
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);
|
command_name, "no such server", server_name);
|
||||||
}
|
}
|
||||||
else if (a->buffer->type == BUFFER_GLOBAL)
|
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");
|
command_name, "no server name given and this buffer is global");
|
||||||
else
|
else
|
||||||
s = a->buffer->server;
|
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;
|
struct config_schema *schema = item->schema;
|
||||||
if (!schema)
|
if (!schema)
|
||||||
{
|
{
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL, "%s: %s", "Option not recognized", name);
|
||||||
"%s: %s", "Option not recognized", name);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
buffer_send_status (ctx, NULL, "%s", "");
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL,
|
||||||
"Option \"%s\":", name);
|
"Option \"%s\":", name);
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL,
|
||||||
" Description: %s", schema->comment);
|
" Description: %s", schema->comment);
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL,
|
||||||
" Type: %s", config_item_type_name (schema->type));
|
" 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");
|
" Default: %s", schema->default_ ? schema->default_ : "null");
|
||||||
|
|
||||||
struct str tmp;
|
struct str tmp;
|
||||||
str_init (&tmp);
|
str_init (&tmp);
|
||||||
config_item_write (item, false, &tmp);
|
config_item_write (item, false, &tmp);
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
buffer_send_status (ctx, NULL,
|
||||||
" Current value: %s", tmp.str);
|
" Current value: %s", tmp.str);
|
||||||
str_free (&tmp);
|
str_free (&tmp);
|
||||||
return true;
|
return true;
|
||||||
|
@ -6857,8 +6852,8 @@ handle_command_help (struct app_context *ctx, struct handler_args *a)
|
||||||
{
|
{
|
||||||
if (!*a->arguments)
|
if (!*a->arguments)
|
||||||
{
|
{
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
buffer_send_status (ctx, NULL, "%s", "");
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "Commands:");
|
buffer_send_status (ctx, NULL, "Commands:");
|
||||||
|
|
||||||
int longest = 0;
|
int longest = 0;
|
||||||
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
|
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++)
|
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
|
||||||
{
|
{
|
||||||
struct command_handler *handler = &g_command_handlers[i];
|
struct command_handler *handler = &g_command_handlers[i];
|
||||||
buffer_send_status (ctx, ctx->global_buffer, " %-*s %s",
|
buffer_send_status (ctx, NULL,
|
||||||
longest, handler->name, handler->description);
|
" %-*s %s", longest, handler->name, handler->description);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6882,16 +6877,16 @@ handle_command_help (struct app_context *ctx, struct handler_args *a)
|
||||||
if (strcasecmp_ascii (command, handler->name))
|
if (strcasecmp_ascii (command, handler->name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
buffer_send_status (ctx, NULL, "%s", "");
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s: %s",
|
buffer_send_status (ctx, NULL, "%s: %s",
|
||||||
handler->name, handler->description);
|
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)");
|
handler->usage ? handler->usage : "(none)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!try_handle_command_help_option (ctx, command))
|
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);
|
"%s: %s", "No such command or option", command);
|
||||||
return true;
|
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);
|
struct command_handler *handler = str_map_find (&partial, command_name);
|
||||||
if (!handler)
|
if (!handler)
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
buffer_send_error (ctx, NULL,
|
||||||
"%s: %s", "No such command", command_name);
|
"%s: %s", "No such command", command_name);
|
||||||
else if ((handler->flags & HANDLER_SERVER)
|
else if ((handler->flags & HANDLER_SERVER)
|
||||||
&& args.buffer->type == BUFFER_GLOBAL)
|
&& 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");
|
"/%s: %s", command_name, "can't do this from a global buffer");
|
||||||
else if ((handler->flags & HANDLER_SERVER)
|
else if ((handler->flags & HANDLER_SERVER)
|
||||||
&& !irc_is_connected ((args.s = args.buffer->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,
|
buffer_send_error (ctx, args.buffer, "/%s: %s", command_name,
|
||||||
"no channel name given and this buffer is not a channel");
|
"no channel name given and this buffer is not a channel");
|
||||||
else if (!handler->handler (ctx, &args))
|
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);
|
"%s: /%s %s", "Usage", handler->name, handler->usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue