glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / set / plugin_block_set_test.c
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2017 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  * @file set/plugin_block_set_test.c
18  * @brief set test block, recognizes elements with non-zero first byte as invalid
19  * @author Christian Grothoff
20  */
21
22 #include "platform.h"
23 #include "gnunet_block_plugin.h"
24 #include "gnunet_block_group_lib.h"
25
26
27 /**
28  * Function called to validate a reply or a request.  For
29  * request evaluation, simply pass "NULL" for the reply_block.
30  *
31  * @param cls closure
32  * @param ctx block context
33  * @param type block type
34  * @param group block group to use
35  * @param eo control flags
36  * @param query original query (hash)
37  * @param xquery extrended query data (can be NULL, depending on type)
38  * @param xquery_size number of bytes in xquery
39  * @param reply_block response to validate
40  * @param reply_block_size number of bytes in reply block
41  * @return characterization of result
42  */
43 static enum GNUNET_BLOCK_EvaluationResult
44 block_plugin_set_test_evaluate (void *cls,
45                                 struct GNUNET_BLOCK_Context *ctx,
46                                 enum GNUNET_BLOCK_Type type,
47                                 struct GNUNET_BLOCK_Group *group,
48                                 enum GNUNET_BLOCK_EvaluationOptions eo,
49                                 const struct GNUNET_HashCode *query,
50                                 const void *xquery,
51                                 size_t xquery_size,
52                                 const void *reply_block,
53                                 size_t reply_block_size)
54 {
55   if ( (NULL == reply_block) ||
56        (reply_block_size == 0) ||
57        (0 != ((char *) reply_block)[0]) )
58     return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
59   return GNUNET_BLOCK_EVALUATION_OK_MORE;
60 }
61
62
63 /**
64  * Function called to obtain the key for a block.
65  *
66  * @param cls closure
67  * @param type block type
68  * @param block block to get the key for
69  * @param block_size number of bytes in block
70  * @param key set to the key (query) for the given block
71  * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
72  *         (or if extracting a key from a block of this type does not work)
73  */
74 static int
75 block_plugin_set_test_get_key (void *cls,
76                                enum GNUNET_BLOCK_Type type,
77                                const void *block,
78                                size_t block_size,
79                                struct GNUNET_HashCode *key)
80 {
81   return GNUNET_SYSERR;
82 }
83
84
85 /**
86  * Entry point for the plugin.
87  */
88 void *
89 libgnunet_plugin_block_set_test_init (void *cls)
90 {
91   static enum GNUNET_BLOCK_Type types[] =
92   {
93     GNUNET_BLOCK_TYPE_SET_TEST,
94     GNUNET_BLOCK_TYPE_ANY       /* end of list */
95   };
96   struct GNUNET_BLOCK_PluginFunctions *api;
97
98   api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
99   api->evaluate = &block_plugin_set_test_evaluate;
100   api->get_key = &block_plugin_set_test_get_key;
101   api->types = types;
102   return api;
103 }
104
105
106 /**
107  * Exit point from the plugin.
108  */
109 void *
110 libgnunet_plugin_block_set_test_done (void *cls)
111 {
112   struct GNUNET_BLOCK_PluginFunctions *api = cls;
113
114   GNUNET_free (api);
115   return NULL;
116 }
117
118 /* end of plugin_block_set_test.c */