Commit b9f1163c authored by huni's avatar huni

Fixed BOSH version handling, added cache-preventing to script syntax.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@10588 b35dd754-fafc-0310-a699-88a17e54d16e
parent e351eee8
......@@ -45,7 +45,7 @@ public enum BoshBindingError {
/**
* (1) 'sid' is not valid, (2) 'stream' is not valid, (3) 'rid' is larger than the upper limit
* of the expected window, (4) connection manager is unable to resend response, (5) 'key'
* sequence is invalid
* sequence is invalid (6) script syntax is not enabled
*/
itemNotFound(Type.terminal, "item-not-found", HttpServletResponse.SC_NOT_FOUND),
/**
......
......@@ -181,7 +181,8 @@ public class HttpBindServlet extends HttpServlet {
throws IOException
{
try {
if (session.getVersion() >= 1.6) {
if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) ||
session.getMajorVersion() > 1) {
respond(response, createErrorBody(bindingError.getErrorType().getType(),
bindingError.getCondition()), request.getMethod());
}
......@@ -306,6 +307,10 @@ public class HttpBindServlet extends HttpServlet {
response.setCharacterEncoding("utf-8");
if ("GET".equals(method)) {
// Prevent caching of responses
response.addHeader("Cache-Control", "no-store");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Pragma", "no-cache");
content = "_BOSH_(\"" + StringEscapeUtils.escapeJavaScript(content) + "\")";
}
......
......@@ -90,7 +90,8 @@ public class HttpSession extends LocalClientSession {
private long lastRequestID;
private int maxRequests;
private PacketDeliverer backupDeliverer;
private Double version = Double.NaN;
private int majorVersion = -1;
private int minorVersion = -1;
private X509Certificate[] sslCertificates;
private final Queue<Collection<Element>> packetsToSend = new LinkedList<Collection<Element>>();
......@@ -362,38 +363,67 @@ public class HttpSession extends LocalClientSession {
}
/**
* Sets the version of BOSH which the client implements. Currently, the only versions supported
* by Openfire are 1.5 and 1.6. Any versions less than or equal to 1.5 will be interpreted as
* 1.5 and any values greater than or equal to 1.6 will be interpreted as 1.6.
* Sets the major version of BOSH which the client implements. Currently, the only versions supported
* by Openfire are 1.5 and 1.6.
*
* @param version the version of BOSH which the client implements, represented as a Double,
* {major version}.{minor version}.
* @param version the major version of BOSH which the client implements.
*/
public void setVersion(double version) {
if(version <= 1.5) {
public void setMajorVersion(int majorVersion) {
if(majorVersion != 1) {
return;
}
else if(version >= 1.6) {
version = 1.6;
this.majorVersion = majorVersion;
}
/**
* Returns the major version of BOSH which this session utilizes. The version refers to the
* version of the XEP which the connecting client implements. If the client did not specify
* a version 1 is returned as 1.5 is the last version of the <a
* href="http://www.xmpp.org/extensions/xep-0124.html">XEP</a> that the client was not
* required to pass along its version information when creating a session.
*
* @return the major version of the BOSH XEP which the client is utilizing.
*/
public int getMajorVersion() {
if (this.majorVersion != -1) {
return this.majorVersion;
}
else {
return 1;
}
}
/**
* Sets the minor version of BOSH which the client implements. Currently, the only versions supported
* by Openfire are 1.5 and 1.6. Any versions less than or equal to 5 will be interpreted as
* 5 and any values greater than or equal to 6 will be interpreted as 6.
*
* @param version the minor version of BOSH which the client implements.
*/
public void setMinorVersion(int minorVersion) {
if(minorVersion <= 5) {
this.minorVersion = 5;
}
else if(minorVersion >= 6) {
this.minorVersion = 6;
}
this.version = version;
}
/**
* Returns the BOSH version which this session utilizes. The version refers to the
* Returns the major version of BOSH which this session utilizes. The version refers to the
* version of the XEP which the connecting client implements. If the client did not specify
* a version 1.5 is returned as this is the last version of the <a
* a version 5 is returned as 1.5 is the last version of the <a
* href="http://www.xmpp.org/extensions/xep-0124.html">XEP</a> that the client was not
* required to pass along its version information when creating a session.
*
* @return the version of the BOSH XEP which the client is utilizing.
* @return the minor version of the BOSH XEP which the client is utilizing.
*/
public double getVersion() {
if (!Double.isNaN(this.version)) {
return this.version;
public int getMinorVersion() {
if (this.minorVersion != -1) {
return this.minorVersion;
}
else {
return 1.5;
return 5;
}
}
......
......@@ -119,7 +119,11 @@ public class HttpSessionManager {
int wait = getIntAttribute(rootNode.attributeValue("wait"), 60);
int hold = getIntAttribute(rootNode.attributeValue("hold"), 1);
double version = getDoubleAttribute(rootNode.attributeValue("ver"), 1.5);
String version = rootNode.attributeValue("ver");
if (version == null || "".equals(version)) {
version = "1.5";
}
HttpSession session = createSession(connection.getRequestId(), address, connection);
session.setWait(Math.min(wait, getMaxWait()));
......@@ -130,7 +134,11 @@ public class HttpSessionManager {
session.setInactivityTimeout(getInactivityTimeout());
// Store language and version information in the connection.
session.setLanaguage(language);
session.setVersion(version);
String [] versionString = version.split("\\.");
session.setMajorVersion(Integer.parseInt(versionString[0]));
session.setMinorVersion(Integer.parseInt(versionString[1]));
try {
connection.deliverBody(createSessionCreationResponse(session));
}
......@@ -278,9 +286,11 @@ public class HttpSessionManager {
response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout()));
response.addAttribute("polling", String.valueOf(session.getMaxPollingInterval()));
response.addAttribute("wait", String.valueOf(session.getWait()));
if(session.getVersion() >= 1.6) {
if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) ||
session.getMajorVersion() > 1) {
response.addAttribute("hold", String.valueOf(session.getHold()));
response.addAttribute("ver", String.valueOf(session.getVersion()));
response.addAttribute("ver", String.valueOf(session.getMajorVersion())
+ "." + String.valueOf(session.getMinorVersion()));
}
Element features = response.addElement("stream:features");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment