예제 #1
0
// refresh the local tag key array m_keys from preferences
nsresult nsMsgTagService::RefreshKeyCache()
{
  nsIMsgTag **tagArray;
  uint32_t numTags;
  nsresult rv = GetAllTags(&numTags, &tagArray);
  NS_ENSURE_SUCCESS(rv, rv);
  m_keys.Clear();

  for (uint32_t tagIndex = 0; tagIndex < numTags; tagIndex++)
  {
    nsIMsgTag *tag = tagArray[tagIndex];
    if (!tag) {
      rv = NS_ERROR_FAILURE;
      break;
    }
    nsCAutoString key;
    tag->GetKey(key);
    if (!m_keys.InsertElementAt(tagIndex, key)) {
      rv = NS_ERROR_FAILURE;
      break;
    }
  }
  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numTags, tagArray);
  return rv;
}
예제 #2
0
NS_IMETHODIMP
nsSmtpServer::ForgetPassword()
{
  nsresult rv;
  nsCOMPtr<nsILoginManager> loginMgr =
    do_GetService(NS_LOGINMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the current server URI without the username
  nsCAutoString serverUri(NS_LITERAL_CSTRING("smtp://"));

  nsCString hostname;
  rv = GetHostname(hostname);

  if (NS_SUCCEEDED(rv) && !hostname.IsEmpty()) {
    nsCString escapedHostname;
    *((char **)getter_Copies(escapedHostname)) =
      nsEscape(hostname.get(), url_Path);
    // not all servers have a hostname
    serverUri.Append(escapedHostname);
  }

  PRUint32 count;
  nsILoginInfo** logins;

  NS_ConvertUTF8toUTF16 currServer(serverUri);

  nsCString serverCUsername;
  rv = GetUsername(serverCUsername);
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ConvertUTF8toUTF16 serverUsername(serverCUsername);

  rv = loginMgr->FindLogins(&count, currServer, EmptyString(),
                            currServer, &logins);
  NS_ENSURE_SUCCESS(rv, rv);

  // There should only be one-login stored for this url, however just in case
  // there isn't.
  nsString username;
  for (PRUint32 i = 0; i < count; ++i)
  {
    if (NS_SUCCEEDED(logins[i]->GetUsername(username)) &&
        username.Equals(serverUsername))
    {
      // If this fails, just continue, we'll still want to remove the password
      // from our local cache.
      loginMgr->RemoveLogin(logins[i]);
    }
  }
  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);

  rv = SetPassword(EmptyCString());
  m_logonFailed = PR_TRUE;
  return rv;
}
nsresult
nsSeamonkeyProfileMigrator::CopyPasswords(PRBool aReplace)
{
  nsresult rv;

  nsCString signonsFileName;
  GetSignonFileName(aReplace, getter_Copies(signonsFileName));

  if (signonsFileName.IsEmpty())
    return NS_ERROR_FILE_NOT_FOUND;

  NS_ConvertASCIItoUTF16 fileName(signonsFileName);
  if (aReplace)
    rv = CopyFile(fileName, fileName);
  else {
    // Get the password manager, which is the destination for the passwords
    // being migrated. Also create a new instance of the legacy password
    // storage component, which we'll use to slurp in the signons from
    // Seamonkey's signons.txt.
    nsCOMPtr<nsILoginManager> pwmgr(
        do_GetService("@mozilla.org/login-manager;1"));
    nsCOMPtr<nsILoginManagerStorage> importer(
        do_CreateInstance("@mozilla.org/login-manager/storage/legacy;1"));

    nsCOMPtr<nsIFile> signonsFile;
    mSourceProfile->Clone(getter_AddRefs(signonsFile));
    signonsFile->Append(fileName);

    importer->InitWithFile(signonsFile, nsnull);

    PRUint32 count;
    nsILoginInfo **logins;

    rv = importer->GetAllLogins(&count, &logins);
    NS_ENSURE_SUCCESS(rv, rv);
    for (PRUint32 i = 0; i < count; i++) {
        pwmgr->AddLogin(logins[i]);
    }
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);

    PRUnichar **hostnames;
    rv = importer->GetAllDisabledHosts(&count, &hostnames);
    NS_ENSURE_SUCCESS(rv, rv);
    for (PRUint32 i = 0; i < count; i++) {
        pwmgr->SetLoginSavingEnabled(nsDependentString(hostnames[i]),
                                     PR_FALSE);
    }
    NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, hostnames);
  }
  return rv;
}
예제 #4
0
nsresult
nsSmtpServer::GetPasswordWithoutUI()
{
  nsresult rv;
  nsCOMPtr<nsILoginManager> loginMgr(do_GetService(NS_LOGINMANAGER_CONTRACTID,
                                                   &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ConvertASCIItoUTF16 serverUri(GetServerURIInternal(false));

  uint32_t numLogins = 0;
  nsILoginInfo** logins = nullptr;
  rv = loginMgr->FindLogins(&numLogins, serverUri, EmptyString(),
                            serverUri, &logins);
  // Login manager can produce valid fails, e.g. NS_ERROR_ABORT when a user
  // cancels the master password dialog. Therefore handle that here, but don't
  // warn about it.
  if (NS_FAILED(rv))
    return rv;

  // Don't abort here, if we didn't find any or failed, then we'll just have
  // to prompt.
  if (numLogins > 0)
  {
    nsCString serverCUsername;
    rv = GetUsername(serverCUsername);
    NS_ConvertASCIItoUTF16 serverUsername(serverCUsername);

    nsString username;
    for (uint32_t i = 0; i < numLogins; ++i)
    {
      rv = logins[i]->GetUsername(username);
      NS_ENSURE_SUCCESS(rv, rv);

      if (username.Equals(serverUsername))
      {
        nsString password;
        rv = logins[i]->GetPassword(password);
        NS_ENSURE_SUCCESS(rv, rv);

        LossyCopyUTF16toASCII(password, m_password);
        break;
      }
    }
  }
  NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numLogins, logins);
  return NS_OK;
}
예제 #5
0
/**
 * Export VirtualBox machines
 */
void exportVirtualBoxMachines(IVirtualBox *virtualBox, xmlTextWriterPtr writer) {
	IMachine **machines = NULL;
	PRUint32 machinesCount = 0;
	nsresult rc = virtualBox->GetMachines(&machinesCount, &machines);

	if (NS_SUCCEEDED(rc)) {
		xmlTextWriterStartElement(writer, TOXMLCHAR("machines"));

			for (PRUint32 i = 0; i < machinesCount; i++) {
				PRBool accessible = PR_FALSE;

				rc = machines[i]->GetAccessible(&accessible);
				if (NS_SUCCEEDED(rc) && accessible) {
					exportVirtualBoxMachine(virtualBox, machines[i], writer);
				}
			}

		xmlTextWriterEndElement(writer);

		NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(machinesCount, machines);
	}
}
예제 #6
0
nsresult nsMsgTagService::MigrateLabelsToTags()
{
  nsCString prefString;

  int32_t prefVersion = 0;
  nsresult rv = m_tagPrefBranch->GetIntPref(TAG_PREF_VERSION, &prefVersion);
  if (NS_SUCCEEDED(rv) && prefVersion > 1)
    return rv;
  else if (prefVersion == 1)
  {
    gMigratingKeys = true;
  // need to convert the keys to lower case
    nsIMsgTag **tagArray;
    uint32_t numTags;
    GetAllTags(&numTags, &tagArray);
    for (uint32_t tagIndex = 0; tagIndex < numTags; tagIndex++)
    {
      nsCAutoString key, color, ordinal;
      nsAutoString tagStr;
      nsIMsgTag *tag = tagArray[tagIndex];
      tag->GetKey(key);
      tag->GetTag(tagStr);
      tag->GetOrdinal(ordinal);
      tag->GetColor(color);
      DeleteKey(key);
      ToLowerCase(key);
      AddTagForKey(key, tagStr, color, ordinal);
    }
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(numTags, tagArray);
    gMigratingKeys = false;
  }
  else 
  {
    nsCOMPtr<nsIPrefBranch> prefRoot(do_GetService(NS_PREFSERVICE_CONTRACTID));
    nsCOMPtr<nsIPrefLocalizedString> pls;
    nsString ucsval;
    nsCAutoString labelKey("$label1");
    for(int32_t i = 0; i < PREF_LABELS_MAX; )
    {
      prefString.Assign(PREF_LABELS_DESCRIPTION);
      prefString.AppendInt(i + 1);
      rv = prefRoot->GetComplexValue(prefString.get(),
                                     NS_GET_IID(nsIPrefLocalizedString),
                                     getter_AddRefs(pls));
      NS_ENSURE_SUCCESS(rv, rv);
      pls->ToString(getter_Copies(ucsval));

      prefString.Assign(PREF_LABELS_COLOR);
      prefString.AppendInt(i + 1);
      nsCString csval;
      rv = prefRoot->GetCharPref(prefString.get(), getter_Copies(csval));
      NS_ENSURE_SUCCESS(rv, rv);

      rv = AddTagForKey(labelKey, ucsval, csval, EmptyCString());
      NS_ENSURE_SUCCESS(rv, rv);
      labelKey.SetCharAt(++i + '1', 6);
    }
  }
  m_tagPrefBranch->SetIntPref(TAG_PREF_VERSION, 2);
  return rv;
}
예제 #7
0
/* void getAllTags (out unsigned long count, [array, size_is (count), retval] out nsIMsgTag tagArray); */
NS_IMETHODIMP nsMsgTagService::GetAllTags(uint32_t *aCount, nsIMsgTag ***aTagArray)
{
  NS_ENSURE_ARG_POINTER(aCount);
  NS_ENSURE_ARG_POINTER(aTagArray);

  // preset harmless default values
  *aCount = 0;
  *aTagArray = nullptr;

  // get the actual tag definitions
  nsresult rv;
  uint32_t prefCount;
  char **prefList;
  rv = m_tagPrefBranch->GetChildList("", &prefCount, &prefList);
  NS_ENSURE_SUCCESS(rv, rv);
  // sort them by key for ease of processing
  NS_QuickSort(prefList, prefCount, sizeof(char*), CompareMsgTagKeys, nullptr);

  // build an array of nsIMsgTag elements from the orderered list
  // it's at max the same size as the preflist, but usually only about half
  nsIMsgTag** tagArray = (nsIMsgTag**) NS_Alloc(sizeof(nsIMsgTag*) * prefCount);

  if (!tagArray)
  {
    NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);
    return NS_ERROR_OUT_OF_MEMORY;
  }
  uint32_t currentTagIndex = 0;
  nsMsgTag *newMsgTag;
  nsString tag;
  nsCString lastKey, color, ordinal;
  for (uint32_t i = prefCount; i--;)
  {
    // extract just the key from <key>.<info=tag|color|ordinal>
    char *info = strrchr(prefList[i], '.');
    if (info)
    {
      nsCAutoString key(Substring(prefList[i], info));
      if (key != lastKey)
      {
        if (!key.IsEmpty())
        {
          // .tag MUST exist (but may be empty)
          rv = GetTagForKey(key, tag);
          if (NS_SUCCEEDED(rv))
          {
            // .color MAY exist
            color.Truncate();
            GetColorForKey(key, color);
            // .ordinal MAY exist
            rv = GetOrdinalForKey(key, ordinal);
            if (NS_FAILED(rv))
              ordinal.Truncate();
            // store the tag info in our array
            newMsgTag = new nsMsgTag(key, tag, color, ordinal);
            if (!newMsgTag)
            {
              NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(currentTagIndex, tagArray);
              NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);
              return NS_ERROR_OUT_OF_MEMORY;
            }
            NS_ADDREF(tagArray[currentTagIndex++] = newMsgTag);
          }
        }
        lastKey = key;
      }
    }
  }
  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);

  // sort the non-null entries by ordinal
  NS_QuickSort(tagArray, currentTagIndex, sizeof(nsMsgTag*), CompareMsgTags,
               nullptr);

  // All done, now return the values (the idl's size_is(count) parameter
  // ensures that the array is cut accordingly).
  *aCount = currentTagIndex;
  *aTagArray = tagArray;

  return NS_OK;
}
예제 #8
0
/**
 * Export VirtualBox machine
 */
void exportVirtualBoxMachine(IVirtualBox *virtualBox, IMachine *machine, xmlTextWriterPtr writer) {
	nsCOMPtr<ISystemProperties> systemProperties;
	nsresult rc = virtualBox->GetSystemProperties(getter_AddRefs(systemProperties));

	if (NS_SUCCEEDED(rc)) {
		xmlTextWriterStartElement(writer, TOXMLCHAR("machine"));

			// uuid
			ADDXMLSTRING(machine->GetId, "id");

			// name
			ADDXMLSTRING(machine->GetName, "name");

			// description
			ADDXMLSTRING(machine->GetDescription, "description");

			// os type
			ADDXMLSTRING(machine->GetOSTypeId, "ostype");

			// settings file
			ADDXMLSTRING(machine->GetSettingsFilePath, "path");

			// hardware uuid
			ADDXMLSTRING(machine->GetHardwareUUID, "hardwareuuid");

			// memory size
			ADDXMLINT32U(machine->GetMemorySize, "memory");

			// memory balloon size
			ADDXMLINT32U(machine->GetMemoryBalloonSize, "memoryballoon");

			// page fusion
			ADDXMLBOOL(machine->GetPageFusionEnabled, "pagefusion");

			// vram size
			ADDXMLINT32U(machine->GetVRAMSize, "vram");

			// hpet
			ADDXMLBOOL(machine->GetHPETEnabled, "hpet");

			// cpu count
			ADDXMLINT32U(machine->GetCPUCount, "cpus");

			// cpu execution cap
			ADDXMLINT32U(machine->GetCPUExecutionCap, "cpucap");

			// cpu hotplug
			ADDXMLBOOL(machine->GetCPUHotPlugEnabled, "cpuhotplug");

			// synthcpu
			// {
			// 	PRBool value;

			// 	rc = machine->GetCPUProperty(CPUPropertyType_Synthetic, &value);
			// 	if (NS_SUCCEEDED(rc)) {
			// 		WRITEXMLBOOL("synthcpu", value);
			// 	}
			// }

			// firmware type
			ADDXMLENUM(machine->GetFirmwareType, "firmware", firmwareTypeConverter);

			// bios settings
			{
				nsCOMPtr<IBIOSSettings> value;

				rc = machine->GetBIOSSettings(getter_AddRefs(value));
				if (NS_SUCCEEDED(rc)) {
					exportVirtualBoxBIOSSettings(value, writer);
				}
			}

			// boot order
			{
				PRUint32 bootPositions;

				rc = systemProperties->GetMaxBootPosition(&bootPositions);
				if (NS_SUCCEEDED(rc)) {
					for (PRUint32 i = 1; i <= bootPositions; i++) {
						PRUint32 value;

						rc = machine->GetBootOrder(i, &value);
						if (NS_SUCCEEDED(rc)) {
							char name[256];

							sprintf(name, "boot%d", i);
							WRITEXMLENUM(name, value, deviceTypeConverter);
						}
					}
				}
			}

			// pae
			{
				PRBool value;

				rc = machine->GetCPUProperty(CPUPropertyType_PAE, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("pae", value);
				}
			}

			// rtc use utc
			ADDXMLBOOL(machine->GetRTCUseUTC, "rtcuseutc");

			// monitor count
			ADDXMLINT32U(machine->GetMonitorCount, "monitorcount");

			// accelerate 3D
			ADDXMLBOOL(machine->GetAccelerate3DEnabled, "accelerate3d");

			// accelerate 2D video
			ADDXMLBOOL(machine->GetAccelerate2DVideoEnabled, "accelerate2dvideo");

			// hwvirtex
			{
				PRBool value;

				rc = machine->GetCPUProperty(HWVirtExPropertyType_Enabled, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("hwvirtex", value);
				}
			}

			// vtxvpid
			{
				PRBool value;

				rc = machine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("vtxvpid", value);
				}
			}

			// nestedpaging
			{
				PRBool value;

				rc = machine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("nestedpaging", value);
				}
			}

			// unrestrictedexec
			{
				PRBool value;

				rc = machine->GetHWVirtExProperty(HWVirtExPropertyType_UnrestrictedExecution, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("unrestrictedexec", value);
				}
			}

			// largepages
			{
				PRBool value;

				rc = machine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("largepages", value);
				}
			}

			// force
			{
				PRBool value;

				rc = machine->GetHWVirtExProperty(HWVirtExPropertyType_Force, &value);
				if (NS_SUCCEEDED(rc)) {
					WRITEXMLBOOL("hwforce", value);
				}
			}

			// io cache
			ADDXMLBOOL(machine->GetIOCacheEnabled, "iocache");

			// io cache size
			ADDXMLINT32U(machine->GetIOCacheSize, "iocachesize");

			// chipset type
			ADDXMLENUM(machine->GetChipsetType, "chipset", chipsetTypeConverter);

			// pointing hid type
			ADDXMLENUM(machine->GetPointingHIDType, "mouse", pointingHidTypeConverter);

			// keyboard hid type
			ADDXMLENUM(machine->GetKeyboardHIDType, "keyboard", keyboardHidTypeConverter);

			// clipboard mode
			ADDXMLENUM(machine->GetClipboardMode, "clipboard", clipboardModeConverter);

			// vm state
			ADDXMLENUM(machine->GetState, "state", stateConverter);

			// vm state change
			ADDXMLTIMESTAMP(machine->GetLastStateChange, "statechanged");

			// teleporterenabled, teleporterport, teleporteraddress, teleporterpassword

			// storage controller
			{
				IStorageController **storageControllers = nsnull;
				PRUint32 storageControllersCount = 0;

				rc = machine->GetStorageControllers(&storageControllersCount, &storageControllers);
				if (NS_SUCCEEDED(rc)) {
					for (PRUint32 i = 0; i < storageControllersCount; i++) {
						exportVirtualBoxStorageController(storageControllers[i], i, writer);
					}
				}

				NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(storageControllersCount, storageControllers);
			}

			// medium attachments
			{
				IMediumAttachment **mediumAttachments = nsnull;
				PRUint32 mediumAttachmentsCount = 0;

				rc = machine->GetMediumAttachments(&mediumAttachmentsCount, &mediumAttachments);
				if (NS_SUCCEEDED(rc)) {
					for (PRUint32 i = 0; i < mediumAttachmentsCount; i++) {
						exportVirtualBoxMediumAttachment(mediumAttachments[i], writer);
					}
				}

				NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(mediumAttachmentsCount, mediumAttachments);
			}

			// network adapters
			{
				PRUint32 networkAdaptersCount;
				PRUint32 chipsetType;

				rc = machine->GetChipsetType(&chipsetType);
				if (NS_SUCCEEDED(rc)) {
					rc = systemProperties->GetMaxNetworkAdapters(chipsetType, &networkAdaptersCount);
					if (NS_SUCCEEDED(rc)) {
						for (PRUint32 i = 0; i < networkAdaptersCount; i++) {
							nsCOMPtr<INetworkAdapter> networkAdapter;

							rc = machine->GetNetworkAdapter(i, getter_AddRefs(networkAdapter));
							if (NS_SUCCEEDED(rc)) {
								exportVirtualBoxNetworkAdapter(networkAdapter, i + 1, writer);
							}
						}
					}
				}
			}

			// uartX

			// audio adapter
			{
				nsCOMPtr<IAudioAdapter> value;

				rc = machine->GetAudioAdapter(getter_AddRefs(value));
				if (NS_SUCCEEDED(rc)) {
					exportVirtualBoxAudioAdapter(value, writer);
				}
			}

			// vrde server
			{
				nsCOMPtr<IVRDEServer> value;

				rc = machine->GetVRDEServer(getter_AddRefs(value));
				if (NS_SUCCEEDED(rc)) {
					exportVirtualBoxVRDEServer(value, writer);
				}
			}

			// usb controllers
			// {
			// 	nsCOMPtr<IUSBController> value;

			// 	rc = machine->GetUSBController(getter_AddRefs(value));
			// 	if (NS_SUCCEEDED(rc)) {
			// 		exportVirtualBoxUSBController(value, writer);
			// 	}
			// }

			// guest properties
			{
				PRUnichar **names = nsnull;
				PRUnichar **values = nsnull;
				PRInt64 *timestamps = nsnull;
				PRUnichar **flags = nsnull;
				PRUint32 namesCount = 0;
				PRUint32 valuesCount = 0;
				PRUint32 timestampsCount = 0;
				PRUint32 flagsCount = 0;

				rc = machine->EnumerateGuestProperties((const PRUnichar*)nsnull, &namesCount, &names, &valuesCount, &values, &timestampsCount, &timestamps, &flagsCount, &flags);
				if (NS_SUCCEEDED(rc)) {
					for (PRUint32 i = 0; i < namesCount; i++) {
						nsAutoString name(names[i]);
						nsAutoString value(values[i]);
						PRUint64 timestamp = timestamps[i];
						nsAutoString flag(flags[i]);

						WRITEXMLSTRING(convertString(name).c_str(), convertString(value));
					}
				}

				NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(namesCount, names);
				NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(valuesCount, values);
				nsMemory::Free(timestamps);
				NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(flagsCount, flags);
			}

		xmlTextWriterEndElement(writer);
	}
}
NS_IMETHODIMP nsSMimeJSHelper::GetRecipientCertsInfo(
    nsIMsgCompFields *compFields,
    PRUint32 *count,
    PRUnichar ***emailAddresses,
    PRInt32 **certVerification,
    PRUnichar ***certIssuedInfos,
    PRUnichar ***certExpiresInfos,
    nsIX509Cert ***certs,
    PRBool *canEncrypt)
{
  NS_ENSURE_ARG_POINTER(count);
  *count = 0;

  NS_ENSURE_ARG_POINTER(emailAddresses);
  NS_ENSURE_ARG_POINTER(certVerification);
  NS_ENSURE_ARG_POINTER(certIssuedInfos);
  NS_ENSURE_ARG_POINTER(certExpiresInfos);
  NS_ENSURE_ARG_POINTER(certs);
  NS_ENSURE_ARG_POINTER(canEncrypt);

  NS_ENSURE_ARG_POINTER(compFields);

  PRUint32 mailbox_count;
  char *mailbox_list;

  nsresult rv = getMailboxList(compFields, &mailbox_count, &mailbox_list);
  if (NS_FAILED(rv))
    return rv;

  if (!mailbox_list)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIX509CertDB> certdb = do_GetService(NS_X509CERTDB_CONTRACTID);

  *count = mailbox_count;
  *canEncrypt = PR_FALSE;
  rv = NS_OK;

  if (mailbox_count)
  {
    PRUnichar **outEA = static_cast<PRUnichar **>(nsMemory::Alloc(mailbox_count * sizeof(PRUnichar *)));
    PRInt32 *outCV = static_cast<PRInt32 *>(nsMemory::Alloc(mailbox_count * sizeof(PRInt32)));
    PRUnichar **outCII = static_cast<PRUnichar **>(nsMemory::Alloc(mailbox_count * sizeof(PRUnichar *)));
    PRUnichar **outCEI = static_cast<PRUnichar **>(nsMemory::Alloc(mailbox_count * sizeof(PRUnichar *)));
    nsIX509Cert **outCerts = static_cast<nsIX509Cert **>(nsMemory::Alloc(mailbox_count * sizeof(nsIX509Cert *)));

    if (!outEA || !outCV || !outCII || !outCEI || !outCerts)
    {
      nsMemory::Free(outEA);
      nsMemory::Free(outCV);
      nsMemory::Free(outCII);
      nsMemory::Free(outCEI);
      nsMemory::Free(outCerts);
      rv = NS_ERROR_OUT_OF_MEMORY;
    }
    else
    {
      PRUnichar **iEA = outEA;
      PRInt32 *iCV = outCV;
      PRUnichar **iCII = outCII;
      PRUnichar **iCEI = outCEI;
      nsIX509Cert **iCert = outCerts;

      PRBool found_blocker = PR_FALSE;
      PRBool memory_failure = PR_FALSE;

      const char *walk = mailbox_list;

      // To understand this loop, especially the "+= strlen +1", look at the documentation
      // of ParseHeaderAddresses. Basically, it returns a list of zero terminated strings.
      for (PRUint32 i = 0;
          i < mailbox_count;
          ++i, ++iEA, ++iCV, ++iCII, ++iCEI, ++iCert, walk += strlen(walk) + 1)
      {
        *iCert = nsnull;
        *iCV = 0;
        *iCII = nsnull;
        *iCEI = nsnull;

        if (memory_failure) {
          *iEA = nsnull;
          continue;
        }

        nsDependentCString email(walk);
        *iEA = ToNewUnicode(email);
        if (!*iEA) {
          memory_failure = PR_TRUE;
          continue;
        }

        nsCString email_lowercase;
        ToLowerCase(email, email_lowercase);

        nsCOMPtr<nsIX509Cert> cert;
        if (NS_SUCCEEDED(certdb->FindCertByEmailAddress(nsnull, email_lowercase.get(), getter_AddRefs(cert)))
            && cert)
        {
          *iCert = cert;
          NS_ADDREF(*iCert);

          PRUint32 verification_result;

          if (NS_FAILED(
              cert->VerifyForUsage(nsIX509Cert::CERT_USAGE_EmailRecipient, &verification_result)))
          {
            *iCV = nsIX509Cert::NOT_VERIFIED_UNKNOWN;
            found_blocker = PR_TRUE;
          }
          else
          {
            *iCV = verification_result;

            if (verification_result != nsIX509Cert::VERIFIED_OK)
            {
              found_blocker = PR_TRUE;
            }
          }

          nsCOMPtr<nsIX509CertValidity> validity;
          rv = cert->GetValidity(getter_AddRefs(validity));

          if (NS_SUCCEEDED(rv)) {
            nsString id, ed;

            if (NS_SUCCEEDED(validity->GetNotBeforeLocalDay(id)))
            {
              *iCII = ToNewUnicode(id);
              if (!*iCII) {
                memory_failure = PR_TRUE;
                continue;
              }
            }

            if (NS_SUCCEEDED(validity->GetNotAfterLocalDay(ed)))
            {
              *iCEI = ToNewUnicode(ed);
              if (!*iCEI) {
                memory_failure = PR_TRUE;
                continue;
              }
            }
          }
        }
        else
        {
          found_blocker = PR_TRUE;
        }
      }

      if (memory_failure) {
        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mailbox_count, outEA);
        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mailbox_count, outCII);
        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mailbox_count, outCEI);
        NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(mailbox_count, outCerts);
        nsMemory::Free(outCV);
        rv = NS_ERROR_OUT_OF_MEMORY;
      }
      else {
        if (mailbox_count > 0 && !found_blocker)
        {
          *canEncrypt = PR_TRUE;
        }

        *emailAddresses = outEA;
        *certVerification = outCV;
        *certIssuedInfos = outCII;
        *certExpiresInfos = outCEI;
        *certs = outCerts;
      }
    }
  }

  if (mailbox_list) {
    nsMemory::Free(mailbox_list);
  }
  return rv;
}
예제 #10
0
nsresult
WSPProxy::ArrayXPTCMiniVariantToVariant(uint8 aTypeTag,
                                        nsXPTCMiniVariant aResult,
                                        PRUint32 aLength,
                                        nsIInterfaceInfo* aInterfaceInfo,
                                        nsIVariant** aVariant)
{
  nsresult rv;

  nsCOMPtr<nsIWritableVariant> retvar =
    do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }

  if (aLength) {
    PRUint32 i = 0;
    void* array = aResult.val.p;
    void* entries;
    nsISupports** entriesSup = nsnull;
    const nsIID* iid = nsnull;

    switch (aTypeTag) {
      case nsXPTType::T_I8:
      case nsXPTType::T_I16:
      case nsXPTType::T_I32:
      case nsXPTType::T_I64:
      case nsXPTType::T_U8:
      case nsXPTType::T_U16:
      case nsXPTType::T_U32:
      case nsXPTType::T_U64:
      case nsXPTType::T_FLOAT:
      case nsXPTType::T_DOUBLE:
      case nsXPTType::T_BOOL:
      case nsXPTType::T_CHAR:
      case nsXPTType::T_WCHAR:
      case nsXPTType::T_CHAR_STR:
      case nsXPTType::T_WCHAR_STR:
        entries = array;
        break;
      case nsXPTType::T_INTERFACE:
      {
        aInterfaceInfo->GetIIDShared(&iid);
        if (iid->Equals(NS_GET_IID(nsIVariant))) {
          entries = array;
        }
        else {
          entriesSup = (nsISupports**)nsMemory::Alloc(aLength *
                                                      sizeof(nsISupports*));
          if (!entriesSup) {
            return NS_ERROR_OUT_OF_MEMORY;
          }
          const nsIID& propbagIID = NS_GET_IID(nsIPropertyBag);
          iid = &propbagIID;
          entries = (void*)entriesSup;
          for(i = 0; i < aLength; i++) {
            nsISupports* instance = *((nsISupports**)array + i);
            nsISupports** outptr = entriesSup + i;
            if (instance) {
              nsCOMPtr<nsIPropertyBag> propBag;
              rv = WrapInPropertyBag(instance, aInterfaceInfo,
                                     getter_AddRefs(propBag));
              if (NS_FAILED(rv)) {
                break;
              }
              propBag->QueryInterface(NS_GET_IID(nsISupports),
                                      (void**)outptr);
            }
            else {
              *outptr = nsnull;
            }
          }
        }
        aTypeTag = nsXPTType::T_INTERFACE_IS;
        break;
      }
      default:
        NS_ERROR("Conversion of illegal array type");
        return NS_ERROR_FAILURE;
    }

    if (NS_SUCCEEDED(rv)) {
      rv = retvar->SetAsArray(aTypeTag, iid, aLength, entries);
    }

    if (entriesSup) {
      NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, entriesSup);
    }
  }
  else {
    retvar->SetAsEmpty();
  }

  if (NS_SUCCEEDED(rv)) {
    *aVariant = retvar;
    NS_ADDREF(*aVariant);
  }

  return rv;
}
예제 #11
0
/**
 * Asynchronous processing :
 * 1-> WSPProxy::CallMethod
 * 2  -> WSPCallContext::CallAsync
 * 3    -> nsSOAPCall::AsyncInvoke
 * 4      -> nsXXXSOAPTransport::AsyncCall
 * 5        -> nsIXMLHttpRequest::Send, nsXXXSOAPTransportCompletion::AddEventListener
 * ---- asynchronous ----
 * 6          -> nsXXXSOAPTransportCompletion::HandleEvent
 * 7            -> WSPCallContext::HandleResponse, 
 *                 WSPCallContext::CallCompletionListener
 * 8              -> nsSOAPBlock::SetSchemaType, nsSOAPBlock::GetValue
 * 9                -> nsSOAPEncoding::Decode, nsDefaultSOAPDecode::Decode
 * 10                 -> WSPProxy::CallCompleted
 */
NS_IMETHODIMP
WSPProxy::CallMethod(PRUint16 methodIndex,
                     const XPTMethodDescriptor* info,
                     nsXPTCMiniVariant* params)
{
  nsresult rv;
  nsCOMPtr<nsIWebServiceCallContext> cc;
  nsCOMPtr<nsIWSDLBinding> binding;

  if (methodIndex < 3) {
    NS_ERROR("WSPProxy: bad method index");
    return NS_ERROR_FAILURE;
  }

  // The first method in the interface for async callers is the
  // one to set the async listener
  if (mIsAsync && (methodIndex == 3)) {
    nsISupports* listener = static_cast<nsISupports*>(params[0].val.p);
    mAsyncListener = listener;
    return NS_OK;
  }

  PRUint32 methodOffset;
  if (mIsAsync) {
    methodOffset = 4;
  }
  else {
    methodOffset = 3;
  }

  nsCOMPtr<nsIWSDLOperation> operation;
  rv = mPort->GetOperation(methodIndex - methodOffset,
                           getter_AddRefs(operation));
  if (NS_FAILED(rv)) {
    return rv;
  }

  nsCOMPtr<nsIWSDLMessage> input;
  rv = operation->GetInput(getter_AddRefs(input));
  if (NS_FAILED(rv)) {
    return rv;
  }

  // Create the call instance
  nsCOMPtr<nsISOAPCall> call = do_CreateInstance(NS_SOAPCALL_CONTRACTID, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }

  nsCOMPtr<nsISOAPEncoding> encoding =
    do_CreateInstance(NS_SOAPENCODING_CONTRACTID, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }
  call->SetEncoding(encoding);

  // Get the method name and target object uri
  nsAutoString methodName, targetObjectURI;
  rv = operation->GetBinding(getter_AddRefs(binding));
  if (NS_FAILED(rv)) {
    return rv;
  }

  nsCOMPtr<nsISOAPOperationBinding> operationBinding =
    do_QueryInterface(binding, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }

  nsAutoString soapAction;
  operationBinding->GetSoapAction(soapAction);
  call->SetActionURI(soapAction);

  PRUint16 style;
  operationBinding->GetStyle(&style);
  // If the style is RPC, find the method name and target object URI.
  // If it is document-style, these are both left blank.
  if (style == nsISOAPPortBinding::STYLE_RPC) {
    operation->GetName(methodName);
    rv = input->GetBinding(getter_AddRefs(binding));
    if (NS_FAILED(rv)) {
      return rv;
    }
    nsCOMPtr<nsISOAPMessageBinding> messageBinding =
      do_QueryInterface(binding, &rv);
    if (NS_FAILED(rv)) {
      return rv;
    }
    messageBinding->GetNamespace(targetObjectURI);
  }

  // Set the transport URI
  rv = mPort->GetBinding(getter_AddRefs(binding));
  if (NS_FAILED(rv)) {
    return rv;
  }
  nsCOMPtr<nsISOAPPortBinding> portBinding = do_QueryInterface(binding, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }

  nsAutoString address;
  portBinding->GetAddress(address);
  rv = call->SetTransportURI(address);
  if (NS_FAILED(rv)) {
    return rv;
  }

  PRUint16 version;
  portBinding->GetSoapVersion(&version);
  if (version == nsISOAPMessage::VERSION_UNKNOWN) {
    version = nsISOAPMessage::VERSION_1_1;
  }

  // Set up the parameters to the call
  PRUint32 i, partCount;
  input->GetPartCount(&partCount);

  PRUint32 maxParamIndex = info->num_args - 1;

  // Iterate through the parts to figure out how many are
  // body vs. header blocks
  nsCOMPtr<nsIWSDLPart> part;
  PRUint32 headerCount = 0, bodyCount = 0;

  for (i = 0; i < partCount; i++) {
    rv = input->GetPart(i, getter_AddRefs(part));
    if (NS_FAILED(rv)) {
      return rv;
    }

    rv = part->GetBinding(getter_AddRefs(binding));
    if (NS_FAILED(rv)) {
      return rv;
    }

    nsCOMPtr<nsISOAPPartBinding> partBinding = do_QueryInterface(binding, &rv);
    if (NS_FAILED(rv)) {
      return rv;
    }

    PRUint16 location;
    partBinding->GetLocation(&location);
    if (location == nsISOAPPartBinding::LOCATION_HEADER) {
      headerCount++;
    }
    else if (location == nsISOAPPartBinding::LOCATION_BODY) {
      bodyCount++;
    }
  }

  // Allocate parameter and header blocks
  nsISOAPParameter** bodyBlocks = nsnull;
  if (bodyCount) {
    bodyBlocks = static_cast<nsISOAPParameter**>
                            (nsMemory::Alloc(bodyCount * sizeof(nsISOAPParameter*)));
    if (!bodyBlocks) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    for (i = 0; i < bodyCount; i++) {
      rv = CallCreateInstance(NS_SOAPPARAMETER_CONTRACTID, &bodyBlocks[i]);
      if (NS_FAILED(rv)) {
        NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, bodyBlocks);

        return rv;
      }
    }
  }

  nsISOAPHeaderBlock** headerBlocks = nsnull;
  if (headerCount) {
    headerBlocks = static_cast<nsISOAPHeaderBlock**>
                              (nsMemory::Alloc(headerCount * sizeof(nsISOAPHeaderBlock*)));
    if (!headerBlocks) {
      if (bodyBlocks) {
        NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(bodyCount, bodyBlocks);
      }
      return NS_ERROR_OUT_OF_MEMORY;
    }
    for (i = 0; i < headerCount; i++) {
      rv = CallCreateInstance(NS_SOAPHEADERBLOCK_CONTRACTID, &headerBlocks[i]);
      if (NS_FAILED(rv)) {
        if (bodyBlocks) {
          NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(bodyCount, bodyBlocks);
        }
        NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, headerBlocks);

        return rv;
      }
    }
  }

  // Now iterate through the parameters and set up the parameter blocks
  PRUint32 bodyEntry = 0, headerEntry = 0, paramIndex = 0;
  for (i = 0; i < partCount; paramIndex++, i++) {
    input->GetPart(i, getter_AddRefs(part));
    part->GetBinding(getter_AddRefs(binding));
    nsCOMPtr<nsISOAPPartBinding> partBinding = do_QueryInterface(binding);
    PRUint16 location;
    partBinding->GetLocation(&location);

    nsCOMPtr<nsISOAPBlock> block;
    if (location == nsISOAPPartBinding::LOCATION_HEADER) {
      block = do_QueryInterface(headerBlocks[headerEntry++]);
    }
    else if (location == nsISOAPPartBinding::LOCATION_BODY) {
      block = do_QueryInterface(bodyBlocks[bodyEntry++]);
    }

    if (!block) {
      rv = NS_ERROR_FAILURE;
      goto call_method_end;
    }

    // Get the name, namespaceURI and type of the block based on
    // information from the WSDL part. If the schema component
    // associated with the part is an element, these values come
    // from the schema description of the element. If it is a
    // type, then the values are gathered from elsewhere.
    nsCOMPtr<nsISchemaComponent> schemaComponent;
    rv = part->GetSchemaComponent(getter_AddRefs(schemaComponent));
    if (NS_FAILED(rv)) {
      goto call_method_end;
    }

    nsCOMPtr<nsISchemaType> type;
    nsAutoString blockName, blockNamespace;
    nsCOMPtr<nsISchemaElement> element = do_QueryInterface(schemaComponent);

    if (element) {
      rv = element->GetType(getter_AddRefs(type));
      if (NS_FAILED(rv)) {
        goto call_method_end;
      }

      element->GetName(blockName);
      element->GetTargetNamespace(blockNamespace);
    }
    else {
      type = do_QueryInterface(schemaComponent);

      nsAutoString paramName;
      part->GetName(paramName);

      blockName.Assign(paramName);
      partBinding->GetNamespace(blockNamespace);
    }

    block->SetName(blockName);
    block->SetNamespaceURI(blockNamespace);
    block->SetSchemaType(type);

    nsAutoString encodingStyle;
    PRUint16 use;

    partBinding->GetUse(&use);
    // XXX Need a way to specify that a block should not be
    // encoded.
    if (use == nsISOAPPartBinding::USE_ENCODED) {
      partBinding->GetEncodingStyle(encodingStyle);
      if (!encodingStyle.IsEmpty()) {
        nsCOMPtr<nsISOAPEncoding> partEncoding;
        encoding->GetAssociatedEncoding(encodingStyle, PR_FALSE,
                                        getter_AddRefs(partEncoding));
        block->SetEncoding(partEncoding);
      }
    }

    // Look ahead in the param info array to see if the current part has to be
    // treated as an array. If so then get the array length from the current
    // param and increment the param index.

    PRUint32 arrayLength;

    if (paramIndex < maxParamIndex &&
        nsXPTType(info->params[paramIndex + 1].type.prefix).IsArray()) {
      arrayLength = params[paramIndex++].val.u32;
    }
    else {
      arrayLength = 0;
    }

    NS_ASSERTION(paramIndex <= maxParamIndex,
                 "WSDL/IInfo param count mismatch");

    const nsXPTParamInfo& paramInfo = info->params[paramIndex];

    nsCOMPtr<nsIVariant> value;
    rv = ParameterToVariant(mPrimaryInterface, methodIndex,
                            &paramInfo, params[paramIndex],
                            arrayLength, getter_AddRefs(value));
    if (NS_FAILED(rv)) {
      goto call_method_end;
    }

    block->SetValue(value);
  }

  // Encode the parameters to the call
  rv = call->Encode(version,
                    methodName, targetObjectURI,
                    headerCount, headerBlocks,
                    bodyCount, bodyBlocks);
  if (NS_FAILED(rv)) {
    goto call_method_end;
  }

  WSPCallContext* ccInst;
  ccInst = new WSPCallContext(this, call, methodName, operation);
  if (!ccInst) {
    rv = NS_ERROR_OUT_OF_MEMORY;
    goto call_method_end;
  }
  cc = ccInst;

  if (mIsAsync) {
    PRUint8 pcount;
    pcount = info->num_args;
    // There has to be at least one parameter - the retval.
    if (pcount == 0) {
      rv = NS_ERROR_FAILURE;
      goto call_method_end;
    }

#ifdef DEBUG
    // The last one should be the retval.
    const nsXPTParamInfo& retParamInfo = info->params[pcount - 1];
    if (!retParamInfo.IsRetval()) {
      rv = NS_ERROR_FAILURE;
      goto call_method_end;
    }

    // It should be an interface pointer
    const nsXPTType& retType = retParamInfo.GetType();
    if (!retType.IsInterfacePointer()) {
      rv = NS_ERROR_FAILURE;
      goto call_method_end;
    }
#endif

    nsIWebServiceCallContext** retval =
      static_cast<nsIWebServiceCallContext**>(params[pcount-1].val.p);
    if (!retval) {
      rv = NS_ERROR_FAILURE;
      goto call_method_end;
    }
    *retval = cc;
    NS_ADDREF(*retval);

    rv = ccInst->CallAsync(methodIndex, mAsyncListener);
    if (NS_FAILED(rv)) {
      goto call_method_end;
    }

    mPendingCalls.AppendObject(ccInst);
  }
  else {
    rv = ccInst->CallSync(methodIndex, params);
  }

call_method_end:
  if (bodyBlocks) {
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(bodyCount, bodyBlocks);
  }
  if (headerBlocks) {
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(headerCount, headerBlocks);
  }
  return rv;
}
예제 #12
0
nsresult
WSPProxy::VariantToArrayValue(uint8 aTypeTag,
                              nsXPTCMiniVariant* aResultSize,
                              nsXPTCMiniVariant* aResultArray,
                              nsIInterfaceInfo* aInterfaceInfo,
                              nsIVariant* aProperty)
{
  void* array;
  PRUint16 type;
  PRUint32 count;

  nsIID arrayIID;
  nsresult rv = aProperty->GetAsArray(&type, &arrayIID, &count, &array);
  if (NS_FAILED(rv)) {
    return rv;
  }

  aResultSize->val.u32 = count;

  switch (aTypeTag) {
    case nsXPTType::T_I8:
    case nsXPTType::T_U8:
    case nsXPTType::T_I16:
    case nsXPTType::T_U16:
    case nsXPTType::T_I32:
    case nsXPTType::T_U32:
    case nsXPTType::T_I64:
    case nsXPTType::T_U64:
    case nsXPTType::T_FLOAT:
    case nsXPTType::T_DOUBLE:
    case nsXPTType::T_BOOL:
    case nsXPTType::T_CHAR:
    case nsXPTType::T_WCHAR:
    case nsXPTType::T_CHAR_STR:
    case nsXPTType::T_WCHAR_STR:
      aResultArray->val.p = array;
      break;
    case nsXPTType::T_INTERFACE:
    case nsXPTType::T_INTERFACE_IS:
    {
      if (arrayIID.Equals(NS_GET_IID(nsIVariant))) {
        aResultArray->val.p = array;
      }
      else if (!arrayIID.Equals(NS_GET_IID(nsIPropertyBag))) {
        NS_ERROR("Array of complex types should be represented by property "
                 "bags");
        return NS_ERROR_FAILURE;
      }
      else {
        nsISupports** outptr =
          (nsISupports**)nsMemory::Alloc(count * sizeof(nsISupports*));
        if (!outptr) {
          return NS_ERROR_OUT_OF_MEMORY;
        }
        nsISupports** arraySup = (nsISupports**)array;
        const nsIID* iid;
        aInterfaceInfo->GetIIDShared(&iid);
        PRUint32 i;
        for (i = 0; i < count; i++) {
          nsCOMPtr<nsIPropertyBag> propBag(do_QueryInterface(arraySup[i]));
          if (!propBag) {
            *(outptr + i) = nsnull;
          }
          else {
            nsCOMPtr<nsISupports> wrapper;
            rv = WrapInComplexType(propBag, aInterfaceInfo,
                                   getter_AddRefs(wrapper));
            if (NS_FAILED(rv)) {
              NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, outptr);
              return rv;
            }
            rv = wrapper->QueryInterface(*iid, (void**)(outptr + i));
            if (NS_FAILED(rv)) {
              NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(i, outptr);
              return rv;
            }
          }
        }
        aResultArray->val.p = outptr;
      }
      break;
    }
    default:
      NS_ERROR("Conversion of illegal array type");
      return NS_ERROR_FAILURE;
  }

  return NS_OK;
}