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#include "inputstr.h" 37 38#include <X11/Xmd.h> 39#include <X11/X.h> 40#include <X11/extensions/XI2proto.h> 41 42#include "exglobals.h" 43#include "exevents.h" 44#include "xiqueryversion.h" 45#include "misc.h" 46 47extern XExtensionVersion XIVersion; /* defined in getvers.c */ 48 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 62 REQUEST(xXIQueryVersionReq); 63 REQUEST_SIZE_MATCH(xXIQueryVersionReq); 64 65 /* This request only exists after XI2 */ 66 if (stuff->major_version < 2) { 67 client->errorValue = stuff->major_version; 68 return BadValue; 69 } 70 71 pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey); 72 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; 77 } else { 78 major = XIVersion.major_version; 79 minor = XIVersion.minor_version; 80 } 81 82 if (pXIClient->major_version) { 83 84 /* Check to see if the client has only ever asked 85 * for version 2.2 or higher 86 */ 87 if (version_compare(major, minor, 2, 2) >= 0 && 88 version_compare(pXIClient->major_version, pXIClient->minor_version, 2, 2) >= 0) 89 { 90 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 95 */ 96 if (version_compare(major, minor, 97 pXIClient->major_version, pXIClient->minor_version) > 0) 98 { 99 pXIClient->major_version = major; 100 pXIClient->minor_version = minor; 101 } 102 } else { 103 if (version_compare(major, minor, 104 pXIClient->major_version, pXIClient->minor_version) < 0) { 105 106 client->errorValue = stuff->major_version; 107 return BadValue; 108 } 109 major = pXIClient->major_version; 110 minor = pXIClient->minor_version; 111 } 112 } else { 113 pXIClient->major_version = major; 114 pXIClient->minor_version = minor; 115 } 116 117 rep = (xXIQueryVersionReply) { 118 .repType = X_Reply, 119 .RepType = X_XIQueryVersion, 120 .sequenceNumber = client->sequence, 121 .length = 0, 122 .major_version = major, 123 .minor_version = minor 124 }; 125 126 WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep); 127 128 return Success; 129} 130 131/* Swapping routines */ 132 133int _X_COLD 134SProcXIQueryVersion(ClientPtr client) 135{ 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)); 142} 143 144void _X_COLD 145SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply * rep) 146{ 147 swaps(&rep->sequenceNumber); 148 swapl(&rep->length); 149 swaps(&rep->major_version); 150 swaps(&rep->minor_version); 151 WriteToClient(client, size, rep); 152} 153