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 $
37 #include <X11/Intrinsic.h>
38 #include <X11/SM/SMlib.h>
42 * Forward declarations
44 static SmPropValue * CopyPropValues (
46 SmPropValue * thePropValues);
52 SmPointer managerData,
56 ClientRecPtr pClient = (ClientRecPtr) managerData;
62 (void) printf ("Received SET PROPERTIES [%p]\n", smsConn);
68 for (i = 0; i < numProps; i++) {
72 if (theProps[i]->num_vals == 0)
75 for (pProp = pClient->props;
77 pProp = pProp->next) {
79 if (!strcmp (theProps[i]->name, pProp->prop.name) &&
80 !strcmp (theProps[i]->type, pProp->prop.type)) {
82 * Reuse this property but replace its
86 for (j = 0; j < pProp->prop.num_vals; j++) {
87 XtFree (pProp->prop.vals[j].value);
90 if (pProp->prop.num_vals > 0)
91 XtFree ((char *) pProp->prop.vals);
93 pProp->prop.vals = CopyPropValues (
94 theProps[i]->num_vals,
97 pProp->prop.num_vals = theProps[i]->num_vals;
107 * Put it at the end of the list (or the beginning
108 * if this client has no properties)
110 PropertyRecPtr trail = pClient->props;
111 for (pProp = pClient->props;
113 trail = pProp, pProp = pProp->next);
116 pProp = (PropertyRecPtr)XtMalloc (sizeof (PropertyRec));
123 pClient->props = pProp;
125 pProp->prop.name = XtNewString (theProps[i]->name);
126 pProp->prop.type = XtNewString (theProps[i]->type);
127 pProp->prop.num_vals = theProps[i]->num_vals;
130 pProp->prop.vals = CopyPropValues (
131 theProps[i]->num_vals, theProps[i]->vals);
134 SmFreeProperty (theProps[i]);
138 free ((char *) theProps);
141 for (i = 0, pProp = pClient->props;
143 i++, pProp = pProp->next) {
144 (void) printf ("\t[%2d] name = %s\n", i + 1,
146 (void) printf ("\t[%2d] type = %s\n", i + 1,
148 (void) printf ("\t[%2d] num props = %d\n", i + 1,
149 pProp->prop.num_vals);
150 for (j = 0; j < pProp->prop.num_vals; j++) {
151 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
152 pProp->prop.vals[j].length,
153 pProp->prop.vals[j].value);
161 DeletePropertiesProc (
163 SmPointer managerData,
167 ClientRecPtr pClient = (ClientRecPtr) managerData;
171 (void) printf ("Received DELETE PROPERTIES [%p] - %d properties\n",
173 for (i = 0; i < numProps; i++)
174 (void) printf ("\t%s\n", propNames[i]);
180 for (i = 0; i < numProps; i++) {
182 PropertyRecPtr pProp;
184 PropertyRecPtr trail;
186 for (pProp = pClient->props, trail = pClient->props ;
188 trail = pProp, pProp = pProp->next) {
190 if (!strcmp (pProp->prop.name, propNames[i])) {
194 XtFree (pProp->prop.name);
195 XtFree (pProp->prop.type);
197 for (j = 0; j < pProp->prop.num_vals; j++) {
198 XtFree (pProp->prop.vals[j].value);
201 if (pProp->prop.num_vals > 0)
202 XtFree ((char *) pProp->prop.vals);
204 * Remove the record from the list and then
207 trail->next = pProp->next;
208 XtFree ((char *) pProp);
216 free ((char *) propNames);
223 SmPointer managerData)
225 ClientRecPtr pClient = (ClientRecPtr) managerData;
226 PropertyRecPtr pProp;
227 PropertyRecPtr trail;
233 (void) printf ("Received GET PROPERTIES [%p]\n", smsConn);
236 if (!pClient->props) {
237 SmsReturnProperties (smsConn, 0, NULL);
241 for (pProp = pClient->props, numProps = 0;
243 pProp = pProp->next, numProps++);
245 pPropsRet = (SmProp **) XtMalloc (numProps * sizeof (SmProp *));
248 SmsReturnProperties (smsConn, 0, NULL);
253 * This function must return an array of pointers to SmProp
254 * structures and since the properties are actually stored
255 * in a linked list, a transformation is required.
257 for (i=0, pProp = pClient->props;
259 i++, pProp = pProp->next) {
261 pPropsRet[i] = (SmProp *) XtMalloc (sizeof (SmProp));
263 SmsReturnProperties (smsConn, 0, NULL);
267 pPropsRet[i]->name = XtNewString (pProp->prop.name);
268 pPropsRet[i]->type = XtNewString (pProp->prop.type);
269 pPropsRet[i]->num_vals = pProp->prop.num_vals;
270 pPropsRet[i]->vals = (SmPropValue *) XtMalloc (
271 pProp->prop.num_vals * sizeof (SmPropValue));
273 if (!pPropsRet[i]->vals) {
274 SmsReturnProperties (smsConn, 0, NULL);
278 for (j = 0; j < pProp->prop.num_vals; j++) {
280 pPropsRet[i]->vals[j].length =
281 pProp->prop.vals[j].length;
282 pPropsRet[i]->vals[j].value = (SmPointer)
283 XtMalloc (pProp->prop.vals[j].length);
285 if (!pPropsRet[i]->vals[j].value) {
286 SmsReturnProperties (smsConn, 0, NULL);
290 memcpy (pPropsRet[i]->vals[j].value,
291 pProp->prop.vals[j].value,
292 pProp->prop.vals[j].length);
296 SmsReturnProperties (smsConn, numProps, pPropsRet);
299 for (i = 0; i < numProps; i++) {
300 (void) printf ("\t[%2d] name = %s\n", i + 1,
302 (void) printf ("\t[%2d] type = %s\n", i + 1,
304 (void) printf ("\t[%2d] num props = %d\n", i + 1,
305 pPropsRet[i]->num_vals);
306 for (j = 0; j < pPropsRet[i]->num_vals; j++) {
307 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
308 pPropsRet[i]->vals[j].length,
309 pPropsRet[i]->vals[j].value);
314 for (i = 0; i < numProps; i++)
315 SmFreeProperty (pPropsRet[i]);
317 XtFree ((char *) pPropsRet);
324 SmPropValue * thePropValues)
326 SmPropValue * pPropValueRet;
329 pPropValueRet = (SmPropValue *) XtMalloc (numPropValues *
330 sizeof (SmPropValue));
335 for (i = 0; i < numPropValues; i++) {
337 pPropValueRet[i].length = thePropValues[i].length;
338 pPropValueRet[i].value = (SmPointer)
339 XtMalloc(thePropValues[i].length + 1);
341 if (!pPropValueRet[i].value)
344 memcpy (pPropValueRet[i].value,
345 thePropValues[i].value,
346 thePropValues[i].length);
348 ((char *) pPropValueRet[i].value)[pPropValueRet[i].length]='\0';
351 return (pPropValueRet);
356 * Returns a ptr to the property record list for the given
361 ClientRecPtr pClientRec,
364 PropertyRecPtr pPropRec;
366 for (pPropRec = pClientRec->props; pPropRec;
367 pPropRec = pPropRec->next) {
369 if (!strcmp (propName, pPropRec->prop.name))
379 * If the given property exists, it returns a ptr to the first
380 * value of the property if the type of the property is SmARRAY8
384 GetArrayPropertyValue (
385 ClientRecPtr pClientRec,
388 PropertyRecPtr pPropRec;
390 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
393 if ((!strcmp (pPropRec->prop.type, SmARRAY8)) &&
394 (pPropRec->prop.num_vals >= 1))
395 return (pPropRec->prop.vals[0].value);
401 /*************************************<->*************************************
403 * GetListOfArrayPropertyValue -
405 * Description: If the specified property exits and its type is
406 * a LISTofARRAY8, then a NULL-terminated array of pointers
407 * to the values is returned.
409 * Returns: NULL-terminated array of values or NULL
411 * Comments: caller is responsible for using XtFree to free the returned
412 * pointer if it is not NULL
414 *************************************<->***********************************/
416 GetListOfArrayPropertyValue (
417 ClientRecPtr pClientRec,
420 PropertyRecPtr pPropRec;
424 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
427 if ((strcmp (pPropRec->prop.type, SmLISTofARRAY8)) ||
428 (pPropRec->prop.num_vals <= 0))
431 ppchar = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
436 for (i = 0; i < pPropRec->prop.num_vals; i++)
437 ppchar[i] = pPropRec->prop.vals[i].value;
439 ppchar[pPropRec->prop.num_vals] = NULL;
445 /*************************************<->*************************************
447 * GetCardPropertyValue -
449 * Description: If the specified property exits and its type is
450 * a CARD8, then return its value.
452 * Returns: True if the property is found; False otherwise
454 *************************************<->***********************************/
456 GetCardPropertyValue (
457 ClientRecPtr pClientRec,
459 int * propValue) /* MODIFIED */
461 PropertyRecPtr pPropRec;
463 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
466 if ((!strcmp (pPropRec->prop.type, SmCARD8)) &&
467 (pPropRec->prop.num_vals >= 1)) {
468 int hint = (int) *((char *) (pPropRec->prop.vals[0].value));