Methods Summary |
---|
boolean | check()Checks if test passed.
// DEBUG: System.out.println("Header: " + name + ":" + value);
SipHeader h;
try {
h = new SipHeader(name, value);
} catch (IllegalArgumentException e) {
System.out.println("Error parsing the header:" + e
+ " name=" + name
+ " value=" + value);
e.printStackTrace();
return false;
}
String strValue = h.toString();
boolean ok = true;
ok &= checkName(h);
ok &= checkValue(h);
ok &= checkParameters(h);
// DEBUG: System.out.println("Checking getHeaderValue result");
try {
h = new SipHeader(h.getName(), h.getHeaderValue());
} catch (IllegalArgumentException e) {
System.out.println("Error parsing values returned by parser " + e
+ " name=" + h.getName()
+ " value=" + h.getHeaderValue());
e.printStackTrace();
return false;
}
ok &= checkName(h);
ok &= checkValue(h);
ok &= checkParameters(h);
// DEBUG: System.out.println("Checking toString result");
int i = strValue.indexOf(':");
try {
h = new SipHeader(strValue.substring(0, i).trim(),
strValue.substring(i + 1).trim());
} catch (IllegalArgumentException e) {
System.out.println("Error parsing toString result " + e
+ " name=" + strValue.substring(0, i).trim()
+ " value=" + strValue.substring(i + 1).trim());
e.printStackTrace();
return false;
}
ok &= checkName(h);
ok &= checkValue(h);
ok &= checkParameters(h);
return ok;
|
boolean | checkName(SipHeader h)Checks for valid name in hedaer.
String pname = h.getName();
if (! (parsedName.equalsIgnoreCase(pname) ||
toShortForm(parsedName).equalsIgnoreCase(pname))) {
System.out.println("Invalid name " + h.getName());
return false;
}
return true;
|
boolean | checkParameters(SipHeader h)Checks for valid parameters in header.
String[] paramNames = h.getParameterNames();
if (parameters.length == 0) {
if (paramNames != null) {
System.out.println("getParameterNames must return null");
return false;
}
return true;
}
if (paramNames == null) {
System.out.println("getParameterNames returns null");
return false;
}
if (parameters.length != paramNames.length) {
System.out.println("getParameterNames returns invalid "+
"number of parameters: " + paramNames.length +
", must be " + parameters.length);
return false;
}
for (int i = 0; i < parameters.length; i++) {
String paramName = parameters[i][0];
String paramValue = parameters[i][1];
boolean found = false;
for (int j = 0; j < paramNames.length; j++) {
if (paramName.equalsIgnoreCase(paramNames[j])) {
found = true;
break;
}
}
if (! found) {
System.out.println(paramName +
"not found in results of getParameterNames");
return false;
}
String v = h.getParameter(paramName);
if (paramValue == null) {
if (v != null) {
System.out.println("null expected: " + paramName);
return false;
}
} else {
if (v == null) {
System.out.println("parameter " + paramName +
" not found");
return false;
}
v = fixSpaces(v);
boolean isSensitive = v.startsWith("\"");
if (! (isSensitive ? v.equals(paramValue) :
v.equalsIgnoreCase(paramValue))) {
System.out.println("Invalid parameter value: " +
v + ".");
return false;
}
}
}
return true;
|
boolean | checkValue(SipHeader h)Checks for valid value in header.
String pValue = h.getValue();
if ((pValue == null || parsedHeaderValue == null) &&
pValue != parsedHeaderValue) {
System.out.println("getValue(): Invalid value '" + h.getValue() +
"', must be '" + parsedHeaderValue + "'");
return false;
}
pValue = fixSpaces(pValue);
String name = toShortForm(h.getName());
// In case of "t:"/"T:" header, parsedHeaderValue is
// a SIP URI, so add "<"/">" around the value.
if (name.equalsIgnoreCase("t")) {
if (!pValue.startsWith("<")) {
pValue = "<" + pValue + ">";
}
if (!parsedHeaderValue.startsWith("<")) {
parsedHeaderValue = "<" + parsedHeaderValue + ">";
}
}
boolean isSensitive = name.equals("i") ||
name.equals("cseq") ||
name.equals("date");
if (!(isSensitive ?
pValue.equals(parsedHeaderValue) :
pValue.equalsIgnoreCase(parsedHeaderValue))) {
System.out.println("Invalid value '" + h.getValue() +
"', must be '" + parsedHeaderValue + "'");
return false;
}
return true;
|
public static java.lang.String | fixSpaces(java.lang.String src)Inserts white space into string.
if (src == null) {
return null;
}
StringBuffer dst = new StringBuffer();
boolean quoted = false;
boolean prevBlank = false;
for (int i = 0; i < src.length(); i++) {
char c = src.charAt(i);
if (c == '\"") {
quoted = ! quoted;
}
if (c == '\t") {
c = ' ";
}
boolean isBlank = c == ' ";
if (quoted || ! (prevBlank && isBlank)) {
dst.append(c);
}
prevBlank = isBlank;
}
return dst.toString();
|
static java.lang.String | fixString(java.lang.String src)Extracts quoted strings.
if (src == null) {
return null;
}
if (src.indexOf('\"") == -1) {
return src;
}
StringBuffer s = new StringBuffer();
for (int i = 0; i < src.length(); i++) {
char c = src.charAt(i);
if (c == '\"") {
s.append('\\");
}
if (c == '\t") {
s.append('\\");
c = 't";
}
s.append(c);
}
return s.toString();
|
public static int | runTests()Runs the set of tests.
int failed = 0, passed = 0;
for (int i = 0; i < testCases.length; i++) {
if (testCases[i].check()) {
passed++;
} else {
System.out.println("\n*** " + i + " "
+ testCases[i].name + ":"
+ testCases[i].value);
failed++;
}
}
if (failed > 0) {
System.out.println("\n*** RESULT: "
+ passed + " passed, "
+ failed + " failed; "
+ "total = " + (passed + failed) + "\n");
}
return failed;
|
public static java.lang.String | toLongForm(java.lang.String name)Output to long format string.
name = name.toLowerCase();
int i = shortForm.indexOf(name + " ");
return i == -1 ? name :
shortForm.substring(i + 2, shortForm.indexOf(':", i));
|
public static java.lang.String | toShortForm(java.lang.String name)Output from short format string.
name = name.toLowerCase();
int i = shortForm.indexOf(" " + name + ":");
return i == -1 ? name : shortForm.substring(i - 1, i);
|