fix #3869: outdated FSF address
[oweals/gnunet.git] / src / include / gnunet_service_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file include/gnunet_service_lib.h
23  * @brief functions related to starting services
24  * @author Christian Grothoff
25  * @defgroup service generic functions for implementing service processes
26  * @{
27  */
28
29 #ifndef GNUNET_SERVICE_LIB_H
30 #define GNUNET_SERVICE_LIB_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_server_lib.h"
42
43
44 /**
45  * Get the list of addresses that a server for the given service
46  * should bind to.
47  *
48  * @param service_name name of the service
49  * @param cfg configuration (which specifies the addresses)
50  * @param addrs set (call by reference) to an array of pointers to the
51  *              addresses the server should bind to and listen on; the
52  *              array will be NULL-terminated (on success)
53  * @param addr_lens set (call by reference) to an array of the lengths
54  *              of the respective `struct sockaddr` struct in the @a addrs
55  *              array (on success)
56  * @return number of addresses found on success,
57  *              #GNUNET_SYSERR if the configuration
58  *              did not specify reasonable finding information or
59  *              if it specified a hostname that could not be resolved;
60  *              #GNUNET_NO if the number of addresses configured is
61  *              zero (in this case, '* @a addrs' and '* @a addr_lens' will be
62  *              set to NULL).
63  */
64 int
65 GNUNET_SERVICE_get_server_addresses (const char *service_name,
66                                      const struct GNUNET_CONFIGURATION_Handle
67                                      *cfg, struct sockaddr ***addrs,
68                                      socklen_t **addr_lens);
69
70
71 /**
72  * Function called by the service's run
73  * method to run service-specific setup code.
74  *
75  * @param cls closure
76  * @param server the initialized server
77  * @param cfg configuration to use
78  */
79 typedef void
80 (*GNUNET_SERVICE_Main) (void *cls,
81                         struct GNUNET_SERVER_Handle *server,
82                         const struct GNUNET_CONFIGURATION_Handle *cfg);
83
84
85 /**
86  * Options for the service (bitmask).
87  */
88 enum GNUNET_SERVICE_Options
89 {
90   /**
91    * Use defaults.
92    */
93   GNUNET_SERVICE_OPTION_NONE = 0,
94
95   /**
96    * Do not trigger server shutdown on signals, allow for the user
97    * to terminate the server explicitly when needed.
98    */
99   GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1,
100
101   /**
102    * Trigger a SOFT server shutdown on signals, allowing active
103    * non-monitor clients to complete their transactions.
104    */
105   GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN = 2
106 };
107
108
109 /**
110  * Run a standard GNUnet service startup sequence (initialize loggers
111  * and configuration, parse options).
112  *
113  * @param argc number of command line arguments in @a argv
114  * @param argv command line arguments
115  * @param service_name our service name
116  * @param options service options
117  * @param task main task of the service
118  * @param task_cls closure for @a task
119  * @return #GNUNET_SYSERR on error, #GNUNET_OK
120  *         if we shutdown nicely
121  */
122 int
123 GNUNET_SERVICE_run (int argc, char *const *argv,
124                     const char *service_name,
125                     enum GNUNET_SERVICE_Options options,
126                     GNUNET_SERVICE_Main task,
127                     void *task_cls);
128
129
130 /**
131  * Opaque handle for a service.
132  */
133 struct GNUNET_SERVICE_Context;
134
135
136 /**
137  * Run a service startup sequence within an existing
138  * initialized system.
139  *
140  * @param service_name our service name
141  * @param cfg configuration to use
142  * @param options service options
143  * @return NULL on error, service handle
144  */
145 struct GNUNET_SERVICE_Context *
146 GNUNET_SERVICE_start (const char *service_name,
147                       const struct GNUNET_CONFIGURATION_Handle *cfg,
148                       enum GNUNET_SERVICE_Options options);
149
150
151 /**
152  * Obtain the server used by a service.  Note that the server must NOT
153  * be destroyed by the caller.
154  *
155  * @param ctx the service context returned from the start function
156  * @return handle to the server for this service, NULL if there is none
157  */
158 struct GNUNET_SERVER_Handle *
159 GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx);
160
161
162 /**
163  * Get the NULL-terminated array of listen sockets for this service.
164  *
165  * @param ctx service context to query
166  * @return NULL if there are no listen sockets, otherwise NULL-terminated
167  *              array of listen sockets.
168  */
169 struct GNUNET_NETWORK_Handle *const *
170 GNUNET_SERVICE_get_listen_sockets (struct GNUNET_SERVICE_Context *ctx);
171
172
173 /**
174  * Stop a service that was started with #GNUNET_SERVICE_start.
175  *
176  * @param sctx the service context returned from the start function
177  */
178 void
179 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx);
180
181
182 #if 0                           /* keep Emacsens' auto-indent happy */
183 {
184 #endif
185 #ifdef __cplusplus
186 }
187 #endif
188
189
190 /** @} */ /* end of group service */
191
192
193 /* ifndef GNUNET_SERVICE_LIB_H */
194 #endif
195 /* end of gnunet_service_lib.h */