1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_net_NeckoMessageUtils_h
#define mozilla_net_NeckoMessageUtils_h
#include "ipc/EnumSerializer.h"
#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "mozilla/net/ClassOfService.h"
#include "mozilla/net/DNS.h"
#include "nsExceptionHandler.h"
#include "nsICacheInfoChannel.h"
#include "nsIDNSService.h"
#include "nsIHttpChannel.h"
#include "nsITRRSkipReason.h"
#include "nsPrintfCString.h"
#include "nsString.h"
#include "prio.h"
#include "mozilla/net/HttpTransactionShell.h"
namespace IPC {
// nsIPermissionManager utilities
struct Permission {
nsCString origin, type;
uint32_t capability, expireType;
int64_t expireTime;
Permission() : capability(0), expireType(0), expireTime(0) {}
Permission(const nsCString& aOrigin, const nsACString& aType,
const uint32_t aCapability, const uint32_t aExpireType,
const int64_t aExpireTime)
: origin(aOrigin),
type(aType),
capability(aCapability),
expireType(aExpireType),
expireTime(aExpireTime) {}
bool operator==(const Permission& aOther) const {
return aOther.origin == origin && aOther.type == type &&
aOther.capability == capability && aOther.expireType == expireType &&
aOther.expireTime == expireTime;
}
};
template <>
struct ParamTraits<Permission> {
static void Write(MessageWriter* aWriter, const Permission& aParam) {
WriteParam(aWriter, aParam.origin);
WriteParam(aWriter, aParam.type);
WriteParam(aWriter, aParam.capability);
WriteParam(aWriter, aParam.expireType);
WriteParam(aWriter, aParam.expireTime);
}
static bool Read(MessageReader* aReader, Permission* aResult) {
return ReadParam(aReader, &aResult->origin) &&
ReadParam(aReader, &aResult->type) &&
ReadParam(aReader, &aResult->capability) &&
ReadParam(aReader, &aResult->expireType) &&
ReadParam(aReader, &aResult->expireTime);
}
};
template <>
struct ParamTraits<mozilla::net::NetAddr> {
static void Write(MessageWriter* aWriter,
const mozilla::net::NetAddr& aParam) {
WriteParam(aWriter, aParam.raw.family);
if (aParam.raw.family == AF_UNSPEC) {
aWriter->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
} else if (aParam.raw.family == AF_INET) {
WriteParam(aWriter, aParam.inet.port);
WriteParam(aWriter, aParam.inet.ip);
} else if (aParam.raw.family == AF_INET6) {
WriteParam(aWriter, aParam.inet6.port);
WriteParam(aWriter, aParam.inet6.flowinfo);
WriteParam(aWriter, aParam.inet6.ip.u64[0]);
WriteParam(aWriter, aParam.inet6.ip.u64[1]);
WriteParam(aWriter, aParam.inet6.scope_id);
#if defined(XP_UNIX)
} else if (aParam.raw.family == AF_LOCAL) {
// Train's already off the rails: let's get a stack trace at least...
MOZ_CRASH(
"Error: please post stack trace to "
"https://bugzilla.mozilla.org/show_bug.cgi?id=661158");
aWriter->WriteBytes(aParam.local.path, sizeof(aParam.local.path));
#endif
} else {
if (XRE_IsParentProcess()) {
CrashReporter::RecordAnnotationU32(
CrashReporter::Annotation::UnknownNetAddrSocketFamily,
aParam.raw.family);
}
MOZ_CRASH("Unknown socket family");
}
}
static bool Read(MessageReader* aReader, mozilla::net::NetAddr* aResult) {
if (!ReadParam(aReader, &aResult->raw.family)) return false;
if (aResult->raw.family == AF_UNSPEC) {
return aReader->ReadBytesInto(&aResult->raw.data,
sizeof(aResult->raw.data));
} else if (aResult->raw.family == AF_INET) {
return ReadParam(aReader, &aResult->inet.port) &&
ReadParam(aReader, &aResult->inet.ip);
} else if (aResult->raw.family == AF_INET6) {
return ReadParam(aReader, &aResult->inet6.port) &&
ReadParam(aReader, &aResult->inet6.flowinfo) &&
ReadParam(aReader, &aResult->inet6.ip.u64[0]) &&
ReadParam(aReader, &aResult->inet6.ip.u64[1]) &&
ReadParam(aReader, &aResult->inet6.scope_id);
#if defined(XP_UNIX)
} else if (aResult->raw.family == AF_LOCAL) {
return aReader->ReadBytesInto(&aResult->local.path,
sizeof(aResult->local.path));
#endif
}
/* We've been tricked by some socket family we don't know about! */
return false;
}
};
template <>
struct ParamTraits<nsIRequest::TRRMode>
: public ContiguousEnumSerializerInclusive<nsIRequest::TRRMode,
nsIRequest::TRR_DEFAULT_MODE,
nsIRequest::TRR_ONLY_MODE> {};
template <>
struct ParamTraits<nsITRRSkipReason::value>
: public ContiguousEnumSerializerInclusive<
nsITRRSkipReason::value, nsITRRSkipReason::value::TRR_UNSET,
nsITRRSkipReason::value::eLAST_VALUE> {};
template <>
struct ParamTraits<nsIDNSService::DNSFlags>
: public BitFlagsEnumSerializer<
nsIDNSService::DNSFlags, nsIDNSService::DNSFlags::ALL_DNSFLAGS_BITS> {
};
template <>
struct ParamTraits<nsIDNSService::ResolverMode>
: public ContiguousEnumSerializerInclusive<
nsIDNSService::ResolverMode,
nsIDNSService::ResolverMode::MODE_NATIVEONLY,
nsIDNSService::ResolverMode::MODE_TRROFF> {};
template <>
struct ParamTraits<nsIClassOfService::FetchPriority>
: public ContiguousEnumSerializerInclusive<
nsIClassOfService::FetchPriority,
nsIClassOfService::FETCHPRIORITY_UNSET,
nsIClassOfService::FETCHPRIORITY_HIGH> {};
template <>
struct ParamTraits<mozilla::net::ClassOfService> {
typedef mozilla::net::ClassOfService paramType;
static void Write(MessageWriter* aWriter, const paramType& aParam) {
WriteParam(aWriter, aParam.mClassFlags);
WriteParam(aWriter, aParam.mIncremental);
WriteParam(aWriter, aParam.mFetchPriority);
}
static bool Read(MessageReader* aReader, paramType* aResult) {
if (!ReadParam(aReader, &aResult->mClassFlags) ||
!ReadParam(aReader, &aResult->mIncremental) ||
!ReadParam(aReader, &aResult->mFetchPriority))
return false;
return true;
}
};
template <>
struct ParamTraits<struct mozilla::net::LNAPerms> {
typedef struct mozilla::net::LNAPerms paramType;
static void Write(MessageWriter* aWriter, const paramType& aParam) {
WriteParam(aWriter, aParam.mLocalHostPermission);
WriteParam(aWriter, aParam.mLocalNetworkPermission);
}
static bool Read(MessageReader* aReader, paramType* aResult) {
if (!ReadParam(aReader, &aResult->mLocalHostPermission) ||
!ReadParam(aReader, &aResult->mLocalNetworkPermission))
return false;
return true;
}
};
template <>
struct ParamTraits<mozilla::net::LNAPermission>
: public ContiguousEnumSerializerInclusive<
mozilla::net::LNAPermission, mozilla::net::LNAPermission::Granted,
mozilla::net::LNAPermission::Pending> {};
template <>
struct ParamTraits<nsICacheInfoChannel::CacheDisposition>
: public ContiguousEnumSerializer<
nsICacheInfoChannel::CacheDisposition,
nsICacheInfoChannel::kCacheUnresolved,
nsICacheInfoChannel::kCacheDispositionEnd> {};
} // namespace IPC
#endif // mozilla_net_NeckoMessageUtils_h
|