lost: adds HELD (RFC6155) and LOST (RFC5222) queries for location-based routing
authorwkampich <wolfgang.kampichler@gmail.com>
Wed, 14 Aug 2019 18:22:04 +0000 (20:22 +0200)
committerHenning Westerholt <hw@skalatan.de>
Fri, 16 Aug 2019 06:04:03 +0000 (08:04 +0200)
- code review, updates to memory managment and error handling

src/modules/lost/functions.c
src/modules/lost/lost.c
src/modules/lost/pidf.c
src/modules/lost/pidf.h
src/modules/lost/utilities.c
src/modules/lost/utilities.h

index b7380dd..3686402 100644 (file)
@@ -84,6 +84,8 @@ int lost_function_held(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
        str res = {NULL, 0};\r
        str idhdr = {NULL, 0};\r
 \r
+       int curlres = 0;\r
+\r
        if(_con == NULL || _pidf == NULL || _url == NULL || _err == NULL) {\r
                LM_ERR("invalid parameter\n");\r
                goto err;\r
@@ -129,12 +131,9 @@ int lost_function_held(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
        /* assemble locationRequest */\r
        que.s = lost_held_location_request(did.s, &que.len);\r
        /* free memory */\r
-       if(idhdr.s) {\r
-               pkg_free(idhdr.s);\r
-               idhdr.len = 0;\r
-               did.s = NULL;\r
-               did.len = 0;\r
-       }\r
+       lost_free_string(&idhdr);\r
+       did.s = NULL;\r
+       did.len = 0;\r
        if(!que.s) {\r
                LM_ERR("held request document error\n");\r
                goto err;\r
@@ -143,10 +142,19 @@ int lost_function_held(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
        LM_DBG("held location request: \n[%s]\n", que.s);\r
 \r
        /* send locationRequest to location server - HTTP POST */\r
-       httpapi.http_connect(_m, &con, NULL, &res, mtheld, &que);\r
+       curlres = httpapi.http_connect(_m, &con, NULL, &res, mtheld, &que);\r
+       /* only HTTP 2xx responses are accepted */ \r
+       if(curlres >= 300 || curlres < 100) {\r
+               LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curlres);\r
+               res.s = NULL;\r
+               res.len = 0;\r
+               goto err;\r
+       }\r
+\r
+       LM_DBG("[%.*s] returned: %d\n", con.len, con.s, curlres);\r
+\r
        /* free memory */\r
-       pkg_free(que.s);\r
-       que.len = 0;\r
+       lost_free_string(&que);\r
        /* read and parse the returned xml */\r
        doc = xmlReadMemory(res.s, res.len, 0, NULL,\r
                        XML_PARSE_RECOVER | XML_PARSE_NOBLANKS | XML_PARSE_NONET\r
@@ -159,6 +167,7 @@ int lost_function_held(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
                                        res.s);\r
                        goto err;\r
                }\r
+\r
                LM_DBG("xml document recovered\n");\r
        }\r
        root = xmlDocGetRootElement(doc);\r
@@ -225,6 +234,10 @@ int lost_function_held(struct sip_msg *_m, char *_con, char *_pidf, char *_url,
 err:\r
        if(doc)\r
                xmlFreeDoc(doc);\r
+       \r
+       lost_free_string(&idhdr);\r
+       lost_free_string(&que);\r
+\r
        return LOST_CLIENT_ERROR;\r
 }\r
 \r
@@ -255,13 +268,15 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
        str con = {NULL, 0};\r
        str ret = {NULL, 0};\r
        str geo = {NULL, 0};\r
+       str geohdr = {NULL, 0};\r
        str name = {NULL, 0};\r
        str pidf = {NULL, 0};\r
-       str pidf_h = {NULL, 0};\r
+       str pidfhdr = {NULL, 0};\r
 \r
-       char *search = NULL;\r
        struct msg_start *fl;\r
-\r
+       char *search = NULL;\r
+       int curlres = 0;\r
+       \r
        if(_con == NULL || _uri == NULL || _name == NULL || _err == NULL) {\r
                LM_ERR("invalid parameter\n");\r
                goto err;\r
@@ -310,13 +325,13 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
        /* pidf from geolocation header */\r
        if(pidf.len == 0) {\r
                LM_WARN("no pidf parameter, trying Geolocation header ...\n");\r
-               geo.s = lost_get_geolocation_header(_m, &geo.len);\r
-               if(!geo.s) {\r
+               geohdr.s = lost_get_geolocation_header(_m, &geohdr.len);\r
+               if(!geohdr.s) {\r
                        LM_ERR("geolocation header not found\n");\r
                        goto err;\r
                } else {\r
                        /* pidf from multipart body, check cid scheme */\r
-                       search = geo.s;\r
+                       search = geohdr.s;\r
                        if((*(search + 0) == '<')\r
                                        && ((*(search + 1) == 'c') || (*(search + 1) == 'C'))\r
                                        && ((*(search + 2) == 'i') || (*(search + 2) == 'I'))\r
@@ -343,25 +358,38 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
                                        && ((*(search + 2) == 't') || (*(search + 2) == 'T'))\r
                                        && ((*(search + 3) == 'p') || (*(search + 3) == 'P'))\r
                                        && (*(search + 4) == ':')) {\r
+                               geo.s = geohdr.s;\r
+                               geo.len = geohdr.len;\r
 \r
                                LM_DBG("url: \n[%.*s]\n", geo.len, geo.s);\r
 \r
                                /* ! dereference pidf.lo at location server - HTTP GET */\r
                                /* ! requires hack in http_client module */\r
                                /* ! functions.c => http_client_query => query_params.oneline = 0; */\r
-                               httpapi.http_client_query(_m, geo.s, &pidf_h, NULL, NULL);\r
-\r
+                               curlres = httpapi.http_client_query(_m, geo.s, &pidfhdr, NULL, NULL);\r
                                /* free memory */\r
-                               pkg_free(geo.s);\r
+                               lost_free_string(&geohdr);\r
+                               geo.s = NULL;\r
                                geo.len = 0;\r
+                               /* only HTTP 2xx responses are accepted */ \r
+                               if(curlres >= 300 || curlres < 100) {\r
+                                       LM_ERR("http GET failed with error: %d\n", curlres);\r
+                                       pidfhdr.s = NULL;\r
+                                       pidfhdr.len = 0;\r
+                                       goto err;\r
+                               }\r
+\r
+                               LM_DBG("http GET returned: %d\n", curlres);\r
 \r
-                               if(!pidf_h.s) {\r
+                               if(!pidfhdr.s) {\r
                                        LM_ERR("dereferencing location failed\n");\r
                                        goto err;\r
                                }\r
-                               pidf.s = pidf_h.s;\r
-                               pidf.len = pidf_h.len;\r
+                               pidf.s = pidfhdr.s;\r
+                               pidf.len = pidfhdr.len;\r
                        }\r
+                       /* free memory */\r
+                       lost_free_string(&geohdr);\r
                }\r
        }\r
 \r
@@ -399,6 +427,10 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
                        || (!xmlStrcmp(root->name, (const xmlChar *)"locationResponse"))) {\r
                /* get the geolocation: point or circle, urn, ... */\r
                loc = lost_new_loc(urn);\r
+               if(!loc) {\r
+                       LM_ERR("location object allocation failed\n");\r
+                       goto err;                       \r
+               }\r
                if(lost_parse_location_info(root, loc) < 0) {\r
                        LM_ERR("location element not found\n");\r
                        goto err;\r
@@ -411,12 +443,9 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
        }\r
 \r
        /* free memory */\r
-       if(pidf_h.s) {\r
-               pkg_free(pidf_h.s);\r
-               pidf_h.len = 0;\r
-               pidf.s = NULL;\r
-               pidf.len = 0;\r
-       }\r
+       lost_free_string(&pidfhdr);\r
+       pidf.s = NULL;\r
+       pidf.len = 0;\r
 \r
        /* check if connection exits */\r
        if(httpapi.http_connection_exists(&con) == 0) {\r
@@ -426,8 +455,12 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
        /* assemble findService request */\r
        res.s = lost_find_service_request(loc, &res.len);\r
        /* free memory */\r
-       lost_free_loc(loc);\r
+       if(loc) {\r
+               lost_free_loc(loc);\r
+               loc = NULL;\r
+       }\r
        xmlFreeDoc(doc);\r
+       doc = NULL;\r
 \r
        if(!res.s) {\r
                LM_ERR("lost request failed\n");\r
@@ -437,9 +470,20 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
        LM_DBG("findService request: \n[%.*s]\n", res.len, res.s);\r
 \r
        /* send findService request to mapping server - HTTP POST */\r
-       httpapi.http_connect(_m, &con, NULL, &ret, mtlost, &res);\r
-       pkg_free(res.s);\r
-       res.len = 0;\r
+       curlres = httpapi.http_connect(_m, &con, NULL, &ret, mtlost, &res);\r
+       /* only HTTP 2xx responses are accepted */ \r
+       if(curlres >= 300 || curlres < 100) {\r
+               LM_ERR("[%.*s] failed with error: %d\n", con.len, con.s, curlres);\r
+               ret.s = NULL;\r
+               ret.len = 0;\r
+               goto err;\r
+       }\r
+\r
+       LM_DBG("[%.*s] returned: %d\n", con.len, con.s, curlres);\r
+\r
+       /* free memory */\r
+       lost_free_string(&res);\r
+\r
        if(!ret.s) {\r
                LM_ERR("findService request failed\n");\r
                goto err;\r
@@ -502,12 +546,10 @@ int lost_function(struct sip_msg *_m, char *_con, char *_uri, char *_name,
 \r
        /* free memory */\r
        xmlFreeDoc(doc);\r
-       if(ret.s) {\r
-               pkg_free(ret.s);\r
-               ret.len = 0;\r
-       }\r
+       doc = NULL;\r
+       lost_free_string(&ret);\r
 \r
-       /* set writeable pvars */\r
+       /* set writable pvars */\r
        pvname.rs = name;\r
        pvname.rs.s = name.s;\r
        pvname.rs.len = name.len;\r
@@ -539,13 +581,10 @@ err:
                lost_free_loc(loc);\r
        if(doc)\r
                xmlFreeDoc(doc);\r
-       if(pidf_h.s) {\r
-               pkg_free(pidf_h.s);\r
-               pidf_h.len = 0;\r
-       }\r
-       if(ret.s) {\r
-               pkg_free(ret.s);\r
-               ret.len = 0;\r
-       }\r
+\r
+       lost_free_string(&pidfhdr);\r
+       lost_free_string(&geohdr);\r
+       lost_free_string(&ret);\r
+\r
        return LOST_CLIENT_ERROR;\r
 }\r
index c4b5e66..5bdba54 100644 (file)
@@ -124,10 +124,6 @@ static int mod_init(void)
 /* Child initialization function */\r
 static int child_init(int rank)\r
 {\r
-       if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN) {\r
-               return 0; /* do nothing for the main process */\r
-       }\r
-\r
        return 0;\r
 }\r
 \r
@@ -152,7 +148,7 @@ static int fixup_lost_held_query(void **param, int param_no)
                        return -1;\r
                }\r
                if(((pv_spec_t *)(*param))->setf == NULL) {\r
-                       LM_ERR("result pvar is not writeble\n");\r
+                       LM_ERR("result pvar is not writable\n");\r
                        return -1;\r
                }\r
                return 0;\r
@@ -195,7 +191,7 @@ static int fixup_lost_held_query_id(void **param, int param_no)
                        return -1;\r
                }\r
                if(((pv_spec_t *)(*param))->setf == NULL) {\r
-                       LM_ERR("result pvar is not writeble\n");\r
+                       LM_ERR("result pvar is not writable\n");\r
                        return -1;\r
                }\r
                return 0;\r
@@ -237,7 +233,7 @@ static int fixup_lost_query(void **param, int param_no)
                        return -1;\r
                }\r
                if(((pv_spec_t *)(*param))->setf == NULL) {\r
-                       LM_ERR("result pvar is not writeble\n");\r
+                       LM_ERR("result pvar is not writable\n");\r
                        return -1;\r
                }\r
                return 0;\r
@@ -279,7 +275,7 @@ static int fixup_lost_query_all(void **param, int param_no)
                        return -1;\r
                }\r
                if(((pv_spec_t *)(*param))->setf == NULL) {\r
-                       LM_ERR("result pvar is not writeble\n");\r
+                       LM_ERR("result pvar is not writable\n");\r
                        return -1;\r
                }\r
                return 0;\r
index e418583..c018313 100755 (executable)
@@ -21,9 +21,6 @@
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
  *\r
- * History:\r
- * --------\r
- *  2007-04-14  initial version (anca)\r
  */\r
 \r
 /*! \file\r
@@ -101,12 +98,9 @@ xmlNodePtr xmlNodeGetNodeByName(
        while(cur) {\r
                xmlNodePtr match = NULL;\r
                if(xmlStrcasecmp(cur->name, (unsigned char *)name) == 0) {\r
-                       if(!ns\r
-                                       || (cur->ns\r
-                                                          && xmlStrcasecmp(\r
-                                                                                 cur->ns->prefix, (unsigned char *)ns)\r
-                                                                                 == 0))\r
-                               return cur;\r
+                       if(!ns || (cur->ns &&\r
+                               xmlStrcasecmp(cur->ns->prefix, (unsigned char *)ns) == 0))\r
+                       return cur;\r
                }\r
                match = xmlNodeGetNodeByName(cur->children, name, ns);\r
                if(match)\r
index e2f62fd..78c5d84 100755 (executable)
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
  *\r
- * History:\r
- * --------\r
- *  2006-08-15  initial version (anca)\r
  */\r
 \r
 /*! \file\r
  * \brief Kamailio Presence_XML :: PIDF handling\r
  * \ref pidf.c\r
- * \ingroup presence_xml\r
+ * \ingroup lost\r
  */\r
 \r
 \r
index 2df1075..78fb45c 100644 (file)
@@ -106,29 +106,40 @@ void lost_free_loc(p_loc_t ptr)
        pkg_free(ptr);\r
 }\r
 \r
+void lost_free_string(str *string)\r
+{\r
+       str ptr = *string;\r
+\r
+       if(ptr.s) {\r
+               pkg_free(ptr.s);\r
+               ptr.s = NULL;\r
+               ptr.len = 0;\r
+       }\r
+}\r
+\r
 /*\r
  * lost_new_loc(urn)\r
  * creates a new location object in private memory and returns a pointer\r
  */\r
 p_loc_t lost_new_loc(str rurn)\r
 {\r
-       s_loc_t *ptr;\r
-       char *id;\r
-       char *urn;\r
+       s_loc_t *ptr = NULL;;\r
+       char *id = NULL;\r
+       char *urn = NULL;\r
 \r
        ptr = (s_loc_t *)pkg_malloc(sizeof(s_loc_t));\r
        if(ptr == NULL) {\r
-               LM_ERR("no more private memory\n");\r
+               goto err;\r
        }\r
 \r
        id = (char *)pkg_malloc(RANDSTRSIZE * sizeof(char) + 1);\r
        if(id == NULL) {\r
-               LM_ERR("no more private memory\n");\r
+               goto err;\r
        }\r
 \r
        urn = (char *)pkg_malloc(rurn.len + 1);\r
        if(urn == NULL) {\r
-               LM_ERR("no more private memory\n");\r
+               goto err;\r
        }\r
 \r
        memset(urn, 0, rurn.len + 1);\r
@@ -145,6 +156,10 @@ p_loc_t lost_new_loc(str rurn)
        ptr->recursive = 0;\r
 \r
        return ptr;\r
+\r
+err:   \r
+       LM_ERR("no more private memory\n");\r
+       return NULL;\r
 }\r
 \r
 /*\r
@@ -156,7 +171,6 @@ char *lost_get_content(xmlNodePtr node, const char *name, int *lgth)
        xmlNodePtr cur = node;\r
        char *content;\r
        char *cnt = NULL;\r
-\r
        int len;\r
 \r
        *lgth = 0;\r
@@ -166,6 +180,7 @@ char *lost_get_content(xmlNodePtr node, const char *name, int *lgth)
        cnt = (char *)pkg_malloc((len + 1) * sizeof(char));\r
        if(cnt == NULL) {\r
                LM_ERR("No more private memory\n");\r
+               return cnt;\r
        }\r
 \r
        memset(cnt, 0, len + 1);\r
@@ -188,7 +203,6 @@ char *lost_get_property(xmlNodePtr node, const char *name, int *lgth)
        xmlNodePtr cur = node;\r
        char *content;\r
        char *cnt = NULL;\r
-\r
        int len;\r
 \r
        *lgth = 0;\r
@@ -198,6 +212,7 @@ char *lost_get_property(xmlNodePtr node, const char *name, int *lgth)
        cnt = (char *)pkg_malloc((len + 1) * sizeof(char));\r
        if(cnt == NULL) {\r
                LM_ERR("No more private memory\n");\r
+               return cnt;\r
        }\r
 \r
        memset(cnt, 0, len + 1);\r
@@ -220,21 +235,19 @@ char *lost_get_childname(xmlNodePtr node, const char *name, int *lgth)
        xmlNodePtr cur = node;\r
        xmlNodePtr parent = NULL;\r
        xmlNodePtr child = NULL;\r
-\r
        char *cnt = NULL;\r
        int len;\r
 \r
        *lgth = 0;\r
-\r
        parent = xmlNodeGetNodeByName(cur, name, NULL);\r
        child = parent->children;\r
 \r
        if(child) {\r
                len = strlen((char *)child->name);\r
-\r
                cnt = (char *)pkg_malloc((len + 1) * sizeof(char));\r
                if(cnt == NULL) {\r
                        LM_ERR("no more private memory\n");\r
+                       return cnt;\r
                }\r
 \r
                memset(cnt, 0, len + 1);\r
@@ -271,6 +284,7 @@ char *lost_get_geolocation_header(struct sip_msg *msg, int *lgth)
                                res = (char *)pkg_malloc((hf->body.len + 1) * sizeof(char));\r
                                if(res == NULL) {\r
                                        LM_ERR("no more private memory\n");\r
+                                       return res;\r
                                } else {\r
                                        memset(res, 0, hf->body.len + 1);\r
                                        memcpy(res, hf->body.s, hf->body.len + 1);\r
@@ -311,6 +325,7 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
                                res = (char *)pkg_malloc((hf->body.len + 1) * sizeof(char));\r
                                if(res == NULL) {\r
                                        LM_ERR("no more private memory\n");\r
+                                       return res;\r
                                } else {\r
 \r
                                        memset(res, 0, hf->body.len + 1);\r
@@ -351,6 +366,7 @@ char *lost_get_from_header(struct sip_msg *msg, int *lgth)
        res = (char *)pkg_malloc((f_body->uri.len + 1) * sizeof(char));\r
        if(res == NULL) {\r
                LM_ERR("no more private memory\n");\r
+               return res;\r
        } else {\r
                memset(res, 0, f_body->uri.len + 1);\r
                memcpy(res, f_body->uri.s, f_body->uri.len + 1);\r
@@ -361,7 +377,6 @@ char *lost_get_from_header(struct sip_msg *msg, int *lgth)
        return res;\r
 }\r
 \r
-\r
 /*\r
  * lost_parse_location_info(node, loc)\r
  * parses locationResponse and writes results to location object\r
@@ -442,8 +457,16 @@ https://tools.ietf.org/html/rfc6155
 \r
        /* create request */\r
        request = xmlNewDoc(BAD_CAST "1.0");\r
+       if(!request) {\r
+               LM_ERR("locationRequest xmlNewDoc() failed\n");\r
+               return doc;\r
+       }\r
        /* locationRequest - element */\r
        ptrLocationRequest = xmlNewNode(NULL, BAD_CAST "locationRequest");\r
+       if(!ptrLocationRequest) {\r
+               LM_ERR("locationRequest xmlNewNode() failed\n");\r
+               return doc;\r
+       }\r
        xmlDocSetRootElement(request, ptrLocationRequest);\r
        /* properties */\r
        xmlNewProp(ptrLocationRequest, BAD_CAST "xmlns",\r
@@ -456,6 +479,10 @@ https://tools.ietf.org/html/rfc6155
        xmlNewProp(ptrLocationType, BAD_CAST "exact", BAD_CAST "false");\r
        /* device - element */\r
        ptrDevice = xmlNewChild(ptrLocationRequest, NULL, BAD_CAST "device", NULL);\r
+       if(!ptrDevice) {\r
+               LM_ERR("locationRequest xmlNewChild() failed\n");\r
+               return doc;\r
+       }\r
        /* properties */\r
        xmlNewProp(ptrDevice, BAD_CAST "xmlns",\r
                        BAD_CAST "urn:ietf:params:xml:ns:geopriv:held:id");\r
@@ -464,10 +491,15 @@ https://tools.ietf.org/html/rfc6155
        xmlNewChild(ptrDevice, NULL, BAD_CAST "uri", BAD_CAST buf);\r
 \r
        xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);\r
+       if(!xmlbuff) {\r
+               LM_ERR("locationRequest xmlDocDumpFormatMemory() failed\n");\r
+               return doc;\r
+       }\r
 \r
        doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));\r
        if(doc == NULL) {\r
                LM_ERR("no more private memory\n");\r
+               return doc;\r
        }\r
 \r
        memset(doc, 0, buffersize + 1);\r
@@ -524,8 +556,16 @@ https://tools.ietf.org/html/rfc5222
  */\r
        /* create request */\r
        request = xmlNewDoc(BAD_CAST "1.0");\r
+       if(!request) {\r
+               LM_ERR("findService request xmlNewDoc() failed\n");\r
+               return doc;\r
+       }\r
        /* findService - element */\r
        ptrFindService = xmlNewNode(NULL, BAD_CAST "findService");\r
+       if(!ptrFindService) {\r
+               LM_ERR("findService xmlNewNode() failed\n");\r
+               return doc;\r
+       }\r
        xmlDocSetRootElement(request, ptrFindService);\r
        /* set properties */\r
        xmlNewProp(ptrFindService, BAD_CAST "xmlns",\r
@@ -544,6 +584,10 @@ https://tools.ietf.org/html/rfc5222
        /* Point */\r
        if(loc->radius == 0) {\r
                ptrPoint = xmlNewChild(ptrLocation, NULL, BAD_CAST "Point", NULL);\r
+               if(!ptrPoint) {\r
+                       LM_ERR("locationRequest xmlNewChild() failed\n");\r
+                       return doc;\r
+               }\r
                xmlNewProp(ptrPoint, BAD_CAST "xmlns",\r
                                BAD_CAST "http://www.opengis.net/gml");\r
                xmlNewProp(ptrPoint, BAD_CAST "srsName",\r
@@ -553,6 +597,10 @@ https://tools.ietf.org/html/rfc5222
        } else {\r
                /* circle - Point */\r
                ptrCircle = xmlNewChild(ptrLocation, NULL, BAD_CAST "gs:Circle", NULL);\r
+               if(!ptrCircle) {\r
+                       LM_ERR("locationRequest xmlNewChild() failed\n");\r
+                       return doc;\r
+               }\r
                xmlNewProp(ptrCircle, BAD_CAST "xmlns:gml",\r
                                BAD_CAST "http://www.opengis.net/gml");\r
                xmlNewProp(ptrCircle, BAD_CAST "xmlns:gs",\r
@@ -565,6 +613,10 @@ https://tools.ietf.org/html/rfc5222
                snprintf(buf, BUFSIZE, "%d", loc->radius);\r
                ptrRadius = xmlNewChild(\r
                                ptrCircle, NULL, BAD_CAST "gs:radius", BAD_CAST buf);\r
+               if(!ptrRadius) {\r
+                       LM_ERR("locationRequest xmlNewChild() failed\n");\r
+                       return doc;\r
+               }\r
                xmlNewProp(ptrRadius, BAD_CAST "uom",\r
                                BAD_CAST "urn:ogc:def:uom:EPSG::9001");\r
        }\r
@@ -573,10 +625,15 @@ https://tools.ietf.org/html/rfc5222
        xmlNewChild(ptrFindService, NULL, BAD_CAST "service", BAD_CAST buf);\r
 \r
        xmlDocDumpFormatMemory(request, &xmlbuff, &buffersize, 0);\r
+       if(!xmlbuff) {\r
+               LM_ERR("findService request xmlDocDumpFormatMemory() failed\n");\r
+               return doc;\r
+       }\r
 \r
        doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));\r
        if(doc == NULL) {\r
                LM_ERR("no more private memory\n");\r
+               return doc;\r
        }\r
 \r
        memset(doc, 0, buffersize + 1);\r
index f6bf935..6872214 100644 (file)
@@ -40,6 +40,8 @@
 #define BUFSIZE 128    /* temporary buffer to hold geolocation */\r
 #define RANDSTRSIZE 16 /* temporary id in a findService request */\r
 \r
+#define LOSTFREE(x) pkg_free(x); x = NULL;\r
+\r
 typedef struct\r
 {\r
        char *identity;\r
@@ -54,6 +56,7 @@ typedef struct
 \r
 void lost_rand_str(char *, size_t);\r
 void lost_free_loc(p_loc_t);\r
+void lost_free_string(str *);\r
 \r
 int lost_get_location_object(p_loc_t, xmlDocPtr, xmlNodePtr);\r
 int lost_parse_location_info(xmlNodePtr node, p_loc_t loc);\r