2 * (c) Copyright 1992 by Panagiotis Tsirigotis
3 * (c) Sections Copyright 1998-2001 by Rob Braun
4 * All rights reserved. The file named COPYRIGHT specifies the terms
5 * and conditions for redistribution.
12 #include <sys/types.h>
13 #include <netinet/in.h>
22 * $Id: service.h,v 1.5 2005/03/29 15:50:34 bbraun Exp $
28 * NOTE: A service can be disabled but not deleted if it has any servers
31 typedef enum /* service states */
33 SVC_NOT_STARTED = 0, /* no attempt to start it yet */
34 SVC_ACTIVE, /* service is available */
35 SVC_SUSPENDED, /* service is suspended */
36 SVC_DISABLED /* service disabled */
41 * NOTE: Clearing the structure will give all its fields their default values
46 int svc_ref_count ; /* # of pters to this struct */
47 struct service_config *svc_conf ; /* service configuration */
48 int svc_fd ; /* The Listening FD for the service */
49 unsigned svc_running_servers ;
50 unsigned svc_retry_servers ;
51 unsigned svc_attempts ; /* # of attempts to start server */
52 int svc_not_generic ; /* 1 spec_service, 0 generic */
55 * These fields are used to avoid generating too many messages when
56 * receiving datagrams from a bad address.
58 union xsockaddr *svc_last_dgram_addr ;
59 time_t svc_last_dgram_time ;
64 #define SP( p ) ( (struct service *) (p) )
65 #define SUSPEND( sp ) (sp)->svc_state = SVC_SUSPENDED
66 #define RESUME( sp ) (sp)->svc_state = SVC_ACTIVE
72 #define SVC_CONF( sp ) ( (sp)->svc_conf )
73 #define SVC_FD( sp ) ( (sp)->svc_fd )
74 #define SVC_RUNNING_SERVERS( sp ) (sp)->svc_running_servers
75 #define SVC_RETRIES( sp ) (sp)->svc_retry_servers
76 #define SVC_LOG( sp ) (sp)->svc_log
77 #define SVC_REFCOUNT( sp ) (sp)->svc_ref_count
78 #define SVC_ID( sp ) SC_ID( SVC_CONF( sp ) )
79 #define SVC_SOCKET_TYPE( sp ) SC_SOCKET_TYPE( SVC_CONF( sp ) )
80 #define SVC_STATE( sp ) (sp)->svc_state
81 #define SVC_ATTEMPTS( sp ) (sp)->svc_attempts
82 #define SVC_LAST_DGRAM_ADDR( sp ) (sp)->svc_last_dgram_addr
83 #define SVC_LAST_DGRAM_TIME( sp ) (sp)->svc_last_dgram_time
84 #define SVC_NOT_GENERIC( sp ) (sp)->svc_not_generic
86 #define SVC_IS_ACTIVE( sp ) ( (sp)->svc_state == SVC_ACTIVE )
87 #define SVC_IS_SUSPENDED( sp ) ( (sp)->svc_state == SVC_SUSPENDED )
88 #define SVC_IS_AVAILABLE( sp ) ( SVC_IS_ACTIVE(sp) || SVC_IS_SUSPENDED(sp) )
89 #define SVC_IS_DISABLED( sp ) ( (sp)->svc_state == SVC_DISABLED )
90 #define SVC_IS_MUXCLIENT( sp ) ( SC_IS_MUXCLIENT( SVC_CONF ( sp ) ) )
91 #define SVC_IS_MUXPLUSCLIENT(sp) ( SC_IS_MUXPLUSCLIENT( SVC_CONF ( sp ) ) )
92 #define SVC_IS_TCPMUX( sp ) ( SC_IS_TCPMUX( SVC_CONF ( sp ) ) )
94 #define TCPMUX_ACK "+Go\r\n"
96 * Predicate checking macros
98 #define SVC_FORKS( sp ) SC_FORKS( SVC_CONF( sp ) )
99 #define SVC_RETRY( sp ) SC_RETRY( SVC_CONF( sp ) )
100 #define SVC_WAITS( sp ) SC_WAITS( SVC_CONF( sp ) )
101 #define SVC_IS_INTERCEPTED( sp ) SC_IS_INTERCEPTED( SVC_CONF( sp ) )
102 #define SVC_ACCEPTS_CONNECTIONS( sp ) \
103 SC_ACCEPTS_CONNECTIONS( SVC_CONF( sp ) )
105 #define SVC_IS_LOGGING( sp ) ( (sp)->svc_log != NULL )
106 #define SVC_LOGS_ON_SUCCESS( sp ) \
107 ( SVC_IS_LOGGING( sp ) && SC_LOGS_ON_SUCCESS( SVC_CONF( sp ) ) )
108 #define SVC_LOGS_ON_FAILURE( sp ) \
109 ( SVC_IS_LOGGING( sp ) && SC_LOGS_ON_FAILURE( SVC_CONF( sp ) ) )
110 #define SVC_LOGS_ON_EXIT( sp ) \
111 ( SVC_IS_LOGGING( sp ) && SC_LOGS_ON_EXIT( SVC_CONF( sp ) ) )
112 #define SVC_LOGS_USERID_ON_SUCCESS( sp ) \
113 ( SVC_IS_LOGGING( sp ) && SC_LOGS_USERID_ON_SUCCESS( SVC_CONF( sp ) ) )
114 #define SVC_LOGS_USERID_ON_FAILURE( sp ) \
115 ( SVC_IS_LOGGING( sp ) && SC_LOGS_USERID_ON_FAILURE( SVC_CONF( sp ) ) )
118 * Reference counting macros
120 #define SVC_HOLD( sp ) (sp)->svc_ref_count++
121 #define SVC_RELE( sp ) ( --(sp)->svc_ref_count )
124 #define SVC_INTERNAL( sp, serp ) SC_INTERNAL( SVC_CONF( sp ), serp )
125 #define SVC_MAKE_EXTERNAL( sp ) SC_MAKE_EXTERNAL( SVC_CONF( sp ) )
127 #define SVC_DEC_RUNNING_SERVERS( sp ) \
129 if ( SVC_RUNNING_SERVERS( sp ) != 0 ) \
130 (sp)->svc_running_servers-- ; \
132 msg( LOG_ERR, func, \
133 "Service %s: server exit with 0 running servers", SVC_ID( sp ) ) ;\
136 #define SVC_INC_RUNNING_SERVERS( sp ) (sp)->svc_running_servers++
138 #define SVC_INC_RETRIES( sp ) (sp)->svc_retry_servers++
139 #define SVC_DEC_RETRIES( sp ) (sp)->svc_retry_servers--
141 struct service *svc_new(struct service_config *scp);
142 struct service *svc_make_special(struct service_config *scp);
143 void svc_free(struct service *sp);
144 status_e svc_activate(struct service *sp);
145 void svc_deactivate(struct service *sp);
146 void svc_suspend(struct service *sp);
147 void svc_resume(struct service *sp);
148 int svc_release(struct service *sp);
149 void svc_dump(const struct service *sp,int fd);
150 void svc_request(struct service *sp);
151 status_e svc_generic_handler( struct service *sp, connection_s *cp );
152 status_e svc_parent_access_control(struct service *sp,connection_s *cp);
153 status_e svc_child_access_control(struct service *sp,connection_s *cp);
154 void svc_postmortem(struct service *sp,struct server *serp);
155 void close_all_svc_descriptors(void);
157 #endif /* SERVICE_H */