home *** CD-ROM | disk | FTP | other *** search
- /*
- * The dialing window routines.
- */
-
- #define MAX_PASS 25
-
- #include <stdio.h>
- #include <curses.h>
- #include <signal.h>
- #include <setjmp.h>
- #include "dial_dir.h"
- #include "misc.h"
- #include "modem.h"
- #include "param.h"
- #include "status.h"
-
- /*
- * The dialing window. Its job is to kill the input routine, get a port,
- * cycle thru the entries in the queue, while interpreting both the
- * user's requests and the modem's responses. A return code of 1 means
- * we're ready to fire up the input mode.
- */
-
- int
- dial_win()
- {
- WINDOW *di_win, *newwin();
- int i, j, ans, want_out, pass, tic, baud, modem_sync;
- long now, time();
- char *tbuf, *ctime(), *str, cr=13, *monitor_dial();
- void disp_queue(), send_str(), dial_it(), delay_times(), input_off();
- void error_win(), status_line(), line_set(), hang_up();
- extern int rc_index;
- unsigned int sleep();
- /* are we already talking? */
- input_off();
- hang_up(1);
-
- if (get_port())
- return(0);
- /*
- * If the phone number is a NULL, then either we are on a
- * direct line, or you want to do the dialing yourself.
- */
- if (*dir->number[dir->q_num[0]] == NULL) {
- /* check LD permission */
- if (limit_ld(0))
- return(0);
- /* can't talk directly to OBM */
- if (!strcmp(modem->mname[modem->m_cur], "OBM")) {
- error_win(0, "Can't access the line directly.", "Use the automatic dialing feature");
- return(0);
- }
- unlink(status->vs_path);
- touchwin(stdscr);
- clear();
- printw("Connected to %s at %d baud...\n", modem->tty[modem->t_cur], dir->baud[dir->d_cur]);
- refresh();
- return(1);
- }
-
- di_win = newwin(17, 70, 3, 5);
- /* the basic window */
- mvwattrstr(di_win, 1, 20, A_BOLD, "D I A L I N G W I N D O W");
- mvwaddstr(di_win, 2, 0, "---------------------------------------------------------------------");
- mvwaddstr(di_win, 4, 23, "System name:");
- mvwaddstr(di_win, 5, 23, "Pass number:");
- mvwaddstr(di_win, 6, 14, "Elapse time this try:");
- mvwaddstr(di_win, 7, 13, "Time at start of dial:");
- mvwaddstr(di_win, 8, 9, "Time at start of this try:");
- mvwaddstr(di_win, 9, 16, "Connect delay time:");
- mvwaddstr(di_win, 10, 15, "Pause between tries:");
- mvwaddstr(di_win, 11, 25, "Index/tty:");
- mvwaddstr(di_win, 12, 16, "Result of last try:");
-
- mvwaddstr(di_win, 14, 3, "SPACE: Recycle");
- mvwaddstr(di_win, 14, 21, "DEL: Remove from queue");
- mvwaddstr(di_win, 14, 46, "E: Change delay times");
-
- /* the start time */
- time(&now);
- tbuf = ctime(&now);
- tbuf[19] = NULL;
- mvwaddstr(di_win, 7, 36, &tbuf[11]);
-
- mvwprintw(di_win, 9, 36, "%-4d", param->cdelay);
- mvwprintw(di_win, 10, 36, "%-4d", param->pause);
-
- box(di_win, '|', '-');
- mvwaddstr(di_win, 16, 25, " Press ESC to abort ");
-
- pass = 0;
- i = 0;
- want_out = 0;
- while (!want_out && pass <= MAX_PASS) {
- ans = -1;
- pass++;
- /* update the d_cur variable */
- dir->d_cur = dir->q_num[i];
- /* check LD permission */
- if (limit_ld(i))
- return(0);
- /* get a port */
- if (get_port())
- return(0);
- /* can the modem sync baud rates ? */
- modem_sync = can_sync();
- /* fill in the window */
- disp_queue(di_win, dir->d_cur, pass);
-
- /*
- * The actual dial routine. The 'i' is the index into the
- * queue, not the entry number. Returns immediately without
- * waiting for a carrier.
- */
- dial_it(i);
- ioctl(status->fd, TCFLSH, 0);
-
- /*
- * Here we do a time-slice between reading the result codes
- * from the modem and reading the keyboard. The one second
- * granularity won't be too accurate, but who cares?
- */
- tic = 0;
- rc_index = 0;
- while (tic < param->cdelay) {
- if (!(str = monitor_dial())) {
- mvwprintw(di_win, 6, 36, "%-4d", ++tic);
- wrefresh(di_win);
- }
- else {
- /*
- * A return code that converts to an number
- * that is less than 300 is probably an error
- * message.
- */
- baud = atoi(str);
- if (baud < 300) {
- mvwprintw(di_win, 12, 36, "%-20.20s", str);
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- break;
- }
- /* we're connected */
- beep();
- clear_line(di_win, 12, 36, 1);
- wattrstr(di_win, A_BLINK, "CONNECTED");
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- wait_key(di_win, 2);
- delwin(di_win);
-
- /*
- * Did the modem sync at a different baud
- * rate than what we expected?
- */
- if (modem_sync) {
- if (dir->baud[dir->d_cur] != baud) {
- dir->baud[dir->d_cur] = baud;
- line_set();
- }
- }
-
- unlink(status->vs_path);
- touchwin(stdscr);
- clear();
- printw("Connected to %s at %d baud...\n",
- dir->name[dir->d_cur], dir->baud[dir->d_cur]);
- refresh();
-
- /* log the call */
- log_calls(i);
- return(1);
- }
- if (tic == param->cdelay)
- break;
- /* ok... try the keyboard */
- if ((ans = wait_key(di_win, 1)) != -1)
- break;
-
- mvwprintw(di_win, 6, 36, "%-4d", ++tic);
- wrefresh(di_win);
- }
- /*
- * If the modem did not return a code, then we need to
- * stop it. Sending a CR will stop most modems cold,
- * except of course for the OBM...
- */
- if (str == NULL) {
- if (!strcmp(modem->mname[modem->m_cur], "OBM"))
- hang_up(0);
- else
- write(status->fd, &cr, 1);
- sleep(1);
- }
- /* if we get here, no key was pressed */
- if (ans == -1) {
- clear_line(di_win, 6, 14, 1);
- mvwaddstr(di_win, 6, 27, "Pausing:");
- /* no return code ? */
- if (str == NULL) {
- clear_line(di_win, 12, 36, 1);
- waddstr(di_win, "TIMED OUT");
- wmove(di_win, 12, 36);
- }
- /* do the pause */
- tic = 0;
- while (tic < param->pause) {
- if ((ans = wait_key(di_win, 1)) != -1)
- break;
- mvwprintw(di_win, 6, 36, "%-4d", ++tic);
- wrefresh(di_win);
- }
- clear_line(di_win, 6, 14, 1);
- waddstr(di_win, "Elapse time this try:");
- }
- /* Process the keystroke */
- switch(ans) {
- case ' ': /* next in the queue */
- clear_line(di_win, 12, 36, 1);
- waddstr(di_win, "RECYCLED");
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- /* fall thru... */
- case -1: /* no key was pressed */
- i++;
- if (i > NUM_QUEUE)
- i = 0;
- if (dir->q_num[i] == -1)
- i = 0;
- break;
- case 127: /* DEL key, remove from queue */
- if (dir->q_num[1] == -1) {
- beep();
- clear_line(di_win, 12, 36, 1);
- waddstr(di_win, "NO MORE ENTRIES");
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- wait_key(di_win, 3);
- break;
- }
- clear_line(di_win, 12, 36, 1);
- waddstr(di_win, "ENTRY DELETED");
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- wait_key(di_win, 3);
-
- /* compact the queue */
- for (j=i; j<NUM_QUEUE-1; j++)
- dir->q_num[j] = dir->q_num[j+1];
- dir->q_num[NUM_QUEUE-1] = -1;
- break;
- case 'e':
- case 'E': /* change delay time */
- delay_times();
- touchwin(di_win);
- mvwprintw(di_win, 9, 36, "%-4d", param->cdelay);
- mvwprintw(di_win, 10, 36, "%-4d", param->pause);
- break;
- case 27: /* ESC key */
- beep();
- clear_line(di_win, 12, 36, 1);
- wattrstr(di_win, A_BLINK, "DIAL ABORTED");
- wmove(di_win, 12, 36);
- wrefresh(di_win);
- wait_key(di_win, 3);
- want_out++;
- break;
- default:
- beep();
- break;
- }
- }
- /* clean up and go home */
- werase(di_win);
- wrefresh(di_win);
- delwin(di_win);
- if (!want_out)
- error_win(0, "Exceeded the maximum number number of dialing attempts", NULL);
- return(0);
- }
-
- /*
- * Display what info we know at this time.
- */
-
- void
- disp_queue(win, entry, pass)
- WINDOW *win;
- int entry, pass;
- {
- long now, time();
- char *tbuf, *ctime();
- void status_line();
- /* redo the status line */
- status_line(NULL);
- /* system name */
- clear_line(win, 4, 36, 1);
- waddstr(win, dir->name[entry]);
- /* pass number */
- mvwprintw(win, 5, 36, "%-4d", pass);
- /* time of this call */
- time(&now);
- tbuf = ctime(&now);
- tbuf[19] = NULL;
- mvwaddstr(win, 8, 36, &tbuf[11]);
- /* the index field */
- clear_line(win, 11, 36, 1);
- waddstr(win, dir->index[entry]);
-
- wmove(win, 12, 36);
- wrefresh(win);
- return;
- }
-
- /*
- * Monitor the progress of the dialing, but returns a NULL after one
- * second of inactivity.
- */
-
- jmp_buf md_jmp;
-
- char *
- monitor_dial()
- {
- int force_md();
- char *ans, *read_codes();
- unsigned int alarm();
-
- if (setjmp(md_jmp))
- return(NULL);
- signal(SIGALRM, force_md);
- alarm(1);
- ans = read_codes();
- alarm(0);
- return(ans);
- }
- int
- force_md(dummy)
- int dummy;
- {
- void longjmp();
-
- longjmp(md_jmp, 1);
- }
-
- /*
- * Determine if the modem can detect the synchronization of the baud
- * rate if it's different that what it expects. To do this, we check
- * to see if any two connect strings are the same. A return code of
- * 1 means the modem can sync.
- */
-
- int
- can_sync()
- {
- int i;
-
- i = modem->m_cur;
- /* not both null (sneaky trick) */
- if (*modem->con_3[i] + *modem->con_12[i]) {
- if (!strcmp(modem->con_3[i], modem->con_12[i]))
- return(0);
- }
- if (*modem->con_12[i] + *modem->con_24[i]) {
- if (!strcmp(modem->con_12[i], modem->con_24[i]))
- return(0);
- }
- if (*modem->con_24[i] + *modem->con_48[i]) {
- if (!strcmp(modem->con_24[i], modem->con_48[i]))
- return(0);
- }
- if (*modem->con_48[i] + *modem->con_96[i]) {
- if (!strcmp(modem->con_48[i], modem->con_96[i]))
- return(0);
- }
- if (*modem->con_96[i] + *modem->con_192[i]) {
- if (!strcmp(modem->con_96[i], modem->con_192[i]))
- return(0);
- }
- return(1);
- }
-