Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/xre/CreateAppData.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "nsXULAppAPI.h"
7
#include "nsINIParser.h"
8
#include "nsIFile.h"
9
#include "nsAutoPtr.h"
10
#include "mozilla/XREAppData.h"
11
12
using namespace mozilla;
13
14
static void
15
ReadString(nsINIParser &parser, const char* section,
16
           const char* key, XREAppData::CharPtr& result)
17
0
{
18
0
  nsCString str;
19
0
  nsresult rv = parser.GetString(section, key, str);
20
0
  if (NS_SUCCEEDED(rv)) {
21
0
    result = str.get();
22
0
  }
23
0
}
24
25
struct ReadFlag {
26
  const char *section;
27
  const char *key;
28
  uint32_t flag;
29
};
30
31
static void
32
ReadFlag(nsINIParser &parser, const char* section,
33
         const char* key, uint32_t flag, uint32_t& result)
34
0
{
35
0
  char buf[6]; // large enough to hold "false"
36
0
  nsresult rv = parser.GetString(section, key, buf, sizeof(buf));
37
0
  if (NS_SUCCEEDED(rv) || rv == NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
38
0
    if (buf[0] == '1' || buf[0] == 't' || buf[0] == 'T') {
39
0
      result |= flag;
40
0
    }
41
0
    if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
42
0
      result &= ~flag;
43
0
    }
44
0
  }
45
0
}
46
47
nsresult
48
XRE_ParseAppData(nsIFile* aINIFile, XREAppData& aAppData)
49
0
{
50
0
  NS_ENSURE_ARG(aINIFile);
51
0
52
0
  nsresult rv;
53
0
54
0
  nsINIParser parser;
55
0
  rv = parser.Init(aINIFile);
56
0
  if (NS_FAILED(rv))
57
0
    return rv;
58
0
59
0
  ReadString(parser, "App", "Vendor", aAppData.vendor);
60
0
  ReadString(parser, "App", "Name", aAppData.name);
61
0
  ReadString(parser, "App", "RemotingName", aAppData.remotingName);
62
0
  ReadString(parser, "App", "Version", aAppData.version);
63
0
  ReadString(parser, "App", "BuildID", aAppData.buildID);
64
0
  ReadString(parser, "App", "ID", aAppData.ID);
65
0
  ReadString(parser, "App", "Copyright", aAppData.copyright);
66
0
  ReadString(parser, "App", "Profile", aAppData.profile);
67
0
  ReadString(parser, "Gecko", "MinVersion", aAppData.minVersion);
68
0
  ReadString(parser, "Gecko", "MaxVersion", aAppData.maxVersion);
69
0
  ReadString(parser, "Crash Reporter", "ServerURL", aAppData.crashReporterURL);
70
0
  ReadString(parser, "App", "UAName", aAppData.UAName);
71
0
  ReadFlag(parser, "XRE", "EnableProfileMigrator",
72
0
           NS_XRE_ENABLE_PROFILE_MIGRATOR, aAppData.flags);
73
0
  ReadFlag(parser, "Crash Reporter", "Enabled",
74
0
           NS_XRE_ENABLE_CRASH_REPORTER, aAppData.flags);
75
0
76
0
  return NS_OK;
77
0
}