6 #include <WINNT/TaAfsAdmSvr.h>
10 * DEFINITIONS ________________________________________________________________
14 #define cREALLOC_ASIDLIST 64
16 #define cREALLOC_OBJPROPLIST 32
18 #define cREALLOC_ACTIONLIST 8
22 * REALLOC ____________________________________________________________________
24 * This thing, RPC_REALLOC, is a specialized version of the REALLOC() code that
25 * you'll find in most libraries. It's intended to deal with structures that
30 * size_t cElements; <- The interesting bit
32 * MYTYPE aElements[1]; <- <- <- The really interesting bit
35 * Remember that since the array is growable, it must be the last element
36 * in the structure. This thing's called RPC_REALLOC because these growable
37 * arrays are well-suited for transferring via rpc--just make the aElements
38 * line in your .IDL file look like:
40 * [size_is(cElements) length_is(cElements)] MYTYPE aElements[*];
42 * As an example of its use, say we want to fill in element 15:
44 * void FillInElement15 (MYSTRUCT *pStruct, MYTYPE *pNewData)
47 * if (RPC_REALLOC (MYSTRUCT, pStruct, aElements, cElements, 1+iElement, cREALLOC_MYSTRUCT))
49 * memcpy (&pStruct->aElements[ iElement ], pNewData, sizeof(MYTYPE));
53 * As always, the "cREALLOC_MYSTRUCT" can be any positive value; it specifies
54 * the granularity with which the the array will be over-allocated. Note that
55 * unlike the normal REALLOC() routine, the {aElements} and {cElements}
56 * parameters are presumed to be members of the specified pointer-to-structure.
57 * If {*pStruct} is NULL upon entry, it will be allocated and zero-filled.
61 #define OFFSETOF(_type,_a) (size_t)&(((_type *)0)->_a)
62 #define RPC_REALLOC(_type,_str,_a,_c,_r,_ci) AfsAdmSvr_ReallocFunction ((PVOID*)&(_str), OFFSETOF(_type,_a), OFFSETOF(_type,_c), sizeof((_str)->_a[0]), (size_t)_r, (size_t)_ci, 0x00)
64 BOOL AfsAdmSvr_ReallocFunction (PVOID *ppStructure, size_t cbHeader, size_t iposCount, size_t cbElement, size_t cReq, size_t cInc, BYTE chFill)
66 // Use cInc to over-estimate how much space is really required; that
67 // way, allocating space for one element actually allocates space for
68 // many--so that next time we get here, we won't have to do any work.
71 cReq = cInc * ( (cReq + cInc - 1) / cInc );
74 // See how much space is allocated now. If we have no structure to start
75 // with, obviously we have no array elements either.
79 cNow = *(size_t *)( ((PBYTE)(*ppStructure)) + iposCount );
83 // Hmmm... there wasn't enough space. Allocate a new structure.
85 size_t cbAlloc = cbHeader + cbElement * cReq;
87 if ((pNewStructure = Allocate (cbAlloc)) == NULL)
90 memset (pNewStructure, 0x00, cbHeader);
91 memset ((PBYTE)pNewStructure + cbHeader, chFill, cbAlloc - cbHeader);
93 memcpy (pNewStructure, *ppStructure, cbHeader);
95 *(size_t *)( ((PBYTE)pNewStructure) + iposCount ) = cReq;
97 // Transfer any information from the old structure's elements
100 memcpy ((PBYTE)pNewStructure + cbHeader, ((PBYTE)(*ppStructure)) + cbHeader, cNow * cbElement);
102 // If there was one, free the old structure
106 *ppStructure = pNewStructure;
114 * ROUTINES ___________________________________________________________________
118 // ASIDLIST - Managed type for lists of cell objects
120 LPASIDLIST AfsAdmSvr_CreateAsidList (void)
122 LPASIDLIST pList = NULL;
123 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ASIDLIST))
128 LPASIDLIST AfsAdmSvr_CopyAsidList (LPASIDLIST pListSource)
130 LPASIDLIST pList = NULL;
131 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ASIDLIST))
133 if (pList->cEntriesAllocated)
134 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
135 pList->cEntries = pListSource->cEntries;
139 BOOL AfsAdmSvr_AddToAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
141 if (!ppList || !*ppList)
144 if (!RPC_REALLOC (ASIDLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_ASIDLIST))
147 (*ppList)->aEntries[ (*ppList)->cEntries ].idObject = idObject;
148 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
149 (*ppList)->cEntries ++;
153 BOOL AfsAdmSvr_RemoveFromAsidList (LPASIDLIST *ppList, ASID idObject)
155 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
159 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
161 if ((*ppList)->aEntries[ iEntry ].idObject != idObject)
163 else if ((fFound = AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iEntry)) == FALSE)
171 BOOL AfsAdmSvr_RemoveFromAsidListByIndex (LPASIDLIST *ppList, size_t iIndex)
173 if (iIndex >= (*ppList)->cEntries)
176 if (iIndex < (*ppList)->cEntries -1)
177 memcpy (&(*ppList)->aEntries[ iIndex ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
178 (*ppList)->cEntries --;
183 BOOL AfsAdmSvr_SetAsidListParam (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
186 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
188 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
190 (*ppList)->aEntries[ iEntry ].lParam = lp;
198 BOOL AfsAdmSvr_SetAsidListParamByIndex (LPASIDLIST *ppList, size_t iIndex, LPARAM lp)
200 if (iIndex >= (*ppList)->cEntries)
203 (*ppList)->aEntries[ iIndex ].lParam = lp;
208 BOOL AfsAdmSvr_IsInAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM *pParam)
210 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
213 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
215 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
218 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
227 void AfsAdmSvr_FreeAsidList (LPASIDLIST *ppList)
229 if (ppList && *ppList)
237 // ASOBJPROPLIST - Managed type for lists of cell objects
239 LPASOBJPROPLIST AfsAdmSvr_CreateObjPropList (void)
241 LPASOBJPROPLIST pList = NULL;
242 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_OBJPROPLIST))
247 LPASOBJPROPLIST AfsAdmSvr_CopyObjPropList (LPASOBJPROPLIST pListSource)
249 LPASOBJPROPLIST pList = NULL;
250 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_OBJPROPLIST))
252 if (pList->cEntriesAllocated)
253 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
254 pList->cEntries = pListSource->cEntries;
258 BOOL AfsAdmSvr_AddToObjPropList (LPASOBJPROPLIST *ppList, LPASOBJPROP pProperties, LPARAM lp)
260 if (!ppList || !*ppList)
263 if (!RPC_REALLOC (ASOBJPROPLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
266 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].ObjectProperties, pProperties, sizeof(ASOBJPROP));
267 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
268 (*ppList)->cEntries ++;
272 BOOL AfsAdmSvr_RemoveFromObjPropList (LPASOBJPROPLIST *ppList, ASID idObject)
274 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
278 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
280 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject != idObject)
285 if (iEntry < (*ppList)->cEntries -1)
286 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
287 (*ppList)->cEntries --;
294 BOOL AfsAdmSvr_IsInObjPropList (LPASOBJPROPLIST *ppList, ASID idObject, LPASOBJPROP pProperties, LPARAM *pParam)
296 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
299 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
301 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject == idObject)
304 memcpy (pProperties, &(*ppList)->aEntries[ iEntry ].ObjectProperties, sizeof(ASOBJPROP));
306 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
314 void AfsAdmSvr_FreeObjPropList (LPASOBJPROPLIST *ppList)
316 if (ppList && *ppList)
324 // ASACTIONLIST - Managed type for lists of cell objects
326 LPASACTIONLIST AfsAdmSvr_CreateActionList (void)
328 LPASACTIONLIST pList = NULL;
329 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ACTIONLIST))
334 LPASACTIONLIST AfsAdmSvr_CopyActionList (LPASACTIONLIST pListSource)
336 LPASACTIONLIST pList = NULL;
337 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ACTIONLIST))
339 if (pList->cEntriesAllocated)
340 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
341 pList->cEntries = pListSource->cEntries;
345 BOOL AfsAdmSvr_AddToActionList (LPASACTIONLIST *ppList, LPASACTION pAction)
347 if (!ppList || !*ppList)
350 if (!RPC_REALLOC (ASACTIONLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
353 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].Action, pAction, sizeof(ASACTION));
354 (*ppList)->cEntries ++;
358 BOOL AfsAdmSvr_RemoveFromActionList (LPASACTIONLIST *ppList, DWORD idAction)
360 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
364 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
366 if ((*ppList)->aEntries[ iEntry ].Action.idAction != idAction)
371 if (iEntry < (*ppList)->cEntries -1)
372 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
373 (*ppList)->cEntries --;
380 BOOL AfsAdmSvr_IsInActionList (LPASACTIONLIST *ppList, DWORD idAction, LPASACTION pAction)
382 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
385 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
387 if ((*ppList)->aEntries[ iEntry ].Action.idAction == idAction)
390 memcpy (pAction, &(*ppList)->aEntries[ iEntry ].Action, sizeof(ASACTION));
398 void AfsAdmSvr_FreeActionList (LPASACTIONLIST *ppList)
400 if (ppList && *ppList)