1c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/*
2c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Copyright (C) 2008 The Android Open Source Project
3c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
4c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Licensed under the Apache License, Version 2.0 (the "License");
5c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * you may not use this file except in compliance with the License.
6c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * You may obtain a copy of the License at
7c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
8c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *      http://www.apache.org/licenses/LICENSE-2.0
9c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
10c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Unless required by applicable law or agreed to in writing, software
11c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * distributed under the License is distributed on an "AS IS" BASIS,
12c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * See the License for the specific language governing permissions and
14c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * limitations under the License.
15c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
16c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
17c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepackage com.android.internal.telephony;
18c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
19c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport java.util.HashMap;
20c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
21c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/**
22c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Implement the WSP data type decoder.
23c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
24c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * @hide
25c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
26c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepublic class WspTypeDecoder {
27c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
28c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private static final int WAP_PDU_SHORT_LENGTH_MAX = 30;
29c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private static final int WAP_PDU_LENGTH_QUOTE = 31;
30c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
31c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final int PDU_TYPE_PUSH = 0x06;
32c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final int PDU_TYPE_CONFIRMED_PUSH = 0x07;
33c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
34c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private final static HashMap<Integer, String> WELL_KNOWN_MIME_TYPES =
35c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            new HashMap<Integer, String>();
36c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
37c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private final static HashMap<Integer, String> WELL_KNOWN_PARAMETERS =
38c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            new HashMap<Integer, String>();
39c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
40c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final int PARAMETER_ID_X_WAP_APPLICATION_ID = 0x2f;
41c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private static final int Q_VALUE = 0x00;
42c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
43c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static {
44c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x00, "*/*");
45c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x01, "text/*");
46c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x02, "text/html");
47c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x03, "text/plain");
48c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x04, "text/x-hdml");
49c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x05, "text/x-ttml");
50c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x06, "text/x-vCalendar");
51c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x07, "text/x-vCard");
52c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x08, "text/vnd.wap.wml");
53c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x09, "text/vnd.wap.wmlscript");
54c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0A, "text/vnd.wap.wta-event");
55c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0B, "multipart/*");
56c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0C, "multipart/mixed");
57c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0D, "multipart/form-data");
58c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0E, "multipart/byterantes");
59c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0F, "multipart/alternative");
60c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x10, "application/*");
61c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x11, "application/java-vm");
62c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x12, "application/x-www-form-urlencoded");
63c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x13, "application/x-hdmlc");
64c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x14, "application/vnd.wap.wmlc");
65c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x15, "application/vnd.wap.wmlscriptc");
66c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x16, "application/vnd.wap.wta-eventc");
67c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x17, "application/vnd.wap.uaprof");
68c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x18, "application/vnd.wap.wtls-ca-certificate");
69c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x19, "application/vnd.wap.wtls-user-certificate");
70c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1A, "application/x-x509-ca-cert");
71c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1B, "application/x-x509-user-cert");
72c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1C, "image/*");
73c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1D, "image/gif");
74c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1E, "image/jpeg");
75c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x1F, "image/tiff");
76c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x20, "image/png");
77c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x21, "image/vnd.wap.wbmp");
78c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x22, "application/vnd.wap.multipart.*");
79c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x23, "application/vnd.wap.multipart.mixed");
80c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x24, "application/vnd.wap.multipart.form-data");
81c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x25, "application/vnd.wap.multipart.byteranges");
82c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x26, "application/vnd.wap.multipart.alternative");
83c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x27, "application/xml");
84c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x28, "text/xml");
85c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x29, "application/vnd.wap.wbxml");
86c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2A, "application/x-x968-cross-cert");
87c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2B, "application/x-x968-ca-cert");
88c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2C, "application/x-x968-user-cert");
89c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2D, "text/vnd.wap.si");
90c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2E, "application/vnd.wap.sic");
91c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x2F, "text/vnd.wap.sl");
92c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x30, "application/vnd.wap.slc");
93c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x31, "text/vnd.wap.co");
94c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x32, "application/vnd.wap.coc");
95c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x33, "application/vnd.wap.multipart.related");
96c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x34, "application/vnd.wap.sia");
97c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x35, "text/vnd.wap.connectivity-xml");
98c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x36, "application/vnd.wap.connectivity-wbxml");
99c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x37, "application/pkcs7-mime");
100c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x38, "application/vnd.wap.hashed-certificate");
101c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x39, "application/vnd.wap.signed-certificate");
102c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3A, "application/vnd.wap.cert-response");
103c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3B, "application/xhtml+xml");
104c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3C, "application/wml+xml");
105c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3D, "text/css");
106c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3E, "application/vnd.wap.mms-message");
107c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x3F, "application/vnd.wap.rollover-certificate");
108c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x40, "application/vnd.wap.locc+wbxml");
109c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x41, "application/vnd.wap.loc+xml");
110c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x42, "application/vnd.syncml.dm+wbxml");
111c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x43, "application/vnd.syncml.dm+xml");
112c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x44, "application/vnd.syncml.notification");
113c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x45, "application/vnd.wap.xhtml+xml");
114c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x46, "application/vnd.wv.csp.cir");
115c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x47, "application/vnd.oma.dd+xml");
116c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x48, "application/vnd.oma.drm.message");
117c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x49, "application/vnd.oma.drm.content");
118c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4A, "application/vnd.oma.drm.rights+xml");
119c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4B, "application/vnd.oma.drm.rights+wbxml");
120c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4C, "application/vnd.wv.csp+xml");
121c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4D, "application/vnd.wv.csp+wbxml");
122c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4E, "application/vnd.syncml.ds.notification");
123c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x4F, "audio/*");
124c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x50, "video/*");
125c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x51, "application/vnd.oma.dd2+xml");
126c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x52, "application/mikey");
127c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x53, "application/vnd.oma.dcd");
128c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x54, "application/vnd.oma.dcdc");
129c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
130c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0201, "application/vnd.uplanet.cacheop-wbxml");
131c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0202, "application/vnd.uplanet.signal");
132c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0203, "application/vnd.uplanet.alert-wbxml");
133c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0204, "application/vnd.uplanet.list-wbxml");
134c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0205, "application/vnd.uplanet.listcmd-wbxml");
135c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0206, "application/vnd.uplanet.channel-wbxml");
136c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0207, "application/vnd.uplanet.provisioning-status-uri");
137c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0208, "x-wap.multipart/vnd.uplanet.header-set");
138c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0209, "application/vnd.uplanet.bearer-choice-wbxml");
139c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x020A, "application/vnd.phonecom.mmc-wbxml");
140c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x020B, "application/vnd.nokia.syncset+wbxml");
141c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x020C, "image/x-up-wpng");
142c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0300, "application/iota.mmc-wbxml");
143c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0301, "application/iota.mmc-xml");
144c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0302, "application/vnd.syncml+xml");
145c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0303, "application/vnd.syncml+wbxml");
146c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0304, "text/vnd.wap.emn+xml");
147c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0305, "text/calendar");
148c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0306, "application/vnd.omads-email+xml");
149c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0307, "application/vnd.omads-file+xml");
150c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0308, "application/vnd.omads-folder+xml");
151c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0309, "text/directory;profile=vCard");
152c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030A, "application/vnd.wap.emn+wbxml");
153c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030B, "application/vnd.nokia.ipdc-purchase-response");
154c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030C, "application/vnd.motorola.screen3+xml");
155c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030D, "application/vnd.motorola.screen3+gzip");
156c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030E, "application/vnd.cmcc.setting+wbxml");
157c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x030F, "application/vnd.cmcc.bombing+wbxml");
158c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0310, "application/vnd.docomo.pf");
159c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0311, "application/vnd.docomo.ub");
160c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0312, "application/vnd.omaloc-supl-init");
161c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0313, "application/vnd.oma.group-usage-list+xml");
162c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0314, "application/oma-directory+xml");
163c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0315, "application/vnd.docomo.pf2");
164c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0316, "application/vnd.oma.drm.roap-trigger+wbxml");
165c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0317, "application/vnd.sbm.mid2");
166c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0318, "application/vnd.wmf.bootstrap");
167c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x0319, "application/vnc.cmcc.dcd+xml");
168c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x031A, "application/vnd.sbm.cid");
169c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_MIME_TYPES.put(0x031B, "application/vnd.oma.bcast.provisioningtrigger");
170c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
171c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x00, "Q");
172c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x01, "Charset");
173c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x02, "Level");
174c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x03, "Type");
175c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x07, "Differences");
176c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x08, "Padding");
177c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x09, "Type");
178c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x0E, "Max-Age");
179c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x10, "Secure");
180c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x11, "SEC");
181c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x12, "MAC");
182c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x13, "Creation-date");
183c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x14, "Modification-date");
184c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x15, "Read-date");
185c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x16, "Size");
186c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x17, "Name");
187c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x18, "Filename");
188c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x19, "Start");
189c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x1A, "Start-info");
190c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x1B, "Comment");
191c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x1C, "Domain");
192c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        WELL_KNOWN_PARAMETERS.put(0x1D, "Path");
193c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
194c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
195c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final String CONTENT_TYPE_B_PUSH_CO = "application/vnd.wap.coc";
196c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final String CONTENT_TYPE_B_MMS = "application/vnd.wap.mms-message";
197c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static final String CONTENT_TYPE_B_PUSH_SYNCML_NOTI = "application/vnd.syncml.notification";
198c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
19922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    byte[] mWspData;
20022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    int    mDataLength;
20122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    long   mUnsigned32bit;
20222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    String mStringValue;
203c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
20422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    HashMap<String, String> mContentParameters;
205c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
206c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public WspTypeDecoder(byte[] pdu) {
20722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mWspData = pdu;
208c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
209c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
210c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
211c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Text-string" type for WSP pdu
212c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
213c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Text-string" in this pdu
214c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
215c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Text-string) occur
216c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValueString() method length of data in pdu can be
217c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         retrieved by getDecodedDataLength() method
218c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
219c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeTextString(int startIndex) {
220c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int index = startIndex;
22122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        while (mWspData[index] != 0) {
222c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            index++;
223c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
22422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = index - startIndex + 1;
22522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if (mWspData[startIndex] == 127) {
22622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mStringValue = new String(mWspData, startIndex + 1, mDataLength - 2);
227c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
22822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mStringValue = new String(mWspData, startIndex, mDataLength - 1);
229c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
230c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
231c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
232c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
233c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
234c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Token-text" type for WSP pdu
235c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
236c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Token-text" in this pdu
237c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
238c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return always true
239c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValueString() method
240c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
241c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
242c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeTokenText(int startIndex) {
243c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int index = startIndex;
24422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        while (mWspData[index] != 0) {
245c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            index++;
246c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
24722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = index - startIndex + 1;
24822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mStringValue = new String(mWspData, startIndex, mDataLength - 1);
249c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
250c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
251c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
252c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
253c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
254c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Short-integer" type for WSP pdu
255c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
256c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Short-integer" in this pdu
257c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
258c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Short-integer) occur
259c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
260c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
261c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
262c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeShortInteger(int startIndex) {
26322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if ((mWspData[startIndex] & 0x80) == 0) {
264c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
265c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
26622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUnsigned32bit = mWspData[startIndex] & 0x7f;
26722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = 1;
268c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
269c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
270c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
271c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
272c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Long-integer" type for WSP pdu
273c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
274c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Long-integer" in this pdu
275c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
276c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Long-integer) occur
277c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
278c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
279c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
280c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeLongInteger(int startIndex) {
28122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        int lengthMultiOctet = mWspData[startIndex] & 0xff;
282c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
283c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (lengthMultiOctet > WAP_PDU_SHORT_LENGTH_MAX) {
284c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
285c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
28622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUnsigned32bit = 0;
287c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        for (int i = 1; i <= lengthMultiOctet; i++) {
28822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUnsigned32bit = (mUnsigned32bit << 8) | (mWspData[startIndex + i] & 0xff);
289c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
29022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = 1 + lengthMultiOctet;
291c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
292c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
293c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
294c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
295c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Integer-Value" type for WSP pdu
296c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
297c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Integer-Value" in this pdu
298c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
299c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Integer-Value) occur
300c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
301c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
302c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
303c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeIntegerValue(int startIndex) {
304c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (decodeShortInteger(startIndex) == true) {
305c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return true;
306c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
307c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeLongInteger(startIndex);
308c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
309c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
310c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
311c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Uintvar-integer" type for WSP pdu
312c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
313c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Uintvar-integer" in this pdu
314c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
315c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Uintvar-integer) occur
316c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
317c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
318c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
319c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeUintvarInteger(int startIndex) {
320c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int index = startIndex;
321c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
32222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUnsigned32bit = 0;
32322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        while ((mWspData[index] & 0x80) != 0) {
324c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if ((index - startIndex) >= 4) {
325c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                return false;
326c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
32722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUnsigned32bit = (mUnsigned32bit << 7) | (mWspData[index] & 0x7f);
328c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            index++;
329c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
33022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUnsigned32bit = (mUnsigned32bit << 7) | (mWspData[index] & 0x7f);
33122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = index - startIndex + 1;
332c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
333c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
334c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
335c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
336c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Value-length" type for WSP pdu
337c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
338c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Value-length" in this pdu
339c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
340c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Value-length) occur
341c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
342c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
343c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
344c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeValueLength(int startIndex) {
34522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if ((mWspData[startIndex] & 0xff) > WAP_PDU_LENGTH_QUOTE) {
346c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
347c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
34822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if (mWspData[startIndex] < WAP_PDU_LENGTH_QUOTE) {
34922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUnsigned32bit = mWspData[startIndex];
35022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mDataLength = 1;
351c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
352c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            decodeUintvarInteger(startIndex + 1);
35322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mDataLength++;
354c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
355c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return true;
356c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
357c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
358c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
359c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Extension-media" type for WSP PDU.
360c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
361c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Extension-media" in this PDU.
362c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
363c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false on error, such as if there is no Extension-media at startIndex.
364c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         Side-effects: updates stringValue (available with
365c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         getValueString()), which will be null on error. The length of the
366c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         data in the PDU is available with getValue32(), 0 on error.
367c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
368c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeExtensionMedia(int startIndex) {
369c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int index = startIndex;
37022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = 0;
37122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mStringValue = null;
37222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        int length = mWspData.length;
373c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        boolean rtrn = index < length;
374c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
37522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        while (index < length && mWspData[index] != 0) {
376c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            index++;
377c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
378c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
37922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mDataLength = index - startIndex + 1;
38022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mStringValue = new String(mWspData, startIndex, mDataLength - 1);
381c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
382c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return rtrn;
383c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
384c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
385c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
386c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Constrained-encoding" type for WSP pdu
387c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
388c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Constrained-encoding" in this pdu
389c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
390c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Constrained-encoding) occur
391c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved first by getValueString() and second by getValue32() method
392c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
393c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
394c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeConstrainedEncoding(int startIndex) {
395c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (decodeShortInteger(startIndex) == true) {
39622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mStringValue = null;
397c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return true;
398c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
399c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeExtensionMedia(startIndex);
400c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
401c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
402c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
403c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Content-type" type for WSP pdu
404c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
405c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Content-type" in this pdu
406c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
407c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Content-type) occurs
408c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         If a content type exists in the headers (either as inline string, or as well-known
409c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         value), getValueString() will return it. If a 'well known value' is encountered that
410c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         cannot be mapped to a string mime type, getValueString() will return null, and
411c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         getValue32() will return the unknown content type value.
412c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
413c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         Any content type parameters will be accessible via getContentParameters()
414c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
415c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeContentType(int startIndex) {
416c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int mediaPrefixLength;
41722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mContentParameters = new HashMap<String, String>();
418c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
419c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
420c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (decodeValueLength(startIndex) == false) {
421c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                boolean found = decodeConstrainedEncoding(startIndex);
422c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (found) {
423c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    expandWellKnownMimeType();
424c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
425c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                return found;
426c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
42722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            int headersLength = (int) mUnsigned32bit;
428c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            mediaPrefixLength = getDecodedDataLength();
429c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (decodeIntegerValue(startIndex + mediaPrefixLength) == true) {
43022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                mDataLength += mediaPrefixLength;
43122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                int readLength = mDataLength;
43222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                mStringValue = null;
433c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                expandWellKnownMimeType();
43422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                long wellKnownValue = mUnsigned32bit;
43522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                String mimeType = mStringValue;
43622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                if (readContentParameters(startIndex + mDataLength,
43722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        (headersLength - (mDataLength - mediaPrefixLength)), 0)) {
43822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mDataLength += readLength;
43922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mUnsigned32bit = wellKnownValue;
44022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mStringValue = mimeType;
441c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    return true;
442c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
443c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                return false;
444c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
445c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (decodeExtensionMedia(startIndex + mediaPrefixLength) == true) {
44622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                mDataLength += mediaPrefixLength;
44722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                int readLength = mDataLength;
448c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                expandWellKnownMimeType();
44922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                long wellKnownValue = mUnsigned32bit;
45022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                String mimeType = mStringValue;
45122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                if (readContentParameters(startIndex + mDataLength,
45222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        (headersLength - (mDataLength - mediaPrefixLength)), 0)) {
45322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mDataLength += readLength;
45422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mUnsigned32bit = wellKnownValue;
45522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mStringValue = mimeType;
456c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    return true;
457c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
458c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
459c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (ArrayIndexOutOfBoundsException e) {
460c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            //something doesn't add up
461c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
462c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
463c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return false;
464c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
465c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
466c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private boolean readContentParameters(int startIndex, int leftToRead, int accumulator) {
467c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
468c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int totalRead = 0;
469c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
470c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (leftToRead > 0) {
47122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            byte nextByte = mWspData[startIndex];
472c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            String value = null;
473c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            String param = null;
474c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if ((nextByte & 0x80) == 0x00 && nextByte > 31) { // untyped
475c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                decodeTokenText(startIndex);
47622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                param = mStringValue;
47722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                totalRead += mDataLength;
478c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            } else { // typed
479c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (decodeIntegerValue(startIndex)) {
48022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    totalRead += mDataLength;
48122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    int wellKnownParameterValue = (int) mUnsigned32bit;
482c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    param = WELL_KNOWN_PARAMETERS.get(wellKnownParameterValue);
483c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (param == null) {
484c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        param = "unassigned/0x" + Long.toHexString(wellKnownParameterValue);
485c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
486c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    // special case for the "Q" parameter, value is a uintvar
487c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (wellKnownParameterValue == Q_VALUE) {
488c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        if (decodeUintvarInteger(startIndex + totalRead)) {
48922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            totalRead += mDataLength;
49022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            value = String.valueOf(mUnsigned32bit);
49122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            mContentParameters.put(param, value);
492c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                            return readContentParameters(startIndex + totalRead, leftToRead
493c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                                                            - totalRead, accumulator + totalRead);
494c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        } else {
495c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                            return false;
496c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        }
497c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
498c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                } else {
499c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    return false;
500c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
501c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
502c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
503c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (decodeNoValue(startIndex + totalRead)) {
50422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                totalRead += mDataLength;
505c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                value = null;
506c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            } else if (decodeIntegerValue(startIndex + totalRead)) {
50722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                totalRead += mDataLength;
50822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                int intValue = (int) mUnsigned32bit;
5090fcf2097e7e217319b625d5dfc24aded06c02227Johan Redestig                value = String.valueOf(intValue);
510c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            } else {
511c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                decodeTokenText(startIndex + totalRead);
51222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                totalRead += mDataLength;
51322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                value = mStringValue;
514c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (value.startsWith("\"")) {
515c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    // quoted string, so remove the quote
516c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    value = value.substring(1);
517c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
518c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
51922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mContentParameters.put(param, value);
520c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return readContentParameters(startIndex + totalRead, leftToRead - totalRead,
521c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                                            accumulator + totalRead);
522c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
523c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
52422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mDataLength = accumulator;
525c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return true;
526c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
527c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
528c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
529c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
530c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Check if the next byte is No-Value
531c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
532c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Content length" in this pdu
533c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
534c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return true if and only if the next byte is 0x00
535c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
536c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private boolean decodeNoValue(int startIndex) {
53722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if (mWspData[startIndex] == 0) {
53822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mDataLength = 1;
539c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return true;
540c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
541c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
542c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
543c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
544c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
545c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
546c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Populate stringValue with the mime type corresponding to the value in unsigned32bit
547c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
548c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Sets unsigned32bit to -1 if stringValue is already populated
549c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
550c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    private void expandWellKnownMimeType() {
55122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if (mStringValue == null) {
55222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            int binaryContentType = (int) mUnsigned32bit;
55322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mStringValue = WELL_KNOWN_MIME_TYPES.get(binaryContentType);
554c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } else {
55522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUnsigned32bit = -1;
556c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
557c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
558c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
559c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
560c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Content length" type for WSP pdu
561c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
562c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Content length" in this pdu
563c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
564c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Content length) occur
565c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32() method
566c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
567c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
568c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeContentLength(int startIndex) {
569c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeIntegerValue(startIndex);
570c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
571c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
572c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
573c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "Content location" type for WSP pdu
574c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
575c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "Content location" in this pdu
576c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
577c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a Content location) occur
578c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValueString() method
579c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
580c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
581c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeContentLocation(int startIndex) {
582c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeTextString(startIndex);
583c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
584c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
585c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
586c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "X-Wap-Application-Id" type for WSP pdu
587c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
588c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "X-Wap-Application-Id" in this pdu
589c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
590c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a X-Wap-Application-Id) occur
591c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved first by getValueString() and second by getValue32()
592c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         method
593c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
594c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
595c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeXWapApplicationId(int startIndex) {
596c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        if (decodeIntegerValue(startIndex) == true) {
59722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mStringValue = null;
598c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return true;
599c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
600c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeTextString(startIndex);
601c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
602c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
603c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
604c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Seek for the "X-Wap-Application-Id" field for WSP pdu
605c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
606c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of seek pointer
607c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param endIndex Valid seek area end point
608c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
609c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a X-Wap-Application-Id) occur
610c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValue32()
611c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
612c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean seekXWapApplicationId(int startIndex, int endIndex) {
613c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        int index = startIndex;
614c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
615c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        try {
616c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            for (index = startIndex; index <= endIndex; ) {
617c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                /**
618c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 8.4.1.1  Field name
619c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * Field name is integer or text.
620c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 */
621c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (decodeIntegerValue(index)) {
622c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    int fieldValue = (int) getValue32();
623c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
624c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (fieldValue == PARAMETER_ID_X_WAP_APPLICATION_ID) {
62522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        mUnsigned32bit = index + 1;
626c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        return true;
627c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
628c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                } else {
629c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (!decodeTextString(index)) return false;
630c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
631c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                index += getDecodedDataLength();
632c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (index > endIndex) return false;
633c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
634c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                /**
635c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 8.4.1.2 Field values
636c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * Value Interpretation of First Octet
637c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 0 - 30 This octet is followed by the indicated number (0 - 30)
638c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        of data octets
639c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 31 This octet is followed by a uintvar, which indicates the number
640c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 *      of data octets after it
641c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 32 - 127 The value is a text string, terminated by a zero octet
642c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        (NUL character)
643c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 * 128 - 255 It is an encoded 7-bit value; this header has no more data
644c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                 */
64522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                byte val = mWspData[index];
646c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                if (0 <= val && val <= WAP_PDU_SHORT_LENGTH_MAX) {
64722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    index += mWspData[index] + 1;
648c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                } else if (val == WAP_PDU_LENGTH_QUOTE) {
649c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (index + 1 >= endIndex) return false;
650c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    index++;
651c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (!decodeUintvarInteger(index)) return false;
652c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    index += getDecodedDataLength();
653c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                } else if (WAP_PDU_LENGTH_QUOTE < val && val <= 127) {
654c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if (!decodeTextString(index)) return false;
655c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    index += getDecodedDataLength();
656c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                } else {
657c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    index++;
658c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
659c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
660c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        } catch (ArrayIndexOutOfBoundsException e) {
661c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            //seek application ID failed. WSP header might be corrupted
662c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            return false;
663c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
664c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return false;
665c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
666c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
667c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
668c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "X-Wap-Content-URI" type for WSP pdu
669c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
670c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "X-Wap-Content-URI" in this pdu
671c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
672c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a X-Wap-Content-URI) occur
673c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValueString() method
674c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
675c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
676c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeXWapContentURI(int startIndex) {
677c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeTextString(startIndex);
678c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
679c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
680c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
681c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Decode the "X-Wap-Initiator-URI" type for WSP pdu
682c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
683c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param startIndex The starting position of the "X-Wap-Initiator-URI" in this pdu
684c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
685c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return false when error(not a X-Wap-Initiator-URI) occur
686c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         return value can be retrieved by getValueString() method
687c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         length of data in pdu can be retrieved by getDecodedDataLength() method
688c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
689c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public boolean decodeXWapInitiatorURI(int startIndex) {
690c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return decodeTextString(startIndex);
691c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
692c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
693c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
694c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * The data length of latest operation.
695c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
696c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public int getDecodedDataLength() {
69722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        return mDataLength;
698c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
699c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
700c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
701c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * The 32-bits result of latest operation.
702c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
703c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public long getValue32() {
70422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        return mUnsigned32bit;
705c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
706c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
707c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
708c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * The String result of latest operation.
709c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
710c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public String getValueString() {
71122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        return mStringValue;
712c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
713c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
714c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
715c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Any parameters encountered as part of a decodeContentType() invocation.
716c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
717c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return a map of content parameters keyed by their names, or null if
718c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         decodeContentType() has not been called If any unassigned
719c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         well-known parameters are encountered, the key of the map will be
720c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         'unassigned/0x...', where '...' is the hex value of the
721c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *         unassigned parameter.  If a parameter has No-Value the value will be null.
722c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     *
723c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
724c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public HashMap<String, String> getContentParameters() {
72522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        return mContentParameters;
726c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
727c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville}
728