Roxen.git / server / modules / filesystems / filesystem.pike

version» Context lines:

Roxen.git/server/modules/filesystems/filesystem.pike:1: - // This is a roxen module. Copyright © 1996 - 1998, Idonex AB. + // This is a roxen module. Copyright © 1996 - 1999, Idonex AB.      // This is a virtual "file-system".   // It will be located somewhere in the name-space of the server.   // Also inherited by some of the other filesystems.      inherit "module";   inherit "roxenlib";   inherit "socket";    - constant cvs_version= "$Id: filesystem.pike,v 1.60 1999/12/22 16:59:50 jhs Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.61 1999/12/28 03:12:21 nilsson Exp $";   constant thread_safe=1;    -  +    #include <module.h>   #include <roxen.h>   #include <stat.h>   #include <request_trace.h>      #if DEBUG_LEVEL > 20   # ifndef FILESYSTEM_DEBUG   # define FILESYSTEM_DEBUG   # endif   #endif    -  + #ifdef FILESYSTEM_DEBUG + # define FILESYSTEM_WERR(X) werror("Filesystem: "+X+"\n") + #else + # define FILESYSTEM_WERR(X) + #endif +  + #ifdef QUOTA_DEBUG + # define QUOTA_WERR(X) werror("QUOTA: "+X+"\n") + #else + # define QUOTA_WERR(X) + #endif +    constant module_type = MODULE_LOCATION;   constant module_name = "Filesystem";   constant module_doc =   ("This is a virtual filesystem, use it to make files available to "+    "the users of your WWW-server. If you want to serve any 'normal' "    "files from your server, you will have to have atleast one filesystem.") ;   constant module_unique = 0;    -  -  +    int redirects, accesses, errors, dirlists;   int puts, deletes, mkdirs, moves, chmods;      static mapping http_low_answer(int errno, string data, string|void desc)   {    mapping res = ::http_low_answer(errno, data);       if (desc) {    res->rettext = desc;    }       return res;   }      static int do_stat = 1;      string status()   { -  return ("<h2>Accesses to this filesystem</h2>"+ +  return "<h2>Accesses to this filesystem</h2>"+    (redirects?"<b>Redirects</b>: "+redirects+"<br>":"")+    (accesses?"<b>Normal files</b>: "+accesses+"<br>"    :"No file accesses<br>")+    (QUERY(put)&&puts?"<b>Puts</b>: "+puts+"<br>":"")+    (QUERY(put)&&mkdirs?"<b>Mkdirs</b>: "+mkdirs+"<br>":"")+    (QUERY(put)&&QUERY(delete)&&moves?    "<b>Moved files</b>: "+moves+"<br>":"")+    (QUERY(put)&&chmods?"<b>CHMODs</b>: "+chmods+"<br>":"")+    (QUERY(delete)&&deletes?"<b>Deletes</b>: "+deletes+"<br>":"")+    (errors?"<b>Permission denied</b>: "+errors    +" (not counting .htaccess)<br>":"")+ -  (dirlists?"<b>Directories</b>:"+dirlists+"<br>":"")); +  (dirlists?"<b>Directories</b>:"+dirlists+"<br>":"");   }      void create()   {    defvar("mountpoint", "/", "Mount point", TYPE_LOCATION,    "This is where the module will be inserted in the "+    "namespace of your server.");       defvar("searchpath", "NONE", "Search path", TYPE_DIR,    "This is where the module will find the files in the real "+
Roxen.git/server/modules/filesystems/filesystem.pike:134: Inside #if defined(THREADS)
  {   #ifdef THREADS    if(QUERY(access_as_user))    report_warning("It is not possible to use 'Access as user' when "    "running with threads. Remove -DENABLE_THREADS from "    "the start script if you really need this function\n");   #endif       path = QUERY(searchpath);    stat_cache = QUERY(stat_cache); - #ifdef FILESYSTEM_DEBUG -  werror("FILESYSTEM: Online at "+QUERY(mountpoint)+" (path="+path+")\n"); - #endif +  FILESYSTEM_WERR("Online at "+QUERY(mountpoint)+" (path="+path+")");   }      string query_location()   {    return QUERY(mountpoint);   }         mixed stat_file( mixed f, mixed id )   {
Roxen.git/server/modules/filesystems/filesystem.pike:244:   void done_with_put( array(object|string) id_arr )   {   // werror("Done with put.\n");    object to;    object from;    object id;    string oldf;       [to, from, id, oldf] = id_arr;    - #ifdef FILESYSTEM_DEBUG -  werror(sprintf("done_with_put(%O)\n" +  FILESYSTEM_WERR(sprintf("done_with_put(%O)\n"    "from: %O\n",    id_arr, mkmapping(indices(from), values(from)))); - #endif /* FILESYSTEM_DEBUG */ +        to->close();    from->set_blocking();    m_delete(putting, from);       if (putting[from] && (putting[from] != 0x7fffffff)) {    // Truncated!    id->send_result(http_low_answer(400,    "<h2>Bad Request - "    "Expected more data.</h2>"));
Roxen.git/server/modules/filesystems/filesystem.pike:361:   }      mixed find_file( string f, object id )   {    TRACE_ENTER("find_file(\""+f+"\")", 0);    object o;    int size;    string tmp;    string oldf = f;    - #ifdef FILESYSTEM_DEBUG -  werror("FILESYSTEM: Request for \""+f+"\"\n"); - #endif /* FILESYSTEM_DEBUG */ +  FILESYSTEM_WERR("Request for \""+f+"\"");       string mountpoint = QUERY(mountpoint);       string uri = combine_path(mountpoint + "/" + f, ".");       f = path + f;   #ifdef __NT__    if(f[-1]=='/') f = f[..strlen(f)-2];   #endif    size = FILE_SIZE( f );
Roxen.git/server/modules/filesystems/filesystem.pike:542:    }       if(QUERY(check_auth) && (!id->auth || !id->auth[0])) {    TRACE_LEAVE("PUT: Permission denied");    return http_auth_required("foo",    "<h1>Permission to 'PUT' files denied</h1>");    }       puts++;    - #ifdef QUOTA_DEBUG -  report_debug("Checking quota.\n"); - #endif /* QUOTA_DEBUG */ +  QUOTA_WERR("Checking quota.\n");    if (id->misc->quota_obj && (id->misc->len > 0) &&    !id->misc->quota_obj->check_quota(uri, id->misc->len)) {    errors++;    report_warning("Creation of " + f + " failed. Out of quota.\n");    TRACE_LEAVE("PUT: Out of quota.");    return http_low_answer(413, "<h2>Out of disk quota.</h2>",    "413 Out of disk quota");    }       object privs;
Roxen.git/server/modules/filesystems/filesystem.pike:577:    TRACE_LEAVE("PUT: Contains symlinks. Permission denied");    return http_low_answer(403, "<h2>Permission denied.</h2>");    }       TRACE_ENTER("PUT: Accepted", 0);       rm( f );    mkdirhier( f );       if (id->misc->quota_obj) { - #ifdef QUOTA_DEBUG -  report_debug("Checking if the file already exists.\n"); - #endif /* QUOTA_DEBUG */ +  QUOTA_WERR("Checking if the file already exists.");    if (size > 0) { - #ifdef QUOTA_DEBUG -  report_debug("Deallocating " + size + "bytes.\n"); - #endif /* QUOTA_DEBUG */ +  QUOTA_WERR("Deallocating " + size + "bytes.");    id->misc->quota_obj->deallocate(uri, size);    }    if (size) { - #ifdef QUOTA_DEBUG -  report_debug("Deleting old file.\n"); - #endif /* QUOTA_DEBUG */ +  QUOTA_WERR("Deleting old file.");    rm(f);    }    }       /* Clear the stat-cache for this file */    if (stat_cache) {    cache_set("stat_cache", f, 0);    }       object to = open(f, "wct");
Roxen.git/server/modules/filesystems/filesystem.pike:623:       putting[id->my_fd] = id->misc->len;    if(id->data && strlen(id->data))    {    // FIXME: What if sizeof(id->data) > id->misc->len ?    if (id->misc->len > 0) {    putting[id->my_fd] -= strlen(id->data);    }    int bytes = to->write( id->data );    if (id->misc->quota_obj) { - #ifdef QUOTA_DEBUG -  report_debug("Allocating " + bytes + "bytes.\n"); - #endif /* QUOTA_DEBUG */ +  QUOTA_WERR("Allocating " + bytes + "bytes.");    if (!id->misc->quota_obj->allocate(f, bytes)) {    TRACE_LEAVE("PUT: A string");    TRACE_LEAVE("PUT: Out of quota");    return http_low_answer(413, "<h2>Out of disk quota.</h2>",    "413 Out of disk quota");    }    }    }    if(!putting[id->my_fd]) {    TRACE_LEAVE("PUT: Just a string");
Roxen.git/server/modules/filesystems/filesystem.pike:691:    }       chmods++;       TRACE_ENTER("CHMOD: Accepted", 0);       if (stat_cache) {    cache_set("stat_cache", f, 0);    }   #ifdef DEBUG -  report_notice(sprintf("CHMODing file "+f+" to 0%o\n", id->misc->mode)); +  werror(sprintf("CHMODing file "+f+" to 0%o\n", id->misc->mode));   #endif    array err = catch(chmod(f, id->misc->mode & 0777));    privs = 0;       if(err)    {    id->misc->error_code = 403;    TRACE_LEAVE("CHMOD: Failure");    TRACE_LEAVE("Failure");    return 0;
Roxen.git/server/modules/filesystems/filesystem.pike:777: Inside #if defined(__NT__)
   /* Clear the stat-cache for this file */   #ifdef __NT__    // if(movefrom[-1] == '/')    // movefrom = move_from[..strlen(movefrom)-2];   #endif    if (stat_cache) {    cache_set("stat_cache", movefrom, 0);    cache_set("stat_cache", f, 0);    }   #ifdef DEBUG -  report_notice("Moving file "+movefrom+" to "+ f+"\n"); - #endif /* DEBUG */ +  werror("Moving file "+movefrom+" to "+ f+"\n"); + #endif       int code = mv(movefrom, f);    privs = 0;       if(!code)    {    id->misc->error_code = 403;    TRACE_LEAVE("MV: Move failed");    TRACE_LEAVE("Failure");    return 0;
Roxen.git/server/modules/filesystems/filesystem.pike:882: Inside #if defined(__NT__)
   /* Clear the stat-cache for this file */   #ifdef __NT__    // if(movefrom[-1] == '/')    // movefrom = move_from[..strlen(movefrom)-2];   #endif    if (stat_cache) {    cache_set("stat_cache", moveto, 0);    cache_set("stat_cache", f, 0);    }   #ifdef DEBUG -  report_notice("Moving file " + f + " to " + moveto + "\n"); - #endif /* DEBUG */ +  werror("Moving file " + f + " to " + moveto + "\n"); + #endif       int code = mv(f, moveto);    privs = 0;       if(!code)    {    id->misc->error_code = 403;    TRACE_LEAVE("MOVE: Move failed");    TRACE_LEAVE("Failure");    return 0;