aboutsummaryrefslogtreecommitdiff
path: root/src/auction
diff options
context:
space:
mode:
authorMarkus Teich <teichm@fs.tum.de>2017-01-12 19:23:12 +0100
committerMarkus Teich <teichm@fs.tum.de>2017-01-12 20:18:09 +0100
commitcafbbb5994d333323e79c02ecd4700d82ff4242c (patch)
tree1b70ff85d9068610e69bff3b85d48ffea822759e /src/auction
parent70f09e5d0892371486446878af330721db3845e9 (diff)
downloadgnunet-cafbbb5994d333323e79c02ecd4700d82ff4242c.tar.gz
gnunet-cafbbb5994d333323e79c02ecd4700d82ff4242c.zip
auction: add pricemap validation
Diffstat (limited to 'src/auction')
-rw-r--r--src/auction/gnunet-auction-create.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/auction/gnunet-auction-create.c b/src/auction/gnunet-auction-create.c
index c21e93f26..dc43f635e 100644
--- a/src/auction/gnunet-auction-create.c
+++ b/src/auction/gnunet-auction-create.c
@@ -24,6 +24,9 @@
24 * @author Markus Teich 24 * @author Markus Teich
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27
28#include <float.h>
29
27#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
28#include "gnunet_json_lib.h" 31#include "gnunet_json_lib.h"
29/* #include "gnunet_auction_service.h" */ 32/* #include "gnunet_auction_service.h" */
@@ -56,6 +59,13 @@ run (void *cls,
56 const char *cfgfile, 59 const char *cfgfile,
57 const struct GNUNET_CONFIGURATION_Handle *cfg) 60 const struct GNUNET_CONFIGURATION_Handle *cfg)
58{ 61{
62 unsigned int i;
63 double cur, prev = DBL_MAX;
64 json_t *pmap;
65 json_t *parray;
66 json_t *pnode;
67 json_error_t jerr;
68
59 /* cmdline parsing */ 69 /* cmdline parsing */
60 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us) 70 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == dstart.rel_value_us)
61 { 71 {
@@ -82,6 +92,48 @@ run (void *cls,
82 goto fail; 92 goto fail;
83 } 93 }
84 94
95 /* parse and check pricemap validity */
96 if (!(pmap = json_load_file (fnprices, JSON_DECODE_INT_AS_REAL, &jerr)))
97 {
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 "parsing pricemap json at %d:%d: %s\n",
100 jerr.line, jerr.column, jerr.text);
101 goto fail;
102 }
103 if (-1 == json_unpack_ex (pmap, &jerr, JSON_VALIDATE_ONLY,
104 "{s:s, s:[]}", "currency", "prices"))
105 {
106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
107 "validating pricemap: %s\n", jerr.text);
108 goto fail;
109 }
110 if (!(parray = json_object_get (pmap, "prices")) || !json_is_array (parray))
111 {
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 "could not get `prices` array node from pricemap\n");
114 goto fail;
115 }
116 json_array_foreach (parray, i, pnode)
117 {
118 if (-1 == json_unpack_ex (pnode, &jerr, 0, "F", &cur))
119 {
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
121 "validating pricearray index %d: %s\n", i, jerr.text);
122 goto fail;
123 }
124 if (prev <= cur)
125 {
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
127 "validating pricearray index %d: "
128 "prices must be strictly monotonically decreasing\n",
129 i);
130 goto fail;
131 }
132 prev = cur;
133 }
134
135 return;
136
85fail: 137fail:
86 ret = 1; 138 ret = 1;
87 return; 139 return;