FileDocCategorySizeDatePackage
PlatformConfigMessenger.javaAPI DocAzureus 3.0.3.46839Wed Jul 25 12:07:36 BST 2007com.aelitis.azureus.core.messenger.config

PlatformConfigMessenger

public class PlatformConfigMessenger extends Object
author
TuxPaper
created
Sep 26, 2006

Fields Summary
public static final String
LISTENER_ID
public static final String
SECTION_TYPE_BIGBROWSE
public static final String
SECTION_TYPE_MINIBROWSE
private static int
iRPCVersion
private static String
DEFAULT_WHITELIST
private static String[]
sURLWhiteList
private static String
playAfterURL
Constructors Summary
Methods Summary
public static voidgetBrowseSections(java.lang.String sectionType, long maxDelayMS, com.aelitis.azureus.core.messenger.config.PlatformConfigMessenger$GetBrowseSectionsReplyListener replyListener)

	
	      
			   

		PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
				"get-browse-sections", new Object[] {
					"section-type",
					sectionType,
					"locale",
					Locale.getDefault().toString()
				}, maxDelayMS);

		PlatformMessengerListener listener = new PlatformMessengerListener() {
			public void messageSent(PlatformMessage message) {
				replyListener.messageSent();
			}

			public void replyReceived(PlatformMessage message, String replyType,
					Map reply) {
				if (reply != null) {
					List array = (List) reply.get("value");
					Map[] newReply = new HashMap[array.size()];
					for (int i = 0; i < newReply.length; i++) {
						newReply[i] = (Map) array.get(i);

						String url = (String) newReply[i].get("url");
						if (url != null && !url.startsWith("http://")) {
							url = Constants.URL_PREFIX + url;
							if (url.indexOf('?") < 0) {
								url += "?";
							} else {
								url += "&";
							}
							url += Constants.URL_SUFFIX;

							newReply[i].put("url", url);
						}
					}
					replyListener.replyReceived(newReply);
				} else {
					replyListener.replyReceived(new Map[0]);
				}
			}
		};

		PlatformMessenger.queueMessage(message, listener);
	
public static java.lang.StringgetPlayAfterURL()

		return playAfterURL;
	
public static intgetRPCVersion()

return
the iRPCVersion

		return iRPCVersion;
	
public static java.lang.String[]getURLWhitelist()

		return sURLWhiteList;
	
public static booleanisURLBlocked(java.lang.String url)

		if (url == null) {
			Debug.out("URL null and should be blocked");
			return true;
		}

		String[] whitelist = PlatformConfigMessenger.getURLWhitelist();
		for (int i = 0; i < whitelist.length; i++) {
			if (url.matches(whitelist[i])) {
				return false;
			}
		}
		Debug.out("URL '" + url + "' " + " does not match one of the "
				+ whitelist.length + " whitelist entries");
		return true;
	
public static voidlogin(long maxDelayMS)

		PlatformManager pm = PlatformManagerFactory.getPlatformManager();
		String azComputerID = "";
		try {
			azComputerID = pm.getAzComputerID();
		} catch (PlatformManagerException e) {
		}

		Object[] params = new Object[] {
			"version",
			org.gudy.azureus2.core3.util.Constants.AZUREUS_VERSION,
			"locale",
			Locale.getDefault().toString(),
			"azCID",
			azComputerID
		};
		PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
				"login", params, maxDelayMS);

		PlatformMessengerListener listener = new PlatformMessengerListener() {

			public void replyReceived(PlatformMessage message, String replyType,
					Map reply) {
				if (reply == null) {
					return;
				}

				try {
					List listURLs = (List) MapUtils.getMapObject(reply, "url-whitelist",
							null, List.class);
					if (listURLs != null) {
						String[] sNewWhiteList = new String[listURLs.size() + 1];
						sNewWhiteList[0] = DEFAULT_WHITELIST;

						for (int i = 0; i < listURLs.size(); i++) {
							String string = (String) listURLs.get(i);
							PlatformMessenger.debug("v3.login: got whitelist of " + string);
							sNewWhiteList[i + 1] = string;
						}
						sURLWhiteList = sNewWhiteList;
					}
				} catch (Exception e) {
					Debug.out(e);
				}

				try {
					List listDomains = (List) MapUtils.getMapObject(reply, "tracker-domains",
							null, List.class);
					if (listDomains != null) {
						for (int i = 0; i < listDomains.size(); i++) {
							String s = (String) listDomains.get(i);
							PlatformTorrentUtils.addPlatformHost(s);
							PlatformMessenger.debug("v3.login: got tracker domain of " + s);
						}
					}
				} catch (Exception e) {
					Debug.out(e);
				}

				try {
  				iRPCVersion = MapUtils.getMapInt(reply, "rpc-version", 0);
  				playAfterURL = (String) MapUtils.getMapString(reply,
  						"play-after-url", null);
				} catch (Exception e) {
					Debug.out(e);
				}
			}

			public void messageSent(PlatformMessage message) {
			}

		};

		PlatformMessenger.queueMessage(message, listener);
	
public static voidsendUsageStats(java.util.Map stats, long timestamp, com.aelitis.azureus.core.messenger.PlatformMessengerListener l)

		try {
			PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
					"send-usage-stats", new Object[] {
						"stats",
						stats,
						"version",
						org.gudy.azureus2.core3.util.Constants.AZUREUS_VERSION,
						"timestamp",
						new Long(timestamp)
					}, 5000);

			PlatformMessenger.queueMessage(message, l);
		} catch (Exception e) {
			Debug.out(e);
		}