Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/about/nsAboutProtocolUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef nsAboutProtocolUtils_h
6
#define nsAboutProtocolUtils_h
7
8
#include "nsIURI.h"
9
#include "nsString.h"
10
#include "nsReadableUtils.h"
11
#include "nsIAboutModule.h"
12
#include "nsServiceManagerUtils.h"
13
#include "prtime.h"
14
15
inline MOZ_MUST_USE nsresult
16
NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule)
17
4.94k
{
18
#ifdef DEBUG
19
    {
20
        bool isAbout;
21
        NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) &&
22
                     isAbout,
23
                     "should be used only on about: URIs");
24
    }
25
#endif
26
27
4.94k
    nsresult rv = aAboutURI->GetPathQueryRef(aModule);
28
4.94k
    NS_ENSURE_SUCCESS(rv, rv);
29
4.94k
30
4.94k
    int32_t f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?"));
31
4.94k
    if (f != kNotFound) {
32
1.43k
        aModule.Truncate(f);
33
1.43k
    }
34
4.94k
35
4.94k
    // convert to lowercase, as all about: modules are lowercase
36
4.94k
    ToLowerCase(aModule);
37
4.94k
    return NS_OK;
38
4.94k
}
39
40
inline nsresult
41
NS_GetAboutModule(nsIURI *aAboutURI, nsIAboutModule** aModule)
42
4.09k
{
43
4.09k
  MOZ_ASSERT(aAboutURI, "Must have URI");
44
4.09k
45
4.09k
  nsAutoCString contractID;
46
4.09k
  nsresult rv = NS_GetAboutModuleName(aAboutURI, contractID);
47
4.09k
  if (NS_FAILED(rv)) return rv;
48
4.09k
49
4.09k
  // look up a handler to deal with "what"
50
4.09k
  contractID.InsertLiteral(NS_ABOUT_MODULE_CONTRACTID_PREFIX, 0);
51
4.09k
52
4.09k
  return CallGetService(contractID.get(), aModule);
53
4.09k
}
54
55
inline PRTime SecondsToPRTime(uint32_t t_sec)
56
0
{
57
0
    PRTime t_usec, usec_per_sec;
58
0
    t_usec = t_sec;
59
0
    usec_per_sec = PR_USEC_PER_SEC;
60
0
    return t_usec *= usec_per_sec;
61
0
}
62
inline void PrintTimeString(char *buf, uint32_t bufsize, uint32_t t_sec)
63
0
{
64
0
    PRExplodedTime et;
65
0
    PRTime t_usec = SecondsToPRTime(t_sec);
66
0
    PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
67
0
    PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et);
68
0
}
69
70
#endif