chiark / gitweb /
*** empty log message ***
[sympathy.git] / apps / clients.c
index 6c70e9d5452a502dbcfed300e77c7189bda426e8..b5bafcdabd42e146565beb74f61074b2245edc73 100644 (file)
@@ -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 <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)
@@ -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