4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.6 2008/02/15 03:32:07 james
14 * *** empty log message ***
16 * Revision 1.5 2008/02/14 10:34:47 james
17 * *** empty log message ***
19 * Revision 1.4 2008/02/14 10:34:30 james
20 * *** empty log message ***
22 * Revision 1.3 2008/02/14 02:46:44 james
23 * *** empty log message ***
25 * Revision 1.2 2008/02/14 00:57:58 james
26 * *** empty log message ***
28 * Revision 1.1 2008/02/13 18:05:06 james
29 * *** empty log message ***
37 client_msg (IPC_Msg * m, Context * c)
42 case IPC_MSG_TYPE_NOOP:
44 case IPC_MSG_TYPE_DEBUG:
45 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
47 case IPC_MSG_TYPE_KEY:
48 vt102_send (c, m->key.key);
50 case IPC_MSG_TYPE_SETBAUD:
51 tty_set_baud (c->t, m->setbaud.baud);
53 case IPC_MSG_TYPE_SENDBREAK:
54 tty_send_break (c->t);
56 case IPC_MSG_TYPE_SETFLOW:
57 tty_set_flow (c->t, m->setflow.flow);
60 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
65 client_free (Client * c)
71 fprintf (stderr, "Client at %p freed\n", c);
75 clients_new_client (Clients * cs, Socket * s, Context * ctx)
79 c = (Client *) malloc (sizeof (Client));
88 fprintf (stderr, "Client at %p created\n", c);
91 if (ipc_msg_send_debug (s, "new_client"))
98 clients_reap (Clients * cs)
103 for (p = &cs->head; *p;)
123 Clients *ret = (Clients *) malloc (sizeof (Clients));
132 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
136 for (c = cs->head; c; c = c->next)
138 socket_pre_select (c->s, rfds, wfds);
143 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
149 for (c = cs->head; c; c = c->next)
151 if (socket_post_select (c->s, rfds, wfds))
159 client_msg (c->s->msg, ctx);
160 socket_consume_msg (c->s);
171 clients_shutdown (Clients * cs)
175 for (c = cs->head; c; c = c->next)
190 send_status (Clients * cs, char *msg)
192 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
193 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
200 len = strlen (msg) + 1;
204 if (len > IPC_MAX_BUF)
207 m->size = len + sizeof (IPC_Msg_status);
208 m->type = IPC_MSG_TYPE_STATUS;
209 strncpy (m->status, msg, IPC_MAX_BUF);
210 m->status[IPC_MAX_BUF - 1] = 0;
212 for (c = cs->head; c; c = c->next)
215 if (ipc_msg_send (c->s, (IPC_Msg *) m))
224 send_output (Clients * cs, void *buf, int len)
226 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
227 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
233 if (len > IPC_MAX_BUF)
236 m->size = len + sizeof (IPC_Msg_term);
237 m->type = IPC_MSG_TYPE_TERM;
239 memcpy (m->term, buf, len);
241 for (c = cs->head; c; c = c->next)
244 if (ipc_msg_send (c->s, (IPC_Msg *) m))
253 send_history (History * h, Client * c)
257 HISTORY_INC (h, rptr);
259 HISTORY_INC (h, rptr);
260 while (rptr != h->wptr)
262 History_ent *l = &h->lines[rptr];
266 if (ipc_msg_send_history (c->s, l))
270 HISTORY_INC (h, rptr);
275 send_vt102 (VT102 * v, Client * c)
277 if (ipc_msg_send_vt102 (c->s, v))