/* * Copyrights: * * Copyright (c) 1996, 1998 Smithsonian Astrophysical Observatory * * Permission to use, copy, modify, distribute, and sell this * software and its documentation for any purpose is hereby * granted without fee, provided that the above copyright * notice appear in all copies and that both that copyright * notice and this permission notice appear in supporting docu- * mentation, and that the name of the Smithsonian Astro- * physical Observatory not be used in advertising or publicity * pertaining to distribution of the software without specific, * written prior permission. The Smithsonian Astrophysical * Observatory makes no representations about the suitability * of this software for any purpose. It is provided "as is" * without express or implied warranty. * THE SMITHSONIAN ASTROPHYSICAL OBSERVATORY DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THE SMITHSONIAN ASTROPHYSICAL OBSERVATORY BE * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH * THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ /* * * xpa.h - include file for the X Public Access mechanism * */ #ifndef __xpa_h #define __xpa_h /* #define XPA_DEBUG 1 */ #include #include #include /* this should be defined in the Makefile */ #ifndef XPA_VERSION #define XPA_VERSION 2.0 #endif /* the ever-present */ #ifndef SZ_LINE #define SZ_LINE 1024 #endif #ifndef NewString #define NewString(str) \ ((str) != (char *)NULL ? \ ((char *)strcpy((char *)malloc((unsigned)strlen(str)+1), str)) : \ (char *)NULL) #endif /* defines the types of callback procedure we use */ typedef int (*SendCb)( #ifdef ANSI_FUNC void *client_data, void *call_data, char *paramlist, char **buf, int *len #endif ); typedef int (*ReceiveCb)( #ifdef ANSI_FUNC void *client_data, void *call_data, char *paramlist, char *buf, int 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 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; } *ACL, ACLRec; /* * * * xpa communication structure for each connection * */ typedef struct xpacommrec{ struct xpacommrec *next; int n; int level; int cmd; int telnet; int usebuf; int useacl; char *id; char *target; char *paramlist; int cmdfd; FILE *cmdin; FILE *cmdout; int datafd; char *cendian; int ack; /* for AF_INET */ unsigned int cmdip; int cmdport; unsigned int dataip; int dataport; /* for AF_UNIX */ char *cmdname; char *dataname; int acl[4]; /* for handling fd's in non-select event loops */ void *selcptr; /* cmdfd struct for seldel */ void *seldptr; /* datafd struct for seldel */ } *XPAComm, XPACommRec; /* * * record struct for receiving data from stdin * */ typedef struct xpainputrec{ struct xpainputrec *next; int start; int end; int bytes; char *buf; } *XPAInput, XPAInputRec; /* * * * xpa command record structure * */ typedef struct xpacmdrec{ struct xpacmdrec *next; 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 active; char *id; char *xtemplate; int type; char *xclass; char *name; char *method; int cmdfd; FILE *cmdin; FILE *cmdout; int datafd; int mode; /* xpaget parameters */ char **bufptr; int *lenptr; int fd; /* xpaset parameters */ char *buf; int len; int bytes; /* 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; /* "g", "s", "i" are server types; "c" for client */ char *type; /* * THE SERVER SIDE */ struct xparec *next; int status; char *xclass; char *name; char *help; char *id; /* buf and len passed to callbacks */ char *buf; int len; /* 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 */ XPAComm commhead; /* linked list of communcation records */ char *filename; /* file name (unix sockets) for listening */ char *sendian; /* endian-ness of server */ /* request-specific info */ int cmdfd; /* file descriptor for commands */ FILE *cmdin; /* input file pointer for commands */ FILE *cmdout; /* output file pointer for commands */ int datafd; /* file descriptor for data */ char *cendian; /* endian-ness of current client */ 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 ack; /* flag if this client wants to be ack'ed */ int message; /* flag if an acknowledgement message was sent */ 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() */ int 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_cmdfd(xpa) ((xpa)->cmdfd) #define xpa_datafd(xpa) ((xpa)->datafd) #define xpa_sendian(xpa)((xpa)->sendian) #define xpa_cendian(xpa)((xpa)->cendian) extern char *xpaMessbuf[]; _PRBEGIN XPA XPAListHead _PR((void)); void XPAListAdd _PR((XPA *head, XPA xpa)); void XPAListDel _PR((XPA *head, XPA xpa)); int XPAAddSelect _PR((XPA xpa, fd_set *readfdsptr)); int XPAProcessSelect _PR((fd_set *readfdsptr, int maxreq)); void XPACloseData _PR((XPA xpa, XPAComm comm)); int XPAHandler _PR((XPA xpa, int fd)); void XPAMode _PR((char *mode, int *flag, char *name, int mask, int def)); int XPAEndian _PR((void)); int XPAShortTimeout _PR((void)); int XPALongTimeout _PR((void)); int XPASendLTimeout _PR((void *client_data, void *call_data, char *paramlist, char **buf, int *len)); int XPAReceiveLTimeout _PR((void *client_data, void *call_data, char *paramlist, char *buf, int len)); int XPASendSTimeout _PR((void *client_data, void *call_data, char *paramlist, char **buf, int *len)); int XPAReceiveSTimeout _PR((void *client_data, void *call_data, char *paramlist, char *buf, int len)); int XPADebug _PR((void)); int XPASigusr1 _PR((void)); int XPAVerbosity _PR((void)); void XPAInitEnv _PR((void)); void XPAParseName _PR((char *xpaname, char *xclass, char *name, int len)); int XPAParseIpPort _PR((char *host, unsigned int *ip, unsigned short *port)); int XPAParseUnixSocket _PR((char *host)); int _XPAValid _PR((XPA head, XPA xpa, char *type)); int XPAValid _PR((XPA xpa)); int XPAError _PR((XPA xpa, char *s)); int XPAMessage _PR((XPA xpa, char *s)); char *XPAArgvParamlist _PR((int argc, char **argv, int start)); int XPAMethod _PR((char *method)); int XPAAccess _PR((char *tname, char *ttype)); int XPANSLookup _PR((char *tname, char *ttype, char ***xclasses, char ***names, char ***methods)); int XPANSClose _PR((void)); int XPANSReset _PR((void)); char *XPANSMethod _PR((int flag)); XPA XPANew _PR((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 _PR((XPA xpa)); XPA XPAInfoNew _PR((char *xclass, char *name, InfoCb info_callback, void *info_data, char *info_mode)); int XPAPoll _PR((int msec, int maxreq)); int XPAMainLoop _PR((void)); void XPASleep _PR((int msec)); /* command.c */ void XPAInitReserved _PR((void)); XPACmd XPACmdLookupReserved _PR((XPA xpa, char *lbuf, int *lp)); XPACmd XPACmdLookup _PR((XPA xpa, char *lbuf, int *lp)); int XPAReceiveCommands _PR((void *client_data, void *call_data, char *paramlist, char *buf, int len)); int XPASendCommands _PR((void *client_data, void *call_data, char *paramlist, char **buf, int *len)); XPA XPACmdNew _PR((char *xclass, char *name)); XPACmd XPACmdAdd _PR((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 _PR((XPA xpa, XPACmd cmd)); int XPACmdInternalReceive _PR((void *client_data, void *call_data, char *paramlist, char *buf, int len)); int XPACmdInternalSend _PR((void *client_data, void *call_data, char *paramlist, char **buf, int *len)); XPA XPAGetReserved _PR((void)); /* client.c */ XPA XPAOpen _PR((char *mode)); void XPAClose _PR((XPA xpa)); int XPAGet _PR((XPA xpa, char *xtemplate, char *paramlist, char *mode, char **bufs, int *lens, char **names, char **errs, int n)); int XPAGetFd _PR((XPA xpa, char *xtemplate, char *paramlist, char *mode, int *fds, char **names, char **errs, int n)); int XPASet _PR((XPA xpa, char *xtemplate, char *paramlist, char *mode, char *buf, int len, char **names, char **errs, int n)); int XPASetFd _PR((XPA xpa, char *xtemplate, char *paramlist, char *mode, int fd, char **names, char **errs, int n)); int XPAInfo _PR((XPA xpa, char *xtemplate, char *paramlist, char *mode, char **names, char **errs, int n)); int XPAClientValid _PR((XPA xpa)); /* acl.c */ int XPAReceiveAcl _PR((void *client_data, void *call_data, char *paramlist, char *buf, int len)); int XPASendAcl _PR((void *client_data, void *call_data, char *paramlist, char **buf, int *len)); int XPAAclEdit _PR((char *lbuf)); int XPAAclAdd _PR((char *lbuf)); int XPAAclDel _PR((ACL acl)); void XPAAclFree _PR((void)); int XPAAclNew _PR((char *aname, int flag)); int XPAAclCheck _PR((XPA xpa, int ip, int acl)); /* xt.c */ int XPAXtAddInput _PR((void *app, XPA xpa)); /* tcl.c */ int XPATclAddInput _PR((XPA xpa)); int Xpa_Init _PR((void *vinterp)); /* xpaio.c */ int XPAGets _PR((FILE *fp, char *buf, int len, int timeout)); int XPAPuts _PR((FILE *fp, char *buf, int timeout)); int XPAGetBuf _PR((int fd, char **buf, int *len, int timeout)); int XPAPutBuf _PR((int fd, char *buf, int len, int timeout)); int XPASetBuf _PR((XPA xpa, char *buf, int len, int xcopy)); int XPARdl _PR((int fd, char *buf, int len, int timeout)); void XPADefaultSigaction _PR((void)); _PREND #endif /* __xpa.h */