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 librararies 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: cmsentry.c /main/4 1995/11/09 12:41:44 rswiston $ */
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>
40 /******************************************************************************
41 * forward declaration of static functions used within the file
42 ******************************************************************************/
43 static CSA_return_code
44 _ExtractEntryAttrsFromEntry(uint srcsize, cms_attribute *srcattrs,
45 uint *dstsize, cms_attribute **dstattrs, boolean_t time_only);
47 /*****************************************************************************
49 *****************************************************************************/
52 * Given a hashed name table, initialize a new cms_entry with
53 * the given list of attribute values
55 extern CSA_return_code
56 _DtCmsMakeHashedEntry(
64 CSA_return_code stat = CSA_SUCCESS;
66 if (cal == NULL || entry == NULL)
67 return (CSA_E_INVALID_PARAMETER);
69 if ((eptr = _DtCm_make_cms_entry(cal->entry_tbl)) == NULL)
70 return (CSA_E_INSUFFICIENT_MEMORY);
72 for (i = 0; i < num && stat == CSA_SUCCESS; i++) {
73 index = _DtCm_get_index_from_table(cal->entry_tbl,
78 if (index > _DtCM_DEFINED_ENTRY_ATTR_SIZE &&
80 attrs[i].value->type != cal->types[index])
81 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
83 stat = _DtCm_copy_cms_attr_val(attrs[i].value,
84 &eptr->attrs[index].value);
85 } else if (attrs[i].value) {
86 if ((stat = _DtCmExtendNameTable(attrs[i].name.name, 0,
87 attrs[i].value->type, _DtCm_entry_name_tbl,
88 _DtCM_DEFINED_ENTRY_ATTR_SIZE,
89 _CSA_entry_attribute_names, &cal->entry_tbl,
90 &cal->types)) == CSA_SUCCESS) {
92 attrs[i].name.num = cal->entry_tbl->size;
94 stat = _DtCmGrowAttrArray(&eptr->num_attrs,
95 &eptr->attrs, &attrs[i]);
100 if (stat != CSA_SUCCESS) {
101 _DtCm_free_cms_entry(eptr);
106 return (CSA_SUCCESS);
110 _DtCmsFreeEntryAttrResItem(cms_get_entry_attr_res_item *elist)
112 cms_get_entry_attr_res_item *ptr;
117 _DtCm_free_cms_attributes(elist->num_attrs, elist->attrs);
124 extern CSA_return_code
125 _DtCmsGetCmsEntryForClient(cms_entry *e, cms_entry **e_r, boolean_t time_only)
128 CSA_return_code stat;
130 if (e == NULL || e_r == NULL)
131 return (CSA_E_INVALID_PARAMETER);
133 if ((ptr = (cms_entry *)calloc(1, sizeof(cms_entry))) == NULL)
134 return (CSA_E_INSUFFICIENT_MEMORY);
136 if ((stat = _ExtractEntryAttrsFromEntry(e->num_attrs, e->attrs,
137 &ptr->num_attrs, &ptr->attrs,time_only)) != CSA_SUCCESS) {
143 return (CSA_SUCCESS);
147 /*****************************************************************************
148 * static functions used within the file
149 *****************************************************************************/
151 static CSA_return_code
152 _ExtractEntryAttrsFromEntry(
154 cms_attribute *srcattrs,
156 cms_attribute **dstattrs,
159 CSA_return_code stat;
161 cms_attribute *attrs;
163 if (dstsize == NULL || dstattrs == NULL)
164 return (CSA_E_INVALID_PARAMETER);
170 return (CSA_SUCCESS);
172 if ((attrs = calloc(1, sizeof(cms_attribute) * srcsize)) == NULL)
173 return (CSA_E_INSUFFICIENT_MEMORY);
175 for (i = 0, j = 0; i <= srcsize; i++) {
176 if (srcattrs[i].value == NULL)
179 if ((stat = _DtCm_copy_cms_attribute(&attrs[j], &srcattrs[i],
180 B_TRUE)) != CSA_SUCCESS)
183 if ( (i == CSA_ENTRY_ATTR_SUMMARY_I) && (time_only == B_TRUE) ) {
184 if (attrs[j].value && attrs[j].value->item.string_value)
185 attrs[j].value->item.string_value[0] = '\0';
192 if (stat == CSA_SUCCESS && j > 0) {
196 _DtCm_free_cms_attributes(j, attrs);