home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fax-3.2.1 / cmd / faxspooler / send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-31  |  2.7 KB  |  115 lines

  1. /*
  2.   This file is part of the NetFax system.
  3.  
  4.   (c) Copyright 1989 by David M. Siegel. 
  5.       All rights reserved.
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation.
  10.  
  11.     This program is distributed in the hope that it will be useful, 
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <sys/param.h>
  24.  
  25. #include "../../lib/libfax/libfax.h"
  26. #include "spooler.h"
  27. #include "send.h"
  28.  
  29. /*
  30.  * This function actually sends off a fax.
  31.  *
  32.  * Return codes:
  33.  *    0    no hard errors, check recip flags for more details.
  34.  *     -1    something failed
  35.  */
  36. int send_fax(fmp, r, qdir, base_filename, pages)
  37.      FaxModem *fmp;
  38.      Recip *r;
  39.      char *qdir;
  40.      char *base_filename;
  41.      int pages;
  42. {
  43.     time_t start;
  44.     int page;
  45.     char *phone;
  46.  
  47.     /*
  48.      * Delete the privacy notice.
  49.      */
  50.     if (r->phone[0] == '@')
  51.       phone = &r->phone[1];
  52.     else
  53.       phone = r->phone;
  54.  
  55.     /*
  56.      * Attempt to call the recipient.
  57.      */
  58.     if (faxmodem_initiate_call(fmp, phone) < 0) {
  59.     r->status = SEND_STATUS_FAILED;
  60.     return (0);
  61.     }
  62.  
  63.     /*
  64.      * If we didn't connect, save the dialer code for possible
  65.      * queries, and return.
  66.      */
  67.     if (!FAX_CONNECTED(fmp)) {
  68.     r->status = SEND_STATUS_DIALER;
  69.     r->dialer_code = fmp->dialer_code;
  70.     return (0);
  71.     }
  72.     start = time(0);
  73.  
  74.     /*
  75.      * Assume status is OK.  Use this as a flag to break out of the
  76.      * sending loop as well.
  77.      */
  78.     r->status = SEND_STATUS_SENT;
  79.  
  80.     /*
  81.      * Send all the pages, stopping when done or when an error is
  82.      * detected.
  83.      */
  84.     for (page = 0; page < pages && r->status != SEND_STATUS_FAILED; page++) {
  85.     char pathname[MAXPATHLEN];
  86.     int fd;
  87.  
  88.     sprintf(pathname, "%s/%s/%d", qdir, base_filename, page);
  89.     if ((fd = open(pathname, O_RDONLY)) < 0)
  90.       log(L_WARNING, "can't access file: %s\n", pathname);
  91.     else {
  92.         if (faxmodem_send_page(fmp, fd, page+1 == pages, MAX_PAGE_RETRIES)
  93.         < 0) {
  94.         log(L_WARNING, "send of page %d failed", page);
  95.         r->status = SEND_STATUS_FAILED;
  96.         }
  97.         close(fd);
  98.     }
  99.     } 
  100.  
  101.     /*
  102.      * Force the modem to hangup, though this shouldn't have any
  103.      * effect on whether the fax was sent.
  104.      */
  105.     if (faxmodem_hangup(fmp) < 0)
  106.       log(L_WARNING, "hangup failed");
  107.  
  108.     /*
  109.      * Record the transmission time.
  110.      */
  111.     r->total_time = time(0) - start;
  112.  
  113.     return (0);
  114. }
  115.