⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repos.c

📁 Apache V2.0.15 Alpha For Linuxhttpd-2_0_15-alpha.tar.Z
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. *//*** DAV filesystem-based repository provider*/#include "apr.h"#include "apr_file_io.h"#include "apr_strings.h"#if APR_HAVE_STDIO_H#include <stdio.h>              /* for sprintf() */#endif#include "httpd.h"#include "http_log.h"#include "http_protocol.h"	/* for ap_set_* (in dav_fs_set_headers) */#include "http_request.h"       /* for ap_update_mtime() */#include "mod_dav.h"#include "repos.h"/* to assist in debugging mod_dav's GET handling */#define DEBUG_GET_HANDLER       0#define DEBUG_PATHNAME_STYLE    0#define DAV_FS_COPY_BLOCKSIZE	16384	/* copy 16k at a time *//* context needed to identify a resource */struct dav_resource_private {    apr_pool_t *pool;        /* memory storage pool associated with request */    const char *pathname;   /* full pathname to resource */    apr_finfo_t finfo;       /* filesystem info */};/* private context for doing a filesystem walk */typedef struct {    /* the input walk parameters */    const dav_walk_params *params;    /* reused as we walk */    dav_walk_resource wres;    dav_resource res1;    dav_resource_private info1;    dav_buffer path1;    dav_buffer uri_buf;    /* MOVE/COPY need a secondary path */    dav_resource res2;    dav_resource_private info2;    dav_buffer path2;    dav_buffer locknull_buf;} dav_fs_walker_context;typedef struct {    int is_move;                /* is this a MOVE? */    dav_buffer work_buf;        /* handy buffer for copymove_file() */    /* CALLBACK: this is a secondary resource managed specially for us */    const dav_resource *res_dst;    /* copied from dav_walk_params (they are invariant across the walk) */    const dav_resource *root;    apr_pool_t *pool;} dav_fs_copymove_walk_ctx;/* an internal WALKTYPE to walk hidden files (the .DAV directory) */#define DAV_WALKTYPE_HIDDEN	0x4000/* an internal WALKTYPE to call collections (again) after their contents */#define DAV_WALKTYPE_POSTFIX    0x8000#define DAV_CALLTYPE_POSTFIX    1000    /* a private call type *//* pull this in from the other source file */extern const dav_hooks_locks dav_hooks_locks_fs;/* forward-declare the hook structures */static const dav_hooks_repository dav_hooks_repository_fs;static const dav_hooks_liveprop dav_hooks_liveprop_fs;/*** The namespace URIs that we use. This list and the enumeration must** stay in sync.*/static const char * const dav_fs_namespace_uris[] ={    "DAV:",    "http://apache.org/dav/props/",    NULL	/* sentinel */};enum {    DAV_FS_URI_DAV,		/* the DAV: namespace URI */    DAV_FS_URI_MYPROPS		/* the namespace URI for our custom props */};/*** The single property that we define (in the DAV_FS_URI_MYPROPS namespace)*/#define DAV_PROPID_FS_executable        1static const dav_liveprop_spec dav_fs_props[] ={    {        DAV_FS_URI_DAV,        "creationdate",        DAV_PROPID_creationdate,        0    },    {        DAV_FS_URI_DAV,        "getcontentlength",        DAV_PROPID_getcontentlength,        0    },    {        DAV_FS_URI_DAV,        "getetag",        DAV_PROPID_getetag,        0    },    {        DAV_FS_URI_DAV,        "getlastmodified",        DAV_PROPID_getlastmodified,        0    },    {        DAV_FS_URI_MYPROPS,        "executable",        DAV_PROPID_FS_executable,        0       /* handled special in dav_fs_is_writable */    },    { 0 }	/* sentinel */};static const dav_liveprop_group dav_fs_liveprop_group ={    dav_fs_props,    dav_fs_namespace_uris,    &dav_hooks_liveprop_fs};/* define the dav_stream structure for our use */struct dav_stream {    apr_pool_t *p;    apr_file_t *f;    const char *pathname;	/* we may need to remove it at close time */};/* forward declaration for internal treewalkers */static dav_error * dav_fs_walk(const dav_walk_params *params, int depth,                               dav_response **response);static dav_error * dav_fs_internal_walk(const dav_walk_params *params,                                        int depth, int is_move,                                        const dav_resource *root_dst,                                        dav_response **response);/* --------------------------------------------------------------------**** PRIVATE REPOSITORY FUNCTIONS*/apr_pool_t *dav_fs_pool(const dav_resource *resource){    return resource->info->pool;}const char *dav_fs_pathname(const dav_resource *resource){    return resource->info->pathname;}void dav_fs_dir_file_name(    const dav_resource *resource,    const char **dirpath_p,    const char **fname_p){    dav_resource_private *ctx = resource->info;    if (resource->collection) {        *dirpath_p = ctx->pathname;        if (fname_p != NULL)            *fname_p = NULL;    }    else {        char *dirpath = ap_make_dirstr_parent(ctx->pool, ctx->pathname);        apr_size_t dirlen = strlen(dirpath);        if (fname_p != NULL)            *fname_p = ctx->pathname + dirlen;        *dirpath_p = dirpath;        /* remove trailing slash from dirpath, unless it's the root dir */        /* ### Win32 check */        if (dirlen > 1 && dirpath[dirlen - 1] == '/') {            dirpath[dirlen - 1] = '\0';        }    }}/* Note: picked up from ap_gm_timestr_822() *//* NOTE: buf must be at least DAV_TIMEBUF_SIZE chars in size */static void dav_format_time(int style, apr_time_t sec, char *buf){    apr_exploded_time_t tms;        /* ### what to do if fails? */    (void) apr_explode_gmt(&tms, sec);    if (style == DAV_STYLE_ISO8601) {	/* ### should we use "-00:00" instead of "Z" ?? */	/* 20 chars plus null term */	sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ",               tms.tm_year + 1900, tms.tm_mon + 1, tms.tm_mday,               tms.tm_hour, tms.tm_min, tms.tm_sec);        return;    }    /* RFC 822 date format; as strftime '%a, %d %b %Y %T GMT' */    /* 29 chars plus null term */    sprintf(buf,	    "%s, %.2d %s %d %.2d:%.2d:%.2d GMT",           apr_day_snames[tms.tm_wday],           tms.tm_mday, apr_month_snames[tms.tm_mon],           tms.tm_year + 1900,           tms.tm_hour, tms.tm_min, tms.tm_sec);}static dav_error * dav_fs_copymove_file(    int is_move,    apr_pool_t * p,    const char *src,    const char *dst,    dav_buffer *pbuf){    dav_buffer work_buf = { 0 };    apr_file_t *inf = NULL;    apr_file_t *outf = NULL;    if (pbuf == NULL)	pbuf = &work_buf;    dav_set_bufsize(p, pbuf, DAV_FS_COPY_BLOCKSIZE);    if ((apr_file_open(&inf, src, APR_READ | APR_BINARY, APR_OS_DEFAULT, p)) 	!= APR_SUCCESS) {	/* ### use something besides 500? */	return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,			     "Could not open file for reading");    }    /* ### do we need to deal with the umask? */    if ((apr_file_open(&outf, dst, APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY,		 APR_OS_DEFAULT, p)) != APR_SUCCESS) {	apr_file_close(inf);	/* ### use something besides 500? */	return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,			     "Could not open file for writing");    }    while (1) {	apr_size_t len = DAV_FS_COPY_BLOCKSIZE;	apr_status_t status;	status = apr_file_read(inf, pbuf->buf, &len);	if (status != APR_SUCCESS && status != APR_EOF) {	    apr_file_close(inf);	    apr_file_close(outf);	    	    if (apr_file_remove(dst, p) != APR_SUCCESS) {		/* ### ACK! Inconsistent state... */		/* ### use something besides 500? */		return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,				     "Could not delete output after read "				     "failure. Server is now in an "				     "inconsistent state.");	    }	    /* ### use something besides 500? */	    return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,				 "Could not read input file");	}        /* write any bytes that were read (applies to APR_EOF, too) */        if (apr_file_write_full(outf, pbuf->buf, len, NULL) != APR_SUCCESS) {            int save_errno = errno;	    apr_file_close(inf);	    apr_file_close(outf);	    if (apr_file_remove(dst, p) != APR_SUCCESS) {		/* ### ACK! Inconsistent state... */		/* ### use something besides 500? */		return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,				     "Could not delete output after write "				     "failure. Server is now in an "				     "inconsistent state.");	    }	    if (save_errno == ENOSPC) {		return dav_new_error(p, HTTP_INSUFFICIENT_STORAGE, 0,				     "There is not enough storage to write to "				     "this resource.");	    }	    /* ### use something besides 500? */	    return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,				 "Could not write output file");	}        if (status == APR_EOF)            break;    }    apr_file_close(inf);    apr_file_close(outf);    if (is_move && apr_file_remove(src, p) != APR_SUCCESS) {	dav_error *err;	int save_errno = errno;	/* save the errno that got us here */	if (apr_file_remove(dst, p) != APR_SUCCESS) {	    /* ### ACK. this creates an inconsistency. do more!? */	    /* ### use something besides 500? */	    /* Note that we use the latest errno */	    return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,				 "Could not remove source or destination "				 "file. Server is now in an inconsistent "				 "state.");	}	/* ### use something besides 500? */	err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,			    "Could not remove source file after move. "			    "Destination was removed to ensure consistency.");	err->save_errno = save_errno;	return err;    }    return NULL;}/* copy/move a file from within a state dir to another state dir *//* ### need more buffers to replace the pool argument */static dav_error * dav_fs_copymove_state(    int is_move,    apr_pool_t * p,    const char *src_dir, const char *src_file,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -