Author: sayer
Date: 2009-03-13 19:09:48 +0100 (Fri, 13 Mar 2009)
New Revision: 1318

Modified:
   trunk/apps/examples/di_dialer/DIDial.cpp
   trunk/apps/examples/di_dialer/DIDial.h
   trunk/apps/examples/di_dialer/Readme.di_dial
Log:
added extra parameters to dial and dial_auth functions

Modified: trunk/apps/examples/di_dialer/DIDial.cpp
===================================================================
--- trunk/apps/examples/di_dialer/DIDial.cpp    2009-03-13 17:40:22 UTC (rev 
1317)
+++ trunk/apps/examples/di_dialer/DIDial.cpp    2009-03-13 18:09:48 UTC (rev 
1318)
@@ -37,40 +37,17 @@
     unsigned int i_pin = 0;
     while (i_pin<100) { // only for safety..
       string dialout_pin = cfg.getParameter("dialout_pin"+int2str(i_pin));
+
       if (!dialout_pin.length()) 
        break;
-      size_t pos = dialout_pin.find_first_of(';');
-      if (pos == string::npos)
-       break;
-      string pin = dialout_pin.substr(0, pos);
-      
-      size_t pos2 = dialout_pin.find_first_of(';', pos+1);
-      if ((pos == string::npos)||(pos2 == string::npos))
-       break;
-      string userpart = dialout_pin.substr(pos+1, pos2-pos-1);
-      pos = pos2;
 
-      pos2 = dialout_pin.find_first_of(';', pos+1);
-      if ((pos == string::npos)||(pos2 == string::npos))
+      vector<string> d_pin = explode(dialout_pin, ";");
+      if (d_pin.size() != 5)
        break;
-      string user = dialout_pin.substr(pos+1, pos2-pos-1);
-      pos = pos2;
 
-      pos2 = dialout_pin.find_first_of(';', pos+1);
-      if ((pos == string::npos)||(pos2 == string::npos))
-       break;
-      string domain = dialout_pin.substr(pos+1, pos2-pos-1);
-      pos = pos2;
-
-      pos2 = dialout_pin.find_first_of(';', pos+1);
-      if ((pos == string::npos)||(pos2 == string::npos))
-       break;
-      string pwd = dialout_pin.substr(pos+1, pos2-pos-1);
-      pos = pos2;
-
-      dialout_pins[pin] = DIDialoutInfo(userpart, domain, user, pwd);
+      dialout_pins[d_pin[0]] = DIDialoutInfo(d_pin[1], d_pin[2], d_pin[3], 
d_pin[4]);
       DBG("DIDial: added PIN '%s' userpart '%s' domain '%s' user '%s' pwd 
'<not shown>'\n", 
-         pin.c_str(), userpart.c_str(), domain.c_str(), user.c_str());
+         d_pin[0].c_str(), d_pin[1].c_str(), d_pin[2].c_str(), 
d_pin[3].c_str());
       i_pin++;         
     } 
   } else {
@@ -103,15 +80,17 @@
        ret.push(dialout(args.get(0).asCStr(), 
                        args.get(1).asCStr(), 
                        args.get(2).asCStr(), 
-                       args.get(3).asCStr()).c_str());
+                       args.get(3).asCStr(),
+                       args.size()>4? &args.get(4) : NULL).c_str());
     } else if(method == "dial_auth"){
        ret.push(dialout_auth(args.get(0).asCStr(), 
-                       args.get(1).asCStr(), 
-                       args.get(2).asCStr(), 
-                       args.get(3).asCStr(),
-                       args.get(4).asCStr(), 
-                       args.get(5).asCStr(), 
-                       args.get(6).asCStr()
+                            args.get(1).asCStr(), 
+                            args.get(2).asCStr(), 
+                            args.get(3).asCStr(),
+                            args.get(4).asCStr(), 
+                            args.get(5).asCStr(), 
+                            args.get(6).asCStr(),
+                            args.size()>7? &args.get(7) : NULL
                        ).c_str());
     } else if(method == "dial_auth_b2b"){
        ret.push(dialout_auth_b2b(args.get(0).asCStr(), 
@@ -148,12 +127,14 @@
 string DIDial::dialout(const string& application, 
                       const string& user, 
                       const string& from, 
-                      const string& to) {
-  DBG("dialout application '%s', user '%s', from '%s', to '%s'", 
+                      const string& to,
+                      AmArg* extra_params) {
+  DBG("dialout application '%s', user '%s', from '%s', to '%s'\n", 
       application.c_str(), user.c_str(), from.c_str(), to.c_str());
 
   AmSession* s = AmUAC::dialout(user.c_str(), application,  to,  
-                               "<" + from +  ">", from, "<" + to + ">");
+                               "<" + from +  ">", from, "<" + to + ">", 
+                               string(""), string(""), extra_params);
   if (s)
     return s->getLocalTag();
   else 
@@ -161,24 +142,33 @@
 }
 
 string DIDial::dialout_auth(const string& application, 
-                      const string& user, 
-                      const string& from, 
-                      const string& to,
-                      const string& a_realm, 
-                      const string& a_user, 
-                      const string& a_pwd
+                           const string& user, 
+                           const string& from, 
+                           const string& to,
+                           const string& a_realm, 
+                           const string& a_user, 
+                           const string& a_pwd,
+                           AmArg* extra_params
                       ) {
   DBG("dialout application '%s', user '%s', from '%s', to '%s', authrealm 
'%s', authuser '%s', authpass '%s'", 
       application.c_str(), user.c_str(), from.c_str(), to.c_str(), 
a_realm.c_str(), a_user.c_str(), a_pwd.c_str());
 
   AmArg* a = new AmArg();
-  a->setBorrowedPointer(new UACAuthCred(a_realm, a_user, a_pwd));
 
+  if (extra_params) {
+    a->assertArray(2);
+    (*a)[0].setBorrowedPointer(new UACAuthCred(a_realm, a_user, a_pwd));
+    (*a)[1] = *extra_params;
+  } else {
+    a->setBorrowedPointer(new UACAuthCred(a_realm, a_user, a_pwd));
+  }
   AmSession* s = AmUAC::dialout(user.c_str(), application,  to,  
                                "<" + from +  ">", from, "<" + to + ">", 
                                string(""), // callid
                                string(""), // xtra hdrs
                                a);
+  delete a;
+
   if (s)
     return s->getLocalTag();
   else 
@@ -186,8 +176,7 @@
 }
 
 string DIDial::dialout_auth_b2b(const string& application, 
-          const string& announcement, 
-          const string& from, 
+          const string& announcement,           const string& from, 
           const string& to,
           const string& caller_ruri, 
           const string& callee_ruri,

Modified: trunk/apps/examples/di_dialer/DIDial.h
===================================================================
--- trunk/apps/examples/di_dialer/DIDial.h      2009-03-13 17:40:22 UTC (rev 
1317)
+++ trunk/apps/examples/di_dialer/DIDial.h      2009-03-13 18:09:48 UTC (rev 
1318)
@@ -23,7 +23,8 @@
   string dialout(const string& application, 
                 const string& user,
                 const string& from, 
-                const string& to);
+                const string& to,
+                AmArg* extra_params);
 
   string dialout_auth(const string& application, 
                      const string& user,
@@ -31,7 +32,8 @@
                      const string& to,
                      const string& realm, 
                      const string& a_user,
-                     const string& pwd);
+                     const string& pwd,
+                     AmArg* extra_params);
 
   string dialout_auth_b2b(const string& application, 
                       const string& announcement, 

Modified: trunk/apps/examples/di_dialer/Readme.di_dial
===================================================================
--- trunk/apps/examples/di_dialer/Readme.di_dial        2009-03-13 17:40:22 UTC 
(rev 1317)
+++ trunk/apps/examples/di_dialer/Readme.di_dial        2009-03-13 18:09:48 UTC 
(rev 1318)
@@ -13,7 +13,8 @@
                1 - string user
                2 - string from
                3 - string to
-
+                4 - optional: variable arguments, e.g. dict:
+                     {'somevar':'someval'}
        method: "dial_auth"
           place a call with uac authentication (see below) 
        params:
@@ -24,6 +25,8 @@
                4 - string auth_realm
                5 - string auth_user
                6 - string auth_pwd
+                7 - optional: variable arguments, e.g. dict:
+                     {'somevar':'someval'}
 
        method: "dial_pin"
           place a call with uac authentication, 
@@ -50,7 +53,11 @@
  sleep 1; \
 done
 
+For dialing DSM scripts, variables can be given to the script: 
+ s.dial('test_di_dial_params', '123', 'sip:[email protected]', 
'sip:[email protected]', {'somevar':'someval'}) 
+s.dial_auth('test_di_dial_params', '123', 'sip:[email protected]', 
'sip:[email protected]', 'realm','user','pwd',{'somevar':'someval'})     
 
+
 Outgoing calls with SIP authentication
 --------------------------------------
 

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to