4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.11 2008/02/23 11:48:51 james
14 * *** empty log message ***
16 * Revision 1.10 2008/02/22 17:06:59 james
17 * *** empty log message ***
19 * Revision 1.9 2008/02/20 18:49:11 staffcvs
20 * *** empty log message ***
22 * Revision 1.8 2008/02/20 18:31:44 james
23 * *** empty log message ***
25 * Revision 1.7 2008/02/15 23:52:12 james
26 * *** empty log message ***
28 * Revision 1.6 2008/02/15 03:32:07 james
29 * *** empty log message ***
31 * Revision 1.5 2008/02/14 10:34:47 james
32 * *** empty log message ***
34 * Revision 1.4 2008/02/14 10:34:30 james
35 * *** empty log message ***
37 * Revision 1.3 2008/02/14 02:46:44 james
38 * *** empty log message ***
40 * Revision 1.2 2008/02/14 00:57:58 james
41 * *** empty log message ***
43 * Revision 1.1 2008/02/13 18:05:06 james
44 * *** empty log message ***
57 client_msg (IPC_Msg * m, Context * c)
62 case IPC_MSG_TYPE_NOOP:
64 case IPC_MSG_TYPE_DEBUG:
65 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
67 case IPC_MSG_TYPE_KEY:
68 vt102_send (c, m->key.key);
70 case IPC_MSG_TYPE_SETBAUD:
71 tty_set_baud (c->t, m->setbaud.baud);
74 log_f (c->l, "<baud changed to %d>", m->setbaud.baud);
76 case IPC_MSG_TYPE_SENDBREAK:
77 tty_send_break (c->t);
79 case IPC_MSG_TYPE_SETFLOW:
80 tty_set_flow (c->t, m->setflow.flow);
82 case IPC_MSG_TYPE_SETANSI:
83 vt102_set_ansi (c->v, m->setansi.ansi);
85 case IPC_MSG_TYPE_HANGUP:
89 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
94 client_free (Client * c)
101 fprintf (stderr, "Client at %p freed\n", c);
106 clients_new_client (Clients * cs, Socket * s, Context * ctx)
110 c = (Client *) malloc (sizeof (Client));
120 fprintf (stderr, "Client at %p created\n", c);
124 if (ipc_msg_send_debug (s, "new_client"))
131 clients_reap (Clients * cs)
136 for (p = &cs->head; *p;)
156 Clients *ret = (Clients *) malloc (sizeof (Clients));
165 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
169 for (c = cs->head; c; c = c->next)
171 socket_pre_select (c->s, rfds, wfds);
176 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
182 for (c = cs->head; c; c = c->next)
184 if (socket_post_select (c->s, rfds, wfds))
192 client_msg (c->s->msg, ctx);
193 socket_consume_msg (c->s);
204 clients_shutdown (Clients * cs)
208 for (c = cs->head; c; c = c->next)
223 send_status (Clients * cs, char *msg)
225 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
226 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
233 len = strlen (msg) + 1;
237 if (len > IPC_MAX_BUF)
240 m->size = len + sizeof (IPC_Msg_status);
241 m->type = IPC_MSG_TYPE_STATUS;
242 strncpy (m->status, msg, IPC_MAX_BUF);
243 m->status[IPC_MAX_BUF - 1] = 0;
245 for (c = cs->head; c; c = c->next)
248 if (ipc_msg_send (c->s, (IPC_Msg *) m))
257 send_output (Clients * cs, void *buf, int len)
259 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
260 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
266 if (len > IPC_MAX_BUF)
269 m->size = len + sizeof (IPC_Msg_term);
270 m->type = IPC_MSG_TYPE_TERM;
272 memcpy (m->term, buf, len);
274 for (c = cs->head; c; c = c->next)
277 if (ipc_msg_send (c->s, (IPC_Msg *) m))
286 send_history (History * h, Client * c)
290 HISTORY_INC (h, rptr);
292 HISTORY_INC (h, rptr);
293 while (rptr != h->wptr)
295 History_ent *l = &h->lines[rptr];
299 if (ipc_msg_send_history (c->s, l))
303 HISTORY_INC (h, rptr);
308 send_vt102 (VT102 * v, Client * c)
310 if (ipc_msg_send_vt102 (c->s, v))