- remove regex integration from mesh2
[oweals/gnunet.git] / src / include / gnunet_helper_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2011, 2012 Christian Grothoff
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_helper_lib.h
23  * @brief API for dealing with (SUID) helper processes that communicate via GNUNET_MessageHeaders on stdin/stdout
24  * @author Philipp Toelke
25  * @author Christian Grothoff
26  */
27
28 #ifndef GNUNET_HELPER_LIB_H
29 #define GNUNET_HELPER_LIB_H
30
31 #include "gnunet_scheduler_lib.h"
32 #include "gnunet_server_lib.h"
33
34 /**
35  * The handle to a helper process.
36  */
37 struct GNUNET_HELPER_Handle;
38
39
40 /**
41  * Callback that will be called when the helper process dies. This is not called
42  * when the helper process is stoped using GNUNET_HELPER_stop()
43  *
44  * @param cls the closure from GNUNET_HELPER_start()
45  */
46 typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls);
47
48
49 /**
50  * Starts a helper and begins reading from it. The helper process is
51  * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
52  * or when the exp_cb callback is not NULL.
53  *
54  * @param with_control_pipe does the helper support the use of a control pipe for signalling?
55  * @param binary_name name of the binary to run
56  * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this
57  *                    argument must not be modified by the client for
58  *                     the lifetime of the helper handle)
59  * @param cb function to call if we get messages from the helper
60  * @param exp_cb the exception callback to call. Set this to NULL if the helper
61  *          process has to be restarted automatically when it dies/crashes
62  * @param cb_cls closure for the above callbacks
63  * @return the new Handle, NULL on error
64  */
65 struct GNUNET_HELPER_Handle *
66 GNUNET_HELPER_start (int with_control_pipe,
67                      const char *binary_name,
68                      char *const binary_argv[],
69                      GNUNET_SERVER_MessageTokenizerCallback cb,
70                      GNUNET_HELPER_ExceptionCallback exp_cb,
71                      void *cb_cls);
72
73
74 /**
75  * Kills the helper, closes the pipe and frees the handle
76  *
77  * @param h handle to helper to stop
78  */
79 void
80 GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h);
81
82
83 /**
84  * Kills the helper by closing its stdin (the helper is expected to catch the
85  * resulting SIGPIPE and shutdown), closes the pipe and frees the handle
86  *
87  * @param h handle to helper to stop
88  */
89 void
90 GNUNET_HELPER_soft_stop (struct GNUNET_HELPER_Handle *h);
91
92
93 /**
94  * Continuation function.
95  * 
96  * @param cls closure
97  * @param result GNUNET_OK on success,
98  *               GNUNET_NO if helper process died
99  *               GNUNET_SYSERR during GNUNET_HELPER_stop
100  */
101 typedef void (*GNUNET_HELPER_Continuation)(void *cls,
102                                            int result);
103
104
105 /**
106  * Handle to cancel 'send'
107  */
108 struct GNUNET_HELPER_SendHandle;
109
110
111 /**
112  * Send an message to the helper.
113  *
114  * @param h helper to send message to
115  * @param msg message to send
116  * @param can_drop can the message be dropped if there is already one in the queue?
117  * @param cont continuation to run once the message is out
118  * @param cont_cls closure for 'cont'
119  * @return NULL if the message was dropped, 
120  *         otherwise handle to cancel *cont* (actual transmission may
121  *         not be abortable)
122  */
123 struct GNUNET_HELPER_SendHandle *
124 GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 
125                     const struct GNUNET_MessageHeader *msg,
126                     int can_drop,
127                     GNUNET_HELPER_Continuation cont,
128                     void *cont_cls);
129
130
131 /**
132  * Cancel a 'send' operation.  If possible, transmitting the
133  * message is also aborted, but at least 'cont' won't be
134  * called.
135  *
136  * @param sh operation to cancel
137  */
138 void
139 GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
140
141 #endif /* end of include guard: GNUNET_HELPER_LIB_H */