Browse code

SIP Session Timer support for conference app

Stefan Sayer authored on 21/09/2010 22:25:46
Showing 3 changed files
... ...
@@ -73,6 +73,8 @@ PlayoutType ConferenceFactory::m_PlayoutType = ADAPTIVE_PLAYOUT;
73 73
 unsigned int ConferenceFactory::MaxParticipants;
74 74
 
75 75
 bool ConferenceFactory::UseRFC4240Rooms;
76
+AmConfigReader ConferenceFactory::cfg;
77
+AmSessionEventHandlerFactory* ConferenceFactory::session_timer_f = NULL;
76 78
 
77 79
 #ifdef USE_MYSQL
78 80
 mysqlpp::Connection ConferenceFactory::Connection(mysqlpp::use_exceptions);
... ...
@@ -155,7 +157,6 @@ int get_audio_file(const string& message, const string& domain, const string& la
155 157
 
156 158
 int ConferenceFactory::onLoad()
157 159
 {
158
-  AmConfigReader cfg;
159 160
   if(cfg.loadFile(AmConfig::ModConfigPath + string(APP_NAME)+ ".conf"))
160 161
     return -1;
161 162
 
... ...
@@ -297,6 +298,15 @@ int ConferenceFactory::onLoad()
297 298
   UseRFC4240Rooms = cfg.getParameter("use_rfc4240_rooms")=="yes";
298 299
   DBG("%ssing RFC4240 room naming.\n", UseRFC4240Rooms?"U":"Not u");
299 300
 
301
+  if(cfg.hasParameter("enable_session_timer") &&
302
+     (cfg.getParameter("enable_session_timer") == string("yes")) ){
303
+    DBG("enabling session timers\n");
304
+    session_timer_f = AmPlugIn::instance()->getFactory4Seh("session_timer");
305
+    if(session_timer_f == NULL){
306
+      ERROR("Could not load the session_timer module: disabling session timers.\n");
307
+    }
308
+  }
309
+
300 310
   return 0;
301 311
 }
302 312
 
... ...
@@ -322,7 +332,27 @@ AmSession* ConferenceFactory::onInvite(const AmSipRequest& req)
322 332
     conf_id = req.user.substr(5);
323 333
   }
324 334
 
325
-  return new ConferenceDialog(conf_id);
335
+  ConferenceDialog* s = new ConferenceDialog(conf_id);
336
+
337
+  setupSessionTimer(s);
338
+
339
+  return s;
340
+}
341
+
342
+void ConferenceFactory::setupSessionTimer(AmSession* s) {
343
+  if (NULL != session_timer_f) {
344
+
345
+    AmSessionEventHandler* h = session_timer_f->getHandler(s);
346
+    if (NULL == h)
347
+      return;
348
+
349
+    if(h->configure(cfg)){
350
+      ERROR("Could not configure the session timer: disabling session timers.\n");
351
+      delete h;
352
+    } else {
353
+      s->addHandler(h);
354
+    }
355
+  }
326 356
 }
327 357
 
328 358
 AmSession* ConferenceFactory::onRefer(const AmSipRequest& req)
... ...
@@ -332,7 +362,8 @@ AmSession* ConferenceFactory::onRefer(const AmSipRequest& req)
332 362
 
333 363
   AmSession* s = new ConferenceDialog(req.user);
334 364
   s->dlg.local_tag  = req.from_tag;
335
-    
365
+  
366
+  setupSessionTimer(s);
336 367
 
337 368
   DBG("ConferenceFactory::onRefer: local_tag = %s\n",s->dlg.local_tag.c_str());
338 369
 
... ...
@@ -749,6 +780,8 @@ void ConferenceDialog::createDialoutParticipant(const string& uri_user)
749 780
 			 AmConferenceStatus::getChannel(getLocalTag(),
750 781
 							dialout_id));
751 782
 
783
+  ConferenceFactory::setupSessionTimer(dialout_session);
784
+
752 785
   AmSipDialog& dialout_dlg = dialout_session->dlg;
753 786
 
754 787
   dialout_dlg.local_tag    = dialout_id;
... ...
@@ -75,6 +75,9 @@ struct DialoutConfEvent : public AmEvent {
75 75
 /** \brief Factory for conference sessions */
76 76
 class ConferenceFactory : public AmSessionFactory
77 77
 {
78
+  static AmSessionEventHandlerFactory* session_timer_f;
79
+  static AmConfigReader cfg;
80
+
78 81
 public:
79 82
   static string AudioPath;
80 83
   static string LonelyUserFile;
... ...
@@ -85,6 +88,7 @@ public:
85 88
   static unsigned int MaxParticipants;
86 89
   static bool UseRFC4240Rooms;
87 90
 
91
+  static void setupSessionTimer(AmSession* s);
88 92
 
89 93
 #ifdef USE_MYSQL
90 94
   static mysqlpp::Connection Connection;
... ...
@@ -33,3 +33,37 @@ playout_type=adaptive_playout
33 33
 #default:
34 34
 # use_rfc4240_rooms=no
35 35
 #
36
+
37
+###############################################################
38
+# RFC4028 Session Timer
39
+#
40
+
41
+# - enables the session timer ([yes,no]; default: no)
42
+# 
43
+# enable_session_timer=yes
44
+
45
+# - set the "Session-Expires" parameter for the session timer.
46
+#
47
+# session_expires=240
48
+
49
+# - set the "Min-SE" parameter for the session timer.
50
+#
51
+# minimum_timer=90
52
+
53
+# session refresh (Session Timer, RFC4028) method
54
+#
55
+# INVITE                 - use re-INVITE
56
+# UPDATE                 - use UPDATE
57
+# UPDATE_FALLBACK_INVITE - use UPDATE if indicated in Allow, re-INVITE otherwise
58
+#
59
+# Default: UPDATE_FALLBACK_INVITE
60
+#
61
+# Note: Session Timers are only supported in some applications
62
+#
63
+#session_refresh_method=UPDATE
64
+
65
+# accept_501_reply - accept 501 reply as successful refresh? [yes|no]
66
+#
67
+# Default: yes
68
+#
69
+#accept_501_reply=no