зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1159179 - Patch 1/3: [PBAP] Add OBEX related functions, r=shuang
This commit is contained in:
Родитель
3857c89951
Коммит
a482aeaa6d
|
@ -8,36 +8,81 @@
|
|||
|
||||
BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
//
|
||||
// Internal functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Append byte array and length to header
|
||||
*/
|
||||
int
|
||||
AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const char* aName,
|
||||
int aLength)
|
||||
AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aBufferSize,
|
||||
const uint8_t* aData, int aLength)
|
||||
{
|
||||
int headerLength = aLength + 3;
|
||||
|
||||
aRetBuf[0] = ObexHeaderId::Name;
|
||||
aRetBuf[0] = aHeaderId;
|
||||
aRetBuf[1] = (headerLength & 0xFF00) >> 8;
|
||||
aRetBuf[2] = headerLength & 0x00FF;
|
||||
|
||||
memcpy(&aRetBuf[3], aName, (aLength < aBufferSize - 3)? aLength
|
||||
: aBufferSize - 3);
|
||||
memcpy(&aRetBuf[3], aData, (aLength < aBufferSize - 3) ? aLength
|
||||
: aBufferSize - 3);
|
||||
|
||||
return headerLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append 4-byte integer to header
|
||||
*/
|
||||
int
|
||||
AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aData,
|
||||
AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aValue)
|
||||
{
|
||||
aRetBuf[0] = aHeaderId;
|
||||
aRetBuf[1] = (aValue & 0xFF000000) >> 24;
|
||||
aRetBuf[2] = (aValue & 0x00FF0000) >> 16;
|
||||
aRetBuf[3] = (aValue & 0x0000FF00) >> 8;
|
||||
aRetBuf[4] = aValue & 0x000000FF;
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
//
|
||||
// Exposed functions
|
||||
//
|
||||
|
||||
int
|
||||
AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
|
||||
int aLength)
|
||||
{
|
||||
int headerLength = aLength + 3;
|
||||
return AppendHeader(ObexHeaderId::Name, aRetBuf, aBufferSize,
|
||||
aName, aLength);
|
||||
}
|
||||
|
||||
aRetBuf[0] = ObexHeaderId::Body;
|
||||
aRetBuf[1] = (headerLength & 0xFF00) >> 8;
|
||||
aRetBuf[2] = headerLength & 0x00FF;
|
||||
int
|
||||
AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
|
||||
int aLength)
|
||||
{
|
||||
return AppendHeader(ObexHeaderId::Body, aRetBuf, aBufferSize,
|
||||
aBody, aLength);
|
||||
}
|
||||
|
||||
memcpy(&aRetBuf[3], aData, (aLength < aBufferSize - 3)? aLength
|
||||
: aBufferSize - 3);
|
||||
int
|
||||
AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
|
||||
int aLength)
|
||||
{
|
||||
return AppendHeader(ObexHeaderId::Who, aRetBuf, aBufferSize,
|
||||
aWho, aLength);
|
||||
}
|
||||
|
||||
return headerLength;
|
||||
int
|
||||
AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength)
|
||||
{
|
||||
return AppendHeader(ObexHeaderId::Length, aRetBuf, aObjectLength);
|
||||
}
|
||||
|
||||
int
|
||||
AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId)
|
||||
{
|
||||
return AppendHeader(ObexHeaderId::ConnectionId, aRetBuf, aConnectionId);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -50,30 +95,6 @@ AppendHeaderEndOfBody(uint8_t* aRetBuf)
|
|||
return 3;
|
||||
}
|
||||
|
||||
int
|
||||
AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength)
|
||||
{
|
||||
aRetBuf[0] = ObexHeaderId::Length;
|
||||
aRetBuf[1] = (aObjectLength & 0xFF000000) >> 24;
|
||||
aRetBuf[2] = (aObjectLength & 0x00FF0000) >> 16;
|
||||
aRetBuf[3] = (aObjectLength & 0x0000FF00) >> 8;
|
||||
aRetBuf[4] = aObjectLength & 0x000000FF;
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
int
|
||||
AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId)
|
||||
{
|
||||
aRetBuf[0] = ObexHeaderId::ConnectionId;
|
||||
aRetBuf[1] = (aConnectionId & 0xFF000000) >> 24;
|
||||
aRetBuf[2] = (aConnectionId & 0x00FF0000) >> 16;
|
||||
aRetBuf[3] = (aConnectionId & 0x0000FF00) >> 8;
|
||||
aRetBuf[4] = aConnectionId & 0x000000FF;
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
void
|
||||
SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength)
|
||||
{
|
||||
|
@ -119,7 +140,7 @@ ParseHeaders(const uint8_t* aHeaderStart,
|
|||
break;
|
||||
}
|
||||
|
||||
// Length check to prevent from memory pollusion.
|
||||
// Length check to prevent from memory pollution.
|
||||
if (ptr + contentLength > aHeaderStart + aTotalLength) {
|
||||
// Severe error occurred. We can't even believe the received data, so
|
||||
// clear all headers.
|
||||
|
|
|
@ -199,24 +199,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void GetBodyLength(int* aRetBodyLength) const
|
||||
{
|
||||
int length = mHeaders.Length();
|
||||
*aRetBodyLength = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (mHeaders[i]->mId == ObexHeaderId::Body ||
|
||||
mHeaders[i]->mId == ObexHeaderId::EndOfBody) {
|
||||
*aRetBodyLength = mHeaders[i]->mDataLength;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetBody(uint8_t** aRetBody) const
|
||||
void GetBody(uint8_t** aRetBody, int* aRetBodyLength) const
|
||||
{
|
||||
int length = mHeaders.Length();
|
||||
*aRetBody = nullptr;
|
||||
*aRetBodyLength = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (mHeaders[i]->mId == ObexHeaderId::Body ||
|
||||
|
@ -224,6 +211,24 @@ public:
|
|||
uint8_t* ptr = mHeaders[i]->mData.get();
|
||||
*aRetBody = new uint8_t[mHeaders[i]->mDataLength];
|
||||
memcpy(*aRetBody, ptr, mHeaders[i]->mDataLength);
|
||||
*aRetBodyLength = mHeaders[i]->mDataLength;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetTarget(uint8_t** aRetTarget, int* aRetTargetLength) const
|
||||
{
|
||||
int length = mHeaders.Length();
|
||||
*aRetTarget = nullptr;
|
||||
*aRetTargetLength = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (mHeaders[i]->mId == ObexHeaderId::Target) {
|
||||
uint8_t* ptr = mHeaders[i]->mData.get();
|
||||
*aRetTarget = new uint8_t[mHeaders[i]->mDataLength];
|
||||
memcpy(*aRetTarget, ptr, mHeaders[i]->mDataLength);
|
||||
*aRetTargetLength = mHeaders[i]->mDataLength;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -251,13 +256,15 @@ private:
|
|||
nsTArray<nsAutoPtr<ObexHeader> > mHeaders;
|
||||
};
|
||||
|
||||
int AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const char* aName,
|
||||
int AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
|
||||
int aLength);
|
||||
int AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aData,
|
||||
int AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
|
||||
int aLength);
|
||||
int AppendHeaderEndOfBody(uint8_t* aRetBuf);
|
||||
int AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
|
||||
int aLength);
|
||||
int AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength);
|
||||
int AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId);
|
||||
int AppendHeaderEndOfBody(uint8_t* aRetBuf);
|
||||
void SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength);
|
||||
|
||||
/**
|
||||
|
|
|
@ -742,10 +742,8 @@ BluetoothOppManager::ExtractPacketHeaders(const ObexHeaderSet& aHeader)
|
|||
if (aHeader.Has(ObexHeaderId::Body) ||
|
||||
aHeader.Has(ObexHeaderId::EndOfBody)) {
|
||||
uint8_t* bodyPtr;
|
||||
aHeader.GetBody(&bodyPtr);
|
||||
aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
|
||||
mBodySegment = bodyPtr;
|
||||
|
||||
aHeader.GetBodyLength(&mBodySegmentLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1203,7 +1201,7 @@ BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
|
|||
|
||||
int index = 3;
|
||||
index += AppendHeaderName(&req[index], mRemoteMaxPacketLength - index,
|
||||
(char*)fileName, (len + 1) * 2);
|
||||
fileName, (len + 1) * 2);
|
||||
index += AppendHeaderLength(&req[index], aFileSize);
|
||||
|
||||
// This is final put packet if file size equals to 0
|
||||
|
|
|
@ -714,10 +714,8 @@ BluetoothOppManager::ExtractPacketHeaders(const ObexHeaderSet& aHeader)
|
|||
if (aHeader.Has(ObexHeaderId::Body) ||
|
||||
aHeader.Has(ObexHeaderId::EndOfBody)) {
|
||||
uint8_t* bodyPtr;
|
||||
aHeader.GetBody(&bodyPtr);
|
||||
aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
|
||||
mBodySegment = bodyPtr;
|
||||
|
||||
aHeader.GetBodyLength(&mBodySegmentLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1170,7 +1168,7 @@ BluetoothOppManager::SendPutHeaderRequest(const nsAString& aFileName,
|
|||
|
||||
int index = 3;
|
||||
index += AppendHeaderName(&req[index], mRemoteMaxPacketLength - index,
|
||||
(char*)fileName, (len + 1) * 2);
|
||||
fileName, (len + 1) * 2);
|
||||
index += AppendHeaderLength(&req[index], aFileSize);
|
||||
|
||||
// This is final put packet if file size equals to 0
|
||||
|
|
Загрузка…
Ссылка в новой задаче