diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-30 15:56:16 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-30 15:56:16 +0200 |
commit | 342619bf17d389e4305c9ee72b609059706a8023 (patch) | |
tree | 391ff802b3d7389a08947dfb2e2fc816f4013752 /src/json/json_generator.c | |
parent | 57636ddf7839aaeedd14c90afcd28b375ec516a6 (diff) | |
download | gnunet-342619bf17d389e4305c9ee72b609059706a8023.tar.gz gnunet-342619bf17d389e4305c9ee72b609059706a8023.zip |
REST/NAMESTORE: rework API
Diffstat (limited to 'src/json/json_generator.c')
-rw-r--r-- | src/json/json_generator.c | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index 0b25013e3..de6898da6 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -160,58 +160,56 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) | |||
160 | } | 160 | } |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Convert Gns record to JSON. | 163 | * Convert GNS record to JSON. |
164 | * | 164 | * |
165 | * @param rname name of record | 165 | * @param rname name of record |
166 | * @param rd record data | 166 | * @param rd record data |
167 | * @return corresponding JSON encoding | 167 | * @return corresponding JSON encoding |
168 | */ | 168 | */ |
169 | json_t * | 169 | json_t * |
170 | GNUNET_JSON_from_gns_record (const char* rname, | 170 | GNUNET_JSON_from_gnsrecord (const char* rname, |
171 | const struct GNUNET_GNSRECORD_Data *rd) | 171 | const struct GNUNET_GNSRECORD_Data *rd, |
172 | unsigned int rd_count) | ||
172 | { | 173 | { |
173 | struct GNUNET_TIME_Absolute expiration_time; | 174 | struct GNUNET_TIME_Absolute expiration_time; |
174 | const char *expiration_time_str; | 175 | const char *expiration_time_str; |
175 | const char *record_type_str; | 176 | const char *record_type_str; |
176 | char *value_str; | 177 | char *value_str; |
177 | json_t *ret; | 178 | json_t *data; |
178 | int flags; | 179 | json_t *record; |
179 | 180 | json_t *records; | |
180 | value_str = GNUNET_GNSRECORD_value_to_string(rd->record_type,rd->data,rd->data_size); | 181 | |
181 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time(1, rd); | 182 | data = json_object (); |
182 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string(expiration_time); | 183 | json_object_set_new (data, |
183 | flags = (int)rd->flags; //maybe necessary | 184 | "record_name", |
184 | record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type); | 185 | json_string (rname)); |
185 | 186 | records = json_array (); | |
186 | // ? for possible NULL values | 187 | for (int i = 0; i < rd_count; i++) |
187 | if (NULL != rname) | ||
188 | { | 188 | { |
189 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i,s:s?}", | 189 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
190 | "value", | 190 | rd[i].data, |
191 | value_str, | 191 | rd[i].data_size); |
192 | "record_type", | 192 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time(1, &rd[i]); |
193 | record_type_str, | 193 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (expiration_time); |
194 | "expiration_time", | 194 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
195 | expiration_time_str, | 195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
196 | "flag", | 196 | "Packing %s %s %s %d\n", |
197 | flags, | 197 | value_str, record_type_str, expiration_time_str, rd[i].flags); |
198 | "record_name", | 198 | record = json_pack ("{s:s,s:s,s:s,s:i}", |
199 | rname); | 199 | "value", |
200 | value_str, | ||
201 | "record_type", | ||
202 | record_type_str, | ||
203 | "expiration_time", | ||
204 | expiration_time_str, | ||
205 | "flag", | ||
206 | rd[i].flags); | ||
207 | GNUNET_assert (NULL != record); | ||
208 | GNUNET_free (value_str); | ||
209 | json_array_append_new (records, record); | ||
200 | } | 210 | } |
201 | else | 211 | json_object_set_new (data, "data", records); |
202 | { | 212 | return data; |
203 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i}", | ||
204 | "value", | ||
205 | value_str, | ||
206 | "record_type", | ||
207 | record_type_str, | ||
208 | "expiration_time", | ||
209 | expiration_time_str, | ||
210 | "flag", | ||
211 | flags); | ||
212 | } | ||
213 | GNUNET_free_non_null(value_str); | ||
214 | return ret; | ||
215 | } | 213 | } |
216 | 214 | ||
217 | 215 | ||