Home | History | Annotate | Line # | Download | only in src
      1 /*
      2 
      3 Copyright 1986, 1998  The Open Group
      4 
      5 All rights reserved.
      6 
      7 Permission is hereby granted, free of charge, to any person obtaining a
      8 copy of this software and associated documentation files (the
      9 "Software"), to deal in the Software without restriction, including
     10 without limitation the rights to use, copy, modify, merge, publish,
     11 distribute, and/or sell copies of the Software, and to permit persons
     12 to whom the Software is furnished to do so, provided that the above
     13 copyright notice(s) and this permission notice appear in all copies of
     14 the Software and that both the above copyright notice(s) and this
     15 permission notice appear in supporting documentation.
     16 
     17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
     20 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     21 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
     22 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
     23 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
     24 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     25 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     26 
     27 Except as contained in this notice, the name of a copyright holder
     28 shall not be used in advertising or otherwise to promote the sale, use
     29 or other dealings in this Software without prior written authorization
     30 of the copyright holder.
     31 
     32 X Window System is a trademark of The Open Group.
     33 
     34 */
     35 
     36 /*
     37  * Copyright (c) 2004, Oracle and/or its affiliates.
     38  *
     39  * Permission is hereby granted, free of charge, to any person obtaining a
     40  * copy of this software and associated documentation files (the "Software"),
     41  * to deal in the Software without restriction, including without limitation
     42  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     43  * and/or sell copies of the Software, and to permit persons to whom the
     44  * Software is furnished to do so, subject to the following conditions:
     45  *
     46  * The above copyright notice and this permission notice (including the next
     47  * paragraph) shall be included in all copies or substantial portions of the
     48  * Software.
     49  *
     50  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     51  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     52  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     53  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     54  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     55  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     56  * DEALINGS IN THE SOFTWARE.
     57  */
     58 
     59 
     60 /* this might be rightly regarded an os dependent file */
     61 
     62 #ifdef HAVE_CONFIG_H
     63 #include <config.h>
     64 #endif
     65 #include "Xlibint.h"
     66 
     67 static inline int
     68 changehost (Display *dpy, XHostAddress *host, BYTE mode)
     69 {
     70     xChangeHostsReq *req;
     71     int length;
     72     XServerInterpretedAddress *siAddr;
     73     int addrlen;
     74 
     75     siAddr = host->family == FamilyServerInterpreted ?
     76 	(XServerInterpretedAddress *)host->address : NULL;
     77     addrlen = siAddr ?
     78 	siAddr->typelength + siAddr->valuelength + 1 : host->length;
     79 
     80     length = (addrlen + 3) & ~0x3;	/* round up */
     81 
     82     LockDisplay(dpy);
     83     GetReqExtra (ChangeHosts, length, req);
     84     if (!req) {
     85 	UnlockDisplay(dpy);
     86 	return 0;
     87     }
     88     req->mode = mode;
     89     req->hostFamily = host->family;
     90     req->hostLength = addrlen;
     91     if (siAddr) {
     92 	char *dest = (char *) NEXTPTR(req,xChangeHostsReq);
     93 	memcpy(dest, siAddr->type, (size_t) siAddr->typelength);
     94 	dest[siAddr->typelength] = '\0';
     95 	memcpy(dest + siAddr->typelength + 1,siAddr->value,(size_t) siAddr->valuelength);
     96     } else {
     97 	memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, (size_t) addrlen);
     98     }
     99     UnlockDisplay(dpy);
    100     SyncHandle();
    101     return 1;
    102 }
    103 
    104 int
    105 XAddHost (
    106     register Display *dpy,
    107     XHostAddress *host)
    108 {
    109     return changehost(dpy, host, HostInsert);
    110 }
    111 
    112 int
    113 XRemoveHost (
    114     register Display *dpy,
    115     XHostAddress *host)
    116 {
    117     return changehost(dpy, host, HostDelete);
    118 }
    119 
    120 int
    121 XAddHosts (
    122     register Display *dpy,
    123     XHostAddress *hosts,
    124     int n)
    125 {
    126     register int i;
    127     for (i = 0; i < n; i++) {
    128 	(void) XAddHost(dpy, &hosts[i]);
    129       }
    130     return 1;
    131 }
    132 
    133 int
    134 XRemoveHosts (
    135     register Display *dpy,
    136     XHostAddress *hosts,
    137     int n)
    138 {
    139     register int i;
    140     for (i = 0; i < n; i++) {
    141 	(void) XRemoveHost(dpy, &hosts[i]);
    142       }
    143     return 1;
    144 }
    145