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:
Implemented nodes special outbound boxes.
Corrected a problem with getting modem aftercall info for ISDN
modems.
mbout:
Implemented nodes special outbound boxes.

View File

@ -60,240 +60,247 @@ extern char *inetaddr;
int portopen(faddr *addr)
{
char *p;
int rc;
char *p;
int rc;
if (inetaddr) {
Syslog('d', "portopen inetaddr %s", inetaddr);
if ((rc = opentcp(inetaddr))) {
Syslog('+', "Cannot connect %s", inetaddr);
nodeulock(addr);
putstatus(addr,1,ST_NOCONN);
return ST_NOCONN;
}
return 0;
if (inetaddr) {
Syslog('d', "portopen inetaddr %s", inetaddr);
if ((rc = opentcp(inetaddr))) {
Syslog('+', "Cannot connect %s", inetaddr);
nodeulock(addr);
putstatus(addr,1,ST_NOCONN);
return ST_NOCONN;
}
return 0;
}
if (forcedline) {
Syslog('d', "portopen forcedline %s", forcedline);
p = forcedline;
strncpy(history.tty, p, 6);
if (forcedline) {
Syslog('d', "portopen forcedline %s", forcedline);
p = forcedline;
strncpy(history.tty, p, 6);
if (load_port(p)) {
if ((rc = openport(p, ttyinfo.portspeed))) {
Syslog('+', "Cannot open port %s",p);
nodeulock(addr);
putstatus(addr, 10, ST_PORTERR);
return ST_PORTERR;
}
return ST_PORTOK;
} else {
nodeulock(addr);
putstatus(addr, 0, ST_PORTERR);
return ST_PORTERR;
}
if (load_port(p)) {
if ((rc = openport(p, ttyinfo.portspeed))) {
Syslog('+', "Cannot open port %s",p);
nodeulock(addr);
putstatus(addr, 10, ST_PORTERR);
return ST_PORTERR;
}
return ST_PORTOK;
} else {
nodeulock(addr);
putstatus(addr, 0, ST_PORTERR);
return ST_PORTERR;
}
}
WriteError("No call method available");
return ST_PORTERR;
WriteError("No call method available, maybe missing parameters");
return ST_PORTERR;
}
int call(faddr *addr)
{
int i, rc = 1;
struct hostent *he;
int i, rc = 1;
struct hostent *he;
/*
* Don't call points, call their boss instead.
*/
addr->point = 0;
/*
* Don't call points, call their boss instead.
*/
addr->point = 0;
/*
* First check if node is locked, if not lock it immediatly
* or stop further waste of time and logfile space.
*/
if (nodelock(addr)) {
Syslog('+', "System %s is locked", ascfnode(addr, 0x1f));
putstatus(addr, 0, ST_LOCKED);
return ST_LOCKED;
}
/*
* First check if node is locked, if not lock it immediatly
* or stop further waste of time and logfile space.
*/
if (nodelock(addr)) {
Syslog('+', "System %s is locked", ascfnode(addr, 0x1f));
putstatus(addr, 0, ST_LOCKED);
return ST_LOCKED;
}
if ((nlent = getnlent(addr)) == NULL) {
WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f));
putstatus(addr,0,ST_LOOKUP);
nodeulock(addr);
return ST_LOOKUP;
}
if ((nlent = getnlent(addr)) == NULL) {
WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f));
putstatus(addr,0,ST_LOOKUP);
nodeulock(addr);
return ST_LOOKUP;
}
/*
* Load the noderecord if the node is in the setup.
*/
noderecord(addr);
rdoptions(TRUE);
/*
* Load the noderecord if the node is in the setup.
*/
noderecord(addr);
rdoptions(TRUE);
/*
* Fill default history info in case we get a FTS0001 session
*/
strncpy(history.system_name, nlent->name, 35);
strncpy(history.location, nlent->location, 35);
strncpy(history.sysop, nlent->sysop, 35);
history.aka.zone = addr->zone;
history.aka.net = addr->net;
history.aka.node = addr->node;
history.aka.point = addr->point;
if (addr->domain && strlen(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");
}
}
}
/*
* Fill default history info in case we get a FTS0001 session
*/
strncpy(history.system_name, nlent->name, 35);
strncpy(history.location, nlent->location, 35);
strncpy(history.sysop, nlent->sysop, 35);
history.aka.zone = addr->zone;
history.aka.net = addr->net;
history.aka.node = addr->node;
history.aka.point = addr->point;
if (addr->domain && strlen(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 {
/*
* If we have an internet address, set protocol
* Try to find the fdn in several places in the nodelist fields.
*/
if (inetaddr) {
RegTCP();
Syslog('d', "TCP/IP node \"%s\"", MBSE_SS(inetaddr));
if (tcp_mode == TCPMODE_NONE) {
/*
* If protocol not forced at the commandline, get it
* from the nodelist. If it fails, fallback to dial.
* Priority IBN, IFC, ITN.
*/
if ((nlent->iflags & IP_IBN) && ((localoptions & NOIBN) == 0)) {
tcp_mode = TCPMODE_IBN;
Syslog('d', "TCP/IP mode set to IBN");
} else if ((nlent->iflags & IP_IFC) && ((localoptions & NOIFC) == 0)) {
tcp_mode = TCPMODE_IFC;
Syslog('d', "TCP/IP mode set to IFC");
} 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->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");
}
}
}
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 we have an internet address, set protocol
*/
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 (inetaddr) {
RegTCP();
Syslog('d', "TCP/IP node \"%s\"", MBSE_SS(inetaddr));
if ((rc == 0) && (!inetaddr)) {
if ((rc = dialphone(forcedphone?forcedphone:nlent->phone))) {
Syslog('+', "Dial failed");
nodeulock(addr);
rc+=1; /* rc=2 - dial fail, rc=3 - could not reset */
}
}
if (rc == 0) {
if (!inetaddr)
nolocalport();
if (tcp_mode == TCPMODE_IBN)
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();
if (tcp_mode == TCPMODE_NONE) {
/*
* If protocol not forced at the commandline, get it
* from the nodelist. If it fails, fallback to dial.
* Priority IBN, IFC, ITN.
*/
if ((nlent->iflags & IP_IBN) && ((localoptions & NOIBN) == 0)) {
tcp_mode = TCPMODE_IBN;
Syslog('d', "TCP/IP mode set to IBN");
} else if ((nlent->iflags & IP_IFC) && ((localoptions & NOIFC) == 0)) {
tcp_mode = TCPMODE_IFC;
Syslog('d', "TCP/IP mode set to IFC");
} else if ((nlent->iflags & IP_ITN) && ((localoptions & NOITN) == 0)) {
tcp_mode = TCPMODE_ITN;
Syslog('d', "TCP/IP mode seto to ITN");
} else {
hangup();
if (rc == 0)
aftercall();
localport();
closeport();
Syslog('+', "No common TCP/IP protocols for node %s", nlent->name);
free(inetaddr);
inetaddr = NULL;
}
}
} 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);
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:
* 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);
return rc;
rc+=1; /* rc=2 - dial fail, rc=3 - could not reset */
}
}
if ((rc > 10) && (rc < 20)) /* Session error */
putstatus(addr, 5, rc);
else if ((rc == 2) || (rc == 30))
putstatus(addr,1,rc);
if (rc == 0) {
if (!inetaddr)
nolocalport();
if (tcp_mode == TCPMODE_IBN)
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
putstatus(addr,0,rc);
rc=ST_NOCALL7;
putstatus(addr, 10, rc);
nodeulock(addr);
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)
{
static char trp[21];
char buf[21];
char *p;
int ln, i, j;
static char trp[21];
char buf[21], *p;
int ln, i, j;
if (Phone == NULL)
return NULL;
strncpy(trp,Phone,sizeof(trp)-1);
if (Phone == NULL)
return NULL;
strncpy(trp,Phone,sizeof(trp)-1);
for (i = 0; i < 40; i++)
if (strlen(CFG.phonetrans[i].match) || strlen(CFG.phonetrans[i].repl)) {
memset(&buf, 0, sizeof(buf));
strncpy(buf,CFG.phonetrans[i].match,strlen(CFG.phonetrans[i].match));
ln=strlen(buf);
p = xstrcpy(CFG.phonetrans[i].repl);
for (i = 0; i < 40; i++)
if (strlen(CFG.phonetrans[i].match) || strlen(CFG.phonetrans[i].repl)) {
memset(&buf, 0, sizeof(buf));
strncpy(buf,CFG.phonetrans[i].match,strlen(CFG.phonetrans[i].match));
ln=strlen(buf);
p = xstrcpy(CFG.phonetrans[i].repl);
if (strncmp(Phone,buf,ln) == 0) {
strcpy(trp,p);
strncat(trp,Phone+ln,sizeof(trp)-strlen(p)-1);
free(p);
break;
} else {
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';
if (strncmp(Phone,buf,ln) == 0) {
strcpy(trp,p);
strncat(trp,Phone+ln,sizeof(trp)-strlen(p)-1);
free(p);
break;
} else {
free(p);
}
}
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 *str, char *Phone)
{
char *p, *q;
static char logs[81];
char *p, *q;
static char logs[81];
p = str;
memset(&logs, 0, sizeof(logs));
q = logs;
p = str;
memset(&logs, 0, sizeof(logs));
q = logs;
while (*p) {
if (*p == '\\') {
switch (*++p) {
case '\0': p--; break;
case '\\': PUTCHAR('\\'); *q++ = '\\'; break;
case 'r': PUTCHAR('\r'); *q++ = '\\'; *q++ = 'r'; break;
case 'n': PUTCHAR('\n'); *q++ = '\\'; *q++ = 'n'; break;
case 't': PUTCHAR('\t'); *q++ = '\\'; *q++ = 't'; break;
case 'b': PUTCHAR('\b'); *q++ = '\\'; *q++ = 'b'; break;
case 's': PUTCHAR(' '); *q++ = ' '; break;
case ' ': PUTCHAR(' '); *q++ = ' '; break;
case 'd': sleep(1); *q++ = '\\'; *q++ = 'd'; break;
case 'p': usleep(250000L); *q++ = '\\'; *q++ = 'p'; break;
case 'D': if (Phone) {
PUTSTR(Phone);
sprintf(q, "%s", Phone);
}
break;
case 'T': if (Phone) {
PUTSTR(tranphone(Phone));
sprintf(q, "%s", tranphone(Phone));
}
break;
default: PUTCHAR(*p); *q++ = *p; break;
}
while (*q)
q++;
} else {
PUTCHAR(*p);
*q++ = *p;
}
p++;
while (*p) {
if (*p == '\\') {
switch (*++p) {
case '\0': p--; break;
case '\\': PUTCHAR('\\'); *q++ = '\\'; break;
case 'r': PUTCHAR('\r'); *q++ = '\\'; *q++ = 'r'; break;
case 'n': PUTCHAR('\n'); *q++ = '\\'; *q++ = 'n'; break;
case 't': PUTCHAR('\t'); *q++ = '\\'; *q++ = 't'; break;
case 'b': PUTCHAR('\b'); *q++ = '\\'; *q++ = 'b'; break;
case 's': PUTCHAR(' '); *q++ = ' '; break;
case ' ': PUTCHAR(' '); *q++ = ' '; break;
case 'd': sleep(1); *q++ = '\\'; *q++ = 'd'; break;
case 'p': usleep(250000L); *q++ = '\\'; *q++ = 'p'; break;
case 'D': if (Phone) {
PUTSTR(Phone);
sprintf(q, "%s", Phone);
}
break;
case 'T': if (Phone) {
PUTSTR(tranphone(Phone));
sprintf(q, "%s", tranphone(Phone));
}
break;
default: PUTCHAR(*p); *q++ = *p; break;
}
while (*q)
q++;
} else {
PUTCHAR(*p);
*q++ = *p;
}
Syslog('+', "chat: snd \"%s\"", logs);
p++;
}
Syslog('+', "chat: snd \"%s\"", logs);
if (STATUS) {
WriteError("$chat: send_str error %d", STATUS);
return 1;
} else
return 0;
if (STATUS) {
WriteError("$chat: send_str error %d", STATUS);
return 1;
} else
return 0;
}
@ -143,94 +142,93 @@ static int expired = FALSE;
void almhdl(int);
void almhdl(int sig)
{
expired = TRUE;
Syslog('c' ,"chat: timeout");
return;
expired = TRUE;
Syslog('c' ,"chat: timeout");
return;
}
int expect_str(int, char *);
int expect_str(int timeout, char *Phone)
int expect_str(int, int, char *);
int expect_str(int timeout, int aftermode, char *Phone)
{
int matched = FALSE;
int smatch = FALSE;
int ematch = FALSE;
int ioerror = FALSE;
int i, rc;
char inbuf[256];
unsigned char ch = '\0';
int eol = FALSE;
int matched = FALSE, smatch = FALSE, ematch = FALSE, ioerror = FALSE, i, rc;
char inbuf[256];
unsigned char ch = '\0';
int eol = FALSE;
expired = FALSE;
signal(SIGALRM, almhdl);
alarm(timeout);
expired = FALSE;
signal(SIGALRM, almhdl);
alarm(timeout);
while (!matched && !expired && !ioerror && !feof(stdin)) {
while (!matched && !expired && !ioerror && !feof(stdin)) {
eol = FALSE;
i = 0;
memset(&inbuf, 0, sizeof(inbuf));
eol = FALSE;
i = 0;
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) {
ioerror = TRUE;
} else {
switch(ch) {
case '\n': break;
case '\r': inbuf[i++] = '\r';
eol = TRUE;
break;
default: inbuf[i++] = ch;
}
}
if (expired)
Syslog('c', "chat: got TIMEOUT");
if ((rc = read(0, &ch, 1)) != 1) {
ioerror = TRUE;
} else {
switch(ch) {
case '\n': break;
case '\r': inbuf[i++] = '\r';
eol = TRUE;
break;
default: inbuf[i++] = ch;
}
}
if (expired)
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';
Syslog('c', "chat: rcv \"%s\"", printable(inbuf, 0));
if (Phone != NULL)
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 (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));
}
if (!matched)
if (strlen(modem.ok))
if (strncmp(modem.ok, inbuf, strlen(modem.ok)) == 0) {
matched = TRUE;
smatch = TRUE;
Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
}
if (Phone != NULL)
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));
}
if (expired)
Syslog('+', "chat: got timeout, aborting");
else
if (ferror(stdin))
Syslog('+', "chat: got error, aborting");
if (!matched)
if (strlen(modem.ok))
if (strncmp(modem.ok, inbuf, strlen(modem.ok)) == 0) {
matched = TRUE;
smatch = TRUE;
Syslog('+', "chat: got \"%s\", continue", printable(inbuf, 0));
}
if (feof(stdin))
WriteError("$chat: got EOF, aborting");
}
alarm(0);
signal(SIGALRM, SIG_DFL);
if (expired)
Syslog('+', "chat: got timeout, aborting");
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;
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
* 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)
rc = expect_str(timeout, Phone);
if ((rc = send_str(Send, Phone)) == 0)
rc = expect_str(timeout, aftermode, Phone);
return rc;
return rc;
}

View File

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

View File

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

View File

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