コード例 #1
0
NS_IMETHODIMP
Location::SetPort(const nsAString& aPort)
{
  nsCOMPtr<nsIURI> uri;
  nsresult rv = GetWritableURI(getter_AddRefs(uri));
  if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
    return rv;
  }

  // perhaps use nsReadingIterators at some point?
  NS_ConvertUTF16toUTF8 portStr(aPort);
  const char *buf = portStr.get();
  int32_t port = -1;

  if (!portStr.IsEmpty() && buf) {
    if (*buf == ':') {
      port = atol(buf+1);
    }
    else {
      port = atol(buf);
    }
  }

  rv = uri->SetPort(port);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  return SetURI(uri);
}
コード例 #2
0
int Dialog::verifyFields()
{
  QMessageBox messageBox;
  string velStr(velocityLineEdit->text().toStdString());
  string portStr(portLineEdit->text().toStdString());
  QString rootStr = rootLineEdit->text();
  QFile rootPath(rootStr);
  int vel = strtol(velStr.c_str(), NULL, numberBase);
  int port = strtol(portStr.c_str(), NULL, numberBase);

  if (rootStr.size() > 0 && !rootPath.exists())
  {
    messageBox.information(this, "Invalid root path",
                           "It's not a valid server root path");
    return -1;
  }

  if (velStr.size() > 0 && (1 > vel || 10240000 < vel))
  {
    messageBox.information(this, "Invalid parameter", 
                           "Invalid velocity number!"
                           "\nInterval: (0, 10240000]");
    return -1;
  }

  if (portStr.size() > 0 && (1024 > port || 65535 < port))
  {
    messageBox.information(this, "Invalid parameter", 
                           "Invalid port number!"
                           "\nInterval: [1024, 65535]");
    return -1;
  }

  return 0;
}
コード例 #3
0
NS_IMETHODIMP
nsLocation::SetPort(const nsAString& aPort)
{
  if (!CallerSubsumes())
    return NS_ERROR_DOM_SECURITY_ERR;

  nsCOMPtr<nsIURI> uri;
  nsresult rv = GetWritableURI(getter_AddRefs(uri));

  if (uri) {
    // perhaps use nsReadingIterators at some point?
    NS_ConvertUTF16toUTF8 portStr(aPort);
    const char *buf = portStr.get();
    int32_t port = -1;

    if (buf) {
      if (*buf == ':') {
        port = atol(buf+1);
      }
      else {
        port = atol(buf);
      }
    }

    rv = uri->SetPort(port);
    if (NS_SUCCEEDED(rv)) {
      SetURI(uri);
    }
  }

  return rv;
}
コード例 #4
0
static PRBool
IsInNoProxyList(const nsACString& aHost, PRInt32 aPort, const char* noProxyVal)
{
  NS_ASSERTION(aPort >= 0, "Negative port?");
  
  nsCAutoString noProxy(noProxyVal);
  if (noProxy.EqualsLiteral("*"))
    return PR_TRUE;
    
  noProxy.StripWhitespace();
  
  nsReadingIterator<char> pos;
  nsReadingIterator<char> end;
  noProxy.BeginReading(pos);
  noProxy.EndReading(end);
  while (pos != end) {
    nsReadingIterator<char> last = pos;
    nsReadingIterator<char> nextPos;
    if (FindCharInReadable(',', last, end)) {
      nextPos = last;
      ++nextPos;
    } else {
      last = end;
      nextPos = end;
    }
    
    nsReadingIterator<char> colon = pos;
    PRInt32 port = -1;
    if (FindCharInReadable(':', colon, last)) {
      ++colon;
      nsDependentCSubstring portStr(colon, last);
      nsCAutoString portStr2(portStr); // We need this for ToInteger. String API's suck.
      PRInt32 err;
      port = portStr2.ToInteger(&err);
      if (NS_FAILED(err)) {
        port = -2; // don't match any port, so we ignore this pattern
      }
      --colon;
    } else {
      colon = last;
    }
    
    if (port == -1 || port == aPort) {
      nsDependentCSubstring hostStr(pos, colon);
      // By using StringEndsWith instead of an equality comparator, we can include sub-domains
      if (StringEndsWith(aHost, hostStr, nsCaseInsensitiveCStringComparator()))
        return PR_TRUE;
    }
    
    pos = nextPos;
  }
  
  return PR_FALSE;
}
コード例 #5
0
void ArpTelnetSettings::ShowCurrentPort(const ArpMessage& settings)
{
	ArpD(cdb << ADH << "ArpTelnetSettings::ShowCurrentPort()" << endl);
	int32 port = 23;
	if( settings.FindInt32(ArpTelnet::PortConfigName,
							&port) == B_OK ) {
		if( mPortText ) {
			ArpString portStr(port);
			mPortText->SetText(portStr);
		}
	}
}
コード例 #6
0
ファイル: URL.cpp プロジェクト: Gabuzo/mozilla-central
void
URL::SetPort(const nsAString& aPort)
{
  nsresult rv;
  nsAutoString portStr(aPort);
  int32_t port = portStr.ToInteger(&rv);
  if (NS_FAILED(rv)) {
    return;
  }

  mURI->SetPort(port);
}
コード例 #7
0
void UDPTTYRunnable::run(int argc, char ** argv) {
	if (argc < 2) {
		std::cerr << "udp-tty was expecting at least 2 arguments." << std::endl;
		return;
	}
	std::string address(argv[0]);
	unsigned int port;
	std::string portStr(argv[1]);
	std::stringstream ss(portStr);
	ss >> port;
	UDPTTY tty(address, port);
}
コード例 #8
0
ファイル: URL.cpp プロジェクト: jasonLaster/gecko-dev
void URL::SetPort(const nsAString& aPort) {
  nsresult rv;
  nsAutoString portStr(aPort);
  int32_t port = -1;

  // nsIURI uses -1 as default value.
  if (!portStr.IsEmpty()) {
    port = portStr.ToInteger(&rv);
    if (NS_FAILED(rv)) {
      return;
    }
  }

  Unused << NS_MutateURI(mURI).SetPort(port).Finalize(mURI);
}
コード例 #9
0
ファイル: URL.cpp プロジェクト: JaminLiu/gecko-dev
void
URL::SetPort(const nsAString& aPort)
{
  nsresult rv;
  nsAutoString portStr(aPort);
  int32_t port = -1;

  // nsIURI uses -1 as default value.
  if (!portStr.IsEmpty()) {
    port = portStr.ToInteger(&rv);
    if (NS_FAILED(rv)) {
      return;
    }
  }

  mURI->SetPort(port);
}
コード例 #10
0
ファイル: Link.cpp プロジェクト: PinZhang/up-central
void
Link::SetPort(const nsAString &aPort)
{
  nsCOMPtr<nsIURI> uri(GetURIToMutate());
  if (!uri) {
    // Ignore failures to be compatible with NS4.
    return;
  }

  nsresult rv;
  nsAutoString portStr(aPort);
  int32_t port = portStr.ToInteger(&rv);
  if (NS_FAILED(rv)) {
    return;
  }

  (void)uri->SetPort(port);
  SetHrefAttribute(uri);
}
コード例 #11
0
void ArpTelnetSettings::ChangeCurrentPort(void)
{
	ArpD(cdb << ADH << "ArpTelnetSettings::ChangeCurrentPort()" << endl);
	int32 port;
	if( mSettings.FindInt32(ArpTelnet::PortConfigName,
							&port) == B_OK ) {
		if( mPortText ) {
			ArpString portStr(mPortText->Text());
			bool valid = false;
			int32 tmp = portStr.AsInt(10,&valid);
			if( valid ) port = tmp;
		}
		ArpMessage update(ARP_PUT_CONFIGURATION_MSG);
		ArpMessage settings;
		settings.AddInt32(ArpTelnet::PortConfigName, port);
		update.AddMessage("settings", &settings);
		mTelnet.SendMessage(&update);
		mSettings.Update(settings);
	}
}
コード例 #12
0
ファイル: Location.cpp プロジェクト: marcoscaceres/gecko-dev
void
Location::SetPort(const nsAString& aPort,
                  nsIPrincipal& aSubjectPrincipal,
                  ErrorResult& aRv)
{
  if (!CallerSubsumes(&aSubjectPrincipal)) {
    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
    return;
  }

  nsCOMPtr<nsIURI> uri;
  aRv = GetURI(getter_AddRefs(uri));
  if (NS_WARN_IF(aRv.Failed() || !uri)) {
    return;
  }

  // perhaps use nsReadingIterators at some point?
  NS_ConvertUTF16toUTF8 portStr(aPort);
  const char *buf = portStr.get();
  int32_t port = -1;

  if (!portStr.IsEmpty() && buf) {
    if (*buf == ':') {
      port = atol(buf+1);
    }
    else {
      port = atol(buf);
    }
  }

  aRv = NS_MutateURI(uri)
          .SetPort(port)
          .Finalize(uri);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  aRv = SetURI(uri);
}
コード例 #13
0
ファイル: Link.cpp プロジェクト: PinZhang/up-central
void
Link::SetHost(const nsAString &aHost)
{
  nsCOMPtr<nsIURI> uri(GetURIToMutate());
  if (!uri) {
    // Ignore failures to be compatible with NS4.
    return;
  }

  // We cannot simply call nsIURI::SetHost because that would treat the name as
  // an IPv6 address (like http:://[server:443]/).  We also cannot call
  // nsIURI::SetHostPort because that isn't implemented.  Sadfaces.

  // First set the hostname.
  nsAString::const_iterator start, end;
  aHost.BeginReading(start);
  aHost.EndReading(end);
  nsAString::const_iterator iter(start);
  (void)FindCharInReadable(':', iter, end);
  NS_ConvertUTF16toUTF8 host(Substring(start, iter));
  (void)uri->SetHost(host);

  // Also set the port if needed.
  if (iter != end) {
    iter++;
    if (iter != end) {
      nsAutoString portStr(Substring(iter, end));
      nsresult rv;
      int32_t port = portStr.ToInteger(&rv);
      if (NS_SUCCEEDED(rv)) {
        (void)uri->SetPort(port);
      }
    }
  };

  SetHrefAttribute(uri);
  return;
}
コード例 #14
0
ファイル: Link.cpp プロジェクト: alex-tifrea/gecko-dev
void
Link::SetPort(const nsAString &aPort, ErrorResult& aError)
{
  nsCOMPtr<nsIURI> uri(GetURIToMutate());
  if (!uri) {
    // Ignore failures to be compatible with NS4.
    return;
  }

  nsresult rv;
  nsAutoString portStr(aPort);

  // nsIURI uses -1 as default value.
  int32_t port = -1;
  if (!aPort.IsEmpty()) {
    port = portStr.ToInteger(&rv);
    if (NS_FAILED(rv)) {
      return;
    }
  }

  (void)uri->SetPort(port);
  SetHrefAttribute(uri);
}
コード例 #15
0
ファイル: settings.cpp プロジェクト: Feyre/BeeChat
//loop through command line arguments and extract settings
void Settings::parse(const int argc, const char** argv)
{
    bool hasUserName = false;   //assume user hasn't entered a username

    //loops through arguments, reads in each argument and decides what to do with it
    for(int ii = 0; ii < argc; ++ii)
    {
        std::string arg(argv[ii]);

        if (arg[0] != '-')
        {
            continue;   //not a switch, skip it
        }

        if(arg.find("-username="******"-address=") == 0)    //are we setting a server IP?
        {
            std::string address(getArgValue(arg));
            try
            {
                (void)serverAddress(address);    //set and validate requested server address
            }
            catch (BeeChatException bce)
            {
                throw;    //rethrow the same exception
            }
        }

        else if(arg.find("-server") == 0)
        {
            (void)isServer(true);    //request to bee a server
        }

        else if(arg.find("-port=") == 0)
        {
            std::string portStr(getArgValue(arg));
            try
            {
                (void)port((unsigned short)atoi(portStr.c_str()));    //set and validate requested port
            }
            catch(BeeChatException e)
            {
                std::stringstream ss;
                ss << "Could not set port: " << e.type() << ":" << e.message();
                throw BeeChatException(eET_invalid_port, ss.str());
            }
        }

        else
        {
            std::stringstream ss;
            ss << "Unknown argument: " << arg;
            throw BeeChatException(eET_unknown_arg, ss.str());
        }
    }

    if(!hasUserName)
    {
        throw BeeChatException(eET_empty_username, "No username supplied");
    }

}