/* HTFile_readDir ** -------------- ** Reads the directory "path" ** Returns: ** HT_ERROR Error ** HT_FORBIDDEN Directory reading not allowed ** HT_LOADED Successfully read the directory */ PRIVATE int HTFile_readDir (HTRequest * request, file_info *file) { #ifdef HAVE_READDIR DIR * dp; struct stat file_info; HTParentAnchor * anchor = HTRequest_anchor(request); char *url = HTAnchor_physical(anchor); char fullname[HT_MAX_PATH+1]; char *name; HTTRACE(PROT_TRACE, "Reading..... directory\n"); if (dir_access == HT_DIR_FORBID) { HTRequest_addError(request, ERR_FATAL, NO, HTERR_FORBIDDEN, NULL, 0, "HTFile_readDir"); return HT_FORBIDDEN; } /* Initialize path name for stat() */ if (*(name = (url+strlen(url)-1)) != '/') { char *newurl = NULL; StrAllocCopy(newurl, url); StrAllocCat(newurl, "/"); HT_FREE(file->local); file->local = HTWWWToLocal(newurl, "", HTRequest_userProfile(request)); HT_FREE(newurl); } strcpy(fullname, file->local); name = fullname+strlen(fullname); /* Point to end of fullname */ /* Check if access is enabled */ if (dir_access == HT_DIR_SELECTIVE) { strcpy(name, DEFAULT_DIR_FILE); if (HT_STAT(fullname, &file_info)) { HTTRACE(PROT_TRACE, "Read dir.... `%s\' not found\n" _ DEFAULT_DIR_FILE); HTRequest_addError(request, ERR_FATAL, NO, HTERR_FORBIDDEN, NULL, 0, "HTFile_readDir"); return HT_FORBIDDEN; } } if ((dp = opendir(file->local))) { struct dirent * dirbuf; HTDir *dir = HTDir_new(request, dir_show, dir_key); char datestr[20]; char sizestr[10]; HTFileMode mode; #ifdef HT_REENTRANT struct dirent result; /* For readdir_r */ #endif #ifdef HAVE_READDIR_R_2 while ((dirbuf = (struct dirent *) readdir_r(dp, &result))) #elif defined(HAVE_READDIR_R_3) while (readdir_r(dp, &result, &dirbuf) == 0) #else while ((dirbuf = readdir(dp))) #endif /* HAVE_READDIR_R_2 */ { /* Current and parent directories are never shown in list */ #ifdef HAVE_DIRENT_INO if (!dirbuf->d_ino || !strcmp(dirbuf->d_name, ".") || !strcmp(dirbuf->d_name, "..")) #else if (!strcmp(dirbuf->d_name, ".") || !strcmp(dirbuf->d_name, "..")) #endif continue; /* Make a lstat on the file */ strcpy(name, dirbuf->d_name); if (HT_LSTAT(fullname, &file_info)) { HTTRACE(PROT_TRACE, "Read dir.... lstat failed: %s\n" _ fullname); continue; } /* Convert stat info to fit our setup */ if (((mode_t) file_info.st_mode & S_IFMT) == S_IFDIR) { #ifdef VMS char *dot = strstr(name, ".DIR"); /* strip .DIR part... */ if (dot) *dot = '\0'; #endif /* VMS */ mode = HT_IS_DIR; if (dir_show & HT_DS_SIZE) strcpy(sizestr, "-"); } else { mode = HT_IS_FILE; if (dir_show & HT_DS_SIZE) HTNumToStr(file_info.st_size, sizestr, 10); } if (dir_show & HT_DS_DATE) HTDateDirStr(&file_info.st_mtime, datestr, 20); /* Add to the list */ if (HTDir_addElement(dir, name, datestr, sizestr, mode) != YES) break; } closedir(dp); HTDir_free(dir); return HT_LOADED; } else { HTRequest_addSystemError(request, ERR_FATAL, errno, NO, "opendir"); return HT_ERROR; } #else return HT_ERROR; /* needed for WWW_MSWINDOWS */ #endif /* HAVE_READDIR */ }
PUBLIC char * HTDialog_progressMessage (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input) { char * result = NULL; switch (op) { case HT_PROG_DNS: StrAllocMCopy(&result, "Looking up ", input ? (char *) input : "", NULL); break; case HT_PROG_CONNECT: StrAllocMCopy(&result, "Contacting ", input ? (char *) input : "", NULL); break; case HT_PROG_ACCEPT: StrAllocCopy(result, "Waiting for connection..."); break; case HT_PROG_LOGIN: StrAllocCopy(result, "Logging in..."); break; case HT_PROG_READ: if (request) { long cl = HTAnchor_length(HTRequest_anchor(request)); if (cl > 0) { long b_read = HTRequest_bodyRead(request); double pro = (double) b_read/cl*100; char buf[10]; char pct[10]; HTNumToStr((unsigned long) cl, buf, 10); sprintf(pct, "%d%%", (int) pro); StrAllocMCopy(&result, "Read (", pct, " of ", buf, ")", NULL); } else { long b_read = HTRequest_bytesRead(request); int * raw_read = input ? (int *) input : NULL; if (b_read > 0) { char buf[10]; HTNumToStr(b_read, buf, 10); StrAllocMCopy(&result, "Read ", buf, "bytes", NULL); } else if (raw_read && *raw_read>0) { char buf[10]; HTNumToStr(*raw_read, buf, 10); StrAllocMCopy(&result, "Read ", buf, "bytes", NULL); } else { StrAllocCopy(result, "Reading..."); } } } break; case HT_PROG_WRITE: if (request && HTMethod_hasEntity(HTRequest_method(request))) { HTParentAnchor *anchor=HTRequest_anchor(HTRequest_source(request)); long cl = HTAnchor_length(anchor); if (cl > 0) { long b_write = HTRequest_bodyWritten(request); double pro = (double) b_write/cl*100; char buf[10]; char pct[10]; HTNumToStr((unsigned long) cl, buf, 10); sprintf(pct, "%d%%", (int) pro); StrAllocMCopy(&result, "Writing (", pct, " of ", buf, ")", NULL); } else { long b_written = HTRequest_bytesWritten(request); int * raw_written = input ? (int *) input : NULL; if (b_written > 0) { char buf[10]; HTNumToStr(b_written>0 ? b_written : 0, buf, 10); StrAllocMCopy(&result, "Writing ", buf, "bytes", NULL); } if (raw_written && *raw_written>0) { char buf[10]; HTNumToStr(*raw_written, buf, 10); StrAllocMCopy(&result, "Writing ", buf, "bytes", NULL); } else { StrAllocCopy(result, "Writing..."); } } } break; case HT_PROG_DONE: StrAllocCopy(result, "Done!"); break; case HT_PROG_INTERRUPT: StrAllocCopy(result, "Interrupted!"); break; case HT_PROG_OTHER: StrAllocCopy(result, "Working - please wait..."); break; case HT_PROG_TIMEOUT: StrAllocCopy(result, "Request timeout - server did not respond."); break; default: StrAllocCopy(result, "UNKNOWN PROGRESS STATE"); break; } return result; }