mozilla-libproxy.patch
branchmozilla-1.9.2
changeset 119 8fea954c3b28
parent 113 04527a174eec
child 174 b3f909e83302
equal deleted inserted replaced
118:deb8fdcf4792 119:8fea954c3b28
   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,159 @@
   172 @@ -0,0 +1,167 @@
   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
   222 +class nsUnixSystemProxySettings : public nsISystemProxySettings {
   222 +class nsUnixSystemProxySettings : public nsISystemProxySettings {
   223 +public:
   223 +public:
   224 +  NS_DECL_ISUPPORTS
   224 +  NS_DECL_ISUPPORTS
   225 +  NS_DECL_NSISYSTEMPROXYSETTINGS
   225 +  NS_DECL_NSISYSTEMPROXYSETTINGS
   226 +
   226 +
   227 +  nsUnixSystemProxySettings() {}
   227 +  nsUnixSystemProxySettings() { mProxyFactory = nsnull; }
   228 +  nsresult Init();
   228 +  nsresult Init();
   229 +
   229 +
   230 +private:
   230 +private:
   231 +  ~nsUnixSystemProxySettings() {
   231 +  ~nsUnixSystemProxySettings() {
   232 +    if (mProxyFactory)
   232 +    if (mProxyFactory)
   239 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   239 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   240 +
   240 +
   241 +nsresult
   241 +nsresult
   242 +nsUnixSystemProxySettings::Init()
   242 +nsUnixSystemProxySettings::Init()
   243 +{
   243 +{
   244 +  mProxyFactory = nsnull;
       
   245 +  return NS_OK;
   244 +  return NS_OK;
   246 +}
   245 +}
   247 +
   246 +
   248 +nsresult
   247 +nsresult
   249 +nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
   248 +nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
   273 +  char **proxyArray = nsnull;
   272 +  char **proxyArray = nsnull;
   274 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   273 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   275 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
   274 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
   276 +
   275 +
   277 +  // Translate libproxy's output to PAC string as expected
   276 +  // Translate libproxy's output to PAC string as expected
   278 +  // libproxy's prefixes: http, proxy, socks, socks4, socks5, direct, unknown
   277 +  // libproxy returns an array of proxies in the format:
       
   278 +  // <procotol>://[username:password@]proxy:port
       
   279 +  // or
       
   280 +  // direct://
       
   281 +  //
   279 +  // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
   282 +  // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
   280 +  int c = 0;
   283 +  int c = 0;
   281 +  while (proxyArray[c] != NULL) {
   284 +  while (proxyArray[c] != NULL) {
   282 +    if (c != 0) {
   285 +    if (!aResult.IsEmpty()) {
   283 +      aResult.AppendLiteral("; ");
   286 +      aResult.AppendLiteral("; ");
   284 +    }
   287 +    }
   285 +
   288 +
   286 +    PRBool isScheme = PR_FALSE;
   289 +    PRBool isScheme = PR_FALSE;
   287 +    nsXPIDLCString schemeString;
   290 +    nsXPIDLCString schemeString;
   290 +
   293 +
   291 +    rv = ios->NewURI(nsDependentCString(proxyArray[c]),
   294 +    rv = ios->NewURI(nsDependentCString(proxyArray[c]),
   292 +                                        nsnull,
   295 +                                        nsnull,
   293 +                                        nsnull,
   296 +                                        nsnull,
   294 +                                        getter_AddRefs(proxyURI));
   297 +                                        getter_AddRefs(proxyURI));
   295 +    NS_ENSURE_SUCCESS(rv, rv);
   298 +    if (NS_FAILED(rv)) {
       
   299 +      c++;
       
   300 +      continue;
       
   301 +    }
   296 +
   302 +
   297 +    proxyURI->GetScheme(schemeString);
   303 +    proxyURI->GetScheme(schemeString);
   298 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   304 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   299 +      schemeString.AssignLiteral("proxy");
   305 +      schemeString.AssignLiteral("proxy");
   300 +    }
   306 +    }
   307 +    }
   313 +    }
   308 +
   314 +
   309 +    c++;
   315 +    c++;
   310 +  }
   316 +  }
   311 +
   317 +
   312 +//printf("returned PAC proxy string: %s\n", PromiseFlatCString(aResult).get());
   318 +#ifdef DEBUG
       
   319 +  printf("returned PAC proxy string: %s\n", PromiseFlatCString(aResult).get());
       
   320 +#endif
   313 +
   321 +
   314 +  PR_Free(proxyArray);
   322 +  PR_Free(proxyArray);
   315 +  return NS_OK;
   323 +  return NS_OK;
   316 +}
   324 +}
   317 +
   325 +