?? filesystem.c++
字號:
logDebug("Filesystem has %s-style file creation semantics.", IS(SETGID) ? "BSD" : "SysV"); } state &= ~S_CHECKGID; } if (IS(SETGID)) { struct stat sb; if (!FileCache::lookup(file, sb)) { fatal("setFileOwner called for non-existent file (set)"); } if (!FileCache::chown(file, sb.st_uid, (gid_t) uid)) { logError("%s: chown: %s", file, strerror(errno)); } }}/* * Is the specified file visible to the client. */boolHylaFAXServer::fileVisible(const SpoolDir& dir, const char* filename, const struct stat& sb){ return (IS(PRIVILEGED) || (this->*dir.isVisibleFile)(filename, sb));}boolHylaFAXServer::isVisibletrue(const char*, const struct stat&) { return (true); }boolHylaFAXServer::isVisibleDocQFile(const char* filename, const struct stat&) { return (strncmp(filename, "doc", 3) == 0 || strncmp(filename, "cover", 5) == 0); }boolHylaFAXServer::isVisibleRootFile(const char*, const struct stat& sb) { return (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode)); }/* * Change the working (pseudo) directory. */voidHylaFAXServer::cwdCmd(const char* path){ SpoolDir* dir = dirAccess(path); if (dir) { if (Sys::chdir(path) >= 0) { ack(250, cmdToken(T_CWD)); cwd = dir; } else perror_reply(550, path, errno); }}/* * Return the path of the current working (pseudo) directory. */voidHylaFAXServer::pwdCmd(void){ u_int len = strlen(cwd->pathname)-1; // strip trailing "/" reply(257, "\"%.*s\" is the current directory.", len ? len : len+1, cwd->pathname);}/* * LIST a directory. */voidHylaFAXServer::listCmd(const char* pathname){ SpoolDir* sd = dirAccess(pathname); if (sd) { DIR* dir = opendir(pathname); if (dir != NULL) { int code; FILE* dout = openDataConn("w", code); if (dout != NULL) { reply(code, "%s for \"%s\".", dataConnMsg(code), pathname); if (setjmp(urgcatch) == 0) { state |= S_TRANSFER; (this->*sd->listDirectory)(dout, *sd, dir); fflush(dout); reply(226, "Transfer complete."); } state &= ~S_TRANSFER; closeDataConn(dout); } closedir(dir); } else if (errno != 0) perror_reply(550, pathname, errno); else reply(550, "%s: Cannot open directory.", pathname); }}voidHylaFAXServer::listDirectory(FILE* fd, const SpoolDir& sd, DIR* dir){ /* * Use an absolute pathname when doing file * lookups to improve cache locality. */ fxStr path(sd.pathname); struct dirent* dp; while ((dp = readdir(dir))) { if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || strcmp(dp->d_name, "..") == 0)) continue; struct stat sb; if (!FileCache::update(path | dp->d_name, sb)) continue; if ((this->*sd.isVisibleFile)(dp->d_name, sb)) { (this->*sd.listFile)(fd, sd, dp->d_name, sb); fputs("\r\n", fd); } }}voidHylaFAXServer::listUnixFile(FILE* fd, const SpoolDir&, const char* filename, const struct stat& sb){ Fprintf(fd, fileFormat, filename, sb);}static const char fformat[] = { 's', // a (last access time) 'b', // b 's', // c (create time) 'o', // d (device) 'e', // e 's', // f (filename) 'u', // g (GID of file) 'h', // h 'u', // i (inode number) 'j', // j 'k', // k 'u', // l (link count) 's', // m (last modification time) 'n', // n 's', // o (owner based on file GID) 's', // p (fax-style protection flags, no group bits) 's', // q (UNIX-style protection flags) 'o', // r (root device) 'u', // s (file size in bytes) 't', // t 'u', // u (UID of file) 'v', // v 'w', // w 'x', // x 'y', // y 'z' // z};/* * Print a formatted string with fields filled in from * a file's stat buffer. This functionality is * used to permit clients to get modem status listings * in preferred formats. */voidHylaFAXServer::Fprintf(FILE* fd, const char* fmt, const char* filename, const struct stat& sb){ for (const char* cp = fmt; *cp; cp++) { if (*cp == '%') {#define MAXSPEC 20 char fspec[MAXSPEC]; char* fp = fspec; *fp++ = '%'; char c = *++cp; if (c == '-') *fp++ = c, c = *++cp; if (isdigit(c)) { do { *fp++ = c; } while (isdigit(c = *++cp) && fp < &fspec[MAXSPEC-3]); } if (c == '.') { do { *fp++ = c; } while (isdigit(c = *++cp) && fp < &fspec[MAXSPEC-2]); } if (!islower(c)) { if (c == '%') // %% -> % putc(c, fd); else fprintf(fd, "%.*s%c", fp-fspec, fspec, c); continue; } fp[0] = fformat[c-'a']; // printf format string fp[1] = '\0'; switch (c) { case 'a': fprintf(fd, fspec, asctime(cvtTime(sb.st_atime))+4); break; case 'c': fprintf(fd, fspec, asctime(cvtTime(sb.st_ctime))+4); break; case 'd': fprintf(fd, fspec, (u_int) sb.st_dev); break; case 'f': fprintf(fd, fspec, filename); break; case 'g': fprintf(fd, fspec, (u_int) sb.st_gid); break; case 'i': fprintf(fd, fspec, (u_int) sb.st_ino); // XXX break; case 'l': fprintf(fd, fspec, (u_int) sb.st_nlink); break; case 'm': fprintf(fd, fspec, asctime(cvtTime(sb.st_mtime))+4); break; case 'o': fprintf(fd, fspec, userName((u_int) sb.st_gid)); break; case 'p': case 'q': { char prot[10]; // XXX HP C++ makeProt(sb, c == 'q', prot); fprintf(fd, fspec, prot); } break; case 'r': fprintf(fd, fspec, (u_int) sb.st_rdev); break; case 's': fprintf(fd, fspec, (u_int) sb.st_size); // XXX break; case 'u': fprintf(fd, fspec, (u_int) sb.st_uid); break; } } else putc(*cp, fd); }}voidHylaFAXServer::makeProt(const struct stat& sb, bool withGrp, char prot[10]){ char* pp = prot; *pp++ = S_ISREG(sb.st_mode) ? '-' : S_ISDIR(sb.st_mode) ? 'd' : S_ISFIFO(sb.st_mode) ? 'p' :#ifdef S_ISSOCK S_ISSOCK(sb.st_mode) ? 's' :#endif '?' ; *pp++ = (sb.st_mode&S_IRUSR) ? 'r' : '-'; *pp++ = (sb.st_mode&S_IWUSR) ? 'w' : '-'; *pp++ = (sb.st_mode&S_IXUSR) ? 'x' : '-'; if (withGrp) { *pp++ = (sb.st_mode&S_IRGRP) ? 'r' : '-'; *pp++ = (sb.st_mode&S_IWGRP) ? 'w' : '-'; *pp++ = (sb.st_mode&S_IXGRP) ? 'x' : '-'; } *pp++ = (sb.st_mode&S_IROTH) ? 'r' : '-'; *pp++ = (sb.st_mode&S_IWOTH) ? 'w' : '-'; *pp++ = (sb.st_mode&S_IXOTH) ? 'x' : '-'; *pp++ = '\0';}voidHylaFAXServer::statFileCmd(const char* pathname){ struct stat sb; SpoolDir* dir = fileAccess(pathname, X_OK, sb); if (dir) { (void) FileCache::update(pathname, sb); // insure up to date info lreply(211, "Status of %s:", pathname); const char* cp = strrchr(pathname, '/'); (this->*dir->listFile)(stdout, *dir, cp ? cp+1 : pathname, sb); fputs("\r\n", stdout); reply(211, "End of Status"); }}/* * NLST a directory. */voidHylaFAXServer::nlstCmd(const char* pathname){ SpoolDir* sd = dirAccess(pathname); if (sd) { DIR* dir = opendir(pathname); if (dir != NULL) { int code; FILE* dout = openDataConn("w", code); if (dout != NULL) { reply(code, "%s for \"%s\".", dataConnMsg(code), pathname); if (setjmp(urgcatch) == 0) { state |= S_TRANSFER; (this->*sd->nlstDirectory)(dout, *sd, dir); fflush(dout); reply(226, "Transfer complete."); } state &= ~S_TRANSFER; closeDataConn(dout); } closedir(dir); } else if (errno != 0) perror_reply(550, pathname, errno); else reply(550, "%s: Cannot open directory.", pathname); }}voidHylaFAXServer::nlstDirectory(FILE* fd, const SpoolDir& sd, DIR* dir){ /* * Use an absolute pathname when doing file * lookups to improve cache locality. */ fxStr path(sd.pathname); struct dirent* dp; while ((dp = readdir(dir))) { if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || strcmp(dp->d_name, "..") == 0)) continue; struct stat sb; if (!FileCache::update(path | dp->d_name, sb)) continue; if ((this->*sd.isVisibleFile)(dp->d_name, sb)) { (this->*sd.nlstFile)(fd, sd, dp->d_name, sb); fputs("\r\n", fd); } }}voidHylaFAXServer::nlstUnixFile(FILE* fd, const SpoolDir&, const char* filename, const struct stat&){ fprintf(fd, "%s", filename);}static boolisTIFF(const TIFFHeader& h){ if (h.tiff_magic != TIFF_BIGENDIAN && h.tiff_magic != TIFF_LITTLEENDIAN) return (false); union { int32 i; char c[4]; } u; u.i = 1; uint16 version = h.tiff_version; // byte swap version stamp if opposite byte order if ((u.c[0] == 0) ^ (h.tiff_magic == TIFF_BIGENDIAN)) TIFFSwabShort(&version); return (version == TIFF_VERSION);}boolHylaFAXServer::docType(const char* docname, FaxSendOp& op){ op = FaxRequest::send_unknown; int fd = Sys::open(docname, O_RDONLY); if (fd >= 0) { struct stat sb; if (FileCache::lookup(docname, sb) && S_ISREG(sb.st_mode)) { union { char buf[512]; TIFFHeader h; } b; ssize_t cc = Sys::read(fd, (char*) &b, sizeof (b)); if (cc > 2 && b.buf[0] == '%' && b.buf[1] == '!') op = FaxRequest::send_postscript; else if (cc > 2 && b.buf[0] == '%' && b.buf[1] == 'P') { logDebug("What we have here is a PDF file"); op = FaxRequest::send_pdf; } else if (cc > (ssize_t)sizeof (b.h) && isTIFF(b.h)) op = FaxRequest::send_tiff; else op = FaxRequest::send_data; } Sys::close(fd); } if (op == FaxRequest::send_unknown) logError("Don't know what file"); return (op != FaxRequest::send_unknown); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -