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
24 * (c) Copyright 1995 Digital Equipment Corporation.
25 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
27 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
29 * (c) Copyright 1995 FUJITSU LIMITED.
30 * (c) Copyright 1995 Hitachi.
32 * $XConsortium: SmProp.c /main/4 1996/10/07 10:29:51 drk $
36 #include <X11/Intrinsic.h>
37 #include <X11/SM/SMlib.h>
41 * Forward declarations
43 static SmPropValue * CopyPropValues (
45 SmPropValue * thePropValues);
51 SmPointer managerData,
55 ClientRecPtr pClient = (ClientRecPtr) managerData;
61 (void) printf ("Received SET PROPERTIES [%p]\n", smsConn);
67 for (i = 0; i < numProps; i++) {
71 if (theProps[i]->num_vals == 0)
74 for (pProp = pClient->props;
76 pProp = pProp->next) {
78 if (!strcmp (theProps[i]->name, pProp->prop.name) &&
79 !strcmp (theProps[i]->type, pProp->prop.type)) {
81 * Reuse this property but replace its
85 for (j = 0; j < pProp->prop.num_vals; j++) {
86 XtFree (pProp->prop.vals[j].value);
89 if (pProp->prop.num_vals > 0)
90 XtFree ((char *) pProp->prop.vals);
92 pProp->prop.vals = CopyPropValues (
93 theProps[i]->num_vals,
96 pProp->prop.num_vals = theProps[i]->num_vals;
106 * Put it at the end of the list (or the beginning
107 * if this client has no properties)
109 PropertyRecPtr trail = pClient->props;
110 for (pProp = pClient->props;
112 trail = pProp, pProp = pProp->next);
115 pProp = (PropertyRecPtr)XtMalloc (sizeof (PropertyRec));
122 pClient->props = pProp;
124 pProp->prop.name = XtNewString (theProps[i]->name);
125 pProp->prop.type = XtNewString (theProps[i]->type);
126 pProp->prop.num_vals = theProps[i]->num_vals;
129 pProp->prop.vals = CopyPropValues (
130 theProps[i]->num_vals, theProps[i]->vals);
133 SmFreeProperty (theProps[i]);
137 free ((char *) theProps);
140 for (i = 0, pProp = pClient->props;
142 i++, pProp = pProp->next) {
143 (void) printf ("\t[%2d] name = %s\n", i + 1,
145 (void) printf ("\t[%2d] type = %s\n", i + 1,
147 (void) printf ("\t[%2d] num props = %d\n", i + 1,
148 pProp->prop.num_vals);
149 for (j = 0; j < pProp->prop.num_vals; j++) {
150 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
151 pProp->prop.vals[j].length,
152 pProp->prop.vals[j].value);
160 DeletePropertiesProc (
162 SmPointer managerData,
166 ClientRecPtr pClient = (ClientRecPtr) managerData;
170 (void) printf ("Received DELETE PROPERTIES [%p] - %d properties\n",
172 for (i = 0; i < numProps; i++)
173 (void) printf ("\t%s\n", propNames[i]);
179 for (i = 0; i < numProps; i++) {
181 PropertyRecPtr pProp;
183 PropertyRecPtr trail;
185 for (pProp = pClient->props, trail = pClient->props ;
187 trail = pProp, pProp = pProp->next) {
189 if (!strcmp (pProp->prop.name, propNames[i])) {
193 XtFree (pProp->prop.name);
194 XtFree (pProp->prop.type);
196 for (j = 0; j < pProp->prop.num_vals; j++) {
197 XtFree (pProp->prop.vals[j].value);
200 if (pProp->prop.num_vals > 0)
201 XtFree ((char *) pProp->prop.vals);
203 * Remove the record from the list and then
206 trail->next = pProp->next;
207 XtFree ((char *) pProp);
215 free ((char *) propNames);
222 SmPointer managerData)
224 ClientRecPtr pClient = (ClientRecPtr) managerData;
225 PropertyRecPtr pProp;
226 PropertyRecPtr trail;
232 (void) printf ("Received GET PROPERTIES [%p]\n", smsConn);
235 if (!pClient->props) {
236 SmsReturnProperties (smsConn, 0, NULL);
240 for (pProp = pClient->props, numProps = 0;
242 pProp = pProp->next, numProps++);
244 pPropsRet = (SmProp **) XtMalloc (numProps * sizeof (SmProp *));
247 SmsReturnProperties (smsConn, 0, NULL);
252 * This function must return an array of pointers to SmProp
253 * structures and since the properties are actually stored
254 * in a linked list, a transformation is required.
256 for (i=0, pProp = pClient->props;
258 i++, pProp = pProp->next) {
260 pPropsRet[i] = (SmProp *) XtMalloc (sizeof (SmProp));
262 SmsReturnProperties (smsConn, 0, NULL);
266 pPropsRet[i]->name = XtNewString (pProp->prop.name);
267 pPropsRet[i]->type = XtNewString (pProp->prop.type);
268 pPropsRet[i]->num_vals = pProp->prop.num_vals;
269 pPropsRet[i]->vals = (SmPropValue *) XtMalloc (
270 pProp->prop.num_vals * sizeof (SmPropValue));
272 if (!pPropsRet[i]->vals) {
273 SmsReturnProperties (smsConn, 0, NULL);
277 for (j = 0; j < pProp->prop.num_vals; j++) {
279 pPropsRet[i]->vals[j].length =
280 pProp->prop.vals[j].length;
281 pPropsRet[i]->vals[j].value = (SmPointer)
282 XtMalloc (pProp->prop.vals[j].length);
284 if (!pPropsRet[i]->vals[j].value) {
285 SmsReturnProperties (smsConn, 0, NULL);
289 memcpy (pPropsRet[i]->vals[j].value,
290 pProp->prop.vals[j].value,
291 pProp->prop.vals[j].length);
295 SmsReturnProperties (smsConn, numProps, pPropsRet);
298 for (i = 0; i < numProps; i++) {
299 (void) printf ("\t[%2d] name = %s\n", i + 1,
301 (void) printf ("\t[%2d] type = %s\n", i + 1,
303 (void) printf ("\t[%2d] num props = %d\n", i + 1,
304 pPropsRet[i]->num_vals);
305 for (j = 0; j < pPropsRet[i]->num_vals; j++) {
306 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
307 pPropsRet[i]->vals[j].length,
308 pPropsRet[i]->vals[j].value);
313 for (i = 0; i < numProps; i++)
314 SmFreeProperty (pPropsRet[i]);
316 XtFree ((char *) pPropsRet);
323 SmPropValue * thePropValues)
325 SmPropValue * pPropValueRet;
328 pPropValueRet = (SmPropValue *) XtMalloc (numPropValues *
329 sizeof (SmPropValue));
334 for (i = 0; i < numPropValues; i++) {
336 pPropValueRet[i].length = thePropValues[i].length;
337 pPropValueRet[i].value = (SmPointer)
338 XtMalloc(thePropValues[i].length + 1);
340 if (!pPropValueRet[i].value)
343 memcpy (pPropValueRet[i].value,
344 thePropValues[i].value,
345 thePropValues[i].length);
347 ((char *) pPropValueRet[i].value)[pPropValueRet[i].length]='\0';
350 return (pPropValueRet);
355 * Returns a ptr to the property record list for the given
360 ClientRecPtr pClientRec,
363 PropertyRecPtr pPropRec;
365 for (pPropRec = pClientRec->props; pPropRec;
366 pPropRec = pPropRec->next) {
368 if (!strcmp (propName, pPropRec->prop.name))
378 * If the given property exists, it returns a ptr to the first
379 * value of the property if the type of the property is SmARRAY8
383 GetArrayPropertyValue (
384 ClientRecPtr pClientRec,
387 PropertyRecPtr pPropRec;
389 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
392 if ((!strcmp (pPropRec->prop.type, SmARRAY8)) &&
393 (pPropRec->prop.num_vals >= 1))
394 return (pPropRec->prop.vals[0].value);
400 /*************************************<->*************************************
402 * GetListOfArrayPropertyValue -
404 * Description: If the specified property exits and its type is
405 * a LISTofARRAY8, then a NULL-terminated array of pointers
406 * to the values is returned.
408 * Returns: NULL-terminated array of values or NULL
410 * Comments: caller is responsible for using XtFree to free the returned
411 * pointer if it is not NULL
413 *************************************<->***********************************/
415 GetListOfArrayPropertyValue (
416 ClientRecPtr pClientRec,
419 PropertyRecPtr pPropRec;
423 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
426 if ((strcmp (pPropRec->prop.type, SmLISTofARRAY8)) ||
427 (pPropRec->prop.num_vals <= 0))
430 ppchar = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
435 for (i = 0; i < pPropRec->prop.num_vals; i++)
436 ppchar[i] = pPropRec->prop.vals[i].value;
438 ppchar[pPropRec->prop.num_vals] = NULL;
444 /*************************************<->*************************************
446 * GetCardPropertyValue -
448 * Description: If the specified property exits and its type is
449 * a CARD8, then return its value.
451 * Returns: True if the property is found; False otherwise
453 *************************************<->***********************************/
455 GetCardPropertyValue (
456 ClientRecPtr pClientRec,
458 int * propValue) /* MODIFIED */
460 PropertyRecPtr pPropRec;
462 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
465 if ((!strcmp (pPropRec->prop.type, SmCARD8)) &&
466 (pPropRec->prop.num_vals >= 1)) {
467 int hint = (int) *((char *) (pPropRec->prop.vals[0].value));