From: Aidan Van Dyk Date: Tue, 15 May 2007 15:52:03 +0000 (+0000) Subject: faxGetty: fix some EXTERN GETTY bugs X-Git-Tag: HYLAFAX-4_4_0BETA1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd4f79328bbcb17f4c73ddeffbbc5d6120ff8a44;p=thirdparty%2FHylaFAX.git faxGetty: fix some EXTERN GETTY bugs In the work on egetty, it changed from modemAnswerCallCmd to modemAnswerCall. Unfortunately, this broke the use of the ModemAnswer*BeginCmd config options which used to be used, and chagne to the ModeAnswer*Cmd ones (which the answerCall() routines use. In addition, the answerCall() routine actively *disallows* setting any of those to blank, making it impossible to have nothing be sent to the modem for any of these cases. It would blindly send ATA if any of them were set to blank. This fixes some bugs in the extern handling, updates the getty stuff to allow CallID passing as arguments, and reverts back to useing modemAnswerCallCmd() instead of modemAnswerCall(). --- diff --git a/faxd/ClassModem.c++ b/faxd/ClassModem.c++ index af9a475f..c4c329bc 100644 --- a/faxd/ClassModem.c++ +++ b/faxd/ClassModem.c++ @@ -80,19 +80,21 @@ const char* ClassModem::ATresponses[17] = { "", // AT_XON "" // AT_OTHER }; -const char* ClassModem::callTypes[5] = { +const char* ClassModem::callTypes[6] = { "unknown", "data", "fax", "voice", - "error" + "error", + "done" }; -const char* ClassModem::answerTypes[5] = { +const char* ClassModem::answerTypes[6] = { "any", - "fax", "data", + "fax", "voice", - "dial" + "dial", + "external" }; ClassModem::ClassModem(ModemServer& s, const ModemConfig& c) @@ -229,7 +231,7 @@ ClassModem::answerResponse(fxStr& emsg) do { r = atResponse(rbuf, conf.answerResponseTimeout); again: - if (r == AT_TIMEOUT || r == AT_DLEEOT) + if (r == AT_TIMEOUT || r == AT_DLEEOT || r == AT_NOCARRIER) break; const AnswerMsg* am = findAnswer(rbuf); if (am != NULL) { diff --git a/faxd/ClassModem.h b/faxd/ClassModem.h index 4d2c97db..6b81117c 100644 --- a/faxd/ClassModem.h +++ b/faxd/ClassModem.h @@ -108,7 +108,7 @@ public: CALLTYPE_ERROR = 4, // error deducing type of incoming call CALLTYPE_DONE = 5 // subprocess completed call handling }; - static const char* callTypes[5]; + static const char* callTypes[6]; enum { // ClassModem::SpeakerVolume OFF = 0, // nothing @@ -155,10 +155,10 @@ public: ANSTYPE_DATA = 1, // data call ANSTYPE_FAX = 2, // fax call ANSTYPE_VOICE = 3, // voice call - ANSTYPE_EXTERN = 3, // any kind of call, but answered externally - ANSTYPE_DIAL = 4 // dial out to receive (pseudo poll) + ANSTYPE_DIAL = 4, // dial out to receive (pseudo poll) + ANSTYPE_EXTERN = 5 // any kind of call, but answered externally }; - static const char* answerTypes[5]; + static const char* answerTypes[6]; enum { // ClassModem::ATResponse AT_NOTHING = 0, // for passing as a parameter diff --git a/faxd/Getty.c++ b/faxd/Getty.c++ index 2f0f88cc..72d0e9a0 100644 --- a/faxd/Getty.c++ +++ b/faxd/Getty.c++ @@ -76,12 +76,9 @@ sigHUP(int) * exec getty below. */ void -Getty::setupArgv(const char* args, const fxStr& name, const fxStr& number) +Getty::setupArgv(const char* args, const CallID& callid) { argbuf = args; - nambuf = name; - numbuf = number; - bool insertName = false, insertNumber = false; u_int l; /* * Substitute escape sequences. @@ -101,14 +98,17 @@ Getty::setupArgv(const char* args, const fxStr& name, const fxStr& number) argbuf.insert(speed, l); l += speed.length(); // avoid loops break; - case 'a': - argbuf.remove(l-1,3); - insertName = true; - break; - case 'u': - argbuf.remove(l-1,3); - insertNumber = true; - break; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + { + u_int id = argbuf[l+1] - 0x31; + argbuf.remove(l,2); + if (id < callid.size()) { + argbuf.insert(callid.id(id), l); + l += callid.length(id); + } + } + break; case '%': // %% = % argbuf.remove(l,1); break; @@ -129,10 +129,6 @@ Getty::setupArgv(const char* args, const fxStr& name, const fxStr& number) argv[nargs++] = &argbuf[token]; } } - if (nargs < GETTY_MAXARGS-1 && insertName && nambuf.length()) - argv[nargs++] = &nambuf[0]; - if (nargs < GETTY_MAXARGS-1 && insertNumber && numbuf.length()) - argv[nargs++] = &numbuf[0]; argv[nargs] = NULL; } diff --git a/faxd/Getty.h b/faxd/Getty.h index 25092e32..c216d000 100644 --- a/faxd/Getty.h +++ b/faxd/Getty.h @@ -31,6 +31,7 @@ * System V, BSD, etc. are derived from this. */ #include "Str.h" +#include "CallID.h" const int GETTY_MAXARGS = 64; // max args passed to getty @@ -55,7 +56,7 @@ protected: public: virtual ~Getty(); // setup arguments for getty process - void setupArgv(const char* args, const fxStr&, const fxStr&); + void setupArgv(const char* args, const CallID& callid); // run getty process virtual void run(int fd, bool parentIsInit); virtual bool wait(int& status, bool block = false); diff --git a/faxd/faxGettyApp.c++ b/faxd/faxGettyApp.c++ index a2880de7..02b6bdda 100644 --- a/faxd/faxGettyApp.c++ +++ b/faxd/faxGettyApp.c++ @@ -438,6 +438,8 @@ faxGettyApp::answerPhone(AnswerType atype, CallType ctype, const CallID& callid, callResolved = answerCall(atype, ctype, emsg, callid, dialnumber); } } + if (emsg.length()) + traceProtocol((const char*) emsg); /* * Call resolved. If we were able to recognize the call * type and setup a session, then reset the answer rotary @@ -532,7 +534,7 @@ faxGettyApp::answerCall(AnswerType atype, CallType& ctype, fxStr& emsg, const Ca if (ctype == ClassModem::CALLTYPE_DONE) // NB: call completed return (true); if (ctype != ClassModem::CALLTYPE_ERROR) - modemAnswerCall(ctype, emsg, dialnumber); + modemAnswerCallCmd(ctype); } else emsg = "External getty use is not permitted"; } else @@ -629,9 +631,9 @@ faxGettyApp::runGetty( emsg = fxStr::format("%s: could not create", what); return (ClassModem::CALLTYPE_ERROR); } - getty->setupArgv(args, - callid.size() > CallID::NUMBER ? callid.id(CallID::NUMBER) : "", - callid.size() > CallID::NAME ? callid.id(CallID::NAME) : ""); + + getty->setupArgv(args, callid); + /* * The getty process should not inherit the lock file. * Remove it here before the fork so that our state is diff --git a/man/hylafax-config.4f b/man/hylafax-config.4f index 45534b9a..27b93fc8 100644 --- a/man/hylafax-config.4f +++ b/man/hylafax-config.4f @@ -140,6 +140,7 @@ DistinctiveRings string \- configuration for distinctive ring cadences DRingOff string \- distinctive ring ``off'' cadence indicator DRingOn string \- distinctive ring ``on'' cadence indicator DynamicConfig string \- script for dynamic receive configuration +EGettyArgs string \- arguments passed to external getty program FAXNumber string \- facsimile modem phone number FaxRcvdCmd string \s-1bin/faxrcvd\s+1 notification script for received facsimile GettyArgs string \- arguments passed to getty program @@ -835,6 +836,53 @@ modem configurations for different senders. This program can also set the options to cause the current call to be rejected instaead of answered. Note that this file must be marked as executable by the faxgetty process. .TP +.B EGettyArgs +A string that indicates whether or not the server should use an +an external getty application to deduce and possibly handle an incoming call. +If the string value is not null, then it is interpreted +as a set of arguments to pass to the getty program. +Before supplying the arguments, the string is first scanned +for ``%''-escape sequences: any appearance of ``%l'' is replaced +with the tty name and any appearance of ``%s'' is replaced with +the serial port speed (in decimal). +Any appearance of escaped numbers 1 through 9 (``%1'' through ``%9'') are replaced +by the match to the corresponding +.BR CallIDPattern , +if present. +The ``%'' character can be specified with ``%%''. +If the +.B EGettyArgs +parameter is not specified in the configuration file or if +the string value is null, then ``extern'' connections will be rejected. +Note that in addition to the specified command line arguments, the +external getty +program is invoked with its standard input, output, and error +descriptors directed to the controlling tty device. + +When the external getty application completes, its exit status is evaluated +and is interpreted to indicate what, if anything, should be done with the call. +An exit status of ``0'' indicates an unknown call type and that the call should +be handled as if the external getty program had not been used. An exit status +of ``1'' indicates a data connection and that the +.IR getty (${MANNUM1_8}) +program should be used to handle the call (see +.BR GettyArgs ) +after being answered with +.B ModemAnswerDataBeginCmd . +An exit status of ``2'' indicates a fax connection that should be handled after +being answered with +.BR ModemAnswerFaxBeginCmd . +An exit status of ``3'' indicates a voice call and that the +.I vgetty +program should be used to handle the call (see +.BR VGettyArgs ) +after being answered with +BR ModemAnswerVoiceBeginCmd . +An exit status of ``4'' is considered to be an error condition. The session +will be terminated. An exit status of ``5'' is used to indicate that the +external getty program handled the call entirely, is not an error condition, and +that the session is to be considered terminated. +.TP .B FAXNumber The phone number associated with the facsimile modem. This string is used to generate the @@ -967,6 +1015,10 @@ Before supplying the arguments, the string is first scanned for ``%''-escape sequences: any appearance of ``%l'' is replaced with the tty name and any appearance of ``%s'' is replaced with the serial port speed (in decimal). +Any appearance of escaped numbers 1 through 9 (``%1'' through ``%9'') are replaced +by the match to the corresponding +.BR CallIDPattern , +if present. The ``%'' character can be specified with ``%%''. If the .B GettyArgs @@ -1692,6 +1744,10 @@ Before supplying the arguments, the string is first scanned for ``%''-escape sequences: any appearance of ``%l'' is replaced with the tty name and any appearance of ``%s'' is replaced with the serial port speed (in decimal). +Any appearance of escaped numbers 1 through 9 (``%1'' through ``%9'') are replaced +by the match to the corresponding +.BR CallIDPattern , +if present. The ``%'' character can be specified with ``%%''. If the .B VGettyArgs