示例#1
0
ServerEntry SessionInfo::GetServerEntry() const 
{
    if (!HasServerEntry()) {
        assert(false);
        throw std::exception("SessionInfo::GetServerEntry(): !HasServerEntry()");
    }

    // It is sometimes the case that we know more about our current server than
    // is contained in m_serverEntry or in the ServerEntry in the registry. So
    // we'll construct a new ServerEntry with the best info we have.

    ServerEntry newServerEntry(
        GetServerAddress(), GetRegion(), GetWebPort(), 
        GetWebServerSecret(), GetWebServerCertificate(), 
        GetSSHPort(), GetSSHUsername(), GetSSHPassword(), 
        GetSSHHostKey(), GetSSHObfuscatedPort(), 
        GetSSHObfuscatedKey(),
        GetMeekObfuscatedKey(), GetMeekServerPort(),
        GetMeekCookieEncryptionPublicKey(),
        GetMeekFrontingDomain(), GetMeekFrontingHost(),
        m_serverEntry.meekFrontingAddressesRegex,
        m_serverEntry.meekFrontingAddresses,
        m_serverEntry.capabilities);
    return newServerEntry;
}
void CSocketHTTPDataSource::SendHelper(const char *pzRequest, int nRequestLen, GString &destinationStream, const char *pzNamespace)
{
	int fd, numbytes;  
#ifdef _WIN32
	WSADATA wsaData;
	WSAStartup(MAKEWORD( 1, 0 ), &wsaData);
#endif

	int nNamespaceLen = (int)strlen(pzNamespace);


	struct sockaddr_in their_addr; 
	their_addr.sin_family = AF_INET;      
	their_addr.sin_port = htons(m_nPort); 
	their_addr.sin_addr.s_addr = inet_addr (GetServerAddress());
	if (their_addr.sin_addr.s_addr == -1)
	{
		// resolve a DNS server name if inet_addr() came up empty.
		struct hostent *pHE = (struct hostent *)gethostbyname(GetServerAddress());
		if (pHE == 0)
		{ 
			GString strError;
			strError.Format("gethostbyname() failed to resolve[%s]",GetServerAddress());
			throw CSocketError(errno,(const char *)strError);
		}
		memcpy((char *)&(their_addr.sin_addr), pHE->h_addr,pHE->h_length); 
	}
	memset(&(their_addr.sin_zero),0, 8);//zero the rest of the struct


	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) 
	{	
		throw CSocketError(0,"socket");
	}
	CSocketWrap sockfd(fd); 


	// local bind() is not required on WIN32 platform
	struct sockaddr_in localAddr; 
	localAddr.sin_family = AF_INET;
	localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	localAddr.sin_port = htons(0);
	int rc = bind(fd, (struct sockaddr *) &localAddr, sizeof(localAddr));
	if(rc<0) 
	{
		GString strError;
		strError.Format("failed to bind([%s]:%d)",GetServerAddress(),(int)m_nPort);
		throw CSocketError(errno,(const char *)strError);
	}


	if (connect(fd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) 
	{
		GString strError;
		strError.Format("failed to connect([%s]:%d)",GetServerAddress(),(int)m_nPort);
		throw CSocketError(errno,(const char *)strError);
	}

	// 200 bytes in excess
	char *pSendBuf = new char[200 + nRequestLen + nNamespaceLen];
	sprintf(pSendBuf,"POST /XMLServer/UBT.dll?%s HTTP/1.1\r\nUser-Agent: XML_Object_Framework_DataSource\r\nHost: 100.100.100.100\r\nContent-Length:  ",pzNamespace);
	
	GString strTemp;
	strTemp.Format("%d\r\n\r\n%s",(int)nNamespaceLen + nRequestLen,pzNamespace);
	strcat(&pSendBuf[120],(const char *)strTemp);
	int nHeaderLen = (int)strlen(&pSendBuf[120]) + 120;
	strcat(&pSendBuf[120],pzRequest);


	int nTotalMessageLength = nHeaderLen + nRequestLen;


	if ((numbytes=sendto(sockfd, pSendBuf, nTotalMessageLength, 0, 
		 (struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) 
	{
		delete[] pSendBuf;
		throw CSocketError(sockfd,"sendto");
	}
	delete[] pSendBuf;

	int nCumulativeBytes = 0;
	numbytes = 0;
	do
	{
		if ((numbytes=recv(sockfd, m_winsockBuffer, sizeof(m_winsockBuffer), 0)) == -1) 
		{
			continue;
		}
		destinationStream.write(m_winsockBuffer,numbytes);
		nCumulativeBytes += numbytes;
	}while( numbytes != 0 );
}
示例#3
0
BOOL CHwSMTP::SendSpeedEmail
		(
			LPCTSTR	lpszAddrFrom,
			LPCTSTR	lpszAddrTo,
			LPCTSTR	lpszSubject,
			LPCTSTR	lpszBody,
			LPCTSTR	lpszCharSet,
			CStringArray *pStrAryAttach,
			LPCTSTR	pStrAryCC,
			UINT	nSmtpSrvPort,
			LPCTSTR	pSend
		)
{

	BOOL ret=true;
	CString To;
	To += GET_SAFE_STRING(lpszAddrTo);
	To += _T(";");
	To += GET_SAFE_STRING(pStrAryCC);

	std::map<CString,std::vector<CString>> Address;

	int start = 0;
	while( start >= 0 )
	{
		CString one= To.Tokenize(_T(";"),start);
		one=one.Trim();
		if(one.IsEmpty())
			continue;

		CString addr;
		addr = GetServerAddress(one);
		if(addr.IsEmpty())
			continue;

		Address[addr].push_back(one);

	}

	std::map<CString,std::vector<CString>>::iterator itr1  =  Address.begin();
	for(  ;  itr1  !=  Address.end();  ++itr1 )
	{
		PDNS_RECORD pDnsRecord;
		PDNS_RECORD pNext;

		DnsQuery(itr1->first ,
						DNS_TYPE_MX,DNS_QUERY_STANDARD,
						NULL,			//Contains DNS server IP address.
						&pDnsRecord,	//Resource record that contains the response.
						NULL
						);

		CString to;
		to.Empty();
		for(int i=0;i<itr1->second.size();i++)
		{
			to+=itr1->second[i];
			to+=_T(";");
		}
		if(to.IsEmpty())
			continue;

		pNext=pDnsRecord;
		while(pNext)
		{
			if(pNext->wType == DNS_TYPE_MX)
				if(SendEmail(pNext->Data.MX.pNameExchange,NULL,NULL,false,
					lpszAddrFrom,to,lpszSubject,lpszBody,lpszCharSet,pStrAryAttach,pStrAryCC,
					25,pSend,lpszAddrTo))
					break;
			pNext=pNext->pNext;
		}
		if(pNext == NULL)
			ret = false;

		//SendEmail(itr1.first,NULL,NULL,false,lpszAddrFrom,,lpszFromname);
		DnsRecordListFree(pDnsRecord,DnsFreeRecordList);
	}

	return ret;
}