Пример #1
0
  public static boolean hasFullLicence() {
    if (featman == null) {
      // Debug.out("featman null");
      Set<String> featuresInstalled = UtilitiesImpl.getFeaturesInstalled();
      return featuresInstalled.contains("dvdburn");
    }

    boolean full = false;
    FeatureDetails[] featureDetails = featman.getFeatureDetails("dvdburn");
    // if any of the feature details are still valid, we have a full
    for (FeatureDetails fd : featureDetails) {
      int state = fd.getLicence().getState();
      if (state == Licence.LS_CANCELLED || state == Licence.LS_REVOKED) {
        continue;
      }
      long now = SystemTime.getCurrentTime();
      Long lValidUntil = (Long) fd.getProperty(FeatureDetails.PR_VALID_UNTIL);
      if (lValidUntil != null && lValidUntil.longValue() >= now) {
        full = true;
        break;
      }
      Long lValidOfflineUntil = (Long) fd.getProperty(FeatureDetails.PR_OFFLINE_VALID_UNTIL);
      if (lValidOfflineUntil != null && lValidOfflineUntil.longValue() >= now) {
        full = true;
        break;
      }
    }

    return full;
  }
Пример #2
0
 public static long getExpiresOn(TOTorrent torrent) {
   Map mapContent = getContentMap(torrent);
   Long l = (Long) mapContent.get(TOR_AZ_PROP_EXPIRESON);
   if (l == null) {
     return 0;
   }
   return l.longValue();
 }
Пример #3
0
 public static long getMetaDataRefreshOn(TOTorrent torrent) {
   Map mapContent = getTempContentMap(torrent);
   Long l = (Long) mapContent.get(TOR_AZ_PROP_METADATA_REFRESHON);
   if (l == null) {
     return 0;
   }
   return l.longValue();
 }
Пример #4
0
 /**
  * @param torrent
  * @return -1: No rating
  */
 public static int getUserRating(TOTorrent torrent) {
   Map mapContent = getTempContentMap(torrent);
   Long l = (Long) mapContent.get(TOR_AZ_PROP_USER_RATING);
   if (l == null) {
     return -1;
   }
   return l.intValue();
 }
Пример #5
0
 private static long getRemainingUses(FeatureDetails fd) {
   if (fd == null) {
     return 0;
   }
   Long lRemainingUses = (Long) fd.getProperty(FeatureDetails.PR_TRIAL_USES_REMAINING);
   long remainingUses = lRemainingUses == null ? -1 : lRemainingUses.longValue();
   return remainingUses;
 }
 private boolean notifyParameterListenersIfChanged(
     String parameter, Long newValue, Long oldValue) {
   if (oldValue == null || 0 != newValue.compareTo(oldValue)) {
     notifyParameterListeners(parameter);
     return true;
   }
   return false;
 }
Пример #7
0
  protected void writeGeneric(Long l) {
    if (generic_simple) {

      writeLineRaw(l.toString());

    } else {
      writeTag("LONG", "" + l);
    }
  }
Пример #8
0
  private static long getContentMapLong(TOTorrent torrent, String key, long def) {
    if (torrent == null) {
      return def;
    }

    Map mapContent = getContentMap(torrent);
    Object obj = mapContent.get(key);

    try {
      if (obj instanceof Long) {
        return ((Long) obj).longValue();
      } else if (obj instanceof Integer) {
        return ((Integer) obj).longValue();
      } else if (obj instanceof String) {
        return Long.parseLong((String) obj);
      } else if (obj instanceof byte[]) {
        return Long.parseLong(new String((byte[]) obj));
      }
    } catch (Exception e) {
    }

    return def;
  }
Пример #9
0
  public static licenceDetails getFullFeatureDetails() {
    if (featman == null) {
      Debug.out("featman null");
      return null;
    }

    FeatureDetails[] featureDetails = featman.getFeatureDetails("dvdburn");
    // if any of the feature details are still valid, we have a full
    for (FeatureDetails fd : featureDetails) {
      long now = SystemTime.getCurrentTime();
      Long lValidUntil = (Long) fd.getProperty(FeatureDetails.PR_VALID_UNTIL);
      if (lValidUntil != null && lValidUntil.longValue() >= now) {
        return new licenceDetails(
            lValidUntil.longValue(), fd.getLicence().getKey(), fd.getLicence().getState());
      }
      Long lValidOfflineUntil = (Long) fd.getProperty(FeatureDetails.PR_OFFLINE_VALID_UNTIL);
      if (lValidOfflineUntil != null && lValidOfflineUntil.longValue() >= now) {
        return new licenceDetails(
            lValidOfflineUntil.longValue(), fd.getLicence().getKey(), fd.getLicence().getState());
      }
    }

    Licence bestLicence = null;
    Licence[] licences = featman.getLicences();
    for (Licence licence : licences) {
      FeatureDetails[] details = licence.getFeatures();
      boolean isTrial = false;
      for (FeatureDetails fd : details) {
        Object property = fd.getProperty(FeatureDetails.PR_IS_TRIAL);
        if ((property instanceof Number) && ((Number) property).intValue() == 1) {
          isTrial = true;
          break;
        }
      }
      if (isTrial) {
        continue;
      }
      int state = licence.getState();
      if (state == Licence.LS_AUTHENTICATED) {
        bestLicence = licence;
        break;
      } else {
        bestLicence = licence;
      }
    }

    if (bestLicence != null) {
      return new licenceDetails(0, bestLicence.getKey(), bestLicence.getState());
    }

    return null;
  }
  public long getFeatureFlags() {
    long now = SystemTime.getCurrentTime();

    if (now > last_feature_flag_cache_time && now - last_feature_flag_cache_time < 60000) {

      return (last_feature_flag_cache);
    }

    Map m = getMostRecentVersionCheckData();

    long result;

    if (m == null) {

      result = 0;

    } else {

      byte[] b_feat_flags = (byte[]) m.get("feat_flags");

      if (b_feat_flags != null) {

        try {

          result = Long.parseLong(new String((byte[]) b_feat_flags));

        } catch (Throwable e) {

          result = 0;
        }
      } else {

        result = 0;
      }
    }

    last_feature_flag_cache = result;
    last_feature_flag_cache_time = now;

    return (result);
  }
Пример #11
0
  public static licenceDetails getFullFeatureDetails() {
    if (featman == null) {
      Debug.out("featman null");
      return null;
    }

    TreeMap<Long, Object[]> mapOrder = new TreeMap<Long, Object[]>(Collections.reverseOrder());
    FeatureDetails[] featureDetails = featman.getFeatureDetails("dvdburn");
    // if any of the feature details are still valid, we have a full
    for (FeatureDetails fd : featureDetails) {
      Licence licence = fd.getLicence();
      int state = licence.getState();
      if (state == Licence.LS_ACTIVATION_DENIED) {
        mapOrder.put(-1L, new Object[] {licence, Long.valueOf(0)});
        continue;
      } else if (state == Licence.LS_CANCELLED) {
        mapOrder.put(-2L, new Object[] {licence, Long.valueOf(0)});
        continue;
      } else if (state == Licence.LS_INVALID_KEY) {
        mapOrder.put(-3L, new Object[] {licence, Long.valueOf(0)});
        continue;
      } else if (state == Licence.LS_REVOKED) {
        mapOrder.put(-4L, new Object[] {licence, Long.valueOf(0)});
        continue;
      } else if (state == Licence.LS_PENDING_AUTHENTICATION) {
        mapOrder.put(-6L, new Object[] {licence, Long.valueOf(0)});
        continue;
      }

      long now = SystemTime.getCurrentTime();
      Long lValidUntil = (Long) fd.getProperty(FeatureDetails.PR_VALID_UNTIL);
      Long lValidOfflineUntil = (Long) fd.getProperty(FeatureDetails.PR_OFFLINE_VALID_UNTIL);

      if (lValidUntil == null && lValidOfflineUntil == null) {
        continue;
      }

      long minValidUntil = -1;
      long maxValidUntil = -1;
      if (lValidUntil != null) {
        minValidUntil = maxValidUntil = lValidUntil.longValue();
        if (minValidUntil < now) {
          mapOrder.put(minValidUntil, new Object[] {licence, Long.valueOf(minValidUntil)});
          continue;
        }
      }
      if (lValidOfflineUntil != null) {
        long validOfflineUntil = lValidOfflineUntil.longValue();
        if (validOfflineUntil < now) {
          mapOrder.put(validOfflineUntil, new Object[] {licence, Long.valueOf(maxValidUntil)});
          continue;
        }
        if (maxValidUntil == -1 || validOfflineUntil > maxValidUntil) {
          maxValidUntil = validOfflineUntil;
        }
      }

      mapOrder.put(maxValidUntil, new Object[] {licence, minValidUntil});
    }

    if (mapOrder.size() == 0) {
      return null;
    }

    Long firstKey = mapOrder.firstKey();
    Object[] objects = mapOrder.get(firstKey);
    Licence licence = (Licence) objects[0];
    return new licenceDetails(firstKey.longValue(), ((Long) objects[1]).longValue(), licence);
  }
 public long getLongParameter(String parameter, long defaultValue) {
   Long tempValue = getLongParameterRaw(parameter);
   return tempValue != null ? tempValue.longValue() : defaultValue;
 }
 public int getIntParameter(String parameter, int defaultValue) {
   Long tempValue = getLongParameterRaw(parameter);
   return tempValue != null ? tempValue.intValue() : defaultValue;
 }
Пример #14
0
 public long getPersistentLongProperty(String prop, long def) {
   return (Long.parseLong(getPersistentStringProperty(prop, String.valueOf(def))));
 }
Пример #15
0
 public static boolean isTrial(FeatureDetails fd) {
   Long lIsTrial = (Long) fd.getProperty(FeatureDetails.PR_IS_TRIAL);
   return lIsTrial == null ? false : lIsTrial.longValue() != 0;
 }
  public long[] getTotalUsageInPeriod(Date start_date, Date end_date) {
    synchronized (this) {
      long[] result = new long[STAT_ENTRY_COUNT];

      long start_millis = start_date.getTime();
      long end_millis = end_date.getTime();

      long now = SystemTime.getCurrentTime();

      long now_day = (now / DAY_IN_MILLIS) * DAY_IN_MILLIS;

      if (end_millis > now) {

        end_millis = now;
      }

      long start_day = (start_millis / DAY_IN_MILLIS) * DAY_IN_MILLIS;
      long end_day = (end_millis / DAY_IN_MILLIS) * DAY_IN_MILLIS;

      if (start_day > end_day) {

        return (result);
      }

      long start_offset = start_millis - start_day;

      start_offset = start_offset / MIN_IN_MILLIS;

      boolean offset_cachable = start_offset % 60 == 0;

      System.out.println(
          "start="
              + debug_utc_format.format(start_date)
              + ", end="
              + debug_utc_format.format(end_date)
              + ", offset="
              + start_offset);

      MonthCache month_cache = null;

      for (long this_day = start_day; this_day <= end_day; this_day += DAY_IN_MILLIS) {

        String[] bits = utc_date_format.format(new Date(this_day)).split(",");

        String year_str = bits[0];
        String month_str = bits[1];
        String day_str = bits[2];

        int year = Integer.parseInt(year_str);
        int month = Integer.parseInt(month_str);
        int day = Integer.parseInt(day_str);

        if (month_cache == null || !month_cache.isForMonth(year_str, month_str)) {

          if (month_cache != null && month_cache.isDirty()) {

            month_cache.save();
          }

          month_cache = getMonthCache(year_str, month_str);
        }

        boolean can_cache =
            this_day != now_day
                && (this_day > start_day || (this_day == start_day && offset_cachable))
                && this_day < end_day;

        long cache_offset = this_day == start_day ? start_offset : 0;

        if (can_cache) {

          long[] cached_totals = month_cache.getTotals(day, cache_offset);

          if (cached_totals != null) {

            for (int i = 0; i < cached_totals.length; i++) {

              result[i] += cached_totals[i];
            }

            continue;
          }
        } else {

          if (this_day == now_day) {

            if (day_cache != null) {

              if (day_cache.isForDay(year_str, month_str, day_str)) {

                long[] cached_totals = day_cache.getTotals(cache_offset);

                if (cached_totals != null) {

                  for (int i = 0; i < cached_totals.length; i++) {

                    result[i] += cached_totals[i];
                  }

                  continue;
                }

              } else {

                day_cache = null;
              }
            }
          }
        }

        String current_rel_file =
            bits[0] + File.separator + bits[1] + File.separator + bits[2] + ".dat";

        File stats_file = new File(stats_dir, current_rel_file);

        if (!stats_file.exists()) {

          if (can_cache) {

            month_cache.setTotals(day, cache_offset, new long[0]);
          }
        } else {

          LineNumberReader lnr = null;

          try {
            System.out.println("Reading " + stats_file);

            lnr = new LineNumberReader(new FileReader(stats_file));

            long file_start_time = 0;

            long[] file_totals = null;

            long[] file_result_totals = new long[STAT_ENTRY_COUNT];

            long[] session_start_stats = null;
            long session_start_time = 0;
            long session_time = 0;

            while (true) {

              String line = lnr.readLine();

              if (line == null) {

                break;
              }

              // System.out.println( line );

              String[] fields = line.split(",");

              if (fields.length < 6) {

                continue;
              }

              String first_field = fields[0];

              if (first_field.equals("s")) {

                session_start_time = Long.parseLong(fields[2]) * MIN_IN_MILLIS;

                if (file_totals == null) {

                  file_totals = new long[STAT_ENTRY_COUNT];

                  file_start_time = session_start_time;
                }

                session_time = session_start_time;

                session_start_stats = new long[STAT_ENTRY_COUNT];

                for (int i = 3; i < 9; i++) {

                  session_start_stats[i - 3] = Long.parseLong(fields[i]);
                }
              } else if (session_start_time > 0) {

                session_time += MIN_IN_MILLIS;

                int field_offset = 0;

                if (first_field.equals("e")) {

                  field_offset = 3;
                }

                long[] line_stats = new long[STAT_ENTRY_COUNT];

                for (int i = 0; i < 6; i++) {

                  line_stats[i] = Long.parseLong(fields[i + field_offset]);

                  file_totals[i] += line_stats[i];
                }

                if (session_time >= start_millis && session_time <= end_millis) {

                  for (int i = 0; i < 6; i++) {

                    result[i] += line_stats[i];

                    file_result_totals[i] += line_stats[i];
                  }
                }

                // System.out.println( getString( line_stats ));
              }
            }

            System.out.println(
                "File total: start="
                    + debug_utc_format.format(file_start_time)
                    + ", end="
                    + debug_utc_format.format(session_time)
                    + " - "
                    + getString(file_totals));

            if (can_cache) {

              month_cache.setTotals(day, cache_offset, file_result_totals);

              if (cache_offset != 0) {

                month_cache.setTotals(day, 0, file_totals);
              }
            } else {

              if (this_day == now_day) {

                if (day_cache == null) {

                  System.out.println("Creating day cache");

                  day_cache = new DayCache(year_str, month_str, day_str);
                }

                day_cache.setTotals(cache_offset, file_result_totals);

                if (cache_offset != 0) {

                  day_cache.setTotals(0, file_totals);
                }
              }
            }

          } catch (Throwable e) {

            Debug.out(e);

          } finally {

            if (lnr != null) {

              try {
                lnr.close();

              } catch (Throwable e) {
              }
            }
          }
        }
      }

      if (month_cache != null && month_cache.isDirty()) {

        month_cache.save();
      }

      System.out.println("    -> " + getString(result));

      return (result);
    }
  }
  protected void preProcessReply(Map reply, final boolean v6) {
    NetworkAdmin admin = NetworkAdmin.getSingleton();

    try {
      byte[] address = (byte[]) reply.get("source_ip_address");

      InetAddress my_ip = InetAddress.getByName(new String(address));

      NetworkAdminASN old_asn = admin.getCurrentASN();

      NetworkAdminASN new_asn = admin.lookupCurrentASN(my_ip);

      if (!new_asn.sameAs(old_asn)) {

        // kick off a secondary version check to communicate the new information

        if (!secondary_check_done) {

          secondary_check_done = true;

          new AEThread("Secondary version check", true) {
            public void runSupport() {
              getVersionCheckInfoSupport(REASON_SECONDARY_CHECK, false, true, v6);
            }
          }.start();
        }
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);
    }

    Long as_advice = (Long) reply.get("as_advice");

    if (as_advice != null) {

      NetworkAdminASN current_asn = admin.getCurrentASN();

      String asn = current_asn.getASName();

      if (asn != null) {

        long advice = as_advice.longValue();

        if (advice != 0) {

          // require crypto

          String done_asn = COConfigurationManager.getStringParameter("ASN Advice Followed", "");

          if (!done_asn.equals(asn)) {

            COConfigurationManager.setParameter("ASN Advice Followed", asn);

            boolean change = advice == 1 || advice == 2;
            boolean alert = advice == 1 || advice == 3;

            if (!COConfigurationManager.getBooleanParameter(
                "network.transport.encrypted.require")) {

              if (change) {

                COConfigurationManager.setParameter("network.transport.encrypted.require", true);
              }

              if (alert) {

                String msg = MessageText.getString("crypto.alert.as.warning", new String[] {asn});

                Logger.log(new LogAlert(false, LogAlert.AT_WARNING, msg));
              }
            }
          }
        }
      }
    }

    // set ui.toolbar.uiswitcher based on instructions from tracker
    // Really shouldn't be in VersionCheck client, but instead have some
    // listener and have the code elsewhere.  Simply calling
    // getVersionCheckInfo from "code elsewhere" (to get the cached result)
    // caused a deadlock at startup.
    Long lEnabledUISwitcher = (Long) reply.get("ui.toolbar.uiswitcher");
    if (lEnabledUISwitcher != null) {
      COConfigurationManager.setBooleanDefault(
          "ui.toolbar.uiswitcher", lEnabledUISwitcher.longValue() == 1);
    }
  }