2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: updateattrs.c /main/1 1996/04/21 19:24:52 drk $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #include <EUSCompat.h>
34 #include "updateattrs.h"
40 /*****************************************************************************
41 * extern functions used in the library
42 *****************************************************************************/
45 * need to copy original attributes and roll back if update fails
47 extern CSA_return_code
48 _DtCmUpdateAttributes(
50 cms_attribute *srcattrs,
52 cms_attribute **dstattrs,
58 CSA_return_code stat = CSA_SUCCESS;
60 cms_attribute *oldattrs;
63 /* copy original attributes for rollback if update fails */
64 if (makecopy && *numdst > 0 && (stat = _DtCm_copy_cms_attributes(
65 *numdst, *dstattrs, &oldnum, &oldattrs)) != CSA_SUCCESS)
68 for (i = 0; i < numsrc && stat == CSA_SUCCESS; i++) {
69 if (srcattrs[i].name.name == NULL)
72 if (srcattrs[i].name.num <= 0)
73 srcattrs[i].name.num = _DtCm_get_index_from_table(*tbl,
74 srcattrs[i].name.name);
76 index = srcattrs[i].name.num;
78 if (index < 0 || index > (*tbl)->size) {
80 srcattrs[i].name.num = 0;
82 if ((stat = _DtCmExtendNameTable(srcattrs[i].name.name,
83 index > 0 ? index : 0, srcattrs[i].value->type,
84 (caltbl == B_TRUE ? _DtCm_cal_name_tbl :
85 _DtCm_entry_name_tbl),
86 (caltbl == B_TRUE ? _DtCM_DEFINED_CAL_ATTR_SIZE :
87 _DtCM_DEFINED_ENTRY_ATTR_SIZE),
88 (caltbl == B_TRUE ? _CSA_calendar_attribute_names :
89 _CSA_entry_attribute_names), tbl, types))
93 srcattrs[i].name.num = (*tbl)->size;
95 stat = _DtCmGrowAttrArray(numdst,
96 dstattrs, &srcattrs[i]);
99 if ((*tbl)->names[index] == NULL) {
100 /* fill in the missing hole */
101 if ((stat = _DtCm_add_name_to_table(*tbl,
102 index, srcattrs[i].name.name))
106 if (types && srcattrs[i].value)
108 srcattrs[i].value->type;
111 if (types && srcattrs[i].value &&
112 srcattrs[i].value->type != (*types)[index])
113 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
114 else if (index > *numdst)
115 stat = _DtCmGrowAttrArray(numdst, dstattrs,
118 stat = _DtCmUpdateAttribute(&srcattrs[i],
119 &(*dstattrs)[index]);
123 if (makecopy && oldnum > 0) {
124 if (stat != CSA_SUCCESS) {
125 _DtCm_free_cms_attributes(*numdst + 1, *dstattrs);
128 *dstattrs = oldattrs;
130 _DtCm_free_cms_attributes(oldnum + 1, oldattrs);
138 extern CSA_return_code
139 _DtCmUpdateAttribute(
143 CSA_return_code stat = CSA_SUCCESS;
145 if (to->name.name == NULL) {
146 to->name.num = from->name.num;
147 if ((to->name.name = strdup(from->name.name)) == NULL)
148 return (CSA_E_INSUFFICIENT_MEMORY);
151 if (from->value && to->value && from->value->type != to->value->type)
152 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
155 switch (from->value->type) {
156 case CSA_VALUE_BOOLEAN:
157 case CSA_VALUE_ENUMERATED:
158 case CSA_VALUE_FLAGS:
159 case CSA_VALUE_SINT32:
160 case CSA_VALUE_UINT32:
161 stat = _DtCmUpdateSint32AttrVal(from->value,
165 case CSA_VALUE_STRING:
166 case CSA_VALUE_CALENDAR_USER:
167 case CSA_VALUE_DATE_TIME:
168 case CSA_VALUE_DATE_TIME_RANGE:
169 case CSA_VALUE_TIME_DURATION:
170 stat = _DtCmUpdateStringAttrVal(from->value,
174 case CSA_VALUE_REMINDER:
175 stat = _DtCmUpdateReminderAttrVal(from->value,
179 case CSA_VALUE_ACCESS_LIST:
180 stat = _DtCmUpdateAccessListAttrVal(from->value,
184 case CSA_VALUE_DATE_TIME_LIST:
185 stat = _DtCmUpdateDateTimeListAttrVal(from->value,
189 case CSA_VALUE_OPAQUE_DATA:
190 stat = _DtCmUpdateOpaqueDataAttrVal(from->value,
195 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
198 _DtCm_free_cms_attribute_value(to->value);
205 extern CSA_return_code
206 _DtCmUpdateAccessListAttrVal(
207 cms_attribute_value *newval,
208 cms_attribute_value **attrval)
210 cms_attribute_value *val;
211 cms_access_entry *newlist = NULL;
213 if (newval && newval->item.access_list_value &&
214 (newlist = _DtCm_copy_cms_access_list(
215 newval->item.access_list_value)) == NULL)
216 return (CSA_E_INSUFFICIENT_MEMORY);
218 if (*attrval == NULL) {
219 if ((val = (cms_attribute_value *)malloc(
220 sizeof(cms_attribute_value))) == NULL) {
222 _DtCm_free_cms_access_entry(newlist);
223 return (CSA_E_INSUFFICIENT_MEMORY);
226 val->type = CSA_VALUE_ACCESS_LIST;
229 _DtCm_free_cms_access_entry(
230 (cms_access_entry *)val->item.access_list_value);
233 val->item.access_list_value = newlist;
237 return (CSA_SUCCESS);
240 extern CSA_return_code
241 _DtCmUpdateSint32AttrVal(
242 cms_attribute_value *newval,
243 cms_attribute_value **attrval)
245 cms_attribute_value *val;
248 if (*attrval == NULL) {
249 if ((val = (cms_attribute_value *)malloc(
250 sizeof(cms_attribute_value))) == NULL) {
251 return (CSA_E_INSUFFICIENT_MEMORY);
254 val->type = newval->type;
258 (*attrval)->item.sint32_value = newval->item.sint32_value;
260 } else if (*attrval) {
266 return (CSA_SUCCESS);
269 extern CSA_return_code
270 _DtCmUpdateStringAttrVal(
271 cms_attribute_value *newval,
272 cms_attribute_value **attrval)
274 cms_attribute_value *val;
275 char *newstring = NULL;
278 if (newval->item.string_value &&
279 (newstring = strdup(newval->item.string_value)) == NULL)
280 return (CSA_E_INSUFFICIENT_MEMORY);
282 if (*attrval == NULL) {
283 if ((val = (cms_attribute_value *)malloc(
284 sizeof(cms_attribute_value))) == NULL) {
287 return (CSA_E_INSUFFICIENT_MEMORY);
290 val->type = newval->type;
293 if (val->item.string_value)
294 free(val->item.string_value);
297 val->item.string_value = newstring;
301 } else if (*attrval) {
303 free((*attrval)->item.string_value);
308 return (CSA_SUCCESS);
311 extern CSA_return_code
312 _DtCmUpdateReminderAttrVal(
313 cms_attribute_value *newval,
314 cms_attribute_value **attrval)
316 CSA_return_code stat;
317 cms_attribute_value *val;
318 CSA_reminder *rem = NULL;
320 if (newval && newval->item.reminder_value) {
321 if ((stat = _DtCm_copy_reminder(newval->item.reminder_value,
322 &rem)) != CSA_SUCCESS)
323 return (CSA_E_INSUFFICIENT_MEMORY);
325 if (*attrval == NULL) {
326 if ((val = (cms_attribute_value *)malloc(
327 sizeof(cms_attribute_value))) == NULL) {
329 _DtCm_free_reminder(rem);
330 return (CSA_E_INSUFFICIENT_MEMORY);
333 val->type = newval->type;
336 if (val->item.reminder_value)
337 _DtCm_free_reminder(val->item.reminder_value);
340 val->item.reminder_value = rem;
344 } else if (*attrval) {
346 _DtCm_free_reminder((*attrval)->item.reminder_value);
351 return (CSA_SUCCESS);
354 extern CSA_return_code
355 _DtCmUpdateDateTimeListAttrVal(
356 cms_attribute_value *newval,
357 cms_attribute_value **attrval)
359 cms_attribute_value *val;
360 CSA_date_time_list dtlist = NULL;
362 if (newval && newval->item.date_time_list_value) {
363 if ((dtlist = _DtCm_copy_date_time_list(
364 newval->item.date_time_list_value)) == NULL)
365 return (CSA_E_INSUFFICIENT_MEMORY);
367 if (*attrval == NULL) {
368 if ((val = (cms_attribute_value *)malloc(
369 sizeof(cms_attribute_value))) == NULL) {
371 _DtCm_free_date_time_list(dtlist);
372 return (CSA_E_INSUFFICIENT_MEMORY);
375 val->type = newval->type;
378 if (val->item.date_time_list_value)
379 _DtCm_free_date_time_list(
380 val->item.date_time_list_value);
383 val->item.date_time_list_value = dtlist;
387 } else if (*attrval) {
389 _DtCm_free_date_time_list((*attrval)->item.date_time_list_value);
394 return (CSA_SUCCESS);
397 extern CSA_return_code
398 _DtCmUpdateOpaqueDataAttrVal(
399 cms_attribute_value *newval,
400 cms_attribute_value **attrval)
402 CSA_return_code stat;
403 cms_attribute_value *val;
404 CSA_opaque_data *opq = NULL;
406 if (newval && newval->item.opaque_data_value) {
407 if ((stat = _DtCm_copy_opaque_data(
408 newval->item.opaque_data_value, &opq)) != CSA_SUCCESS)
409 return (CSA_E_INSUFFICIENT_MEMORY);
411 if (*attrval == NULL) {
412 if ((val = (cms_attribute_value *)malloc(
413 sizeof(cms_attribute_value))) == NULL) {
414 if (opq) _DtCm_free_opaque_data(opq);
415 return (CSA_E_INSUFFICIENT_MEMORY);
418 val->type = newval->type;
421 if (val->item.opaque_data_value)
422 _DtCm_free_opaque_data(
423 val->item.opaque_data_value);
426 val->item.opaque_data_value = opq;
430 } else if (*attrval) {
432 _DtCm_free_opaque_data((*attrval)->item.opaque_data_value);
437 return (CSA_SUCCESS);