void* Extractor::masterExtractorThreadMethod(void)
	{
	/* Enable asynchronous cancellation of this thread: */
	Threads::Thread::setCancelState(Threads::Thread::CANCEL_ENABLE);
	Threads::Thread::setCancelType(Threads::Thread::CANCEL_ASYNCHRONOUS);
	
	/* Handle extraction requests until interrupted: */
	Realtime::AlarmTimer alarm;
	Misc::Time expirationTime(0.1);
	while(true)
		{
		/* Wait until there is a seed request: */
		Parameters* parameters;
		unsigned int requestID;
		{
		Threads::Mutex::Lock seedRequestLock(seedRequestMutex);
		#ifdef __DARWIN__
		if(terminate)
			return 0;
		while(seedParameters==0)
			{
			seedRequestCond.wait(seedRequestMutex);
			if(terminate)
				return 0;
			}
		#else
		while(seedParameters==0)
			seedRequestCond.wait(seedRequestMutex);
		#endif
		
		/* Grab the seed request parameters: */
		parameters=seedParameters;
		seedParameters=0;
		
		/* Grab the seed request ID: */
		requestID=seedRequestID;
		}
		
		/* Get the next free visualization element: */
		int nextIndex=(lockedIndex+1)%3;
		if(nextIndex==mostRecentIndex)
			nextIndex=(nextIndex+1)%3;
		
		if(parameters->isValid())
			{
			/* Prepare for extracting a new visualization element: */
			if(extractor->getPipe()!=0)
				{
				/* Notify the slave nodes that a new visualization element is coming: */
				extractor->getPipe()->write<unsigned int>(requestID);
				
				/* Send the extraction parameters to the slaves: */
				parameters->write(*extractor->getPipe(),extractor->getVariableManager());
				extractor->getPipe()->finishMessage();
				}
			
			if(extractor->hasIncrementalCreator())
				{
				/* Start the visualization element: */
				trackedElements[nextIndex]=extractor->startElement(parameters);
				trackedElementIDs[nextIndex]=requestID;
				
				/* Continue extracting the visualization element until it is done: */
				bool keepGrowing;
				do
					{
					/* Grow the visualization element by a little bit: */
					alarm.armTimer(expirationTime);
					keepGrowing=!extractor->continueElement(alarm);
					
					/* Push this visualization element to the main thread: */
					mostRecentIndex=nextIndex;
					Vrui::requestUpdate();
					
					/* Check if there is another seed request: */
					if(keepGrowing)
						{
						Threads::Mutex::Lock seedRequestLock(seedRequestMutex);
						keepGrowing=seedParameters==0;
						}
					
					if(extractor->getPipe()!=0)
						{
						/* Tell the slave nodes whether the current visualization element is finished: */
						extractor->getPipe()->write<unsigned int>(keepGrowing?1:0);
						extractor->getPipe()->finishMessage();
						}
					}
				while(keepGrowing);
				
				/* Finish the element: */
				extractor->finishElement();
				}
			else
				{
				/* Extract the visualization element: */
				trackedElements[nextIndex]=extractor->createElement(parameters);
				trackedElementIDs[nextIndex]=requestID;
				
				if(extractor->getPipe()!=0)
					{
					/* Tell the slave nodes that the current visualization element is finished: */
					extractor->getPipe()->write<unsigned int>(0);
					extractor->getPipe()->finishMessage();
					}
				
				/* Push this visualization element to the main thread: */
				mostRecentIndex=nextIndex;
				update();
				}
			}
		else
			{
			if(extractor->getPipe()!=0)
				{
				/* Notify the slave nodes that there is no visualization element: */
				extractor->getPipe()->write<unsigned int>(0);
				extractor->getPipe()->write<unsigned int>(requestID);
				extractor->getPipe()->finishMessage();
				}
			
			/* Store an invalid visualization element: */
			trackedElements[nextIndex]=0;
			trackedElementIDs[nextIndex]=requestID;
			
			/* Push this visualization element to the main thread: */
			mostRecentIndex=nextIndex;
			update();
			}
		}
	
	return 0;
	}
Beispiel #2
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
#ifdef __EXPIRATION__
	// Program Expiration routines
	CTime expirationTime(2010,	// year
		2,					// month
		30,					// date
		23,					// hour 24
		59,					// minute
		59);				// second
	CTime currentTime = CTime::GetCurrentTime();

    CTimeSpan leftTime = expirationTime - currentTime;   

	// 사용 기간이 남았을 경우
	if(leftTime.GetTotalSeconds() > 0)
    {
		 CString msg;
		 msg = L"";
		 msg += L"This is a trial version of BTools2\n";
		 msg += expirationTime.Format(L"Expiration date :\n %Y-%m-%d  %H:%M:%S\n\n");
		 msg += leftTime.Format(L"%D day(s) and\n %H:%M:%S left" );
     
		 // 사용 기간이 3일 미만 남았을 경우
		 if(leftTime.GetDays() < 7)
		 {
			 msg = leftTime.Format(L"This software will expire after %D day(s)");// %H Hour(s) %M Minute(s)");
			 //AtlMessageBox(NULL, msg.GetBuffer(), L"Expiration Warning");
		 }
		 //AfxMessageBox(msg);
    }
    else // 사용 기간이 만료된 경우
    {
		CString msg("This is a trial version of BTools2\n"
				"If you want to use this software more\n"
				"Please contact to me.\[email protected]\n"
				"Thank you for your interest\n");

		msg += expirationTime.Format(L"Expiration date :\n %Y-%m-%d  %H:%M\n\n");
		msg += leftTime.Format(L"%D day(s) and\n %H:%M:%S passed" );
        //msg.Format(L"This software is submitted for the Windows Mobile Contest");
		//AtlMessageBox(NULL, msg.GetBuffer(), L"Warning");
		return FALSE;
	 }

#endif

#ifdef __TSTORE_ARM__0
	// ARM
	T_RETURN ret;
	TAPPID *APPID = TSTORE_APPLICATION_ID;

	bool aSuccess=true;

	T_RETURN res; 
	ARM_PLUGIN_Initialize(&res,APPID);
	if (res.code == ARM_SUCCESS) 
	{
		ARM_PLUGIN_CheckLicense(&res); 
		if (res.code == ARM_SUCCESS) 
		{ 
			ARM_PLUGIN_RequestLicense(&res); 
			if (res.code !=ARM_SUCCESS) 
			{ //실패시 구현 
				aSuccess=false;
				TCHAR wszMsg[1024];
				if(ret.pMsg)
				{
					ansi_to_unicode(ret.pMsg, strlen(ret.pMsg), wszMsg, 1024);
					::AtlMessageBox(NULL, wszMsg, L"[ARM]Request License");
				}
			}
		
		} 
		else 
		{//실패시 메시 구현 
			aSuccess=false;

			TCHAR wszMsg[1024];

			switch(res.code)
			{
			case CLICENSE_DENY:
			case CLICENSE_NOT_EXIST:
			case CLICENSE_EXPIRED:
			case CLICENSE_INVALID:
				{
					if(ret.pMsg)
					{
						ansi_to_unicode(ret.pMsg, strlen(ret.pMsg), wszMsg, 1024);
						::AtlMessageBox(NULL, wszMsg, L"[ARM]Check License");
					}
				}

			default:
				;
			}
		} 
	} 
	else 
	{ 
		aSuccess=false; 
	} 
	ARM_PLUGIN_Uninitialize(&res); 


	//if (! aSuccess) return 0;//PostQuitMessage(0); 

#endif

	//CAboutDlg aboutDlg;	aboutDlg.DoModal();
    //
	HRESULT hRes = CBTools2Frame::ActivatePreviousInstance(hInstance, lpstrCmdLine);

	if(FAILED(hRes) || S_FALSE == hRes)
	{
		return hRes;
	}

	hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	AtlInitCommonControls(ICC_DATE_CLASSES);
	SHInitExtraControls();

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = CBTools2Frame::AppRun(lpstrCmdLine, nCmdShow);

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Beispiel #3
0
bool CTlsSocket::ExtractCert(gnutls_datum_t const* datum, CCertificate& out)
{
	gnutls_x509_crt_t cert;
	if (gnutls_x509_crt_init(&cert)) {
		m_pOwner->LogMessage(MessageType::Error, _("Could not initialize structure for peer certificates, gnutls_x509_crt_init failed"));
		return false;
	}

	if (gnutls_x509_crt_import(cert, datum, GNUTLS_X509_FMT_DER)) {
		m_pOwner->LogMessage(MessageType::Error, _("Could not import peer certificates, gnutls_x509_crt_import failed"));
		gnutls_x509_crt_deinit(cert);
		return false;
	}

	fz::datetime expirationTime(gnutls_x509_crt_get_expiration_time(cert), fz::datetime::seconds);
	fz::datetime activationTime(gnutls_x509_crt_get_activation_time(cert), fz::datetime::seconds);

	// Get the serial number of the certificate
	unsigned char buffer[40];
	size_t size = sizeof(buffer);
	int res = gnutls_x509_crt_get_serial(cert, buffer, &size);
	if( res != 0 ) {
		size = 0;
	}

	wxString serial = bin2hex(buffer, size);

	unsigned int pkBits;
	int pkAlgo = gnutls_x509_crt_get_pk_algorithm(cert, &pkBits);
	wxString pkAlgoName;
	if (pkAlgo >= 0) {
		const char* pAlgo = gnutls_pk_algorithm_get_name((gnutls_pk_algorithm_t)pkAlgo);
		if (pAlgo)
			pkAlgoName = wxString(pAlgo, wxConvUTF8);
	}

	int signAlgo = gnutls_x509_crt_get_signature_algorithm(cert);
	wxString signAlgoName;
	if (signAlgo >= 0) {
		const char* pAlgo = gnutls_sign_algorithm_get_name((gnutls_sign_algorithm_t)signAlgo);
		if (pAlgo)
			signAlgoName = wxString(pAlgo, wxConvUTF8);
	}

	wxString subject, issuer;

	size = 0;
	res = gnutls_x509_crt_get_dn(cert, 0, &size);
	if (size) {
		char* dn = new char[size + 1];
		dn[size] = 0;
		if (!(res = gnutls_x509_crt_get_dn(cert, dn, &size)))
		{
			dn[size] = 0;
			subject = wxString(dn, wxConvUTF8);
		}
		else
			LogError(res, _T("gnutls_x509_crt_get_dn"));
		delete [] dn;
	}
	else
		LogError(res, _T("gnutls_x509_crt_get_dn"));
	if (subject.empty()) {
		m_pOwner->LogMessage(MessageType::Error, _("Could not get distinguished name of certificate subject, gnutls_x509_get_dn failed"));
		gnutls_x509_crt_deinit(cert);
		return false;
	}

	std::vector<wxString> alt_subject_names = GetCertSubjectAltNames(cert);

	size = 0;
	res = gnutls_x509_crt_get_issuer_dn(cert, 0, &size);
	if (size) {
		char* dn = new char[++size + 1];
		dn[size] = 0;
		if (!(res = gnutls_x509_crt_get_issuer_dn(cert, dn, &size))) {
			dn[size] = 0;
			issuer = wxString(dn, wxConvUTF8);
		}
		else
			LogError(res, _T("gnutls_x509_crt_get_issuer_dn"));
		delete [] dn;
	}
	else
		LogError(res, _T("gnutls_x509_crt_get_issuer_dn"));
	if (issuer.empty() ) {
		m_pOwner->LogMessage(MessageType::Error, _("Could not get distinguished name of certificate issuer, gnutls_x509_get_issuer_dn failed"));
		gnutls_x509_crt_deinit(cert);
		return false;
	}

	wxString fingerprint_sha256;
	wxString fingerprint_sha1;

	unsigned char digest[100];
	size = sizeof(digest) - 1;
	if (!gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA256, digest, &size)) {
		digest[size] = 0;
		fingerprint_sha256 = bin2hex(digest, size);
	}
	size = sizeof(digest) - 1;
	if (!gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, digest, &size)) {
		digest[size] = 0;
		fingerprint_sha1 = bin2hex(digest, size);
	}

	gnutls_x509_crt_deinit(cert);

	out = CCertificate(
		datum->data, datum->size,
		activationTime, expirationTime,
		serial,
		pkAlgoName, pkBits,
		signAlgoName,
		fingerprint_sha256,
		fingerprint_sha1,
		issuer,
		subject,
		alt_subject_names);

	return true;
}
void* Visualizer::DataLocator::incrementalExtractorThreadMethod(void)
	{
	/* Enable asynchronous cancellation of this thread: */
	Threads::Thread::setCancelState(Threads::Thread::CANCEL_ENABLE);
	Threads::Thread::setCancelType(Threads::Thread::CANCEL_ASYNCHRONOUS);
	
	/* Handle extraction requests until interrupted: */
	Realtime::AlarmTimer alarm;
	Misc::Time expirationTime(0.1);
	while(true)
		{
		/* Wait until there is a seed request: */
		Locator* locator;
		{
		Threads::Mutex::Lock seedRequestLock(seedRequestMutex);
		#ifdef __DARWIN__
		while(seedLocator==0)
			{
			seedRequestCond.wait(seedRequestMutex);
			if(terminate)
				return 0;
			}
		#else
		while(seedLocator==0)
			seedRequestCond.wait(seedRequestMutex);
		#endif
		locator=seedLocator;
		seedLocator=0;
		extracting=true;
		}
		
		/* Start extracting a new visualization element: */
		int nextIndex=(renderIndex+1)%3;
		if(nextIndex==mostRecentIndex)
			nextIndex=(nextIndex+1)%3;
		
		if(locator->isValid())
			{
			if(extractor->getPipe()!=0)
				{
				/* Notify the slave nodes that a new visualization element is coming: */
				extractor->getPipe()->write<int>(1);
				}
			trackedElements[nextIndex]=extractor->startElement(locator);
			
			/* Continue extracting the visualization element until it is done: */
			bool keepGrowing;
			do
				{
				/* Grow the visualization element by a little bit: */
				alarm.armTimer(expirationTime);
				keepGrowing=!extractor->continueElement(alarm);
				
				/* Set the most recently updated visualization element: */
				mostRecentIndex=nextIndex;
				Vrui::requestUpdate();
				
				/* Check if the current element is still being tracked: */
				{
				Threads::Mutex::Lock seedRequestLock(seedRequestMutex);
				if(seedTracking)
					keepGrowing=false;
				extracting=keepGrowing;
				}
				}
			while(keepGrowing);
			extractor->finishElement();
			}
		else
			{
			if(extractor->getPipe()!=0)
				{
				/* Notify the slave nodes that the currently tracked visualization element should be deleted: */
				extractor->getPipe()->write<int>(0);
				}
			trackedElements[nextIndex]=0;
			mostRecentIndex=nextIndex;
			Vrui::requestUpdate();
			}
		delete locator;
		if(extractor->getPipe()!=0)
			{
			extractor->getPipe()->barrier();
			}
		}
	
	return 0;
	}