Use C++ linker
[oweals/cde.git] / cde / programs / dtlogin / dpylist.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 librararies 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 /* (c) Copyright 1997 The Open Group */
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  * xdm - display manager daemon
32  *
33  * $TOG: dpylist.c /main/5 1997/03/14 13:44:46 barstow $
34  *
35  * Copyright 1988 Massachusetts Institute of Technology
36  *
37  * Permission to use, copy, modify, and distribute this software and its
38  * documentation for any purpose and without fee is hereby granted, provided
39  * that the above copyright notice appear in all copies and that both that
40  * copyright notice and this permission notice appear in supporting
41  * documentation, and that the name of M.I.T. not be used in advertising or
42  * publicity pertaining to distribution of the software without specific,
43  * written prior permission.  M.I.T. makes no representations about the
44  * suitability of this software for any purpose.  It is provided "as is"
45  * without express or implied warranty.
46  *
47  * Author:  Keith Packard, MIT X Consortium
48  */
49
50 /*
51  * a simple linked list of known displays
52  */
53
54 # include "dm.h"
55 # include "vgmsg.h"
56
57 struct display  *displays;
58
59
60 int 
61 AnyDisplaysLeft( void )
62 {
63         return displays != (struct display *) 0;
64 }
65
66 void
67 ForEachDisplay( void (*f)() )
68 {
69         struct display  *d, *next;
70
71         for (d = displays; d; d = next) {
72                 next = d->next;
73                 (*f) (d);
74         }
75 }
76
77 struct display * 
78 FindDisplayByName( char *name )
79 {
80         struct display  *d;
81
82         for (d = displays; d; d = d->next)
83                 if (!strcmp (name, d->name))
84                         return d;
85         return 0;
86 }
87
88 struct display *
89 FindDisplayByPid( int pid )
90 {
91         struct display  *d;
92
93         for (d = displays; d; d = d->next)
94                 if (pid == d->pid)
95                         return d;
96         return 0;
97 }
98
99 struct display * 
100 FindDisplayByServerPid( int serverPid )
101 {
102         struct display  *d;
103
104         for (d = displays; d; d = d->next)
105                 if (serverPid == d->serverPid)
106                         return d;
107         return 0;
108 }
109
110 struct display * 
111 FindDisplayBySessionID( CARD32 sessionID )
112 {
113     struct display      *d;
114
115     for (d = displays; d; d = d->next)
116         if (sessionID == d->sessionID)
117             return d;
118     return 0;
119 }
120
121 struct display * 
122 FindDisplayByAddress(struct sockaddr *addr, int addrlen,
123 #if NeedWidePrototypes
124         int displayNumber )
125 #else
126         CARD16 displayNumber )
127 #endif /* NeedWidePrototypes */
128 {
129     struct display  *d;
130
131     for (d = displays; d; d = d->next)
132         if (d->displayType.origin == FromXDMCP &&
133             d->displayNumber == displayNumber &&
134             addressEqual ((char *)d->from, d->fromlen, (char *)addr, addrlen))
135         {
136             return d;
137         }
138     return 0;
139 }
140
141 #define IfFree(x)  if (x) free ((char *) x)
142     
143 void
144 RemoveDisplay( struct display *old )
145 {
146     struct display      *d, *p;
147     char                **x;
148     int                       i;
149
150     extern int          wakeupTime;
151     
152     Debug("Removing display %s from display list.\n", old->name);
153     
154     p = 0;
155     for (d = displays; d; d = d->next) {
156         if (d == old) {
157             if (p)
158                 p->next = d->next;
159             else
160                 displays = d->next;
161             IfFree (d->name);
162             IfFree (d->class);
163             for (x = d->argv; x && *x; x++)
164                 IfFree (*x);
165             IfFree (d->argv);
166             IfFree (d->resources);
167             IfFree (d->xrdb);
168             IfFree (d->cpp);
169             IfFree (d->setup);
170             IfFree (d->startup);
171             IfFree (d->reset);
172             IfFree (d->session);
173             IfFree (d->userPath);
174             IfFree (d->systemPath);
175             IfFree (d->systemShell);
176             IfFree (d->failsafeClient);
177             IfFree (d->chooser);
178             if (d->authorizations)
179             {
180                 for (i = 0; i < d->authNum; i++)
181                     XauDisposeAuth (d->authorizations[i]);
182                 free ((char *) d->authorizations);
183             }
184             IfFree (d->clientAuthFile);
185             if (d->authFile)
186                 (void) unlink (d->authFile);
187             IfFree (d->authFile);
188             IfFree (d->userAuthDir);
189             IfFree (d->authNames);
190             IfFree (d->peer);
191             IfFree (d->from);
192             XdmcpDisposeARRAY8(&d->clientAddr);
193             IfFree (d->language);
194             IfFree (d->langList);
195             IfFree (d->utmpId);
196             IfFree (d->gettyLine);
197             IfFree (d->gettySpeed);
198             IfFree (d->environStr);
199             IfFree (d->verifyName);
200
201             /*
202              *  turn off polling if we are removing a suspended display...
203              */
204              
205             if ( d->status == suspended )
206                 wakeupTime = -1;
207
208
209             free ((char *) d);
210             break;
211         }
212         p = d;
213     }
214 }
215
216 struct display * 
217 NewDisplay( char *name, char *class )
218 {
219     struct display      *d;
220
221     d = (struct display *) malloc (sizeof (struct display));
222     if (!d) {
223         LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
224         return 0;
225     }
226     d->next = displays;
227     d->name = malloc ((unsigned) (strlen (name) + 1));
228     if (!d->name) {
229         LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
230         free ((char *) d);
231         return 0;
232     }
233     strcpy (d->name, name);
234     if (class)
235     {
236         d->class = malloc ((unsigned) (strlen (class) + 1));
237         if (!d->class) {
238             LogOutOfMem(
239                 ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
240             free (d->name);
241             free ((char *) d);
242             return 0;
243         }
244         strcpy (d->class, class);
245     }
246     else
247     {
248         d->class = (char *) 0;
249     }
250     /* initialize every field to avoid possible problems */
251     d->argv = 0;
252     d->status = notRunning;
253     d->pid = -1;
254     d->serverPid = -1;
255     d->state = NewEntry;
256     d->resources = NULL;
257     d->xrdb = NULL;
258     d->cpp = NULL;
259     d->setup = NULL;
260     d->startup = NULL;
261     d->reset = NULL;
262     d->session = NULL;
263     d->userPath = NULL;
264     d->systemPath = NULL;
265     d->systemShell = NULL;
266     d->failsafeClient = NULL;
267     d->chooser = NULL;
268     d->authorize = FALSE;
269     d->authorizations = NULL;
270     d->authNum = 0;
271     d->authNameNum = 0;
272     d->clientAuthFile = NULL;
273     d->authFile = NULL;
274     d->userAuthDir = NULL;
275     d->authNames = NULL;
276     d->authNameLens = NULL;
277     d->openDelay = 0;
278     d->openRepeat = 0;
279     d->openTimeout = 0;
280     d->startAttempts = 0;
281     d->startTries = 0;
282     d->terminateServer = 0;
283     d->grabTimeout = 0;
284     d->sessionID = 0;
285     d->peer = 0;
286     d->peerlen = 0;
287     d->from = 0;
288     d->fromlen = 0;
289     d->displayNumber = 0;
290     d->useChooser = 0;
291     d->clientAddr.data = NULL;
292     d->clientAddr.length = 0;
293     d->language = NULL;
294     d->langList = NULL;
295     d->utmpId = NULL;
296     d->gettyLine = NULL;
297     d->gettySpeed = NULL;
298     d->environStr = NULL;
299     d->dtlite = FALSE;
300     d->verifyName = NULL;
301     d->pmSearchPath = NULL;
302     d->bmSearchPath = NULL;
303     displays = d;
304     return d;
305 }
306