comparison lib-src/gnuserv.h @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 /* -*-C-*-
2
3 Header file for the GNU Emacs server and client C code.
4
5 This file is part of GNU Emacs.
6
7 Copying is permitted under those conditions described by the GNU
8 General Public License.
9
10 Copyright (C) 1989 Free Software Foundation, Inc.
11
12 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
13 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
14 Emacs distribution.
15
16 Please mail bugs and suggestions to the author at the above address.
17 */
18
19 /* HISTORY
20 * 11-Nov-1990 bristor@simba
21 * Added EOT stuff.
22 */
23
24 /*
25 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
26 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
27 * Please see the note at the end of the README file for details.
28 *
29 * (If gnuserv came bundled with your emacs, the README file is probably
30 * ../etc/gnuserv.README relative to the directory containing this file)
31 */
32
33 #if 0
34 static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup alpha !";
35 #endif
36
37 #define NO_SHORTNAMES
38
39 #define PATCHLEVEL 2
40
41 #define NO_SHORTNAMES
42 /* gnuserv should not be compiled using SOCKS */
43 #define DO_NOT_SOCKSIFY
44 #include <../src/config.h>
45 #undef read
46 #undef write
47 #undef open
48 #undef close
49 #undef signal
50
51 /* Define the communication method between server and clients:
52 * You can have either or both kinds of sockets, but you can't mix
53 * sockets with sysv ipc
54 */
55
56
57 #define INTERNET_DOMAIN_SOCKETS
58 #define UNIX_DOMAIN_SOCKETS
59 /* #define SYSV_IPC */
60
61 /*
62 * Define additional authentication protocols to be used. These methods will
63 * be tried before falling back to the default gnuserv protocol (based on
64 * the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1
65 * is also supported.
66 *
67 * Comment out the next line(s) if you don't want to enable the
68 * appropriate authentication protocol.
69 */
70
71 #if defined (HAVE_XAUTH)
72 #define AUTH_MAGIC_COOKIE
73 #endif /* HAVE_XAUTH */
74
75 /*
76 * stuff related to supporting MIT-MAGIC-COOKIE-1
77 */
78
79 #define MCOOKIE_SCREEN "999" /* screen # to use as the gnuserv cookie */
80 #define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */
81 #define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */
82
83
84 #define DEFAUTH_NAME "GNU-SECURE" /* name of default auth protocol */
85 #define AUTH_TIMEOUT 15 /* # seconds to wait for auth data */
86 #define AUTH_NAMESZ 15 /* max allows auth protocol name size */
87
88
89 /*
90 * Pick a default communication scheme, if none was specified.
91 */
92
93 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
94
95 #ifdef HAVE_SYSVIPC
96 #define SYSV_IPC /* SYSV systems use SYSV IPC by default */
97 #endif /* HAVE_SYSVIPC */
98
99 #ifdef BSD
100 #define UNIX_DOMAIN_SOCKETS /* BSD systems use Unix Domain sockets by default */
101 #endif /* BSD */
102
103 #endif /* No communication method pre-defined */
104
105 #include <sys/types.h>
106 #include <sys/param.h>
107 #include <sys/stat.h>
108 #include <stdio.h>
109 #ifdef STDC_HEADERS
110 #include <stdlib.h>
111 #include <string.h>
112 #endif /* STDC_HEADERS */
113 #include <signal.h>
114 #include <errno.h>
115
116 #ifdef HAVE_UNISTD_H
117 #include <unistd.h>
118 #endif
119
120 #ifdef HAVE_SYS_TIME_H
121 #include <sys/time.h>
122 #endif
123
124 /*
125 * If you are using SYSV_IPC, you might want to make the buffer size bigger
126 * since it limits the size of requests and responses. Don't make it bigger
127 * than your system's max message size though (usually a couple of k) or else
128 * msgsend will start failing. For sockets, using the system BUFSIZ is usually
129 * what you want.
130 */
131
132 # define GSERV_BUFSZ BUFSIZ
133
134
135 #ifdef SYSV_IPC
136 #include <sys/ipc.h>
137 #include <sys/msg.h>
138
139 #define send_string(s,str) \
140 if (strlen(msgp->mtext) + strlen(str) < GSERV_BUFSZ) \
141 strcat(msgp->mtext,str); \
142 else \
143 { \
144 fprintf(stderr,"%s: not enough message buffer space\n",progname); \
145 exit(1); \
146 } \
147
148 #endif /* SYSV_IPC */
149
150 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
151 #include <sys/socket.h>
152 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
153
154 #ifdef INTERNET_DOMAIN_SOCKETS
155 #include <netdb.h>
156 #include <netinet/in.h>
157 #include <arpa/inet.h>
158 #define TABLE_SIZE 101 /* The number of entries in the hash table */
159 #define HASH(host) host /* Rather simplistic hash function */
160 #define DEFAULT_PORT 21490 /* default port number to use is
161 * DEFAULT_PORT + uid */
162 #endif /* INTERNET_DOMAIN_SOCKETS */
163
164 #ifdef UNIX_DOMAIN_SOCKETS
165 #include <sys/un.h>
166 #define HIDE_UNIX_SOCKET /* put the unix socket in a protected dir */
167 #endif /* UNIX_DOMAIN_SOCKETS */
168
169 /* On some platforms, we need to do the equivalent of "stty litout" to get
170 * characters like ^D to pass through to emacs. This problem has only
171 * been observed under emacs18; fsf19 and lemacs are probably okay without it.
172 */
173 #ifndef DONT_USE_LITOUT
174 #if !defined(HAVE_TERMIO) && !defined(HAVE_TERMIOS) && !defined(VMS)
175 #if !defined(MSDOS) && !defined(BSD4_1)
176 #define USE_LITOUT
177 #endif
178 #endif
179 #endif
180
181
182 #define HOSTNAMSZ 255 /* max size of a hostname */
183 #define REPLYSIZ 300 /* max size of reply from server to client */
184 #undef FALSE
185 #define FALSE 0
186 #undef TRUE
187 #define TRUE 1
188
189 extern char *getenv();
190 extern char *optarg;
191 extern int optind;
192 extern char *progname;
193
194 #ifndef BSD
195 extern char *getcwd();
196 #endif
197
198 /* The casts shut Sun's compiler up and are safe in the context these
199 are actually used. */
200 #define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y))
201 #define min2(x,y) (((int) (x) < (int) (y)) ? (x) : (y))
202
203 #ifndef _NFILE /* rough guess at maximum number of open files */
204 #define _NFILE 20
205 #endif
206
207 #define EOT_STR "\004"
208 #define EOT_CHR '\004'
209
210 /* connection types */
211 #define CONN_UNIX 0
212 #define CONN_INTERNET 1
213 #define CONN_IPC 2
214
215 /* function declarations */
216 extern int make_connection (char *hostarg, int portarg, int *s);
217 #ifdef SYSV_IPC
218 extern void disconnect_from_ipc_server();
219 #endif
220 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
221 extern void send_string (int s, CONST char *msg);
222 extern void disconnect_from_server (int s, int echo);
223 #endif
224 #ifdef INTERNET_DOMAIN_SOCKETS
225 extern int internet_addr (char *host);
226 #endif