void
nsHttpConnectionInfo::SetOriginServer(const nsACString &host, int32_t port)
{
    mOrigin = host;
    mOriginPort = port == -1 ? DefaultPort() : port;
    BuildHashKey();
}
void
nsHttpConnectionInfo::SetOriginServer(const nsACString &host, int32_t port)
{
    mHost = host;
    mPort = port == -1 ? DefaultPort() : port;

    //
    // build hash key:
    //
    // the hash key uniquely identifies the connection type.  two connections
    // are "equal" if they end up talking the same protocol to the same server
    // and are both used for anonymous or non-anonymous connection only;
    // anonymity of the connection is setup later from nsHttpChannel::AsyncOpen
    // where we know we use anonymous connection (LOAD_ANONYMOUS load flag)
    //

    const char *keyHost;
    int32_t keyPort;

    if (mUsingHttpProxy && !mUsingConnect) {
        keyHost = ProxyHost();
        keyPort = ProxyPort();
    }
    else {
        keyHost = Host();
        keyPort = Port();
    }

    mHashKey.AssignLiteral("....");
    mHashKey.Append(keyHost);
    mHashKey.Append(':');
    mHashKey.AppendInt(keyPort);

    if (mUsingHttpProxy)
        mHashKey.SetCharAt('P', 0);
    if (mUsingSSL)
        mHashKey.SetCharAt('S', 1);

    // NOTE: for transparent proxies (e.g., SOCKS) we need to encode the proxy
    // info in the hash key (this ensures that we will continue to speak the
    // right protocol even if our proxy preferences change).
    //
    // NOTE: for SSL tunnels add the proxy information to the cache key.
    // We cannot use the proxy as the host parameter (as we do for non SSL)
    // because this is a single host tunnel, but we need to include the proxy
    // information so that a change in proxy config will mean this connection
    // is not reused

    if ((!mUsingHttpProxy && ProxyHost()) ||
        (mUsingHttpProxy && mUsingConnect)) {
        mHashKey.AppendLiteral(" (");
        mHashKey.Append(ProxyType());
        mHashKey.Append(':');
        mHashKey.Append(ProxyHost());
        mHashKey.Append(':');
        mHashKey.AppendInt(ProxyPort());
        mHashKey.Append(')');
    }
}
Esempio n. 3
0
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
	ControllerEmu::ControlGroup(_name,GROUP_TYPE_UDPWII),
	inst(NULL), index(indx),
	updIR(false),updAccel(false),
	updButt(false),udpEn(false)
	, port(DefaultPort(indx))
{
	//PanicAlert("UDPWrapper #%d ctor",index);
}
Esempio n. 4
0
void UDPWrapper::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
{
	ControlGroup::SaveConfig(sec,defdev,base);
	std::string group( base + name ); group += "/";
	sec->Set((group + "Enable").c_str(), (int)udpEn, 0);
	sec->Set((group + "Port").c_str(), port, DefaultPort(index));
	sec->Set((group + "Update_Accel").c_str(), (int)updAccel, 1);
	sec->Set((group + "Update_IR").c_str(), (int)updIR, 1);
	sec->Set((group + "Update_Butt").c_str(), (int)updButt, 1);
	sec->Set((group + "Update_Nunchuk").c_str(), (int)updNun, 1);
	sec->Set((group + "Update_NunchukAccel").c_str(), (int)updNunAccel, 0);
}
Esempio n. 5
0
void
nsHttpConnectionInfo::SetOriginServer(const nsACString &host, PRInt32 port)
{
    mHost = host;
    mPort = port == -1 ? DefaultPort() : port;

    //
    // build hash key:
    //
    // the hash key uniquely identifies the connection type.  two connections
    // are "equal" if they end up talking the same protocol to the same server
    // and are both used for anonymous or non-anonymous connection only;
    // anonymity of the connection is setup later from nsHttpChannel::AsyncOpen
    // where we know we use anonymous connection (LOAD_ANONYMOUS load flag)
    //

    const char *keyHost;
    PRInt32 keyPort;

    if (mUsingHttpProxy && !mUsingSSL) {
        keyHost = ProxyHost();
        keyPort = ProxyPort();
    }
    else {
        keyHost = Host();
        keyPort = Port();
    }

    mHashKey.AssignLiteral("...");
    mHashKey.Append(keyHost);
    mHashKey.Append(':');
    mHashKey.AppendInt(keyPort);

    if (mUsingHttpProxy)
        mHashKey.SetCharAt('P', 0);
    if (mUsingSSL)
        mHashKey.SetCharAt('S', 1);

    // NOTE: for transparent proxies (e.g., SOCKS) we need to encode the proxy
    // type in the hash key (this ensures that we will continue to speak the
    // right protocol even if our proxy preferences change).
    if (!mUsingHttpProxy && ProxyHost()) {
        mHashKey.AppendLiteral(" (");
        mHashKey.Append(ProxyType());
        mHashKey.Append(')');
    }
}
nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &originHost,
                                           int32_t originPort,
                                           const nsACString &npnToken,
                                           const nsACString &username,
                                           nsProxyInfo *proxyInfo,
                                           const NeckoOriginAttributes &originAttributes,
                                           const nsACString &routedHost,
                                           int32_t routedPort)
{
    mEndToEndSSL = true; // so DefaultPort() works
    mRoutedPort = routedPort == -1 ? DefaultPort() : routedPort;

    if (!originHost.Equals(routedHost) || (originPort != routedPort)) {
        mRoutedHost = routedHost;
    }
    Init(originHost, originPort, npnToken, username, proxyInfo, originAttributes, true);
}
Esempio n. 7
0
char *HTTP_Open(URL *Url)
{
 char *msg=NULL;
 char *proxy=NULL;
 char *server_host=NULL;
 int server_port=-1;

 /* Sort out the host. */

 if(!IsLocalNetHost(Url->host))
    proxy=ConfigStringURL(Proxies,Url);

 if(proxy)
   {
    if(proxyUrl)
       FreeURL(proxyUrl);
    proxyUrl=NULL;

    proxyUrl=CreateURL("http",proxy,"/",NULL,NULL,NULL);
    server_host=proxyUrl->host;
    server_port=proxyUrl->port;
   }
 else
   {
    server_host=Url->host;
    server_port=Url->port;
   }

 if(server_port==-1)
    server_port=DefaultPort(Url);

 /* Open the connection. */

 server=OpenClientSocket(server_host,server_port);

 if(server==-1)
    msg=GetPrintMessage(Warning,"Cannot open the HTTP connection to %s port %d; [%!s].",server_host,server_port);
 else
   {
    init_io(server);
    configure_io_timeout(server,ConfigInteger(SocketTimeout),ConfigInteger(SocketTimeout));
   }

 return(msg);
}
Esempio n. 8
0
void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
{
	ControlGroup::LoadConfig(sec,defdev,base);

	std::string group( base + name ); group += "/";

	int _updAccel,_updIR,_updButt,_udpEn,_updNun,_updNunAccel;
	sec->Get((group + "Enable").c_str(),&_udpEn, 0);
	sec->Get((group + "Port").c_str(), &port, DefaultPort(index));
	sec->Get((group + "Update_Accel").c_str(), &_updAccel, 1);
	sec->Get((group + "Update_IR").c_str(), &_updIR, 1);
	sec->Get((group + "Update_Butt").c_str(), &_updButt, 1);
	sec->Get((group + "Update_Nunchuk").c_str(), &_updNun, 1);
	sec->Get((group + "Update_NunchukAccel").c_str(), &_updNunAccel, 0);

	udpEn=(_udpEn>0);
	updAccel=(_updAccel>0);
	updIR=(_updIR>0);
	updButt=(_updButt>0);
	updNun=(_updNun>0);
	updNunAccel=(_updNunAccel>0);

	Refresh();
}
Esempio n. 9
0
URL *CreateURL(const char *proto,const char *hostport,const char *path,const char *args,const char *user,const char *pass)
{
 URL *Url=(URL*)malloc(sizeof(URL));
 int n=0,i;
 char *colon,*temp;

 /* Original URL */

 Url->original_name=malloc(strlen(proto)+strlen(hostport)+strlen(path)+(args?strlen(args):0)+8);

 Url->original_path=malloc(strlen(path)+1);
 strcpy(Url->original_path,path);

 if(args)
   {
    Url->original_args=malloc(strlen(args)+1);
    strcpy(Url->original_args,args);
   }
 else
    Url->original_args=NULL;

 strcpy(Url->original_name,proto);
 n=strlen(proto);

 strcpy(Url->original_name+n,"://");
 n+=3;

 strcpy(Url->original_name+n,hostport);
 n+=strlen(hostport);

 Url->original_pathp=Url->original_name+n;

 strcpy(Url->original_name+n,path);
 n+=strlen(path);

 if(args)
   {
    strcpy(Url->original_name+n,"?");
    strcpy(Url->original_name+n+1,args);
   }

 /* proto = Url->proto */

 Url->proto=(char*)malloc(strlen(proto)+1);

 for(i=0;proto[i];i++)
    Url->proto[i]=tolower(proto[i]);
 Url->proto[i]=0;

 /* hostport = Url->hostport */

 temp=URLDecodeGeneric(hostport);

 for(i=0;temp[i];i++)
    if(isalpha(temp[i]))
       temp[i]=tolower(temp[i]);
    else if(!isalnum(temp[i]) && temp[i]!=':' && temp[i]!='-' &&
       temp[i]!='.' && temp[i]!='[' && temp[i]!=']')
      {temp[i]=0;break;}

 Url->hostport=CanonicaliseHost(temp);

 free(temp);

 /* path = Url->path */

 temp=URLDecodeGeneric(path);
 CanonicaliseName(temp);

 Url->path=URLEncodePath(temp);

 free(temp);

 /* args = Url->args */

 if(args && *args)
    Url->args=URLRecodeFormArgs(args);
 else
    Url->args=NULL;

 /* user, pass = Url->user, Url->pass */

 if(user) /* allow empty usernames */
    Url->user=URLDecodeGeneric(user);
 else
    Url->user=NULL;

 if(pass && *pass)
    Url->pass=URLDecodeGeneric(pass);
 else
    Url->pass=NULL;

 /* Hostname, port = Url->host, Url->port */

 if(*Url->hostport=='[')
   {
    char *square=strchr(Url->hostport,']');
    colon=strchr(square,':');
   }
 else
    colon=strchr(Url->hostport,':');

 if(colon)
   {
    int defport=DefaultPort(Url);
    if(defport && atoi(colon+1)==defport)
       *colon=0;
   }

 if(colon && *colon)
   {
    Url->host=(char*)malloc(colon-Url->hostport+1);
    *colon=0;
    strcpy(Url->host,Url->hostport);
    *colon=':';
    Url->port=atoi(colon+1);
   }
 else
   {
    Url->host=Url->hostport;
    Url->port=-1;
   }

 /* Canonical URL = Url->name (and pointers Url->hostp, Url->pathp). */

 Url->name=(char*)malloc(strlen(Url->proto)+
                         strlen(Url->hostport)+
                         strlen(Url->path)+
                         (Url->args?strlen(Url->args):0)+
                         8);

 strcpy(Url->name,Url->proto);
 n=strlen(Url->proto);

 strcpy(Url->name+n,"://");
 n+=3;

 Url->hostp=Url->name+n;

 strcpy(Url->name+n,Url->hostport);
 n+=strlen(Url->hostport);

 Url->pathp=Url->name+n;

 strcpy(Url->name+n,Url->path);
 n+=strlen(Url->path);

 if(Url->args)
   {
    strcpy(Url->name+n,"?");
    strcpy(Url->name+n+1,Url->args);
   }

 /* File name = Url->file */

 if(Url->user)
   {
    char *encuserpass;

    Url->file=(char*)malloc(strlen(Url->name)+
                            3*strlen(Url->user)+
                            (Url->pass?3*strlen(Url->pass):0)+
                            8);

    n=Url->hostp-Url->name;
    strncpy(Url->file,Url->name,(size_t)n);

    encuserpass=URLEncodePassword(Url->user);

    strcpy(Url->file+n,encuserpass);
    n+=strlen(encuserpass);

    free(encuserpass);

    if(Url->pass)
      {
       encuserpass=URLEncodePassword(Url->pass);

       strcpy(Url->file+n,":");
       strcpy(Url->file+n+1,encuserpass);
       n+=strlen(encuserpass)+1;

       free(encuserpass);
      }

    strcpy(Url->file+n,"@");
    strcpy(Url->file+n+1,Url->hostp);
   }
 else
    Url->file=Url->name;

 /* Host directory = Url->private_dir - Private data */

 Url->private_dir=NULL;

 /* Cache filename = Url->private_file - Private data */

 Url->private_file=NULL;

 /* Proxyable link = Url->private_link - Private data */

 Url->private_link=NULL;

 return(Url);
}