1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
|
#ident "$Id: sendfax.c,v 4.16 1999/03/13 19:21:44 gert Exp $ Copyright (c) Gert Doering"
/* sendfax.c
*
* Send a Fax using a class 2 faxmodem.
* Calls routines in faxrec.c and faxlib.c
*
* The code is still quite rough, but it works.
*/
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "syslibs.h"
#ifndef sunos4
#include <sys/ioctl.h>
#endif
#include <signal.h>
#include <sys/types.h>
#ifndef ENOENT
# include <errno.h>
#endif
#include "version.h"
#include "mgetty.h"
#include "tio.h"
#include "policy.h"
#include "fax_lib.h"
/* configuration */
#include "config.h"
#include "conf_sf.h"
/* use direct bit order in modem, that means, we have to reverse */
#define REVERSE 1
char * fac_tel_no;
boolean verbose = FALSE;
extern time_t call_start; /* for accounting */
/* seems to missing nearly everywhere */
#ifndef __NetBSD__
time_t time _PROTO(( long * tloc ));
#endif
void exit_usage _P2( (program, msg ),
char * program, char * msg )
{
if ( msg != NULL )
{
lprintf( L_ERROR, "exit_usage: %s", msg );
fprintf( stderr, "%s: %s\n", program, msg );
}
fprintf( stderr,
"usage: %s [options] <fax-number> <page(s) in g3-format>\n", program);
fprintf( stderr,
"\tvalid options: -p, -v, -l <device(s)>, -x <debug>, -n, -S, -r, -D <x>\n");
lprintf( L_AUDIT, "failed: command line error" );
exit(1);
}
TIO fax_tio;
char *Device = "unset";
int fax_open_device _P2( (fax_tty, use_stdin),
char * fax_tty, boolean use_stdin )
{
char device[MAXPATH];
int fd;
if ( use_stdin ) /* fax modem on stdin */
{
fd = 0;
Device = ttyname(fd); /* for faxrec() */
if ( Device == NULL || *Device == '\0' ) Device = "unknown";
}
else
{
int tries;
/* ignore leading "/dev/" prefix */
if ( strncmp( fax_tty, "/dev/", 5 ) == 0 ) fax_tty += 5;
if ( verbose ) printf( "Trying fax device '/dev/%s'... ", fax_tty );
tries = 0;
while ( makelock( fax_tty ) != SUCCESS )
{
if ( ++ tries < 3 )
{
if ( verbose ) { printf( "locked... " ); fflush( stdout ); }
sleep(5);
}
else
{
if ( verbose ) { printf( "locked, give up!\n" );
fflush( stdout ); }
lprintf( L_MESG, "cannot lock %s", fax_tty );
return -1;
}
}
sprintf( device, "/dev/%s", fax_tty );
if ( ( fd = open( device, O_RDWR | O_NDELAY ) ) == -1 )
{
lprintf( L_ERROR, "error opening %s", device );
if ( verbose ) printf( "cannot open!\n" );
rmlocks();
return fd;
}
/* make device name externally visible (faxrec())
* we have to dup() it, because caller will change fax_tty
*/
Device = malloc( strlen(fax_tty)+1 );
if ( Device == NULL )
{ perror( "sendfax: can't malloc" ); exit(2); }
strcpy(Device, fax_tty);
}
/* unset O_NDELAY (otherwise waiting for characters */
/* would be "busy waiting", eating up all cpu) */
if ( fcntl( fd, F_SETFL, O_RDWR ) == -1 )
{
lprintf( L_ERROR, "error in fcntl" );
close( fd );
if ( verbose ) printf( "cannot fcntl!\n" );
rmlocks();
return -1;
}
/* initialize baud rate, hardware handshake, ... */
tio_get( fd, &fax_tio );
/* even if we use a modem that requires Xon/Xoff flow control,
* do *not* enable it here - it would interefere with the Xon
* received at the top of a page.
*/
tio_mode_sane( &fax_tio, TRUE );
tio_set_speed( &fax_tio, c_int(speed) );
tio_mode_raw( &fax_tio );
#ifdef sun
/* sunos does not rx with RTSCTS unless carrier present */
tio_set_flow_control( fd, &fax_tio, FLOW_NONE );
#else
tio_set_flow_control( fd, &fax_tio, (FAXSEND_FLOW) & FLOW_HARD );
#endif
if ( tio_set( fd, &fax_tio ) == ERROR )
{
lprintf( L_ERROR, "error in tio_set" );
close( fd );
if ( verbose ) printf( "cannot set termio values!\n" );
rmlocks();
return -1;
}
/* reset parameters */
fax_to_poll = FALSE;
fax_remote_id[0] = 0;
fax_param[0] = 0;
if ( use_stdin )
{
lprintf( L_NOISE, "fax_open_device, fax on stdin" );
}
else
{
log_init_paths( NULL, NULL, &fax_tty[ strlen(fax_tty)-3 ] );
lprintf( L_NOISE, "fax_open_device succeeded, %s -> %d", fax_tty, fd );
}
if ( verbose ) printf( "OK.\n" );
return fd;
}
/* fax_open: loop through all devices in fax_ttys until fax_open_device()
* succeeds on one of them; then return file descriptor
* return "-1" of no open succeeded (all locked, permission denied, ...)
*/
int fax_open _P2( (fax_ttys, use_stdin),
char * fax_ttys, boolean use_stdin )
{
char * p, * fax_tty;
int fd;
p = fax_tty = fax_ttys;
do
{
p = strchr( fax_tty, ':' );
if ( p != NULL ) *p = 0;
fd = fax_open_device( fax_tty, use_stdin );
if ( p != NULL ) *p = ':';
fax_tty = p+1;
}
while ( p != NULL && fd == -1 );
return fd;
}
/* finish off - close modem device, rm lockfile */
void fax_close _P1( (fd),
int fd )
{
tio_flush_queue( fd, TIO_Q_BOTH ); /* unlock flow ctl. */
fax_send( "AT+FCLASS=0", fd );
delay(500);
tio_flush_queue( fd, TIO_Q_BOTH ); /* unlock flow ctl. */
close( fd );
rmlocks();
}
/* sendfax-specific fax initializations */
/* polling: set calling station ID, receiver on, local poll on */
static int faxpoll_client_init _P2( (fd, cid), int fd, char * cid )
{
char buf[60];
if ( modem_type == Mt_class2_0 )
{
sprintf( buf, "AT+FPI=\"%.40s\"", cid );
if ( mdm_command( buf, fd ) == ERROR ) return ERROR;
if ( mdm_command( "AT+FSP=1", fd ) == ERROR ) return ERROR;
}
else
{
sprintf( buf, "AT+FCIG=\"%.40s\"", cid );
if ( mdm_command( buf, fd ) == ERROR ) return ERROR;
if ( mdm_command( "AT+FSPL=1", fd ) == ERROR ) return ERROR;
}
if ( mdm_command( "AT+FCR=1", fd ) == ERROR ) return ERROR;
return NOERROR;
}
RETSIGTYPE fax_sig_goodbye _P1( (signo), int signo )
{
if ( call_start == 0 ) call_start = time(NULL);
lprintf( L_AUDIT,
"failed: got signal %d, pid=%d, dev=%s, time=%ds, acct=\"%s\"",
signo, getpid(), Device,
( time(NULL)-call_start ), c_string(acct_handle));
rmlocks();
exit(15); /* will close the fax device */
}
int main _P2( (argc, argv),
int argc, char ** argv )
{
int argidx;
int fd;
char buf[1000];
int i;
int tries; /* number of unsuccessful tries */
int total_bytes = 0; /* number of bytes sent */
int total_pages = 0; /* number of pages (files) sent */
int total_resent= 0; /* number of pages resent */
/* initialize logging */
log_init_paths( argv[0], FAX_LOG, NULL );
/* parse switches (-> conf_sf.c) and read global config file */
if ( sendfax_parse_args( argc, argv ) == ERROR )
{
exit_usage( argv[0], NULL );
}
/* read config file (defaults) */
sendfax_get_config( NULL );
lprintf( L_MESG, "sendfax: %s", mgetty_version );
lprintf( L_NOISE, "%s compiled at %s, %s", __FILE__, __DATE__, __TIME__ );
/* for simplicity, put a few config things into global variables */
verbose = c_bool( verbose );
argidx = optind;
/* fax number given? */
if ( argidx == argc )
{
exit_usage( argv[0], "no fax number specified" );
}
fac_tel_no = argv[ argidx++ ];
lprintf( L_MESG, "sending fax to %s", fac_tel_no );
/* check, if all the arguments passed are normal files and
* readable
*/
for ( i=argidx; i<argc; i++ )
{
lprintf( L_MESG, "checking %s", argv[i] );
if ( access( argv[i], R_OK ) == -1 )
{
if ( errno == ENOENT && i == argidx /* first file */
&& c_bool( rename_files ) ) /* and '-r' set */
{
argidx++; continue; /* just skip */
}
lprintf( L_ERROR, "cannot access %s", argv[i] );
fprintf( stderr, "%s: cannot access %s\n", argv[0], argv[i]);
exit(1);
}
}
/* check if any files specified / left */
if ( ! c_bool(fax_poll_wanted) && argidx == argc )
{
exit_usage( argv[0], "no files to send" );
}
/* if modem on stdin, shut off blurb */
if ( c_bool(use_stdin) ) verbose = FALSE;
fd = fax_open( c_string(ttys), c_bool(use_stdin) );
if ( fd == -1 )
{
lprintf( L_AUDIT, "failed: can't get modem (locked/permissions)");
fprintf( stderr, "%s: cannot access fax device(s) (locked?)\n", argv[0] );
exit(2);
}
/* read config file (port specific) */
sendfax_get_config( Device );
/* sanity checks */
if ( strcmp( c_string(modem_type), "cls2" ) != 0 &&
strcmp( c_string(modem_type), "c2.0" ) != 0 &&
strcmp( c_string(modem_type), "cls1" ) != 0 &&
strncmp(c_string(modem_type), "auto", 4) != 0 )
{
fprintf( stderr, "%s: warning: invalid modem class '%s'\n",
argv[0], c_string(modem_type) );
}
/* arrange that lock files get removed if INTR or QUIT is pressed */
signal( SIGINT, fax_sig_goodbye );
signal( SIGQUIT, fax_sig_goodbye );
signal( SIGTERM, fax_sig_goodbye );
#ifdef HAVE_SIGINTERRUPT
/* interruptible system calls */
siginterrupt( SIGINT, TRUE );
siginterrupt( SIGALRM, TRUE );
siginterrupt( SIGHUP, TRUE );
#endif
/* now set speed for this port (do this *after* sendfax_get_config())!
*/
if ( tio_set_speed( &fax_tio, c_int(speed) ) == ERROR ||
tio_set( fd, &fax_tio ) == ERROR )
{
fprintf( stderr, "%s: cannot set serial port speed %d on \"%s\"\n",
argv[0], c_int(speed), Device );
close(fd);
rmlocks();
lprintf( L_AUDIT, "failed: tio_set*, dev=%s, acct=\"%s\"",
Device, c_string(acct_handle));
exit(2);
}
/* some modems send an "OK" after DTR is raised - catch it
*/
if ( c_isset(open_delay) )
{
lprintf( L_NOISE, "pausing %d ms", c_int(open_delay));
delay(c_int(open_delay)); /* give modem time to settle */
}
tio_flush_queue(fd, TIO_Q_BOTH); /* clear junk */
/* Is there a modem...? */
if ( mdm_command( "ATV1Q0", fd ) == ERROR )
{
/* no??!? -- try again, maybe modem was just unwilling... */
if ( mdm_command( "ATV1Q0", fd ) == ERROR )
{
lprintf( L_AUDIT, "failed initializing modem, dev=%s, acct=\"%s\"",
Device, c_string(acct_handle) );
fprintf( stderr, "The modem doesn't respond!\n" );
tio_flush_queue( fd, TIO_Q_BOTH ); /* unlock flow ctl. */
close(fd);
rmlocks();
exit(3);
}
lprintf( L_WARN, "retry succeded, dev=%s", Device );
}
/* extra initialization: -m / modem-init */
if ( c_isset(modem_init) )
{
if ( strncmp( c_string(modem_init), "AT", 2 ) != 0 )
{
write( fd, "AT", 2 );
}
if ( fax_command( c_string(modem_init), "OK", fd ) == ERROR )
{
lprintf( L_WARN, "cannot send extra modem init string '%s'",
c_string(modem_init) );
fprintf( stderr, "%s: modem doesnt't accept '%s'\n",
argv[0], c_string(modem_init) );
fax_close( fd );
exit(3);
}
} /* end if (c_isset(modem_init)) */
/* get modem type (class 2 / class 2.0), switch modem to fax mode */
if ( (modem_type =
fax_get_modem_type( fd, c_string(modem_type) ) ) == Mt_unknown )
{
lprintf( L_AUDIT, "failed: modem type unknown, dev=%s", Device);
fprintf( stderr, "%s: cannot set modem to fax mode\n", argv[0] );
fax_close( fd );
exit( 3 );
}
if ( modem_type == Mt_data )
{
lprintf( L_AUDIT, "failed: no class 2/2.0 fax modem, dev=%s", Device);
fprintf( stderr, "%s: not a class 2/2.0 fax modem\n", argv[0] );
fax_close( fd );
exit( 3 );
}
/* some modems need a baud rate switch after +FCLASS=2,
* see policy.h for details
*/
if ( c_isset(switchbd) && c_int(switchbd) != 0 &&
c_int(switchbd) != c_int(speed) )
{
lprintf( L_MESG, "switchbd: change to %d", c_int(switchbd) );
tio_set_speed( &fax_tio, c_int(switchbd) );
tio_set( fd, &fax_tio );
}
if ( fax_set_l_id( fd, c_string(station_id) ) == ERROR )
{
lprintf( L_AUDIT, "failed: cannot set fax station ID, dev=%s", Device);
fprintf( stderr, "%s: cannot set fax station ID\n", argv[0] );
fax_close( fd );
exit(3);
}
/* set desired resolution, maximum and minimum bit rate */
/* FIXME: ask modem if it can do 14400 bps / fine res. at all */
fax_set_fdcc( fd, !c_bool(normal_res), c_int(fax_max_speed), 0 );
#if REVERSE
fax_set_bor( fd, 0 );
#else
fax_set_bor( fd, 1 );
#endif
/* AT+FNR=... is necessary in class 2.0 to make the modem tell us
* about the remote fax ID, transmission speed, NSFs, etc.
*/
if ( modem_type == Mt_class2_0 )
mdm_command( (modem_quirks & MQ_SHOW_NSF)? "AT+FNR=1,1,1,1"
: "AT+FNR=1,1,1,0", fd );
/* tell the modem if we are willing to poll faxes
*/
if ( c_bool(fax_poll_wanted) )
{
if ( faxpoll_client_init( fd, c_string(station_id) ) == ERROR )
{
lprintf( L_WARN, "cannot enable polling" );
fprintf( stderr, "Warning: polling is not possible!\n" );
conf_set_bool( &c.fax_poll_wanted, FALSE );
}
}
/* set modem to use desired flow control type, dial out
*/
if ( fax_set_flowcontrol( fd, (FAXSEND_FLOW) & FLOW_HARD ) == ERROR )
{
lprintf( L_WARN, "cannot set modem flow control" );
}
if ( c_isset( modem_handshake ) &&
strlen( c_string(modem_handshake) ) != 0 &&
mdm_command( c_string(modem_handshake), fd ) == ERROR )
{
lprintf( L_WARN, "cannot set 'modem_handshake'; ignored" );
}
if ( verbose ) { printf( "Dialing %s... ", fac_tel_no ); fflush(stdout); }
call_start = time( NULL );
sprintf( buf, "%s%s", c_string(dial_prefix), fac_tel_no );
#ifdef CLASS1
if ( modem_type == Mt_class1 )
i = fax1_dial_and_phase_AB( buf, fd );
else
#endif
i = fax_command( buf, "OK", fd );
if ( i == ERROR )
{
lprintf( L_AUDIT, "failed dialing, phone=\"%s\", +FHS:%02d, dev=%s, time=%ds, acct=\"%s\"",
fac_tel_no, fax_hangup_code, Device,
( time(NULL)-call_start ), c_string(acct_handle) );
/* close fax line */
fax_close( fd );
/* print message, and end program -
return codes signals kind of dial failure */
if ( fax_hangup_code == FHUP_BUSY || /* BUSY */
fax_hangup_code == 3 || /* no loop current */
fax_hangup_code == 4 ) /* ringing, no answer */
{
if ( verbose )
printf( "dial failed (BUSY/NO ANSWER)\n" );
exit(4);
}
else if ( fax_hangup_code == FHUP_NODIAL )
{
if ( verbose )
printf( "dial failed (NO DIALTONE)\n" );
exit(5);
}
else
{
fprintf( stderr, "\n%s: dial %s failed (ERROR / NO CARRIER)\n",
argv[0], fac_tel_no );
exit(10);
}
}
if ( verbose ) printf( "OK.\n" );
if ( c_bool( ignore_carrier )) /* ignore carrier */
{
lprintf( L_MESG, "sendfax: IGNORE DCD (carrier) status" );
}
else /* honour carrier */
{
/* by now, the modem should have raised DCD, so remove CLOCAL flag */
tio_carrier( &fax_tio, TRUE );
#ifdef sun
/* now we can request hardware flow control since we have carrier */
tio_set_flow_control( fd, &fax_tio, (FAXSEND_FLOW) & (FLOW_HARD|FLOW_XON_OUT) );
#endif /* sun */
tio_set( fd, &fax_tio );
lprintf( L_MESG, "sendfax: honouring DCD (carrier) drops now" );
}
total_pages = argc-argidx; /* for statistics */
/* process all files to send / abort, if Modem sent +FHNG result */
tries = 0;
while ( argidx < argc )
{
Post_page_messages ppm;
/* send page header, if requested */
if ( c_string(fax_page_header) )
{
#if 0
if ( fax_send_page( c_string(fax_page_header), fd ) == ERROR )
break;
#else
fprintf( stderr, "WARNING: no page header is transmitted. Does not work yet!\n" );
#endif
}
/* send page */
if ( verbose ) printf( "sending '%s'...\n", argv[ argidx ] );
/* how to continue after page? */
if ( argidx == argc -1 ) /* last page to send */
{
if ( c_bool(fax_poll_wanted) && /* do we want to poll? */
fax_to_poll ) /* yeah!! */
ppm = pp_eom; /* another doc. next (->phase B) */
else
ppm = pp_eop; /* over & out (->hangup) */
}
else /* not last page -> */
ppm = pp_mps; /* another page next */
fax_page_tx_status = -1; /* set by fax_send_page() */
if ( fax_send_page( argv[ argidx ],
&total_bytes, &fax_tio, ppm, fd ) == ERROR )
{
break;
}
/* after the page punctuation command, the modem
* will send us a +FPTS:<ppm> page transmit status.
* The ppm value is written to fax_page_tx_status by
* fax_send_page() / fax_send_ppm()
* If the other side requests retransmission, do so.
*/
switch ( fax_page_tx_status )
{
case 1: break; /* page good */
/* page bad - r. req. */
case 2:
if ( c_int(max_tries) <= 0 ) /* ignore */
{
fprintf( stderr, "WARNING: page bad (RTN), ignoring\n" );
lprintf( L_WARN, "WARNING: RTN ignored\n" );
}
else /* try again */
{
fprintf( stderr, "ERROR: RTN: page bad - retrain requested\n" );
tries ++;
if ( tries >= c_int(max_tries) ) /* max tries reached */
{
if ( c_bool(max_tries_ctd) ) /* go on */
{
fprintf( stderr, "WARNING: maximum number of retries reached, going on\n" );
lprintf( L_WARN, "max. tries (%d) reached, going on", tries );
}
else /* abort */
{
fprintf( stderr, "ERROR: too many retries - aborting send\n" );
fax_hangup_code = -1;
fax_hangup = 1;
}
}
else
{
if ( verbose )
printf( "sending page again (retry %d)\n", tries );
total_resent++;
continue; /* don't go to next page */
}
}
break;
case 3: fprintf( stderr, "WARNING: RTP: page good, but retrain requested\n" );
break;
case 4:
case 5: fprintf( stderr, "WARNING: procedure interrupt requested - don't know how to handle it\n" );
break;
case -1: /* something broke */
lprintf( L_WARN, "fpts:-1" );
break;
default:fprintf( stderr, "WARNING: invalid code: +FPTS:%d\n",
fax_page_tx_status );
break;
}
if ( fax_hangup && fax_hangup_code != 0 ) break;
/* page transmitted successfully, rename file to ".done" */
if ( c_bool( rename_files ) )
{
char done[MAXPATH+6];
if ( strlen( argv[argidx] ) > sizeof(done)-6 )
fprintf( stderr, "file name %s too long\n", argv[argidx] );
else
{
sprintf( done, "%s.done", argv[argidx] );
if ( rename( argv[argidx], done ) == -1 )
lprintf( L_ERROR, "can't rename work file to %s", done );
}
}
argidx++; /* next page */
tries=0; /* no tries yet */
} /* end main page loop */
if ( argidx < argc || ( fax_hangup && fax_hangup_code != 0 ) )
{
lprintf( L_AUDIT, "failed transmitting %s: phone=\"%s\", +FHS:%02d, dev=%s, time=%ds, acct=\"%s\"",
argv[argidx], fac_tel_no, fax_hangup_code, Device,
( time(NULL)-call_start ), c_string(acct_handle) );
fprintf( stderr, "\n%s: FAILED to transmit '%s'.\n",
argv[0], argv[argidx] );
if ( fax_hangup_code == -1 )
fprintf( stderr, "(number of tries exhausted)\n" );
else
fprintf( stderr, "Transmission error: +FHNG:%2d (%s)\n",
fax_hangup_code,
fax_strerror( fax_hangup_code ) );
fax_close( fd );
exit(12);
}
/* OK, handle (optional) fax polling now.
* Fax polling will only be tried if user specified "-p" and the
* faxmodem sent us a "+FPOLL" response
*/
if ( c_bool(fax_poll_wanted) )
{
int pagenum = 0;
if ( verbose ) printf( "starting fax poll\n" );
if ( ! fax_to_poll )
{
printf( "remote does not have document to poll!\n" );
}
else
{
/* class 2.0 modems use the correct byte order, Rockwell-
* compatible class 2 modems get it wrong.
*/
if ( modem_type == Mt_class2_0 ) fax_set_bor( fd, 1 );
/* switch to fax receiver flow control */
tio_set_flow_control( fd, &fax_tio,
(FAXREC_FLOW) & (FLOW_HARD|FLOW_XON_IN) );
tio_set( fd, &fax_tio );
if ( fax_get_pages( fd, &pagenum, c_string(poll_dir),
-1, -1, -1 ) == ERROR )
{
fprintf( stderr, "warning: polling failed\n" );
lprintf( L_AUDIT, "failed: polling failed, phone=\"%s\", +FHS:%02d, dev=%s, time=%ds, acct=\"%s\"",
fac_tel_no, fax_hangup_code, Device,
( time(NULL)-call_start ), c_string(acct_handle) );
fax_close( fd );
exit(12);
}
}
if ( verbose ) printf( "%d pages successfully polled!\n", pagenum );
}
fax_close( fd );
lprintf( L_AUDIT, "success, phone=\"%s\", dev=%s, time=%ds, pages=%d(+%d), bytes=%d, acct=\"%s\"",
fac_tel_no, Device, ( time(NULL)-call_start ),
total_pages, total_resent, total_bytes,
c_string(acct_handle) );
return 0;
}
|