📄 ajp13parser.java
字号:
// key. case Ajp13RequestHeaders.SECRET_ATTR: // XXX Investigate safest way to // deal with // this... // should this tie into shutdown // packet? break; case Ajp13RequestHeaders.STORED_METHOD_ATTR: // XXX Confirm this should // really overide // previously parsed method? // _handler.parsedMethod(Ajp13PacketMethods.CACHE.get(Ajp13RequestPacket.getString())); break; case Ajp13RequestHeaders.CONTEXT_ATTR: _handler.parsedContextPath(Ajp13RequestPacket.getString(_buffer, _tok1)); break; case Ajp13RequestHeaders.SERVLET_PATH_ATTR: _handler.parsedServletPath(Ajp13RequestPacket.getString(_buffer, _tok1)); break; default: Log.warn("Unsupported Ajp13 Request Attribute {}", new Integer(attr_type)); break; } attr_type = Ajp13RequestPacket.getByte(_buffer) & 0xff; } _contentPosition = 0; switch ((int) _contentLength) { case HttpTokens.NO_CONTENT: _state = STATE_END; _handler.headerComplete(); _handler.messageComplete(_contentPosition); break; case HttpTokens.UNKNOWN_CONTENT: _generator.getBodyChunk(); if (_buffers != null && _body == null && _buffer == _header && _header.length() <= 0) { _body = _buffers.getBuffer(Ajp13Packet.MAX_PACKET_SIZE); _body.clear(); } _state = STATE_AJP13CHUNK_START; _handler.headerComplete(); // May recurse here! return total_filled; default: if (_buffers != null && _body == null && _buffer == _header && _contentLength > (_header.capacity() - _header.getIndex())) { _body = _buffers.getBuffer(Ajp13Packet.MAX_PACKET_SIZE); _body.clear(); } _state = STATE_AJP13CHUNK_START; _handler.headerComplete(); // May recurse here! return total_filled; } } Buffer chunk; while (_state>STATE_END) { switch (_state) { case STATE_AJP13CHUNK_START: if (_buffer.length()<6) { if (total_filled<0) total_filled=0; total_filled+=fill(); if (_buffer.length()<6) return total_filled; } int _magic=Ajp13RequestPacket.getInt(_buffer); if (_magic!=Ajp13RequestHeaders.MAGIC) { throw new IOException("Bad AJP13 rcv packet: "+"0x"+Integer.toHexString(_magic)+" expected "+"0x" +Integer.toHexString(Ajp13RequestHeaders.MAGIC)+" "+this); } _chunkPosition=0; _chunkLength=Ajp13RequestPacket.getInt(_buffer)-2; Ajp13RequestPacket.getInt(_buffer); if (_chunkLength==0) { _state=STATE_END; _generator.gotBody(); _handler.messageComplete(_contentPosition); return total_filled; } _state=STATE_AJP13CHUNK; case STATE_AJP13CHUNK: if (_buffer.length()<_chunkLength) { if (total_filled<0) total_filled=0; total_filled+=fill(); if (_buffer.length()<_chunkLength) return total_filled; } int remaining=_chunkLength-_chunkPosition; if (remaining==0) { _state=STATE_AJP13CHUNK_START; if (_contentPosition<_contentLength) { _generator.getBodyChunk(); } else { _generator.gotBody(); } return total_filled; } if (_buffer.length()<remaining) { remaining=_buffer.length(); } chunk=Ajp13RequestPacket.get(_buffer,(int)remaining); _contentPosition+=chunk.length(); _chunkPosition+=chunk.length(); _contentView.update(chunk); remaining=_chunkLength-_chunkPosition; if (remaining==0) { _state=STATE_AJP13CHUNK_START; if (_contentPosition<_contentLength || _contentLength == HttpTokens.UNKNOWN_CONTENT) { _generator.getBodyChunk(); } else { _generator.gotBody(); } } _handler.content(chunk); return total_filled; default: throw new IllegalStateException("Invalid Content State"); } } return total_filled; } /* ------------------------------------------------------------------------------- */ public void reset(boolean returnBuffers) { _state = STATE_START; _contentLength = HttpTokens.UNKNOWN_CONTENT; _contentPosition = 0; _length = 0; _packetLength = 0; if (_body != null) { if (_body.hasContent()) { _header.setMarkIndex(-1); _header.compact(); // TODO if pipelined requests received after big // input - maybe this is not good?. _body.skip(_header.put(_body)); } if (_body.length() == 0) { if (_buffers != null && returnBuffers) _buffers.returnBuffer(_body); _body = null; } else { _body.setMarkIndex(-1); _body.compact(); } } if (_header != null) { _header.setMarkIndex(-1); if (!_header.hasContent() && _buffers != null && returnBuffers) { _buffers.returnBuffer(_header); _header = null; _buffer = null; } else { _header.compact(); _tok0.update(_header); _tok0.update(0, 0); _tok1.update(_header); _tok1.update(0, 0); } } _buffer = _header; } /* ------------------------------------------------------------------------------- */ Buffer getHeaderBuffer() { return _buffer; } private void shutdownRequest() { _state = STATE_END; if(!Ajp13SocketConnector.__allowShutdown) { Log.warn("AJP13: Shutdown Request is Denied, allowShutdown is set to false!!!"); return; } if(Ajp13SocketConnector.__secretWord != null) { Log.warn("AJP13: Validating Secret Word"); try { String secretWord = Ajp13RequestPacket.getString(_buffer, _tok1).toString(); if(!Ajp13SocketConnector.__secretWord.equals(secretWord)) { Log.warn("AJP13: Shutdown Request Denied, Invalid Sercret word!!!"); throw new IllegalStateException("AJP13: Secret Word is Invalid: Peer has requested shutdown but, Secret Word did not match"); } } catch (Exception e) { Log.warn("AJP13: Secret Word is Required!!!"); Log.debug(e); throw new IllegalStateException("AJP13: Secret Word is Required: Peer has requested shutdown but, has not provided a Secret Word"); } Log.warn("AJP13: Shutdown Request is Denied, allowShutdown is set to false!!!"); return; } Log.warn("AJP13: Peer Has Requested for Shutdown!!!"); Log.warn("AJP13: Jetty 6 is shutting down !!!"); System.exit(0); } /* ------------------------------------------------------------------------------- */ public interface EventHandler { // public void shutdownRequest() throws IOException; // public void cpingRequest() throws IOException; public void content(Buffer ref) throws IOException; public void headerComplete() throws IOException; public void messageComplete(long contextLength) throws IOException; public void parsedHeader(Buffer name, Buffer value) throws IOException; public void parsedMethod(Buffer method) throws IOException; public void parsedProtocol(Buffer protocol) throws IOException; public void parsedQueryString(Buffer value) throws IOException; public void parsedRemoteAddr(Buffer addr) throws IOException; public void parsedRemoteHost(Buffer host) throws IOException; public void parsedRequestAttribute(String key, Buffer value) throws IOException; public void parsedRequestAttribute(String key, int value) throws IOException; public void parsedServerName(Buffer name) throws IOException; public void parsedServerPort(int port) throws IOException; public void parsedSslSecure(boolean secure) throws IOException; public void parsedUri(Buffer uri) throws IOException; public void startForwardRequest() throws IOException; public void parsedAuthorizationType(Buffer authType) throws IOException; public void parsedRemoteUser(Buffer remoteUser) throws IOException; public void parsedServletPath(Buffer servletPath) throws IOException; public void parsedContextPath(Buffer context) throws IOException; public void parsedSslCert(Buffer sslCert) throws IOException; public void parsedSslCipher(Buffer sslCipher) throws IOException; public void parsedSslSession(Buffer sslSession) throws IOException; public void parsedSslKeySize(int keySize) throws IOException; } /* ------------------------------------------------------------ */ /** * TODO Make this common with HttpParser * */ public static class Input extends ServletInputStream { private Ajp13Parser _parser; private EndPoint _endp; private long _maxIdleTime; private View _content; /* ------------------------------------------------------------ */ public Input(Ajp13Parser parser, long maxIdleTime) { _parser = parser; _endp = parser._endp; _maxIdleTime = maxIdleTime; _content = _parser._contentView; } /* ------------------------------------------------------------ */ public int read() throws IOException { int c = -1; if (blockForContent()) c = 0xff & _content.get(); return c; } /* ------------------------------------------------------------ */ /* * @see java.io.InputStream#read(byte[], int, int) */ public int read(byte[] b, int off, int len) throws IOException { int l = -1; if (blockForContent()) l = _content.get(b, off, len); return l; } /* ------------------------------------------------------------ */ private boolean blockForContent() throws IOException { if (_content.length() > 0) return true; if (_parser.isState(Ajp13Parser.STATE_END)) return false; // Handle simple end points. if (_endp == null) _parser.parseNext(); // Handle blocking end points else if (_endp.isBlocking()) { _parser.parseNext(); // parse until some progress is made (or IOException thrown for timeout) while (_content.length() == 0 && !_parser.isState(Ajp13Parser.STATE_END)) { // Try to get more _parser._content _parser.parseNext(); } } else // Handle non-blocking end point { long filled = _parser.parseNext(); boolean blocked = false; // parse until some progress is made (or // IOException thrown for timeout) while (_content.length() == 0 && !_parser.isState(Ajp13Parser.STATE_END)) { // if fill called, but no bytes read, // then block if (filled > 0) blocked = false; else if (filled == 0) { if (blocked) throw new InterruptedIOException("timeout"); blocked = true; _endp.blockReadable(_maxIdleTime); } // Try to get more _parser._content filled = _parser.parseNext(); } } return _content.length() > 0; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -