aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/datastore/plugin_datastore_mysql.c98
-rw-r--r--src/datastore/test_datastore_api.c8
2 files changed, 62 insertions, 44 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 637fb83c5..28b59cb60 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -371,6 +371,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
371#ifndef WINDOWS 371#ifndef WINDOWS
372 struct passwd *pw; 372 struct passwd *pw;
373#endif 373#endif
374 int configured;
374 375
375#ifndef WINDOWS 376#ifndef WINDOWS
376 pw = getpwuid (getuid ()); 377 pw = getpwuid (getuid ());
@@ -382,10 +383,12 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
382 } 383 }
383 if (GNUNET_YES == 384 if (GNUNET_YES ==
384 GNUNET_CONFIGURATION_have_value (cfg, 385 GNUNET_CONFIGURATION_have_value (cfg,
385 "MYSQL", "CONFIG")) 386 "datastore-mysql", "CONFIG"))
386 { 387 {
387 GNUNET_CONFIGURATION_get_value_filename (cfg, 388 GNUNET_assert (GNUNET_OK ==
388 "MYSQL", "CONFIG", &cnffile); 389 GNUNET_CONFIGURATION_get_value_filename (cfg,
390 "datastore-mysql", "CONFIG", &cnffile));
391 configured = GNUNET_YES;
389 } 392 }
390 else 393 else
391 { 394 {
@@ -396,6 +399,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
396#endif 399#endif
397 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); 400 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
398 GNUNET_free (home_dir); 401 GNUNET_free (home_dir);
402 configured = GNUNET_NO;
399 } 403 }
400 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 404 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
401 _("Trying to use file `%s' for MySQL configuration.\n"), 405 _("Trying to use file `%s' for MySQL configuration.\n"),
@@ -403,9 +407,10 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
403 if ((0 != STAT (cnffile, &st)) || 407 if ((0 != STAT (cnffile, &st)) ||
404 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) 408 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
405 { 409 {
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 410 if (configured == GNUNET_YES)
407 _("Could not access file `%s': %s\n"), cnffile, 411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
408 STRERROR (errno)); 412 _("Could not access file `%s': %s\n"), cnffile,
413 STRERROR (errno));
409 GNUNET_free (cnffile); 414 GNUNET_free (cnffile);
410 return NULL; 415 return NULL;
411 } 416 }
@@ -481,57 +486,62 @@ iopen (struct Plugin *ret)
481 mysql_options (ret->dbf, MYSQL_OPT_RECONNECT, &reconnect); 486 mysql_options (ret->dbf, MYSQL_OPT_RECONNECT, &reconnect);
482 mysql_options (ret->dbf, 487 mysql_options (ret->dbf,
483 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); 488 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
489 mysql_options(ret->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
484 timeout = 60; /* in seconds */ 490 timeout = 60; /* in seconds */
485 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 491 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
486 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 492 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
487 mysql_dbname = NULL; 493 mysql_dbname = NULL;
488 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 494 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
489 "MYSQL", "DATABASE")) 495 "datastore-mysql", "DATABASE"))
490 GNUNET_assert (GNUNET_OK == 496 GNUNET_assert (GNUNET_OK ==
491 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 497 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
492 "MYSQL", "DATABASE", 498 "datastore-mysql", "DATABASE",
493 &mysql_dbname)); 499 &mysql_dbname));
494 else 500 else
495 mysql_dbname = GNUNET_strdup ("gnunet"); 501 mysql_dbname = GNUNET_strdup ("gnunet");
496 mysql_user = NULL; 502 mysql_user = NULL;
497 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 503 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
498 "MYSQL", "USER")) 504 "datastore-mysql", "USER"))
499 { 505 {
500 GNUNET_break (GNUNET_OK == 506 GNUNET_assert (GNUNET_OK ==
501 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 507 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
502 "MYSQL", "USER", 508 "datastore-mysql", "USER",
503 &mysql_user)); 509 &mysql_user));
504 } 510 }
505 mysql_password = NULL; 511 mysql_password = NULL;
506 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 512 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
507 "MYSQL", "PASSWORD")) 513 "datastore-mysql", "PASSWORD"))
508 { 514 {
509 GNUNET_break (GNUNET_OK == 515 GNUNET_assert (GNUNET_OK ==
510 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 516 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
511 "MYSQL", "PASSWORD", 517 "datastore-mysql", "PASSWORD",
512 &mysql_password)); 518 &mysql_password));
513 } 519 }
514 mysql_server = NULL; 520 mysql_server = NULL;
515 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 521 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
516 "MYSQL", "HOST")) 522 "datastore-mysql", "HOST"))
517 { 523 {
518 GNUNET_break (GNUNET_OK == 524 GNUNET_assert (GNUNET_OK ==
519 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 525 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
520 "MYSQL", "HOST", 526 "datastore-mysql", "HOST",
521 &mysql_server)); 527 &mysql_server));
522 } 528 }
523 mysql_port = 0; 529 mysql_port = 0;
524 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 530 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg,
525 "MYSQL", "PORT")) 531 "datastore-mysql", "PORT"))
526 { 532 {
527 GNUNET_break (GNUNET_OK == 533 GNUNET_assert (GNUNET_OK ==
528 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, "MYSQL", 534 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, "datastore-mysql",
529 "PORT", &mysql_port)); 535 "PORT", &mysql_port));
530 } 536 }
531 537
532 GNUNET_assert (mysql_dbname != NULL); 538 GNUNET_assert (mysql_dbname != NULL);
533 mysql_real_connect (ret->dbf, mysql_server, mysql_user, mysql_password, 539 mysql_real_connect (ret->dbf, mysql_server, mysql_user, mysql_password,
534 mysql_dbname, (unsigned int) mysql_port, NULL, 0); 540 mysql_dbname, (unsigned int) mysql_port, NULL,
541 CLIENT_IGNORE_SIGPIPE);
542 GNUNET_free_non_null (mysql_server);
543 GNUNET_free_non_null (mysql_user);
544 GNUNET_free_non_null (mysql_password);
535 GNUNET_free (mysql_dbname); 545 GNUNET_free (mysql_dbname);
536 if (mysql_error (ret->dbf)[0]) 546 if (mysql_error (ret->dbf)[0])
537 { 547 {
@@ -1064,7 +1074,6 @@ sqlite_next_request_cont (void *next_cls,
1064 unsigned long hashSize; 1074 unsigned long hashSize;
1065 GNUNET_HashCode key; 1075 GNUNET_HashCode key;
1066 struct GNUNET_TIME_Absolute expiration; 1076 struct GNUNET_TIME_Absolute expiration;
1067 unsigned int contentSize;
1068 unsigned long length; 1077 unsigned long length;
1069 MYSQL_BIND *rbind; /* size 7 */ 1078 MYSQL_BIND *rbind; /* size 7 */
1070 MYSQL_BIND dbind[1]; 1079 MYSQL_BIND dbind[1];
@@ -1075,10 +1084,6 @@ sqlite_next_request_cont (void *next_cls,
1075 plugin->next_task_nc = NULL; 1084 plugin->next_task_nc = NULL;
1076 1085
1077 AGAIN: 1086 AGAIN:
1078 ret = nrc->prep (nrc->prep_cls,
1079 nrc);
1080 if (ret != GNUNET_OK)
1081 goto END_SET;
1082 nrc->now = GNUNET_TIME_absolute_get (); 1087 nrc->now = GNUNET_TIME_absolute_get ();
1083 hashSize = sizeof (GNUNET_HashCode); 1088 hashSize = sizeof (GNUNET_HashCode);
1084 memset (nrc->rbind, 0, sizeof (nrc->rbind)); 1089 memset (nrc->rbind, 0, sizeof (nrc->rbind));
@@ -1106,6 +1111,17 @@ sqlite_next_request_cont (void *next_cls,
1106 rbind[6].buffer = &vkey; 1111 rbind[6].buffer = &vkey;
1107 rbind[6].is_unsigned = GNUNET_YES; 1112 rbind[6].is_unsigned = GNUNET_YES;
1108 1113
1114 ret = nrc->prep (nrc->prep_cls,
1115 nrc);
1116 if (ret != GNUNET_OK)
1117 goto END_SET;
1118 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1119 {
1120 GNUNET_break (0); /* far too big */
1121 goto END_SET;
1122 }
1123
1124
1109 nrc->last_vkey = vkey; 1125 nrc->last_vkey = vkey;
1110 nrc->last_prio = priority; 1126 nrc->last_prio = priority;
1111 nrc->last_expire = exp; 1127 nrc->last_expire = exp;
@@ -1128,19 +1144,13 @@ sqlite_next_request_cont (void *next_cls,
1128 GNUNET_break (0); 1144 GNUNET_break (0);
1129 goto END_SET; 1145 goto END_SET;
1130 } 1146 }
1131 contentSize = *(unsigned int *) rbind[0].buffer;
1132 if (contentSize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1133 {
1134 GNUNET_break (0); /* far too big */
1135 goto END_SET;
1136 }
1137 /* now do query on gn072 */ 1147 /* now do query on gn072 */
1138 length = contentSize; 1148 length = size;
1139 memset (rbind, 0, sizeof (rbind)); 1149 memset (dbind, 0, sizeof (dbind));
1140 rbind[0].buffer_type = MYSQL_TYPE_BLOB; 1150 dbind[0].buffer_type = MYSQL_TYPE_BLOB;
1141 rbind[0].buffer_length = contentSize; 1151 dbind[0].buffer_length = size;
1142 rbind[0].length = &length; 1152 dbind[0].length = &length;
1143 rbind[0].buffer = datum; 1153 dbind[0].buffer = datum;
1144 ret = prepared_statement_run_select (plugin, 1154 ret = prepared_statement_run_select (plugin,
1145 plugin->select_value, 1155 plugin->select_value,
1146 1, 1156 1,
@@ -1153,22 +1163,22 @@ sqlite_next_request_cont (void *next_cls,
1153 if (ret > 0) 1163 if (ret > 0)
1154 ret = GNUNET_OK; 1164 ret = GNUNET_OK;
1155 if ((ret != GNUNET_OK) || 1165 if ((ret != GNUNET_OK) ||
1156 (dbind[0].buffer_length != contentSize) || (length != contentSize)) 1166 (dbind[0].buffer_length != size) || (length != size))
1157 { 1167 {
1158 GNUNET_break (ret != 0); /* should have one rbind! */ 1168 GNUNET_break (ret != 0); /* should have one rbind! */
1159 GNUNET_break (length == contentSize); /* length should match! */ 1169 GNUNET_break (length == size); /* length should match! */
1160 GNUNET_break (dbind[0].buffer_length == contentSize); /* length should be internally consistent! */ 1170 GNUNET_break (dbind[0].buffer_length == size); /* length should be internally consistent! */
1161 do_delete_value (plugin, vkey); 1171 do_delete_value (plugin, vkey);
1162 if (ret != 0) 1172 if (ret != 0)
1163 do_delete_entry_by_vkey (plugin, vkey); 1173 do_delete_entry_by_vkey (plugin, vkey);
1164 plugin->content_size -= contentSize; 1174 plugin->content_size -= size;
1165 goto AGAIN; 1175 goto AGAIN;
1166 } 1176 }
1167 expiration.value = exp; 1177 expiration.value = exp;
1168 ret = nrc->dviter (nrc->dviter_cls, 1178 ret = nrc->dviter (nrc->dviter_cls,
1169 nrc, 1179 nrc,
1170 &key, 1180 &key,
1171 contentSize, 1181 size,
1172 datum, 1182 datum,
1173 type, 1183 type,
1174 priority, 1184 priority,
@@ -1184,7 +1194,7 @@ sqlite_next_request_cont (void *next_cls,
1184 { 1194 {
1185 do_delete_value (plugin, vkey); 1195 do_delete_value (plugin, vkey);
1186 do_delete_entry_by_vkey (plugin, vkey); 1196 do_delete_entry_by_vkey (plugin, vkey);
1187 plugin->content_size -= contentSize; 1197 plugin->content_size -= size;
1188 } 1198 }
1189 return; 1199 return;
1190 END_SET: 1200 END_SET:
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index ec83e9196..1a753d2bf 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -33,6 +33,8 @@
33 33
34#define VERBOSE GNUNET_NO 34#define VERBOSE GNUNET_NO
35 35
36#define START_DATASTORE GNUNET_NO
37
36/** 38/**
37 * How long until we give up on transmitting the message? 39 * How long until we give up on transmitting the message?
38 */ 40 */
@@ -598,7 +600,9 @@ static int
598check () 600check ()
599{ 601{
600 char cfg_name[128]; 602 char cfg_name[128];
603#if START_DATASTORE
601 pid_t pid; 604 pid_t pid;
605#endif
602 char *const argv[] = { 606 char *const argv[] = {
603 "test-datastore-api", 607 "test-datastore-api",
604 "-c", 608 "-c",
@@ -615,21 +619,25 @@ check ()
615 sizeof (cfg_name), 619 sizeof (cfg_name),
616 "test_datastore_api_data_%s.conf", 620 "test_datastore_api_data_%s.conf",
617 plugin_name); 621 plugin_name);
622#if START_DATASTORE
618 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 623 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
619 "gnunet-service-arm", 624 "gnunet-service-arm",
620#if VERBOSE 625#if VERBOSE
621 "-L", "DEBUG", 626 "-L", "DEBUG",
622#endif 627#endif
623 "-c", cfg_name, NULL); 628 "-c", cfg_name, NULL);
629#endif
624 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 630 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
625 argv, "test-datastore-api", "nohelp", 631 argv, "test-datastore-api", "nohelp",
626 options, &run, NULL); 632 options, &run, NULL);
633#if START_DATASTORE
627 if (0 != PLIBC_KILL (pid, SIGTERM)) 634 if (0 != PLIBC_KILL (pid, SIGTERM))
628 { 635 {
629 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 636 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
630 ok = 1; 637 ok = 1;
631 } 638 }
632 GNUNET_OS_process_wait(pid); 639 GNUNET_OS_process_wait(pid);
640#endif
633 if (ok != 0) 641 if (ok != 0)
634 fprintf (stderr, "Missed some testcases: %u\n", ok); 642 fprintf (stderr, "Missed some testcases: %u\n", ok);
635 return ok; 643 return ok;