Browse Source

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/scm-ssi-student-hostage.git

Mihai Plasoianu 10 years ago
parent
commit
e4d16b6f32

+ 4 - 1
src/de/tudarmstadt/informatik/hostage/protocol/HTTP.java

@@ -157,7 +157,10 @@ public class HTTP implements Protocol {
 		List<Packet> responsePackets = new ArrayList<Packet>();
 		this.request = request;
 
-		if (!request.contains(httpVersion)) {
+		if (request.startsWith("G")) {
+			//weird if clause but required for https
+			responsePackets.add(buildPacket(STATUS_CODE_200, GET));
+		} else if (!request.contains(httpVersion)) {
 			responsePackets.add(buildPacket(STATUS_CODE_505, ""));
 		} else if (request.contains(GET)) {
 			responsePackets.add(buildPacket(STATUS_CODE_200, GET));

+ 4 - 1
src/de/tudarmstadt/informatik/hostage/protocol/SIP.java

@@ -7,7 +7,7 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
 
 /**
  * SIP protocol. Implementation of RFC document 3261 It can handle the
- * following requests: INVITE, ACK, BYE. For all other requests
+ * following requests: REGISTER, INVITE, ACK, BYE. For all other requests
  * '400 Bad Request' will be replied.
  * @author Wulf Pfeiffer
  */
@@ -20,6 +20,7 @@ public class SIP implements Protocol {
 	private STATE state = STATE.NONE;
 		
 	private static final String VERSION = "SIP/2.0";
+	private static final String REGISTER = "REGISTER";
 	private static final String INVITE = "INVITE";
 	private static final String ACK= "ACK";
 	private static final String BYE = "BYE";
@@ -58,6 +59,8 @@ public class SIP implements Protocol {
 		if(!lines[0].contains(VERSION)) {
 			responsePackets.add(getVersionNotSupportedResponse());
 			return responsePackets;
+		} else if(lines[0].contains(REGISTER)) {
+			responsePackets.add(getOkResponse());
 		} else if(lines[0].contains(INVITE)) {
 			responsePackets.add(getOkResponseWithSDP());
 		} else if(lines[0].contains(BYE)) {

+ 11 - 6
src/de/tudarmstadt/informatik/hostage/wrapper/Packet.java

@@ -1,9 +1,12 @@
 package de.tudarmstadt.informatik.hostage.wrapper;
 
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
+
 /**
  * Wrapper class for the payload of a network packet.
  * 
  * @author Mihai Plasoianu
+ * @author Wulf Pfeiffer
  */
 public class Packet {
 
@@ -40,20 +43,22 @@ public class Packet {
 
 	/**
 	 * Returns a String representation of the payload.
+	 * If the payload contains a ASCII character the whole
+	 * String will be represented as a String of a byte values.
+	 * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
+	 * the String "01, 4A, 03".
+	 * Otherwise a normal String will be created with the payload.
 	 * 
 	 * @return String representation.
 	 */
 	@Override
 	public String toString() {
-		StringBuilder builder = new StringBuilder(payload.length);
 		for (int i = 0; i < payload.length; ++i) {
-			if (payload[i] < 10) {
-				builder.append("{0x").append(payload[i]).append("}");
-			} else {
-				builder.append(Character.toString((char) payload[i]));
+			if (((char) payload[i]) < 9) {
+				return HelperUtils.bytesToHexString(payload);
 			}
 		}
-		return builder.toString();
+		return new String(payload);
 	}
 
 }