예제 #1
0
void HTTPRequestHandler::handleRequest()
{
    int err = 0;
    
    switch (msg.request) {
        case HTTP_RT_GET:
            INFO("Dispatching GET Request.");
            err = handleGetRequest();
            break;
            
        case HTTP_RT_POST:
            INFO("Dispatching POST request.");
            err = handlePostRequest();
            break;
            
        case HTTP_RT_PUT:
            INFO("Dispatching PUT request.");
            err = handlePutRequest();
            break;
            
        default:
            INFO("Error in handleRequest, unhandled request type.");
            err = HTTP_NotImplemented;
            break;
    }
    
    //  if any of these functions returns a negative number, call the error handler
    if (err > 0) {
        handleError(err);
    }        
}
예제 #2
0
static void startFileHandler(HttpQueue *q)
{
    HttpConn    *conn;
    HttpRx      *rx;
    HttpTx      *tx;
    HttpPacket  *packet;

    conn = q->conn;
    rx = conn->rx;
    tx = conn->tx;
    
    if (tx->finalized || conn->error) {
        return;

    } else if (rx->flags & HTTP_PUT) {
        handlePutRequest(q);
        
    } else if (rx->flags & HTTP_DELETE) {
        handleDeleteRequest(q);
        
    } else if (rx->flags & HTTP_OPTIONS) {
        httpHandleOptions(q->conn);
        
    } else if (!(tx->flags & HTTP_TX_NO_BODY)) {
        /* Create a single data packet based on the entity length */
        packet = httpCreateEntityPacket(0, tx->entityLength, readFileData);
        if (!tx->outputRanges) {
            /* Can set a content length */
            tx->length = tx->entityLength;
        }
        /* Add to the output service queue */
        httpPutForService(q, packet, 0);
    }
}
예제 #3
0
uint16_t handleRequest(char* req, cSocket* sock) {
	if(req == NULL || sock == NULL)
		return -1;
		
	if(strlen(req) == 0)
		return -1;

	// init buffer for requests
	char buffer[1024];
	bzero(buffer,1024);
	uint16_t offset = 0;
	uint16_t bufferoffset = 0;
	
	while(offset < strlen(req) && req[offset] != '\0') {
		// copy request to buffer
		buffer[bufferoffset] = req[offset];
		
		// if string is ended
		if(req[offset] == '\n' || req[offset] == '\0') {
			buffer[bufferoffset] = '\0';
			// check what request is it and create header for request
			if(preg_match(buffer,"^GET[ ](.+)$") == 0) {
				uint16_t retcode = handleGetRequest(buffer,sock);
				if(retcode != HTTP_OK) forgeHeader(retcode,sock,"");
				return retcode;
			}
			else if(preg_match(buffer,"^POST[ ](.+)$") == 0) {
				uint16_t retcode = handlePostRequest(buffer,sock);
				if(retcode != HTTP_OK) forgeHeader(retcode,sock,"");
				return retcode;
			}
			else if(preg_match(buffer,"^PUT[ ](.+)$") == 0) {
				uint16_t retcode = handlePutRequest(buffer,sock);
				if(retcode != HTTP_OK) forgeHeader(retcode,sock,"");
				return retcode;
			}
			else {
				forgeHeader(HTTP_ERROR_NOT_IMPLEMENTED,sock,"");
				return HTTP_ERROR_NOT_IMPLEMENTED;
			}
			bzero(buffer,1024);
			bufferoffset = 0;
		}
		else
			bufferoffset++;
		
		offset++;
	}
	
	return 0;
}
예제 #4
0
static void startFileHandler(HttpQueue *q)
{
    HttpConn    *conn;
    HttpRx      *rx;
    HttpTx      *tx;
    HttpPacket  *packet;

	int beint;
				
	printf("\n  startFileHandler  \n");

    conn = q->conn;
    rx = conn->rx;
    tx = conn->tx;
    assure(!tx->finalized);
    
    if (rx->flags & HTTP_PUT) {
        handlePutRequest(q);
        
    } else if (rx->flags & HTTP_DELETE) {
        handleDeleteRequest(q);
        
    } else if (!(tx->flags & HTTP_TX_NO_BODY)) {
        /* Create a single data packet based on the entity length */
        packet = httpCreateEntityPacket(0, tx->entityLength, readFileData);
        if (!tx->outputRanges) {
            /* Can set a content length */
			
			if(strcmp(tx->filename ,"C:\\Project\\appweb-4.2.0\\windows-x86-vsdebug\\web\\movie.mp4") == 0)
			{	
				tx->cacheBuffer = 0;
				tx->length = 400000;

			}
			else
			{
				tx->length = tx->entityLength;
			}	
	beint = tx->length;

	printf("\n--------------------\n");
	printf("beint,tx->filename : %d \t +%s+",beint,tx->filename);
	printf("\n--------------------\n");


        }
        /* Add to the output service queue */
        httpPutForService(q, packet, 0);
    }

}
예제 #5
0
void receieveMessages(int socket){
	char *mesg;
	mesg = malloc(1);
	while(1){
		if (recv(socket, mesg, 1, 0) >= 1){
			if(strcmp(mesg, "0") == 0){
				handlePutRequest(socket);
			}
			else if(strcmp(mesg, "1") == 0){
				handleGetRequest(socket);
			}
			else if(strcmp(mesg, "2") == 0){
				handleListRequest(socket);
			}							
		}
	}	
}