degesch: buffer creation cleanup
This commit is contained in:
parent
3dc6ee9a5b
commit
8f5dec0456
41
degesch.c
41
degesch.c
@ -1591,12 +1591,14 @@ static struct ispect_field g_buffer_ispect[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct buffer *
|
static struct buffer *
|
||||||
buffer_new (struct input *input)
|
buffer_new (struct input *input, enum buffer_type type, char *name)
|
||||||
{
|
{
|
||||||
struct buffer *self = xcalloc (1, sizeof *self);
|
struct buffer *self = xcalloc (1, sizeof *self);
|
||||||
self->ref_count = 1;
|
self->ref_count = 1;
|
||||||
self->input = input;
|
self->input = input;
|
||||||
self->input_data = CALL (input, buffer_new);
|
self->input_data = CALL (input, buffer_new);
|
||||||
|
self->type = type;
|
||||||
|
self->name = name;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4446,9 +4448,8 @@ buffer_remove_safe (struct app_context *ctx, struct buffer *buffer)
|
|||||||
static void
|
static void
|
||||||
init_global_buffer (struct app_context *ctx)
|
init_global_buffer (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
struct buffer *global = ctx->global_buffer = buffer_new (ctx->input);
|
struct buffer *global = ctx->global_buffer =
|
||||||
global->type = BUFFER_GLOBAL;
|
buffer_new (ctx->input, BUFFER_GLOBAL, xstrdup (PROGRAM_NAME));
|
||||||
global->name = xstrdup (PROGRAM_NAME);
|
|
||||||
|
|
||||||
buffer_add (ctx, global);
|
buffer_add (ctx, global);
|
||||||
buffer_activate (ctx, global);
|
buffer_activate (ctx, global);
|
||||||
@ -4456,6 +4457,19 @@ init_global_buffer (struct app_context *ctx)
|
|||||||
|
|
||||||
// --- Users, channels ---------------------------------------------------------
|
// --- Users, channels ---------------------------------------------------------
|
||||||
|
|
||||||
|
static char *
|
||||||
|
irc_make_buffer_name (struct server *s, const char *target)
|
||||||
|
{
|
||||||
|
if (!target)
|
||||||
|
return xstrdup (s->name);
|
||||||
|
|
||||||
|
// XXX: this may be able to trigger the uniqueness assertion with non-UTF-8
|
||||||
|
char *target_utf8 = irc_to_utf8 (target);
|
||||||
|
char *result = xstrdup_printf ("%s.%s", s->name, target_utf8);
|
||||||
|
free (target_utf8);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
irc_user_on_destroy (void *object, void *user_data)
|
irc_user_on_destroy (void *object, void *user_data)
|
||||||
{
|
{
|
||||||
@ -4495,11 +4509,8 @@ irc_get_or_make_user_buffer (struct server *s, const char *nickname)
|
|||||||
struct user *user = irc_get_or_make_user (s, nickname);
|
struct user *user = irc_get_or_make_user (s, nickname);
|
||||||
|
|
||||||
// Open a new buffer for the user
|
// Open a new buffer for the user
|
||||||
buffer = buffer_new (s->ctx->input);
|
buffer = buffer_new (s->ctx->input,
|
||||||
buffer->type = BUFFER_PM;
|
BUFFER_PM, irc_make_buffer_name (s, nickname));
|
||||||
char *nickname_utf8 = irc_to_utf8 (nickname);
|
|
||||||
buffer->name = xstrdup_printf ("%s.%s", s->name, nickname_utf8);
|
|
||||||
free (nickname_utf8);
|
|
||||||
buffer->server = s;
|
buffer->server = s;
|
||||||
buffer->user = user;
|
buffer->user = user;
|
||||||
str_map_set (&s->irc_buffer_map, user->nickname, buffer);
|
str_map_set (&s->irc_buffer_map, user->nickname, buffer);
|
||||||
@ -6644,11 +6655,8 @@ irc_handle_join (struct server *s, const struct irc_message *msg)
|
|||||||
if (!irc_is_this_us (s, msg->prefix))
|
if (!irc_is_this_us (s, msg->prefix))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buffer = buffer_new (s->ctx->input);
|
buffer = buffer_new (s->ctx->input,
|
||||||
buffer->type = BUFFER_CHANNEL;
|
BUFFER_CHANNEL, irc_make_buffer_name (s, channel_name));
|
||||||
char *channel_name_utf8 = irc_to_utf8 (channel_name);
|
|
||||||
buffer->name = xstrdup_printf ("%s.%s", s->name, channel_name_utf8);
|
|
||||||
free (channel_name_utf8);
|
|
||||||
buffer->server = s;
|
buffer->server = s;
|
||||||
buffer->channel = channel =
|
buffer->channel = channel =
|
||||||
irc_make_channel (s, xstrdup (channel_name));
|
irc_make_channel (s, xstrdup (channel_name));
|
||||||
@ -8318,9 +8326,8 @@ server_add (struct app_context *ctx,
|
|||||||
s->config = subtree;
|
s->config = subtree;
|
||||||
|
|
||||||
// Add a buffer and activate it
|
// Add a buffer and activate it
|
||||||
struct buffer *buffer = s->buffer = buffer_new (ctx->input);
|
struct buffer *buffer = s->buffer = buffer_new (ctx->input,
|
||||||
buffer->type = BUFFER_SERVER;
|
BUFFER_SERVER, irc_make_buffer_name (s, NULL));
|
||||||
buffer->name = xstrdup (s->name);
|
|
||||||
buffer->server = s;
|
buffer->server = s;
|
||||||
|
|
||||||
buffer_add (ctx, buffer);
|
buffer_add (ctx, buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user