home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / nsfast / root.9 / usr / ns-home / nsapi / include / base / daemon.h / daemon
Text File  |  1998-08-19  |  6KB  |  249 lines

  1. /*
  2.  * Copyright (c) 1994, 1995.  Netscape Communications Corporation.  All
  3.  * rights reserved.
  4.  * 
  5.  * Use of this software is governed by the terms of the license agreement for
  6.  * the Netscape FastTrack or Netscape Enterprise Server between the
  7.  * parties.
  8.  */
  9.  
  10.  
  11. /* ------------------------------------------------------------------------ */
  12.  
  13.  
  14. /*
  15.  * daemon.h: Things related to the accepting connections
  16.  * 
  17.  * Rob McCool
  18.  */
  19.  
  20.  
  21. #ifndef DAEMON_H
  22. #define DAEMON_H
  23.  
  24. #include "net.h"
  25. #include "session.h"
  26.  
  27. #ifdef XP_UNIX
  28. #include <pwd.h>    /* struct passwd */
  29. #endif /* XP_UNIX */
  30.  
  31.  
  32. /* ------------------------------- Defines -------------------------------- */
  33.  
  34.  
  35. NSAPI_PUBLIC void child_exit(int status);
  36.  
  37.  
  38. /* Codes for child_status */
  39. #define CHILD_EMPTY_SLOT 0xfe
  40. #define CHILD_AWAIT_CONNECT 0xff
  41. #define CHILD_PROCESSING 0x00
  42. #define CHILD_READING 0x01
  43. #define CHILD_WRITING 0x02
  44. #define CHILD_RESOLVING 0x03
  45. #define CHILD_KEEPALIVE_LISTEN 0x04
  46. #define CHILD_KEEPALIVE_ACCEPT 0x05
  47. #ifdef XP_WIN32
  48. /* Need completors to handle async IO */
  49. #define CHILD_DONE_PROCESSING 0x14
  50. #define CHILD_DONE_READING 0x15
  51. #define CHILD_DONE_WRITING 0x16
  52. #define CHILD_DONE_RESOLVING 0x17
  53. #endif
  54.  
  55. #ifdef XP_WIN32 
  56. #define MAX_IP_DOMAINS 256
  57. struct _multiple_domains {
  58.     char *address;
  59.     char *docroot;
  60.     SYS_NETFD sd;
  61.     int threads;
  62.     int AddressNumber;
  63. };
  64. typedef struct _multiple_domains multiple_domains;
  65.  
  66. /* array of address-docroot mappings */
  67. extern multiple_domains domain_array[];
  68.  
  69. #endif /* XP_WIN32 */
  70.  
  71.  
  72. /* #ifdef DAEMON_STATS */
  73.  
  74. #define DSTATS_MAJOR_VERSION        (char)0x1
  75. #define DSTATS_MINOR_VERSION        (char)0x0
  76.  
  77. #define DSTATS_SOFTWARE_ENTERPRICE    (char)0x1
  78. #define DSTATS_SOFTWARE_PERSONAL    (char)0x2
  79. #define DSTATS_SOFTWARE_PROXY        (char)0x3
  80. #define DSTATS_SOFTWARE_NEWS        (char)0x4
  81.  
  82. #define DSTATS_FILE            "daemonstat."
  83.  
  84. typedef struct _StatHeader {
  85.     int  header_size;        /* sizeof StatHeader */
  86.     int  slot_size;        /* sizeof StatSlot */
  87.     char software;
  88.     char version_major;
  89.     char version_minor;
  90.     char active;
  91.     char pad1[2 * sizeof(long) - 4 * sizeof(char)];
  92.     int  restart_cookie;    /* changing restart counter */
  93.     int  maxprocs;        /* current MaxProcs */
  94.     int  maxthreads;        /* current MaxThreads */
  95.     char pad2[2 * sizeof(long) - sizeof(int)];
  96.     long start_time;
  97. } StatHeader;
  98.  
  99. typedef struct _StatSlot {
  100.     char mode;
  101.     char pad[sizeof(long) - sizeof(char)];
  102.  
  103.     long tot_bytes;
  104.     long tot_reqs;
  105.     long tot_errs;
  106.  
  107.     long tot_2xx;
  108.     long tot_3xx;
  109.     long tot_4xx;
  110.     long tot_5xx;
  111.     long tot_xxx;
  112.  
  113.     long tot_200;
  114.     long tot_302;
  115.     long tot_304;
  116.     long tot_401;
  117.     long tot_403;
  118. #ifdef XP_WIN32
  119.     long state_counts[CHILD_RESOLVING+1];    /* for threads handling many reqs */
  120.     long cur_async_io;        /* current async IO requests */
  121.     long tot_async_io;        /* total async IO requests */
  122. #endif
  123. } StatSlot;
  124. /* #endif */
  125.  
  126.  
  127. #ifdef DAEMON_STATS
  128.  
  129. void child_status2(int http_status, long bytes);
  130.  
  131. #endif /* DAEMON_STATS */
  132.  
  133.  
  134. typedef struct {
  135.     char *ipstr;
  136.     int port;
  137. #if defined (XP_UNIX)
  138.     struct passwd *pw;
  139.     char *chr;
  140.     char *pidfn;
  141. #elif defined (XP_WIN32)
  142.     void(*child_callback)(Session *);
  143.     void(*rotate_callback)();
  144.     char *servid;
  145.     multiple_domains *domains;
  146. #endif /* XP_WIN32 */
  147.     void (*rcback)(int);
  148. #if defined(DAEMON_UNIX_MOBRULE) || defined(DAEMON_WIN32)
  149.     int maxprocs, minprocs, proclife;
  150. #endif
  151. #if defined (THREAD_ANY) || defined (THREAD_WIN32)
  152.     int maxthreads, minthreads;
  153. #endif
  154. #ifdef NET_SSL
  155.     char *secure_keyfn;
  156.     char *secure_certfn;
  157.     int secure_auth;
  158.     int secure_session_timeout;
  159.     long ssl3_secure_session_timeout;
  160.     int security;
  161.     int ssl3;
  162.     int ssl2;
  163. #endif
  164.     int single_accept;
  165.     int num_keep_alives;
  166.     int mp_optimization;
  167.     int concurrency;
  168. } daemon_s;
  169.  
  170. #define SINGLE_ACCEPT_NONE        -1        /* uninitialized state */
  171. #define SINGLE_ACCEPT_OFF        0
  172. #define SINGLE_ACCEPT_ON        1
  173. #define SINGLE_ACCEPT_PARTIAL    2        /* do mutex but not file lock */
  174.  
  175. /* ------------------------------ Prototypes ------------------------------ */
  176.  
  177. #ifdef MCC_PROXY
  178. /* A unique serial number assigned to each child. */
  179. extern int child_serial;
  180. #endif
  181.  
  182. /*
  183.  * daemon_run accepts whether or not it should detach from its parent process,
  184.  * and a daemon structure as its arguments. The daemon structure contains 
  185.  * a port number, a root directory to chroot to (can be NULL), a filename to 
  186.  * log the daemon pid to (can be NULL). daemon_run never returns.
  187.  * 
  188.  * child_callback is a function which will be called every time a new
  189.  * connection is recieved. Session is a new session ID.
  190.  *
  191.  * rcback is a function which is a restart function: When SIGHUP is received,
  192.  * this function will be called. You may give SIG_DFL if you don't want to
  193.  * support restarting. The rcback will be passed SIGHUP.
  194.  *
  195.  * pw is the passwd entry to run the daemon as. If the effective user id is
  196.  * root, daemon_run will try to set its uid and gid to the user pointed
  197.  * to by this structure. You may pass NULL.
  198.  */
  199.  
  200. #ifdef XP_UNIX
  201. NSAPI_PUBLIC
  202. void daemon_run(int det, void (*child_callback)(Session *), daemon_s *d);
  203. #else /* XP_WIN32 */
  204. #if defined (USE_NSPR) && !defined (NO_NSPR_THREADS)
  205. NSAPI_PUBLIC void _ntdaemon_run(void *);
  206. #else /* !USE_NSPR || NO_NSPR_THREADS */
  207. NSAPI_PUBLIC unsigned  int __stdcall _ntdaemon_run(void *);
  208. #endif /* !USE_NSPR || NO_NSPR_THREADS */
  209. #endif /* XP_WIN32 */
  210.  
  211.  
  212. /*
  213.  * daemon_atrestart registers a function to be called fn, with the given
  214.  * void pointer as an argument, when the server is restarted.
  215.  */
  216.  
  217. NSAPI_PUBLIC void daemon_atrestart(void (*fn)(void *), void *data);
  218.  
  219.  
  220.  
  221. /*
  222.  * fork is a wrapper for the system's fork function. This closes the listen
  223.  * socket for the mob. This also makes sure that a threaded daemon only gets
  224.  * the calling thread and not all of them.
  225.  */
  226.  
  227. NSAPI_PUBLIC pid_t child_fork(void);
  228.  
  229.  
  230. /*
  231.  * Set status to the given code for statistics reporting
  232.  */
  233.  
  234. #ifdef DAEMON_STATS
  235. NSAPI_PUBLIC void child_status(int code);
  236. #else /* ! DAEMON_STATS */
  237. #define child_status(code) (void)(code)
  238. #endif /* DAEMON_STATS */
  239.  
  240. /* servssl_init is in base/servssl.c */
  241. #ifdef NET_SSL
  242. NSAPI_PUBLIC 
  243. void servssl_init(char *keyfn, char *certfn, int stimeout, long ssl3timeout,
  244.           char *servid);
  245.  
  246. #endif /* NET_SSL */
  247.  
  248. #endif
  249.