Esempio n. 1
0
// dnsResolve(host) javascript implementation
static
bool PACDnsResolve(JSContext *cx, unsigned int argc, JS::Value *vp)
{
  JS::CallArgs args = CallArgsFromVp(argc, vp);

  if (NS_IsMainThread()) {
    NS_WARNING("DNS Resolution From PAC on Main Thread. How did that happen?");
    return false;
  }

  JS::Rooted<JSString*> arg1(cx);
  if (!JS_ConvertArguments(cx, args, "S", arg1.address()))
    return false;

  nsDependentJSString hostName;
  nsAutoCString dottedDecimal;

  if (!hostName.init(cx, arg1))
    return false;
  if (PACResolveToString(NS_ConvertUTF16toUTF8(hostName), dottedDecimal, 0)) {
    JSString *dottedDecimalString = JS_NewStringCopyZ(cx, dottedDecimal.get());
    args.rval().setString(dottedDecimalString);
  }
  else {
    args.rval().setNull();
  }

  return true;
}
// dnsResolve(host) javascript implementation
static
JSBool PACDnsResolve(JSContext *cx, unsigned int argc, jsval *vp)
{
  if (NS_IsMainThread()) {
    NS_WARNING("DNS Resolution From PAC on Main Thread. How did that happen?");
    return false;
  }

  JSString *arg1 = nullptr;
  if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &arg1))
    return false;

  nsDependentJSString hostName;
  nsAutoCString dottedDecimal;

  if (!hostName.init(cx, arg1))
    return false;
  if (PACResolveToString(NS_ConvertUTF16toUTF8(hostName), dottedDecimal, 0)) {
    JSString *dottedDecimalString = JS_NewStringCopyZ(cx, dottedDecimal.get());
    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(dottedDecimalString));
  }
  else {
    JS_SET_RVAL(cx, vp, JSVAL_NULL);
  }
  
  return true;
}
Esempio n. 3
0
bool
ProxyAutoConfig::MyIPAddress(JS::Value *vp)
{
  nsAutoCString remoteDottedDecimal;
  nsAutoCString localDottedDecimal;
  JSContext *cx = mJSRuntime->Context();

  // first, lookup the local address of a socket connected
  // to the host of uri being resolved by the pac file. This is
  // v6 safe.. but is the last step like that
  if (MyIPAddressTryHost(mRunningHost, kTimeout, vp))
    return true;

  // next, look for a route to a public internet address that doesn't need DNS.
  // This is the google anycast dns address, but it doesn't matter if it
  // remains operable (as we don't contact it) as long as the address stays
  // in commonly routed IP address space.
  remoteDottedDecimal.AssignLiteral("8.8.8.8");
  if (MyIPAddressTryHost(remoteDottedDecimal, 0, vp))
    return true;
  
  // next, use the old algorithm based on the local hostname
  nsAutoCString hostName;
  nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
  if (dns && NS_SUCCEEDED(dns->GetMyHostName(hostName)) &&
      PACResolveToString(hostName, localDottedDecimal, kTimeout)) {
    JSString *dottedDecimalString =
      JS_NewStringCopyZ(cx, localDottedDecimal.get());
    JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(dottedDecimalString));
    return true;
  }

  // next try a couple RFC 1918 variants.. maybe there is a
  // local route
  remoteDottedDecimal.AssignLiteral("192.168.0.1");
  if (MyIPAddressTryHost(remoteDottedDecimal, 0, vp))
    return true;

  // more RFC 1918
  remoteDottedDecimal.AssignLiteral("10.0.0.1");
  if (MyIPAddressTryHost(remoteDottedDecimal, 0, vp))
    return true;

  // who knows? let's fallback to localhost
  localDottedDecimal.AssignLiteral("127.0.0.1");
  JSString *dottedDecimalString =
    JS_NewStringCopyZ(cx, localDottedDecimal.get());
  JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(dottedDecimalString));
  return true;
}