Browse code

dialout function

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

Stefan Sayer authored on 21/04/2010 00:26:00
Showing 3 changed files
... ...
@@ -34,6 +34,9 @@
34 34
 #include <string.h>
35 35
 #include "AmSipHeaders.h"
36 36
 
37
+#include "AmUAC.h"
38
+#include "ampi/UACAuthAPI.h"
39
+
37 40
 SC_EXPORT(MOD_CLS_NAME);
38 41
 
39 42
 
... ...
@@ -43,6 +46,7 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
43 46
   DEF_CMD("dlg.acceptInvite", DLGAcceptInviteAction);
44 47
   DEF_CMD("dlg.bye", DLGByeAction);
45 48
   DEF_CMD("dlg.connectCalleeRelayed", DLGConnectCalleeRelayedAction);
49
+  DEF_CMD("dlg.dialout", DLGDialoutAction);
46 50
 
47 51
 } MOD_ACTIONEXPORT_END;
48 52
 
... ...
@@ -159,3 +163,82 @@ EXEC_ACTION_START(DLGConnectCalleeRelayedAction) {
159 163
 
160 164
   sc_sess->B2BconnectCallee(remote_party, remote_uri, true);
161 165
 } EXEC_ACTION_END;
166
+
167
+EXEC_ACTION_START(DLGDialoutAction) {  
168
+  string arrayname = resolveVars(arg, sess, sc_sess, event_params);
169
+
170
+#define GET_VARIABLE_MANDATORY(varname_suffix, outvar)			\
171
+  it = sc_sess->var.find(arrayname+varname_suffix); \
172
+  if (it == sc_sess->var.end()) {					\
173
+    WARN("%s", std::string("need " + arrayname + varname_suffix " set for dlg.dialoutSimple("+arrayname+")").c_str()); \
174
+    sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG);				\
175
+    return false;							\
176
+  }									\
177
+  outvar = it->second;
178
+
179
+#define GET_VARIABLE_OPTIONAL(varname_suffix, outvar) \
180
+  it = sc_sess->var.find(arrayname+varname_suffix);  \
181
+  if (it != sc_sess->var.end())		      \
182
+    outvar = it->second;
183
+
184
+  map<string, string>::iterator it; 
185
+
186
+  string v_from;
187
+  GET_VARIABLE_MANDATORY("_caller", v_from);
188
+  string v_to;
189
+  GET_VARIABLE_MANDATORY("_callee", v_to);
190
+  string v_domain;
191
+  GET_VARIABLE_MANDATORY("_domain", v_domain);
192
+  string app_name;
193
+  GET_VARIABLE_MANDATORY("_app", app_name);
194
+
195
+  string user = v_from;
196
+  string r_uri = "sip:"+v_to+"@"+v_domain;
197
+
198
+  GET_VARIABLE_OPTIONAL("_r_uri", r_uri);
199
+
200
+  string from = "<sip:"+v_from+"@"+v_domain+">"; 
201
+  GET_VARIABLE_OPTIONAL("_from", from);
202
+
203
+  string from_uri = "sip:"+v_from+"@"+v_domain; 
204
+  GET_VARIABLE_OPTIONAL("_from_uri", from_uri);
205
+
206
+  string to = "<sip:"+v_to+"@"+v_domain+">";
207
+  GET_VARIABLE_OPTIONAL("_to", to);
208
+
209
+  string auth_user; 
210
+  GET_VARIABLE_OPTIONAL("_auth_user", auth_user);
211
+
212
+  string auth_pwd; 
213
+  GET_VARIABLE_OPTIONAL("_auth_pwd", auth_pwd);
214
+   
215
+  string ltag; 
216
+  GET_VARIABLE_OPTIONAL("_ltag", ltag);
217
+
218
+  string hdrs; 
219
+  GET_VARIABLE_OPTIONAL("_hdrs", hdrs);
220
+  
221
+#undef GET_VARIABLE_MANDATORY
222
+#undef GET_VARIABLE_OPTIONAL
223
+
224
+  DBG("placing UAC call: user <%s>, app <%s>, ruri <%s>, from <%s> "
225
+      "from_uri <%s>, to <%s>, ltag <%s>, hdrs <%s>, auth_user <%s>, auth_pwd <not shown>\n",
226
+      user.c_str(), app_name.c_str(), r_uri.c_str(), from.c_str(),
227
+      from_uri.c_str(), to.c_str(), ltag.c_str(), hdrs.c_str(), auth_user.c_str());
228
+
229
+  AmArg* sess_params = NULL;
230
+  if (!auth_user.empty() && !auth_pwd.empty()) {
231
+    sess_params = new AmArg();
232
+    sess_params->setBorrowedPointer(new UACAuthCred("", auth_user,auth_pwd));
233
+  }
234
+ 
235
+ AmSession* new_sess = AmUAC::dialout(user, app_name, r_uri, from, from_uri, to, ltag, hdrs, sess_params);
236
+
237
+ if (NULL != new_sess) {
238
+   sc_sess->var[arrayname + "_ltag"] = new_sess->getLocalTag();
239
+ } else {
240
+   sc_sess->var[arrayname + "_ltag"] = "";
241
+   sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
242
+ }
243
+
244
+} EXEC_ACTION_END;
... ...
@@ -38,4 +38,5 @@ DEF_ACTION_2P(DLGReplyAction);
38 38
 DEF_ACTION_2P(DLGAcceptInviteAction);
39 39
 DEF_ACTION_2P(DLGConnectCalleeRelayedAction);
40 40
 DEF_ACTION_1P(DLGByeAction);
41
+DEF_ACTION_1P(DLGDialoutAction);
41 42
 #endif
... ...
@@ -22,3 +22,28 @@ dlg.bye([headers])
22 22
 dlg.connectCalleeRelayed(string remote_party, string remote_uri)
23 23
  like B2B.connectCallee() but for relayed INVITEs, i.e. for executing in 
24 24
  invite run (run_invite_event=yes and transition "on INVITE" START - invite -> runinvite;)
25
+
26
+
27
+dlg.dialout(string arrayname)
28
+  dial out a new call
29
+  simple format/mandatory:
30
+   arrayname_caller   caller user
31
+   arrayname_callee   callee user
32
+   arrayname_domain   domain caller and callee
33
+   arrayname_app      application to execute
34
+
35
+  additional/overwrite:
36
+   arrayname_r_uri     INVITE request URI
37
+   arrayname_from      From
38
+   arrayname_from_uri  From URI (only internally used)
39
+   arrayname_to        To
40
+   arrayname_auth_user authentication user
41
+   arrayname_auth_pwd  authentication pwd
42
+   arrayname_ltag      ltag for new call
43
+   arrayname_hdrs      headers for new call
44
+
45
+  returns $arrayname_ltag and sets ERRNO.
46
+   
47
+
48
+
49
+