diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/json | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/json')
-rw-r--r-- | src/json/json.c | 88 | ||||
-rw-r--r-- | src/json/json_generator.c | 145 | ||||
-rw-r--r-- | src/json/json_gnsrecord.c | 217 | ||||
-rw-r--r-- | src/json/json_helper.c | 648 | ||||
-rw-r--r-- | src/json/json_mhd.c | 331 | ||||
-rw-r--r-- | src/json/test_json.c | 184 | ||||
-rw-r--r-- | src/json/test_json_mhd.c | 218 |
7 files changed, 920 insertions, 911 deletions
diff --git a/src/json/json.c b/src/json/json.c index ecdea0294..f6d2406c4 100644 --- a/src/json/json.c +++ b/src/json/json.c | |||
@@ -42,34 +42,34 @@ | |||
42 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 42 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
43 | */ | 43 | */ |
44 | int | 44 | int |
45 | GNUNET_JSON_parse(const json_t *root, | 45 | GNUNET_JSON_parse (const json_t *root, |
46 | struct GNUNET_JSON_Specification *spec, | 46 | struct GNUNET_JSON_Specification *spec, |
47 | const char **error_json_name, | 47 | const char **error_json_name, |
48 | unsigned int *error_line) | 48 | unsigned int *error_line) |
49 | { | 49 | { |
50 | if (NULL == root) | 50 | if (NULL == root) |
51 | return GNUNET_SYSERR; | 51 | return GNUNET_SYSERR; |
52 | for (unsigned int i = 0; NULL != spec[i].parser; i++) | 52 | for (unsigned int i = 0; NULL != spec[i].parser; i++) |
53 | { | ||
54 | json_t *pos; | ||
55 | |||
56 | if (NULL == spec[i].field) | ||
57 | pos = (json_t *) root; | ||
58 | else | ||
59 | pos = json_object_get (root, spec[i].field); | ||
60 | if ((NULL == pos) && (spec[i].is_optional)) | ||
61 | continue; | ||
62 | if ((NULL == pos) || | ||
63 | (GNUNET_OK != spec[i].parser (spec[i].cls, pos, &spec[i]))) | ||
53 | { | 64 | { |
54 | json_t *pos; | 65 | if (NULL != error_json_name) |
55 | 66 | *error_json_name = spec[i].field; | |
56 | if (NULL == spec[i].field) | 67 | if (NULL != error_line) |
57 | pos = (json_t *)root; | 68 | *error_line = i; |
58 | else | 69 | GNUNET_JSON_parse_free (spec); |
59 | pos = json_object_get(root, spec[i].field); | 70 | return GNUNET_SYSERR; |
60 | if ((NULL == pos) && (spec[i].is_optional)) | ||
61 | continue; | ||
62 | if ((NULL == pos) || | ||
63 | (GNUNET_OK != spec[i].parser(spec[i].cls, pos, &spec[i]))) | ||
64 | { | ||
65 | if (NULL != error_json_name) | ||
66 | *error_json_name = spec[i].field; | ||
67 | if (NULL != error_line) | ||
68 | *error_line = i; | ||
69 | GNUNET_JSON_parse_free(spec); | ||
70 | return GNUNET_SYSERR; | ||
71 | } | ||
72 | } | 71 | } |
72 | } | ||
73 | return GNUNET_OK; /* all OK! */ | 73 | return GNUNET_OK; /* all OK! */ |
74 | } | 74 | } |
75 | 75 | ||
@@ -81,7 +81,7 @@ GNUNET_JSON_parse(const json_t *root, | |||
81 | * @return spec copy of @a spec with optional bit set | 81 | * @return spec copy of @a spec with optional bit set |
82 | */ | 82 | */ |
83 | struct GNUNET_JSON_Specification | 83 | struct GNUNET_JSON_Specification |
84 | GNUNET_JSON_spec_mark_optional(struct GNUNET_JSON_Specification spec) | 84 | GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec) |
85 | { | 85 | { |
86 | struct GNUNET_JSON_Specification ret = spec; | 86 | struct GNUNET_JSON_Specification ret = spec; |
87 | 87 | ||
@@ -97,11 +97,11 @@ GNUNET_JSON_spec_mark_optional(struct GNUNET_JSON_Specification spec) | |||
97 | * @param spec specification of the parse operation | 97 | * @param spec specification of the parse operation |
98 | */ | 98 | */ |
99 | void | 99 | void |
100 | GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec) | 100 | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec) |
101 | { | 101 | { |
102 | for (unsigned int i = 0; NULL != spec[i].parser; i++) | 102 | for (unsigned int i = 0; NULL != spec[i].parser; i++) |
103 | if (NULL != spec[i].cleaner) | 103 | if (NULL != spec[i].cleaner) |
104 | spec[i].cleaner(spec[i].cls, &spec[i]); | 104 | spec[i].cleaner (spec[i].cls, &spec[i]); |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
@@ -118,24 +118,24 @@ GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec) | |||
118 | * @return #GNUNET_OK if parsing the value worked | 118 | * @return #GNUNET_OK if parsing the value worked |
119 | */ | 119 | */ |
120 | static int | 120 | static int |
121 | set_json(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 121 | set_json (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
122 | void *scls, | 122 | void *scls, |
123 | const char *option, | 123 | const char *option, |
124 | const char *value) | 124 | const char *value) |
125 | { | 125 | { |
126 | json_t **json = scls; | 126 | json_t **json = scls; |
127 | json_error_t error; | 127 | json_error_t error; |
128 | 128 | ||
129 | *json = json_loads(value, JSON_REJECT_DUPLICATES, &error); | 129 | *json = json_loads (value, JSON_REJECT_DUPLICATES, &error); |
130 | if (NULL == *json) | 130 | if (NULL == *json) |
131 | { | 131 | { |
132 | fprintf(stderr, | 132 | fprintf (stderr, |
133 | _("Failed to parse JSON in option `%s': %s (%s)\n"), | 133 | _ ("Failed to parse JSON in option `%s': %s (%s)\n"), |
134 | option, | 134 | option, |
135 | error.text, | 135 | error.text, |
136 | error.source); | 136 | error.source); |
137 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
138 | } | 138 | } |
139 | return GNUNET_OK; | 139 | return GNUNET_OK; |
140 | } | 140 | } |
141 | 141 | ||
@@ -150,11 +150,11 @@ set_json(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
150 | * @param[out] val set to the JSON specified at the command line | 150 | * @param[out] val set to the JSON specified at the command line |
151 | */ | 151 | */ |
152 | struct GNUNET_GETOPT_CommandLineOption | 152 | struct GNUNET_GETOPT_CommandLineOption |
153 | GNUNET_JSON_getopt(char shortName, | 153 | GNUNET_JSON_getopt (char shortName, |
154 | const char *name, | 154 | const char *name, |
155 | const char *argumentHelp, | 155 | const char *argumentHelp, |
156 | const char *description, | 156 | const char *description, |
157 | json_t **json) | 157 | json_t **json) |
158 | { | 158 | { |
159 | struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, | 159 | struct GNUNET_GETOPT_CommandLineOption clo = { .shortName = shortName, |
160 | .name = name, | 160 | .name = name, |
@@ -162,7 +162,7 @@ GNUNET_JSON_getopt(char shortName, | |||
162 | .description = description, | 162 | .description = description, |
163 | .require_argument = 1, | 163 | .require_argument = 1, |
164 | .processor = &set_json, | 164 | .processor = &set_json, |
165 | .scls = (void *)json }; | 165 | .scls = (void *) json }; |
166 | 166 | ||
167 | return clo; | 167 | return clo; |
168 | } | 168 | } |
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index 61993c86a..72ee05dfc 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -36,15 +36,15 @@ | |||
36 | * @return json string that encodes @a data | 36 | * @return json string that encodes @a data |
37 | */ | 37 | */ |
38 | json_t * | 38 | json_t * |
39 | GNUNET_JSON_from_data(const void *data, | 39 | GNUNET_JSON_from_data (const void *data, |
40 | size_t size) | 40 | size_t size) |
41 | { | 41 | { |
42 | char *buf; | 42 | char *buf; |
43 | json_t *json; | 43 | json_t *json; |
44 | 44 | ||
45 | buf = GNUNET_STRINGS_data_to_string_alloc(data, size); | 45 | buf = GNUNET_STRINGS_data_to_string_alloc (data, size); |
46 | json = json_string(buf); | 46 | json = json_string (buf); |
47 | GNUNET_free(buf); | 47 | GNUNET_free (buf); |
48 | return json; | 48 | return json; |
49 | } | 49 | } |
50 | 50 | ||
@@ -56,22 +56,23 @@ GNUNET_JSON_from_data(const void *data, | |||
56 | * @return a json string with the timestamp in @a stamp | 56 | * @return a json string with the timestamp in @a stamp |
57 | */ | 57 | */ |
58 | json_t * | 58 | json_t * |
59 | GNUNET_JSON_from_time_abs(struct GNUNET_TIME_Absolute stamp) | 59 | GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) |
60 | { | 60 | { |
61 | json_t *j; | 61 | json_t *j; |
62 | char *mystr; | 62 | char *mystr; |
63 | int ret; | 63 | int ret; |
64 | 64 | ||
65 | GNUNET_assert(GNUNET_OK == | 65 | GNUNET_assert (GNUNET_OK == |
66 | GNUNET_TIME_round_abs(&stamp)); | 66 | GNUNET_TIME_round_abs (&stamp)); |
67 | if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 67 | if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
68 | return json_string("/never/"); | 68 | return json_string ("/never/"); |
69 | ret = GNUNET_asprintf(&mystr, | 69 | ret = GNUNET_asprintf (&mystr, |
70 | "/Date(%llu)/", | 70 | "/Date(%llu)/", |
71 | (unsigned long long)(stamp.abs_value_us / (1000LL * 1000LL))); | 71 | (unsigned long long) (stamp.abs_value_us / (1000LL |
72 | GNUNET_assert(ret > 0); | 72 | * 1000LL))); |
73 | j = json_string(mystr); | 73 | GNUNET_assert (ret > 0); |
74 | GNUNET_free(mystr); | 74 | j = json_string (mystr); |
75 | GNUNET_free (mystr); | ||
75 | return j; | 76 | return j; |
76 | } | 77 | } |
77 | 78 | ||
@@ -83,9 +84,9 @@ GNUNET_JSON_from_time_abs(struct GNUNET_TIME_Absolute stamp) | |||
83 | * @return a json string with the timestamp in @a stamp | 84 | * @return a json string with the timestamp in @a stamp |
84 | */ | 85 | */ |
85 | json_t * | 86 | json_t * |
86 | GNUNET_JSON_from_time_abs_nbo(struct GNUNET_TIME_AbsoluteNBO stamp) | 87 | GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp) |
87 | { | 88 | { |
88 | return GNUNET_JSON_from_time_abs(GNUNET_TIME_absolute_ntoh(stamp)); | 89 | return GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (stamp)); |
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
@@ -96,22 +97,23 @@ GNUNET_JSON_from_time_abs_nbo(struct GNUNET_TIME_AbsoluteNBO stamp) | |||
96 | * @return a json string with the timestamp in @a stamp | 97 | * @return a json string with the timestamp in @a stamp |
97 | */ | 98 | */ |
98 | json_t * | 99 | json_t * |
99 | GNUNET_JSON_from_time_rel(struct GNUNET_TIME_Relative stamp) | 100 | GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp) |
100 | { | 101 | { |
101 | json_t *j; | 102 | json_t *j; |
102 | char *mystr; | 103 | char *mystr; |
103 | int ret; | 104 | int ret; |
104 | 105 | ||
105 | GNUNET_assert(GNUNET_OK == | 106 | GNUNET_assert (GNUNET_OK == |
106 | GNUNET_TIME_round_rel(&stamp)); | 107 | GNUNET_TIME_round_rel (&stamp)); |
107 | if (stamp.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 108 | if (stamp.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
108 | return json_string("/forever/"); | 109 | return json_string ("/forever/"); |
109 | ret = GNUNET_asprintf(&mystr, | 110 | ret = GNUNET_asprintf (&mystr, |
110 | "/Delay(%llu)/", | 111 | "/Delay(%llu)/", |
111 | (unsigned long long)(stamp.rel_value_us / (1000LL * 1000LL))); | 112 | (unsigned long long) (stamp.rel_value_us / (1000LL |
112 | GNUNET_assert(ret > 0); | 113 | * 1000LL))); |
113 | j = json_string(mystr); | 114 | GNUNET_assert (ret > 0); |
114 | GNUNET_free(mystr); | 115 | j = json_string (mystr); |
116 | GNUNET_free (mystr); | ||
115 | return j; | 117 | return j; |
116 | } | 118 | } |
117 | 119 | ||
@@ -123,17 +125,17 @@ GNUNET_JSON_from_time_rel(struct GNUNET_TIME_Relative stamp) | |||
123 | * @return corresponding JSON encoding | 125 | * @return corresponding JSON encoding |
124 | */ | 126 | */ |
125 | json_t * | 127 | json_t * |
126 | GNUNET_JSON_from_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *pk) | 128 | GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk) |
127 | { | 129 | { |
128 | char *buf; | 130 | char *buf; |
129 | size_t buf_len; | 131 | size_t buf_len; |
130 | json_t *ret; | 132 | json_t *ret; |
131 | 133 | ||
132 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode(pk, | 134 | buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pk, |
133 | &buf); | 135 | &buf); |
134 | ret = GNUNET_JSON_from_data(buf, | 136 | ret = GNUNET_JSON_from_data (buf, |
135 | buf_len); | 137 | buf_len); |
136 | GNUNET_free(buf); | 138 | GNUNET_free (buf); |
137 | return ret; | 139 | return ret; |
138 | } | 140 | } |
139 | 141 | ||
@@ -145,17 +147,17 @@ GNUNET_JSON_from_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *pk) | |||
145 | * @return corresponding JSON encoding | 147 | * @return corresponding JSON encoding |
146 | */ | 148 | */ |
147 | json_t * | 149 | json_t * |
148 | GNUNET_JSON_from_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *sig) | 150 | GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) |
149 | { | 151 | { |
150 | char *buf; | 152 | char *buf; |
151 | size_t buf_len; | 153 | size_t buf_len; |
152 | json_t *ret; | 154 | json_t *ret; |
153 | 155 | ||
154 | buf_len = GNUNET_CRYPTO_rsa_signature_encode(sig, | 156 | buf_len = GNUNET_CRYPTO_rsa_signature_encode (sig, |
155 | &buf); | 157 | &buf); |
156 | ret = GNUNET_JSON_from_data(buf, | 158 | ret = GNUNET_JSON_from_data (buf, |
157 | buf_len); | 159 | buf_len); |
158 | GNUNET_free(buf); | 160 | GNUNET_free (buf); |
159 | return ret; | 161 | return ret; |
160 | } | 162 | } |
161 | 163 | ||
@@ -167,9 +169,9 @@ GNUNET_JSON_from_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *sig) | |||
167 | * @return corresponding JSON encoding | 169 | * @return corresponding JSON encoding |
168 | */ | 170 | */ |
169 | json_t * | 171 | json_t * |
170 | GNUNET_JSON_from_gnsrecord(const char* rname, | 172 | GNUNET_JSON_from_gnsrecord (const char*rname, |
171 | const struct GNUNET_GNSRECORD_Data *rd, | 173 | const struct GNUNET_GNSRECORD_Data *rd, |
172 | unsigned int rd_count) | 174 | unsigned int rd_count) |
173 | { | 175 | { |
174 | struct GNUNET_TIME_Absolute expiration_time; | 176 | struct GNUNET_TIME_Absolute expiration_time; |
175 | const char *expiration_time_str; | 177 | const char *expiration_time_str; |
@@ -179,36 +181,37 @@ GNUNET_JSON_from_gnsrecord(const char* rname, | |||
179 | json_t *record; | 181 | json_t *record; |
180 | json_t *records; | 182 | json_t *records; |
181 | 183 | ||
182 | data = json_object(); | 184 | data = json_object (); |
183 | json_object_set_new(data, | 185 | json_object_set_new (data, |
184 | "record_name", | 186 | "record_name", |
185 | json_string(rname)); | 187 | json_string (rname)); |
186 | records = json_array(); | 188 | records = json_array (); |
187 | for (int i = 0; i < rd_count; i++) | 189 | for (int i = 0; i < rd_count; i++) |
188 | { | 190 | { |
189 | value_str = GNUNET_GNSRECORD_value_to_string(rd[i].record_type, | 191 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
190 | rd[i].data, | 192 | rd[i].data, |
191 | rd[i].data_size); | 193 | rd[i].data_size); |
192 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time(1, &rd[i]); | 194 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time (1, &rd[i]); |
193 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string(expiration_time); | 195 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string ( |
194 | record_type_str = GNUNET_GNSRECORD_number_to_typename(rd[i].record_type); | 196 | expiration_time); |
195 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 197 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
196 | "Packing %s %s %s %d\n", | 198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
197 | value_str, record_type_str, expiration_time_str, rd[i].flags); | 199 | "Packing %s %s %s %d\n", |
198 | record = json_pack("{s:s,s:s,s:s,s:i}", | 200 | value_str, record_type_str, expiration_time_str, rd[i].flags); |
199 | "value", | 201 | record = json_pack ("{s:s,s:s,s:s,s:i}", |
200 | value_str, | 202 | "value", |
201 | "record_type", | 203 | value_str, |
202 | record_type_str, | 204 | "record_type", |
203 | "expiration_time", | 205 | record_type_str, |
204 | expiration_time_str, | 206 | "expiration_time", |
205 | "flag", | 207 | expiration_time_str, |
206 | rd[i].flags); | 208 | "flag", |
207 | GNUNET_assert(NULL != record); | 209 | rd[i].flags); |
208 | GNUNET_free(value_str); | 210 | GNUNET_assert (NULL != record); |
209 | json_array_append_new(records, record); | 211 | GNUNET_free (value_str); |
210 | } | 212 | json_array_append_new (records, record); |
211 | json_object_set_new(data, "data", records); | 213 | } |
214 | json_object_set_new (data, "data", records); | ||
212 | return data; | 215 | return data; |
213 | } | 216 | } |
214 | 217 | ||
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c index 5991683bb..41af2b0a2 100644 --- a/src/json/json_gnsrecord.c +++ b/src/json/json_gnsrecord.c | |||
@@ -35,7 +35,8 @@ | |||
35 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" | 35 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" |
36 | #define GNUNET_JSON_GNSRECORD_NEVER "never" | 36 | #define GNUNET_JSON_GNSRECORD_NEVER "never" |
37 | 37 | ||
38 | struct GnsRecordInfo { | 38 | struct GnsRecordInfo |
39 | { | ||
39 | char **name; | 40 | char **name; |
40 | 41 | ||
41 | unsigned int *rd_count; | 42 | unsigned int *rd_count; |
@@ -45,20 +46,20 @@ struct GnsRecordInfo { | |||
45 | 46 | ||
46 | 47 | ||
47 | static void | 48 | static void |
48 | cleanup_recordinfo(struct GnsRecordInfo *gnsrecord_info) | 49 | cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info) |
49 | { | 50 | { |
50 | if (NULL != *(gnsrecord_info->rd)) | 51 | if (NULL != *(gnsrecord_info->rd)) |
52 | { | ||
53 | for (int i = 0; i < *(gnsrecord_info->rd_count); i++) | ||
51 | { | 54 | { |
52 | for (int i = 0; i < *(gnsrecord_info->rd_count); i++) | 55 | if (NULL != (*(gnsrecord_info->rd))[i].data) |
53 | { | 56 | GNUNET_free ((char *) (*(gnsrecord_info->rd))[i].data); |
54 | if (NULL != (*(gnsrecord_info->rd))[i].data) | ||
55 | GNUNET_free((char *)(*(gnsrecord_info->rd))[i].data); | ||
56 | } | ||
57 | GNUNET_free(*(gnsrecord_info->rd)); | ||
58 | *(gnsrecord_info->rd) = NULL; | ||
59 | } | 57 | } |
58 | GNUNET_free (*(gnsrecord_info->rd)); | ||
59 | *(gnsrecord_info->rd) = NULL; | ||
60 | } | ||
60 | if (NULL != *(gnsrecord_info->name)) | 61 | if (NULL != *(gnsrecord_info->name)) |
61 | GNUNET_free(*(gnsrecord_info->name)); | 62 | GNUNET_free (*(gnsrecord_info->name)); |
62 | *(gnsrecord_info->name) = NULL; | 63 | *(gnsrecord_info->name) = NULL; |
63 | } | 64 | } |
64 | 65 | ||
@@ -72,7 +73,7 @@ cleanup_recordinfo(struct GnsRecordInfo *gnsrecord_info) | |||
72 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 73 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
73 | */ | 74 | */ |
74 | static int | 75 | static int |
75 | parse_record(json_t *data, struct GNUNET_GNSRECORD_Data *rd) | 76 | parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) |
76 | { | 77 | { |
77 | struct GNUNET_TIME_Absolute abs_expiration_time; | 78 | struct GNUNET_TIME_Absolute abs_expiration_time; |
78 | struct GNUNET_TIME_Relative rel_expiration_time; | 79 | struct GNUNET_TIME_Relative rel_expiration_time; |
@@ -82,60 +83,60 @@ parse_record(json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
82 | int flag; | 83 | int flag; |
83 | int unpack_state = 0; | 84 | int unpack_state = 0; |
84 | 85 | ||
85 | //interpret single gns record | 86 | // interpret single gns record |
86 | unpack_state = json_unpack(data, | 87 | unpack_state = json_unpack (data, |
87 | "{s:s, s:s, s:s, s?:i!}", | 88 | "{s:s, s:s, s:s, s?:i!}", |
88 | GNUNET_JSON_GNSRECORD_VALUE, | 89 | GNUNET_JSON_GNSRECORD_VALUE, |
89 | &value, | 90 | &value, |
90 | GNUNET_JSON_GNSRECORD_TYPE, | 91 | GNUNET_JSON_GNSRECORD_TYPE, |
91 | &record_type, | 92 | &record_type, |
92 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, | 93 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, |
93 | &expiration_time, | 94 | &expiration_time, |
94 | GNUNET_JSON_GNSRECORD_FLAG, | 95 | GNUNET_JSON_GNSRECORD_FLAG, |
95 | &flag); | 96 | &flag); |
96 | if (0 != unpack_state) | 97 | if (0 != unpack_state) |
97 | { | 98 | { |
98 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 99 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
99 | "Error gnsdata object has a wrong format!\n"); | 100 | "Error gnsdata object has a wrong format!\n"); |
100 | return GNUNET_SYSERR; | 101 | return GNUNET_SYSERR; |
101 | } | 102 | } |
102 | rd->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); | 103 | rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type); |
103 | if (UINT32_MAX == rd->record_type) | 104 | if (UINT32_MAX == rd->record_type) |
104 | { | 105 | { |
105 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unsupported type\n"); | 106 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unsupported type\n"); |
106 | return GNUNET_SYSERR; | 107 | return GNUNET_SYSERR; |
107 | } | 108 | } |
108 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(rd->record_type, | 109 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (rd->record_type, |
109 | value, | 110 | value, |
110 | (void**)&rd->data, | 111 | (void**) &rd->data, |
111 | &rd->data_size)) | 112 | &rd->data_size)) |
112 | { | 113 | { |
113 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Value invalid for record type\n"); | 114 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Value invalid for record type\n"); |
114 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
115 | } | 116 | } |
116 | 117 | ||
117 | if (0 == strcmp(expiration_time, GNUNET_JSON_GNSRECORD_NEVER)) | 118 | if (0 == strcmp (expiration_time, GNUNET_JSON_GNSRECORD_NEVER)) |
118 | { | 119 | { |
119 | rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 120 | rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
120 | } | 121 | } |
121 | else if (GNUNET_OK == | 122 | else if (GNUNET_OK == |
122 | GNUNET_STRINGS_fancy_time_to_absolute(expiration_time, | 123 | GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, |
123 | &abs_expiration_time)) | 124 | &abs_expiration_time)) |
124 | { | 125 | { |
125 | rd->expiration_time = abs_expiration_time.abs_value_us; | 126 | rd->expiration_time = abs_expiration_time.abs_value_us; |
126 | } | 127 | } |
127 | else if (GNUNET_OK == | 128 | else if (GNUNET_OK == |
128 | GNUNET_STRINGS_fancy_time_to_relative(expiration_time, | 129 | GNUNET_STRINGS_fancy_time_to_relative (expiration_time, |
129 | &rel_expiration_time)) | 130 | &rel_expiration_time)) |
130 | { | 131 | { |
131 | rd->expiration_time = rel_expiration_time.rel_value_us; | 132 | rd->expiration_time = rel_expiration_time.rel_value_us; |
132 | } | 133 | } |
133 | else | 134 | else |
134 | { | 135 | { |
135 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n"); | 136 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n"); |
136 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
137 | } | 138 | } |
138 | rd->flags = (enum GNUNET_GNSRECORD_Flags)flag; | 139 | rd->flags = (enum GNUNET_GNSRECORD_Flags) flag; |
139 | return GNUNET_OK; | 140 | return GNUNET_OK; |
140 | } | 141 | } |
141 | 142 | ||
@@ -149,23 +150,23 @@ parse_record(json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
149 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 150 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
150 | */ | 151 | */ |
151 | static int | 152 | static int |
152 | parse_record_data(struct GnsRecordInfo *gnsrecord_info, json_t *data) | 153 | parse_record_data (struct GnsRecordInfo *gnsrecord_info, json_t *data) |
153 | { | 154 | { |
154 | GNUNET_assert(NULL != data); | 155 | GNUNET_assert (NULL != data); |
155 | if (!json_is_array(data)) | 156 | if (! json_is_array (data)) |
156 | { | 157 | { |
157 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
158 | "Error gns record data JSON is not an array!\n"); | 159 | "Error gns record data JSON is not an array!\n"); |
159 | return GNUNET_SYSERR; | 160 | return GNUNET_SYSERR; |
160 | } | 161 | } |
161 | *(gnsrecord_info->rd_count) = json_array_size(data); | 162 | *(gnsrecord_info->rd_count) = json_array_size (data); |
162 | *(gnsrecord_info->rd) = GNUNET_malloc(sizeof(struct GNUNET_GNSRECORD_Data) * | 163 | *(gnsrecord_info->rd) = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Data) |
163 | json_array_size(data)); | 164 | * json_array_size (data)); |
164 | size_t index; | 165 | size_t index; |
165 | json_t *value; | 166 | json_t *value; |
166 | json_array_foreach(data, index, value) | 167 | json_array_foreach (data, index, value) |
167 | { | 168 | { |
168 | if (GNUNET_OK != parse_record(value, &(*(gnsrecord_info->rd))[index])) | 169 | if (GNUNET_OK != parse_record (value, &(*(gnsrecord_info->rd))[index])) |
169 | return GNUNET_SYSERR; | 170 | return GNUNET_SYSERR; |
170 | } | 171 | } |
171 | return GNUNET_OK; | 172 | return GNUNET_OK; |
@@ -173,42 +174,42 @@ parse_record_data(struct GnsRecordInfo *gnsrecord_info, json_t *data) | |||
173 | 174 | ||
174 | 175 | ||
175 | static int | 176 | static int |
176 | parse_gnsrecordobject(void *cls, | 177 | parse_gnsrecordobject (void *cls, |
177 | json_t *root, | 178 | json_t *root, |
178 | struct GNUNET_JSON_Specification *spec) | 179 | struct GNUNET_JSON_Specification *spec) |
179 | { | 180 | { |
180 | struct GnsRecordInfo *gnsrecord_info; | 181 | struct GnsRecordInfo *gnsrecord_info; |
181 | int unpack_state = 0; | 182 | int unpack_state = 0; |
182 | const char *name; | 183 | const char *name; |
183 | json_t *data; | 184 | json_t *data; |
184 | 185 | ||
185 | GNUNET_assert(NULL != root); | 186 | GNUNET_assert (NULL != root); |
186 | if (!json_is_object(root)) | 187 | if (! json_is_object (root)) |
187 | { | 188 | { |
188 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 189 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
189 | "Error record JSON is not an object!\n"); | 190 | "Error record JSON is not an object!\n"); |
190 | return GNUNET_SYSERR; | 191 | return GNUNET_SYSERR; |
191 | } | 192 | } |
192 | //interpret single gns record | 193 | // interpret single gns record |
193 | unpack_state = json_unpack(root, | 194 | unpack_state = json_unpack (root, |
194 | "{s:s, s:o!}", | 195 | "{s:s, s:o!}", |
195 | GNUNET_JSON_GNSRECORD_RECORD_NAME, | 196 | GNUNET_JSON_GNSRECORD_RECORD_NAME, |
196 | &name, | 197 | &name, |
197 | GNUNET_JSON_GNSRECORD_RECORD_DATA, | 198 | GNUNET_JSON_GNSRECORD_RECORD_DATA, |
198 | &data); | 199 | &data); |
199 | if (0 != unpack_state) | 200 | if (0 != unpack_state) |
200 | { | 201 | { |
201 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
202 | "Error namestore records object has a wrong format!\n"); | 203 | "Error namestore records object has a wrong format!\n"); |
203 | return GNUNET_SYSERR; | 204 | return GNUNET_SYSERR; |
204 | } | 205 | } |
205 | gnsrecord_info = (struct GnsRecordInfo *)spec->ptr; | 206 | gnsrecord_info = (struct GnsRecordInfo *) spec->ptr; |
206 | *(gnsrecord_info->name) = GNUNET_strdup(name); | 207 | *(gnsrecord_info->name) = GNUNET_strdup (name); |
207 | if (GNUNET_OK != parse_record_data(gnsrecord_info, data)) | 208 | if (GNUNET_OK != parse_record_data (gnsrecord_info, data)) |
208 | { | 209 | { |
209 | cleanup_recordinfo(gnsrecord_info); | 210 | cleanup_recordinfo (gnsrecord_info); |
210 | return GNUNET_SYSERR; | 211 | return GNUNET_SYSERR; |
211 | } | 212 | } |
212 | return GNUNET_OK; | 213 | return GNUNET_OK; |
213 | } | 214 | } |
214 | 215 | ||
@@ -220,11 +221,11 @@ parse_gnsrecordobject(void *cls, | |||
220 | * @param[out] spec where to free the data | 221 | * @param[out] spec where to free the data |
221 | */ | 222 | */ |
222 | static void | 223 | static void |
223 | clean_gnsrecordobject(void *cls, struct GNUNET_JSON_Specification *spec) | 224 | clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec) |
224 | { | 225 | { |
225 | struct GnsRecordInfo *gnsrecord_info = (struct GnsRecordInfo *)spec->ptr; | 226 | struct GnsRecordInfo *gnsrecord_info = (struct GnsRecordInfo *) spec->ptr; |
226 | 227 | ||
227 | GNUNET_free(gnsrecord_info); | 228 | GNUNET_free (gnsrecord_info); |
228 | } | 229 | } |
229 | 230 | ||
230 | 231 | ||
@@ -235,11 +236,11 @@ clean_gnsrecordobject(void *cls, struct GNUNET_JSON_Specification *spec) | |||
235 | * @return JSON Specification | 236 | * @return JSON Specification |
236 | */ | 237 | */ |
237 | struct GNUNET_JSON_Specification | 238 | struct GNUNET_JSON_Specification |
238 | GNUNET_JSON_spec_gnsrecord(struct GNUNET_GNSRECORD_Data **rd, | 239 | GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, |
239 | unsigned int *rd_count, | 240 | unsigned int *rd_count, |
240 | char **name) | 241 | char **name) |
241 | { | 242 | { |
242 | struct GnsRecordInfo *gnsrecord_info = GNUNET_new(struct GnsRecordInfo); | 243 | struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo); |
243 | 244 | ||
244 | gnsrecord_info->rd = rd; | 245 | gnsrecord_info->rd = rd; |
245 | gnsrecord_info->name = name; | 246 | gnsrecord_info->name = name; |
diff --git a/src/json/json_helper.c b/src/json/json_helper.c index a732219c1..c3ba9c555 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c | |||
@@ -32,7 +32,7 @@ | |||
32 | * End of a parser specification. | 32 | * End of a parser specification. |
33 | */ | 33 | */ |
34 | struct GNUNET_JSON_Specification | 34 | struct GNUNET_JSON_Specification |
35 | GNUNET_JSON_spec_end() | 35 | GNUNET_JSON_spec_end () |
36 | { | 36 | { |
37 | struct GNUNET_JSON_Specification ret = { | 37 | struct GNUNET_JSON_Specification ret = { |
38 | .parser = NULL, | 38 | .parser = NULL, |
@@ -53,33 +53,33 @@ GNUNET_JSON_spec_end() | |||
53 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 53 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
54 | */ | 54 | */ |
55 | static int | 55 | static int |
56 | parse_fixed_data(void *cls, | 56 | parse_fixed_data (void *cls, |
57 | json_t *root, | 57 | json_t *root, |
58 | struct GNUNET_JSON_Specification *spec) | 58 | struct GNUNET_JSON_Specification *spec) |
59 | { | 59 | { |
60 | const char *enc; | 60 | const char *enc; |
61 | unsigned int len; | 61 | unsigned int len; |
62 | 62 | ||
63 | if (NULL == (enc = json_string_value(root))) | 63 | if (NULL == (enc = json_string_value (root))) |
64 | { | 64 | { |
65 | GNUNET_break_op(0); | 65 | GNUNET_break_op (0); |
66 | return GNUNET_SYSERR; | 66 | return GNUNET_SYSERR; |
67 | } | 67 | } |
68 | len = strlen(enc); | 68 | len = strlen (enc); |
69 | if (((len * 5) / 8) != spec->ptr_size) | 69 | if (((len * 5) / 8) != spec->ptr_size) |
70 | { | 70 | { |
71 | GNUNET_break_op(0); | 71 | GNUNET_break_op (0); |
72 | return GNUNET_SYSERR; | 72 | return GNUNET_SYSERR; |
73 | } | 73 | } |
74 | if (GNUNET_OK != | 74 | if (GNUNET_OK != |
75 | GNUNET_STRINGS_string_to_data(enc, | 75 | GNUNET_STRINGS_string_to_data (enc, |
76 | len, | 76 | len, |
77 | spec->ptr, | 77 | spec->ptr, |
78 | spec->ptr_size)) | 78 | spec->ptr_size)) |
79 | { | 79 | { |
80 | GNUNET_break_op(0); | 80 | GNUNET_break_op (0); |
81 | return GNUNET_SYSERR; | 81 | return GNUNET_SYSERR; |
82 | } | 82 | } |
83 | return GNUNET_OK; | 83 | return GNUNET_OK; |
84 | } | 84 | } |
85 | 85 | ||
@@ -93,9 +93,9 @@ parse_fixed_data(void *cls, | |||
93 | * @param size number of bytes expected in @a obj | 93 | * @param size number of bytes expected in @a obj |
94 | */ | 94 | */ |
95 | struct GNUNET_JSON_Specification | 95 | struct GNUNET_JSON_Specification |
96 | GNUNET_JSON_spec_fixed(const char *name, | 96 | GNUNET_JSON_spec_fixed (const char *name, |
97 | void *obj, | 97 | void *obj, |
98 | size_t size) | 98 | size_t size) |
99 | { | 99 | { |
100 | struct GNUNET_JSON_Specification ret = { | 100 | struct GNUNET_JSON_Specification ret = { |
101 | .parser = &parse_fixed_data, | 101 | .parser = &parse_fixed_data, |
@@ -120,39 +120,39 @@ GNUNET_JSON_spec_fixed(const char *name, | |||
120 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 120 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
121 | */ | 121 | */ |
122 | static int | 122 | static int |
123 | parse_variable_data(void *cls, | 123 | parse_variable_data (void *cls, |
124 | json_t *root, | 124 | json_t *root, |
125 | struct GNUNET_JSON_Specification *spec) | 125 | struct GNUNET_JSON_Specification *spec) |
126 | { | 126 | { |
127 | const char *str; | 127 | const char *str; |
128 | size_t size; | 128 | size_t size; |
129 | void *data; | 129 | void *data; |
130 | int res; | 130 | int res; |
131 | 131 | ||
132 | str = json_string_value(root); | 132 | str = json_string_value (root); |
133 | if (NULL == str) | 133 | if (NULL == str) |
134 | { | 134 | { |
135 | GNUNET_break_op(0); | 135 | GNUNET_break_op (0); |
136 | return GNUNET_SYSERR; | 136 | return GNUNET_SYSERR; |
137 | } | 137 | } |
138 | size = (strlen(str) * 5) / 8; | 138 | size = (strlen (str) * 5) / 8; |
139 | if (size >= 1024) | 139 | if (size >= 1024) |
140 | { | 140 | { |
141 | GNUNET_break_op(0); | 141 | GNUNET_break_op (0); |
142 | return GNUNET_SYSERR; | 142 | return GNUNET_SYSERR; |
143 | } | 143 | } |
144 | data = GNUNET_malloc(size); | 144 | data = GNUNET_malloc (size); |
145 | res = GNUNET_STRINGS_string_to_data(str, | 145 | res = GNUNET_STRINGS_string_to_data (str, |
146 | strlen(str), | 146 | strlen (str), |
147 | data, | 147 | data, |
148 | size); | 148 | size); |
149 | if (GNUNET_OK != res) | 149 | if (GNUNET_OK != res) |
150 | { | 150 | { |
151 | GNUNET_break_op(0); | 151 | GNUNET_break_op (0); |
152 | GNUNET_free(data); | 152 | GNUNET_free (data); |
153 | return GNUNET_SYSERR; | 153 | return GNUNET_SYSERR; |
154 | } | 154 | } |
155 | *(void**)spec->ptr = data; | 155 | *(void**) spec->ptr = data; |
156 | *spec->size_ptr = size; | 156 | *spec->size_ptr = size; |
157 | return GNUNET_OK; | 157 | return GNUNET_OK; |
158 | } | 158 | } |
@@ -165,15 +165,15 @@ parse_variable_data(void *cls, | |||
165 | * @param[out] spec where to free the data | 165 | * @param[out] spec where to free the data |
166 | */ | 166 | */ |
167 | static void | 167 | static void |
168 | clean_variable_data(void *cls, | 168 | clean_variable_data (void *cls, |
169 | struct GNUNET_JSON_Specification *spec) | 169 | struct GNUNET_JSON_Specification *spec) |
170 | { | 170 | { |
171 | if (0 != *spec->size_ptr) | 171 | if (0 != *spec->size_ptr) |
172 | { | 172 | { |
173 | GNUNET_free(*(void **)spec->ptr); | 173 | GNUNET_free (*(void **) spec->ptr); |
174 | *(void**)spec->ptr = NULL; | 174 | *(void**) spec->ptr = NULL; |
175 | *spec->size_ptr = 0; | 175 | *spec->size_ptr = 0; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
@@ -186,9 +186,9 @@ clean_variable_data(void *cls, | |||
186 | * @param[out] size where to store the number of bytes allocated for @a obj | 186 | * @param[out] size where to store the number of bytes allocated for @a obj |
187 | */ | 187 | */ |
188 | struct GNUNET_JSON_Specification | 188 | struct GNUNET_JSON_Specification |
189 | GNUNET_JSON_spec_varsize(const char *name, | 189 | GNUNET_JSON_spec_varsize (const char *name, |
190 | void **obj, | 190 | void **obj, |
191 | size_t *size) | 191 | size_t *size) |
192 | { | 192 | { |
193 | struct GNUNET_JSON_Specification ret = { | 193 | struct GNUNET_JSON_Specification ret = { |
194 | .parser = &parse_variable_data, | 194 | .parser = &parse_variable_data, |
@@ -215,19 +215,19 @@ GNUNET_JSON_spec_varsize(const char *name, | |||
215 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 215 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
216 | */ | 216 | */ |
217 | static int | 217 | static int |
218 | parse_string(void *cls, | 218 | parse_string (void *cls, |
219 | json_t *root, | 219 | json_t *root, |
220 | struct GNUNET_JSON_Specification *spec) | 220 | struct GNUNET_JSON_Specification *spec) |
221 | { | 221 | { |
222 | const char *str; | 222 | const char *str; |
223 | 223 | ||
224 | str = json_string_value(root); | 224 | str = json_string_value (root); |
225 | if (NULL == str) | 225 | if (NULL == str) |
226 | { | 226 | { |
227 | GNUNET_break_op(0); | 227 | GNUNET_break_op (0); |
228 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
229 | } | 229 | } |
230 | *(const char **)spec->ptr = str; | 230 | *(const char **) spec->ptr = str; |
231 | return GNUNET_OK; | 231 | return GNUNET_OK; |
232 | } | 232 | } |
233 | 233 | ||
@@ -239,8 +239,8 @@ parse_string(void *cls, | |||
239 | * @param strptr where to store a pointer to the field | 239 | * @param strptr where to store a pointer to the field |
240 | */ | 240 | */ |
241 | struct GNUNET_JSON_Specification | 241 | struct GNUNET_JSON_Specification |
242 | GNUNET_JSON_spec_string(const char *name, | 242 | GNUNET_JSON_spec_string (const char *name, |
243 | const char **strptr) | 243 | const char **strptr) |
244 | { | 244 | { |
245 | struct GNUNET_JSON_Specification ret = { | 245 | struct GNUNET_JSON_Specification ret = { |
246 | .parser = &parse_string, | 246 | .parser = &parse_string, |
@@ -266,17 +266,17 @@ GNUNET_JSON_spec_string(const char *name, | |||
266 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 266 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
267 | */ | 267 | */ |
268 | static int | 268 | static int |
269 | parse_object(void *cls, | 269 | parse_object (void *cls, |
270 | json_t *root, | 270 | json_t *root, |
271 | struct GNUNET_JSON_Specification *spec) | 271 | struct GNUNET_JSON_Specification *spec) |
272 | { | 272 | { |
273 | if (!(json_is_object(root) || json_is_array(root))) | 273 | if (! (json_is_object (root) || json_is_array (root))) |
274 | { | 274 | { |
275 | GNUNET_break_op(0); | 275 | GNUNET_break_op (0); |
276 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
277 | } | 277 | } |
278 | json_incref(root); | 278 | json_incref (root); |
279 | *(json_t **)spec->ptr = root; | 279 | *(json_t **) spec->ptr = root; |
280 | return GNUNET_OK; | 280 | return GNUNET_OK; |
281 | } | 281 | } |
282 | 282 | ||
@@ -288,16 +288,16 @@ parse_object(void *cls, | |||
288 | * @param[out] spec where to free the data | 288 | * @param[out] spec where to free the data |
289 | */ | 289 | */ |
290 | static void | 290 | static void |
291 | clean_object(void *cls, | 291 | clean_object (void *cls, |
292 | struct GNUNET_JSON_Specification *spec) | 292 | struct GNUNET_JSON_Specification *spec) |
293 | { | 293 | { |
294 | json_t **ptr = (json_t **)spec->ptr; | 294 | json_t **ptr = (json_t **) spec->ptr; |
295 | 295 | ||
296 | if (NULL != *ptr) | 296 | if (NULL != *ptr) |
297 | { | 297 | { |
298 | json_decref(*ptr); | 298 | json_decref (*ptr); |
299 | *ptr = NULL; | 299 | *ptr = NULL; |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
@@ -308,8 +308,8 @@ clean_object(void *cls, | |||
308 | * @param[out] jsonp where to store the JSON found under @a name | 308 | * @param[out] jsonp where to store the JSON found under @a name |
309 | */ | 309 | */ |
310 | struct GNUNET_JSON_Specification | 310 | struct GNUNET_JSON_Specification |
311 | GNUNET_JSON_spec_json(const char *name, | 311 | GNUNET_JSON_spec_json (const char *name, |
312 | json_t **jsonp) | 312 | json_t **jsonp) |
313 | { | 313 | { |
314 | struct GNUNET_JSON_Specification ret = { | 314 | struct GNUNET_JSON_Specification ret = { |
315 | .parser = &parse_object, | 315 | .parser = &parse_object, |
@@ -335,25 +335,25 @@ GNUNET_JSON_spec_json(const char *name, | |||
335 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 335 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
336 | */ | 336 | */ |
337 | static int | 337 | static int |
338 | parse_u8(void *cls, | 338 | parse_u8 (void *cls, |
339 | json_t *root, | 339 | json_t *root, |
340 | struct GNUNET_JSON_Specification *spec) | 340 | struct GNUNET_JSON_Specification *spec) |
341 | { | 341 | { |
342 | json_int_t val; | 342 | json_int_t val; |
343 | uint8_t *up = spec->ptr; | 343 | uint8_t *up = spec->ptr; |
344 | 344 | ||
345 | if (!json_is_integer(root)) | 345 | if (! json_is_integer (root)) |
346 | { | 346 | { |
347 | GNUNET_break_op(0); | 347 | GNUNET_break_op (0); |
348 | return GNUNET_SYSERR; | 348 | return GNUNET_SYSERR; |
349 | } | 349 | } |
350 | val = json_integer_value(root); | 350 | val = json_integer_value (root); |
351 | if ((0 > val) || (val > UINT8_MAX)) | 351 | if ((0 > val) || (val > UINT8_MAX)) |
352 | { | 352 | { |
353 | GNUNET_break_op(0); | 353 | GNUNET_break_op (0); |
354 | return GNUNET_SYSERR; | 354 | return GNUNET_SYSERR; |
355 | } | 355 | } |
356 | *up = (uint8_t)val; | 356 | *up = (uint8_t) val; |
357 | return GNUNET_OK; | 357 | return GNUNET_OK; |
358 | } | 358 | } |
359 | 359 | ||
@@ -365,8 +365,8 @@ parse_u8(void *cls, | |||
365 | * @param[out] u8 where to store the integer found under @a name | 365 | * @param[out] u8 where to store the integer found under @a name |
366 | */ | 366 | */ |
367 | struct GNUNET_JSON_Specification | 367 | struct GNUNET_JSON_Specification |
368 | GNUNET_JSON_spec_uint8(const char *name, | 368 | GNUNET_JSON_spec_uint8 (const char *name, |
369 | uint8_t *u8) | 369 | uint8_t *u8) |
370 | { | 370 | { |
371 | struct GNUNET_JSON_Specification ret = { | 371 | struct GNUNET_JSON_Specification ret = { |
372 | .parser = &parse_u8, | 372 | .parser = &parse_u8, |
@@ -391,25 +391,25 @@ GNUNET_JSON_spec_uint8(const char *name, | |||
391 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 391 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
392 | */ | 392 | */ |
393 | static int | 393 | static int |
394 | parse_u16(void *cls, | 394 | parse_u16 (void *cls, |
395 | json_t *root, | 395 | json_t *root, |
396 | struct GNUNET_JSON_Specification *spec) | 396 | struct GNUNET_JSON_Specification *spec) |
397 | { | 397 | { |
398 | json_int_t val; | 398 | json_int_t val; |
399 | uint16_t *up = spec->ptr; | 399 | uint16_t *up = spec->ptr; |
400 | 400 | ||
401 | if (!json_is_integer(root)) | 401 | if (! json_is_integer (root)) |
402 | { | 402 | { |
403 | GNUNET_break_op(0); | 403 | GNUNET_break_op (0); |
404 | return GNUNET_SYSERR; | 404 | return GNUNET_SYSERR; |
405 | } | 405 | } |
406 | val = json_integer_value(root); | 406 | val = json_integer_value (root); |
407 | if ((0 > val) || (val > UINT16_MAX)) | 407 | if ((0 > val) || (val > UINT16_MAX)) |
408 | { | 408 | { |
409 | GNUNET_break_op(0); | 409 | GNUNET_break_op (0); |
410 | return GNUNET_SYSERR; | 410 | return GNUNET_SYSERR; |
411 | } | 411 | } |
412 | *up = (uint16_t)val; | 412 | *up = (uint16_t) val; |
413 | return GNUNET_OK; | 413 | return GNUNET_OK; |
414 | } | 414 | } |
415 | 415 | ||
@@ -421,8 +421,8 @@ parse_u16(void *cls, | |||
421 | * @param[out] u16 where to store the integer found under @a name | 421 | * @param[out] u16 where to store the integer found under @a name |
422 | */ | 422 | */ |
423 | struct GNUNET_JSON_Specification | 423 | struct GNUNET_JSON_Specification |
424 | GNUNET_JSON_spec_uint16(const char *name, | 424 | GNUNET_JSON_spec_uint16 (const char *name, |
425 | uint16_t *u16) | 425 | uint16_t *u16) |
426 | { | 426 | { |
427 | struct GNUNET_JSON_Specification ret = { | 427 | struct GNUNET_JSON_Specification ret = { |
428 | .parser = &parse_u16, | 428 | .parser = &parse_u16, |
@@ -447,25 +447,25 @@ GNUNET_JSON_spec_uint16(const char *name, | |||
447 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 447 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
448 | */ | 448 | */ |
449 | static int | 449 | static int |
450 | parse_u32(void *cls, | 450 | parse_u32 (void *cls, |
451 | json_t *root, | 451 | json_t *root, |
452 | struct GNUNET_JSON_Specification *spec) | 452 | struct GNUNET_JSON_Specification *spec) |
453 | { | 453 | { |
454 | json_int_t val; | 454 | json_int_t val; |
455 | uint32_t *up = spec->ptr; | 455 | uint32_t *up = spec->ptr; |
456 | 456 | ||
457 | if (!json_is_integer(root)) | 457 | if (! json_is_integer (root)) |
458 | { | 458 | { |
459 | GNUNET_break_op(0); | 459 | GNUNET_break_op (0); |
460 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
461 | } | 461 | } |
462 | val = json_integer_value(root); | 462 | val = json_integer_value (root); |
463 | if ((0 > val) || (val > UINT32_MAX)) | 463 | if ((0 > val) || (val > UINT32_MAX)) |
464 | { | 464 | { |
465 | GNUNET_break_op(0); | 465 | GNUNET_break_op (0); |
466 | return GNUNET_SYSERR; | 466 | return GNUNET_SYSERR; |
467 | } | 467 | } |
468 | *up = (uint32_t)val; | 468 | *up = (uint32_t) val; |
469 | return GNUNET_OK; | 469 | return GNUNET_OK; |
470 | } | 470 | } |
471 | 471 | ||
@@ -477,8 +477,8 @@ parse_u32(void *cls, | |||
477 | * @param[out] u32 where to store the integer found under @a name | 477 | * @param[out] u32 where to store the integer found under @a name |
478 | */ | 478 | */ |
479 | struct GNUNET_JSON_Specification | 479 | struct GNUNET_JSON_Specification |
480 | GNUNET_JSON_spec_uint32(const char *name, | 480 | GNUNET_JSON_spec_uint32 (const char *name, |
481 | uint32_t *u32) | 481 | uint32_t *u32) |
482 | { | 482 | { |
483 | struct GNUNET_JSON_Specification ret = { | 483 | struct GNUNET_JSON_Specification ret = { |
484 | .parser = &parse_u32, | 484 | .parser = &parse_u32, |
@@ -503,20 +503,20 @@ GNUNET_JSON_spec_uint32(const char *name, | |||
503 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 503 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
504 | */ | 504 | */ |
505 | static int | 505 | static int |
506 | parse_u64(void *cls, | 506 | parse_u64 (void *cls, |
507 | json_t *root, | 507 | json_t *root, |
508 | struct GNUNET_JSON_Specification *spec) | 508 | struct GNUNET_JSON_Specification *spec) |
509 | { | 509 | { |
510 | json_int_t val; | 510 | json_int_t val; |
511 | uint64_t *up = spec->ptr; | 511 | uint64_t *up = spec->ptr; |
512 | 512 | ||
513 | if (!json_is_integer(root)) | 513 | if (! json_is_integer (root)) |
514 | { | 514 | { |
515 | GNUNET_break_op(0); | 515 | GNUNET_break_op (0); |
516 | return GNUNET_SYSERR; | 516 | return GNUNET_SYSERR; |
517 | } | 517 | } |
518 | val = json_integer_value(root); | 518 | val = json_integer_value (root); |
519 | *up = (uint64_t)val; | 519 | *up = (uint64_t) val; |
520 | return GNUNET_OK; | 520 | return GNUNET_OK; |
521 | } | 521 | } |
522 | 522 | ||
@@ -528,8 +528,8 @@ parse_u64(void *cls, | |||
528 | * @param[out] u64 where to store the integer found under @a name | 528 | * @param[out] u64 where to store the integer found under @a name |
529 | */ | 529 | */ |
530 | struct GNUNET_JSON_Specification | 530 | struct GNUNET_JSON_Specification |
531 | GNUNET_JSON_spec_uint64(const char *name, | 531 | GNUNET_JSON_spec_uint64 (const char *name, |
532 | uint64_t *u64) | 532 | uint64_t *u64) |
533 | { | 533 | { |
534 | struct GNUNET_JSON_Specification ret = { | 534 | struct GNUNET_JSON_Specification ret = { |
535 | .parser = &parse_u64, | 535 | .parser = &parse_u64, |
@@ -556,45 +556,45 @@ GNUNET_JSON_spec_uint64(const char *name, | |||
556 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 556 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
557 | */ | 557 | */ |
558 | static int | 558 | static int |
559 | parse_abs_time(void *cls, | 559 | parse_abs_time (void *cls, |
560 | json_t *root, | 560 | json_t *root, |
561 | struct GNUNET_JSON_Specification *spec) | 561 | struct GNUNET_JSON_Specification *spec) |
562 | { | 562 | { |
563 | struct GNUNET_TIME_Absolute *abs = spec->ptr; | 563 | struct GNUNET_TIME_Absolute *abs = spec->ptr; |
564 | const char *val; | 564 | const char *val; |
565 | unsigned long long int tval; | 565 | unsigned long long int tval; |
566 | 566 | ||
567 | val = json_string_value(root); | 567 | val = json_string_value (root); |
568 | if (NULL == val) | 568 | if (NULL == val) |
569 | { | 569 | { |
570 | GNUNET_break_op(0); | 570 | GNUNET_break_op (0); |
571 | return GNUNET_SYSERR; | 571 | return GNUNET_SYSERR; |
572 | } | 572 | } |
573 | if ((0 == strcasecmp(val, | 573 | if ((0 == strcasecmp (val, |
574 | "/forever/")) || | 574 | "/forever/")) || |
575 | (0 == strcasecmp(val, | 575 | (0 == strcasecmp (val, |
576 | "/end of time/")) || | 576 | "/end of time/")) || |
577 | (0 == strcasecmp(val, | 577 | (0 == strcasecmp (val, |
578 | "/never/"))) | 578 | "/never/"))) |
579 | { | 579 | { |
580 | *abs = GNUNET_TIME_UNIT_FOREVER_ABS; | 580 | *abs = GNUNET_TIME_UNIT_FOREVER_ABS; |
581 | return GNUNET_OK; | 581 | return GNUNET_OK; |
582 | } | 582 | } |
583 | if (1 != sscanf(val, | 583 | if (1 != sscanf (val, |
584 | "/Date(%llu)/", | 584 | "/Date(%llu)/", |
585 | &tval)) | 585 | &tval)) |
586 | { | 586 | { |
587 | GNUNET_break_op(0); | 587 | GNUNET_break_op (0); |
588 | return GNUNET_SYSERR; | 588 | return GNUNET_SYSERR; |
589 | } | 589 | } |
590 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ | 590 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ |
591 | abs->abs_value_us = tval * 1000LL * 1000LL; | 591 | abs->abs_value_us = tval * 1000LL * 1000LL; |
592 | if ((abs->abs_value_us) / 1000LL / 1000LL != tval) | 592 | if ((abs->abs_value_us) / 1000LL / 1000LL != tval) |
593 | { | 593 | { |
594 | /* Integer overflow */ | 594 | /* Integer overflow */ |
595 | GNUNET_break_op(0); | 595 | GNUNET_break_op (0); |
596 | return GNUNET_SYSERR; | 596 | return GNUNET_SYSERR; |
597 | } | 597 | } |
598 | return GNUNET_OK; | 598 | return GNUNET_OK; |
599 | } | 599 | } |
600 | 600 | ||
@@ -606,8 +606,8 @@ parse_abs_time(void *cls, | |||
606 | * @param[out] at where to store the absolute time found under @a name | 606 | * @param[out] at where to store the absolute time found under @a name |
607 | */ | 607 | */ |
608 | struct GNUNET_JSON_Specification | 608 | struct GNUNET_JSON_Specification |
609 | GNUNET_JSON_spec_absolute_time(const char *name, | 609 | GNUNET_JSON_spec_absolute_time (const char *name, |
610 | struct GNUNET_TIME_Absolute *at) | 610 | struct GNUNET_TIME_Absolute *at) |
611 | { | 611 | { |
612 | struct GNUNET_JSON_Specification ret = { | 612 | struct GNUNET_JSON_Specification ret = { |
613 | .parser = &parse_abs_time, | 613 | .parser = &parse_abs_time, |
@@ -632,47 +632,47 @@ GNUNET_JSON_spec_absolute_time(const char *name, | |||
632 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 632 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
633 | */ | 633 | */ |
634 | static int | 634 | static int |
635 | parse_abs_time_nbo(void *cls, | 635 | parse_abs_time_nbo (void *cls, |
636 | json_t *root, | 636 | json_t *root, |
637 | struct GNUNET_JSON_Specification *spec) | 637 | struct GNUNET_JSON_Specification *spec) |
638 | { | 638 | { |
639 | struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr; | 639 | struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr; |
640 | const char *val; | 640 | const char *val; |
641 | unsigned long long int tval; | 641 | unsigned long long int tval; |
642 | struct GNUNET_TIME_Absolute a; | 642 | struct GNUNET_TIME_Absolute a; |
643 | 643 | ||
644 | val = json_string_value(root); | 644 | val = json_string_value (root); |
645 | if (NULL == val) | 645 | if (NULL == val) |
646 | { | 646 | { |
647 | GNUNET_break_op(0); | 647 | GNUNET_break_op (0); |
648 | return GNUNET_SYSERR; | 648 | return GNUNET_SYSERR; |
649 | } | 649 | } |
650 | if ((0 == strcasecmp(val, | 650 | if ((0 == strcasecmp (val, |
651 | "/forever/")) || | 651 | "/forever/")) || |
652 | (0 == strcasecmp(val, | 652 | (0 == strcasecmp (val, |
653 | "/end of time/")) || | 653 | "/end of time/")) || |
654 | (0 == strcasecmp(val, | 654 | (0 == strcasecmp (val, |
655 | "/never/"))) | 655 | "/never/"))) |
656 | { | 656 | { |
657 | *abs = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS); | 657 | *abs = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); |
658 | return GNUNET_OK; | 658 | return GNUNET_OK; |
659 | } | 659 | } |
660 | if (1 != sscanf(val, | 660 | if (1 != sscanf (val, |
661 | "/Date(%llu)/", | 661 | "/Date(%llu)/", |
662 | &tval)) | 662 | &tval)) |
663 | { | 663 | { |
664 | GNUNET_break_op(0); | 664 | GNUNET_break_op (0); |
665 | return GNUNET_SYSERR; | 665 | return GNUNET_SYSERR; |
666 | } | 666 | } |
667 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ | 667 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ |
668 | a.abs_value_us = tval * 1000LL * 1000LL; | 668 | a.abs_value_us = tval * 1000LL * 1000LL; |
669 | if ((a.abs_value_us) / 1000LL / 1000LL != tval) | 669 | if ((a.abs_value_us) / 1000LL / 1000LL != tval) |
670 | { | 670 | { |
671 | /* Integer overflow */ | 671 | /* Integer overflow */ |
672 | GNUNET_break_op(0); | 672 | GNUNET_break_op (0); |
673 | return GNUNET_SYSERR; | 673 | return GNUNET_SYSERR; |
674 | } | 674 | } |
675 | *abs = GNUNET_TIME_absolute_hton(a); | 675 | *abs = GNUNET_TIME_absolute_hton (a); |
676 | return GNUNET_OK; | 676 | return GNUNET_OK; |
677 | } | 677 | } |
678 | 678 | ||
@@ -684,8 +684,8 @@ parse_abs_time_nbo(void *cls, | |||
684 | * @param[out] at where to store the absolute time found under @a name | 684 | * @param[out] at where to store the absolute time found under @a name |
685 | */ | 685 | */ |
686 | struct GNUNET_JSON_Specification | 686 | struct GNUNET_JSON_Specification |
687 | GNUNET_JSON_spec_absolute_time_nbo(const char *name, | 687 | GNUNET_JSON_spec_absolute_time_nbo (const char *name, |
688 | struct GNUNET_TIME_AbsoluteNBO *at) | 688 | struct GNUNET_TIME_AbsoluteNBO *at) |
689 | { | 689 | { |
690 | struct GNUNET_JSON_Specification ret = { | 690 | struct GNUNET_JSON_Specification ret = { |
691 | .parser = &parse_abs_time_nbo, | 691 | .parser = &parse_abs_time_nbo, |
@@ -710,41 +710,41 @@ GNUNET_JSON_spec_absolute_time_nbo(const char *name, | |||
710 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 710 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
711 | */ | 711 | */ |
712 | static int | 712 | static int |
713 | parse_rel_time(void *cls, | 713 | parse_rel_time (void *cls, |
714 | json_t *root, | 714 | json_t *root, |
715 | struct GNUNET_JSON_Specification *spec) | 715 | struct GNUNET_JSON_Specification *spec) |
716 | { | 716 | { |
717 | struct GNUNET_TIME_Relative *rel = spec->ptr; | 717 | struct GNUNET_TIME_Relative *rel = spec->ptr; |
718 | const char *val; | 718 | const char *val; |
719 | unsigned long long int tval; | 719 | unsigned long long int tval; |
720 | 720 | ||
721 | val = json_string_value(root); | 721 | val = json_string_value (root); |
722 | if (NULL == val) | 722 | if (NULL == val) |
723 | { | 723 | { |
724 | GNUNET_break_op(0); | 724 | GNUNET_break_op (0); |
725 | return GNUNET_SYSERR; | 725 | return GNUNET_SYSERR; |
726 | } | 726 | } |
727 | if ((0 == strcasecmp(val, | 727 | if ((0 == strcasecmp (val, |
728 | "/forever/"))) | 728 | "/forever/"))) |
729 | { | 729 | { |
730 | *rel = GNUNET_TIME_UNIT_FOREVER_REL; | 730 | *rel = GNUNET_TIME_UNIT_FOREVER_REL; |
731 | return GNUNET_OK; | 731 | return GNUNET_OK; |
732 | } | 732 | } |
733 | if (1 != sscanf(val, | 733 | if (1 != sscanf (val, |
734 | "/Delay(%llu)/", | 734 | "/Delay(%llu)/", |
735 | &tval)) | 735 | &tval)) |
736 | { | 736 | { |
737 | GNUNET_break_op(0); | 737 | GNUNET_break_op (0); |
738 | return GNUNET_SYSERR; | 738 | return GNUNET_SYSERR; |
739 | } | 739 | } |
740 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */ | 740 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */ |
741 | rel->rel_value_us = tval * 1000LL * 1000LL; | 741 | rel->rel_value_us = tval * 1000LL * 1000LL; |
742 | if ((rel->rel_value_us) / 1000LL / 1000LL != tval) | 742 | if ((rel->rel_value_us) / 1000LL / 1000LL != tval) |
743 | { | 743 | { |
744 | /* Integer overflow */ | 744 | /* Integer overflow */ |
745 | GNUNET_break_op(0); | 745 | GNUNET_break_op (0); |
746 | return GNUNET_SYSERR; | 746 | return GNUNET_SYSERR; |
747 | } | 747 | } |
748 | return GNUNET_OK; | 748 | return GNUNET_OK; |
749 | } | 749 | } |
750 | 750 | ||
@@ -756,8 +756,8 @@ parse_rel_time(void *cls, | |||
756 | * @param[out] rt where to store the relative time found under @a name | 756 | * @param[out] rt where to store the relative time found under @a name |
757 | */ | 757 | */ |
758 | struct GNUNET_JSON_Specification | 758 | struct GNUNET_JSON_Specification |
759 | GNUNET_JSON_spec_relative_time(const char *name, | 759 | GNUNET_JSON_spec_relative_time (const char *name, |
760 | struct GNUNET_TIME_Relative *rt) | 760 | struct GNUNET_TIME_Relative *rt) |
761 | { | 761 | { |
762 | struct GNUNET_JSON_Specification ret = { | 762 | struct GNUNET_JSON_Specification ret = { |
763 | .parser = &parse_rel_time, | 763 | .parser = &parse_rel_time, |
@@ -782,9 +782,9 @@ GNUNET_JSON_spec_relative_time(const char *name, | |||
782 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 782 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
783 | */ | 783 | */ |
784 | static int | 784 | static int |
785 | parse_rsa_public_key(void *cls, | 785 | parse_rsa_public_key (void *cls, |
786 | json_t *root, | 786 | json_t *root, |
787 | struct GNUNET_JSON_Specification *spec) | 787 | struct GNUNET_JSON_Specification *spec) |
788 | { | 788 | { |
789 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; | 789 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; |
790 | const char *enc; | 790 | const char *enc; |
@@ -792,32 +792,32 @@ parse_rsa_public_key(void *cls, | |||
792 | size_t len; | 792 | size_t len; |
793 | size_t buf_len; | 793 | size_t buf_len; |
794 | 794 | ||
795 | if (NULL == (enc = json_string_value(root))) | 795 | if (NULL == (enc = json_string_value (root))) |
796 | { | 796 | { |
797 | GNUNET_break_op(0); | 797 | GNUNET_break_op (0); |
798 | return GNUNET_SYSERR; | 798 | return GNUNET_SYSERR; |
799 | } | 799 | } |
800 | len = strlen(enc); | 800 | len = strlen (enc); |
801 | buf_len = (len * 5) / 8; | 801 | buf_len = (len * 5) / 8; |
802 | buf = GNUNET_malloc(buf_len); | 802 | buf = GNUNET_malloc (buf_len); |
803 | if (GNUNET_OK != | 803 | if (GNUNET_OK != |
804 | GNUNET_STRINGS_string_to_data(enc, | 804 | GNUNET_STRINGS_string_to_data (enc, |
805 | len, | 805 | len, |
806 | buf, | 806 | buf, |
807 | buf_len)) | 807 | buf_len)) |
808 | { | 808 | { |
809 | GNUNET_break_op(0); | 809 | GNUNET_break_op (0); |
810 | GNUNET_free(buf); | 810 | GNUNET_free (buf); |
811 | return GNUNET_SYSERR; | 811 | return GNUNET_SYSERR; |
812 | } | 812 | } |
813 | if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode(buf, | 813 | if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, |
814 | buf_len))) | 814 | buf_len))) |
815 | { | 815 | { |
816 | GNUNET_break_op(0); | 816 | GNUNET_break_op (0); |
817 | GNUNET_free(buf); | 817 | GNUNET_free (buf); |
818 | return GNUNET_SYSERR; | 818 | return GNUNET_SYSERR; |
819 | } | 819 | } |
820 | GNUNET_free(buf); | 820 | GNUNET_free (buf); |
821 | return GNUNET_OK; | 821 | return GNUNET_OK; |
822 | } | 822 | } |
823 | 823 | ||
@@ -829,16 +829,16 @@ parse_rsa_public_key(void *cls, | |||
829 | * @param[out] spec where to free the data | 829 | * @param[out] spec where to free the data |
830 | */ | 830 | */ |
831 | static void | 831 | static void |
832 | clean_rsa_public_key(void *cls, | 832 | clean_rsa_public_key (void *cls, |
833 | struct GNUNET_JSON_Specification *spec) | 833 | struct GNUNET_JSON_Specification *spec) |
834 | { | 834 | { |
835 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; | 835 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; |
836 | 836 | ||
837 | if (NULL != *pk) | 837 | if (NULL != *pk) |
838 | { | 838 | { |
839 | GNUNET_CRYPTO_rsa_public_key_free(*pk); | 839 | GNUNET_CRYPTO_rsa_public_key_free (*pk); |
840 | *pk = NULL; | 840 | *pk = NULL; |
841 | } | 841 | } |
842 | } | 842 | } |
843 | 843 | ||
844 | 844 | ||
@@ -849,8 +849,8 @@ clean_rsa_public_key(void *cls, | |||
849 | * @param pk where to store the RSA key found under @a name | 849 | * @param pk where to store the RSA key found under @a name |
850 | */ | 850 | */ |
851 | struct GNUNET_JSON_Specification | 851 | struct GNUNET_JSON_Specification |
852 | GNUNET_JSON_spec_rsa_public_key(const char *name, | 852 | GNUNET_JSON_spec_rsa_public_key (const char *name, |
853 | struct GNUNET_CRYPTO_RsaPublicKey **pk) | 853 | struct GNUNET_CRYPTO_RsaPublicKey **pk) |
854 | { | 854 | { |
855 | struct GNUNET_JSON_Specification ret = { | 855 | struct GNUNET_JSON_Specification ret = { |
856 | .parser = &parse_rsa_public_key, | 856 | .parser = &parse_rsa_public_key, |
@@ -876,9 +876,9 @@ GNUNET_JSON_spec_rsa_public_key(const char *name, | |||
876 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 876 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
877 | */ | 877 | */ |
878 | static int | 878 | static int |
879 | parse_rsa_signature(void *cls, | 879 | parse_rsa_signature (void *cls, |
880 | json_t *root, | 880 | json_t *root, |
881 | struct GNUNET_JSON_Specification *spec) | 881 | struct GNUNET_JSON_Specification *spec) |
882 | { | 882 | { |
883 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; | 883 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; |
884 | size_t size; | 884 | size_t size; |
@@ -886,32 +886,32 @@ parse_rsa_signature(void *cls, | |||
886 | int res; | 886 | int res; |
887 | void *buf; | 887 | void *buf; |
888 | 888 | ||
889 | str = json_string_value(root); | 889 | str = json_string_value (root); |
890 | if (NULL == str) | 890 | if (NULL == str) |
891 | { | 891 | { |
892 | GNUNET_break_op(0); | 892 | GNUNET_break_op (0); |
893 | return GNUNET_SYSERR; | 893 | return GNUNET_SYSERR; |
894 | } | 894 | } |
895 | size = (strlen(str) * 5) / 8; | 895 | size = (strlen (str) * 5) / 8; |
896 | buf = GNUNET_malloc(size); | 896 | buf = GNUNET_malloc (size); |
897 | res = GNUNET_STRINGS_string_to_data(str, | 897 | res = GNUNET_STRINGS_string_to_data (str, |
898 | strlen(str), | 898 | strlen (str), |
899 | buf, | 899 | buf, |
900 | size); | 900 | size); |
901 | if (GNUNET_OK != res) | 901 | if (GNUNET_OK != res) |
902 | { | 902 | { |
903 | GNUNET_free(buf); | 903 | GNUNET_free (buf); |
904 | GNUNET_break_op(0); | 904 | GNUNET_break_op (0); |
905 | return GNUNET_SYSERR; | 905 | return GNUNET_SYSERR; |
906 | } | 906 | } |
907 | if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode(buf, | 907 | if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf, |
908 | size))) | 908 | size))) |
909 | { | 909 | { |
910 | GNUNET_break_op(0); | 910 | GNUNET_break_op (0); |
911 | GNUNET_free(buf); | 911 | GNUNET_free (buf); |
912 | return GNUNET_SYSERR; | 912 | return GNUNET_SYSERR; |
913 | } | 913 | } |
914 | GNUNET_free(buf); | 914 | GNUNET_free (buf); |
915 | return GNUNET_OK; | 915 | return GNUNET_OK; |
916 | } | 916 | } |
917 | 917 | ||
@@ -923,16 +923,16 @@ parse_rsa_signature(void *cls, | |||
923 | * @param[out] spec where to free the data | 923 | * @param[out] spec where to free the data |
924 | */ | 924 | */ |
925 | static void | 925 | static void |
926 | clean_rsa_signature(void *cls, | 926 | clean_rsa_signature (void *cls, |
927 | struct GNUNET_JSON_Specification *spec) | 927 | struct GNUNET_JSON_Specification *spec) |
928 | { | 928 | { |
929 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; | 929 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; |
930 | 930 | ||
931 | if (NULL != *sig) | 931 | if (NULL != *sig) |
932 | { | 932 | { |
933 | GNUNET_CRYPTO_rsa_signature_free(*sig); | 933 | GNUNET_CRYPTO_rsa_signature_free (*sig); |
934 | *sig = NULL; | 934 | *sig = NULL; |
935 | } | 935 | } |
936 | } | 936 | } |
937 | 937 | ||
938 | 938 | ||
@@ -943,8 +943,8 @@ clean_rsa_signature(void *cls, | |||
943 | * @param sig where to store the RSA signature found under @a name | 943 | * @param sig where to store the RSA signature found under @a name |
944 | */ | 944 | */ |
945 | struct GNUNET_JSON_Specification | 945 | struct GNUNET_JSON_Specification |
946 | GNUNET_JSON_spec_rsa_signature(const char *name, | 946 | GNUNET_JSON_spec_rsa_signature (const char *name, |
947 | struct GNUNET_CRYPTO_RsaSignature **sig) | 947 | struct GNUNET_CRYPTO_RsaSignature **sig) |
948 | { | 948 | { |
949 | struct GNUNET_JSON_Specification ret = { | 949 | struct GNUNET_JSON_Specification ret = { |
950 | .parser = &parse_rsa_signature, | 950 | .parser = &parse_rsa_signature, |
@@ -970,18 +970,18 @@ GNUNET_JSON_spec_rsa_signature(const char *name, | |||
970 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 970 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
971 | */ | 971 | */ |
972 | static int | 972 | static int |
973 | parse_boolean(void *cls, | 973 | parse_boolean (void *cls, |
974 | json_t *root, | 974 | json_t *root, |
975 | struct GNUNET_JSON_Specification *spec) | 975 | struct GNUNET_JSON_Specification *spec) |
976 | { | 976 | { |
977 | int *bp = spec->ptr; | 977 | int *bp = spec->ptr; |
978 | 978 | ||
979 | if (!json_is_boolean(root)) | 979 | if (! json_is_boolean (root)) |
980 | { | 980 | { |
981 | GNUNET_break_op(0); | 981 | GNUNET_break_op (0); |
982 | return GNUNET_SYSERR; | 982 | return GNUNET_SYSERR; |
983 | } | 983 | } |
984 | *bp = json_boolean_value(root) ? GNUNET_YES : GNUNET_NO; | 984 | *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO; |
985 | return GNUNET_OK; | 985 | return GNUNET_OK; |
986 | } | 986 | } |
987 | 987 | ||
@@ -993,8 +993,8 @@ parse_boolean(void *cls, | |||
993 | * @param[out] boolean where to store the boolean found under @a name | 993 | * @param[out] boolean where to store the boolean found under @a name |
994 | */ | 994 | */ |
995 | struct GNUNET_JSON_Specification | 995 | struct GNUNET_JSON_Specification |
996 | GNUNET_JSON_spec_boolean(const char *name, | 996 | GNUNET_JSON_spec_boolean (const char *name, |
997 | int *boolean) | 997 | int *boolean) |
998 | { | 998 | { |
999 | struct GNUNET_JSON_Specification ret = { | 999 | struct GNUNET_JSON_Specification ret = { |
1000 | .parser = &parse_boolean, | 1000 | .parser = &parse_boolean, |
diff --git a/src/json/json_mhd.c b/src/json/json_mhd.c index 0b4dcfee8..602a15b7a 100644 --- a/src/json/json_mhd.c +++ b/src/json/json_mhd.c | |||
@@ -40,7 +40,8 @@ | |||
40 | /** | 40 | /** |
41 | * Buffer for POST requests. | 41 | * Buffer for POST requests. |
42 | */ | 42 | */ |
43 | struct Buffer { | 43 | struct Buffer |
44 | { | ||
44 | /** | 45 | /** |
45 | * Allocated memory | 46 | * Allocated memory |
46 | */ | 47 | */ |
@@ -74,19 +75,19 @@ struct Buffer { | |||
74 | * @return a GNUnet result code | 75 | * @return a GNUnet result code |
75 | */ | 76 | */ |
76 | static int | 77 | static int |
77 | buffer_init(struct Buffer *buf, | 78 | buffer_init (struct Buffer *buf, |
78 | const void *data, | 79 | const void *data, |
79 | size_t data_size, | 80 | size_t data_size, |
80 | size_t alloc_size, | 81 | size_t alloc_size, |
81 | size_t max_size) | 82 | size_t max_size) |
82 | { | 83 | { |
83 | if ((data_size > max_size) || (alloc_size > max_size)) | 84 | if ((data_size > max_size) || (alloc_size > max_size)) |
84 | return GNUNET_SYSERR; | 85 | return GNUNET_SYSERR; |
85 | if (data_size > alloc_size) | 86 | if (data_size > alloc_size) |
86 | alloc_size = data_size; | 87 | alloc_size = data_size; |
87 | buf->data = GNUNET_malloc(alloc_size); | 88 | buf->data = GNUNET_malloc (alloc_size); |
88 | buf->alloc = alloc_size; | 89 | buf->alloc = alloc_size; |
89 | GNUNET_memcpy(buf->data, data, data_size); | 90 | GNUNET_memcpy (buf->data, data, data_size); |
90 | buf->fill = data_size; | 91 | buf->fill = data_size; |
91 | buf->max = max_size; | 92 | buf->max = max_size; |
92 | return GNUNET_OK; | 93 | return GNUNET_OK; |
@@ -100,9 +101,9 @@ buffer_init(struct Buffer *buf, | |||
100 | * @param buf buffer to de-initialize | 101 | * @param buf buffer to de-initialize |
101 | */ | 102 | */ |
102 | static void | 103 | static void |
103 | buffer_deinit(struct Buffer *buf) | 104 | buffer_deinit (struct Buffer *buf) |
104 | { | 105 | { |
105 | GNUNET_free(buf->data); | 106 | GNUNET_free (buf->data); |
106 | buf->data = NULL; | 107 | buf->data = NULL; |
107 | } | 108 | } |
108 | 109 | ||
@@ -118,28 +119,28 @@ buffer_deinit(struct Buffer *buf) | |||
118 | * #GNUNET_NO if the buffer can't accomodate for the new data | 119 | * #GNUNET_NO if the buffer can't accomodate for the new data |
119 | */ | 120 | */ |
120 | static int | 121 | static int |
121 | buffer_append(struct Buffer *buf, | 122 | buffer_append (struct Buffer *buf, |
122 | const void *data, | 123 | const void *data, |
123 | size_t data_size, | 124 | size_t data_size, |
124 | size_t max_size) | 125 | size_t max_size) |
125 | { | 126 | { |
126 | if (buf->fill + data_size > max_size) | 127 | if (buf->fill + data_size > max_size) |
127 | return GNUNET_NO; | 128 | return GNUNET_NO; |
128 | if (buf->fill + data_size > buf->alloc) | 129 | if (buf->fill + data_size > buf->alloc) |
129 | { | 130 | { |
130 | char *new_buf; | 131 | char *new_buf; |
131 | size_t new_size = buf->alloc; | 132 | size_t new_size = buf->alloc; |
132 | while (new_size < buf->fill + data_size) | 133 | while (new_size < buf->fill + data_size) |
133 | new_size += 2; | 134 | new_size += 2; |
134 | if (new_size > max_size) | 135 | if (new_size > max_size) |
135 | return GNUNET_NO; | 136 | return GNUNET_NO; |
136 | new_buf = GNUNET_malloc(new_size); | 137 | new_buf = GNUNET_malloc (new_size); |
137 | GNUNET_memcpy(new_buf, buf->data, buf->fill); | 138 | GNUNET_memcpy (new_buf, buf->data, buf->fill); |
138 | GNUNET_free(buf->data); | 139 | GNUNET_free (buf->data); |
139 | buf->data = new_buf; | 140 | buf->data = new_buf; |
140 | buf->alloc = new_size; | 141 | buf->alloc = new_size; |
141 | } | 142 | } |
142 | GNUNET_memcpy(buf->data + buf->fill, data, data_size); | 143 | GNUNET_memcpy (buf->data + buf->fill, data, data_size); |
143 | buf->fill += data_size; | 144 | buf->fill += data_size; |
144 | return GNUNET_OK; | 145 | return GNUNET_OK; |
145 | } | 146 | } |
@@ -152,95 +153,95 @@ buffer_append(struct Buffer *buf, | |||
152 | * @return result code indicating the status of the operation | 153 | * @return result code indicating the status of the operation |
153 | */ | 154 | */ |
154 | static enum GNUNET_JSON_PostResult | 155 | static enum GNUNET_JSON_PostResult |
155 | inflate_data(struct Buffer *buf) | 156 | inflate_data (struct Buffer *buf) |
156 | { | 157 | { |
157 | z_stream z; | 158 | z_stream z; |
158 | char *tmp; | 159 | char *tmp; |
159 | size_t tmp_size; | 160 | size_t tmp_size; |
160 | int ret; | 161 | int ret; |
161 | 162 | ||
162 | memset(&z, 0, sizeof(z)); | 163 | memset (&z, 0, sizeof(z)); |
163 | z.next_in = (Bytef *)buf->data; | 164 | z.next_in = (Bytef *) buf->data; |
164 | z.avail_in = buf->fill; | 165 | z.avail_in = buf->fill; |
165 | tmp_size = GNUNET_MIN(buf->max, buf->fill * 4); | 166 | tmp_size = GNUNET_MIN (buf->max, buf->fill * 4); |
166 | tmp = GNUNET_malloc(tmp_size); | 167 | tmp = GNUNET_malloc (tmp_size); |
167 | z.next_out = (Bytef *)tmp; | 168 | z.next_out = (Bytef *) tmp; |
168 | z.avail_out = tmp_size; | 169 | z.avail_out = tmp_size; |
169 | ret = inflateInit(&z); | 170 | ret = inflateInit (&z); |
170 | switch (ret) | 171 | switch (ret) |
172 | { | ||
173 | case Z_MEM_ERROR: | ||
174 | GNUNET_break (0); | ||
175 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | ||
176 | |||
177 | case Z_STREAM_ERROR: | ||
178 | GNUNET_break_op (0); | ||
179 | return GNUNET_JSON_PR_JSON_INVALID; | ||
180 | |||
181 | case Z_OK: | ||
182 | break; | ||
183 | } | ||
184 | while (1) | ||
185 | { | ||
186 | ret = inflate (&z, 0); | ||
187 | switch (ret) | ||
171 | { | 188 | { |
172 | case Z_MEM_ERROR: | 189 | case Z_MEM_ERROR: |
173 | GNUNET_break(0); | 190 | GNUNET_break (0); |
191 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
192 | GNUNET_free (tmp); | ||
174 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | 193 | return GNUNET_JSON_PR_OUT_OF_MEMORY; |
175 | 194 | ||
176 | case Z_STREAM_ERROR: | 195 | case Z_DATA_ERROR: |
177 | GNUNET_break_op(0); | 196 | GNUNET_break (0); |
197 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
198 | GNUNET_free (tmp); | ||
199 | return GNUNET_JSON_PR_JSON_INVALID; | ||
200 | |||
201 | case Z_NEED_DICT: | ||
202 | GNUNET_break (0); | ||
203 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
204 | GNUNET_free (tmp); | ||
178 | return GNUNET_JSON_PR_JSON_INVALID; | 205 | return GNUNET_JSON_PR_JSON_INVALID; |
179 | 206 | ||
180 | case Z_OK: | 207 | case Z_OK: |
181 | break; | 208 | if ((0 < z.avail_out) && (0 == z.avail_in)) |
209 | { | ||
210 | /* truncated input stream */ | ||
211 | GNUNET_break (0); | ||
212 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
213 | GNUNET_free (tmp); | ||
214 | return GNUNET_JSON_PR_JSON_INVALID; | ||
215 | } | ||
216 | if (0 < z.avail_out) | ||
217 | continue; /* just call it again */ | ||
218 | /* output buffer full, can we grow it? */ | ||
219 | if (tmp_size == buf->max) | ||
220 | { | ||
221 | /* already at max */ | ||
222 | GNUNET_break (0); | ||
223 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
224 | GNUNET_free (tmp); | ||
225 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | ||
226 | } | ||
227 | if (tmp_size * 2 < tmp_size) | ||
228 | tmp_size = buf->max; | ||
229 | else | ||
230 | tmp_size = GNUNET_MIN (buf->max, tmp_size * 2); | ||
231 | tmp = GNUNET_realloc (tmp, tmp_size); | ||
232 | z.next_out = (Bytef *) &tmp[z.total_out]; | ||
233 | continue; | ||
234 | |||
235 | case Z_STREAM_END: | ||
236 | /* decompression successful, make 'tmp' the new 'data' */ | ||
237 | GNUNET_free (buf->data); | ||
238 | buf->data = tmp; | ||
239 | buf->alloc = tmp_size; | ||
240 | buf->fill = z.total_out; | ||
241 | GNUNET_break (Z_OK == inflateEnd (&z)); | ||
242 | return GNUNET_JSON_PR_SUCCESS; /* at least for now */ | ||
182 | } | 243 | } |
183 | while (1) | 244 | } /* while (1) */ |
184 | { | ||
185 | ret = inflate(&z, 0); | ||
186 | switch (ret) | ||
187 | { | ||
188 | case Z_MEM_ERROR: | ||
189 | GNUNET_break(0); | ||
190 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
191 | GNUNET_free(tmp); | ||
192 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | ||
193 | |||
194 | case Z_DATA_ERROR: | ||
195 | GNUNET_break(0); | ||
196 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
197 | GNUNET_free(tmp); | ||
198 | return GNUNET_JSON_PR_JSON_INVALID; | ||
199 | |||
200 | case Z_NEED_DICT: | ||
201 | GNUNET_break(0); | ||
202 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
203 | GNUNET_free(tmp); | ||
204 | return GNUNET_JSON_PR_JSON_INVALID; | ||
205 | |||
206 | case Z_OK: | ||
207 | if ((0 < z.avail_out) && (0 == z.avail_in)) | ||
208 | { | ||
209 | /* truncated input stream */ | ||
210 | GNUNET_break(0); | ||
211 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
212 | GNUNET_free(tmp); | ||
213 | return GNUNET_JSON_PR_JSON_INVALID; | ||
214 | } | ||
215 | if (0 < z.avail_out) | ||
216 | continue; /* just call it again */ | ||
217 | /* output buffer full, can we grow it? */ | ||
218 | if (tmp_size == buf->max) | ||
219 | { | ||
220 | /* already at max */ | ||
221 | GNUNET_break(0); | ||
222 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
223 | GNUNET_free(tmp); | ||
224 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | ||
225 | } | ||
226 | if (tmp_size * 2 < tmp_size) | ||
227 | tmp_size = buf->max; | ||
228 | else | ||
229 | tmp_size = GNUNET_MIN(buf->max, tmp_size * 2); | ||
230 | tmp = GNUNET_realloc(tmp, tmp_size); | ||
231 | z.next_out = (Bytef *)&tmp[z.total_out]; | ||
232 | continue; | ||
233 | |||
234 | case Z_STREAM_END: | ||
235 | /* decompression successful, make 'tmp' the new 'data' */ | ||
236 | GNUNET_free(buf->data); | ||
237 | buf->data = tmp; | ||
238 | buf->alloc = tmp_size; | ||
239 | buf->fill = z.total_out; | ||
240 | GNUNET_break(Z_OK == inflateEnd(&z)); | ||
241 | return GNUNET_JSON_PR_SUCCESS; /* at least for now */ | ||
242 | } | ||
243 | } /* while (1) */ | ||
244 | } | 245 | } |
245 | 246 | ||
246 | 247 | ||
@@ -260,12 +261,12 @@ inflate_data(struct Buffer *buf) | |||
260 | * @return result code indicating the status of the operation | 261 | * @return result code indicating the status of the operation |
261 | */ | 262 | */ |
262 | enum GNUNET_JSON_PostResult | 263 | enum GNUNET_JSON_PostResult |
263 | GNUNET_JSON_post_parser(size_t buffer_max, | 264 | GNUNET_JSON_post_parser (size_t buffer_max, |
264 | struct MHD_Connection *connection, | 265 | struct MHD_Connection *connection, |
265 | void **con_cls, | 266 | void **con_cls, |
266 | const char *upload_data, | 267 | const char *upload_data, |
267 | size_t *upload_data_size, | 268 | size_t *upload_data_size, |
268 | json_t **json) | 269 | json_t **json) |
269 | { | 270 | { |
270 | struct Buffer *r = *con_cls; | 271 | struct Buffer *r = *con_cls; |
271 | const char *ce; | 272 | const char *ce; |
@@ -273,71 +274,71 @@ GNUNET_JSON_post_parser(size_t buffer_max, | |||
273 | 274 | ||
274 | *json = NULL; | 275 | *json = NULL; |
275 | if (NULL == *con_cls) | 276 | if (NULL == *con_cls) |
277 | { | ||
278 | /* We are seeing a fresh POST request. */ | ||
279 | r = GNUNET_new (struct Buffer); | ||
280 | if (GNUNET_OK != buffer_init (r, | ||
281 | upload_data, | ||
282 | *upload_data_size, | ||
283 | REQUEST_BUFFER_INITIAL, | ||
284 | buffer_max)) | ||
276 | { | 285 | { |
277 | /* We are seeing a fresh POST request. */ | 286 | *con_cls = NULL; |
278 | r = GNUNET_new(struct Buffer); | 287 | buffer_deinit (r); |
279 | if (GNUNET_OK != buffer_init(r, | 288 | GNUNET_free (r); |
280 | upload_data, | 289 | return GNUNET_JSON_PR_OUT_OF_MEMORY; |
281 | *upload_data_size, | ||
282 | REQUEST_BUFFER_INITIAL, | ||
283 | buffer_max)) | ||
284 | { | ||
285 | *con_cls = NULL; | ||
286 | buffer_deinit(r); | ||
287 | GNUNET_free(r); | ||
288 | return GNUNET_JSON_PR_OUT_OF_MEMORY; | ||
289 | } | ||
290 | /* everything OK, wait for more POST data */ | ||
291 | *upload_data_size = 0; | ||
292 | *con_cls = r; | ||
293 | return GNUNET_JSON_PR_CONTINUE; | ||
294 | } | 290 | } |
291 | /* everything OK, wait for more POST data */ | ||
292 | *upload_data_size = 0; | ||
293 | *con_cls = r; | ||
294 | return GNUNET_JSON_PR_CONTINUE; | ||
295 | } | ||
295 | if (0 != *upload_data_size) | 296 | if (0 != *upload_data_size) |
297 | { | ||
298 | /* We are seeing an old request with more data available. */ | ||
299 | |||
300 | if (GNUNET_OK != | ||
301 | buffer_append (r, upload_data, *upload_data_size, buffer_max)) | ||
296 | { | 302 | { |
297 | /* We are seeing an old request with more data available. */ | 303 | /* Request too long */ |
298 | 304 | *con_cls = NULL; | |
299 | if (GNUNET_OK != | 305 | buffer_deinit (r); |
300 | buffer_append(r, upload_data, *upload_data_size, buffer_max)) | 306 | GNUNET_free (r); |
301 | { | 307 | return GNUNET_JSON_PR_REQUEST_TOO_LARGE; |
302 | /* Request too long */ | ||
303 | *con_cls = NULL; | ||
304 | buffer_deinit(r); | ||
305 | GNUNET_free(r); | ||
306 | return GNUNET_JSON_PR_REQUEST_TOO_LARGE; | ||
307 | } | ||
308 | /* everything OK, wait for more POST data */ | ||
309 | *upload_data_size = 0; | ||
310 | return GNUNET_JSON_PR_CONTINUE; | ||
311 | } | 308 | } |
309 | /* everything OK, wait for more POST data */ | ||
310 | *upload_data_size = 0; | ||
311 | return GNUNET_JSON_PR_CONTINUE; | ||
312 | } | ||
312 | 313 | ||
313 | /* We have seen the whole request. */ | 314 | /* We have seen the whole request. */ |
314 | ce = MHD_lookup_connection_value(connection, | 315 | ce = MHD_lookup_connection_value (connection, |
315 | MHD_HEADER_KIND, | 316 | MHD_HEADER_KIND, |
316 | MHD_HTTP_HEADER_CONTENT_ENCODING); | 317 | MHD_HTTP_HEADER_CONTENT_ENCODING); |
317 | if ((NULL != ce) && (0 == strcasecmp("deflate", ce))) | 318 | if ((NULL != ce) && (0 == strcasecmp ("deflate", ce))) |
319 | { | ||
320 | ret = inflate_data (r); | ||
321 | if (GNUNET_JSON_PR_SUCCESS != ret) | ||
318 | { | 322 | { |
319 | ret = inflate_data(r); | 323 | buffer_deinit (r); |
320 | if (GNUNET_JSON_PR_SUCCESS != ret) | 324 | GNUNET_free (r); |
321 | { | 325 | *con_cls = NULL; |
322 | buffer_deinit(r); | 326 | return ret; |
323 | GNUNET_free(r); | ||
324 | *con_cls = NULL; | ||
325 | return ret; | ||
326 | } | ||
327 | } | 327 | } |
328 | } | ||
328 | 329 | ||
329 | *json = json_loadb(r->data, r->fill, 0, NULL); | 330 | *json = json_loadb (r->data, r->fill, 0, NULL); |
330 | if (NULL == *json) | 331 | if (NULL == *json) |
331 | { | 332 | { |
332 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 333 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
333 | "Failed to parse JSON request body\n"); | 334 | "Failed to parse JSON request body\n"); |
334 | buffer_deinit(r); | 335 | buffer_deinit (r); |
335 | GNUNET_free(r); | 336 | GNUNET_free (r); |
336 | *con_cls = NULL; | 337 | *con_cls = NULL; |
337 | return GNUNET_JSON_PR_JSON_INVALID; | 338 | return GNUNET_JSON_PR_JSON_INVALID; |
338 | } | 339 | } |
339 | buffer_deinit(r); | 340 | buffer_deinit (r); |
340 | GNUNET_free(r); | 341 | GNUNET_free (r); |
341 | *con_cls = NULL; | 342 | *con_cls = NULL; |
342 | 343 | ||
343 | return GNUNET_JSON_PR_SUCCESS; | 344 | return GNUNET_JSON_PR_SUCCESS; |
@@ -352,15 +353,15 @@ GNUNET_JSON_post_parser(size_t buffer_max, | |||
352 | * #GNUNET_JSON_post_parser(), to be cleaned up | 353 | * #GNUNET_JSON_post_parser(), to be cleaned up |
353 | */ | 354 | */ |
354 | void | 355 | void |
355 | GNUNET_JSON_post_parser_cleanup(void *con_cls) | 356 | GNUNET_JSON_post_parser_cleanup (void *con_cls) |
356 | { | 357 | { |
357 | struct Buffer *r = con_cls; | 358 | struct Buffer *r = con_cls; |
358 | 359 | ||
359 | if (NULL != r) | 360 | if (NULL != r) |
360 | { | 361 | { |
361 | buffer_deinit(r); | 362 | buffer_deinit (r); |
362 | GNUNET_free(r); | 363 | GNUNET_free (r); |
363 | } | 364 | } |
364 | } | 365 | } |
365 | 366 | ||
366 | /* end of mhd_json.c */ | 367 | /* end of mhd_json.c */ |
diff --git a/src/json/test_json.c b/src/json/test_json.c index 4b9fbc710..f77d9add9 100644 --- a/src/json/test_json.c +++ b/src/json/test_json.c | |||
@@ -34,32 +34,34 @@ | |||
34 | * @return 0 on success | 34 | * @return 0 on success |
35 | */ | 35 | */ |
36 | static int | 36 | static int |
37 | test_abs_time() | 37 | test_abs_time () |
38 | { | 38 | { |
39 | json_t *j; | 39 | json_t *j; |
40 | struct GNUNET_TIME_Absolute a1; | 40 | struct GNUNET_TIME_Absolute a1; |
41 | struct GNUNET_TIME_Absolute a2; | 41 | struct GNUNET_TIME_Absolute a2; |
42 | struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_absolute_time(NULL, | 42 | struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_absolute_time ( |
43 | &a2), | 43 | NULL, |
44 | GNUNET_JSON_spec_end() }; | 44 | &a2), |
45 | struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_absolute_time(NULL, | 45 | GNUNET_JSON_spec_end () }; |
46 | &a2), | 46 | struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_absolute_time ( |
47 | GNUNET_JSON_spec_end() }; | 47 | NULL, |
48 | 48 | &a2), | |
49 | a1 = GNUNET_TIME_absolute_get(); | 49 | GNUNET_JSON_spec_end () }; |
50 | GNUNET_TIME_round_abs(&a1); | 50 | |
51 | j = GNUNET_JSON_from_time_abs(a1); | 51 | a1 = GNUNET_TIME_absolute_get (); |
52 | GNUNET_assert(NULL != j); | 52 | GNUNET_TIME_round_abs (&a1); |
53 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s1, NULL, NULL)); | 53 | j = GNUNET_JSON_from_time_abs (a1); |
54 | GNUNET_assert(a1.abs_value_us == a2.abs_value_us); | 54 | GNUNET_assert (NULL != j); |
55 | json_decref(j); | 55 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s1, NULL, NULL)); |
56 | GNUNET_assert (a1.abs_value_us == a2.abs_value_us); | ||
57 | json_decref (j); | ||
56 | 58 | ||
57 | a1 = GNUNET_TIME_UNIT_FOREVER_ABS; | 59 | a1 = GNUNET_TIME_UNIT_FOREVER_ABS; |
58 | j = GNUNET_JSON_from_time_abs(a1); | 60 | j = GNUNET_JSON_from_time_abs (a1); |
59 | GNUNET_assert(NULL != j); | 61 | GNUNET_assert (NULL != j); |
60 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s2, NULL, NULL)); | 62 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s2, NULL, NULL)); |
61 | GNUNET_assert(a1.abs_value_us == a2.abs_value_us); | 63 | GNUNET_assert (a1.abs_value_us == a2.abs_value_us); |
62 | json_decref(j); | 64 | json_decref (j); |
63 | return 0; | 65 | return 0; |
64 | } | 66 | } |
65 | 67 | ||
@@ -70,31 +72,33 @@ test_abs_time() | |||
70 | * @return 0 on success | 72 | * @return 0 on success |
71 | */ | 73 | */ |
72 | static int | 74 | static int |
73 | test_rel_time() | 75 | test_rel_time () |
74 | { | 76 | { |
75 | json_t *j; | 77 | json_t *j; |
76 | struct GNUNET_TIME_Relative r1; | 78 | struct GNUNET_TIME_Relative r1; |
77 | struct GNUNET_TIME_Relative r2; | 79 | struct GNUNET_TIME_Relative r2; |
78 | struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_relative_time(NULL, | 80 | struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_relative_time ( |
79 | &r2), | 81 | NULL, |
80 | GNUNET_JSON_spec_end() }; | 82 | &r2), |
81 | struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_relative_time(NULL, | 83 | GNUNET_JSON_spec_end () }; |
82 | &r2), | 84 | struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_relative_time ( |
83 | GNUNET_JSON_spec_end() }; | 85 | NULL, |
86 | &r2), | ||
87 | GNUNET_JSON_spec_end () }; | ||
84 | 88 | ||
85 | r1 = GNUNET_TIME_UNIT_SECONDS; | 89 | r1 = GNUNET_TIME_UNIT_SECONDS; |
86 | j = GNUNET_JSON_from_time_rel(r1); | 90 | j = GNUNET_JSON_from_time_rel (r1); |
87 | GNUNET_assert(NULL != j); | 91 | GNUNET_assert (NULL != j); |
88 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s1, NULL, NULL)); | 92 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s1, NULL, NULL)); |
89 | GNUNET_assert(r1.rel_value_us == r2.rel_value_us); | 93 | GNUNET_assert (r1.rel_value_us == r2.rel_value_us); |
90 | json_decref(j); | 94 | json_decref (j); |
91 | 95 | ||
92 | r1 = GNUNET_TIME_UNIT_FOREVER_REL; | 96 | r1 = GNUNET_TIME_UNIT_FOREVER_REL; |
93 | j = GNUNET_JSON_from_time_rel(r1); | 97 | j = GNUNET_JSON_from_time_rel (r1); |
94 | GNUNET_assert(NULL != j); | 98 | GNUNET_assert (NULL != j); |
95 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s2, NULL, NULL)); | 99 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s2, NULL, NULL)); |
96 | GNUNET_assert(r1.rel_value_us == r2.rel_value_us); | 100 | GNUNET_assert (r1.rel_value_us == r2.rel_value_us); |
97 | json_decref(j); | 101 | json_decref (j); |
98 | return 0; | 102 | return 0; |
99 | } | 103 | } |
100 | 104 | ||
@@ -105,26 +109,26 @@ test_rel_time() | |||
105 | * @return 0 on success | 109 | * @return 0 on success |
106 | */ | 110 | */ |
107 | static int | 111 | static int |
108 | test_raw() | 112 | test_raw () |
109 | { | 113 | { |
110 | char blob[256]; | 114 | char blob[256]; |
111 | unsigned int i; | 115 | unsigned int i; |
112 | json_t *j; | 116 | json_t *j; |
113 | 117 | ||
114 | for (i = 0; i <= 256; i++) | 118 | for (i = 0; i <= 256; i++) |
115 | { | 119 | { |
116 | char blob2[256]; | 120 | char blob2[256]; |
117 | struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed(NULL, | 121 | struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed (NULL, |
118 | blob2, | 122 | blob2, |
119 | i), | 123 | i), |
120 | GNUNET_JSON_spec_end() }; | 124 | GNUNET_JSON_spec_end () }; |
121 | 125 | ||
122 | memset(blob, i, i); | 126 | memset (blob, i, i); |
123 | j = GNUNET_JSON_from_data(blob, i); | 127 | j = GNUNET_JSON_from_data (blob, i); |
124 | GNUNET_assert(NULL != j); | 128 | GNUNET_assert (NULL != j); |
125 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, spec, NULL, NULL)); | 129 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, spec, NULL, NULL)); |
126 | GNUNET_assert(0 == memcmp(blob, blob2, i)); | 130 | GNUNET_assert (0 == memcmp (blob, blob2, i)); |
127 | } | 131 | } |
128 | return 0; | 132 | return 0; |
129 | } | 133 | } |
130 | 134 | ||
@@ -135,36 +139,36 @@ test_raw() | |||
135 | * @return 0 on success | 139 | * @return 0 on success |
136 | */ | 140 | */ |
137 | static int | 141 | static int |
138 | test_rsa() | 142 | test_rsa () |
139 | { | 143 | { |
140 | struct GNUNET_CRYPTO_RsaPublicKey *pub; | 144 | struct GNUNET_CRYPTO_RsaPublicKey *pub; |
141 | struct GNUNET_CRYPTO_RsaPublicKey *pub2; | 145 | struct GNUNET_CRYPTO_RsaPublicKey *pub2; |
142 | struct GNUNET_JSON_Specification pspec[] = | 146 | struct GNUNET_JSON_Specification pspec[] = |
143 | { GNUNET_JSON_spec_rsa_public_key(NULL, &pub2), GNUNET_JSON_spec_end() }; | 147 | { GNUNET_JSON_spec_rsa_public_key (NULL, &pub2), GNUNET_JSON_spec_end () }; |
144 | struct GNUNET_CRYPTO_RsaSignature *sig; | 148 | struct GNUNET_CRYPTO_RsaSignature *sig; |
145 | struct GNUNET_CRYPTO_RsaSignature *sig2; | 149 | struct GNUNET_CRYPTO_RsaSignature *sig2; |
146 | struct GNUNET_JSON_Specification sspec[] = | 150 | struct GNUNET_JSON_Specification sspec[] = |
147 | { GNUNET_JSON_spec_rsa_signature(NULL, &sig2), GNUNET_JSON_spec_end() }; | 151 | { GNUNET_JSON_spec_rsa_signature (NULL, &sig2), GNUNET_JSON_spec_end () }; |
148 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; | 152 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; |
149 | struct GNUNET_HashCode msg; | 153 | struct GNUNET_HashCode msg; |
150 | json_t *jp; | 154 | json_t *jp; |
151 | json_t *js; | 155 | json_t *js; |
152 | 156 | ||
153 | priv = GNUNET_CRYPTO_rsa_private_key_create(1024); | 157 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); |
154 | pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); | 158 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); |
155 | memset(&msg, 42, sizeof(msg)); | 159 | memset (&msg, 42, sizeof(msg)); |
156 | sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, &msg); | 160 | sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, &msg); |
157 | GNUNET_assert(NULL != (jp = GNUNET_JSON_from_rsa_public_key(pub))); | 161 | GNUNET_assert (NULL != (jp = GNUNET_JSON_from_rsa_public_key (pub))); |
158 | GNUNET_assert(NULL != (js = GNUNET_JSON_from_rsa_signature(sig))); | 162 | GNUNET_assert (NULL != (js = GNUNET_JSON_from_rsa_signature (sig))); |
159 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(jp, pspec, NULL, NULL)); | 163 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (jp, pspec, NULL, NULL)); |
160 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(js, sspec, NULL, NULL)); | 164 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (js, sspec, NULL, NULL)); |
161 | GNUNET_break(0 == GNUNET_CRYPTO_rsa_signature_cmp(sig, sig2)); | 165 | GNUNET_break (0 == GNUNET_CRYPTO_rsa_signature_cmp (sig, sig2)); |
162 | GNUNET_break(0 == GNUNET_CRYPTO_rsa_public_key_cmp(pub, pub2)); | 166 | GNUNET_break (0 == GNUNET_CRYPTO_rsa_public_key_cmp (pub, pub2)); |
163 | GNUNET_CRYPTO_rsa_signature_free(sig); | 167 | GNUNET_CRYPTO_rsa_signature_free (sig); |
164 | GNUNET_CRYPTO_rsa_signature_free(sig2); | 168 | GNUNET_CRYPTO_rsa_signature_free (sig2); |
165 | GNUNET_CRYPTO_rsa_private_key_free(priv); | 169 | GNUNET_CRYPTO_rsa_private_key_free (priv); |
166 | GNUNET_CRYPTO_rsa_public_key_free(pub); | 170 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
167 | GNUNET_CRYPTO_rsa_public_key_free(pub2); | 171 | GNUNET_CRYPTO_rsa_public_key_free (pub2); |
168 | return 0; | 172 | return 0; |
169 | } | 173 | } |
170 | 174 | ||
@@ -175,47 +179,47 @@ test_rsa() | |||
175 | * @return 0 on success | 179 | * @return 0 on success |
176 | */ | 180 | */ |
177 | static int | 181 | static int |
178 | test_boolean() | 182 | test_boolean () |
179 | { | 183 | { |
180 | int b1; | 184 | int b1; |
181 | int b2; | 185 | int b2; |
182 | json_t *json; | 186 | json_t *json; |
183 | struct GNUNET_JSON_Specification pspec[] = { GNUNET_JSON_spec_boolean("b1", | 187 | struct GNUNET_JSON_Specification pspec[] = { GNUNET_JSON_spec_boolean ("b1", |
184 | &b1), | 188 | &b1), |
185 | GNUNET_JSON_spec_boolean("b2", | 189 | GNUNET_JSON_spec_boolean ("b2", |
186 | &b2), | 190 | &b2), |
187 | GNUNET_JSON_spec_end() }; | 191 | GNUNET_JSON_spec_end () }; |
188 | 192 | ||
189 | json = json_object(); | 193 | json = json_object (); |
190 | json_object_set_new(json, "b1", json_true()); | 194 | json_object_set_new (json, "b1", json_true ()); |
191 | json_object_set_new(json, "b2", json_false()); | 195 | json_object_set_new (json, "b2", json_false ()); |
192 | 196 | ||
193 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(json, pspec, NULL, NULL)); | 197 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (json, pspec, NULL, NULL)); |
194 | 198 | ||
195 | GNUNET_assert(GNUNET_YES == b1); | 199 | GNUNET_assert (GNUNET_YES == b1); |
196 | GNUNET_assert(GNUNET_NO == b2); | 200 | GNUNET_assert (GNUNET_NO == b2); |
197 | 201 | ||
198 | json_object_set_new(json, "b1", json_integer(42)); | 202 | json_object_set_new (json, "b1", json_integer (42)); |
199 | 203 | ||
200 | GNUNET_assert(GNUNET_OK != GNUNET_JSON_parse(json, pspec, NULL, NULL)); | 204 | GNUNET_assert (GNUNET_OK != GNUNET_JSON_parse (json, pspec, NULL, NULL)); |
201 | 205 | ||
202 | return 0; | 206 | return 0; |
203 | } | 207 | } |
204 | 208 | ||
205 | 209 | ||
206 | int | 210 | int |
207 | main(int argc, const char *const argv[]) | 211 | main (int argc, const char *const argv[]) |
208 | { | 212 | { |
209 | GNUNET_log_setup("test-json", "WARNING", NULL); | 213 | GNUNET_log_setup ("test-json", "WARNING", NULL); |
210 | if (0 != test_abs_time()) | 214 | if (0 != test_abs_time ()) |
211 | return 1; | 215 | return 1; |
212 | if (0 != test_rel_time()) | 216 | if (0 != test_rel_time ()) |
213 | return 1; | 217 | return 1; |
214 | if (0 != test_raw()) | 218 | if (0 != test_raw ()) |
215 | return 1; | 219 | return 1; |
216 | if (0 != test_rsa()) | 220 | if (0 != test_rsa ()) |
217 | return 1; | 221 | return 1; |
218 | if (0 != test_boolean()) | 222 | if (0 != test_boolean ()) |
219 | return 1; | 223 | return 1; |
220 | /* FIXME: test EdDSA signature conversion... */ | 224 | /* FIXME: test EdDSA signature conversion... */ |
221 | return 0; | 225 | return 0; |
diff --git a/src/json/test_json_mhd.c b/src/json/test_json_mhd.c index 213b95e12..6af1edd86 100644 --- a/src/json/test_json_mhd.c +++ b/src/json/test_json_mhd.c | |||
@@ -37,69 +37,69 @@ static int global_ret; | |||
37 | 37 | ||
38 | 38 | ||
39 | static int | 39 | static int |
40 | access_handler_cb(void *cls, | 40 | access_handler_cb (void *cls, |
41 | struct MHD_Connection *connection, | 41 | struct MHD_Connection *connection, |
42 | const char *url, | 42 | const char *url, |
43 | const char *method, | 43 | const char *method, |
44 | const char *version, | 44 | const char *version, |
45 | const char *upload_data, | 45 | const char *upload_data, |
46 | size_t *upload_data_size, | 46 | size_t *upload_data_size, |
47 | void **con_cls) | 47 | void **con_cls) |
48 | { | 48 | { |
49 | int ret; | 49 | int ret; |
50 | json_t *json; | 50 | json_t *json; |
51 | struct MHD_Response *resp; | 51 | struct MHD_Response *resp; |
52 | 52 | ||
53 | json = NULL; | 53 | json = NULL; |
54 | ret = GNUNET_JSON_post_parser(MAX_SIZE, | 54 | ret = GNUNET_JSON_post_parser (MAX_SIZE, |
55 | connection, | 55 | connection, |
56 | con_cls, | 56 | con_cls, |
57 | upload_data, | 57 | upload_data, |
58 | upload_data_size, | 58 | upload_data_size, |
59 | &json); | 59 | &json); |
60 | switch (ret) | 60 | switch (ret) |
61 | { | ||
62 | case GNUNET_JSON_PR_SUCCESS: | ||
63 | if (json_equal (bigj, json)) | ||
61 | { | 64 | { |
62 | case GNUNET_JSON_PR_SUCCESS: | 65 | global_ret = 0; |
63 | if (json_equal(bigj, json)) | ||
64 | { | ||
65 | global_ret = 0; | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | GNUNET_break(0); | ||
70 | global_ret = 6; | ||
71 | } | ||
72 | json_decref(json); | ||
73 | resp = MHD_create_response_from_buffer(3, "OK\n", MHD_RESPMEM_PERSISTENT); | ||
74 | ret = MHD_queue_response(connection, MHD_HTTP_OK, resp); | ||
75 | MHD_destroy_response(resp); | ||
76 | return ret; | ||
77 | |||
78 | case GNUNET_JSON_PR_CONTINUE: | ||
79 | return MHD_YES; | ||
80 | |||
81 | case GNUNET_JSON_PR_OUT_OF_MEMORY: | ||
82 | GNUNET_break(0); | ||
83 | global_ret = 3; | ||
84 | break; | ||
85 | |||
86 | case GNUNET_JSON_PR_REQUEST_TOO_LARGE: | ||
87 | GNUNET_break(0); | ||
88 | global_ret = 4; | ||
89 | break; | ||
90 | |||
91 | case GNUNET_JSON_PR_JSON_INVALID: | ||
92 | GNUNET_break(0); | ||
93 | global_ret = 5; | ||
94 | break; | ||
95 | } | 66 | } |
96 | GNUNET_break(0); | 67 | else |
68 | { | ||
69 | GNUNET_break (0); | ||
70 | global_ret = 6; | ||
71 | } | ||
72 | json_decref (json); | ||
73 | resp = MHD_create_response_from_buffer (3, "OK\n", MHD_RESPMEM_PERSISTENT); | ||
74 | ret = MHD_queue_response (connection, MHD_HTTP_OK, resp); | ||
75 | MHD_destroy_response (resp); | ||
76 | return ret; | ||
77 | |||
78 | case GNUNET_JSON_PR_CONTINUE: | ||
79 | return MHD_YES; | ||
80 | |||
81 | case GNUNET_JSON_PR_OUT_OF_MEMORY: | ||
82 | GNUNET_break (0); | ||
83 | global_ret = 3; | ||
84 | break; | ||
85 | |||
86 | case GNUNET_JSON_PR_REQUEST_TOO_LARGE: | ||
87 | GNUNET_break (0); | ||
88 | global_ret = 4; | ||
89 | break; | ||
90 | |||
91 | case GNUNET_JSON_PR_JSON_INVALID: | ||
92 | GNUNET_break (0); | ||
93 | global_ret = 5; | ||
94 | break; | ||
95 | } | ||
96 | GNUNET_break (0); | ||
97 | return MHD_NO; | 97 | return MHD_NO; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | int | 101 | int |
102 | main(int argc, const char *const argv[]) | 102 | main (int argc, const char *const argv[]) |
103 | { | 103 | { |
104 | struct MHD_Daemon *daemon; | 104 | struct MHD_Daemon *daemon; |
105 | uint16_t port; | 105 | uint16_t port; |
@@ -112,79 +112,79 @@ main(int argc, const char *const argv[]) | |||
112 | uLongf dlen; | 112 | uLongf dlen; |
113 | struct curl_slist *json_header; | 113 | struct curl_slist *json_header; |
114 | 114 | ||
115 | GNUNET_log_setup("test-json-mhd", "WARNING", NULL); | 115 | GNUNET_log_setup ("test-json-mhd", "WARNING", NULL); |
116 | global_ret = 2; | 116 | global_ret = 2; |
117 | daemon = MHD_start_daemon(MHD_USE_DUAL_STACK | MHD_USE_AUTO_INTERNAL_THREAD, | 117 | daemon = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_AUTO_INTERNAL_THREAD, |
118 | 0, | 118 | 0, |
119 | NULL, | 119 | NULL, |
120 | NULL, | 120 | NULL, |
121 | &access_handler_cb, | 121 | &access_handler_cb, |
122 | NULL, | 122 | NULL, |
123 | MHD_OPTION_END); | 123 | MHD_OPTION_END); |
124 | if (NULL == daemon) | 124 | if (NULL == daemon) |
125 | return 77; | 125 | return 77; |
126 | bigj = json_object(); | 126 | bigj = json_object (); |
127 | json_object_set_new(bigj, "test", json_string("value")); | 127 | json_object_set_new (bigj, "test", json_string ("value")); |
128 | for (unsigned int i = 0; i < 1000; i++) | 128 | for (unsigned int i = 0; i < 1000; i++) |
129 | { | 129 | { |
130 | char tmp[5]; | 130 | char tmp[5]; |
131 | 131 | ||
132 | GNUNET_snprintf(tmp, sizeof(tmp), "%u", i); | 132 | GNUNET_snprintf (tmp, sizeof(tmp), "%u", i); |
133 | json_object_set_new(bigj, tmp, json_string(tmp)); | 133 | json_object_set_new (bigj, tmp, json_string (tmp)); |
134 | } | 134 | } |
135 | str = json_dumps(bigj, JSON_INDENT(2)); | 135 | str = json_dumps (bigj, JSON_INDENT (2)); |
136 | slen = strlen(str); | 136 | slen = strlen (str); |
137 | 137 | ||
138 | #ifdef compressBound | 138 | #ifdef compressBound |
139 | dlen = compressBound(slen); | 139 | dlen = compressBound (slen); |
140 | #else | 140 | #else |
141 | dlen = slen + slen / 100 + 20; | 141 | dlen = slen + slen / 100 + 20; |
142 | /* documentation says 100.1% oldSize + 12 bytes, but we | 142 | /* documentation says 100.1% oldSize + 12 bytes, but we |
143 | * should be able to overshoot by more to be safe */ | 143 | * should be able to overshoot by more to be safe */ |
144 | #endif | 144 | #endif |
145 | post_data = GNUNET_malloc(dlen); | 145 | post_data = GNUNET_malloc (dlen); |
146 | if (Z_OK != | 146 | if (Z_OK != |
147 | compress2((Bytef *)post_data, &dlen, (const Bytef *)str, slen, 9)) | 147 | compress2 ((Bytef *) post_data, &dlen, (const Bytef *) str, slen, 9)) |
148 | { | 148 | { |
149 | GNUNET_break(0); | 149 | GNUNET_break (0); |
150 | MHD_stop_daemon(daemon); | 150 | MHD_stop_daemon (daemon); |
151 | json_decref(bigj); | 151 | json_decref (bigj); |
152 | GNUNET_free(post_data); | 152 | GNUNET_free (post_data); |
153 | GNUNET_free(str); | 153 | GNUNET_free (str); |
154 | return 1; | 154 | return 1; |
155 | } | 155 | } |
156 | post_data_size = (long)dlen; | 156 | post_data_size = (long) dlen; |
157 | port = MHD_get_daemon_info(daemon, MHD_DAEMON_INFO_BIND_PORT)->port; | 157 | port = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT)->port; |
158 | easy = curl_easy_init(); | 158 | easy = curl_easy_init (); |
159 | GNUNET_asprintf(&url, "http://localhost:%u/", (unsigned int)port); | 159 | GNUNET_asprintf (&url, "http://localhost:%u/", (unsigned int) port); |
160 | curl_easy_setopt(easy, CURLOPT_VERBOSE, 0); | 160 | curl_easy_setopt (easy, CURLOPT_VERBOSE, 0); |
161 | curl_easy_setopt(easy, CURLOPT_URL, url); | 161 | curl_easy_setopt (easy, CURLOPT_URL, url); |
162 | curl_easy_setopt(easy, CURLOPT_POST, 1); | 162 | curl_easy_setopt (easy, CURLOPT_POST, 1); |
163 | curl_easy_setopt(easy, CURLOPT_POSTFIELDS, post_data); | 163 | curl_easy_setopt (easy, CURLOPT_POSTFIELDS, post_data); |
164 | curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE, post_data_size); | 164 | curl_easy_setopt (easy, CURLOPT_POSTFIELDSIZE, post_data_size); |
165 | 165 | ||
166 | json_header = curl_slist_append(NULL, "Content-Type: application/json"); | 166 | json_header = curl_slist_append (NULL, "Content-Type: application/json"); |
167 | json_header = curl_slist_append(json_header, "Content-Encoding: deflate"); | 167 | json_header = curl_slist_append (json_header, "Content-Encoding: deflate"); |
168 | curl_easy_setopt(easy, CURLOPT_HTTPHEADER, json_header); | 168 | curl_easy_setopt (easy, CURLOPT_HTTPHEADER, json_header); |
169 | if (0 != curl_easy_perform(easy)) | 169 | if (0 != curl_easy_perform (easy)) |
170 | { | 170 | { |
171 | GNUNET_break(0); | 171 | GNUNET_break (0); |
172 | MHD_stop_daemon(daemon); | 172 | MHD_stop_daemon (daemon); |
173 | GNUNET_free(url); | 173 | GNUNET_free (url); |
174 | json_decref(bigj); | 174 | json_decref (bigj); |
175 | GNUNET_free(post_data); | 175 | GNUNET_free (post_data); |
176 | GNUNET_free(str); | 176 | GNUNET_free (str); |
177 | curl_slist_free_all(json_header); | 177 | curl_slist_free_all (json_header); |
178 | curl_easy_cleanup(easy); | 178 | curl_easy_cleanup (easy); |
179 | return 1; | 179 | return 1; |
180 | } | 180 | } |
181 | MHD_stop_daemon(daemon); | 181 | MHD_stop_daemon (daemon); |
182 | GNUNET_free(url); | 182 | GNUNET_free (url); |
183 | json_decref(bigj); | 183 | json_decref (bigj); |
184 | GNUNET_free(post_data); | 184 | GNUNET_free (post_data); |
185 | GNUNET_free(str); | 185 | GNUNET_free (str); |
186 | curl_slist_free_all(json_header); | 186 | curl_slist_free_all (json_header); |
187 | curl_easy_cleanup(easy); | 187 | curl_easy_cleanup (easy); |
188 | return global_ret; | 188 | return global_ret; |
189 | } | 189 | } |
190 | 190 | ||