diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-16 14:27:42 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-16 14:27:42 +0100 |
commit | 4bd515191b6db342ff465e0595cfeafe6da8a680 (patch) | |
tree | 982d32e7920dc86c1e7c20ac620dca3fea33e38a | |
parent | f398b34414e3dbde31c0ec4b627aaa7ccf593ee0 (diff) | |
download | exchange-4bd515191b6db342ff465e0595cfeafe6da8a680.tar.gz exchange-4bd515191b6db342ff465e0595cfeafe6da8a680.zip |
nicer TALER_MINT_parse_post_json return value handling, fixing return values where GNUNET_SYSERR is used instead of MHD_NO, marking cases where we should return a proper error message
-rw-r--r-- | src/mint/taler-mint-httpd_deposit.c | 28 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.c | 53 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.h | 5 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_refresh.c | 113 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 65 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.h | 33 |
6 files changed, 215 insertions, 82 deletions
diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index f1df0ad89..d92dd5ef7 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c | |||
@@ -89,21 +89,19 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
89 | int res; | 89 | int res; |
90 | 90 | ||
91 | res = TALER_MINT_parse_post_json (connection, | 91 | res = TALER_MINT_parse_post_json (connection, |
92 | connection_cls, | 92 | connection_cls, |
93 | upload_data, upload_data_size, | 93 | upload_data, |
94 | &json); | 94 | upload_data_size, |
95 | &json); | ||
95 | if (GNUNET_SYSERR == res) | 96 | if (GNUNET_SYSERR == res) |
96 | { | ||
97 | // FIXME: return 'internal error' | ||
98 | GNUNET_break (0); | ||
99 | return MHD_NO; | 97 | return MHD_NO; |
100 | } | 98 | if ( (GNUNET_NO == res) || (NULL == json) ) |
101 | if (GNUNET_NO == res) | ||
102 | return MHD_YES; | 99 | return MHD_YES; |
103 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) | 100 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) |
104 | { | 101 | { |
102 | /* FIXME: return error message to client via MHD! */ | ||
105 | GNUNET_break (0); | 103 | GNUNET_break (0); |
106 | return GNUNET_SYSERR; | 104 | return MHD_NO; |
107 | } | 105 | } |
108 | 106 | ||
109 | deposit = NULL; | 107 | deposit = NULL; |
@@ -213,7 +211,8 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
213 | if (GNUNET_SYSERR == res) | 211 | if (GNUNET_SYSERR == res) |
214 | { | 212 | { |
215 | GNUNET_break (0); | 213 | GNUNET_break (0); |
216 | return GNUNET_SYSERR; | 214 | /* FIXME: return error message to client via MHD! */ |
215 | return MHD_NO; | ||
217 | } | 216 | } |
218 | } | 217 | } |
219 | 218 | ||
@@ -235,7 +234,8 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
235 | if (GNUNET_SYSERR == res) | 234 | if (GNUNET_SYSERR == res) |
236 | { | 235 | { |
237 | GNUNET_break (0); | 236 | GNUNET_break (0); |
238 | return GNUNET_SYSERR; | 237 | /* FIXME: return error message to client via MHD! */ |
238 | return MHD_NO; | ||
239 | } | 239 | } |
240 | 240 | ||
241 | /* coin valid but not known => insert into DB */ | 241 | /* coin valid but not known => insert into DB */ |
@@ -246,14 +246,16 @@ TALER_MINT_handler_deposit (struct RequestHandler *rh, | |||
246 | if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) | 246 | if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) |
247 | { | 247 | { |
248 | GNUNET_break (0); | 248 | GNUNET_break (0); |
249 | return GNUNET_SYSERR; | 249 | /* FIXME: return error message to client via MHD! */ |
250 | return MHD_NO; | ||
250 | } | 251 | } |
251 | } | 252 | } |
252 | 253 | ||
253 | if (GNUNET_OK != TALER_MINT_DB_insert_deposit (db_conn, deposit)) | 254 | if (GNUNET_OK != TALER_MINT_DB_insert_deposit (db_conn, deposit)) |
254 | { | 255 | { |
255 | GNUNET_break (0); | 256 | GNUNET_break (0); |
256 | return GNUNET_SYSERR; | 257 | /* FIXME: return error message to client via MHD! */ |
258 | return MHD_NO; | ||
257 | } | 259 | } |
258 | return helper_deposit_send_response_success (connection, deposit); | 260 | return helper_deposit_send_response_success (connection, deposit); |
259 | 261 | ||
diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index 9a3fc1d6b..19c88d456 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c | |||
@@ -112,7 +112,6 @@ buffer_deinit (struct Buffer *buf) | |||
112 | * @param max_size maximum size that the buffer can grow to | 112 | * @param max_size maximum size that the buffer can grow to |
113 | * @return GNUNET_OK on success, | 113 | * @return GNUNET_OK on success, |
114 | * GNUNET_NO if the buffer can't accomodate for the new data | 114 | * GNUNET_NO if the buffer can't accomodate for the new data |
115 | * GNUNET_SYSERR on fatal error (out of memory?) | ||
116 | */ | 115 | */ |
117 | static int | 116 | static int |
118 | buffer_append (struct Buffer *buf, | 117 | buffer_append (struct Buffer *buf, |
@@ -142,18 +141,28 @@ buffer_append (struct Buffer *buf, | |||
142 | 141 | ||
143 | 142 | ||
144 | /** | 143 | /** |
145 | * Process a POST request containing a JSON object. | 144 | * Process a POST request containing a JSON object. This |
145 | * function realizes an MHD POST processor that will | ||
146 | * (incrementally) process JSON data uploaded to the HTTP | ||
147 | * server. It will store the required state in the | ||
148 | * "connection_cls", which must be cleaned up using | ||
149 | * #TALER_MINT_parse_post_cleanup_callback(). | ||
146 | * | 150 | * |
147 | * @param connection the MHD connection | 151 | * @param connection the MHD connection |
148 | * @param con_cs the closure (contains a 'struct Buffer *') | 152 | * @param con_cs the closure (points to a `struct Buffer *`) |
149 | * @param upload_data the POST data | 153 | * @param upload_data the POST data |
150 | * @param upload_data_size the POST data size | 154 | * @param upload_data_size number of bytes in @a upload_data |
151 | * @param json the JSON object for a completed request | 155 | * @param json the JSON object for a completed request |
152 | * | ||
153 | * @returns | 156 | * @returns |
154 | * GNUNET_YES if json object was parsed | 157 | * GNUNET_YES if json object was parsed or at least |
158 | * may be parsed in the future (call again); | ||
159 | * `*json` will be NULL if we need to be called again, | ||
160 | * and non-NULL if we are done. | ||
155 | * GNUNET_NO is request incomplete or invalid | 161 | * GNUNET_NO is request incomplete or invalid |
162 | * (error message was generated) | ||
156 | * GNUNET_SYSERR on internal error | 163 | * GNUNET_SYSERR on internal error |
164 | * (we could not even queue an error message, | ||
165 | * close HTTP session with MHD_NO) | ||
157 | */ | 166 | */ |
158 | int | 167 | int |
159 | TALER_MINT_parse_post_json (struct MHD_Connection *connection, | 168 | TALER_MINT_parse_post_json (struct MHD_Connection *connection, |
@@ -164,10 +173,10 @@ TALER_MINT_parse_post_json (struct MHD_Connection *connection, | |||
164 | { | 173 | { |
165 | struct Buffer *r = *con_cls; | 174 | struct Buffer *r = *con_cls; |
166 | 175 | ||
176 | *json = NULL; | ||
167 | if (NULL == *con_cls) | 177 | if (NULL == *con_cls) |
168 | { | 178 | { |
169 | /* We are seeing a fresh POST request. */ | 179 | /* We are seeing a fresh POST request. */ |
170 | |||
171 | r = GNUNET_new (struct Buffer); | 180 | r = GNUNET_new (struct Buffer); |
172 | if (GNUNET_OK != | 181 | if (GNUNET_OK != |
173 | buffer_init (r, | 182 | buffer_init (r, |
@@ -179,11 +188,15 @@ TALER_MINT_parse_post_json (struct MHD_Connection *connection, | |||
179 | *con_cls = NULL; | 188 | *con_cls = NULL; |
180 | buffer_deinit (r); | 189 | buffer_deinit (r); |
181 | GNUNET_free (r); | 190 | GNUNET_free (r); |
182 | return GNUNET_SYSERR; | 191 | return (MHD_NO == |
192 | TALER_MINT_reply_internal_error (connection, | ||
193 | "out of memory")) | ||
194 | ? GNUNET_SYSERR : GNUNET_NO; | ||
183 | } | 195 | } |
196 | /* everything OK, wait for more POST data */ | ||
184 | *upload_data_size = 0; | 197 | *upload_data_size = 0; |
185 | *con_cls = r; | 198 | *con_cls = r; |
186 | return GNUNET_NO; | 199 | return GNUNET_YES; |
187 | } | 200 | } |
188 | if (0 != *upload_data_size) | 201 | if (0 != *upload_data_size) |
189 | { | 202 | { |
@@ -195,31 +208,33 @@ TALER_MINT_parse_post_json (struct MHD_Connection *connection, | |||
195 | *upload_data_size, | 208 | *upload_data_size, |
196 | REQUEST_BUFFER_MAX)) | 209 | REQUEST_BUFFER_MAX)) |
197 | { | 210 | { |
198 | /* Request too long or we're out of memory. */ | 211 | /* Request too long */ |
199 | |||
200 | *con_cls = NULL; | 212 | *con_cls = NULL; |
201 | buffer_deinit (r); | 213 | buffer_deinit (r); |
202 | GNUNET_free (r); | 214 | GNUNET_free (r); |
203 | return GNUNET_SYSERR; | 215 | return (MHD_NO == |
216 | TALER_MINT_reply_request_too_large (connection)) | ||
217 | ? GNUNET_SYSERR : GNUNET_NO; | ||
204 | } | 218 | } |
219 | /* everything OK, wait for more POST data */ | ||
205 | *upload_data_size = 0; | 220 | *upload_data_size = 0; |
206 | return GNUNET_NO; | 221 | return GNUNET_YES; |
207 | } | 222 | } |
208 | 223 | ||
209 | /* We have seen the whole request. */ | 224 | /* We have seen the whole request. */ |
210 | 225 | ||
211 | *json = json_loadb (r->data, r->fill, 0, NULL); | 226 | *json = json_loadb (r->data, |
227 | r->fill, | ||
228 | 0, | ||
229 | NULL); | ||
212 | buffer_deinit (r); | 230 | buffer_deinit (r); |
213 | GNUNET_free (r); | 231 | GNUNET_free (r); |
214 | if (NULL == *json) | 232 | if (NULL == *json) |
215 | { | 233 | { |
216 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
217 | "Can't parse JSON request body\n"); | 235 | "Failed to parse JSON request body\n"); |
218 | return (MHD_YES == | 236 | return (MHD_YES == |
219 | TALER_MINT_reply_json_pack (connection, | 237 | TALER_MINT_reply_invalid_json (connection)) |
220 | MHD_HTTP_BAD_REQUEST, | ||
221 | "{s:s}", | ||
222 | "error", "invalid json")) | ||
223 | ? GNUNET_NO : GNUNET_SYSERR; | 238 | ? GNUNET_NO : GNUNET_SYSERR; |
224 | } | 239 | } |
225 | *con_cls = NULL; | 240 | *con_cls = NULL; |
diff --git a/src/mint/taler-mint-httpd_parsing.h b/src/mint/taler-mint-httpd_parsing.h index d9516d486..c725187c5 100644 --- a/src/mint/taler-mint-httpd_parsing.h +++ b/src/mint/taler-mint-httpd_parsing.h | |||
@@ -80,10 +80,11 @@ enum | |||
80 | * @param upload_data the POST data | 80 | * @param upload_data the POST data |
81 | * @param upload_data_size number of bytes in @a upload_data | 81 | * @param upload_data_size number of bytes in @a upload_data |
82 | * @param json the JSON object for a completed request | 82 | * @param json the JSON object for a completed request |
83 | * | ||
84 | * @returns | 83 | * @returns |
85 | * GNUNET_YES if json object was parsed or at least | 84 | * GNUNET_YES if json object was parsed or at least |
86 | * may be parsed in the future (call again) | 85 | * may be parsed in the future (call again); |
86 | * `*json` will be NULL if we need to be called again, | ||
87 | * and non-NULL if we are done. | ||
87 | * GNUNET_NO is request incomplete or invalid | 88 | * GNUNET_NO is request incomplete or invalid |
88 | * (error message was generated) | 89 | * (error message was generated) |
89 | * GNUNET_SYSERR on internal error | 90 | * GNUNET_SYSERR on internal error |
diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 83225fc15..1f19aedb2 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c | |||
@@ -607,20 +607,20 @@ TALER_MINT_handler_refresh_melt (struct RequestHandler *rh, | |||
607 | struct GNUNET_HashCode melt_hash; | 607 | struct GNUNET_HashCode melt_hash; |
608 | 608 | ||
609 | res = TALER_MINT_parse_post_json (connection, | 609 | res = TALER_MINT_parse_post_json (connection, |
610 | connection_cls, | 610 | connection_cls, |
611 | upload_data, | 611 | upload_data, |
612 | upload_data_size, &root); | 612 | upload_data_size, |
613 | &root); | ||
613 | if (GNUNET_SYSERR == res) | 614 | if (GNUNET_SYSERR == res) |
614 | { | ||
615 | // FIXME: return 'internal error'? | ||
616 | GNUNET_break (0); | ||
617 | return MHD_NO; | 615 | return MHD_NO; |
618 | } | 616 | if ( (GNUNET_NO == res) || (NULL == root) ) |
619 | if (GNUNET_NO == res) | ||
620 | return MHD_YES; | 617 | return MHD_YES; |
621 | 618 | ||
622 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) | 619 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) |
623 | return GNUNET_SYSERR; | 620 | { |
621 | /* FIXME: return error code to MHD! */ | ||
622 | return MHD_NO; | ||
623 | } | ||
624 | 624 | ||
625 | /* session_pub field must always be present */ | 625 | /* session_pub field must always be present */ |
626 | res = request_json_require_nav (connection, root, | 626 | res = request_json_require_nav (connection, root, |
@@ -824,19 +824,15 @@ TALER_MINT_handler_refresh_commit (struct RequestHandler *rh, | |||
824 | json_t *root; | 824 | json_t *root; |
825 | 825 | ||
826 | res = TALER_MINT_parse_post_json (connection, | 826 | res = TALER_MINT_parse_post_json (connection, |
827 | connection_cls, | 827 | connection_cls, |
828 | upload_data, | 828 | upload_data, |
829 | upload_data_size, &root); | 829 | upload_data_size, |
830 | &root); | ||
830 | if (GNUNET_SYSERR == res) | 831 | if (GNUNET_SYSERR == res) |
831 | { | ||
832 | // FIXME: return 'internal error'? | ||
833 | GNUNET_break (0); | ||
834 | return MHD_NO; | 832 | return MHD_NO; |
835 | } | 833 | if ( (GNUNET_NO == res) || (NULL == root) ) |
836 | if (GNUNET_NO == res) | ||
837 | return MHD_YES; | 834 | return MHD_YES; |
838 | 835 | ||
839 | |||
840 | res = request_json_require_nav (connection, root, | 836 | res = request_json_require_nav (connection, root, |
841 | JNAV_FIELD, "session_pub", | 837 | JNAV_FIELD, "session_pub", |
842 | JNAV_RET_DATA, | 838 | JNAV_RET_DATA, |
@@ -1160,16 +1156,13 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1160 | json_t *root; | 1156 | json_t *root; |
1161 | 1157 | ||
1162 | res = TALER_MINT_parse_post_json (connection, | 1158 | res = TALER_MINT_parse_post_json (connection, |
1163 | connection_cls, | 1159 | connection_cls, |
1164 | upload_data, upload_data_size, | 1160 | upload_data, |
1165 | &root); | 1161 | upload_data_size, |
1162 | &root); | ||
1166 | if (GNUNET_SYSERR == res) | 1163 | if (GNUNET_SYSERR == res) |
1167 | { | ||
1168 | // FIXME: return 'internal error'? | ||
1169 | GNUNET_break (0); | ||
1170 | return MHD_NO; | 1164 | return MHD_NO; |
1171 | } | 1165 | if ( (GNUNET_NO == res) || (NULL == root) ) |
1172 | if (GNUNET_NO == res) | ||
1173 | return MHD_YES; | 1166 | return MHD_YES; |
1174 | 1167 | ||
1175 | res = request_json_require_nav (connection, root, | 1168 | res = request_json_require_nav (connection, root, |
@@ -1186,6 +1179,7 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1186 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) | 1179 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) |
1187 | { | 1180 | { |
1188 | GNUNET_break (0); | 1181 | GNUNET_break (0); |
1182 | // FIXME: return 'internal error'? | ||
1189 | return MHD_NO; | 1183 | return MHD_NO; |
1190 | } | 1184 | } |
1191 | 1185 | ||
@@ -1199,6 +1193,7 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1199 | if (GNUNET_SYSERR == res) | 1193 | if (GNUNET_SYSERR == res) |
1200 | { | 1194 | { |
1201 | GNUNET_break (0); | 1195 | GNUNET_break (0); |
1196 | // FIXME: return 'internal error'? | ||
1202 | return MHD_NO; | 1197 | return MHD_NO; |
1203 | } | 1198 | } |
1204 | 1199 | ||
@@ -1242,14 +1237,16 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1242 | if (GNUNET_OK != res) | 1237 | if (GNUNET_OK != res) |
1243 | { | 1238 | { |
1244 | GNUNET_break (0); | 1239 | GNUNET_break (0); |
1245 | return GNUNET_SYSERR; | 1240 | // FIXME: return 'internal error'? |
1241 | return MHD_NO; | ||
1246 | } | 1242 | } |
1247 | 1243 | ||
1248 | res = TALER_MINT_DB_get_refresh_melt (db_conn, &refresh_session_pub, j, &coin_pub); | 1244 | res = TALER_MINT_DB_get_refresh_melt (db_conn, &refresh_session_pub, j, &coin_pub); |
1249 | if (GNUNET_OK != res) | 1245 | if (GNUNET_OK != res) |
1250 | { | 1246 | { |
1251 | GNUNET_break (0); | 1247 | GNUNET_break (0); |
1252 | return GNUNET_SYSERR; | 1248 | // FIXME: return 'internal error'? |
1249 | return MHD_NO; | ||
1253 | } | 1250 | } |
1254 | 1251 | ||
1255 | /* We're converting key types here, which is not very nice | 1252 | /* We're converting key types here, which is not very nice |
@@ -1259,14 +1256,16 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1259 | &transfer_secret)) | 1256 | &transfer_secret)) |
1260 | { | 1257 | { |
1261 | GNUNET_break (0); | 1258 | GNUNET_break (0); |
1262 | return GNUNET_SYSERR; | 1259 | // FIXME: return 'internal error'? |
1260 | return MHD_NO; | ||
1263 | } | 1261 | } |
1264 | 1262 | ||
1265 | if (0 >= TALER_refresh_decrypt (commit_link.shared_secret_enc, TALER_REFRESH_SHARED_SECRET_LENGTH, | 1263 | if (0 >= TALER_refresh_decrypt (commit_link.shared_secret_enc, TALER_REFRESH_SHARED_SECRET_LENGTH, |
1266 | &transfer_secret, &shared_secret)) | 1264 | &transfer_secret, &shared_secret)) |
1267 | { | 1265 | { |
1268 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decryption failed\n"); | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decryption failed\n"); |
1269 | return GNUNET_SYSERR; | 1267 | // FIXME: return 'internal error'? |
1268 | return MHD_NO; | ||
1270 | } | 1269 | } |
1271 | 1270 | ||
1272 | if (GNUNET_NO == secret_initialized) | 1271 | if (GNUNET_NO == secret_initialized) |
@@ -1277,7 +1276,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1277 | else if (0 != memcmp (&shared_secret, &last_shared_secret, sizeof (struct GNUNET_HashCode))) | 1276 | else if (0 != memcmp (&shared_secret, &last_shared_secret, sizeof (struct GNUNET_HashCode))) |
1278 | { | 1277 | { |
1279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "shared secrets do not match\n"); | 1278 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "shared secrets do not match\n"); |
1280 | return GNUNET_SYSERR; | 1279 | // FIXME: return error code! |
1280 | return MHD_NO; | ||
1281 | } | 1281 | } |
1282 | 1282 | ||
1283 | { | 1283 | { |
@@ -1286,7 +1286,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1286 | if (0 != memcmp (&transfer_pub_check, &commit_link.transfer_pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 1286 | if (0 != memcmp (&transfer_pub_check, &commit_link.transfer_pub, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
1287 | { | 1287 | { |
1288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "transfer keys do not match\n"); | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "transfer keys do not match\n"); |
1289 | return GNUNET_SYSERR; | 1289 | // FIXME: return error code! |
1290 | return MHD_NO; | ||
1290 | } | 1291 | } |
1291 | } | 1292 | } |
1292 | } | 1293 | } |
@@ -1310,7 +1311,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1310 | if (GNUNET_OK != res) | 1311 | if (GNUNET_OK != res) |
1311 | { | 1312 | { |
1312 | GNUNET_break (0); | 1313 | GNUNET_break (0); |
1313 | return GNUNET_SYSERR; | 1314 | // FIXME: return error code! |
1315 | return MHD_NO; | ||
1314 | } | 1316 | } |
1315 | 1317 | ||
1316 | 1318 | ||
@@ -1318,20 +1320,23 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1318 | &last_shared_secret, &link_data)) | 1320 | &last_shared_secret, &link_data)) |
1319 | { | 1321 | { |
1320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decryption failed\n"); | 1322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "decryption failed\n"); |
1321 | return GNUNET_SYSERR; | 1323 | // FIXME: return error code! |
1324 | return MHD_NO; | ||
1322 | } | 1325 | } |
1323 | 1326 | ||
1324 | GNUNET_CRYPTO_ecdsa_key_get_public (&link_data.coin_priv, &coin_pub); | 1327 | GNUNET_CRYPTO_ecdsa_key_get_public (&link_data.coin_priv, &coin_pub); |
1325 | if (NULL == (bkey = TALER_RSA_blinding_key_decode (&link_data.bkey_enc))) | 1328 | if (NULL == (bkey = TALER_RSA_blinding_key_decode (&link_data.bkey_enc))) |
1326 | { | 1329 | { |
1327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid blinding key\n"); | 1330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid blinding key\n"); |
1328 | return GNUNET_SYSERR; | 1331 | // FIXME: return error code! |
1332 | return MHD_NO; | ||
1329 | } | 1333 | } |
1330 | res = TALER_MINT_DB_get_refresh_order (db_conn, j, &refresh_session_pub, &denom_pub); | 1334 | res = TALER_MINT_DB_get_refresh_order (db_conn, j, &refresh_session_pub, &denom_pub); |
1331 | if (GNUNET_OK != res) | 1335 | if (GNUNET_OK != res) |
1332 | { | 1336 | { |
1333 | GNUNET_break (0); | 1337 | GNUNET_break (0); |
1334 | return GNUNET_SYSERR; | 1338 | // FIXME: return error code! |
1339 | return MHD_NO; | ||
1335 | } | 1340 | } |
1336 | if (NULL == (coin_ev_check = | 1341 | if (NULL == (coin_ev_check = |
1337 | TALER_RSA_message_blind (&coin_pub, | 1342 | TALER_RSA_message_blind (&coin_pub, |
@@ -1340,7 +1345,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1340 | &denom_pub))) | 1345 | &denom_pub))) |
1341 | { | 1346 | { |
1342 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "blind failed\n"); | 1347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "blind failed\n"); |
1343 | return GNUNET_SYSERR; | 1348 | // FIXME: return error code! |
1349 | return MHD_NO; | ||
1344 | } | 1350 | } |
1345 | 1351 | ||
1346 | if (0 != memcmp (&coin_ev_check, | 1352 | if (0 != memcmp (&coin_ev_check, |
@@ -1349,7 +1355,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1349 | { | 1355 | { |
1350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "blind envelope does not match for kappa=%d, old=%d\n", | 1356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "blind envelope does not match for kappa=%d, old=%d\n", |
1351 | (int) i, (int) j); | 1357 | (int) i, (int) j); |
1352 | return GNUNET_SYSERR; | 1358 | // FIXME: return error code! |
1359 | return MHD_NO; | ||
1353 | } | 1360 | } |
1354 | } | 1361 | } |
1355 | } | 1362 | } |
@@ -1358,6 +1365,7 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1358 | if (GNUNET_OK != TALER_MINT_DB_transaction (db_conn)) | 1365 | if (GNUNET_OK != TALER_MINT_DB_transaction (db_conn)) |
1359 | { | 1366 | { |
1360 | GNUNET_break (0); | 1367 | GNUNET_break (0); |
1368 | // FIXME: return error code! | ||
1361 | return MHD_NO; | 1369 | return MHD_NO; |
1362 | } | 1370 | } |
1363 | 1371 | ||
@@ -1376,13 +1384,15 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1376 | if (GNUNET_OK != res) | 1384 | if (GNUNET_OK != res) |
1377 | { | 1385 | { |
1378 | GNUNET_break (0); | 1386 | GNUNET_break (0); |
1379 | return GNUNET_SYSERR; | 1387 | // FIXME: return error code! |
1388 | return MHD_NO; | ||
1380 | } | 1389 | } |
1381 | res = TALER_MINT_DB_get_refresh_order (db_conn, j, &refresh_session_pub, &denom_pub); | 1390 | res = TALER_MINT_DB_get_refresh_order (db_conn, j, &refresh_session_pub, &denom_pub); |
1382 | if (GNUNET_OK != res) | 1391 | if (GNUNET_OK != res) |
1383 | { | 1392 | { |
1384 | GNUNET_break (0); | 1393 | GNUNET_break (0); |
1385 | return GNUNET_SYSERR; | 1394 | // FIXME: return error code! |
1395 | return MHD_NO; | ||
1386 | } | 1396 | } |
1387 | 1397 | ||
1388 | 1398 | ||
@@ -1392,7 +1402,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1392 | if (NULL == dki) | 1402 | if (NULL == dki) |
1393 | { | 1403 | { |
1394 | GNUNET_break (0); | 1404 | GNUNET_break (0); |
1395 | return GNUNET_SYSERR; | 1405 | // FIXME: return error code! |
1406 | return MHD_NO; | ||
1396 | } | 1407 | } |
1397 | if (GNUNET_OK != | 1408 | if (GNUNET_OK != |
1398 | TALER_RSA_sign (dki->denom_priv, | 1409 | TALER_RSA_sign (dki->denom_priv, |
@@ -1401,7 +1412,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1401 | &ev_sig)) | 1412 | &ev_sig)) |
1402 | { | 1413 | { |
1403 | GNUNET_break (0); | 1414 | GNUNET_break (0); |
1404 | return GNUNET_SYSERR; | 1415 | // FIXME: return error code! |
1416 | return MHD_NO; | ||
1405 | } | 1417 | } |
1406 | 1418 | ||
1407 | res = TALER_MINT_DB_insert_refresh_collectable (db_conn, | 1419 | res = TALER_MINT_DB_insert_refresh_collectable (db_conn, |
@@ -1411,7 +1423,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1411 | if (GNUNET_OK != res) | 1423 | if (GNUNET_OK != res) |
1412 | { | 1424 | { |
1413 | GNUNET_break (0); | 1425 | GNUNET_break (0); |
1414 | return GNUNET_SYSERR; | 1426 | // FIXME: return error code! |
1427 | return MHD_NO; | ||
1415 | } | 1428 | } |
1416 | } | 1429 | } |
1417 | /* mark that reveal was successful */ | 1430 | /* mark that reveal was successful */ |
@@ -1420,7 +1433,8 @@ TALER_MINT_handler_refresh_reveal (struct RequestHandler *rh, | |||
1420 | if (GNUNET_OK != res) | 1433 | if (GNUNET_OK != res) |
1421 | { | 1434 | { |
1422 | GNUNET_break (0); | 1435 | GNUNET_break (0); |
1423 | return GNUNET_SYSERR; | 1436 | // FIXME: return error code! |
1437 | return MHD_NO; | ||
1424 | } | 1438 | } |
1425 | 1439 | ||
1426 | if (GNUNET_OK != TALER_MINT_DB_commit (db_conn)) | 1440 | if (GNUNET_OK != TALER_MINT_DB_commit (db_conn)) |
@@ -1459,9 +1473,9 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh, | |||
1459 | struct SharedSecretEnc shared_secret_enc; | 1473 | struct SharedSecretEnc shared_secret_enc; |
1460 | 1474 | ||
1461 | res = TALER_MINT_mhd_request_arg_data (connection, | 1475 | res = TALER_MINT_mhd_request_arg_data (connection, |
1462 | "coin_pub", | 1476 | "coin_pub", |
1463 | &coin_pub, | 1477 | &coin_pub, |
1464 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1478 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
1465 | if (GNUNET_SYSERR == res) | 1479 | if (GNUNET_SYSERR == res) |
1466 | { | 1480 | { |
1467 | // FIXME: return 'internal error' | 1481 | // FIXME: return 'internal error' |
@@ -1474,7 +1488,8 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh, | |||
1474 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) | 1488 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) |
1475 | { | 1489 | { |
1476 | GNUNET_break (0); | 1490 | GNUNET_break (0); |
1477 | return GNUNET_SYSERR; | 1491 | // FIXME: return error code! |
1492 | return MHD_NO; | ||
1478 | } | 1493 | } |
1479 | 1494 | ||
1480 | list = json_array (); | 1495 | list = json_array (); |
@@ -1488,6 +1503,7 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh, | |||
1488 | if (GNUNET_SYSERR == res) | 1503 | if (GNUNET_SYSERR == res) |
1489 | { | 1504 | { |
1490 | GNUNET_break (0); | 1505 | GNUNET_break (0); |
1506 | // FIXME: return error code! | ||
1491 | return MHD_NO; | 1507 | return MHD_NO; |
1492 | } | 1508 | } |
1493 | if (GNUNET_NO == res) | 1509 | if (GNUNET_NO == res) |
@@ -1504,6 +1520,7 @@ TALER_MINT_handler_refresh_link (struct RequestHandler *rh, | |||
1504 | if (GNUNET_SYSERR == res) | 1520 | if (GNUNET_SYSERR == res) |
1505 | { | 1521 | { |
1506 | GNUNET_break (0); | 1522 | GNUNET_break (0); |
1523 | // FIXME: return error code! | ||
1507 | return MHD_NO; | 1524 | return MHD_NO; |
1508 | } | 1525 | } |
1509 | if (GNUNET_NO == res) | 1526 | if (GNUNET_NO == res) |
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 8f886c3d9..bad4991da 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c | |||
@@ -138,6 +138,71 @@ TALER_MINT_reply_arg_missing (struct MHD_Connection *connection, | |||
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | /** | ||
142 | * Send a response indicating an internal error. | ||
143 | * | ||
144 | * @param connection the MHD connection to use | ||
145 | * @param hint hint about the internal error's nature | ||
146 | * @return a MHD result code | ||
147 | */ | ||
148 | int | ||
149 | TALER_MINT_reply_internal_error (struct MHD_Connection *connection, | ||
150 | const char *hint) | ||
151 | { | ||
152 | json_t *json; | ||
153 | |||
154 | json = json_pack ("{ s:s, s:s }", | ||
155 | "error", | ||
156 | "internal error", | ||
157 | "hint", | ||
158 | hint); | ||
159 | return TALER_MINT_reply_json (connection, | ||
160 | json, | ||
161 | MHD_HTTP_BAD_REQUEST); | ||
162 | } | ||
163 | |||
164 | |||
165 | /** | ||
166 | * Send a response indicating that the request was too big. | ||
167 | * | ||
168 | * @param connection the MHD connection to use | ||
169 | * @return a MHD result code | ||
170 | */ | ||
171 | int | ||
172 | TALER_MINT_reply_request_too_large (struct MHD_Connection *connection) | ||
173 | { | ||
174 | struct MHD_Response *resp; | ||
175 | int ret; | ||
176 | |||
177 | resp = MHD_create_response_from_buffer (0, | ||
178 | NULL, | ||
179 | MHD_RESPMEM_PERSISTENT); | ||
180 | if (NULL == resp) | ||
181 | return MHD_NO; | ||
182 | ret = MHD_queue_response (connection, | ||
183 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, | ||
184 | resp); | ||
185 | MHD_destroy_response (resp); | ||
186 | return ret; | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Send a response indicating that the JSON was malformed. | ||
192 | * | ||
193 | * @param connection the MHD connection to use | ||
194 | * @return a MHD result code | ||
195 | */ | ||
196 | int | ||
197 | TALER_MINT_reply_invalid_json (struct MHD_Connection *connection) | ||
198 | { | ||
199 | return TALER_MINT_reply_json_pack (connection, | ||
200 | MHD_HTTP_BAD_REQUEST, | ||
201 | "{s:s}", | ||
202 | "error", | ||
203 | "invalid json"); | ||
204 | } | ||
205 | |||
141 | 206 | ||
142 | 207 | ||
143 | 208 | ||
diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 230904519..be662319f 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h | |||
@@ -90,6 +90,39 @@ TALER_MINT_reply_arg_missing (struct MHD_Connection *connection, | |||
90 | const char *param_name); | 90 | const char *param_name); |
91 | 91 | ||
92 | 92 | ||
93 | /** | ||
94 | * Send a response indicating an internal error. | ||
95 | * | ||
96 | * @param connection the MHD connection to use | ||
97 | * @param hint hint about the internal error's nature | ||
98 | * @return a MHD result code | ||
99 | */ | ||
100 | int | ||
101 | TALER_MINT_reply_internal_error (struct MHD_Connection *connection, | ||
102 | const char *hint); | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Send a response indicating that the request was too big. | ||
107 | * | ||
108 | * @param connection the MHD connection to use | ||
109 | * @return a MHD result code | ||
110 | */ | ||
111 | int | ||
112 | TALER_MINT_reply_request_too_large (struct MHD_Connection *connection); | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Send a response indicating that the JSON was malformed. | ||
117 | * | ||
118 | * @param connection the MHD connection to use | ||
119 | * @return a MHD result code | ||
120 | */ | ||
121 | int | ||
122 | TALER_MINT_reply_invalid_json (struct MHD_Connection *connection); | ||
123 | |||
124 | |||
125 | |||
93 | 126 | ||
94 | 127 | ||
95 | #endif | 128 | #endif |