LCOV - code coverage report
Current view: top level - netwerk/ipc - NeckoMessageUtils.h (source / functions) Hit Total Coverage
Test: output.info Lines: 67 89 75.3 %
Date: 2017-07-14 16:53:18 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef mozilla_net_NeckoMessageUtils_h
       7             : #define mozilla_net_NeckoMessageUtils_h
       8             : 
       9             : #include "mozilla/DebugOnly.h"
      10             : 
      11             : #include "ipc/IPCMessageUtils.h"
      12             : #include "nsStringGlue.h"
      13             : #include "prio.h"
      14             : #include "mozilla/net/DNS.h"
      15             : #include "TimingStruct.h"
      16             : 
      17             : #ifdef MOZ_CRASHREPORTER
      18             : #include "nsExceptionHandler.h"
      19             : #include "nsPrintfCString.h"
      20             : #endif
      21             : 
      22             : namespace IPC {
      23             : 
      24             : // nsIPermissionManager utilities
      25             : 
      26          26 : struct Permission
      27             : {
      28             :   nsCString origin, type;
      29             :   uint32_t capability, expireType;
      30             :   int64_t expireTime;
      31             : 
      32           4 :   Permission() { }
      33          14 :   Permission(const nsCString& aOrigin,
      34             :              const nsCString& aType,
      35             :              const uint32_t aCapability,
      36             :              const uint32_t aExpireType,
      37          14 :              const int64_t aExpireTime) : origin(aOrigin),
      38             :                                           type(aType),
      39             :                                           capability(aCapability),
      40             :                                           expireType(aExpireType),
      41          14 :                                           expireTime(aExpireTime)
      42          14 :   {}
      43             : };
      44             : 
      45             : template<>
      46             : struct ParamTraits<Permission>
      47             : {
      48           4 :   static void Write(Message* aMsg, const Permission& aParam)
      49             :   {
      50           4 :     WriteParam(aMsg, aParam.origin);
      51           4 :     WriteParam(aMsg, aParam.type);
      52           4 :     WriteParam(aMsg, aParam.capability);
      53           4 :     WriteParam(aMsg, aParam.expireType);
      54           4 :     WriteParam(aMsg, aParam.expireTime);
      55           4 :   }
      56             : 
      57           4 :   static bool Read(const Message* aMsg, PickleIterator* aIter, Permission* aResult)
      58             :   {
      59           8 :     return ReadParam(aMsg, aIter, &aResult->origin) &&
      60           8 :            ReadParam(aMsg, aIter, &aResult->type) &&
      61           8 :            ReadParam(aMsg, aIter, &aResult->capability) &&
      62          12 :            ReadParam(aMsg, aIter, &aResult->expireType) &&
      63           8 :            ReadParam(aMsg, aIter, &aResult->expireTime);
      64             :   }
      65             : 
      66             :   static void Log(const Permission& p, std::wstring* l)
      67             :   {
      68             :     l->append(L"(");
      69             :     LogParam(p.origin, l);
      70             :     l->append(L", ");
      71             :     LogParam(p.capability, l);
      72             :     l->append(L", ");
      73             :     LogParam(p.expireTime, l);
      74             :     l->append(L", ");
      75             :     LogParam(p.expireType, l);
      76             :     l->append(L")");
      77             :   }
      78             : };
      79             : 
      80             : template<>
      81             : struct ParamTraits<mozilla::net::NetAddr>
      82             : {
      83           6 :   static void Write(Message* aMsg, const mozilla::net::NetAddr &aParam)
      84             :   {
      85           6 :     WriteParam(aMsg, aParam.raw.family);
      86           6 :     if (aParam.raw.family == AF_UNSPEC) {
      87           4 :       aMsg->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
      88           2 :     } else if (aParam.raw.family == AF_INET) {
      89           2 :       WriteParam(aMsg, aParam.inet.port);
      90           2 :       WriteParam(aMsg, aParam.inet.ip);
      91           0 :     } else if (aParam.raw.family == AF_INET6) {
      92           0 :       WriteParam(aMsg, aParam.inet6.port);
      93           0 :       WriteParam(aMsg, aParam.inet6.flowinfo);
      94           0 :       WriteParam(aMsg, aParam.inet6.ip.u64[0]);
      95           0 :       WriteParam(aMsg, aParam.inet6.ip.u64[1]);
      96           0 :       WriteParam(aMsg, aParam.inet6.scope_id);
      97             : #if defined(XP_UNIX)
      98           0 :     } else if (aParam.raw.family == AF_LOCAL) {
      99             :       // Train's already off the rails:  let's get a stack trace at least...
     100           0 :       MOZ_CRASH("Error: please post stack trace to "
     101             :                       "https://bugzilla.mozilla.org/show_bug.cgi?id=661158");
     102             :       aMsg->WriteBytes(aParam.local.path, sizeof(aParam.local.path));
     103             : #endif
     104             :     } else {
     105             : #ifdef MOZ_CRASHREPORTER
     106           0 :       if (XRE_IsParentProcess()) {
     107           0 :         nsPrintfCString msg("%d", aParam.raw.family);
     108           0 :         CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Unknown NetAddr socket family"), msg);
     109             :       }
     110             : #endif
     111           0 :       MOZ_CRASH("Unknown socket family");
     112             :     }
     113           6 :   }
     114             : 
     115           6 :   static bool Read(const Message* aMsg, PickleIterator* aIter, mozilla::net::NetAddr* aResult)
     116             :   {
     117           6 :     if (!ReadParam(aMsg, aIter, &aResult->raw.family))
     118           0 :       return false;
     119             : 
     120           6 :     if (aResult->raw.family == AF_UNSPEC) {
     121           4 :       return aMsg->ReadBytesInto(aIter, &aResult->raw.data, sizeof(aResult->raw.data));
     122           2 :     } else if (aResult->raw.family == AF_INET) {
     123           4 :       return ReadParam(aMsg, aIter, &aResult->inet.port) &&
     124           4 :              ReadParam(aMsg, aIter, &aResult->inet.ip);
     125           0 :     } else if (aResult->raw.family == AF_INET6) {
     126           0 :       return ReadParam(aMsg, aIter, &aResult->inet6.port) &&
     127           0 :              ReadParam(aMsg, aIter, &aResult->inet6.flowinfo) &&
     128           0 :              ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[0]) &&
     129           0 :              ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[1]) &&
     130           0 :              ReadParam(aMsg, aIter, &aResult->inet6.scope_id);
     131             : #if defined(XP_UNIX)
     132           0 :     } else if (aResult->raw.family == AF_LOCAL) {
     133           0 :       return aMsg->ReadBytesInto(aIter, &aResult->local.path, sizeof(aResult->local.path));
     134             : #endif
     135             :     }
     136             : 
     137             :     /* We've been tricked by some socket family we don't know about! */
     138           0 :     return false;
     139             :   }
     140             : };
     141             : 
     142             : template<>
     143             : struct ParamTraits<mozilla::net::ResourceTimingStruct>
     144             : {
     145           3 :   static void Write(Message* aMsg, const mozilla::net::ResourceTimingStruct& aParam)
     146             :   {
     147           3 :     WriteParam(aMsg, aParam.domainLookupStart);
     148           3 :     WriteParam(aMsg, aParam.domainLookupEnd);
     149           3 :     WriteParam(aMsg, aParam.connectStart);
     150           3 :     WriteParam(aMsg, aParam.connectEnd);
     151           3 :     WriteParam(aMsg, aParam.requestStart);
     152           3 :     WriteParam(aMsg, aParam.responseStart);
     153           3 :     WriteParam(aMsg, aParam.responseEnd);
     154             : 
     155           3 :     WriteParam(aMsg, aParam.fetchStart);
     156           3 :     WriteParam(aMsg, aParam.redirectStart);
     157           3 :     WriteParam(aMsg, aParam.redirectEnd);
     158             : 
     159           3 :     WriteParam(aMsg, aParam.transferSize);
     160           3 :     WriteParam(aMsg, aParam.encodedBodySize);
     161           3 :     WriteParam(aMsg, aParam.protocolVersion);
     162             : 
     163           3 :     WriteParam(aMsg, aParam.cacheReadStart);
     164           3 :     WriteParam(aMsg, aParam.cacheReadEnd);
     165           3 :   }
     166             : 
     167           3 :   static bool Read(const Message* aMsg, PickleIterator* aIter, mozilla::net::ResourceTimingStruct* aResult)
     168             :   {
     169           6 :     return ReadParam(aMsg, aIter, &aResult->domainLookupStart) &&
     170           6 :            ReadParam(aMsg, aIter, &aResult->domainLookupEnd) &&
     171           6 :            ReadParam(aMsg, aIter, &aResult->connectStart) &&
     172           6 :            ReadParam(aMsg, aIter, &aResult->connectEnd) &&
     173           6 :            ReadParam(aMsg, aIter, &aResult->requestStart) &&
     174           6 :            ReadParam(aMsg, aIter, &aResult->responseStart) &&
     175           6 :            ReadParam(aMsg, aIter, &aResult->responseEnd) &&
     176           6 :            ReadParam(aMsg, aIter, &aResult->fetchStart) &&
     177           6 :            ReadParam(aMsg, aIter, &aResult->redirectStart) &&
     178           6 :            ReadParam(aMsg, aIter, &aResult->redirectEnd) &&
     179           6 :            ReadParam(aMsg, aIter, &aResult->transferSize) &&
     180           6 :            ReadParam(aMsg, aIter, &aResult->encodedBodySize) &&
     181           6 :            ReadParam(aMsg, aIter, &aResult->protocolVersion) &&
     182           9 :            ReadParam(aMsg, aIter, &aResult->cacheReadStart) &&
     183           6 :            ReadParam(aMsg, aIter, &aResult->cacheReadEnd);
     184             :   }
     185             : };
     186             : 
     187             : } // namespace IPC
     188             : 
     189             : #endif // mozilla_net_NeckoMessageUtils_h

Generated by: LCOV version 1.13