Browse code

Merge remote-tracking branch 'frafos/1.6-dev' into 1.6-dev-ccdsm

* frafos/1.6-dev:
sbc: b/f: fixed use of setting for unsolicited NOTIFY forwarding
core: made allowUnsolicitedNotify() virtual
core: move str2bool() to AmUtils
core/sbc: added support for subscription-less NOTIFY forwarding

Conflicts:
apps/sbc/SBCCallProfile.h
core/AmUtils.cpp
core/AmUtils.h

Stefan Sayer authored on 20/01/2014 15:57:20
Showing 7 changed files
... ...
@@ -189,6 +189,8 @@ SBCCallLeg::SBCCallLeg(SBCCallLeg* caller, AmSipDialog* p_dlg,
189 189
   }
190 190
 
191 191
   setLogger(caller->getLogger());
192
+
193
+  subs->allowUnsolicitedNotify(call_profile.allow_subless_notify);
192 194
 }
193 195
 
194 196
 SBCCallLeg::SBCCallLeg(AmSipDialog* p_dlg, AmSipSubscription* p_subs)
... ...
@@ -896,6 +898,8 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
896 898
   if(a_leg && call_profile.keep_vias)
897 899
     invite_req.hdrs = invite_req.vias + invite_req.hdrs;
898 900
 
901
+  subs->allowUnsolicitedNotify(call_profile.allow_subless_notify);
902
+
899 903
   // call extend call controls
900 904
   InitialInviteHandlerParams params(to, ruri, from, &req, &invite_req);
901 905
   for (vector<ExtendedCCInterface*>::iterator i = cc_ext.begin(); i != cc_ext.end(); ++i) {
... ...
@@ -681,21 +681,6 @@ string SBCCallProfile::print() const {
681 681
   return res;
682 682
 }
683 683
 
684
-/* translates string value into bool, returns false on error */
685
-static bool str2bool(const string &s, bool &dst)
686
-{
687
-  // TODO: optimize
688
-  if ((s == "yes") || (s == "true") || (s == "1")) {
689
-    dst = true;
690
-    return true;
691
-  }
692
-  if ((s == "no") || (s == "false") || (s == "0")) {
693
-    dst = false;
694
-    return true;
695
-  }
696
-  return false;
697
-}
698
-
699 684
 static bool isTranscoderNeeded(const AmSipRequest& req, vector<PayloadDesc> &caps,
700 685
 			       bool default_value)
701 686
 {
... ...
@@ -148,6 +148,8 @@ struct SBCCallProfile
148 148
 
149 149
   string aleg_next_hop;
150 150
 
151
+  bool allow_subless_notify;
152
+
151 153
   vector<FilterEntry> headerfilter;
152 154
   vector<FilterEntry> messagefilter;
153 155
 
... ...
@@ -349,7 +351,8 @@ struct SBCCallProfile
349 351
     log_sip(false),
350 352
     patch_ruri_next_hop(false),
351 353
     next_hop_1st_req(false),
352
-    next_hop_fixed(false)
354
+    next_hop_fixed(false),
355
+    allow_subless_notify(false)
353 356
   { }
354 357
 
355 358
   ~SBCCallProfile()
... ...
@@ -562,6 +562,12 @@ bool AmSipSubscription::onRequestIn(const AmSipRequest& req)
562 562
   // UAS side
563 563
   Subscriptions::iterator sub_it = matchSubscription(req,false);
564 564
   if((sub_it == subs.end()) || (*sub_it)->terminated()) {
565
+
566
+    if((sub_it == subs.end()) && (req.method == SIP_METH_NOTIFY)
567
+       && allow_subless_notify) {
568
+      return true;
569
+    }
570
+
565 571
     dlg->reply(req, 481, SIP_REPLY_NOT_EXIST);
566 572
     return false;
567 573
   }
... ...
@@ -576,6 +582,12 @@ void AmSipSubscription::onRequestSent(const AmSipRequest& req)
576 582
   // UAC side
577 583
   Subscriptions::iterator sub_it = matchSubscription(req,true);
578 584
   if(sub_it == subs.end()){
585
+
586
+    if((req.method == SIP_METH_NOTIFY)
587
+       && allow_subless_notify) {
588
+      return;
589
+    }
590
+
579 591
     // should we exclude this case in onSendRequest???
580 592
     ERROR("we just sent a request for which we could obtain no subscription\n");
581 593
     return;
... ...
@@ -592,6 +604,12 @@ bool AmSipSubscription::onReplyIn(const AmSipRequest& req,
592 604
   // UAC side
593 605
   CSeqMap::iterator cseq_it = uac_cseq_map.find(req.cseq);
594 606
   if(cseq_it == uac_cseq_map.end()){
607
+
608
+    if((req.method == SIP_METH_NOTIFY)
609
+       && allow_subless_notify) {
610
+      return true;
611
+    }
612
+
595 613
     DBG("could not find %i in our uac_cseq_map\n",req.cseq);
596 614
     return false;
597 615
   }
... ...
@@ -164,6 +164,8 @@ protected:
164 164
   CSeqMap  uas_cseq_map;
165 165
   CSeqMap  uac_cseq_map;
166 166
 
167
+  bool allow_subless_notify;
168
+
167 169
   SingleSubscription* makeSubscription(const AmSipRequest& req, bool uac);
168 170
   Subscriptions::iterator createSubscription(const AmSipRequest& req, bool uac);
169 171
   Subscriptions::iterator matchSubscription(const AmSipRequest& req, bool uac);
... ...
@@ -184,6 +186,10 @@ public:
184 186
   AmSipSubscription(AmBasicSipDialog* dlg, AmEventQueue* ev_q);
185 187
   virtual ~AmSipSubscription();
186 188
 
189
+  virtual void allowUnsolicitedNotify(bool allow) {
190
+    allow_subless_notify = allow;
191
+  }
192
+
187 193
   /**
188 194
    * Is there at least one active subscription?
189 195
    */
... ...
@@ -367,6 +367,21 @@ bool str2long(char*& str, long& result, char sep)
367 367
   return false;
368 368
 }
369 369
 
370
+
371
+bool str2bool(const string &s, bool &dst)
372
+{
373
+  // TODO: optimize
374
+  if ((s == "yes") || (s == "true") || (s == "1")) {
375
+    dst = true;
376
+    return true;
377
+  }
378
+  if ((s == "no") || (s == "false") || (s == "0")) {
379
+    dst = false;
380
+    return true;
381
+  }
382
+  return false;
383
+}
384
+
370 385
 std::string URL_decode(const std::string& s) {
371 386
   enum {
372 387
     uSNormal=       0, // start
... ...
@@ -430,7 +445,6 @@ std::string URL_decode(const std::string& s) {
430 445
   return res;
431 446
 }
432 447
 
433
-
434 448
 std::string URL_encode(const std::string &s)
435 449
 {
436 450
     const std::string unreserved = "-_.~";
... ...
@@ -158,6 +158,9 @@ bool str2long(const string& str, long& result);
158 158
  */
159 159
 bool str2long(char*& str, long& result, char sep = ' ');
160 160
 
161
+/* translates string value into bool, returns false on error */
162
+bool str2bool(const string &s, bool &dst);
163
+
161 164
 std::string URL_decode(const std::string& s);
162 165
 std::string URL_encode(const std::string& s);
163 166