#ifndef _X_H_f10b1303_ #define _X_H_f10b1303_ /* This file is in the public domain. */ /* * X stuff. This stuff is used by the client and server code to handle * X forwarding. */ /* * A CFXREQ is an X forwarding request on the client side; SFXREQ is * the same thing on the server side. These are opaque handles to * everyone outside of x.c - they are created and returned by * X_forward_req and X_fwdreq_start and are passed to other functions. */ typedef struct cfxreq CFXREQ; typedef struct sfxreq SFXREQ; /* * Client-side stuff. * * X_forward_req creates and returns a CFXREQ suitable for forwarding * local X connections to a remote server. It returns a nil pointer * if this cannot be done (eg, if there is no $DISPLAY). * * X_forward_done destroys a CFXREQ, cleaning up any nascent forwarded * connections based on it. * * X_fwdreq_gen generates the X-specific part of an X forwarding * request. (This is just the screen number, but nobody outside x.c * knows enough about X to know that X even *has* screen numbers.) * The first arg points to the space to generate into; the returned * value points just beyond the generated data. * * X_start_connect is called to initiate the connection to the real * server when a forwarded X connection is received. The second arg * points to the first six bytes of data on the connection, the * beginning of the header. The third and fourth args are callbacks, * called when the connection succeeds or fails, respectively; the * fifth arg is passed to the callbacks. (The success callback's * first arg is a connected file descriptor.) */ extern CFXREQ *X_forward_req(void); extern void X_forward_done(CFXREQ *); extern void *X_fwdreq_gen(void *, CFXREQ *); extern void X_start_connect(CFXREQ *, const unsigned char *, void (*)(int, void *), void (*)(void *), void *); /* * Server-side stuff. * * X_fwdreq_start sets up the server-side stuff for a forwarded X * connection. Its args are: * data * datalen * These describe the packet beginning with the X-specific * data (the screen number - this is the converse of * X_fwdreq_gen). * restp * restlenp * These receive the part of the packet following the * X-specific data. * fail * A callback called in case of parsing failure. This * must be something suitable for passing as the third arg * to parse_data(). It is expected to never return. * gotfd * A callback called when an incoming X connection is * received for this forwarding. Args: * fd File descriptor on the new connection * chdr Pointer to the first six bytes of * protocol data received. * arg See below. * arg * Passed as the third arg to the gotfd callback. * flags * Zero or more of the XFF_* flags. * This does not actually set up the local X listener; it just * prepares to do so. * * X_fwdreq_abort aborts the X forwarding request, tearing down any * nascent forwarded connections associated with it. * * X_fwdreq_go sets up the local X listener. It is separated from * X_fwdreq_start because there is some non-X-related checking that * needs to happen in between them. * * X_fwdreq_env is used to set whatever is appropriate in the local * environment for the forwarded X connection. (In our * implementation, this means just setting $DISPLAY.) The second arg * is a callback, called for eacn environment variable to be set; its * args are the variable name and the value it is to be set to. */ extern SFXREQ *X_fwdreq_start( const void *, int, const void **, int *, void (*)(const void *, const char *, ...), void (*)(int, unsigned char *, void *), void *, unsigned int ); extern void X_fwdreq_abort(SFXREQ *); extern void X_fwdreq_go(SFXREQ *); extern void X_fwdreq_env(SFXREQ *, void (*)(const char *, const char *)); /* * Flags for the flags argument to X_fwdreq_start(). * * XFF_TCPONLY * This forwarding should be established for TCP only. This is * necessary to support the stock X forwarding semantics, which * have the assumption that the connection is TCP wired fairly * deeply into them. * * XFF_SINGLE * This forwarding should be established for only a single * connection; after one connection, it should automatically be * torn down. */ #define XFF_TCPONLY 0x00000001 #define XFF_SINGLE 0x00000002 /* * General utility stuff. * * X_put_2(char bo, void *dp, unsigned short int v) puts v, as a 2-byte * integer, to the two bytes pointed to by dp, in byte order as * determined by bo (which must be ASCII 'B' or 'l', per the X * protocol spec). * * X_auth_len takes a pointer to the 12-byte header at the beginning of * an X data stream and returns the number of bytes following it that * constitute authentication information. * * X_auth_match takes a pointer to the header at the beginning of an X * data stream (12+X_auth_len() bytes), and the expected protocol and * cookie (each as a pointer-and-length), and returns true if the data * matches or false if it does not. * * X_pad_roundup takes a byte count and returns it rounded up to a * multiple of 4. X uses this kind of padding in many places. */ extern void X_put_2(char, void *, unsigned short int); extern int X_auth_len(const unsigned char *); extern int X_auth_match(const unsigned char *, const void *, int, const void *, int); extern unsigned int X_pad_roundup(unsigned int); #endif