tmate/tmate.h

164 lines
4.0 KiB
C
Raw Normal View History

2013-06-02 05:16:06 +02:00
#ifndef TMATE_H
#define TMATE_H
#include <sys/types.h>
#include <msgpack.h>
#include <libssh/libssh.h>
2013-07-22 23:06:28 +02:00
#include <libssh/callbacks.h>
2013-06-02 05:16:06 +02:00
#include <event.h>
#include "tmux.h"
2015-12-23 11:41:41 +01:00
#define tmate_debug(...) log_debug("[tmate] D " __VA_ARGS__)
#define tmate_warn(...) log_debug("[tmate] W " __VA_ARGS__)
#define tmate_info(...) log_debug("[tmate] I " __VA_ARGS__)
#define tmate_fatal(...) fatal("[tmate]" __VA_ARGS__)
2013-06-02 05:16:06 +02:00
/* tmate-encoder.c */
#define TMATE_MAX_MESSAGE_SIZE (16*1024)
#define TMATE_PROTOCOL_VERSION 4
2013-06-02 05:16:06 +02:00
enum tmate_commands {
TMATE_HEADER,
2013-06-12 08:53:44 +02:00
TMATE_SYNC_LAYOUT,
2013-06-02 05:16:06 +02:00
TMATE_PTY_DATA,
TMATE_EXEC_CMD,
TMATE_FAILED_CMD,
2013-06-12 05:50:16 +02:00
TMATE_STATUS,
2013-06-13 04:38:41 +02:00
TMATE_SYNC_COPY_MODE,
TMATE_WRITE_COPY_MODE,
2013-06-02 05:16:06 +02:00
};
struct tmate_encoder {
msgpack_packer pk;
struct evbuffer *buffer;
struct event ev_readable;
};
extern void tmate_encoder_init(struct tmate_encoder *encoder);
extern void tmate_write_header(void);
2013-06-12 08:53:44 +02:00
extern void tmate_sync_layout(void);
2013-06-02 05:16:06 +02:00
extern void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len);
2013-06-12 04:45:33 +02:00
extern int tmate_should_replicate_cmd(const struct cmd_entry *cmd);
extern void tmate_exec_cmd(const char *cmd);
extern void tmate_failed_cmd(int client_id, const char *cause);
2013-06-12 05:50:16 +02:00
extern void tmate_status(const char *left, const char *right);
2013-06-13 04:38:41 +02:00
extern void tmate_sync_copy_mode(struct window_pane *wp);
extern void tmate_write_copy_mode(struct window_pane *wp, const char *str);
2013-06-02 05:16:06 +02:00
/* tmate-decoder.c */
2013-06-12 04:45:33 +02:00
enum tmate_client_commands {
2013-06-13 10:31:25 +02:00
TMATE_NOTIFY,
2013-06-12 04:07:04 +02:00
TMATE_CLIENT_PANE_KEY,
2013-06-02 05:16:06 +02:00
TMATE_CLIENT_RESIZE,
TMATE_CLIENT_EXEC_CMD,
TMATE_CLIENT_ENV,
TMATE_CLIENT_READY,
2013-06-02 05:16:06 +02:00
};
struct tmate_decoder {
struct msgpack_unpacker unpacker;
int ready;
2013-06-02 05:16:06 +02:00
};
extern int tmate_sx;
extern int tmate_sy;
extern void tmate_decoder_init(struct tmate_decoder *decoder);
extern void tmate_decoder_get_buffer(struct tmate_decoder *decoder,
char **buf, size_t *len);
extern void tmate_decoder_commit(struct tmate_decoder *decoder, size_t len);
/* tmate-ssh-client.c */
enum tmate_ssh_client_state_types {
SSH_NONE,
SSH_INIT,
SSH_CONNECT,
2013-06-12 07:28:01 +02:00
SSH_AUTH_SERVER,
SSH_AUTH_CLIENT,
2013-06-02 05:16:06 +02:00
SSH_OPEN_CHANNEL,
SSH_BOOTSTRAP,
SSH_READY,
};
struct tmate_ssh_client {
2013-07-22 23:06:28 +02:00
/* XXX The "session" word is used for three things:
* - the ssh session
* - the tmate sesssion
* - the tmux session
* A tmux session is associated 1:1 with a tmate session.
* An ssh session belongs to a tmate session, and a tmate session
* has one ssh session, except during bootstrapping where
* there is one ssh session per tmate server, and the first one wins.
*/
struct tmate_session *tmate_session;
TAILQ_ENTRY(tmate_ssh_client) node;
char *server_ip;
int has_encoder;
2013-06-02 05:16:06 +02:00
int state;
2013-07-22 23:06:28 +02:00
/*
* ssh_callbacks is allocated because the libssh API sucks (userdata
* has to be in the struct itself).
*/
struct ssh_callbacks_struct ssh_callbacks;
2013-07-23 01:45:34 +02:00
char *tried_passphrase;
2013-06-02 05:16:06 +02:00
ssh_session session;
ssh_channel channel;
struct event ev_ssh;
struct event ev_ssh_reconnect;
};
2013-07-22 23:06:28 +02:00
TAILQ_HEAD(tmate_ssh_clients, tmate_ssh_client);
extern struct tmate_ssh_client *tmate_ssh_client_alloc(struct tmate_session *session,
const char *server_ip);
2013-06-02 05:16:06 +02:00
2013-07-22 23:06:28 +02:00
/* tmate-session.c */
2013-06-02 05:16:06 +02:00
2013-07-22 23:06:28 +02:00
struct tmate_session {
2015-12-23 11:41:41 +01:00
struct event_base *ev_base;
struct evdns_base *ev_dnsbase;
struct event ev_dns_retry;
2013-07-22 23:06:28 +02:00
struct tmate_encoder encoder;
struct tmate_decoder decoder;
/*
* This list contains one connection per IP. The first connected
* client wins, and saved in *client. When we have a winner, the
* losers are disconnected and killed.
*/
struct tmate_ssh_clients clients;
2013-07-23 01:45:34 +02:00
int need_passphrase;
char *passphrase;
2013-07-22 23:06:28 +02:00
};
2013-06-02 05:16:06 +02:00
2013-07-22 23:06:28 +02:00
extern struct tmate_session tmate_session;
2015-12-23 11:41:41 +01:00
extern void tmate_session_init(struct event_base *base);
2013-07-22 23:06:28 +02:00
extern void tmate_session_start(void);
2013-06-02 05:16:06 +02:00
2013-06-12 23:57:53 +02:00
/* tmate-debug.c */
2013-07-22 23:06:28 +02:00
extern void tmate_print_trace(void);
extern void tmate_catch_sigsegv(void);
2013-06-12 23:57:53 +02:00
2013-06-13 01:40:30 +02:00
/* tmate-msg.c */
extern void __tmate_status_message(const char *fmt, va_list ap);
2015-12-23 11:41:41 +01:00
extern void printflike(1, 2) tmate_status_message(const char *fmt, ...);
2013-06-13 01:40:30 +02:00
/* tmate-env.c */
extern int tmate_has_received_env(void);
extern void tmate_set_env(const char *name, const char *value);
extern void tmate_format(struct format_tree *ft);
2013-06-02 05:16:06 +02:00
#endif