Browse code

sbc: ext_cc: if ext cc init(...) fails, stop call with 500 Server Internal Error

Stefan Sayer authored on 04/11/2013 15:42:43
Showing 3 changed files
... ...
@@ -35,7 +35,7 @@ class ExtendedCCInterface
35 35
     /** First method called from extended CC module interface.
36 36
      * It should initialize CC module internals (values from sbcprofile.conf can
37 37
      * be used for evaluating CC module parameters). */
38
-    virtual void init(SBCCallLeg *call, const map<string, string> &values) { }
38
+    virtual bool init(SBCCallLeg *call, const map<string, string> &values) { return true; }
39 39
 
40 40
     virtual void onStateChange(SBCCallLeg *call, const CallLeg::StatusChangeCause &cause) { };
41 41
 
... ...
@@ -83,7 +83,7 @@ class ExtendedCCInterface
83 83
 
84 84
     // using extended CC modules with simple relay
85 85
 
86
-    virtual void init(SBCCallProfile &profile, SimpleRelayDialog *relay, void *&user_data) { }
86
+    virtual bool init(SBCCallProfile &profile, SimpleRelayDialog *relay, void *&user_data) { return true; }
87 87
     virtual void initUAC(const AmSipRequest &req, void *user_data) { }
88 88
     virtual void initUAS(const AmSipRequest &req, void *user_data) { }
89 89
     virtual void finalize(void *user_data) { }
... ...
@@ -223,7 +223,10 @@ SBCCallLeg::SBCCallLeg(SBCCallLeg* caller, AmSipDialog* p_dlg,
223 223
     throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
224 224
   }
225 225
 
226
-  initCCExtModules();
226
+  if (!initCCExtModules()) {
227
+    ERROR("initializing extended call control modules\n");
228
+    throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
229
+  }
227 230
 
228 231
   setLogger(caller->getLogger());
229 232
 }
... ...
@@ -845,7 +848,10 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
845 848
     throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
846 849
   }
847 850
 
848
-  initCCExtModules();
851
+  if (!initCCExtModules()) {
852
+    ERROR("initializing extended call control modules\n");
853
+    throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);    
854
+  }
849 855
 
850 856
   string ruri, to, from;
851 857
   AmSipRequest uac_req(req);
... ...
@@ -1573,7 +1579,7 @@ bool SBCCallLeg::reinvite(const AmSdp &sdp, unsigned &request_cseq)
1573 1579
   return true;
1574 1580
 }
1575 1581
 
1576
-void SBCCallLeg::initCCExtModules()
1582
+bool SBCCallLeg::initCCExtModules()
1577 1583
 {
1578 1584
   // init extended call control modules
1579 1585
   vector<AmDynInvoke*>::iterator cc_mod = cc_modules.begin();
... ...
@@ -1590,19 +1596,32 @@ void SBCCallLeg::initCCExtModules()
1590 1596
       ExtendedCCInterface *iface = dynamic_cast<ExtendedCCInterface*>(ret[0].asObject());
1591 1597
       if (iface) {
1592 1598
         DBG("extended CC interface offered by cc_module '%s'\n", cc_module.c_str());
1593
-        cc_ext.push_back(iface);
1594
-
1595 1599
         // module initialization
1596
-        iface->init(this, cc_if.cc_values);
1600
+        if (!iface->init(this, cc_if.cc_values)) {
1601
+	  ERROR("initializing extended call control interface\n");
1602
+	  // call onDestroyLeg to clean up on call not going forward
1603
+	  for (vector<ExtendedCCInterface*>::iterator i = cc_ext.begin(); i != cc_ext.end(); ++i) {
1604
+	    (*i)->onDestroyLeg(this);
1605
+	  }
1606
+	  return false;
1607
+	}
1608
+
1609
+        cc_ext.push_back(iface);
1597 1610
       }
1598 1611
       else WARN("BUG: returned invalid extended CC interface by cc_module '%s'\n", cc_module.c_str());
1599 1612
     }
1613
+    catch (const string& s) {
1614
+      DBG("initialization error '%s' or extended CC interface "
1615
+	  "not supported by cc_module '%s'\n", s.c_str(), cc_module.c_str());
1616
+    }
1600 1617
     catch (...) {
1601
-      DBG("extended CC interface not supported by cc_module '%s'\n", cc_module.c_str());
1618
+      DBG("initialization error or extended CC interface not "
1619
+	  "supported by cc_module '%s'\n", cc_module.c_str());
1602 1620
     }
1603 1621
 
1604 1622
     ++cc_mod;
1605 1623
   }
1624
+  return true; // success
1606 1625
 }
1607 1626
 
1608 1627
 void SBCCallLeg::putOnHold()
... ...
@@ -126,7 +126,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
126 126
   UACAuthCred* getCredentials();
127 127
 
128 128
   void setAuthHandler(AmSessionEventHandler* h) { auth = h; }
129
-  void initCCExtModules();
129
+  bool initCCExtModules();
130 130
 
131 131
   /** save call timer; only effective before call is connected */
132 132
   void saveCallTimer(int timer, double timeout);