* $Id$
*/
+#include <sys/types.h>
#include <stdio.h>
#include <sys/time.h>
-#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include "sel.h"
#include "cmsg.h"
+#include "chain.h"
#include "debug.h"
#define TEXT 1
char *connsort = "local"; /* the connection variety */
int state = 0; /* the current state of the connection */
int laststate = 0; /* the last state we were in */
-
-
+char echocancel = 1; /* echo cancelling */
+reft echobase; /* the anti echo queue */
+int maxecho = 5; /* the depth of the anti echo queue */
+int echon; /* no of entries in the anti echo queue */
#define CONNECTED 100
#define WAITLOGIN 1
#define WAITPASSWD 2
#define WAITINPUT 10
-
+#define DOCHAT 20
myregex_t iscallreg[] = { /* regexes to determine whether this is a reasonable callsign */
{
return 0;
}
+void reaper(int i)
+{
+ pid_t mypid;
+ while ((mypid = waitpid(-1, 0, WNOHANG)) > 0) {
+ ;
+ }
+}
+
/*
* higher level send and receive routines
*/
void flush_text(fcb_t *f)
{
if (f->obuf) {
- cmsg_send(f->outq, f->obuf, 0);
+ /* save this onto the front of the echo chain */
+ cmsg_t *imp = f->obuf;
+ int size = imp->inp - imp->data;
+ cmsg_t *emp = cmsg_new(size, imp->sort, imp->portp);
+
+ emp->size = size;
+ memcpy(emp->data, imp->data, size);
+ emp->inp = emp->data + size; /* just in case */
+ if (echocancel) {
+ chain_add(&echobase, emp);
+ if (++echon > maxecho) {
+ emp = cmsg_prev(&echobase);
+ cmsg_free(emp);
+ }
+ }
+
+ /* queue it for sending */
+ cmsg_send(f->outq, imp, 0);
f->sp->flags |= SEL_OUTPUT;
f->obuf = 0;
}
/*
* set up the various mode flags, NL endings and things
*/
-void setmode(char *m)
+void setconntype(char *m)
{
connsort = strlower(m);
if (eq(connsort, "telnet") || eq(connsort, "local") || eq(connsort, "nlonly")) {
void process_stdin()
{
- cmsg_t *mp = cmsg_next(in->inq);
+ cmsg_t *wmp, *mp = cmsg_next(in->inq);
char *p, hasa, hasn, i;
char callsign[MAXCALLSIGN+1];
if (mp) {
dbg(DMSG, "MSG size: %d", mp->size);
+
+ /* check for echos */
+ if (echocancel) {
+ for (wmp = 0; wmp = chain_get_next(&echobase, wmp); ) {
+ if (!memcmp(wmp->data, mp->data, wmp->size)) {
+ cmsg_callback(mp, 0);
+ return;
+ }
+ }
+ }
switch (state) {
case CONNECTED:
chgstate(CONNECTED);
send_file("connected");
+ break;
+
+ case DOCHAT:
+
+ break;
}
cmsg_callback(mp, 0);
{
int i, c, err = 0;
- while ((c = getopt(argc, argv, "h:p:x:")) > 0) {
+ while ((c = getopt(argc, argv, "eh:l:p:x:")) > 0) {
switch (c) {
+ case 'e':
+ echocancel ^= 1;
+ break;
case 'h':
node_addr = optarg;
break;
lerr:
if (err) {
- die("usage: client [-x n|-h<host>|-p<port>|-l<paclen>] <call>|login [local|telnet|ax25]");
+ die("usage: client [-e|-x n|-h<host>|-p<port>|-l<paclen>] <call>|login [local|telnet|ax25]");
}
if (optind < argc) {
die("Must have at least a callsign (for now)");
if (optind < argc) {
- setmode(argv[optind]);
+ setconntype(argv[optind]);
} else {
- setmode("local");
+ setconntype("local");
}
/* this is kludgy, but hey so is the rest of this! */
#ifdef SIGPWR
signal(SIGPWR, terminate);
#endif
+
+ /* init a few things */
+ chain_init(&echobase);
/* connect up stdin */
in = fcb_new(0, TEXT);