aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-28 19:58:20 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-28 19:58:20 +0100
commit554ee3d4da95a9fcfd408f1085586d0b6d1834f4 (patch)
tree0a157dd6545e7fc192e29f409365828e9e205d51
parent2e0e30291c4e490389f85bbd4973374f0adf22f4 (diff)
downloadexchange-554ee3d4da95a9fcfd408f1085586d0b6d1834f4.tar.gz
exchange-554ee3d4da95a9fcfd408f1085586d0b6d1834f4.zip
cleaning up some memory management issues in response generation
-rw-r--r--src/mint/taler-mint-httpd_db.c8
-rw-r--r--src/mint/taler-mint-httpd_responses.c119
-rw-r--r--src/mint/taler-mint-httpd_responses.h5
3 files changed, 64 insertions, 68 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index 6949da22d..34ca6c775 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -1293,7 +1293,9 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
1293 json_object_set_new (root, "secret_enc", 1293 json_object_set_new (root, "secret_enc",
1294 TALER_JSON_from_data (&shared_secret_enc, 1294 TALER_JSON_from_data (&shared_secret_enc,
1295 sizeof (struct GNUNET_HashCode))); 1295 sizeof (struct GNUNET_HashCode)));
1296 return TALER_MINT_reply_json (connection, 1296 res = TALER_MINT_reply_json (connection,
1297 root, 1297 root,
1298 MHD_HTTP_OK); 1298 MHD_HTTP_OK);
1299 json_decref (root);
1300 return res;
1299} 1301}
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index 58addf98d..c91b5a11c 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -36,8 +36,7 @@
36 36
37 37
38/** 38/**
39 * Send JSON object as response. Decreases the reference count of the 39 * Send JSON object as response.
40 * JSON object.
41 * 40 *
42 * @param connection the MHD connection 41 * @param connection the MHD connection
43 * @param json the json object 42 * @param json the json object
@@ -46,7 +45,7 @@
46 */ 45 */
47int 46int
48TALER_MINT_reply_json (struct MHD_Connection *connection, 47TALER_MINT_reply_json (struct MHD_Connection *connection,
49 json_t *json, 48 const json_t *json,
50 unsigned int response_code) 49 unsigned int response_code)
51{ 50{
52 struct MHD_Response *resp; 51 struct MHD_Response *resp;
@@ -54,7 +53,6 @@ TALER_MINT_reply_json (struct MHD_Connection *connection,
54 int ret; 53 int ret;
55 54
56 json_str = json_dumps (json, JSON_INDENT(2)); 55 json_str = json_dumps (json, JSON_INDENT(2));
57 json_decref (json);
58 resp = MHD_create_response_from_buffer (strlen (json_str), json_str, 56 resp = MHD_create_response_from_buffer (strlen (json_str), json_str,
59 MHD_RESPMEM_MUST_FREE); 57 MHD_RESPMEM_MUST_FREE);
60 if (NULL == resp) 58 if (NULL == resp)
@@ -86,15 +84,18 @@ TALER_MINT_reply_json_pack (struct MHD_Connection *connection,
86{ 84{
87 json_t *json; 85 json_t *json;
88 va_list argp; 86 va_list argp;
87 int ret;
89 88
90 va_start (argp, fmt); 89 va_start (argp, fmt);
91 json = json_vpack_ex (NULL, 0, fmt, argp); 90 json = json_vpack_ex (NULL, 0, fmt, argp);
92 va_end (argp); 91 va_end (argp);
93 if (NULL == json) 92 if (NULL == json)
94 return MHD_NO; 93 return MHD_NO;
95 return TALER_MINT_reply_json (connection, 94 ret = TALER_MINT_reply_json (connection,
96 json, 95 json,
97 response_code); 96 response_code);
97 json_decref (json);
98 return ret;
98} 99}
99 100
100 101
@@ -109,16 +110,11 @@ int
109TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection, 110TALER_MINT_reply_arg_invalid (struct MHD_Connection *connection,
110 const char *param_name) 111 const char *param_name)
111{ 112{
112 json_t *json; 113 return TALER_MINT_reply_json_pack (connection,
113 114 MHD_HTTP_BAD_REQUEST,
114 json = json_pack ("{ s:s, s:s }", 115 "{s:s, s:s}",
115 "error", 116 "error", "invalid parameter",
116 "invalid parameter", 117 "parameter", param_name);
117 "parameter",
118 param_name);
119 return TALER_MINT_reply_json (connection,
120 json,
121 MHD_HTTP_BAD_REQUEST);
122} 118}
123 119
124 120
@@ -153,16 +149,11 @@ int
153TALER_MINT_reply_arg_missing (struct MHD_Connection *connection, 149TALER_MINT_reply_arg_missing (struct MHD_Connection *connection,
154 const char *param_name) 150 const char *param_name)
155{ 151{
156 json_t *json; 152 return TALER_MINT_reply_json_pack (connection,
157 153 MHD_HTTP_BAD_REQUEST,
158 json = json_pack ("{ s:s, s:s }", 154 "{ s:s, s:s}",
159 "error", 155 "error", "missing parameter",
160 "missing parameter", 156 "parameter", param_name);
161 "parameter",
162 param_name);
163 return TALER_MINT_reply_json (connection,
164 json,
165 MHD_HTTP_BAD_REQUEST);
166} 157}
167 158
168 159
@@ -177,16 +168,11 @@ int
177TALER_MINT_reply_internal_error (struct MHD_Connection *connection, 168TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
178 const char *hint) 169 const char *hint)
179{ 170{
180 json_t *json; 171 return TALER_MINT_reply_json_pack (connection,
181 172 MHD_HTTP_BAD_REQUEST,
182 json = json_pack ("{ s:s, s:s }", 173 "{s:s, s:s}",
183 "error", 174 "error", "internal error",
184 "internal error", 175 "hint", hint);
185 "hint",
186 hint);
187 return TALER_MINT_reply_json (connection,
188 json,
189 MHD_HTTP_BAD_REQUEST);
190} 176}
191 177
192 178
@@ -319,20 +305,20 @@ TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection,
319 const struct TALER_Amount balance, 305 const struct TALER_Amount balance,
320 struct GNUNET_TIME_Absolute expiration) 306 struct GNUNET_TIME_Absolute expiration)
321{ 307{
322 json_t *json; 308 json_t *json_balance;
309 json_t *json_expiration;
310 int ret;
323 311
324 /* Convert the public information of a reserve (i.e. 312 json_balance = TALER_JSON_from_amount (balance);
325 excluding private key) to a JSON object. */ 313 json_expiration = TALER_JSON_from_abs (expiration);
326 json = json_object (); 314 ret = TALER_MINT_reply_json_pack (connection,
327 json_object_set_new (json, 315 MHD_HTTP_OK,
328 "balance", 316 "{s:o, s:o}",
329 TALER_JSON_from_amount (balance)); 317 "balance", json_balance,
330 json_object_set_new (json, 318 "expiration", json_expiration);
331 "expiration", 319 json_decref (json_balance);
332 TALER_JSON_from_abs (expiration)); 320 json_decref (json_expiration);
333 return TALER_MINT_reply_json (connection, 321 return ret;
334 json,
335 MHD_HTTP_OK);
336} 322}
337 323
338 324
@@ -347,19 +333,23 @@ int
347TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection, 333TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection,
348 const struct CollectableBlindcoin *collectable) 334 const struct CollectableBlindcoin *collectable)
349{ 335{
350 json_t *root = json_object (); 336 json_t *sig_json;
351 size_t sig_buf_size; 337 size_t sig_buf_size;
352 char *sig_buf; 338 char *sig_buf;
339 int ret;
353 340
341 /* FIXME: use TALER_JSON_from_sig here instead! */
354 sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig, 342 sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig,
355 &sig_buf); 343 &sig_buf);
356 json_object_set_new (root, "ev_sig", 344 sig_json = TALER_JSON_from_data (sig_buf,
357 TALER_JSON_from_data (sig_buf, 345 sig_buf_size);
358 sig_buf_size));
359 GNUNET_free (sig_buf); 346 GNUNET_free (sig_buf);
360 return TALER_MINT_reply_json (connection, 347 ret = TALER_MINT_reply_json_pack (connection,
361 root, 348 MHD_HTTP_OK,
362 MHD_HTTP_OK); 349 "{s:o}",
350 "ev_sig", sig_json);
351 json_decref (sig_json);
352 return ret;
363} 353}
364 354
365 355
@@ -421,6 +411,7 @@ TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection,
421 struct RefreshCommitResponseSignatureBody body; 411 struct RefreshCommitResponseSignatureBody body;
422 struct GNUNET_CRYPTO_EddsaSignature sig; 412 struct GNUNET_CRYPTO_EddsaSignature sig;
423 json_t *sig_json; 413 json_t *sig_json;
414 int ret;
424 415
425 body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody)); 416 body.purpose.size = htonl (sizeof (struct RefreshCommitResponseSignatureBody));
426 body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE); 417 body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_COMMIT_RESPONSE);
@@ -429,11 +420,13 @@ TALER_MINT_reply_refresh_commit_success (struct MHD_Connection *connection,
429 &sig); 420 &sig);
430 sig_json = TALER_JSON_from_sig (&body.purpose, &sig); 421 sig_json = TALER_JSON_from_sig (&body.purpose, &sig);
431 GNUNET_assert (NULL != sig_json); 422 GNUNET_assert (NULL != sig_json);
432 return TALER_MINT_reply_json_pack (connection, 423 ret = TALER_MINT_reply_json_pack (connection,
433 MHD_HTTP_OK, 424 MHD_HTTP_OK,
434 "{s:i, s:o}", 425 "{s:i, s:o}",
435 "noreveal_index", (int) refresh_session->noreveal_index, 426 "noreveal_index", (int) refresh_session->noreveal_index,
436 "signature", sig_json); 427 "signature", sig_json);
428 json_decref (sig_json);
429 return ret;
437} 430}
438 431
439 432
@@ -455,6 +448,7 @@ TALER_MINT_reply_refresh_reveal_success (struct MHD_Connection *connection,
455 json_t *list; 448 json_t *list;
456 char *buf; 449 char *buf;
457 size_t buf_size; 450 size_t buf_size;
451 int ret;
458 452
459 root = json_object (); 453 root = json_object ();
460 list = json_array (); 454 list = json_array ();
@@ -468,10 +462,11 @@ TALER_MINT_reply_refresh_reveal_success (struct MHD_Connection *connection,
468 buf_size)); 462 buf_size));
469 GNUNET_free (buf); 463 GNUNET_free (buf);
470 } 464 }
471 return TALER_MINT_reply_json (connection, 465 ret = TALER_MINT_reply_json (connection,
472 root, 466 root,
473 MHD_HTTP_OK); 467 MHD_HTTP_OK);
474 468 json_decref (root);
469 return ret;
475} 470}
476 471
477 472
diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h
index 30c9e1185..421113eed 100644
--- a/src/mint/taler-mint-httpd_responses.h
+++ b/src/mint/taler-mint-httpd_responses.h
@@ -34,8 +34,7 @@
34 34
35 35
36/** 36/**
37 * Send JSON object as response. Decreases the reference count of the 37 * Send JSON object as response.
38 * JSON object.
39 * 38 *
40 * @param connection the MHD connection 39 * @param connection the MHD connection
41 * @param json the json object 40 * @param json the json object
@@ -44,7 +43,7 @@
44 */ 43 */
45int 44int
46TALER_MINT_reply_json (struct MHD_Connection *connection, 45TALER_MINT_reply_json (struct MHD_Connection *connection,
47 json_t *json, 46 const json_t *json,
48 unsigned int response_code); 47 unsigned int response_code);
49 48
50 49