osdep.h revision 706f2543
1/*********************************************************** 2 3Copyright 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25 26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 27 28 All Rights Reserved 29 30Permission to use, copy, modify, and distribute this software and its 31documentation for any purpose and without fee is hereby granted, 32provided that the above copyright notice appear in all copies and that 33both that copyright notice and this permission notice appear in 34supporting documentation, and that the name of Digital not be 35used in advertising or publicity pertaining to distribution of the 36software without specific, written prior permission. 37 38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 44SOFTWARE. 45 46******************************************************************/ 47 48#ifdef HAVE_DIX_CONFIG_H 49#include <dix-config.h> 50#endif 51 52#ifndef _OSDEP_H_ 53#define _OSDEP_H_ 1 54 55#define BOTIMEOUT 200 /* in milliseconds */ 56#define BUFSIZE 4096 57#define BUFWATERMARK 8192 58 59#if defined(XDMCP) || defined(HASXDMAUTH) 60#include <X11/Xdmcp.h> 61#endif 62 63#ifdef _POSIX_SOURCE 64#include <limits.h> 65#else 66#define _POSIX_SOURCE 67#include <limits.h> 68#undef _POSIX_SOURCE 69#endif 70 71#ifndef OPEN_MAX 72#ifdef SVR4 73#define OPEN_MAX 256 74#else 75#include <sys/param.h> 76#ifndef OPEN_MAX 77#if defined(NOFILE) && !defined(NOFILES_MAX) 78#define OPEN_MAX NOFILE 79#else 80#if !defined(WIN32) 81#define OPEN_MAX NOFILES_MAX 82#else 83#define OPEN_MAX 256 84#endif 85#endif 86#endif 87#endif 88#endif 89 90#include <X11/Xpoll.h> 91 92/* 93 * MAXSOCKS is used only for initialising MaxClients when no other method 94 * like sysconf(_SC_OPEN_MAX) is not supported. 95 */ 96 97#if OPEN_MAX <= 256 98#define MAXSOCKS (OPEN_MAX - 1) 99#else 100#define MAXSOCKS 256 101#endif 102 103/* MAXSELECT is the number of fds that select() can handle */ 104#define MAXSELECT (sizeof(fd_set) * NBBY) 105 106#ifndef HAS_GETDTABLESIZE 107#if !defined(SVR4) && !defined(SYSV) 108#define HAS_GETDTABLESIZE 109#endif 110#endif 111 112#include <stddef.h> 113 114#if defined(XDMCP) || defined(HASXDMAUTH) 115typedef Bool (*ValidatorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type); 116typedef Bool (*GeneratorFunc)(ARRAY8Ptr Auth, ARRAY8Ptr Data, int packet_type); 117typedef Bool (*AddAuthorFunc)(unsigned name_length, const char *name, 118 unsigned data_length, char *data); 119#endif 120 121typedef struct _connectionInput { 122 struct _connectionInput *next; 123 char *buffer; /* contains current client input */ 124 char *bufptr; /* pointer to current start of data */ 125 int bufcnt; /* count of bytes in buffer */ 126 int lenLastReq; 127 int size; 128 unsigned int ignoreBytes; /* bytes to ignore before the next request */ 129} ConnectionInput, *ConnectionInputPtr; 130 131typedef struct _connectionOutput { 132 struct _connectionOutput *next; 133 int size; 134 unsigned char *buf; 135 int count; 136} ConnectionOutput, *ConnectionOutputPtr; 137 138struct _osComm; 139 140#define AuthInitArgs void 141typedef void (*AuthInitFunc) (AuthInitArgs); 142 143#define AuthAddCArgs unsigned short data_length, const char *data, XID id 144typedef int (*AuthAddCFunc) (AuthAddCArgs); 145 146#define AuthCheckArgs unsigned short data_length, const char *data, ClientPtr client, char **reason 147typedef XID (*AuthCheckFunc) (AuthCheckArgs); 148 149#define AuthFromIDArgs XID id, unsigned short *data_lenp, char **datap 150typedef int (*AuthFromIDFunc) (AuthFromIDArgs); 151 152#define AuthGenCArgs unsigned data_length, const char *data, XID id, unsigned *data_length_return, char **data_return 153typedef XID (*AuthGenCFunc) (AuthGenCArgs); 154 155#define AuthRemCArgs unsigned short data_length, const char *data 156typedef int (*AuthRemCFunc) (AuthRemCArgs); 157 158#define AuthRstCArgs void 159typedef int (*AuthRstCFunc) (AuthRstCArgs); 160 161#define AuthToIDArgs unsigned short data_length, char *data 162typedef XID (*AuthToIDFunc) (AuthToIDArgs); 163 164typedef void (*OsCloseFunc)(ClientPtr); 165 166typedef int (*OsFlushFunc)(ClientPtr who, struct _osComm * oc, char* extraBuf, int extraCount); 167 168typedef struct _osComm { 169 int fd; 170 ConnectionInputPtr input; 171 ConnectionOutputPtr output; 172 XID auth_id; /* authorization id */ 173 CARD32 conn_time; /* timestamp if not established, else 0 */ 174 struct _XtransConnInfo *trans_conn; /* transport connection object */ 175 Bool local_client; 176} OsCommRec, *OsCommPtr; 177 178extern int FlushClient( 179 ClientPtr /*who*/, 180 OsCommPtr /*oc*/, 181 const void * /*extraBuf*/, 182 int /*extraCount*/ 183); 184 185extern void FreeOsBuffers( 186 OsCommPtr /*oc*/ 187); 188 189#include "dix.h" 190 191extern fd_set AllSockets; 192extern fd_set AllClients; 193extern fd_set LastSelectMask; 194extern fd_set WellKnownConnections; 195extern fd_set EnabledDevices; 196extern fd_set ClientsWithInput; 197extern fd_set ClientsWriteBlocked; 198extern fd_set OutputPending; 199extern fd_set IgnoredClientsWithInput; 200 201#ifndef WIN32 202extern int *ConnectionTranslation; 203#else 204extern int GetConnectionTranslation(int conn); 205extern void SetConnectionTranslation(int conn, int client); 206extern void ClearConnectionTranslation(void); 207#endif 208 209extern Bool NewOutputPending; 210extern Bool AnyClientsWriteBlocked; 211 212extern WorkQueuePtr workQueue; 213 214/* in WaitFor.c */ 215#ifdef WIN32 216typedef long int fd_mask; 217#endif 218#define ffs mffs 219extern int mffs(fd_mask); 220 221/* in access.c */ 222extern Bool ComputeLocalClient(ClientPtr client); 223 224/* in auth.c */ 225extern void GenerateRandomData (int len, char *buf); 226 227/* in mitauth.c */ 228extern XID MitCheckCookie (AuthCheckArgs); 229extern XID MitGenerateCookie (AuthGenCArgs); 230extern XID MitToID (AuthToIDArgs); 231extern int MitAddCookie (AuthAddCArgs); 232extern int MitFromID (AuthFromIDArgs); 233extern int MitRemoveCookie (AuthRemCArgs); 234extern int MitResetCookie (AuthRstCArgs); 235 236/* in xdmauth.c */ 237#ifdef HASXDMAUTH 238extern XID XdmCheckCookie (AuthCheckArgs); 239extern XID XdmToID (AuthToIDArgs); 240extern int XdmAddCookie (AuthAddCArgs); 241extern int XdmFromID (AuthFromIDArgs); 242extern int XdmRemoveCookie (AuthRemCArgs); 243extern int XdmResetCookie (AuthRstCArgs); 244#endif 245 246/* in rpcauth.c */ 247#ifdef SECURE_RPC 248extern void SecureRPCInit (AuthInitArgs); 249extern XID SecureRPCCheck (AuthCheckArgs); 250extern XID SecureRPCToID (AuthToIDArgs); 251extern int SecureRPCAdd (AuthAddCArgs); 252extern int SecureRPCFromID (AuthFromIDArgs); 253extern int SecureRPCRemove (AuthRemCArgs); 254extern int SecureRPCReset (AuthRstCArgs); 255#endif 256 257#ifdef XDMCP 258/* in xdmcp.c */ 259extern void XdmcpUseMsg (void); 260extern int XdmcpOptions(int argc, char **argv, int i); 261extern void XdmcpRegisterConnection ( 262 int type, 263 const char *address, 264 int addrlen); 265extern void XdmcpRegisterAuthorizations (void); 266extern void XdmcpRegisterAuthorization (const char *name, int namelen); 267extern void XdmcpInit (void); 268extern void XdmcpReset (void); 269extern void XdmcpOpenDisplay(int sock); 270extern void XdmcpCloseDisplay(int sock); 271extern void XdmcpRegisterAuthentication ( 272 const char *name, 273 int namelen, 274 const char *data, 275 int datalen, 276 ValidatorFunc Validator, 277 GeneratorFunc Generator, 278 AddAuthorFunc AddAuth); 279 280struct sockaddr_in; 281extern void XdmcpRegisterBroadcastAddress (const struct sockaddr_in *addr); 282#endif 283 284#ifdef HASXDMAUTH 285extern void XdmAuthenticationInit (const char *cookie, int cookie_length); 286#endif 287 288#endif /* _OSDEP_H_ */ 289