Fixed mbcico ISDN modem aftercall function

This commit is contained in:
Michiel Broek 2002-07-02 20:00:49 +00:00
parent f5132ca7a0
commit 2a01693438
6 changed files with 453 additions and 447 deletions

View File

@ -33,6 +33,8 @@ v0.35.02 22-Jun-2002
mbcico: mbcico:
Implemented nodes special outbound boxes. Implemented nodes special outbound boxes.
Corrected a problem with getting modem aftercall info for ISDN
modems.
mbout: mbout:
Implemented nodes special outbound boxes. Implemented nodes special outbound boxes.

View File

@ -60,240 +60,247 @@ extern char *inetaddr;
int portopen(faddr *addr) int portopen(faddr *addr)
{ {
char *p; char *p;
int rc; int rc;
if (inetaddr) { if (inetaddr) {
Syslog('d', "portopen inetaddr %s", inetaddr); Syslog('d', "portopen inetaddr %s", inetaddr);
if ((rc = opentcp(inetaddr))) { if ((rc = opentcp(inetaddr))) {
Syslog('+', "Cannot connect %s", inetaddr); Syslog('+', "Cannot connect %s", inetaddr);
nodeulock(addr); nodeulock(addr);
putstatus(addr,1,ST_NOCONN); putstatus(addr,1,ST_NOCONN);
return ST_NOCONN; return ST_NOCONN;
}
return 0;
} }
return 0;
}
if (forcedline) { if (forcedline) {
Syslog('d', "portopen forcedline %s", forcedline); Syslog('d', "portopen forcedline %s", forcedline);
p = forcedline; p = forcedline;
strncpy(history.tty, p, 6); strncpy(history.tty, p, 6);
if (load_port(p)) { if (load_port(p)) {
if ((rc = openport(p, ttyinfo.portspeed))) { if ((rc = openport(p, ttyinfo.portspeed))) {
Syslog('+', "Cannot open port %s",p); Syslog('+', "Cannot open port %s",p);
nodeulock(addr); nodeulock(addr);
putstatus(addr, 10, ST_PORTERR); putstatus(addr, 10, ST_PORTERR);
return ST_PORTERR; return ST_PORTERR;
} }
return ST_PORTOK; return ST_PORTOK;
} else { } else {
nodeulock(addr); nodeulock(addr);
putstatus(addr, 0, ST_PORTERR); putstatus(addr, 0, ST_PORTERR);
return ST_PORTERR; return ST_PORTERR;
}
} }
}
WriteError("No call method available"); WriteError("No call method available, maybe missing parameters");
return ST_PORTERR; return ST_PORTERR;
} }
int call(faddr *addr) int call(faddr *addr)
{ {
int i, rc = 1; int i, rc = 1;
struct hostent *he; struct hostent *he;
/* /*
* Don't call points, call their boss instead. * Don't call points, call their boss instead.
*/ */
addr->point = 0; addr->point = 0;
/* /*
* First check if node is locked, if not lock it immediatly * First check if node is locked, if not lock it immediatly
* or stop further waste of time and logfile space. * or stop further waste of time and logfile space.
*/ */
if (nodelock(addr)) { if (nodelock(addr)) {
Syslog('+', "System %s is locked", ascfnode(addr, 0x1f)); Syslog('+', "System %s is locked", ascfnode(addr, 0x1f));
putstatus(addr, 0, ST_LOCKED); putstatus(addr, 0, ST_LOCKED);
return ST_LOCKED; return ST_LOCKED;
} }
if ((nlent = getnlent(addr)) == NULL) { if ((nlent = getnlent(addr)) == NULL) {
WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f)); WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f));
putstatus(addr,0,ST_LOOKUP); putstatus(addr,0,ST_LOOKUP);
nodeulock(addr); nodeulock(addr);
return ST_LOOKUP; return ST_LOOKUP;
} }
/* /*
* Load the noderecord if the node is in the setup. * Load the noderecord if the node is in the setup.
*/ */
noderecord(addr); noderecord(addr);
rdoptions(TRUE); rdoptions(TRUE);
/* /*
* Fill default history info in case we get a FTS0001 session * Fill default history info in case we get a FTS0001 session
*/ */
strncpy(history.system_name, nlent->name, 35); strncpy(history.system_name, nlent->name, 35);
strncpy(history.location, nlent->location, 35); strncpy(history.location, nlent->location, 35);
strncpy(history.sysop, nlent->sysop, 35); strncpy(history.sysop, nlent->sysop, 35);
history.aka.zone = addr->zone; history.aka.zone = addr->zone;
history.aka.net = addr->net; history.aka.net = addr->net;
history.aka.node = addr->node; history.aka.node = addr->node;
history.aka.point = addr->point; history.aka.point = addr->point;
if (addr->domain && strlen(addr->domain)) if (addr->domain && strlen(addr->domain))
sprintf(history.aka.domain, "%s", addr->domain); sprintf(history.aka.domain, "%s", addr->domain);
/*
* First see if this node can be reached over the internet and
* that internet calls are allowed.
*/
if (nlent->iflags && ((localoptions & (NOIBN | NOITN | NOIFC)) == 0)) {
if (!inetaddr) {
Syslog('d', "Trying to find IP address...");
/*
* There is no fdn or IP address at the commandline.
* First check nodesetup for an override in the phone field.
*/
if (strlen(nodes.phone[0])) {
inetaddr = xstrcpy(nodes.phone[0]);
} else if (strlen(nodes.phone[1])) {
inetaddr = xstrcpy(nodes.phone[1]);
} else {
/*
* Try to find the fdn in several places in the nodelist fields.
*/
if ((nlent->phone != NULL) && (strncmp(nlent->phone, (char *)"000-", 4) == 0)) {
inetaddr = xstrcpy(nlent->phone+4);
for (i = 0; i < strlen(inetaddr); i++)
if (inetaddr[i] == '-')
inetaddr[i] = '.';
Syslog('d', "Got IP address from phone field");
} else if ((he = gethostbyname(nlent->name))) {
inetaddr = xstrcpy(nlent->name);
Syslog('d', "Got hostname from nodelist system name");
} else if ((he = gethostbyname(nlent->location))) {
/*
* A fdn at the nodelist location field is not in the specs
* but the real world differs from the specs.
*/
inetaddr = xstrcpy(nlent->location);
Syslog('d', "Got hostname from nodelist location");
}
}
}
/*
* First see if this node can be reached over the internet and
* that internet calls are allowed.
*/
if (nlent->iflags && ((localoptions & (NOIBN | NOITN | NOIFC)) == 0)) {
if (!inetaddr) {
Syslog('d', "Trying to find IP address...");
/*
* There is no fdn or IP address at the commandline.
* First check nodesetup for an override in the phone field.
*/
if (strlen(nodes.phone[0])) {
inetaddr = xstrcpy(nodes.phone[0]);
} else if (strlen(nodes.phone[1])) {
inetaddr = xstrcpy(nodes.phone[1]);
} else {
/* /*
* If we have an internet address, set protocol * Try to find the fdn in several places in the nodelist fields.
*/ */
if (inetaddr) { if ((nlent->phone != NULL) && (strncmp(nlent->phone, (char *)"000-", 4) == 0)) {
RegTCP(); inetaddr = xstrcpy(nlent->phone+4);
Syslog('d', "TCP/IP node \"%s\"", MBSE_SS(inetaddr)); for (i = 0; i < strlen(inetaddr); i++)
if (inetaddr[i] == '-')
if (tcp_mode == TCPMODE_NONE) { inetaddr[i] = '.';
/* Syslog('d', "Got IP address from phone field");
* If protocol not forced at the commandline, get it } else if ((he = gethostbyname(nlent->name))) {
* from the nodelist. If it fails, fallback to dial. inetaddr = xstrcpy(nlent->name);
* Priority IBN, IFC, ITN. Syslog('d', "Got hostname from nodelist system name");
*/ } else if ((he = gethostbyname(nlent->location))) {
if ((nlent->iflags & IP_IBN) && ((localoptions & NOIBN) == 0)) { /*
tcp_mode = TCPMODE_IBN; * A fdn at the nodelist location field is not in the specs
Syslog('d', "TCP/IP mode set to IBN"); * but the real world differs from the specs.
} else if ((nlent->iflags & IP_IFC) && ((localoptions & NOIFC) == 0)) { */
tcp_mode = TCPMODE_IFC; inetaddr = xstrcpy(nlent->location);
Syslog('d', "TCP/IP mode set to IFC"); Syslog('d', "Got hostname from nodelist location");
} else if ((nlent->iflags & IP_ITN) && ((localoptions & NOITN) == 0)) {
tcp_mode = TCPMODE_ITN;
Syslog('d', "TCP/IP mode seto to ITN");
} else {
Syslog('+', "No common TCP/IP protocols for node %s", nlent->name);
free(inetaddr);
inetaddr = NULL;
}
}
} else {
WriteError("No IP address, abort call");
rc = ST_NOCALL8;
putstatus(addr, 10, rc);
nodeulock(addr);
return rc;
} }
}
} }
if (((nlent->oflags & OL_CM) == 0) && (!IsZMH())) {
Syslog('?', "Warning: calling MO system outside ZMH");
}
if (inbound)
free(inbound);
inbound = xstrcpy(CFG.pinbound); /* master sessions are secure */
/* /*
* Call when: * If we have an internet address, set protocol
* the nodelist has a phone, or phone on commandline, or TCP address given
* and
* nodenumber on commandline, or node is CM and not down, hold, pvt
* and
* nocall is false
*/ */
if ((nlent->phone || forcedphone || inetaddr ) && if (inetaddr) {
(forcedcalls || (((nlent->pflag & (NL_DUMMY|NL_DOWN|NL_HOLD|NL_PVT)) == 0) && ((localoptions & NOCALL) == 0)))) { RegTCP();
Syslog('+', "Calling %s (%s, phone %s)",ascfnode(addr,0x1f), nlent->name,nlent->phone?nlent->phone:forcedphone); Syslog('d', "TCP/IP node \"%s\"", MBSE_SS(inetaddr));
IsDoing("Call %s", ascfnode(addr, 0x0f));
rc = portopen(addr);
if ((rc == 0) && (!inetaddr)) { if (tcp_mode == TCPMODE_NONE) {
if ((rc = dialphone(forcedphone?forcedphone:nlent->phone))) { /*
Syslog('+', "Dial failed"); * If protocol not forced at the commandline, get it
nodeulock(addr); * from the nodelist. If it fails, fallback to dial.
rc+=1; /* rc=2 - dial fail, rc=3 - could not reset */ * Priority IBN, IFC, ITN.
} */
} if ((nlent->iflags & IP_IBN) && ((localoptions & NOIBN) == 0)) {
tcp_mode = TCPMODE_IBN;
if (rc == 0) { Syslog('d', "TCP/IP mode set to IBN");
if (!inetaddr) } else if ((nlent->iflags & IP_IFC) && ((localoptions & NOIFC) == 0)) {
nolocalport(); tcp_mode = TCPMODE_IFC;
Syslog('d', "TCP/IP mode set to IFC");
if (tcp_mode == TCPMODE_IBN) } else if ((nlent->iflags & IP_ITN) && ((localoptions & NOITN) == 0)) {
rc = session(addr,nlent,SESSION_MASTER,SESSION_BINKP,NULL); tcp_mode = TCPMODE_ITN;
else Syslog('d', "TCP/IP mode seto to ITN");
rc = session(addr,nlent,SESSION_MASTER,SESSION_UNKNOWN,NULL);
if (rc)
rc=abs(rc)+10;
}
IsDoing("Disconnect");
if (inetaddr) {
closetcp();
} else { } else {
hangup(); Syslog('+', "No common TCP/IP protocols for node %s", nlent->name);
if (rc == 0) free(inetaddr);
aftercall(); inetaddr = NULL;
localport();
closeport();
} }
}
} else { } else {
IsDoing("NoCall"); WriteError("No IP address, abort call");
Syslog('+', "Cannot call %s (%s, phone %s)", ascfnode(addr,0x1f),MBSE_SS(nlent->name), MBSE_SS(nlent->phone)); rc = ST_NOCALL8;
if ((nlent->phone || forcedphone || inetaddr )) putstatus(addr, 10, rc);
rc=ST_NOCALL8; nodeulock(addr);
else return rc;
rc=ST_NOCALL7; }
putstatus(addr, 10, rc); }
if (((nlent->oflags & OL_CM) == 0) && (!IsZMH())) {
Syslog('?', "Warning: calling MO system outside ZMH");
}
if (inbound)
free(inbound);
inbound = xstrcpy(CFG.pinbound); /* master sessions are secure */
/*
* Call when:
* the nodelist has a phone, or phone on commandline, or TCP address given
* and
* nodenumber on commandline, or node is CM and not down, hold, pvt
* and
* nocall is false
*/
if ((nlent->phone || forcedphone || inetaddr ) &&
(forcedcalls || (((nlent->pflag & (NL_DUMMY|NL_DOWN|NL_HOLD|NL_PVT)) == 0) && ((localoptions & NOCALL) == 0)))) {
Syslog('+', "Calling %s (%s, phone %s)",ascfnode(addr,0x1f), nlent->name,nlent->phone?nlent->phone:forcedphone);
IsDoing("Call %s", ascfnode(addr, 0x0f));
rc = portopen(addr);
if ((rc == 0) && (!inetaddr)) {
if ((rc = dialphone(forcedphone?forcedphone:nlent->phone))) {
Syslog('+', "Dial failed");
nodeulock(addr); nodeulock(addr);
return rc; rc+=1; /* rc=2 - dial fail, rc=3 - could not reset */
}
} }
if ((rc > 10) && (rc < 20)) /* Session error */ if (rc == 0) {
putstatus(addr, 5, rc); if (!inetaddr)
else if ((rc == 2) || (rc == 30)) nolocalport();
putstatus(addr,1,rc);
else if (tcp_mode == TCPMODE_IBN)
putstatus(addr,0,rc); rc = session(addr,nlent,SESSION_MASTER,SESSION_BINKP,NULL);
else
rc = session(addr,nlent,SESSION_MASTER,SESSION_UNKNOWN,NULL);
if (rc)
rc=abs(rc)+10;
}
IsDoing("Disconnect");
if (inetaddr) {
closetcp();
} else {
hangup();
localport();
closeport();
if (strlen(modem.info)) {
/*
* If mode info string defined, open port again to get
* the aftercall information. Mostly used with ISDN.
*/
portopen(addr);
aftercall();
closeport();
}
}
} else {
IsDoing("NoCall");
Syslog('+', "Cannot call %s (%s, phone %s)", ascfnode(addr,0x1f),MBSE_SS(nlent->name), MBSE_SS(nlent->phone));
if ((nlent->phone || forcedphone || inetaddr ))
rc=ST_NOCALL8;
else
rc=ST_NOCALL7;
putstatus(addr, 10, rc);
nodeulock(addr);
return rc; return rc;
}
if ((rc > 10) && (rc < 20)) /* Session error */
putstatus(addr, 5, rc);
else if ((rc == 2) || (rc == 30))
putstatus(addr,1,rc);
else
putstatus(addr,0,rc);
return rc;
} }

View File

@ -43,43 +43,42 @@
char *tranphone(char *Phone) char *tranphone(char *Phone)
{ {
static char trp[21]; static char trp[21];
char buf[21]; char buf[21], *p;
char *p; int ln, i, j;
int ln, i, j;
if (Phone == NULL) if (Phone == NULL)
return NULL; return NULL;
strncpy(trp,Phone,sizeof(trp)-1); strncpy(trp,Phone,sizeof(trp)-1);
for (i = 0; i < 40; i++) for (i = 0; i < 40; i++)
if (strlen(CFG.phonetrans[i].match) || strlen(CFG.phonetrans[i].repl)) { if (strlen(CFG.phonetrans[i].match) || strlen(CFG.phonetrans[i].repl)) {
memset(&buf, 0, sizeof(buf)); memset(&buf, 0, sizeof(buf));
strncpy(buf,CFG.phonetrans[i].match,strlen(CFG.phonetrans[i].match)); strncpy(buf,CFG.phonetrans[i].match,strlen(CFG.phonetrans[i].match));
ln=strlen(buf); ln=strlen(buf);
p = xstrcpy(CFG.phonetrans[i].repl); p = xstrcpy(CFG.phonetrans[i].repl);
if (strncmp(Phone,buf,ln) == 0) { if (strncmp(Phone,buf,ln) == 0) {
strcpy(trp,p); strcpy(trp,p);
strncat(trp,Phone+ln,sizeof(trp)-strlen(p)-1); strncat(trp,Phone+ln,sizeof(trp)-strlen(p)-1);
free(p); free(p);
break; break;
} else { } else {
free(p); free(p);
} }
}
if (modem.stripdash) {
j = 0;
for (i = 0; i < strlen(trp); i++) {
if (trp[i] != '-') {
trp[j] = trp[i];
j++;
}
}
trp[j] = '\0';
} }
return trp;
if (modem.stripdash) {
j = 0;
for (i = 0; i < strlen(trp); i++) {
if (trp[i] != '-') {
trp[j] = trp[i];
j++;
}
}
trp[j] = '\0';
}
return trp;
} }
@ -87,53 +86,53 @@ char *tranphone(char *Phone)
int send_str(char *, char *); int send_str(char *, char *);
int send_str(char *str, char *Phone) int send_str(char *str, char *Phone)
{ {
char *p, *q; char *p, *q;
static char logs[81]; static char logs[81];
p = str; p = str;
memset(&logs, 0, sizeof(logs)); memset(&logs, 0, sizeof(logs));
q = logs; q = logs;
while (*p) { while (*p) {
if (*p == '\\') { if (*p == '\\') {
switch (*++p) { switch (*++p) {
case '\0': p--; break; case '\0': p--; break;
case '\\': PUTCHAR('\\'); *q++ = '\\'; break; case '\\': PUTCHAR('\\'); *q++ = '\\'; break;
case 'r': PUTCHAR('\r'); *q++ = '\\'; *q++ = 'r'; break; case 'r': PUTCHAR('\r'); *q++ = '\\'; *q++ = 'r'; break;
case 'n': PUTCHAR('\n'); *q++ = '\\'; *q++ = 'n'; break; case 'n': PUTCHAR('\n'); *q++ = '\\'; *q++ = 'n'; break;
case 't': PUTCHAR('\t'); *q++ = '\\'; *q++ = 't'; break; case 't': PUTCHAR('\t'); *q++ = '\\'; *q++ = 't'; break;
case 'b': PUTCHAR('\b'); *q++ = '\\'; *q++ = 'b'; break; case 'b': PUTCHAR('\b'); *q++ = '\\'; *q++ = 'b'; break;
case 's': PUTCHAR(' '); *q++ = ' '; break; case 's': PUTCHAR(' '); *q++ = ' '; break;
case ' ': PUTCHAR(' '); *q++ = ' '; break; case ' ': PUTCHAR(' '); *q++ = ' '; break;
case 'd': sleep(1); *q++ = '\\'; *q++ = 'd'; break; case 'd': sleep(1); *q++ = '\\'; *q++ = 'd'; break;
case 'p': usleep(250000L); *q++ = '\\'; *q++ = 'p'; break; case 'p': usleep(250000L); *q++ = '\\'; *q++ = 'p'; break;
case 'D': if (Phone) { case 'D': if (Phone) {
PUTSTR(Phone); PUTSTR(Phone);
sprintf(q, "%s", Phone); sprintf(q, "%s", Phone);
} }
break; break;
case 'T': if (Phone) { case 'T': if (Phone) {
PUTSTR(tranphone(Phone)); PUTSTR(tranphone(Phone));
sprintf(q, "%s", tranphone(Phone)); sprintf(q, "%s", tranphone(Phone));
} }
break; break;
default: PUTCHAR(*p); *q++ = *p; break; default: PUTCHAR(*p); *q++ = *p; break;
} }
while (*q) while (*q)
q++; q++;
} else { } else {
PUTCHAR(*p); PUTCHAR(*p);
*q++ = *p; *q++ = *p;
}
p++;
} }
Syslog('+', "chat: snd \"%s\"", logs); p++;
}
Syslog('+', "chat: snd \"%s\"", logs);
if (STATUS) { if (STATUS) {
WriteError("$chat: send_str error %d", STATUS); WriteError("$chat: send_str error %d", STATUS);
return 1; return 1;
} else } else
return 0; return 0;
} }
@ -143,94 +142,93 @@ static int expired = FALSE;
void almhdl(int); void almhdl(int);
void almhdl(int sig) void almhdl(int sig)
{ {
expired = TRUE; expired = TRUE;
Syslog('c' ,"chat: timeout"); Syslog('c' ,"chat: timeout");
return; return;
} }
int expect_str(int, char *); int expect_str(int, int, char *);
int expect_str(int timeout, char *Phone) int expect_str(int timeout, int aftermode, char *Phone)
{ {
int matched = FALSE; int matched = FALSE, smatch = FALSE, ematch = FALSE, ioerror = FALSE, i, rc;
int smatch = FALSE; char inbuf[256];
int ematch = FALSE; unsigned char ch = '\0';
int ioerror = FALSE; int eol = FALSE;
int i, rc;
char inbuf[256];
unsigned char ch = '\0';
int eol = FALSE;
expired = FALSE; expired = FALSE;
signal(SIGALRM, almhdl); signal(SIGALRM, almhdl);
alarm(timeout); alarm(timeout);
while (!matched && !expired && !ioerror && !feof(stdin)) { while (!matched && !expired && !ioerror && !feof(stdin)) {
eol = FALSE; eol = FALSE;
i = 0; i = 0;
memset(&inbuf, 0, sizeof(inbuf)); memset(&inbuf, 0, sizeof(inbuf));
while (!ioerror && !feof(stdin) && !eol && (i < 255)) { while (!ioerror && !feof(stdin) && !eol && (i < 255)) {
if ((rc = read(0, &ch, 1)) != 1) { if ((rc = read(0, &ch, 1)) != 1) {
ioerror = TRUE; ioerror = TRUE;
} else { } else {
switch(ch) { switch(ch) {
case '\n': break; case '\n': break;
case '\r': inbuf[i++] = '\r'; case '\r': inbuf[i++] = '\r';
eol = TRUE; eol = TRUE;
break; break;
default: inbuf[i++] = ch; default: inbuf[i++] = ch;
} }
} }
if (expired) if (expired)
Syslog('c', "chat: got TIMEOUT"); Syslog('c', "chat: got TIMEOUT");
}
inbuf[i] = '\0';
if (aftermode && strcmp(inbuf, (char *)"OK\r") && strcmp(inbuf, (char *)"\r"))
Syslog('+', "chat: rcv \"%s\"", printable(inbuf, 0));
else
Syslog('c', "chat: rcv \"%s\"", printable(inbuf, 0));
for (i = 0; (i < 10) && !matched; i++)
if (strlen(modem.error[i]))
if (strncmp(modem.error[i], inbuf, strlen(modem.error[i])) == 0) {
matched = TRUE;
ematch = TRUE;
Syslog('+', "chat: got \"%s\", aborting", printable(inbuf, 0));
} }
inbuf[i] = '\0'; if (Phone != NULL)
Syslog('c', "chat: rcv \"%s\"", printable(inbuf, 0)); for (i = 0; (i < 20) && !matched; i++)
if (strlen(modem.connect[i]))
if (strncmp(modem.connect[i], inbuf, strlen(modem.connect[i])) == 0) {
matched = TRUE;
smatch = TRUE;
Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
}
for (i = 0; (i < 10) && !matched; i++) if (!matched)
if (strlen(modem.error[i])) if (strlen(modem.ok))
if (strncmp(modem.error[i], inbuf, strlen(modem.error[i])) == 0) { if (strncmp(modem.ok, inbuf, strlen(modem.ok)) == 0) {
matched = TRUE; matched = TRUE;
ematch = TRUE; smatch = TRUE;
Syslog('+', "chat: got \"%s\", aborting", printable(inbuf, 0)); Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
} }
if (Phone != NULL) if (expired)
for (i = 0; (i < 20) && !matched; i++) Syslog('+', "chat: got timeout, aborting");
if (strlen(modem.connect[i])) else
if (strncmp(modem.connect[i], inbuf, strlen(modem.connect[i])) == 0) { if (ferror(stdin))
matched = TRUE; Syslog('+', "chat: got error, aborting");
smatch = TRUE;
Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
}
if (!matched) if (feof(stdin))
if (strlen(modem.ok)) WriteError("$chat: got EOF, aborting");
if (strncmp(modem.ok, inbuf, strlen(modem.ok)) == 0) { }
matched = TRUE; alarm(0);
smatch = TRUE; signal(SIGALRM, SIG_DFL);
Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
}
if (expired) rc = !(matched && smatch);
Syslog('+', "chat: got timeout, aborting"); return rc;
else
if (ferror(stdin))
Syslog('+', "chat: got error, aborting");
if (feof(stdin))
WriteError("$chat: got EOF, aborting");
}
alarm(0);
signal(SIGALRM, SIG_DFL);
rc = !(matched && smatch);
return rc;
} }
@ -241,14 +239,14 @@ int expect_str(int timeout, char *Phone)
* The phone number must be full international notation unless the \D * The phone number must be full international notation unless the \D
* macro is in the dial command. * macro is in the dial command.
*/ */
int chat(char *Send, int timeout, char *Phone) int chat(char *Send, int timeout, int aftermode, char *Phone)
{ {
int rc; int rc;
if ((rc = send_str(Send, Phone)) == 0) if ((rc = send_str(Send, Phone)) == 0)
rc = expect_str(timeout, Phone); rc = expect_str(timeout, aftermode, Phone);
return rc; return rc;
} }

View File

@ -1,8 +1,10 @@
#ifndef _CHAT_H #ifndef _CHAT_H
#define _CHAT_H #define _CHAT_H
/* $Id$ */
char *tranphone(char *); char *tranphone(char *);
int chat(char *, int, char *); int chat(char *, int, int, char *);
#endif #endif

View File

@ -44,123 +44,120 @@
#include "dial.h" #include "dial.h"
extern time_t c_start; extern time_t c_start;
extern time_t c_end; extern time_t c_end;
extern int online; extern int online;
extern int master; extern int master;
int carrier; int carrier;
extern long sentbytes; extern long sentbytes;
extern long rcvdbytes; extern long rcvdbytes;
extern int Loaded; extern int Loaded;
int initmodem(void) int initmodem(void)
{ {
int i; int i;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (strlen(modem.init[i])) if (strlen(modem.init[i]))
if (chat(modem.init[i], CFG.timeoutreset, NULL)) { if (chat(modem.init[i], CFG.timeoutreset, FALSE, NULL)) {
WriteError("dial: could not reset the modem"); WriteError("dial: could not reset the modem");
return 1; return 1;
} }
return 0; return 0;
} }
int dialphone(char *Phone) int dialphone(char *Phone)
{ {
int rc; int rc;
Syslog('+', "dial: %s (%s)",MBSE_SS(Phone), MBSE_SS(tranphone(Phone))); Syslog('+', "dial: %s (%s)",MBSE_SS(Phone), MBSE_SS(tranphone(Phone)));
carrier = FALSE; carrier = FALSE;
if (initmodem()) if (initmodem())
return 2; return 2;
rc = 0; rc = 0;
if (strlen(nodes.phone[0])) { if (strlen(nodes.phone[0])) {
if (strlen(nodes.dial)) if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, nodes.phone[0]); rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, nodes.phone[0]);
else else
rc = chat(modem.dial, CFG.timeoutconnect, nodes.phone[0]); rc = chat(modem.dial, CFG.timeoutconnect, FALSE, nodes.phone[0]);
if ((rc == 0) && strlen(nodes.phone[1])) { if ((rc == 0) && strlen(nodes.phone[1])) {
if (strlen(nodes.dial)) if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, nodes.phone[1]); rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, nodes.phone[1]);
else else
rc = chat(modem.dial, CFG.timeoutconnect, nodes.phone[1]); rc = chat(modem.dial, CFG.timeoutconnect, FALSE, nodes.phone[1]);
}
} else {
if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, Phone);
else
rc = chat(modem.dial, CFG.timeoutconnect, Phone);
} }
} else {
if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, Phone);
else
rc = chat(modem.dial, CFG.timeoutconnect, FALSE, Phone);
}
if (rc) { if (rc) {
Syslog('+', "Could not connect to the remote"); Syslog('+', "Could not connect to the remote");
return 1; return 1;
} else { } else {
c_start = time(NULL); c_start = time(NULL);
carrier = TRUE; carrier = TRUE;
return 0; return 0;
} }
} }
int hangup() int hangup()
{ {
char *tmp; char *tmp;
FILE *fp; FILE *fp;
FLUSHIN(); FLUSHIN();
FLUSHOUT(); FLUSHOUT();
if (strlen(modem.hangup)) if (strlen(modem.hangup))
chat(modem.hangup, CFG.timeoutreset, NULL); chat(modem.hangup, CFG.timeoutreset, FALSE, NULL);
if (carrier) { if (carrier) {
c_end = time(NULL); c_end = time(NULL);
online += (c_end - c_start); online += (c_end - c_start);
Syslog('+', "Connection time %s", t_elapsed(c_start, c_end)); Syslog('+', "Connection time %s", t_elapsed(c_start, c_end));
carrier = FALSE; carrier = FALSE;
history.offline = c_end; history.offline = c_end;
history.online = c_start; history.online = c_start;
history.sent_bytes = sentbytes; history.sent_bytes = sentbytes;
history.rcvd_bytes = rcvdbytes; history.rcvd_bytes = rcvdbytes;
history.inbound = ~master; history.inbound = ~master;
tmp = calloc(128, sizeof(char)); tmp = calloc(128, sizeof(char));
sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT")); sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
if ((fp = fopen(tmp, "a")) == NULL) if ((fp = fopen(tmp, "a")) == NULL)
WriteError("$Can't open %s", tmp); WriteError("$Can't open %s", tmp);
else { else {
fwrite(&history, sizeof(history), 1, fp); fwrite(&history, sizeof(history), 1, fp);
fclose(fp); fclose(fp);
}
free(tmp);
memset(&history, 0, sizeof(history));
if (Loaded) {
nodes.LastDate = time(NULL);
UpdateNode();
}
} }
FLUSHIN(); free(tmp);
FLUSHOUT(); memset(&history, 0, sizeof(history));
return 0; if (Loaded) {
nodes.LastDate = time(NULL);
UpdateNode();
}
}
FLUSHIN();
FLUSHOUT();
return 0;
} }
int aftercall() void aftercall()
{ {
if (strlen(modem.info)) { Syslog('d', "Reading link stat (aftercall)");
Syslog('d', "Reading link stat (aftercall)"); FLUSHIN();
FLUSHIN(); FLUSHOUT();
FLUSHOUT(); chat(modem.info, CFG.timeoutreset, TRUE, NULL);
chat(modem.info, CFG.timeoutreset, NULL);
}
return 0;
} }

View File

@ -1,11 +1,11 @@
#ifndef _DIAL_H #ifndef _DIAL_H
#define _DIAL_H #define _DIAL_H
int dialphone(char *); /* $Id$ */
int hangup(void);
int aftercall(void);
int dialphone(char *);
int hangup(void);
void aftercall(void);
#endif #endif