-fix off-by-1
[oweals/gnunet.git] / src / jsonapi / jsonapi_error.c
index d91f0a650d885ffcec8f846b7a39d43d37d84f2b..8ce71d26f90a56f48ca0db6b85e999aad03cd5d2 100644 (file)
@@ -131,6 +131,42 @@ parse_jsonapierror (void *cls,
   return GNUNET_OK;
 }
 
+/**
+ * Create a JSON API error
+ *
+ * @param res the JSON error
+ */
+struct GNUNET_JSONAPI_Error*
+GNUNET_JSONAPI_error_new (const char *id,
+                          const char *status,
+                          const char *code,
+                          const char *title,
+                          const char *detail,
+                          json_t *links,
+                          json_t *source,
+                          json_t *meta)
+{
+  struct GNUNET_JSONAPI_Error *error;
+  error = GNUNET_new (struct GNUNET_JSONAPI_Error);
+
+  if (NULL != id)
+    error->id = GNUNET_strdup (id);
+  if (NULL != status)
+    error->status = GNUNET_strdup (status);
+  if (NULL != code)
+    error->code = GNUNET_strdup (code);
+  if (NULL != title)
+    error->title = GNUNET_strdup (title);
+  if (NULL != detail)
+    error->detail = GNUNET_strdup (detail);
+  if (NULL != links)
+    error->links = json_deep_copy (links);
+  if (NULL != source)
+    error->source = json_deep_copy (source);
+  if (NULL != meta)
+    error->meta = json_deep_copy (meta);
+  return error;
+}
 /**
  * Delete a JSON API error
  *