Пример #1
0
void Request::handle( void ){
	if( getRequest() ){
		if( method == "GET" )
			processGet( true );
		if( method == "HEAD" ) 
			processGet( false);
	}
}
Пример #2
0
STDMETHODIMP GuestSessionWrap::ProcessGet(ULONG aPid,
                                          IGuestProcess **aGuestProcess)
{
    LogRelFlow(("{%p} %s:enter aPid=%RU32 aGuestProcess=%p\n", this, "GuestSession::processGet", aPid, aGuestProcess));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        CheckComArgOutPointerValidThrow(aGuestProcess);

        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = processGet(aPid,
                         ComTypeOutConverter<IGuestProcess>(aGuestProcess).ptr());
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave aGuestProcess=%p hrc=%Rhrc\n", this, "GuestSession::processGet", *aGuestProcess, hrc));
    return hrc;
}
Пример #3
0
// This callback function is called when the CMD_EXECUTE command is received.  
// It should look at the data received so far, and figure out what operation 
// needs to be done on that data.  Since this is a simulation, and our 
// protocol doesn't really do anything useful, we will not really do much in 
// this example.   
void cmdExecute(void *base) 
{
	risp_length_t existing;
	node_t *ptr = (node_t *) base;
 	assert(ptr != NULL);
	
 	assert(ptr->stats != NULL);
	ptr->stats->operations ++;
	ptr->stats->commands ++;

	existing = ptr->out.length;

	printf("node:%d EXECUTE (%d)\n", ptr->handle, ptr->data.op);

	// here we check what the current operation is.
	switch(ptr->data.op) {
		case CMD_LIST:
// 			processList(ptr);
			break;

		case CMD_LISTING:
// 			processListing(ptr);
			break;
			
		case CMD_LISTING_DONE:
// 			processListingDone(ptr);
			break;

		case CMD_PUT:
// 			processPut(ptr);
			break;

		case CMD_GET:
			processGet(ptr);
			break;

		default:
			// we should not have any other op than what we know about.
			assert(0);
			break;
	}
	
	if (existing == 0 && ptr->out.length > 0) {
		// we weren't previously going to send out anything... but now we are, so we need to send the write event.
		if (event_del(&ptr->event) != -1) {
			event_set(&ptr->event, ptr->handle, EV_READ | EV_WRITE | EV_PERSIST, node_event_handler, base);
			event_base_set(ptr->event.ev_base, &ptr->event);
			event_add(&ptr->event, 0);
		}
	}
}
Пример #4
0
void processClientMessage(char* command, char* out_buffer)
{
	/*
	 * If other commands have not implemented logic to overwrite the server's output buffer,
	 *    client calling any any valid command after calling "list" causes the server output
	 *    to still display the list output.
	 */
	printf("**processClientMessage: command=%s\n", command);
	if(strcmp(command, "test") == 0) {
		strcpy(out_buffer, command);
	}
	else if(strcmp(command, "list") == 0) {  //process client command: list
		printf("**processClientMessage/processList\n");
		processList(out_buffer);
	}
	else if(strncmp(command, "check", 5) == 0) {  // processes client command: check filename
		printf("**processClientMessage/processCheck\n");
		char filename[MAXDATASIZE];
		strcpy(filename, command+strlen("check"));
		printf("**processClientMessage/processCheck: filename=%s\n", filename);

		processCheck(out_buffer, filename);
	}
	else if(strncmp(command, "get", 3) == 0) {  // processes client command: get filename
		printf("**processClientMessage/processGet\n");
		char filename[MAXDATASIZE];
		strcpy(filename, command+strlen("get"));
		printf("**processClientMessage/processCheck: filename=%s\n", filename);

		processGet(out_buffer, filename);
	}
	else if(strcmp(command, "quit") == 0) {
		strcpy(out_buffer, "goodbye");
	}
	else {
		printf("**processClientMessage/default\n");
		strcpy(out_buffer, "**command not recognized");
	}

	printf("**exiting processClientMessage\n");
}
Пример #5
0
void Request::processGet( bool isget ){
	string file, filetype;
	struct stat fileinfo;

	file.assign( server_root  );
	file.append( url );
	

	if( lstat( file.c_str(), &fileinfo ) < 0 )
		send_r_404();
	else if( S_ISREG( fileinfo.st_mode )  )
		send_r_200(isget?file:"", (int)fileinfo.st_size );
	else if( S_ISDIR( fileinfo.st_mode ) ){
		if( url[ url.length()-1 ] != '/' )
			send_r_301( url+"/" );
		else{
			url += "/index.html";
			processGet( isget );
		}
	}
}
Пример #6
0
void sendingLogic(int sending_filedes, char *command) {
	printf("client367>> ");
	scanf("%s", command);

	int needsFilenameArg = strcmp(command, "check") == 0 || strcmp(command, "get") == 0;
	if (needsFilenameArg) {
		char filename[MAXDATASIZE - strlen(command)];
		scanf("%s", filename);  // catching space separated filename
		printf("**filename=%s\n", filename);
		strcat(command, filename);
	}

	// processing client-side commands
	int isClientSideCommand = strcmp(command, "display") == 0 || strcmp(command, "help") == 0;
	if (isClientSideCommand) {
		if(strcmp(command, "display") == 0) {
			char display[MAXDATASIZE];
			char filename[MAXDATASIZE];
			scanf("%s", filename);
			processGet(display, filename);
		}
		if(strcmp(command, "help") == 0) {
			printf("list: lists all files and directory names at the directory of the server.\n"
				   "check filename: checks if the file filename is contained in the server directory.\n"
				   "get filename: downloads the contents of the file filename from the server to a file of the same name in the client directory\n"
				   "display filename: Displays the contents of the file filename from the client directory\n"
				   "help: Displays this message\n"
				   "quit: Closes client connection to the server.\n");
		}
	}
	else {
		printf("Sending %s\n", command);
		ssize_t sendStatus = send(sending_filedes, command, MAXDATASIZE-1, 0);

		if (sendStatus == ERRNUM) {
			// send message thru socket
			perror("send");
		}
	}
}
Пример #7
0
bool QUERY_RETRIEVE_SCP_EMULATOR_CLASS::processCommandDataset(DCM_COMMAND_CLASS *command_ptr, DCM_DATASET_CLASS *dataset_ptr)

//  DESCRIPTION     : Process the Storage command and dataset.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	bool result;

	// handle individual commands
	switch(command_ptr->getCommandId())
	{
	case DIMSE_CMD_CFIND_RQ:
		if (dataset_ptr)
		{
			// process the FIND command
			result = processFind(dataset_ptr);
		}
		else
		{
			// missing dataset
			UINT16 status = DCM_STATUS_PROCESSING_FAILURE;
			result = sendResponse(DIMSE_CMD_CFIND_RSP, status);
		}
		break;

	case DIMSE_CMD_CMOVE_RQ:
		if (dataset_ptr)
		{
			// process the MOVE command
			result = processMove(dataset_ptr);
		}
		else
		{
			// missing dataset
			UINT16 status = DCM_STATUS_PROCESSING_FAILURE;
			result = sendResponse(DIMSE_CMD_CMOVE_RSP, status);
		}
		break;

	case DIMSE_CMD_CGET_RQ:
		if (dataset_ptr)
		{
			// process the GET command
			result = processGet(dataset_ptr);
		}
		else
		{
			// missing dataset
			UINT16 status = DCM_STATUS_PROCESSING_FAILURE;
			result = sendResponse(DIMSE_CMD_CGET_RSP, status);
		}
		break;

	default:
		{
			// unknown command
			UINT16 status = DCM_STATUS_UNRECOGNIZED_OPERATION;
			result = sendResponse(command_ptr->getCommandId(), status);
		}
		break;
	}

	// return result
	return result;
}
Пример #8
0
bool PRINT_SCP_EMULATOR_CLASS::processCommandDataset(DCM_COMMAND_CLASS *command_ptr, DCM_DATASET_CLASS *dataset_ptr)

//  DESCRIPTION     : Process the Print command (and dataset).
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	bool result;

	// handle individual commands
	switch(command_ptr->getCommandId())
	{
	case DIMSE_CMD_NACTION_RQ:
		// process the ACTION command
		result = processAction(command_ptr->getEncodePresentationContextId());
		break;
	case DIMSE_CMD_NCREATE_RQ:
	    if ((sopClassUidM == FILM_SESSION_SOP_CLASS_UID) ||
		    (dataset_ptr))
		{
			// process the CREATE command
            // - Basic Film Session may not define a dataset - but that is OK
			result = processCreate(command_ptr->getEncodePresentationContextId(), dataset_ptr);
		}
		else
		{
			// missing dataset
			UINT16 status = DCM_STATUS_PROCESSING_FAILURE;
			result = sendResponse(DIMSE_CMD_NCREATE_RSP,
				command_ptr->getEncodePresentationContextId(),
				status);
		}
		break;
	case DIMSE_CMD_NDELETE_RQ:
		// process the DELETE command
		result = processDelete(command_ptr->getEncodePresentationContextId());
		break;
	case DIMSE_CMD_NEVENTREPORT_RSP:
		// nothing to do here
		result = true;
		break;
	case DIMSE_CMD_NGET_RQ:
		// process the GET command
		result = processGet(command_ptr);
		break;
	case DIMSE_CMD_NSET_RQ:
		if (dataset_ptr)
		{
			// process the SET dataset
			result = processSet(command_ptr->getEncodePresentationContextId(), dataset_ptr);
		}
		else
		{
			// missing dataset
			UINT16 status = DCM_STATUS_PROCESSING_FAILURE;
			result = sendResponse(DIMSE_CMD_NSET_RSP,
				command_ptr->getEncodePresentationContextId(), 
				status);
		}
		break;
	default:
		{
			// unknown command
			UINT16 status = DCM_STATUS_UNRECOGNIZED_OPERATION;
			result = sendResponse(command_ptr->getCommandId(),
				command_ptr->getEncodePresentationContextId(), 
				status);
		}
		break;
	}

	// return result
	return result;
}