Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / drivers / ksfilter / ks / irp.c
index 2b94a6d..0c493ee 100644 (file)
@@ -652,7 +652,7 @@ KsProbeStreamIrp(
     PKSSTREAM_HEADER StreamHeader;
     PIO_STACK_LOCATION IoStack;
     ULONG Length;
-    BOOLEAN AllocateMdl = FALSE;
+    //BOOLEAN AllocateMdl = FALSE;
 
     /* get current irp stack */
     IoStack = IoGetCurrentIrpStackLocation(Irp);
@@ -1024,7 +1024,7 @@ ProbeMdl:
                             }
 
                             /* break out to probe for the irp */
-                            AllocateMdl = TRUE;
+                            //AllocateMdl = TRUE;
                             break;
                         }
                     }
@@ -1175,9 +1175,10 @@ KsDefaultDeviceIoCompletion(
     /* get current irp stack */
     IoStack = IoGetCurrentIrpStackLocation(Irp);
 
-    if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY && 
+    if (IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY &&
         IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_METHOD &&
-        IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_PROPERTY)
+        IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_ENABLE_EVENT &&
+        IoStack->Parameters.DeviceIoControl.IoControlCode != IOCTL_KS_DISABLE_EVENT)
     {
         if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_KS_RESET_STATE)
         {
@@ -1643,13 +1644,13 @@ KsAddIrpToCancelableQueue(
     /* get current irp stack */
     IoStack = IoGetCurrentIrpStackLocation(Irp);
 
-    DPRINT1("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead, SpinLock, Irp, ListLocation, DriverCancel);
+    DPRINT("KsAddIrpToCancelableQueue QueueHead %p SpinLock %p Irp %p ListLocation %x DriverCancel %p\n", QueueHead, SpinLock, Irp, ListLocation, DriverCancel);
 
     // HACK for ms portcls
     if (IoStack->MajorFunction == IRP_MJ_CREATE)
     {
         // complete the request
-DPRINT1("MS HACK\n");
+        DPRINT1("MS HACK\n");
         Irp->IoStatus.Status = STATUS_SUCCESS;
         CompleteRequest(Irp, IO_NO_INCREMENT);
 
@@ -1744,41 +1745,53 @@ KsCancelRoutine(
 NTSTATUS
 FindMatchingCreateItem(
     PLIST_ENTRY ListHead,
-    ULONG BufferSize,
-    LPWSTR Buffer,
+    PUNICODE_STRING String,
     OUT PCREATE_ITEM_ENTRY *OutCreateItem)
 {
     PLIST_ENTRY Entry;
     PCREATE_ITEM_ENTRY CreateItemEntry;
     UNICODE_STRING RefString;
     LPWSTR pStr;
+    ULONG Count;
 
-    /* get terminator */
-    pStr = wcschr(Buffer, L'\\');
+    /* Copy the input string */
+    RefString = *String;
 
-    /* sanity check */
-    ASSERT(pStr != NULL);
-
-    if (pStr == Buffer)
+    /* Check if the string starts with a backslash */
+    if (String->Buffer[0] == L'\\')
     {
-        // skip slash
-        RtlInitUnicodeString(&RefString, ++pStr);
+        /* Skip backslash */
+        RefString.Buffer++;
+        RefString.Length -= sizeof(WCHAR);
     }
     else
     {
+        /* get terminator */
+        pStr = String->Buffer;
+        Count = String->Length / sizeof(WCHAR);
+        while ((Count > 0) && (*pStr != L'\\'))
+        {
+            pStr++;
+            Count--;
+        }
+
+        /* sanity check */
+        ASSERT(Count != 0);
+
         // request is for pin / node / allocator
-        RefString.Buffer = Buffer;
-        RefString.Length = BufferSize = RefString.MaximumLength = ((ULONG_PTR)pStr - (ULONG_PTR)Buffer);
+        RefString.Length = (USHORT)((PCHAR)pStr - (PCHAR)String->Buffer);
     }
 
     /* point to first entry */
     Entry = ListHead->Flink;
 
     /* loop all device items */
-    while(Entry != ListHead)
+    while (Entry != ListHead)
     {
         /* get create item entry */
-        CreateItemEntry = (PCREATE_ITEM_ENTRY)CONTAINING_RECORD(Entry, CREATE_ITEM_ENTRY, Entry);
+        CreateItemEntry = (PCREATE_ITEM_ENTRY)CONTAINING_RECORD(Entry,
+                                                                CREATE_ITEM_ENTRY,
+                                                                Entry);
 
         ASSERT(CreateItemEntry->CreateItem);
 
@@ -1796,10 +1809,11 @@ FindMatchingCreateItem(
             continue;
         }
 
-        DPRINT("CreateItem %S Length %u Request %wZ %u\n", CreateItemEntry->CreateItem->ObjectClass.Buffer,
-                                                           CreateItemEntry->CreateItem->ObjectClass.Length,
-                                                           &RefString,
-                                                           RefString.Length);
+        DPRINT("CreateItem %S Length %u Request %wZ %u\n",
+               CreateItemEntry->CreateItem->ObjectClass.Buffer,
+               CreateItemEntry->CreateItem->ObjectClass.Length,
+               &RefString,
+               RefString.Length);
 
         if (CreateItemEntry->CreateItem->ObjectClass.Length > RefString.Length)
         {
@@ -1809,7 +1823,9 @@ FindMatchingCreateItem(
         }
 
          /* now check if the object class is the same */
-        if (!RtlCompareUnicodeString(&CreateItemEntry->CreateItem->ObjectClass, &RefString, TRUE))
+        if (!RtlCompareUnicodeString(&CreateItemEntry->CreateItem->ObjectClass,
+                                     &RefString,
+                                     TRUE))
         {
             /* found matching create item */
             *OutCreateItem = CreateItemEntry;
@@ -1865,12 +1881,16 @@ KspCreate(
         ASSERT(ObjectHeader);
 
         /* find a matching a create item */
-        Status = FindMatchingCreateItem(&ObjectHeader->ItemList, IoStack->FileObject->FileName.Length, IoStack->FileObject->FileName.Buffer, &CreateItemEntry);
+        Status = FindMatchingCreateItem(&ObjectHeader->ItemList,
+                                        &IoStack->FileObject->FileName,
+                                        &CreateItemEntry);
     }
     else
     {
         /* request to create a filter */
-        Status = FindMatchingCreateItem(&DeviceHeader->ItemList, IoStack->FileObject->FileName.Length, IoStack->FileObject->FileName.Buffer, &CreateItemEntry);
+        Status = FindMatchingCreateItem(&DeviceHeader->ItemList,
+                                        &IoStack->FileObject->FileName,
+                                        &CreateItemEntry);
     }
 
     if (NT_SUCCESS(Status))
@@ -1903,9 +1923,9 @@ KspDispatchIrp(
     IN  PIRP Irp)
 {
     PIO_STACK_LOCATION IoStack;
-    PDEVICE_EXTENSION DeviceExtension;
+    //PDEVICE_EXTENSION DeviceExtension;
     PKSIOBJECT_HEADER ObjectHeader;
-    PKSIDEVICE_HEADER DeviceHeader;
+    //PKSIDEVICE_HEADER DeviceHeader;
     PDRIVER_DISPATCH Dispatch;
     NTSTATUS Status;
 
@@ -1913,9 +1933,9 @@ KspDispatchIrp(
     IoStack = IoGetCurrentIrpStackLocation(Irp);
 
     /* get device extension */
-    DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
+    //DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
     /* get device header */
-    DeviceHeader = DeviceExtension->DeviceHeader;
+    //DeviceHeader = DeviceExtension->DeviceHeader;
 
     ASSERT(IoStack->FileObject);
 
@@ -1963,6 +1983,7 @@ KspDispatchIrp(
             break;
         case IRP_MJ_PNP:
             Dispatch = KsDefaultDispatchPnp;
+            break;
         default:
             Dispatch = NULL;
     }