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
11 #include <afs/param.h>
15 #include <WINNT/TaAfsAdmSvr.h>
19 * DEFINITIONS ________________________________________________________________
23 #define cREALLOC_ASIDLIST 64
25 #define cREALLOC_OBJPROPLIST 32
27 #define cREALLOC_ACTIONLIST 8
31 * REALLOC ____________________________________________________________________
33 * This thing, RPC_REALLOC, is a specialized version of the REALLOC() code that
34 * you'll find in most libraries. It's intended to deal with structures that
39 * size_t cElements; <- The interesting bit
41 * MYTYPE aElements[1]; <- <- <- The really interesting bit
44 * Remember that since the array is growable, it must be the last element
45 * in the structure. This thing's called RPC_REALLOC because these growable
46 * arrays are well-suited for transferring via rpc--just make the aElements
47 * line in your .IDL file look like:
49 * [size_is(cElements) length_is(cElements)] MYTYPE aElements[*];
51 * As an example of its use, say we want to fill in element 15:
53 * void FillInElement15 (MYSTRUCT *pStruct, MYTYPE *pNewData)
56 * if (RPC_REALLOC (MYSTRUCT, pStruct, aElements, cElements, 1+iElement, cREALLOC_MYSTRUCT))
58 * memcpy (&pStruct->aElements[ iElement ], pNewData, sizeof(MYTYPE));
62 * As always, the "cREALLOC_MYSTRUCT" can be any positive value; it specifies
63 * the granularity with which the the array will be over-allocated. Note that
64 * unlike the normal REALLOC() routine, the {aElements} and {cElements}
65 * parameters are presumed to be members of the specified pointer-to-structure.
66 * If {*pStruct} is NULL upon entry, it will be allocated and zero-filled.
70 #define OFFSETOF(_type,_a) (size_t)&(((_type *)0)->_a)
71 #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)
73 BOOL AfsAdmSvr_ReallocFunction (PVOID *ppStructure, size_t cbHeader, size_t iposCount, size_t cbElement, size_t cReq, size_t cInc, BYTE chFill)
75 // Use cInc to over-estimate how much space is really required; that
76 // way, allocating space for one element actually allocates space for
77 // many--so that next time we get here, we won't have to do any work.
80 cReq = cInc * ( (cReq + cInc - 1) / cInc );
83 // See how much space is allocated now. If we have no structure to start
84 // with, obviously we have no array elements either.
88 cNow = *(size_t *)( ((PBYTE)(*ppStructure)) + iposCount );
92 // Hmmm... there wasn't enough space. Allocate a new structure.
94 size_t cbAlloc = cbHeader + cbElement * cReq;
96 if ((pNewStructure = Allocate (cbAlloc)) == NULL)
99 memset (pNewStructure, 0x00, cbHeader);
100 memset ((PBYTE)pNewStructure + cbHeader, chFill, cbAlloc - cbHeader);
102 memcpy (pNewStructure, *ppStructure, cbHeader);
104 *(size_t *)( ((PBYTE)pNewStructure) + iposCount ) = cReq;
106 // Transfer any information from the old structure's elements
109 memcpy ((PBYTE)pNewStructure + cbHeader, ((PBYTE)(*ppStructure)) + cbHeader, cNow * cbElement);
111 // If there was one, free the old structure
115 *ppStructure = pNewStructure;
123 * ROUTINES ___________________________________________________________________
127 // ASIDLIST - Managed type for lists of cell objects
129 LPASIDLIST AfsAdmSvr_CreateAsidList (void)
131 LPASIDLIST pList = NULL;
132 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ASIDLIST))
137 LPASIDLIST AfsAdmSvr_CopyAsidList (LPASIDLIST pListSource)
139 LPASIDLIST pList = NULL;
140 if (!RPC_REALLOC (ASIDLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ASIDLIST))
142 if (pList->cEntriesAllocated)
143 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
144 pList->cEntries = pListSource->cEntries;
148 BOOL AfsAdmSvr_AddToAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
150 if (!ppList || !*ppList)
153 if (!RPC_REALLOC (ASIDLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_ASIDLIST))
156 (*ppList)->aEntries[ (*ppList)->cEntries ].idObject = idObject;
157 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
158 (*ppList)->cEntries ++;
162 BOOL AfsAdmSvr_RemoveFromAsidList (LPASIDLIST *ppList, ASID idObject)
164 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
168 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
170 if ((*ppList)->aEntries[ iEntry ].idObject != idObject)
172 else if ((fFound = AfsAdmSvr_RemoveFromAsidListByIndex (ppList, iEntry)) == FALSE)
180 BOOL AfsAdmSvr_RemoveFromAsidListByIndex (LPASIDLIST *ppList, size_t iIndex)
182 if (iIndex >= (*ppList)->cEntries)
185 if (iIndex < (*ppList)->cEntries -1)
186 memcpy (&(*ppList)->aEntries[ iIndex ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
187 (*ppList)->cEntries --;
192 BOOL AfsAdmSvr_SetAsidListParam (LPASIDLIST *ppList, ASID idObject, LPARAM lp)
195 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
197 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
199 (*ppList)->aEntries[ iEntry ].lParam = lp;
207 BOOL AfsAdmSvr_SetAsidListParamByIndex (LPASIDLIST *ppList, size_t iIndex, LPARAM lp)
209 if (iIndex >= (*ppList)->cEntries)
212 (*ppList)->aEntries[ iIndex ].lParam = lp;
217 BOOL AfsAdmSvr_IsInAsidList (LPASIDLIST *ppList, ASID idObject, LPARAM *pParam)
219 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
222 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
224 if ((*ppList)->aEntries[ iEntry ].idObject == idObject)
227 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
236 void AfsAdmSvr_FreeAsidList (LPASIDLIST *ppList)
238 if (ppList && *ppList)
246 // ASOBJPROPLIST - Managed type for lists of cell objects
248 LPASOBJPROPLIST AfsAdmSvr_CreateObjPropList (void)
250 LPASOBJPROPLIST pList = NULL;
251 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_OBJPROPLIST))
256 LPASOBJPROPLIST AfsAdmSvr_CopyObjPropList (LPASOBJPROPLIST pListSource)
258 LPASOBJPROPLIST pList = NULL;
259 if (!RPC_REALLOC (ASOBJPROPLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_OBJPROPLIST))
261 if (pList->cEntriesAllocated)
262 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
263 pList->cEntries = pListSource->cEntries;
267 BOOL AfsAdmSvr_AddToObjPropList (LPASOBJPROPLIST *ppList, LPASOBJPROP pProperties, LPARAM lp)
269 if (!ppList || !*ppList)
272 if (!RPC_REALLOC (ASOBJPROPLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
275 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].ObjectProperties, pProperties, sizeof(ASOBJPROP));
276 (*ppList)->aEntries[ (*ppList)->cEntries ].lParam = lp;
277 (*ppList)->cEntries ++;
281 BOOL AfsAdmSvr_RemoveFromObjPropList (LPASOBJPROPLIST *ppList, ASID idObject)
283 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
287 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
289 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject != idObject)
294 if (iEntry < (*ppList)->cEntries -1)
295 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
296 (*ppList)->cEntries --;
303 BOOL AfsAdmSvr_IsInObjPropList (LPASOBJPROPLIST *ppList, ASID idObject, LPASOBJPROP pProperties, LPARAM *pParam)
305 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
308 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
310 if ((*ppList)->aEntries[ iEntry ].ObjectProperties.idObject == idObject)
313 memcpy (pProperties, &(*ppList)->aEntries[ iEntry ].ObjectProperties, sizeof(ASOBJPROP));
315 *pParam = (*ppList)->aEntries[ iEntry ].lParam;
323 void AfsAdmSvr_FreeObjPropList (LPASOBJPROPLIST *ppList)
325 if (ppList && *ppList)
333 // ASACTIONLIST - Managed type for lists of cell objects
335 LPASACTIONLIST AfsAdmSvr_CreateActionList (void)
337 LPASACTIONLIST pList = NULL;
338 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, 0, cREALLOC_ACTIONLIST))
343 LPASACTIONLIST AfsAdmSvr_CopyActionList (LPASACTIONLIST pListSource)
345 LPASACTIONLIST pList = NULL;
346 if (!RPC_REALLOC (ASACTIONLIST, pList, aEntries, cEntriesAllocated, pListSource->cEntries, cREALLOC_ACTIONLIST))
348 if (pList->cEntriesAllocated)
349 memcpy (pList->aEntries, pListSource->aEntries, sizeof(pList->aEntries[0]) * pList->cEntriesAllocated);
350 pList->cEntries = pListSource->cEntries;
354 BOOL AfsAdmSvr_AddToActionList (LPASACTIONLIST *ppList, LPASACTION pAction)
356 if (!ppList || !*ppList)
359 if (!RPC_REALLOC (ASACTIONLIST, *ppList, aEntries, cEntriesAllocated, (*ppList)->cEntries +1, cREALLOC_OBJPROPLIST))
362 memcpy (&(*ppList)->aEntries[ (*ppList)->cEntries ].Action, pAction, sizeof(ASACTION));
363 (*ppList)->cEntries ++;
367 BOOL AfsAdmSvr_RemoveFromActionList (LPASACTIONLIST *ppList, DWORD idAction)
369 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
373 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; )
375 if ((*ppList)->aEntries[ iEntry ].Action.idAction != idAction)
380 if (iEntry < (*ppList)->cEntries -1)
381 memcpy (&(*ppList)->aEntries[ iEntry ], &(*ppList)->aEntries[ (*ppList)->cEntries-1 ], sizeof((*ppList)->aEntries[0]));
382 (*ppList)->cEntries --;
389 BOOL AfsAdmSvr_IsInActionList (LPASACTIONLIST *ppList, DWORD idAction, LPASACTION pAction)
391 if (!ppList || !(*ppList) || !(*ppList)->cEntries)
394 for (ULONG iEntry = 0; iEntry < (*ppList)->cEntries; ++iEntry)
396 if ((*ppList)->aEntries[ iEntry ].Action.idAction == idAction)
399 memcpy (pAction, &(*ppList)->aEntries[ iEntry ].Action, sizeof(ASACTION));
407 void AfsAdmSvr_FreeActionList (LPASACTIONLIST *ppList)
409 if (ppList && *ppList)