X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=apps%2Fclients.c;h=9f97a676d59e0b105de56b8272ad873883ba70a4;hb=e398b84ba34f0290e21830e36ff40719e2ec7125;hp=c75c9841e69c4db5b46ef8f5dd137c7de32df88e;hpb=14a8a191f4ada9a2529659b02c58ebca31872dce;p=sympathy.git diff --git a/apps/clients.c b/apps/clients.c index c75c984..9f97a67 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -1,15 +1,54 @@ -/* +/* * clients.c: * - * Copyright (c) 2008 James McKenzie , + * Copyright (c) 2008 James McKenzie , * All rights reserved. * */ -static char rcsid[] = "$Id$"; +static char rcsid[] = "$Id: clients.c,v 1.25 2008/05/09 12:35:57 james Exp $"; -/* - * $Log$ +/* + * $Log: clients.c,v $ + * Revision 1.25 2008/05/09 12:35:57 james + * *** empty log message *** + * + * Revision 1.24 2008/03/11 17:56:04 james + * *** empty log message *** + * + * Revision 1.23 2008/03/11 17:47:24 james + * *** empty log message *** + * + * Revision 1.22 2008/03/07 14:16:44 james + * *** empty log message *** + * + * Revision 1.21 2008/03/07 14:13:40 james + * *** empty log message *** + * + * Revision 1.20 2008/03/07 13:56:39 james + * *** empty log message *** + * + * Revision 1.19 2008/03/07 13:16:02 james + * *** empty log message *** + * + * Revision 1.18 2008/03/03 18:16:16 james + * *** empty log message *** + * + * Revision 1.17 2008/03/03 18:15:19 james + * *** empty log message *** + * + * Revision 1.16 2008/03/03 06:04:42 james + * *** empty log message *** + * + * Revision 1.15 2008/03/02 10:27:24 james + * *** empty log message *** + * + * Revision 1.14 2008/02/28 16:57:51 james + * *** empty log message *** + * + * Revision 1.13 2008/02/28 16:37:16 james + * *** empty log message *** + * * Revision 1.12 2008/02/28 12:12:24 james * *** empty log message *** * @@ -56,16 +95,24 @@ static char rcsid[] = "$Id$"; #include #include "clients.h" -static void -client_msg (IPC_Msg * m, Context * c) + +void +client_initialize (Client * c, Context * ctx) +{ + send_history (ctx->h, c); + send_vt102 (ctx->v, c); + c->initialized = 1; +} + +void +client_execute_message (Client * client, IPC_Msg * m, Context * c) { switch (m->hdr.type) { - case IPC_MSG_TYPE_NOOP: break; case IPC_MSG_TYPE_DEBUG: - fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg); + log_f (c->l, "", m->debug.msg); break; case IPC_MSG_TYPE_KEY: vt102_send (c, m->key.key); @@ -73,32 +120,43 @@ client_msg (IPC_Msg * m, Context * c) case IPC_MSG_TYPE_SETBAUD: tty_set_baud (c->t, m->setbaud.baud); tty_parse_reset (c); - log_f (c->l, "", m->setbaud.baud); break; case IPC_MSG_TYPE_SENDBREAK: + log_f (c->l, ""); tty_send_break (c->t); break; case IPC_MSG_TYPE_SETFLOW: + log_f (c->l, "", + m->setflow.flow ? "on" : "off"); tty_set_flow (c->t, m->setflow.flow); break; case IPC_MSG_TYPE_SETANSI: vt102_set_ansi (c->v, m->setansi.ansi); break; case IPC_MSG_TYPE_HANGUP: + log_f (c->l, ""); tty_hangup (c->t); break; case IPC_MSG_TYPE_SETSIZE: - vt102_resize(c,m->setsize.winsize); + vt102_resize (c, m->setsize.winsize); break; case IPC_MSG_TYPE_RESET: - vt102_reset(c); + vt102_reset (c); break; + case IPC_MSG_TYPE_INITIALIZE: + client_initialize (client, c); + break; + case IPC_MSG_TYPE_KILLME: + client->dead++; + break; + default: - fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + log_f (c->l, "", m->hdr.type); } } + void client_free (Client * c) { @@ -116,8 +174,9 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) { Client *c; - c = (Client *) malloc (sizeof (Client)); + c = (Client *) xmalloc (sizeof (Client)); + c->initialized = 0; c->dead = 0; c->s = s; c->next = cs->head; @@ -129,6 +188,7 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) fprintf (stderr, "Client at %p created\n", c); #endif + log_f (ctx->l, "", c, cs->n); if (ipc_msg_send_debug (s, "new_client")) c->dead++; @@ -137,7 +197,7 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) } void -clients_reap (Clients * cs) +clients_reap (Clients * cs, Context * ctx) { Client **p, *c; @@ -151,6 +211,8 @@ clients_reap (Clients * cs) *p = c->next; client_free (c); cs->n--; + log_f (ctx->l, "", c, + cs->n); } else { @@ -162,7 +224,7 @@ clients_reap (Clients * cs) Clients * clients_new (void) { - Clients *ret = (Clients *) malloc (sizeof (Clients)); + Clients *ret = (Clients *) xmalloc (sizeof (Clients)); ret->n = 0; ret->head = NULL; @@ -198,19 +260,21 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, if (c->s->msg) { - client_msg (c->s->msg, ctx); + client_execute_message (c, c->s->msg, ctx); socket_consume_msg (c->s); + if (c->dead) + deaded++; } } if (deaded) - clients_reap (cs); + clients_reap (cs, ctx); } void -clients_shutdown (Clients * cs) +clients_shutdown (Clients * cs, Context * ctx) { Client *c; @@ -220,7 +284,7 @@ clients_shutdown (Clients * cs) } - clients_reap (cs); + clients_reap (cs, ctx); } @@ -253,7 +317,7 @@ send_status (Clients * cs, char *msg) for (c = cs->head; c; c = c->next) { - if (!c->dead) + if (!c->dead && c->initialized) if (ipc_msg_send (c->s, (IPC_Msg *) m)) c->dead++; } @@ -282,7 +346,7 @@ send_output (Clients * cs, void *buf, int len) for (c = cs->head; c; c = c->next) { - if (!c->dead) + if (!c->dead && c->initialized) if (ipc_msg_send (c->s, (IPC_Msg *) m)) c->dead++; }