2 This file is part of GNUnet.
3 Copyright (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @author Gabor X Toth
23 * @author Christian Grothoff
28 * @defgroup psyc-util-slicer PSYC Utilities library: Slicer
29 * Try-and-slice processing of PSYC method names and environment.
33 #ifndef GNUNET_PSYC_SLICER_H
34 #define GNUNET_PSYC_SLICER_H
40 #if 0 /* keep Emacsens' auto-indent happy */
45 #include "gnunet_util_lib.h"
49 * Handle to an implementation of try-and-slice.
51 struct GNUNET_PSYC_Slicer;
55 * Function called upon receiving a message indicating a call to a @e method.
57 * This function is called one or more times for each message until all data
58 * fragments arrive from the network.
63 * Message part, as it arrived from the network.
65 * Message counter, monotonically increasing from 1.
67 * The sender of the message.
68 * Can be NULL if the message is not connected to a pseudonym.
70 * OR'ed GNUNET_PSYC_MessageFlags
72 * Original method name from PSYC.
73 * May be more specific than the registered method name due to
74 * try-and-slice matching.
77 (*GNUNET_PSYC_MethodCallback) (void *cls,
78 const struct GNUNET_PSYC_MessageMethod *msg,
81 const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
82 const char *method_name);
86 * Function called upon receiving a modifier of a message.
91 * Message ID this data fragment belongs to.
93 * Message part, as it arrived from the network.
95 * Operation to perform.
96 * 0 in case of a modifier continuation.
98 * Name of the modifier.
99 * NULL in case of a modifier continuation.
101 * Value of the modifier.
106 (*GNUNET_PSYC_ModifierCallback) (void *cls,
107 const struct GNUNET_MessageHeader *msg,
109 enum GNUNET_PSYC_Operator oper,
113 uint16_t full_value_size);
117 * Function called upon receiving a data fragment of a message.
122 * Message ID this data fragment belongs to.
124 * Message part, as it arrived from the network.
126 * Byte offset of @a data in the overall data of the method.
128 * Number of bytes in @a data.
130 * Data stream given to the method.
133 * #GNUNET_NO if there are further fragments,
134 * #GNUNET_YES if this is the last fragment,
135 * #GNUNET_SYSERR indicates the message was cancelled by the sender.
138 (*GNUNET_PSYC_DataCallback) (void *cls,
139 const struct GNUNET_MessageHeader *msg,
141 uint64_t data_offset,
152 * Message part, as it arrived from the network.
154 * Message ID this data fragment belongs to.
156 * #GNUNET_YES if the message was cancelled,
157 * #GNUNET_NO if the message is complete.
160 (*GNUNET_PSYC_EndOfMessageCallback) (void *cls,
161 const struct GNUNET_MessageHeader *msg,
167 * Create a try-and-slice instance.
169 * A slicer processes incoming messages and notifies callbacks about matching
170 * methods or modifiers encountered.
172 * @return A new try-and-slice construct.
174 struct GNUNET_PSYC_Slicer *
175 GNUNET_PSYC_slicer_create (void);
179 * Add a method to the try-and-slice instance.
181 * The callbacks are called for messages with a matching @a method_name prefix.
184 * The try-and-slice instance to extend.
186 * Name of the given method, use empty string to match all.
188 * Method handler invoked upon a matching message.
190 * Modifier handler, invoked after @a method_cb
191 * for each modifier in the message.
193 * Data handler, invoked after @a modifier_cb for each data fragment.
195 * Invoked upon reaching the end of a matching message.
197 * Closure for the callbacks.
200 GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer,
201 const char *method_name,
202 GNUNET_PSYC_MethodCallback method_cb,
203 GNUNET_PSYC_ModifierCallback modifier_cb,
204 GNUNET_PSYC_DataCallback data_cb,
205 GNUNET_PSYC_EndOfMessageCallback eom_cb,
209 * Remove a registered method from the try-and-slice instance.
211 * Removes one matching handler registered with the given
212 * @a method_name and callbacks.
215 * The try-and-slice instance.
217 * Name of the method to remove.
225 * End of message handler.
227 * @return #GNUNET_OK if a method handler was removed,
228 * #GNUNET_NO if no handler matched the given method name and callbacks.
231 GNUNET_PSYC_slicer_method_remove (struct GNUNET_PSYC_Slicer *slicer,
232 const char *method_name,
233 GNUNET_PSYC_MethodCallback method_cb,
234 GNUNET_PSYC_ModifierCallback modifier_cb,
235 GNUNET_PSYC_DataCallback data_cb,
236 GNUNET_PSYC_EndOfMessageCallback eom_cb);
240 * Watch a place for changed objects.
243 * The try-and-slice instance.
244 * @param object_filter
245 * Object prefix to match.
247 * Function to call when encountering a state modifier.
249 * Closure for callback.
252 GNUNET_PSYC_slicer_modifier_add (struct GNUNET_PSYC_Slicer *slicer,
253 const char *object_filter,
254 GNUNET_PSYC_ModifierCallback modifier_cb,
259 * Remove a registered modifier from the try-and-slice instance.
261 * Removes one matching handler registered with the given
262 * @a object_filter and callback.
265 * The try-and-slice instance.
266 * @param object_filter
267 * Object prefix to match.
269 * Function to call when encountering a state modifier changes.
272 GNUNET_PSYC_slicer_modifier_remove (struct GNUNET_PSYC_Slicer *slicer,
273 const char *object_filter,
274 GNUNET_PSYC_ModifierCallback modifier_cb);
278 * Process an incoming message part and call matching handlers.
285 * Flags for the message.
286 * @see enum GNUNET_PSYC_MessageFlags
288 * The message part. as it arrived from the network.
291 GNUNET_PSYC_slicer_message (void *cls,
292 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key,
295 uint64_t fragment_offset,
296 const struct GNUNET_MessageHeader *msg);
300 * Destroy a given try-and-slice instance.
306 GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer);
309 #if 0 /* keep Emacsens' auto-indent happy */
316 /* ifndef GNUNET_PSYC_SLICER_H */
319 /** @} */ /* end of group */