diff options
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r-- | src/reclaim/json_reclaim.c | 209 |
1 files changed, 105 insertions, 104 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index a98dec717..fa3901e43 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -41,7 +41,7 @@ | |||
41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
42 | */ | 42 | */ |
43 | static int | 43 | static int |
44 | parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 44 | parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
45 | { | 45 | { |
46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
47 | const char *name_str = NULL; | 47 | const char *name_str = NULL; |
@@ -53,52 +53,52 @@ parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
53 | uint32_t type; | 53 | uint32_t type; |
54 | size_t data_size; | 54 | size_t data_size; |
55 | 55 | ||
56 | GNUNET_assert(NULL != root); | 56 | GNUNET_assert (NULL != root); |
57 | 57 | ||
58 | if (!json_is_object(root)) | 58 | if (! json_is_object (root)) |
59 | { | 59 | { |
60 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
61 | "Error json is not array nor object!\n"); | 61 | "Error json is not array nor object!\n"); |
62 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
63 | } | 63 | } |
64 | // interpret single attribute | 64 | // interpret single attribute |
65 | unpack_state = json_unpack(root, | 65 | unpack_state = json_unpack (root, |
66 | "{s:s, s?s, s:s, s:s!}", | 66 | "{s:s, s?s, s:s, s:s!}", |
67 | "name", | 67 | "name", |
68 | &name_str, | 68 | &name_str, |
69 | "id", | 69 | "id", |
70 | &id_str, | 70 | &id_str, |
71 | "type", | 71 | "type", |
72 | &type_str, | 72 | &type_str, |
73 | "value", | 73 | "value", |
74 | &val_str); | 74 | &val_str); |
75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || |
76 | (NULL == type_str)) | 76 | (NULL == type_str)) |
77 | { | 77 | { |
78 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
79 | "Error json object has a wrong format!\n"); | 79 | "Error json object has a wrong format!\n"); |
80 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
81 | } | 81 | } |
82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); | 82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); |
83 | if (GNUNET_SYSERR == | 83 | if (GNUNET_SYSERR == |
84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, | 84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, |
85 | val_str, | 85 | val_str, |
86 | (void **)&data, | 86 | (void **) &data, |
87 | &data_size))) | 87 | &data_size))) |
88 | { | 88 | { |
89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
90 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
91 | } | 91 | } |
92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new(name_str, type, data, data_size); | 92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); |
93 | if ((NULL == id_str) || (0 == strlen(id_str))) | 93 | if ((NULL == id_str) || (0 == strlen (id_str))) |
94 | attr->id = 0; | 94 | attr->id = 0; |
95 | else | 95 | else |
96 | GNUNET_STRINGS_string_to_data(id_str, | 96 | GNUNET_STRINGS_string_to_data (id_str, |
97 | strlen(id_str), | 97 | strlen (id_str), |
98 | &attr->id, | 98 | &attr->id, |
99 | sizeof(uint64_t)); | 99 | sizeof(uint64_t)); |
100 | 100 | ||
101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr; | 101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; |
102 | return GNUNET_OK; | 102 | return GNUNET_OK; |
103 | } | 103 | } |
104 | 104 | ||
@@ -109,16 +109,16 @@ parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
109 | * @param[out] spec where to free the data | 109 | * @param[out] spec where to free the data |
110 | */ | 110 | */ |
111 | static void | 111 | static void |
112 | clean_attr(void *cls, struct GNUNET_JSON_Specification *spec) | 112 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) |
113 | { | 113 | { |
114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; |
115 | 115 | ||
116 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr; | 116 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; |
117 | if (NULL != *attr) | 117 | if (NULL != *attr) |
118 | { | 118 | { |
119 | GNUNET_free(*attr); | 119 | GNUNET_free (*attr); |
120 | *attr = NULL; | 120 | *attr = NULL; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | /** | 124 | /** |
@@ -128,7 +128,7 @@ clean_attr(void *cls, struct GNUNET_JSON_Specification *spec) | |||
128 | * @return JSON Specification | 128 | * @return JSON Specification |
129 | */ | 129 | */ |
130 | struct GNUNET_JSON_Specification | 130 | struct GNUNET_JSON_Specification |
131 | GNUNET_RECLAIM_JSON_spec_claim(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 131 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) |
132 | { | 132 | { |
133 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, | 133 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, |
134 | .cleaner = &clean_attr, | 134 | .cleaner = &clean_attr, |
@@ -150,7 +150,7 @@ GNUNET_RECLAIM_JSON_spec_claim(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | |||
150 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 150 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
151 | */ | 151 | */ |
152 | static int | 152 | static int |
153 | parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 153 | parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
154 | { | 154 | { |
155 | struct GNUNET_RECLAIM_Ticket *ticket; | 155 | struct GNUNET_RECLAIM_Ticket *ticket; |
156 | const char *rnd_str; | 156 | const char *rnd_str; |
@@ -158,63 +158,64 @@ parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
158 | const char *id_str; | 158 | const char *id_str; |
159 | int unpack_state; | 159 | int unpack_state; |
160 | 160 | ||
161 | GNUNET_assert(NULL != root); | 161 | GNUNET_assert (NULL != root); |
162 | 162 | ||
163 | if (!json_is_object(root)) | 163 | if (! json_is_object (root)) |
164 | { | 164 | { |
165 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 165 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
166 | "Error json is not array nor object!\n"); | 166 | "Error json is not array nor object!\n"); |
167 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
168 | } | 168 | } |
169 | // interpret single ticket | 169 | // interpret single ticket |
170 | unpack_state = json_unpack(root, | 170 | unpack_state = json_unpack (root, |
171 | "{s:s, s:s, s:s!}", | 171 | "{s:s, s:s, s:s!}", |
172 | "rnd", | 172 | "rnd", |
173 | &rnd_str, | 173 | &rnd_str, |
174 | "audience", | 174 | "audience", |
175 | &aud_str, | 175 | &aud_str, |
176 | "issuer", | 176 | "issuer", |
177 | &id_str); | 177 | &id_str); |
178 | if (0 != unpack_state) | 178 | if (0 != unpack_state) |
179 | { | 179 | { |
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
181 | "Error json object has a wrong format!\n"); | 181 | "Error json object has a wrong format!\n"); |
182 | return GNUNET_SYSERR; | 182 | return GNUNET_SYSERR; |
183 | } | 183 | } |
184 | ticket = GNUNET_new(struct GNUNET_RECLAIM_Ticket); | 184 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); |
185 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data(rnd_str, | 185 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, |
186 | strlen(rnd_str), | 186 | strlen (rnd_str), |
187 | &ticket->rnd, | 187 | &ticket->rnd, |
188 | sizeof(uint64_t))) | 188 | sizeof(uint64_t))) |
189 | { | 189 | { |
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); | 190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); |
191 | GNUNET_free(ticket); | 191 | GNUNET_free (ticket); |
192 | return GNUNET_SYSERR; | 192 | return GNUNET_SYSERR; |
193 | } | 193 | } |
194 | if (GNUNET_OK != | 194 | if (GNUNET_OK != |
195 | GNUNET_STRINGS_string_to_data(id_str, | 195 | GNUNET_STRINGS_string_to_data (id_str, |
196 | strlen(id_str), | 196 | strlen (id_str), |
197 | &ticket->identity, | 197 | &ticket->identity, |
198 | sizeof( | 198 | sizeof( |
199 | struct GNUNET_CRYPTO_EcdsaPublicKey))) | 199 | struct GNUNET_CRYPTO_EcdsaPublicKey))) |
200 | { | 200 | { |
201 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); | 201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); |
202 | GNUNET_free(ticket); | 202 | GNUNET_free (ticket); |
203 | return GNUNET_SYSERR; | 203 | return GNUNET_SYSERR; |
204 | } | 204 | } |
205 | 205 | ||
206 | if (GNUNET_OK != | 206 | if (GNUNET_OK != |
207 | GNUNET_STRINGS_string_to_data(aud_str, | 207 | GNUNET_STRINGS_string_to_data (aud_str, |
208 | strlen(aud_str), | 208 | strlen (aud_str), |
209 | &ticket->audience, | 209 | &ticket->audience, |
210 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 210 | sizeof(struct |
211 | { | 211 | GNUNET_CRYPTO_EcdsaPublicKey))) |
212 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); | 212 | { |
213 | GNUNET_free(ticket); | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); |
214 | return GNUNET_SYSERR; | 214 | GNUNET_free (ticket); |
215 | } | 215 | return GNUNET_SYSERR; |
216 | } | ||
216 | 217 | ||
217 | *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket; | 218 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; |
218 | return GNUNET_OK; | 219 | return GNUNET_OK; |
219 | } | 220 | } |
220 | 221 | ||
@@ -225,16 +226,16 @@ parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
225 | * @param[out] spec where to free the data | 226 | * @param[out] spec where to free the data |
226 | */ | 227 | */ |
227 | static void | 228 | static void |
228 | clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec) | 229 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) |
229 | { | 230 | { |
230 | struct GNUNET_RECLAIM_Ticket **ticket; | 231 | struct GNUNET_RECLAIM_Ticket **ticket; |
231 | 232 | ||
232 | ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr; | 233 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; |
233 | if (NULL != *ticket) | 234 | if (NULL != *ticket) |
234 | { | 235 | { |
235 | GNUNET_free(*ticket); | 236 | GNUNET_free (*ticket); |
236 | *ticket = NULL; | 237 | *ticket = NULL; |
237 | } | 238 | } |
238 | } | 239 | } |
239 | 240 | ||
240 | /** | 241 | /** |
@@ -244,7 +245,7 @@ clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec) | |||
244 | * @return JSON Specification | 245 | * @return JSON Specification |
245 | */ | 246 | */ |
246 | struct GNUNET_JSON_Specification | 247 | struct GNUNET_JSON_Specification |
247 | GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket) | 248 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) |
248 | { | 249 | { |
249 | struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket, | 250 | struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket, |
250 | .cleaner = &clean_ticket, | 251 | .cleaner = &clean_ticket, |