2 * Copyright © 2009 Red Hat, Inc.
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:
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
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.
23 * Authors: Peter Hutterer
28 * @file xiqueryversion.c
29 * Protocol handling for the XIQueryVersion request/reply.
32 #ifdef HAVE_DIX_CONFIG_H
33 #include <dix-config.h>
40 #include <X11/extensions/XI2proto.h>
42 #include "exglobals.h"
44 #include "xiqueryversion.h"
47 extern XExtensionVersion XIVersion
; /* defined in getvers.c */
50 * Return the supported XI version.
52 * Saves the version the client claims to support as well, for future
56 ProcXIQueryVersion(ClientPtr client
)
58 xXIQueryVersionReply rep
;
59 XIClientPtr pXIClient
;
62 REQUEST(xXIQueryVersionReq
);
63 REQUEST_SIZE_MATCH(xXIQueryVersionReq
);
65 /* This request only exists after XI2 */
66 if (stuff
->major_version
< 2) {
67 client
->errorValue
= stuff
->major_version
;
71 pXIClient
= dixLookupPrivate(&client
->devPrivates
, XIClientPrivateKey
);
73 if (version_compare(XIVersion
.major_version
, XIVersion
.minor_version
,
74 stuff
->major_version
, stuff
->minor_version
) > 0) {
75 major
= stuff
->major_version
;
76 minor
= stuff
->minor_version
;
78 major
= XIVersion
.major_version
;
79 minor
= XIVersion
.minor_version
;
82 if (pXIClient
->major_version
) {
84 /* Check to see if the client has only ever asked
85 * for version 2.2 or higher
87 if (version_compare(major
, minor
, 2, 2) >= 0 &&
88 version_compare(pXIClient
->major_version
, pXIClient
->minor_version
, 2, 2) >= 0)
91 /* As of version 2.2, Peter promises to never again break
92 * backward compatibility, so we'll return the requested
93 * version to the client but leave the server internal
94 * version set to the highest requested value
96 if (version_compare(major
, minor
,
97 pXIClient
->major_version
, pXIClient
->minor_version
) > 0)
99 pXIClient
->major_version
= major
;
100 pXIClient
->minor_version
= minor
;
103 if (version_compare(major
, minor
,
104 pXIClient
->major_version
, pXIClient
->minor_version
) < 0) {
106 client
->errorValue
= stuff
->major_version
;
109 major
= pXIClient
->major_version
;
110 minor
= pXIClient
->minor_version
;
113 pXIClient
->major_version
= major
;
114 pXIClient
->minor_version
= minor
;
117 rep
= (xXIQueryVersionReply
) {
119 .RepType
= X_XIQueryVersion
,
120 .sequenceNumber
= client
->sequence
,
122 .major_version
= major
,
123 .minor_version
= minor
126 WriteReplyToClient(client
, sizeof(xXIQueryVersionReply
), &rep
);
131 /* Swapping routines */
134 SProcXIQueryVersion(ClientPtr client
)
136 REQUEST(xXIQueryVersionReq
);
137 swaps(&stuff
->length
);
138 REQUEST_AT_LEAST_SIZE(xXIQueryVersionReq
);
139 swaps(&stuff
->major_version
);
140 swaps(&stuff
->minor_version
);
141 return (ProcXIQueryVersion(client
));
145 SRepXIQueryVersion(ClientPtr client
, int size
, xXIQueryVersionReply
* rep
)
147 swaps(&rep
->sequenceNumber
);
149 swaps(&rep
->major_version
);
150 swaps(&rep
->minor_version
);
151 WriteToClient(client
, size
, rep
);