xiqueryversion.c revision 706f2543
1/*
2 * Copyright © 2009 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Peter Hutterer
24 *
25 */
26
27/**
28 * @file xiqueryversion.c
29 * Protocol handling for the XIQueryVersion request/reply.
30 */
31
32#ifdef HAVE_DIX_CONFIG_H
33#include <dix-config.h>
34#endif
35
36
37#include "inputstr.h"
38
39#include <X11/Xmd.h>
40#include <X11/X.h>
41#include <X11/extensions/XI2proto.h>
42
43#include "exglobals.h"
44#include "exevents.h"
45#include "xiqueryversion.h"
46#include "misc.h"
47
48extern XExtensionVersion XIVersion; /* defined in getvers.c */
49/**
50 * Return the supported XI version.
51 *
52 * Saves the version the client claims to support as well, for future
53 * reference.
54 */
55int
56ProcXIQueryVersion(ClientPtr client)
57{
58    xXIQueryVersionReply rep;
59    XIClientPtr pXIClient;
60    int major, minor;
61    unsigned int sversion, cversion;
62
63    REQUEST(xXIQueryVersionReq);
64    REQUEST_SIZE_MATCH(xXIQueryVersionReq);
65
66    /* This request only exists after XI2 */
67    if (stuff->major_version < 2)
68    {
69        client->errorValue = stuff->major_version;
70        return BadValue;
71    }
72
73    pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
74
75    sversion = XIVersion.major_version * 1000 + XIVersion.minor_version;
76    cversion = stuff->major_version * 1000 + stuff->minor_version;
77
78    if (sversion > cversion)
79    {
80        major = stuff->major_version;
81        minor = stuff->minor_version;
82    } else
83    {
84        major = XIVersion.major_version;
85        minor = XIVersion.minor_version;
86    }
87
88    pXIClient->major_version = major;
89    pXIClient->minor_version = minor;
90
91    memset(&rep, 0, sizeof(xXIQueryVersionReply));
92    rep.repType = X_Reply;
93    rep.RepType = X_XIQueryVersion;
94    rep.length = 0;
95    rep.sequenceNumber = client->sequence;
96    rep.major_version = major;
97    rep.minor_version = minor;
98
99    WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep);
100
101    return Success;
102}
103
104/* Swapping routines */
105
106int
107SProcXIQueryVersion(ClientPtr client)
108{
109    char n;
110
111    REQUEST(xXIQueryVersionReq);
112    swaps(&stuff->length, n);
113    REQUEST_AT_LEAST_SIZE(xXIQueryVersionReq);
114    swaps(&stuff->major_version, n);
115    swaps(&stuff->minor_version, n);
116    return (ProcXIQueryVersion(client));
117}
118
119void
120SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply *rep)
121{
122    char n;
123    swaps(&rep->sequenceNumber, n);
124    swapl(&rep->length, n);
125    swaps(&rep->major_version, n);
126    swaps(&rep->minor_version, n);
127    WriteToClient(client, size, (char *)rep);
128}
129