source: trunk/athena/etc/xdm/xdm/dpylist.c @ 6052

Revision 6052, 5.3 KB checked in by lwvanels, 33 years ago (diff)
Initial revision
Line 
1/*
2 * xdm - display manager daemon
3 *
4 * $XConsortium: dpylist.c,v 1.27 91/07/18 21:03:49 rws Exp $
5 *
6 * Copyright 1988 Massachusetts Institute of Technology
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission.  M.I.T. makes no representations about the
15 * suitability of this software for any purpose.  It is provided "as is"
16 * without express or implied warranty.
17 *
18 * Author:  Keith Packard, MIT X Consortium
19 */
20
21/*
22 * a simple linked list of known displays
23 */
24
25# include "dm.h"
26
27static struct display   *displays;
28
29AnyDisplaysLeft ()
30{
31        return displays != (struct display *) 0;
32}
33
34ForEachDisplay (f)
35        void    (*f)();
36{
37        struct display  *d, *next;
38
39        for (d = displays; d; d = next) {
40                next = d->next;
41                (*f) (d);
42        }
43}
44
45struct display *
46FindDisplayByName (name)
47char    *name;
48{
49        struct display  *d;
50
51        for (d = displays; d; d = d->next)
52                if (!strcmp (name, d->name))
53                        return d;
54        return 0;
55}
56
57struct display *
58FindDisplayByPid (pid)
59int     pid;
60{
61        struct display  *d;
62
63        for (d = displays; d; d = d->next)
64                if (pid == d->pid)
65                        return d;
66        return 0;
67}
68
69struct display *
70FindDisplayByServerPid (serverPid)
71int     serverPid;
72{
73        struct display  *d;
74
75        for (d = displays; d; d = d->next)
76                if (serverPid == d->serverPid)
77                        return d;
78        return 0;
79}
80
81#ifdef XDMCP
82
83struct display *
84FindDisplayBySessionID (sessionID)
85    CARD32  sessionID;
86{
87    struct display      *d;
88
89    for (d = displays; d; d = d->next)
90        if (sessionID == d->sessionID)
91            return d;
92    return 0;
93}
94
95struct display *
96FindDisplayByAddress (addr, addrlen, displayNumber)
97    XdmcpNetaddr addr;
98    int          addrlen;
99    CARD16       displayNumber;
100{
101    struct display  *d;
102
103    for (d = displays; d; d = d->next)
104        if (d->displayType.origin == FromXDMCP &&
105            d->displayNumber == displayNumber &&
106            addressEqual (d->from, d->fromlen, addr, addrlen))
107        {
108            return d;
109        }
110    return 0;
111}
112
113#endif /* XDMCP */
114
115#define IfFree(x)  if (x) free ((char *) x)
116   
117RemoveDisplay (old)
118struct display  *old;
119{
120    struct display      *d, *p;
121    char                **x;
122    int                 i;
123
124    p = 0;
125    for (d = displays; d; d = d->next) {
126        if (d == old) {
127            if (p)
128                p->next = d->next;
129            else
130                displays = d->next;
131            IfFree (d->name);
132            IfFree (d->class);
133            for (x = d->argv; x && *x; x++)
134                IfFree (*x);
135            IfFree (d->argv);
136            IfFree (d->resources);
137            IfFree (d->xrdb);
138            IfFree (d->setup);
139            IfFree (d->startup);
140            IfFree (d->reset);
141            IfFree (d->session);
142            IfFree (d->userPath);
143            IfFree (d->systemPath);
144            IfFree (d->systemShell);
145            IfFree (d->failsafeClient);
146            IfFree (d->chooser);
147            if (d->authorizations)
148            {
149                for (i = 0; i < d->authNum; i++)
150                    XauDisposeAuth (d->authorizations[i]);
151                free ((char *) d->authorizations);
152            }
153            IfFree (d->clientAuthFile);
154            if (d->authFile)
155                (void) unlink (d->authFile);
156            IfFree (d->authFile);
157            IfFree (d->userAuthDir);
158            for (x = d->authNames; x && *x; x++)
159                IfFree (*x);
160            IfFree (d->authNames);
161            IfFree (d->authNameLens);
162#ifdef XDMCP
163            IfFree (d->peer);
164            IfFree (d->from);
165            XdmcpDisposeARRAY8 (&d->clientAddr);
166#endif
167            free ((char *) d);
168            break;
169        }
170        p = d;
171    }
172}
173
174struct display *
175NewDisplay (name, class)
176char            *name;
177char            *class;
178{
179    struct display      *d;
180
181    d = (struct display *) malloc (sizeof (struct display));
182    if (!d) {
183        LogOutOfMem ("NewDisplay");
184        return 0;
185    }
186    d->next = displays;
187    d->name = malloc ((unsigned) (strlen (name) + 1));
188    if (!d->name) {
189        LogOutOfMem ("NewDisplay");
190        free ((char *) d);
191        return 0;
192    }
193    strcpy (d->name, name);
194    if (class)
195    {
196        d->class = malloc ((unsigned) (strlen (class) + 1));
197        if (!d->class) {
198            LogOutOfMem ("NewDisplay");
199            free (d->name);
200            free ((char *) d);
201            return 0;
202        }
203        strcpy (d->class, class);
204    }
205    else
206    {
207        d->class = (char *) 0;
208    }
209    /* initialize every field to avoid possible problems */
210    d->argv = 0;
211    d->status = notRunning;
212    d->pid = -1;
213    d->serverPid = -1;
214    d->state = NewEntry;
215    d->resources = NULL;
216    d->xrdb = NULL;
217    d->setup = NULL;
218    d->startup = NULL;
219    d->reset = NULL;
220    d->session = NULL;
221    d->userPath = NULL;
222    d->systemPath = NULL;
223    d->systemShell = NULL;
224    d->failsafeClient = NULL;
225    d->chooser = NULL;
226    d->authorize = FALSE;
227    d->authorizations = NULL;
228    d->authNum = 0;
229    d->authNameNum = 0;
230    d->clientAuthFile = NULL;
231    d->authFile = NULL;
232    d->userAuthDir = NULL;
233    d->authNames = NULL;
234    d->authNameLens = NULL;
235    d->authComplain = 1;
236    d->openDelay = 0;
237    d->openRepeat = 0;
238    d->openTimeout = 0;
239    d->startAttempts = 0;
240    d->startTries = 0;
241    d->terminateServer = 0;
242    d->grabTimeout = 0;
243#ifdef XDMCP
244    d->sessionID = 0;
245    d->peer = 0;
246    d->peerlen = 0;
247    d->from = 0;
248    d->fromlen = 0;
249    d->displayNumber = 0;
250    d->useChooser = 0;
251    d->clientAddr.data = NULL;
252    d->clientAddr.length = 0;
253    d->connectionType = 0;
254#endif
255    displays = d;
256    return d;
257}
Note: See TracBrowser for help on using the repository browser.