From 447aea0323133e11156f1081d48ba63cf5666935 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
Date: Thu, 15 Oct 2015 18:23:57 +0200
Subject: [PATCH] fixed some bugs in the NGSI rewrite

---
 server/src/ngsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/server/src/ngsi.c b/server/src/ngsi.c
index 015959753..91cac8d10 100644
--- a/server/src/ngsi.c
+++ b/server/src/ngsi.c
@@ -282,7 +282,7 @@ static int ngsi_parse_context_response(json_t *response, int *code, char **reaso
 	int ret;
 	char *codestr;
 	 
-	ret = json_unpack(response, "{ s: [ { s: o, s: { s: s, s: s } } ] }",
+	ret = json_unpack(response, "{ s: [ { s: O, s: { s: s, s: s } } ] }",
 		"contextResponses",
 			"contextElement", rentity,
 			"statusCode",
@@ -299,7 +299,7 @@ static int ngsi_parse_context_response(json_t *response, int *code, char **reaso
 	if (*code != 200)
 		warn("NGSI response: %s %s", codestr, *reason);
 
-	return 0;
+	return ret;
 }
 
 static size_t ngsi_request_writer(void *contents, size_t size, size_t nmemb, void *userp)
@@ -359,7 +359,7 @@ static int ngsi_request(CURL *handle, const char *endpoint, const char *operatio
 out:	free(post);
 	free(chunk.data);
 
-	return 0;
+	return ret;
 }
 
 static int ngsi_request_context_query(CURL *handle, const char *endpoint, json_t *entity, json_t **rentity)
@@ -371,7 +371,7 @@ static int ngsi_request_context_query(CURL *handle, const char *endpoint, json_t
 	json_t *request = json_pack("{ s: [ o ] }", "entities", entity);
 
 	ret = ngsi_request(handle, endpoint, "queryContext", request, &response);
-	if (ret < 0)
+	if (ret)
 		goto out;
 	
 	ret = ngsi_parse_context_response(response, &code, &reason, rentity);
@@ -557,10 +557,10 @@ int ngsi_read(struct node *n, struct msg *pool, int poolsize, int first, int cnt
 	if (ret)
 		goto out2;
 	
-out2:	json_decref(entity);
-out:	json_decref(rentity);
+out2:	json_decref(rentity);
+out:	json_decref(entity);
 
-	return ret ? 0 : cnt;
+	return ret;
 }
 
 int ngsi_write(struct node *n, struct msg *pool, int poolsize, int first, int cnt)