home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / xinetd.2.0.6 / service.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  3.1 KB  |  116 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef SERVICE_H
  8. #define SERVICE_H
  9.  
  10. /*
  11.  * $Id: service.h,v 5.1 1992/10/31 23:59:07 panos Exp $
  12.  */
  13.  
  14. #ifndef NO_POSIX_TYPES
  15. #include <sys/types.h>        /* for pid_t */
  16. #else
  17. typedef int pid_t ;
  18. #endif
  19.  
  20. #include "xlog.h"
  21.  
  22. #include "defs.h"
  23. #include "sconf.h"
  24. #include "builtin.h"
  25.  
  26.  
  27. /*
  28.  * This struct holds data for an active service
  29.  *
  30.  * There are 3 function pointers:
  31.  *
  32.  *        post_mortem:    invoked when a server exits
  33.  *        shutdown:        invoked to playback the protocol and get information
  34.  *                            from the other end. It also sets up the connection
  35.  *                            for an orderly close.
  36.  */
  37. struct service_data
  38. {
  39.     int service_fd ;
  40.     unsigned running_servers ;
  41.     unsigned retry_servers ;
  42.     unsigned attempts ;                /* # of attempts to start a server        */
  43.     time_t start_time ;                /* since this time                            */
  44.     voidfunc postmortem ;             /* ARGS: struct server *                    */ 
  45.     voidfunc shutdown ;                /* ARGS: int sd, char **msgp                */
  46.     status_e (*handler)() ;            /* ARGS: service *, connection *            */
  47.     pset_h no_access ;
  48.     pset_h only_from ;
  49.     xlog_h log_handle ;
  50. } ;
  51.  
  52.  
  53. /*
  54.  * NOTE: A service can be disabled but not deleted if it has any servers
  55.  *       running
  56.  */
  57. typedef enum                     /* service states */
  58.    {
  59.       SVC_NOT_STARTED = 0,       /* no attempt to start it yet       */
  60.       SVC_ACTIVE,                /* service is available             */
  61.         SVC_SUSPENDED,                    /* service is suspended                    */
  62.       SVC_DISABLED               /* service disabled                 */
  63.    } state_e ;
  64.  
  65.  
  66.  
  67. /*
  68.  * NOTE: Clearing the structure will give all its fields their default values
  69.  */
  70. struct service
  71. {
  72.     state_e state ;
  73.     int ref_count ;                            /* number of pointers to this service */
  74.     struct builtin_service *builtin ;
  75.     struct service_config conf ;
  76.     struct service_data sd ;
  77. } ;
  78.  
  79. #define IS_ACTIVE( sp )                ( (sp)->state == SVC_ACTIVE )
  80. #define IS_SUSPENDED( sp )            ( (sp)->state == SVC_SUSPENDED )
  81. #define IS_AVAILABLE( sp )            ( IS_ACTIVE( sp ) || IS_SUSPENDED( sp ) )
  82.  
  83. #define SVC_HOLD( sp )                (sp)->ref_count++
  84. #define SVC_RELE( sp )    \
  85.     ( ( (sp)->ref_count <= 1 ) ? svc_release( sp ) : --(sp)->ref_count )
  86.  
  87. #define SP( p )                        ( (struct service *) (p) )
  88.  
  89. #define CONF( sp )                    ( &(sp)->conf )
  90. #define SDATA( sp )                    ( &(sp)->sd )
  91. #define SVC_FORKS( sp )                ( ! IS_INTERNAL( CONF( sp ) ) ||             \
  92.                                                         (sp)->builtin->fork_server == YES )
  93. #define SVC_IS_LOGGING( sp )        ( SDATA( sp )->log_handle )
  94. #define SVC_FD( sp )                    ( SDATA( sp )->service_fd )
  95. #define SVC_RETRY( sp )                ( M_IS_CLEAR( CONF(sp)->flags, SF_NORETRY ) )
  96. #define SVC_HANDLE( sp, cp )        (*SDATA( sp )->handler)( sp, cp )
  97.  
  98. #define INTERCEPT_SERVICE_NAME    "intercept"
  99.  
  100. status_e svc_init() ;
  101. struct service *svc_new() ;
  102. struct service *svc_alloc() ;
  103. void svc_free() ;
  104. status_e svc_activate() ;
  105. void svc_setup_address_control() ;
  106. void svc_deactivate() ;
  107. void svc_suspend() ;
  108. void svc_resume() ;
  109. int svc_release() ;
  110. void svc_dump() ;
  111. void svc_request() ;
  112. status_e svc_access_control() ;
  113. void svc_shutdown() ;
  114.  
  115. #endif    /* SERVICE_H */
  116.