summaryrefslogtreecommitdiff
path: root/third-party/pjproject/patches/0001-sip_transport-Search-for-transport-even-if-listener-.patch
blob: 001912cfe30c03f702935836d33f16ffaa20e91b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From 552194179eb6deae8326eb0fef446e69240ea41b Mon Sep 17 00:00:00 2001
From: George Joseph <george.joseph@fairview5.com>
Date: Fri, 19 Feb 2016 17:05:53 -0700
Subject: [PATCH] sip_transport:  Search for transport even if listener was
 specified.

If a listener was specified when calling pjsip_tpmgr_acquire_transport2,
a new transport was always created instead of using an existing one.  This
caused several issues mostly related to the remote end not expecting a new
connection.  I.E.  A TCP client who registered to a server is not going to
be listening for connections coming back from the server and refuses the
connection.

Now when pjsip_tpmgr_acquire_transport2 is called with a listener, the
registry is still searched for an existing transport and the listener
is used as a factory only if no existing transport can be found.
---
 pjsip/src/pjsip/sip_transport.c | 68 ++++++++++++++++++++---------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index 0410324..620b9c0 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -1999,29 +1999,11 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_transport2(pjsip_tpmgr *mgr,
 
 	TRACE_((THIS_FILE, "Transport %s acquired", seltp->obj_name));
 	return PJ_SUCCESS;
-
-
-    } else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER &&
-	       sel->u.listener)
-    {
-	/* Application has requested that a specific listener is to
-	 * be used. In this case, skip transport hash table lookup.
-	 */
-
-	/* Verify that the listener type matches the destination type */
-	if (sel->u.listener->type != type) {
-	    pj_lock_release(mgr->lock);
-	    return PJSIP_ETPNOTSUITABLE;
-	}
-
-	/* We'll use this listener to create transport */
-	factory = sel->u.listener;
-
     } else {
 
 	/*
 	 * This is the "normal" flow, where application doesn't specify
-	 * specific transport/listener to be used to send message to.
+	 * specific transport to be used to send message to.
 	 * In this case, lookup the transport from the hash table.
 	 */
 	pjsip_transport_key key;
@@ -2081,22 +2063,40 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_transport2(pjsip_tpmgr *mgr,
 	    return PJ_SUCCESS;
 	}
 
-	/*
-	 * Transport not found!
-	 * Find factory that can create such transport.
-	 */
-	factory = mgr->factory_list.next;
-	while (factory != &mgr->factory_list) {
-	    if (factory->type == type)
-		break;
-	    factory = factory->next;
-	}
+	if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER &&
+		sel->u.listener)
+		{
+		/* Application has requested that a specific listener is to
+		 * be used.
+		 */
+
+		/* Verify that the listener type matches the destination type */
+		if (sel->u.listener->type != type) {
+			pj_lock_release(mgr->lock);
+			return PJSIP_ETPNOTSUITABLE;
+		}
 
-	if (factory == &mgr->factory_list) {
-	    /* No factory can create the transport! */
-	    pj_lock_release(mgr->lock);
-	    TRACE_((THIS_FILE, "No suitable factory was found either"));
-	    return PJSIP_EUNSUPTRANSPORT;
+		/* We'll use this listener to create transport */
+		factory = sel->u.listener;
+
+	} else {
+		/*
+		 * Transport not found!
+		 * Find factory that can create such transport.
+		 */
+		factory = mgr->factory_list.next;
+		while (factory != &mgr->factory_list) {
+			if (factory->type == type)
+				break;
+			factory = factory->next;
+		}
+
+		if (factory == &mgr->factory_list) {
+			/* No factory can create the transport! */
+			pj_lock_release(mgr->lock);
+			TRACE_((THIS_FILE, "No suitable factory was found either"));
+			return PJSIP_EUNSUPTRANSPORT;
+		}
 	}
     }
 
-- 
2.5.0