コード例 #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
ProtocolHandler::ErrorCode BuiltinProtocolHandlersHttp::open(const Uri &uri, iint32 openMode)
{
    if (!uri.isValid()) {
        return InvalidURI;
    }
    d->m_uri = uri;
    d->m_sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
    if (d->m_sockfd == -1) {
        switch(errno) {
            case EACCES:
                return InsufficientPermissions;
                break;
            default:
                return UnknownError;
                break;
        }
    }
    struct hostent *const host = ::gethostbyname(uri.host().data());
    if (!host) {
        switch (h_errno) {
            case HOST_NOT_FOUND:
                return CouldNotResolveHost;
                break;
            default:
                return UnknownError;
                break;
        }
    }
    struct sockaddr_in destAddr;
    destAddr.sin_family = AF_INET;
    destAddr.sin_port = htons(uri.port() == -1 ? 80 : uri.port());
    destAddr.sin_addr.s_addr = ::inet_addr(inet_ntoa(*((struct in_addr*) host->h_addr)));
    memset(&(destAddr.sin_zero), '\0', 8);
    if (!::connect(d->m_sockfd, (struct sockaddr*) &destAddr, sizeof(struct sockaddr))) {
        d->sendCommand(Private::Get, uri);
    }
    switch(errno) {
        case EADDRNOTAVAIL:
        case ECONNREFUSED:
        case ENETUNREACH:
        case ETIMEDOUT:
            return CouldNotConnect;
            break;
        default:
            return UnknownError;
            break;
    }
}
コード例 #3
0
ファイル: SipIMP.cpp プロジェクト: HolgerJahnel/resiprocate
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 );
	}
}