Bug 1199107 - Access PBAP vCard input stream directly instead of passing it as input parameter, r=shuang

This commit is contained in:
Ben Tian 2015-09-04 12:04:37 +08:00
parent a59f3de257
commit 0ad960e49f
2 changed files with 15 additions and 17 deletions

View File

@ -282,7 +282,7 @@ BluetoothPbapManager::ReceiveSocketData(BluetoothSocket* aSocket,
// final body information (in an End-of-Body header) arrives, along with
// the response code 0xA0 Success.
if (mVCardDataStream) {
if (!ReplyToGet(mVCardDataStream)) {
if (!ReplyToGet()) {
BT_WARNING("Failed to reply to PBAP GET request.");
ReplyError(ObexResponseCode::InternalServerError);
}
@ -819,12 +819,12 @@ BluetoothPbapManager::ReplyToPullPhonebook(Blob* aBlob, uint16_t aPhonebookSize)
return false;
}
if (!GetInputStreamFromBlob(mVCardDataStream, aBlob)) {
if (!GetInputStreamFromBlob(aBlob)) {
ReplyError(ObexResponseCode::InternalServerError);
return false;
}
return ReplyToGet(mVCardDataStream, aPhonebookSize);
return ReplyToGet(aPhonebookSize);
}
bool
@ -845,12 +845,12 @@ BluetoothPbapManager::ReplyToPullvCardListing(Blob* aBlob,
return false;
}
if (!GetInputStreamFromBlob(mVCardDataStream, aBlob)) {
if (!GetInputStreamFromBlob(aBlob)) {
ReplyError(ObexResponseCode::InternalServerError);
return false;
}
return ReplyToGet(mVCardDataStream, aPhonebookSize);
return ReplyToGet(aPhonebookSize);
}
bool
@ -869,19 +869,18 @@ BluetoothPbapManager::ReplyToPullvCardEntry(Blob* aBlob)
return false;
}
if (!GetInputStreamFromBlob(mVCardDataStream, aBlob)) {
if (!GetInputStreamFromBlob(aBlob)) {
ReplyError(ObexResponseCode::InternalServerError);
return false;
}
return ReplyToGet(mVCardDataStream);
return ReplyToGet();
}
bool
BluetoothPbapManager::ReplyToGet(nsIInputStream* aStream,
uint16_t aPhonebookSize)
BluetoothPbapManager::ReplyToGet(uint16_t aPhonebookSize)
{
MOZ_ASSERT(aStream);
MOZ_ASSERT(mVCardDataStream);
MOZ_ASSERT(mRemoteMaxPacketLength >= kObexLeastMaxSize);
// This response will be composed by these four parts.
@ -928,7 +927,7 @@ BluetoothPbapManager::ReplyToGet(nsIInputStream* aStream,
// Read vCard data from input stream
uint32_t numRead = 0;
nsAutoArrayPtr<char> buffer(new char[remainingPacketSize]);
nsresult rv = aStream->Read(buffer, remainingPacketSize, &numRead);
nsresult rv = mVCardDataStream->Read(buffer, remainingPacketSize, &numRead);
if (NS_FAILED(rv)) {
BT_WARNING("Failed to read from input stream.");
return false;
@ -951,8 +950,8 @@ BluetoothPbapManager::ReplyToGet(nsIInputStream* aStream,
opcode = ObexResponseCode::Success;
index += AppendHeaderEndOfBody(&res[index]);
aStream->Close();
aStream = nullptr;
mVCardDataStream->Close();
mVCardDataStream = nullptr;
}
SendObexData(res, opcode, index);
@ -962,8 +961,7 @@ BluetoothPbapManager::ReplyToGet(nsIInputStream* aStream,
}
bool
BluetoothPbapManager::GetInputStreamFromBlob(nsIInputStream* aStream,
Blob* aBlob)
BluetoothPbapManager::GetInputStreamFromBlob(Blob* aBlob)
{
// PBAP can only handle one OBEX BODY transfer at the same time.
if (mVCardDataStream) {

View File

@ -143,8 +143,7 @@ private:
void ReplyToSetPath();
void ReplyError(uint8_t aError);
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
bool ReplyToGet(nsIInputStream* aStream, uint16_t aPhonebookSize = 0);
bool GetInputStreamFromBlob(nsIInputStream* aStream, Blob* aBlob);
bool ReplyToGet(uint16_t aPhonebookSize = 0);
uint8_t SetPhoneBookPath(uint8_t flags, const ObexHeaderSet& aHeader);
uint8_t PullPhonebook(const ObexHeaderSet& aHeader);
@ -158,6 +157,7 @@ private:
InfallibleTArray<uint32_t> PackPropertiesMask(uint8_t* aData, int aSize);
bool CompareHeaderTarget(const ObexHeaderSet& aHeader);
bool IsLegalPath(const nsAString& aPath);
bool GetInputStreamFromBlob(Blob* aBlob);
void AfterPbapConnected();
void AfterPbapDisconnected();