public @Override boolean enabled() { if (Boolean.getBoolean("netbeans.keyring.no.native")) { LOG.fine("native keyring integration disabled"); return false; } boolean envVarSet = false; for (String key : System.getenv().keySet()) { if (key.startsWith("GNOME_KEYRING_")) { // NOI18N envVarSet = true; break; } } if (!envVarSet) { LOG.fine("no GNOME_KEYRING_* environment variable set"); return false; } String appName = "JOSM"; try { // Need to do this somewhere, or we get warnings on console. // Also used by confirmation dialogs to give the app access to the login keyring. LIBRARY.g_set_application_name(appName); if (!LIBRARY.gnome_keyring_is_available()) { return false; } // #178571: try to read some key just to make sure gnome_keyring_find_password_sync is bound: read("NoNeXiStEnT"); // NOI18N return true; } catch (Throwable t) { LOG.log(Level.FINE, null, t); return false; } }
static { List<String> directives = new ArrayList<String>(); List<String> keywords = new ArrayList<String>(); List<String> pseudoKeywords = new ArrayList<String>(); List<String> operators = new ArrayList<String>(); com.google.dart.compiler.parser.Token[] tokens = com.google.dart.compiler.parser.Token.values(); for (int i = 0; i < tokens.length; i++) { com.google.dart.compiler.parser.Token token = tokens[i]; if ((BREAK.ordinal() <= token.ordinal() && token.ordinal() <= WITH.ordinal()) || token.ordinal() == AS.ordinal() || token.ordinal() == IS.ordinal()) { keywords.add(token.getSyntax()); } if ((LIBRARY.ordinal() <= token.ordinal()) && (token.ordinal() <= NATIVE.ordinal())) { String name = token.getSyntax(); directives.add(name.substring(1)); } if (token.isBinaryOperator() || token.isUnaryOperator()) { operators.add(token.getSyntax()); } } for (String kw : DartParser.PSEUDO_KEYWORDS) { pseudoKeywords.add(kw); } DIRECTIVES = directives.toArray(new String[directives.size()]); KEYWORDS = keywords.toArray(new String[keywords.size()]); PSEUDO_KEYWORDS = pseudoKeywords.toArray(new String[pseudoKeywords.size()]); OPERATORS = operators.toArray(new String[operators.size()]); }
public @Override void save(String key, char[] password, String description) { Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); int[] item_id = new int[1]; error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_create_sync( null, GNOME_KEYRING_ITEM_GENERIC_SECRET, description != null ? description : key, attributes, new String(password), true, item_id)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } }
public @Override char[] read(String key) { Pointer[] found = new Pointer[1]; Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync( GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, found)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } if (found[0] != null) { try { if (LIBRARY.g_list_length(found[0]) > 0) { GnomeKeyringFound result = LIBRARY.g_list_nth_data(found[0], 0); if (result != null) { if (result.secret != null) { return result.secret.toCharArray(); } else { LOG.warning("#183670: GnomeKeyringFound.secret == null"); delete(key); } } else { LOG.warning("#183670: GList<GnomeKeyringFound>[0].result == null"); } } } finally { LIBRARY.gnome_keyring_found_list_free(found[0]); } } return null; }
public @Override void delete(String key) { Pointer[] found = new Pointer[1]; Pointer attributes = LIBRARY.g_array_new(0, 0, GnomeKeyringAttribute_SIZE); try { LIBRARY.gnome_keyring_attribute_list_append_string(attributes, KEY, key); error( GnomeKeyringLibrary.LIBRARY.gnome_keyring_find_items_sync( GNOME_KEYRING_ITEM_GENERIC_SECRET, attributes, found)); } finally { LIBRARY.gnome_keyring_attribute_list_free(attributes); } if (found[0] == null) { return; } int id; try { if (LIBRARY.g_list_length(found[0]) > 0) { GnomeKeyringFound result = LIBRARY.g_list_nth_data(found[0], 0); id = result.item_id; } else { id = 0; } } finally { LIBRARY.gnome_keyring_found_list_free(found[0]); } if (id > 0) { if ("SunOS".equals(System.getProperty("os.name")) && "5.10".equals(System.getProperty("os.version"))) { // #185698 save( key, new char[0], null); // gnome_keyring_item_delete(null, id, null, null, null) does not seem to do // anything } else { error(GnomeKeyringLibrary.LIBRARY.gnome_keyring_item_delete_sync(null, id)); } } }
public void startSeedingLibrary() { Tools.dbInit(); List<Library> library = LIBRARY.findAll(); library.isEmpty(); Tools.dbClose(); // start sharing them Integer i = 0; while (i < library.size()) { log.info("File #" + i.toString() + "/" + library.size() + " songs in library"); Library track = library.get(i); String torrentPath = track.getString("torrent_path"); String filePath = track.getString("file_path"); File outputParent = new File(filePath).getParentFile(); TorrentHandle torrent = addTorrent(outputParent, new File(torrentPath)); // Set up the scanInfo ScanInfo si = ScanInfo.create(new File(filePath)); si.setStatus(ScanStatus.Seeding); si.setMbid(track.getString("mbid")); scanInfos.add(si); // Do increments of every x, but only after the x'th torrent announce was a success if (i % 25 == 0) { // log.info("active torrents:" + session.getStatus().get) torrent.setAutoManaged(false); torrent.resume(); torrent.forceReannounce(); try { final CountDownLatch signal = new CountDownLatch(1); session.addListener( new TorrentAlertAdapter(torrent) { @Override public void trackerReply(TrackerReplyAlert alert) { log.info("Tracked reply received for torrent " + torrent.getName()); signal.countDown(); torrent.setAutoManaged(true); } @Override public void peerConnect(PeerConnectAlert alert) { log.info("Peer connect alert received for torrent " + torrent.getName()); signal.countDown(); torrent.setAutoManaged(true); } }); signal.await(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } i++; } log.info("Done seeding library, total of " + session.getTorrents().size() + " torrents shared"); }