Author: rco
Date: 2010-05-25 16:30:06 +0200 (Tue, 25 May 2010)
New Revision: 1929

Modified:
   trunk/apps/annrecorder/AnnRecorder.cpp
   trunk/apps/annrecorder/AnnRecorder.h
   trunk/apps/annrecorder/etc/annrecorder.conf
   trunk/apps/voicebox/Voicebox.cpp
   trunk/apps/voicebox/Voicebox.h
   trunk/apps/voicebox/etc/voicebox.conf
   trunk/apps/voicemail/AnswerMachine.cpp
   trunk/apps/voicemail/AnswerMachine.h
   trunk/apps/voicemail/etc/voicemail.conf
Log:
A new "simple mode" has been added to all the voicemail/voicebox
related module. This simple mode is aimed at very simple setup
with just standard SIP (no params required in P-App-Param...).
Please have a look at the example config files for more details.


Modified: trunk/apps/annrecorder/AnnRecorder.cpp
===================================================================
--- trunk/apps/annrecorder/AnnRecorder.cpp      2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/annrecorder/AnnRecorder.cpp      2010-05-25 14:30:06 UTC (rev 
1929)
@@ -30,6 +30,7 @@
 #include "AmUtils.h"
 #include "AmPlugIn.h"
 #include "AmPromptCollection.h"
+#include "AmUriParser.h"
 #include "../msg_storage/MsgStorageAPI.h"
 #include "sems.h"
 #include "log.h"
@@ -56,6 +57,7 @@
 
 string AnnRecorderFactory::AnnouncePath;
 string AnnRecorderFactory::DefaultAnnounce;
+bool   AnnRecorderFactory::SimpleMode=false;
 AmDynInvokeFactory* AnnRecorderFactory::user_timer_fact = NULL;
 AmDynInvokeFactory* AnnRecorderFactory::message_storage_fact = NULL;
 
@@ -93,6 +95,8 @@
     AnnouncePath += "/";
   DefaultAnnounce = cfg.getParameter("default_announce");
 
+  SimpleMode = (cfg.getParameter("simple_mode") == "yes");
+
   AM_PROMPT_START;
   AM_PROMPT_ADD(WELCOME, ANNREC_ANNOUNCE_PATH WELCOME".wav");
   AM_PROMPT_ADD(YOUR_PROMPT, ANNREC_ANNOUNCE_PATH YOUR_PROMPT".wav");
@@ -125,32 +129,46 @@
   string user;
   string typ;
 
-  string iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
-
-  if (!iptel_app_param.length()) {
-    throw AmSession::Exception(500, MOD_NAME ": parameters not found");
+  if (SimpleMode){
+    AmUriParser p;
+    p.uri = req.from_uri;
+    if (!p.parse_uri()) {
+      DBG("parsing From-URI '%s' failed\n", p.uri.c_str());
+      throw AmSession::Exception(500, MOD_NAME ": could not parse From-URI");
+    }
+    user = p.uri_user;
+    //domain = p.uri_domain;
+    domain = "default";
+    typ = DEFAULT_TYPE;
   }
-
-  language = get_header_keyvalue(iptel_app_param, "lng", "Language");
-
-  user = get_header_keyvalue(iptel_app_param,"uid", "UserID");
-  if (user.empty()) {
-    user = get_header_keyvalue(iptel_app_param,"usr", "User");
-    if (!user.length())
-      user = req.user;
+  else {
+    string iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
+    
+    if (!iptel_app_param.length()) {
+      throw AmSession::Exception(500, MOD_NAME ": parameters not found");
+    }
+    
+    language = get_header_keyvalue(iptel_app_param, "lng", "Language");
+    
+    user = get_header_keyvalue(iptel_app_param,"uid", "UserID");
+    if (user.empty()) {
+      user = get_header_keyvalue(iptel_app_param,"usr", "User");
+      if (!user.length())
+       user = req.user;
+    }
+    
+    domain = get_header_keyvalue(iptel_app_param, "did", "DomainID");
+    if (domain.empty()){
+      domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
+      if (domain.empty())
+       domain = req.domain;
+    }
+    
+    typ = get_header_keyvalue(iptel_app_param, "typ", "Type");
+    if (!typ.length())
+      typ = DEFAULT_TYPE;
   }
   
-  domain = get_header_keyvalue(iptel_app_param, "did", "DomainID");
-  if (domain.empty()){
-    domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
-    if (domain.empty())
-      domain = req.domain;
-  }
-  
-  typ = get_header_keyvalue(iptel_app_param, "typ", "Type");
-  if (!typ.length())
-    typ = DEFAULT_TYPE;
-
   // checks
   if (user.empty()) 
     throw AmSession::Exception(500, MOD_NAME ": user missing");    

Modified: trunk/apps/annrecorder/AnnRecorder.h
===================================================================
--- trunk/apps/annrecorder/AnnRecorder.h        2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/annrecorder/AnnRecorder.h        2010-05-25 14:30:06 UTC (rev 
1929)
@@ -72,6 +72,7 @@
 
   static string AnnouncePath;
   static string DefaultAnnounce;
+  static bool   SimpleMode;
 
   AnnRecorderFactory(const string& _app_name);
 

Modified: trunk/apps/annrecorder/etc/annrecorder.conf
===================================================================
--- trunk/apps/annrecorder/etc/annrecorder.conf 2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/annrecorder/etc/annrecorder.conf 2010-05-25 14:30:06 UTC (rev 
1929)
@@ -23,3 +23,13 @@
 # "Thank you for using the iptel dot org service. Good Bye. - "
 bye=/usr/local/lib/sems/audio/annrecorder/bye.wav
 
+#
+# Simple mode: 
+#
+#  If the simple mode is activated, the user part 
+#  of the From-URI is used as the key to store the 
+#  user annoucement. (no domain is used)
+#
+# Default value: no
+#
+# simple_mode=yes

Modified: trunk/apps/voicebox/Voicebox.cpp
===================================================================
--- trunk/apps/voicebox/Voicebox.cpp    2010-05-25 11:11:04 UTC (rev 1928)
+++ trunk/apps/voicebox/Voicebox.cpp    2010-05-25 14:30:06 UTC (rev 1929)
@@ -30,6 +30,7 @@
 #include "log.h"
 #include "AmPlugIn.h"
 #include "AmSessionContainer.h"
+#include "AmUriParser.h"
 #include "../msg_storage/MsgStorageAPI.h"
 
 #include "VoiceboxDialog.h"
@@ -57,7 +58,7 @@
 unsigned int VoiceboxFactory::save_key = 2;
 unsigned int VoiceboxFactory::delete_key = 3;
 unsigned int VoiceboxFactory::startover_key = 4;
-
+bool   VoiceboxFactory::SimpleMode=false;
 string VoiceboxFactory::default_language = "";
 
 AmPromptCollection* VoiceboxFactory::getPrompts(const string& domain, 
@@ -189,6 +190,8 @@
   // get application specific global parameters
   configureModule(cfg);
 
+  SimpleMode = cfg.getParameter("simple_mode") == "yes";
+
   default_language = cfg.getParameter("default_language");
   if (default_language.length()) {
     DBG("set default language '%s'\n", default_language.c_str());
@@ -299,29 +302,41 @@
   string uid;
   string did;
 
-   
-  string iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
-  
-  if (!iptel_app_param.length()) {
-    AmSession::Exception(500, APP_NAME ": parameters not found");
+  if(SimpleMode){
+    AmUriParser p;
+    p.uri = req.from_uri;
+    if (!p.parse_uri()) {
+      DBG("parsing From-URI '%s' failed\n", p.uri.c_str());
+      throw AmSession::Exception(500, APP_NAME ": could not parse From-URI");
+    }
+    user = p.uri_user;
+    //domain = p.uri_domain;
+    domain = "default";
   }
+  else {
+    string iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
   
+    if (!iptel_app_param.length()) {
+      throw AmSession::Exception(500, APP_NAME ": parameters not found");
+    }
+  
 
-  // consistently with voicemail application:
-  //  uid overrides user
-  user = get_header_keyvalue(iptel_app_param, "uid", "UserID");
-  if (user.empty())
-    user = get_header_keyvalue(iptel_app_param, "usr", "User");
+    // consistently with voicemail application:
+    //  uid overrides user
+    user = get_header_keyvalue(iptel_app_param, "uid", "UserID");
+    if (user.empty())
+      user = get_header_keyvalue(iptel_app_param, "usr", "User");
 
-  //  did overrides domain
-  domain = get_header_keyvalue(iptel_app_param, "did", "DomainID");
-  if (domain.empty())
-    domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
 
+    //  did overrides domain
+    domain = get_header_keyvalue(iptel_app_param, "did", "DomainID");
+    if (domain.empty())
+      domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
 
-  pin = get_header_keyvalue(iptel_app_param, "pin", "PIN");
-  language = get_header_keyvalue(iptel_app_param,"lng", "Language");
 
+    pin = get_header_keyvalue(iptel_app_param, "pin", "PIN");
+    language = get_header_keyvalue(iptel_app_param,"lng", "Language");
+  }
   
   // checks
   if (user.empty()) 

Modified: trunk/apps/voicebox/Voicebox.h
===================================================================
--- trunk/apps/voicebox/Voicebox.h      2010-05-25 11:11:04 UTC (rev 1928)
+++ trunk/apps/voicebox/Voicebox.h      2010-05-25 14:30:06 UTC (rev 1929)
@@ -64,6 +64,7 @@
   static unsigned int delete_key;
   static unsigned int startover_key;
   static string default_language;
+  static bool   SimpleMode;
 
 public:
 

Modified: trunk/apps/voicebox/etc/voicebox.conf
===================================================================
--- trunk/apps/voicebox/etc/voicebox.conf       2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/voicebox/etc/voicebox.conf       2010-05-25 14:30:06 UTC (rev 
1929)
@@ -15,7 +15,7 @@
 # 
 # specific prompts for these domains will be supported:
 #
-domains=iptel.org
+# domains=iptel.org;otherdomain.org
 
 # 
 # a language may have single digits to follow the tens if spoken 
@@ -33,6 +33,20 @@
 default_language=english
 
 #
+# Simple mode: 
+#
+#  If the simple mode is activated, the user part   
+#  of the From-URI is used as the key to retrieve the voicemails. 
+#
+#  Also, the user will not be asked for a PIN. It is the responsability
+#  of upstream SIP proxies to ensure any requried protection of the 
+#  personnal voiceboxes.
+#
+# Default value: no
+#
+#simple_mode=yes
+
+#
 # keys config (optional)
 #
 # repeat_key=1

Modified: trunk/apps/voicemail/AnswerMachine.cpp
===================================================================
--- trunk/apps/voicemail/AnswerMachine.cpp      2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/voicemail/AnswerMachine.cpp      2010-05-25 14:30:06 UTC (rev 
1929)
@@ -81,6 +81,8 @@
 AmDynInvokeFactory* AnswerMachineFactory::MessageStorage=0;
 bool AnswerMachineFactory::SaveEmptyMsg = true;
 bool AnswerMachineFactory::TryPersonalGreeting = false;
+int  AnswerMachineFactory::DefaultVMMode = MODE_VOICEMAIL;
+bool AnswerMachineFactory::SimpleMode = false;
 
 vector<string> AnswerMachineFactory::MailHeaderVariables;
 
@@ -365,18 +367,21 @@
   // get application specific global parameters
   configureModule(cfg);
 
+  DefaultVMMode = cfg.getParameterInt("default_vm_mode",DefaultVMMode);
+  SimpleMode = cfg.getParameter("simple_mode") == "yes";
+
   // smtp_server
   SmtpServerAddress = cfg.getParameter("smtp_server",SmtpServerAddress);
-
+  
   // smtp_port
   if(cfg.hasParameter("smtp_port")){
     if(sscanf(cfg.getParameter("smtp_port").c_str(),
-             "%u",&SmtpServerPort) != 1) {
+             "%u",&SmtpServerPort) != 1) {
       ERROR("invalid smtp_port specified\n");
       return -1;
     }
   }
-
+  
   DBG("SMTP server set to %s:%u\n",
       SmtpServerAddress.c_str(), SmtpServerPort);
 
@@ -433,7 +438,7 @@
 #else
 
   /* Get email templates from file system */
-
+  
   if(loadEmailTemplates(cfg.getParameter("email_template_path",
                                         DEFAULT_MAIL_TMPL_PATH))){
     ERROR("while loading email templates\n");
@@ -479,8 +484,7 @@
           MailHeaderVariables.begin(); it != MailHeaderVariables.end(); it++) {
       DBG("         %s\n", it->c_str());
     }
-  }
-    
+  }    
 
   DBG("Starting SMTP daemon\n");
   AmMailDeamon::instance()->start();
@@ -508,69 +512,81 @@
   string typ;
   string uid; // user ID
   string did; // domain ID
+  string mode;
+  string iptel_app_param;
 
   EmailTmplDict template_variables;
 
-  int vm_mode = MODE_VOICEMAIL; 
+  int vm_mode = DefaultVMMode; 
 
-  string iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
-  string mode = get_header_keyvalue(iptel_app_param,"mod", "Mode");
-
-  if (!EmailAddress.length()) {
-
-    if (!iptel_app_param.length()) {
-      throw AmSession::Exception(500, "voicemail: parameters not found");
+  if(SimpleMode) {
+    email = EmailAddress;
+    uid = user = req.user;
+    //did = domain = req.domain;
+    did = domain = "default";
+    sender = req.from;
+    typ = DEFAULT_TYPE;
+  }
+  else {
+  
+    iptel_app_param = getHeader(req.hdrs, PARAM_HDR);
+    mode = get_header_keyvalue(iptel_app_param,"mod", "Mode");
+    
+    if (!EmailAddress.length()) {
+      
+      if (!iptel_app_param.length()) {
+       throw AmSession::Exception(500, "voicemail: parameters not found");
+      }
+      
+      language = get_header_keyvalue(iptel_app_param, "lng", "Language");
+      email = get_header_keyvalue(iptel_app_param, "eml", "Email-Address");
+      
+      if (!mode.empty()) {
+       if (mode == "box")
+         vm_mode = MODE_BOX;
+       else if (mode == "both")
+         vm_mode = MODE_BOTH;
+       else if (mode == "ann")
+         vm_mode = MODE_ANN;
+      }
+    } else {
+      // overrides email address
+      //vm_mode = MODE_VOICEMAIL;
+      email = EmailAddress;
     }
     
-    language = get_header_keyvalue(iptel_app_param, "lng", "Language");
-    email = get_header_keyvalue(iptel_app_param, "eml", "Email-Address");
+    if (((vm_mode == MODE_BOTH) || (vm_mode == MODE_VOICEMAIL)) &&
+       (email.find('@') == string::npos)) {
+      ERROR("no @ found in email address '%s' from params '%s'\n",
+           email.c_str(), iptel_app_param.c_str());
+      throw AmSession::Exception(500, "voicemail: no email address");
+    }
     
-    if (!mode.empty()) {
-      if (mode == "box")
-       vm_mode = MODE_BOX;
-      else if (mode == "both")
-       vm_mode = MODE_BOTH;
-      else if (mode == "ann")
-       vm_mode = MODE_ANN;
-    }
-  } else {
-    // overrides email address
-    vm_mode = MODE_VOICEMAIL;
-    email = EmailAddress;
+    user = get_header_keyvalue(iptel_app_param,"usr", "User");
+    if (!user.length())
+      user = req.user;
+    
+    sender = get_header_keyvalue(iptel_app_param, "snd", "Sender");
+    if (!sender.length()) 
+      sender = req.from;  
+    
+    domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
+    if (!domain.length())
+      domain = req.domain;
+    
+    typ = get_header_keyvalue(iptel_app_param, "typ", "Type");
+    if (!typ.length())
+      typ = DEFAULT_TYPE;
+    
+    uid = get_header_keyvalue(iptel_app_param, "uid", "UserID");
+    if (uid.empty())
+      uid=user;
+    
+    did = get_header_keyvalue(iptel_app_param, "did", "DomainID");
+    if (did.empty())
+      did=domain;
   }
-
-  if (((vm_mode == MODE_BOTH) || (vm_mode == MODE_VOICEMAIL)) &&
-      (email.find('@') == string::npos)) {
-    ERROR("no @ found in email address '%s' from params '%s'\n",
-         email.c_str(), iptel_app_param.c_str());
-    throw AmSession::Exception(500, "voicemail: no email address");
-  }
-  
-  user = get_header_keyvalue(iptel_app_param,"usr", "User");
-  if (!user.length())
-    user = req.user;
-  
-  sender = get_header_keyvalue(iptel_app_param, "snd", "Sender");
-  if (!sender.length()) 
-    sender = req.from;  
-  
-  domain = get_header_keyvalue(iptel_app_param, "dom", "Domain");
-  if (!domain.length())
-    domain = req.domain;
-  
-  typ = get_header_keyvalue(iptel_app_param, "typ", "Type");
-  if (!typ.length())
-    typ = DEFAULT_TYPE;
-  
-  uid = get_header_keyvalue(iptel_app_param, "uid", "UserID");
-  if (uid.empty())
-    uid=user;
-  
-  did = get_header_keyvalue(iptel_app_param, "did", "DomainID");
-  if (did.empty())
-    did=domain;
-  
-  
+    
   // checks
   if (uid.empty()) 
     throw AmSession::Exception(500, "voicemail: user missing");
@@ -594,7 +610,7 @@
   DBG(" Type:     <%s> \n", typ.c_str());
   DBG(" UID:      <%s> \n", uid.c_str());
   DBG(" DID:      <%s> \n", did.c_str());
-
+  
   FILE* greeting_fp = NULL;
   if (TryPersonalGreeting)
     greeting_fp = getMsgStoreGreeting(typ, uid, did);
@@ -656,10 +672,13 @@
   if(announce_file.empty())
     throw AmSession::Exception(500,"voicemail: no greeting file found");
 
-  // a little inefficient this way - but get_header_keyvalue supports escaping
-  for (vector<string>::iterator it=
-        MailHeaderVariables.begin(); it != MailHeaderVariables.end(); it++) {
-    template_variables[*it] = get_header_keyvalue(iptel_app_param, *it);
+  if(!SimpleMode) {
+
+    // a little inefficient this way - but get_header_keyvalue supports 
escaping
+    for (vector<string>::iterator it=
+          MailHeaderVariables.begin(); it != MailHeaderVariables.end(); it++) {
+      template_variables[*it] = get_header_keyvalue(iptel_app_param, *it);
+    }
   }
 
   // VBOX mode does not need email template

Modified: trunk/apps/voicemail/AnswerMachine.h
===================================================================
--- trunk/apps/voicemail/AnswerMachine.h        2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/voicemail/AnswerMachine.h        2010-05-25 14:30:06 UTC (rev 
1929)
@@ -84,6 +84,8 @@
   static AmDynInvokeFactory* MessageStorage;
   static bool SaveEmptyMsg;
   static bool TryPersonalGreeting;
+  static int  DefaultVMMode;
+  static bool SimpleMode;
 
   static vector<string> MailHeaderVariables;
 

Modified: trunk/apps/voicemail/etc/voicemail.conf
===================================================================
--- trunk/apps/voicemail/etc/voicemail.conf     2010-05-25 11:11:04 UTC (rev 
1928)
+++ trunk/apps/voicemail/etc/voicemail.conf     2010-05-25 14:30:06 UTC (rev 
1929)
@@ -1,42 +1,43 @@
 #
-# optional parameter: smtp_server=<hostname>
+# Voicemail plug-in configuration file
 #
-# - sets address of smtp server
 #
-# Default: localhost
-#smtp_server=mail
 
-# optional parameter: smtp_port=<port>
 #
-# - sets port of smtp server
+# Generic settings: applicable in any operation mode
 #
-# Default: 25
-#smtp_port=25
 
-# if set, this overrides the email address, meaning that
-# the voicemail will always be sent to that address.
-# email_address = [email protected]
 #
+# Default Voicemail mode:
+#  This sets the main operation mode of this plug-in.
+#
+# - 0: voicemail classic (only send an email)
+# - 1: voicebox (message stored through the msg_storage plug-in; query with 
the voicebox app)
+# - 2: both (send an email AND store with msg_storage)
+# - 3: announcement (play the annoucement but do not record anything)
+#
+# Default value: 0
+#
+default_vm_mode=0
 
-# These are needed if you keep audio and template files in file system:
 #
-# path from which announcements are played:
-announce_path=/usr/local/lib/sems/audio/voicemail/
+# Simple mode:
 #
-# announcement played if no user/domain specific prompt found
-default_announce=default_en.wav
+#  If the simple mode is activated, the user part of the 
+#  request URI is used as the key to store the voicemails. 
 #
-# path for email templates:
-email_template_path=/usr/local/etc/sems/
+#  When the simple mode is de-activated (default), several parameters
+#  have to be passed to SEMS either through the 'P-App-Param' header field
+#  (together with the 'P-App-Name' header field), or through R-URI parameters.
+#
+#  Please note that the simple mode requires a default email address if
+#  either the 'voicemail' or 'both' operation mode has been chosen
+#  (see 'email_address' configuration parameter).
+#
+# Default value: no
+#
+#simple_mode=yes
 
-# These are needed if you keep audio and template files in MySQL database:
-#mysql_host=localhost
-#mysql_user=sems
-#mysql_passwd=sems
-#mysql_db=sems
-
-# These are independent on where audio and template files are kept:
-
 #
 # maximum voicemail message length, in seconds.
 # After the maximum time, the call is ended by SEMS.
@@ -67,6 +68,52 @@
 # Default:
 #  try_personal_greeting=no
 
+
+#
+# These settings are needed if you keep audio and template files in MySQL 
database:
+# (voicemail must have been compiled with MySQL support)
+#
+#mysql_host=localhost
+#mysql_user=sems
+#mysql_passwd=sems
+#mysql_db=sems
+
+# These settings are needed if you keep audio and template files in file 
system:
+#
+# path from which announcements are played:
+announce_path=/usr/local/lib/sems/audio/voicemail/
+#
+# announcement played if no user/domain specific prompt found
+default_announce=default_en.wav
+
+#
+# Options specific to the voicemail mode (and 'both')
+#
+
+# if set, this overrides any other email address, meaning that
+# the voicemail will always be sent to that address.
+#
+# email_address = [email protected]
+
+#
+# optional parameter: smtp_server=<hostname>
+#
+# - sets address of smtp server
+#
+# Default: localhost
+#smtp_server=mail
+
+# optional parameter: smtp_port=<port>
+#
+# - sets port of smtp server
+#
+# Default: 25
+#smtp_port=25
+
+#
+# path for email templates:
+email_template_path=/usr/local/etc/sems/
+
 # mail_header_vars=var1;var2;var3;...
 #
 # Variables that are substituted in the email template with 
@@ -81,3 +128,8 @@
 #                   %sender_count% from this sender.
 #
 # Default: none
+
+
+#
+# These options are applicable to all configurations:
+#

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

Reply via email to