diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-07 13:50:08 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-07 13:50:08 +0000 |
commit | f12ac33d46fad89af94831f16dcdebd436a851da (patch) | |
tree | 0e79ed94a2348be62f8c683421251d69bcc159f3 /src/my | |
parent | ec817d5981e88f06f9f153cd423d13860fba4b57 (diff) | |
download | gnunet-f12ac33d46fad89af94831f16dcdebd436a851da.tar.gz gnunet-f12ac33d46fad89af94831f16dcdebd436a851da.zip |
written function cleanup
Diffstat (limited to 'src/my')
-rw-r--r-- | src/my/my.c | 22 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 49 | ||||
-rw-r--r-- | src/my/my_result_helper.c | 1 | ||||
-rw-r--r-- | src/my/test_my.c | 395 |
4 files changed, 232 insertions, 235 deletions
diff --git a/src/my/my.c b/src/my/my.c index 5409166fb..cec22716f 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -65,6 +65,10 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
65 | p, | 65 | p, |
66 | &qbind[off])) | 66 | &qbind[off])) |
67 | { | 67 | { |
68 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
69 | "Conversion for MySQL query failed at offset %u\n", | ||
70 | i); | ||
71 | GNUNET_MY_cleanup_query (params); | ||
68 | return GNUNET_SYSERR; | 72 | return GNUNET_SYSERR; |
69 | } | 73 | } |
70 | off += p->num_params; | 74 | off += p->num_params; |
@@ -88,6 +92,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
88 | "mysql_stmt_execute", __FILE__, __LINE__, | 92 | "mysql_stmt_execute", __FILE__, __LINE__, |
89 | mysql_stmt_error (stmt)); | 93 | mysql_stmt_error (stmt)); |
90 | GNUNET_MYSQL_statements_invalidate (mc); | 94 | GNUNET_MYSQL_statements_invalidate (mc); |
95 | GNUNET_MY_cleanup_query (params); | ||
91 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
92 | } | 97 | } |
93 | } | 98 | } |
@@ -97,6 +102,23 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
97 | 102 | ||
98 | 103 | ||
99 | /** | 104 | /** |
105 | * Free all memory that was allocated in @a qp during | ||
106 | * #GNUNET_MY_exect_prepared(). | ||
107 | * | ||
108 | * @param qp query specification to clean up | ||
109 | */ | ||
110 | void | ||
111 | GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp) | ||
112 | { | ||
113 | unsigned int i; | ||
114 | |||
115 | for (i=0;NULL != qp[i].cleaner;i++) | ||
116 | qp[i].cleaner (qp[i].conv_cls, | ||
117 | &qp[i]); | ||
118 | } | ||
119 | |||
120 | |||
121 | /** | ||
100 | * Extract results from a query result according to the given | 122 | * Extract results from a query result according to the given |
101 | * specification. Always fetches the next row. | 123 | * specification. Always fetches the next row. |
102 | * | 124 | * |
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index 99bb4a5e4..cfa52b43a 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -62,6 +62,7 @@ GNUNET_MY_query_param_fixed_size (const void *ptr, | |||
62 | { | 62 | { |
63 | struct GNUNET_MY_QueryParam qp = { | 63 | struct GNUNET_MY_QueryParam qp = { |
64 | .conv = &my_conv_fixed_size, | 64 | .conv = &my_conv_fixed_size, |
65 | .cleaner = NULL, | ||
65 | .conv_cls = NULL, | 66 | .conv_cls = NULL, |
66 | .num_params = 1, | 67 | .num_params = 1, |
67 | .data = ptr, | 68 | .data = ptr, |
@@ -106,7 +107,6 @@ my_conv_uint16 (void *cls, | |||
106 | if (NULL == u_nbo) | 107 | if (NULL == u_nbo) |
107 | return -1; | 108 | return -1; |
108 | 109 | ||
109 | // *u_nbo = htons (*u_hbo); | ||
110 | *u_nbo = *u_hbo; | 110 | *u_nbo = *u_hbo; |
111 | 111 | ||
112 | qbind->buffer = (void *) u_nbo; | 112 | qbind->buffer = (void *) u_nbo; |
@@ -126,6 +126,7 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x) | |||
126 | { | 126 | { |
127 | struct GNUNET_MY_QueryParam res = { | 127 | struct GNUNET_MY_QueryParam res = { |
128 | .conv = &my_conv_uint16, | 128 | .conv = &my_conv_uint16, |
129 | .cleaner = NULL, | ||
129 | .conv_cls = NULL, | 130 | .conv_cls = NULL, |
130 | .num_params = 1, | 131 | .num_params = 1, |
131 | .data = x, | 132 | .data = x, |
@@ -174,6 +175,7 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x) | |||
174 | { | 175 | { |
175 | struct GNUNET_MY_QueryParam res = { | 176 | struct GNUNET_MY_QueryParam res = { |
176 | .conv = &my_conv_uint32, | 177 | .conv = &my_conv_uint32, |
178 | .cleaner = NULL, | ||
177 | .conv_cls = NULL, | 179 | .conv_cls = NULL, |
178 | .num_params = 1, | 180 | .num_params = 1, |
179 | .data = x, | 181 | .data = x, |
@@ -222,6 +224,7 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x) | |||
222 | { | 224 | { |
223 | struct GNUNET_MY_QueryParam res = { | 225 | struct GNUNET_MY_QueryParam res = { |
224 | .conv = &my_conv_uint64, | 226 | .conv = &my_conv_uint64, |
227 | .cleaner = NULL, | ||
225 | .conv_cls = NULL, | 228 | .conv_cls = NULL, |
226 | .num_params = 1, | 229 | .num_params = 1, |
227 | .data = x, | 230 | .data = x, |
@@ -260,6 +263,27 @@ my_conv_rsa_public_key (void *cls, | |||
260 | } | 263 | } |
261 | 264 | ||
262 | 265 | ||
266 | /** | ||
267 | * Function called to clean up memory allocated | ||
268 | * by a #GNUNET_MY_ResultConverter. | ||
269 | * | ||
270 | * @param cls closure | ||
271 | * @param rd result data to clean up | ||
272 | */ | ||
273 | static void | ||
274 | my_clean_rsa_public_key (void *cls, | ||
275 | struct GNUNET_MY_QueryParam *qp) | ||
276 | { | ||
277 | struct GNUNET_CRYPTO_RsaPublicKey **pk = qp->data; | ||
278 | |||
279 | if (NULL != *pk) | ||
280 | { | ||
281 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | ||
282 | *pk = NULL; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | |||
263 | /** | 287 | /** |
264 | * Generate query parameter for an RSA public key. The | 288 | * Generate query parameter for an RSA public key. The |
265 | * database must contain a BLOB type in the respective position. | 289 | * database must contain a BLOB type in the respective position. |
@@ -272,6 +296,7 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x | |||
272 | { | 296 | { |
273 | struct GNUNET_MY_QueryParam res = { | 297 | struct GNUNET_MY_QueryParam res = { |
274 | .conv = &my_conv_rsa_public_key, | 298 | .conv = &my_conv_rsa_public_key, |
299 | .cleaner = &my_clean_rsa_public_key, | ||
275 | .conv_cls = NULL, | 300 | .conv_cls = NULL, |
276 | .num_params = 1, | 301 | .num_params = 1, |
277 | .data = x, | 302 | .data = x, |
@@ -312,6 +337,27 @@ my_conv_rsa_signature (void *cls, | |||
312 | 337 | ||
313 | 338 | ||
314 | /** | 339 | /** |
340 | * Function called to clean up memory allocated | ||
341 | * by a #GNUNET_MY_QueryConverter. | ||
342 | * | ||
343 | * @param cls closure | ||
344 | * @param rd result data to clean up | ||
345 | */ | ||
346 | static void | ||
347 | my_clean_rsa_signature (void *cls, | ||
348 | struct GNUNET_MY_QueryParam *qp) | ||
349 | { | ||
350 | struct GNUNET_CRYPTO_RsaSignature **sig = qp->data; | ||
351 | |||
352 | if (NULL != *sig) | ||
353 | { | ||
354 | GNUNET_CRYPTO_rsa_signature_free (*sig); | ||
355 | *sig = NULL; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | |||
360 | /** | ||
315 | * Generate query parameter for an RSA signature. The | 361 | * Generate query parameter for an RSA signature. The |
316 | * database must contain a BLOB type in the respective position | 362 | * database must contain a BLOB type in the respective position |
317 | * | 363 | * |
@@ -323,6 +369,7 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
323 | { | 369 | { |
324 | struct GNUNET_MY_QueryParam res = { | 370 | struct GNUNET_MY_QueryParam res = { |
325 | .conv = &my_conv_rsa_signature, | 371 | .conv = &my_conv_rsa_signature, |
372 | .cleaner = &my_clean_rsa_signature, | ||
326 | .conv_cls = NULL, | 373 | .conv_cls = NULL, |
327 | .num_params = 1, | 374 | .num_params = 1, |
328 | .data = (x), | 375 | .data = (x), |
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index 9cfd373c7..6f1b27065 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -43,7 +43,6 @@ pre_extract_varsize_blob (void *cls, | |||
43 | results[0].buffer = NULL; | 43 | results[0].buffer = NULL; |
44 | results[0].buffer_length = 0; | 44 | results[0].buffer_length = 0; |
45 | results[0].length = &rs->mysql_bind_output_length; | 45 | results[0].length = &rs->mysql_bind_output_length; |
46 | // results[0].buffer_type = MYSQL_TYPE_BLOB; | ||
47 | 46 | ||
48 | return GNUNET_OK; | 47 | return GNUNET_OK; |
49 | } | 48 | } |
diff --git a/src/my/test_my.c b/src/my/test_my.c index f0766ac2c..f7e6ae68a 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -38,44 +38,44 @@ static int | |||
38 | run_queries (struct GNUNET_MYSQL_Context *context) | 38 | run_queries (struct GNUNET_MYSQL_Context *context) |
39 | { | 39 | { |
40 | struct GNUNET_CRYPTO_RsaPublicKey *pub; | 40 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
41 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; | 41 | struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; |
42 | struct GNUNET_CRYPTO_RsaSignature *sig; | 42 | struct GNUNET_CRYPTO_RsaSignature *sig; |
43 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; | 43 | struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; |
44 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); | 44 | struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); |
45 | struct GNUNET_TIME_Absolute abs_time2; | 45 | struct GNUNET_TIME_Absolute abs_time2; |
46 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; | 46 | struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; |
47 | struct GNUNET_TIME_Absolute forever2; | 47 | struct GNUNET_TIME_Absolute forever2; |
48 | struct GNUNET_HashCode hc; | 48 | struct GNUNET_HashCode hc; |
49 | struct GNUNET_HashCode hc2; | 49 | struct GNUNET_HashCode hc2; |
50 | const char msg[] = "hello"; | 50 | const char msg[] = "hello"; |
51 | void *msg2; | 51 | void *msg2; |
52 | size_t msg2_len; | 52 | size_t msg2_len; |
53 | 53 | ||
54 | uint16_t u16; | 54 | uint16_t u16; |
55 | uint16_t u162; | 55 | uint16_t u162; |
56 | uint32_t u32; | 56 | uint32_t u32; |
57 | uint32_t u322; | 57 | uint32_t u322; |
58 | uint64_t u64; | 58 | uint64_t u64; |
59 | uint64_t u642; | 59 | uint64_t u642; |
60 | 60 | ||
61 | int ret; | 61 | int ret; |
62 | 62 | ||
63 | struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; | 63 | struct GNUNET_MYSQL_StatementHandle *statements_handle_insert; |
64 | struct GNUNET_MYSQL_StatementHandle *statements_handle_select; | 64 | struct GNUNET_MYSQL_StatementHandle *statements_handle_select; |
65 | 65 | ||
66 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; | 66 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; |
67 | struct GNUNET_HashCode hmsg; | 67 | struct GNUNET_HashCode hmsg; |
68 | 68 | ||
69 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); | 69 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); |
70 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); | 70 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); |
71 | memset (&hmsg, 42, sizeof(hmsg)); | 71 | memset (&hmsg, 42, sizeof(hmsg)); |
72 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, | 72 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, |
73 | &hmsg); | 73 | &hmsg); |
74 | u16 = 16; | 74 | u16 = 16; |
75 | u32 = 32; | 75 | u32 = 32; |
76 | u64 = 64; | 76 | u64 = 64; |
77 | 77 | ||
78 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 78 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
79 | "INSERT INTO test_my2 (" | 79 | "INSERT INTO test_my2 (" |
80 | " pub" | 80 | " pub" |
81 | ",sig" | 81 | ",sig" |
@@ -89,190 +89,146 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
89 | ") VALUES " | 89 | ") VALUES " |
90 | "( ?, ?, ?, ?, ?, ?, ?, ?, ?)"); | 90 | "( ?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
91 | 91 | ||
92 | if (NULL == statements_handle_insert) | 92 | if (NULL == statements_handle_insert) |
93 | { | 93 | { |
94 | fprintf (stderr, "Failed to prepared statement INSERT\n"); | 94 | fprintf (stderr, "Failed to prepared statement INSERT\n"); |
95 | return 1; | 95 | return 1; |
96 | } | 96 | } |
97 | 97 | ||
98 | struct GNUNET_MY_QueryParam params_insert[] = { | 98 | struct GNUNET_MY_QueryParam params_insert[] = { |
99 | GNUNET_MY_query_param_rsa_public_key (pub), | 99 | GNUNET_MY_query_param_rsa_public_key (pub), |
100 | GNUNET_MY_query_param_rsa_signature (sig), | 100 | GNUNET_MY_query_param_rsa_signature (sig), |
101 | GNUNET_MY_query_param_absolute_time (&abs_time), | 101 | GNUNET_MY_query_param_absolute_time (&abs_time), |
102 | GNUNET_MY_query_param_absolute_time (&forever), | 102 | GNUNET_MY_query_param_absolute_time (&forever), |
103 | GNUNET_MY_query_param_auto_from_type (&hc), | 103 | GNUNET_MY_query_param_auto_from_type (&hc), |
104 | GNUNET_MY_query_param_fixed_size (msg, strlen (msg)), | 104 | GNUNET_MY_query_param_fixed_size (msg, strlen (msg)), |
105 | GNUNET_MY_query_param_uint16 (&u16), | 105 | GNUNET_MY_query_param_uint16 (&u16), |
106 | GNUNET_MY_query_param_uint32 (&u32), | 106 | GNUNET_MY_query_param_uint32 (&u32), |
107 | GNUNET_MY_query_param_uint64 (&u64), | 107 | GNUNET_MY_query_param_uint64 (&u64), |
108 | GNUNET_MY_query_param_end | 108 | GNUNET_MY_query_param_end |
109 | }; | 109 | }; |
110 | 110 | ||
111 | /* statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 111 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, |
112 | "INSERT INTO test_my2 (" | 112 | statements_handle_insert, |
113 | " abs_time" | 113 | params_insert)) |
114 | ",forever" | 114 | { |
115 | ",hash" | 115 | fprintf (stderr, "Failed to execute prepared statement INSERT\n"); |
116 | ",u16" | 116 | return 1; |
117 | ",u32" | 117 | } |
118 | ",u64" | 118 | |
119 | ") VALUES " | 119 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, |
120 | "( ?, ?, ?, ?, ?, ?)"); | 120 | "SELECT" |
121 | 121 | " pub" | |
122 | struct GNUNET_MY_QueryParam params_insert[] = { | 122 | ",sig" |
123 | GNUNET_MY_query_param_absolute_time (&abs_time), | 123 | ",abs_time" |
124 | GNUNET_MY_query_param_absolute_time (&forever), | 124 | ",forever" |
125 | GNUNET_MY_query_param_auto_from_type (&hc), | 125 | ",hash" |
126 | GNUNET_MY_query_param_uint16 (&u16), | 126 | ",vsize" |
127 | GNUNET_MY_query_param_uint32 (&u32), | 127 | ",u16" |
128 | GNUNET_MY_query_param_uint64 (&u64), | 128 | ",u32" |
129 | GNUNET_MY_query_param_end | 129 | ",u64" |
130 | }; | 130 | " FROM test_my2"); |
131 | */ | 131 | |
132 | if (GNUNET_OK != GNUNET_MY_exec_prepared(context, | 132 | if (NULL == statements_handle_select) |
133 | statements_handle_insert, | 133 | { |
134 | params_insert)) | 134 | fprintf(stderr, "Failed to prepared statement SELECT\n"); |
135 | { | 135 | return 1; |
136 | fprintf (stderr, "Failed to execute prepared statement INSERT\n"); | 136 | } |
137 | return 1; | 137 | |
138 | } | 138 | struct GNUNET_MY_QueryParam params_select[] = { |
139 | 139 | GNUNET_MY_query_param_end | |
140 | 140 | }; | |
141 | 141 | ||
142 | /* statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | 142 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, |
143 | "SELECT" | 143 | statements_handle_select, |
144 | " pub" | 144 | params_select)) |
145 | ",sig" | 145 | { |
146 | ",abs_time" | ||
147 | ",forever" | ||
148 | ",hash" | ||
149 | ",vsize" | ||
150 | ",u16" | ||
151 | ",u32" | ||
152 | ",u64" | ||
153 | " FROM test_my" | ||
154 | " ORDER BY abs_time DESC " | ||
155 | " LIMIT 1;"); | ||
156 | |||
157 | */ | ||
158 | statements_handle_select = GNUNET_MYSQL_statement_prepare (context, | ||
159 | "SELECT" | ||
160 | " pub" | ||
161 | ",sig" | ||
162 | ",abs_time" | ||
163 | ",forever" | ||
164 | ",hash" | ||
165 | ",vsize" | ||
166 | ",u16" | ||
167 | ",u32" | ||
168 | ",u64" | ||
169 | " FROM test_my2"); | ||
170 | |||
171 | if (NULL == statements_handle_select) | ||
172 | { | ||
173 | fprintf(stderr, "Failed to prepared statement SELECT\n"); | ||
174 | return 1; | ||
175 | } | ||
176 | |||
177 | struct GNUNET_MY_QueryParam params_select[] = { | ||
178 | GNUNET_MY_query_param_end | ||
179 | }; | ||
180 | |||
181 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | ||
182 | statements_handle_select, | ||
183 | params_select)) | ||
184 | { | ||
185 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); | 146 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); |
186 | return 1; | 147 | return 1; |
187 | } | 148 | } |
188 | 149 | ||
189 | /* | 150 | struct GNUNET_MY_ResultSpec results_select[] = { |
190 | struct GNUNET_MY_ResultSpec results_select[] = { | 151 | GNUNET_MY_result_spec_rsa_public_key (&pub2), |
191 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | 152 | GNUNET_MY_result_spec_rsa_signature (&sig2), |
192 | GNUNET_MY_result_spec_rsa_signature (&sig2), | 153 | GNUNET_MY_result_spec_absolute_time (&abs_time2), |
193 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 154 | GNUNET_MY_result_spec_absolute_time (&forever2), |
194 | GNUNET_MY_result_spec_absolute_time (&forever2), | 155 | GNUNET_MY_result_spec_auto_from_type (&hc2), |
195 | GNUNET_MY_result_spec_auto_from_type (&hc2), | 156 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), |
196 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | 157 | GNUNET_MY_result_spec_uint16 (&u162), |
197 | GNUNET_MY_result_spec_uint16 (&u162), | 158 | GNUNET_MY_result_spec_uint32 (&u322), |
198 | GNUNET_MY_result_spec_uint32 (&u322), | 159 | GNUNET_MY_result_spec_uint64 (&u642), |
199 | GNUNET_MY_result_spec_uint64 (&u642), | 160 | GNUNET_MY_result_spec_end |
200 | GNUNET_MY_result_spec_end | 161 | }; |
201 | }; | 162 | |
202 | */ | 163 | ret = GNUNET_MY_extract_result (statements_handle_select, |
203 | struct GNUNET_MY_ResultSpec results_select[] = { | 164 | results_select); |
204 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | 165 | |
205 | GNUNET_MY_result_spec_rsa_signature (&sig2), | 166 | GNUNET_break (GNUNET_YES == ret); |
206 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 167 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); |
207 | GNUNET_MY_result_spec_absolute_time (&forever2), | 168 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); |
208 | GNUNET_MY_result_spec_auto_from_type (&hc2), | 169 | GNUNET_break (0 == |
209 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | 170 | memcmp (&hc, |
210 | GNUNET_MY_result_spec_uint16 (&u162), | ||
211 | GNUNET_MY_result_spec_uint32 (&u322), | ||
212 | GNUNET_MY_result_spec_uint64 (&u642), | ||
213 | GNUNET_MY_result_spec_end | ||
214 | }; | ||
215 | |||
216 | ret = GNUNET_MY_extract_result (statements_handle_select, | ||
217 | results_select); | ||
218 | |||
219 | GNUNET_break (GNUNET_YES == ret); | ||
220 | GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); | ||
221 | GNUNET_break (forever.abs_value_us == forever2.abs_value_us); | ||
222 | GNUNET_break (0 == | ||
223 | memcmp (&hc, | ||
224 | &hc2, | 171 | &hc2, |
225 | sizeof (struct GNUNET_HashCode))); | 172 | sizeof (struct GNUNET_HashCode))); |
226 | 173 | ||
227 | GNUNET_break (strlen (msg) == msg2_len); | 174 | GNUNET_break (0 == |
228 | GNUNET_break (0 == | 175 | GNUNET_CRYPTO_rsa_signature_cmp (sig, |
176 | sig2)); | ||
177 | GNUNET_break (0 == | ||
178 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, | ||
179 | pub2)); | ||
180 | |||
181 | GNUNET_break (strlen (msg) == msg2_len); | ||
182 | GNUNET_break (0 == | ||
229 | strncmp (msg, | 183 | strncmp (msg, |
230 | msg2, | 184 | msg2, |
231 | msg2_len)); | 185 | msg2_len)); |
232 | fprintf(stderr, "msg2 : %d\n", strlen(msg2)); | 186 | GNUNET_break (16 == u162); |
233 | GNUNET_break (16 == u162); | 187 | GNUNET_break (32 == u322); |
234 | GNUNET_break (32 == u322); | 188 | GNUNET_break (64 == u642); |
235 | GNUNET_break (64 == u642); | 189 | |
236 | 190 | GNUNET_MY_cleanup_result (results_select); | |
237 | if (GNUNET_OK != ret) | ||
238 | { | ||
239 | fprintf(stderr, "Failed to extract result\n"); | ||
240 | return 1; | ||
241 | } | ||
242 | 191 | ||
243 | return 0; | 192 | GNUNET_CRYPTO_rsa_signature_free (sig); |
193 | GNUNET_CRYPTO_rsa_private_key_free (priv); | ||
194 | GNUNET_CRYPTO_rsa_public_key_free (pub); | ||
195 | |||
196 | if (GNUNET_OK != ret) | ||
197 | return 1; | ||
198 | |||
199 | return 0; | ||
244 | } | 200 | } |
245 | 201 | ||
246 | 202 | ||
247 | int | 203 | int |
248 | main (int argc, const char * const argv[]) | 204 | main (int argc, const char * const argv[]) |
249 | { | 205 | { |
250 | struct GNUNET_CONFIGURATION_Handle *config; | 206 | struct GNUNET_CONFIGURATION_Handle *config; |
251 | struct GNUNET_MYSQL_Context *context; | 207 | struct GNUNET_MYSQL_Context *context; |
252 | int ret; | 208 | int ret; |
253 | 209 | ||
254 | GNUNET_log_setup ( "test-my", | 210 | GNUNET_log_setup ( "test-my", |
255 | "WARNING", | 211 | "WARNING", |
256 | NULL); | 212 | NULL); |
257 | 213 | ||
258 | config = GNUNET_CONFIGURATION_create (); | 214 | config = GNUNET_CONFIGURATION_create (); |
259 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) | 215 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) |
260 | { | 216 | { |
261 | fprintf (stderr, "Failed to parse configuaration\n"); | 217 | fprintf (stderr, "Failed to parse configuaration\n"); |
262 | return 1; | 218 | return 1; |
263 | } | 219 | } |
264 | 220 | ||
265 | context = GNUNET_MYSQL_context_create (config, | 221 | context = GNUNET_MYSQL_context_create (config, |
266 | "datastore-mysql"); | 222 | "datastore-mysql"); |
267 | if (NULL == context) | 223 | if (NULL == context) |
268 | { | 224 | { |
269 | fprintf(stderr, "Failed to connect to database\n"); | 225 | fprintf(stderr, "Failed to connect to database\n"); |
270 | return 77; | 226 | return 77; |
271 | } | 227 | } |
272 | 228 | ||
273 | (void) GNUNET_MYSQL_statement_run (context, | 229 | (void) GNUNET_MYSQL_statement_run (context, |
274 | "DROP TABLE test_my2;"); | 230 | "DROP TABLE test_my2;"); |
275 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 231 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
276 | "CREATE TABLE IF NOT EXISTS test_my2(" | 232 | "CREATE TABLE IF NOT EXISTS test_my2(" |
277 | " pub BLOB NOT NULL" | 233 | " pub BLOB NOT NULL" |
278 | ",sig BLOB NOT NULL" | 234 | ",sig BLOB NOT NULL" |
@@ -284,43 +240,16 @@ main (int argc, const char * const argv[]) | |||
284 | ",u32 INT NOT NULL" | 240 | ",u32 INT NOT NULL" |
285 | ",u64 BIGINT NOT NULL" | 241 | ",u64 BIGINT NOT NULL" |
286 | ")")) | 242 | ")")) |
287 | { | 243 | { |
288 | fprintf (stderr, | 244 | fprintf (stderr, |
289 | "Failed to create table \n"); | 245 | "Failed to create table \n"); |
290 | GNUNET_MYSQL_statements_invalidate (context); | 246 | GNUNET_MYSQL_statements_invalidate (context); |
291 | GNUNET_MYSQL_context_destroy (context); | 247 | GNUNET_MYSQL_context_destroy (context); |
292 | |||
293 | return 1; | ||
294 | } | ||
295 | |||
296 | /* if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | ||
297 | "CREATE TABLE test_my2(" | ||
298 | " abs_time BIGINT NOT NULL" | ||
299 | ", forever BIGINT NOT NULL" | ||
300 | ", hash VARCHAR(32) NOT NULL CHECK(LENGTH(hash)=64)" | ||
301 | ", u16 SMALLINT NOT NULL" | ||
302 | ", u32 INT NOT NULL" | ||
303 | ", u64 BIGINT NOT NULL" | ||
304 | ")")) | ||
305 | { | ||
306 | fprintf (stderr, | ||
307 | "Failed to create table \n"); | ||
308 | GNUNET_MYSQL_statements_invalidate (context); | ||
309 | GNUNET_MYSQL_context_destroy (context); | ||
310 | 248 | ||
311 | return 1; | 249 | return 1; |
312 | } | 250 | } |
313 | */ | ||
314 | ret = run_queries (context); | ||
315 | 251 | ||
316 | /* if(GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 252 | ret = run_queries (context); |
317 | "DROP TABLE test_my2")) | ||
318 | { | ||
319 | fprintf (stderr, "Failed to drop table test_my\n"); | ||
320 | GNUNET_MYSQL_statements_invalidate (context); | ||
321 | } | ||
322 | 253 | ||
323 | GNUNET_MYSQL_context_destroy (context); | 254 | return ret; |
324 | */ | ||
325 | return ret; | ||
326 | } | 255 | } |