Преглед на файлове

lost: error response fix in lost_function(), lost_held_dereference() and lost_held_function()

- error variable was set to 0 (clean up) before return. Lost functions now returns 500
  in case of LOST/HELD server error, or 400 in case of internal error, otherwise 2xx.

(cherry picked from commit 201c219a5496924e701cc2b17fb0a439ee530813)
Wolfgang Kampichler преди 4 години
родител
ревизия
3914325514
променени са 3 файла, в които са добавени 64 реда и са изтрити 6 реда
  1. 29 6
      src/modules/lost/functions.c
  2. 30 0
      src/modules/lost/response.c
  3. 5 0
      src/modules/lost/response.h

+ 29 - 6
src/modules/lost/functions.c

@@ -211,6 +211,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	int flag = 0;
 	int naptr = 0;
 	int presence = 0;
+	int res_error = 0;
 
 	if(_pidf == NULL || _url == NULL || _err == NULL) {
 		LM_ERR("invalid parameter\n");
@@ -505,6 +506,10 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	psurl->setf(_m, &psurl->pvp, (int)EQ_T, &pvurl);
 	lost_free_string(&geo); /* clean up */
  
+ 	/* return error code in case of response error */
+	if(err.len > 0) {
+		res_error = 1;
+	}
 	pverr.rs = err;
 	pverr.rs.s = err.s;
 	pverr.rs.len = err.len;
@@ -514,7 +519,7 @@ int lost_held_function(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 	pserr->setf(_m, &pserr->pvp, (int)EQ_T, &pverr);
 	lost_free_string(&err); /* clean up */
 
-	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
+	return (res_error > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
 
 err:
 	/* clean up pointer */
@@ -574,6 +579,7 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
 	int len = 0;
 	int curl = 0;
 	int exact = 0;
+	int ret = LOST_SUCCESS;
 
 	if(_url == NULL || _rtime == NULL || _pidf == NULL || _rtype == NULL
 			|| _err == NULL) {
@@ -709,12 +715,20 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
 		goto err;
 	}
 
-	/* check the root element ... shall be locationResponse, or error */
-	if(xmlStrcmp(root->name, (const xmlChar *)"presence") == 0) {
+	/* check root element ... shall be presence|locationResponse, or error */
+	if((!xmlStrcmp(root->name, (const xmlChar *)"presence"))
+			|| (!xmlStrcmp(root->name, (const xmlChar *)"locationResponse"))) {
 
 		LM_DBG("HELD location response [%.*s]\n", res.len, res.s);
 
-		/* error received */
+		/* check content and set response code
+		 * + 0 nothing found: return 200
+		 * + 1 value found: return 201
+		 * + 2 reference found: return 202
+		 * + 3 value and reference found: return 203
+		 */
+		ret += lost_check_HeldResponse(root);
+	/* error received */
 	} else if(xmlStrcmp(root->name, (const xmlChar *)"error") == 0) {
 
 		LM_DBG("HELD error response [%.*s]\n", res.len, res.s);
@@ -745,6 +759,10 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
 	pspidf->setf(_m, &pspidf->pvp, (int)EQ_T, &pvpidf);
 	lost_free_string(&res); /* clean up */
 
+	/* return error code in case of response error */
+	if(err.len > 0) {
+		ret = LOST_SERVER_ERROR;
+	}
 	pverr.rs = err;
 	pverr.rs.s = err.s;
 	pverr.rs.len = err.len;
@@ -754,7 +772,7 @@ int lost_held_dereference(struct sip_msg *_m, char *_url, char *_pidf,
 	pserr->setf(_m, &pserr->pvp, (int)EQ_T, &pverr);
 	lost_free_string(&err); /* clean up */
 
-	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
+	return ret;
 
 err:
 	/* clean up xml */
@@ -822,6 +840,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	int len = 0;
 	int naptr = 0;
 	int geoitems = 0;
+	int res_error = 0;
 
 	if(_con == NULL || _uri == NULL || _name == NULL || _err == NULL) {
 		LM_ERR("invalid parameter\n");
@@ -1253,6 +1272,10 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	psuri->setf(_m, &psuri->pvp, (int)EQ_T, &pvuri);
 	lost_free_string(&uri); /* clean up */
 
+	/* return error code in case of response error */
+	if(err.len > 0) {
+		res_error = 1;
+	}
 	pverr.rs = err;
 	pverr.rs.s = err.s;
 	pverr.rs.len = err.len;
@@ -1262,7 +1285,7 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 	pserr->setf(_m, &pserr->pvp, (int)EQ_T, &pverr);
 	lost_free_string(&err); /* clean up */
 
-	return (err.len > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
+	return (res_error > 0) ? LOST_SERVER_ERROR : LOST_SUCCESS;
 
 err:
 	/* clean up */

+ 30 - 0
src/modules/lost/response.c

@@ -1000,4 +1000,34 @@ p_lost_fsr_t lost_parse_findServiceResponse(str ret)
 	xmlFreeDoc(doc); /* clean up */
 
 	return res;
+}
+
+/*
+ * lost_check_HeldResponse(node)
+ * does a quick check of HELD dereference response and returns ...
+ * 0: neither location value nor reference found
+ * 1: location value found
+ * 2: location reference found
+ * 3: location value and reference found
+ * multiple occurences are ignored
+ */
+int lost_check_HeldResponse(xmlNodePtr node)
+{
+	char *tmp = NULL;
+
+	int ret = 0; /* response error */
+
+	tmp = xmlNodeGetNodeContentByName(node, "location-info", NULL);
+	if(tmp != NULL) {
+		ret += HELD_RESPONSE_VALUE; /* LocByVal: civic or geodetic */
+	}
+	xmlFree(tmp); /* clean up */
+
+	tmp = xmlNodeGetNodeContentByName(node, "locationURI", NULL);
+	if(tmp != NULL) {
+		ret += HELD_RESPONSE_REFERENCE; /* LocByRef: reference */
+	}
+	xmlFree(tmp); /* clean up */
+
+	return ret;
 }

+ 5 - 0
src/modules/lost/response.h

@@ -56,6 +56,9 @@
 
 #define ERRORS_NODE (const char *)"errors"
 
+#define HELD_RESPONSE_VALUE 1
+#define HELD_RESPONSE_REFERENCE 2
+
 typedef struct lost_list
 {
 	char *value;
@@ -114,6 +117,8 @@ typedef struct lost_fsr
 
 /* read and parse response data */
 p_lost_fsr_t lost_parse_findServiceResponse(str);
+/* check response to dereferece request */
+int lost_check_HeldResponse(xmlNodePtr); 
 /* print the response */
 void lost_print_findServiceResponse(p_lost_fsr_t);
 /* remove response data from memory */