2010-04-09 06:26:36 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-04-09 06:26:36 +00:00
|
|
|
|
|
|
|
#ifndef mozilla_net_NeckoMessageUtils_h
|
|
|
|
#define mozilla_net_NeckoMessageUtils_h
|
|
|
|
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-08-28 12:41:04 +00:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2010-04-09 06:26:36 +00:00
|
|
|
#include "nsStringGlue.h"
|
2011-05-05 15:45:59 +00:00
|
|
|
#include "prio.h"
|
2012-12-23 21:08:43 +00:00
|
|
|
#include "mozilla/net/DNS.h"
|
2010-04-09 06:26:36 +00:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
2010-10-09 18:07:38 +00:00
|
|
|
// nsIPermissionManager utilities
|
|
|
|
|
|
|
|
struct Permission
|
|
|
|
{
|
|
|
|
nsCString host, type;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t capability, expireType;
|
|
|
|
int64_t expireTime;
|
2012-08-23 18:38:01 +00:00
|
|
|
uint32_t appId;
|
|
|
|
bool isInBrowserElement;
|
2010-10-09 18:07:38 +00:00
|
|
|
|
|
|
|
Permission() { }
|
|
|
|
Permission(const nsCString& aHost,
|
2012-08-23 18:38:01 +00:00
|
|
|
const uint32_t aAppId,
|
|
|
|
const bool aIsInBrowserElement,
|
2010-10-09 18:07:38 +00:00
|
|
|
const nsCString& aType,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t aCapability,
|
|
|
|
const uint32_t aExpireType,
|
|
|
|
const int64_t aExpireTime) : host(aHost),
|
2010-10-09 18:07:38 +00:00
|
|
|
type(aType),
|
|
|
|
capability(aCapability),
|
|
|
|
expireType(aExpireType),
|
2012-08-23 18:38:01 +00:00
|
|
|
expireTime(aExpireTime),
|
|
|
|
appId(aAppId),
|
|
|
|
isInBrowserElement(aIsInBrowserElement)
|
|
|
|
{}
|
2010-10-09 18:07:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<Permission>
|
|
|
|
{
|
|
|
|
static void Write(Message* aMsg, const Permission& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.host);
|
|
|
|
WriteParam(aMsg, aParam.type);
|
|
|
|
WriteParam(aMsg, aParam.capability);
|
|
|
|
WriteParam(aMsg, aParam.expireType);
|
|
|
|
WriteParam(aMsg, aParam.expireTime);
|
2012-08-23 18:38:01 +00:00
|
|
|
WriteParam(aMsg, aParam.appId);
|
|
|
|
WriteParam(aMsg, aParam.isInBrowserElement);
|
2010-10-09 18:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, Permission* aResult)
|
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->host) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->type) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->capability) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->expireType) &&
|
2012-08-23 18:38:01 +00:00
|
|
|
ReadParam(aMsg, aIter, &aResult->expireTime) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->appId) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->isInBrowserElement);
|
2010-10-09 18:07:38 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 18:38:01 +00:00
|
|
|
static void Log(const Permission& p, std::wstring* l)
|
2010-10-09 18:07:38 +00:00
|
|
|
{
|
2012-08-23 18:38:01 +00:00
|
|
|
l->append(L"(");
|
|
|
|
LogParam(p.host, l);
|
|
|
|
l->append(L", ");
|
|
|
|
LogParam(p.appId, l);
|
|
|
|
l->append(L", ");
|
|
|
|
LogParam(p.isInBrowserElement, l);
|
|
|
|
l->append(L", ");
|
|
|
|
LogParam(p.capability, l);
|
|
|
|
l->append(L", ");
|
|
|
|
LogParam(p.expireTime, l);
|
|
|
|
l->append(L", ");
|
|
|
|
LogParam(p.expireType, l);
|
|
|
|
l->append(L")");
|
2010-10-09 18:07:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-05 15:45:59 +00:00
|
|
|
template<>
|
2012-12-23 21:08:43 +00:00
|
|
|
struct ParamTraits<mozilla::net::NetAddr>
|
2011-05-05 15:45:59 +00:00
|
|
|
{
|
2012-12-23 21:08:43 +00:00
|
|
|
static void Write(Message* aMsg, const mozilla::net::NetAddr &aParam)
|
2011-05-05 15:45:59 +00:00
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.raw.family);
|
2012-12-23 21:08:43 +00:00
|
|
|
if (aParam.raw.family == AF_UNSPEC) {
|
2011-05-05 15:45:59 +00:00
|
|
|
aMsg->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aParam.raw.family == AF_INET) {
|
2011-05-05 15:45:59 +00:00
|
|
|
WriteParam(aMsg, aParam.inet.port);
|
|
|
|
WriteParam(aMsg, aParam.inet.ip);
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aParam.raw.family == AF_INET6) {
|
|
|
|
WriteParam(aMsg, aParam.inet6.port);
|
|
|
|
WriteParam(aMsg, aParam.inet6.flowinfo);
|
|
|
|
WriteParam(aMsg, aParam.inet6.ip.u64[0]);
|
|
|
|
WriteParam(aMsg, aParam.inet6.ip.u64[1]);
|
|
|
|
WriteParam(aMsg, aParam.inet6.scope_id);
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_UNIX)
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aParam.raw.family == AF_LOCAL) {
|
2011-06-09 21:02:09 +00:00
|
|
|
// Train's already off the rails: let's get a stack trace at least...
|
|
|
|
NS_RUNTIMEABORT("Error: please post stack trace to "
|
|
|
|
"https://bugzilla.mozilla.org/show_bug.cgi?id=661158");
|
2011-05-05 15:45:59 +00:00
|
|
|
aMsg->WriteBytes(aParam.local.path, sizeof(aParam.local.path));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here without hitting any of the cases above, there's not much
|
|
|
|
* we can do but let the deserializer fail when it gets this message */
|
|
|
|
}
|
|
|
|
|
2012-12-23 21:08:43 +00:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, mozilla::net::NetAddr* aResult)
|
2011-05-05 15:45:59 +00:00
|
|
|
{
|
|
|
|
if (!ReadParam(aMsg, aIter, &aResult->raw.family))
|
|
|
|
return false;
|
|
|
|
|
2012-12-23 21:08:43 +00:00
|
|
|
if (aResult->raw.family == AF_UNSPEC) {
|
2011-05-05 15:45:59 +00:00
|
|
|
return aMsg->ReadBytes(aIter,
|
|
|
|
reinterpret_cast<const char**>(&aResult->raw.data),
|
|
|
|
sizeof(aResult->raw.data));
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aResult->raw.family == AF_INET) {
|
2011-05-05 15:45:59 +00:00
|
|
|
return ReadParam(aMsg, aIter, &aResult->inet.port) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet.ip);
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aResult->raw.family == AF_INET6) {
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->inet6.port) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet6.flowinfo) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[0]) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[1]) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet6.scope_id);
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_UNIX)
|
2012-12-23 21:08:43 +00:00
|
|
|
} else if (aResult->raw.family == AF_LOCAL) {
|
2011-05-05 15:45:59 +00:00
|
|
|
return aMsg->ReadBytes(aIter,
|
|
|
|
reinterpret_cast<const char**>(&aResult->local.path),
|
|
|
|
sizeof(aResult->local.path));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We've been tricked by some socket family we don't know about! */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-09 06:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // mozilla_net_NeckoMessageUtils_h
|