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

📄 servlethandler.h

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 H
字号:
/*____________________________________________________________________________*\
 *

 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/Servlet/ServletHandler.h,v $
 * $Date: 2003/05/13 18:42:19 $
 *
 Description:
\*____________________________________________________________________________*/
//$SourceTop:$

#ifndef SERVLETHANDLER_H_
#define SERVLETHANDLER_H_

#include "HandBase.h"
#include "HTTPCore.h"
#include "HTTPUtil.h"
#include "PIStrStr.h"
#include "DeQuote.h"
#include "PiAPI.h"


#include <jni.h>       /* where everything is defined */

#undef SERVLET_REF
#ifdef WIN32
#ifdef _EXPORTING
   #define SERVLET_REF __declspec(dllexport)
#else
   #define SERVLET_REF __declspec(dllimport)
#endif
#else
   #define SERVLET_REF
#endif

/*
** #define D { cerr << __FILE__ << ": " << __LINE__ << endl; }
*/
#define D

class Jsp;

/*____________________________________________________________________________*\
 *
 Description:
\*____________________________________________________________________________*/
class Servlet : public HandlerBaseServlet
{
	friend class Jsp;
private:
	PIDB *pRequestTypes;			/* DB for request variable types */
	PIDB *pResponseTypes;			/* DB for response variable types */
	PIDB *pInitParams;				/* DB for Servlet init parameters */
	PIString sClassName;			/* ClassName of Servlet */
	PIString sServletName;			/* Name of Servlet */
	jobject jServlet;
	jobject jServletConfig;
	PISync *pMutex;
	int initServlet( JNIEnv *env );
	int destroyServlet();
	jobject GetContextServlet( JNIEnv *env, const char *pServletClass );
protected:
	virtual int Parameter( const char *pVariable, const char *pValue,
		const char *pWhere );

	/* ---
	Lookup functions (for GetServerVariable)
	--- */
	typedef const char *(* PMFN)( Servlet *, PIHTTP * );

# define FN_DB_STR( name, db, type, key ) \
	static const char *(name)( Servlet *, PIHTTP *pPIHTTP )			\
	{																\
	return (const char *)PIDB_lookup( pPIHTTP->db, type, key, 0 );	\
	};			

# define FN_STRING( name, value ) \
	static const char *(name)( Servlet *pThis, PIHTTP *pPIHTTP )			\
	{																\
	return value;													\
	};			
	FN_DB_STR( fnServerProtocol, pRequestDB, PIDBTYPE_STRING, KEY_HTTP_PROTOCOL );
	FN_DB_STR( fnRequestMethod, pRequestDB, PIDBTYPE_STRING, KEY_HTTP_METHOD );
	FN_DB_STR( fnQueryString, pRequestDB, PIDBTYPE_STRING, KEY_HTTP_QUERYSTRING );
	FN_DB_STR( fnContentLengthReq, pRequestDB, PIDBTYPE_RFC822, KEY_HTTP_CONTENTLENGTH );
	FN_DB_STR( fnContentTypeReq, pRequestDB, PIDBTYPE_RFC822, KEY_HTTP_CONTENTTYPE );
	FN_DB_STR( fnIfModifiedSince, pRequestDB, PIDBTYPE_RFC822, KEY_HTTP_IFMODIFIEDSINCE );
	FN_DB_STR( fnHttpUri, pRequestDB, PIDBTYPE_STRING, KEY_HTTP_URI );
	FN_DB_STR( fnCookie, pRequestDB, PIDBTYPE_RFC822, KEY_HTTP_COOKIE );

	FN_DB_STR( fnAuthType, pResponseDB, PIDBTYPE_STRING, KEY_INT_AUTHTYPE );
	FN_DB_STR( fnAuthPass, pResponseDB, PIDBTYPE_STRING, KEY_INT_AUTHPASS );
	FN_DB_STR( fnContentLengthRes, pResponseDB, PIDBTYPE_RFC822, KEY_HTTP_CONTENTLENGTH );
	FN_DB_STR( fnContentTypeRes, pResponseDB, PIDBTYPE_RFC822, KEY_HTTP_CONTENTTYPE );
	FN_DB_STR( fnPathInfo, pResponseDB, PIDBTYPE_STRING, KEY_INT_PATHINFO );
	FN_DB_STR( fnPathTranslated, pResponseDB, PIDBTYPE_STRING, KEY_INT_PATHTRANSLATED );
	FN_DB_STR( fnRemoteUser, pResponseDB, PIDBTYPE_STRING, KEY_INT_REMOTEUSER );
	FN_DB_STR( fnScriptName, pResponseDB, PIDBTYPE_STRING, KEY_INT_SCRIPTNAME );
	FN_DB_STR( fnLastModified, pResponseDB, PIDBTYPE_RFC822, KEY_HTTP_LASTMODIFIED );
	
	FN_DB_STR( fnRemoteAddr, pConnectionDB, PIDBTYPE_STRING, KEY_INT_REMOTEADDR );
	FN_DB_STR( fnRemoteHost, pConnectionDB, PIDBTYPE_STRING, KEY_INT_REMOTEHOST );
	FN_DB_STR( fnHttpsKeysize, pConnectionDB, PIDBTYPE_STRING, KEY_HTTPS_KEYSIZE );
	FN_DB_STR( fnHttpPrivKeysize, pConnectionDB, PIDBTYPE_STRING, KEY_HTTPS_SECRETKEYSIZE );

	FN_STRING( fnServerName, HTTPUtil_getHostName(pPIHTTP) );
	FN_STRING( fnServerPort, HTTPUtil_getHostPort(pPIHTTP) );
	FN_STRING( fnServerSoftware, HTTPCore_getServerStamp() );
	FN_STRING( fnGatewayInterface, "Servlet API/2.1a" );
#undef FN_DB_STR
#undef FN_STRING

public:
	Servlet( PIObject *pObject, int iArgc, const char *ppArgv[], const char *pLogName );
	virtual ~Servlet();
	SERVLET_REF const char *GetPathTranslated( PIHTTP *pPIHTTP, const char *pPath );
	SERVLET_REF const char *GetRequestVariable( PIHTTP *pPIHTTP, const char *pVariableName );
	SERVLET_REF const char *GetResponseVariable( PIHTTP *pPIHTTP, const char *pVariableName );
	SERVLET_REF jobject CreateSession( PIHTTP *pPIHTTP, JNIEnv *env );
	SERVLET_REF jobject GetServlet( PIHTTP *pPIHTTP, JNIEnv *env, const char *pPath );
	SERVLET_REF int DoForward( PIHTTP *pPIHTTP, JNIEnv *env, const char *pPath,
		jobject request, jobject response );
	int Handle( int iPhase, PIHTTP &tPIHTTP, PIIOBuffer &/* tBuffer */ );
};

#endif

⌨️ 快捷键说明

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