4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.8 2008/02/20 18:31:44 james
14 * *** empty log message ***
16 * Revision 1.7 2008/02/15 23:52:12 james
17 * *** empty log message ***
19 * Revision 1.6 2008/02/15 03:32:07 james
20 * *** empty log message ***
22 * Revision 1.5 2008/02/14 10:34:47 james
23 * *** empty log message ***
25 * Revision 1.4 2008/02/14 10:34:30 james
26 * *** empty log message ***
28 * Revision 1.3 2008/02/14 02:46:44 james
29 * *** empty log message ***
31 * Revision 1.2 2008/02/14 00:57:58 james
32 * *** empty log message ***
34 * Revision 1.1 2008/02/13 18:05:06 james
35 * *** empty log message ***
43 client_msg (IPC_Msg * m, Context * c)
48 case IPC_MSG_TYPE_NOOP:
50 case IPC_MSG_TYPE_DEBUG:
51 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
53 case IPC_MSG_TYPE_KEY:
54 vt102_send (c, m->key.key);
56 case IPC_MSG_TYPE_SETBAUD:
57 tty_set_baud (c->t, m->setbaud.baud);
59 case IPC_MSG_TYPE_SENDBREAK:
60 tty_send_break (c->t);
62 case IPC_MSG_TYPE_SETFLOW:
63 tty_set_flow (c->t, m->setflow.flow);
65 case IPC_MSG_TYPE_HANGUP:
69 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
74 client_free (Client * c)
81 fprintf (stderr, "Client at %p freed\n", c);
86 clients_new_client (Clients * cs, Socket * s, Context * ctx)
90 c = (Client *) malloc (sizeof (Client));
100 fprintf (stderr, "Client at %p created\n", c);
104 if (ipc_msg_send_debug (s, "new_client"))
111 clients_reap (Clients * cs)
116 for (p = &cs->head; *p;)
136 Clients *ret = (Clients *) malloc (sizeof (Clients));
145 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
149 for (c = cs->head; c; c = c->next)
151 socket_pre_select (c->s, rfds, wfds);
156 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
162 for (c = cs->head; c; c = c->next)
164 if (socket_post_select (c->s, rfds, wfds))
172 client_msg (c->s->msg, ctx);
173 socket_consume_msg (c->s);
184 clients_shutdown (Clients * cs)
188 for (c = cs->head; c; c = c->next)
203 send_status (Clients * cs, char *msg)
205 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
206 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
213 len = strlen (msg) + 1;
217 if (len > IPC_MAX_BUF)
220 m->size = len + sizeof (IPC_Msg_status);
221 m->type = IPC_MSG_TYPE_STATUS;
222 strncpy (m->status, msg, IPC_MAX_BUF);
223 m->status[IPC_MAX_BUF - 1] = 0;
225 for (c = cs->head; c; c = c->next)
228 if (ipc_msg_send (c->s, (IPC_Msg *) m))
237 send_output (Clients * cs, void *buf, int len)
239 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
240 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
246 if (len > IPC_MAX_BUF)
249 m->size = len + sizeof (IPC_Msg_term);
250 m->type = IPC_MSG_TYPE_TERM;
252 memcpy (m->term, buf, len);
254 for (c = cs->head; c; c = c->next)
257 if (ipc_msg_send (c->s, (IPC_Msg *) m))
266 send_history (History * h, Client * c)
270 HISTORY_INC (h, rptr);
272 HISTORY_INC (h, rptr);
273 while (rptr != h->wptr)
275 History_ent *l = &h->lines[rptr];
279 if (ipc_msg_send_history (c->s, l))
283 HISTORY_INC (h, rptr);
288 send_vt102 (VT102 * v, Client * c)
290 if (ipc_msg_send_vt102 (c->s, v))