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