From bc6a29d06c22bdcada4cb18d8401e5d37f46fd36 Mon Sep 17 00:00:00 2001 From: james <> Date: Thu, 14 Feb 2008 02:46:45 +0000 Subject: *** empty log message *** --- apps/Makefile.am | 5 +++- apps/client.c | 64 +++++++++++++++++++++++++++++++++++------ apps/client.h | 5 +++- apps/clients.c | 74 ++++++++++++++++++++++++++++++++---------------- apps/clients.h | 29 +++++++++++-------- apps/sympathy.c | 8 ++++-- apps/sympathyd.c | 86 ++++++++++++++++++++++++++++++++++++-------------------- 7 files changed, 193 insertions(+), 78 deletions(-) (limited to 'apps') diff --git a/apps/Makefile.am b/apps/Makefile.am index f0f5881..b14601c 100644 --- a/apps/Makefile.am +++ b/apps/Makefile.am @@ -7,6 +7,9 @@ # $Id$ # # $Log$ +# Revision 1.5 2008/02/14 02:46:44 james +# *** empty log message *** +# # Revision 1.4 2008/02/14 00:57:58 james # *** empty log message *** # @@ -34,6 +37,6 @@ sympathy_LDADD = ../src/libsympathy.a -lutil sympathyd_SOURCES = sympathyd.c clients.c client.c sympathyd_LDADD = ../src/libsympathy.la -lutil -AM_CFLAGS=-g +AM_CFLAGS=-g -Werror diff --git a/apps/client.c b/apps/client.c index 54f4c33..90bcf60 100644 --- a/apps/client.c +++ b/apps/client.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.2 2008/02/14 00:57:58 james * *** empty log message *** * @@ -21,21 +24,44 @@ static char rcsid[] = "$Id$"; #include #include "client.h" -static void client_msg(s) +static void +server_msg (IPC_Msg * m, Context * c) { - printf ("%p [%d] %s\n", s->msg, s->msg->hdr.size , s->msg->debug.msg ); - - + 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 ); + break; + case IPC_MSG_TYPE_HISTORY: + history_add (c->h, m->history.history.line); + break; + case IPC_MSG_TYPE_VT102: + if (sizeof (VT102) != m->vt102.len) + abort (); + + *(c->v) = m->vt102.vt102; + break; + case IPC_MSG_TYPE_TERM: + vt102_parse (c, m->term.term, m->term.len); + break; + default: + fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + } } + void client (void) { Socket *s; fd_set rfds, wfds; - s = socket_connect ("socket"); + ANSI a = { 0 }; + Context c; + s = socket_connect ("socket"); if (!s) { @@ -43,25 +69,47 @@ client (void) return; } + c.t = NULL; + c.v = vt102_new (); + c.h = history_new (200); + c.l = NULL; + c.k = keydis_ipc_new (s); + + terminal_register_handlers (); + a.terminal = terminal_open (0, 1); + + ansi_reset (&a, NULL); + for (;;) { struct timeval tv = { 0, 100000 }; - FD_ZERO (&rfds); FD_ZERO (&wfds); socket_pre_select (s, &rfds, &wfds); + tty_pre_select (a.terminal, &rfds, &wfds); select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); - socket_post_select (s, &rfds, &wfds); + if (socket_post_select (s, &rfds, &wfds)) + break; while (s->msg) { - client_msg(s); + server_msg (s->msg, &c); socket_consume_msg (s); } + + if (ansi_dispatch (&a, &c)) + break; + + ansi_update (&a, &c); + } + ansi_terminal_reset (&a); + terminal_atexit (); + printf ("QUAT\n"); + } diff --git a/apps/client.h b/apps/client.h index 1f46781..d3b650d 100644 --- a/apps/client.h +++ b/apps/client.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.2 2008/02/14 00:57:58 james * *** empty log message *** * @@ -23,7 +26,7 @@ #ifndef __CLIENT_H__ #define __CLIENT_H__ -void client(void); +void client (void); #endif /* __CLIENT_H__ */ diff --git a/apps/clients.c b/apps/clients.c index 6c70e9d..b5bafcd 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.2 2008/02/14 00:57:58 james * *** empty log message *** * @@ -21,6 +24,24 @@ static char rcsid[] = "$Id$"; #include #include "clients.h" +static void +client_msg (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); + break; + case IPC_MSG_TYPE_KEY: + vt102_send (c, m->key.key); + break; + default: + fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + } +} void client_free (Client * c) @@ -29,7 +50,7 @@ client_free (Client * c) socket_free (c->s); free (c); - fprintf(stderr,"Client at %p freed\n",c); + fprintf (stderr, "Client at %p freed\n", c); } Client * @@ -46,11 +67,11 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) cs->head = c; cs->n++; - fprintf(stderr,"Client at %p created\n",c); + fprintf (stderr, "Client at %p created\n", c); - if (ipc_msg_send_debug (s, "new_client")) - c->dead++; + if (ipc_msg_send_debug (s, "new_client")) + c->dead++; return c; } @@ -69,7 +90,7 @@ clients_reap (Clients * cs) { *p = c->next; client_free (c); - cs->n--; + cs->n--; } else { @@ -114,41 +135,46 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, c->dead++; deaded++; } + + if (c->s->msg) + { + client_msg (c->s->msg, ctx); + socket_consume_msg (c->s); + } + } if (deaded) clients_reap (cs); } -void -clients_output (Clients * cs, void *_buf, int len) +int +clients_output (Clients * cs, void *buf, int len) { -uint8_t *buf=(uint8_t *) _buf; -Client *c; - -#define DEBUG_MSG_LEN 128 + char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)]; + IPC_Msg_term *m = (IPC_Msg_term *) mbuf; - char mbuf[sizeof (IPC_Msg_hdr) + DEBUG_MSG_LEN]; - IPC_Msg *m; -int i; - -if (!len) return; - - m = (IPC_Msg *) mbuf; - m->debug.type = IPC_MSG_TYPE_DEBUG; - i=sprintf(m->debug.msg,"buf[0]=%d len=%d",buf[0],len); - m->debug.size = sizeof (IPC_Msg_hdr) + i + 1; + Client *c; + if (!len) + return; + if (len > IPC_MAX_BUF) + len = IPC_MAX_BUF; + m->size = len + sizeof (IPC_Msg_term); + m->type = IPC_MSG_TYPE_TERM; + m->len = len; + memcpy (m->term, buf, len); for (c = cs->head; c; c = c->next) { - if (!c->dead) - if (ipc_msg_send(c->s,m)) - c->dead++; + if (!c->dead) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; } + return len; } void diff --git a/apps/clients.h b/apps/clients.h index da5fd01..c59a521 100644 --- a/apps/clients.h +++ b/apps/clients.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.2 2008/02/14 00:57:58 james * *** empty log message *** * @@ -23,23 +26,25 @@ #ifndef __CLIENTS_H__ #define __CLIENTS_H__ -typedef struct Client_struct { - struct Client_struct *next; - Socket *s; - int dead; +typedef struct Client_struct +{ + struct Client_struct *next; + Socket *s; + int dead; } Client; -typedef struct { - Client *head; - int n; +typedef struct +{ + Client *head; + int n; } Clients; -extern Clients *clients_new(void); +extern Clients *clients_new (void); extern void clients_pre_select (Clients *, fd_set *, fd_set *); -extern void clients_post_select(Clients *,Context *, fd_set *, fd_set *); -extern Client *clients_new_client(Clients *,Socket *,Context *); -extern void clients_shutdown(Clients *); -extern void clients_output (Clients *, void *, int); +extern void clients_post_select (Clients *, Context *, fd_set *, fd_set *); +extern Client *clients_new_client (Clients *, Socket *, Context *); +extern void clients_shutdown (Clients *); +extern int clients_output (Clients *, void *, int); #endif /* __CLIENTS_H__ */ diff --git a/apps/sympathy.c b/apps/sympathy.c index a9140f8..e11df1e 100644 --- a/apps/sympathy.c +++ b/apps/sympathy.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.2 2008/02/14 00:57:58 james * *** empty log message *** * @@ -21,8 +24,9 @@ static char rcsid[] = "$Id$"; #include #include "client.h" -int main(int argc,char *argv[]) +int +main (int argc, char *argv[]) { -client(); + client (); } diff --git a/apps/sympathyd.c b/apps/sympathyd.c index 6480713..8f45ca5 100644 --- a/apps/sympathyd.c +++ b/apps/sympathyd.c @@ -6,10 +6,14 @@ * */ -static char rcsid[] = "$Id$"; +static char rcsid[] = + "$Id$"; /* * $Log$ + * Revision 1.7 2008/02/14 02:46:44 james + * *** empty log message *** + * * Revision 1.6 2008/02/14 00:57:58 james * *** empty log message *** * @@ -36,30 +40,41 @@ static char rcsid[] = "$Id$"; #include "clients.h" -static void send_history(History *h,Client *c) +static void +send_history (History * h, Client * c) { -int rptr=h->wptr; + int rptr = h->wptr; -HISTORY_INC(h,rptr); + HISTORY_INC (h, rptr); -HISTORY_INC(h,rptr); -while (rptr!=h->wptr) -{ -History_ent *l=&h->lines[rptr]; -if (l->valid) { + HISTORY_INC (h, rptr); + while (rptr != h->wptr) + { + History_ent *l = &h->lines[rptr]; + if (l->valid) + { -if (ipc_msg_send_history(c->s,l)) - c->dead++; + if (ipc_msg_send_history (c->s, l)) + c->dead++; + } + HISTORY_INC (h, rptr); + } } -HISTORY_INC(h,rptr); -} + +static void +send_vt102 (VT102 * v, Client * c) +{ + if (ipc_msg_send_vt102 (c->s, v)) + c->dead++; + } -int main (int argc,char *argv[]) +int +main (int argc, char *argv[]) { fd_set rfds, wfds; - ANSI a = { 0 }; +// ANSI a = { 0 }; Context c; Socket *s, *cs; Clients *clients; @@ -71,49 +86,56 @@ int main (int argc,char *argv[]) c.v = vt102_new (); c.h = history_new (200); c.l = file_log_new ("log"); + c.k = keydis_vt102_new (&c); +#if 0 terminal_register_handlers (); a.terminal = terminal_open (0, 1); ansi_reset (&a, NULL); +#endif - clients=clients_new(); + clients = clients_new (); for (;;) { - struct timeval tv = { 0, 100000 }; - + struct timeval tv = { 10, 0 }; FD_ZERO (&rfds); FD_ZERO (&wfds); - tty_pre_select (c.t, &rfds,&wfds); + tty_pre_select (c.t, &rfds, &wfds); +#if 0 + tty_pre_select (a.terminal, &rfds, &wfds); +#endif - FD_SET(s->fd,&rfds); + FD_SET (s->fd, &rfds); socket_pre_select (s, &rfds, &wfds); - clients_pre_select (clients,&rfds,&wfds); + clients_pre_select (clients, &rfds, &wfds); select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); - if (FD_ISSET (s->fd, &rfds) && ((cs=socket_accept (s)))) { + if (FD_ISSET (s->fd, &rfds) && ((cs = socket_accept (s)))) { - Client *cl; - /*New client connexion */ - cl=clients_new_client (clients, cs, &c); + { + Client *cl; + /*New client connexion */ + cl = clients_new_client (clients, cs, &c); + + send_history (c.h, cl); + send_vt102 (c.v, cl); - send_history(c.h,cl); - + } } - } clients_post_select (clients, &c, &rfds, &wfds); if (FD_ISSET (c.t->rfd, &rfds)) { - char buf[1024]; + char buf[IPC_MAX_BUF]; int red; red = c.t->recv (c.t, buf, sizeof (buf)); @@ -128,14 +150,18 @@ int main (int argc,char *argv[]) } } +#if 0 ansi_dispatch (&a, &c); ansi_update (&a, &c); +#endif + - } clients_shutdown (clients); +#if 0 ansi_terminal_reset (&a); +#endif terminal_atexit (); printf ("QUAT\n"); } -- cgit v1.2.3