[sr-dev] git:5.1:f3340967: nat_traversal: handle local generated transactions (#1344)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[sr-dev] git:5.1:f3340967: nat_traversal: handle local generated transactions (#1344)

Luis Azedo
Module: kamailio
Branch: 5.1
Commit: f3340967e2979f4ec7de2cc1c828f35028a65306
URL: https://github.com/kamailio/kamailio/commit/f3340967e2979f4ec7de2cc1c828f35028a65306

Author: lazedo <[hidden email]>
Committer: Luis Azedo <[hidden email]>
Date: 2017-11-29T11:11:46Z

nat_traversal: handle local generated transactions (#1344)

* nat_traversal: fix local generated transactions

* nat_traversal: handle TMCB_RESPONSE_SENT only for FAKED_REPLY

* nat_traversal: free allocated buffer

(cherry picked from commit 886f14e11e3e5fe9d2bc56fd37d2102ae5b99645)

---

Modified: src/modules/nat_traversal/nat_traversal.c

---

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

---

diff --git a/src/modules/nat_traversal/nat_traversal.c b/src/modules/nat_traversal/nat_traversal.c
index ae38d7653b..3ddee233d6 100644
--- a/src/modules/nat_traversal/nat_traversal.c
+++ b/src/modules/nat_traversal/nat_traversal.c
@@ -1358,17 +1358,42 @@ __sl_reply_out(sl_cbp_t *slcbp)
 static void
 __tm_reply_in(struct cell *trans, int type, struct tmcb_params *param)
 {
-    time_t expire;
+    time_t expire = 0;
 
     if (param->req==NULL || param->rpl==NULL)
         return;
 
+    if(type == TMCB_RESPONSE_SENT && param->rpl!=FAKED_REPLY)
+ return;
+
     if (param->code >= 200 && param->code < 300) {
         switch (param->req->REQ_METHOD) {
         case METHOD_SUBSCRIBE:
-            expire = get_expires(param->rpl);
-            if (expire > 0)
+            if(type == TMCB_RESPONSE_SENT) {
+             char* tmp = pkg_malloc(param->send_buf.len+1);
+             if(tmp) {
+                 sip_msg_t msg;
+                 strncpy(tmp, param->send_buf.s, param->send_buf.len);
+                 tmp[param->send_buf.len] = '\0';
+                 memset(&msg, 0, sizeof(sip_msg_t));
+                 msg.buf=tmp;
+                 msg.len=param->send_buf.len;
+                 if(parse_msg(tmp, param->send_buf.len, &msg) != 0) {
+                 LM_ERR("ERROR PARSING REPLY\n");
+                 } else {
+ expire = get_expires(&msg);
+                 }
+                 free_sip_msg(&msg);
+ pkg_free(tmp);
+             }
+            } else {
+             expire = get_expires(param->rpl);
+            }
+            if (expire > 0) {
                 keepalive_subscription(param->req, expire);
+            } else {
+             LM_DBG("expires == 0\n");
+            }
             break;
         case METHOD_REGISTER:
             expire = get_register_expire(param->req, param->rpl);
@@ -1404,7 +1429,7 @@ NAT_Keepalive(struct sip_msg *msg)
         // fallthrough
     case METHOD_SUBSCRIBE:
         msg->msg_flags |= FL_DO_KEEPALIVE;
-        if (tm_api.register_tmcb(msg, 0, TMCB_RESPONSE_IN, __tm_reply_in, 0, 0) <= 0) {
+        if (tm_api.register_tmcb(msg, 0, TMCB_RESPONSE_IN | TMCB_RESPONSE_SENT, __tm_reply_in, 0, 0) <= 0) {
             LM_ERR("cannot register TM callback for incoming replies\n");
             return -1;
         }


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