Use C++ linker
[oweals/cde.git] / cde / programs / dtlogin / protodpy.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 /*                                                                      *
24  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
25  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
26  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
27  * (c) Copyright 1993, 1994 Novell, Inc.                                *
28  */
29 /*
30  * $XConsortium: protodpy.c /main/4 1995/10/27 16:14:24 rswiston $
31  *
32  * Copyright 1989 Massachusetts Institute of Technology
33  *
34  * Permission to use, copy, modify, distribute, and sell this software and its
35  * documentation for any purpose is hereby granted without fee, provided that
36  * the above copyright notice appear in all copies and that both that
37  * copyright notice and this permission notice appear in supporting
38  * documentation, and that the name of M.I.T. not be used in advertising or
39  * publicity pertaining to distribution of the software without specific,
40  * written prior permission.  M.I.T. makes no representations about the
41  * suitability of this software for any purpose.  It is provided "as is"
42  * without express or implied warranty.
43  *
44  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
46  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
48  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
49  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50  *
51  * Author:  Keith Packard, MIT X Consortium
52  */
53
54 /*
55  * protodpy.c
56  *
57  * manage a collection of proto-displays.  These are displays for
58  * which sessionID's have been generated, but no session has been
59  * started.
60  */
61
62 #include "dm.h"
63
64 struct protoDisplay     *protoDisplays;
65
66 struct protoDisplay * 
67 FindProtoDisplay( struct sockaddr *address, int addrlen,
68 #if NeedWidePrototypes
69         int displayNumber )
70 #else
71         CARD16 displayNumber )
72 #endif /* NeedWidePrototypes */
73 {
74     struct protoDisplay *pdpy;
75
76     for (pdpy = protoDisplays; pdpy; pdpy=pdpy->next)
77         if (pdpy->displayNumber == displayNumber &&
78             addressEqual ((char *)address, addrlen, (char *)pdpy->address, pdpy->addrlen))
79         {
80             return pdpy;
81         }
82     return (struct protoDisplay *) 0;
83 }
84
85 void
86 TimeoutProtoDisplays( long now )
87 {
88     struct protoDisplay *pdpy, *next;
89
90     for (pdpy = protoDisplays; pdpy; pdpy = next)
91     {
92         next = pdpy->next;
93         if (pdpy->date < now - PROTO_TIMEOUT)
94             DisposeProtoDisplay (pdpy);
95     }
96 }
97
98 struct protoDisplay * 
99 NewProtoDisplay( struct sockaddr *address, int addrlen,
100 #if NeedWidePrototypes
101         int displayNumber,
102         int connectionType,
103 #else
104         CARD16 displayNumber,
105         CARD16 connectionType,
106 #endif /* NeedWidePrototypes */
107         ARRAY8Ptr connectionAddress, CARD32 sessionID )
108 {
109     struct protoDisplay *pdpy;
110     time_t  date;
111
112     time (&date);
113     TimeoutProtoDisplays (date);
114     pdpy = (struct protoDisplay *) malloc (sizeof *pdpy);
115     if (!pdpy)
116         return NULL;
117     pdpy->address = (struct sockaddr *) malloc (addrlen);
118     if (!pdpy->address)
119     {
120         free ((char *) pdpy);
121         return NULL;
122     }
123     pdpy->addrlen = addrlen;
124     bcopy ((char *)address, (char *)pdpy->address, addrlen);
125     pdpy->displayNumber = displayNumber;
126     pdpy->connectionType = connectionType;
127     pdpy->date = date;
128     if (!XdmcpCopyARRAY8 (connectionAddress, &pdpy->connectionAddress))
129     {
130         free ((char *) pdpy->address);
131         free ((char *) pdpy);
132         return NULL;
133     }
134     pdpy->sessionID = sessionID;
135     pdpy->fileAuthorization = (Xauth *) NULL;
136     pdpy->xdmcpAuthorization = (Xauth *) NULL;
137     pdpy->next = protoDisplays;
138     protoDisplays = pdpy;
139     return pdpy;
140 }
141
142 int 
143 DisposeProtoDisplay( struct protoDisplay *pdpy )
144 {
145     struct protoDisplay *p, *prev;
146
147     prev = 0;
148     for (p = protoDisplays; p; p=p->next)
149     {
150         if (p == pdpy)
151             break;
152         prev = p;
153     }
154     if (!p)
155         return;
156     if (prev)
157         prev->next = pdpy->next;
158     else
159         protoDisplays = pdpy->next;
160     XdmcpDisposeARRAY8 (&pdpy->connectionAddress);
161     if (pdpy->fileAuthorization)
162         XauDisposeAuth (pdpy->fileAuthorization);
163     if (pdpy->xdmcpAuthorization)
164         XauDisposeAuth (pdpy->xdmcpAuthorization);
165     free ((char *) pdpy->address);
166     free ((char *) pdpy);
167 }