19439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly/* 28949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * Copyright (c) 2014 The Android Open Source Project 39439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Copyright (c) 2008-2009, Motorola, Inc. 49439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 59439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * All rights reserved. 69439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 79439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Redistribution and use in source and binary forms, with or without 89439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * modification, are permitted provided that the following conditions are met: 99439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Redistributions of source code must retain the above copyright notice, 119439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * this list of conditions and the following disclaimer. 129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 139439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Redistributions in binary form must reproduce the above copyright notice, 149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * this list of conditions and the following disclaimer in the documentation 159439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * and/or other materials provided with the distribution. 169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * - Neither the name of the Motorola, Inc. nor the names of its contributors 189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * may be used to endorse or promote products derived from this software 199439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * without specific prior written permission. 209439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * 219439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 229439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 249439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 259439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 279439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 299439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 319439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * POSSIBILITY OF SUCH DAMAGE. 329439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 339439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 349439a7fe517b858bc5e5c654b459315e4722feb2Nick Pellypackage javax.obex; 359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 362e0da96e757a977154063f980d3f4e1abd41cf09Nick Pellyimport java.io.ByteArrayOutputStream; 372e0da96e757a977154063f980d3f4e1abd41cf09Nick Pellyimport java.io.IOException; 382e0da96e757a977154063f980d3f4e1abd41cf09Nick Pellyimport java.util.Calendar; 3925f2c4cd953764008d04147a14d990c06a8154e5Oscar Montemayorimport java.security.SecureRandom; 409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly/** 429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * This class implements the javax.obex.HeaderSet interface for OBEX over 439439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * RFCOMM. 442e0da96e757a977154063f980d3f4e1abd41cf09Nick Pelly * @hide 459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 469439a7fe517b858bc5e5c654b459315e4722feb2Nick Pellypublic final class HeaderSet { 479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 4905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Count header. This allows the connection statement to 5005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * tell the server how many objects it plans to send or retrieve. 519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>COUNT</code> is 0xC0 (192). 539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int COUNT = 0xC0; 559439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 569439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 5705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Name header. This specifies the name of the object. 589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 599439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>NAME</code> is 0x01 (1). 609439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 619439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int NAME = 0x01; 629439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 6405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Type header. This allows a request to specify the 659439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * type of the object (e.g. text, html, binary, etc.). 669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 679439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>TYPE</code> is 0x42 (66). 689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 699439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int TYPE = 0x42; 709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 7205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Length header. This is the length of the object in 739439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * bytes. 749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 759439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>LENGTH</code> is 0xC3 (195). 769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 779439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int LENGTH = 0xC3; 789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 799439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 8005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Time header using the ISO 8601 standards. This is the 8105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * preferred time header. 829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 839439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>TIME_ISO_8601</code> is 0x44 (68). 849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 859439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int TIME_ISO_8601 = 0x44; 869439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 879439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 8805ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Time header using the 4 byte representation. This is 8905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * only included for backwards compatibility. It represents the number of 9005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * seconds since January 1, 1970. 919439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 929439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>TIME_4_BYTE</code> is 0xC4 (196). 939439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 949439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int TIME_4_BYTE = 0xC4; 959439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 9705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Description header. This is a text description of the 9805ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * object. 999439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>DESCRIPTION</code> is 0x05 (5). 1019439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int DESCRIPTION = 0x05; 1039439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 10505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Target header. This is the name of the service an 1069439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * operation is targeted to. 1079439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>TARGET</code> is 0x46 (70). 1099439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int TARGET = 0x46; 1119439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 11305ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX HTTP header. This allows an HTTP 1.X header to be 1149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * included in a request or reply. 1159439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>HTTP</code> is 0x47 (71). 1179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int HTTP = 0x47; 1199439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1209439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 1213998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * Represents the OBEX BODY header. 1223998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * <P> 1233998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>BODY</code> is 0x48 (72). 1243998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun */ 1253998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int BODY = 0x48; 1263998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1273998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun /** 1283998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * Represents the OBEX End of BODY header. 1293998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * <P> 1303998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>BODY</code> is 0x49 (73). 1313998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun */ 1323998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int END_OF_BODY = 0x49; 1333998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1343998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun /** 13505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Who header. Identifies the OBEX application to 1369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * determine if the two peers are talking to each other. 1379439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>WHO</code> is 0x4A (74). 1399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int WHO = 0x4A; 1419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 1433998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * Represents the OBEX Connection ID header. Identifies used for OBEX 1443998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * connection multiplexing. 1459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1463998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>CONNECTION_ID</code> is 0xCB (203). 1479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1483998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1493998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int CONNECTION_ID = 0xCB; 1509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 15205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Application Parameter header. This header specifies 1539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * additional application request and response information. 1549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <P> 1559439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * The value of <code>APPLICATION_PARAMETER</code> is 0x4C (76). 1569439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 1579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public static final int APPLICATION_PARAMETER = 0x4C; 1589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1593998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun /** 1603998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * Represents the OBEX authentication digest-challenge. 1613998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * <P> 1623998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>AUTH_CHALLENGE</code> is 0x4D (77). 1633998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun */ 1643998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int AUTH_CHALLENGE = 0x4D; 1653998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1663998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun /** 1673998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * Represents the OBEX authentication digest-response. 1683998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * <P> 1693998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>AUTH_RESPONSE</code> is 0x4E (78). 1703998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun */ 1713998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int AUTH_RESPONSE = 0x4E; 1723998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1733998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun /** 17405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Represents the OBEX Object Class header. This header specifies the OBEX 17505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * object class of the object. 1763998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * <P> 1773998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * The value of <code>OBJECT_CLASS</code> is 0x4F (79). 1783998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun */ 1793998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public static final int OBJECT_CLASS = 0x4F; 1803998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 1813998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Long mCount; // 4 byte unsigned integer 1829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1833998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private String mName; // null terminated Unicode text string 1849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1858949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta private boolean mEmptyName; 1868949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 1873998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private String mType; // null terminated ASCII text string 1889439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1893998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Long mLength; // 4 byte unsigend integer 1909439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1913998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Calendar mIsoTime; // String of the form YYYYMMDDTHHMMSSZ 1929439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1933998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Calendar mByteTime; // 4 byte unsigned integer 1949439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1953998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private String mDescription; // null terminated Unicode text String 1969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1973998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[] mTarget; // byte sequence 1989439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 1993998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[] mHttpHeader; // byte sequence 2009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2013998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[] mWho; // length prefixed byte sequence 2029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2033998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[] mAppParam; // byte sequence of the form tag length value 2049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2053998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[] mObjectClass; // byte sequence 2069439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2073998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private String[] mUnicodeUserDefined; //null terminated unicode string 2089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2093998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private byte[][] mSequenceUserDefined; // byte sequence user defined 2109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2113998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Byte[] mByteUserDefined; // 1 byte 2129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2133998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun private Long[] mIntegerUserDefined; // 4 byte unsigned integer 2149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 21525f2c4cd953764008d04147a14d990c06a8154e5Oscar Montemayor private final SecureRandom mRandom; 2169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 21705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun /*package*/ byte[] nonce; 2189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 21905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun public byte[] mAuthChall; // The authentication challenge header 22005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun 22105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun public byte[] mAuthResp; // The authentication response header 22205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun 22305ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun public byte[] mConnectionID; // THe connection ID 22405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun 22505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun public int responseCode; 2269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2279439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 2289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Creates new <code>HeaderSet</code> object. 2299439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param size the max packet size for this connection 2309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 2319439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public HeaderSet() { 2323998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mUnicodeUserDefined = new String[16]; 2333998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mSequenceUserDefined = new byte[16][]; 2343998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mByteUserDefined = new Byte[16]; 2353998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mIntegerUserDefined = new Long[16]; 2369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly responseCode = -1; 23725f2c4cd953764008d04147a14d990c06a8154e5Oscar Montemayor mRandom = new SecureRandom(); 2389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 2399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 2418949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * Sets flag for special "value" of NAME header which should be empty. This 2428949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * is not the same as NAME header with empty string in which case it will 2438949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * have length of 5 bytes. It should be 3 bytes with only header id and 2448949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * length field. 2458949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta */ 2468949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public void setEmptyNameHeader() { 2478949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta mName = null; 2488949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta mEmptyName = true; 2498949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 2508949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 2518949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** 2528949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * Gets flag for special "value" of NAME header which should be empty. See 2538949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta * above. 2548949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta */ 2558949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta public boolean getEmptyNameHeader() { 2568949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta return mEmptyName; 2578949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta } 2588949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta 2598949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta /** 26005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Sets the value of the header identifier to the value provided. The type 2619439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * of object must correspond to the Java type defined in the description of 26205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * this interface. If <code>null</code> is passed as the 2639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * <code>headerValue</code> then the header will be removed from the set of 2649439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * headers to include in the next request. 2659439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param headerID the identifier to include in the message 2669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param headerValue the value of the header identifier 26705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * @throws IllegalArgumentException if the header identifier provided is not 26805ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * one defined in this interface or a user-defined header; if the 26905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * type of <code>headerValue</code> is not the correct Java type as 27005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * defined in the description of this interface\ 2719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 2729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public void setHeader(int headerID, Object headerValue) { 2739439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly long temp = -1; 2749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 2759439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly switch (headerID) { 2769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case COUNT: 2779439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof Long)) { 2789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 2793998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mCount = null; 2809439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 2819439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 2829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Count must be a Long"); 2839439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 2849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly temp = ((Long)headerValue).longValue(); 2859439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((temp < 0L) || (temp > 0xFFFFFFFFL)) { 2869439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Count must be between 0 and 0xFFFFFFFF"); 2879439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 2883998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mCount = (Long)headerValue; 2899439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 2909439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case NAME: 2919439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof String))) { 2929439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Name must be a String"); 2939439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 2948949bfb90c415629dbd0e30d25003fb3e0375fb5Hemant Gupta mEmptyName = false; 2953998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mName = (String)headerValue; 2969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 2979439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TYPE: 2989439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof String))) { 2999439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Type must be a String"); 3009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3013998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mType = (String)headerValue; 3029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3039439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case LENGTH: 3049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof Long)) { 3059439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3063998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mLength = null; 3079439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3099439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Length must be a Long"); 3109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3119439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly temp = ((Long)headerValue).longValue(); 3129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((temp < 0L) || (temp > 0xFFFFFFFFL)) { 3139439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Length must be between 0 and 0xFFFFFFFF"); 3149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3153998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mLength = (Long)headerValue; 3169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TIME_ISO_8601: 3189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof Calendar))) { 3199439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Time ISO 8601 must be a Calendar"); 3209439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3213998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mIsoTime = (Calendar)headerValue; 3229439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TIME_4_BYTE: 3249439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof Calendar))) { 3259439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Time 4 Byte must be a Calendar"); 3269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3273998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mByteTime = (Calendar)headerValue; 3289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3299439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case DESCRIPTION: 3309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof String))) { 3319439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Description must be a String"); 3329439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3333998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mDescription = (String)headerValue; 3349439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TARGET: 3369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3373998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mTarget = null; 3389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 3409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Target must be a byte array"); 3419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3423998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mTarget = new byte[((byte[])headerValue).length]; 3433998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mTarget, 0, mTarget.length); 3449439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3469439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case HTTP: 3489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3493998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mHttpHeader = null; 3509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 3529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("HTTP must be a byte array"); 3539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3543998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mHttpHeader = new byte[((byte[])headerValue).length]; 3553998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mHttpHeader, 0, mHttpHeader.length); 3569439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3599439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case WHO: 3609439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3613998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mWho = null; 3629439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 3649439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("WHO must be a byte array"); 3659439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3663998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mWho = new byte[((byte[])headerValue).length]; 3673998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mWho, 0, mWho.length); 3689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3699439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case OBJECT_CLASS: 3729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3733998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mObjectClass = null; 3749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3759439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 3769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Object Class must be a byte array"); 3779439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3783998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mObjectClass = new byte[((byte[])headerValue).length]; 3793998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mObjectClass, 0, mObjectClass.length); 3809439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3819439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3839439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case APPLICATION_PARAMETER: 3849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 3853998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mAppParam = null; 3869439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3879439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 3889439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException( 3899439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly "Application Parameter must be a byte array"); 3909439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 3913998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mAppParam = new byte[((byte[])headerValue).length]; 3923998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mAppParam, 0, mAppParam.length); 3939439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3949439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 3959439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 3969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly default: 3979439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a Unicode String user Defined 3989439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0x30) && (headerID <= 0x3F)) { 3999439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof String))) { 4009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException( 4019439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly "Unicode String User Defined must be a String"); 4029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4033998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mUnicodeUserDefined[headerID - 0x30] = (String)headerValue; 4049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 4059439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 4069439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4079439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a byte sequence user defined value 4089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0x70) && (headerID <= 0x7F)) { 4099439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 4109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 4113998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mSequenceUserDefined[headerID - 0x70] = null; 4129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 4139439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof byte[])) { 4149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException( 4159439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly "Byte Sequence User Defined must be a byte array"); 4169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 4173998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mSequenceUserDefined[headerID - 0x70] = new byte[((byte[])headerValue).length]; 4183998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun System.arraycopy(headerValue, 0, mSequenceUserDefined[headerID - 0x70], 4193998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun 0, mSequenceUserDefined[headerID - 0x70].length); 4209439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4219439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4229439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 4239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4249439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a Byte user Defined 4259439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0xB0) && (headerID <= 0xBF)) { 4269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerValue != null) && (!(headerValue instanceof Byte))) { 4279439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("ByteUser Defined must be a Byte"); 4289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4293998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mByteUserDefined[headerID - 0xB0] = (Byte)headerValue; 4309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 4319439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 4329439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4339439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that is was not the 4 byte unsigned integer user 4349439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // defined header 4359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0xF0) && (headerID <= 0xFF)) { 4369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (!(headerValue instanceof Long)) { 4379439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (headerValue == null) { 4383998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mIntegerUserDefined[headerID - 0xF0] = null; 4399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 4409439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Integer User Defined must be a Long"); 4429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4439439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly temp = ((Long)headerValue).longValue(); 4449439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((temp < 0L) || (temp > 0xFFFFFFFFL)) { 4459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException( 4469439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly "Integer User Defined must be between 0 and 0xFFFFFFFF"); 4479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4483998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun mIntegerUserDefined[headerID - 0xF0] = (Long)headerValue; 4499439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly break; 4509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Invalid Header Identifier"); 4529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 4549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 4559439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 45605ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Retrieves the value of the header identifier provided. The type of the 4579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Object returned is defined in the description of this interface. 4589439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param headerID the header identifier whose value is to be returned 4599439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @return the value of the header provided or <code>null</code> if the 46005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * header identifier specified is not part of this 46105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>HeaderSet</code> object 46205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * @throws IllegalArgumentException if the <code>headerID</code> is not one 46305ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * defined in this interface or any of the user-defined headers 4642e0da96e757a977154063f980d3f4e1abd41cf09Nick Pelly * @throws IOException if an error occurred in the transport layer during 46505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * the operation or if the connection has been closed 4669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 4679439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public Object getHeader(int headerID) throws IOException { 4689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 4699439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly switch (headerID) { 4709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case COUNT: 4713998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mCount; 4729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case NAME: 4733998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mName; 4749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TYPE: 4753998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mType; 4769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case LENGTH: 4773998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mLength; 4789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TIME_ISO_8601: 4793998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mIsoTime; 4809439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TIME_4_BYTE: 4813998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mByteTime; 4829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case DESCRIPTION: 4833998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mDescription; 4849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case TARGET: 4853998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mTarget; 4869439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case HTTP: 4873998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mHttpHeader; 4889439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case WHO: 4893998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mWho; 490fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie case CONNECTION_ID: 491fe3807a5b23f54f6539436d71aa0cd931a2b76f0Matthew Xie return mConnectionID; 4929439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case OBJECT_CLASS: 4933998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mObjectClass; 4949439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly case APPLICATION_PARAMETER: 4953998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mAppParam; 4969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly default: 4979439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a Unicode String user Defined 4989439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0x30) && (headerID <= 0x3F)) { 4993998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mUnicodeUserDefined[headerID - 0x30]; 5009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5019439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a byte sequence user defined header 5029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0x70) && (headerID <= 0x7F)) { 5033998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mSequenceUserDefined[headerID - 0x70]; 5049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5059439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Verify that it was not a byte user defined header 5069439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0xB0) && (headerID <= 0xBF)) { 5073998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mByteUserDefined[headerID - 0xB0]; 5089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5093998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun // Verify that it was not a integer user defined header 5109439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headerID >= 0xF0) && (headerID <= 0xFF)) { 5113998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun return mIntegerUserDefined[headerID - 0xF0]; 5129439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5139439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IllegalArgumentException("Invalid Header Identifier"); 5149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5159439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5169439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 5189439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * Retrieves the list of headers that may be retrieved via the 51905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>getHeader</code> method that will not return <code>null</code>. In 52005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * other words, this method returns all the headers that are available in 52105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * this object. 5229439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @see #getHeader 5239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @return the array of headers that are set in this object or 52405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>null</code> if no headers are available 5252e0da96e757a977154063f980d3f4e1abd41cf09Nick Pelly * @throws IOException if an error occurred in the transport layer during 52605ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * the operation or the connection has been closed 5279439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 5289439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public int[] getHeaderList() throws IOException { 5299439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly ByteArrayOutputStream out = new ByteArrayOutputStream(); 5309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5313998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mCount != null) { 5329439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(COUNT); 5339439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5343998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mName != null) { 5359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(NAME); 5369439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5373998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mType != null) { 5389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(TYPE); 5399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5403998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mLength != null) { 5419439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(LENGTH); 5429439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5433998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mIsoTime != null) { 5449439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(TIME_ISO_8601); 5459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5463998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mByteTime != null) { 5479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(TIME_4_BYTE); 5489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5493998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mDescription != null) { 5509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(DESCRIPTION); 5519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5523998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mTarget != null) { 5539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(TARGET); 5549439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5553998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mHttpHeader != null) { 5569439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(HTTP); 5579439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5583998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mWho != null) { 5599439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(WHO); 5609439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5613998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mAppParam != null) { 5629439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(APPLICATION_PARAMETER); 5639439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5643998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mObjectClass != null) { 5659439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(OBJECT_CLASS); 5669439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5679439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5689439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly for (int i = 0x30; i < 0x40; i++) { 5693998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mUnicodeUserDefined[i - 0x30] != null) { 5709439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(i); 5719439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5729439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5739439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5749439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly for (int i = 0x70; i < 0x80; i++) { 5753998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mSequenceUserDefined[i - 0x70] != null) { 5769439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(i); 5779439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5789439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5799439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5809439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly for (int i = 0xB0; i < 0xC0; i++) { 5813998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mByteUserDefined[i - 0xB0] != null) { 5829439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(i); 5839439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5849439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5859439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5869439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly for (int i = 0xF0; i < 0x100; i++) { 5873998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun if (mIntegerUserDefined[i - 0xF0] != null) { 5889439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.write(i); 5899439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5909439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5919439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5929439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly byte[] headers = out.toByteArray(); 5939439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly out.close(); 5949439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5959439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if ((headers == null) || (headers.length == 0)) { 5969439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly return null; 5979439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 5989439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 5999439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly int[] result = new int[headers.length]; 6009439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly for (int i = 0; i < headers.length; i++) { 6019439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // Convert the byte to a positive integer. That is, an integer 6029439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly // between 0 and 256. 6039439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly result[i] = headers[i] & 0xFF; 6049439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 6059439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 6069439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly return result; 6079439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 6089439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 6099439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 61005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Sets the authentication challenge header. The <code>realm</code> will be 61105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * encoded based upon the default encoding scheme used by the implementation 61205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * to encode strings. Therefore, the encoding scheme used to encode the 61305ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>realm</code> is application dependent. 6149439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param realm a short description that describes what password to use; if 61505ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>null</code> no realm will be sent in the authentication 61605ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * challenge header 6179439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param userID if <code>true</code>, a user ID is required in the reply; 61805ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * if <code>false</code>, no user ID is required 6199439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @param access if <code>true</code> then full access will be granted if 62005ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * successful; if <code>false</code> then read-only access will be 62105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * granted if successful 6223998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun * @throws IOException 6239439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 6243998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun public void createAuthenticationChallenge(String realm, boolean userID, boolean access) 6253998bf009acaf8cde4d7f837f8b8e41ae0a65141Tao Liejun throws IOException { 6269439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 62705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun nonce = new byte[16]; 62805ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun for (int i = 0; i < 16; i++) { 62905ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun nonce[i] = (byte)mRandom.nextInt(); 6309439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 63105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun 63205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun mAuthChall = ObexHelper.computeAuthenticationChallenge(nonce, realm, access, userID); 6339439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 6349439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly 6359439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly /** 63605ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * Returns the response code received from the server. Response codes are 63705ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * defined in the <code>ResponseCodes</code> class. 6389439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @see ResponseCodes 6399439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly * @return the response code retrieved from the server 6402e0da96e757a977154063f980d3f4e1abd41cf09Nick Pelly * @throws IOException if an error occurred in the transport layer during 64105ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * the transaction; if this method is called on a 64205ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>HeaderSet</code> object created by calling 64305ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * <code>createHeaderSet()</code> in a <code>ClientSession</code> 64405ff98bbefda39b9ff26f8bca132cfd0248745c6Tao Liejun * object; if this object was created by an OBEX server 6459439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly */ 6469439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly public int getResponseCode() throws IOException { 6479439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly if (responseCode == -1) { 6489439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly throw new IOException("May not be called on a server"); 6499439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } else { 6509439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly return responseCode; 6519439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 6529439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly } 6539439a7fe517b858bc5e5c654b459315e4722feb2Nick Pelly} 654