2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include <WINNT/TaAfsAdmSvr.h>
24 * DEFINITIONS ________________________________________________________________
28 #define cREALLOC_ASIDLIST 64
30 #define cREALLOC_OBJPROPLIST 32
32 #define cREALLOC_ACTIONLIST 8
36 * REALLOC ____________________________________________________________________
38 * This thing, RPC_REALLOC, is a specialized version of the REALLOC() code that
39 * you'll find in most libraries. It's intended to deal with structures that
44 * size_t cElements; <- The interesting bit
46 * MYTYPE aElements[1]; <- <- <- The really interesting bit
49 * Remember that since the array is growable, it must be the last element
50 * in the structure. This thing's called RPC_REALLOC because these growable
51 * arrays are well-suited for transferring via rpc--just make the aElements
52 * line in your .IDL file look like:
54 * [size_is(cElements) length_is(cElements)] MYTYPE aElements[*];
56 * As an example of its use, say we want to fill in element 15:
58 * void FillInElement15 (MYSTRUCT *pStruct, MYTYPE *pNewData)
61 * if (RPC_REALLOC (MYSTRUCT, pStruct, aElements, cElements, 1+iElement, cREALLOC_MYSTRUCT))
63 * memcpy (&pStruct->aElements[ iElement ], pNewData, sizeof(MYTYPE));
67 * As always, the "cREALLOC_MYSTRUCT" can be any positive value; it specifies
68 * the granularity with which the the array will be over-allocated. Note that
69 * unlike the normal REALLOC() routine, the {aElements} and {cElements}
70 * parameters are presumed to be members of the specified pointer-to-structure.
71 * If {*pStruct} is NULL upon entry, it will be allocated and zero-filled.
75 #define OFFSETOF(_type,_a) (size_t)&(((_type *)0)->_a)
76 #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)
78 BOOL AfsAdmSvr_ReallocFunction (PVOID *ppStructure, size_t cbHeader, size_t iposCount, size_t cbElement, size_t cReq, size_t cInc, BYTE chFill)
80 // Use cInc to over-estimate how much space is really required; that
81 // way, allocating space for one element actually allocates space for
82 // many--so that next time we get here, we won't have to do any work.
85 cReq = cInc * ( (cReq + cInc - 1) / cInc );
88 // See how much space is allocated now. If we have no structure to start
89 // with, obviously we have no array elements either.
93 cNow = *(size_t *)( ((PBYTE)(*ppStructure)) + iposCount );
97 // Hmmm... there wasn't enough space. Allocate a new structure.
99 size_t cbAlloc = cbHeader + cbElement * cReq;
101 if ((pNewStructure = Allocate (cbAlloc)) == NULL)
104 memset (pNewStructure, 0x00, cbHeader);
105 memset ((PBYTE)pNewStructure + cbHeader, chFill, cbAlloc - cbHeader);
107 memcpy (pNewStructure, *ppStructure, cbHeader);
109 *(size_t *)( ((PBYTE)pNewStructure) + iposCount ) = cReq;
111 // Transfer any information from the old structure's elements
114 memcpy ((PBYTE)pNewStructure + cbHeader, ((PBYTE)(*ppStructure)) + cbHeader, cNow * cbElement);
116 // If there was one, free the old structure
120 *ppStructure = pNewStructure;
128 * ROUTINES ___________________________________________________________________
132 // ASIDLIST - Managed type for lists of cell objects
134 LPASIDLIST AfsAdmSvr_CreateAsidList (void)
136 LPASIDLIST pList = NULL;
137 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ASIDLIST))
142 LPASIDLIST AfsAdmSvr_CopyAsidList (LPASIDLIST pListSource)
144 LPASIDLIST pList = NULL;
145 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ASIDLIST))
147 if (pList->cEntriesAllocated)
148 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
149 pList->cEntries = pListSource->cEntries;
153 BOOL AfsAdmSvr_AddToAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
155 if (!ppList || !*ppList)
158 if (!RPC_REALLOC (ASIDLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_ASIDLIST))
161 (*ppList)->aEntries[ (*ppList)->cEntries ].idObject = idObject;
162 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
163 (*ppList)->cEntries ++;
167 BOOL AfsAdmSvr_RemoveFromAsidList (LPASIDLIST *ppList, ASID idObject)
169 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
173 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
175 if ((*ppList)->aEntries[ iEntry ].idObject != idObject)
177 else if ((fFound = AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iEntry)) == FALSE)
185 BOOL AfsAdmSvr_RemoveFromAsidListByIndex (LPASIDLIST *ppList, size_t iIndex)
187 if (iIndex >= (*ppList)->cEntries)
190 if (iIndex < (*ppList)->cEntries -1)
191 memcpy (&(*ppList)->aEntries[ iIndex ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
192 (*ppList)->cEntries --;
197 BOOL AfsAdmSvr_SetAsidListParam (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
200 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
202 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
204 (*ppList)->aEntries[ iEntry ].lParam = lp;
212 BOOL AfsAdmSvr_SetAsidListParamByIndex (LPASIDLIST *ppList, size_t iIndex, LPARAM lp)
214 if (iIndex >= (*ppList)->cEntries)
217 (*ppList)->aEntries[ iIndex ].lParam = lp;
222 BOOL AfsAdmSvr_IsInAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM *pParam)
224 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
227 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
229 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
232 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
241 void AfsAdmSvr_FreeAsidList (LPASIDLIST *ppList)
243 if (ppList && *ppList)
251 // ASOBJPROPLIST - Managed type for lists of cell objects
253 LPASOBJPROPLIST AfsAdmSvr_CreateObjPropList (void)
255 LPASOBJPROPLIST pList = NULL;
256 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_OBJPROPLIST))
261 LPASOBJPROPLIST AfsAdmSvr_CopyObjPropList (LPASOBJPROPLIST pListSource)
263 LPASOBJPROPLIST pList = NULL;
264 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_OBJPROPLIST))
266 if (pList->cEntriesAllocated)
267 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
268 pList->cEntries = pListSource->cEntries;
272 BOOL AfsAdmSvr_AddToObjPropList (LPASOBJPROPLIST *ppList, LPASOBJPROP pProperties, LPARAM lp)
274 if (!ppList || !*ppList)
277 if (!RPC_REALLOC (ASOBJPROPLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
280 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].ObjectProperties, pProperties, sizeof(ASOBJPROP));
281 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
282 (*ppList)->cEntries ++;
286 BOOL AfsAdmSvr_RemoveFromObjPropList (LPASOBJPROPLIST *ppList, ASID idObject)
288 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
292 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
294 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject != idObject)
299 if (iEntry < (*ppList)->cEntries -1)
300 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
301 (*ppList)->cEntries --;
308 BOOL AfsAdmSvr_IsInObjPropList (LPASOBJPROPLIST *ppList, ASID idObject, LPASOBJPROP pProperties, LPARAM *pParam)
310 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
313 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
315 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject == idObject)
318 memcpy (pProperties, &(*ppList)->aEntries[ iEntry ].ObjectProperties, sizeof(ASOBJPROP));
320 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
328 void AfsAdmSvr_FreeObjPropList (LPASOBJPROPLIST *ppList)
330 if (ppList && *ppList)
338 // ASACTIONLIST - Managed type for lists of cell objects
340 LPASACTIONLIST AfsAdmSvr_CreateActionList (void)
342 LPASACTIONLIST pList = NULL;
343 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ACTIONLIST))
348 LPASACTIONLIST AfsAdmSvr_CopyActionList (LPASACTIONLIST pListSource)
350 LPASACTIONLIST pList = NULL;
351 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ACTIONLIST))
353 if (pList->cEntriesAllocated)
354 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
355 pList->cEntries = pListSource->cEntries;
359 BOOL AfsAdmSvr_AddToActionList (LPASACTIONLIST *ppList, LPASACTION pAction)
361 if (!ppList || !*ppList)
364 if (!RPC_REALLOC (ASACTIONLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
367 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].Action, pAction, sizeof(ASACTION));
368 (*ppList)->cEntries ++;
372 BOOL AfsAdmSvr_RemoveFromActionList (LPASACTIONLIST *ppList, DWORD idAction)
374 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
378 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
380 if ((*ppList)->aEntries[ iEntry ].Action.idAction != idAction)
385 if (iEntry < (*ppList)->cEntries -1)
386 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
387 (*ppList)->cEntries --;
394 BOOL AfsAdmSvr_IsInActionList (LPASACTIONLIST *ppList, DWORD idAction, LPASACTION pAction)
396 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
399 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
401 if ((*ppList)->aEntries[ iEntry ].Action.idAction == idAction)
404 memcpy (pAction, &(*ppList)->aEntries[ iEntry ].Action, sizeof(ASACTION));
412 void AfsAdmSvr_FreeActionList (LPASACTIONLIST *ppList)
414 if (ppList && *ppList)