summaryrefslogtreecommitdiffstats
path: root/xpa/xpa.h
blob: d5e27ab262d6cb332977ff6ca84ba9bb82c0aaf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/*
 *	Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
 */

/*
 *
 * xpa.h - include file for the X Public Access mechanism
 *
 */

#ifndef	__xpa_h
#define	__xpa_h

#include <stdio.h>
#include <sys/types.h>
#include <prsetup.h>
#if HAVE_MINGW32
#include <winsock2.h>
#endif

#define XPA_MAJOR_VERSION 2
#define XPA_MINOR_VERSION 1
#define XPA_PATCH_LEVEL 18
#define XPA_VERSION "2.1.18"

/* #define XPA_DEBUG 1 */
#ifdef XPA_DEBUG
#define FPRINTF(x) fprintf x
#define PERROR(x)  perror x
#else
#define FPRINTF(x)
#define PERROR(x)
#endif

/* types of xpa request */
#define XPA_SET		1
#define XPA_GET		2
#define XPA_INFO	3
#define XPA_ACCESS	4
/* not actually commands but ... */
#define XPA_DATA	5
#define XPA_ACCEPT	6
#define XPA_NAGLE	7

/* this is the number of actual commands we have above */
#define XPA_CMDS	4

/* comm modes */
#define COMM_RESERVED	1
#define COMM_CONNECT	2

/* the ever-present */
#ifndef SZ_LINE
#define SZ_LINE 4096
#endif

/* limit the length of the name and xclass strings */
/* at least 2 of these should fit into SZ_LINE with lots of room to spare */
#define XPA_NAMELEN	1024

/* defines the types of callback procedure we use */
typedef int (*SendCb)(
#ifdef ANSI_FUNC
    void *client_data,
    void *call_data,
    char *paramlist,
    char **buf,
    size_t *len
#endif
);

typedef int (*ReceiveCb)(
#ifdef ANSI_FUNC
    void *client_data,
    void *call_data,
    char *paramlist,
    char *buf,
    size_t len
#endif
);

typedef int (*InfoCb)(
#ifdef ANSI_FUNC
    void *client_data,
    void *call_data,
    char *paramlist
#endif
);

typedef void *(*SelAdd)(
#ifdef ANSI_FUNC
    void *client_data,
    int fd
#endif
);

typedef void (*SelDel)(
#ifdef ANSI_FUNC
    void *client_data
#endif
);

typedef void (*SelOn)(
#ifdef ANSI_FUNC
    void *client_data
#endif
);

typedef void (*SelOff)(
#ifdef ANSI_FUNC
    void *client_data
#endif
);

typedef void (*MyFree)(
#ifdef ANSI_FUNC
    void *buf
#endif
);

typedef void Sigfunc(
#ifdef ANSI_FUNC
    int		     
#endif
);

/*
 *
 *
 * xpa access control record structure
 *
 */
typedef struct aclrec{
  struct aclrec *next;
  char *xclass;
  char *name;
  unsigned int ip;
  char *acl;
  int flag;
} *XACL, XACLRec;

/*
 *
 *
 * port management record structure
 *
 */
typedef struct portrec{
  struct portrec *next;
  char *xclass;
  char *name;
  int port;
} *PORT, PORTRec;

/*
 *
 *
 * xpa name server management
 *
 */
typedef struct nsrec{
  struct nsrec *next;
  char *method;
  int nxpa;
  int nproxy;
  char *host;
  int fd;
  FILE *in;
  FILE *out;
  /* for AF_INET */
  unsigned int ip;
  int port;
  /* for AF_UNIX */
  char *name;
} *NS, NSRec;

/*
 *
 *
 * xpa communication structure for each connection
 *
 */
typedef struct xpacommrec{
  struct xpacommrec *next;
  int status;
  int message;
  int n;
  int cmd;
  int mode;
  int telnet;
  int usebuf;
  int useacl;
  char *id;
  char *info;
  char *target;
  char *paramlist;
  int cmdfd;
  int datafd;
  char *cendian;
  int ack;
  /* buf and len passed to callbacks */
  char *buf;
  size_t len;
  /* for AF_INET */
  unsigned int cmdip;
  int cmdport;
  int dataport;
  /* for AF_UNIX */
  char *cmdname;
  char *dataname;
  int acl[XPA_CMDS+1];
  /* for handling fd's in non-select event loops */
  void *selcptr;	/* cmdfd struct for seldel */
  void *seldptr;	/* datafd struct for seldel */
  /* pointer to associated name server */
  struct nsrec *ns;
  /* myfree routine */
  MyFree myfree;
  void *myfree_ptr;
} *XPAComm, XPACommRec;

/*
 *
 *
 * clipboard record structure
 *
 */
typedef struct cliprec{
  struct cliprec *next;
  unsigned int ip;
  char *name;
  char *value;
} *XPAClip, XPAClipRec;

/* 
 *
 * record struct for receiving data from stdin
 *
 */
typedef struct xpainputrec{
  struct xpainputrec *next;
  size_t start;
  size_t end;
  size_t bytes;
  char *buf;
} *XPAInput, XPAInputRec;

/*
 *
 *
 * xpa command record structure
 *
 */
typedef struct xpacmdrec{
  struct xpacmdrec *next;
  struct xparec *xpa;
  char *name;
  char *help;
  int ntokens;
  /* send callback info */
  SendCb send_callback;
  void *send_data;
  int send_mode;
  /* receive callback info */
  ReceiveCb receive_callback;
  void *receive_data;
  int receive_mode;
} *XPACmd, XPACmdRec;

/*
 *
 *
 * xpa client record structure
 *
 */
typedef struct xpaclientrec{
  struct xpaclientrec *next;
  int status;
  char *id;
  char *xtemplate;
  int type;
  char *xclass;
  char *name;
  char *method;
  char *info;
  char *dataname;
  unsigned int ip;
  int cmdfd;
  int datafd;
  int mode;
  int nsproxy;
  /* xpaget parameters */
  char **bufptr;
  size_t  *lenptr;
  size_t bufsize;
  int fd;
  /* xpaset parameters */
  char *buf;
  size_t len;
  size_t bytes;
  /* fork parameters */
  pid_t pid;
  /* common parameters */
  char **nameptr;
  char **errptr;
} *XPAClient, XPAClientRec;

/*
 *
 *
 * main xpa record structure
 *
 * explanation of send_mode and receive_mode flags:
 *
 * receive-specific callback modes:
 *
 *	r (raw) 	-- don't read data into buf (callback will read)
 *
 * general callback modes:
 *
 *	r (raw) 	-- write raw data without protocol info to client
 *	s (save)	-- 's' save passed buf (don't free it)
 *
 */
typedef struct xparec{
  /* xpa version */
  char *version;
  /* status of this xpa */
  int status;
  /* "g", "s", "i" are server types; "c" for client */
  char *type;
  /*
   * THE SERVER SIDE
   */
  struct xparec *next;
  char *xclass;
  char *name;
  char *help;
  /* send callback info */
  SendCb send_callback;
  void *send_data;
  int send_mode;
  /* receive callback info */
  ReceiveCb receive_callback;
  void *receive_data;
  int receive_mode;
  /* info callback info */
  InfoCb info_callback;
  void *info_data;
  int info_mode;
  /* list of sub-commands for this access point */
  XPACmd commands;
  /* communication info */
  int fd;		/* listening socket file descriptor */
  char *method;		/* method string: host:ip or unix_filename */
  NS nshead;		/* name servers associated with this access point */
  XPAComm commhead;	/* linked list of communcation records */
  XPAClip cliphead;	/* linked list of cliboard records */
  char *filename;	/* file name (unix sockets) for listening */
  char *sendian;	/* endian-ness of server */
  /* request-specific info */
  XPAComm comm;		/* current comm if we are processing a request */
  /* select loop info */
  SelDel seldel;	/* routine to remove xpa socket from select loop */
  SelAdd seladd;	/* routine to add xpa command sockets to select loop */
  SelOn selon;		/* routine to enable xpa command sockets */
  SelOff seloff;	/* routine to disable xpa command sockets */
  void *selptr;		/* additional info for seldelete() */
  /*
   * THE CLIENT SIDE
   */
  int persist;		/* flag whether this is a persistent client */
  int nclient;		/* number of clients -- used in processing headers */
  int client_mode;	/* global client mode */
  XPAClient clienthead;	/* linked list of active clients */
  int ifd;		/* input fd for XPASetFd() */
  size_t inpbytes;	/* total number of bytes in input lists */
  XPAInput inphead;	/* linked list of input structs */
} *XPA, XPARec;

/* macros to access the xpa struct */
#define xpa_name(xpa)	 ((xpa)->name)
#define xpa_class(xpa)	 ((xpa)->xclass)
#define xpa_method(xpa)	 ((xpa)->method)
#define xpa_sendian(xpa) ((xpa)->sendian)
#define xpa_comm(xpa)	 (xpa&&(xpa)->comm?(xpa)->comm:NULL)
#define xpa_cendian(xpa) (((xpa)->comm&&(xpa)->comm->cendian)?(xpa)->comm->cendian:"?")
#define xpa_cmdfd(xpa)	 ((xpa)->comm?(xpa)->comm->cmdfd:-1)
#define xpa_datafd(xpa)	 ((xpa)->comm?(xpa)->comm->datafd:-1)
#define xpa_ack(xpa)	 ((xpa)->comm?(xpa)->comm->ack:1)
#define xpa_status(xpa)	 ((xpa)->comm?(xpa)->comm->status:0)
#define xpa_id(xpa)	 (((xpa)->comm&&(xpa)->comm->id)?(xpa)->comm->id:"?")

extern char *xpaMessbuf[];

_PRbeg

XPA XPAListHead _PRx((void));
void XPAListAdd _PRx((XPA *head, XPA xpa));
void XPAListDel _PRx((XPA *head, XPA xpa));
int XPAActive _PRx((XPA xpa, XPAComm comm, int flag));
int XPAActiveFd _PRx((int fd));
int XPAAddSelect _PRx((XPA xpa, fd_set *readfdsptr));
int XPAProcessSelect _PRx((fd_set *readfdsptr, int maxreq));
void XPACloseData _PRx((XPA xpa, XPAComm comm));
int XPAHandler _PRx((XPA xpa, int fd));
void XPAMode  _PRx((char *mode, int *flag, char *name, int mask, int def));
int XPAEndian _PRx((void));
char *XPATmpdir _PRx((void));
void XPACleanup _PRx((void));
int XPASetBuf  _PRx((XPA xpa, char *buf, size_t len, int xcopy));
int XPASetFree _PRx((XPA xpa, MyFree myfree, void *myfree_ptr));
int XPAShortTimeout _PRx((void));
int XPALongTimeout _PRx((void));
int XPASendLTimeout _PRx((void *client_data, void *call_data,
			  char *paramlist, char **buf, size_t *len));
int XPAReceiveLTimeout _PRx((void *client_data, void *call_data,
			     char *paramlist, char *buf, size_t len));
int XPASendSTimeout _PRx((void *client_data, void *call_data,
			  char *paramlist, char **buf, size_t *len));
int XPAReceiveSTimeout _PRx((void *client_data, void *call_data,
			     char *paramlist, char *buf, size_t len));
int XPADebug _PRx((void));
int XPASigusr1 _PRx((void));
int XPAVerbosity _PRx((void));
void XPAInitEnv _PRx((void));
void XPAParseName _PRx((char *xpaname, char *xclass, char *name, int len));
int XPAParseIpPort _PRx((char *host, unsigned int *ip, unsigned short *port));
int XPAParseUnixSocket _PRx((char *host));
int _XPAValid _PRx((XPA head, XPA xpa, char *type));
int XPAValid _PRx((XPA xpa));
char *XPATimestamp _PRx((void));
int XPAError _PRx((XPA xpa, char *s));
int XPAOK _PRx((XPA xpa));
int XPAMessage _PRx((XPA xpa, char *s));
char *XPAArgvParamlist _PRx((int argc, char **argv, int start));
int XPAMethod _PRx((char *method));
int XPAAccess _PRx((XPA xpa, char *xtemplate, char *paramlist, char *mode,
		    char **names, char **messages, int n));
int XPANSLookup _PRx((XPA xpa, char *tname, char *ttype, 
		      char ***xclasses, char ***names,
		      char ***methods, char ***infs));
int XPANSClose _PRx((XPA xpa, NS ns));
int XPANSKeepAlive _PRx((XPA xpa, int type));
int XPANSAdd _PRx((XPA xpa, char *host, char *mode));
int XPANSDel _PRx((XPA xpa, char *host, char *mode));
int XPAVersionCheck _PRx((char *serv, char *nsv));
void XPAVersionWarn _PRx((char *myv, char *nsv));
char *XPANSMethod _PRx((char *host, int flag));
XPA XPANew _PRx((char *xclass, char *name, char *help,
		 SendCb send_callback, void *send_data, char *send_mode,
		 ReceiveCb rec_callback, void *rec_data, char *rec_mode));
int XPAFree _PRx((XPA xpa));
XPA XPAInfoNew _PRx((char *xclass, char *name,
		     InfoCb info_callback, void *info_data, char *info_mode));
int XPAPoll  _PRx((int msec, int maxreq));
int XPAMainLoop _PRx((void));
void XPASleep  _PRx((int msec));
void XPAAtExit  _PRx((void));
/* command.c */
void XPAInitReserved _PRx((void));
void XPAFreeReserved _PRx((void));
XPACmd XPACmdLookupReserved _PRx((XPA xpa, char *lbuf, int *lp));
XPACmd XPACmdLookup _PRx((XPA xpa, char *lbuf, int *lp));
int XPAReceiveCommands _PRx((void *client_data, void *call_data,
			     char *paramlist, char *buf, size_t len));
int XPASendCommands _PRx((void *client_data, void *call_data,
			  char *paramlist, char **buf, size_t *len));
XPA XPACmdNew  _PRx((char *xclass, char *name));
XPACmd XPACmdAdd _PRx((XPA xpa, char *name, char *help,
		      SendCb send_callback, void *send_data, char *send_mode,
		      ReceiveCb rec_callback, void *rec_data, char *rec_mode));
int XPACmdDel _PRx((XPA xpa, XPACmd cmd));
int XPACmdInternalReceive _PRx((void *client_data, void *call_data,
				char *paramlist, char *buf, size_t len));
int XPACmdInternalSend _PRx((void *client_data, void *call_data,
			     char *paramlist, char **buf, size_t *len));
XPA XPAGetReserved  _PRx((void));
int XPAMtype _PRx((void));
/* client.c */
int XPAClientAddSelect _PRx((XPA xpa,
			     fd_set *readfdsptr, fd_set *writefdsptr));
int XPAClientProcessSelect _PRx((XPA xpa,
				 fd_set *readfdsptr, fd_set *writefdsptr,
				 int maxreq));
XPA XPAOpen  _PRx((char *mode));
void XPAClose _PRx((XPA xpa));
int XPAGet _PRx((XPA xpa, char *xtemplate,
		 char *paramlist, char *mode,
		 char **bufs, size_t *lens, char **names, char **errs, int n));
int XPAGetFd _PRx((XPA xpa, char *xtemplate,
		   char *paramlist, char *mode,
		   int *fds, char **names, char **errs, int n));
int XPASet _PRx((XPA xpa, char *xtemplate,
		 char *paramlist, char *mode,
		 char *buf, size_t len, char **names, char **errs, int n));
int XPASetFd _PRx((XPA xpa, char *xtemplate,
		   char *paramlist, char *mode,
		   int fd, char **names, char **errs, int n));
int XPAInfo _PRx((XPA xpa, char *xtemplate,
		  char *paramlist, char *mode,
		  char **names, char **errs, int n));
int XPAClientValid _PRx((XPA xpa));
void XPASaveJmp _PRx((void *env));


/* acl.c */
int XPAReceiveAcl _PRx((void *client_data, void *call_data,
			char *paramlist, char *buf, size_t len));
int XPASendAcl _PRx((void *client_data, void *call_data,
		     char *paramlist, char **buf, size_t *len));
int XPAAclEdit _PRx((char *lbuf));
int XPAAclAdd _PRx((char *lbuf));
int XPAAclDel _PRx((XACL acl));
void XPAAclFree _PRx((void));
int XPAAclNew _PRx((char *aname, int flag));
int XPAAclCheck _PRx((XPA xpa, unsigned int ip, char *acl));
/* port.c */
int XPAPortEdit _PRx((char *lbuf));
int XPAPortAdd _PRx((char *lbuf));
int XPAPortDel _PRx((PORT port));
void XPAPortFree _PRx((void));
int XPAPortNew _PRx((char *aname, int flag));
int XPAPort _PRx((XPA xpa));
/* remote.c */
int XPAReceiveRemote _PRx((void *client_data, void *call_data,
			   char *paramlist, char *buf, size_t len));
int XPASendRemote _PRx((void *client_data, void *call_data,
			char *paramlist, char **buf, size_t *len));
int XPARemote _PRx((XPA xpa, char *host, char *acl, char *mode));
/* clipboard.c */
int XPAReceiveClipboard _PRx((void *client_data, void *call_data,
			      char *paramlist, char *buf, size_t len));
int XPASendClipboard _PRx((void *client_data, void *call_data,
			   char *paramlist, char **buf, size_t *len));
int ClipBoardFree _PRx((XPA xpa, XPAClip clip));
/* xt.c */
int XPAXtAddInput _PRx((void *app, XPA xpa));
/* tcl.c */
int XPATclAddInput _PRx((XPA xpa));
int Tclxpa_Init _PRx((void *vinterp));
/* gtkloop.c */
int XPAGtkAddInput _PRx((XPA xpa));
/* xpaio.c */
int XPAGets _PRx((XPA xpa, int fd, char *buf, int len, int timeout));
int XPAPuts _PRx((XPA xpa, int fd, char *buf, int timeout));
int XPAGetBuf _PRx((XPA xpa, int fd, char **buf, size_t *len, int timeout));
int XPAPutBuf _PRx((XPA xpa, int fd, char *buf, size_t len, int timeout));
int XPAIOCallsXPA _PRx((int flag));
char *XPALevelSpaces _PRx((void));
void XPALevelSet _PRx((int lev));
int XPALevelGet _PRx((void));

_PRend

#endif /* __xpa.h */