📄 pi3httpservletrequest.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/Servlet/Pi3HttpServletRequest.cpp,v $
* $Date: 2003/05/13 18:42:19 $
*
Description:
Execute an servlet extension.
\*____________________________________________________________________________*/
//$SourceTop:$
#include <ctype.h>
#include <jni.h> /* where everything is defined */
#include "org_pi3_servlet_core_Pi3HttpServletRequest.h" /* automatically created JNI header */
#include "PiAPI.h"
#include "Pi2API.h"
#include "Pi3API.h"
#include "ServletHandler.h"
#include "StrToken.h"
/*
* Class: org_pi3_servlet_core_Pi3HttpServletRequest
* Method: createSession
* Signature: ()Ljavax/servlet/http/HttpSession;
*/
JNIEXPORT jobject JNICALL Java_org_pi3_servlet_core_Pi3HttpServletRequest_createSession
(JNIEnv *env, jobject request) {
jclass cls = env->GetObjectClass(request);
jmethodID getServletHandler;
getServletHandler = env->GetMethodID( cls, "getServletHandler", "()I");
// Errorhandling!
if (!getServletHandler) { return NULL; };
env->ExceptionClear();
int SHandler = env->CallIntMethod(request, getServletHandler);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return NULL;
};
jmethodID getPiHttp;
getPiHttp = env->GetMethodID( cls, "getPiHttp", "()I");
// Errorhandling!
if (!getPiHttp) { return NULL; };
env->ExceptionClear();
int PiHttp = env->CallIntMethod(request, getPiHttp);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return NULL;
};
Servlet *sh = (Servlet *)SHandler;
return sh->CreateSession( (PIHTTP *)PiHttp, env );
};
/*
* Class: org_pi3_servlet_core_Pi3HttpServletRequest
* Method: getCookies
* Signature: ()[Ljavax/servlet/http/Cookie;
*/
JNIEXPORT jobjectArray JNICALL Java_org_pi3_servlet_core_Pi3HttpServletRequest_getCookies
(JNIEnv *env, jobject request) {
jclass cls = env->GetObjectClass(request);
jmethodID getServletHandler;
getServletHandler = env->GetMethodID( cls, "getServletHandler", "()I");
// Errorhandling!
if (!getServletHandler) { return NULL; };
env->ExceptionClear();
int SHandler = env->CallIntMethod(request, getServletHandler);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return NULL;
};
jmethodID getPiHttp;
getPiHttp = env->GetMethodID( cls, "getPiHttp", "()I");
// Errorhandling!
if (!getPiHttp) { return NULL; };
env->ExceptionClear();
int PiHttp = env->CallIntMethod(request, getPiHttp);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return NULL;
};
Servlet *sh = (Servlet *)SHandler;
const char *szCookie = sh->GetRequestVariable( (PIHTTP *)PiHttp, KEY_HTTP_COOKIE );
if (!szCookie) { return NULL; };
const char *tToken;
StringTokenizer tTokens = StringTokenizer(szCookie, ";");
jclass cookiecls = env->FindClass("javax/servlet/http/Cookie");
if (!cookiecls) { return NULL; };
jmethodID cookieMID = env->GetMethodID( cookiecls, "<init>",
"(Ljava/lang/String;Ljava/lang/String;)V");
if (!cookieMID) { return NULL; };
jobjectArray cookies = env->NewObjectArray(tTokens.NumTokens(), cookiecls, NULL);
for (int i = 0; i < tTokens.NumTokens(); i++ ) {
tToken = tTokens.GetToken(i);
/* --- skip leading whitespace --- */
for( ; *tToken && (isspace(*tToken)); *tToken++ );
PIString sValue = PIString(DeQuote(strrchr(tToken, '=') + 1));
PIString sName = PIString(tToken, strrchr(tToken, '=') - tToken);
jstring jName = env->NewStringUTF(sName);
jstring jValue = env->NewStringUTF(sValue);
jobject cookie = env->NewObject( cookiecls, cookieMID, jName, jValue);
env->SetObjectArrayElement(cookies, i, cookie);
};
return cookies;
};
/*
* Class: org_pi3_servlet_core_Pi3HttpServletRequest
* Method: getRealPath
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_pi3_servlet_core_Pi3HttpServletRequest_getRealPath
(JNIEnv *env, jobject request, jstring path) {
jclass cls = env->GetObjectClass(request);
jmethodID getServletHandler;
getServletHandler = env->GetMethodID( cls, "getServletHandler", "()I");
// Errorhandling!
if (!getServletHandler) { return env->NewStringUTF(""); };
env->ExceptionClear();
int SHandler = env->CallIntMethod(request, getServletHandler);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return env->NewStringUTF("");
};
jmethodID getPiHttp;
getPiHttp = env->GetMethodID( cls, "getPiHttp", "()I");
// Errorhandling!
if (!getPiHttp) { return env->NewStringUTF(""); };
env->ExceptionClear();
int PiHttp = env->CallIntMethod(request, getPiHttp);
if ( env->ExceptionOccurred() )
{
env->ExceptionDescribe();
env->ExceptionClear();
// Errorhandling!
return env->NewStringUTF("");
};
jboolean isCopy;
const char *pPath = env->GetStringUTFChars(path, &isCopy);
Servlet *sh = (Servlet *)SHandler;
const char *pPathTranslated = sh->GetPathTranslated( (PIHTTP *)PiHttp, pPath );
env->ReleaseStringUTFChars(path, pPath);
return pPathTranslated ? env->NewStringUTF( pPathTranslated ) : env->NewStringUTF("");
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -