Methods Summary |
---|
public boolean | decodeConstrainedEncoding(int startIndex)Decode the "Constrained-encoding" type for WSP pdu
if (decodeShortInteger(startIndex) == true) {
mStringValue = null;
return true;
}
return decodeExtensionMedia(startIndex);
|
public boolean | decodeContentLength(int startIndex)Decode the "Content length" type for WSP pdu
return decodeIntegerValue(startIndex);
|
public boolean | decodeContentLocation(int startIndex)Decode the "Content location" type for WSP pdu
return decodeTextString(startIndex);
|
public boolean | decodeContentType(int startIndex)Decode the "Content-type" type for WSP pdu
int mediaPrefixLength;
mContentParameters = new HashMap<String, String>();
try {
if (decodeValueLength(startIndex) == false) {
boolean found = decodeConstrainedEncoding(startIndex);
if (found) {
expandWellKnownMimeType();
}
return found;
}
int headersLength = (int) mUnsigned32bit;
mediaPrefixLength = getDecodedDataLength();
if (decodeIntegerValue(startIndex + mediaPrefixLength) == true) {
mDataLength += mediaPrefixLength;
int readLength = mDataLength;
mStringValue = null;
expandWellKnownMimeType();
long wellKnownValue = mUnsigned32bit;
String mimeType = mStringValue;
if (readContentParameters(startIndex + mDataLength,
(headersLength - (mDataLength - mediaPrefixLength)), 0)) {
mDataLength += readLength;
mUnsigned32bit = wellKnownValue;
mStringValue = mimeType;
return true;
}
return false;
}
if (decodeExtensionMedia(startIndex + mediaPrefixLength) == true) {
mDataLength += mediaPrefixLength;
int readLength = mDataLength;
expandWellKnownMimeType();
long wellKnownValue = mUnsigned32bit;
String mimeType = mStringValue;
if (readContentParameters(startIndex + mDataLength,
(headersLength - (mDataLength - mediaPrefixLength)), 0)) {
mDataLength += readLength;
mUnsigned32bit = wellKnownValue;
mStringValue = mimeType;
return true;
}
}
} catch (ArrayIndexOutOfBoundsException e) {
//something doesn't add up
return false;
}
return false;
|
public boolean | decodeExtensionMedia(int startIndex)Decode the "Extension-media" type for WSP PDU.
int index = startIndex;
mDataLength = 0;
mStringValue = null;
int length = mWspData.length;
boolean rtrn = index < length;
while (index < length && mWspData[index] != 0) {
index++;
}
mDataLength = index - startIndex + 1;
mStringValue = new String(mWspData, startIndex, mDataLength - 1);
return rtrn;
|
public boolean | decodeIntegerValue(int startIndex)Decode the "Integer-Value" type for WSP pdu
if (decodeShortInteger(startIndex) == true) {
return true;
}
return decodeLongInteger(startIndex);
|
public boolean | decodeLongInteger(int startIndex)Decode the "Long-integer" type for WSP pdu
int lengthMultiOctet = mWspData[startIndex] & 0xff;
if (lengthMultiOctet > WAP_PDU_SHORT_LENGTH_MAX) {
return false;
}
mUnsigned32bit = 0;
for (int i = 1; i <= lengthMultiOctet; i++) {
mUnsigned32bit = (mUnsigned32bit << 8) | (mWspData[startIndex + i] & 0xff);
}
mDataLength = 1 + lengthMultiOctet;
return true;
|
private boolean | decodeNoValue(int startIndex)Check if the next byte is No-Value
if (mWspData[startIndex] == 0) {
mDataLength = 1;
return true;
} else {
return false;
}
|
public boolean | decodeShortInteger(int startIndex)Decode the "Short-integer" type for WSP pdu
if ((mWspData[startIndex] & 0x80) == 0) {
return false;
}
mUnsigned32bit = mWspData[startIndex] & 0x7f;
mDataLength = 1;
return true;
|
public boolean | decodeTextString(int startIndex)Decode the "Text-string" type for WSP pdu
int index = startIndex;
while (mWspData[index] != 0) {
index++;
}
mDataLength = index - startIndex + 1;
if (mWspData[startIndex] == 127) {
mStringValue = new String(mWspData, startIndex + 1, mDataLength - 2);
} else {
mStringValue = new String(mWspData, startIndex, mDataLength - 1);
}
return true;
|
public boolean | decodeTokenText(int startIndex)Decode the "Token-text" type for WSP pdu
int index = startIndex;
while (mWspData[index] != 0) {
index++;
}
mDataLength = index - startIndex + 1;
mStringValue = new String(mWspData, startIndex, mDataLength - 1);
return true;
|
public boolean | decodeUintvarInteger(int startIndex)Decode the "Uintvar-integer" type for WSP pdu
int index = startIndex;
mUnsigned32bit = 0;
while ((mWspData[index] & 0x80) != 0) {
if ((index - startIndex) >= 4) {
return false;
}
mUnsigned32bit = (mUnsigned32bit << 7) | (mWspData[index] & 0x7f);
index++;
}
mUnsigned32bit = (mUnsigned32bit << 7) | (mWspData[index] & 0x7f);
mDataLength = index - startIndex + 1;
return true;
|
public boolean | decodeValueLength(int startIndex)Decode the "Value-length" type for WSP pdu
if ((mWspData[startIndex] & 0xff) > WAP_PDU_LENGTH_QUOTE) {
return false;
}
if (mWspData[startIndex] < WAP_PDU_LENGTH_QUOTE) {
mUnsigned32bit = mWspData[startIndex];
mDataLength = 1;
} else {
decodeUintvarInteger(startIndex + 1);
mDataLength++;
}
return true;
|
public boolean | decodeXWapApplicationId(int startIndex)Decode the "X-Wap-Application-Id" type for WSP pdu
if (decodeIntegerValue(startIndex) == true) {
mStringValue = null;
return true;
}
return decodeTextString(startIndex);
|
public boolean | decodeXWapContentURI(int startIndex)Decode the "X-Wap-Content-URI" type for WSP pdu
return decodeTextString(startIndex);
|
public boolean | decodeXWapInitiatorURI(int startIndex)Decode the "X-Wap-Initiator-URI" type for WSP pdu
return decodeTextString(startIndex);
|
private void | expandWellKnownMimeType()Populate stringValue with the mime type corresponding to the value in unsigned32bit
Sets unsigned32bit to -1 if stringValue is already populated
if (mStringValue == null) {
int binaryContentType = (int) mUnsigned32bit;
mStringValue = WELL_KNOWN_MIME_TYPES.get(binaryContentType);
} else {
mUnsigned32bit = -1;
}
|
public java.util.HashMap | getContentParameters()Any parameters encountered as part of a decodeContentType() invocation.
return mContentParameters;
|
public int | getDecodedDataLength()The data length of latest operation.
return mDataLength;
|
public long | getValue32()The 32-bits result of latest operation.
return mUnsigned32bit;
|
public java.lang.String | getValueString()The String result of latest operation.
return mStringValue;
|
private boolean | readContentParameters(int startIndex, int leftToRead, int accumulator)
int totalRead = 0;
if (leftToRead > 0) {
byte nextByte = mWspData[startIndex];
String value = null;
String param = null;
if ((nextByte & 0x80) == 0x00 && nextByte > 31) { // untyped
decodeTokenText(startIndex);
param = mStringValue;
totalRead += mDataLength;
} else { // typed
if (decodeIntegerValue(startIndex)) {
totalRead += mDataLength;
int wellKnownParameterValue = (int) mUnsigned32bit;
param = WELL_KNOWN_PARAMETERS.get(wellKnownParameterValue);
if (param == null) {
param = "unassigned/0x" + Long.toHexString(wellKnownParameterValue);
}
// special case for the "Q" parameter, value is a uintvar
if (wellKnownParameterValue == Q_VALUE) {
if (decodeUintvarInteger(startIndex + totalRead)) {
totalRead += mDataLength;
value = String.valueOf(mUnsigned32bit);
mContentParameters.put(param, value);
return readContentParameters(startIndex + totalRead, leftToRead
- totalRead, accumulator + totalRead);
} else {
return false;
}
}
} else {
return false;
}
}
if (decodeNoValue(startIndex + totalRead)) {
totalRead += mDataLength;
value = null;
} else if (decodeIntegerValue(startIndex + totalRead)) {
totalRead += mDataLength;
int intValue = (int) mUnsigned32bit;
value = String.valueOf(intValue);
} else {
decodeTokenText(startIndex + totalRead);
totalRead += mDataLength;
value = mStringValue;
if (value.startsWith("\"")) {
// quoted string, so remove the quote
value = value.substring(1);
}
}
mContentParameters.put(param, value);
return readContentParameters(startIndex + totalRead, leftToRead - totalRead,
accumulator + totalRead);
} else {
mDataLength = accumulator;
return true;
}
|
public boolean | seekXWapApplicationId(int startIndex, int endIndex)Seek for the "X-Wap-Application-Id" field for WSP pdu
int index = startIndex;
try {
for (index = startIndex; index <= endIndex; ) {
/**
* 8.4.1.1 Field name
* Field name is integer or text.
*/
if (decodeIntegerValue(index)) {
int fieldValue = (int) getValue32();
if (fieldValue == PARAMETER_ID_X_WAP_APPLICATION_ID) {
mUnsigned32bit = index + 1;
return true;
}
} else {
if (!decodeTextString(index)) return false;
}
index += getDecodedDataLength();
if (index > endIndex) return false;
/**
* 8.4.1.2 Field values
* Value Interpretation of First Octet
* 0 - 30 This octet is followed by the indicated number (0 - 30)
of data octets
* 31 This octet is followed by a uintvar, which indicates the number
* of data octets after it
* 32 - 127 The value is a text string, terminated by a zero octet
(NUL character)
* 128 - 255 It is an encoded 7-bit value; this header has no more data
*/
byte val = mWspData[index];
if (0 <= val && val <= WAP_PDU_SHORT_LENGTH_MAX) {
index += mWspData[index] + 1;
} else if (val == WAP_PDU_LENGTH_QUOTE) {
if (index + 1 >= endIndex) return false;
index++;
if (!decodeUintvarInteger(index)) return false;
index += getDecodedDataLength();
} else if (WAP_PDU_LENGTH_QUOTE < val && val <= 127) {
if (!decodeTextString(index)) return false;
index += getDecodedDataLength();
} else {
index++;
}
}
} catch (ArrayIndexOutOfBoundsException e) {
//seek application ID failed. WSP header might be corrupted
return false;
}
return false;
|