mozilla-libproxy.patch
changeset 120 a535723d4453
parent 115 5e8354f0b873
equal deleted inserted replaced
117:565d666e22a1 120:a535723d4453
   165  include $(topsrcdir)/config/rules.mk
   165  include $(topsrcdir)/config/rules.mk
   166 diff --git a/toolkit/system/unixproxy/nsLibProxySettings.cpp b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   166 diff --git a/toolkit/system/unixproxy/nsLibProxySettings.cpp b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   167 new file mode 100644
   167 new file mode 100644
   168 --- /dev/null
   168 --- /dev/null
   169 +++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   169 +++ b/toolkit/system/unixproxy/nsLibProxySettings.cpp
   170 @@ -0,0 +1,170 @@
   170 @@ -0,0 +1,178 @@
   171 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
   171 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
   172 +/* ***** BEGIN LICENSE BLOCK *****
   172 +/* ***** BEGIN LICENSE BLOCK *****
   173 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
   173 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
   174 + *
   174 + *
   175 + * The contents of this file are subject to the Mozilla Public License Version
   175 + * The contents of this file are subject to the Mozilla Public License Version
   220 +class nsUnixSystemProxySettings : public nsISystemProxySettings {
   220 +class nsUnixSystemProxySettings : public nsISystemProxySettings {
   221 +public:
   221 +public:
   222 +  NS_DECL_ISUPPORTS
   222 +  NS_DECL_ISUPPORTS
   223 +  NS_DECL_NSISYSTEMPROXYSETTINGS
   223 +  NS_DECL_NSISYSTEMPROXYSETTINGS
   224 +
   224 +
   225 +  nsUnixSystemProxySettings() {}
   225 +  nsUnixSystemProxySettings() { mProxyFactory = nsnull; }
   226 +  nsresult Init();
   226 +  nsresult Init();
   227 +
   227 +
   228 +private:
   228 +private:
   229 +  ~nsUnixSystemProxySettings() {
   229 +  ~nsUnixSystemProxySettings() {
   230 +    if (mProxyFactory) 
   230 +    if (mProxyFactory) 
   237 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   237 +NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
   238 +
   238 +
   239 +nsresult
   239 +nsresult
   240 +nsUnixSystemProxySettings::Init()
   240 +nsUnixSystemProxySettings::Init()
   241 +{
   241 +{
   242 +  mProxyFactory = nsnull;
       
   243 +  return NS_OK;
   242 +  return NS_OK;
   244 +}
   243 +}
   245 +
   244 +
   246 +nsresult
   245 +nsresult
   247 +nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
   246 +nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
   271 +  char **proxyArray = nsnull;
   270 +  char **proxyArray = nsnull;
   272 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   271 +  proxyArray = px_proxy_factory_get_proxies(mProxyFactory, (char*)(spec.get()));
   273 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
   272 +  NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE);
   274 +
   273 +
   275 +  // Translate libproxy's output to PAC string as expected
   274 +  // Translate libproxy's output to PAC string as expected
   276 +  // libproxy's prefixes: http, proxy, socks, socks4, socks5, direct, unknown
   275 +  // libproxy returns an array of proxies in the format:
   277 +  // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; // DIRECT"
   276 +  // <procotol>://[username:password@]proxy:port
       
   277 +  // or
       
   278 +  // direct://
       
   279 +  //
       
   280 +  // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT"
   278 +  int c = 0;
   281 +  int c = 0;
   279 +  while (proxyArray[c] != NULL) {
   282 +  while (proxyArray[c] != NULL) {
   280 +    if (c != 0) {
   283 +    if (!aResult.IsEmpty()) {
   281 +      aResult.AppendLiteral("; ");
   284 +      aResult.AppendLiteral("; ");
   282 +    }
   285 +    }
   283 +
   286 +
   284 +    PRBool isScheme = PR_FALSE;
   287 +    PRBool isScheme = PR_FALSE;
   285 +    nsXPIDLCString schemeString;
   288 +    nsXPIDLCString schemeString;
   286 +    nsXPIDLCString hostPortString;
   289 +    nsXPIDLCString hostPortString;
   287 +    nsCOMPtr<nsIURI> proxyURI;
   290 +    nsCOMPtr<nsIURI> proxyURI;
   288 +
   291 +
   289 +    rv = ios->NewURI(nsDependentCString(proxyArray[c]), 
   292 +    rv = ios->NewURI(nsDependentCString(proxyArray[c]),
   290 +                                        nsnull, 
   293 +                                        nsnull,
   291 +                                        nsnull, 
   294 +                                        nsnull,
   292 +                                        getter_AddRefs(proxyURI));
   295 +                                        getter_AddRefs(proxyURI));
   293 +    NS_ENSURE_SUCCESS(rv, rv);
   296 +    if (NS_FAILED(rv)) {
       
   297 +      c++;
       
   298 +      continue;
       
   299 +    }
   294 +
   300 +
   295 +    proxyURI->GetScheme(schemeString);
   301 +    proxyURI->GetScheme(schemeString);
   296 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   302 +    if (NS_SUCCEEDED(proxyURI->SchemeIs("http", &isScheme)) && isScheme) {
   297 +      schemeString.AssignLiteral("proxy");
   303 +      schemeString.AssignLiteral("proxy");
   298 +    }
   304 +    }
   305 +    }
   311 +    }
   306 +
   312 +
   307 +    c++;
   313 +    c++;
   308 +  }
   314 +  }
   309 +
   315 +
   310 +//printf("returned PAC proxy string: %s\n", PromiseFlatCString(aResult).get());
   316 +#ifdef DEBUG
       
   317 +  printf("returned PAC proxy string: %s\n", PromiseFlatCString(aResult).get());
       
   318 +#endif
   311 +
   319 +
   312 +  PR_Free(proxyArray);
   320 +  PR_Free(proxyArray);
   313 +  return NS_OK;
   321 +  return NS_OK;
   314 +}
   322 +}
   315 +
   323 +