aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2017-12-04 16:37:28 +0100
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2017-12-04 16:37:28 +0100
commitf485d0399e8ef0c388a321bbad7ae424935752bc (patch)
tree7b7dcad11af2375c4a0e1904d1dec33bd8a88397 /src
parentb16fa2d88aabb18f222b40136d6ace68ffc104c6 (diff)
downloadgnunet-f485d0399e8ef0c388a321bbad7ae424935752bc.tar.gz
gnunet-f485d0399e8ef0c388a321bbad7ae424935752bc.zip
-fix makefile
Diffstat (limited to 'src')
-rw-r--r--src/identity-attribute/Makefile.am2
-rw-r--r--src/identity-attribute/identity_attribute.c176
-rw-r--r--src/identity-provider/gnunet-idp.c12
-rw-r--r--src/include/gnunet_identity_attribute_lib.h45
4 files changed, 230 insertions, 5 deletions
diff --git a/src/identity-attribute/Makefile.am b/src/identity-attribute/Makefile.am
index 770bc2ead..583545344 100644
--- a/src/identity-attribute/Makefile.am
+++ b/src/identity-attribute/Makefile.am
@@ -38,7 +38,7 @@ libgnunet_plugin_identity_attribute_gnuid_la_SOURCES = \
38libgnunet_plugin_identity_attribute_gnuid_la_LIBADD = \ 38libgnunet_plugin_identity_attribute_gnuid_la_LIBADD = \
39 $(top_builddir)/src/util/libgnunetutil.la \ 39 $(top_builddir)/src/util/libgnunetutil.la \
40 $(LTLIBINTL) 40 $(LTLIBINTL)
41libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \ 41libgnunet_plugin_identity_attribute_gnuid_la_LDFLAGS = \
42 $(GN_PLUGIN_LDFLAGS) 42 $(GN_PLUGIN_LDFLAGS)
43 43
44 44
diff --git a/src/identity-attribute/identity_attribute.c b/src/identity-attribute/identity_attribute.c
index 377eb3211..05cdcdaf0 100644
--- a/src/identity-attribute/identity_attribute.c
+++ b/src/identity-attribute/identity_attribute.c
@@ -26,6 +26,182 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "identity_attribute.h" 28#include "identity_attribute.h"
29#include "gnunet_identity_attribute_plugin.h"
30
31/**
32 * Handle for a plugin
33 */
34struct Plugin
35{
36 /**
37 * Name of the plugin
38 */
39 char *library_name;
40
41 /**
42 * Plugin API
43 */
44 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api;
45};
46
47/**
48 * Plugins
49 */
50static struct Plugin **attr_plugins;
51
52/**
53 * Number of plugins
54 */
55static unsigned int num_plugins;
56
57/**
58 * Init canary
59 */
60static int initialized;
61
62/**
63 * Add a plugin
64 */
65static void
66add_plugin (void* cls,
67 const char *library_name,
68 void *lib_ret)
69{
70 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = lib_ret;
71 struct Plugin *plugin;
72
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
74 "Loading attribute plugin `%s'\n",
75 library_name);
76 plugin = GNUNET_new (struct Plugin);
77 plugin->api = api;
78 plugin->library_name = GNUNET_strdup (library_name);
79 GNUNET_array_append (attr_plugins, num_plugins, plugin);
80}
81
82/**
83 * Load plugins
84 */
85static void
86init()
87{
88 if (GNUNET_YES == initialized)
89 return;
90 initialized = GNUNET_YES;
91 GNUNET_PLUGIN_load_all ("libgnunet_plugin_attribute_", NULL,
92 &add_plugin, NULL);
93}
94
95/**
96 * Convert a type name to the corresponding number
97 *
98 * @param typename name to convert
99 * @return corresponding number, UINT32_MAX on error
100 */
101uint32_t
102GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename)
103{
104 unsigned int i;
105 struct Plugin *plugin;
106 uint32_t ret;
107
108 init ();
109 for (i = 0; i < num_plugins; i++)
110 {
111 plugin = attr_plugins[i];
112 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
113 typename)))
114 return ret;
115 }
116 return UINT32_MAX;
117}
118
119/**
120 * Convert a type number to the corresponding type string
121 *
122 * @param type number of a type
123 * @return corresponding typestring, NULL on error
124 */
125const char*
126GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type)
127{
128 unsigned int i;
129 struct Plugin *plugin;
130 const char *ret;
131
132 init ();
133 for (i = 0; i < num_plugins; i++)
134 {
135 plugin = attr_plugins[i];
136 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
137 type)))
138 return ret;
139 }
140 return NULL;
141}
142
143/**
144 * Convert human-readable version of a 'claim' of an attribute to the binary
145 * representation
146 *
147 * @param type type of the claim
148 * @param s human-readable string
149 * @param data set to value in binary encoding (will be allocated)
150 * @param data_size set to number of bytes in @a data
151 * @return #GNUNET_OK on success
152 */
153int
154GNUNET_IDENTITY_ATTRIBUTE_string_to_claim (uint32_t type,
155 const char *s,
156 void **data,
157 size_t *data_size)
158{
159 unsigned int i;
160 struct Plugin *plugin;
161
162 init ();
163 for (i = 0; i < num_plugins; i++)
164 {
165 plugin = attr_plugins[i];
166 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
167 type,
168 s,
169 data,
170 data_size))
171 return GNUNET_OK;
172 }
173 return GNUNET_SYSERR;
174}
175
176/**
177 * Convert the 'claim' of an attribute to a string
178 *
179 * @param type the type of attribute
180 * @param data claim in binary encoding
181 * @param data_size number of bytes in @a data
182 * @return NULL on error, otherwise human-readable representation of the claim
183 */
184char *
185GNUNET_IDENTITY_ATTRIBUTE_claim_to_string (uint32_t type,
186 const void* data,
187 size_t data_size)
188{
189 unsigned int i;
190 struct Plugin *plugin;
191 char *ret;
192
193 init();
194 for (i = 0; i < num_plugins; i++)
195 {
196 plugin = attr_plugins[i];
197 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
198 type,
199 data,
200 data_size)))
201 return ret;
202 }
203 return NULL;
204}
29 205
30/** 206/**
31 * Create a new attribute. 207 * Create a new attribute.
diff --git a/src/identity-provider/gnunet-idp.c b/src/identity-provider/gnunet-idp.c
index 18a5676c0..78da1cb4d 100644
--- a/src/identity-provider/gnunet-idp.c
+++ b/src/identity-provider/gnunet-idp.c
@@ -168,6 +168,7 @@ process_attrs (void *cls,
168 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 168 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
169 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 169 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr)
170{ 170{
171 char *claim;
171 if (NULL == identity) 172 if (NULL == identity)
172 { 173 {
173 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 174 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
@@ -178,8 +179,11 @@ process_attrs (void *cls,
178 ret = 1; 179 ret = 1;
179 return; 180 return;
180 } 181 }
182 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_to_string (attr->type,
183 attr->data,
184 attr->data_size);
181 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 185 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
182 "%s: %s\n", attr->name, (char*)attr->data); 186 "%s: %s\n", attr->name, claim);
183} 187}
184 188
185 189
@@ -245,9 +249,9 @@ iter_finished (void *cls)
245 return; 249 return;
246 } 250 }
247 attr = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name, 251 attr = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name,
248 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING, 252 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
249 attr_value, 253 attr_value,
250 strlen (attr_value) + 1); 254 strlen (attr_value) + 1);
251 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle, 255 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
252 pkey, 256 pkey,
253 attr, 257 attr,
diff --git a/src/include/gnunet_identity_attribute_lib.h b/src/include/gnunet_identity_attribute_lib.h
index 039b50351..4e32c2ae1 100644
--- a/src/include/gnunet_identity_attribute_lib.h
+++ b/src/include/gnunet_identity_attribute_lib.h
@@ -213,7 +213,52 @@ GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data,
213struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* 213struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList*
214GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 214GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs);
215 215
216/**
217 * Convert a type name to the corresponding number
218 *
219 * @param typename name to convert
220 * @return corresponding number, UINT32_MAX on error
221 */
222uint32_t
223GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename);
224
225/**
226 * Convert human-readable version of a 'claim' of an attribute to the binary
227 * representation
228 *
229 * @param type type of the claim
230 * @param s human-readable string
231 * @param data set to value in binary encoding (will be allocated)
232 * @param data_size set to number of bytes in @a data
233 * @return #GNUNET_OK on success
234 */
235int
236GNUNET_IDENTITY_ATTRIBUTE_string_to_claim (uint32_t type,
237 const char *s,
238 void **data,
239 size_t *data_size);
216 240
241/**
242 * Convert the 'claim' of an attribute to a string
243 *
244 * @param type the type of attribute
245 * @param data claim in binary encoding
246 * @param data_size number of bytes in @a data
247 * @return NULL on error, otherwise human-readable representation of the claim
248 */
249char *
250GNUNET_IDENTITY_ATTRIBUTE_claim_to_string (uint32_t type,
251 const void* data,
252 size_t data_size);
253
254/**
255 * Convert a type number to the corresponding type string
256 *
257 * @param type number of a type
258 * @return corresponding typestring, NULL on error
259 */
260const char*
261GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type);
217 262
218#if 0 /* keep Emacsens' auto-indent happy */ 263#if 0 /* keep Emacsens' auto-indent happy */
219{ 264{