Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Private Member Functions
nsWSAUtils Class Reference

#include <nsWSAUtils.h>

List of all members.

Static Public Member Functions

static PRBool IsEqual (const nsAString &aLhs, const nsAString &aRhs)
 This method compares two strings where the lhs string value may contain asterisk.
static nsresult ReportError (const PRUnichar *aMessageID, const PRUnichar **aInputs, const PRInt32 aLength)
static nsresult GetOfficialHostName (nsIURI *aURI, nsACString &aResult)

Private Member Functions

 nsWSAUtils ()
 ~nsWSAUtils ()

Detailed Description

Definition at line 47 of file nsWSAUtils.h.

Constructor & Destructor Documentation

nsWSAUtils::nsWSAUtils ( ) [inline, private]

Definition at line 61 of file nsWSAUtils.h.

nsWSAUtils::~nsWSAUtils ( ) [inline, private]

Definition at line 62 of file nsWSAUtils.h.


Member Function Documentation

nsresult nsWSAUtils::GetOfficialHostName ( nsIURI aURI,
nsACString &  aResult 
) [static]

Definition at line 222 of file nsWSAUtils.cpp.

  NS_ASSERTION(aServiceURI, "Cannot get FQDN for a null URI!");
  if (!aServiceURI)

  nsresult rv;
  nsCOMPtr<nsIDNSService> dns(do_GetService(kDNSServiceCID, &rv));
  if (NS_FAILED(rv)) 
    return rv;
  nsCAutoString host;

  nsRefPtr<nsDNSListener> listener = new nsDNSListener();
  nsCOMPtr<nsIEventQueueService> eventQService = 
    do_GetService(kEventQueueServiceCID, &rv);
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIEventQueue> eventQ;
  rv = eventQService->PushThreadEventQueue(getter_AddRefs(eventQ));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsICancelable> dummy;
  rv = dns->AsyncResolve(host, nsIDNSService::RESOLVE_CANONICAL_NAME,
                         listener, eventQ, getter_AddRefs(dummy));
  PLEvent *ev;
  while (NS_SUCCEEDED(rv) && !listener->mLookupFinished) {
    rv = eventQ->WaitForEvent(&ev);
    NS_ASSERTION(NS_SUCCEEDED(rv), "WaitForEvent failed");
    if (NS_SUCCEEDED(rv)) {
      rv = eventQ->HandleEvent(ev);
      NS_ASSERTION(NS_SUCCEEDED(rv), "HandleEvent failed");


  return rv;

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsWSAUtils::IsEqual ( const nsAString &  aLhs,
const nsAString &  aRhs 
) [static]

This method compares two strings where the lhs string value may contain asterisk.

Therefore, an lhs with a value of "he*o" should be equal to a rhs value of "hello" or "hero" etc.. These strings are compared as follows: 1) Characters before the first asterisk are compared from left to right. Thus if the lhs string did not contain an asterisk then we just do a simple string comparison. 2) Match a pattern, found between asterisk. That is, if lhs and rhs were "h*ll*" and "hello" respectively, then compare the pattern "ll". 3) Characters after the last asterisk are compared from right to left. Thus, "*lo" == "hello" and != "blow"

Definition at line 129 of file nsWSAUtils.cpp.

  nsAString::const_iterator lhs_begin, lhs_end;
  nsAString::const_iterator rhs_begin, rhs_end;

  PRBool pattern_before_asterisk = PR_TRUE; 
  nsAString::const_iterator curr_posn = lhs_begin;
  while (curr_posn != lhs_end) {
    if (*lhs_begin == '*') {
      pattern_before_asterisk = PR_FALSE;
      ++lhs_begin; // Do this to not include '*' when pattern matching.
    else if (pattern_before_asterisk) {
      // Match character by character to see if lhs and rhs are identical
      if (*curr_posn != *rhs_begin) {
        return PR_FALSE;
      if (rhs_begin == rhs_end &&
          curr_posn == lhs_end) {
        return PR_TRUE; // lhs and rhs matched perfectly
    else if (++curr_posn == lhs_end) {
      if (curr_posn != lhs_begin) {
        // Here we're matching the last few characters to make sure
        // that lhs is actually equal to rhs. Ex. "a*c" != "abcd"
        // and "*xabcd" != "abcd".
        PRBool done = PR_FALSE;
        for (;;) {
          if (--curr_posn == lhs_begin)
            done = PR_TRUE;
          if (rhs_end == rhs_begin)
            return PR_FALSE;
          if (*(--rhs_end) != *curr_posn)
            return PR_FALSE;
          if (done)
            return PR_TRUE;
      // No discrepency between lhs and rhs
      return PR_TRUE;
    else if (*curr_posn == '*') {
      // Matching pattern between asterisks. That is, in "h*ll*" we
      // check to see if "ll" exists in the rhs string.
      const nsAString& pattern = Substring(lhs_begin, curr_posn);

      nsAString::const_iterator tmp_end = rhs_end;
      if (!FindInReadable(pattern, rhs_begin, rhs_end)) {
         return PR_FALSE;
      rhs_begin = rhs_end;
      rhs_end   = tmp_end;
      lhs_begin = curr_posn;

  return PR_FALSE;

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWSAUtils::ReportError ( const PRUnichar aMessageID,
const PRUnichar **  aInputs,
const PRInt32  aLength 
) [static]

Definition at line 198 of file nsWSAUtils.cpp.

  nsCOMPtr<nsIStringBundleService> bundleService
  NS_ENSURE_TRUE(bundleService, NS_OK); // intentionally returning NS_OK;

  nsCOMPtr<nsIStringBundle> bundle;
  bundleService->CreateBundle(kSecurityProperties, getter_AddRefs(bundle));
  NS_ENSURE_TRUE(bundle, NS_OK);

  nsXPIDLString message;
  bundle->FormatStringFromName(aMessageID, aInputs, aLength,

  nsCOMPtr<nsIConsoleService> consoleService = 
  NS_ENSURE_TRUE(consoleService, NS_OK); // intentionally returning NS_OK;
  return consoleService->LogStringMessage(message.get());

Here is the call graph for this function:

The documentation for this class was generated from the following files: