/* $OpenBSD$ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/ioctl.h>
#include <event.h>
#include <fcntl.h>
#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "tmux.h"
void server_client_check_focus(struct window_pane *);
void server_client_check_resize(struct window_pane *);
void server_client_check_mouse(struct client *, struct window_pane *);
void server_client_repeat_timer(int, short, void *);
void server_client_check_exit(struct client *);
void server_client_check_redraw(struct client *);
void server_client_set_title(struct client *);
void server_client_reset_state(struct client *);
int server_client_assume_paste(struct session *);
int server_client_msg_dispatch(struct client *);
void server_client_msg_command(struct client *, struct msg_command_data *);
void server_client_msg_identify(
struct client *, struct msg_identify_data *, int);
void server_client_msg_shell(struct client *);
/* Create a new client. */
void
server_client_create(int fd)
{
struct client *c;
u_int i;
setblocking(fd, 0);
c = xcalloc(1, sizeof *c);
c->references = 0;
imsg_init(&c->ibuf, fd);
server_update_event(c);
if (gettimeofday(&c->creation_time, NULL) != 0)
fatal("gettimeofday failed");
memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
c->cmdq = cmdq_new(c);
c->cmdq->client_exit = 1;
c->stdin_data = evbuffer_new ();
c->stdout_data = evbuffer_new ();
c->stderr_data = evbuffer_new ();
c->tty.fd = -1;
c->title = NULL;
c->session = NULL;
c->last_session = NULL;
c->tty.sx = 80;
c->tty.sy = 24;
screen_init(&c->status, c->tty.sx, 1, 0);
RB_INIT(&c->status_new);
RB_INIT(&c->status_old);
c->message_string = NULL;
ARRAY_INIT(&c->message_log);
c->prompt_string = NULL;
c->prompt_buffer = NULL;
c->prompt_index = 0;
c->tty.mouse.xb = c->tty.mouse.button = 3;
c->tty.mouse.x = c->tty.mouse.y = -1;
c->tty.mouse.lx = c->tty.mouse.ly = -1;
c->tty.mouse.sx = c->tty.mouse.sy = -1;
c->tty.mouse.event = MOUSE_EVENT_UP;
c->tty.mouse.flags = 0;
c->flags |= CLIENT_FOCUSED;
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
if (ARRAY_ITEM(&clients, i) == NULL) {
ARRAY_SET(&clients, i, c);
return;
}
}
ARRAY_ADD(&clients, c);
log_debug("new client %d", fd);
}
/* Open client terminal if needed. */
int
server_client_open(struct client *c, struct session *s, char **cause)
{
struct options *oo = s != NULL ? &s->options : &global_s_options;
char *overrides;
if (c->flags & CLIENT_CONTROL)
return (0);
if (!(c->flags & CLIENT_TERMINAL))