Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / drivers / ksfilter / ks / connectivity.c
index bcc55cc..7cd0fab 100644 (file)
@@ -239,7 +239,7 @@ KspReadMediaCategory(
     /* allocate buffer for the registry key */
     Path.Length = 0;
     Path.MaximumLength = MediaPath.MaximumLength + GuidString.MaximumLength;
-    Path.Buffer = ExAllocatePool(NonPagedPool, Path.MaximumLength);
+    Path.Buffer = AllocateItem(NonPagedPool, Path.MaximumLength);
     if (!Path.Buffer)
     {
         /* not enough memory */
@@ -259,10 +259,10 @@ KspReadMediaCategory(
     /* open the key */
     Status = ZwOpenKey(&hKey, GENERIC_READ, &ObjectAttributes);
 
-    DPRINT("ZwOpenKey() status 0x%08lx %S\n", Status, Path.Buffer);
+    DPRINT("ZwOpenKey() status 0x%08lx %wZ\n", Status, &Path);
 
     /* free path buffer */
-    ExFreePool(Path.Buffer);
+    FreeItem(Path.Buffer);
 
     /* check for success */
     if (!NT_SUCCESS(Status))
@@ -281,7 +281,7 @@ KspReadMediaCategory(
     }
 
     /* allocate buffer to read key info */
-    KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) ExAllocatePool(NonPagedPool, Size);
+    KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) AllocateItem(NonPagedPool, Size);
     if (!KeyInfo)
     {
         /* not enough memory */
@@ -298,7 +298,7 @@ KspReadMediaCategory(
     if (!NT_SUCCESS(Status))
     {
         /* failed to read key */
-        ExFreePool(KeyInfo);
+        FreeItem(KeyInfo);
         return Status;
     }
 
@@ -330,9 +330,10 @@ KspPinPropertyHandler(
     NTSTATUS Status = STATUS_NOT_SUPPORTED;
     ULONG Count;
     const PKSDATARANGE* DataRanges;
+    LPGUID Guid;
 
     IoStack = IoGetCurrentIrpStackLocation(Irp);
-    Buffer = Irp->UserBuffer;
+    Buffer = Data;
 
     //DPRINT("KsPinPropertyHandler Irp %p Property %p Data %p DescriptorsCount %u Descriptor %p OutputLength %u Id %u\n", Irp, Property, Data, DescriptorsCount, Descriptor, IoStack->Parameters.DeviceIoControl.OutputBufferLength, Property->Id);
 
@@ -509,49 +510,78 @@ KspPinPropertyHandler(
 
         case KSPROPERTY_PIN_CATEGORY:
 
+            if (!Descriptor->Category)
+            {
+                /* no pin category */
+                return STATUS_NOT_FOUND;
+            }
+
+            /* check size */
             Size = sizeof(GUID);
             if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < Size)
             {
+                /* buffer too small */
                 Irp->IoStatus.Information = Size;
                 Status = STATUS_BUFFER_TOO_SMALL;
                 break;
             }
-            if (Descriptor->Category)
-            {
-                RtlMoveMemory(Buffer, Descriptor->Category, sizeof(GUID));
-            }
 
+            /* copy category guid */
+            RtlMoveMemory(Buffer, Descriptor->Category, sizeof(GUID));
+
+            /* save result */
             Status = STATUS_SUCCESS;
             Irp->IoStatus.Information = Size;
             break;
 
         case KSPROPERTY_PIN_NAME:
-            if (!Descriptor->Name)
+
+            if (Descriptor->Name)
             {
-                Irp->IoStatus.Information = 0;
-                Status = STATUS_SUCCESS;
-                break;
+                /* use pin name */
+                Guid = (LPGUID)Descriptor->Name;
+            }
+            else
+            {
+                /* use pin category as fallback */
+                Guid = (LPGUID)Descriptor->Category;
+            }
+
+            if (!Guid)
+            {
+                /* no friendly name available */
+                return STATUS_NOT_FOUND;
             }
 
-            Status = KspReadMediaCategory((LPGUID)Descriptor->Name, &KeyInfo);
+            /* read friendly name category name */
+            Status = KspReadMediaCategory(Guid, &KeyInfo);
             if (!NT_SUCCESS(Status))
             {
+                /* failed to read category */
                 Irp->IoStatus.Information = 0;
                 break;
             }
 
+            /* store required length */
             Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
 
+            /* check if buffer is too small */
             if (KeyInfo->DataLength + sizeof(WCHAR) > IoStack->Parameters.DeviceIoControl.OutputBufferLength)
             {
+                /* buffer too small */
                 Status = STATUS_BUFFER_OVERFLOW;
-                ExFreePool(KeyInfo);
+                FreeItem(KeyInfo);
                 break;
             }
 
+            /* copy result */
             RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data, KeyInfo->DataLength);
+
+            /* null terminate name */
             ((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] = L'\0';
-            ExFreePool(KeyInfo);
+
+            /* free key info */
+            FreeItem(KeyInfo);
             break;
         case KSPROPERTY_PIN_PROPOSEDATAFORMAT:
             Size = sizeof(KSDATAFORMAT);
@@ -745,7 +775,7 @@ KsHandleSizedListQuery(
     Size = DataItemSize * DataItemsCount + sizeof(KSMULTIPLE_ITEM);
 
     /* get multiple item */
-    Item = (PKSMULTIPLE_ITEM)Irp->UserBuffer;
+    Item = (PKSMULTIPLE_ITEM)Irp->AssociatedIrp.SystemBuffer;
 
     if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == 0)
     {