libDtSearch: Remove optional code for NO_DBN which is not used on CDE
[oweals/cde.git] / cde / programs / dtsession / SmProperty.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 libraries 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 /* $XConsortium: SmProperty.c /main/7 1996/02/08 11:27:32 barstow $ */
24 /*                                                                      *
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30 /*************************************<+>*************************************
31  *****************************************************************************
32  **
33  **  File:        SmProperty.c
34  **
35  **  Project:     HP DT Session Manager (dtsession)
36  **
37  **  Description:
38  **  -----------
39  **  This file contains routines that deal with the properties used by the
40  **  session manager to save and restore client information.
41  **
42  **
43  **
44  *******************************************************************
45  **  (c) Copyright Hewlett-Packard Company, 1990.  All rights are  
46  **  reserved.  Copying or other reproduction of this program      
47  **  except for archival purposes is prohibited without prior      
48  **  written consent of Hewlett-Packard Company.                     
49  ********************************************************************
50  **
51  **
52  **
53  *****************************************************************************
54  *************************************<+>*************************************/
55
56 #include <stdio.h>
57 #include <X11/Intrinsic.h>
58 #include <X11/Xutil.h>
59 #include <X11/Xatom.h>
60 #include "Sm.h"
61 #include "SmProtocol.h"
62 #include "SmXSMP.h"
63
64 \f
65 /*************************************<->*************************************
66  *
67  *  GetStandardProperties -
68  *
69  *
70  *  Description: returns information about the specified window
71  *  -----------
72  *
73  *  Inputs:
74  *  ------
75  *  window = window for which we are getting properties
76  * 
77  *  Outputs:
78  *  -------
79  *  argv = data returned from WM_COMMAND property (to restart client)
80  *  argc = number of arguments returned from WM_COMMAND property
81  *  clientMachine = which machine is client running on
82  *  xsmpClient = True if the client is XSMP and False otherwise
83  *  screen = window's screen number
84  *
85  *  Comments:
86  *  --------
87  *  All X (except GetWMHints) were not available until R4 and therefore have
88  *  R4 or greater dependencies.
89  *
90  *  BEWARE OF THESE ROUTINES:  The XGetWindowProperty routine returns 0 if
91  *  it succeeds.  These routines (which were derived from XGetWindowProperty
92  *  return 0 if they FAIL.
93  * 
94  *************************************<->***********************************/
95 Status GetStandardProperties(
96         Window                  window,
97         int                     screen,
98         int                     *argc,                  /* RETURNED */
99         char                    ***argv,                /* RETURNED */
100         char                    **clientMachine,        /* RETURNED */
101         Boolean                 *xsmpClient)            /* RETURNED */
102 {
103   int                           cc;
104   long                          suppliedRet;
105   XTextProperty                 sessProp;
106   Atom                          actType;
107   int                           actFormat;
108   unsigned long                 bytesAfter;
109   unsigned long                 nitems;
110   unsigned char                 *data = NULL;
111
112   /*
113    * If this client is participating in the XSMP, then don't save
114    * it as a proxy (pre-XSMP) client.  However, do cache its
115    * screen number before returning.
116    */
117   if (XGetWindowProperty(smGD.display, window, XaSmClientId, 0L,
118                          (long) BUFSIZ, False, XA_STRING, &actType,
119                          &actFormat, &nitems, &bytesAfter, &data) == Success) 
120   {
121       if (data && actType == XA_STRING)
122       {
123           ClientRecPtr          pClient;
124
125           for (pClient = connectedList; pClient != NULL; 
126                pClient = pClient->next) {
127                if (!strcmp ((char *) data, pClient->clientId)) {
128                    pClient->screenNum = screen;
129                    break;
130                }
131           }
132           *xsmpClient = True;
133           SM_FREE ((char *) data);
134           return (0);
135       }
136       SM_FREE ((char *) data);
137   }
138   *xsmpClient = False;
139
140   /*
141    * Get WM_COMMAND property
142    */
143   if ((cc=XGetCommand(smGD.display,window,argv,argc))==0)
144       return(cc);
145
146   /*
147    * If there is no argc or argv - don't bother going on.  We're not
148    * going to save anything anyway
149    */
150   if(*argc == 0)
151       return(0);
152
153
154   /*
155    * Get WM_CLIENT_MACHINE property
156    */
157   if ((cc=XGetWMClientMachine(smGD.display,window,&sessProp))==0)
158   {
159       *clientMachine = NULL;
160   }
161   else
162   {
163       *clientMachine =  (char *) sessProp.value;
164   }
165
166   return(1);
167 }