FaxRequest.c++
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:22k
- /* $Id: FaxRequest.c++,v 1.18 2008/09/16 05:39:07 faxguy Exp $ */
- /*
- * Copyright (c) 1990-1996 Sam Leffler
- * Copyright (c) 1991-1996 Silicon Graphics, Inc.
- * HylaFAX is a trademark of Silicon Graphics
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that (i) the above copyright notices and this permission notice appear in
- * all copies of the software and related documentation, and (ii) the names of
- * Sam Leffler and Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Sam Leffler and Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
- * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
- * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
- * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- */
- #include "Sys.h"
- #include "FaxRequest.h"
- #include "StackBuffer.h"
- #include "class2.h"
- #include "config.h"
- #include "hash.h" // pre-calculated hash values
- #include <ctype.h>
- #include <errno.h>
- /*
- * HylaFAX job request file handling.
- */
- extern void vlogError(const char* fmt, va_list ap);
- extern void logError(const char* fmt ...);
- FaxRequest::FaxRequest(const fxStr& qf, int f) : qfile(qf)
- {
- reset();
- fd = f;
- }
- void
- FaxRequest::reset(void)
- {
- tts = 0;
- killtime = 0;
- retrytime = 0;
- state = 0;
- status = send_retry;
- pri = (u_short) -1;
- usrpri = FAX_DEFPRIORITY;
- pagewidth = pagelength = resolution = 0;
- npages = totpages = skippages = skippedpages = nocountcover = 0;
- ntries = ndials = 0;
- minbr = BR_2400;
- desiredbr = BR_33600;
- desiredst = ST_0MS;
- desiredec = EC_ENABLE256;
- desireddf = DF_2DMMR;
- desiredtl = 0;
- totdials = 0, maxdials = (u_short) FAX_REDIALS;
- tottries = 0, maxtries = (u_short) FAX_RETRIES;
- useccover = true;
- usexvres = false;
- serverdocover = false;
- ignoremodembusy = false;
- pagechop = chop_default;
- chopthreshold = -1;
- csi = fxStr::null;
- nsf = fxStr::null;
- notify = no_notice;
- jobtype = "facsimile"; // for compatibility w/ old clients
- writeQFilePid = 0;
- }
- FaxRequest::~FaxRequest()
- {
- if (fd != -1)
- Sys::close(fd);
- }
- #define N(a) (sizeof (a) / sizeof (a[0]))
- FaxRequest::stringval FaxRequest::strvals[] = {
- { "canonical", &FaxRequest::canonical },
- { "external", &FaxRequest::external },
- { "number", &FaxRequest::number },
- { "mailaddr", &FaxRequest::mailaddr },
- { "sender", &FaxRequest::sender },
- { "jobid", &FaxRequest::jobid },
- { "jobtag", &FaxRequest::jobtag },
- { "pagehandling", &FaxRequest::pagehandling },
- { "modem", &FaxRequest::modem },
- { "modemused", &FaxRequest::modemused },
- { "faxnumber", &FaxRequest::faxnumber },
- { "faxname", &FaxRequest::faxname },
- { "tsi", &FaxRequest::tsi },
- { "receiver", &FaxRequest::receiver },
- { "company", &FaxRequest::company },
- { "location", &FaxRequest::location },
- { "voice", &FaxRequest::voice },
- { "fromcompany", &FaxRequest::fromcompany },
- { "fromlocation", &FaxRequest::fromlocation },
- { "fromvoice", &FaxRequest::fromvoice },
- { "regarding", &FaxRequest::regarding },
- { "comments", &FaxRequest::comments },
- { "cover", &FaxRequest::cover },
- { "client", &FaxRequest::client },
- { "owner", &FaxRequest::owner },
- { "groupid", &FaxRequest::groupid },
- { "signalrate", &FaxRequest::sigrate },
- { "dataformat", &FaxRequest::df },
- { "jobtype", &FaxRequest::jobtype },
- { "tagline", &FaxRequest::tagline },
- { "subaddr", &FaxRequest::subaddr },
- { "passwd", &FaxRequest::passwd },
- { "doneop", &FaxRequest::doneop },
- { "commid", &FaxRequest::commid },
- { "csi", &FaxRequest::csi },
- { "nsf", &FaxRequest::nsf },
- { "timeofday", &FaxRequest::timeofday },
- { "errorcode", &FaxRequest::errorcode },
- };
- FaxRequest::shortval FaxRequest::shortvals[] = {
- { "state", &FaxRequest::state },
- { "npages", &FaxRequest::npages },
- { "skippages", &FaxRequest::skippages },
- { "nocountcover", &FaxRequest::nocountcover },
- { "serverdocover", &FaxRequest::serverdocover },
- { "ignoremodembusy",&FaxRequest::ignoremodembusy },
- { "totpages", &FaxRequest::totpages },
- { "ntries", &FaxRequest::ntries },
- { "ndials", &FaxRequest::ndials },
- { "totdials", &FaxRequest::totdials },
- { "maxdials", &FaxRequest::maxdials },
- { "tottries", &FaxRequest::tottries },
- { "maxtries", &FaxRequest::maxtries },
- { "pagewidth", &FaxRequest::pagewidth },
- { "resolution", &FaxRequest::resolution },
- { "pagelength", &FaxRequest::pagelength },
- { "priority", &FaxRequest::usrpri },
- { "schedpri", &FaxRequest::pri },
- { "minbr", &FaxRequest::minbr },
- { "desiredbr", &FaxRequest::desiredbr },
- { "desiredst", &FaxRequest::desiredst },
- { "desiredec", &FaxRequest::desiredec },
- { "desireddf", &FaxRequest::desireddf },
- { "desiredtl", &FaxRequest::desiredtl },
- { "useccover", &FaxRequest::useccover },
- { "usexvres", &FaxRequest::usexvres },
- };
- FaxRequest::intval FaxRequest::intvals[] = {
- { "skippedpages", &FaxRequest::skippedpages },
- };
- const char* FaxRequest::opNames[18] = {
- "fax",
- "tiff",
- "!tiff",
- "pdf",
- "!pdf",
- "postscript",
- "!postscript",
- "pcl",
- "!pcl",
- "data",
- "!data",
- "poll",
- "page",
- "!page",
- "uucp",
- "15", "16", "17"
- };
- const char* FaxRequest::notifyVals[4] = {
- "none", // no_notice
- "when done", // when_done
- "when requeued", // when_requeued
- "when done+requeued" // when_done|when_requeued
- };
- const char* FaxRequest::chopVals[4] = {
- "default", // chop_default
- "none", // chop_none
- "all", // chop_all
- "last" // chop_last
- };
- /*
- * Parse the contents of a job description file.
- */
- bool
- FaxRequest::readQFile(bool& rejectJob)
- {
- rejectJob = false;
- lineno = 0;
- lseek(fd, 0L, SEEK_SET); // XXX should only for re-read
- /*
- * Read the file contents in with one read. If the
- * file is too large to fit in the buffer allocated
- * on the stack then dynamically allocate one. The
- * 2K size was chosen based on statistics; most files
- * are less than 1K in size.
- *
- * NB: we don't mmap the file because we're going to
- * modify its contents in memory during parsing
- * (plus it's not clear that mmap is a win for
- * such a small file).
- */
- struct stat sb;
- Sys::fstat(fd, sb);
- if (sb.st_size < 2) {
- error("Corrupted file (too small)");
- return (false);
- }
- char stackbuf[2048];
- char* buf = stackbuf;
- char* bp = buf;
- if (sb.st_size > (off_t)sizeof(stackbuf)-1) // extra byte for terminating