~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/backend/protodpy.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 1988, 1998  The Open Group
 
4
 
 
5
Permission to use, copy, modify, distribute, and sell this software and its
 
6
documentation for any purpose is hereby granted without fee, provided that
 
7
the above copyright notice appear in all copies and that both that
 
8
copyright notice and this permission notice appear in supporting
 
9
documentation.
 
10
 
 
11
The above copyright notice and this permission notice shall be included
 
12
in all copies or substantial portions of the Software.
 
13
 
 
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
15
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
16
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
17
IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
18
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
19
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
20
OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of a copyright holder shall
 
23
not be used in advertising or otherwise to promote the sale, use or
 
24
other dealings in this Software without prior written authorization
 
25
from the copyright holder.
 
26
 
 
27
*/
 
28
 
 
29
/*
 
30
 * xdm - display manager daemon
 
31
 * Author: Keith Packard, MIT X Consortium
 
32
 *
 
33
 * manage a collection of proto-displays.  These are displays for
 
34
 * which sessionID's have been generated, but no session has been
 
35
 * started.
 
36
 */
 
37
 
 
38
#include "dm.h"
 
39
#include "dm_error.h"
 
40
 
 
41
static struct protoDisplay *protoDisplays;
 
42
 
 
43
struct protoDisplay *
 
44
findProtoDisplay(XdmcpNetaddr address,
 
45
                 int addrlen,
 
46
                 CARD16 displayNumber)
 
47
{
 
48
    struct protoDisplay *pdpy;
 
49
 
 
50
    debug("findProtoDisplay\n");
 
51
    for (pdpy = protoDisplays; pdpy; pdpy = pdpy->next)
 
52
        if (pdpy->displayNumber == displayNumber &&
 
53
                addressEqual(address, addrlen, pdpy->address, pdpy->addrlen))
 
54
            return pdpy;
 
55
    return 0;
 
56
}
 
57
 
 
58
static void
 
59
timeoutProtoDisplays(void)
 
60
{
 
61
    struct protoDisplay *pdpy, *next;
 
62
 
 
63
    for (pdpy = protoDisplays; pdpy; pdpy = next) {
 
64
        next = pdpy->next;
 
65
        if (pdpy->date < (unsigned long)(now - PROTO_TIMEOUT))
 
66
            disposeProtoDisplay(pdpy);
 
67
    }
 
68
}
 
69
 
 
70
struct protoDisplay *
 
71
newProtoDisplay(XdmcpNetaddr address, int addrlen, CARD16 displayNumber,
 
72
                CARD16 connectionType, ARRAY8Ptr connectionAddress,
 
73
                CARD32 sessionID)
 
74
{
 
75
    struct protoDisplay *pdpy;
 
76
 
 
77
    debug("newProtoDisplay\n");
 
78
    timeoutProtoDisplays();
 
79
    pdpy = Malloc(sizeof(*pdpy));
 
80
    if (!pdpy)
 
81
        return 0;
 
82
    pdpy->address = Malloc(addrlen);
 
83
    if (!pdpy->address) {
 
84
        free(pdpy);
 
85
        return 0;
 
86
    }
 
87
    pdpy->addrlen = addrlen;
 
88
    memmove(pdpy->address, address, addrlen);
 
89
    pdpy->displayNumber = displayNumber;
 
90
    pdpy->connectionType = connectionType;
 
91
    pdpy->date = now;
 
92
    if (!XdmcpCopyARRAY8(connectionAddress, &pdpy->connectionAddress)) {
 
93
        free(pdpy->address);
 
94
        free(pdpy);
 
95
        return 0;
 
96
    }
 
97
    pdpy->sessionID = sessionID;
 
98
    pdpy->fileAuthorization = 0;
 
99
    pdpy->xdmcpAuthorization = 0;
 
100
    pdpy->next = protoDisplays;
 
101
    protoDisplays = pdpy;
 
102
    return pdpy;
 
103
}
 
104
 
 
105
void
 
106
disposeProtoDisplay(struct protoDisplay *pdpy)
 
107
{
 
108
    struct protoDisplay *p, *prev;
 
109
 
 
110
    prev = False;
 
111
    for (p = protoDisplays; p; p = p->next) {
 
112
        if (p == pdpy)
 
113
            break;
 
114
        prev = p;
 
115
    }
 
116
    if (!p)
 
117
        return;
 
118
    if (prev)
 
119
        prev->next = pdpy->next;
 
120
    else
 
121
        protoDisplays = pdpy->next;
 
122
    bzero(&pdpy->key, sizeof(pdpy->key));
 
123
    if (pdpy->fileAuthorization)
 
124
        XauDisposeAuth(pdpy->fileAuthorization);
 
125
    if (pdpy->xdmcpAuthorization)
 
126
        XauDisposeAuth(pdpy->xdmcpAuthorization);
 
127
    XdmcpDisposeARRAY8(&pdpy->connectionAddress);
 
128
    free(pdpy->address);
 
129
    free(pdpy);
 
130
}