home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xdm / protodpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  4.3 KB  |  162 lines

  1. /*
  2.  * $XConsortium: protodpy.c,v 1.10 91/07/18 18:50:17 rws Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. /*
  27.  * protodpy.c
  28.  *
  29.  * manage a collection of proto-displays.  These are displays for
  30.  * which sessionID's have been generated, but no session has been
  31.  * started.
  32.  */
  33.  
  34. #include "dm.h"
  35.  
  36. #ifdef XDMCP
  37.  
  38. #include <sys/types.h>
  39.  
  40. static struct protoDisplay    *protoDisplays;
  41.  
  42. #ifdef DEBUG
  43. static
  44. PrintProtoDisplay (pdpy)
  45.     struct protoDisplay    *pdpy;
  46. {
  47.     Debug ("ProtoDisplay 0x%x\n", pdpy);
  48.     Debug ("\taddress: ");
  49.     PrintSockAddr (pdpy->address, pdpy->addrlen);
  50.     Debug ("\tdate %d (%d from now)\n", pdpy->date, time(0) - pdpy->date);
  51.     Debug ("\tdisplay Number %d\n", pdpy->displayNumber);
  52.     Debug ("\tsessionID %d\n", pdpy->sessionID);
  53. }
  54. #endif
  55.  
  56. struct protoDisplay *
  57. FindProtoDisplay (address, addrlen, displayNumber)
  58.     XdmcpNetaddr    address;
  59.     int            addrlen;
  60.     CARD16        displayNumber;
  61. {
  62.     struct protoDisplay    *pdpy;
  63.  
  64.     Debug ("FindProtoDisplay\n");
  65.     for (pdpy = protoDisplays; pdpy; pdpy=pdpy->next)
  66.     {
  67.     if (pdpy->displayNumber == displayNumber &&
  68.         addressEqual (address, addrlen, pdpy->address, pdpy->addrlen))
  69.     {
  70.         return pdpy;
  71.     }
  72.     }
  73.     return (struct protoDisplay *) 0;
  74. }
  75.  
  76. static
  77. TimeoutProtoDisplays (now)
  78.     long    now;
  79. {
  80.     struct protoDisplay    *pdpy, *next;
  81.  
  82.     for (pdpy = protoDisplays; pdpy; pdpy = next)
  83.     {
  84.     next = pdpy->next;
  85.     if (pdpy->date < now - PROTO_TIMEOUT)
  86.         DisposeProtoDisplay (pdpy);
  87.     }
  88. }
  89.  
  90. struct protoDisplay *
  91. NewProtoDisplay (address, addrlen, displayNumber,
  92.          connectionType, connectionAddress, sessionID)
  93.     XdmcpNetaddr    address;
  94.     int            addrlen;
  95.     CARD16        displayNumber;
  96.     CARD16        connectionType;
  97.     ARRAY8Ptr        connectionAddress;
  98.     CARD32        sessionID;
  99. {
  100.     struct protoDisplay    *pdpy;
  101.     long    date;
  102.  
  103.     Debug ("NewProtoDisplay\n");
  104.     time (&date);
  105.     TimeoutProtoDisplays (date);
  106.     pdpy = (struct protoDisplay *) malloc (sizeof *pdpy);
  107.     if (!pdpy)
  108.     return NULL;
  109.     pdpy->address = (XdmcpNetaddr) malloc (addrlen);
  110.     if (!pdpy->address)
  111.     {
  112.     free ((char *) pdpy);
  113.     return NULL;
  114.     }
  115.     pdpy->addrlen = addrlen;
  116.     bcopy (address, pdpy->address, addrlen);
  117.     pdpy->displayNumber = displayNumber;
  118.     pdpy->connectionType = connectionType;
  119.     pdpy->date = date;
  120.     if (!XdmcpCopyARRAY8 (connectionAddress, &pdpy->connectionAddress))
  121.     {
  122.     free ((char *) pdpy->address);
  123.     free ((char *) pdpy);
  124.     return NULL;
  125.     }
  126.     pdpy->sessionID = sessionID;
  127.     pdpy->fileAuthorization = (Xauth *) NULL;
  128.     pdpy->xdmcpAuthorization = (Xauth *) NULL;
  129.     pdpy->next = protoDisplays;
  130.     protoDisplays = pdpy;
  131.     return pdpy;
  132. }
  133.  
  134. DisposeProtoDisplay (pdpy)
  135.     struct protoDisplay    *pdpy;
  136. {
  137.     struct protoDisplay    *p, *prev;
  138.  
  139.     prev = 0;
  140.     for (p = protoDisplays; p; p=p->next)
  141.     {
  142.     if (p == pdpy)
  143.         break;
  144.     prev = p;
  145.     }
  146.     if (!p)
  147.     return;
  148.     if (prev)
  149.     prev->next = pdpy->next;
  150.     else
  151.     protoDisplays = pdpy->next;
  152.     XdmcpDisposeARRAY8 (&pdpy->connectionAddress);
  153.     if (pdpy->fileAuthorization)
  154.     XauDisposeAuth (pdpy->fileAuthorization);
  155.     if (pdpy->xdmcpAuthorization)
  156.     XauDisposeAuth (pdpy->xdmcpAuthorization);
  157.     free ((char *) pdpy->address);
  158.     free ((char *) pdpy);
  159. }
  160.  
  161. #endif /* XDMCP */
  162.