protodpy.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* *
  24. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  25. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  26. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  27. * (c) Copyright 1993, 1994 Novell, Inc. *
  28. */
  29. /*
  30. * $XConsortium: protodpy.c /main/4 1995/10/27 16:14:24 rswiston $
  31. *
  32. * Copyright 1989 Massachusetts Institute of Technology
  33. *
  34. * Permission to use, copy, modify, distribute, and sell this software and its
  35. * documentation for any purpose is hereby granted without fee, provided that
  36. * the above copyright notice appear in all copies and that both that
  37. * copyright notice and this permission notice appear in supporting
  38. * documentation, and that the name of M.I.T. not be used in advertising or
  39. * publicity pertaining to distribution of the software without specific,
  40. * written prior permission. M.I.T. makes no representations about the
  41. * suitability of this software for any purpose. It is provided "as is"
  42. * without express or implied warranty.
  43. *
  44. * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  45. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  46. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  47. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  48. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  49. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  50. *
  51. * Author: Keith Packard, MIT X Consortium
  52. */
  53. /*
  54. * protodpy.c
  55. *
  56. * manage a collection of proto-displays. These are displays for
  57. * which sessionID's have been generated, but no session has been
  58. * started.
  59. */
  60. #include "dm.h"
  61. struct protoDisplay *protoDisplays;
  62. struct protoDisplay *
  63. FindProtoDisplay( struct sockaddr *address, int addrlen,
  64. #if NeedWidePrototypes
  65. int displayNumber )
  66. #else
  67. CARD16 displayNumber )
  68. #endif /* NeedWidePrototypes */
  69. {
  70. struct protoDisplay *pdpy;
  71. for (pdpy = protoDisplays; pdpy; pdpy=pdpy->next)
  72. if (pdpy->displayNumber == displayNumber &&
  73. addressEqual ((char *)address, addrlen, (char *)pdpy->address, pdpy->addrlen))
  74. {
  75. return pdpy;
  76. }
  77. return (struct protoDisplay *) 0;
  78. }
  79. void
  80. TimeoutProtoDisplays( long now )
  81. {
  82. struct protoDisplay *pdpy, *next;
  83. for (pdpy = protoDisplays; pdpy; pdpy = next)
  84. {
  85. next = pdpy->next;
  86. if (pdpy->date < now - PROTO_TIMEOUT)
  87. DisposeProtoDisplay (pdpy);
  88. }
  89. }
  90. struct protoDisplay *
  91. NewProtoDisplay( struct sockaddr *address, int addrlen,
  92. #if NeedWidePrototypes
  93. int displayNumber,
  94. int connectionType,
  95. #else
  96. CARD16 displayNumber,
  97. CARD16 connectionType,
  98. #endif /* NeedWidePrototypes */
  99. ARRAY8Ptr connectionAddress, CARD32 sessionID )
  100. {
  101. struct protoDisplay *pdpy;
  102. time_t date;
  103. time (&date);
  104. TimeoutProtoDisplays (date);
  105. pdpy = (struct protoDisplay *) malloc (sizeof *pdpy);
  106. if (!pdpy)
  107. return NULL;
  108. pdpy->address = (struct sockaddr *) malloc (addrlen);
  109. if (!pdpy->address)
  110. {
  111. free ((char *) pdpy);
  112. return NULL;
  113. }
  114. pdpy->addrlen = addrlen;
  115. bcopy ((char *)address, (char *)pdpy->address, addrlen);
  116. pdpy->displayNumber = displayNumber;
  117. pdpy->connectionType = connectionType;
  118. pdpy->date = date;
  119. if (!XdmcpCopyARRAY8 (connectionAddress, &pdpy->connectionAddress))
  120. {
  121. free ((char *) pdpy->address);
  122. free ((char *) pdpy);
  123. return NULL;
  124. }
  125. pdpy->sessionID = sessionID;
  126. pdpy->fileAuthorization = (Xauth *) NULL;
  127. pdpy->xdmcpAuthorization = (Xauth *) NULL;
  128. pdpy->next = protoDisplays;
  129. protoDisplays = pdpy;
  130. return pdpy;
  131. }
  132. int
  133. DisposeProtoDisplay( struct protoDisplay *pdpy )
  134. {
  135. struct protoDisplay *p, *prev;
  136. prev = 0;
  137. for (p = protoDisplays; p; p=p->next)
  138. {
  139. if (p == pdpy)
  140. break;
  141. prev = p;
  142. }
  143. if (!p)
  144. return 0;
  145. if (prev)
  146. prev->next = pdpy->next;
  147. else
  148. protoDisplays = pdpy->next;
  149. XdmcpDisposeARRAY8 (&pdpy->connectionAddress);
  150. if (pdpy->fileAuthorization)
  151. XauDisposeAuth (pdpy->fileAuthorization);
  152. if (pdpy->xdmcpAuthorization)
  153. XauDisposeAuth (pdpy->xdmcpAuthorization);
  154. free ((char *) pdpy->address);
  155. free ((char *) pdpy);
  156. return 1;
  157. }