aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r--src/datastore/plugin_datastore_mysql.c86
1 files changed, 59 insertions, 27 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index ea6cc2322..51a60a1dc 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -48,36 +48,30 @@
48 * MANUAL SETUP INSTRUCTIONS 48 * MANUAL SETUP INSTRUCTIONS
49 * 49 *
50 * 1) in /etc/gnunet.conf, set 50 * 1) in /etc/gnunet.conf, set
51 * <pre> 51 * @verbatim
52 * [datastore] 52 * [datastore]
53 * DATABASE = "mysql" 53 * DATABASE = "mysql"
54 * </pre> 54 * @endverbatim
55 * 2) Then access mysql as root, 55 * 2) Then access mysql as root,
56 * <pre> 56 * @verbatim
57 * 57 $ mysql -u root -p
58 * $ mysql -u root -p 58 * @endverbatim
59 *
60 * </pre>
61 * and do the following. [You should replace $USER with the username 59 * and do the following. [You should replace $USER with the username
62 * that will be running the gnunetd process]. 60 * that will be running the gnunetd process].
63 * <pre> 61 * @verbatim
64 *
65 CREATE DATABASE gnunet; 62 CREATE DATABASE gnunet;
66 GRANT select,insert,update,delete,create,alter,drop,create temporary tables 63 GRANT select,insert,update,delete,create,alter,drop,create temporary tables
67 ON gnunet.* TO $USER@localhost; 64 ON gnunet.* TO $USER@localhost;
68 SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like'); 65 SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like');
69 FLUSH PRIVILEGES; 66 FLUSH PRIVILEGES;
70 * 67 * @endverbatim
71 * </pre>
72 * 3) In the $HOME directory of $USER, create a ".my.cnf" file 68 * 3) In the $HOME directory of $USER, create a ".my.cnf" file
73 * with the following lines 69 * with the following lines
74 * <pre> 70 * @verbatim
75
76 [client] 71 [client]
77 user=$USER 72 user=$USER
78 password=$the_password_you_like 73 password=$the_password_you_like
79 74 * @endverbatim
80 * </pre>
81 * 75 *
82 * Thats it. Note that .my.cnf file is a security risk unless its on 76 * Thats it. Note that .my.cnf file is a security risk unless its on
83 * a safe partition etc. The $HOME/.my.cnf can of course be a symbolic 77 * a safe partition etc. The $HOME/.my.cnf can of course be a symbolic
@@ -89,10 +83,10 @@
89 * 4) Still, perhaps you should briefly try if the DB connection 83 * 4) Still, perhaps you should briefly try if the DB connection
90 * works. First, login as $USER. Then use, 84 * works. First, login as $USER. Then use,
91 * 85 *
92 * <pre> 86 * @verbatim
93 * $ mysql -u $USER -p $the_password_you_like 87 $ mysql -u $USER -p $the_password_you_like
94 * mysql> use gnunet; 88 mysql> use gnunet;
95 * </pre> 89 * @endverbatim
96 * 90 *
97 * If you get the message &quot;Database changed&quot; it probably works. 91 * If you get the message &quot;Database changed&quot; it probably works.
98 * 92 *
@@ -110,8 +104,10 @@
110 * - The tables can be verified/fixed in two ways; 104 * - The tables can be verified/fixed in two ways;
111 * 1) by running mysqlcheck -A, or 105 * 1) by running mysqlcheck -A, or
112 * 2) by executing (inside of mysql using the GNUnet database): 106 * 2) by executing (inside of mysql using the GNUnet database):
113 * mysql> REPAIR TABLE gn090; 107 * @verbatim
114 * mysql> REPAIR TABLE gn072; 108 mysql> REPAIR TABLE gn090;
109 mysql> REPAIR TABLE gn072;
110 * @endverbatim
115 * 111 *
116 * PROBLEMS? 112 * PROBLEMS?
117 * 113 *
@@ -353,6 +349,8 @@ struct Plugin
353 349
354/** 350/**
355 * Obtain the location of ".my.cnf". 351 * Obtain the location of ".my.cnf".
352 *
353 * @param cfg our configuration
356 * @return NULL on error 354 * @return NULL on error
357 */ 355 */
358static char * 356static char *
@@ -414,6 +412,9 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
414 412
415/** 413/**
416 * Free a prepared statement. 414 * Free a prepared statement.
415 *
416 * @param plugin plugin context
417 * @param s prepared statement
417 */ 418 */
418static void 419static void
419prepared_statement_destroy (struct Plugin *plugin, 420prepared_statement_destroy (struct Plugin *plugin,
@@ -549,6 +550,8 @@ iopen (struct Plugin *ret)
549/** 550/**
550 * Run the given MySQL statement. 551 * Run the given MySQL statement.
551 * 552 *
553 * @param plugin plugin context
554 * @param statement SQL statement to run
552 * @return GNUNET_OK on success, GNUNET_SYSERR on error 555 * @return GNUNET_OK on success, GNUNET_SYSERR on error
553 */ 556 */
554static int 557static int
@@ -572,6 +575,8 @@ run_statement (struct Plugin *plugin,
572/** 575/**
573 * Create a prepared statement. 576 * Create a prepared statement.
574 * 577 *
578 * @param plugin plugin context
579 * @param statement SQL statement text to prepare
575 * @return NULL on error 580 * @return NULL on error
576 */ 581 */
577static struct GNUNET_MysqlStatementHandle * 582static struct GNUNET_MysqlStatementHandle *
@@ -592,6 +597,8 @@ prepared_statement_create (struct Plugin *plugin,
592/** 597/**
593 * Prepare a statement for running. 598 * Prepare a statement for running.
594 * 599 *
600 * @param plugin plugin context
601 * @param ret handle to prepared statement
595 * @return GNUNET_OK on success 602 * @return GNUNET_OK on success
596 */ 603 */
597static int 604static int
@@ -631,6 +638,7 @@ prepare_statement (struct Plugin *plugin,
631 * Bind the parameters for the given MySQL statement 638 * Bind the parameters for the given MySQL statement
632 * and run it. 639 * and run it.
633 * 640 *
641 * @param plugin plugin context
634 * @param s statement to bind and run 642 * @param s statement to bind and run
635 * @param ap arguments for the binding 643 * @param ap arguments for the binding
636 * @return GNUNET_SYSERR on error, GNUNET_OK on success 644 * @return GNUNET_SYSERR on error, GNUNET_OK on success
@@ -729,6 +737,8 @@ typedef int (*GNUNET_MysqlDataProcessor) (void *cls,
729/** 737/**
730 * Run a prepared SELECT statement. 738 * Run a prepared SELECT statement.
731 * 739 *
740 * @param plugin plugin context
741 * @param s statement to run
732 * @param result_size number of elements in results array 742 * @param result_size number of elements in results array
733 * @param results pointer to already initialized MYSQL_BIND 743 * @param results pointer to already initialized MYSQL_BIND
734 * array (of sufficient size) for passing results 744 * array (of sufficient size) for passing results
@@ -812,11 +822,13 @@ prepared_statement_run_select (struct Plugin *plugin,
812/** 822/**
813 * Run a prepared statement that does NOT produce results. 823 * Run a prepared statement that does NOT produce results.
814 * 824 *
825 * @param plugin plugin context
826 * @param s statement to run
827 * @param insert_id NULL or address where to store the row ID of whatever
828 * was inserted (only for INSERT statements!)
815 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective 829 * @param ... pairs and triplets of "MYSQL_TYPE_XXX" keys and their respective
816 * values (size + buffer-reference for pointers); terminated 830 * values (size + buffer-reference for pointers); terminated
817 * with "-1" 831 * with "-1"
818 * @param insert_id NULL or address where to store the row ID of whatever
819 * was inserted (only for INSERT statements!)
820 * @return GNUNET_SYSERR on error, otherwise 832 * @return GNUNET_SYSERR on error, otherwise
821 * the number of successfully affected rows 833 * the number of successfully affected rows
822 */ 834 */
@@ -848,6 +860,7 @@ prepared_statement_run (struct Plugin *plugin,
848/** 860/**
849 * Delete an value from the gn072 table. 861 * Delete an value from the gn072 table.
850 * 862 *
863 * @param plugin plugin context
851 * @param vkey vkey identifying the value to delete 864 * @param vkey vkey identifying the value to delete
852 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error 865 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
853 */ 866 */
@@ -883,6 +896,7 @@ do_delete_value (struct Plugin *plugin,
883/** 896/**
884 * Insert a value into the gn072 table. 897 * Insert a value into the gn072 table.
885 * 898 *
899 * @param plugin plugin context
886 * @param value the value to insert 900 * @param value the value to insert
887 * @param size size of the value 901 * @param size size of the value
888 * @param vkey vkey identifying the value henceforth (set) 902 * @param vkey vkey identifying the value henceforth (set)
@@ -922,6 +936,7 @@ do_insert_value (struct Plugin *plugin,
922/** 936/**
923 * Delete an entry from the gn090 table. 937 * Delete an entry from the gn090 table.
924 * 938 *
939 * @param plugin plugin context
925 * @param vkey vkey identifying the entry to delete 940 * @param vkey vkey identifying the entry to delete
926 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error 941 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
927 */ 942 */
@@ -955,6 +970,14 @@ do_delete_entry_by_vkey (struct Plugin *plugin,
955} 970}
956 971
957 972
973/**
974 * Function that simply returns GNUNET_OK
975 *
976 * @param cls closure, not used
977 * @param num_values not used
978 * @param values not used
979 * @return GNUNET_OK
980 */
958static int 981static int
959return_ok (void *cls, 982return_ok (void *cls,
960 unsigned int num_values, 983 unsigned int num_values,
@@ -964,6 +987,13 @@ return_ok (void *cls,
964} 987}
965 988
966 989
990/**
991 * FIXME.
992 *
993 * @param cls FIXME
994 * @param ncr FIXME
995 * @return FIXME
996 */
967static int 997static int
968iterator_helper_prepare (void *cls, 998iterator_helper_prepare (void *cls,
969 struct NextRequestClosure *nrc) 999 struct NextRequestClosure *nrc)
@@ -1059,7 +1089,7 @@ iterator_helper_prepare (void *cls,
1059 */ 1089 */
1060static void 1090static void
1061mysql_next_request_cont (void *next_cls, 1091mysql_next_request_cont (void *next_cls,
1062 const struct GNUNET_SCHEDULER_TaskContext *tc) 1092 const struct GNUNET_SCHEDULER_TaskContext *tc)
1063{ 1093{
1064 struct NextRequestClosure *nrc = next_cls; 1094 struct NextRequestClosure *nrc = next_cls;
1065 struct Plugin *plugin; 1095 struct Plugin *plugin;
@@ -1239,14 +1269,16 @@ mysql_plugin_next_request (void *next_cls,
1239 * using the given query to select and order 1269 * using the given query to select and order
1240 * the items. 1270 * the items.
1241 * 1271 *
1272 * @param plugin plugin context
1242 * @param type entries of which type should be considered? 1273 * @param type entries of which type should be considered?
1243 * Use 0 for any type. 1274 * @param iter_select which iterator statement are we using
1244 * @param iter never NULL
1245 * @param is_asc are we using ascending order? 1275 * @param is_asc are we using ascending order?
1276 * @param dviter function to call on each matching item
1277 * @param dviter_cls closure for dviter
1246 */ 1278 */
1247static void 1279static void
1248iterateHelper (struct Plugin *plugin, 1280iterateHelper (struct Plugin *plugin,
1249 unsigned int type, 1281 enum GNUNET_BLOCK_Type type,
1250 int is_asc, 1282 int is_asc,
1251 unsigned int iter_select, 1283 unsigned int iter_select,
1252 PluginIterator dviter, 1284 PluginIterator dviter,