[Freeswitch-svn] [commit] r12881 - in freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket: . Commands General SipEvents

FreeSWITCH SVN verifier at freeswitch.org
Thu Apr 2 03:08:41 PDT 2009


Author: verifier
Date: Thu Apr  2 05:08:41 2009
New Revision: 12881

Log:


Added:
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallLegVariable.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallVariable.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaUnregister.cs
Modified:
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/HoldCmd.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/Originate.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventManager.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventParser.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.pfx
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/FreeSwitch.EventSocket.csproj
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/SofiaSipAddress.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventPresence.cs
   freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaExpire.cs

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/HoldCmd.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/HoldCmd.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/HoldCmd.cs	Thu Apr  2 05:08:41 2009
@@ -13,7 +13,7 @@
 
         public override string Command
         {
-            get { return "hold"; }
+            get { return "uuid_hold"; }
         }
 
         public override string Arguments

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/Originate.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/Originate.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/Commands/Originate.cs	Thu Apr  2 05:08:41 2009
@@ -22,7 +22,7 @@
     {
         private SofiaSipAddress _caller;
         private Address _destination;
-        private readonly IList<ChannelVariable> _variables = new List<ChannelVariable>();
+        private readonly IList<CallVariable> _variables = new List<CallVariable>();
         private string _callerIdName;
         private string _callerIdNumber;
         private bool _varsAdded;
@@ -49,7 +49,7 @@
             set { _destination = value; }
         }
 
-        public IList<ChannelVariable> Variables
+        public IList<CallVariable> Variables
         {
             get { return _variables; }
         }
@@ -77,22 +77,35 @@
             {
                 if (!_varsAdded)
                 {
-                    _variables.Add(new ChannelVariable("origination_caller_id_name", CallerIdName ?? _caller.Extension));
+                    string name = CallerIdName ?? _caller.Extension;
+                    _variables.Add(new CallVariable("origination_caller_id_name", "'" + name + "'"));
                     if (!string.IsNullOrEmpty(_callerIdNumber))
-                        _variables.Add(new ChannelVariable("origination_caller_id_number", _callerIdNumber));
+                        _variables.Add(new CallVariable("origination_caller_id_number", _callerIdNumber));
                     _varsAdded = true;
 
                     if (_autoAnswer)
-                        _variables.Add(new ChannelVariable("sip_auto_answer", "true"));
+                    {
+                        _variables.Add(new CallLegVariable("sip_invite_params", "intercom=true"));
+                        _variables.Add(new CallLegVariable("sip_h_Call-Info", "<sip:$${domain}>;answer-after=0"));
+                        _variables.Add(new CallLegVariable("sip_auto_answer", "true"));
+                    }
                 }
 
                 string variables = string.Empty;
-                foreach (ChannelVariable var in _variables)
-                    variables += var + ",";
+                string legVariables = string.Empty;
+                foreach (CallVariable var in _variables)
+                {
+                    if (var is CallLegVariable)
+                        legVariables += var + ",";
+                    else
+                        variables += var + ",";
+                }
                 if (variables.Length > 0)
                     variables = "{" + variables.Remove(variables.Length - 1, 1) + "}";
+                if (legVariables.Length > 0)
+                    legVariables = "[" + legVariables.Remove(legVariables.Length - 1, 1) + "]";
 
-                return variables + Caller + " " + Destination;
+                return variables + legVariables + Caller + " " + Destination;
             }
         }
 

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventManager.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventManager.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventManager.cs	Thu Apr  2 05:08:41 2009
@@ -73,8 +73,8 @@
         public void Start(string hostname)
         {
             _socket.MessageReceived += OnMessage;
-            _socket.Connect(hostname);
             _socket.DataReceived += OnData;
+            _socket.Connect(hostname);
         }
 
         private void OnData(string data)

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventParser.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventParser.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventParser.cs	Thu Apr  2 05:08:41 2009
@@ -141,18 +141,22 @@
                     _text.CopyTo(i, chars, 0, plainEvent.ContentLength);
                     plainEvent.Body = new string(chars);
 
-                    // check for errors.
-                    int pos = plainEvent.Body.IndexOf("\n\n");
-                    if (pos < plainEvent.Body.Length - 2)
+                    // api/response is buggy for originate, no \n\n are appended at the end.
+                    if (plainEvent.ContentType != "api/response")
                     {
-                        Console.WriteLine("Invalid event");
-                        Console.WriteLine("Header");
-                        Console.WriteLine(headers);
-                        Console.WriteLine("Body");
-                        Console.WriteLine(plainEvent.Body);
-                        Console.WriteLine("=========================== EVERYTHING in _text ==============================");
-                        Console.WriteLine(_text);
-                        throw new InvalidDataException("Invalid event: " + _text);
+                        // check for errors.
+                        int pos = plainEvent.Body.IndexOf("\n\n");
+                        if (pos < plainEvent.Body.Length - 2)
+                        {
+                            Console.WriteLine("Invalid event");
+                            Console.WriteLine("Header");
+                            Console.WriteLine(headers);
+                            Console.WriteLine("Body");
+                            Console.WriteLine(plainEvent.Body);
+                            Console.WriteLine("=========================== EVERYTHING unparsed ==============================");
+                            Console.WriteLine(_text);
+                            throw new InvalidDataException("Invalid event: " + _text);
+                        }
                     }
 
                     if (plainEvent.Body.Length < plainEvent.ContentLength)

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.cs	Thu Apr  2 05:08:41 2009
@@ -198,12 +198,16 @@
             }
             catch (InvalidDataException err)
             {
-                LogWriter(LogPrio.Warning, "Failed to parse event message (" + err.Message + "): " + Environment.NewLine + _parser.Text);
+                LogWriter(LogPrio.Warning,
+                          "Failed to parse event message." + Environment.NewLine + "Exception: " + err +
+                          Environment.NewLine + _parser.Text);
                 HandleDisconnect();
             }
             catch (ArgumentException err)
             {
-                LogWriter(LogPrio.Warning, "Failed to parse event message ("+err.Message+"): " + Environment.NewLine +  _parser.Text);
+                LogWriter(LogPrio.Warning,
+                          "Failed to parse event message." + Environment.NewLine + "Exception: " + err +
+                          Environment.NewLine + _parser.Text);
                 HandleDisconnect();
             }
         }
@@ -260,10 +264,10 @@
             try
             {
                 PlainEventMsg msg = _parser.ParseOne();
-                LogWriter(LogPrio.Trace, "MessageType: " + msg.ContentType);
                 while (msg != null)
                 {
-                    switch (msg.ContentType)
+					LogWriter(LogPrio.Trace, "MessageType: " + msg.ContentType);
+					switch (msg.ContentType)
                     {
                         case "auth/request":
                             {

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/EventSocket.pfx
==============================================================================
Binary files. No diff available.

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/FreeSwitch.EventSocket.csproj
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/FreeSwitch.EventSocket.csproj	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/FreeSwitch.EventSocket.csproj	Thu Apr  2 05:08:41 2009
@@ -70,6 +70,7 @@
     <Compile Include="Commands\SleepCmd.cs" />
     <Compile Include="EventManager.cs" />
     <Compile Include="ChannelEvents\EventDtmfStatus.cs" />
+    <Compile Include="General\CallVariable.cs" />
     <Compile Include="Ivr\DtmfEventArgs.cs" />
     <Compile Include="Ivr\IvrInterface.cs" />
     <Compile Include="Ivr\IvrQueue.cs" />
@@ -90,7 +91,7 @@
     <Compile Include="Events\EventHeartbeat.cs" />
     <Compile Include="Events\EventReSchedule.cs" />
     <Compile Include="General\Address.cs" />
-    <Compile Include="General\ChannelVariable.cs" />
+    <Compile Include="General\CallLegVariable.cs" />
     <Compile Include="General\SipAddress.cs" />
     <Compile Include="General\SofiaSipAddress.cs" />
     <Compile Include="PartyInfo.cs" />
@@ -103,6 +104,7 @@
     <Compile Include="SipEvents\EventPresenceProbe.cs" />
     <Compile Include="SipEvents\EventRoster.cs" />
     <Compile Include="Events\EventMessageWaiting.cs" />
+    <Compile Include="SipEvents\EventSofiaUnregister.cs" />
     <Compile Include="SipEvents\SipEvent.cs" />
     <Compile Include="SipEvents\EventPresence.cs" />
     <Compile Include="SipEvents\EventSofiaExpire.cs" />

Added: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallLegVariable.cs
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallLegVariable.cs	Thu Apr  2 05:08:41 2009
@@ -0,0 +1,22 @@
+namespace FreeSwitch.EventSocket.General
+{
+    /// <summary>
+    /// Variable stored only for a specific leg.
+    /// </summary>
+    /// <remarks>
+    /// Channel variables are used in FreeSWITCH to store information
+    /// that can be used by JavaScript programs.
+    /// </remarks>
+    public class CallLegVariable : CallVariable
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="CallLegVariable"/> class.
+        /// </summary>
+        /// <param name="name">The name.</param>
+        /// <param name="value">The value.</param>
+        public CallLegVariable(string name, string value) : base(name, value)
+        {
+        }
+
+    }
+}

Added: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallVariable.cs
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/CallVariable.cs	Thu Apr  2 05:08:41 2009
@@ -0,0 +1,41 @@
+namespace FreeSwitch.EventSocket.General
+{
+    /// <summary>
+    /// Variable that applies to both legs in a call.
+    /// </summary>
+    /// <remarks>
+    /// Variables can be access from FreeSWITCH with the name
+    /// "variable_[name]"
+    /// </remarks>
+    public class CallVariable
+    {
+        private readonly string _name;
+        private readonly string _value;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="CallVariable"/> class.
+        /// </summary>
+        /// <param name="name">Name of variable.</param>
+        /// <param name="value">Value.</param>
+        public CallVariable(string name, string value)
+        {
+            _name = name;
+            _value = value;
+        }
+
+        public string Name
+        {
+            get { return _name; }
+        }
+
+        public string Value
+        {
+            get { return _value; }
+        }
+
+        public override string ToString()
+        {
+            return _name + "=" + _value;
+        }
+    }
+}

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/SofiaSipAddress.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/SofiaSipAddress.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/General/SofiaSipAddress.cs	Thu Apr  2 05:08:41 2009
@@ -1,44 +1,46 @@
 namespace FreeSwitch.EventSocket.General
 {
+    /// <summary>
+    /// Destination as a FreeSWITCH Sofia sip address.
+    /// </summary>
     public class SofiaSipAddress : Address
     {
-        private readonly string _domain;
+        private readonly string _profileName;
 
-        public SofiaSipAddress(string domain, string userName)
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SofiaSipAddress"/> class.
+        /// </summary>
+        /// <param name="profileName">Profile (context) name.</param>
+        /// <param name="userName">User name (and if needed, IP address / domain name).</param>
+        public SofiaSipAddress(string profileName, string userName)
         {
             Extension = userName;
-            _domain = domain;
+            _profileName = profileName;
         }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SofiaSipAddress"/> class.
+        /// </summary>
+        /// <param name="address">Another address.</param>
         public SofiaSipAddress(SipAddress address)
         {
-            _domain = address.Domain;
+            _profileName = address.Domain;
             Extension = address.Extension;
         }
 
         public override string ToString()
         {
-            return "sofia/mydomain.com/" + Extension + "%" + _domain;
+            return "sofia/" + _profileName + "/" + Extension;
         }
 
         public static SofiaSipAddress Parse(string fullAddress)
         {
             string[] parts = fullAddress.Split('@');
             if (parts.Length == 2)
-            {
                 return new SofiaSipAddress(parts[1], parts[0]);
-            }
-            else
-            {
-                parts = fullAddress.Split('/');
-                if (parts.Length == 3)
-                {
-                    return new SofiaSipAddress(parts[1], parts[2]);
-                }
-            }
 
-            return null;
-            
+            parts = fullAddress.Split('/');
+            return parts.Length == 3 ? new SofiaSipAddress(parts[1], parts[2]) : null;
         }
     }
 }

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventPresence.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventPresence.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventPresence.cs	Thu Apr  2 05:08:41 2009
@@ -95,14 +95,8 @@
                             Caller = new PartyInfo();
                         return Caller.Parse(name.Substring(7), value);
                     }
-                    else
-                    {
-                        if (base.ParseCommand(name, value))
-                            return true;
-                        else
-                            return res;
-                    }
-                        
+
+                    return base.ParseCommand(name, value) || res;
             }
             return true;
         }

Modified: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaExpire.cs
==============================================================================
--- freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaExpire.cs	(original)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaExpire.cs	Thu Apr  2 05:08:41 2009
@@ -1,11 +1,15 @@
+using System;
+
 namespace FreeSwitch.EventSocket
 {
     public class EventSofiaExpire : EventPresence
     {
+        private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1);
         private string _profileName;
         private string _userName;
         private string _domain;
         private string _userAgent;
+        private DateTime _expires;
 
         public string ProfileName
         {
@@ -31,6 +35,12 @@
             set { _userAgent = value; }
         }
 
+        public DateTime Expires
+        {
+            get { return _expires; }
+            set { _expires = value; }
+        }
+
         /*
 				switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", argv[6]);
 			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[1]);
@@ -50,6 +60,11 @@
                 case "host":
                     _domain = value;
                     break;
+                case "expires":
+                    int seconds;
+                    if (int.TryParse(value, out seconds))
+                        _expires = UnixEpoch.AddSeconds(seconds);
+                    break;
                 case "user-agent":
                     _userAgent = value;
                     break;

Added: freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaUnregister.cs
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/verifier/EventSocket/trunk/FreeSwitchEventSocket/SipEvents/EventSofiaUnregister.cs	Thu Apr  2 05:08:41 2009
@@ -0,0 +1,87 @@
+namespace FreeSwitch.EventSocket.SipEvents
+{
+    public class EventSofiaUnregister : EventBase
+{
+        private string _domain;
+        private string _profileName;
+        private string _user;
+        private string _contact;
+        private string _callId;
+        private int _expires;
+
+        public string ProfileName
+        {
+            get { return _profileName; }
+            set { _profileName = value; }
+        }
+
+        public string UserName
+        {
+            get { return _user; }
+            set { _user = value; }
+        }
+
+        public string Domain
+        {
+            get { return _domain; }
+            set { _domain = value; }
+        }
+
+        public string Contact
+        {
+            get { return _contact; }
+            set { _contact = value; }
+        }
+
+        public string CallId
+        {
+            get { return _callId; }
+            set { _callId = value; }
+        }
+
+        public int Expires
+        {
+            get { return _expires; }
+            set { _expires = value; }
+        }
+
+        /*
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", profile->name);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-user", "%s", to_user);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", to_host);
+			switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
+        */        
+        public override bool ParseCommand(string name, string value)
+        {
+            switch (name)
+            {
+                case "profile-name":
+                    _profileName = value;
+                    break;
+                case "from-user":
+                    _user = value;
+                    break;
+                case "from-host":
+                    _domain = value;
+                    break;
+                case "contact":
+                    _contact = value;
+                    break;
+                case "call-id":
+                    _callId = value;
+                    break;
+                case "expires":
+                    int.TryParse(value, out _expires);
+                    break;
+                default:
+                    return base.ParseCommand(name, value);
+            }
+            return true;
+        }
+
+        public override string ToString()
+        {
+            return "SofiaUnregister(" + _user + "@" + _domain + ", " + _expires + ")." + base.ToString();
+        }
+    }
+}



More information about the Freeswitch-svn mailing list