/*
* @(#)FCGIMessage.java
*
*
* FastCGi compatibility package Interface
*
*
* Copyright (c) 1996 Open Market, Inc.
*
* See the file "LICENSE.TERMS" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* $Id: FCGIMessage.java,v 1.4 2000/10/02 15:09:07 robs Exp $
*/
package com.fastcgi;
import java.io.*;
import java.util.Properties;
/* This class handles reading and building the fastcgi messages.
* For reading incoming mesages, we pass the input
* stream as a param to the constructor rather than to each method.
* Methods that build messages use and return internal buffers, so they
* dont need a stream.
*/
public class FCGIMessage
{
private static final String RCSID = "$Id: FCGIMessage.java,v 1.4 2000/10/02 15:09:07 robs Exp $";
/*
* Instance variables
*/
/*
* FCGI Message Records
* The logical structures of the FCGI Message Records.
* Fields are originally 1 unsigned byte in message
* unless otherwise noted.
*/
/*
* FCGI Header
*/
private int h_version;
private int h_type;
private int h_requestID; // 2 bytes
private int h_contentLength; // 2 bytes
private int h_paddingLength;
/*
* FCGI BeginRequest body.
*/
private int br_role; // 2 bytes
private int br_flags;
private FCGIInputStream in;
/*
* constructor - Java would do this implicitly.
*/
public FCGIMessage(){
super();
}
/*
* constructor - get the stream.
*/
public FCGIMessage(FCGIInputStream instream){
in = instream;
}
/*
* Message Reading Methods
*/
/*
* Interpret the FCGI Message Header. Processes FCGI
* BeginRequest and Management messages. Param hdr is the header.
* The calling routine has to keep track of the stream reading
* management or use FCGIInputStream.fill() which does just that.
*/
public int processHeader(byte[] hdr) throws IOException{
processHeaderBytes(hdr);
if (h_version != FCGIGlobalDefs.def_FCGIVersion1) {
return(FCGIGlobalDefs.def_FCGIUnsupportedVersion);
}
in.contentLen = h_contentLength;
in.paddingLen = h_paddingLength;
if (h_type == FCGIGlobalDefs.def_FCGIBeginRequest) {
return processBeginRecord(h_requestID);
}
if (h_requestID == FCGIGlobalDefs.def_FCGINullRequestID) {
return processManagementRecord(h_type);
}
if (h_requestID != in.request.requestID) {
return(FCGIGlobalDefs.def_FCGISkip);
}
if (h_type != in.type) {
return(FCGIGlobalDefs.def_FCGIProtocolError);
}
return(FCGIGlobalDefs.def_FCGIStreamRecord);
}
/* Put the unsigned bytes in the incoming FCGI header into
* integer form for Java, concatinating bytes when needed.
* Because Java has no unsigned byte type, we have to be careful
* about signed numeric promotion to int.
*/
private void processHeaderBytes(byte[] hdrBuf){
h_version = hdrBuf[0] & 0xFF;
h_type = hdrBuf[1] & 0xFF;
h_requestID = ((hdrBuf[2] & 0xFF) << 8) | (hdrBuf[3] & 0xFF);
h_contentLength = ((hdrBuf[4] & 0xFF) << 8) | (hdrBuf[5] & 0xFF);
h_paddingLength = hdrBuf[6] & 0xFF;
}
/*
* Reads FCGI Begin Request Record.
*/
public int processBeginRecord(int requestID) throws IOException {
byte beginReqBody[];
byte endReqMsg[];
if (requestID == 0 || in.contentLen
!= FCGIGlobalDefs.def_FCGIEndReqBodyLen) {
return FCGIGlobalDefs.def_FCGIProtocolError;
}
/*
* If the webserver is multiplexing the connection,
* this library can't deal with it, so repond with
* FCGIEndReq message with protocolStatus FCGICantMpxConn
*/
if (in.request.isBeginProcessed) {
endReqMsg = new byte[FCGIGlobalDefs.def_FCGIHeaderLen
+ FCGIGlobalDefs.def_FCGIEndReqBodyLen];
System.arraycopy(makeHeader(
FCGIGlobalDefs.def_FCGIEndRequest,
requestID,
FCGIGlobalDefs.def_FCGIEndReqBodyLen,
0), 0, endReqMsg, 0,
FCGIGlobalDefs.def_FCGIHeaderLen);
System.arraycopy(makeEndrequestBody(0,
FCGIGlobalDefs.def_FCGICantMpxConn), 0,
endReqMsg,
FCGIGlobalDefs.def_FCGIHeaderLen,
FCGIGlobalDefs.def_FCGIEndReqBodyLen);
/*
* since isBeginProcessed is first set below,this
* can't be out first call, so request.out is properly set
*/
try {
in.request.outStream.write(endReqMsg, 0,
FCGIGlobalDefs.def_FCGIHeaderLen
+ FCGIGlobalDefs.def_FCGIEndReqBodyLen);
} catch (IOException e){
in.request.outStream.setException(e);
return -1;
}
}
/*
* Accept this new request. Read the record body
*/
in.request.requestID = requestID;
beginReqBody =
new byte[FCGIGlobalDefs.def_FCGIBeginReqBodyLen];
if (in.read(beginReqBody, 0,
FCGIGlobalDefs.def_FCGIBeginReqBodyLen) !=
FCGIGlobalDefs.def_FCGIBeginReqBodyLen) {
return FCGIGlobalDefs.def_FCGIProtocolError;
}
br_flags = beginReqBody[2] & 0xFF;
in.request.keepConnection
= (br_flags & FCGIGlobalDefs.def_FCGIKeepConn) != 0;
br_role = ((beginReqBody[0] & 0xFF) << 8) | (beginReqBody[1] & 0xFF);
in.request.role = br_role;
in.request.isBeginProcessed = true;
return FCGIGlobalDefs.def_FCGIBeginRecord;
}
/*
* Reads and Responds to a Management Message. The only type of
* management message this library understands is FCGIGetValues.
* The only variables that this library's FCGIGetValues understands
* are def_FCGIMaxConns, def_FCGIMaxReqs, and def_FCGIMpxsConns.
* Ignore the other management variables, and repsond to other
* management messages with FCGIUnknownType.
*/
public int processManagementRecord(int type) throws IOException {
byte[] response = new byte[64];
int wrndx = response[FCGIGlobalDefs.def_FCGIHeaderLen];
int value, len, plen;
if (type == FCGIGlobalDefs.def_FCGIGetValues) {
Properties tmpProps = new Properties();
readParams(tmpProps);
if (in.getFCGIError() != 0 || in.contentLen != 0) {
return FCGIGlobalDefs.def_FCGIProtocolError;
}
if (tmpProps.containsKey(
FCGIGlobalDefs.def_FCGIMaxConns)) {
makeNameVal(
FCGIGlobalDefs.def_FCGIMaxConns, "1",
response, wrndx);
}
else {
if (tmpProps.containsKey(
FCGIGlobalDefs.def_FCGIMaxReqs)) {
makeNameVal(
FCGIGlobalDefs.def_FCGIMaxReqs, "1",
response, wrndx);
}
else {
if (tmpProps.containsKey(
FCGIGlobalDefs.def_FCGIMaxConns)) {
makeNameVal(
FCGIGlobalDefs.def_FCGIMpxsConns, "0",
response, wrndx);
}
}
}
plen = 64 - wrndx;
len = wrndx - FCGIGlobalDefs.def_FCGIHeaderLen;
System.arraycopy(makeHeader(
FCGIGlobalDefs.def_FCGIGetValuesResult,
FCGIGlobalDefs.def_FCGINullRequestID,
len, plen), 0,
response, 0,
FCGIGlobalDefs.def_FCGIHeaderLen);
}
else {
ple
u011303910
- 粉丝: 0
- 资源: 8
最新资源
- 基于mmse的不确定电力系统有限次测量的分析估计 源代码, matlab代码按照高水平文章复现,保证正确 大量可再生分布式能源的预期渗透正推动下一代电力系统走向不确定性,这可能对状态估计的可靠性和复杂
- 西南科技大学数据分析期末大作业.zip
- 西门子PLC1200立体库机器人码垛机伺服视觉AGV程序 包括2台西门子PLC1215程序和2台西门子触摸屏TP700程序 PLC和基恩士相机视觉定位Modbus TCP通讯(SCL语言) PLC和A
- 知名扫地机代码方案 某知名大厂扫地机代码 适合需要学习项目与代码规范的工程师 硬件驱动包含 陀螺仪姿态传感器bmi160、电源管理bq24733等 软件驱动包括 IIC、PWM、SPI、多路A
- siddhi-execution-json jar包用于在处理事件中对json字符串进行处理
- 直流充电桩,双枪控制板方案,需要的砸单
- 埃斯顿量产控制器 埃斯顿量产伺服控制器C代码和硬件图纸 1)TMS320F28335+FPGA全套代码;全C写的DSP代码,VHDL写的FPGA代码(Lattice MXO1200) 2)AD电
- 信捷XC PLC与西门子V20变频器通讯程序 原创可直接用于生产的程序,程序带注释,并附送触摸屏程序,有接线方式和设置,通讯地址说明等 程序采用轮询,可靠稳定 器件:信捷XC3的PLC,西门子V20
- 台达DVP ES系列PLC与3台英威腾GD变频器通讯 程序带注释,并附送昆仑通态和威纶通触摸屏程序,有接线方式,设置 器件:台达DVP ES系列的PLC,3台英威腾GD系列变频器,昆仑通态,威纶通触
- 控制系统的数学建模,被控对象的数学模型建立,simulink模型实现 提供四旋翼和带尾翼直升机,共轴式直升机的数学模型、simulink模型,推导 提供资料,文献 刚体飞行动力学模型,运动学模型
- 深度学习中的Fashion-MNIST数据集与卷积神经网络实现及其训练分析
- MPC控制器设计,模型预测控制,线性时变模型预测控制,LTV MPC,提供理论讲解与应用实现 提供MPC算法、LTV MPC 算法在直升机和四旋翼中的应用实例 提供模型预测控制资料 提供matl
- Flink Forward Asia 2024 上海站(脱敏)PPT合集.zip
- Node.js安装与环境配置指南:覆盖Windows、macOS及Linux系统全流程
- 微信小程序开发全流程详解:从准备到发布的全面指南与关键技术解析
- 斑马打印机C#控制程序源代码,适合自己进行二次开发 文档齐全,包括驱动程序和如何设置斑马打印机的说明文档 源代码可以打印条形码标签和二维码标签
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈