1 /*	$Id$ */
2 /*
3  * Copyright (c) 1994-1996 Sam Leffler
4  * Copyright (c) 1994-1996 Silicon Graphics, Inc.
5  * HylaFAX is a trademark of Silicon Graphics
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 #include <ctype.h>
27 
28 #include "Sys.h"
29 
30 #include "JobControl.h"
31 #include "faxQueueApp.h"
32 #include "FaxTrace.h"
33 
34 #define	DCI_MAXCONCURRENTCALLS	0x0001
35 #define	DCI_TIMEOFDAY		0x0002
36 #define	DCI_MAXSENDPAGES	0x0004
37 #define	DCI_MAXDIALS		0x0008
38 #define	DCI_MAXTRIES		0x0010
39 #define	DCI_USEXVRES		0x0020
40 #define	DCI_VRES		0x0040
41 #define	DCI_DESIREDDF		0x0100
42 
43 #define	isDefined(b)		(defined & b)
44 #define	setDefined(b)		(defined |= b)
45 
JobControlInfo()46 JobControlInfo::JobControlInfo()		 	{ defined = 0; }
JobControlInfo(const JobControlInfo & other)47 JobControlInfo::JobControlInfo(const JobControlInfo& other)
48     : rejectNotice(other.rejectNotice)
49     , modem(other.modem)
50     , tod(other.tod)
51     , args(other.args)
52 {
53     defined = other.defined;
54     maxConcurrentCalls = other.maxConcurrentCalls;
55     maxSendPages = other.maxSendPages;
56     maxDials = other.maxDials;
57     maxTries = other.maxTries;
58     usexvres = other.usexvres;
59     vres = other.vres;
60     desireddf = other.desireddf;
61 }
62 
JobControlInfo(const fxStr & buffer)63 JobControlInfo::JobControlInfo (const fxStr& buffer)
64 {
65     defined = 0;
66     u_int pos = 0;
67     u_int last_pos = 0;
68     int loop = 0;
69     while ( (pos = buffer.next(last_pos, '\n')) < buffer.length() )
70     {
71     	// Quick safety-net
72 	if (loop++ > 100)
73 	    break;
74 
75     	fxStr l(buffer.extract(last_pos, pos - last_pos));
76 	last_pos = pos+1;
77 
78 	readConfigItem(l);
79     }
80 }
81 
~JobControlInfo()82 JobControlInfo::~JobControlInfo() {}
83 
84 bool
isCompatible(const JobControlInfo & other) const85 JobControlInfo::isCompatible (const JobControlInfo& other) const
86 {
87     if (args != other.args)
88 	return false;
89 
90     return true;
91 }
92 
93 void
configError(const char * fmt,...)94 JobControlInfo::configError (const char* fmt, ...)
95 {
96     va_list ap;
97     va_start(ap, fmt);
98     vlogError(fxStr::format("JobControl: %s", fmt) , ap);
99     va_end(ap);
100 }
101 
102 void
configTrace(const char *,...)103 JobControlInfo::configTrace (const char*, ...)
104 {
105    // We don't trace JobControl parsing...
106 }
107 
108 bool
setConfigItem(const char * tag,const char * value)109 JobControlInfo::setConfigItem (const char* tag, const char* value)
110 {
111     if (streq(tag, "rejectnotice")) {
112 	rejectNotice = value;
113     } else if (streq(tag, "modem")) {
114 	modem = value;
115     } else if (streq(tag, "maxconcurrentjobs")) {	// backwards compatibility
116 	maxConcurrentCalls = getNumber(value);
117 	setDefined(DCI_MAXCONCURRENTCALLS);
118     } else if (streq(tag, "maxconcurrentcalls")) {
119 	maxConcurrentCalls = getNumber(value);
120 	setDefined(DCI_MAXCONCURRENTCALLS);
121     } else if (streq(tag, "maxsendpages")) {
122 	maxSendPages = getNumber(value);
123 	setDefined(DCI_MAXSENDPAGES);
124     } else if (streq(tag, "maxdials")) {
125 	maxDials = getNumber(value);
126 	setDefined(DCI_MAXDIALS);
127     } else if (streq(tag, "maxtries")) {
128 	maxTries = getNumber(value);
129 	setDefined(DCI_MAXTRIES);
130     } else if (streq(tag, "timeofday")) {
131 	tod.parse(value);
132 	setDefined(DCI_TIMEOFDAY);
133     } else if (streq(tag, "usexvres")) {
134 	usexvres = getNumber(value);
135 	setDefined(DCI_USEXVRES);
136     } else if (streq(tag, "vres")) {
137 	vres = getNumber(value);
138 	setDefined(DCI_VRES);
139     } else {
140 	if (streq(tag, "desireddf")) {		// need to pass desireddf to faxsend, also
141 	    desireddf = getNumber(value);
142 	    setDefined(DCI_DESIREDDF);
143 	}
144 	if( args != "" )
145 	    args.append('\0');
146 	args.append(fxStr::format("-c%c%s:\"%s\"",
147 	    '\0', tag, (const char*) value));
148     }
149     return true;
150 }
151 
152 u_int
getMaxConcurrentCalls() const153 JobControlInfo::getMaxConcurrentCalls() const
154 {
155     if (isDefined(DCI_MAXCONCURRENTCALLS))
156 	return maxConcurrentCalls;
157     else
158 	return faxQueueApp::instance().getMaxConcurrentCalls();
159 }
160 
161 u_int
getMaxSendPages() const162 JobControlInfo::getMaxSendPages() const
163 {
164     if (isDefined(DCI_MAXSENDPAGES))
165 	return maxSendPages;
166     else
167 	return faxQueueApp::instance().getMaxSendPages();
168 }
169 
170 u_int
getMaxDials() const171 JobControlInfo::getMaxDials() const
172 {
173     if (isDefined(DCI_MAXDIALS))
174 	return maxDials;
175     else
176 	return faxQueueApp::instance().getMaxDials();
177 }
178 
179 u_int
getMaxTries() const180 JobControlInfo::getMaxTries() const
181 {
182     if (isDefined(DCI_MAXTRIES))
183 	return maxTries;
184     else
185 	return faxQueueApp::instance().getMaxTries();
186 }
187 
188 const fxStr&
getRejectNotice() const189 JobControlInfo::getRejectNotice() const
190 {
191     return rejectNotice;
192 }
193 
194 const fxStr&
getModem() const195 JobControlInfo::getModem() const
196 {
197     return modem;
198 }
199 
200 time_t
nextTimeToSend(time_t t) const201 JobControlInfo::nextTimeToSend(time_t t) const
202 {
203     if (isDefined(DCI_TIMEOFDAY))
204 	return tod.nextTimeOfDay(t);
205     else
206 	return faxQueueApp::instance().nextTimeToSend(t);
207 }
208 
209 int
getUseXVRes() const210 JobControlInfo::getUseXVRes() const
211 {
212     if (isDefined(DCI_USEXVRES))
213 	return usexvres;
214     else
215 	return -1;
216 }
217 
218 u_int
getVRes() const219 JobControlInfo::getVRes() const
220 {
221     if (isDefined(DCI_VRES))
222 	return vres;
223     else
224 	return 0;
225 }
226 
getArgs() const227 const fxStr& JobControlInfo::getArgs() const
228 {
229     return args;
230 }
231 
232 int
getDesiredDF() const233 JobControlInfo::getDesiredDF() const
234 {
235     if (isDefined(DCI_DESIREDDF))
236 	return desireddf;
237     else
238 	return -1;
239 }
240