netwerk/wifi/nsWifiAccessPoint.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial