/*
* $Log$
+ * Revision 1.6 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/14 10:34:47 james
* *** empty log message ***
*
vt102_parse (c, m->term.term, m->term.len);
break;
case IPC_MSG_TYPE_STATUS:
- vt102_status_line (c->v, m->status.status);
+ cmd_new_status (c->d, c, m->status.status);
break;
default:
fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
ANSI a = { 0 };
Context c;
+
s = socket_connect ("socket");
if (!s)
c.h = history_new (200);
c.l = NULL;
c.k = keydis_ipc_new (s);
+ c.d = cmd_new ();
terminal_register_handlers ();
a.terminal = terminal_open (0, 1);
{
struct timeval tv = { 0, 100000 };
+ if (c.d->disconnect)
+ break;
+
FD_ZERO (&rfds);
FD_ZERO (&wfds);
/*
* $Log$
+ * Revision 1.6 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/14 10:34:47 james
* *** empty log message ***
*
case IPC_MSG_TYPE_KEY:
vt102_send (c, m->key.key);
break;
+ case IPC_MSG_TYPE_SETBAUD:
+ tty_set_baud (c->t, m->setbaud.baud);
+ break;
+ case IPC_MSG_TYPE_SENDBREAK:
+ tty_send_break (c->t);
+ break;
+ case IPC_MSG_TYPE_SETFLOW:
+ tty_set_flow (c->t, m->setflow.flow);
+ break;
default:
fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
}
/*
* $Log$
+ * Revision 1.12 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/14 16:21:17 james
* *** empty log message ***
*
status.lines = tty_status.lines;
status.baud = tty_status.baud;
status.crtscts = (tty_status.termios.c_cflag & CRTSCTS) ? 1 : 0;
- status.blocked=tty_status.blocked;
+ status.blocked = tty_status.blocked;
cd = (tty_status.lines & TIOCM_CD) ? 1 : 0;
log_line_changes (c, old_status.lines, status.lines);
+ ptr += sprintf (ptr, "CTRL-B ");
+
t = c->t->name;
if (!strncmp (t, "/dev/", 5))
t += 5;
ptr = do_line (ptr, status.lines, TIOCM_DTR);
ptr = do_line (ptr, status.lines, TIOCM_DSR);
ptr = do_line (ptr, status.lines, TIOCM_RI);
+ ptr = do_line (ptr, status.lines, TIOCM_CD);
if (status.blocked)
- {
+ {
t = ", Locked";
while (*t)
*(ptr++) = *(t++);
- }
+ }
if (status.crtscts)
{
*(ptr++) = *(t++);
}
+#if 0
if (status.lines & TIOCM_CD)
{
ptr +=
sprintf (ptr, ", Off %d.%d", status.cd_edge_sec / 60,
status.cd_edge_sec % 60);
}
+#endif
ptr +=
sprintf (ptr, ", %d client%s", status.nclients,
Clients *clients;
- construct_possible_lock_files("/dev/modem");
- return 0;
+#if 0
+ construct_possible_lock_files ("/dev/modem");
+ return 0;
+#endif
s = socket_listen ("socket");
c.v = vt102_new ();
c.h = history_new (200);
c.l = file_log_new ("log");
- c.k = keydis_vt102_new (&c);
+ c.k = keydis_vt102_new ();
+ c.d = NULL;
clients = clients_new ();
# $Id$
#
# $Log$
+# Revision 1.14 2008/02/15 03:32:07 james
+# *** empty log message ***
+#
# Revision 1.13 2008/02/14 16:21:17 james
# *** empty log message ***
#
# NB order here matters.
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
+ log.h ipc.h symsocket.h keydis.h cmd.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 \
keydis.c history.c ring.c ptty.c terminal.c util.c log.c ipc.c \
- slide.c symsocket.c serial.c
+ slide.c symsocket.c serial.c cmd.c
CPROTO=cproto
/*
* $Log$
+ * Revision 1.22 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.21 2008/02/14 02:46:44 james
* *** empty log message ***
*
for (i = 0; i < p->escape_ptr; ++i)
{
- c->k->key (c->k, p->escape_buf[i]);
+ keydis_key (c->k, c, p->escape_buf[i]);
}
p->escape_ptr = 0;
if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
{
- c->k->key (c->k, KEY_UP + (p->escape_buf[2] - 'A'));
+ keydis_key (c->k, c, KEY_UP + (p->escape_buf[2] - 'A'));
}
else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
{
- c->k->key (c->k, KEY_154 + (p->escape_buf[2] - 'a'));
+ keydis_key (c->k, c, KEY_154 + (p->escape_buf[2] - 'a'));
}
else
{
}
if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
{
- c->k->key (c->k, KEY_180 + (p->escape_buf[2] - '0'));
+ keydis_key (c->k, c, KEY_180 + (p->escape_buf[2] - '0'));
}
else
{
}
else
{
- c->k->key (c->k, ch);
+ keydis_key (c->k, c, ch);
}
}
return -1;
#endif
-#if 1
+#if 0
if (*buf == 2)
{
#if 0
/*
* $Log$
+ * Revision 1.6 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/14 02:46:44 james
* *** empty log message ***
*
#ifndef __CONTEXT_H__
#define __CONTEXT_H__
-typedef struct
+typedef struct Context_struct
{
VT102 *v;
TTY *t;
History *h;
Log *l;
KeyDis *k;
+ Cmd *d;
} Context;
#endif /* __CONTEXT_H__ */
/*
* $Log$
+ * Revision 1.2 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/14 12:17:42 james
* *** empty log message ***
*
return ipc_msg_send (s, (IPC_Msg *) & m);
}
+
+
+int
+ipc_msg_send_setbaud (Socket * s, int baud)
+{
+ IPC_Msg_setbaud m;
+
+ m.size = sizeof (m);
+ m.type = IPC_MSG_TYPE_SETBAUD;
+ m.baud = baud;
+ return ipc_msg_send (s, (IPC_Msg *) & m);
+}
+
+
+int
+ipc_msg_send_sendbreak (Socket * s)
+{
+ IPC_Msg_sendbreak m;
+
+ m.size = sizeof (m);
+ m.type = IPC_MSG_TYPE_SENDBREAK;
+ return ipc_msg_send (s, (IPC_Msg *) & m);
+}
+
+
+int
+ipc_msg_send_setflow (Socket * s, int flow)
+{
+ IPC_Msg_setflow m;
+
+ m.size = sizeof (m);
+ m.type = IPC_MSG_TYPE_SETFLOW;
+ m.flow = flow;
+ return ipc_msg_send (s, (IPC_Msg *) & m);
+}
/*
* $Log$
+ * Revision 1.2 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/14 12:17:42 james
* *** empty log message ***
*
#define IPC_MSG_TYPE_KEY 4
#define IPC_MSG_TYPE_TERM 5
#define IPC_MSG_TYPE_STATUS 6
+#define IPC_MSG_TYPE_SETBAUD 7
+#define IPC_MSG_TYPE_SENDBREAK 8
+#define IPC_MSG_TYPE_SETFLOW 9
typedef struct
{
char status[0];
} IPC_Msg_status;
+typedef struct
+{
+ int32_t size;
+ int32_t type;
+ int32_t baud;
+} IPC_Msg_setbaud;
+
+
+typedef struct
+{
+ int32_t size;
+ int32_t type;
+} IPC_Msg_sendbreak;
+
+
+typedef struct
+{
+ int32_t size;
+ int32_t type;
+ int32_t flow;
+} IPC_Msg_setflow;
+
typedef union
IPC_Msg_key key;
IPC_Msg_term term;
IPC_Msg_status status;
+IPC_Msg_setbaud setbaud;
+IPC_Msg_sendbreak sendbreak;
+IPC_Msg_setflow setflow;
} IPC_Msg;
/*
* $Log$
+ * Revision 1.2 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/14 02:46:44 james
* *** empty log message ***
*
#include "project.h"
+#define CMD_BUFLEN 128
+
typedef struct
{
KEYDIS_SIGNATURE;
- Context *c;
} KeyDis_VT102;
typedef struct
static int
-keydis_ipc_key (KeyDis * _t, int key)
+keydis_ipc_key (KeyDis * _t, Context * c, int key)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
}
static int
-keydis_vt102_key (KeyDis * _t, int key)
+keydis_ipc_set_baud (KeyDis * _t, Context * c, int baud)
+{
+ KeyDis_IPC *t = (KeyDis_IPC *) _t;
+
+ ipc_msg_send_setbaud (t->s, baud);
+
+ return 0;
+}
+
+static int
+keydis_ipc_send_break (KeyDis * _t, Context * c)
+{
+ KeyDis_IPC *t = (KeyDis_IPC *) _t;
+
+ ipc_msg_send_sendbreak (t->s);
+
+ return 0;
+}
+
+static int
+keydis_ipc_set_flow (KeyDis * _t, Context * c, int flow)
+{
+ KeyDis_IPC *t = (KeyDis_IPC *) _t;
+
+ ipc_msg_send_setflow (t->s, flow);
+
+ return 0;
+}
+
+static int
+keydis_vt102_key (KeyDis * _t, Context * c, int key)
+{
+ KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
+
+ vt102_send (c, key);
+ return 0;
+}
+
+static int
+keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)
{
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
- vt102_send (t->c, key);
+ tty_set_baud (c->t, baud);
+
return 0;
}
+static int
+keydis_vt102_send_break (KeyDis * _t, Context * c)
+{
+ KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
+
+ tty_send_break (c->t);
+
+ return 0;
+}
+
+static int
+keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)
+{
+ KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
+
+ tty_set_flow (c->t, flow);
+
+ return 0;
+}
+
+
KeyDis *
-keydis_vt102_new (Context * c)
+keydis_vt102_new (void)
{
KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102));
t->key = keydis_vt102_key;
t->close = keydis_close;
- t->c = c;
+ t->set_baud = keydis_vt102_set_baud;
+ t->send_break = keydis_vt102_send_break;
+ t->set_flow = keydis_vt102_set_flow;
return (KeyDis *) t;
}
KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC));
t->key = keydis_ipc_key;
t->close = keydis_close;
+ t->set_baud = keydis_ipc_set_baud;
+ t->send_break = keydis_ipc_send_break;
+ t->set_flow = keydis_ipc_set_flow;
t->s = s;
return (KeyDis *) t;
}
+
+
+
+
+
+
+int
+keydis_key (KeyDis * t, Context * c, int key)
+{
+
+ if (!c->d)
+ return t->key (t, c, key);
+
+ cmd_show_status (c->d, c);
+
+ if (c->d->active)
+ return cmd_key (c->d, c, key);
+
+ if (key == CMD_KEY)
+ return cmd_activate (c->d, c);
+
+
+ return t->key (t, c, key);
+}
/*
* $Log$
+ * Revision 1.2 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/14 02:46:44 james
* *** empty log message ***
*
#define __KEYDIS_H__
+struct Context_struct;
+
#define KEYDIS_SIGNATURE \
void (*close)(struct KeyDis_struct *); \
- int (*key)(struct KeyDis_struct *,int key)
+ int (*key)(struct KeyDis_struct *,struct Context_struct *,int key); \
+ int (*set_baud)(struct KeyDis_struct *,struct Context_struct *,int rate); \
+ int (*send_break)(struct KeyDis_struct *,struct Context_struct *); \
+ int (*set_flow)(struct KeyDis_struct *,struct Context_struct *,int flow)
+
+
typedef struct KeyDis_struct
{
/* tty.c */
extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds);
extern int tty_get_status(TTY *t, TTY_Status *s);
+extern void tty_set_baud(TTY *t, int rate);
+extern void tty_send_break(TTY *t);
+extern void tty_set_flow(TTY *t, int flow);
/* keydis.c */
-extern KeyDis *keydis_vt102_new(Context *c);
+extern KeyDis *keydis_vt102_new(void);
extern KeyDis *keydis_ipc_new(Socket *s);
+extern int keydis_key(KeyDis *t, Context *c, int key);
/* history.c */
extern History *history_new(int n);
extern void history_free(History *h);
extern void socket_pre_select(Socket *s, fd_set *rfds, fd_set *wfds);
extern int socket_post_select(Socket *s, fd_set *rfds, fd_set *wfds);
extern int socket_write(Socket *s, void *buf, int len);
+/* serial.c */
+extern int make_lockfile(char *name);
+extern void construct_lock_file_name_by_name(char *ptr);
+extern void construct_lock_file_name_by_device(dev_t dev);
+extern int construct_possible_lock_files(char *device);
+extern TTY *serial_open(char *path);
+/* cmd.c */
+extern void cmd_parse(Cmd *c, Context *ctx, char *buf);
+extern void cmd_show_status(Cmd *c, Context *ctx);
+extern int cmd_key(Cmd *c, Context *ctx, int key);
+extern int cmd_activate(Cmd *c, Context *ctx);
+extern void cmd_new_status(Cmd *c, Context *ctx, char *msg);
+extern Cmd *cmd_new(void);
/*
* $Log$
+ * Revision 1.3 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/14 16:21:17 james
* *** empty log message ***
*
#define NLOCKFILES 10
-typedef struct {
-char *lockfiles[NLOCKFILES];
-char *potential_lockfiles[NLOCKFILES];
-struct timeval last_content_check;
+typedef struct
+{
+ char *lockfiles[NLOCKFILES];
+ char *potential_lockfiles[NLOCKFILES];
+ struct timeval last_content_check;
} Serial_lock;
typedef struct
static int
-chown_uucp(fd)
-int fd;
+chown_uucp (fd)
+ int fd;
{
- static int uuid = -1, ugid;
- struct passwd *pw;
-
- if (uuid <0) {
- if (pw = getpwnam("uucp")) {
- uuid = pw->pw_uid;
- ugid = pw->pw_gid;
- } else {
- return -1;
- }
+ static int uuid = -1, ugid;
+ struct passwd *pw;
+
+ if (uuid < 0)
+ {
+ if (pw = getpwnam ("uucp"))
+ {
+ uuid = pw->pw_uid;
+ ugid = pw->pw_gid;
+ }
+ else
+ {
+ return -1;
+ }
}
- return fchown(fd, uuid, ugid);
+ return fchown (fd, uuid, ugid);
}
-int make_lockfile(char *name)
+int
+make_lockfile (char *name)
{
-char buf[1024],tmpfn[1024];
-char *ptr;
-int fd;
-int i;
+ char buf[1024], tmpfn[1024];
+ char *ptr;
+ int fd;
+ int i;
-strcpy(tmpfn,name);
+ strcpy (tmpfn, name);
-ptr=rindex(tmpfn,'/');
-if (!ptr) return -1;
+ ptr = rindex (tmpfn, '/');
+ if (!ptr)
+ return -1;
-ptr++;
+ ptr++;
-ptr+=sprintf(ptr,"LTMP.%d",getpid());
-*ptr=0;
+ ptr += sprintf (ptr, "LTMP.%d", getpid ());
+ *ptr = 0;
-i=sprintf(buf,"%10d\n",getpid());
+ i = sprintf (buf, "%10d\n", getpid ());
-fd=open(tmpfn,O_WRONLY|O_CREAT|O_TRUNC,0444);
-if (fd<0) {
- unlink(tmpfn);
- return -1;
-}
+ fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444);
+ if (fd < 0)
+ {
+ unlink (tmpfn);
+ return -1;
+ }
-write(fd,buf,i);
-fchmod(fd,044);
-if( chown_uucp(fd)) {
- close(fd);
- unlink(tmpfn);
- return -1;
-}
+ write (fd, buf, i);
+ fchmod (fd, 044);
+ if (chown_uucp (fd))
+ {
+ close (fd);
+ unlink (tmpfn);
+ return -1;
+ }
-close(fd);
+ close (fd);
-if (link(tmpfn,name)<0) {
- unlink(tmpfn);
- return -1;
-}
+ if (link (tmpfn, name) < 0)
+ {
+ unlink (tmpfn);
+ return -1;
+ }
-unlink(tmpfn);
-return 0;
+ unlink (tmpfn);
+ return 0;
}
-void construct_lock_file_name_by_name(char *ptr)
+void
+construct_lock_file_name_by_name (char *ptr)
{
-printf("lock by file %s\n",ptr);
+ printf ("lock by file %s\n", ptr);
}
-void construct_lock_file_name_by_device(dev_t dev)
+
+void
+construct_lock_file_name_by_device (dev_t dev)
{
-printf("lock by dev %x\n",dev);
+ printf ("lock by dev %x\n", dev);
}
#define DEV "/dev/"
-int construct_possible_lock_files(char *device)
+int
+construct_possible_lock_files (char *device)
{
-int nl;
-struct dirent *de;
-DIR *d;
-struct stat dev_stat,ent_stat;
-char buf[1024];
+ int nl;
+ struct dirent *de;
+ DIR *d;
+ struct stat dev_stat, ent_stat;
+ char buf[1024];
-if (stat(device,&dev_stat)) return -1;
-if (!S_ISCHR(dev_stat.st_mode)) return -1;
+ if (stat (device, &dev_stat))
+ return -1;
+ if (!S_ISCHR (dev_stat.st_mode))
+ return -1;
-construct_lock_file_name_by_device(dev_stat.st_rdev);
+ construct_lock_file_name_by_device (dev_stat.st_rdev);
-construct_lock_file_name_by_name(device);
+ construct_lock_file_name_by_name (device);
-for (d=opendir(DEV);(de=readdir(d));)
-{
-strcpy(buf,DEV);
-strcat(buf,de->d_name);
+ for (d = opendir (DEV); (de = readdir (d));)
+ {
+ strcpy (buf, DEV);
+ strcat (buf, de->d_name);
-if (stat(buf,&ent_stat)) continue;
-if (!S_ISCHR(ent_stat.st_mode)) continue;
-if (ent_stat.st_rdev!=dev_stat.st_rdev) continue;
+ if (stat (buf, &ent_stat))
+ continue;
+ if (!S_ISCHR (ent_stat.st_mode))
+ continue;
+ if (ent_stat.st_rdev != dev_stat.st_rdev)
+ continue;
-construct_lock_file_name_by_name(buf);
+ construct_lock_file_name_by_name (buf);
-}
-closedir(d);
+ }
+ closedir (d);
}
-static void
-serial_check_lock(Serial *t)
+static void
+serial_check_lock (Serial * t)
{
}
Serial *t = (Serial *) _t;
int red, done = 0;
- serial_check_lock(t);
- if (t->blocked) return 0;
+ serial_check_lock (t);
+ if (t->blocked)
+ return 0;
do
{
int writ, done = 0;
Serial *t = (Serial *) _t;
- serial_check_lock(t);
- if (t->blocked) return 0;
+ serial_check_lock (t);
+ if (t->blocked)
+ return 0;
do
{
default_termios (&termios);
- fd=open(path,O_RDWR);
+ fd = open (path, O_RDWR);
set_nonblocking (fd);
/*
* $Log$
+ * Revision 1.9 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.8 2008/02/14 10:39:14 james
* *** empty log message ***
*
t = (TERMINAL *) malloc (sizeof (TERMINAL));
- strcpy(t->name,"terminal");
+ strcpy (t->name, "terminal");
t->rfd = rfd;
t->wfd = wfd;
/*
* $Log$
+ * Revision 1.9 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.8 2008/02/14 10:36:18 james
* *** empty log message ***
*
return 0;
}
+void
+tty_set_baud (TTY * t, int rate)
+{
+ struct termios tios = { 0 };
+
+ speed_t s = baud_to_speed_t (rate);
+
+ if (s == (speed_t) - 1)
+ return;
+
+ if (tcgetattr (t->rfd, &tios))
+ return;
+
+ cfsetispeed (&tios, s);
+ cfsetospeed (&tios, s);
+
+ tcsetattr (t->rfd, TCSANOW, &tios);
+}
+
+void
+tty_send_break (TTY * t)
+{
+ tcsendbreak (t->wfd, 0);
+}
+
+void
+tty_set_flow (TTY * t, int flow)
+{
+ struct termios tios = { 0 };
+
+ if (tcgetattr (t->rfd, &tios))
+ return;
+
+ if (flow)
+ tios.c_cflag |= CRTSCTS;
+ else
+ tios.c_cflag &= ~CRTSCTS;
+
+ tcsetattr (t->rfd, TCSANOW, &tios);
+
+}
+
+
#if 0
int
tty_post_select (Context * c, fd_set * rfds, fd_set * wfds)
/*
* $Log$
+ * Revision 1.29 2008/02/15 03:32:07 james
+ * *** empty log message ***
+ *
* Revision 1.28 2008/02/14 10:34:30 james
* *** empty log message ***
*
v->current_line = v->pos;
}
+ if (c->d)
+ cmd_show_status (c->d, c);
}
vt102_parse (Context * c, char *buf, int len)