X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProxy.java;h=750b3eef6a37c874b69b485e8f30b9c41ca47946;hb=cab46763df87b1aacf51a9c064a3f5fc49642df9;hp=fa59c738439e40467aa62dfb28252799375b0375;hpb=5644a84eee241f6c831f06e0bbf29650f0b82cc2;p=fanfix.git
diff --git a/src/be/nikiroo/utils/Proxy.java b/src/be/nikiroo/utils/Proxy.java
old mode 100755
new mode 100644
index fa59c73..750b3ee
--- a/src/be/nikiroo/utils/Proxy.java
+++ b/src/be/nikiroo/utils/Proxy.java
@@ -9,6 +9,64 @@ import java.net.PasswordAuthentication;
* @author niki
*/
public class Proxy {
+ /**
+ * Use the proxy described by this string:
+ *
+ * - ((user(:pass)@)proxy:port)
+ * - System proxy is noted :
+ *
+ * Some examples:
+ *
+ * - â do not use any proxy
+ * - : â use the system proxy
+ * - user@prox.com â use the proxy "prox.com" with default port
+ * and user "user"
+ * - prox.com:8080 â use the proxy "prox.com" on port 8080
+ * - user:pass@prox.com:8080 â use "prox.com" on port 8080
+ * authenticated as "user" with password "pass"
+ * - user:pass@: â use the system proxy authenticated as user
+ * "user" with password "pass"
+ *
+ *
+ * @param proxy
+ * the proxy
+ */
+ static public void use(String proxy) {
+ if (proxy != null && !proxy.isEmpty()) {
+ String user = null;
+ String password = null;
+ int port = 8080;
+
+ if (proxy.contains("@")) {
+ int pos = proxy.indexOf("@");
+ user = proxy.substring(0, pos);
+ proxy = proxy.substring(pos + 1);
+ if (user.contains(":")) {
+ pos = user.indexOf(":");
+ password = user.substring(pos + 1);
+ user = user.substring(0, pos);
+ }
+ }
+
+ if (proxy.equals(":")) {
+ proxy = null;
+ } else if (proxy.contains(":")) {
+ int pos = proxy.indexOf(":");
+ try {
+ port = Integer.parseInt(proxy.substring(0, pos));
+ proxy = proxy.substring(pos + 1);
+ } catch (Exception e) {
+ }
+ }
+
+ if (proxy == null) {
+ Proxy.useSystemProxy(user, password);
+ } else {
+ Proxy.useProxy(proxy, port, user, password);
+ }
+ }
+ }
+
/**
* Use the system proxy.
*/
@@ -61,8 +119,8 @@ public class Proxy {
*/
static public void useProxy(String host, int port, String user,
String password) {
- System.setProperty("http.proxyHost", "proxy.stluc.ucl.ac.be");
- System.setProperty("http.proxyPort", "8080");
+ System.setProperty("http.proxyHost", host);
+ System.setProperty("http.proxyPort", Integer.toString(port));
auth(user, password);
}