glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / include / gnunet_psyc_message.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012, 2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14 */
15
16 /**
17  * @author Gabor X Toth
18  *
19  * @file
20  * PSYC message utilities; receiving/transmitting/logging PSYC messages
21  *
22  * @defgroup psyc-util-message  PSYC Utilities library: Messages
23  * Receiving, transmitting, logging PSYC messages.
24  * @{
25  */
26
27 #ifndef GNUNET_PSYC_MESSAGE_H
28 #define GNUNET_PSYC_MESSAGE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38
39 #include "gnunet_util_lib.h"
40 #include "gnunet_psyc_util_lib.h"
41 #include "gnunet_psyc_service.h"
42
43
44 /**
45  * Create a PSYC message.
46  *
47  * @param method_name
48  *        PSYC method for the message.
49  * @param env
50  *        Environment for the message.
51  * @param data
52  *        Data payload for the message.
53  * @param data_size
54  *        Size of @a data.
55  *
56  * @return Message header with size information,
57  *         followed by the message parts.
58  *
59  * FIXME: arg order
60  */
61 struct GNUNET_PSYC_Message *
62 GNUNET_PSYC_message_create (const char *method_name,
63                             const struct GNUNET_PSYC_Environment *env,
64                             const void *data,
65                             size_t data_size);
66
67 /**
68  * Parse PSYC message.
69  *
70  * @param msg
71  *        The PSYC message to parse.
72  * @param env
73  *        The environment for the message with a list of modifiers.
74  * @param[out] method_name
75  *        Pointer to the method name inside @a pmsg.
76  * @param[out] data
77  *        Pointer to data inside @a pmsg.
78  * @param[out] data_size
79  *        Size of @data is written here.
80  *
81  * @return #GNUNET_OK on success,
82  *         #GNUNET_SYSERR on parse error.
83  *
84  * FIXME: arg order
85  */
86 int
87 GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
88                            const char **method_name,
89                            struct GNUNET_PSYC_Environment *env,
90                            const void **data,
91                            uint16_t *data_size);
92
93
94 void
95 GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind,
96                          const struct GNUNET_MessageHeader *msg);
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 (struct GNUNET_MQ_Handle *mq);
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_PSYC_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
207  *        Receive handle.
208  * @param msg
209  *        The message.
210  *
211  * @return #GNUNET_OK on success,
212  *         #GNUNET_SYSERR on receive error.
213  */
214 int
215 GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
216                              const struct GNUNET_PSYC_MessageHeader *msg);
217
218
219 /**
220  * Check if @a data contains a series of valid message parts.
221  *
222  * @param data_size
223  *        Size of @a data.
224  * @param data
225  *        Data.
226  * @param[out] first_ptype
227  *        Type of first message part.
228  * @param[out] last_ptype
229  *        Type of last message part.
230  *
231  * @return Number of message parts found in @a data.
232  *         or GNUNET_SYSERR if the message contains invalid parts.
233  */
234 int
235 GNUNET_PSYC_receive_check_parts (uint16_t data_size, const char *data,
236                                  uint16_t *first_ptype, uint16_t *last_ptype);
237
238
239 /**
240  * Initialize PSYC message header.
241  */
242 void
243 GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
244                                  const struct GNUNET_MULTICAST_MessageHeader *mmsg,
245                                  uint32_t flags);
246
247
248 /**
249  * Create a new PSYC message header from a multicast message for sending it to clients.
250  */
251 struct GNUNET_PSYC_MessageHeader *
252 GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
253                                    uint32_t flags);
254
255
256 /**
257  * Create a new PSYC message header from a PSYC message.
258  */
259 struct GNUNET_PSYC_MessageHeader *
260 GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
261
262
263 #if 0                           /* keep Emacsens' auto-indent happy */
264 {
265 #endif
266 #ifdef __cplusplus
267 }
268 #endif
269
270 /* ifndef GNUNET_PSYC_MESSAGE_H */
271 #endif
272
273 /** @} */  /* end of group */