|
@@ -5,16 +5,21 @@ import java.util.List;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
|
+/**
|
|
|
+ * SIP protocol. Implementation of RFC document 3261 It can handle the
|
|
|
+ * following requests: INVITE, BYE. For all other requests
|
|
|
+ * '400 Bad Request' will be replied.
|
|
|
+ * @author Wulf Pfeiffer
|
|
|
+ */
|
|
|
public class SIP implements Protocol {
|
|
|
-
|
|
|
- private String request;
|
|
|
-
|
|
|
+
|
|
|
private static final String VERSION = "SIP/2.0";
|
|
|
private static final String INVITE = "INVITE";
|
|
|
private static final String ACK= "ACK";
|
|
|
private static final String BYE = "BYE";
|
|
|
private static final String STATUS_CODE_180 = "180 Ringing";
|
|
|
private static final String STATUS_CODE_200 = "200 OK";
|
|
|
+ private static final String STATUS_CODE_400 = "400 Bad Request";
|
|
|
private static final String STATUS_CODE_505 = "505 Version Not Supported";
|
|
|
|
|
|
private String header;
|
|
@@ -44,8 +49,6 @@ public class SIP implements Protocol {
|
|
|
request = requestPacket.toString();
|
|
|
}
|
|
|
List<Packet> responsePackets = new ArrayList<Packet>();
|
|
|
- this.request = request;
|
|
|
- System.out.println(request);
|
|
|
String[] lines = request.split("\r\n");
|
|
|
extractLines(lines);
|
|
|
|
|
@@ -57,6 +60,10 @@ public class SIP implements Protocol {
|
|
|
responsePackets.add(getOkResponseWithSDP());
|
|
|
} else if(lines[0].contains(BYE)) {
|
|
|
responsePackets.add(getOkResponse());
|
|
|
+ } else if(lines[0].contains(ACK)) {
|
|
|
+ //nothing here
|
|
|
+ } else {
|
|
|
+ responsePackets.add(getBadRequestResponse());
|
|
|
}
|
|
|
|
|
|
return responsePackets;
|
|
@@ -84,6 +91,10 @@ public class SIP implements Protocol {
|
|
|
recordHeader = false;
|
|
|
} else if(line.startsWith("v=")) {
|
|
|
recordSdp = true;
|
|
|
+ } else if(line.startsWith("a=")) {
|
|
|
+ sbSdp.append(line + "\r\n");
|
|
|
+ header = sbHeader.toString();
|
|
|
+ sdpPayload = sbSdp.toString();
|
|
|
}
|
|
|
if(recordHeader) {
|
|
|
sbHeader.append(line + "\r\n");
|
|
@@ -91,8 +102,6 @@ public class SIP implements Protocol {
|
|
|
sbSdp.append(line + "\r\n");
|
|
|
}
|
|
|
}
|
|
|
- header = sbHeader.toString();
|
|
|
- sdpPayload = sbSdp.toString();
|
|
|
}
|
|
|
|
|
|
private Packet getRingResponse() {
|
|
@@ -100,6 +109,7 @@ public class SIP implements Protocol {
|
|
|
sb.append(VERSION + " " + STATUS_CODE_180 + "\r\n");
|
|
|
sb.append(header);
|
|
|
sb.append("Content-Length: 0\r\n");
|
|
|
+
|
|
|
return new Packet(sb.toString());
|
|
|
}
|
|
|
|
|
@@ -111,7 +121,7 @@ public class SIP implements Protocol {
|
|
|
sb.append("Content-Length: " + sdpPayload.length() + "\r\n");
|
|
|
sb.append("\r\n");
|
|
|
sb.append(sdpPayload);
|
|
|
- System.out.println(sb.toString());
|
|
|
+
|
|
|
return new Packet(sb.toString());
|
|
|
}
|
|
|
|
|
@@ -123,5 +133,14 @@ public class SIP implements Protocol {
|
|
|
|
|
|
return new Packet(sb.toString());
|
|
|
}
|
|
|
+
|
|
|
+ private Packet getBadRequestResponse() {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sb.append(VERSION + " " + STATUS_CODE_400 + "\r\n");
|
|
|
+ sb.append(header);
|
|
|
+ sb.append("Content-Length: 0\r\n");
|
|
|
+
|
|
|
+ return new Packet(sb.toString());
|
|
|
+ }
|
|
|
|
|
|
}
|