2 This file is part of GNUnet
3 Copyright (C) 2013, 2014, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU 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 * @file identity-attribute/plugin_identity_attribute_gnuid.c
18 * @brief identity attribute plugin to provide the API for fundamental
21 * @author Martin Schanzenbach
24 #include "gnunet_util_lib.h"
25 #include "gnunet_identity_attribute_plugin.h"
30 * Convert the 'value' of an attribute to a string.
32 * @param cls closure, unused
33 * @param type type of the attribute
34 * @param data value in binary encoding
35 * @param data_size number of bytes in @a data
36 * @return NULL on error, otherwise human-readable representation of the value
39 gnuid_value_to_string (void *cls,
47 case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING:
48 return GNUNET_strndup (data, data_size);
56 * Convert human-readable version of a 'value' of an attribute to the binary
59 * @param cls closure, unused
60 * @param type type of the attribute
61 * @param s human-readable string
62 * @param data set to value in binary encoding (will be allocated)
63 * @param data_size set to number of bytes in @a data
64 * @return #GNUNET_OK on success
67 gnuid_string_to_value (void *cls,
78 case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING:
79 *data = GNUNET_strdup (s);
80 *data_size = strlen (s);
89 * Mapping of attribute type numbers to human-readable
90 * attribute type names.
95 } gnuid_name_map[] = {
96 { "STRING", GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING },
102 * Convert a type name to the corresponding number.
104 * @param cls closure, unused
105 * @param gnuid_typename name to convert
106 * @return corresponding number, UINT32_MAX on error
109 gnuid_typename_to_number (void *cls,
110 const char *gnuid_typename)
115 while ( (NULL != gnuid_name_map[i].name) &&
116 (0 != strcasecmp (gnuid_typename,
117 gnuid_name_map[i].name)) )
119 return gnuid_name_map[i].number;
124 * Convert a type number (i.e. 1) to the corresponding type string
126 * @param cls closure, unused
127 * @param type number of a type to convert
128 * @return corresponding typestring, NULL on error
131 gnuid_number_to_typename (void *cls,
137 while ( (NULL != gnuid_name_map[i].name) &&
138 (type != gnuid_name_map[i].number) )
140 return gnuid_name_map[i].name;
145 * Entry point for the plugin.
148 * @return the exported block API
151 libgnunet_plugin_identity_attribute_gnuid_init (void *cls)
153 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api;
155 api = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions);
156 api->value_to_string = &gnuid_value_to_string;
157 api->string_to_value = &gnuid_string_to_value;
158 api->typename_to_number = &gnuid_typename_to_number;
159 api->number_to_typename = &gnuid_number_to_typename;
165 * Exit point from the plugin.
167 * @param cls the return value from #libgnunet_plugin_block_test_init()
171 libgnunet_plugin_identity_attribute_gnuid_done (void *cls)
173 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = cls;
179 /* end of plugin_identity_attribute_type_gnuid.c */