示例#1
0
/*
 * Performs an action based on the passed key.
 * 
 * Parameters:
 *   int key: The value of the key to perform an action based upon
 *   
 * Returns: A pointer to the Screen object control should shift to after this function exits, or
 *   NULL if control should not shift to another Screen object
 */
void GameScreen::respondToKey(int key) throw (QUIT, NEW_SCREEN) {
    switch (key) {
        case 'w':
        case Key::UP: // UP
            doSoftFall();
            break;
        case 'a':
        case Key::LEFT: // LEFT
            doShiftLeft();
            break;
        case 's':
        case Key::DOWN: // DOWN
            doShiftDown();
            break;
        case 'd':
        case Key::RIGHT: // RIGHT
            doShiftRight();
            break;
        case 'q': // Rotate CCW
            doRotateCCWWithKick();
            break;
        case 'e': // Rotate CW
            doRotateCWWithKick();
            break;
        case 'p':
        case ' ':
            doPause();
            break;
        case Key::ESC:
            doExit();
            break;
    }
}
示例#2
0
void CPlay::eval () {

	game->draw ();

	if (game->isLevelComplete()) {
		doExitLevel();
		return;
	}		
	
	//
	// eval game when EVAL_INTERVAL has elapsed.
	// this ensures the game plays at the same speed 
	// on all machines.		
	//
	
	bool evaled = false;
	while (adjustedEvalTime >= CGame::EVAL_INTERVAL) {

		adjustedEvalTime -= CGame::EVAL_INTERVAL;
		evaled = true;	
		
		game->eval (lmbExists); 

		if (CGameDevice::MOUSE_RMB) rmbExists = true;	else if (rmbExists) { doPause (); return; }							
		if (isKeyPressed (CGameDevice::ESC, esc)) { doAbort (); return; }				

	}
	if (evaled) adjustedEvalTime = 0; // discard remaining time for smooth motion					

}
示例#3
0
bool GameClassic::doRun()
{
	SDL_Event event;
	if(SDL_PollEvent(&event))
	{
		switch(event.type)
		{
			case SDL_QUIT:
			{
				return false;
				break;
			}
			case SDL_KEYDOWN:
			{
				if ( event.key.keysym.sym == SDLK_ESCAPE ) 
				{
					m_mgr->SetActiveModule(MAINMENU);
					return true;
				} 
				if ( event.key.keysym.sym == SDLK_p || event.key.keysym.sym == SDLK_SPACE) 
				{
					doPause();
				} 
				if ( event.key.keysym.sym == SDLK_UP && snake->GetDirection()!=Down) 
				{
					snake->SetDirection(Up);
				} 
				if ( event.key.keysym.sym == SDLK_DOWN && snake->GetDirection()!=Up) 
				{
					snake->SetDirection(Down);
				} 
				if ( event.key.keysym.sym == SDLK_LEFT && snake->GetDirection()!=Right) 
				{
					snake->SetDirection(Left);
				} 
				if ( event.key.keysym.sym == SDLK_RIGHT && snake->GetDirection()!=Left) 
				{
					snake->SetDirection(Right);
				} 
				break;
			}
		}

	}
	if(snake->Move())
	{
		Converter.Convert();
		DrawField();
		DrawTop();
		SDL_Delay(50);
	}
	else
	{
		Converter.Convert();
		DrawField();
		DrawTop();
		GameOver();		
	}
	return true;
}
示例#4
0
 void Service::control( DWORD code )
 {
   switch ( code )
   {
     case SERVICE_CONTROL_INTERROGATE:
       SetServiceStatus( mStatusHandle, &mStatus );
     break;
     case SERVICE_CONTROL_STOP:
     case SERVICE_CONTROL_SHUTDOWN:
       if ( mStatus.dwCurrentState == SERVICE_STOP_PENDING
         || mStatus.dwCurrentState == SERVICE_STOPPED )
         return;
       setState( SERVICE_STOP_PENDING, 0 );
       doStop();
       setState( SERVICE_STOPPED, 0 );
     break;
     case SERVICE_CONTROL_PAUSE:
       if ( mStatus.dwCurrentState != SERVICE_RUNNING )
         return;
       setState( SERVICE_PAUSE_PENDING, 0 );
       doPause();
       setState( SERVICE_PAUSED, 0 );
     break;
     case SERVICE_CONTROL_CONTINUE:
       if ( mStatus.dwCurrentState != SERVICE_PAUSED )
         return;
       setState( SERVICE_CONTINUE_PENDING, 0 );
       doContinue();
       setState( SERVICE_RUNNING, 0 );
     break;
   }
 }
示例#5
0
void ThreadPool::run()
{
	for (uint8 x=0; x<m_uiCount; x++)
	{
		ThreadPoolThread *thread = new ThreadPoolThread(this, false);
		thread->onCompleteEvent += delegate(this, &ThreadPool::onThreadComplete);
		m_vThreadList.push_back( thread );


		thread->start();
	}

	while (!isStopped())
	{
		doPause();

		removedForced();

		uint32 runTaskCount = activeThreads();

		if (runTaskCount < m_uiCount)
			startNewTasks();

		runTaskCount = activeThreads();

		if ((runTaskCount == m_uiCount || m_vTaskList.empty()) && !isStopped())
			m_WaitCondition.wait();
	}
}
示例#6
0
int MWBotWin::oilGameEscape() {
	qDebug() << "oil game escape";
	QWebElement blk, tlm;
	blk = frm->findFirstElement("div#neftlenin_alert_mission div.content-block div.actions button.button div.c");
	tlm = blk.findFirst("span.suspicion span.price_escape");
	int need = 0;
	if (!tlm.isNull()) {
		need = tlm.toPlainText().toInt();
	}
	qDebug() << "need" << need << "susp";

	if (need == 0) {
		log(trUtf8("Патруль пройден успешно"),"neft.png");
		fightResult();
		clickElement(blk);
	} else {
		tlm = frm->findFirstElement("div.pipeline-actions table td.mc div.progress i.counter");
		int susp = tlm.toPlainText().toInt();

		if (!checkSusp(susp, need)) {
			clickElement(blk);
			log(trUtf8("Уходим от патруля за %0 подозрительности").arg(need),"neft.png");
			doPause(2);
		}
	}
	return need;
}
示例#7
0
void ItemThread::run()
{
    while (!isStopped())
    {
        doPause();

        if (!performTask())
            m_WaitCond.wait(2);
    }
}
示例#8
0
void UpdateProgThread::run()
{
	m_tStartTime = gcTime();
	m_tLastUpdateTime = gcTime();

	for (uint8 x=0; x<m_pCount; x++)
		m_vProgInfo.push_back(0);

	while (!isStopped())
	{
		doPause();
		gcSleep(500);
		calcResults();
	}
}
示例#9
0
void SMTController::run()
{
	assert(m_uiNumber);
	assert(m_szFile);

	fillFileList();
	m_pUPThread->start();

	if (!makeThreads())
		return;

	for (size_t x=0; x<m_vWorkerList.size(); x++)
		m_vWorkerList[x]->workThread->start();

	while (true)
	{
		doPause();

		if (isStopped())
			break;

		//wait here as we have nothing else to do
		m_WaitCond.wait(2);

		if (m_iRunningWorkers==0)
			break;
	}

	m_pUPThread->stop();

	for (size_t x=0; x<m_vWorkerList.size(); x++)
		m_vWorkerList[x]->workThread->stop();

	if (!isStopped())
		postProcessing();

	safe_delete(m_vWorkerList);
}
示例#10
0
GstPlayer::GstPlayer(QObject *parent):
    IMediaPlayer(parent),
    playing(false),
    loaded(false),
    error(false),
    playingRequested(false),
    mustSeek(true),
    duration(-1),
    position(0),
    formatTime(GST_FORMAT_TIME),
    pipeline(0),
    gstObjectName("player")
{
    GstPlayer::ensureInitGst();
    connect(this,SIGNAL(requestPause()),this,SLOT(doPause()));
    connect(this,SIGNAL(requestPlay()),this,SLOT(doPlay()));
    connect(this,SIGNAL(requestStop()),this,SLOT(doStop()));
    //watcher = NULL;
    theVol = new GValue();
    g_value_init(theVol,G_TYPE_DOUBLE);

    positionQueryTimer = new QTimer(this);

}
示例#11
0
void controlPause(player_struct* p, bool down, bool held)
{
	if(!p || !down)return;

	doPause(NULL);
}
示例#12
0
static OSStatus sslServe(
	otSocket				listenSock,
	SSLProtocol				tryVersion,
	const char				*hostName,			// e.g., "www.amazon.com"
	CFArrayRef				serverCerts,		// required
	CFArrayRef				encryptServerCerts,	// optional
	CSSM_BOOL				allowExpired,
	CSSM_BOOL				allowAnyRoot,
	char					cipherRestrict,		// '2', 'd'. etc...'\0' for no
												//   restriction
	SSLAuthenticate			authenticate,
	CSSM_BOOL				resumableEnable,
	CSSM_BOOL				silent,				// no stdout
	CSSM_BOOL				pause,
	SSLProtocol				*negVersion,		// RETURNED
	SSLCipherSuite			*negCipher,			// RETURNED
	CFArrayRef				*peerCerts)			// mallocd & RETURNED
{
	otSocket			acceptSock;
    PeerSpec            peerId;
    OSStatus            ortn;
    SSLContextRef       ctx = NULL;
    UInt32              length;
    uint8               rcvBuf[RCV_BUF_SIZE];
	char *outMsg = SERVER_MESSAGE;
	
    *negVersion = kSSLProtocolUnknown;
    *negCipher = SSL_NULL_WITH_NULL_NULL;
    *peerCerts = NULL;
    
	#if IGNORE_SIGPIPE
	signal(SIGPIPE, sigpipe);
	#endif
	
	/* first wait for a connection */
	if(!silent) {
		printf("Waiting for client connection...");
		fflush(stdout);
	}
	ortn = AcceptClientConnection(listenSock, &acceptSock, &peerId);
    if(ortn) {
    	printf("AcceptClientConnection returned %d; aborting\n", ortn);
    	return ortn;
    }

	/* 
	 * Set up a SecureTransport session.
	 * First the standard calls.
	 */
	ortn = SSLNewContext(true, &ctx);
	if(ortn) {
		printSslErrStr("SSLNewContext", ortn);
		goto cleanup;
	} 
	ortn = SSLSetIOFuncs(ctx, SocketRead, SocketWrite);
	if(ortn) {
		printSslErrStr("SSLSetIOFuncs", ortn);
		goto cleanup;
	} 
	ortn = SSLSetProtocolVersion(ctx, tryVersion);
	if(ortn) {
		printSslErrStr("SSLSetProtocolVersion", ortn);
		goto cleanup;
	} 
	ortn = SSLSetConnection(ctx, acceptSock);
	if(ortn) {
		printSslErrStr("SSLSetConnection", ortn);
		goto cleanup;
	}
	ortn = SSLSetPeerDomainName(ctx, hostName, strlen(hostName) + 1);
	if(ortn) {
		printSslErrStr("SSLSetPeerDomainName", ortn);
		goto cleanup;
	}
	
	/* have to do these options befor setting server certs */
	if(allowExpired) {
		ortn = SSLSetAllowsExpiredCerts(ctx, true);
		if(ortn) {
			printSslErrStr("SSLSetAllowExpiredCerts", ortn);
			goto cleanup;
		}
	}
	if(allowAnyRoot) {
		ortn = SSLSetAllowsAnyRoot(ctx, true);
		if(ortn) {
			printSslErrStr("SSLSetAllowAnyRoot", ortn);
			goto cleanup;
		}
	}

	ortn = SSLSetCertificate(ctx, serverCerts);
	if(ortn) {
		printSslErrStr("SSLSetCertificate", ortn);
		goto cleanup;
	}
	if(encryptServerCerts) {
		ortn = SSLSetEncryptionCertificate(ctx, encryptServerCerts);
		if(ortn) {
			printSslErrStr("SSLSetEncryptionCertificate", ortn);
			goto cleanup;
		}
	}
	
	/* 
	 * SecureTransport options.
	 */ 
	if(resumableEnable) {
		ortn = SSLSetPeerID(ctx, &peerId, sizeof(PeerSpec));
		if(ortn) {
			printSslErrStr("SSLSetPeerID", ortn);
			goto cleanup;
		}
	}
	if(cipherRestrict != '\0') {
		ortn = setCipherRestrictions(ctx, cipherRestrict);
		if(ortn) {
			goto cleanup;
		}
	}
	#if AUTHENTICATE_ENABLE
	if(authenticate != kNeverAuthenticate) {
		ortn = SSLSetClientSideAuthenticate(ctx, authenticate);
		if(ortn) {
			printSslErrStr("SSLSetClientSideAuthenticate", ortn);
			goto cleanup;
		}
	}
	#endif
	if(pause) {
		doPause("SSLContext initialized");
	}
	
	/* Perform SSL/TLS handshake */
    do
    {   ortn = SSLHandshake(ctx);
	    if((ortn == errSSLWouldBlock) && !silent) {
	    	/* keep UI responsive */ 
	    	outputDot();
	    }
    } while (ortn == errSSLWouldBlock);
	
	/* this works even if handshake failed due to cert chain invalid */
	copyPeerCerts(ctx, peerCerts);

	SSLGetNegotiatedCipher(ctx, negCipher);
	SSLGetNegotiatedProtocolVersion(ctx, negVersion);
	
	if(!silent) {
		printf("\n");
	}
    if(ortn) {
    	goto cleanup;
    }
	if(pause) {
		doPause("SSLContext handshake complete");
	}

	/* wait for one complete line or user says they've had enough */
	while(ortn == noErr) {
	    length = sizeof(rcvBuf);
	    ortn = SSLRead(ctx, rcvBuf, length, &length);
	    if(length == 0) {
	    	/* keep UI responsive */ 
	    	outputDot();
	    }
	    else {
	    	/* print what we have */
	    	printf("client request: ");
	    	dumpAscii(rcvBuf, length);
	    }
	    if(pause) {
	    	/* allow user to bail */
	    	char resp;
	    	
			fpurge(stdin);
	    	printf("\nMore client request (y/anything): ");
	    	resp = getchar();
	    	if(resp != 'y') {
	    		break;
	    	}
	    }
	    
	    /* poor person's line completion scan */
	    for(unsigned i=0; i<length; i++) {
	    	if((rcvBuf[i] == '\n') || (rcvBuf[i] == '\r')) {
	    		/* a labelled break would be nice here.... */
	    		goto serverResp;
	    	}
	    }
	    if (ortn == errSSLWouldBlock) {
	        ortn = noErr;
	    }
	}
	
serverResp:
	if(pause) {
		doPause("Client GET msg received");
	}

	/* send out canned response */
	length = strlen(outMsg);
 	ortn = SSLWrite(ctx, outMsg, length, &length);
 	if(ortn) {
 		printSslErrStr("SSLWrite", ortn);
 	}
	if(pause) {
		doPause("Server response sent");
	}
    if (ortn == noErr) {
        ortn = SSLClose(ctx);
	}
cleanup:
	if(acceptSock) {
		endpointShutdown(acceptSock);
	}
	if(ctx) {
	    SSLDisposeContext(ctx);  
	}    
	/* FIXME - dispose of serverCerts */
	return ortn;
}
static OSStatus sslServe(
	otSocket				listenSock,
	unsigned short			portNum,
	SSLProtocol				tryVersion,			// only used if acceptedProts NULL
	const char				*acceptedProts,
	CFArrayRef				serverCerts,		// required
	char					*password,			// optional
	CFArrayRef				encryptServerCerts,	// optional
	bool				allowExpired,
	bool				allowAnyRoot,
	bool				allowExpiredRoot,
	bool				disableCertVerify,
	char					*anchorFile,
	bool				replaceAnchors,
	char					cipherRestrict,		// '2', 'd'. etc...'\0' for no
												//   restriction
	SSLAuthenticate			authenticate,
	unsigned char			*dhParams,			// optional D-H parameters	
	unsigned				dhParamsLen,
	CFArrayRef				acceptableDNList,	// optional 
	bool				resumableEnable,
	uint32_t					sessionCacheTimeout,// optional
	bool				disableAnonCiphers,
	bool				silent,				// no stdout
	bool				pause,
	SSLProtocol				*negVersion,		// RETURNED
	SSLCipherSuite			*negCipher,			// RETURNED
	SSLClientCertificateState *certState,		// RETURNED
	Boolean					*sessionWasResumed,	// RETURNED
	unsigned char			*sessionID,			// mallocd by caller, RETURNED
	size_t					*sessionIDLength,	// RETURNED
	CFArrayRef				*peerCerts,			// mallocd & RETURNED
	char					**argv)
{
	otSocket			acceptSock;
    PeerSpec            peerId;
    OSStatus            ortn;
    SSLContextRef       ctx = NULL;
    size_t              length;
    uint8_t             rcvBuf[RCV_BUF_SIZE];
	const char *outMsg = SERVER_MESSAGE;
	
    *negVersion = kSSLProtocolUnknown;
    *negCipher = SSL_NULL_WITH_NULL_NULL;
    *peerCerts = NULL;
    
	#if IGNORE_SIGPIPE
	signal(SIGPIPE, sigpipe);
	#endif
	
	/* first wait for a connection */
	if(!silent) {
		printf("Waiting for client connection on port %u...", portNum);
		fflush(stdout);
	}
	ortn = AcceptClientConnection(listenSock, &acceptSock, &peerId);
    if(ortn) {
    	printf("AcceptClientConnection returned %d; aborting\n", (int)ortn);
    	return ortn;
    }

	/* 
	 * Set up a SecureTransport session.
	 * First the standard calls.
	 */
	ortn = SSLNewContext(true, &ctx);
	if(ortn) {
		printSslErrStr("SSLNewContext", ortn);
		goto cleanup;
	} 
	ortn = SSLSetIOFuncs(ctx, SocketRead, SocketWrite);
	if(ortn) {
		printSslErrStr("SSLSetIOFuncs", ortn);
		goto cleanup;
	} 
	ortn = SSLSetConnection(ctx, (SSLConnectionRef)(intptr_t)acceptSock);
	if(ortn) {
		printSslErrStr("SSLSetConnection", ortn);
		goto cleanup;
	}
	
	/* have to do these options befor setting server certs */
	if(allowExpired) {
		ortn = SSLSetAllowsExpiredCerts(ctx, true);
		if(ortn) {
			printSslErrStr("SSLSetAllowExpiredCerts", ortn);
			goto cleanup;
		}
	}
	if(allowAnyRoot) {
		ortn = SSLSetAllowsAnyRoot(ctx, true);
		if(ortn) {
			printSslErrStr("SSLSetAllowAnyRoot", ortn);
			goto cleanup;
		}
	}

	if(anchorFile) {
		ortn = sslAddTrustedRoot(ctx, anchorFile, replaceAnchors);
		if(ortn) {
			printf("***Error obtaining anchor file %s\n", anchorFile);
			goto cleanup;
		}
	}
	if(serverCerts != NULL) {
		if(anchorFile == NULL) {
			/* no specific anchors, so assume we want to trust this one */
			ortn = addIdentityAsTrustedRoot(ctx, serverCerts);
			if(ortn) {
				goto cleanup;
			}
		}
		ortn = SSLSetCertificate(ctx, serverCerts);
		if(ortn) {
			printSslErrStr("SSLSetCertificate", ortn);
			goto cleanup;
		}
	}
	if(encryptServerCerts) {
		ortn = SSLSetEncryptionCertificate(ctx, encryptServerCerts);
		if(ortn) {
			printSslErrStr("SSLSetEncryptionCertificate", ortn);
			goto cleanup;
		}
	}
	if(allowExpiredRoot) {
		ortn = SSLSetAllowsExpiredRoots(ctx, true);
		if(ortn) {
			printSslErrStr("SSLSetAllowsExpiredRoots", ortn);
			goto cleanup;
		}
	}
	if(disableCertVerify) {
		ortn = SSLSetEnableCertVerify(ctx, false);
		if(ortn) {
			printSslErrStr("SSLSetEnableCertVerify", ortn);
			goto cleanup;
		}
	}
	
	/* 
	 * SecureTransport options.
	 */ 
	if(acceptedProts) {
		ortn = SSLSetProtocolVersionEnabled(ctx, kSSLProtocolAll, false);
		if(ortn) {
			printSslErrStr("SSLSetProtocolVersionEnabled(all off)", ortn);
			goto cleanup;
		}
		for(const char *cp = acceptedProts; *cp; cp++) {
			SSLProtocol prot = kSSLProtocolUnknown;
			switch(*cp) {
				case '2':
					prot = kSSLProtocol2;
					break;
				case '3':
					prot = kSSLProtocol3;
					break;
				case 't':
					prot = kTLSProtocol1;
					break;
				default:
					usage(argv);
			}
			ortn = SSLSetProtocolVersionEnabled(ctx, prot, true);
			if(ortn) {
				printSslErrStr("SSLSetProtocolVersionEnabled", ortn);
				goto cleanup;
			}
		}
	}
	else {
		ortn = SSLSetProtocolVersion(ctx, tryVersion);
		if(ortn) {
			printSslErrStr("SSLSetProtocolVersion", ortn);
			goto cleanup;
		} 
	}
	if(resumableEnable) {
		ortn = SSLSetPeerID(ctx, &peerId, sizeof(PeerSpec));
		if(ortn) {
			printSslErrStr("SSLSetPeerID", ortn);
			goto cleanup;
		}
	}
	if(cipherRestrict != '\0') {
		ortn = sslSetCipherRestrictions(ctx, cipherRestrict);
		if(ortn) {
			goto cleanup;
		}
	}
	if(authenticate != kNeverAuthenticate) {
		ortn = SSLSetClientSideAuthenticate(ctx, authenticate);
		if(ortn) {
			printSslErrStr("SSLSetClientSideAuthenticate", ortn);
			goto cleanup;
		}
	}
	if(dhParams) {
		ortn = SSLSetDiffieHellmanParams(ctx, dhParams, dhParamsLen);
		if(ortn) {
			printSslErrStr("SSLSetDiffieHellmanParams", ortn);
			goto cleanup;
		}
	}
	if(sessionCacheTimeout) {
		ortn = SSLSetSessionCacheTimeout(ctx, sessionCacheTimeout);
		if(ortn) {
			printSslErrStr("SSLSetSessionCacheTimeout", ortn);
			goto cleanup;
		}
	}
	if(disableAnonCiphers) {
		ortn = SSLSetAllowAnonymousCiphers(ctx, false);
		if(ortn) {
			printSslErrStr("SSLSetAllowAnonymousCiphers", ortn);
			goto cleanup;
		}
		/* quickie test of the getter */
		Boolean e;
		ortn = SSLGetAllowAnonymousCiphers(ctx, &e);
		if(ortn) {
			printSslErrStr("SSLGetAllowAnonymousCiphers", ortn);
			goto cleanup;
		}
		if(e) {
			printf("***SSLGetAllowAnonymousCiphers() returned true; expected false\n");
			ortn = errSecIO;
			goto cleanup;
		}
	}
/* XXX/cs
	if(acceptableDNList) {
		ortn = SSLSetCertificateAuthorities(ctx, acceptableDNList, TRUE);
		if(ortn) {
			printSslErrStr("SSLSetCertificateAuthorities", ortn);
			goto cleanup;
		}
	}
*/
	/* end options */

	if(pause) {
		doPause("SSLContext initialized");
	}
	
	/* Perform SSL/TLS handshake */
    do
    {   ortn = SSLHandshake(ctx);
	    if((ortn == errSSLWouldBlock) && !silent) {
	    	/* keep UI responsive */ 
	    	sslOutputDot();
	    }
    } while (ortn == errSSLWouldBlock);
	
	/* this works even if handshake failed due to cert chain invalid */
	copyPeerCerts(ctx, peerCerts);

	SSLGetClientCertificateState(ctx, certState);
	SSLGetNegotiatedCipher(ctx, negCipher);
	SSLGetNegotiatedProtocolVersion(ctx, negVersion);
	*sessionIDLength = MAX_SESSION_ID_LENGTH;
	SSLGetResumableSessionInfo(ctx, sessionWasResumed, sessionID,
		sessionIDLength);
	
	if(!silent) {
		printf("\n");
	}
    if(ortn) {
    	goto cleanup;
    }
	if(pause) {
		doPause("SSLContext handshake complete");
	}

	/* wait for one complete line or user says they've had enough */
	while(ortn == errSecSuccess) {
	    length = sizeof(rcvBuf);
	    ortn = SSLRead(ctx, rcvBuf, length, &length);
	    if(length == 0) {
	    	/* keep UI responsive */ 
	    	sslOutputDot();
	    }
	    else {
	    	/* print what we have */
	    	printf("client request: ");
	    	dumpAscii(rcvBuf, length);
	    }
	    if(pause) {
	    	/* allow user to bail */
	    	char resp;
	    	
			fpurge(stdin);
	    	printf("\nMore client request (y/anything): ");
	    	resp = getchar();
	    	if(resp != 'y') {
	    		break;
	    	}
	    }
	    
	    /* poor person's line completion scan */
	    for(unsigned i=0; i<length; i++) {
	    	if((rcvBuf[i] == '\n') || (rcvBuf[i] == '\r')) {
	    		/* a labelled break would be nice here.... */
	    		goto serverResp;
	    	}
	    }
	    if (ortn == errSSLWouldBlock) {
	        ortn = errSecSuccess;
	    }
	}
	
serverResp:
	if(pause) {
		doPause("Client GET msg received");
	}

	/* send out canned response */
	length = strlen(outMsg);
 	ortn = SSLWrite(ctx, outMsg, length, &length);
 	if(ortn) {
 		printSslErrStr("SSLWrite", ortn);
 	}
	if(pause) {
		doPause("Server response sent");
	}
cleanup:
	/*
	 * always do close, even on error - to flush outgoing write queue 
	 */
	OSStatus cerr = SSLClose(ctx);
	if(ortn == errSecSuccess) {
		ortn = cerr;
	}
	if(acceptSock) {
		endpointShutdown(acceptSock);
	}
	if(ctx) {
	    SSLDisposeContext(ctx);  
	}    
	/* FIXME - dispose of serverCerts */
	return ortn;
}
int main(int argc, char **argv)
{
	int					arg;
	char				*argp;
	CSSM_HANDLE 		modHand = 0;
	void 				*foo;
	CSSM_SERVICE_TYPE	svcType = CSSM_SERVICE_CSP;
	const CSSM_GUID		*guid = &gGuidAppleCSP;
	const char			*modName = "AppleCSP";
	CSSM_RETURN			crtn;
	CSSM_BOOL			doLoad = CSSM_FALSE;
	CSSM_BOOL			doUnload = CSSM_FALSE;
	
	/* force link against malloc */
	foo = malloc(1);
	for(arg=1; arg<argc; arg++) {
		argp = argv[arg];
		switch(argp[0]) {
			case 'l':
				doLoad = CSSM_TRUE;
				break;
			case 'u':
				doLoad = doUnload = CSSM_TRUE;
				break;
			case 'd':
				guid = &gGuidAppleCSPDL;
				modName = "AppleCSPDL";
				break;
			case 'c':
				guid = &gGuidAppleX509CL;
				svcType = CSSM_SERVICE_CL;
				modName = "AppleX509CL";
				break;
			case 't':
				guid = &gGuidAppleX509TP;
				svcType = CSSM_SERVICE_TP;
				modName = "AppleX509TP";
				break;
		    case 'h':
		    default:
				usage(argv);
		}
	}
	
	if(doPause("Top of test")) {
		goto done;
	}
	
	/* CSSM init, just once */
	if(!cssmStartup()) {
		printf("Oops, error starting up CSSM\n");
		exit(1);
	}
	if(doPause("CSSM initialized")) {
		goto done;
	}
		
	
	if(!doLoad) {
		/* load, just once */
		crtn = CSSM_ModuleLoad(guid,
			CSSM_KEY_HIERARCHY_NONE,
			NULL,			// eventHandler
			NULL);			// AppNotifyCallbackCtx
		if(crtn) {
			printf("Error loading %s\n", modName);
			printError("CSSM_ModuleLoad", crtn);
			return 0;
		}
		if(doPause("CSSM_ModuleLoad() complete")) {
			goto done;
		}
	}
	while(1) {
		if(doLoad) {
			/* load, each time */
			crtn = CSSM_ModuleLoad(guid,
				CSSM_KEY_HIERARCHY_NONE,
				NULL,			// eventHandler
				NULL);			// AppNotifyCallbackCtx
			if(crtn) {
				printf("Error loading %s\n", modName);
				printError("CSSM_ModuleLoad", crtn);
				return 0;
			}
			if(doPause("CSSM_ModuleLoad() complete")) {
				break;
			}
		}
		crtn = CSSM_ModuleAttach (guid,
			&vers,
			&memFuncs,				// memFuncs
			0,						// SubserviceID
			svcType,			
			0,						// AttachFlags
			CSSM_KEY_HIERARCHY_NONE,
			NULL,					// FunctionTable
			0,						// NumFuncTable
			NULL,					// reserved
			&modHand);
		if(crtn) {
			printf("Error attaching to %s\n", modName);
			printError("CSSM_ModuleAttach", crtn);
			return 0;
		}
		if(doPause("ModuleAttach() complete")) {
			break;
		}
		CSSM_ModuleDetach(modHand);
		modHand = 0;
		if(doPause("ModuleDetach() complete")) {
			break;
		}
		if(doUnload) {
			/* unload, each time */
			crtn = CSSM_ModuleUnload(guid, NULL, NULL);
			if(crtn) {
				printf("Error unloading %s\n", modName);
				printError("CSSM_ModuleUnload", crtn);
				return 0;
			}
			if(doPause("ModuleUnload() complete")) {
				break;
			}
		}	/* unloading */
	}		/* main loop */

done:
	fpurge(stdin);
	if(modHand) {
		CSSM_ModuleDetach(modHand);
		printf("Final detach complete; cr to exit: ");
	}
	else {
		printf("Test complete; cr to exit: ");
	}
	getchar();
	return 0;
}
void DirectShowPlayerService::run()
{
    QMutexLocker locker(&m_mutex);

    for (;;) {
        ::ResetEvent(m_taskHandle);

        while (m_pendingTasks == 0) {
            DWORD result = 0;

            locker.unlock();
            if (m_eventHandle) {
                HANDLE handles[] = { m_taskHandle, m_eventHandle };

                result = ::WaitForMultipleObjects(2, handles, false, INFINITE);
            } else {
                result = ::WaitForSingleObject(m_taskHandle, INFINITE);
            }
            locker.relock();

            if (result == WAIT_OBJECT_0 + 1) {
                graphEvent(&locker);
            }
        }

        if (m_pendingTasks & ReleaseGraph) {
            m_pendingTasks ^= ReleaseGraph;
            m_executingTask = ReleaseGraph;

            doReleaseGraph(&locker);
        } else if (m_pendingTasks & Shutdown) {
            return;
        } else if (m_pendingTasks & ReleaseAudioOutput) {
            m_pendingTasks ^= ReleaseAudioOutput;
            m_executingTask = ReleaseAudioOutput;

            doReleaseAudioOutput(&locker);
        } else if (m_pendingTasks & ReleaseVideoOutput) {
            m_pendingTasks ^= ReleaseVideoOutput;
            m_executingTask = ReleaseVideoOutput;

            doReleaseVideoOutput(&locker);
        } else if (m_pendingTasks & SetUrlSource) {
            m_pendingTasks ^= SetUrlSource;
            m_executingTask = SetUrlSource;

            doSetUrlSource(&locker);
        } else if (m_pendingTasks & SetStreamSource) {
            m_pendingTasks ^= SetStreamSource;
            m_executingTask = SetStreamSource;

            doSetStreamSource(&locker);
        } else if (m_pendingTasks & Render) {
            m_pendingTasks ^= Render;
            m_executingTask = Render;

            doRender(&locker);
        } else if (!(m_executedTasks & Render)) {
            m_pendingTasks &= ~(FinalizeLoad | SetRate | Stop | Pause | Seek | Play);
        } else if (m_pendingTasks & FinalizeLoad) {
            m_pendingTasks ^= FinalizeLoad;
            m_executingTask = FinalizeLoad;

            doFinalizeLoad(&locker);
        } else if (m_pendingTasks & Stop) {
            m_pendingTasks ^= Stop;
            m_executingTask = Stop;

            doStop(&locker);
        } else if (m_pendingTasks & SetRate) {
            m_pendingTasks ^= SetRate;
            m_executingTask = SetRate;

            doSetRate(&locker);
        } else if (m_pendingTasks & Pause) {
            m_pendingTasks ^= Pause;
            m_executingTask = Pause;

            doPause(&locker);
        } else if (m_pendingTasks & Seek) {
            m_pendingTasks ^= Seek;
            m_executingTask = Seek;

            doSeek(&locker);
        } else if (m_pendingTasks & Play) {
            m_pendingTasks ^= Play;
            m_executingTask = Play;

            doPlay(&locker);
        }
        m_executingTask = 0;
    }
}
示例#16
0
/* -------------------------------------------------------------------- */
BOOL mAbort(void)
{
    char c, rc, oldEcho, tmpOutFlag;

    /* Check for abort/pause from user */
    if (outFlag == IMPERVIOUS)
        return FALSE;

    if (!BBSCharReady() && outFlag != OUTPAUSE) {
    /* Let modIn() report the problem */
        if (haveCarrier && !gotCarrier())
            iChar();
        rc = FALSE;
    } else {
        oldEcho = echo;
        echo = NEITHER;
        echoChar = 0;

        if (outFlag == OUTPAUSE) {
            c = 'P';
        } else {
            c = (char) toupper(iChar());
        }

        switch (c) {
            case 19:        /* XOFF */
            case 'P':       /* pause:         */
				rc = doPause();
                break;
            case 'C':
                dotoMessage = COPY_IT;
                rc = FALSE;
                break;
            case 'J':       /* jump paragraph: */
                outFlag = OUTPARAGRAPH;
                rc = FALSE;
                break;
            case 'K':       /* kill:          */
                if (gl_user.aide ||
                    (cfg.kill && (strcmpi(logBuf.lbname, msgBuf->mbauth) == SAMESTRING)
                    && loggedIn))
                    dotoMessage = PULL_IT;
                rc = FALSE;
                break;
            case 'M':       /* mark:          */
                if (gl_user.aide)
                    dotoMessage = MARK_IT;
                rc = FALSE;
                break;
            case 'N':       /* next:          */
                outFlag = OUTNEXT;
                rc = TRUE;
                break;
            case 'S':       /* skip:          */
                outFlag = OUTSKIP;
                rc = TRUE;
                break;
            case 'R':
                dotoMessage = REVERSE_READ;
                rc = FALSE;
                break;
            case '~':
                termCap(TERM_NORMAL);
                gl_term.ansiOn = !gl_term.ansiOn;
                break;
            case '!':
                gl_term.IBMOn = !gl_term.IBMOn;
                break;
            default:
                rc = FALSE;
                break;
        }
        echo = oldEcho;
    }
    if (rc) {
		tmpOutFlag = outFlag;
		outFlag = OUTOK;
        termCap(TERM_NORMAL);
		outFlag = tmpOutFlag;
	}
    return rc;
}
示例#17
0
//=============================================================================
// METHOD    : SPELLcontroller::executeCommand()
//=============================================================================
void SPELLcontroller::executeCommand( const ExecutorCommand& cmd )
{
	// If a (repeatable) command is being executed, discard this one
	if (isCommandPending() &&
	    (cmd.id != CMD_ABORT) &&
	    (cmd.id != CMD_FINISH) &&
	    (cmd.id != CMD_INTERRUPT) &&
	    (cmd.id != CMD_PAUSE) &&
	    (cmd.id != CMD_CLOSE))
	{
		LOG_WARN("Discarding command " + cmd.id);
		return;
	}

	LOG_INFO("Now executing command " + cmd.id);

    startCommandProcessing();

    if (cmd.id == CMD_ABORT)
    {
        doAbort();
    }
    else if (cmd.id == CMD_FINISH)
    {
        doFinish();
    }
    else if (cmd.id == CMD_ACTION)
    {
        doUserAction();
    }
    else if (cmd.id == CMD_STEP)
    {
        doStep( false );
    }
    else if (cmd.id == CMD_STEP_OVER)
    {
        doStep( true );
    }
    else if (cmd.id == CMD_RUN)
    {
        doPlay();
    }
    else if (cmd.id == CMD_SKIP)
    {
        doSkip();
    }
    else if (cmd.id == CMD_GOTO)
    {
        if (cmd.earg == "line")
        {
            DEBUG("[C] Processing go-to-line " + cmd.arg);
            try
            {
                int line = STRI(cmd.arg);
                doGoto( line );
            }
            catch(...) {};
        }
        else if (cmd.earg == "label")
        {
            DEBUG("[C] Processing go-to-label " + cmd.arg);
            doGoto( cmd.arg );
        }
        else
        {
        	SPELLexecutor::instance().getCIF().error("Unable to process Go-To command, no target information", LanguageConstants::SCOPE_SYS );
        }
    }
    else if (cmd.id == CMD_PAUSE)
    {
        doPause();
    }
    else if (cmd.id == CMD_INTERRUPT)
    {
        doInterrupt();
    }
    else if (cmd.id == CMD_SCRIPT)
    {
    	/** \todo determine when to override */
        doScript(cmd.arg,false);
    }
    else if (cmd.id == CMD_CLOSE)
    {
        m_recover = false;
        m_reload = false;
        doClose();
    }
    else if (cmd.id == CMD_RELOAD)
    {
        doReload();
    }
    else if (cmd.id == CMD_RECOVER)
    {
        doRecover();
    }
    else
    {
        LOG_ERROR("[C] UNRECOGNISED COMMAND: " + cmd.id)
    }
	m_mailbox.commandProcessed();

	// The command has finished, release the dispatcher
	setCommandFinished();
	DEBUG("[C] Command execution finished " + cmd.id);

	//TEMPORARILY DISABLED: it creates deadlocks.
	// notifyCommandToCore( cmd.id );
}