📄 sipnameaddressparser.java
字号:
}
break;
case 3: // '\003'
switch (o1.m_ctrlState) {
case 1: // '\001'
case 5: // '\005'
case 6: // '\006'
l1.m_host = o1.m_paragraph;
word2 = 4;
break;
default:
error("Host missing, or illegal '" + o1.m_paragraph + "'");
break;
}
break;
case 4: // '\004'
switch (o1.m_ctrlState) {
case 3: // '\003'
case 4: // '\004'
default:
break;
case 5: // '\005'
error("Invalid port or address: " + o1.m_paragraph);
break label0;
case 1: // '\001'
l1.m_port = o1.m_paragraph;
try {
Integer.parseInt(l1.m_port);
}
catch (Exception exception) {
error("Invalid port number; " + exception.getMessage());
}
break label0;
case 2: // '\002'
if (o1.m_initial == ':')
break label0;
if (o1.m_initial == ';') {
word2 = 5;
break label0;
}
if (o1.m_initial == '>') {
flag2 = true;
word2 = 8;
break label0;
}
if (o1.m_initial == '?')
word2 = 7;
else
error("Invalid host:port '" + o1.m_initial + "'");
break;
}
break;
case 5: // '\005'
switch (o1.m_ctrlState) {
case 4: // '\004'
default:
break;
case 1: // '\001'
case 3: // '\003'
case 5: // '\005'
Cache o4 = (Cache) vector.elementAt(word3 + 1);
if (o4.m_initial == '=') {
word2 = 6;
word3++;
break label0;
}
if (o4.m_initial == '>') {
flag2 = true;
checkParameter(o1.m_paragraph, "", l1.m_parameters);
break label0;
}
if (o4.m_initial == ';') {
checkParameter(o1.m_paragraph, "", l1.m_parameters);
break label0;
}
if (o4.m_ctrlState == -1) {
checkParameter(o1.m_paragraph, "", l1.m_parameters);
break label0;
}
if (o4.m_initial == '?') {
checkParameter(o1.m_paragraph, "", l1.m_parameters);
word2 = 7;
}
else {
error("Invalid parameter name '" + o1.m_paragraph + "'");
}
break label0;
case 2: // '\002'
if (o1.m_initial == ';')
break label0;
if (o1.m_initial == '>') {
flag2 = true;
word2 = 8;
}
else {
error("Invalid parameter '" + o1.m_initial + "'");
}
break;
}
break;
case 6: // '\006'
if (o1.m_ctrlState == 1 || o1.m_ctrlState == 5 || o1.m_ctrlState == 3) {
String s1 = ((Cache) vector.elementAt(word3 - 2)).m_paragraph;
checkParameter(s1, o1.m_paragraph, l1.m_parameters);
word2 = 5;
}
else {
error("Invalid parameter value '" + o1.m_paragraph + "'");
}
break;
}
}
if (l1.m_host != null)
checkHostAddress(l1.m_host);
if (flag1 && !flag2)
error("Missing closing '>' quote");
if (flag2 && !flag1)
error("Unexpected right '>' quote");
l1.m_uri = assembledURI(l1.m_scheme, l1.m_fullName, l1.m_host, l1.m_port);
return l1;
}
/**
* checkScheme
*
* @param cache
* @throws SipException
*/
public static void checkScheme(Cache cache) throws SipException {
char c = cache.m_paragraph.charAt(0);
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
if (cache.m_ctrlState == 1)
return;
int i = 1;
do {
if (i >= cache.m_paragraph.length())
break;
char c1 = cache.m_paragraph.charAt(i);
switch (c1) {
case 33: // '!'
case 37: // '%'
case 39: // '\''
case 42: // '*'
case 95: // '_'
error("Illegal characters in scheme '" + cache.m_paragraph + "'");
break;
}
i++;
}
while (true);
}
else {
error("Illegal first character in scheme '" + cache.m_paragraph + "'");
}
}
/**
* checkHostAddress
*
* @param hostAddress
* @throws SipException
*/
public static void checkHostAddress(String hostAddress) throws SipException {
if (hostAddress.charAt(0) == '[')
return;
int i = 0;
int j = 0;
for (int k = 0; k < hostAddress.length(); k++) {
char c = hostAddress.charAt(k);
if (c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c >= 'a' && c <= 'z'
|| c == '-')
continue;
if (c == '.') {
if (i + 1 == k || k == 0)
error("Invalid host address or name '" + hostAddress + "'");
i = k;
if (++j > 3)
error("Invalid host address or name '" + hostAddress + "'");
}
else {
error("Invalid host address or name '" + hostAddress + "'");
}
}
}
/**
* error
*
* @param msg
* @throws SipException
*/
private static void error(String msg) throws SipException {
throw new SipException(msg, SipException.GENERAL_ERROR); // 0
}
/**
* checkParameter
*
* @param paramName
* @param paramValue
* @param headers
* @throws SipException
*/
private static void checkParameter(String paramName, String paramValue,
Vector headers) throws SipException {
paramName = paramName.toLowerCase();
for (Enumeration enumeration = headers.elements(); enumeration
.hasMoreElements();) {
PairStructure t1 = (PairStructure) enumeration.nextElement();
if (paramName.equals(((Object) (t1.getName())))) {
throw new SipException("Duplicate parameter '" + paramName + "'",
(byte) 0);
}
}
headers.addElement(((Object) (new PairStructure(paramName, paramValue))));
}
/**
* assembledURI
*
* @param scheme
* @param name
* @param host
* @param port
* @return URI
*/
public static synchronized String assembledURI(String scheme, String name,
String host, String port) {
StringBuffer stringbuffer = new StringBuffer();
if (scheme != null && scheme.length() > 0) {
stringbuffer.append(scheme);
stringbuffer.append(":");
}
if (name != null) {
stringbuffer.append(name);
stringbuffer.append("@");
}
if (host != null)
stringbuffer.append(host);
if (port != null && port.length() > 0) {
Integer.parseInt(port);
stringbuffer.append(":");
stringbuffer.append(port);
}
return stringbuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -