Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#13 OBEX incorrectly handling non-default connection ID

open
nobody
None
5
2005-11-16
2005-11-16
Bob Krause
No

The current implementaiton doesn't properly handle
non-default (!= -1) connection ID values in CONNECTION,
PUT and GET operations. The problem can be resolved by
creating a consistent handling of connectionIDs on both
the client and server sides. The following changes are
necessary correct this problem...

The handling of CONNECTs in
SessionNotifierImpl.startWaiting.run() should include
the following...

case 0x80: {
int offset;
long conID;
if (data[3] == (byte)HeaderSetImpl.CONNECTION_ID) {
conID = ((data[4] & 0xFF) << 24) + ((data[5] & 0xFF)
<< 16) + ((data[6] & 0xFF) << 8) + (data[7] & 0xFF);
offset = 10;
}
else {
conID = -1;
offset = 5;
}
mtu = 0xffff & ((0xff & data[offset]) << 8 | (0xff &
data[offset + 1]));
HeaderSet request = OBEXConnection.parseHeaders(data,
offset + 2);
if (conID != -1)
myHandler.setConnectionID(conID);
HeaderSet response = myHandler.createHeaderSet();
boolean success = handleAuthResponse(request);
handleAuthChallenge(request, response);
int ret = myHandler.onConnect( request, response);
response.setHeader(HeaderSetImpl.CONNECTION_ID, new
Long(myHandler.getConnectionID()));
...

The code, in the same file, that handles PUT ops should
include the following...

case 0x02:
case 0x82: {
HeaderSet request = OBEXConnection.parseHeaders(data, 3);
HeaderSet response = myHandler.createHeaderSet();
handleAuthResponse(request);
handleAuthChallenge(request, response);
if (m_putOperation == null) {
if (request.getHeader(HeaderSetImpl.CONNECTION_ID)
!= null)
myHandler.setConnectionID(((Long)
request.getHeader(HeaderSetImpl.CONNECTION_ID)).longValue());
m_putOperation = new OperationImpl
(SessionNotifierImpl.this, request, OBEXConnection.PUT);
}
...

The code, in the same file, that handles GET ops should
include the following...

case 0x83:
case 0x03:
{
HeaderSet request = OBEXConnection.parseHeaders(data, 3);
HeaderSet response = null;

int ret = 0xa0;
if (m_getOperation == null) {
m_getOperation = new OperationImpl
(SessionNotifierImpl.this, request, OBEXConnection.GET);
if (request.getHeader(HeaderSetImpl.CONNECTION_ID)
!= null)
myHandler.setConnectionID(((Long)
request.getHeader(HeaderSetImpl.CONNECTION_ID)).longValue());
response =
((OperationImpl)m_getOperation).getHeadersToSend();
handleAuthResponse(request);
handleAuthChallenge(request, response);
...

The implementation of OBEXConnection.hsToByteArray()
also needs to be updated. This method should begin with
the following...

static protected byte[] hsToByteArray (HeaderSet hs) {
if (hs == null) return new byte[0];
ByteArrayOutputStream bos = new ByteArrayOutputStream();

Long cid = (Long)
hs.getHeader(HeaderSetImpl.CONNECTION_ID);
if (cid != null) {
bos.write (HeaderSetImpl.CONNECTION_ID);
writeLen (bos, cid.longValue());
}

int[] hids = new int[0];
try {
hids = hs.getHeaderList();
} catch (IOException e1) {
}
int has48header = -1;

for (int i = 0;i < hids.length + (has48header != -1 ?
1 : 0);i++) {
Object header = null;
if (i == hids.length) { header = hs.getHeader
(hids[has48header]); i = has48header; }
else if (hids[i] == HeaderSetImpl.CONNECTION_ID)
continue;
else if (hids[i] == 0x48 || hids[i] == 0x49) {
has48header = i; continue; }
else header = hs.getHeader(hids[i]);

Discussion