Module: kamailio
Branch: 5.3
Commit: 0a90aecb5737f4001cad7bb20590823deea4390e
URL: 
https://github.com/kamailio/kamailio/commit/0a90aecb5737f4001cad7bb20590823deea4390e

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2020-01-24T10:38:49+01:00

core: msg translator - warning log made info for  multipart body processing

- check boundary cannot find boundary value in content-type when the request
is turned into multipart body
- use different return code for this case
- a few realignmets for curly braces to be corherent across the
respective functions

(cherry picked from commit 2c7ba53b2b6cc7dd5e3c24241d23e76fb052aa50)

---

Modified: src/core/msg_translator.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/0a90aecb5737f4001cad7bb20590823deea4390e.diff
Patch: 
https://github.com/kamailio/kamailio/commit/0a90aecb5737f4001cad7bb20590823deea4390e.patch

---

diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 485fecac1c..2e9d9da240 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -1711,16 +1711,14 @@ int get_boundary(struct sip_msg* msg, str* boundary)
 
        params.s = memchr(msg->content_type->body.s, ';',
                msg->content_type->body.len);
-       if (params.s == NULL)
-       {
+       if (params.s == NULL) {
                LM_INFO("Content-Type hdr has no boundary params <%.*s>\n",
                                msg->content_type->body.len, 
msg->content_type->body.s);
-               return -1;
+               return -2;
        }
        params.len = msg->content_type->body.len -
                (params.s - msg->content_type->body.s);
-       if (parse_params(&params, CLASS_ANY, &hooks, &list) < 0)
-       {
+       if (parse_params(&params, CLASS_ANY, &hooks, &list) < 0) {
                LM_ERR("while parsing Content-Type params\n");
                return -1;
        }
@@ -1728,11 +1726,9 @@ int get_boundary(struct sip_msg* msg, str* boundary)
        boundary->len = 0;
        for (p = list; p; p = p->next) {
                if ((p->name.len == 8)
-                       && (strncasecmp(p->name.s, "boundary", 8) == 0))
-               {
+                       && (strncasecmp(p->name.s, "boundary", 8) == 0)) {
                        boundary->s = pkg_malloc(p->body.len + 2);
-                       if (boundary->s == NULL)
-                       {
+                       if (boundary->s == NULL) {
                                free_params(list);
                                PKG_MEM_ERROR;
                                return -1;
@@ -1765,9 +1761,17 @@ int check_boundaries(struct sip_msg *msg, struct 
dest_info *send_info)
        int t, ret, lb_size;
        char *pb;
 
-       if(!(msg->msg_flags&FL_BODY_MULTIPART)) return 0;
-       else
-       {
+       if(!(msg->msg_flags&FL_BODY_MULTIPART)) {
+               LM_DBG("no multi-part body\n");
+               return 0;
+       } else {
+               if((t = get_boundary(msg, &ob)) != 0) {
+                       if(t==-2) {
+                               LM_INFO("no boundary - maybe just turning into 
multipart body\n");
+                               return -2;
+                       }
+                       return -1;
+               }
                buf.s = build_body(msg, (unsigned int *)&buf.len, &ret, 
send_info);
                if(ret) {
                        LM_ERR("Can't get body\n");
@@ -1775,10 +1779,6 @@ int check_boundaries(struct sip_msg *msg, struct 
dest_info *send_info)
                }
                tmp.s = buf.s;
                t = tmp.len = buf.len;
-               if(get_boundary(msg, &ob)!=0) {
-                       if(tmp.s) pkg_free(tmp.s);
-                       return -1;
-               }
                if(str_append(&ob, &bsuffix, &b)!=0) {
                        LM_ERR("Can't append suffix to boundary\n");
                        goto error;
@@ -1962,6 +1962,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
        unsigned int flags;
        unsigned int udp_mtu;
        struct dest_info di;
+       int ret;
 
        via_insert_param=0;
        uri_len=0;
@@ -1979,9 +1980,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
        path_buf.len=0;
 
        flags=msg->msg_flags|global_req_flags;
-       if(check_boundaries(msg, send_info)<0){
-               LM_WARN("check_boundaries error\n");
+       if((ret = check_boundaries(msg, send_info)) < 0){
+               LM_INFO("check boundaries negative (%d)\n", ret);
        }
+
        /* Calculate message body difference and adjust Content-Length */
        body_delta = lumps_len(msg, msg->body_lumps, send_info);
        if (adjust_clen(msg, body_delta, send_info->proto) < 0) {


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to