コード例 #1
0
ファイル: http_server.c プロジェクト: zhenglu/meowboard
/*! \brief Process an incoming message */
static void hc_process(HttpConnection* connection) {
    const char* tmp;
    const char* data;
    int content_size, header_size;
	HttpRequest hr;
    HttpServer* server = connection->server;

    /* get the content lenght */
    tmp = http_get_field(connection->header, "Content-Length");
    if(tmp == NULL) {
        content_size = 0;
    } else {
        content_size = atoi(tmp);
    }

    /* find the beginning of the content */
    data = strstr(connection->buffer, HTTP_LINE_SEP HTTP_LINE_SEP) + 4;

    header_size = data - connection->buffer;


    /* check if the message is bigger than current buffer size */
    if(content_size + header_size >= MAX_BUFFER_SIZE) {
        log(WARNING, "Message is too big");
        hc_report_error(connection, "Message is too big");
        return;
    }

    /* check if everything is here */
    if(connection->buffer_size >= header_size + content_size) {

        log(INFO, "Processing request Content-Length=%d", content_size);

        /* inform the request */
		hr.connection = connection;
		hr.header = connection->header;
		hr.data = data;
		hr.data_size = content_size;
		server->callback(server->user_data, &hr);

        /* free the header, we don't need it anymore */
		http_delete(connection->header);
		connection->header = NULL;

        /* move the buffer */
        if(connection->buffer_size > header_size + content_size) {
            memmove(connection->buffer, connection->buffer + header_size +
                    content_size, connection->buffer_size - header_size -
                    content_size);
            connection->buffer_size -= header_size + content_size;
        } else {
            connection->buffer_size = 0;
        }
    }
}
コード例 #2
0
ファイル: HttpServer.cpp プロジェクト: svalat/htopml
/*******************  FUNCTION  *********************/
void* HttpServer::staticCallback(mg_event event, mg_connection* conn)
{
    const struct mg_request_info *request_info = mg_get_request_info(conn);
    HttpServer * server = (HttpServer*)request_info->user_data;
    return server->callback(event,conn,request_info);
}