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

📄 htdav.c

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 C
📖 第 1 页 / 共 3 页
字号:
/*** WebDAV MANAGER****      (c) COPYRIGHT MIT 1995.**      Please first read the full copyright statement in the file COPYRIGH.**** Authors**      MKP     Manuele Kirsch Pinheiro, Manuele.Kirsch_Pinheiro@inrialpes.fr **                                       manuele@inf.ufrgs.br**** History**      15 Fev 02 Writen**      15 Mar 02 Changed - All methods will use entity callback and not the**                message body functions. This modification was demanded by**                Jose Kahan.**      30 May 02 Changed - wwwsys.h becames the first include file****      $Log: HTDAV.c,v $**      Revision 1.3  2002/05/30 18:08:56  kirschpi**      Minor changes concerning windows plataform (as STDIN_FILENO reference at**      myext.c and myext2.c) and concerning code readability.****      Revision 1.2  2002/05/29 16:09:13  kirschpi****      Fixes for windows plataform concerning WebDAV and Extension**      methods. In HTMethod and HTRequest, functions defined for**      the Extension Methods are now defined always, but return**      fail values when HT_EXT is not defined. In addition, the**      files "Library/src/WWWDAV.html" and "Library/src/windows/wwwdav.files"**      have been added. These files and modifications were needed**      to produce the correct "*.def" files, for windows plataform.****      Revision 1.1  2002/03/21 14:16:27  kirschpi**      Missing files**      Manuele Kirsch****** $Id: HTDAV.c,v 1.3 2002/05/30 18:08:56 kirschpi Exp $*//* Library include files */#include "wwwsys.h"#include "WWWLib.h"#include "WWWInit.h"#include "WWWUtil.h"#include "WWWStream.h"#include "HTDAV.h"              /* implemented here */#ifdef HT_DAVstruct _HTStream {    const HTStreamClass *       isa;    HTStream *                  target;    HTRequest *                 request;    int                         version;    BOOL                        endHeader;    BOOL                        transparent;};/* --------------------------------------------------------------------------*//*                           WebDAV REQUEST HEADERS                          *//* --------------------------------------------------------------------------*//* Headers defined in WebDAV - RC2518 ** If: state list _ may be a tagged or a non-tag list of state tokens and Etags** Depth: how depth the method should be executed. Values are: 0,1,infinity** Destination: destination URI for COPY and MOVE methods** Overwrite: should the method overwrite any existant resource? Values: T or F** LockToken: lock identification (used only in UNLOCK method)** Timeout: lock timeout. Values: Second-nnn,Infinite or Extend file (RFC2068) */struct _HTDAVHeaders {    char * If;    char * Depth;    char * Destination;    char * LockToken;    char * Timeout;    char Overwrite;};/*** Creates a new HTDAVHeaders struct */ PUBLIC HTDAVHeaders * HTDAVHeaders_new (void) {    HTDAVHeaders *me;    if ( (me = (HTDAVHeaders *) HT_CALLOC (1,sizeof(HTDAVHeaders))) == NULL)        HT_OUTOFMEM ("HTDAVHeaders_new");    /* set everything to an empty value */    me->If = NULL;    me->Depth = NULL;    me->Destination = NULL;    me->LockToken = NULL;    me->Timeout = NULL;    me->Overwrite = ' ';    HTTRACE (PROT_TRACE,"HTDAV.... HTDAVHeaders object created\n");    return me;} /*** Deletes a HTDAVHeaders object*/PUBLIC BOOL HTDAVHeaders_delete (HTDAVHeaders *me) {    if (me) {        if (me->If) HT_FREE (me->If);        if (me->Depth) HT_FREE (me->Depth);        if (me->Destination) HT_FREE (me->Destination);        if (me->LockToken) HT_FREE (me->LockToken);        if (me->Timeout) HT_FREE (me->Timeout);        HT_FREE (me);        HTTRACE (PROT_TRACE,"HTDAV.... HTDAVHeaders object removed\n");        return YES;    }    return NO;}/*** Set the If header - see section 9.4 of RFC2518 */ PUBLIC BOOL HTDAV_setIfHeader (HTDAVHeaders *me, const char *If) {    if (me && If && *If) {        HTTRACE (PROT_TRACE,"HTDAV.... If Header set\n");        StrAllocCopy (me->If,If);        return YES;    }    return NO;}/*** Removes the "If" header.*/PUBLIC BOOL HTDAV_deleteIfHeader (HTDAVHeaders * me) {    if (me && me->If) {        HT_FREE(me->If);        me->If = NULL;        return YES;    }    return NO;}/*** Return the "If" header, NULL if this header is not set.** The caller should FREE the returned string*/PUBLIC char * HTDAV_ifHeader (HTDAVHeaders *me) {    char *copy = NULL;    if (me && me->If) {        StrAllocCopy (copy,me->If);    }    return copy;}/*** Set the Depth header - see section 9.2 of RFC2518 */ PUBLIC BOOL HTDAV_setDepthHeader (HTDAVHeaders *me, const char *Depth) {    if (me && Depth && *Depth) {        HTTRACE (PROT_TRACE,"HTDAV.... Depth Header set\n");        StrAllocCopy (me->Depth,Depth);        return YES;    }    return NO;}/*** Removes the "Depth" header.*/PUBLIC BOOL HTDAV_deleteDepthHeader (HTDAVHeaders * me) {    if (me && me->Depth) {        HT_FREE (me->Depth);        me->Depth = NULL;        return YES;    }    return NO;}/*** Return the "Depth" header, NULL if this header is not set.** The caller should FREE the returned string*/PUBLIC char * HTDAV_DepthHeader (HTDAVHeaders *me) {    char *copy = NULL;    if (me && me->Depth) {        StrAllocCopy (copy,me->Depth);    }    return copy;}/*** Set the LockToken header - see section 9.5 of RFC2518 */ PUBLIC BOOL HTDAV_setLockTokenHeader (HTDAVHeaders *me, const char *LockToken) {    if (me && LockToken && *LockToken) {        HTTRACE (PROT_TRACE,"HTDAV.... Lock-Token Header set\n");        StrAllocCopy (me->LockToken,LockToken);        return YES;    }    return NO;}/*** Removes the "LockToken" header.*/PUBLIC BOOL HTDAV_deleteLockTokenHeader (HTDAVHeaders * me) {    if (me && me->LockToken) {        HT_FREE (me->LockToken);        me->LockToken = NULL;        return YES;    }    return NO;}/*** Return the "LockToken" header, NULL if this header is not set.** The caller should FREE the returned string*/PUBLIC char * HTDAV_LockTokenHeader (HTDAVHeaders *me) {    char *copy = NULL;    if (me && me->LockToken) {        StrAllocCopy (copy,me->LockToken);    }    return copy;}/*** Set the Destination header - see section 9.3 of RFC2518 */ PUBLIC BOOL HTDAV_setDestinationHeader (HTDAVHeaders *me, const char *Destination) {    if (me && Destination && *Destination) {        HTTRACE (PROT_TRACE,"HTDAV.... Destination Header set\n");        StrAllocCopy (me->Destination,Destination);        return YES;    }    return NO;}/*** Removes the "Destination" header.*/PUBLIC BOOL HTDAV_deleteDestinationHeader (HTDAVHeaders * me) {    if (me && me->Destination) {        HT_FREE (me->Destination);        me->Destination = NULL;        return YES;    }    return NO;}/*** Return the "Destination" header, NULL if this header is not set.** The caller should FREE the returned string*/PUBLIC char * HTDAV_DestinationHeader (HTDAVHeaders *me) {    char *copy = NULL;    if (me && me->Destination) {        StrAllocCopy (copy,me->Destination);    }    return copy;}/*** Set the Timeout header - see section 9.8 of RFC2518 */ PUBLIC BOOL HTDAV_setTimeoutHeader (HTDAVHeaders *me, const char *Timeout) {    if (me && Timeout && *Timeout) {        HTTRACE (PROT_TRACE,"HTDAV.... Timeout Header set\n");        StrAllocCopy (me->Timeout,Timeout);        return YES;    }    return NO;}/*** Removes the "Timeout" header.*/PUBLIC BOOL HTDAV_deleteTimeoutHeader (HTDAVHeaders * me) {    if (me && me->Timeout) {        HT_FREE (me->Timeout);        me->Timeout = NULL;        return YES;    }    return NO;}/*** Return the "Timeout" header, NULL if this header is not set.** The caller should FREE the returned string*/PUBLIC char * HTDAV_TimeoutHeader (HTDAVHeaders *me) {    char *copy = NULL;    if (me && me->Timeout) {        StrAllocCopy (copy,me->Timeout);    }    return copy;}/*** Set the Overwrite header - see section 9.6 of RFC2518*/PUBLIC BOOL HTDAV_setOverwriteHeader (HTDAVHeaders *me, BOOL Overwrite) {    if (me) {        HTTRACE (PROT_TRACE,"HTDAV.... Overwrite Header set\n");        me->Overwrite = (Overwrite)?'T':'F';        return YES;    }    return NO;}/*** Removes the "Overwirte" header.*/PUBLIC BOOL HTDAV_deleteOverwriteHeader (HTDAVHeaders * me) {    if (me) {        me->Overwrite = ' ';        return YES;    }    return NO;}/*** Returns the "Overwrite" header. If it is not set, returns the** default value (YES == TRUE)*/PUBLIC BOOL HTDAV_OverwriteHeader (HTDAVHeaders * me) {    if (me) {      return (me->Overwrite==' ' || me->Overwrite=='T')?YES:NO;    }    return YES;}/* --------------------------------------------------------------------------*//*                           ENTITY CALLBACK                                 *//* --------------------------------------------------------------------------*//*** Entity Callback - IDEM HTAccess.c*/PRIVATE int HTEntity_callback (HTRequest * request, HTStream * target){    HTParentAnchor * entity = HTRequest_entityAnchor(request);    HTTRACE(APP_TRACE, "Posting Data from callback function\n");    if (!request || !entity || !target) return HT_ERROR;    {        BOOL chunking = NO;        int status;        char * document = (char *) HTAnchor_document(entity);        int len = HTAnchor_length(entity);        if (!document) {           HTTRACE(PROT_TRACE, "Posting Data No document\n");           return HT_ERROR;        }        /*        ** If the length is unknown (-1) then see if the document is a text        ** type and in that case take the strlen. If not then we don't know        ** how much data we can write and must stop        */        if (len < 0) {            HTFormat actual = HTAnchor_format(entity);            HTFormat tmplate = HTAtom_for("text/*");            if (HTMIMEMatch(tmplate, actual)) {                len = strlen(document);                 /* Naive! */                chunking = YES;            } else {                HTTRACE(PROT_TRACE, "Posting Data Must know the length of document %p\n" _                              document);                return HT_ERROR;            }       }        /* Send the data down the pipe */        status = (*target->isa->put_block)(target, document, len);        if (status == HT_WOULD_BLOCK) {

⌨️ 快捷键说明

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