diff options
Diffstat (limited to 'src/json/json_generator.c')
-rw-r--r-- | src/json/json_generator.c | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index 98f7163bc..96f07bdc2 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | 8 | or (at your option) any later version. | |
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 9 | |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | You should have received a copy of the GNU General Public License along with | 13 | Affero General Public License for more details. |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 14 | |
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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file json/json_generator.c | 19 | * @file json/json_generator.c |
@@ -155,5 +157,60 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) | |||
155 | return ret; | 157 | return ret; |
156 | } | 158 | } |
157 | 159 | ||
160 | /** | ||
161 | * Convert Gns record to JSON. | ||
162 | * | ||
163 | * @param rname name of record | ||
164 | * @param rd record data | ||
165 | * @return corresponding JSON encoding | ||
166 | */ | ||
167 | json_t * | ||
168 | GNUNET_JSON_from_gns_record (const char* rname, | ||
169 | const struct GNUNET_GNSRECORD_Data *rd) | ||
170 | { | ||
171 | struct GNUNET_TIME_Absolute expiration_time; | ||
172 | const char *expiration_time_str; | ||
173 | const char *record_type_str; | ||
174 | char *value_str; | ||
175 | json_t *ret; | ||
176 | int flags; | ||
177 | |||
178 | value_str = GNUNET_GNSRECORD_value_to_string(rd->record_type,rd->data,rd->data_size); | ||
179 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time(1, rd); | ||
180 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string(expiration_time); | ||
181 | flags = (int)rd->flags; //maybe necessary | ||
182 | record_type_str = GNUNET_GNSRECORD_number_to_typename(rd->record_type); | ||
183 | |||
184 | // ? for possible NULL values | ||
185 | if (NULL != rname) | ||
186 | { | ||
187 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i,s:s?}", | ||
188 | "value", | ||
189 | value_str, | ||
190 | "record_type", | ||
191 | record_type_str, | ||
192 | "expiration_time", | ||
193 | expiration_time_str, | ||
194 | "flag", | ||
195 | flags, | ||
196 | "record_name", | ||
197 | rname); | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | ret = json_pack ("{s:s?,s:s?,s:s?,s:i}", | ||
202 | "value", | ||
203 | value_str, | ||
204 | "record_type", | ||
205 | record_type_str, | ||
206 | "expiration_time", | ||
207 | expiration_time_str, | ||
208 | "flag", | ||
209 | flags); | ||
210 | } | ||
211 | GNUNET_free_non_null(value_str); | ||
212 | return ret; | ||
213 | } | ||
214 | |||
158 | 215 | ||
159 | /* End of json/json_generator.c */ | 216 | /* End of json/json_generator.c */ |