|
@@ -7,7 +7,7 @@ import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
|
/**
|
|
/**
|
|
* SIP protocol. Implementation of RFC document 3261 It can handle the
|
|
* SIP protocol. Implementation of RFC document 3261 It can handle the
|
|
- * following requests: INVITE, BYE. For all other requests
|
|
|
|
|
|
+ * following requests: INVITE, ACK, BYE. For all other requests
|
|
* '400 Bad Request' will be replied.
|
|
* '400 Bad Request' will be replied.
|
|
* @author Wulf Pfeiffer
|
|
* @author Wulf Pfeiffer
|
|
*/
|
|
*/
|
|
@@ -23,7 +23,6 @@ public class SIP implements Protocol {
|
|
private static final String INVITE = "INVITE";
|
|
private static final String INVITE = "INVITE";
|
|
private static final String ACK= "ACK";
|
|
private static final String ACK= "ACK";
|
|
private static final String BYE = "BYE";
|
|
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_200 = "200 OK";
|
|
private static final String STATUS_CODE_400 = "400 Bad Request";
|
|
private static final String STATUS_CODE_400 = "400 Bad Request";
|
|
private static final String STATUS_CODE_505 = "505 Version Not Supported";
|
|
private static final String STATUS_CODE_505 = "505 Version Not Supported";
|
|
@@ -57,16 +56,15 @@ public class SIP implements Protocol {
|
|
extractLines(lines);
|
|
extractLines(lines);
|
|
|
|
|
|
if(!lines[0].contains(VERSION)) {
|
|
if(!lines[0].contains(VERSION)) {
|
|
- responsePackets.add(new Packet(STATUS_CODE_505));
|
|
|
|
|
|
+ responsePackets.add(getVersionNotSupportedResponse());
|
|
return responsePackets;
|
|
return responsePackets;
|
|
} else if(lines[0].contains(INVITE)) {
|
|
} else if(lines[0].contains(INVITE)) {
|
|
- responsePackets.add(getRingResponse());
|
|
|
|
responsePackets.add(getOkResponseWithSDP());
|
|
responsePackets.add(getOkResponseWithSDP());
|
|
} else if(lines[0].contains(BYE)) {
|
|
} else if(lines[0].contains(BYE)) {
|
|
responsePackets.add(getOkResponse());
|
|
responsePackets.add(getOkResponse());
|
|
state = STATE.CLOSED;
|
|
state = STATE.CLOSED;
|
|
} else if(lines[0].contains(ACK)) {
|
|
} else if(lines[0].contains(ACK)) {
|
|
- //nothing here
|
|
|
|
|
|
+ //nothing to do here
|
|
} else {
|
|
} else {
|
|
responsePackets.add(getBadRequestResponse());
|
|
responsePackets.add(getBadRequestResponse());
|
|
}
|
|
}
|
|
@@ -85,6 +83,8 @@ public class SIP implements Protocol {
|
|
}
|
|
}
|
|
|
|
|
|
private void extractLines(String[] lines) {
|
|
private void extractLines(String[] lines) {
|
|
|
|
+ header = "";
|
|
|
|
+ sdpPayload = "";
|
|
StringBuffer sbHeader = new StringBuffer();
|
|
StringBuffer sbHeader = new StringBuffer();
|
|
StringBuffer sbSdp = new StringBuffer();
|
|
StringBuffer sbSdp = new StringBuffer();
|
|
boolean recordHeader = false;
|
|
boolean recordHeader = false;
|
|
@@ -92,14 +92,15 @@ public class SIP implements Protocol {
|
|
for (String line : lines) {
|
|
for (String line : lines) {
|
|
if (line.startsWith("Via:")) {
|
|
if (line.startsWith("Via:")) {
|
|
recordHeader = true;
|
|
recordHeader = true;
|
|
- } else if (line.startsWith("Max-Forwards:")) {
|
|
|
|
|
|
+ } else if (line.startsWith("Max-Forwards")) {
|
|
recordHeader = false;
|
|
recordHeader = false;
|
|
|
|
+ header = sbHeader.toString();
|
|
} else if(line.startsWith("v=")) {
|
|
} else if(line.startsWith("v=")) {
|
|
recordSdp = true;
|
|
recordSdp = true;
|
|
} else if(line.startsWith("a=")) {
|
|
} else if(line.startsWith("a=")) {
|
|
sbSdp.append(line + "\r\n");
|
|
sbSdp.append(line + "\r\n");
|
|
- header = sbHeader.toString();
|
|
|
|
sdpPayload = sbSdp.toString();
|
|
sdpPayload = sbSdp.toString();
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
if(recordHeader) {
|
|
if(recordHeader) {
|
|
sbHeader.append(line + "\r\n");
|
|
sbHeader.append(line + "\r\n");
|
|
@@ -109,15 +110,6 @@ public class SIP implements Protocol {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private Packet getRingResponse() {
|
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
|
- sb.append(VERSION + " " + STATUS_CODE_180 + "\r\n");
|
|
|
|
- sb.append(header);
|
|
|
|
- sb.append("Content-Length: 0\r\n");
|
|
|
|
-
|
|
|
|
- return new Packet(sb.toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private Packet getOkResponseWithSDP() {
|
|
private Packet getOkResponseWithSDP() {
|
|
StringBuffer sb = new StringBuffer();
|
|
StringBuffer sb = new StringBuffer();
|
|
sb.append(VERSION + " " + STATUS_CODE_200 + "\r\n");
|
|
sb.append(VERSION + " " + STATUS_CODE_200 + "\r\n");
|
|
@@ -147,5 +139,14 @@ public class SIP implements Protocol {
|
|
|
|
|
|
return new Packet(sb.toString());
|
|
return new Packet(sb.toString());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private Packet getVersionNotSupportedResponse() {
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ sb.append(VERSION + " " + STATUS_CODE_505 + "\r\n");
|
|
|
|
+ sb.append(header);
|
|
|
|
+ sb.append("Content-Length: 0\r\n");
|
|
|
|
+
|
|
|
|
+ return new Packet(sb.toString());
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|