Browse code

allows to give dialout sessions a variant parameter with the call to AmUAC::dialout. Plugin interface stays backward compatible by overloading the AmSessionFactory::onInvite - applications that want to use this feature need to implement the onInvite function with second parameter.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@336 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 28/05/2007 21:33:49
Showing 6 changed files
... ...
@@ -48,11 +48,24 @@ AmSessionFactory::AmSessionFactory(const string& name)
48 48
 {
49 49
 }
50 50
 
51
+AmSession* AmSessionFactory::onInvite(const AmSipRequest& req, 
52
+				      AmArg& session_params) {
53
+  WARN(" discarding session parameters to new session.\n");
54
+  return onInvite(req);
55
+}
56
+
51 57
 AmSession* AmSessionFactory::onRefer(const AmSipRequest& req)
52 58
 {
53 59
   throw AmSession::Exception(488,"Not accepted here");
54 60
 }
55 61
 
62
+AmSession* AmSessionFactory::onRefer(const AmSipRequest& req, 
63
+				     AmArg& session_params)
64
+{
65
+  WARN(" discarding session parameters to new session.\n");
66
+  return onRefer(req);
67
+}
68
+
56 69
 int AmSessionFactory::configureModule(AmConfigReader& cfg) {
57 70
   return mod_conf.readFromConfig(cfg);
58 71
 }
... ...
@@ -71,6 +84,12 @@ AmSessionEventHandlerFactory::AmSessionEventHandlerFactory(const string& name)
71 84
 {
72 85
 }
73 86
 
87
+bool AmSessionEventHandlerFactory::onInvite(const AmSipRequest& req, 
88
+						  AmArg& session_params) {
89
+  WARN("discarding session parameters for new session.\n");
90
+  return onInvite(req);
91
+}
92
+
74 93
 AmSIPEventHandler::AmSIPEventHandler(const string& name) 
75 94
   : AmPluginFactory(name) 
76 95
 {
... ...
@@ -113,6 +113,7 @@ class AmSessionEventHandlerFactory: public AmPluginFactory
113 113
    * @return true if session creation should be stopped
114 114
    */
115 115
   virtual bool onInvite(const AmSipRequest& req)=0;
116
+  virtual bool onInvite(const AmSipRequest& req, AmArg& session_params);
116 117
 };
117 118
 
118 119
 /** \brief Interface for plugins to create sessions */
... ...
@@ -146,6 +147,19 @@ class AmSessionFactory: public AmPluginFactory
146 147
    */
147 148
   virtual AmSession* onInvite(const AmSipRequest& req)=0;
148 149
 
150
+  /**
151
+   * Creates a dialog state on new request. Passes with 
152
+   * parameters to the new session.
153
+   * 
154
+   * @return 0 if the request is not acceptable.
155
+   *
156
+   * Warning:
157
+   *   This method should not make any expensive
158
+   *   processing as it would block the server.
159
+   */
160
+  virtual AmSession* onInvite(const AmSipRequest& req, 
161
+			      AmArg& session_params);
162
+
149 163
   /**
150 164
    * Creates a dialog state on new REFER with local-tag.
151 165
    * @return 0 if the request is not acceptable.
... ...
@@ -156,6 +170,18 @@ class AmSessionFactory: public AmPluginFactory
156 170
    */
157 171
   virtual AmSession* onRefer(const AmSipRequest& req);
158 172
 
173
+  /**
174
+   * Creates a dialog state on new REFER with local-tag.
175
+   * Passes session_params to the new session.
176
+   * @return 0 if the request is not acceptable.
177
+   *
178
+   * Warning:
179
+   *   This method should not make any expensive
180
+   *   processing as it would block the server.
181
+   */
182
+  virtual AmSession* onRefer(const AmSipRequest& req, 
183
+			     AmArg& session_params);
184
+
159 185
   /**
160 186
    * method to receive an Event that is posted
161 187
    * to  the factory
... ...
@@ -177,11 +177,11 @@ AmSession* AmSessionContainer::getSession(const string& local_tag)
177 177
   return it->second;
178 178
 }
179 179
 
180
-AmSession* AmSessionContainer::startSessionUAC(AmSipRequest& req) {
180
+AmSession* AmSessionContainer::startSessionUAC(AmSipRequest& req, AmArg* session_params) {
181 181
   AmSession* session = NULL;
182 182
   as_mut.lock();
183 183
   try {
184
-    if((session = createSession(req)) != 0){
184
+    if((session = createSession(req, session_params)) != 0){
185 185
       session->dlg.updateStatusFromLocalRequest(req); // sets local tag as well
186 186
       session->setCallgroup(req.from_tag);
187 187
 
... ...
@@ -303,7 +303,8 @@ bool AmSessionContainer::postEvent(const string& local_tag,
303 303
   return false;
304 304
 }
305 305
 
306
-AmSession* AmSessionContainer::createSession(AmSipRequest& req)
306
+AmSession* AmSessionContainer::createSession(AmSipRequest& req, 
307
+					     AmArg* session_params)
307 308
 {
308 309
   string& plugin_name = req.cmd;
309 310
 
... ...
@@ -328,12 +329,17 @@ AmSession* AmSessionContainer::createSession(AmSipRequest& req)
328 329
   }
329 330
 	    
330 331
   AmSession* session = 0;
331
-  if (req.method == "INVITE")
332
-    session = state_factory->onInvite(req);
333
-  else if (req.method == "REFER")
334
-    session = state_factory->onRefer(req);
335
-
336
-
332
+  if (req.method == "INVITE") {
333
+    if (NULL != session_params) 
334
+      session = state_factory->onInvite(req, *session_params);
335
+    else 
336
+      session = state_factory->onInvite(req);
337
+  }  else if (req.method == "REFER") {
338
+    if (NULL != session_params) 
339
+      session = state_factory->onRefer(req, *session_params);
340
+    else 
341
+      session = state_factory->onRefer(req);
342
+  }
337 343
 
338 344
   if(!session) {
339 345
     //  State creation failed:
... ...
@@ -141,7 +141,8 @@ class AmSessionContainer : public AmThread
141 141
    * @param req local request
142 142
    * @return a new session or NULL on error.
143 143
    */
144
-  AmSession* createSession(AmSipRequest& req);
144
+  AmSession* createSession(AmSipRequest& req, 
145
+			   AmArg* session_params = NULL);
145 146
 
146 147
   /**
147 148
    * Adds a session to the container (UAS only).
... ...
@@ -169,7 +170,8 @@ class AmSessionContainer : public AmThread
169 170
    * Constructs a new session and adds it to the active session container. 
170 171
    * @param req client's request
171 172
    */
172
-  AmSession* startSessionUAC(AmSipRequest& req);
173
+  AmSession* startSessionUAC(AmSipRequest& req, 
174
+			     AmArg* session_params = NULL);
173 175
 
174 176
   /**
175 177
    * Detroys a session.
... ...
@@ -37,7 +37,8 @@ AmSession* AmUAC::dialout(const string& user,
37 37
 			  const string& from,
38 38
 			  const string& from_uri,
39 39
 			  const string& to,
40
-			  const string& local_tag) {
40
+			  const string& local_tag,
41
+			  AmArg*  session_params) {
41 42
  
42 43
   AmSipRequest req;
43 44
 
... ...
@@ -56,6 +57,6 @@ AmSession* AmUAC::dialout(const string& user,
56 57
   req.to_tag   = "";
57 58
   req.callid   = AmSession::getNewId() + "@" + AmConfig::LocalIP;
58 59
     
59
-  return AmSessionContainer::instance()->startSessionUAC(req);
60
+  return AmSessionContainer::instance()->startSessionUAC(req, session_params);
60 61
 }
61 62
 
... ...
@@ -30,6 +30,7 @@
30 30
 
31 31
 #include "AmThread.h"
32 32
 #include "AmSession.h"
33
+#include "AmArg.h"
33 34
 
34 35
 #include <string>
35 36
 using std::string; 
... ...
@@ -43,7 +44,9 @@ class AmUAC {
43 44
 			    const string& from,
44 45
 			    const string& from_uri,
45 46
 			    const string& to,
46
-			    const string& local_tag = "");
47
+			    const string& local_tag = "",
48
+			    AmArg*  session_params = NULL);
49
+
47 50
 };
48 51
 
49 52
 #endif