summaryrefslogtreecommitdiff
path: root/src/scream.h
blob: 223bab41e174067e2c0275cf92e94434433be066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/****************************************************************************
 * scream::scream.h
 * routines to connect to screen and or scream daemons.
 * BSD Licence applies.
 * 2002/04/19  Azundris  incept
 ***************************************************************************/



#define NS_DK              0
#define NS_SSH             1
#define NS_LCL             2
#define NS_SU              3

#define NS_MODE_NEGOTIATE -1
#define NS_MODE_NONE       0
#define NS_MODE_SCREEN     1
#define NS_MODE_SCREAM     2

#define NS_SUCC          (-1)
#define NS_FAIL            0
#define NS_OOM             1
#define NS_MALFORMED_URL   2
#define NS_UNKNOWN_USER    3
#define NS_INVALID_SESS    4
#define NS_UNKNOWN_PROTO   5
#define NS_CANT_RESOLVE    6
#define NS_CANT_CONNECT    7
#define NS_CANT_LOGIN      8
#define NS_CANT_ATTACH     9
#define NS_UNKNOWN_LOC    10
#define NS_SCREEN_STATUS  11
#define NS_SCREEN_ST_CLR  12
#define NS_EFUN_NOT_SET   13
#define NS_USER_CXL       14

#define NS_ERR_WEIRDSCREEN 1

#define NS_SCREAM_CURR     1
#define NS_SCREAM_PRVS     2
#define NS_SCREAM_UTMP     4
#define NS_SCREAM_BELL     8
#define NS_SCREAM_ACT     16
#define NS_SCREAM_FILE    32
#define NS_SCREAM_SHARED  64
#define NS_SCREAM_ZOMBIE 128

#define NS_SCREAM_MASK   (~(NS_SCREAM_UTMP|NS_SCREAM_PRVS))

#define NS_HOP_DOWN        0
#define NS_HOP_UP          1



/***************************************************************************/



typedef struct __ns_hop {
  int               localport;
  char             *fw;
  int               fwport;
  int               established;
  int               delay;
  int               refcount;
  struct __ns_sess *sess;    /* first only, others have same host/port */
  struct __ns_hop  *next;
} _ns_hop;



typedef struct __ns_sess {   /* a whole screen-session with many clients */
  int     where;             /* local/remote */
  int     backend;           /* screen/scream */
  int     nesting;           /* 0=topLevel, 1=screen within a screen etc */
  time_t  timestamp;         /* last updated when? see NS_SCREEN_UPD_FREQ */
  char   *proto;             /* protocol.  usually "screen" */
  char   *host;              /* host. numeric or symbolic. ("localhost") */
  int     port;              /* port. usually TCP22: SSH */
  char   *user;              /* user. often current local user */
  char   *pass;              /* password. used for su. for remote sessions, a
                                ssh-key should be on the remote machine. */
  char   *rsrc;              /* add'l parameter to screen/scream. URL-enc */
  char   *home;              /* user's home dir. so we can find .screenrc */
  void   *userdef;           /* the term-app can store a pointer here */
  int     fd;                /* fd for communication */
  char    escape,literal;    /* talking to screen: defaults to ^A, a */
  int     dsbb;              /* default length of scroll-back buffer */
  struct __ns_efuns *efuns;  /* callbacks into the terminal program. */
  struct __ns_hop   *hop;    /* tunnel, if any */
  struct __ns_disp  *dsps;   /* first display (that with the lowest index) */
  struct __ns_disp  *curr;   /* current display (NULL for none) */
  struct __ns_sess  *prvs;   /* previous session in session list */
  struct __ns_sess  *next;   /* next     session in session list */
} _ns_sess;



typedef struct __ns_disp {  /* describing the window of a single client */
  int   index;          /* index 0..n */
  char *name;           /* arbitrary \0-terminated string. humans only. */
  int   sbb;            /* scroll-back buffer. 0 if parent to more screens */
  int   x;              /* rsvd */
  int   y;              /* rsvd */
  int   w;              /* rsvd */
  int   h;              /* rsvd */
  int   flags;          /* current, activity, logging, ... */
  struct __ns_sess  *sess;   /* is child of... (always) */
  struct __ns_sess  *child;  /* if parent of... (rarely) */
  struct __ns_efuns *efuns;  /* NULL to use its parent's efuns */
  struct __ns_disp  *prvs;   /* left neighbour (<index) of this session */
  struct __ns_disp  *next;   /* right neighbour (>index) of this session */
} _ns_disp;



typedef struct __ns_efuns {  /* callbacks into the terminal program */
  int   refcount;            /* use calls below to set this up */
  int   (*set_scroll_x)(void *,int);
  int   (*set_scroll_y)(void *,int);
  int   (*set_scroll_w)(void *,int);
  int   (*set_scroll_h)(void *,int);
  int   (*redraw)(void *);
  int   (*redraw_xywh)(void *,int,int,int,int);
  int   (*ins_disp)(void *,int,char *);
  int   (*del_disp)(void *,int);
  int   (*upd_disp)(void *,int,int,char *);
  int   (*err_msg)(void *,int,char *);
  int   (*execute)(void *,char **);
  int   (*inp_text)(void *,int,char *);
  int   (*inp_dial)(void *,char *,int,char **,int (*)(void *,char *,size_t,size_t));
  int   (*inp_tab)(void *,char *[],int,char *,size_t,size_t);
} _ns_efuns;



typedef struct __ns_parse {
  int   screen;
  int   real;
  int   flags;
  char *name;
} _ns_parse;



/***************************************************************************/



/* constructors/destructors */
_ns_efuns *ns_new_efuns(void);
_ns_efuns *ns_dst_efuns(_ns_efuns **);
_ns_efuns *ns_get_efuns(_ns_sess *,_ns_disp *);

/* debug */
void ns_desc_hop(_ns_hop *,char *);
void ns_desc_sess(_ns_sess *,char *);

/* convenience */
_ns_disp *disp_fetch_or_make(_ns_sess *,int);

/* transparent attach/detach */
_ns_sess *ns_attach_by_sess(_ns_sess **,int *);
_ns_sess *ns_attach_by_URL(char *,char *,_ns_efuns **,int *,void *);


/* send command to screen */
int ns_screen_command(_ns_sess *, char *);

/* send statement to screen */
int ns_screen_xcommand(_ns_sess *,char , char *);

/* parse and forward a screen-statement */
int ns_parse_screen_cmd(_ns_sess *,char *);

/* parse and forward a screen-hotkey */
int ns_parse_screen_key(_ns_sess *,char);

/* parse screen escape setup */
char ns_parse_esc(char **);

/* init session (read .screenrc, or whatnot) */
int ns_sess_init(_ns_sess *);

/* what the terminal should call the last line -- screen's "hardstatus"
   changes. submit session, terminal-width, and a pointer to said line. */
int ns_parse_screen(_ns_sess *,int,int,char *);



/* things the term might ask screen/scream to do ***************************/
int ns_scroll2x(_ns_sess *,int);
int ns_scroll2y(_ns_sess *,int);
int ns_go2_disp(_ns_sess *,int);
int ns_add_disp(_ns_sess *,int,char *);
int ns_rsz_disp(_ns_sess *,int,int,int);
int ns_rem_disp(_ns_sess *,int);
int ns_ren_disp(_ns_sess *,int,char *);
int ns_log_disp(_ns_sess *,int,char *);
int ns_upd_stat(_ns_sess *);
int ns_inp_dial(_ns_sess *,char *,int,char **,int (*)(void *,char *,size_t,size_t));



/* register efuns (callbacks) **********************************************/
void ns_register_ssx(_ns_efuns *,int (*set_scroll_x)(void *,int));
void ns_register_ssy(_ns_efuns *,int (*set_scroll_y)(void *,int));
void ns_register_ssw(_ns_efuns *,int (*set_scroll_w)(void *,int));
void ns_register_ssh(_ns_efuns *,int (*set_scroll_h)(void *,int));

void ns_register_red(_ns_efuns *,int (*redraw)(void *));
void ns_register_rda(_ns_efuns *,int (*redraw_xywh)(void *,int,int,int,int));

void ns_register_ins(_ns_efuns *,int (*ins_disp)(void *,int,char *));
void ns_register_del(_ns_efuns *,int (*del_disp)(void *,int));
void ns_register_upd(_ns_efuns *,int (*upd_disp)(void *,int,int,char *));

void ns_register_err(_ns_efuns *,int (*err_msg)(void *,int,char *));

void ns_register_exe(_ns_efuns *,int (*execute)(void *,char **));
void ns_register_txt(_ns_efuns *,int (*inp_text)(void *,int,char *));

void ns_register_inp(_ns_efuns *,int (*)(void *,char *,int,char **,int (*)(void *,char *,size_t,size_t)));
void ns_register_tab(_ns_efuns *,int (*)(void *,char *[],int,char *,size_t,size_t));



/***************************************************************************/