diff options
Diffstat (limited to 'src/identity-provider/plugin_identity_provider_sqlite.c')
-rw-r--r-- | src/identity-provider/plugin_identity_provider_sqlite.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/identity-provider/plugin_identity_provider_sqlite.c b/src/identity-provider/plugin_identity_provider_sqlite.c index ff2d3a22e..ac4e3c686 100644 --- a/src/identity-provider/plugin_identity_provider_sqlite.c +++ b/src/identity-provider/plugin_identity_provider_sqlite.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_identity_provider_service.h" | 28 | #include "gnunet_identity_provider_service.h" |
29 | #include "gnunet_identity_provider_plugin.h" | 29 | #include "gnunet_identity_provider_plugin.h" |
30 | #include "identity_attribute.h" | ||
30 | #include "gnunet_sq_lib.h" | 31 | #include "gnunet_sq_lib.h" |
31 | #include <sqlite3.h> | 32 | #include <sqlite3.h> |
32 | 33 | ||
@@ -252,7 +253,8 @@ database_setup (struct Plugin *plugin) | |||
252 | "CREATE TABLE identity001tickets (" | 253 | "CREATE TABLE identity001tickets (" |
253 | " identity BLOB NOT NULL DEFAULT ''," | 254 | " identity BLOB NOT NULL DEFAULT ''," |
254 | " audience BLOB NOT NULL DEFAULT ''," | 255 | " audience BLOB NOT NULL DEFAULT ''," |
255 | " rnd INT8 NOT NULL DEFAULT ''" | 256 | " rnd INT8 NOT NULL DEFAULT ''," |
257 | " attributes BLOB NOT NULL DEFAULT ''" | ||
256 | ")", | 258 | ")", |
257 | NULL, NULL, NULL) != SQLITE_OK)) | 259 | NULL, NULL, NULL) != SQLITE_OK)) |
258 | { | 260 | { |
@@ -267,8 +269,8 @@ database_setup (struct Plugin *plugin) | |||
267 | 269 | ||
268 | if ( (SQLITE_OK != | 270 | if ( (SQLITE_OK != |
269 | sq_prepare (plugin->dbh, | 271 | sq_prepare (plugin->dbh, |
270 | "INSERT INTO identity001tickets (identity, audience, rnd)" | 272 | "INSERT INTO identity001tickets (identity, audience, rnd, attributes)" |
271 | " VALUES (?, ?, ?)", | 273 | " VALUES (?, ?, ?, ?)", |
272 | &plugin->store_ticket)) || | 274 | &plugin->store_ticket)) || |
273 | (SQLITE_OK != | 275 | (SQLITE_OK != |
274 | sq_prepare (plugin->dbh, | 276 | sq_prepare (plugin->dbh, |
@@ -276,13 +278,13 @@ database_setup (struct Plugin *plugin) | |||
276 | &plugin->delete_ticket)) || | 278 | &plugin->delete_ticket)) || |
277 | (SQLITE_OK != | 279 | (SQLITE_OK != |
278 | sq_prepare (plugin->dbh, | 280 | sq_prepare (plugin->dbh, |
279 | "SELECT identity,audience,rnd" | 281 | "SELECT identity,audience,rnd,attributes" |
280 | " FROM identity001tickets WHERE identity=?" | 282 | " FROM identity001tickets WHERE identity=?" |
281 | " ORDER BY rnd LIMIT 1 OFFSET ?", | 283 | " ORDER BY rnd LIMIT 1 OFFSET ?", |
282 | &plugin->iterate_tickets)) || | 284 | &plugin->iterate_tickets)) || |
283 | (SQLITE_OK != | 285 | (SQLITE_OK != |
284 | sq_prepare (plugin->dbh, | 286 | sq_prepare (plugin->dbh, |
285 | "SELECT identity,audience,rnd" | 287 | "SELECT identity,audience,rnd,attributes" |
286 | " FROM identity001tickets WHERE audience=?" | 288 | " FROM identity001tickets WHERE audience=?" |
287 | " ORDER BY rnd LIMIT 1 OFFSET ?", | 289 | " ORDER BY rnd LIMIT 1 OFFSET ?", |
288 | &plugin->iterate_tickets_by_audience)) ) | 290 | &plugin->iterate_tickets_by_audience)) ) |
@@ -358,9 +360,12 @@ database_shutdown (struct Plugin *plugin) | |||
358 | */ | 360 | */ |
359 | static int | 361 | static int |
360 | identity_provider_sqlite_store_ticket (void *cls, | 362 | identity_provider_sqlite_store_ticket (void *cls, |
361 | const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) | 363 | const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, |
364 | const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs) | ||
362 | { | 365 | { |
363 | struct Plugin *plugin = cls; | 366 | struct Plugin *plugin = cls; |
367 | size_t attrs_len; | ||
368 | char *attrs_ser; | ||
364 | int n; | 369 | int n; |
365 | 370 | ||
366 | { | 371 | { |
@@ -384,11 +389,16 @@ identity_provider_sqlite_store_ticket (void *cls, | |||
384 | n = sqlite3_step (plugin->delete_ticket); | 389 | n = sqlite3_step (plugin->delete_ticket); |
385 | GNUNET_SQ_reset (plugin->dbh, | 390 | GNUNET_SQ_reset (plugin->dbh, |
386 | plugin->delete_ticket); | 391 | plugin->delete_ticket); |
387 | 392 | ||
393 | attrs_len = attribute_list_serialize_get_size (attrs); | ||
394 | attrs_ser = GNUNET_malloc (attrs_len); | ||
395 | attribute_list_serialize (attrs, | ||
396 | attrs_ser); | ||
388 | struct GNUNET_SQ_QueryParam sparams[] = { | 397 | struct GNUNET_SQ_QueryParam sparams[] = { |
389 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), | 398 | GNUNET_SQ_query_param_auto_from_type (&ticket->identity), |
390 | GNUNET_SQ_query_param_auto_from_type (&ticket->audience), | 399 | GNUNET_SQ_query_param_auto_from_type (&ticket->audience), |
391 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), | 400 | GNUNET_SQ_query_param_uint64 (&ticket->rnd), |
401 | GNUNET_SQ_query_param_fixed_size (attrs_ser, attrs_len), | ||
392 | GNUNET_SQ_query_param_end | 402 | GNUNET_SQ_query_param_end |
393 | }; | 403 | }; |
394 | 404 | ||
@@ -406,6 +416,7 @@ identity_provider_sqlite_store_ticket (void *cls, | |||
406 | n = sqlite3_step (plugin->store_ticket); | 416 | n = sqlite3_step (plugin->store_ticket); |
407 | GNUNET_SQ_reset (plugin->dbh, | 417 | GNUNET_SQ_reset (plugin->dbh, |
408 | plugin->store_ticket); | 418 | plugin->store_ticket); |
419 | GNUNET_free (attrs_ser); | ||
409 | } | 420 | } |
410 | switch (n) | 421 | switch (n) |
411 | { | 422 | { |
@@ -503,8 +514,11 @@ get_ticket_and_call_iterator (struct Plugin *plugin, | |||
503 | void *iter_cls) | 514 | void *iter_cls) |
504 | { | 515 | { |
505 | struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; | 516 | struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; |
517 | struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs; | ||
506 | int ret; | 518 | int ret; |
507 | int sret; | 519 | int sret; |
520 | size_t attrs_len; | ||
521 | char *attrs_ser; | ||
508 | 522 | ||
509 | ret = GNUNET_NO; | 523 | ret = GNUNET_NO; |
510 | if (SQLITE_ROW == (sret = sqlite3_step (stmt))) | 524 | if (SQLITE_ROW == (sret = sqlite3_step (stmt))) |
@@ -513,6 +527,8 @@ get_ticket_and_call_iterator (struct Plugin *plugin, | |||
513 | GNUNET_SQ_result_spec_auto_from_type (&ticket.identity), | 527 | GNUNET_SQ_result_spec_auto_from_type (&ticket.identity), |
514 | GNUNET_SQ_result_spec_auto_from_type (&ticket.audience), | 528 | GNUNET_SQ_result_spec_auto_from_type (&ticket.audience), |
515 | GNUNET_SQ_result_spec_uint64 (&ticket.rnd), | 529 | GNUNET_SQ_result_spec_uint64 (&ticket.rnd), |
530 | GNUNET_SQ_result_spec_variable_size ((void**)&attrs_ser, | ||
531 | &attrs_len), | ||
516 | GNUNET_SQ_result_spec_end | 532 | GNUNET_SQ_result_spec_end |
517 | 533 | ||
518 | }; | 534 | }; |
@@ -525,10 +541,13 @@ get_ticket_and_call_iterator (struct Plugin *plugin, | |||
525 | } | 541 | } |
526 | else | 542 | else |
527 | { | 543 | { |
528 | if (NULL != iter) | 544 | attrs = attribute_list_deserialize (attrs_ser, |
529 | iter (iter_cls, | 545 | attrs_len); |
530 | &ticket); | 546 | if (NULL != iter) |
531 | ret = GNUNET_YES; | 547 | iter (iter_cls, |
548 | &ticket, | ||
549 | attrs); | ||
550 | ret = GNUNET_YES; | ||
532 | } | 551 | } |
533 | GNUNET_SQ_cleanup_result (rs); | 552 | GNUNET_SQ_cleanup_result (rs); |
534 | } | 553 | } |