Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtcm / server / cmsattr.c
1 /*******************************************************************************
2 **
3 **  cmsattr.c
4 **
5 **  $XConsortium: cmsattr.c /main/3 1995/11/03 11:08:50 rswiston $
6 **
7 **  RESTRICTED CONFIDENTIAL INFORMATION:
8 **
9 **  The information in this document is subject to special
10 **  restrictions in a confidential disclosure agreement between
11 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
12 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
13 **  Sun's specific written approval.  This document and all copies
14 **  and derivative works thereof must be returned or destroyed at
15 **  Sun's request.
16 **
17 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
18 **
19 *******************************************************************************/
20 #ifndef lint
21 static char sccsid[] = "@(#)cmsattr.c 1.2 94/10/05 Copyr 1991 Sun Microsystems, Inc."; 
22 #endif
23
24 #include <EUSCompat.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "csa.h"
28 #include "cm.h"
29 #include "attr.h"
30 #include "cmsdata.h"
31
32 extern CSA_return_code
33 _DtCmsUpdateSint32AttrVal(
34         cms_attribute_value *newval,
35         cms_attribute_value **attrval)
36 {
37         cms_attribute_value     *val;
38
39         if (newval) {
40                 if (*attrval == NULL) {
41                         if ((val = (cms_attribute_value *)malloc(
42                             sizeof(cms_attribute_value))) == NULL) {
43                                 return (CSA_E_INSUFFICIENT_MEMORY);
44                         }
45
46                         val->type = newval->type;
47
48                         *attrval = val;
49                 }
50                 (*attrval)->item.sint32_value = newval->item.sint32_value;
51
52         } else if (*attrval) {
53
54                 free(*attrval);
55                 *attrval = NULL;
56         }
57
58         return (CSA_SUCCESS);
59 }
60
61 extern CSA_return_code
62 _DtCmsUpdateUint32AttrVal(
63         cms_attribute_value *newval,
64         cms_attribute_value **attrval)
65 {
66         cms_attribute_value     *val;
67
68         if (newval) {
69                 if (*attrval == NULL) {
70                         if ((val = (cms_attribute_value *)malloc(
71                             sizeof(cms_attribute_value))) == NULL) {
72                                 return (CSA_E_INSUFFICIENT_MEMORY);
73                         }
74
75                         val->type = newval->type;
76
77                         *attrval = val;
78                 }
79                 (*attrval)->item.uint32_value = newval->item.uint32_value;
80
81         } else if (*attrval) {
82
83                 free(*attrval);
84                 *attrval = NULL;
85         }
86
87         return (CSA_SUCCESS);
88 }
89
90 extern CSA_return_code
91 _DtCmsUpdateStringAttrVal(
92         cms_attribute_value *newval,
93         cms_attribute_value **attrval)
94 {
95         cms_attribute_value     *val;
96         char *newstring = NULL;
97
98         if (newval) {
99                 if (newval->item.string_value &&
100                     (newstring = strdup(newval->item.string_value)) == NULL)
101                         return (CSA_E_INSUFFICIENT_MEMORY);
102
103                 if (*attrval == NULL) {
104                         if ((val = (cms_attribute_value *)malloc(
105                             sizeof(cms_attribute_value))) == NULL) {
106                                 if (newstring)
107                                         free(newstring);
108                                 return (CSA_E_INSUFFICIENT_MEMORY);
109                         }
110
111                         val->type = newval->type;
112                 } else {
113                         val = *attrval;
114                         if (val->item.string_value)
115                                 free(val->item.string_value);
116                 }
117
118                 val->item.string_value = newstring;
119
120                 *attrval = val;
121
122         } else if (*attrval) {
123
124                 free((*attrval)->item.string_value);
125                 free(*attrval);
126                 *attrval = NULL;
127         }
128
129         return (CSA_SUCCESS);
130 }
131
132 extern CSA_return_code
133 _DtCmsUpdateAccessListAttrVal(
134         cms_attribute_value *newval,
135         cms_attribute_value **attrval)
136 {
137         cms_attribute_value *val;
138         cms_access_entry *newlist = NULL;
139
140         if (newval && newval->item.access_list_value &&
141             (newlist = _DtCm_copy_cms_access_list(
142             newval->item.access_list_value)) == NULL)
143                 return (CSA_E_INSUFFICIENT_MEMORY);
144
145         if (*attrval == NULL) {
146                 if ((val = (cms_attribute_value *)malloc(
147                     sizeof(cms_attribute_value))) == NULL) {
148                         if (newlist)
149                                 _DtCm_free_cms_access_entry(newlist);
150                         return (CSA_E_INSUFFICIENT_MEMORY);
151                 }
152
153                 val->type = CSA_VALUE_ACCESS_LIST;
154         } else {
155                 val = *attrval;
156                 _DtCm_free_cms_access_entry(
157                         (cms_access_entry *)val->item.access_list_value);
158         }
159
160         val->item.access_list_value = newlist;
161
162         *attrval = val;
163
164         return (CSA_SUCCESS);
165 }
166
167 extern CSA_return_code
168 _DtCmsUpdateReminderAttrVal(
169         cms_attribute_value *newval,
170         cms_attribute_value **attrval)
171 {
172         CSA_return_code         stat;
173         cms_attribute_value     *val;
174         CSA_reminder            *rem = NULL;
175
176         if (newval && newval->item.reminder_value) {
177                 if ((stat = _DtCm_copy_reminder(newval->item.reminder_value,
178                     &rem)) != CSA_SUCCESS)
179                         return (CSA_E_INSUFFICIENT_MEMORY);
180
181                 if (*attrval == NULL) {
182                         if ((val = (cms_attribute_value *)malloc(
183                             sizeof(cms_attribute_value))) == NULL) {
184                                 if (rem)
185                                         _DtCm_free_reminder(rem);
186                                 return (CSA_E_INSUFFICIENT_MEMORY);
187                         }
188
189                         val->type = newval->type;
190                 } else {
191                         val = *attrval;
192                         if (val->item.reminder_value)
193                                 _DtCm_free_reminder(val->item.reminder_value);
194                 }
195
196                 val->item.reminder_value = rem;
197
198                 *attrval = val;
199
200         } else if (*attrval) {
201
202                 _DtCm_free_reminder((*attrval)->item.reminder_value);
203                 free(*attrval);
204                 *attrval = NULL;
205         }
206
207         return (CSA_SUCCESS);
208 }
209
210 extern CSA_return_code
211 _DtCmsUpdateDateTimeListAttrVal(
212         cms_attribute_value *newval,
213         cms_attribute_value **attrval)
214 {
215         cms_attribute_value     *val;
216         CSA_date_time_list      dtlist = NULL;
217
218         if (newval && newval->item.date_time_list_value) {
219                 if ((dtlist = _DtCm_copy_date_time_list(
220                     newval->item.date_time_list_value)) == NULL)
221                         return (CSA_E_INSUFFICIENT_MEMORY);
222
223                 if (*attrval == NULL) {
224                         if ((val = (cms_attribute_value *)malloc(
225                             sizeof(cms_attribute_value))) == NULL) {
226                                 if (dtlist)
227                                         _DtCm_free_date_time_list(dtlist);
228                                 return (CSA_E_INSUFFICIENT_MEMORY);
229                         }
230
231                         val->type = newval->type;
232                 } else {
233                         val = *attrval;
234                         if (val->item.date_time_list_value)
235                                 _DtCm_free_date_time_list(
236                                         val->item.date_time_list_value);
237                 }
238
239                 val->item.date_time_list_value = dtlist;
240
241                 *attrval = val;
242
243         } else if (*attrval) {
244
245                 _DtCm_free_date_time_list((*attrval)->item.date_time_list_value);
246                 free(*attrval);
247                 *attrval = NULL;
248         }
249
250         return (CSA_SUCCESS);
251 }
252
253 extern CSA_return_code
254 _DtCmsUpdateOpaqueDataAttrVal(
255         cms_attribute_value *newval,
256         cms_attribute_value **attrval)
257 {
258         CSA_return_code         stat;
259         cms_attribute_value     *val;
260         CSA_opaque_data         *opq = NULL;
261
262         if (newval && newval->item.opaque_data_value) {
263                 if ((stat = _DtCm_copy_opaque_data(
264                     newval->item.opaque_data_value, &opq)) != CSA_SUCCESS)
265                         return (CSA_E_INSUFFICIENT_MEMORY);
266
267                 if (*attrval == NULL) {
268                         if ((val = (cms_attribute_value *)malloc(
269                             sizeof(cms_attribute_value))) == NULL) {
270                                 if (opq) _DtCm_free_opaque_data(opq);
271                                 return (CSA_E_INSUFFICIENT_MEMORY);
272                         }
273
274                         val->type = newval->type;
275                 } else {
276                         val = *attrval;
277                         if (val->item.opaque_data_value)
278                                 _DtCm_free_opaque_data(
279                                         val->item.opaque_data_value);
280                 }
281
282                 val->item.opaque_data_value = opq;
283
284                 *attrval = val;
285
286         } else if (*attrval) {
287
288                 _DtCm_free_opaque_data((*attrval)->item.opaque_data_value);
289                 free(*attrval);
290                 *attrval = NULL;
291         }
292
293         return (CSA_SUCCESS);
294 }
295