4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.14 2008/02/28 16:57:51 james
14 * *** empty log message ***
16 * Revision 1.13 2008/02/28 16:37:16 james
17 * *** empty log message ***
19 * Revision 1.12 2008/02/28 12:12:24 james
20 * *** empty log message ***
22 * Revision 1.11 2008/02/23 11:48:51 james
23 * *** empty log message ***
25 * Revision 1.10 2008/02/22 17:06:59 james
26 * *** empty log message ***
28 * Revision 1.9 2008/02/20 18:49:11 staffcvs
29 * *** empty log message ***
31 * Revision 1.8 2008/02/20 18:31:44 james
32 * *** empty log message ***
34 * Revision 1.7 2008/02/15 23:52:12 james
35 * *** empty log message ***
37 * Revision 1.6 2008/02/15 03:32:07 james
38 * *** empty log message ***
40 * Revision 1.5 2008/02/14 10:34:47 james
41 * *** empty log message ***
43 * Revision 1.4 2008/02/14 10:34:30 james
44 * *** empty log message ***
46 * Revision 1.3 2008/02/14 02:46:44 james
47 * *** empty log message ***
49 * Revision 1.2 2008/02/14 00:57:58 james
50 * *** empty log message ***
52 * Revision 1.1 2008/02/13 18:05:06 james
53 * *** empty log message ***
66 client_msg (IPC_Msg * m, Context * c)
71 case IPC_MSG_TYPE_NOOP:
73 case IPC_MSG_TYPE_DEBUG:
74 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
76 case IPC_MSG_TYPE_KEY:
77 vt102_send (c, m->key.key);
79 case IPC_MSG_TYPE_SETBAUD:
80 tty_set_baud (c->t, m->setbaud.baud);
83 log_f (c->l, "<baud changed to %d>", m->setbaud.baud);
85 case IPC_MSG_TYPE_SENDBREAK:
86 tty_send_break (c->t);
88 case IPC_MSG_TYPE_SETFLOW:
89 tty_set_flow (c->t, m->setflow.flow);
91 case IPC_MSG_TYPE_SETANSI:
92 vt102_set_ansi (c->v, m->setansi.ansi);
94 case IPC_MSG_TYPE_HANGUP:
97 case IPC_MSG_TYPE_SETSIZE:
98 vt102_resize (c, m->setsize.winsize);
100 case IPC_MSG_TYPE_RESET:
104 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
109 client_free (Client * c)
116 fprintf (stderr, "Client at %p freed\n", c);
121 clients_new_client (Clients * cs, Socket * s, Context * ctx)
125 c = (Client *) malloc (sizeof (Client));
135 fprintf (stderr, "Client at %p created\n", c);
139 if (ipc_msg_send_debug (s, "new_client"))
146 clients_reap (Clients * cs)
151 for (p = &cs->head; *p;)
171 Clients *ret = (Clients *) malloc (sizeof (Clients));
180 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
184 for (c = cs->head; c; c = c->next)
186 socket_pre_select (c->s, rfds, wfds);
191 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
197 for (c = cs->head; c; c = c->next)
199 if (socket_post_select (c->s, rfds, wfds))
207 client_msg (c->s->msg, ctx);
208 socket_consume_msg (c->s);
219 clients_shutdown (Clients * cs)
223 for (c = cs->head; c; c = c->next)
238 send_status (Clients * cs, char *msg)
240 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
241 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
248 len = strlen (msg) + 1;
252 if (len > IPC_MAX_BUF)
255 m->size = len + sizeof (IPC_Msg_status);
256 m->type = IPC_MSG_TYPE_STATUS;
257 strncpy (m->status, msg, IPC_MAX_BUF);
258 m->status[IPC_MAX_BUF - 1] = 0;
260 for (c = cs->head; c; c = c->next)
263 if (ipc_msg_send (c->s, (IPC_Msg *) m))
272 send_output (Clients * cs, void *buf, int len)
274 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
275 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
281 if (len > IPC_MAX_BUF)
284 m->size = len + sizeof (IPC_Msg_term);
285 m->type = IPC_MSG_TYPE_TERM;
287 memcpy (m->term, buf, len);
289 for (c = cs->head; c; c = c->next)
292 if (ipc_msg_send (c->s, (IPC_Msg *) m))
301 send_history (History * h, Client * c)
305 HISTORY_INC (h, rptr);
307 HISTORY_INC (h, rptr);
308 while (rptr != h->wptr)
310 History_ent *l = &h->lines[rptr];
314 if (ipc_msg_send_history (c->s, l))
318 HISTORY_INC (h, rptr);
323 send_vt102 (VT102 * v, Client * c)
325 if (ipc_msg_send_vt102 (c->s, v))