fix uninit variable causing crash on 0 value
[oweals/gnunet.git] / src / gns / plugin_rest_gns.c
index 718a9b29bb74e06f3cbca6169a84df5e6a942c35..3cddbc2469a2754ab04266bca1201611669fbe5c 100644 (file)
@@ -33,6 +33,7 @@
 #include <gnunet_gns_service.h>
 #include <gnunet_rest_lib.h>
 #include <gnunet_jsonapi_lib.h>
+#include <gnunet_jsonapi_util.h>
 #include <jansson.h>
 
 #define GNUNET_REST_API_NS_GNS "/gns"
@@ -227,7 +228,7 @@ do_error (void *cls)
   struct LookupHandle *handle = cls;
   struct MHD_Response *resp;
 
-  resp = GNUNET_REST_create_json_response (NULL);
+  resp = GNUNET_REST_create_response (NULL);
   handle->proc (handle->proc_cls, resp, handle->response_code);
   cleanup_handle (handle);
 }
@@ -258,7 +259,7 @@ gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
                 (int) rd->record_type);
     return NULL;
   }
-  record_obj = json_object();
+  record_obj = json_object ();
   json_object_set_new (record_obj, "type", json_string (typename));
   json_object_set_new (record_obj, "value", json_string (string_val));
   GNUNET_free (string_val);
@@ -295,7 +296,7 @@ process_lookup_result (void *cls, uint32_t rd_count,
 {
   struct LookupHandle *handle = cls;
   struct MHD_Response *resp;
-  struct GNUNET_JSONAPI_Object *json_object;
+  struct GNUNET_JSONAPI_Document *json_document;
   struct GNUNET_JSONAPI_Resource *json_resource;
   uint32_t i;
   char *result;
@@ -303,7 +304,7 @@ process_lookup_result (void *cls, uint32_t rd_count,
   json_t *record_obj;
 
   result_array = json_array();
-  json_object = GNUNET_JSONAPI_object_new ();
+  json_document = GNUNET_JSONAPI_document_new ();
   json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_GNS_TYPEINFO, handle->name);
   handle->lookup_request = NULL;
   for (i=0; i<rd_count; i++)
@@ -318,12 +319,12 @@ process_lookup_result (void *cls, uint32_t rd_count,
   GNUNET_JSONAPI_resource_add_attr (json_resource,
                                          GNUNET_REST_JSONAPI_GNS_RECORD,
                                          result_array);
-  GNUNET_JSONAPI_object_resource_add (json_object, json_resource);
-  GNUNET_JSONAPI_data_serialize (json_object, &result);
+  GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
+  GNUNET_JSONAPI_document_serialize (json_document, &result);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
   json_decref (result_array);
-  GNUNET_JSONAPI_object_delete (json_object);
-  resp = GNUNET_REST_create_json_response (result);
+  GNUNET_JSONAPI_document_delete (json_document);
+  resp = GNUNET_REST_create_response (result);
   handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
   GNUNET_free (result);
   cleanup_handle (handle);
@@ -639,7 +640,7 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
   struct LookupHandle *handle = cls;
 
   //For GNS, independent of path return all options
-  resp = GNUNET_REST_create_json_response (NULL);
+  resp = GNUNET_REST_create_response (NULL);
   MHD_add_response_header (resp,
                            "Access-Control-Allow-Methods",
                            MHD_HTTP_METHOD_GET);