2010-04-09 10:26:36 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 10:26:36 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_net_NeckoMessageUtils_h
|
|
|
|
#define mozilla_net_NeckoMessageUtils_h
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-08-28 16:41:04 +04:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2010-04-09 10:26:36 +04:00
|
|
|
#include "nsStringGlue.h"
|
2011-05-05 19:45:59 +04:00
|
|
|
#include "prio.h"
|
2012-12-24 01:08:43 +04:00
|
|
|
#include "mozilla/net/DNS.h"
|
2014-10-06 13:31:29 +04:00
|
|
|
#include "TimingStruct.h"
|
2010-04-09 10:26:36 +04:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
// nsIPermissionManager utilities
|
|
|
|
|
|
|
|
struct Permission
|
|
|
|
{
|
2015-06-10 19:48:22 +03:00
|
|
|
nsCString origin, type;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t capability, expireType;
|
|
|
|
int64_t expireTime;
|
2010-10-09 22:07:38 +04:00
|
|
|
|
|
|
|
Permission() { }
|
2015-06-10 19:48:22 +03:00
|
|
|
Permission(const nsCString& aOrigin,
|
2010-10-09 22:07:38 +04:00
|
|
|
const nsCString& aType,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t aCapability,
|
|
|
|
const uint32_t aExpireType,
|
2015-06-10 19:48:22 +03:00
|
|
|
const int64_t aExpireTime) : origin(aOrigin),
|
2010-10-09 22:07:38 +04:00
|
|
|
type(aType),
|
|
|
|
capability(aCapability),
|
|
|
|
expireType(aExpireType),
|
2015-06-10 19:48:22 +03:00
|
|
|
expireTime(aExpireTime)
|
2012-08-23 22:38:01 +04:00
|
|
|
{}
|
2010-10-09 22:07:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<Permission>
|
|
|
|
{
|
|
|
|
static void Write(Message* aMsg, const Permission& aParam)
|
|
|
|
{
|
2015-06-10 19:48:22 +03:00
|
|
|
WriteParam(aMsg, aParam.origin);
|
2010-10-09 22:07:38 +04:00
|
|
|
WriteParam(aMsg, aParam.type);
|
|
|
|
WriteParam(aMsg, aParam.capability);
|
|
|
|
WriteParam(aMsg, aParam.expireType);
|
|
|
|
WriteParam(aMsg, aParam.expireTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, Permission* aResult)
|
|
|
|
{
|
2015-06-10 19:48:22 +03:00
|
|
|
return ReadParam(aMsg, aIter, &aResult->origin) &&
|
2010-10-09 22:07:38 +04:00
|
|
|
ReadParam(aMsg, aIter, &aResult->type) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->capability) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->expireType) &&
|
2015-06-10 19:48:22 +03:00
|
|
|
ReadParam(aMsg, aIter, &aResult->expireTime);
|
2010-10-09 22:07:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-23 22:38:01 +04:00
|
|
|
static void Log(const Permission& p, std::wstring* l)
|
2010-10-09 22:07:38 +04:00
|
|
|
{
|
2012-08-23 22:38:01 +04:00
|
|
|
l->append(L"(");
|
2015-06-10 19:48:22 +03:00
|
|
|
LogParam(p.origin, l);
|
2012-08-23 22:38:01 +04:00
|
|
|
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 22:07:38 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-05 19:45:59 +04:00
|
|
|
template<>
|
2012-12-24 01:08:43 +04:00
|
|
|
struct ParamTraits<mozilla::net::NetAddr>
|
2011-05-05 19:45:59 +04:00
|
|
|
{
|
2012-12-24 01:08:43 +04:00
|
|
|
static void Write(Message* aMsg, const mozilla::net::NetAddr &aParam)
|
2011-05-05 19:45:59 +04:00
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.raw.family);
|
2012-12-24 01:08:43 +04:00
|
|
|
if (aParam.raw.family == AF_UNSPEC) {
|
2011-05-05 19:45:59 +04:00
|
|
|
aMsg->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
|
2012-12-24 01:08:43 +04:00
|
|
|
} else if (aParam.raw.family == AF_INET) {
|
2011-05-05 19:45:59 +04:00
|
|
|
WriteParam(aMsg, aParam.inet.port);
|
|
|
|
WriteParam(aMsg, aParam.inet.ip);
|
2012-12-24 01:08:43 +04: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-11 02:57:01 +04:00
|
|
|
#if defined(XP_UNIX)
|
2012-12-24 01:08:43 +04:00
|
|
|
} else if (aParam.raw.family == AF_LOCAL) {
|
2011-06-10 01:02:09 +04: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 19:45:59 +04: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-24 01:08:43 +04:00
|
|
|
static bool Read(const Message* aMsg, void** aIter, mozilla::net::NetAddr* aResult)
|
2011-05-05 19:45:59 +04:00
|
|
|
{
|
|
|
|
if (!ReadParam(aMsg, aIter, &aResult->raw.family))
|
|
|
|
return false;
|
|
|
|
|
2012-12-24 01:08:43 +04:00
|
|
|
if (aResult->raw.family == AF_UNSPEC) {
|
2016-02-01 21:03:24 +03:00
|
|
|
const char *tmp;
|
|
|
|
if (aMsg->ReadBytes(aIter, &tmp, sizeof(aResult->raw.data))) {
|
|
|
|
memcpy(&(aResult->raw.data), tmp, sizeof(aResult->raw.data));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-12-24 01:08:43 +04:00
|
|
|
} else if (aResult->raw.family == AF_INET) {
|
2011-05-05 19:45:59 +04:00
|
|
|
return ReadParam(aMsg, aIter, &aResult->inet.port) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->inet.ip);
|
2012-12-24 01:08:43 +04: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-11 02:57:01 +04:00
|
|
|
#if defined(XP_UNIX)
|
2012-12-24 01:08:43 +04:00
|
|
|
} else if (aResult->raw.family == AF_LOCAL) {
|
2016-02-01 21:03:24 +03:00
|
|
|
const char *tmp;
|
|
|
|
if (aMsg->ReadBytes(aIter, &tmp, sizeof(aResult->local.path))) {
|
|
|
|
memcpy(&(aResult->local.path), tmp, sizeof(aResult->local.path));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2011-05-05 19:45:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We've been tricked by some socket family we don't know about! */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-06 13:31:29 +04:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<mozilla::net::ResourceTimingStruct>
|
|
|
|
{
|
|
|
|
static void Write(Message* aMsg, const mozilla::net::ResourceTimingStruct& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.domainLookupStart);
|
|
|
|
WriteParam(aMsg, aParam.domainLookupEnd);
|
|
|
|
WriteParam(aMsg, aParam.connectStart);
|
|
|
|
WriteParam(aMsg, aParam.connectEnd);
|
|
|
|
WriteParam(aMsg, aParam.requestStart);
|
|
|
|
WriteParam(aMsg, aParam.responseStart);
|
|
|
|
WriteParam(aMsg, aParam.responseEnd);
|
|
|
|
|
|
|
|
WriteParam(aMsg, aParam.fetchStart);
|
|
|
|
WriteParam(aMsg, aParam.redirectStart);
|
|
|
|
WriteParam(aMsg, aParam.redirectEnd);
|
2015-07-24 18:49:25 +03:00
|
|
|
|
|
|
|
WriteParam(aMsg, aParam.transferSize);
|
|
|
|
WriteParam(aMsg, aParam.encodedBodySize);
|
2015-11-24 15:42:47 +03:00
|
|
|
WriteParam(aMsg, aParam.protocolVersion);
|
2014-10-06 13:31:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, mozilla::net::ResourceTimingStruct* aResult)
|
|
|
|
{
|
|
|
|
return ReadParam(aMsg, aIter, &aResult->domainLookupStart) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->domainLookupEnd) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->connectStart) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->connectEnd) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->requestStart) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->responseStart) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->responseEnd) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->fetchStart) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->redirectStart) &&
|
2015-07-24 18:49:25 +03:00
|
|
|
ReadParam(aMsg, aIter, &aResult->redirectEnd) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->transferSize) &&
|
2015-11-24 15:42:47 +03:00
|
|
|
ReadParam(aMsg, aIter, &aResult->encodedBodySize) &&
|
|
|
|
ReadParam(aMsg, aIter, &aResult->protocolVersion);
|
2014-10-06 13:31:29 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace IPC
|
2010-04-09 10:26:36 +04:00
|
|
|
|
|
|
|
#endif // mozilla_net_NeckoMessageUtils_h
|