Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/wifi/nsWifiAccessPoint.cpp
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
#include "nsWifiAccessPoint.h"
6
#include "nsString.h"
7
#include "nsMemory.h"
8
#include "mozilla/Logging.h"
9
10
extern mozilla::LazyLogModule gWifiMonitorLog;
11
0
#define LOG(args)     MOZ_LOG(gWifiMonitorLog, mozilla::LogLevel::Debug, args)
12
13
NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
14
15
nsWifiAccessPoint::nsWifiAccessPoint()
16
0
{
17
0
  // make sure these are null terminated (because we are paranoid)
18
0
  mMac[0] = '\0';
19
0
  mSsid[0] = '\0';
20
0
  mSsidLen = 0;
21
0
  mSignal = -1000;
22
0
}
23
24
NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
25
0
{
26
0
  aMac.Assign(mMac);
27
0
  return NS_OK;
28
0
}
29
30
NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
31
0
{
32
0
  // just assign and embedded nulls will truncate resulting
33
0
  // in a displayable string.
34
0
  aSsid.AssignASCII(mSsid);
35
0
  return NS_OK;
36
0
}
37
38
39
NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
40
0
{
41
0
  aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
42
0
  return NS_OK;
43
0
}
44
45
NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal)
46
0
{
47
0
  NS_ENSURE_ARG(aSignal);
48
0
  *aSignal = mSignal;
49
0
  return NS_OK;
50
0
}
51
52
// Helper functions:
53
54
bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
55
0
{
56
0
  if (a.Count() != b.Count()) {
57
0
    LOG(("AccessPoint lists have different lengths\n"));
58
0
    return false;
59
0
  }
60
0
61
0
  for (int32_t i = 0; i < a.Count(); i++) {
62
0
    LOG(("++ Looking for %s\n", a[i]->mSsid));
63
0
    bool found = false;
64
0
    for (int32_t j = 0; j < b.Count(); j++) {
65
0
      LOG(("   %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
66
0
      if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
67
0
          !strcmp(a[i]->mMac, b[j]->mMac) &&
68
0
          a[i]->mSignal == b[j]->mSignal) {
69
0
        found = true;
70
0
      }
71
0
    }
72
0
    if (!found)
73
0
      return false;
74
0
  }
75
0
  LOG(("   match!\n"));
76
0
  return true;
77
0
}
78
79
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
80
0
{
81
0
  a.Clear();
82
0
83
0
  // better way to copy?
84
0
  for (int32_t i = 0; i < b.Count(); i++) {
85
0
    a.AppendObject(b[i]);
86
0
  }
87
0
88
0
  b.Clear();
89
0
}
90
91