topos: handle return code for parse_headers()
authorDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 20 Jul 2017 14:25:42 +0000 (16:25 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 20 Jul 2017 14:25:42 +0000 (16:25 +0200)
src/modules/topos/topos_mod.c
src/modules/topos/tps_msg.c

index dfa8a77..0141c0f 100644 (file)
@@ -240,19 +240,21 @@ int tps_prepare_msg(sip_msg_t *msg)
                return 1;
        }
 
-       if (parse_headers(msg, HDR_EOH_F, 0)==-1) {
-               LM_DBG("parsing headers failed [[%.*s]]\n",
-                               msg->len, msg->buf);
-               return 2;
+       if(parse_headers(msg, HDR_VIA2_F, 0)<0) {
+               LM_DBG("no via2 has been parsed\n");
        }
 
-       parse_headers(msg, HDR_VIA2_F, 0);
-
        if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) {
                LM_ERR("cannot parse cseq header\n");
                return -1;
        }
 
+       if (parse_headers(msg, HDR_EOH_F, 0)==-1) {
+               LM_DBG("parsing headers failed [[%.*s]]\n",
+                               msg->len, msg->buf);
+               return 2;
+       }
+
        if(parse_from_header(msg)<0) {
                LM_ERR("cannot parse FROM header\n");
                return 3;
index 09eda9e..37b075a 100644 (file)
@@ -115,7 +115,10 @@ int tps_remove_headers(sip_msg_t *msg, uint32_t hdr)
        struct hdr_field *hf;
        struct lump* l;
 
-       parse_headers(msg, HDR_EOH_F, 0);
+       if(parse_headers(msg, HDR_EOH_F, 0)<0) {
+               LM_ERR("failed to parse headers\n");
+               return -1;
+       }
        for (hf=msg->headers; hf; hf=hf->next) {
                if (hdr!=hf->type)
                        continue;
@@ -139,7 +142,11 @@ int tps_add_headers(sip_msg_t *msg, str *hname, str *hbody, int hpos)
        if(hname==NULL || hname->len<=0 || hbody==NULL || hbody->len<=0)
                return 0;
 
-       parse_headers(msg, HDR_EOH_F, 0);
+       if(parse_headers(msg, HDR_EOH_F, 0)<0) {
+               LM_ERR("failed to parse headers\n");
+               return -1;
+       }
+
        if(hpos == 0) { /* append */
                /* after last header */
                anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);