Esempio n. 1
0
static PRBool
CheckVersion(const PRUnichar* toCheck,
             const GREVersionRange *versions,
             PRUint32 versionsLength)
{
  for (const GREVersionRange *versionsEnd = versions + versionsLength;
       versions < versionsEnd;
       ++versions) {
      AutoWString wlower(ConvertUTF8toNewUTF16(versions->lower));
      PRInt32 c = NS_CompareVersions(toCheck, wlower);
      if (c < 0)
        continue;

      if (!c && !versions->lowerInclusive)
        continue;

      AutoWString wupper(ConvertUTF8toNewUTF16(versions->upper));
      c = NS_CompareVersions(toCheck, wupper);
      if (c > 0)
        continue;

      if (!c && !versions->upperInclusive)
        continue;

      return PR_TRUE;
  }

  return PR_FALSE;
}
Esempio n. 2
0
static PRBool
CheckVersion(const char* toCheck,
             const GREVersionRange *versions,
             PRUint32 versionsLength)
{
  
  for (const GREVersionRange *versionsEnd = versions + versionsLength;
       versions < versionsEnd;
       ++versions) {
    PRInt32 c = NS_CompareVersions(toCheck, versions->lower);
    if (c < 0)
      continue;

    if (!c && !versions->lowerInclusive)
      continue;

    c = NS_CompareVersions(toCheck, versions->upper);
    if (c > 0)
      continue;

    if (!c && !versions->upperInclusive)
      continue;

    return PR_TRUE;
  }

  return PR_FALSE;
}
Esempio n. 3
0
// Compares the current application version with the update's application
// version.
static PRBool
IsOlderVersion(nsILocalFile *versionFile, const char *&appVersion)
{
    nsresult rv;

    FILE *fp;
    rv = versionFile->OpenANSIFileDesc("r", &fp);
    if (NS_FAILED(rv))
        return PR_TRUE;

    char buf[32];
    char *result = fgets(buf, sizeof(buf), fp);
    fclose(fp);
    if (!result)
        return PR_TRUE;

    // Trim off any trailing newline
    int len = strlen(result);
    if (len > 0 && result[len - 1] == '\n')
        result[len - 1] = '\0';

    // If the update xml doesn't provide the application version the file will
    // contain the string "null" and it is assumed that the update is not older.
    const char kNull[] = "null";
    if (strncmp(buf, kNull, sizeof(kNull) - 1) == 0)
        return PR_FALSE;

    if (NS_CompareVersions(appVersion, result) > 0)
        return PR_TRUE;

    return PR_FALSE;
}
int main(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <versionA> <versionB>\n", argv[0]);
    return 1;
  }

  PRInt32 i = NS_CompareVersions(argv[1], argv[2]);

  char *format;

  if (i < 0)
    format = "%s < %s\n";
  else if (i > 0)
    format = "%s > %s\n";
  else
    format = "%s = %s\n";

  fprintf(stdout, format, argv[1], argv[2]);
  return 0;
}
nsresult sbDeviceXMLInfo::Read(nsIDOMDocument* aDeviceXMLInfoDocument)
{
  // Validate arguments.
  NS_ENSURE_ARG_POINTER(aDeviceXMLInfoDocument);

  // Function variables.
  nsresult rv;

  // Get the list of all device info elements.
  nsCOMPtr<nsIDOMNodeList> nodeList;
  rv = aDeviceXMLInfoDocument->GetElementsByTagNameNS
                                 (NS_LITERAL_STRING(SB_DEVICE_INFO_NS),
                                  NS_LITERAL_STRING("deviceinfo"),
                                  getter_AddRefs(nodeList));
  NS_ENSURE_SUCCESS(rv, rv);

  // Search all device info elements for one that matches target device.
  PRUint32 nodeCount;
  rv = nodeList->GetLength(&nodeCount);
  NS_ENSURE_SUCCESS(rv, rv);
  for (PRUint32 i = 0; i < nodeCount; i++) {
    // Get the next device info element.
    nsCOMPtr<nsIDOMNode> node;
    rv = nodeList->Item(i, getter_AddRefs(node));
    NS_ENSURE_SUCCESS(rv, rv);

    // Use device info node if it matches target device and is
    // newer than any previous match
    nsString foundVersion;
    nsCOMPtr<nsIDOMNode> deviceNode;
    rv = DeviceMatchesDeviceInfoNode(node,
                                     foundVersion,
                                     getter_AddRefs(deviceNode));
    NS_ENSURE_SUCCESS(rv, rv);
    if (foundVersion.IsEmpty()) {
      // Not a match
      continue;
    }

    if (mDeviceInfoVersion.IsEmpty() ||
        NS_CompareVersions(
          NS_LossyConvertUTF16toASCII(foundVersion).get(),
          NS_LossyConvertUTF16toASCII(mDeviceInfoVersion).get()) > 0)
    {
      // Found version is greater than current version, if any.  Keep this
      // node and replace any previously found node

      // Log the found device info if logging enabled
      if (mLogDeviceInfo) {
        nsCOMPtr<nsIDOMSerializer> serializer =
            do_CreateInstance("@mozilla.org/xmlextras/xmlserializer;1");

        // Translate the found deviceinfo element to XML
        nsString fullXml(NS_LITERAL_STRING("<ERROR PRINTING deviceinfo NODE>"));
        if (serializer) {
          serializer->SerializeToString(node, fullXml);
        }

        // Translate the device element matching this device to XML, if any
        nsString deviceXml(NS_LITERAL_STRING("<ERROR PRINTING device NODE>"));
        if (deviceNode && serializer) {
          serializer->SerializeToString(deviceNode, deviceXml);
        }

        nsCAutoString curVersUtf8 = NS_ConvertUTF16toUTF8(mDeviceInfoVersion);
        nsCAutoString foundVersUtf8 = NS_ConvertUTF16toUTF8(foundVersion);

        // Log the device info and version.  The first line has two
        // alternate forms, depending on whether the existing device
        // info is being replaced:
        //
        //  FOUND    deviceinfo version                        <found version>:
        // - OR -
        //  REPLACED deviceinfo version <current version> with <found version>:

        Log("%s deviceinfo version %s%s%s:\n%s%s%s",
            mDeviceInfoElement ?      "REPLACED"       :   "FOUND",
            curVersUtf8.get(),    //  current version  OR  blank
            mDeviceInfoElement ?      " with "         :   "",
            foundVersUtf8.get(),  //  found version    OR  found version

            NS_ConvertUTF16toUTF8(fullXml).get(),

            deviceNode ? "\n\nMATCHING device element:\n" : "",
            deviceNode ? NS_ConvertUTF16toUTF8(deviceXml).get() : "");
      }

      mDeviceInfoVersion.Assign(foundVersion);
      mDeviceInfoElement = do_QueryInterface(node, &rv);
      NS_ENSURE_SUCCESS(rv, rv);
      if (deviceNode) {
        mDeviceElement = do_QueryInterface(deviceNode, &rv);
        NS_ENSURE_SUCCESS(rv, rv);
      }
      else {
        mDeviceElement = nsnull;
      }
    }
  }

  return NS_OK;
}