mozilla-libproxy.patch
branchmozilla-1.9.2
changeset 113 04527a174eec
parent 95 37558f4844c0
child 119 8fea954c3b28
equal deleted inserted replaced
112:22a2c93a47ee 113:04527a174eec
   167  include $(topsrcdir)/config/rules.mk
   167  include $(topsrcdir)/config/rules.mk
   168 diff --git a/toolkit/system/unixproxy/nsLibProxySettings.cpp b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   168 diff --git a/toolkit/system/unixproxy/nsLibProxySettings.cpp b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   169 new file mode 100644
   169 new file mode 100644
   170 --- /dev/null
   170 --- /dev/null
   171 +++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   171 +++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   172 @@ -0,0 +1,162 @@
   172 @@ -0,0 +1,159 @@
   173 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
   173 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
   174 +/* ***** BEGIN LICENSE BLOCK *****
   174 +/* ***** BEGIN LICENSE BLOCK *****
   175 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
   175 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
   176 + *
   176 + *
   177 + * The contents of this file are subject to the Mozilla Public License Version
   177 + * The contents of this file are subject to the Mozilla Public License Version
   186 + *
   186 + *
   187 + * The Original Code is Mozilla libproxy integration code.
   187 + * The Original Code is Mozilla libproxy integration code.
   188 + *
   188 + *
   189 + * The Initial Developer of the Original Code is
   189 + * The Initial Developer of the Original Code is
   190 + * Wolfgang Rosenauer <wr@rosenauer.org>.
   190 + * Wolfgang Rosenauer <wr@rosenauer.org>.
   191 + * Portions created by the Initial Developer are Copyright (C) 2009
   191 + * Portions created by the Initial Developer are Copyright (C) 2010
   192 + * the Initial Developer. All Rights Reserved.
   192 + * the Initial Developer. All Rights Reserved.
   193 + *
   193 + *
   194 + * Contributor(s):
   194 + * Contributor(s):
   195 + *
   195 + *
   196 + * Alternatively, the contents of this file may be used under the terms of
   196 + * Alternatively, the contents of this file may be used under the terms of
   232 +    if (mProxyFactory)
   232 +    if (mProxyFactory)
   233 +      px_proxy_factory_free(mProxyFactory);
   233 +      px_proxy_factory_free(mProxyFactory);
   234 +  }
   234 +  }
   235 +
   235 +
   236 +  pxProxyFactory *mProxyFactory;
   236 +  pxProxyFactory *mProxyFactory;
   237 +  nsCOMPtr<nsIIOService> mIOService;
       
   238 +};
   237 +};
   239 +
   238 +
   240 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   239 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   241 +
   240 +
   242 +nsresult
   241 +nsresult
   260 +  nsresult rv;
   259 +  nsresult rv;
   261 +
   260 +
   262 +  if (!mProxyFactory) {
   261 +  if (!mProxyFactory) {
   263 +    mProxyFactory = px_proxy_factory_new();
   262 +    mProxyFactory = px_proxy_factory_new();
   264 +  }
   263 +  }
   265 +  NS_ENSURE_TRUE(mProxyFactory, NS_ERROR_OUT_OF_MEMORY);
   264 +  NS_ENSURE_TRUE(mProxyFactory, NS_ERROR_NOT_AVAILABLE);
   266 +
   265 +
   267 +  if (!mIOService) {
   266 +  nsCOMPtr<nsIIOService> ios = do_GetIOService(&rv);
   268 +    mIOService = do_GetIOService();
   267 +  NS_ENSURE_SUCCESS(rv, rv);
   269 +  }
       
   270 +  NS_ENSURE_TRUE(mIOService, NS_ERROR_FAILURE);
       
   271 +
   268 +
   272 +  nsCAutoString spec;
   269 +  nsCAutoString spec;
   273 +  rv = aURI->GetSpec(spec);
   270 +  rv = aURI->GetSpec(spec);
   274 +  NS_ENSURE_SUCCESS(rv, rv);
   271 +  NS_ENSURE_SUCCESS(rv, rv);
   275 +
   272 +
   276 +  char **proxyArray = nsnull;
   273 +  char **proxyArray = nsnull;
   277 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   274 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   278 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_FAILURE);
   275 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
   279 +
   276 +
   280 +  // PAC string accepts
   277 +  // Translate libproxy's output to PAC string as expected
   281 +  // http, proxy, socks, socks4, socks5, direct, unknown
   278 +  // libproxy's prefixes: http, proxy, socks, socks4, socks5, direct, unknown
   282 +  // example: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
   279 +  // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
   283 +  int c = 0;
   280 +  int c = 0;
   284 +  while (proxyArray[c] != NULL) {
   281 +  while (proxyArray[c] != NULL) {
   285 +    if (c != 0) {
   282 +    if (c != 0) {
   286 +      aResult.AppendLiteral("; ");
   283 +      aResult.AppendLiteral("; ");
   287 +    }
   284 +    }
   289 +    PRBool isScheme = PR_FALSE;
   286 +    PRBool isScheme = PR_FALSE;
   290 +    nsXPIDLCString schemeString;
   287 +    nsXPIDLCString schemeString;
   291 +    nsXPIDLCString hostPortString;
   288 +    nsXPIDLCString hostPortString;
   292 +    nsCOMPtr<nsIURI> proxyURI;
   289 +    nsCOMPtr<nsIURI> proxyURI;
   293 +
   290 +
   294 +    rv = mIOService->NewURI(nsDependentCString(proxyArray[c]),
   291 +    rv = ios->NewURI(nsDependentCString(proxyArray[c]),
   295 +                                               nsnull,
   292 +                                        nsnull,
   296 +                                               nsnull,
   293 +                                        nsnull,
   297 +                                               getter_AddRefs(proxyURI));
   294 +                                        getter_AddRefs(proxyURI));
   298 +    NS_ENSURE_SUCCESS(rv, rv);
   295 +    NS_ENSURE_SUCCESS(rv, rv);
   299 +
   296 +
   300 +    proxyURI->GetScheme(schemeString);
   297 +    proxyURI->GetScheme(schemeString);
   301 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   298 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   302 +      schemeString.AssignLiteral("proxy");
   299 +      schemeString.AssignLiteral("proxy");