2019-08-22 04:30:11 +00:00
|
|
|
/*
|
|
|
|
* HTTP server driver
|
|
|
|
*
|
|
|
|
* Copyright 2019 Zebediah Figura
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "winternl.h"
|
2019-08-22 04:30:12 +00:00
|
|
|
#include "winioctl.h"
|
2019-08-22 04:30:11 +00:00
|
|
|
#include "ddk/wdm.h"
|
|
|
|
#include "wine/debug.h"
|
2019-08-22 04:30:13 +00:00
|
|
|
#include "wine/heap.h"
|
|
|
|
#include "wine/list.h"
|
2019-08-22 04:30:11 +00:00
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
static HANDLE directory_obj;
|
|
|
|
static DEVICE_OBJECT *device_obj;
|
|
|
|
|
2019-08-22 04:30:11 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(http);
|
|
|
|
|
2019-08-22 04:30:13 +00:00
|
|
|
#define DECLARE_CRITICAL_SECTION(cs) \
|
|
|
|
static CRITICAL_SECTION cs; \
|
|
|
|
static CRITICAL_SECTION_DEBUG cs##_debug = \
|
|
|
|
{ 0, 0, &cs, { &cs##_debug.ProcessLocksList, &cs##_debug.ProcessLocksList }, \
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": " # cs) }}; \
|
|
|
|
static CRITICAL_SECTION cs = { &cs##_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
DECLARE_CRITICAL_SECTION(http_cs);
|
|
|
|
|
|
|
|
struct request_queue
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list request_queues = LIST_INIT(request_queues);
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
static NTSTATUS WINAPI dispatch_create(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
2019-08-22 04:30:13 +00:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
struct request_queue *queue;
|
|
|
|
|
|
|
|
if (!(queue = heap_alloc_zero(sizeof(*queue))))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
stack->FileObject->FsContext = queue;
|
|
|
|
|
|
|
|
EnterCriticalSection(&http_cs);
|
|
|
|
list_add_head(&request_queues, &queue->entry);
|
|
|
|
LeaveCriticalSection(&http_cs);
|
|
|
|
|
|
|
|
TRACE("Created queue %p.\n", queue);
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-08-22 04:30:13 +00:00
|
|
|
static void close_queue(struct request_queue *queue)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&http_cs);
|
|
|
|
list_remove(&queue->entry);
|
|
|
|
LeaveCriticalSection(&http_cs);
|
|
|
|
|
|
|
|
heap_free(queue);
|
|
|
|
}
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
static NTSTATUS WINAPI dispatch_close(DEVICE_OBJECT *device, IRP *irp)
|
|
|
|
{
|
2019-08-22 04:30:13 +00:00
|
|
|
IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation(irp);
|
|
|
|
struct request_queue *queue = stack->FileObject->FsContext;
|
|
|
|
|
|
|
|
TRACE("Closing queue %p.\n", queue);
|
|
|
|
close_queue(queue);
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI unload(DRIVER_OBJECT *driver)
|
|
|
|
{
|
2019-08-22 04:30:13 +00:00
|
|
|
struct request_queue *queue, *queue_next;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(queue, queue_next, &request_queues, struct request_queue, entry)
|
|
|
|
{
|
|
|
|
close_queue(queue);
|
|
|
|
}
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
IoDeleteDevice(device_obj);
|
|
|
|
NtClose(directory_obj);
|
|
|
|
}
|
|
|
|
|
2019-08-22 04:30:11 +00:00
|
|
|
NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, UNICODE_STRING *path)
|
|
|
|
{
|
2019-08-22 04:30:12 +00:00
|
|
|
static const WCHAR device_nameW[] = {'\\','D','e','v','i','c','e','\\','H','t','t','p','\\','R','e','q','Q','u','e','u','e',0};
|
|
|
|
static const WCHAR directory_nameW[] = {'\\','D','e','v','i','c','e','\\','H','t','t','p',0};
|
|
|
|
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
|
|
|
|
UNICODE_STRING string;
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
2019-08-22 04:30:11 +00:00
|
|
|
TRACE("driver %p, path %s.\n", driver, debugstr_w(path->Buffer));
|
|
|
|
|
2019-08-22 04:30:12 +00:00
|
|
|
RtlInitUnicodeString(&string, directory_nameW);
|
|
|
|
attr.ObjectName = &string;
|
|
|
|
if ((ret = NtCreateDirectoryObject(&directory_obj, 0, &attr)) && ret != STATUS_OBJECT_NAME_COLLISION)
|
|
|
|
ERR("Failed to create \\Device\\Http directory, status %#x.\n", ret);
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&string, device_nameW);
|
|
|
|
if ((ret = IoCreateDevice(driver, 0, &string, FILE_DEVICE_UNKNOWN, 0, FALSE, &device_obj)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create request queue device, status %#x.\n", ret);
|
|
|
|
NtClose(directory_obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
driver->MajorFunction[IRP_MJ_CREATE] = dispatch_create;
|
|
|
|
driver->MajorFunction[IRP_MJ_CLOSE] = dispatch_close;
|
|
|
|
driver->DriverUnload = unload;
|
|
|
|
|
2019-08-22 04:30:11 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|