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

📄 _piapi.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 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/Pi2API/_PiAPI.cpp,v $
 * $Date: 2003/05/13 18:42:09 $
 *
 Description:
	Implementation of Pi2API.

	These function call through to the internal functions which implement
	the API facilities. No functionality is implemented here. At most
	parameter validation occurs.
\*____________________________________________________________________________*/
//$SourceTop:$

#include <fstream.h>

#include "Pi2API.h"
#include "PIDBTree.h"
#include "PIConfDB.h"
#include "_PIDBUtl.h"
#include "_PIDBEx.h"

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIDB *PIDB_new( PIDB *pParent, const char *pName )
{
	return PI_NEW( PIDBTree( pParent, pName ) );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIDB *PIDBEx_new( PIDB *pParent, const char *pName,
	void *(* fnLookup)( PIDB *, int, const char *, int ) )
{
	if ( !fnLookup )
		{ return 0; };
	return PI_NEW( _PIDBEx( pParent, pName, fnLookup ) );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIDB *PIDB_getParent( PIDB *pThis )
{
	if ( !pThis ) 	{ return pThis; };
	return pThis->GetParent();
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDB_add( PIDB *pTree, int iType, const char *pKey, void *pV,
	int iFlags )
{
	if ( !pTree ) 	{ return PIAPI_EINVAL; };
	return pTree->Add( iType, pKey, pV, iFlags );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDB_replace( PIDB *pTree, int iType, const char *pKey,
	void *pV, int iFlags )
{
	if ( !pTree )
		{ return PIAPI_EINVAL; };
	return pTree->Replace( iType, pKey, pV, iFlags );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI const char *PIDB_getFastKey( const char *pKey, int iType )
{
	if ( !pKey ) 	{ return 0; };
	return PIDBTree::GetFastKey( pKey, iType );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDB_pidbtypeNameToNumber( const char *pType )
{
	if ( !pType )
		{ return PIDBTYPE_INVALID; };
	return PIDBTree::PIDBTypeNameToNumber( pType );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDB_pidbflagsNameToNumber( const char *pFlags )
{
	if ( !pFlags )
		{ return PIDBFLAG_NONE; };
	return PIDBTree::PIDBFlagsNameToNumber( pFlags );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI void *PIDB_lookup( PIDB *pTree, int iType, const char *pKey,
	int iFlags )
{
	if ( !pTree ) { return 0; };
	return pTree->Lookup( iType, pKey, iFlags );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIDBIterator *PIDB_getIterator( PIDB *pTree, int iType,
	const char *pKey, int iFlags )
{
	if ( !pTree ) { return 0; };
	return pTree->GetIterator( iType, pKey, iFlags );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDB_delete( PIDB *pTree )
{
	if ( !pTree )
		{ return PIAPI_EINVAL; };
	return pTree->Delete();
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIDB *PIDB_getRoot( PIDB *pDB )
{
	if ( !pDB )
		{ return 0; };
	return pDB->GetRoot();
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDBIterator_atValidElement( PIDBIterator *pIter )
{
	if ( !pIter )
		{ return PIAPI_FALSE; };
	return pIter->AtValidElement() ? PIAPI_TRUE : PIAPI_FALSE;
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI void *PIDBIterator_current( PIDBIterator *pIter,
	const char **ppKey )
{
	if ( !pIter )
		{ return 0; };
	return pIter->Current( ppKey );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDBIterator_next( PIDBIterator *pIter )
{
	if ( !pIter )
		{ return PIAPI_EINVAL; };
	pIter->Next();
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDBIterator_removeCurrent( PIDBIterator *pIter )
{
	if ( !pIter )
		{ return PIAPI_EINVAL; };
	pIter->RemoveCurrent();
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIDBIterator_delete( PIDBIterator *pIter )
{
	if ( !pIter )
		{ return PIAPI_EINVAL; };
	PI_DELETE( pIter );
	return PIAPI_COMPLETED;
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI void *PIUserType_getValue( UserDBType *pUserType )
{
	if ( !pUserType )	
		{ return 0; };
	return pUserType->GetValue();
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIConfig_loadConfigurationFile( PIDB *pDB,
	const char *pFileName, PIConfigDB **ppConfigDB )
{
	return PIConfigDB::LoadConfigurationFile( pDB, pFileName, ppConfigDB );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIConfigDB *PIConfig_findConfiguration( PIDB *pDB )
{
	if ( !pDB )
		{ return 0; };
	return PIConfigDB::FindConfiguration( pDB );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI const char *PIConfig_lookupValue( PIConfigDB *pConfigDB,
	const char *pKey, char *pInfoBuffer, int iLen )
{
	if ( !pConfigDB || !pKey )
		{ return 0; };
	return PIConfigDB::LookupValue( pConfigDB, pKey, pInfoBuffer, iLen );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI PIConfigDB *PIConfig_lookupTree( PIConfigDB *pConfigDB,
	const char *pKey, char *pInfoBuffer, int iLen )
{
	if ( !pConfigDB || !pKey )
		{ return 0; };
	return PIConfigDB::LookupTree( pConfigDB, pKey, pInfoBuffer, iLen );
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI const char *PIConfigString_getString( PIConfigDBString *pString )
{
	if ( !pString )
		{ return 0; };
	return pString->GetString();
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PILog_addMessage( _PIDB *pDB, PIConfigDB *pConfigDB,
	int iType, const char *pFormat, ... )
{
	if ( !pDB || !pFormat )
		{ return PIAPI_EINVAL; };

	va_list tvList;
	va_start( tvList, pFormat );
	int iRet = _PIDBUtil::AddLogMessage( pDB, pConfigDB, iType, pFormat,
			tvList );
	va_end( tvList );

	return iRet;
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PILog_writeDiagnostics( _PIDB *pDB, int iFlags, 
	const char *pDumpFile )
{
	if ( !pDB )
		{ return PIAPI_EINVAL; };

	if ( pDumpFile )
		{
		ofstream ofs( pDumpFile, ios::app );
		if ( !ofs.good() )
			{ return PIAPI_ERROR; };
		return _PIDBUtil::WriteDiagnostics( pDB, iFlags, ofs );
		}
	else
		{
		return _PIDBUtil::WriteDiagnostics( pDB, iFlags, cout );
		};
}

/*____________________________________________________________________________*\
 *
 Description:
	See API header files in ../piapi for full description
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PILog_newSink( int iType, const char *pParam )
{

	switch( iType )
		{
		case PILOG_FILE:	
			return PIAPI_NOTSUPPORTED;

		case PILOG_DB:
		case PILOG_STDERR:
		case PILOG_STDOUT:
			break;

		default:
			return PIAPI_EINVAL;
		};

	if ( iType==PILOG_FILE && pParam==0 )
		{ return PIAPI_EINVAL; };

	return _PIDBUtil::NewSink( iType, pParam );
}

⌨️ 快捷键说明

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