]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Bug 601: hfaxd fixes for the FIFO, jobs cache size, and ABOR command
authorLee Howard <faxguy@howardsilvan.com>
Tue, 23 Nov 2004 21:04:07 +0000 (21:04 +0000)
committerLee Howard <faxguy@howardsilvan.com>
Tue, 23 Nov 2004 21:04:07 +0000 (21:04 +0000)
CHANGES
hfaxd/FIFO.c++
hfaxd/InetFaxServer.c++
hfaxd/Jobs.c++
hfaxd/Trigger.c++

diff --git a/CHANGES b/CHANGES
index 99ae5d91acec3fd9f2ad58128d9e46e413b8b3ef..c828537e397b4cd7b93437192c8f04f7862a58c9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 
 Changelog for HylaFAX 4.2.1
 
+* limit hfaxd jobs cache size (23 Nov 2004)
+* fix hfaxd ABOR command and trigger (23 Nov 2004)
+* fix error when hfaxd FIFO fills (23 Nov 2004)
 * document -age option for recvstats/xferfaxstats (23 Nov 2004)
 * add coversheet information into the q-file (23 Nov 2004)
 * fix documentation regarding DesiredEC (23 Nov 2004)
index dd23b48fe47c7f252e3baa9cf244f4badf21f5b0..0c084a524c4b248d6bcc350df92b7ef41d0fbd73 100644 (file)
@@ -72,6 +72,8 @@ HylaFAXServer::FIFOInput(int fd)
     char buf[2048];
     int cc;
     while ((cc = Sys::read(fd, buf, sizeof (buf)-1)) > 0) {
+       if (cc == sizeof(buf)-1)
+           logWarning("FIFO Read full: %d", cc);
        buf[cc] = '\0';
        char* bp = &buf[0];
        do {
@@ -82,13 +84,40 @@ HylaFAXServer::FIFOInput(int fd)
                 * Setup the unpacking work and dispatch it.
                 */
                TriggerMsgHeader h;
-               memcpy(&h, bp, sizeof (h));             // copy to align fields
-               if (&buf[cc]-bp < h.length) {
-                   // XXX need more data to complete msg/should not happen
+               int left = &buf[cc]-bp;
+               bool needy = false;
+               if (left < sizeof(TriggerMsgHeader))
+               {
+                   needy = true;
+               } else
+               {
+                   memcpy(&h, bp, sizeof (h));         // copy to align fields
+                   if (left < h.length)
+                       needy = true;
+               }
+               if (needy)
+               {
+                   /*
+                    * Handle the case where the buffer was read full.  This means that
+                    * we have a "partial" message at the end of buf, and the rest in
+                    * the FIFO.
+                    *
+                    * buf[n] is NEVER read from the file, it's always 1-past.  If we
+                    * have reached buf[n], we know we are past the read data.
+                    *
+                    * We have (left) bytes of the message at the end of the buf.
+                    * We move them to the front, and read as much more as we can to
+                    * fill buf back up, leaving it in the same state as if this was
+                    * the initial read.
+                    */
+                   memmove(buf, bp, left);
+                   cc = Sys::read(fd, buf+left, (sizeof(buf)-1) - left) + left;
+                   buf[cc] = '\0';
+                   bp = &buf[0];
                } else {
                    triggerEvent(h, bp+sizeof (h));
+                   bp += h.length;
                }
-               bp += h.length;
            } else {
                /*
                 * Break up '\0'-separated records and strip
@@ -96,6 +125,29 @@ HylaFAXServer::FIFOInput(int fd)
                 * works (i.e. echo appends a '\n' character).
                 */
                char* cp = strchr(bp, '\0');
+
+               /*
+                * Handle the case where the buffer was read full.  This means that
+                * we have a "partial" message at the end of buf, and the rest in
+                * the FIFO.
+                *
+                * buf[n] is NEVER read from the file, it's always 1-past.  If we
+                * have reached buf[n], we know we are past the read data.
+                *
+                * We have (cp - bp) bytes of the message at the end of the buf.
+                * We move them to the front, and read as much more as we can to
+                * fill buf back up, leaving it in the same state as if this was
+                * the initial read.
+                */
+               if (cp == &buf[sizeof(buf)-1])
+               {
+                   memmove(buf, bp, cp-bp);
+                   cc = Sys::read(fd, buf+(cp-bp), (sizeof(buf)-1) - (cp-bp)) + (cp-bp);
+                   buf[cc] = '\0';
+                   bp = &buf[0];
+                   cp = strchr(bp, '\0');
+               }
+
                if (cp > bp) {
                    if (cp[-1] == '\n') {
                        cp[-1] = '\0';
index daea5b68c3886c20a35d2fc638c190df8aac5aa7..08afae6e717a90a6dba2a8f50cda4aa65e2c49e6 100644 (file)
@@ -289,7 +289,7 @@ InetFaxServer::handleUrgentData(void)
     if (!getCmdLine(line, sizeof (line))) {
         reply(221, "You could at least say goodbye.");
         dologout(0);
-    } else if (strcasecmp(line, "ABOR\r\n") == 0) {
+    } else if (strcasecmp(line, "ABOR\n") == 0) {
        /*
         * Abort the operation in progress.  Two reply
         * codes are sent on the control channel; one
@@ -299,7 +299,7 @@ InetFaxServer::handleUrgentData(void)
         reply(426, "Operation aborted. Data connection closed.");
         reply(226, "Abort successful");
         longjmp(urgcatch, 1);          // XXX potential memory leak
-    } else if (strcasecmp(line, "STAT\r\n") == 0) {
+    } else if (strcasecmp(line, "STAT\n") == 0) {
         if (file_size != (off_t) -1)
             reply(213, "Status: %lu of %lu bytes transferred",
                   byte_count, file_size);
index d2a7b0fd9a51d0f70717cf3f2c73c7e46f31b293..398edabe1eab71093120be91efca3bc1d1f8d779 100644 (file)
@@ -1093,6 +1093,21 @@ HylaFAXServer::findJob(const char* jobid, fxStr& emsg)
        if (!checkJobState(job))
            emsg = "job deleted by another party";
     } else {
+       /*
+        * We can only afford a certain amount of space,
+        * unfortunately, there is no "bright" way to remove jobs
+        * Ideally we'ld have an "aging" method, so the LRU job
+        * would be the one deleted...
+        */
+       if (jobs.size() > 10)
+       {
+           JobDictIter iter(jobs);
+           job = iter.value();
+           logError("Removing: %s", (const char*)job->jobid);
+           jobs.remove(job->jobid);
+           delete job;
+       }
+
        job = findJobOnDisk(jobid, emsg);
        if (job)
            jobs[job->jobid] = job;
index a40ecdaa4c2758c17d1f0f2dfcaa34f222d685d3..0489d1ee851ead2b507175a816438f38f5a7d2b5 100644 (file)
@@ -75,7 +75,8 @@ HylaFAXServer::triggerCmd(const char* fmt ...)
                 */
                for (;;)
                    Dispatcher::instance().dispatch();
-           }
+           } else
+               perror_reply(426, "Data connection", errno);
            state &= ~S_TRANSFER;
            (void) cancelTrigger(emsg);
        } else