#include "tip.h"
acu_t* unidialer_getmodem (const char *modem_name);
static acu_t *acu = NULL;
static int conflag;
static void acuabort(int);
static acu_t *acutype(char *);
static jmp_buf jmpbuf;
char *
connect(void)
{
char *cp = PN;
char *phnum, string[256];
FILE *fd;
int tried = 0;
if (!DU) {
if (CM != NULL)
xpwrite(FD, CM, size(CM));
logent(value(HOST), "", DV, "call completed");
return (NULL);
}
signal(SIGINT, acuabort);
signal(SIGQUIT, acuabort);
if (setjmp(jmpbuf)) {
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
printf("\ncall aborted\n");
logent(value(HOST), "", "", "call aborted");
if (acu != NULL) {
boolean(value(VERBOSE)) = FALSE;
if (conflag)
disconnect(NULL);
else
(*acu->acu_abort)();
}
return ("interrupt");
}
if ((acu = acutype(AT)) == NULL)
return ("unknown ACU type");
if (*cp != '@') {
while (*cp) {
for (phnum = cp; *cp && *cp != ','; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU))) {
if (CM != NULL)
xpwrite(FD, CM, size(CM));
logent(value(HOST), phnum, acu->acu_name,
"call completed");
return (NULL);
} else
logent(value(HOST), phnum, acu->acu_name,
"call failed");
tried++;
}
} else {
if ((fd = fopen(PH, "r")) == NULL) {
printf("%s: ", PH);
return ("can't open phone number file");
}
while (fgets(string, sizeof(string), fd) != NULL) {
for (cp = string; !any(*cp, " \t\n"); cp++)
;
if (*cp == '\n') {
fclose(fd);
return ("unrecognizable host name");
}
*cp++ = '\0';
if (strcmp(string, value(HOST)))
continue;
while (any(*cp, " \t"))
cp++;
if (*cp == '\n') {
fclose(fd);
return ("missing phone number");
}
for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU))) {
fclose(fd);
if (CM != NULL)
xpwrite(FD, CM, size(CM));
logent(value(HOST), phnum, acu->acu_name,
"call completed");
return (NULL);
} else
logent(value(HOST), phnum, acu->acu_name,
"call failed");
tried++;
}
fclose(fd);
}
if (!tried)
logent(value(HOST), "", acu->acu_name, "missing phone number");
else
(*acu->acu_abort)();
return (tried ? "call failed" : "missing phone number");
}
void
disconnect(char *reason)
{
if (!conflag) {
logent(value(HOST), "", DV, "call terminated");
return;
}
if (reason == NULL) {
logent(value(HOST), "", acu->acu_name, "call terminated");
if (boolean(value(VERBOSE)))
printf("\r\ndisconnecting...");
} else
logent(value(HOST), "", acu->acu_name, reason);
(*acu->acu_disconnect)();
}
static void
acuabort(int s)
{
signal(s, SIG_IGN);
longjmp(jmpbuf, 1);
}
static acu_t *
acutype(char *s)
{
return unidialer_getmodem (s);
}