Browse Source

- more dep fixes

Martin Schanzenbach 3 years ago
parent
commit
cd1c45b00a

+ 1 - 1
po/POTFILES.in

@@ -185,6 +185,7 @@ src/gnsrecord/gnsrecord_crypto.c
 src/gnsrecord/gnsrecord_misc.c
 src/gnsrecord/gnsrecord_serialization.c
 src/gnsrecord/gnunet-gnsrecord-tvg.c
+src/gnsrecord/json_gnsrecord.c
 src/gnsrecord/plugin_gnsrecord_dns.c
 src/hello/address.c
 src/hello/gnunet-hello.c
@@ -201,7 +202,6 @@ src/identity/identity_api_suffix_lookup.c
 src/identity/plugin_rest_identity.c
 src/json/json.c
 src/json/json_generator.c
-src/json/json_gnsrecord.c
 src/json/json_helper.c
 src/json/json_mhd.c
 src/my/my.c

+ 1 - 0
src/gns/Makefile.am

@@ -109,6 +109,7 @@ libgnunet_plugin_rest_gns_la_SOURCES = \
   plugin_rest_gns.c
 libgnunet_plugin_rest_gns_la_LIBADD = \
   $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+  $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \
   libgnunetgns.la \
   $(top_builddir)/src/rest/libgnunetrest.la \
   $(top_builddir)/src/identity/libgnunetidentity.la \

+ 2 - 1
src/gns/plugin_rest_gns.c

@@ -28,6 +28,7 @@
 #include "gnunet_rest_lib.h"
 #include "gnunet_json_lib.h"
 #include "gnunet_gnsrecord_lib.h"
+#include "gnunet_gnsrecord_json_lib.h"
 #include "gnunet_gns_service.h"
 #include "microhttpd.h"
 #include <jansson.h>
@@ -264,7 +265,7 @@ handle_gns_response (void *cls,
     return;
   }
 
-  result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count);
+  result_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (handle->name, rd, rd_count);
 
   result = json_dumps (result_obj, 0);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);

+ 13 - 1
src/gnsrecord/Makefile.am

@@ -30,7 +30,8 @@ TESTS = \
 endif
 
 lib_LTLIBRARIES = \
-  libgnunetgnsrecord.la
+  libgnunetgnsrecord.la \
+  libgnunetgnsrecordjson.la
 
 gnunet_gnsrecord_tvg_SOURCES = \
  gnunet-gnsrecord-tvg.c
@@ -56,6 +57,17 @@ libgnunetgnsrecord_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS)  \
   -version-info 0:0:0
 
+libgnunetgnsrecordjson_la_SOURCES = \
+  json_gnsrecord.c
+libgnunetgnsrecordjson_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
+  libgnunetgnsrecord.la \
+  -ljansson \
+  $(GN_LIBINTL)
+libgnunetgnsrecordjson_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS)  \
+  -version-info 0:0:0
 
 plugin_LTLIBRARIES = \
   libgnunet_plugin_gnsrecord_dns.la

+ 113 - 1
src/json/json_gnsrecord.c → src/gnsrecord/json_gnsrecord.c

@@ -26,6 +26,7 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_json_lib.h"
+#include "gnunet_gnsrecord_lib.h"
 
 #define GNUNET_JSON_GNSRECORD_VALUE "value"
 #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data"
@@ -258,7 +259,7 @@ clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec)
  * @return JSON Specification
  */
 struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
+GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
                             unsigned int *rd_count,
                             char **name)
 {
@@ -277,3 +278,114 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
                                            .size_ptr = NULL };
   return ret;
 }
+
+
+/**
+ * Convert GNS record to JSON.
+ *
+ * @param rname name of record
+ * @param rd record data
+ * @return corresponding JSON encoding
+ */
+json_t *
+GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname,
+                            const struct GNUNET_GNSRECORD_Data *rd,
+                            unsigned int rd_count)
+{
+  struct GNUNET_TIME_Absolute abs_exp;
+  struct GNUNET_TIME_Relative rel_exp;
+  const char *expiration_time_str;
+  const char *record_type_str;
+  char *value_str;
+  json_t *data;
+  json_t *record;
+  json_t *records;
+
+  data = json_object ();
+  if (NULL == data)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  if (0 !=
+      json_object_set_new (data,
+                           "record_name",
+                           json_string (rname)))
+  {
+    GNUNET_break (0);
+    json_decref (data);
+    return NULL;
+  }
+  records = json_array ();
+  if (NULL == records)
+  {
+    GNUNET_break (0);
+    json_decref (data);
+    return NULL;
+  }
+  for (int i = 0; i < rd_count; i++)
+  {
+    value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
+                                                  rd[i].data,
+                                                  rd[i].data_size);
+    if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
+    {
+      rel_exp.rel_value_us = rd[i].expiration_time;
+      expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
+                                                                    GNUNET_NO);
+    }
+    else
+    {
+      abs_exp.abs_value_us = rd[i].expiration_time;
+      expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
+    }
+    record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Packing %s %s %s %d\n",
+                value_str, record_type_str, expiration_time_str, rd[i].flags);
+    record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
+                        "value",
+                        value_str,
+                        "record_type",
+                        record_type_str,
+                        "expiration_time",
+                        expiration_time_str,
+                        "private",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
+                        "relative_expiration",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
+                        "supplemental",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
+                        "shadow",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
+    GNUNET_free (value_str);
+    if (NULL == record)
+    {
+      GNUNET_break (0);
+      json_decref (records);
+      json_decref (data);
+      return NULL;
+    }
+    if (0 !=
+        json_array_append_new (records,
+                               record))
+    {
+      GNUNET_break (0);
+      json_decref (records);
+      json_decref (data);
+      return NULL;
+    }
+  }
+  if (0 !=
+      json_object_set_new (data,
+                           "data",
+                           records))
+  {
+    GNUNET_break (0);
+    json_decref (data);
+    return NULL;
+  }
+  return data;
+}
+
+

+ 0 - 25
src/include/gnunet_json_lib.h

@@ -28,7 +28,6 @@
 #define GNUNET_JSON_LIB_H
 
 #include "gnunet_util_lib.h"
-#include "gnunet_gnsrecord_lib.h"
 #include <jansson.h>
 #include <microhttpd.h>
 
@@ -359,18 +358,6 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
                                 struct GNUNET_CRYPTO_RsaSignature **sig);
 
 
-/**
- * JSON Specification for GNS Records.
- *
- * @param gnsrecord_object struct of GNUNET_GNSRECORD_Data to fill
- * @return JSON Specification
- */
-struct GNUNET_JSON_Specification
-GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd,
-                            unsigned int *rd_count,
-                            char **name);
-
-
 /* ****************** Generic generator interface ******************* */
 
 
@@ -446,18 +433,6 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk);
 json_t *
 GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig);
 
-/**
- * Convert Gns record to JSON.
- *
- * @param rname name of record
- * @param rd record data
- * @return corresponding JSON encoding
- */
-json_t *
-GNUNET_JSON_from_gnsrecord (const char *rname,
-                            const struct GNUNET_GNSRECORD_Data *rd,
-                            unsigned int rd_count);
-
 /* ******************* Helpers for MHD upload handling ******************* */
 
 /**

+ 2 - 5
src/json/Makefile.am

@@ -18,18 +18,15 @@ libgnunetjson_la_SOURCES = \
   json.c \
   json_mhd.c \
   json_generator.c \
-  json_helper.c \
-  json_gnsrecord.c
+  json_helper.c
 libgnunetjson_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
   -ljansson \
   $(MHD_LIBS) \
   $(XLIB) \
   $(Z_LIBS)
 libgnunetjson_la_DEPENDENCIES = \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la
+  $(top_builddir)/src/util/libgnunetutil.la
 
 
 check_PROGRAMS = \

+ 0 - 108
src/json/json_generator.c

@@ -201,113 +201,5 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
 }
 
 
-/**
- * Convert GNS record to JSON.
- *
- * @param rname name of record
- * @param rd record data
- * @return corresponding JSON encoding
- */
-json_t *
-GNUNET_JSON_from_gnsrecord (const char*rname,
-                            const struct GNUNET_GNSRECORD_Data *rd,
-                            unsigned int rd_count)
-{
-  struct GNUNET_TIME_Absolute abs_exp;
-  struct GNUNET_TIME_Relative rel_exp;
-  const char *expiration_time_str;
-  const char *record_type_str;
-  char *value_str;
-  json_t *data;
-  json_t *record;
-  json_t *records;
-
-  data = json_object ();
-  if (NULL == data)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  if (0 !=
-      json_object_set_new (data,
-                           "record_name",
-                           json_string (rname)))
-  {
-    GNUNET_break (0);
-    json_decref (data);
-    return NULL;
-  }
-  records = json_array ();
-  if (NULL == records)
-  {
-    GNUNET_break (0);
-    json_decref (data);
-    return NULL;
-  }
-  for (int i = 0; i < rd_count; i++)
-  {
-    value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
-                                                  rd[i].data,
-                                                  rd[i].data_size);
-    if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
-    {
-      rel_exp.rel_value_us = rd[i].expiration_time;
-      expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
-                                                                    GNUNET_NO);
-    }
-    else
-    {
-      abs_exp.abs_value_us = rd[i].expiration_time;
-      expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
-    }
-    record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Packing %s %s %s %d\n",
-                value_str, record_type_str, expiration_time_str, rd[i].flags);
-    record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
-                        "value",
-                        value_str,
-                        "record_type",
-                        record_type_str,
-                        "expiration_time",
-                        expiration_time_str,
-                        "private",
-                        rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
-                        "relative_expiration",
-                        rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
-                        "supplemental",
-                        rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
-                        "shadow",
-                        rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
-    GNUNET_free (value_str);
-    if (NULL == record)
-    {
-      GNUNET_break (0);
-      json_decref (records);
-      json_decref (data);
-      return NULL;
-    }
-    if (0 !=
-        json_array_append_new (records,
-                               record))
-    {
-      GNUNET_break (0);
-      json_decref (records);
-      json_decref (data);
-      return NULL;
-    }
-  }
-  if (0 !=
-      json_object_set_new (data,
-                           "data",
-                           records))
-  {
-    GNUNET_break (0);
-    json_decref (data);
-    return NULL;
-  }
-  return data;
-}
-
 
 /* End of json/json_generator.c */

+ 1 - 0
src/namestore/Makefile.am

@@ -131,6 +131,7 @@ libgnunet_plugin_rest_namestore_la_LIBADD = \
   $(top_builddir)/src/identity/libgnunetidentity.la \
   $(top_builddir)/src/json/libgnunetjson.la \
   $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+  $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \
   $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
   $(LTLIBINTL) -ljansson $(MHD_LIBS)
 libgnunet_plugin_rest_namestore_la_LDFLAGS = \

+ 8 - 8
src/namestore/plugin_rest_namestore.c

@@ -30,7 +30,7 @@
 #include "gnunet_namestore_service.h"
 #include "gnunet_identity_service.h"
 #include "gnunet_rest_lib.h"
-#include "gnunet_json_lib.h"
+#include "gnunet_gnsrecord_json_lib.h"
 #include "microhttpd.h"
 #include <jansson.h>
 
@@ -535,9 +535,9 @@ namestore_list_iteration (void *cls,
   /** Only add if not empty **/
   if (j > 0)
   {
-    record_obj = GNUNET_JSON_from_gnsrecord (rname,
-                                             rd_filtered,
-                                             j);
+    record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname,
+                                                       rd_filtered,
+                                                       j);
     json_array_append_new (handle->resp_object, record_obj);
   }
   GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
@@ -587,9 +587,9 @@ ns_get_lookup_cb (void *cls,
   /** Only add if not empty **/
   if (j > 0)
   {
-    record_obj = GNUNET_JSON_from_gnsrecord (label,
-                                             rd_filtered,
-                                             j);
+    record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
+                                                       rd_filtered,
+                                                       j);
     json_array_append_new (handle->resp_object, record_obj);
   }
   GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle);
@@ -755,7 +755,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle,
                  handle->rest_handle->data_size);
   data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
   struct GNUNET_JSON_Specification gnsspec[] =
-  { GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
+  { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
                                 &handle->record_name),
     GNUNET_JSON_spec_end () };
   if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))