File indexing completed on 2025-01-30 10:26:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 #ifndef _XTRANSINT_H_
0051 #define _XTRANSINT_H_
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 #if !defined(XTRANSDEBUG) && defined(XTRANS_TRANSPORT_C)
0072 # define XTRANSDEBUG 1
0073 #endif
0074
0075 #ifdef WIN32
0076 # define _WILLWINSOCK_
0077 #endif
0078
0079 #include "Xtrans.h"
0080
0081 #ifndef _X_UNUSED
0082 # define _X_UNUSED
0083 #endif
0084
0085 #ifdef XTRANSDEBUG
0086 # include <stdio.h>
0087 #endif
0088
0089 #include <errno.h>
0090
0091 #ifndef WIN32
0092 # include <sys/socket.h>
0093 # include <netinet/in.h>
0094 # include <arpa/inet.h>
0095
0096
0097
0098
0099
0100
0101 # if defined(_POSIX_SOURCE) || defined(SVR4) || defined(__SVR4)
0102 # ifndef NEED_UTSNAME
0103 # define NEED_UTSNAME
0104 # endif
0105 # include <sys/utsname.h>
0106 # endif
0107
0108 # define ESET(val) errno = val
0109 # define EGET() errno
0110
0111 #else
0112
0113 # include <limits.h> /* for USHRT_MAX */
0114
0115 # define ESET(val) WSASetLastError(val)
0116 # define EGET() WSAGetLastError()
0117
0118 #endif
0119
0120 #include <stddef.h>
0121
0122 #ifdef X11_t
0123 #define X_TCP_PORT 6000
0124 #endif
0125
0126 #if XTRANS_SEND_FDS
0127
0128 struct _XtransConnFd {
0129 struct _XtransConnFd *next;
0130 int fd;
0131 int do_close;
0132 };
0133
0134 #endif
0135
0136 struct _XtransConnInfo {
0137 struct _Xtransport *transptr;
0138 int index;
0139 char *priv;
0140 int flags;
0141 int fd;
0142 char *port;
0143 int family;
0144 char *addr;
0145 int addrlen;
0146 char *peeraddr;
0147 int peeraddrlen;
0148 struct _XtransConnFd *recv_fds;
0149 struct _XtransConnFd *send_fds;
0150 };
0151
0152 #define XTRANS_OPEN_COTS_CLIENT 1
0153 #define XTRANS_OPEN_COTS_SERVER 2
0154
0155 typedef struct _Xtransport {
0156 const char *TransName;
0157 int flags;
0158
0159 #ifdef TRANS_CLIENT
0160
0161 XtransConnInfo (*OpenCOTSClient)(
0162 struct _Xtransport *,
0163 const char *,
0164 const char *,
0165 const char *
0166 );
0167
0168 #endif
0169
0170 #ifdef TRANS_SERVER
0171 const char ** nolisten;
0172 XtransConnInfo (*OpenCOTSServer)(
0173 struct _Xtransport *,
0174 const char *,
0175 const char *,
0176 const char *
0177 );
0178
0179 #endif
0180
0181 #ifdef TRANS_REOPEN
0182
0183 XtransConnInfo (*ReopenCOTSServer)(
0184 struct _Xtransport *,
0185 int,
0186 const char *
0187 );
0188
0189 #endif
0190
0191
0192 int (*SetOption)(
0193 XtransConnInfo,
0194 int,
0195 int
0196 );
0197
0198 #ifdef TRANS_SERVER
0199
0200 # define ADDR_IN_USE_ALLOWED 1
0201
0202 int (*CreateListener)(
0203 XtransConnInfo,
0204 const char *,
0205 unsigned int
0206 );
0207
0208 int (*ResetListener)(
0209 XtransConnInfo
0210 );
0211
0212 XtransConnInfo (*Accept)(
0213 XtransConnInfo,
0214 int *
0215 );
0216
0217 #endif
0218
0219 #ifdef TRANS_CLIENT
0220
0221 int (*Connect)(
0222 XtransConnInfo,
0223 const char *,
0224 const char *
0225 );
0226
0227 #endif
0228
0229 int (*BytesReadable)(
0230 XtransConnInfo,
0231 BytesReadable_t *
0232 );
0233
0234 int (*Read)(
0235 XtransConnInfo,
0236 char *,
0237 int
0238 );
0239
0240 int (*Write)(
0241 XtransConnInfo,
0242 char *,
0243 int
0244 );
0245
0246 int (*Readv)(
0247 XtransConnInfo,
0248 struct iovec *,
0249 int
0250 );
0251
0252 int (*Writev)(
0253 XtransConnInfo,
0254 struct iovec *,
0255 int
0256 );
0257
0258 #if XTRANS_SEND_FDS
0259 int (*SendFd)(
0260 XtransConnInfo,
0261 int,
0262 int
0263 );
0264
0265 int (*RecvFd)(
0266 XtransConnInfo
0267 );
0268 #endif
0269
0270 int (*Disconnect)(
0271 XtransConnInfo
0272 );
0273
0274 int (*Close)(
0275 XtransConnInfo
0276 );
0277
0278 int (*CloseForCloning)(
0279 XtransConnInfo
0280 );
0281
0282 } Xtransport;
0283
0284
0285 typedef struct _Xtransport_table {
0286 Xtransport *transport;
0287 int transport_id;
0288 } Xtransport_table;
0289
0290
0291
0292
0293
0294
0295 #define TRANS_ALIAS (1<<0)
0296 #define TRANS_LOCAL (1<<1)
0297 #define TRANS_DISABLED (1<<2)
0298 #define TRANS_NOLISTEN (1<<3)
0299 #define TRANS_NOUNLINK (1<<4)
0300 #define TRANS_ABSTRACT (1<<5)
0301
0302
0303 #define TRANS_NOXAUTH (1<<6)
0304 #define TRANS_RECEIVED (1<<7)
0305
0306
0307 #define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
0308
0309 #ifdef XTRANS_TRANSPORT_C
0310
0311
0312 #ifdef __clang__
0313
0314 #pragma clang diagnostic push
0315 #pragma clang diagnostic ignored "-Wunused-function"
0316 #endif
0317
0318
0319
0320
0321
0322
0323 #ifdef WIN32
0324
0325 #define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
0326
0327 static int TRANS(ReadV)(
0328 XtransConnInfo,
0329 struct iovec *,
0330 int
0331 );
0332
0333 #else
0334
0335 #define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
0336
0337 #endif
0338
0339
0340 #ifdef WIN32
0341
0342 #define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
0343
0344 static int TRANS(WriteV)(
0345 XtransConnInfo,
0346 struct iovec *,
0347 int
0348 );
0349
0350 #else
0351
0352 #define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
0353
0354 #endif
0355
0356 #ifdef TRANS_SERVER
0357 static int trans_mkdir (
0358 const char *,
0359 int
0360 );
0361 #endif
0362
0363 #ifdef __clang__
0364 #pragma clang diagnostic pop
0365 #endif
0366
0367
0368
0369
0370
0371 #ifdef XTRANSDEBUG
0372 #include <stdarg.h>
0373
0374
0375
0376
0377
0378
0379 # if (defined(XSERV_t) || defined(TRANS_HAS_ERRORF)) && defined(TRANS_SERVER)
0380 # include "os.h"
0381 # else
0382 static inline void _X_ATTRIBUTE_PRINTF(1, 0)
0383 VErrorF(const char *f, va_list args)
0384 {
0385 vfprintf(stderr, f, args);
0386 fflush(stderr);
0387 }
0388
0389 static inline void _X_ATTRIBUTE_PRINTF(1, 2)
0390 ErrorF(const char *f, ...)
0391 {
0392 va_list args;
0393
0394 va_start(args, f);
0395 VErrorF(f, args);
0396 va_end(args);
0397 }
0398 # endif
0399 #endif
0400
0401 static inline void _X_ATTRIBUTE_PRINTF(2, 3)
0402 prmsg(int lvl, const char *f, ...)
0403 {
0404 #ifdef XTRANSDEBUG
0405 va_list args;
0406
0407 va_start(args, f);
0408 if (lvl <= XTRANSDEBUG) {
0409 int saveerrno = errno;
0410
0411 ErrorF("%s", __xtransname);
0412 VErrorF(f, args);
0413
0414 # ifdef XTRANSDEBUGTIMESTAMP
0415 {
0416 struct timeval tp;
0417 gettimeofday(&tp, 0);
0418 ErrorF("timestamp (ms): %d\n",
0419 tp.tv_sec * 1000 + tp.tv_usec / 1000);
0420 }
0421 # endif
0422 errno = saveerrno;
0423 }
0424 va_end(args);
0425 #endif
0426 }
0427
0428 #endif
0429
0430 #endif