?? hylafaxserver.c++
字號(hào):
shutdownMsg = ""; char buf[1024]; while (fgets(buf, sizeof (buf), fd)) shutdownMsg.append(buf); ok = true; } else logError("%s: Invalid shutdown time, mktime conversion failed;" "Year=%d Mon=%d Day=%d Hour=%d Min=%d" , (const char*) shutdownFile , tm.tm_year+1900 , tm.tm_mon , tm.tm_mday , tm.tm_hour , tm.tm_min ); } else logError("%s: shutdown file format error", (const char*) shutdownFile); (void) fclose(fd); } else logError("%s: Cannot open shutdown file: %s", (const char*) shutdownFile, strerror(errno)); return (ok);}boolHylaFAXServer::isShutdown(bool quiet){ struct stat sb; if (shutdownFile == "" || Sys::stat(fixPathname(shutdownFile), sb) < 0) return (false); if (sb.st_mtime != lastModTime) { if (!readShutdownFile()) return (false); lastModTime = sb.st_mtime; } time_t now = Sys::now(); if (!quiet) { // possibly send client shutdown msg time_t timeToDisconnect = discTime - now; time_t lastMsg = now-lastTime; bool sendShutDownMsg = (lastTime == 0) // first time || (timeToDisconnect < 60) // <60 seconds, warn continuously // <15 minutes, warn ever 5 minutes || (timeToDisconnect < 15*60 && lastMsg > 5*60) // <24 hours, warn every 30 minutes || (timeToDisconnect < 24*60*60 && lastMsg > 30*60) // >24 hours, warn ever day || (timeToDisconnect < 24*60*60 && lastMsg >= 24*60*60) ; if (sendShutDownMsg) { autospout = shutdownMsg; // XXX append? lastTime = now; } } return (now > discTime);}voidHylaFAXServer::statusCmd(void){ lreply(211, "%s HylaFAX server status:", (const char*) hostname); printf(" %s\r\n", version); printf(" Connected to %s", (const char*) remotehost); if (!isdigit(remotehost[0])) printf(" (%s)", (const char*) remoteaddr); printf("\r\n"); if (IS(LOGGEDIN)) { printf(" Logged in as user %s (uid %u)%s\r\n" , (const char*) the_user , uid , IS(PRIVILEGED) ? " (with administrative privileges)" : "" ); u_int len = strlen(cwd->pathname)-1; // strip trailing "/" printf(" \"%.*s\" is the current directory\r\n", len ? len : len+1, cwd->pathname); printf(" Current job: "); if (curJob->jobid == "default") printf("(default)\r\n"); else printf("jobid %s groupid %s\r\n", (const char*) curJob->jobid, (const char*) curJob->groupid); } else if (IS(WAITPASS)) printf(" Waiting for password\r\n"); else printf(" Waiting for user name\r\n"); printf(" Time values are handled in %s\r\n", IS(USEGMT) ? "GMT" : tzname[0]); printf(" Idle timeout set to %d seconds\r\n", idleTimeout); printf(" %s long replies\r\n", IS(LREPLIES) ? "Using" : "Not using"); if (discTime > 0) printf(" Server scheduled to be unavailable at %.24s\r\n", asctime(cvtTime(discTime))); else printf(" No server down time currently scheduled\r\n"); printf(" HylaFAX scheduler reached at %s (%sconnected)\r\n" , (const char*) faxqFIFOName , faxqFd == -1 ? "not " : "" ); if (clientFd != -1) printf(" Server FIFO is /%s (%sopen)\r\n" , (const char*) clientFIFOName , clientFd == -1 ? "not " : "" ); if (IS(WAITFIFO)) printf(" Waiting for response from HylaFAX scheduler\r\n"); FileCache::printStats(stdout); printTransferStatus(stdout); netStatus(stdout); // transport-dependent status reply(211, "End of status");}intHylaFAXServer::inputReady(int fd){ if (fd == STDIN_FILENO) return parse(); else if (fd == clientFd) return FIFOInput(fd); fatal("Input ready on unknown file descriptor %d", fd); return (0); // to shutup compilers}voidHylaFAXServer::fatal(const char* fmt, ...){ va_list ap; va_start(ap, fmt); vreply(451, fxStr::format("Error in server: %s", fmt), ap); va_end(ap); reply(221, "Closing connection due to server error."); dologout(0); /*NOTREACHED*/}voidHylaFAXServer::reply(int code, const char* fmt, ...){ va_list ap; va_start(ap, fmt); vreply(code, fmt, ap); va_end(ap);}voidHylaFAXServer::vreply(int code, const char* fmt, va_list ap){ if (autospout != "") { printf("%d-", code); int i = 0; while (autospout[i] != '\0') { if (autospout[i] == '\n') { fputs("\r\n", stdout); if (autospout[++i]) printf("%d-", code); } else putchar(autospout[i++]); } if (autospout[--i] != '\n') printf("\r\n"); autospout = ""; } fxStackBuffer buf; buf.vput(fmt, ap); fprintf(stdout, "%d %.*s\r\n", code, buf.getLength(), (const char*) buf); fflush(stdout); if (TRACE(PROTOCOL)) logDebug("<--- %d %.*s", code, buf.getLength(), (const char*) buf);}voidHylaFAXServer::lreply(int code, const char* fmt, ...){ va_list ap; va_start(ap, fmt); vlreply(code, fmt, ap); va_end(ap);}voidHylaFAXServer::vlreply(int code, const char* fmt, va_list ap){ if (IS(LREPLIES)) { fxStackBuffer buf; buf.vput(fmt, ap); printf("%d-%.*s\r\n", code, buf.getLength(), (const char*) buf); fflush(stdout); if (TRACE(PROTOCOL)) logDebug("<--- %d-%.*s", code, buf.getLength(), (const char*) buf); }}/* Format and send reply containing system error number. */voidHylaFAXServer::perror_reply(int code, const char* string, int errnum){ reply(code, "%s: %s.", string, strerror(errnum));}voidHylaFAXServer::ack(int code, const char* s){ reply(code, "%s command successful.", s);}struct tm*HylaFAXServer::cvtTime(const time_t& t) const{ return IS(USEGMT) ? gmtime(&t) : localtime(&t);}u_int HylaFAXServer::getJobNumber(fxStr& emsg) { return (Sequence::getNext(FAX_SENDDIR "/" FAX_SEQF, emsg)); }u_int HylaFAXServer::getDocumentNumber(fxStr& emsg) { return (Sequence::getNext(FAX_DOCDIR "/" FAX_SEQF, emsg)); }voidHylaFAXServer::sanitize(fxStr& s){ for (u_int i = 0; i < s.length(); i++) if (!isascii(s[i]) || !isprint(s[i])) s[i] = '?';}/* * Convert modem name from canonical format back * to a pathname by replacing '_'s with '/'s. */voidHylaFAXServer::canonModem(fxStr& s){ u_int l = 0; while ((l = s.next(l, '_')) < s.length()) s[l] = '/';}/* * Convert pathname to a device ID by * replacing '/'s with '_'s. */voidHylaFAXServer::canonDevID(fxStr& s){ u_int l = 0; while ((l = s.next(l, '/')) < s.length()) s[l] = '_';}/* * Configuration support. */voidHylaFAXServer::resetConfig(){ FaxConfig::resetConfig(); setupConfig();}#define N(a) (sizeof (a) / sizeof (a[0]))HylaFAXServer::stringtag HylaFAXServer::strings[] = {{ "logfacility", &HylaFAXServer::logFacility, LOG_FAX },{ "faxcontact", &HylaFAXServer::faxContact, "FaxMaster" },{ "useraccessfile", &HylaFAXServer::userAccessFile, "/" FAX_PERMFILE },{ "shutdownfile", &HylaFAXServer::shutdownFile, "/etc/shutdown" },{ "xferfaxlogfile", &HylaFAXServer::xferfaxLogFile, "/etc/clientlog" },{ "jobfmt", &HylaFAXServer::jobFormat, "%-4j %3i %1a %6.6o %-12.12e %5P %5D %7z %.25s" },{ "rcvfmt", &HylaFAXServer::recvFormat, "%-7m %4p%1z %-8.8o %14.14s %7t %f" },{ "modemfmt", &HylaFAXServer::modemFormat, "Modem %m (%n): %s" },{ "filefmt", &HylaFAXServer::fileFormat, "%-7p %3l %8o %8s %-12.12m %.48f" },{ "faxqfifoname", &HylaFAXServer::faxqFIFOName, "/" FAX_FIFO },{ "systemtype", &HylaFAXServer::systemType, "UNIX Type: L8 Version: SVR4" },{ "admingroup", &HylaFAXServer::admingroup },};HylaFAXServer::numbertag HylaFAXServer::numbers[] = {{ "servertracing", &HylaFAXServer::tracingLevel, TRACE_SERVER },{ "idletimeout", &HylaFAXServer::idleTimeout, 900 },{ "maxidletimeout", &HylaFAXServer::maxIdleTimeout, 7200 },{ "maxloginattempts", &HylaFAXServer::maxLoginAttempts, 5 },{ "maxadminattempts", &HylaFAXServer::maxAdminAttempts, 5 },{ "maxconsecutivebadcmds",&HylaFAXServer::maxConsecutiveBadCmds,10 },{ "jobprotection", &HylaFAXServer::jobProtection, 0444 },};voidHylaFAXServer::setupConfig(){ int i; for (i = N(strings)-1; i >= 0; i--) (*this).*strings[i].p = (strings[i].def ? strings[i].def : ""); for (i = N(numbers)-1; i >= 0; i--) (*this).*numbers[i].p = numbers[i].def; faxContact.append("@" | hostname); admingroup = "faxadmin";}voidHylaFAXServer::configError(const char* fmt, ...){ va_list ap; va_start(ap, fmt); vlogError(fmt, ap); va_end(ap);}voidHylaFAXServer::configTrace(const char* fmt, ...){ if (TRACE(CONFIG)) { va_list ap; va_start(ap, fmt); vlogError(fmt, ap); va_end(ap); }}boolHylaFAXServer::setConfigItem(const char* tag, const char* value){ u_int ix; if (findTag(tag, (const tags*) strings, N(strings), ix)) { (*this).*strings[ix].p = value; switch (ix) { case 0: setLogFacility(logFacility); break; } } else if (findTag(tag, (const tags*) numbers, N(numbers), ix)) { (*this).*numbers[ix].p = getNumber(value); } else return (false); return (true);}#undef N
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -