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