build-system: Allow building with static pjproject
[asterisk/asterisk.git] / third-party / pjproject / patches / 0001-sip_transport-Search-for-transport-even-if-listener-.patch
1 From 552194179eb6deae8326eb0fef446e69240ea41b Mon Sep 17 00:00:00 2001
2 From: George Joseph <george.joseph@fairview5.com>
3 Date: Fri, 19 Feb 2016 17:05:53 -0700
4 Subject: [PATCH] sip_transport:  Search for transport even if listener was
5  specified.
6
7 If a listener was specified when calling pjsip_tpmgr_acquire_transport2,
8 a new transport was always created instead of using an existing one.  This
9 caused several issues mostly related to the remote end not expecting a new
10 connection.  I.E.  A TCP client who registered to a server is not going to
11 be listening for connections coming back from the server and refuses the
12 connection.
13
14 Now when pjsip_tpmgr_acquire_transport2 is called with a listener, the
15 registry is still searched for an existing transport and the listener
16 is used as a factory only if no existing transport can be found.
17 ---
18  pjsip/src/pjsip/sip_transport.c | 68 ++++++++++++++++++++---------------------
19  1 file changed, 34 insertions(+), 34 deletions(-)
20
21 diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
22 index 0410324..620b9c0 100644
23 --- a/pjsip/src/pjsip/sip_transport.c
24 +++ b/pjsip/src/pjsip/sip_transport.c
25 @@ -1999,29 +1999,11 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_transport2(pjsip_tpmgr *mgr,
26  
27         TRACE_((THIS_FILE, "Transport %s acquired", seltp->obj_name));
28         return PJ_SUCCESS;
29 -
30 -
31 -    } else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER &&
32 -              sel->u.listener)
33 -    {
34 -       /* Application has requested that a specific listener is to
35 -        * be used. In this case, skip transport hash table lookup.
36 -        */
37 -
38 -       /* Verify that the listener type matches the destination type */
39 -       if (sel->u.listener->type != type) {
40 -           pj_lock_release(mgr->lock);
41 -           return PJSIP_ETPNOTSUITABLE;
42 -       }
43 -
44 -       /* We'll use this listener to create transport */
45 -       factory = sel->u.listener;
46 -
47      } else {
48  
49         /*
50          * This is the "normal" flow, where application doesn't specify
51 -        * specific transport/listener to be used to send message to.
52 +        * specific transport to be used to send message to.
53          * In this case, lookup the transport from the hash table.
54          */
55         pjsip_transport_key key;
56 @@ -2081,22 +2063,40 @@ PJ_DEF(pj_status_t) pjsip_tpmgr_acquire_transport2(pjsip_tpmgr *mgr,
57             return PJ_SUCCESS;
58         }
59  
60 -       /*
61 -        * Transport not found!
62 -        * Find factory that can create such transport.
63 -        */
64 -       factory = mgr->factory_list.next;
65 -       while (factory != &mgr->factory_list) {
66 -           if (factory->type == type)
67 -               break;
68 -           factory = factory->next;
69 -       }
70 +       if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER &&
71 +               sel->u.listener)
72 +               {
73 +               /* Application has requested that a specific listener is to
74 +                * be used.
75 +                */
76 +
77 +               /* Verify that the listener type matches the destination type */
78 +               if (sel->u.listener->type != type) {
79 +                       pj_lock_release(mgr->lock);
80 +                       return PJSIP_ETPNOTSUITABLE;
81 +               }
82  
83 -       if (factory == &mgr->factory_list) {
84 -           /* No factory can create the transport! */
85 -           pj_lock_release(mgr->lock);
86 -           TRACE_((THIS_FILE, "No suitable factory was found either"));
87 -           return PJSIP_EUNSUPTRANSPORT;
88 +               /* We'll use this listener to create transport */
89 +               factory = sel->u.listener;
90 +
91 +       } else {
92 +               /*
93 +                * Transport not found!
94 +                * Find factory that can create such transport.
95 +                */
96 +               factory = mgr->factory_list.next;
97 +               while (factory != &mgr->factory_list) {
98 +                       if (factory->type == type)
99 +                               break;
100 +                       factory = factory->next;
101 +               }
102 +
103 +               if (factory == &mgr->factory_list) {
104 +                       /* No factory can create the transport! */
105 +                       pj_lock_release(mgr->lock);
106 +                       TRACE_((THIS_FILE, "No suitable factory was found either"));
107 +                       return PJSIP_EUNSUPTRANSPORT;
108 +               }
109         }
110      }
111  
112 -- 
113 2.5.0
114