]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Add fxStackBuffer interface to Job/Modem/Recv *printf functions
authorAidan Van Dyk <aidan@ifax.com>
Fri, 2 May 2008 17:56:10 +0000 (17:56 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Fri, 2 May 2008 17:56:10 +0000 (17:56 +0000)
This allows us to use the *printf functions to generate data for more than
just direct output to file descriptors.

hfaxd/HylaFAXServer.h
hfaxd/Jobs.c++
hfaxd/RecvQueue.c++
hfaxd/Status.c++

index 3b98e2a8552ea76a1c3603a503af820561d2c3ee..179c549e6277093ae82b817bc8acbef5462b1bee 100644 (file)
@@ -36,6 +36,7 @@
 #include "FileCache.h"
 #include "Trace.h"
 #include "Trigger.h"
+#include "StackBuffer.h"
 #include "SystemLog.h"
 
 #include "config.h"
@@ -553,6 +554,7 @@ protected:
 
     const char* compactTime(time_t t);
     void Jprintf(FILE* fd, const char* fmt, const Job& job);
+    void Jprintf(fxStackBuffer& buf, const char* fmt, const Job& job);
 
     u_int getJobNumber(fxStr&);
     u_int getDocumentNumber(fxStr&);
@@ -561,9 +563,11 @@ protected:
     RecvInfo* getRecvInfo(const fxStr& qfile, const struct stat& sb);
     const char* compactRecvTime(time_t t);
     void Rprintf(FILE*, const char*, const RecvInfo&, const struct stat&);
+    void Rprintf(fxStackBuffer&, const char*, const RecvInfo&, const struct stat&);
 
     void getServerStatus(const char* fileName, fxStr& status);
     void Mprintf(FILE*, const char*, const ModemConfig&);
+    void Mprintf(fxStackBuffer&, const char*, const ModemConfig&);
 public:
     HylaFAXServer();
     virtual ~HylaFAXServer();
index 13a0603e9be7fc57ab933b207cb14a7a74bd8f79..8aa67ef63b978c9d1e68ef4c818678a8d2793fd8 100644 (file)
@@ -1763,7 +1763,7 @@ static const char jformat[] = {
  * preferred formats.
  */
 void
-HylaFAXServer::Jprintf(FILE* fd, const char* fmt, const Job& job)
+HylaFAXServer::Jprintf(fxStackBuffer& buf, const char* fmt, const Job& job)
 {
     /*
      * Check once to see if the client has access to
@@ -1797,184 +1797,191 @@ HylaFAXServer::Jprintf(FILE* fd, const char* fmt, const Job& job)
            }
            if (!isalpha(c)) {
                if (c == '%')           // %% -> %
-                   putc(c, fd);
+                   buf.put(c);
                else
-                   fprintf(fd, "%.*s%c", fp-fspec, fspec, c);
+                   buf.fput("%.*s%c", fp-fspec, fspec, c);
                continue;
            }
            fp[0] = jformat[c-'A'];     // printf format string
            fp[1] = '\0';
             switch (c) {
            case 'A':
-               fprintf(fd, fspec, (const char*) job.subaddr);
+               buf.fput(fspec, (const char*) job.subaddr);
                break;
            case 'B':
-               fprintf(fd, fspec, haveAccess ? (const char*) job.passwd : "");
+               buf.fput(fspec, haveAccess ? (const char*) job.passwd : "");
                break;
            case 'C':
-               fprintf(fd, fspec, (const char*) job.company);
+               buf.fput(fspec, (const char*) job.company);
                break;
            case 'D':
-               fprintf(fd, fspec, (const char*)fxStr::format("%2u:%-2u", job.totdials, job.maxdials));
+               buf.fput(fspec, (const char*)fxStr::format("%2u:%-2u", job.totdials, job.maxdials));
                break;
            case 'E':
-               fprintf(fd, fspec, job.desiredbr);
+               buf.fput(fspec, job.desiredbr);
                break;
            case 'F':
-               fprintf(fd, fspec, (const char*) job.tagline);
+               buf.fput(fspec, (const char*) job.tagline);
                break;
            case 'G':
-               fprintf(fd, fspec, job.desiredst);
+               buf.fput(fspec, job.desiredst);
                break;
            case 'H':
-               fprintf(fd, fspec, job.desireddf);
+               buf.fput(fspec, job.desireddf);
                break;
            case 'I':
-               fprintf(fd, fspec, job.usrpri);
+               buf.fput(fspec, job.usrpri);
                break;
            case 'J':
-               fprintf(fd, fspec, (const char*) job.jobtag);
+               buf.fput(fspec, (const char*) job.jobtag);
                break;
            case 'K':
-               fprintf(fd, fspec, "D HF"[job.desiredec]);
+               buf.fput(fspec, "D HF"[job.desiredec]);
                break;
            case 'L':
-               fprintf(fd, fspec, (const char*) job.location);
+               buf.fput(fspec, (const char*) job.location);
                break;
            case 'M':
-               fprintf(fd, fspec, (const char*) job.mailaddr);
+               buf.fput(fspec, (const char*) job.mailaddr);
                break;
            case 'N':
-               fprintf(fd, fspec, " P"[job.desiredtl]);
+               buf.fput(fspec, " P"[job.desiredtl]);
                break;
            case 'O':
-               fprintf(fd, fspec, "N "[job.useccover]);
+               buf.fput(fspec, "N "[job.useccover]);
                break;
            case 'P':
-               fprintf(fd, fspec, (const char*)fxStr::format("%2u:%-2u", job.npages, job.totpages));
+               buf.fput(fspec, (const char*)fxStr::format("%2u:%-2u", job.npages, job.totpages));
                break;
            case 'Q':
-               fprintf(fd, fspec, job.minbr);
+               buf.fput(fspec, job.minbr);
                break;
            case 'R':
-               fprintf(fd, fspec, (const char*) job.receiver);
+               buf.fput(fspec, (const char*) job.receiver);
                break;
            case 'S':
-               fprintf(fd, fspec, (const char*) job.sender);
+               buf.fput(fspec, (const char*) job.sender);
                break;
            case 'T':
-               fprintf(fd, fspec, (const char*)fxStr::format("%2u:%-2u", job.tottries, job.maxtries));
+               buf.fput(fspec, (const char*)fxStr::format("%2u:%-2u", job.tottries, job.maxtries));
                break;
            case 'U':
-               fprintf(fd, fspec, (const char*)fxStr::format("%.1f", job.chopthreshold));
+               buf.fput(fspec, (const char*)fxStr::format("%.1f", job.chopthreshold));
                break;
            case 'V':
-               fprintf(fd, fspec, (const char*) job.doneop);
+               buf.fput(fspec, (const char*) job.doneop);
                break;
            case 'W':
-               fprintf(fd, fspec, (const char*) job.commid);
+               buf.fput(fspec, (const char*) job.commid);
                break;
            case 'X':
-               fprintf(fd, fspec, toupper(job.jobtype[0]));
+               buf.fput(fspec, toupper(job.jobtype[0]));
                break;
            case 'Y':
-               { char buf[30];                         // XXX HP C++
-                 strftime(buf, sizeof (buf), "%Y/%m/%d %H.%M.%S",
+               { char tbuf[30];                                // XXX HP C++
+                 strftime(tbuf, sizeof (tbuf), "%Y/%m/%d %H.%M.%S",
                        IS(USEGMT) ? gmtime(&job.tts) : localtime(&job.tts));
-                 fprintf(fd, fspec, buf);
+                 buf.fput(fspec, tbuf);
                }
                break;
            case 'Z':
-               fprintf(fd, fspec, job.tts);
+               buf.fput(fspec, job.tts);
                break;
            case 'a':
-               fprintf(fd, fspec, "?TPSBWRDF"[job.state]);
+               buf.fput(fspec, "?TPSBWRDF"[job.state]);
                break;
            case 'b':
-               fprintf(fd, fspec, job.ntries);
+               buf.fput(fspec, job.ntries);
                break;
            case 'c':
-               fprintf(fd, fspec, (const char*) job.client);
+               buf.fput(fspec, (const char*) job.client);
                break;
            case 'd':
-               fprintf(fd, fspec, job.totdials);
+               buf.fput(fspec, job.totdials);
                break;
            case 'e':
-               fprintf(fd, fspec, (const char*) job.external);
+               buf.fput(fspec, (const char*) job.external);
                break;
            case 'f':
-               fprintf(fd, fspec, job.ndials);
+               buf.fput(fspec, job.ndials);
                break;
            case 'g':
-               fprintf(fd, fspec, (const char*) job.groupid);
+               buf.fput(fspec, (const char*) job.groupid);
                break;
            case 'h':
-               fprintf(fd, fspec, " DAL"[job.pagechop]);
+               buf.fput(fspec, " DAL"[job.pagechop]);
                break;
            case 'i':
-               fprintf(fd, fspec, job.pri);
+               buf.fput(fspec, job.pri);
                break;
            case 'j':
-               fprintf(fd, fspec, (const char*) job.jobid);
+               buf.fput(fspec, (const char*) job.jobid);
                break;
            case 'k':
-               fprintf(fd, fspec, compactTime(job.killtime));
+               buf.fput(fspec, compactTime(job.killtime));
                break;
            case 'l':
-               fprintf(fd, fspec, job.pagelength);
+               buf.fput(fspec, job.pagelength);
                break;
            case 'm':
-               fprintf(fd, fspec, (const char*) job.modem);
+               buf.fput(fspec, (const char*) job.modem);
                break;
            case 'n':
-               fprintf(fd, fspec, " DQA"[job.notify]);
+               buf.fput(fspec, " DQA"[job.notify]);
                break;
            case 'o':
-               fprintf(fd, fspec, (const char*) job.owner);
+               buf.fput(fspec, (const char*) job.owner);
                break;
            case 'p':
-               fprintf(fd, fspec, job.npages);
+               buf.fput(fspec, job.npages);
                break;
            case 'q':
-               fprintf(fd, fspec,
+               buf.fput(fspec,
                    job.retrytime == 0 ? "" : fmtTime(job.retrytime));
                break;
            case 'r':
-               fprintf(fd, fspec, job.resolution);
+               buf.fput(fspec, job.resolution);
                break;
            case 's':
-               fprintf(fd, fspec, job.result.string());
+               buf.fput(fspec, job.result.string());
                break;
            case 't':
-               fprintf(fd, fspec, job.tottries);
+               buf.fput(fspec, job.tottries);
                break;
            case 'u':
-               fprintf(fd, fspec, job.maxtries);
+               buf.fput(fspec, job.maxtries);
                break;
            case 'v':
-               fprintf(fd, fspec, haveAccess ? (const char*) job.number : "");
+               buf.fput(fspec, haveAccess ? (const char*) job.number : "");
                break;
            case 'w':
-               fprintf(fd, fspec, job.pagewidth);
+               buf.fput(fspec, job.pagewidth);
                break;
            case 'x':
-               fprintf(fd, fspec, job.maxdials);
+               buf.fput(fspec, job.maxdials);
                break;
            case 'y':
-               fprintf(fd, fspec, job.totpages);
+               buf.fput(fspec, job.totpages);
                break;
            case 'z':
-               fprintf(fd, fspec, compactTime(job.tts));
+               buf.fput(fspec, compactTime(job.tts));
                break;
            case '0':
-               fprintf(fd, fspec, "N "[job.usexvres]);
+               buf.fput(fspec, "N "[job.usexvres]);
                break;
            }
        } else
-           putc(*cp, fd);
+           buf.put(*cp);
     }
 }
 
+void
+HylaFAXServer::Jprintf(FILE* fd, const char* fmt, const Job& job)
+{
+    fxStackBuffer buf;
+    fwrite((const char*)buf, buf.getLength(), 1, fd);
+}
+
 void
 HylaFAXServer::listSendQ(FILE* fd, const SpoolDir&, DIR* dir)
 {
index b1ea2aaa03c15d0166f3b22b264b4326633ad819..861533b5122386eb0116aad720013354b8ec7a02 100644 (file)
@@ -369,7 +369,7 @@ HylaFAXServer::compactRecvTime(time_t t)
  * queue state listings in preferred formats.
  */
 void
-HylaFAXServer::Rprintf(FILE* fd, const char* fmt,
+HylaFAXServer::Rprintf(fxStackBuffer& buf, const char* fmt,
     const RecvInfo& ri, const struct stat& sb)
 {
     for (const char* cp = fmt; *cp; cp++) {
@@ -393,85 +393,94 @@ HylaFAXServer::Rprintf(FILE* fd, const char* fmt,
            }
            if (!isalpha(c)) {
                if (c == '%')           // %% -> %
-                   putc(c, fd);
+                   buf.put(c);
                else
-                   fprintf(fd, "%.*s%c", fp-fspec, fspec, c);
+                   buf.fput("%.*s%c", fp-fspec, fspec, c);
                continue;
            }
            fp[0] = rformat[c-'A'];     // printf format string
            fp[1] = '\0';
            switch (c) {
            case 'a':
-               fprintf(fd, fspec, (const char*) ri.subaddr);
+               buf.fput(fspec, (const char*) ri.subaddr);
                break;
            case 'b':
-               fprintf(fd, fspec, ri.params.bitRate());
+               buf.fput(fspec, ri.params.bitRate());
                break;
            case 'd':
-               fprintf(fd, fspec, ri.params.dataFormatName());
+               buf.fput(fspec, ri.params.dataFormatName());
                break;
            case 'e':
-               fprintf(fd, fspec, (const char*) ri.reason);
+               buf.fput(fspec, (const char*) ri.reason);
                break;
            case 'f':
                fp = (char *) strrchr(ri.qfile, '/');
-               fprintf(fd, fspec, fp ? fp+1 : (const char*) ri.qfile);
+               buf.fput(fspec, fp ? fp+1 : (const char*) ri.qfile);
                break;
            case 'h':
-               fprintf(fd, fspec, fmtTime(ri.time));
+               buf.fput(fspec, fmtTime(ri.time));
                break;
            case 'i':
-               fprintf(fd, fspec, ri.callid.size() > CallID::NAME ? (const char*) ri.callid.id(CallID::NAME) : "");
+               buf.fput(fspec, ri.callid.size() > CallID::NAME ? (const char*) ri.callid.id(CallID::NAME) : "");
                break;
            case 'j':
-               fprintf(fd, fspec, ri.callid.size() > CallID::NUMBER ? (const char*) ri.callid.id(CallID::NUMBER) : "");
+               buf.fput(fspec, ri.callid.size() > CallID::NUMBER ? (const char*) ri.callid.id(CallID::NUMBER) : "");
                break;
            case 'l':
-               fprintf(fd, fspec, ri.params.pageLength());
+               buf.fput(fspec, ri.params.pageLength());
                break;
            case 'm':
            case 'q':
                { char prot[8];                                 // XXX HP C++
                  makeProt(sb, c == 'q', prot);
-                 fprintf(fd, fspec, prot);
+                 buf.fput(fspec, prot);
                }
                break;
            case 'n':
-               fprintf(fd, fspec, (u_int) sb.st_size);         // XXX
+               buf.fput(fspec, (u_int) sb.st_size);            // XXX
                break;
            case 'o':
-               fprintf(fd, fspec, userName((u_int) sb.st_gid));
+               buf.fput(fspec, userName((u_int) sb.st_gid));
                break;
            case 'p':
-               fprintf(fd, fspec, ri.npages);
+               buf.fput(fspec, ri.npages);
                break;
            case 'r':
-               fprintf(fd, fspec, ri.params.verticalRes());
+               buf.fput(fspec, ri.params.verticalRes());
                break;
            case 's':
-               fprintf(fd, fspec, (const char*) ri.sender);
+               buf.fput(fspec, (const char*) ri.sender);
                break;
            case 't':
-               fprintf(fd, fspec, compactRecvTime(ri.recvTime));
+               buf.fput(fspec, compactRecvTime(ri.recvTime));
                break;
            case 'w':
-               fprintf(fd, fspec, ri.params.pageWidth());
+               buf.fput(fspec, ri.params.pageWidth());
                break;
            case 'z':
-               fprintf(fd, fspec, ri.beingReceived ? "*" : " ");
+               buf.fput(fspec, ri.beingReceived ? "*" : " ");
                break;
            case 'Y':
                { char tbuf[30];                                // XXX HP C++
                  strftime(tbuf, sizeof (tbuf), "%Y/%m/%d %H.%M.%S",
                        IS(USEGMT) ? gmtime(&ri.recvTime) : localtime(&ri.recvTime));
-                 fprintf(fd, fspec, tbuf);
+                 buf.fput(fspec, tbuf);
                }
                break;
            case 'Z':
-               fprintf(fd, fspec, ri.recvTime);
+               buf.fput(fspec, ri.recvTime);
                break;
            }
        } else
-           putc(*cp, fd);
+           buf.put(*cp);
     }
 }
+
+void
+HylaFAXServer::Rprintf(FILE* fd, const char* fmt,
+    const RecvInfo& ri, const struct stat& sb)
+{
+    fxStackBuffer buf;
+    Rprintf(buf, fmt, ri, sb);
+    fwrite((const char*)buf, buf.getLength(), 1, fd);
+}
index 0d03abf6e006012dfb6aaacb0c5851b7fe2558fb..a71ffc8dd508ecddf2f46ea23aae22c43ccdc985 100644 (file)
@@ -218,7 +218,7 @@ static const char mformat[] = {
  * in preferred formats.
  */
 void
-HylaFAXServer::Mprintf(FILE* fd, const char* fmt, const ModemConfig& config)
+HylaFAXServer::Mprintf(fxStackBuffer& buf, const char* fmt, const ModemConfig& config)
 {
     for (const char* cp = fmt; *cp; cp++) {
        if (*cp == '%') {
@@ -241,25 +241,25 @@ HylaFAXServer::Mprintf(FILE* fd, const char* fmt, const ModemConfig& config)
            }
            if (!islower(c)) {
                if (c == '%')           // %% -> %
-                   putc(c, fd);
+                   buf.put(c);
                else
-                   fprintf(fd, "%.*s%c", fp-fspec, fspec, c);
+                   buf.fput("%.*s%c", fp-fspec, fspec, c);
                continue;
            }
            fp[0] = mformat[c-'a'];     // printf format string
            fp[1] = '\0';
            switch (c) {
            case 'h':
-               fprintf(fd, fspec, (const char*) hostname);
+               buf.fput(fspec, (const char*) hostname);
                break;
            case 'l':
-               fprintf(fd, fspec, (const char*) config.localIdentifier);
+               buf.fput(fspec, (const char*) config.localIdentifier);
                break;
            case 'm':
-               fprintf(fd, fspec, (const char*) config.modemName);
+               buf.fput(fspec, (const char*) config.modemName);
                break;
            case 'n':
-               fprintf(fd, fspec, (const char*) config.FAXNumber);
+               buf.fput(fspec, (const char*) config.FAXNumber);
                break;
            case 'r':
         /* 
@@ -270,30 +270,39 @@ HylaFAXServer::Mprintf(FILE* fd, const char* fmt, const ModemConfig& config)
                *    tmp = fxStr::format("%u", config.maxRecvPages);
         * }
         */
-               fprintf(fd, fspec, config.maxRecvPages);
+               buf.fput(fspec, config.maxRecvPages);
                break;
            case 's':
-               fprintf(fd, fspec, (const char*) config.status);
+               buf.fput(fspec, (const char*) config.status);
                break;
             case 't': {
                            fxStr tmp = fxStr::format("%05x:%05x",
                         config.tracingLevel&0xfffff,
                         config.logTracingLevel&0xfffff);
-                    fprintf(fd, fspec, (const char*)tmp);
+                    buf.fput(fspec, (const char*)tmp);
                 }
                        break;
            case 'v':
-               fprintf(fd, fspec, " QLMH"[config.speakerVolume]);
+               buf.fput(fspec, " QLMH"[config.speakerVolume]);
                break;
            case 'z':
-               fprintf(fd, fspec, config.isGettyRunning ? '*' : ' ');
+               buf.fput(fspec, config.isGettyRunning ? '*' : ' ');
                break;
            }
        } else
-           putc(*cp, fd);
+           buf.put(*cp);
     }
 }
 
+void
+HylaFAXServer::Mprintf(FILE* fd, const char* fmt, const ModemConfig& config)
+{
+       fxStackBuffer buf;
+       Mprintf(buf, fmt, config);
+       fwrite((const char*)buf, buf.getLength(), 1, fd);
+}
+
+
 void
 HylaFAXServer::nlstStatus(FILE* fd, const SpoolDir& sd, DIR* dir)
 {