Bug 826455 Expose more NetAddr functions to script r=biesi,josh

This commit is contained in:
Neil Rashbrook 2013-01-10 18:44:17 +00:00
Родитель 87223f36ee
Коммит f975dbf535
4 изменённых файлов: 56 добавлений и 2 удалений

Просмотреть файл

@ -12,7 +12,7 @@
* 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
{
/**
@ -57,6 +57,13 @@ interface nsINetAddr : nsISupports
*/
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.

Просмотреть файл

@ -7,6 +7,7 @@
#include "nsNetAddr.h"
#include "nsString.h"
#include "prnetdb.h"
#include "mozilla/net/DNS.h"
using namespace mozilla::net;
@ -131,3 +132,23 @@ NS_IMETHODIMP nsNetAddr::GetScope(uint32_t *aScope)
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;
}

Просмотреть файл

@ -26,6 +26,7 @@
#include "plstr.h"
#include "nsIOService.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsNetAddr.h"
#include "mozilla/Attributes.h"
@ -159,6 +160,18 @@ nsDNSRecord::GetNextAddr(uint16_t port, NetAddr *addr)
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)
{

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/net/DNS.h"
%}
native NetAddr(mozilla::net::NetAddr);
interface nsINetAddr;
/**
* nsIDNSRecord
@ -17,7 +18,7 @@ native NetAddr(mozilla::net::NetAddr);
* 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
{
/**
@ -40,6 +41,18 @@ interface nsIDNSRecord : nsISupports
*/
[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.