Пример #1
0
bool BuiltinProtocolHandlersHttp::canBeReusedWith(const Uri &uri) const
{
    return d->m_uri.scheme() == uri.scheme() &&
           d->m_uri.host() == uri.host() &&
           (uri.userInfo().empty() || d->m_uri.userInfo() == uri.userInfo()) &&
           (uri.port() == -1 || d->m_uri.port() == uri.port());
}
Пример #2
0
void 
SipImpApp::imInit()
{  
	sipStack = new SipStack;  
	resip_assert(sipStack);

	encryp = false;
	sign = false;

	CString	mHost     = this->GetProfileString("Proxy","host","example.com");
	CString mProtocol = this->GetProfileString("Proxy","protocol","UDP");
	int     mPort     = this->GetProfileInt("Proxy","port",5060);
	CString mUser     = this->GetProfileString("Proxy","user","");
	CString mPassword = this->GetProfileString("Proxy","password",""); 
	CString mKey      = this->GetProfileString("PKI","key",""); 
	CString mCertPath = this->GetProfileString("PKI","CertPath","C:\\certs"); 
	CString mOutbound = this->GetProfileString("Proxy","outbound",""); 
	CString mContact  = this->GetProfileString("UA","contact",""); 

	int port    = this->GetProfileInt("UA","udpPort",5060); 
	int tlsPort = this->GetProfileInt("UA","tlsPort",5061); 

	Uri aor;
	Uri contact;

	char* envPort = getenv("SIPPORT");
	if ( envPort )
	{
		port = atoi( envPort );
	}

	char* envTlsPort = getenv("SIPTLSPORT");
	if ( envTlsPort )
	{
		tlsPort = atoi( envTlsPort );
	}

	if ( port == 5060 )
	{
		if ( tlsPort == 0 )
		{
			tlsPort = 5061;
		}
	}

	bool haveContact=false;

	if ( !mContact.IsEmpty() )
	{
		try 
		{
			contact = Uri( Data( mContact ) );
			haveContact = true;
		}
		catch ( resip::BaseException& )
		{
		}
	}

	if ( !haveContact )
	{
		contact.scheme() = Data("sip");
		contact.user() = Data("user");
		contact.port() = port;
		contact.host() = sipStack->getHostAddress();
	}
	
	if ( !mHost.IsEmpty() )
	{
		aor.host() = mHost;
		aor.user() = mUser;
		aor.port() = mPort;
		if ( mProtocol == "UDP" )
		{
			aor.scheme() = "sip";
		}
		if ( mProtocol == "TCP" )
		{
			aor.scheme() = "sip";
			aor.param(p_transport) = "tcp";
		}
		if ( mProtocol == "TLS" )
		{
			aor.scheme() = "sips";
		}

		if (!haveContact)
		{
			contact.user() = aor.user();
			if ( aor.scheme() == "sips" )
			{
				contact.scheme() = aor.scheme();
				contact.port() = tlsPort;
			}
		}
	}
	else
	{
		aor = contact;
	}

#ifdef USE_SSL
	resip_assert( sipStack->security );
	try
	{
		resip::Data key( mKey );
		resip::Data path(mCertPath);

		bool okSec = sipStack->security->loadAllCerts( key , path  );
		if ( !okSec )
		{
			//ErrLog( << "Could not load the certificates" );
			resip_assert( 0 );
		}
	}
	catch ( resip::Security::Exception e )
	{
		Data error = Data::from( e );
		const char* problem = error.c_str();
	}
#endif

	try
	{
		// add the transports
		if (port!=0)
		{
			sipStack->addTransport(UDP, port);
			sipStack->addTransport(TCP, port);
		}
		if ( tlsPort != 0 )
		{
#ifdef USE_SSL
			sipStack->addTransport(Transport::TLS, tlsPort);
#endif
		}
	}
	catch (resip::BaseException* e )
	{
		Data foo = Data::from( *e );
		tuIM = NULL;
		return;
	}

	// build the TU 
	ImCallback* callback = new ImCallback;
	resip_assert( callback );
	tuIM = new TuIM(sipStack,aor,contact,callback);
	resip_assert(tuIM);

	tuIM->setUAName( Data("www.SIPimp.org (win32) ver 0.3.1") );

	if ( !mOutbound.IsEmpty() )
	{
		try
		{
			resip::Data dOutbound( mOutbound );
			Uri outbound( dOutbound );

			tuIM->setOutboundProxy( outbound );
		}
		catch ( resip::BaseException&  )
		{	
		}
	}

	// registter 
	if ( !mHost.IsEmpty() )
	{
		resip_assert(tuIM);
		tuIM->registerAor( aor , Data(mPassword) );
	}

	int n = this->GetProfileInt("buddyList","size",0);
	for ( int i=0; i<n; i++ )
	{
		CString item;
		item.Format("%d",i);
		CString name = this->GetProfileString("buddyList",item,"");

		resip::Data dName( name );
		resip::Uri uri(dName);
		resip_assert( tuIM );
		tuIM->addBuddy( uri , resip::Data::Empty );
	}
}
Пример #3
0
bool BuiltinProtocolHandlersLocal::canBeReusedWith(const Uri &uri) const
{
    return uri.scheme().empty() || !uri.scheme().compare("file");
}
Пример #4
0
Status
parseUri(ParsedUri &result, const std::string &text)
{
    Uri uri;

    if (uri.decode(text, false))
    {
        // Turn Airbitz URI's into bitcoin URI's:
        if ("airbitz" == uri.scheme())
        {
            uri.deauthorize();
            auto path = uri.path();
            if (0 != path.find("bitcoin/", 0))
                return ABC_ERROR(ABC_CC_ParseError, "Unknown airbitz URI");
            path.erase(0, 8);
            uri.pathSet(path);
            uri.schemeSet("bitcoin");
        }

        // Check the scheme:
        if ("bitcoin" == uri.scheme())
        {
            uri.deauthorize();
            if (addressOk(uri.path()))
                result.address = uri.path();

            auto query = uri.queryDecode();
            bc::decode_base10(result.amountSatoshi, query["amount"], 8);
            result.label = query["label"];
            result.message = query["message"];
            result.category = query["category"];
            result.ret = query["ret"];
            result.paymentProto = query["r"];
        }
        else if ("hbits" == uri.scheme())
        {
            uri.deauthorize();
            bc::ec_secret secret;
            ABC_CHECK(hbitsDecode(secret, uri.path()));
            result.wif = bc::secret_to_wif(secret, true);
        }
        else if ("bitid" == uri.scheme())
        {
            result.bitidUri = text;
        }
        else
        {
            return ABC_ERROR(ABC_CC_ParseError, "Unknown URI scheme");
        }
    }
    else if (addressOk(text))
    {
        // This is a raw bitcoin address:
        result.address = text;
    }
    else if (bc::null_hash != bc::wif_to_secret(text))
    {
        // This is a raw WIF private key:
        result.wif = text;
    }
    else if (minikeyOk(text))
    {
        // This is a raw Casascius minikey:
        result.wif = bc::secret_to_wif(bc::minikey_to_secret(text), false);
    }
    else if (hbitsOk(text))
    {
        // This is a raw hbits key:
        bc::ec_secret secret;
        ABC_CHECK(hbitsDecode(secret, text));
        result.wif = bc::secret_to_wif(secret, true);
    }
    else
    {
        return ABC_ERROR(ABC_CC_ParseError, "Malformed bitcoin URI");
    }

    // Private keys also have addresses:
    if (result.wif.size())
    {
        const auto compressed =  bc::is_wif_compressed(result.wif);
        const auto secret = bc::wif_to_secret(result.wif);
        const auto pubkey = bc::secret_to_public_key(secret, compressed);
        bc::payment_address address;
        address.set(pubkeyVersion(), bc::bitcoin_short_hash(pubkey));
        result.address = address.encoded();
    }

    return Status();
}