home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnusrvr2.zip / gnuserv.h < prev    next >
C/C++ Source or Header  |  1997-05-13  |  6KB  |  225 lines

  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. static char header_rcsid [] = "$Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup alpha $";
  34.  
  35. #define NO_SHORTNAMES
  36.  
  37. #define PATCHLEVEL 2
  38.  
  39. #define NO_SHORTNAMES
  40. /* XXX change to "../src/config.h" if included with emacs */
  41. #include <config.h>
  42. #undef read
  43. #undef write
  44. #undef open
  45. #undef close
  46. #undef signal
  47.  
  48. /* Define the communication method between server and clients:
  49.  *   You can have either or both kinds of sockets, but you can't mix
  50.  *   sockets with sysv ipc
  51.  */
  52.  
  53.  
  54. #define INTERNET_DOMAIN_SOCKETS
  55. /* #define UNIX_DOMAIN_SOCKETS */
  56. /* #define SYSV_IPC */
  57.  
  58. /*
  59.  * Define additional authentication protocols to be used. These methods will
  60.  * be tried before falling back to the default gnuserv protocol (based on
  61.  * the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1
  62.  * is also supported.
  63.  *
  64.  * Comment out the next line(s) if you don't want to enable the
  65.  * appropriate authentication protocol.
  66.  */
  67.  
  68. /*
  69. #define AUTH_MAGIC_COOKIE 
  70. */
  71.  
  72. /*
  73.  * stuff related to supporting MIT-MAGIC-COOKIE-1
  74.  */
  75.  
  76. #define MCOOKIE_SCREEN "999"     /* screen # to use as the gnuserv cookie */
  77. #define MCOOKIE_NAME   "MAGIC-1" /* authentication protocol name */
  78. #define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1"  /* as needed by X */
  79.  
  80. #define DEFAUTH_NAME "GNU-SECURE"  /* name of default auth protocol */
  81. #define AUTH_TIMEOUT  15           /* # seconds to wait for auth data */
  82. #define AUTH_NAMESZ   15           /* max allows auth protocol name size */
  83.  
  84.  
  85. /*
  86.  * Pick a default communication scheme, if none was specified.
  87.  */
  88.  
  89. #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
  90.  
  91. #ifdef HAVE_SYSVIPC
  92. #define SYSV_IPC        /* SYSV systems use SYSV IPC by default */
  93. #endif /* HAVE_SYSVIPC */
  94.  
  95. #ifdef BSD
  96. #define UNIX_DOMAIN_SOCKETS    /* BSD systems use Unix Domain sockets by default */
  97. #endif /* BSD */
  98.  
  99. #endif /* No communication method pre-defined */
  100.  
  101. #include <sys/types.h>
  102. #include <sys/param.h>
  103. #include <sys/stat.h>
  104. #include <stdio.h>
  105. #ifdef STDC_HEADERS
  106. #include <stdlib.h>
  107. #include <string.h>
  108. /* This next one is picked up from FSF gnu-emacs v19's regex.c ... */
  109. # ifndef bcmp
  110. #  define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
  111. # endif
  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. #define max2(x,y) (((x) > (y)) ? (x) : (y))
  199. #define min2(x,y) (((x) < (y)) ? (x) : (y))
  200.  
  201. #ifndef _NFILE            /* rough guess at maximum number of open files */
  202. #define _NFILE 20
  203. #endif
  204.  
  205. #define EOT_STR "\004"
  206. #define EOT_CHR '\004'
  207.  
  208. /* connection types */
  209. #define CONN_UNIX     0
  210. #define CONN_INTERNET 1
  211. #define CONN_IPC      2
  212.  
  213. /* function declarations */
  214. extern int make_connection();
  215. #ifdef SYSV_IPC
  216. extern void disconnect_from_ipc_server();
  217. #endif
  218. #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
  219. extern void send_string();
  220. extern void disconnect_from_server();
  221. #endif
  222. #ifdef INTERNET_DOMAIN_SOCKETS
  223. extern int internet_addr();
  224. #endif
  225.