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 <afs/param.h>
18 #include <WINNT/TaAfsAdmSvr.h>
22 * DEFINITIONS ________________________________________________________________
26 #define cREALLOC_ASIDLIST 64
28 #define cREALLOC_OBJPROPLIST 32
30 #define cREALLOC_ACTIONLIST 8
34 * REALLOC ____________________________________________________________________
36 * This thing, RPC_REALLOC, is a specialized version of the REALLOC() code that
37 * you'll find in most libraries. It's intended to deal with structures that
42 * size_t cElements; <- The interesting bit
44 * MYTYPE aElements[1]; <- <- <- The really interesting bit
47 * Remember that since the array is growable, it must be the last element
48 * in the structure. This thing's called RPC_REALLOC because these growable
49 * arrays are well-suited for transferring via rpc--just make the aElements
50 * line in your .IDL file look like:
52 * [size_is(cElements) length_is(cElements)] MYTYPE aElements[*];
54 * As an example of its use, say we want to fill in element 15:
56 * void FillInElement15 (MYSTRUCT *pStruct, MYTYPE *pNewData)
59 * if (RPC_REALLOC (MYSTRUCT, pStruct, aElements, cElements, 1+iElement, cREALLOC_MYSTRUCT))
61 * memcpy (&pStruct->aElements[ iElement ], pNewData, sizeof(MYTYPE));
65 * As always, the "cREALLOC_MYSTRUCT" can be any positive value; it specifies
66 * the granularity with which the the array will be over-allocated. Note that
67 * unlike the normal REALLOC() routine, the {aElements} and {cElements}
68 * parameters are presumed to be members of the specified pointer-to-structure.
69 * If {*pStruct} is NULL upon entry, it will be allocated and zero-filled.
73 #define OFFSETOF(_type,_a) (size_t)&(((_type *)0)->_a)
74 #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)
76 BOOL
AfsAdmSvr_ReallocFunction (PVOID
*ppStructure
, size_t cbHeader
, size_t iposCount
, size_t cbElement
, size_t cReq
, size_t cInc
, BYTE chFill
)
78 // Use cInc to over-estimate how much space is really required; that
79 // way, allocating space for one element actually allocates space for
80 // many--so that next time we get here, we won't have to do any work.
83 cReq
= cInc
* ( (cReq
+ cInc
- 1) / cInc
);
86 // See how much space is allocated now. If we have no structure to start
87 // with, obviously we have no array elements either.
91 cNow
= *(size_t *)( ((PBYTE
)(*ppStructure
)) + iposCount
);
95 // Hmmm... there wasn't enough space. Allocate a new structure.
97 size_t cbAlloc
= cbHeader
+ cbElement
* cReq
;
99 if ((pNewStructure
= Allocate (cbAlloc
)) == NULL
)
102 memset (pNewStructure
, 0x00, cbHeader
);
103 memset ((PBYTE
)pNewStructure
+ cbHeader
, chFill
, cbAlloc
- cbHeader
);
105 memcpy (pNewStructure
, *ppStructure
, cbHeader
);
107 *(size_t *)( ((PBYTE
)pNewStructure
) + iposCount
) = cReq
;
109 // Transfer any information from the old structure's elements
112 memcpy ((PBYTE
)pNewStructure
+ cbHeader
, ((PBYTE
)(*ppStructure
)) + cbHeader
, cNow
* cbElement
);
114 // If there was one, free the old structure
118 *ppStructure
= pNewStructure
;
126 * ROUTINES ___________________________________________________________________
130 // ASIDLIST - Managed type for lists of cell objects
132 LPASIDLIST
AfsAdmSvr_CreateAsidList (void)
134 LPASIDLIST pList
= NULL
;
135 if (!RPC_REALLOC (ASIDLIST
, pList
, aEntries
, cEntriesAllocated
, 0, cREALLOC_ASIDLIST
))
140 LPASIDLIST
AfsAdmSvr_CopyAsidList (LPASIDLIST pListSource
)
142 LPASIDLIST pList
= NULL
;
143 if (!RPC_REALLOC (ASIDLIST
, pList
, aEntries
, cEntriesAllocated
, pListSource
->cEntries
, cREALLOC_ASIDLIST
))
145 if (pList
->cEntriesAllocated
)
146 memcpy (pList
->aEntries
, pListSource
->aEntries
, sizeof(pList
->aEntries
[0]) * pList
->cEntriesAllocated
);
147 pList
->cEntries
= pListSource
->cEntries
;
151 BOOL
AfsAdmSvr_AddToAsidList (LPASIDLIST
*ppList
, ASID idObject
, LPARAM lp
)
153 if (!ppList
|| !*ppList
)
156 if (!RPC_REALLOC (ASIDLIST
, *ppList
, aEntries
, cEntriesAllocated
, (*ppList
)->cEntries
+1, cREALLOC_ASIDLIST
))
159 (*ppList
)->aEntries
[ (*ppList
)->cEntries
].idObject
= idObject
;
160 (*ppList
)->aEntries
[ (*ppList
)->cEntries
].lParam
= lp
;
161 (*ppList
)->cEntries
++;
165 BOOL
AfsAdmSvr_RemoveFromAsidList (LPASIDLIST
*ppList
, ASID idObject
)
167 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
171 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; )
173 if ((*ppList
)->aEntries
[ iEntry
].idObject
!= idObject
)
175 else if ((fFound
= AfsAdmSvr_RemoveFromAsidListByIndex (ppList
, iEntry
)) == FALSE
)
183 BOOL
AfsAdmSvr_RemoveFromAsidListByIndex (LPASIDLIST
*ppList
, size_t iIndex
)
185 if (iIndex
>= (*ppList
)->cEntries
)
188 if (iIndex
< (*ppList
)->cEntries
-1)
189 memcpy (&(*ppList
)->aEntries
[ iIndex
], &(*ppList
)->aEntries
[ (*ppList
)->cEntries
-1 ], sizeof((*ppList
)->aEntries
[0]));
190 (*ppList
)->cEntries
--;
195 BOOL
AfsAdmSvr_SetAsidListParam (LPASIDLIST
*ppList
, ASID idObject
, LPARAM lp
)
198 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; ++iEntry
)
200 if ((*ppList
)->aEntries
[ iEntry
].idObject
== idObject
)
202 (*ppList
)->aEntries
[ iEntry
].lParam
= lp
;
210 BOOL
AfsAdmSvr_SetAsidListParamByIndex (LPASIDLIST
*ppList
, size_t iIndex
, LPARAM lp
)
212 if (iIndex
>= (*ppList
)->cEntries
)
215 (*ppList
)->aEntries
[ iIndex
].lParam
= lp
;
220 BOOL
AfsAdmSvr_IsInAsidList (LPASIDLIST
*ppList
, ASID idObject
, LPARAM
*pParam
)
222 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
225 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; ++iEntry
)
227 if ((*ppList
)->aEntries
[ iEntry
].idObject
== idObject
)
230 *pParam
= (*ppList
)->aEntries
[ iEntry
].lParam
;
239 void AfsAdmSvr_FreeAsidList (LPASIDLIST
*ppList
)
241 if (ppList
&& *ppList
)
249 // ASOBJPROPLIST - Managed type for lists of cell objects
251 LPASOBJPROPLIST
AfsAdmSvr_CreateObjPropList (void)
253 LPASOBJPROPLIST pList
= NULL
;
254 if (!RPC_REALLOC (ASOBJPROPLIST
, pList
, aEntries
, cEntriesAllocated
, 0, cREALLOC_OBJPROPLIST
))
259 LPASOBJPROPLIST
AfsAdmSvr_CopyObjPropList (LPASOBJPROPLIST pListSource
)
261 LPASOBJPROPLIST pList
= NULL
;
262 if (!RPC_REALLOC (ASOBJPROPLIST
, pList
, aEntries
, cEntriesAllocated
, pListSource
->cEntries
, cREALLOC_OBJPROPLIST
))
264 if (pList
->cEntriesAllocated
)
265 memcpy (pList
->aEntries
, pListSource
->aEntries
, sizeof(pList
->aEntries
[0]) * pList
->cEntriesAllocated
);
266 pList
->cEntries
= pListSource
->cEntries
;
270 BOOL
AfsAdmSvr_AddToObjPropList (LPASOBJPROPLIST
*ppList
, LPASOBJPROP pProperties
, LPARAM lp
)
272 if (!ppList
|| !*ppList
)
275 if (!RPC_REALLOC (ASOBJPROPLIST
, *ppList
, aEntries
, cEntriesAllocated
, (*ppList
)->cEntries
+1, cREALLOC_OBJPROPLIST
))
278 memcpy (&(*ppList
)->aEntries
[ (*ppList
)->cEntries
].ObjectProperties
, pProperties
, sizeof(ASOBJPROP
));
279 (*ppList
)->aEntries
[ (*ppList
)->cEntries
].lParam
= lp
;
280 (*ppList
)->cEntries
++;
284 BOOL
AfsAdmSvr_RemoveFromObjPropList (LPASOBJPROPLIST
*ppList
, ASID idObject
)
286 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
290 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; )
292 if ((*ppList
)->aEntries
[ iEntry
].ObjectProperties
.idObject
!= idObject
)
297 if (iEntry
< (*ppList
)->cEntries
-1)
298 memcpy (&(*ppList
)->aEntries
[ iEntry
], &(*ppList
)->aEntries
[ (*ppList
)->cEntries
-1 ], sizeof((*ppList
)->aEntries
[0]));
299 (*ppList
)->cEntries
--;
306 BOOL
AfsAdmSvr_IsInObjPropList (LPASOBJPROPLIST
*ppList
, ASID idObject
, LPASOBJPROP pProperties
, LPARAM
*pParam
)
308 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
311 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; ++iEntry
)
313 if ((*ppList
)->aEntries
[ iEntry
].ObjectProperties
.idObject
== idObject
)
316 memcpy (pProperties
, &(*ppList
)->aEntries
[ iEntry
].ObjectProperties
, sizeof(ASOBJPROP
));
318 *pParam
= (*ppList
)->aEntries
[ iEntry
].lParam
;
326 void AfsAdmSvr_FreeObjPropList (LPASOBJPROPLIST
*ppList
)
328 if (ppList
&& *ppList
)
336 // ASACTIONLIST - Managed type for lists of cell objects
338 LPASACTIONLIST
AfsAdmSvr_CreateActionList (void)
340 LPASACTIONLIST pList
= NULL
;
341 if (!RPC_REALLOC (ASACTIONLIST
, pList
, aEntries
, cEntriesAllocated
, 0, cREALLOC_ACTIONLIST
))
346 LPASACTIONLIST
AfsAdmSvr_CopyActionList (LPASACTIONLIST pListSource
)
348 LPASACTIONLIST pList
= NULL
;
349 if (!RPC_REALLOC (ASACTIONLIST
, pList
, aEntries
, cEntriesAllocated
, pListSource
->cEntries
, cREALLOC_ACTIONLIST
))
351 if (pList
->cEntriesAllocated
)
352 memcpy (pList
->aEntries
, pListSource
->aEntries
, sizeof(pList
->aEntries
[0]) * pList
->cEntriesAllocated
);
353 pList
->cEntries
= pListSource
->cEntries
;
357 BOOL
AfsAdmSvr_AddToActionList (LPASACTIONLIST
*ppList
, LPASACTION pAction
)
359 if (!ppList
|| !*ppList
)
362 if (!RPC_REALLOC (ASACTIONLIST
, *ppList
, aEntries
, cEntriesAllocated
, (*ppList
)->cEntries
+1, cREALLOC_OBJPROPLIST
))
365 memcpy (&(*ppList
)->aEntries
[ (*ppList
)->cEntries
].Action
, pAction
, sizeof(ASACTION
));
366 (*ppList
)->cEntries
++;
370 BOOL
AfsAdmSvr_RemoveFromActionList (LPASACTIONLIST
*ppList
, DWORD idAction
)
372 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
376 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; )
378 if ((*ppList
)->aEntries
[ iEntry
].Action
.idAction
!= idAction
)
383 if (iEntry
< (*ppList
)->cEntries
-1)
384 memcpy (&(*ppList
)->aEntries
[ iEntry
], &(*ppList
)->aEntries
[ (*ppList
)->cEntries
-1 ], sizeof((*ppList
)->aEntries
[0]));
385 (*ppList
)->cEntries
--;
392 BOOL
AfsAdmSvr_IsInActionList (LPASACTIONLIST
*ppList
, DWORD idAction
, LPASACTION pAction
)
394 if (!ppList
|| !(*ppList
) || !(*ppList
)->cEntries
)
397 for (ULONG iEntry
= 0; iEntry
< (*ppList
)->cEntries
; ++iEntry
)
399 if ((*ppList
)->aEntries
[ iEntry
].Action
.idAction
== idAction
)
402 memcpy (pAction
, &(*ppList
)->aEntries
[ iEntry
].Action
, sizeof(ASACTION
));
410 void AfsAdmSvr_FreeActionList (LPASACTIONLIST
*ppList
)
412 if (ppList
&& *ppList
)