xiqueryversion.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * @file xiqueryversion.c
  28. * Protocol handling for the XIQueryVersion request/reply.
  29. */
  30. #ifdef HAVE_DIX_CONFIG_H
  31. #include <dix-config.h>
  32. #endif
  33. #include "inputstr.h"
  34. #include <X11/Xmd.h>
  35. #include <X11/X.h>
  36. #include <X11/extensions/XI2proto.h>
  37. #include "exglobals.h"
  38. #include "exevents.h"
  39. #include "xiqueryversion.h"
  40. #include "misc.h"
  41. extern XExtensionVersion XIVersion; /* defined in getvers.c */
  42. /**
  43. * Return the supported XI version.
  44. *
  45. * Saves the version the client claims to support as well, for future
  46. * reference.
  47. */
  48. int
  49. ProcXIQueryVersion(ClientPtr client)
  50. {
  51. xXIQueryVersionReply rep;
  52. XIClientPtr pXIClient;
  53. int major, minor;
  54. REQUEST(xXIQueryVersionReq);
  55. REQUEST_SIZE_MATCH(xXIQueryVersionReq);
  56. /* This request only exists after XI2 */
  57. if (stuff->major_version < 2) {
  58. client->errorValue = stuff->major_version;
  59. return BadValue;
  60. }
  61. pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
  62. if (version_compare(XIVersion.major_version, XIVersion.minor_version,
  63. stuff->major_version, stuff->minor_version) > 0) {
  64. major = stuff->major_version;
  65. minor = stuff->minor_version;
  66. } else {
  67. major = XIVersion.major_version;
  68. minor = XIVersion.minor_version;
  69. }
  70. if (pXIClient->major_version) {
  71. /* Check to see if the client has only ever asked
  72. * for version 2.2 or higher
  73. */
  74. if (version_compare(major, minor, 2, 2) >= 0 &&
  75. version_compare(pXIClient->major_version, pXIClient->minor_version, 2, 2) >= 0)
  76. {
  77. /* As of version 2.2, Peter promises to never again break
  78. * backward compatibility, so we'll return the requested
  79. * version to the client but leave the server internal
  80. * version set to the highest requested value
  81. */
  82. if (version_compare(major, minor,
  83. pXIClient->major_version, pXIClient->minor_version) > 0)
  84. {
  85. pXIClient->major_version = major;
  86. pXIClient->minor_version = minor;
  87. }
  88. } else {
  89. if (version_compare(major, minor,
  90. pXIClient->major_version, pXIClient->minor_version) < 0) {
  91. client->errorValue = stuff->major_version;
  92. return BadValue;
  93. }
  94. major = pXIClient->major_version;
  95. minor = pXIClient->minor_version;
  96. }
  97. } else {
  98. pXIClient->major_version = major;
  99. pXIClient->minor_version = minor;
  100. }
  101. rep = (xXIQueryVersionReply) {
  102. .repType = X_Reply,
  103. .RepType = X_XIQueryVersion,
  104. .sequenceNumber = client->sequence,
  105. .length = 0,
  106. .major_version = major,
  107. .minor_version = minor
  108. };
  109. WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep);
  110. return Success;
  111. }
  112. /* Swapping routines */
  113. int
  114. SProcXIQueryVersion(ClientPtr client)
  115. {
  116. REQUEST(xXIQueryVersionReq);
  117. swaps(&stuff->length);
  118. REQUEST_AT_LEAST_SIZE(xXIQueryVersionReq);
  119. swaps(&stuff->major_version);
  120. swaps(&stuff->minor_version);
  121. return (ProcXIQueryVersion(client));
  122. }
  123. void
  124. SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply * rep)
  125. {
  126. swaps(&rep->sequenceNumber);
  127. swapl(&rep->length);
  128. swaps(&rep->major_version);
  129. swaps(&rep->minor_version);
  130. WriteToClient(client, size, rep);
  131. }