From bf9fbe58e56ee5299e767e38d83215b574618475 Mon Sep 17 00:00:00 2001 From: Eric Chou Date: Wed, 16 Jan 2013 18:23:28 +0800 Subject: [PATCH] Bug 825762 - Replace VFAT reserved character with '_' to avoid file-transferring failure, r=qdot --- dom/bluetooth/BluetoothOppManager.cpp | 23 +++++++++++++++++++++++ dom/bluetooth/BluetoothOppManager.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/dom/bluetooth/BluetoothOppManager.cpp b/dom/bluetooth/BluetoothOppManager.cpp index f68dac9c0774..e54296cf7417 100644 --- a/dom/bluetooth/BluetoothOppManager.cpp +++ b/dom/bluetooth/BluetoothOppManager.cpp @@ -621,6 +621,28 @@ BluetoothOppManager::ExtractBlobHeaders() return true; } +bool +BluetoothOppManager::IsReservedChar(PRUnichar c) +{ + return (c < 0x0020 || + c == PRUnichar('?') || c == PRUnichar('|') || c == PRUnichar('<') || + c == PRUnichar('>') || c == PRUnichar('"') || c == PRUnichar(':') || + c == PRUnichar('/') || c == PRUnichar('*') || c == PRUnichar('\\')); +} + +void +BluetoothOppManager::ValidateFileName() +{ + int length = sFileName.Length(); + + for (int i = 0; i < length; ++i) { + // Replace reserved char of fat file system with '_' + if (IsReservedChar(sFileName.CharAt(i))) { + sFileName.Replace(i, 1, PRUnichar('_')); + } + } +} + void BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) { @@ -707,6 +729,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) mReceivedDataBufferOffset, &pktHeaders); ExtractPacketHeaders(pktHeaders); + ValidateFileName(); mReceivedDataBufferOffset = 0; diff --git a/dom/bluetooth/BluetoothOppManager.h b/dom/bluetooth/BluetoothOppManager.h index 2654009059fd..b22c39287e5d 100644 --- a/dom/bluetooth/BluetoothOppManager.h +++ b/dom/bluetooth/BluetoothOppManager.h @@ -87,6 +87,9 @@ private: void AfterOppConnected(); void AfterFirstPut(); void AfterOppDisconnected(); + void ValidateFileName(); + bool IsReservedChar(PRUnichar c); + virtual void OnConnectSuccess() MOZ_OVERRIDE; virtual void OnConnectError() MOZ_OVERRIDE; virtual void OnDisconnect() MOZ_OVERRIDE;