aboutsummaryrefslogtreecommitdiff
path: root/src/my
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-05-25 16:37:52 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-05-25 16:37:52 +0000
commit4ed6ea74cc5ee8cdb7b31252ea86570be8268dde (patch)
tree3dd5bb385d97b3d3e5717073adbe1397d5b971f5 /src/my
parent0623fdd510f1dacd25f1b8ff592ff6de038c51dc (diff)
downloadgnunet-4ed6ea74cc5ee8cdb7b31252ea86570be8268dde.tar.gz
gnunet-4ed6ea74cc5ee8cdb7b31252ea86570be8268dde.zip
fix warning compilation libgnunetmy
Diffstat (limited to 'src/my')
-rw-r--r--src/my/my_result_helper.c6
-rw-r--r--src/my/test_my.c219
2 files changed, 138 insertions, 87 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
index f58c8e150..cced22482 100644
--- a/src/my/my_result_helper.c
+++ b/src/my/my_result_helper.c
@@ -406,7 +406,7 @@ extract_string (void * cls,
406 field = mysql_fetch_field (result); 406 field = mysql_fetch_field (result);
407 407
408 //If it's the correct field 408 //If it's the correct field
409 if (field == fname) 409 if (field->name == fname)
410 { 410 {
411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
412 "Field '%s' does not exist in result", 412 "Field '%s' does not exist in result",
@@ -504,7 +504,7 @@ extract_uint16 (void *cls,
504{ 504{
505 //TO COMPLETE 505 //TO COMPLETE
506 uint16_t *udst = dst; 506 uint16_t *udst = dst;
507 const uint16_t *res; 507 uint16_t *res;
508 508
509 MYSQL_ROW rows; 509 MYSQL_ROW rows;
510 MYSQL_FIELD * field; 510 MYSQL_FIELD * field;
@@ -536,7 +536,7 @@ extract_uint16 (void *cls,
536 return GNUNET_SYSERR; 536 return GNUNET_SYSERR;
537 } 537 }
538 538
539 res = (uint16_t) rows[row]; 539 res = atoi (rows[row]);
540 *udst = ntohs (*res); 540 *udst = ntohs (*res);
541 541
542 return GNUNET_OK; 542 return GNUNET_OK;
diff --git a/src/my/test_my.c b/src/my/test_my.c
index 1ab6ef1b7..2df24d444 100644
--- a/src/my/test_my.c
+++ b/src/my/test_my.c
@@ -34,30 +34,26 @@
34 #GNUNET_OK on success 34 #GNUNET_OK on success
35 #GNUNET_SYSERR on failure 35 #GNUNET_SYSERR on failure
36 */ 36 */
37
38/** OK **/
37static int 39static int
38mysql_prepare (MYSQL * mysql) 40mysql_prepare (MYSQL * mysql)
39{ 41{
40 MYSQL_RES *result;
41 MYSQL_STMT *stmt; 42 MYSQL_STMT *stmt;
42
43 stmt = mysql_stmt_init (mysql); 43 stmt = mysql_stmt_init (mysql);
44#define PREPARE (name, sql, ...) 44#define PREPARE(name, sql, size) \
45 do 45 do { \
46 { 46 int ret = mysql_stmt_prepare (stmt, sql, size); \
47 result = mysql_stmt_prepare(stmt, name, sql, __VA_ARGS__); 47 if (ret ) \
48 if (result) 48 { \
49 { 49 GNUNET_break (0); \
50 GNUNET_break (0); 50 mysql_stmt_free_result (stmt); \
51 mysql_stmt_free_result (stmt); 51 return GNUNET_SYSERR; \
52 result = NULL; 52 } \
53 return GNUNET_SYSERR; 53 mysql_stmt_free_result (stmt); \
54 }
55 mysql_stmt_free_result (stmt);
56 result = NULL;
57 } while (0); 54 } while (0);
58 55
59 PREPARE ("test_insert", 56 char *query1 = "INSERT INTO test_my ("
60 "INSERT INTO test_my ("
61 "pub" 57 "pub"
62 ",sig" 58 ",sig"
63 ",abs_time" 59 ",abs_time"
@@ -68,12 +64,13 @@ mysql_prepare (MYSQL * mysql)
68 ",u32" 64 ",u32"
69 ",u64" 65 ",u64"
70 ") VALUES " 66 ") VALUES "
71 "($1, $2, $3, $4, $5, $6, 67 "(1, 2, 3, 4, 5, 6,"
72 $7, $8, $9);", 68 "7, 8, 9);";
73 9, NULL); 69 PREPARE("test_insert",
70 query1,
71 strlen (query1));
74 72
75 PREPARE ("test_select", 73 char *query2 = "SELECT"
76 "SELECT"
77 "pub" 74 "pub"
78 ",sig" 75 ",sig"
79 ",abs_time" 76 ",abs_time"
@@ -85,8 +82,12 @@ mysql_prepare (MYSQL * mysql)
85 ",u64" 82 ",u64"
86 " FROM test_my" 83 " FROM test_my"
87 " ORDER BY abs_time DESC" 84 " ORDER BY abs_time DESC"
88 " LIMIT 1;", 85 " LIMIT 1;";
89 0, NULL); 86
87 PREPARE("test_select",
88 query2,
89 strlen (query2));
90
90 return GNUNET_OK; 91 return GNUNET_OK;
91#undef PREPARE 92#undef PREPARE
92} 93}
@@ -97,35 +98,37 @@ mysql_prepare (MYSQL * mysql)
97 * @param mysql coonection handle to initialize 98 * @param mysql coonection handle to initialize
98 * @return 0 on succes 99 * @return 0 on succes
99 */ 100 */
101
102/*** FIXE THIS FUNCTION ***/
100static int 103static int
101run_queries (MYSQL * mysql) 104run_queries (MYSQL * mysql)
102{ 105{
103 struct GNUNET_CRYPTO_RsaPublicKey *pub; 106 struct GNUNET_CRYPTO_RsaPublicKey *pub;
104 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; 107// struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
105 struct GNUNET_CRYPTO_RsaSignature *sig; 108 struct GNUNET_CRYPTO_RsaSignature *sig;
106 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; 109// struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
107 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get () ; 110 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get () ;
108 struct GNUNET_TIME_Absolute abs_time2; 111// struct GNUNET_TIME_Absolute abs_time2;
109 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; 112 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
110 struct GNUNET_TIME_Absolute forever2; 113 // struct GNUNET_TIME_Absolute forever2;
111 struct GNUNET_HashCode hc; 114 struct GNUNET_HashCode hc;
112 struct GNUNET_HashCode hc2; 115// struct GNUNET_HashCode hc2;
113 MYSQL_RES * result; 116// MYSQL_RES * result;
114 int ret; 117// int ret;
115 struct GNUNET_CRYPTO_RsaPrivateKey *priv; 118 struct GNUNET_CRYPTO_RsaPrivateKey *priv;
116 const char msg[] = "hello"; 119 const char msg[] = "hello";
117 void *msg2; 120// void *msg2;
118 struct GNUNET_HashCode hmsg; 121 struct GNUNET_HashCode hmsg;
119 size_t msg2_len; 122// size_t msg2_len;
120 uint16_t u16; 123 uint16_t u16;
121 uint16_t u162; 124 // uint16_t u162;
122 uint32_t u32; 125 uint32_t u32;
123 uint32_t u322; 126 // uint32_t u322;
124 uint64_t u64; 127 uint64_t u64;
125 uint64_t u642; 128 // uint64_t u642;
126 129
127 priv = GNUNET_CRYPTO_rsa_private_key_create (1024); 130 priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
128 pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); 131 pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
129 memset (&hmsg, 42, sizeof (hmsg)); 132 memset (&hmsg, 42, sizeof (hmsg));
130 sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, 133 sig = GNUNET_CRYPTO_rsa_sign_fdh (priv,
131 &hmsg); 134 &hmsg);
@@ -133,40 +136,87 @@ run_queries (MYSQL * mysql)
133 u32 = 32; 136 u32 = 32;
134 u64 = 64; 137 u64 = 64;
135 138
136 { 139 struct GNUNET_CONFIGURATION_Handle * configuration_handle;
140 configuration_handle = GNUNET_CONFIGURATION_create();
141
142 char *query1 = "INSERT INTO test_my ("
143 "pub"
144 ",sig"
145 ",abs_time"
146 ",forever"
147 ",hash"
148 ",vsize"
149 ",u16"
150 ",u32"
151 ",u64"
152 ") VALUES "
153 "(1, 2, 3, 4, 5, 6,"
154 "7, 8, 9);";
155
156/* char *query2 = "SELECT"
157 "pub"
158 ",sig"
159 ",abs_time"
160 ",forever"
161 ",hash"
162 ",vsize"
163 ",u16"
164 ",u32"
165 ",u64"
166 " FROM test_my"
167 " ORDER BY abs_time DESC"
168 " LIMIT 1;";
169*/
170 struct GNUNET_MYSQL_Context *context_insert = NULL;
171 // context_insert = GNUNET_MYSQL_context_create (configuration_handle,
172 // NULL);
173
174 struct GNUNET_MYSQL_StatementHandle *statements_handle = NULL;
175 // statements_handle = GNUNET_MYSQL_statement_prepare(context_insert, query1);
176
177
178 // {
137 struct GNUNET_MY_QueryParam params_insert[] = { 179 struct GNUNET_MY_QueryParam params_insert[] = {
138 GNUNET_MY_query_param_rsa_public_key (pub), 180 GNUNET_MY_query_param_rsa_public_key (pub),
139 GNUNET_MY_query_param_rsa_signature (sig), 181 GNUNET_MY_query_param_rsa_signature (sig),
140 GNUNET_MY_query_param_absolute_time (&abs_time), 182 GNUNET_MY_query_param_absolute_time (&abs_time),
141 GNUNET_MY_query_param_absolute_time (&forever), 183 GNUNET_MY_query_param_absolute_time (&forever),
142 GNUNET_MY_query_param_auto_from_type (&hc), 184 GNUNET_MY_query_param_auto_from_type (&hc),
143 GNUNET_MY_query_param_fixed_size (msg, strlen (msg)), 185 GNUNET_MY_query_param_fixed_size (msg, strlen (msg)),
144 GNUNET_MY_query_param_uint16 (&u16), 186 GNUNET_MY_query_param_uint16 (&u16),
145 GNUNET_MY_query_param_uint32 (&u32), 187 GNUNET_MY_query_param_uint32 (&u32),
146 GNUNET_MY_query_param_uint64 (&u64), 188 GNUNET_MY_query_param_uint64 (&u64),
147 GNUNET_MY_query_param_end 189 GNUNET_MY_query_param_end
148 }; 190 };
149 191
150 struct GNUNET_MY_QueryParam params_select[] = { 192/* struct GNUNET_MY_QueryParam params_select[] = {
151 GNUNET_MY_query_param_end 193 GNUNET_MY_query_param_end
152 }; 194 };
153 195
154 struct GNUNET_MY_ResultSpec results_select[] = { 196 struct GNUNET_MY_Context *context_insert[] = {
155 GNUNET_MY_result_spec_rsa_public_key ("pub", &pub2), 197
156 GNUNET_MY_result_spec_rsa_signature ("sig", &sig2),
157 GNUNET_MY_result_spec_absolute_time ("abs_time", &abs_time2),
158 GNUNET_MY_result_spec_absolute_time ("forever", &forever2),
159 GNUNET_MY_result_spec_auto_from_type ("hash", &hc2),
160 GNUNET_MY_result_spec_variable_size ("vsize", &msg2, &msg2_len),
161 GNUNET_MY_result_spec_uint16 ("u16", &u162),
162 GNUNET_MY_result_spec_uint32 ("u32", &u322),
163 GNUNET_MY_result_spec_uint64 ("u64", &u642),
164 GNUNET_MY_result_epc_end
165 }; 198 };
166 199
167 if(GNUNET_MY_exec_prepared ( mysql, 200 struct GNUNET_MY_StatementHandle *statement_insert[] = {
168 "test_insert", 201
169 params_insert)) 202 };
203*/
204/* struct GNUNET_MY_ResultSpec results_select[] = {
205 GNUNET_MY_result_spec_rsa_public_key (&pub2),
206 GNUNET_MY_result_spec_rsa_signature (&sig2),
207 GNUNET_MY_result_spec_absolute_time (&abs_time2),
208 GNUNET_MY_result_spec_absolute_time (&forever2),
209 GNUNET_MY_result_spec_auto_from_type (&hc2),
210 GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len),
211 GNUNET_MY_result_spec_uint16 (&u162),
212 GNUNET_MY_result_spec_uint32 (&u322),
213 GNUNET_MY_result_spec_uint64 (&u642),
214 GNUNET_MY_result_spec_end
215 };
216*/
217 if(GNUNET_MY_exec_prepared ( context_insert,
218 statements_handle,
219 params_insert));
170 { 220 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 "Database failure: \n"); 222 "Database failure: \n");
@@ -175,14 +225,14 @@ run_queries (MYSQL * mysql)
175 225
176 GNUNET_CRYPTO_rsa_signature_free (sig); 226 GNUNET_CRYPTO_rsa_signature_free (sig);
177 GNUNET_CRYPTO_rsa_private_key_free (priv); 227 GNUNET_CRYPTO_rsa_private_key_free (priv);
178 GNUNET_CYPTO_rsa_public_key_free (pub); 228 GNUNET_CRYPTO_rsa_public_key_free (pub);
179 return 1; 229 return 1;
180 } 230 }
181 231
182 //free result 232 //free result
183 233
184 result = GNUNET_MY_exec_prepared (mysql, "test_select", params_select); 234/* result = GNUNET_MY_exec_prepared (mysql, "test_select", params_select);
185/* if(1 != mysql_fetch_length (result)) 235 if(1 != mysql_fetch_length (result))
186 { 236 {
187 GNUNET_break (0); 237 GNUNET_break (0);
188 GNUNET_CRYPTO_rsa_signature_free (sig); 238 GNUNET_CRYPTO_rsa_signature_free (sig);
@@ -191,7 +241,7 @@ run_queries (MYSQL * mysql)
191 241
192 return 1; 242 return 1;
193 } 243 }
194*/ 244
195 if (GNUNET_MY_exec_prepared (mysql 245 if (GNUNET_MY_exec_prepared (mysql
196 , "test_select" 246 , "test_select"
197 , params_select)) 247 , params_select))
@@ -205,7 +255,7 @@ run_queries (MYSQL * mysql)
205 } 255 }
206 256
207 257
208 ret = GNUNET_MY_extract_result (result, 258/* ret = GNUNET_MY_extract_result (result,
209 results_select, 259 results_select,
210 0); 260 0);
211 GNUNET_break (GNUNET_YES == ret); 261 GNUNET_break (GNUNET_YES == ret);
@@ -237,15 +287,16 @@ run_queries (MYSQL * mysql)
237 287
238 if (GNUNET_OK != ret) 288 if (GNUNET_OK != ret)
239 return 1; 289 return 1;
240 return 0; 290 */ return 0;
241} 291}
242 292
243 293
294/** OK **/
244int 295int
245main (int argc, const char * const argv[]) 296main (int argc, const char * const argv[])
246{ 297{
247 298
248 MYSQL *mysql; 299 MYSQL mysql ;
249// MYSQL_RES *result; 300// MYSQL_RES *result;
250 301
251 int ret; 302 int ret;
@@ -255,9 +306,9 @@ main (int argc, const char * const argv[])
255 char *mdp = ""; 306 char *mdp = "";
256 char *database = ""; 307 char *database = "";
257 308
258 mysql_init (mysql); 309 mysql_init (&mysql);
259 310
260 mysql_options (mysql, 311 mysql_options (&mysql,
261 MYSQL_READ_DEFAULT_GROUP, 312 MYSQL_READ_DEFAULT_GROUP,
262 NULL); 313 NULL);
263 314
@@ -265,7 +316,7 @@ main (int argc, const char * const argv[])
265 "WARNING", 316 "WARNING",
266 NULL); 317 NULL);
267 318
268 if (! mysql_real_connect (mysql 319 if ( mysql_real_connect (&mysql
269 ,hote 320 ,hote
270 ,pseudo 321 ,pseudo
271 ,mdp,database 322 ,mdp,database
@@ -276,13 +327,13 @@ main (int argc, const char * const argv[])
276 { 327 {
277 fprintf( stderr, 328 fprintf( stderr,
278 "Cannot run test, database connection failed : %s\n", 329 "Cannot run test, database connection failed : %s\n",
279 mysql_error (mysql)); 330 mysql_error (&mysql));
280 GNUNET_break (0); 331 GNUNET_break (0);
281 332
282 return 0; 333 return 0;
283 } 334 }
284 335
285 if (mysql_query (mysql, "CREATE TABLE test_my(" 336 if (mysql_query (&mysql, "CREATE TABLE test_my("
286 "pub INT" 337 "pub INT"
287 ", sig INT" 338 ", sig INT"
288 ", abs_time BIGINT" 339 ", abs_time BIGINT"
@@ -296,32 +347,32 @@ main (int argc, const char * const argv[])
296 { 347 {
297 fprintf (stderr, 348 fprintf (stderr,
298 "Failed to create table : %s\n", 349 "Failed to create table : %s\n",
299 mysql_error (mysql)); 350 mysql_error (&mysql));
300 351
301 mysql_close (mysql); 352 mysql_close (&mysql);
302 return 1; 353 return 1;
303 } 354 }
304 355
305 if (GNUNET_OK != 356 if (GNUNET_OK !=
306 mysql_prepare (mysql)) 357 mysql_prepare (&mysql))
307 { 358 {
308 GNUNET_break (0) ; 359 GNUNET_break (0) ;
309 mysql_close (mysql); 360 mysql_close (&mysql);
310 return 1; 361 return 1;
311 } 362 }
312 363
313 ret = run_queries (mysql); 364 ret = run_queries (&mysql);
314 365
315 if (mysql_query (mysql, 366 if (mysql_query (&mysql,
316 "DROP TABLE test_my;")) 367 "DROP TABLE test_my;"))
317 { 368 {
318 fprintf (stderr, "Failed to drop table : %s\n", 369 fprintf (stderr, "Failed to drop table : %s\n",
319 mysql_error (mysql)); 370 mysql_error (&mysql));
320 mysql_close (mysql); 371 mysql_close (&mysql);
321 return 1; 372 return 1;
322 } 373 }
323 374
324 mysql_close (mysql); 375 mysql_close (&mysql);
325 376
326 return ret; 377 return ret;
327} 378}