missing changes to headers
[oweals/gnunet.git] / src / include / gnunet_psyc_util_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012, 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_psyc_service.h
23  * @brief PSYC utilities; receiving/transmitting/logging PSYC messages.
24  * @author Gabor X Toth
25  */
26
27 #ifndef GNUNET_PSYC_UTIL_LIB_H
28 #define GNUNET_PSYC_UTIL_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_util_lib.h"
39 #include "gnunet_env_lib.h"
40 #include "gnunet_psyc_service.h"
41
42
43 /**
44  * Create a PSYC message.
45  *
46  * @param method_name
47  *        PSYC method for the message.
48  * @param env
49  *        Environment for the message.
50  * @param data
51  *        Data payload for the message.
52  * @param data_size
53  *        Size of @a data.
54  *
55  * @return Message header with size information,
56  *         followed by the message parts.
57  */
58 struct GNUNET_PSYC_Message *
59 GNUNET_PSYC_message_create (const char *method_name,
60                             const struct GNUNET_ENV_Environment *env,
61                             const void *data,
62                             size_t data_size);
63
64 /**
65  * Parse PSYC message.
66  *
67  * @param msg
68  *        The PSYC message to parse.
69  * @param env
70  *        The environment for the message with a list of modifiers.
71  * @param[out] method_name
72  *        Pointer to the method name inside @a pmsg.
73  * @param[out] data
74  *        Pointer to data inside @a pmsg.
75  * @param[out] data_size
76  *        Size of @data is written here.
77  *
78  * @return #GNUNET_OK on success,
79  *         #GNUNET_SYSERR on parse error.
80  */
81 int
82 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg,
83                            const char **method_name,
84                            struct GNUNET_ENV_Environment *env,
85                            const void **data,
86                            uint16_t *data_size);
87
88
89 void
90 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
91                          const struct GNUNET_MessageHeader *msg);
92
93
94 int
95 GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data,
96                                  uint16_t *first_ptype, uint16_t *last_ptype);
97
98
99 struct GNUNET_PSYC_TransmitHandle;
100
101 /**
102  * Create a transmission handle.
103  */
104 struct GNUNET_PSYC_TransmitHandle *
105 GNUNET_PSYC_transmit_create ();
106
107
108 /**
109  * Destroy a transmission handle.
110  */
111 void
112 GNUNET_PSYC_transmit_destroy (struct GNUNET_PSYC_TransmitHandle *tmit);
113
114
115 /**
116  * Transmit a message.
117  *
118  * @param tmit
119  *        Transmission handle.
120  * @param method_name
121  *        Which method should be invoked.
122  * @param env
123  *        Environment for the message.
124  *        Should stay available until the first call to notify_data.
125  *        Can be NULL if there are no modifiers or @a notify_mod is
126  *        provided instead.
127  * @param notify_mod
128  *        Function to call to obtain modifiers.
129  *        Can be NULL if there are no modifiers or @a env is provided instead.
130  * @param notify_data
131  *        Function to call to obtain fragments of the data.
132  * @param notify_cls
133  *        Closure for @a notify_mod and @a notify_data.
134  * @param flags
135  *        Flags for the message being transmitted.
136  *
137  * @return #GNUNET_OK if the transmission was started.
138  *         #GNUNET_SYSERR if another transmission is already going on.
139  */
140 int
141 GNUNET_PSYC_transmit_message (struct GNUNET_PSYC_TransmitHandle *tmit,
142                               const char *method_name,
143                               const struct GNUNET_ENV_Environment *env,
144                               GNUNET_PSYC_TransmitNotifyModifier notify_mod,
145                               GNUNET_PSYC_TransmitNotifyData notify_data,
146                               void *notify_cls,
147                               uint32_t flags);
148
149
150 /**
151  * Resume transmission.
152  *
153  * @param tmit  Transmission handle.
154  */
155 void
156 GNUNET_PSYC_transmit_resume (struct GNUNET_PSYC_TransmitHandle *tmit);
157
158
159 /**
160  * Abort transmission request.
161  *
162  * @param tmit  Transmission handle.
163  */
164 void
165 GNUNET_PSYC_transmit_cancel (struct GNUNET_PSYC_TransmitHandle *tmit);
166
167
168 /**
169  * Got acknowledgement of a transmitted message part, continue transmission.
170  *
171  * @param tmit  Transmission handle.
172  */
173 void
174 GNUNET_PSYC_transmit_got_ack (struct GNUNET_PSYC_TransmitHandle *tmit);
175
176
177 struct GNUNET_PSYC_ReceiveHandle;
178
179
180 /**
181  * Create handle for receiving messages.
182  */
183 struct GNUNET_PSYC_ReceiveHandle *
184 GNUNET_PSYC_receive_create (GNUNET_PSYC_MessageCallback message_cb,
185                             GNUNET_PSYC_MessagePartCallback message_part_cb,
186                             void *cb_cls);
187
188
189 /**
190  * Destroy handle for receiving messages.
191  */
192 void
193 GNUNET_PSYC_receive_destroy (struct GNUNET_PSYC_ReceiveHandle *recv);
194
195
196 /**
197  * Reset stored data related to the last received message.
198  */
199 void
200 GNUNET_PSYC_receive_reset (struct GNUNET_PSYC_ReceiveHandle *recv);
201
202
203 /**
204  * Handle incoming PSYC message.
205  *
206  * @param recv  Receive handle.
207  * @param msg   The message.
208  *
209  * @return #GNUNET_OK on success,
210  *         #GNUNET_SYSERR on receive error.
211  */
212 int
213 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
214                              const struct GNUNET_PSYC_MessageHeader *msg);
215
216
217 /**
218  * Check if @a data contains a series of valid message parts.
219  *
220  * @param      data_size    Size of @a data.
221  * @param      data         Data.
222  * @param[out] first_ptype  Type of first message part.
223  * @param[out] last_ptype   Type of last message part.
224  *
225  * @return Number of message parts found in @a data.
226  *         or GNUNET_SYSERR if the message contains invalid parts.
227  */
228 int
229 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
230                                  uint16_t *first_ptype, uint16_t *last_ptype);
231
232
233 /**
234  * Initialize PSYC message header.
235  */
236 void
237 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
238                                  const struct GNUNET_MULTICAST_MessageHeader *mmsg,
239                                  uint32_t flags);
240
241
242 /**
243  * Create a new PSYC message header from a multicast message for sending it to clients.
244  */
245 struct GNUNET_PSYC_MessageHeader *
246 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
247                                    uint32_t flags);
248
249
250 #if 0                           /* keep Emacsens' auto-indent happy */
251 {
252 #endif
253 #ifdef __cplusplus
254 }
255 #endif
256
257 /* ifndef GNUNET_PSYC_UTIL_LIB_H */
258 #endif
259 /* end of gnunet_psyc_util_lib.h */