2 Commits

8 changed files with 81 additions and 49 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntLaunchConfigurationType"> <launchConfiguration type="org.eclipse.ant.AntLaunchConfigurationType">
<stringAttribute key="org.eclipse.ant.ui.ATTR_BUILD_SCOPE" value="${none}"/> <stringAttribute key="org.eclipse.ant.ui.ATTR_BUILD_SCOPE" value="${none}"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="true"/>
<booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/> <booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${workspace}"/> <stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${workspace}"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
@@ -15,6 +15,8 @@
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/> <listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute> </listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.internal.launching.remote.InternalAntRunner"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Foundation Builder"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Foundation Builder"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:\Foundation Builder\builder\build.xml}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:\Foundation Builder\builder\build.xml}"/>

View File

@@ -113,7 +113,7 @@
<target name="release-compile" depends="make-dirs"> <target name="release-compile" depends="make-dirs">
<mkdir dir="${archives}/release-bin"/> <mkdir dir="${archives}/release-bin"/>
<javac destdir="${archives}/release-bin" executable="c:/java/jdk1.5/bin/javac" encoding="utf-8" nowarn="true" verbose="no" fork="true" classpath="${swt-releases}/win32-win32-x86/swt.jar;${orb-exception-support};${workspace}/Foundation TCV SWT Client Application/proxies;"> <javac destdir="${archives}/release-bin" executable="c:/java/jdk1.7/bin/javac" encoding="utf-8" nowarn="true" verbose="no" fork="true" classpath="${swt-releases}/win32-win32-x86/swt.jar;${orb-exception-support};${workspace}/Foundation TCV SWT Client Application/proxies;">
<src path="${workspace}/Common/src"/> <src path="${workspace}/Common/src"/>
<src path="${workspace}/Class File Services/src"/> <src path="${workspace}/Class File Services/src"/>
<src path="${workspace}/Orb/src"/> <src path="${workspace}/Orb/src"/>

View File

@@ -4,11 +4,11 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Common"/> <classpathentry combineaccessrules="false" kind="src" path="/Common"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Interfaces"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Builder"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation Builder"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation SWT"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation SWT"/>
<classpathentry combineaccessrules="false" kind="src" path="/SWT"/> <classpathentry combineaccessrules="false" kind="src" path="/SWT"/>
<classpathentry combineaccessrules="false" kind="src" path="/Orb"/> <classpathentry combineaccessrules="false" kind="src" path="/Orb"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Shared"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Shared"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Interfaces"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@@ -95,6 +95,14 @@ protected abstract void passThrough(ByteBuffer buffer);
* Closes the socket context and cleans up. * Closes the socket context and cleans up.
*/ */
protected abstract void close(); protected abstract void close();
/**
* Determines whether the socket context has been closed.
* Should synchronize on getLock() prior to calling this.
* @return Whether the socket context is closed.
*/
protected boolean isClosed() {
return !(key != null && key.channel().isOpen());
}//isClosed()//
/** /**
* Gets the socket context related to this one (when two are tied together such that data from one immediately is sent to the other). * Gets the socket context related to this one (when two are tied together such that data from one immediately is sent to the other).
* @return The related socket context, or null if none exists (data not forwarded to a remote server). * @return The related socket context, or null if none exists (data not forwarded to a remote server).

View File

@@ -238,7 +238,7 @@ public void run() {
}//else if// }//else if//
else { else {
//This shouldn't be called I don't think.// //This shouldn't be called I don't think.//
Debug.log(new RuntimeException("Woops! Somehow we aren't closed and we didn't setup the interestOps for the HTTP socket!")); Debug.log(new RuntimeException("Woops! Somehow we aren't closed and we didn't setup the interestOps for the HTTP socket! {" + context.toString() + "}"));
}//else// }//else//
}//finally// }//finally//
}//run()// }//run()//

View File

@@ -249,4 +249,10 @@ protected synchronized void close() {
protected boolean hasPendingWrite() { protected boolean hasPendingWrite() {
return currentOutboundMessage != null; return currentOutboundMessage != null;
}//hasPendingWrite()// }//hasPendingWrite()//
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return "PassThroughSocketContext: " + (relatedSocketContext != null ? relatedSocketContext.toString() : "null");
}//toString()//
}//PassThroughSocketContext// }//PassThroughSocketContext//

View File

@@ -325,33 +325,39 @@ protected void writeOutgoingMessages() throws IOException {
//Synchronized to avoid multiple threads accessing the currentOutboundMessage chain at one time.// //Synchronized to avoid multiple threads accessing the currentOutboundMessage chain at one time.//
synchronized(getLock()) { synchronized(getLock()) {
if(currentOutboundMessage != outboundMessage) { if(!isClosed()) {
Debug.log(new RuntimeException("Cannot change the currentOutboundMessage while we are sending it!")); if(currentOutboundMessage != outboundMessage) {
}//if// Debug.log(new RuntimeException("Cannot change the currentOutboundMessage while we are sending it! {" + toString() + "}"));
//If we finished the message then load the next message, otherwise flag that we need to stop sending (buffers full - flag a write on the socket's key and wait).//
if(messageSent || (currentOutboundMessage != null && currentOutboundMessage.isClosed())) {
if(getWebServer().debug()) {
Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was fully sent.");
}//if// }//if//
//Close the message if possible.// //If we finished the message then load the next message, otherwise flag that we need to stop sending (buffers full - flag a write on the socket's key and wait).//
try {currentOutboundMessage.close();} catch(Throwable e) {} if(messageSent || (currentOutboundMessage != null && currentOutboundMessage.isClosed())) {
//Load the next available message.// if(getWebServer().debug()) {
currentOutboundMessage = currentOutboundMessage.getNext(); Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was fully sent.");
if(currentOutboundMessage == null) lastOutboundMessage = null; }//if//
keepSending = hasPendingWrite() && key.channel().isOpen();
outboundMessage = currentOutboundMessage;
if(getWebServer().debug()) { //Close the message if possible.//
Debug.log(this.getId() + "|" + System.nanoTime() + "| Channel is open? " + key.channel().isOpen() + "; More message available? " + hasPendingWrite() + "; EncryptedWriteBuffer.remaining? " + encryptedWriteBuffer.remaining() + "."); try {currentOutboundMessage.close();} catch(Throwable e) {}
//Load the next available message.//
currentOutboundMessage = currentOutboundMessage.getNext();
if(currentOutboundMessage == null) lastOutboundMessage = null;
keepSending = hasPendingWrite() && key.channel().isOpen();
outboundMessage = currentOutboundMessage;
if(getWebServer().debug()) {
Debug.log(this.getId() + "|" + System.nanoTime() + "| Channel is open? " + key.channel().isOpen() + "; More message available? " + hasPendingWrite() + "; EncryptedWriteBuffer.remaining? " + encryptedWriteBuffer.remaining() + ".");
}//if//
}//if// }//if//
else {
if(getWebServer().debug()) {
Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was only partially sent, stop sending for now.");
}//if//
keepSending = false;
}//else//
}//if// }//if//
else { else {
if(getWebServer().debug()) { Debug.log(this.getId() + "|" + System.nanoTime() + "|Socket closed.");
Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was only partially sent, stop sending for now.");
}//if//
keepSending = false; keepSending = false;
}//else// }//else//
}//synchronized// }//synchronized//
@@ -1259,31 +1265,35 @@ private boolean processRequestedHost(ByteBuffer fragment) throws IOException {
totalHeaderSize++; totalHeaderSize++;
}//while// }//while//
//If we have the minimum number of bytes and the last bytes are a line end, then check the line for "Host: xxxxxxx\r\n" //If we have a full line...
String line = buffer.toString().substring(0, buffer.length() - 2).trim(); if(buffer.length() > 1 && (buffer.charAt(buffer.length() - 2) == '\r') && (buffer.charAt(buffer.length() - 1) == '\n')) {
if(line.startsWith("Host: ")) { //If we have the minimum number of bytes and the last bytes are a line end, then check the line for "Host: xxxxxxx\r\n"
int colonIndex; String line = buffer.toString().substring(0, buffer.length() - 2).trim();
host = line.substring(6).trim(); if(line.startsWith("Host: ")) {
colonIndex = host.indexOf(':'); int colonIndex;
if(colonIndex > 0) { host = line.substring(6).trim();
host = host.substring(0, colonIndex); colonIndex = host.indexOf(':');
if(colonIndex > 0) {
host = host.substring(0, colonIndex);
}//if//
}//if// }//if//
}//if//
if(host == null) { if(host == null) {
if(buffer.length() == 2) { if(buffer.length() == 2) {
//End of the header reached. No host provided. Kill the connection?// //End of the header reached. No host provided. Kill the connection?//
//Force the connection to the client to be closed.// //Force the connection to the client to be closed.//
close(); close();
//Throw an exception that should not be logged. This happens occationally when an attacker tries to exploit any header reading weaknesses (all major browsers send a host header).// //Throw an exception that should not be logged. This happens occationally when an attacker tries to exploit any header reading weaknesses (all major browsers send a host header).//
throw new IgnoredIOException(null); throw new IgnoredIOException(null);
}//if//
else {
//Clear the line.//
buffer.setLength(0);
}//else//
}//if// }//if//
else {
//Clear the line.//
buffer.setLength(0);
}//else//
}//if// }//if//
}//while// }//while//
@@ -2237,4 +2247,10 @@ private int indexOf(byte[] source, byte[] pattern, int fromOffset) {
return result; return result;
}//indexOf()// }//indexOf()//
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return "SocketContext: Domain: " + domain + "; SSL: " + (sslEngine != null) + "; Websocket: " + isWebsocket;
}//toString()//
}//SocketContext// }//SocketContext//

View File

@@ -9,7 +9,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/SWT"/> <classpathentry combineaccessrules="false" kind="src" path="/SWT"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Monitor Shared"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Monitor Shared"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Interfaces"/> <classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Interfaces"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Shared"/>
<classpathentry combineaccessrules="false" kind="src" path="/Class File Services"/> <classpathentry combineaccessrules="false" kind="src" path="/Class File Services"/>
<classpathentry combineaccessrules="false" kind="src" path="/Foundation Web Server Shared"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>