diff options
Diffstat (limited to 'src/json/json_generator.c')
-rw-r--r-- | src/json/json_generator.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index dd6df4f74..d8c82bc86 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -157,5 +157,40 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) | |||
157 | return ret; | 157 | return ret; |
158 | } | 158 | } |
159 | 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 | ret = json_pack("{s:s?,s:s?,s:s?,s:i,s:s?}", | ||
186 | "value", value_str, | ||
187 | "type", record_type_str, | ||
188 | "expiration_time", expiration_time_str, | ||
189 | "flag", flags, | ||
190 | "label", rname); | ||
191 | GNUNET_free_non_null(value_str); | ||
192 | return ret; | ||
193 | } | ||
194 | |||
160 | 195 | ||
161 | /* End of json/json_generator.c */ | 196 | /* End of json/json_generator.c */ |