[xlibs-commit] X11/src xclint.h,NONE,1.1.2.1 Makefile.am,1.20,1.20.2.1 OpenDis.c,3.19,3.19.2.1 XlibInt.c,3.42,3.42.2.1 ClDisplay.c,1.7,NONE ConnDis.c,3.29,NONE Xintconn.h,1.2,NONE x11_trans.c,3.3,NONE x11_trans.h,3.1,NONE

Jamey Sharp xlibs-commit@pdx.freedesktop.org
Thu, 13 Nov 2003 11:28:36 -0800


Committed by: jamey

Update of /cvs/xlibs/X11/src
In directory pdx:/tmp/cvs-serv11074/src

Modified Files:
      Tag: XCL
	Makefile.am OpenDis.c XlibInt.c 
Added Files:
      Tag: XCL
	xclint.h 
Removed Files:
      Tag: XCL
	ClDisplay.c ConnDis.c Xintconn.h x11_trans.c x11_trans.h 
Log Message:
Landed XCL patches on the XCL branch. Removed a ton of code, replacing
it with calls into XCB. Tested on a variety of applications, window
managers, and display managers. Another patch to make it run on Solaris
will land soon; I haven't tested it much yet.

Note that this removes libXdmcp, which kdm on Debian - at least -
assumes is linked into Xlib. I worked around this with the obvious
LD_PRELOAD.


--- NEW FILE: xclint.h ---
#include <assert.h>

#define KEYCODE XCBKEYCODE
#define RECTANGLE XCBRECTANGLE
#include <X11/XCB/xcb.h>
#undef KEYCODE
#undef RECTANGLE

typedef struct XCLPrivate {
	XCBConnection *connection;
	char *reply_data;
	int reply_length;
	int reply_consumed;
} XCLPrivate;

#define XCBConnectionOfDisplay(dpy) (dpy->xcl->connection)

Index: Makefile.am
===================================================================
RCS file: /cvs/xlibs/X11/src/Makefile.am,v
retrieving revision 1.20
retrieving revision 1.20.2.1
diff -u -d -r1.20 -r1.20.2.1
--- Makefile.am	31 Oct 2003 23:43:06 -0000	1.20
+++ Makefile.am	13 Nov 2003 19:28:34 -0000	1.20.2.1
@@ -11,12 +11,11 @@
 		 $(X11_CFLAGS) \
 		 $(XPROTO_CFLAGS) \
 		 $(XTHREADS_CFLAGS) \
-		 $(XDMCP_CFLAGS) \
 		 -DX11_DATADIR='"@X11_DATADIR@"'
 
 libX11_la_LDFLAGS = -version-number 6:2:1
 
-libX11_la_LIBADD = $(X11_LIBS) $(XPROTO_LIBS) $(XTHREADS_LIBS) $(XDMCP_LIBS)
+libX11_la_LIBADD = $(X11_LIBS) $(XPROTO_LIBS) $(XTHREADS_LIBS)
 
 XCMS_SRCS= \
 		  AddDIC.c \
@@ -215,8 +214,7 @@
                   lcUniConv/utf8.h \
                   lcUniConv/viscii.h
 
-X11_SRCS=         x11_trans.c \
-                  x11_trans.h \
+X11_SRCS= \
                   AllCells.c \
                   AllPlanes.c \
                   AllowEv.c \
@@ -244,11 +242,9 @@
                   CirWin.c \
                   CirWinDn.c \
                   CirWinUp.c \
-                  ClDisplay.c \
                   Clear.c \
                   ClearArea.c \
                   ConfWind.c \
-                  ConnDis.c \
                   Context.c \
                   ConvSel.c \
                   CopyArea.c \
@@ -476,7 +472,6 @@
                   Key.h \
                   Xatomtype.h \
                   Xintatom.h \
-                  Xintconn.h \
                   XomGeneric.h \
                   Xresinternal.h \
                   XrmI.h \

Index: OpenDis.c
===================================================================
RCS file: /cvs/xlibs/X11/src/OpenDis.c,v
retrieving revision 3.19
retrieving revision 3.19.2.1
diff -u -d -r3.19 -r3.19.2.1
--- OpenDis.c	27 Oct 2003 06:03:00 -0000	3.19
+++ OpenDis.c	13 Nov 2003 19:28:34 -0000	3.19.2.1
@@ -26,15 +26,16 @@
 */
 /* $XFree86: xc/lib/X11/OpenDis.c,v 3.14tsi Exp $ */
 
+#define _GNU_SOURCE /* for asprintf */
+
 #define NEED_REPLIES
 #define NEED_EVENTS
 #include "Xlibint.h"
-#include "x11_trans.h"
+#include "xclint.h"
 #include <X11/Xatom.h>
 #include <X11/Xresource.h>
 #include <X11/extensions/bigreqstr.h>
 #include <stdio.h>
-#include "Xintconn.h"
 
 #ifdef XKB
 #include "XKBlib.h"
@@ -73,10 +74,201 @@
 	0, 0, 0
 };
 
-static void OutOfMemory(Display *dpy, char *setup);
+static XCBAuthInfo xauth;
+
+static void OutOfMemory(Display *dpy);
+void _XFreeDisplayStructure(Display *dpy);
 static Bool _XBigReqHandler(Display *dpy, xReply *rep, char *buf, int len,
 				XPointer data);
 
+void XSetAuthorization(char *name, int namelen, char *data, int datalen)
+{
+	_XLockMutex(_Xglobal_lock);
+	Xfree(xauth.name);
+	Xfree(xauth.data);
+	xauth.name = xauth.data = 0;
+	xauth.namelen = xauth.datalen = 0;
+	if(namelen > 0)
+	{
+		xauth.name = Xmalloc(namelen);
+		memcpy(xauth.name, name, namelen);
+		xauth.namelen = namelen;
+	}
+	if(datalen > 0)
+	{
+		xauth.data = Xmalloc(datalen);
+		memcpy(xauth.data, data, datalen);
+		xauth.datalen = datalen;
+	}
+	_XUnlockMutex(_Xglobal_lock);
+}
+
+static XCBConnection *_XConnectXCB(_Xconst char *display, char **fullnamep, int *screenp, int *fdp)
+{
+	char *host;
+	int n, use_global;
+	XCBAuthInfo auth;
+	XCBConnection *c;
+
+	n = *screenp = 0;
+	*fdp = -1;
+	if(XCBParseDisplay(display, &host, &n, screenp))
+		*fdp = XCBOpen(host, n);
+	asprintf(fullnamep, "%s:%d.%d", host, n, *screenp);
+	free(host);
+	if(*fdp == -1)
+		return 0;
+
+	_XLockMutex(_Xglobal_lock);
+	use_global = xauth.name && xauth.data;
+	if(use_global)
+		auth = xauth;
+	_XUnlockMutex(_Xglobal_lock);
+
+	if(!use_global)
+		XCBGetAuthInfo(*fdp, XCBNextNonce(), &auth);
+	c = XCBConnect(*fdp, &auth);
+	if(!use_global)
+	{
+		free(auth.name);
+		free(auth.data);
+	}
+	return c;
+}
+
+static int _XInitPixmapFormats(Display *dpy)
+{
+	int i;
+	register ScreenFormat *fmtdst;
+	register FORMAT *fmtsrc;
+	XCBConnection *c = XCBConnectionOfDisplay(dpy);
+	dpy->nformats = XCBConnSetupSuccessRepPixmapFormatsLength(c->setup);
+
+	/* Now iterate down setup information... */
+	fmtdst = (ScreenFormat *) Xmalloc(dpy->nformats * sizeof(ScreenFormat));
+	if(!fmtdst)
+		return 0;
+	dpy->pixmap_format = fmtdst;
+	fmtsrc = XCBConnSetupSuccessRepPixmapFormats(c->setup);
+
+	/* First decode the Z axis Screen format information. */
+	for(i = dpy->nformats; i; --i, ++fmtsrc, ++fmtdst)
+	{
+		fmtdst->depth = fmtsrc->depth;
+		fmtdst->bits_per_pixel = fmtsrc->bits_per_pixel;
+		fmtdst->scanline_pad = fmtsrc->scanline_pad;
+		fmtdst->ext_data = NULL;
+	}
+	return 1;
+}
+
+static Visual *_XInitVisuals(int len, register VISUALTYPE *vpsrc)
+{
+	Visual *vpdst;
+	Visual *dst;
+
+	dst = vpdst = (Visual *) Xmalloc(len * sizeof(Visual));
+	if(!vpdst)
+		return 0;
+
+	for(; len; --len, ++vpsrc, ++vpdst)
+	{
+		vpdst->visualid		= vpsrc->visual_id.id;
+		vpdst->class		= vpsrc->class;
+		vpdst->bits_per_rgb	= vpsrc->bits_per_rgb_value;
+		vpdst->map_entries	= vpsrc->colormap_entries;
+		vpdst->red_mask		= vpsrc->red_mask;
+		vpdst->green_mask	= vpsrc->green_mask;
+		vpdst->blue_mask	= vpsrc->blue_mask;
+		vpdst->ext_data		= NULL;
+	}
+	return dst;
+}
+
+static Depth *_XInitDepths(DEPTHIter dpsrc)
+{
+	register Depth *dpdst;
+	Depth *dst;
+
+	dst = dpdst = (Depth *) Xmalloc(dpsrc.rem * sizeof(Depth));
+	if(!dpdst)
+		return 0;
+
+	/* for all depths on this screen. */
+	for(; dpsrc.rem; DEPTHNext(&dpsrc), ++dpdst)
+	{
+		dpdst->depth		= dpsrc.data->depth;
+		dpdst->nvisuals		= DEPTHVisualsLength(dpsrc.data);
+
+		dpdst->visuals = _XInitVisuals(dpdst->nvisuals, DEPTHVisuals(dpsrc.data));
+		if(!dpdst->visuals)
+			return 0;
+	}
+	return dst;
+}
+
+static int _XInitScreens(Display *dpy, SCREENIter spsrc)
+{
+	register Screen *spdst;
+	XGCValues values;
+
+	dpy->nscreens = spsrc.rem;
+
+	spdst = (Screen *) Xmalloc(spsrc.rem * sizeof(Screen));
+	if(!spdst)
+		return 0;
+	dpy->screens = spdst;
+
+	/* Now go deal with each screen structure. */
+	for(; spsrc.rem; SCREENNext(&spsrc), ++spdst)
+	{
+		spdst->display		= dpy;
+		spdst->root 		= spsrc.data->root.xid;
+		spdst->cmap 		= spsrc.data->default_colormap.xid;
+		spdst->white_pixel	= spsrc.data->white_pixel;
+		values.background	= spdst->white_pixel;
+		spdst->black_pixel	= spsrc.data->black_pixel;
+		values.foreground	= spdst->black_pixel;
+		spdst->root_input_mask	= spsrc.data->current_input_masks;
+		spdst->width		= spsrc.data->width_in_pixels;
+		spdst->height		= spsrc.data->height_in_pixels;
+		spdst->mwidth		= spsrc.data->width_in_millimeters;
+		spdst->mheight		= spsrc.data->height_in_millimeters;
+		spdst->min_maps		= spsrc.data->min_installed_maps;
+		spdst->max_maps		= spsrc.data->max_installed_maps;
+		spdst->backing_store	= spsrc.data->backing_stores;
+		spdst->save_unders	= spsrc.data->save_unders;
+		spdst->root_depth	= spsrc.data->root_depth;
+		spdst->ndepths		= spsrc.data->allowed_depths_len;
+		spdst->ext_data		= NULL;
+
+		spdst->depths = _XInitDepths(SCREENAllowedDepths(spsrc.data));
+		if(!spdst->depths)
+			return 0;
+
+		spdst->root_visual = _XVIDtoVisual(dpy, spsrc.data->root_visual.id);
+
+		/* Set up other stuff clients are always going to use. */
+		spdst->default_gc = XCreateGC(dpy, spdst->root, GCForeground|GCBackground, &values);
+		if(!spdst->default_gc)
+			return 0;
+	}
+	return 1;
+}
+
+static int _XAsyncReplyHandler(Display *dpy, XCBGenericRep *buf)
+{
+	_XAsyncHandler *async, *next;
+	_XSetLastRequestRead(dpy, (xGenericReply *) buf);
+	for(async = dpy->async_handlers; async; async = next)
+	{
+		next = async->next;
+		if(async->handler(dpy, (xReply *) buf, (char *) buf, sizeof(xReply) + (buf->length << 2), async->data))
+			return 1;
+	}
+	return 0;
+}
+
 /* 
  * Connects to a server, creates a Display object and returns a pointer to
  * the newly created Display back to the caller.
@@ -91,51 +283,11 @@
 {
 	register Display *dpy;		/* New Display object being created. */
 	register int i;
-	int j, k;			/* random iterator indexes */
-	char *display_name;		/* pointer to display name */
-	int endian;			/* to determine which endian. */
-	xConnClientPrefix client;	/* client information */
-	xConnSetupPrefix prefix;	/* prefix information */
-	int vendorlen;			/* length of vendor string */
-	char *setup = NULL;		/* memory allocated at startup */
-	char *fullname = NULL;		/* expanded name of display */
-	int idisplay;			/* display number */
+	XCBConnection *c;
 	int iscreen;			/* screen number */
-	int prefixread = 0;             /* setup prefix already read? */
-	union {
-		xConnSetup *setup;
-		char *failure;
-		char *vendor;
-		xPixmapFormat *sf;
-		xWindowRoot *rp;
-		xDepth *dp;
-		xVisualType *vp;
-	} u;				/* proto data returned from server */
-	long setuplength;	/* number of bytes in setup message */
-	long usedbytes = 0;     /* number of bytes we have processed */
-	char *conn_auth_name, *conn_auth_data;
-	int conn_auth_namelen, conn_auth_datalen;
-	unsigned long mask;
        long int conn_buf_size;
        char *xlib_buffer_size;
 
-	bzero((char *) &client, sizeof(client));
-	bzero((char *) &prefix, sizeof(prefix));
-
-	/*
-	 * If the display specifier string supplied as an argument to this 
-	 * routine is NULL or a pointer to NULL, read the DISPLAY variable.
-	 */
-	if (display == NULL || *display == '\0') {
-		if ((display_name = getenv("DISPLAY")) == NULL) {
-			/* Oops! No DISPLAY environment variable - error. */
-			return(NULL);
-		}
-	}
-	else {
-		/* Display is non-NULL, copy the pointer */
-		display_name = (char *)display;
-	}
 /*
  * Set the default error handlers.  This allows the global variables to
  * default to NULL for use with shared libraries.
@@ -156,22 +308,25 @@
  * will set fullname to point to the expanded name.
  */
 
-	if ((dpy->trans_conn = _X11TransConnectDisplay (
-					 display_name, &fullname, &idisplay,
-					 &iscreen, &conn_auth_name,
-					 &conn_auth_namelen, &conn_auth_data,
-					 &conn_auth_datalen)) == NULL) {
-		Xfree ((char *) dpy);
+	if (!(dpy->xcl = Xcalloc(1, sizeof(XCLPrivate)))) {
+		OutOfMemory(dpy);
+		return(NULL);
+	}
+	if ((c = _XConnectXCB (
+					 display, &dpy->display_name,
+					 &iscreen,
+					 &dpy->fd)) == NULL) {
+		OutOfMemory(dpy);
 		return(NULL);
 	}
 
-	dpy->fd = _X11TransGetConnectionNumber (dpy->trans_conn);
+	dpy->xcl->connection = c;
+	XCBSetUnexpectedReplyHandler(c, (XCBUnexpectedReplyFunc) _XAsyncReplyHandler, dpy);
 
 	/* Initialize as much of the display structure as we can.
 	 * Initialize pointers to NULL so that XFreeDisplayStructure will
 	 * work if we run out of memory before we finish initializing.
 	 */
-	dpy->display_name	= fullname;
 	dpy->keysyms		= (KeySym *) NULL;
 	dpy->modifiermap	= NULL;
 	dpy->lock_meaning	= NoSymbol;
@@ -241,12 +396,12 @@
 
 	/* Initialize the display lock */
 	if (InitDisplayLock(dpy) != 0) {
-	        OutOfMemory (dpy, setup);
+		OutOfMemory (dpy);
 		return(NULL);
 	}
 
 	if (!_XPollfdCacheInit(dpy)) {
-	        OutOfMemory (dpy, setup);
+		OutOfMemory (dpy);
 		return(NULL);
 	}	
 
@@ -265,7 +420,7 @@
         conn_buf_size = XLIBMINBUFSIZE;
 
     if ((dpy->bufptr = dpy->buffer = Xcalloc(1, conn_buf_size)) == NULL) {
-         OutOfMemory (dpy, setup);
+         OutOfMemory (dpy);
          return(NULL);
     }
     dpy->bufmax = dpy->buffer + conn_buf_size;
@@ -278,329 +433,56 @@
 	if ((dpy->free_funcs = (_XFreeFuncRec *)Xcalloc(1,
 							sizeof(_XFreeFuncRec)))
 	    == NULL) {
-	    OutOfMemory (dpy, setup);
-	    return(NULL);
-	}
-
-/*
- * The xConnClientPrefix describes the initial connection setup information
- * and is followed by the authorization information.  Sites that are interested
- * in security are strongly encouraged to use an authentication and 
- * authorization system such as Kerberos.
- */
-	endian = 1;
-	if (*(char *) &endian)
-	    client.byteOrder = '\154'; /* 'l' */
-	else
-	    client.byteOrder = '\102'; /* 'B' */
-	client.majorVersion = X_PROTOCOL;
-	client.minorVersion = X_PROTOCOL_REVISION;
-	client.nbytesAuthProto = conn_auth_namelen;
-	client.nbytesAuthString = conn_auth_datalen;
-	prefixread = _XSendClientPrefix(dpy, &client,
-					conn_auth_name, conn_auth_data,
-					&prefix);
-	if (prefixread < 0)
-	{
-	    _XDisconnectDisplay (dpy->trans_conn);
-	    Xfree ((char *)dpy);
-	    return(NULL);
-	}
-	if (conn_auth_name) Xfree(conn_auth_name);
-	if (conn_auth_data) Xfree(conn_auth_data);
-/*
- * Now see if connection was accepted...
- */
-	/* these internal functions expect the display to be locked */
-	LockDisplay(dpy);
-
-	if (prefixread == 0)
-	    _XRead (dpy, (char *)&prefix,(long)SIZEOF(xConnSetupPrefix));
-
-	/* an Authenticate reply we weren't expecting? */
-	if (prefix.success != xTrue && prefix.success != xFalse) {
-	    fprintf (stderr,
-      "Xlib: unexpected connection setup reply from server, type %d.\r\n",
-		     prefix.success);
-	    _XDisconnectDisplay (dpy->trans_conn);
-	    Xfree ((char *)dpy);
-	    return(NULL);
-	}
-
-	if (prefix.majorVersion != X_PROTOCOL) {
-	    /* XXX - printing messages marks a bad programming interface */
-	    fprintf (stderr,
-     "Xlib: client uses different protocol version (%d) than server (%d)!\r\n",
-		     X_PROTOCOL, prefix.majorVersion);
-	    _XDisconnectDisplay (dpy->trans_conn);
-	    Xfree ((char *)dpy);
+	    OutOfMemory (dpy);
 	    return(NULL);
 	}
 
-	setuplength = prefix.length << 2;
-	if ( (u.setup = (xConnSetup *)
-	      (setup =  Xmalloc ((unsigned) setuplength))) == NULL) {
-		_XDisconnectDisplay (dpy->trans_conn);
-		Xfree ((char *)dpy);
-		return(NULL);
-	}
-	_XRead (dpy, (char *)u.setup, setuplength);
-
-/*
- * If the connection was not accepted by the server due to problems,
- * give error message to the user....
- */
-	if (prefix.success != xTrue) {
-		/* XXX - printing messages marks a bad programming interface */
-		fprintf (stderr, 
-		      "Xlib: connection to \"%s\" refused by server\r\nXlib: ",
-			 fullname);
-
-		if (prefix.lengthReason > setuplength) {
-		    fprintf (stderr, "Xlib: Broken initial reply: length of reason > length of packet\r\n");
-		}else{
-		    (void) fwrite (u.failure, (Size_t)sizeof(char),
-			       (Size_t)prefix.lengthReason, stderr);
-		    (void) fwrite ("\r\n", sizeof(char), 2, stderr);
-		}
-
-		OutOfMemory(dpy, setup);
-		return (NULL);
-	}
-
-/*
- * Check if the reply was long enough to get any information out of it.
- */
-	usedbytes = sz_xConnSetup;
-	if (setuplength < usedbytes ) {
-	    fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-	    OutOfMemory(dpy, setup);
-	    return (NULL);
-	}
 
 /*
  * We succeeded at authorization, so let us move the data into
  * the display structure.
  */
-	dpy->proto_major_version= prefix.majorVersion;
-	dpy->proto_minor_version= prefix.minorVersion;
-	dpy->release 		= u.setup->release;
-	dpy->resource_base	= u.setup->ridBase;
-	dpy->resource_mask	= u.setup->ridMask;
-	dpy->min_keycode	= u.setup->minKeyCode;
-	dpy->max_keycode	= u.setup->maxKeyCode;
-	dpy->motion_buffer	= u.setup->motionBufferSize;
-	dpy->nformats		= u.setup->numFormats;
-	dpy->nscreens		= u.setup->numRoots;
-	dpy->byte_order		= u.setup->imageByteOrder;
-	dpy->bitmap_unit	= u.setup->bitmapScanlineUnit;
-	dpy->bitmap_pad		= u.setup->bitmapScanlinePad;
-	dpy->bitmap_bit_order   = u.setup->bitmapBitOrder;
-	dpy->max_request_size	= u.setup->maxRequestSize;
-	mask = dpy->resource_mask;
+	dpy->proto_major_version= c->setup->protocol_major_version;
+	dpy->proto_minor_version= c->setup->protocol_minor_version;
+	dpy->release 		= c->setup->release_number;
+	dpy->resource_base	= c->setup->resource_id_base;
+	dpy->resource_mask	= c->setup->resource_id_mask;
+	dpy->min_keycode	= c->setup->min_keycode.id;
+	dpy->max_keycode	= c->setup->max_keycode.id;
+	dpy->motion_buffer	= c->setup->motion_buffer_size;
+	dpy->byte_order		= c->setup->image_byte_order;
+	dpy->bitmap_unit	= c->setup->bitmap_format_scanline_unit;
+	dpy->bitmap_pad		= c->setup->bitmap_format_scanline_pad;
+	dpy->bitmap_bit_order   = c->setup->bitmap_format_bit_order;
+	dpy->max_request_size	= c->setup->maximum_request_length;
 	dpy->resource_shift	= 0;
-	if (!mask)
+
 	{
-	    fprintf (stderr, "Xlib: connection to \"%s\" invalid setup\n",
-		     fullname);
-	    OutOfMemory(dpy, setup);
-	    return (NULL);
-	}
-    
-	while (!(mask & 1)) {
-	    dpy->resource_shift++;
-	    mask = mask >> 1;
+	    unsigned long mask;
+	    for (mask = dpy->resource_mask; !(mask & 1); mask >>= 1)
+		++dpy->resource_shift;
 	}
 	dpy->resource_max = (dpy->resource_mask >> dpy->resource_shift) - 5;
-/*
- * now extract the vendor string...  String must be null terminated,
- * padded to multiple of 4 bytes.
- */
-	/* Check for a sane vendor string length */
-	if (u.setup->nbytesVendor > 256) {
-	    OutOfMemory(dpy, setup);
-	    return (NULL);
-	}
-
-	dpy->vendor = (char *) Xmalloc((unsigned) (u.setup->nbytesVendor + 1));
-	if (dpy->vendor == NULL) {
-	    OutOfMemory(dpy, setup);
-	    return (NULL);
-	}
-	vendorlen = u.setup->nbytesVendor;
-
-/*
- * validate setup length
- */
-	usedbytes += (vendorlen + 3) & ~3;
-	if (setuplength < usedbytes) {
-	    fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-	    OutOfMemory(dpy, setup);
-	    return (NULL);
-	}
-
- 	u.setup = (xConnSetup *) (((char *) u.setup) + sz_xConnSetup);
-  	(void) strncpy(dpy->vendor, u.vendor, vendorlen);
-	dpy->vendor[vendorlen] = '\0';
- 	vendorlen = (vendorlen + 3) & ~3;	/* round up */
-
-
-	memmove (setup, u.vendor + vendorlen,
-		 (int) setuplength - sz_xConnSetup - vendorlen);
- 	u.vendor = setup;
-/*
- * Now iterate down setup information.....
- */
-	dpy->pixmap_format = 
-	    (ScreenFormat *)Xmalloc(
-		(unsigned) (dpy->nformats *sizeof(ScreenFormat)));
-	if (dpy->pixmap_format == NULL) {
-	        OutOfMemory (dpy, setup);
-		return(NULL);
-	}
-/*
- * First decode the Z axis Screen format information.
- */
-	usedbytes += dpy->nformats * sz_xPixmapFormat;
-
-	if (setuplength < usedbytes) {
-	    fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-	    OutOfMemory (dpy, setup);
-	    return(NULL);
-	}
-
-	for (i = 0; i < dpy->nformats; i++) {
-	    register ScreenFormat *fmt = &dpy->pixmap_format[i];
-	    fmt->depth = u.sf->depth;
-	    fmt->bits_per_pixel = u.sf->bitsPerPixel;
-	    fmt->scanline_pad = u.sf->scanLinePad;
-	    fmt->ext_data = NULL;
-	    u.sf = (xPixmapFormat *) (((char *) u.sf) + sz_xPixmapFormat);
-	}
-
-/*
- * next the Screen structures.
- */
-	dpy->screens = 
-	    (Screen *)Xmalloc((unsigned) dpy->nscreens*sizeof(Screen));
-	if (dpy->screens == NULL) {
-	        OutOfMemory (dpy, setup);
-		return(NULL);
-	}
 
-/*
- * Now go deal with each screen structure.
- */
-	for (i = 0; i < dpy->nscreens; i++) {
-	    register Screen *sp = &dpy->screens[i];
-	    VisualID root_visualID;
-
-	    usedbytes += sz_xWindowRoot;
-	    if (setuplength < usedbytes) {
-		fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-		OutOfMemory (dpy, setup);
-		return(NULL);
-	    }
-
-	    root_visualID = u.rp->rootVisualID;	    
-	    sp->display	    = dpy;
-	    sp->root 	    = u.rp->windowId;
-	    sp->cmap 	    = u.rp->defaultColormap;
-	    sp->white_pixel = u.rp->whitePixel;
-	    sp->black_pixel = u.rp->blackPixel;
-	    sp->root_input_mask = u.rp->currentInputMask;
-	    sp->width	    = u.rp->pixWidth;
-	    sp->height	    = u.rp->pixHeight;
-	    sp->mwidth	    = u.rp->mmWidth;
-	    sp->mheight	    = u.rp->mmHeight;
-	    sp->min_maps    = u.rp->minInstalledMaps;
-	    sp->max_maps    = u.rp->maxInstalledMaps;
-	    sp->backing_store= u.rp->backingStore;
-	    sp->save_unders = u.rp->saveUnders;
-	    sp->root_depth  = u.rp->rootDepth;
-	    sp->ndepths	    = u.rp->nDepths;
-	    sp->ext_data   = NULL;
-	    u.rp = (xWindowRoot *) (((char *) u.rp) + sz_xWindowRoot);
-/*
- * lets set up the depth structures.
- */
-	    sp->depths = (Depth *)Xmalloc(
-			(unsigned)sp->ndepths*sizeof(Depth));
-	    if (sp->depths == NULL) {
-		OutOfMemory (dpy, setup);
-		return(NULL);
-	    }
-	    /*
-	     * for all depths on this screen.
-	     */
-	    for (j = 0; j < sp->ndepths; j++) {
-		Depth *dp = &sp->depths[j];
-
-		usedbytes += sz_xDepth;
-		if (setuplength < usedbytes) {
-		    fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-		    OutOfMemory (dpy, setup);
-		    return(NULL);
-		}
-		
-		dp->depth = u.dp->depth;
-		dp->nvisuals = u.dp->nVisuals;
-		u.dp = (xDepth *) (((char *) u.dp) + sz_xDepth);
-		if (dp->nvisuals > 0) {
-		    dp->visuals = 
-		      (Visual *)Xmalloc((unsigned)dp->nvisuals*sizeof(Visual));
-		    if (dp->visuals == NULL) {
-			OutOfMemory (dpy, setup);
-			return(NULL);
-		    }
-		    for (k = 0; k < dp->nvisuals; k++) {
-			register Visual *vp = &dp->visuals[k];
-
-			usedbytes += sz_xVisualType;
-			if (setuplength < usedbytes) {
-			    fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength);
-			    OutOfMemory (dpy, setup);
-			    return(NULL);
-			}
-			
-			vp->visualid	= u.vp->visualID;
-			vp->class	= u.vp->class;
-			vp->bits_per_rgb= u.vp->bitsPerRGB;
-			vp->map_entries	= u.vp->colormapEntries;
-			vp->red_mask	= u.vp->redMask;
-			vp->green_mask	= u.vp->greenMask;
-			vp->blue_mask	= u.vp->blueMask;
-			vp->ext_data	= NULL;
-			u.vp = (xVisualType *) (((char *) u.vp) +
-						sz_xVisualType);
-		    }
-		} else {
-		    dp->visuals = (Visual *) NULL;
-		}
-	    }
-	    sp->root_visual = _XVIDtoVisual(dpy, root_visualID);
-	}
+	dpy->vendor = Xmalloc(XCBConnSetupSuccessRepVendorLength(c->setup) + 1);
+	memcpy(dpy->vendor, XCBConnSetupSuccessRepVendor(c->setup), XCBConnSetupSuccessRepVendorLength(c->setup));
+	dpy->vendor[XCBConnSetupSuccessRepVendorLength(c->setup)] = '\0';
 
-	if(usedbytes != setuplength){
-	    /* Sanity check, shouldn't happen. */
-	    fprintf(stderr, "Xlib: Did not parse entire setup message: "
-	                    "parsed: %ld, message: %ld\n",
-		    usedbytes, setuplength);
-	    OutOfMemory(dpy, setup);
-	    return(NULL);
+	if(!_XInitPixmapFormats(dpy) || !_XInitScreens(dpy, XCBConnSetupSuccessRepRoots(c->setup)))
+	{
+	    OutOfMemory(dpy);
+	    return NULL;
 	}
 
 /*
  * Now start talking to the server to setup all other information...
  */
 
-	Xfree (setup);	/* all finished with setup information */
-
 /*
  * Make sure default screen is legal.
  */
 	if (iscreen >= dpy->nscreens) {
-	    OutOfMemory(dpy, (char *) NULL);
+	    OutOfMemory(dpy);
 	    return(NULL);
 	}
 
@@ -620,7 +502,7 @@
 	    if ((sp->default_gc = XCreateGC (dpy, sp->root,
 					     GCForeground|GCBackground,
 					     &values)) == NULL) {
-		OutOfMemory(dpy, (char *) NULL);
+		OutOfMemory(dpy);
 		return (NULL);
 	    }
 	}
@@ -851,17 +733,56 @@
 	if (dpy->filedes)
 	    Xfree (dpy->filedes);
 
+	Xfree (dpy->xcl->reply_data);
+	Xfree (dpy->xcl);
+
 	Xfree ((char *)dpy);
 }
 
+/* 
+ * XCloseDisplay - XSync the connection to the X Server, close the connection,
+ * and free all associated storage.  Extension close procs should only free
+ * memory and must be careful about the types of requests they generate.
+ */
+
+int
+XCloseDisplay (
+	register Display *dpy)
+{
+	register _XExtension *ext;
+	register int i;
+
+	if (!(dpy->flags & XlibDisplayClosing))
+	{
+	    dpy->flags |= XlibDisplayClosing;
+	    for (i = 0; i < dpy->nscreens; i++) {
+		    register Screen *sp = &dpy->screens[i];
+		    XFreeGC (dpy, sp->default_gc);
+	    }
+	    if (dpy->cursor_font != None) {
+		XUnloadFont (dpy, dpy->cursor_font);
+	    }
+	    XSync(dpy, 1);  /* throw away pending events, catch errors */
+	    /* call out to any extensions interested */
+	    for (ext = dpy->ext_procs; ext; ext = ext->next) {
+		if (ext->close_display)
+		    (*ext->close_display)(dpy, &ext->codes);
+	    }
+	    /* if the closes generated more protocol, sync them up */
+	    if (dpy->request != dpy->last_request_read)
+		XSync(dpy, 1);
+	}
+	XCBDisconnect(XCBConnectionOfDisplay(dpy));
+	_XFreeDisplayStructure (dpy);
+	return 0;
+}
+
 /* OutOfMemory is called if malloc fails.  XOpenDisplay returns NULL
    after this returns. */
 
-static void OutOfMemory (dpy, setup)
+static void OutOfMemory (dpy)
     Display *dpy;
-    char *setup;
 {
-    _XDisconnectDisplay (dpy->trans_conn);
+    XCBDisconnect(XCBConnectionOfDisplay(dpy));
     _XFreeDisplayStructure (dpy);
-    if (setup) Xfree (setup);
 }

Index: XlibInt.c
===================================================================
RCS file: /cvs/xlibs/X11/src/XlibInt.c,v
retrieving revision 3.42
retrieving revision 3.42.2.1
diff -u -d -r3.42 -r3.42.2.1
--- XlibInt.c	1 Nov 2003 00:33:15 -0000	3.42
+++ XlibInt.c	13 Nov 2003 19:28:34 -0000	3.42.2.1
@@ -39,9 +39,9 @@
 #include "config.h"
 #endif
 #include "Xlibint.h"
-#include "x11_trans.h"
+#include "xclint.h"
+#include <X11/XCB/xcbint.h>
 #include <X11/Xpoll.h>
-#include <X11/extensions/xcmiscstr.h>
 #include <stdio.h>
 
 #ifdef XTHREADS
[...1676 lines suppressed...]
-#ifdef _XNEEDBCOPYFUNC
-void _Xbcopy(b1, b2, length)
-    register char *b1, *b2;
-    register length;
-{
-    if (b1 < b2) {
-	b2 += length;
-	b1 += length;
-	while (length--)
-	    *--b2 = *--b1;
-    } else {
-	while (length--)
-	    *b2++ = *b1++;
-    }
-}
-#endif
-
 #ifdef DataRoutineIsProcedure
 void Data(
 	Display *dpy,

--- ClDisplay.c DELETED ---

--- ConnDis.c DELETED ---

--- Xintconn.h DELETED ---

--- x11_trans.c DELETED ---

--- x11_trans.h DELETED ---