]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
faxGetty: fix some EXTERN GETTY bugs
authorAidan Van Dyk <aidan@ifax.com>
Tue, 15 May 2007 15:52:03 +0000 (15:52 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Tue, 15 May 2007 15:52:03 +0000 (15:52 +0000)
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().

faxd/ClassModem.c++
faxd/ClassModem.h
faxd/Getty.c++
faxd/Getty.h
faxd/faxGettyApp.c++
man/hylafax-config.4f

index af9a475f2a877affcb2152de05e2d2c4846a4e0f..c4c329bc92b86d1a598277b05f4dd5a4af3391c4 100644 (file)
@@ -80,19 +80,21 @@ const char* ClassModem::ATresponses[17] = {
     "<xon>",                   // AT_XON
     "<Unknown response>"       // 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) {
index 4d2c97dbb34ce39bc9e2d11c878de857fbe1647a..6b81117cb66567441383588a7830968940d60711 100644 (file)
@@ -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
index 2f0f88cca040e127df10831e769fca5ae4c4fce0..72d0e9a09764396bd9e11af4ec661746b5bd1f32 100644 (file)
@@ -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;
 }
 
index 25092e3296fef01bcba9f7da57139fcf46b87739..c216d000fb068fca2ce83c7944ff62d771345405 100644 (file)
@@ -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);
index a2880de7c22fa26e7a97ad0c5beafedff90e7a87..02b6bddaad49863f5d448630186b80d7e57e96a1 100644 (file)
@@ -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
index 45534b9a0a4c1b56f33defcbb7249a72e3861c32..27b93fc8dcfdc2bb4a8fc8ea3e9de704c551bdeb 100644 (file)
@@ -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