aboutsummaryrefslogtreecommitdiff
path: root/src/reducer/anastasis_api_backup_redux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reducer/anastasis_api_backup_redux.c')
-rw-r--r--src/reducer/anastasis_api_backup_redux.c176
1 files changed, 144 insertions, 32 deletions
diff --git a/src/reducer/anastasis_api_backup_redux.c b/src/reducer/anastasis_api_backup_redux.c
index cfef852..27b5730 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -286,22 +286,28 @@ add_authentication (json_t *state,
286 286
287 json_object_foreach (auth_providers, url, details) 287 json_object_foreach (auth_providers, url, details)
288 { 288 {
289 json_t *methods; 289 json_t *methods = NULL;
290 json_t *method; 290 json_t *method;
291 size_t index; 291 size_t index;
292 uint32_t size_limit_in_mb; 292 uint32_t size_limit_in_mb = 0;
293 bool disabled = false;
294 uint32_t http_status = 0;
293 struct GNUNET_JSON_Specification ispec[] = { 295 struct GNUNET_JSON_Specification ispec[] = {
294 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", 296 GNUNET_JSON_spec_mark_optional (
295 &size_limit_in_mb), 297 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
296 GNUNET_JSON_spec_json ("methods", 298 &size_limit_in_mb)),
297 &methods), 299 GNUNET_JSON_spec_mark_optional (
300 GNUNET_JSON_spec_uint32 ("http_status",
301 &http_status)),
302 GNUNET_JSON_spec_mark_optional (
303 GNUNET_JSON_spec_bool ("disabled",
304 &disabled)),
305 GNUNET_JSON_spec_mark_optional (
306 GNUNET_JSON_spec_json ("methods",
307 &methods)),
298 GNUNET_JSON_spec_end () 308 GNUNET_JSON_spec_end ()
299 }; 309 };
300 310
301 if (MHD_HTTP_OK !=
302 json_integer_value (json_object_get (details,
303 "http_status")))
304 continue; /* skip providers that are down */
305 if (GNUNET_OK != 311 if (GNUNET_OK !=
306 GNUNET_JSON_parse (details, 312 GNUNET_JSON_parse (details,
307 ispec, 313 ispec,
@@ -310,6 +316,16 @@ add_authentication (json_t *state,
310 GNUNET_break (0); 316 GNUNET_break (0);
311 continue; 317 continue;
312 } 318 }
319 if (disabled)
320 continue;
321 if (MHD_HTTP_OK != http_status)
322 continue; /* skip providers that are down */
323 if ( (NULL == methods) ||
324 (0 == size_limit_in_mb) )
325 {
326 GNUNET_break (0);
327 continue;
328 }
313 json_array_foreach (methods, index, method) 329 json_array_foreach (methods, index, method)
314 { 330 {
315 const char *type; 331 const char *type;
@@ -1082,6 +1098,33 @@ provider_candidate (struct PolicyBuilder *pb,
1082 1098
1083 json_object_foreach (pb->providers, url, pconfig) 1099 json_object_foreach (pb->providers, url, pconfig)
1084 { 1100 {
1101 bool disabled = false;
1102 uint32_t http_status = 0;
1103 struct GNUNET_JSON_Specification spec[] = {
1104 GNUNET_JSON_spec_mark_optional (
1105 GNUNET_JSON_spec_bool ("disabled",
1106 &disabled)),
1107 GNUNET_JSON_spec_mark_optional (
1108 GNUNET_JSON_spec_uint32 ("http_status",
1109 &http_status)),
1110 GNUNET_JSON_spec_end ()
1111 };
1112
1113 if (GNUNET_OK !=
1114 GNUNET_JSON_parse (pconfig,
1115 spec,
1116 NULL, NULL))
1117 {
1118 GNUNET_break (0);
1119 continue;
1120 }
1121 if ( (MHD_HTTP_OK != http_status) ||
1122 disabled)
1123 {
1124 GNUNET_JSON_parse_free (spec);
1125 continue;
1126 }
1127 GNUNET_JSON_parse_free (spec);
1085 prov_sel[i] = url; 1128 prov_sel[i] = url;
1086 if (i == pb->req_methods - 1) 1129 if (i == pb->req_methods - 1)
1087 { 1130 {
@@ -1178,16 +1221,25 @@ method_candidate (struct PolicyBuilder *pb,
1178 * @param[out] salt value to extract 1221 * @param[out] salt value to extract
1179 * @return #GNUNET_OK on success 1222 * @return #GNUNET_OK on success
1180 */ 1223 */
1181static int 1224static enum GNUNET_GenericReturnValue
1182lookup_salt (const json_t *state, 1225lookup_salt (const json_t *state,
1183 const char *provider_url, 1226 const char *provider_url,
1184 struct ANASTASIS_CRYPTO_ProviderSaltP *salt) 1227 struct ANASTASIS_CRYPTO_ProviderSaltP *salt)
1185{ 1228{
1186 const json_t *aps; 1229 const json_t *aps;
1187 const json_t *cfg; 1230 const json_t *cfg;
1231 uint32_t http_status = 0;
1232 bool disabled = false;
1188 struct GNUNET_JSON_Specification spec[] = { 1233 struct GNUNET_JSON_Specification spec[] = {
1189 GNUNET_JSON_spec_fixed_auto ("salt", 1234 GNUNET_JSON_spec_mark_optional (
1190 salt), 1235 GNUNET_JSON_spec_bool ("disabled",
1236 &disabled)),
1237 GNUNET_JSON_spec_mark_optional (
1238 GNUNET_JSON_spec_uint32 ("http_status",
1239 &http_status)),
1240 GNUNET_JSON_spec_mark_optional (
1241 GNUNET_JSON_spec_fixed_auto ("salt",
1242 salt)),
1191 GNUNET_JSON_spec_end () 1243 GNUNET_JSON_spec_end ()
1192 }; 1244 };
1193 1245
@@ -1205,10 +1257,6 @@ lookup_salt (const json_t *state,
1205 GNUNET_break (0); 1257 GNUNET_break (0);
1206 return GNUNET_SYSERR; 1258 return GNUNET_SYSERR;
1207 } 1259 }
1208 if (MHD_HTTP_OK !=
1209 json_integer_value (json_object_get (cfg,
1210 "http_status")))
1211 return GNUNET_NO; /* skip providers that are down */
1212 if (GNUNET_OK != 1260 if (GNUNET_OK !=
1213 GNUNET_JSON_parse (cfg, 1261 GNUNET_JSON_parse (cfg,
1214 spec, 1262 spec,
@@ -1218,6 +1266,12 @@ lookup_salt (const json_t *state,
1218 GNUNET_break_op (0); 1266 GNUNET_break_op (0);
1219 return GNUNET_NO; 1267 return GNUNET_NO;
1220 } 1268 }
1269 if (disabled)
1270 return GNUNET_NO;
1271 if (NULL ==
1272 json_object_get (cfg,
1273 "salt"))
1274 return GNUNET_NO;
1221 return GNUNET_OK; 1275 return GNUNET_OK;
1222} 1276}
1223 1277
@@ -1904,7 +1958,15 @@ add_policy (json_t *state,
1904 { 1958 {
1905 const json_t *prov_cfg; 1959 const json_t *prov_cfg;
1906 uint32_t limit; 1960 uint32_t limit;
1961 bool disabled = false;
1962 uint32_t http_status = 0;
1907 struct GNUNET_JSON_Specification spec[] = { 1963 struct GNUNET_JSON_Specification spec[] = {
1964 GNUNET_JSON_spec_mark_optional (
1965 GNUNET_JSON_spec_bool ("disabled",
1966 &disabled)),
1967 GNUNET_JSON_spec_mark_optional (
1968 GNUNET_JSON_spec_uint32 ("http_status",
1969 &http_status)),
1908 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", 1970 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
1909 &limit), 1971 &limit),
1910 GNUNET_JSON_spec_json ("methods", 1972 GNUNET_JSON_spec_json ("methods",
@@ -1924,10 +1986,6 @@ add_policy (json_t *state,
1924 "provider URL unknown"); 1986 "provider URL unknown");
1925 return NULL; 1987 return NULL;
1926 } 1988 }
1927 if (MHD_HTTP_OK !=
1928 json_integer_value (json_object_get (prov_cfg,
1929 "http_status")))
1930 continue;
1931 if (GNUNET_OK != 1989 if (GNUNET_OK !=
1932 GNUNET_JSON_parse (prov_cfg, 1990 GNUNET_JSON_parse (prov_cfg,
1933 spec, 1991 spec,
@@ -1937,6 +1995,13 @@ add_policy (json_t *state,
1937 json_decref (methods); 1995 json_decref (methods);
1938 continue; 1996 continue;
1939 } 1997 }
1998 if ( (MHD_HTTP_OK != http_status) ||
1999 disabled)
2000 {
2001 /* skip provider, disabled or down */
2002 json_decref (methods);
2003 continue;
2004 }
1940 if (! json_is_array (prov_methods)) 2005 if (! json_is_array (prov_methods))
1941 { 2006 {
1942 GNUNET_break (0); 2007 GNUNET_break (0);
@@ -2373,17 +2438,21 @@ update_expiration_cost (json_t *state,
2373 json_object_foreach (providers, url, provider) 2438 json_object_foreach (providers, url, provider)
2374 { 2439 {
2375 struct TALER_Amount annual_fee; 2440 struct TALER_Amount annual_fee;
2441 bool disabled = false;
2442 uint32_t http_status = 0;
2376 struct GNUNET_JSON_Specification pspec[] = { 2443 struct GNUNET_JSON_Specification pspec[] = {
2444 GNUNET_JSON_spec_mark_optional (
2445 GNUNET_JSON_spec_bool ("disabled",
2446 &disabled)),
2447 GNUNET_JSON_spec_mark_optional (
2448 GNUNET_JSON_spec_uint32 ("http_status",
2449 &http_status)),
2377 TALER_JSON_spec_amount_any ("annual_fee", 2450 TALER_JSON_spec_amount_any ("annual_fee",
2378 &annual_fee), 2451 &annual_fee),
2379 GNUNET_JSON_spec_end () 2452 GNUNET_JSON_spec_end ()
2380 }; 2453 };
2381 struct TALER_Amount fee; 2454 struct TALER_Amount fee;
2382 2455
2383 if (MHD_HTTP_OK !=
2384 json_integer_value (json_object_get (provider,
2385 "http_status")))
2386 continue; /* skip providers that are down */
2387 if (GNUNET_OK != 2456 if (GNUNET_OK !=
2388 GNUNET_JSON_parse (provider, 2457 GNUNET_JSON_parse (provider,
2389 pspec, 2458 pspec,
@@ -2393,6 +2462,9 @@ update_expiration_cost (json_t *state,
2393 GNUNET_break_op (0); 2462 GNUNET_break_op (0);
2394 continue; 2463 continue;
2395 } 2464 }
2465 if ( (MHD_HTTP_OK != http_status) ||
2466 disabled)
2467 continue; /* skip providers that are down or disabled */
2396 if (0 > 2468 if (0 >
2397 TALER_amount_multiply (&fee, 2469 TALER_amount_multiply (&fee,
2398 &annual_fee, 2470 &annual_fee,
@@ -2473,7 +2545,15 @@ update_expiration_cost (json_t *state,
2473 off++; 2545 off++;
2474 { 2546 {
2475 struct TALER_Amount upload_cost; 2547 struct TALER_Amount upload_cost;
2548 bool disabled = false;
2549 uint32_t http_status = 0;
2476 struct GNUNET_JSON_Specification pspec[] = { 2550 struct GNUNET_JSON_Specification pspec[] = {
2551 GNUNET_JSON_spec_mark_optional (
2552 GNUNET_JSON_spec_bool ("disabled",
2553 &disabled)),
2554 GNUNET_JSON_spec_mark_optional (
2555 GNUNET_JSON_spec_uint32 ("http_status",
2556 &http_status)),
2477 TALER_JSON_spec_amount_any ("truth_upload_fee", 2557 TALER_JSON_spec_amount_any ("truth_upload_fee",
2478 &upload_cost), 2558 &upload_cost),
2479 GNUNET_JSON_spec_end () 2559 GNUNET_JSON_spec_end ()
@@ -2491,6 +2571,12 @@ update_expiration_cost (json_t *state,
2491 GNUNET_break (0); 2571 GNUNET_break (0);
2492 return GNUNET_SYSERR; 2572 return GNUNET_SYSERR;
2493 } 2573 }
2574 if ( (MHD_HTTP_OK != http_status) ||
2575 disabled)
2576 {
2577 GNUNET_break (0);
2578 return GNUNET_SYSERR;
2579 }
2494 if (0 > 2580 if (0 >
2495 TALER_amount_multiply (&fee, 2581 TALER_amount_multiply (&fee,
2496 &upload_cost, 2582 &upload_cost,
@@ -4111,17 +4197,22 @@ check_upload_size_limit (json_t *state,
4111 see #6760. */ 4197 see #6760. */
4112 json_object_foreach (aps, url, ap) 4198 json_object_foreach (aps, url, ap)
4113 { 4199 {
4114 uint32_t limit; 4200 uint32_t limit = 0;
4201 bool disabled = false;
4202 uint32_t http_status = 0;
4115 struct GNUNET_JSON_Specification spec[] = { 4203 struct GNUNET_JSON_Specification spec[] = {
4116 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", 4204 GNUNET_JSON_spec_mark_optional (
4117 &limit), 4205 GNUNET_JSON_spec_bool ("disabled",
4206 &disabled)),
4207 GNUNET_JSON_spec_mark_optional (
4208 GNUNET_JSON_spec_uint32 ("http_status",
4209 &http_status)),
4210 GNUNET_JSON_spec_mark_optional (
4211 GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
4212 &limit)),
4118 GNUNET_JSON_spec_end () 4213 GNUNET_JSON_spec_end ()
4119 }; 4214 };
4120 4215
4121 if (MHD_HTTP_OK !=
4122 json_integer_value (json_object_get (ap,
4123 "http_status")))
4124 continue; /* skip providers that are down */
4125 if (GNUNET_OK != 4216 if (GNUNET_OK !=
4126 GNUNET_JSON_parse (ap, 4217 GNUNET_JSON_parse (ap,
4127 spec, 4218 spec,
@@ -4131,6 +4222,9 @@ check_upload_size_limit (json_t *state,
4131 GNUNET_break_op (0); 4222 GNUNET_break_op (0);
4132 continue; 4223 continue;
4133 } 4224 }
4225 if ( (MHD_HTTP_OK != http_status) ||
4226 disabled)
4227 continue;
4134 if (0 == limit) 4228 if (0 == limit)
4135 return GNUNET_SYSERR; 4229 return GNUNET_SYSERR;
4136 min_limit = GNUNET_MIN (min_limit, 4230 min_limit = GNUNET_MIN (min_limit,
@@ -4935,7 +5029,25 @@ ANASTASIS_REDUX_backup_begin_ (json_t *state,
4935 json_object_foreach (provider_list, url, prov) { 5029 json_object_foreach (provider_list, url, prov) {
4936 struct BackupStartStateProviderEntry *pe; 5030 struct BackupStartStateProviderEntry *pe;
4937 json_t *istate; 5031 json_t *istate;
5032 bool disabled = false;
5033 struct GNUNET_JSON_Specification spec[] = {
5034 GNUNET_JSON_spec_mark_optional (
5035 GNUNET_JSON_spec_bool ("disabled",
5036 &disabled)),
5037 GNUNET_JSON_spec_end ()
5038 };
4938 5039
5040 if (GNUNET_OK !=
5041 GNUNET_JSON_parse (prov,
5042 spec,
5043 NULL, NULL))
5044 {
5045 /* skip malformed provider entry */
5046 GNUNET_break_op (0);
5047 continue;
5048 }
5049 if (disabled)
5050 continue;
4939 pe = GNUNET_new (struct BackupStartStateProviderEntry); 5051 pe = GNUNET_new (struct BackupStartStateProviderEntry);
4940 pe->bss = bss; 5052 pe->bss = bss;
4941 istate = json_object (); 5053 istate = json_object ();