2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
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.
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.
17 * @author Gabor X Toth
18 * @author Christian Grothoff
23 * @defgroup psyc-util-slicer PSYC Utilities library: Slicer
24 * Try-and-slice processing of PSYC method names and environment.
28 #ifndef GNUNET_PSYC_SLICER_H
29 #define GNUNET_PSYC_SLICER_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_util_lib.h"
44 * Handle to an implementation of try-and-slice.
46 struct GNUNET_PSYC_Slicer;
50 * Function called upon receiving a message indicating a call to a @e method.
52 * This function is called one or more times for each message until all data
53 * fragments arrive from the network.
58 * Message part, as it arrived from the network.
60 * Message counter, monotonically increasing from 1.
62 * OR'ed GNUNET_PSYC_MessageFlags
63 * @param fragment_offset
64 * Multicast message fragment offset.
66 * OR'ed GNUNET_PSYC_MasterTransmitFlags
68 * The sender of the message.
69 * Can be NULL if the message is not connected to a pseudonym.
71 * Original method name from PSYC.
72 * May be more specific than the registered method name due to
73 * try-and-slice matching.
76 (*GNUNET_PSYC_MethodCallback) (void *cls,
77 const struct GNUNET_PSYC_MessageHeader *msg,
78 const struct GNUNET_PSYC_MessageMethod *meth,
80 const char *method_name);
84 * Function called upon receiving a modifier of a message.
89 * Message ID this data fragment belongs to.
91 * OR'ed GNUNET_PSYC_MessageFlags
92 * @param fragment_offset
93 * Multicast message fragment offset.
95 * Message part, as it arrived from the network.
97 * Operation to perform.
98 * 0 in case of a modifier continuation.
100 * Name of the modifier.
101 * NULL in case of a modifier continuation.
103 * Value of the modifier.
108 (*GNUNET_PSYC_ModifierCallback) (void *cls,
109 const struct GNUNET_PSYC_MessageHeader *msg,
110 const struct GNUNET_MessageHeader *pmsg,
112 enum GNUNET_PSYC_Operator oper,
116 uint16_t full_value_size);
120 * Function called upon receiving a data fragment of a message.
125 * Message part, as it arrived from the network.
127 * Message ID this data fragment belongs to.
129 * OR'ed GNUNET_PSYC_MessageFlags
130 * @param fragment_offset
131 * Multicast message fragment offset.
133 * Data stream given to the method.
135 * Number of bytes in @a data.
138 * #GNUNET_NO if there are further fragments,
139 * #GNUNET_YES if this is the last fragment,
140 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
143 (*GNUNET_PSYC_DataCallback) (void *cls,
144 const struct GNUNET_PSYC_MessageHeader *msg,
145 const struct GNUNET_MessageHeader *pmsg,
157 * Message part, as it arrived from the network.
159 * Message ID this data fragment belongs to.
161 * OR'ed GNUNET_PSYC_MessageFlags
162 * @param fragment_offset
163 * Multicast message fragment offset.
165 * #GNUNET_YES if the message was cancelled,
166 * #GNUNET_NO if the message is complete.
169 (*GNUNET_PSYC_EndOfMessageCallback) (void *cls,
170 const struct GNUNET_PSYC_MessageHeader *msg,
171 const struct GNUNET_MessageHeader *pmsg,
173 uint8_t is_cancelled);
177 * Create a try-and-slice instance.
179 * A slicer processes incoming messages and notifies callbacks about matching
180 * methods or modifiers encountered.
182 * @return A new try-and-slice construct.
184 struct GNUNET_PSYC_Slicer *
185 GNUNET_PSYC_slicer_create (void);
189 * Add a method to the try-and-slice instance.
191 * The callbacks are called for messages with a matching @a method_name prefix.
194 * The try-and-slice instance to extend.
196 * Name of the given method, use empty string to match all.
198 * Method handler invoked upon a matching message.
200 * Modifier handler, invoked after @a method_cb
201 * for each modifier in the message.
203 * Data handler, invoked after @a modifier_cb for each data fragment.
205 * Invoked upon reaching the end of a matching message.
207 * Closure for the callbacks.
210 GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer,
211 const char *method_name,
212 GNUNET_PSYC_MessageCallback msg_cb,
213 GNUNET_PSYC_MethodCallback method_cb,
214 GNUNET_PSYC_ModifierCallback modifier_cb,
215 GNUNET_PSYC_DataCallback data_cb,
216 GNUNET_PSYC_EndOfMessageCallback eom_cb,
220 * Remove a registered method from the try-and-slice instance.
222 * Removes one matching handler registered with the given
223 * @a method_name and callbacks.
226 * The try-and-slice instance.
228 * Name of the method to remove.
230 * Only remove matching method handler, or NULL.
232 * Only remove matching modifier handler, or NULL.
234 * Only remove matching data handler, or NULL.
236 * Only remove matching End of Message handler, or NULL.
238 * @return #GNUNET_OK if a method handler was removed,
239 * #GNUNET_NO if no handler matched the given method name and callbacks.
242 GNUNET_PSYC_slicer_method_remove (struct GNUNET_PSYC_Slicer *slicer,
243 const char *method_name,
244 GNUNET_PSYC_MessageCallback msg_cb,
245 GNUNET_PSYC_MethodCallback method_cb,
246 GNUNET_PSYC_ModifierCallback modifier_cb,
247 GNUNET_PSYC_DataCallback data_cb,
248 GNUNET_PSYC_EndOfMessageCallback eom_cb);
252 * Watch a place for changed objects.
255 * The try-and-slice instance.
256 * @param object_filter
257 * Object prefix to match.
259 * Function to call when encountering a state modifier.
261 * Closure for callback.
264 GNUNET_PSYC_slicer_modifier_add (struct GNUNET_PSYC_Slicer *slicer,
265 const char *object_filter,
266 GNUNET_PSYC_ModifierCallback modifier_cb,
271 * Remove a registered modifier from the try-and-slice instance.
273 * Removes one matching handler registered with the given
274 * @a object_filter and callback.
277 * The try-and-slice instance.
278 * @param object_filter
279 * Object prefix to match.
281 * Function to call when encountering a state modifier changes.
284 GNUNET_PSYC_slicer_modifier_remove (struct GNUNET_PSYC_Slicer *slicer,
285 const char *object_filter,
286 GNUNET_PSYC_ModifierCallback modifier_cb);
290 * Process an incoming message and call matching handlers.
295 * The message as it arrived from the network.
298 GNUNET_PSYC_slicer_message (struct GNUNET_PSYC_Slicer *slicer,
299 const struct GNUNET_PSYC_MessageHeader *msg);
303 * Process an incoming message part and call matching handlers.
310 * Flags for the message.
311 * @see enum GNUNET_PSYC_MessageFlags
312 * @param fragment offset
313 * Fragment offset of the message.
315 * The message part as it arrived from the network.
318 GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer,
319 const struct GNUNET_PSYC_MessageHeader *msg,
320 const struct GNUNET_MessageHeader *pmsg);
324 * Remove all registered method handlers.
330 GNUNET_PSYC_slicer_method_clear (struct GNUNET_PSYC_Slicer *slicer);
334 * Remove all registered modifier handlers.
340 GNUNET_PSYC_slicer_modifier_clear (struct GNUNET_PSYC_Slicer *slicer);
344 * Remove all registered method & modifier handlers.
350 GNUNET_PSYC_slicer_clear (struct GNUNET_PSYC_Slicer *slicer);
354 * Destroy a given try-and-slice instance.
360 GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer);
363 #if 0 /* keep Emacsens' auto-indent happy */
370 /* ifndef GNUNET_PSYC_SLICER_H */
373 /** @} */ /* end of group */