1 /**
2 * Copyright 1993 Network Computing Devices, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name Network Computing Devices, Inc. not be
9 * used in advertising or publicity pertaining to distribution of this
10 * software without specific, written prior permission.
11 *
12 * THIS SOFTWARE IS PROVIDED 'AS-IS'. NETWORK COMPUTING DEVICES, INC.,
13 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
14 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK
16 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
17 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
18 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
19 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
22 * $NCDId: @(#)GetBucAttr.c,v 1.8 1994/03/09 19:25:30 greg Exp $
23 */
24
25 #include "Alibint.h"
26
27 AuBucketAttributes *
AuGetBucketAttributes(AuServer * aud,AuBucketID bucket,AuStatus * ret_status)28 AuGetBucketAttributes(
29 AuServer *aud,
30 AuBucketID bucket,
31 AuStatus *ret_status
32 )
33 {
34 auResourceReq *req;
35 auGetBucketAttributesReply rep;
36 auBucketAttributes a;
37 AuBucketAttributes *attr;
38
39 if (ret_status)
40 *ret_status = AuSuccess;
41
42 if (attr = _AuLookupBucketInCache(aud, bucket))
43 return attr;
44
45 _AuLockServer();
46 _AuGetResReq(GetBucketAttributes, bucket, req, aud);
47
48 (void) _AuReply(aud, (auReply *) & rep, 0, auFalse, ret_status);
49
50 _AuReadPad(aud, (char *) &a, SIZEOF(auBucketAttributes));
51
52 if (!(attr = (AuBucketAttributes *)
53 Aucalloc(1, sizeof(AuBucketAttributes))))
54 {
55 _AuUnlockServer();
56 _AuSyncHandle(aud);
57 return NULL;
58 }
59
60 _xferBucketAttributes(&a, *attr);
61
62 if ((AuBucketValueMask(attr) & AuCompCommonDescriptionMask) &&
63 AuBucketDescription(attr)->len)
64 {
65 if (!(AuBucketDescription(attr)->data = (char *)
66 Aumalloc(AuBucketDescription(attr)->len + 1)))
67 {
68 AuFreeBucketAttributes(aud, 1, attr);
69 _AuUnlockServer();
70 _AuSyncHandle(aud);
71 return NULL;
72 }
73
74 _AuReadPad(aud, AuBucketDescription(attr)->data,
75 AuBucketDescription(attr)->len);
76
77 AuBucketDescription(attr)->data[AuBucketDescription(attr)->len] = 0;
78 }
79
80 _AuUnlockServer();
81 _AuSyncHandle(aud);
82
83 _AuAddToBucketCache(aud, attr);
84 return attr;
85 }
86
87 /* ARGSUSED */
88 void
AuFreeBucketAttributes(AuServer * aud,int num,AuBucketAttributes * attr)89 AuFreeBucketAttributes(
90 AuServer *aud,
91 int num,
92 AuBucketAttributes *attr
93 )
94 {
95 AuBucketAttributes *p = attr;
96
97 if (!num)
98 return;
99
100 while (num--)
101 {
102 if (AuBucketDescription(p)->data)
103 Aufree(AuBucketDescription(p)->data);
104
105 p++;
106 }
107
108 Aufree(attr);
109 }
110