mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 22:28:36 +00:00
a312918fb4
- Bug 1143925 - Avoid crash for HFP/A2DP manager during restart daemon. r=tzimmermann (5cd0d4b4db) - Bug 1195608 - [cleanup] Fix too long lines and revise some comments under dom/bluetooth, r=joliu (44db9edaf8) - Bug 1181512 - Use a single GATT interface, result handler, and notification handler for both GATT client and server operations in bluetooth daemon backend as bluez ipc protocol. r=tzimmermann (d5c1ca04f4) - Bug 1168266 - Add few member functions of ObexHeaderSet for PBAP. r=shuang (113ef68a3f) - Bug 1166587 - Check OBEX packet length before accessing it, r=shuang (dc5ca707fa) - Bug 1180554 - Dispatch events to PBAP event handlers when the PBAP requests comes. r=btian, r=mrbkap (449900a161) - Bug 1180555 - Handle PBAP replies and pass the results through IPC to PbapManager. r=btian (976b4130f0) - Bug 1181480 - Add and implement GATT server connection related Web APIs. r=btian, r=mrbkap (996528346d) - Bug 1195729: Fix ref-counting of Bluetooth result handlers for failed send operations, r=brsun (b40f14f2c5) - Bug 1197877: Remove |CONVERT| macro from Bluetooth, r=btian (7c3cd72556) - Bug 1197877: Remove |INIT_AT| macro from Bluetooth, r=btian (fb1b03e313) - Bug 1187904: Add |DaemonSocketConnector|, r=shuang (8473e149fe) - Bug 1203092: Add |DaemonSocketResultHandler| base class to HAL IPC, r=shuang (41210e6f1f) - Bug 1175067 - Switch Bluetooth marionette test set to BT API v2 and disable unsupported tests. r=joliu (307eb1473c) - Bug 1193379 - Move ipc and tests folders out from dom/bluetooth/bluetooth2. r=joliu (38820c505c) - Bug 1155063 - Part 1: CallStateChanged accepts an array (idl). r=hsinyi (3ae1af7a7f) - Bug 1155063 - Part 2: CallStateChanged accepts an array (telephony dom). r=hsinyi (10063343dc) - Bug 1155063 - Part 3: CallStateChanged accepts an array (bluetooth dom). r=btian (20ef2893b4) - Bug 1155063 - Part 4: CallStateChanged accepts an array (ipc). r=hsinyi (790c583a05) - Bug 1155063 - Part 5: CallStateChanged accepts an array (ril). r=hsinyi (960ca6cd0a) - Bug 1193379 - Rename bluetooth2 folder to common. r=joliu (58e992c298) - Bug 1193379 - Move backend-neutral files into dom/bluetooth/common. r=joliu (f5769a803b) - Bug 1203092: Inherit Bluetooth result handlers from |DaemonSocketResultHandler|, r=shuang (cb874fc706) - Bug 1203092: Remove void pointers from Bluetooth's daemon backend, r=shuang (c78a0507c9) - Bug 1204801: Move |BluetoothDaemonSetupModule| into separate compilation unit, r=btian (a1ae28c948) - Bug 1204801: Use enum constants for Bluetooth Service module, r=btian (876e02a69a) - Bug 1204801: Move |BlutoothSetupResultHandler| to generic backend interface, r=btian (9f12ca6d21) - Bug 1199110: Add |BluetoothAvrcpManager| to Bluedroid and BlueZ backends, r=shuang (7a897a3436) - Bug 1205253: Move |BluetoothDaemonCoreModule| into separate compilation unit, r=btian (d443455b07) - Bug 1205253: Use enum constants for Bluetooth Core module, r=btian (2c69493ea8) - Bug 1204506: Set 'override' attribute for overloaded Bluetooth backend methods, r=btian (211bded054) - Bug 825149 - Add NREC feature bit in bluetooth stack. r=shuang (330103a1c0) - Bug 825149 - Support HFP NREC feature. r=shuang (25e988596c) - Bug 1192695 - Use pref instead of pre-defined C string as origin of bluetooth app. r=btian (06531c82d2) - Bug 1195604 - [cleanup] Integrate similar BluetoothResultHandlers into basic one, r=tzimmermann (b87aeaa8c7) - Bug 1199110: Use mPlayStatus to determine track selection, r=shuang (99f9eebb90) - Bug 1142417 - Truncate AVRCP meta data strings followed by BTRC_MAX_ATTR_STR_LEN. r=tzimmermann (2f586f70e8) - Bug 1142132: Move helper classes of A2DP manager into manager's namespace, r=shuang (12af5f6506) - Bug 1159267: Share Bluedroid's A2DP manager between Bluetooth v1 and v2, r=btian (caa7c3dc56) - missing part of Bug 1132229: Survive crashes of bluetoothd, r=shuang (708a6351be) - Bug 1199110: Remove AVRCP support from |BluetoothA2dpManager| and convert callers, r=shuang (284e2804f8) - CLOSED TREE Bug 1180556 - Pack PBAP replies to OBEX response message and reply to remote device. r=btian (7b02ab708d) - Bug 1199107 - Access PBAP vCard input stream directly instead of passing it as input parameter, r=shuang (a0fd942bc0) - Bug 1199107 - Replace BT_WARNING with BT_LOGR in PBAP manager, r=shuang (ccd44ba040) - Bug 1199548 - Do not append vCard Body payload in PBAP replies when |MaxListCount| is zero, r=shuang (2c1b8d2a52) - Bug 1200124 - Correct PBAP order mapping, r=shuang, r=mrbkap (f988c2276e) - Bug 1193379 - Create dom/bluetooth/common/webapi folder. r=joliu (889546481e) - Bug 1200124 - Pass order and search key with uint32_t instead of nsString to avoid string mismatch error, r=shuang (caf33a4d28) - Bug 1195685 - Transform macro |BT_APPEND_NAMED_VALUE| into function, r=shuang (6879f5624d) - Bug 1141616: Implement |BluetoothService::GetServiceChannel|, r=btian (98b9dd3821) - Bug 1206686: Use |BluetoothUuid| throughout Bluetooth backend interfaces, r=btian (cd4db645e0) - Bug 1205577: Use enum constants for Bluetooth Socket module, r=btian (53f3aedd33) - Bug 1127701 - Fix warning: NS_ENSURE_TRUE(value.isNumber()) failed, r=joliu (e83dc53c8c) - Bug 1203046 - Call |NRECNotification| once RFCOMM is connected. r=shuang (53cc91861e) - Bug 1166645 - Implement MAP profile manager connection related function, r=btian (e47ba31157) - Bug 1203023 - Do not call Reset() for BluetoothMapSmsManager, r=tzimmermann (22bb74f972) - fix misspatches (96dced2ce7) - Bug 1141616: Support SDP lookups in |BluetoothServiceBluedroid|, r=btian (09dd2e1a69) - Bug 1203819 - Fix loop condition in BluetoothPbapManager::PackPropertiesMask, r=shuang (c4fdb58f20) - Bug 1159267: Share Bluedroid's OPP manager between Bluetooth v1 and v2, r=btian (e72a3dd65b) - Bug 1141616: Lookup service channel in Bluedroid's OPP manager, r=btian (17b3cc0a65) - Bug 1166176 - [cleanup] Simplify volume related code in OPP manager, r=shuang (4730023336) - Bug 1191715 - Store local pointer of thread to shutdwon to avoid reentry crash, f=jesup, r=shuang (7d97509067) - Bug 1055434 - Do not inform gaia of current blob's sending failure before assigning it, r=shuang (66f268fda5) - missing bit of Bug 1164425 (59c5844590) - namespace (5e253af0c7)
245 lines
6.0 KiB
C++
245 lines
6.0 KiB
C++
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "DaemonSocketConnector.h"
|
|
#include <fcntl.h>
|
|
#include <limits.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <sys/un.h>
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
|
|
#include "prrng.h"
|
|
|
|
#ifdef CHROMIUM_LOG
|
|
#undef CHROMIUM_LOG
|
|
#endif
|
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
|
#include <android/log.h>
|
|
#define CHROMIUM_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "I/O", args);
|
|
#else
|
|
#include <stdio.h>
|
|
#define IODEBUG true
|
|
#define CHROMIUM_LOG(args...) if (IODEBUG) printf(args);
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace ipc {
|
|
|
|
nsresult
|
|
DaemonSocketConnector::CreateRandomAddressString(
|
|
const nsACString& aPrefix, unsigned long aPostfixLength,
|
|
nsACString& aAddress)
|
|
{
|
|
static const char sHexChar[16] = {
|
|
[0x0] = '0', [0x1] = '1', [0x2] = '2', [0x3] = '3',
|
|
[0x4] = '4', [0x5] = '5', [0x6] = '6', [0x7] = '7',
|
|
[0x8] = '8', [0x9] = '9', [0xa] = 'a', [0xb] = 'b',
|
|
[0xc] = 'c', [0xd] = 'd', [0xe] = 'e', [0xf] = 'f'
|
|
};
|
|
|
|
unsigned short seed[3];
|
|
|
|
if (NS_WARN_IF(!PR_GetRandomNoise(seed, sizeof(seed)))) {
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
}
|
|
|
|
aAddress = aPrefix;
|
|
aAddress.Append('-');
|
|
|
|
while (aPostfixLength) {
|
|
// Android doesn't provide rand_r, so we use nrand48 here,
|
|
// even though it's deprecated.
|
|
long value = nrand48(seed);
|
|
|
|
size_t bits = sizeof(value) * CHAR_BIT;
|
|
|
|
while ((bits > 4) && aPostfixLength) {
|
|
aAddress.Append(sHexChar[value&0xf]);
|
|
bits -= 4;
|
|
value >>= 4;
|
|
--aPostfixLength;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
DaemonSocketConnector::DaemonSocketConnector(const nsACString& aSocketName)
|
|
: mSocketName(aSocketName)
|
|
{
|
|
MOZ_COUNT_CTOR_INHERITED(DaemonSocketConnector, UnixSocketConnector);
|
|
}
|
|
|
|
DaemonSocketConnector::~DaemonSocketConnector()
|
|
{
|
|
MOZ_COUNT_CTOR_INHERITED(DaemonSocketConnector, UnixSocketConnector);
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::CreateSocket(int& aFd) const
|
|
{
|
|
aFd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
|
|
if (aFd < 0) {
|
|
CHROMIUM_LOG("Could not open daemon socket!");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::SetSocketFlags(int aFd) const
|
|
{
|
|
static const int sReuseAddress = 1;
|
|
|
|
// Set close-on-exec bit.
|
|
int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD));
|
|
if (flags < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
flags |= FD_CLOEXEC;
|
|
int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Set non-blocking status flag.
|
|
flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
|
|
if (flags < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
flags |= O_NONBLOCK;
|
|
res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Set socket addr to be reused even if kernel is still waiting to close.
|
|
res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress,
|
|
sizeof(sReuseAddress));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::CreateAddress(struct sockaddr& aAddress,
|
|
socklen_t& aAddressLength) const
|
|
{
|
|
static const size_t sNameOffset = 1;
|
|
|
|
struct sockaddr_un* address =
|
|
reinterpret_cast<struct sockaddr_un*>(&aAddress);
|
|
|
|
size_t namesiz = mSocketName.Length() + 1; // include trailing '\0'
|
|
|
|
if (NS_WARN_IF((sNameOffset + namesiz) > sizeof(address->sun_path))) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
address->sun_family = AF_UNIX;
|
|
memset(address->sun_path, '\0', sNameOffset); // abstract socket
|
|
memcpy(address->sun_path + sNameOffset, mSocketName.get(), namesiz);
|
|
|
|
aAddressLength =
|
|
offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// |UnixSocketConnector|
|
|
|
|
nsresult
|
|
DaemonSocketConnector::ConvertAddressToString(
|
|
const struct sockaddr& aAddress, socklen_t aAddressLength,
|
|
nsACString& aAddressString)
|
|
{
|
|
MOZ_ASSERT(aAddress.sa_family == AF_UNIX);
|
|
|
|
const struct sockaddr_un* un =
|
|
reinterpret_cast<const struct sockaddr_un*>(&aAddress);
|
|
|
|
size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path);
|
|
|
|
aAddressString.Assign(un->sun_path, len);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::CreateListenSocket(struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aListenFd)
|
|
{
|
|
ScopedClose fd;
|
|
|
|
nsresult rv = CreateSocket(fd.rwget());
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
rv = SetSocketFlags(fd);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
if (aAddress && aAddressLength) {
|
|
rv = CreateAddress(*aAddress, *aAddressLength);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
}
|
|
|
|
aListenFd = fd.forget();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::AcceptStreamSocket(int aListenFd,
|
|
struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aStreamFd)
|
|
{
|
|
ScopedClose fd(
|
|
TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength)));
|
|
if (fd < 0) {
|
|
CHROMIUM_LOG("Cannot accept file descriptor!");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
nsresult rv = SetSocketFlags(fd);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
aStreamFd = fd.forget();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::CreateStreamSocket(struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aStreamFd)
|
|
{
|
|
MOZ_CRASH("|DaemonSocketConnector| does not support "
|
|
"creating stream sockets.");
|
|
return NS_ERROR_ABORT;
|
|
}
|
|
|
|
nsresult
|
|
DaemonSocketConnector::Duplicate(UnixSocketConnector*& aConnector)
|
|
{
|
|
aConnector = new DaemonSocketConnector(*this);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
} // namespace ipc
|
|
} // namespace mozilla
|