📄 dirtype.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
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 name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
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 AUTHORS 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.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/HTTP/DirType.cpp,v $
* $Date: 2003/05/13 18:42:02 $
*
Description:
Set the MIME type only if this is a directory.
\*____________________________________________________________________________*/
//$SourceTop:$
#include "HandBase.h"
#include "HTTPCore.h"
#include "PIStrStr.h"
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define KEY_CONF_SETTYPE "SetType"
#if 0
/*
** HTML documentation for this handler
*/
/*___+++HTMLDOC_BEGIN+++___*/
Name:
CheckForDirectory
Description:
Check if the resources identified by the physical path is a directory. If
the resource is a directory then set the Content-Type of the resource to
the type identified by the 'SetType' parameter.
Options:
<H5>Overview</H5>
<TABLE BORDER=1>
<TH>Option
<TH>Default
<TH>Values
<TH>Short Description
<TH>Example(s)
<TR>
<TD>SetType
<TD>+
<TD>A MIME type/subtype pair
<TD>Internal directory MIME type
<TD>SetType="internal/x-directory"
</TABLE>
<STRONG>-</STRONG> in the <IT>default</IT> indicates no default<BR>
<STRONG>+</STRONG> in the <IT>default</IT> indicates the field is mandatory<BR>
<H4>Description of Options</H4>
<H5>
SetType
</H5>
The internal MIME type used to identify directory resources. Typically
this will be "internal/x-directory".
Phase:
CHECKTYPE
Returns:
PIAPI_COMPLETED if the resource was a directory and the Content-Type
was set to the type specified by the 'SetType' parameter.
Example:
<PRE>
<Object>
Name CheckForDirectory
Class CheckForDirectoryClass
</Object>
<Object>
...
CheckType CheckForDirectory SetType="internal/x-directory"
...
</Object>
</PRE>
/*___+++HTMLDOC_END+++___*/
#endif
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class CheckForDirectory : public HandlerBaseHTTP
{
private:
/* ---
Configuration data
--- */
PIString sSetType;
protected:
int Parameter( const char *pVariable, const char *pValue,
const char *pWhere )
{
assert( pVariable && pValue );
PIOStrStream os;
os << pWhere << "CheckForDirectory: ";
if ( !PIUtil_stricmp( KEY_CONF_SETTYPE, pVariable ) )
{
sSetType = pValue;
}
else
{
os << "Undefined parameter '" << pVariable << "'" << ends;
CONFIG_ERR( Object(), os.str() );
};
return 1;
};
public:
CheckForDirectory( PIObject *pObject, int iArgc, const char *ppArgv[] )
: HandlerBaseHTTP( pObject )
{
ReadParameters( iArgc, ppArgv );
/* ---
Check that the type was given
--- */
if ( sSetType==PIString::Empty() )
{
CONFIG_ERR( pObject, "CheckForDirectory: 'SetType' not \
defined" );
SetOK( 0 );
return;
};
};
int Handle( int iPhase, PIHTTP &tPIHTTP, PIIOBuffer &/* tBuffer */ )
{
if ( iPhase!=PH_CHECKTYPE ) { return PIAPI_ERROR; };
PIDB *pR = tPIHTTP.pResponseDB;
const char *pPath = (const char *)PIDB_lookup( pR,
PIDBTYPE_STRING, KEY_INT_PATH, 0 );
PIFInfo *pFInfo = HTTPCore_getCachedFile( pPath );
/* ---
If this is not a directory return CONTINUE, otherwise set
the mime type as given
--- */
int iDirectory = PIFInfo_isDirectory( pFInfo );
HTTPCore_releaseCachedFile( pFInfo );
if ( !iDirectory )
{ return PIAPI_CONTINUE; }
else
{
PIDB_add( pR, PIDBTYPE_RFC822, KEY_HTTP_CONTENTTYPE,
(void *)(const char *)sSetType, 0 );
};
return PIAPI_COMPLETED;
};
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI int CheckForDirectory_constructor( PIObject *pObj,
int iArgc, const char *ppArgv[] )
{
return HandlerBaseHTTP_constructor( pObj, PI_NEW( CheckForDirectory( pObj,
iArgc, ppArgv ) ) );
}
#if 0
/*___+++CNF_BEGIN+++___*/
<Class>
Name CheckForDirectoryClass
Type LogicExtension
Library HTTP
OnClassLoad HandlerBaseHTTP_onClassLoad
Constructor CheckForDirectory_constructor
CopyConstructor HandlerBaseHTTP_copyConstructor
Destructor HandlerBaseHTTP_destructor
Execute HandlerBaseHTTP_execute
</Class>
<Object>
Name CheckForDirectory
Class CheckForDirectoryClass
</Object>
/*___+++CNF_END+++___*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -