Bug 826455 Expose more NetAddr functions to script r=biesi,josh
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 10 Jan 2013 18:44:17 +0000
changeset 118426 33e9b69e55cc0a16471d3d3228ef299118d9806c
parent 118425 5b042b636671dd61e242c8f396ad1f35b56d493f
child 118427 85b09d1c1cdc0ce5346dd7803ebc7f84466bbb13
push id21056
push userneil@parkwaycc.co.uk
push dateThu, 10 Jan 2013 18:44:22 +0000
treeherdermozilla-inbound@33e9b69e55cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi, josh
bugs826455
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 826455 Expose more NetAddr functions to script r=biesi,josh
netwerk/base/public/nsINetAddr.idl
netwerk/base/src/nsNetAddr.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsIDNSRecord.idl
--- a/netwerk/base/public/nsINetAddr.idl
+++ b/netwerk/base/public/nsINetAddr.idl
@@ -7,17 +7,17 @@
 #include "nsISupports.idl"
 
 /**
  * nsINetAddr
  *
  * This interface represents a native NetAddr struct in a readonly
  * interface.
  */
-[scriptable, uuid(c407ab6c-c3ca-4cb2-a99b-a7dfbb88af33)]
+[scriptable, uuid(4f7c40b0-fc7d-42a4-a642-1b2a703c10f6)]
 interface nsINetAddr : nsISupports
 {
     /**
      * @return the address family of the network address, which corresponds to
      * one of the FAMILY_ constants.
      */
     readonly attribute unsigned short family;
 
@@ -53,15 +53,22 @@ interface nsINetAddr : nsISupports
      *
      * @see http://tools.ietf.org/html/rfc4007
      *
      * @throws NS_ERROR_NOT_AVAILABLE if the address family is not FAMILY_INET6
      */
     readonly attribute unsigned long scope;
 
     /**
+     * @return whether a FAMILY_INET6 address is mapped from FAMILY_INET.
+     *
+     * @throws NS_ERROR_NOT_AVAILABLE if the address family is not FAMILY_INET6
+     */
+    readonly attribute boolean isV4Mapped;
+
+    /**
      * Network address families. These correspond to all the network address
      * families supported by the NetAddr struct.
      */
     const unsigned long FAMILY_INET = 1;
     const unsigned long FAMILY_INET6 = 2;
     const unsigned long FAMILY_LOCAL = 3;
 };
--- a/netwerk/base/src/nsNetAddr.cpp
+++ b/netwerk/base/src/nsNetAddr.cpp
@@ -2,16 +2,17 @@
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsNetAddr.h"
 #include "nsString.h"
 #include "prnetdb.h"
+#include "mozilla/net/DNS.h"
 
 using namespace mozilla::net;
 
 NS_IMPL_ISUPPORTS1(nsNetAddr, nsINetAddr)
 
 /* Makes a copy of |addr| */
 nsNetAddr::nsNetAddr(NetAddr* addr)
 {
@@ -126,8 +127,28 @@ NS_IMETHODIMP nsNetAddr::GetScope(uint32
     return NS_ERROR_NOT_AVAILABLE;
   default:
     return NS_ERROR_UNEXPECTED;
   }
 
   return NS_OK;
 }
 
+/* readonly attribute boolean isV4Mapped; */
+NS_IMETHODIMP nsNetAddr::GetIsV4Mapped(bool *aIsV4Mapped)
+{
+  switch(mAddr.raw.family) {
+  case AF_INET6:
+    *aIsV4Mapped = IPv6ADDR_IS_V4MAPPED(&mAddr.inet6.ip);
+    break;
+  case AF_INET:
+#if defined(XP_UNIX) || defined(XP_OS2)
+  case AF_LOCAL:
+#endif
+    // only for IPv6
+    return NS_ERROR_NOT_AVAILABLE;
+  default:
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  return NS_OK;
+}
+
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -21,16 +21,17 @@
 #include "nsIProtocolProxyService.h"
 #include "prsystem.h"
 #include "prnetdb.h"
 #include "prmon.h"
 #include "prio.h"
 #include "plstr.h"
 #include "nsIOService.h"
 #include "nsCharSeparatedTokenizer.h"
+#include "nsNetAddr.h"
 
 #include "mozilla/Attributes.h"
 
 using namespace mozilla;
 using namespace mozilla::net;
 
 static const char kPrefDnsCacheEntries[]    = "network.dnsCacheEntries";
 static const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration";
@@ -155,16 +156,28 @@ nsDNSRecord::GetNextAddr(uint16_t port, 
     else if (addr->raw.family == AF_INET6) {
         addr->inet6.port = port;
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDNSRecord::GetScriptableNextAddr(uint16_t port, nsINetAddr * *result)
+{
+    NetAddr addr;
+    nsresult rv = GetNextAddr(port, &addr);
+    if (NS_FAILED(rv)) return rv;
+
+    NS_ADDREF(*result = new nsNetAddr(&addr));
+
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDNSRecord::GetNextAddrAsString(nsACString &result)
 {
     NetAddr addr;
     nsresult rv = GetNextAddr(0, &addr);
     if (NS_FAILED(rv)) return rv;
 
     char buf[kIPv6CStrBufSize];
     if (NetAddrToString(&addr, buf, sizeof(buf))) {
--- a/netwerk/dns/nsIDNSRecord.idl
+++ b/netwerk/dns/nsIDNSRecord.idl
@@ -3,26 +3,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 %{ C++
 #include "mozilla/net/DNS.h"
 %}
 native NetAddr(mozilla::net::NetAddr);
+interface nsINetAddr;
 
 /**
  * nsIDNSRecord
  *
  * this interface represents the result of a DNS lookup.  since a DNS
  * query may return more than one resolved IP address, the record acts
  * like an enumerator, allowing the caller to easily step through the
  * list of IP addresses.
  */
-[scriptable, uuid(67E6CF03-12C7-4AF4-AE5F-AE362C7AF8FF)]
+[scriptable, uuid(95ced6f3-44b4-4427-a149-c9a1e033d852)]
 interface nsIDNSRecord : nsISupports
 {
     /**
      * @return the canonical hostname for this record.  this value is empty if
      * the record was not fetched with the RESOLVE_CANONICAL_NAME flag.
      *
      * e.g., www.mozilla.org --> rheet.mozilla.org
      */
@@ -37,16 +38,28 @@ interface nsIDNSRecord : nsISupports
      *
      * @throws NS_ERROR_NOT_AVAILABLE if there is not another IP address in
      * the record.
      */
     [noscript] NetAddr getNextAddr(in uint16_t aPort);
 
     /**
      * this function returns the value of the next IP address as a
+     * scriptable address and increments the internal address iterator.
+     *
+     * @param aPort
+     *        A port number to initialize the nsINetAddr with.
+     *
+     * @throws NS_ERROR_NOT_AVAILABLE if there is not another IP address in
+     * the record.
+     */
+    nsINetAddr getScriptableNextAddr(in uint16_t aPort);
+
+    /**
+     * this function returns the value of the next IP address as a
      * string and increments the internal address iterator.
      *
      * @throws NS_ERROR_NOT_AVAILABLE if there is not another IP address in
      * the record.
      */
     ACString getNextAddrAsString();
 
     /**