- Fix property item merge in KsMergeAutomationTable

 

svn path=/trunk/; revision=55989
This commit is contained in:
Johannes Anderwald 2012-03-04 04:44:48 +00:00
parent 4411be35e7
commit acb68dc20d
2 changed files with 109 additions and 3 deletions

View file

@ -2087,15 +2087,100 @@ KspCopyMethodSets(
return STATUS_SUCCESS;
}
VOID
KspAddPropertyItem(
OUT PKSPROPERTY_SET OutPropertySet,
IN PKSPROPERTY_ITEM PropertyItem,
IN ULONG PropertyItemSize)
{
PKSPROPERTY_ITEM CurrentPropertyItem;
ULONG Index;
// check if the property item is already present
CurrentPropertyItem = (PKSPROPERTY_ITEM)OutPropertySet->PropertyItem;
for(Index = 0; Index < OutPropertySet->PropertiesCount; Index++)
{
if (CurrentPropertyItem->PropertyId == PropertyItem->PropertyId)
{
// item already present
return;
}
// next item
CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + PropertyItemSize);
}
// add item
RtlCopyMemory(CurrentPropertyItem, PropertyItem, PropertyItemSize);
OutPropertySet->PropertiesCount++;
}
NTSTATUS
KspMergePropertySet(
OUT PKSAUTOMATION_TABLE Table,
OUT PKSPROPERTY_SET OutPropertySet,
IN PKSPROPERTY_SET PropertySetA,
IN PKSPROPERTY_SET PropertySetB,
IN KSOBJECT_BAG Bag OPTIONAL)
{
ULONG PropertyCount, Index;
PKSPROPERTY_ITEM PropertyItem, CurrentPropertyItem;
NTSTATUS Status;
// max properties
PropertyCount = PropertySetA->PropertiesCount + PropertySetB->PropertiesCount;
// allocate items
PropertyItem = AllocateItem(NonPagedPool, Table->PropertyItemSize * PropertyCount);
if (!PropertyItem)
return STATUS_INSUFFICIENT_RESOURCES;
if (Bag)
{
/* add table to object bag */
Status = KsAddItemToObjectBag(Bag, PropertyItem, NULL);
/* check for success */
if (!NT_SUCCESS(Status))
{
/* free table */
FreeItem(Table);
return Status;
}
}
// copy entries from dominant table
RtlCopyMemory(PropertyItem, PropertySetA->PropertyItem, Table->PropertyItemSize * PropertySetA->PropertiesCount);
// init property set
OutPropertySet->PropertiesCount = PropertySetA->PropertiesCount;
OutPropertySet->PropertyItem = PropertyItem;
// copy other entries
CurrentPropertyItem = (PKSPROPERTY_ITEM)PropertySetB->PropertyItem;
for(Index = 0; Index < PropertySetB->PropertiesCount; Index++)
{
// add entries
KspAddPropertyItem(OutPropertySet, CurrentPropertyItem, Table->PropertyItemSize);
// next entry
CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + Table->PropertyItemSize);
}
// done
return STATUS_SUCCESS;
}
NTSTATUS
KspCopyPropertySets(
OUT PKSAUTOMATION_TABLE Table,
IN PKSAUTOMATION_TABLE AutomationTableA OPTIONAL,
IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL)
IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL,
IN KSOBJECT_BAG Bag OPTIONAL)
{
ULONG Index, SubIndex, Count;
BOOL bFound;
NTSTATUS Status;
if (!AutomationTableA)
{
@ -2137,6 +2222,17 @@ KspCopyPropertySets(
RtlMoveMemory((PVOID)&Table->PropertySets[Count], &AutomationTableB->PropertySets[Index], sizeof(KSPROPERTY_SET));
Count++;
}
else
{
// merge property sets
Status = KspMergePropertySet(Table, (PKSPROPERTY_SET)&Table->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableA->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableB->PropertySets[Index], Bag);
if (!NT_SUCCESS(Status))
{
// failed to merge
DPRINT1("[KS] Failed to merge %x\n", Status);
return Status;
}
}
}
return STATUS_SUCCESS;
@ -2251,6 +2347,12 @@ KsMergeAutomationTables(
Table->PropertyItemSize = AutomationTableB->PropertyItemSize;
}
if (AutomationTableA && AutomationTableB)
{
// FIXME handle different propery item sizes
ASSERT(AutomationTableA->PropertyItemSize == AutomationTableB->PropertyItemSize);
}
/* now allocate the property sets */
Table->PropertySets = AllocateItem(NonPagedPool, sizeof(KSPROPERTY_SET) * Table->PropertySetsCount);
@ -2272,7 +2374,7 @@ KsMergeAutomationTables(
}
}
/* now copy the property sets */
Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB);
Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB, Bag);
if(!NT_SUCCESS(Status))
goto cleanup;

View file

@ -955,7 +955,7 @@ FilterPinPropertyHandler(
UNIMPLEMENTED
Status = STATUS_NOT_FOUND;
}
//DPRINT("KspPinPropertyHandler Pins %lu Request->Id %lu Status %lx\n", This->PinDescriptorCount, Request->Id, Status);
DPRINT("KspPinPropertyHandler Pins %lu Request->Id %lu Status %lx\n", This->Filter.Descriptor->PinDescriptorsCount, Request->Id, Status);
return Status;
@ -1029,6 +1029,9 @@ IKsFilter_DispatchDeviceIoControl(
SetCount = FilterInstance->Descriptor->AutomationTable->PropertySetsCount;
PropertySet = FilterInstance->Descriptor->AutomationTable->PropertySets;
PropertyItemSize = FilterInstance->Descriptor->AutomationTable->PropertyItemSize;
// FIXME: handle variable sized property items
ASSERT(PropertyItemSize == sizeof(KSPROPERTY_ITEM));
PropertyItemSize = 0;
}
/* needed for our property handlers */
@ -1063,6 +1066,7 @@ IKsFilter_DispatchDeviceIoControl(
}
RtlStringFromGUID(&Property->Set, &GuidString);
DPRINT("IKsFilter_DispatchDeviceIoControl property PinCount %x\n", FilterInstance->Descriptor->PinDescriptorsCount);
DPRINT("IKsFilter_DispatchDeviceIoControl property Set |%S| Id %u Flags %x Status %lx ResultLength %lu\n", GuidString.Buffer, Property->Id, Property->Flags, Status, Irp->IoStatus.Information);
RtlFreeUnicodeString(&GuidString);