netwerk/wifi/nsWifiAccessPoint.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsWifiAccessPoint.h"
michael@0 6 #include "nsString.h"
michael@0 7 #include "nsMemory.h"
michael@0 8 #include "prlog.h"
michael@0 9
michael@0 10 #if defined(PR_LOGGING)
michael@0 11 extern PRLogModuleInfo *gWifiMonitorLog;
michael@0 12 #endif
michael@0 13 #define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
michael@0 14
michael@0 15
michael@0 16 NS_IMPL_ISUPPORTS(nsWifiAccessPoint, nsIWifiAccessPoint)
michael@0 17
michael@0 18 nsWifiAccessPoint::nsWifiAccessPoint()
michael@0 19 {
michael@0 20 // make sure these are null terminated (because we are paranoid)
michael@0 21 mMac[0] = '\0';
michael@0 22 mSsid[0] = '\0';
michael@0 23 mSsidLen = 0;
michael@0 24 }
michael@0 25
michael@0 26 nsWifiAccessPoint::~nsWifiAccessPoint()
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
michael@0 31 {
michael@0 32 aMac.Assign(mMac);
michael@0 33 return NS_OK;
michael@0 34 }
michael@0 35
michael@0 36 NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
michael@0 37 {
michael@0 38 // just assign and embedded nulls will truncate resulting
michael@0 39 // in a displayable string.
michael@0 40 CopyASCIItoUTF16(mSsid, aSsid);
michael@0 41 return NS_OK;
michael@0 42 }
michael@0 43
michael@0 44
michael@0 45 NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
michael@0 46 {
michael@0 47 aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
michael@0 48 return NS_OK;
michael@0 49 }
michael@0 50
michael@0 51 NS_IMETHODIMP nsWifiAccessPoint::GetSignal(int32_t *aSignal)
michael@0 52 {
michael@0 53 NS_ENSURE_ARG(aSignal);
michael@0 54 *aSignal = mSignal;
michael@0 55 return NS_OK;
michael@0 56 }
michael@0 57
michael@0 58 // Helper functions:
michael@0 59
michael@0 60 bool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
michael@0 61 {
michael@0 62 if (a.Count() != b.Count()) {
michael@0 63 LOG(("AccessPoint lists have different lengths\n"));
michael@0 64 return false;
michael@0 65 }
michael@0 66
michael@0 67 for (int32_t i = 0; i < a.Count(); i++) {
michael@0 68 LOG(("++ Looking for %s\n", a[i]->mSsid));
michael@0 69 bool found = false;
michael@0 70 for (int32_t j = 0; j < b.Count(); j++) {
michael@0 71 LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
michael@0 72 if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
michael@0 73 !strcmp(a[i]->mMac, b[j]->mMac)) {
michael@0 74 found = true;
michael@0 75 }
michael@0 76 }
michael@0 77 if (!found)
michael@0 78 return false;
michael@0 79 }
michael@0 80 LOG((" match!\n"));
michael@0 81 return true;
michael@0 82 }
michael@0 83
michael@0 84 void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
michael@0 85 {
michael@0 86 a.Clear();
michael@0 87
michael@0 88 // better way to copy?
michael@0 89 for (int32_t i = 0; i < b.Count(); i++) {
michael@0 90 a.AppendObject(b[i]);
michael@0 91 }
michael@0 92
michael@0 93 b.Clear();
michael@0 94 }
michael@0 95
michael@0 96

mercurial