# $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 ***
#
sympathyd_SOURCES = sympathyd.c clients.c client.c
sympathyd_LDADD = ../src/libsympathy.la -lutil
-AM_CFLAGS=-g
+AM_CFLAGS=-g -Werror
/*
* $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 ***
*
#include <sympathy.h>
#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)
{
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");
+
}
/*
* $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 ***
*
#ifndef __CLIENT_H__
#define __CLIENT_H__
-void client(void);
+void client (void);
#endif /* __CLIENT_H__ */
/*
* $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 ***
*
#include <sympathy.h>
#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)
socket_free (c->s);
free (c);
- fprintf(stderr,"Client at %p freed\n",c);
+ fprintf (stderr, "Client at %p freed\n", c);
}
Client *
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;
}
{
*p = c->next;
client_free (c);
- cs->n--;
+ cs->n--;
}
else
{
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
/*
* $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 ***
*
#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__ */
/*
* $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 ***
*
#include <sympathy.h>
#include "client.h"
-int main(int argc,char *argv[])
+int
+main (int argc, char *argv[])
{
-client();
+ client ();
}
*
*/
-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 ***
*
#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;
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));
}
}
+#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");
}
# $Id$
#
# $Log$
+# Revision 1.12 2008/02/14 02:46:44 james
+# *** empty log message ***
+#
# Revision 1.11 2008/02/14 01:55:57 james
# *** empty log message ***
#
INCLUDES=
-PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h symsocket.h term.h context.h prototypes.h
+PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h symsocket.h keydis.h context.h prototypes.h
HDRS=project.h
-SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c term.c \
+SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c keydis.c \
history.c ring.c ptty.c terminal.c util.c log.c ipc.c slide.c symsocket.c
CPROTO=cproto
/*
* $Log$
+ * Revision 1.21 2008/02/14 02:46:44 james
+ * *** empty log message ***
+ *
* Revision 1.20 2008/02/14 01:55:57 james
* *** empty log message ***
*
for (i = 0; i < p->escape_ptr; ++i)
{
- term_send (c, p->escape_buf[i]);
+ c->k->key (c->k, p->escape_buf[i]);
}
p->escape_ptr = 0;
if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
{
- term_send (c, KEY_UP + (p->escape_buf[2] - 'A'));
+ c->k->key (c->k, KEY_UP + (p->escape_buf[2] - 'A'));
}
else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
{
- term_send (c, KEY_154 + (p->escape_buf[2] - 'a'));
+ c->k->key (c->k, KEY_154 + (p->escape_buf[2] - 'a'));
}
else
{
}
if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
{
- term_send (c, KEY_180 + (p->escape_buf[2] - '0'));
+ c->k->key (c->k, KEY_180 + (p->escape_buf[2] - '0'));
}
else
{
}
else
{
- term_send (c, ch);
+ c->k->key (c->k, ch);
}
}
#endif
#if 1
- if (*buf == 1)
- {
- ansi_reset (a, NULL);
- return 0;
- }
if (*buf == 2)
{
+#if 0
a->history_ptr = c->h->wptr;
HISTORY_INC (c->h, a->history_ptr);
- return 0;
+#endif
+ return -1;
}
#endif
/*
* $Log$
+ * Revision 1.5 2008/02/14 02:46:44 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/14 01:55:57 james
* *** empty log message ***
*
TTY *t;
History *h;
Log *l;
- Term *r;
+ KeyDis *k;
} Context;
#endif /* __CONTEXT_H__ */
--- /dev/null
+/*
+ * keydis.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/14 02:46:44 james
+ * *** empty log message ***
+ *
+ * Revision 1.1 2008/02/14 01:55:57 james
+ * *** empty log message ***
+ *
+ */
+
+
+#include "project.h"
+
+typedef struct
+{
+ KEYDIS_SIGNATURE;
+ Context *c;
+} KeyDis_VT102;
+
+typedef struct
+{
+ KEYDIS_SIGNATURE;
+ Socket *s;
+} KeyDis_IPC;
+
+
+static void
+keydis_close (KeyDis * t)
+{
+ free (t);
+}
+
+
+static int
+keydis_ipc_key (KeyDis * _t, int key)
+{
+ KeyDis_IPC *t = (KeyDis_IPC *) _t;
+
+ return ipc_msg_send_key (t->s, key);
+}
+
+static int
+keydis_vt102_key (KeyDis * _t, int key)
+{
+ KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
+
+ vt102_send (t->c, key);
+ return 0;
+}
+
+
+KeyDis *
+keydis_vt102_new (Context * c)
+{
+ KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102));
+ t->key = keydis_vt102_key;
+ t->close = keydis_close;
+ t->c = c;
+ return (KeyDis *) t;
+}
+
+
+KeyDis *
+keydis_ipc_new (Socket * s)
+{
+ KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC));
+ t->key = keydis_ipc_key;
+ t->close = keydis_close;
+ t->s = s;
+ return (KeyDis *) t;
+}
--- /dev/null
+/*
+ * keydis.h:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/14 02:46:44 james
+ * *** empty log message ***
+ *
+ * Revision 1.1 2008/02/14 01:55:57 james
+ * *** empty log message ***
+ *
+ */
+
+#ifndef __KEYDIS_H__
+#define __KEYDIS_H__
+
+
+#define KEYDIS_SIGNATURE \
+ void (*close)(struct KeyDis_struct *); \
+ int (*key)(struct KeyDis_struct *,int key)
+
+typedef struct KeyDis_struct
+{
+ KEYDIS_SIGNATURE;
+} KeyDis;
+
+
+#endif /* __KEYDIS_H__ */
extern void vt102_free(VT102 *v);
/* tty.c */
extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds);
+/* keydis.c */
+extern KeyDis *keydis_vt102_new(Context *c);
+extern KeyDis *keydis_ipc_new(Socket *s);
/* history.c */
extern History *history_new(int n);
extern void history_free(History *h);
extern int ipc_msg_send(Socket *s, IPC_Msg *m);
extern int ipc_msg_send_debug(Socket *s, char *msg);
extern int ipc_msg_send_history(Socket *s, History_ent *l);
+extern int ipc_msg_send_vt102(Socket *s, VT102 *v);
+extern int ipc_msg_send_key(Socket *s, int key);
+extern int ipc_msg_send_term(Socket *s, void *buf, int len);
/* slide.c */
extern void slide_free(Slide *s);
extern void slide_consume(Slide *s, int n);
/*
* $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 ***
*
{
s->nbytes -= n;
- if (s->nbytes<0)
- abort();
+ if (s->nbytes < 0)
+ abort ();
memmove (s->slide, s->slide + n, s->nbytes);
/*
* $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 ***
*
return ret;
}
+
void
socket_consume_msg (Socket * s)
{
if (!s->msg)
return;
- ipc_consume_message_in_slide(s->read_buf);
+ ipc_consume_message_in_slide (s->read_buf);
s->msg = ipc_check_for_message_in_slide (s->read_buf);
}
{
char buf[1024];
int n;
- int error=0;
+ int error = 0;
if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds))
n = wrap_write (s->fd, SLIDE_RPTR (s->write_buf), n);
if (n > 0)
slide_consume (s->write_buf, n);
- if (n<0) error=-1;
+ if (n < 0)
+ error = -1;
}
if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds))
n = wrap_read (s->fd, SLIDE_WPTR (s->read_buf), n);
if (n > 0)
slide_added (s->read_buf, n);
- if (n<0) error=-1;
+ if (n < 0)
+ error = -1;
}
s->msg = ipc_check_for_message_in_slide (s->read_buf);
(SLIDE_BYTES (s->write_buf) >
MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf);
n = wrap_write (s->fd, SLIDE_RPTR (s->write_buf), n);
- {
- uint8_t *c=SLIDE_RPTR(s->write_buf);
+ {
+ uint8_t *c = SLIDE_RPTR (s->write_buf);
}
if (n > 0)
slide_consume (s->write_buf, n);
-
- if (n<0) return -1;
+
+ if (n < 0)
+ return -1;
return len;
}
+++ /dev/null
-/*
- * term.c:
- *
- * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
- * All rights reserved.
- *
- */
-
-static char rcsid[] = "$Id$";
-
-/*
- * $Log$
- * Revision 1.1 2008/02/14 01:55:57 james
- * *** empty log message ***
- *
- */
-
+++ /dev/null
-/*
- * term.h:
- *
- * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
- * All rights reserved.
- *
- */
-
-/*
- * $Id$
- */
-
-/*
- * $Log$
- * Revision 1.1 2008/02/14 01:55:57 james
- * *** empty log message ***
- *
- */
-
-#ifndef __TERM_H__
-#define __TERM_H__
-
-#endif /* __TERM_H__ */
/*
* $Log$
+ * Revision 1.27 2008/02/14 02:46:45 james
+ * *** empty log message ***
+ *
* Revision 1.26 2008/02/14 01:55:57 james
* *** empty log message ***
*
{
uint8_t ch;
- if (!c->t) return;
+ if (!c->t)
+ return;
#if 0
fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');