提交 5912eb1a authored 作者: Jonas Gauffin's avatar Jonas Gauffin

fixed hangup cause parsing.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/scripts/contrib@8297 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 5512435b
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace FreeSwitch.EventSocket namespace FreeSwitch.EventSocket
{ {
public class EventChannelHangup : EventChannelState public class EventChannelHangup : EventChannelState
{ {
private Causes m_hangupCause; private HangupCause _hangupCause;
public enum Causes
{
Success,
NoRouteTransitNet,
NoRouteDestination,
ChannelUnacceptable,
CallAwardedDelivered,
NormalClearing,
UserBusy,
NoUserResponse,
NoAnswer,
SubscriberAbsent,
CallRejected,
NumberChanged,
RedirectionToNewDestination,
ExchangeRoutingError,
DestinationOutOfOrder,
InvalidNumberFormat,
FacilityRejected,
ResponseToStatusEnquiry,
NormalUnspecified,
NormalCircuitCongestion,
NetworkOutOfOrder,
NormalTemporaryFailure,
SwitchCongestion,
AccessInfoDiscarded,
RequestedChanUnavail,
PreEmpted,
FacilityNotSubscribed,
OutgoingCallBarred,
IncomingCallBarred,
BearercapabilityNotauth,
BearercapabilityNotavail,
ServiceUnavailable,
ChanNotImplemented,
FacilityNotImplemented,
ServiceNotImplemented,
InvalidCallReference,
IncompatibleDestination,
InvalidMsgUnspecified,
MandatoryIeMissing,
MessageTypeNonexist,
WrongMessage,
IeNonexist,
InvalidIeContents,
WrongCallState,
RecoveryOnTimerExpire,
MandatoryIeLengthError,
ProtocolError,
Interworking,
OriginatorCancel,
Crash,
SystemShutdown,
LoseRace,
ManagerRequest,
BlindTransfer,
AttendedTransfer,
AllottedTimeout
}
public Causes Cause public HangupCause Cause
{ {
get { return m_hangupCause; } get { return _hangupCause; }
set { m_hangupCause = value; } set { _hangupCause = value; }
} }
public override bool ParseCommand(string name, string value) public override bool ParseCommand(string name, string value)
...@@ -79,7 +18,14 @@ namespace FreeSwitch.EventSocket ...@@ -79,7 +18,14 @@ namespace FreeSwitch.EventSocket
if (name == "hangupcause" || name == "hangup-cause") if (name == "hangupcause" || name == "hangup-cause")
{ {
string cause = StringHelper.UpperCaseToCamelCase(value); string cause = StringHelper.UpperCaseToCamelCase(value);
m_hangupCause = (Causes)Enum.Parse(typeof(Causes), cause); try
{
_hangupCause = (HangupCause)Enum.Parse(typeof(HangupCause), cause, true);
}
catch(ArgumentException)
{
_hangupCause = HangupCause.Unknown;
}
} }
else else
return base.ParseCommand(name, value); return base.ParseCommand(name, value);
...@@ -88,4 +34,67 @@ namespace FreeSwitch.EventSocket ...@@ -88,4 +34,67 @@ namespace FreeSwitch.EventSocket
} }
} }
public enum HangupCause
{
Success,
NoRouteTransitNet,
NoRouteDestination,
ChannelUnacceptable,
CallAwardedDelivered,
NormalClearing,
UserBusy,
NoUserResponse,
NoAnswer,
SubscriberAbsent,
CallRejected,
NumberChanged,
RedirectionToNewDestination,
ExchangeRoutingError,
DestinationOutOfOrder,
InvalidNumberFormat,
FacilityRejected,
ResponseToStatusEnquiry,
NormalUnspecified,
NormalCircuitCongestion,
NetworkOutOfOrder,
NormalTemporaryFailure,
SwitchCongestion,
AccessInfoDiscarded,
RequestedChanUnavail,
PreEmpted,
FacilityNotSubscribed,
OutgoingCallBarred,
IncomingCallBarred,
BearercapabilityNotauth,
BearercapabilityNotavail,
ServiceUnavailable,
ChanNotImplemented,
FacilityNotImplemented,
ServiceNotImplemented,
InvalidCallReference,
IncompatibleDestination,
InvalidMsgUnspecified,
MandatoryIeMissing,
MessageTypeNonexist,
WrongMessage,
IeNonexist,
InvalidIeContents,
WrongCallState,
RecoveryOnTimerExpire,
MandatoryIeLengthError,
ProtocolError,
Interworking,
OriginatorCancel,
Crash,
SystemShutdown,
LoseRace,
ManagerRequest,
BlindTransfer,
AttendedTransfer,
AllottedTimeout,
UnAllocated,
Unknown
}
} }
...@@ -19,16 +19,16 @@ namespace FreeSwitch.EventSocket ...@@ -19,16 +19,16 @@ namespace FreeSwitch.EventSocket
public class ChannelInfo public class ChannelInfo
{ {
private ChannelState m_state; private ChannelState _state;
private int m_stateNumber; private int _stateNumber;
private string _profile; private string _profile;
private string m_address; private string _address;
private string _hostName; private string _hostName;
private string m_protocol = string.Empty; private string _protocol = string.Empty;
private string m_readCodecName; private string _readCodecName;
private int m_readCodecRate; private int _readCodecRate;
private string m_writeCodecName; private string _writeCodecName;
private int m_writeCodecRate; private int _writeCodecRate;
/// <summary> /// <summary>
/// Coded used to read information from the channel. /// Coded used to read information from the channel.
...@@ -36,8 +36,8 @@ namespace FreeSwitch.EventSocket ...@@ -36,8 +36,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public string ReadCodecName public string ReadCodecName
{ {
get { return m_readCodecName; } get { return _readCodecName; }
set { m_readCodecName = value; } set { _readCodecName = value; }
} }
/// <summary> /// <summary>
...@@ -46,8 +46,8 @@ namespace FreeSwitch.EventSocket ...@@ -46,8 +46,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public int ReadCodecRate public int ReadCodecRate
{ {
get { return m_readCodecRate; } get { return _readCodecRate; }
set { m_readCodecRate = value; } set { _readCodecRate = value; }
} }
/// <summary> /// <summary>
...@@ -56,8 +56,8 @@ namespace FreeSwitch.EventSocket ...@@ -56,8 +56,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public string WriteCodecName public string WriteCodecName
{ {
get { return m_writeCodecName; } get { return _writeCodecName; }
set { m_writeCodecName = value; } set { _writeCodecName = value; }
} }
/// <summary> /// <summary>
...@@ -66,8 +66,8 @@ namespace FreeSwitch.EventSocket ...@@ -66,8 +66,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public int WriteCodecRate public int WriteCodecRate
{ {
get { return m_writeCodecRate; } get { return _writeCodecRate; }
set { m_writeCodecRate = value; } set { _writeCodecRate = value; }
} }
/// <summary> /// <summary>
...@@ -75,8 +75,8 @@ namespace FreeSwitch.EventSocket ...@@ -75,8 +75,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public ChannelState State public ChannelState State
{ {
get { return m_state; } get { return _state; }
set { m_state = value; } set { _state = value; }
} }
/// <summary> /// <summary>
...@@ -84,8 +84,8 @@ namespace FreeSwitch.EventSocket ...@@ -84,8 +84,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public int StateNumber public int StateNumber
{ {
get { return m_stateNumber; } get { return _stateNumber; }
set { m_stateNumber = value; } set { _stateNumber = value; }
} }
/// <summary> /// <summary>
...@@ -98,22 +98,22 @@ namespace FreeSwitch.EventSocket ...@@ -98,22 +98,22 @@ namespace FreeSwitch.EventSocket
/// <seealso cref="HostName"/> /// <seealso cref="HostName"/>
public string Name public string Name
{ {
get { return m_protocol + "/" + _profile + "/" + m_address + "@" + _hostName; } get { return _protocol + "/" + _profile + "/" + _address + "@" + _hostName; }
set set
{ {
string[] bits = value.Split('/'); string[] bits = value.Split('/');
if (bits.Length == 3) if (bits.Length == 3)
{ {
m_protocol = bits[0]; _protocol = bits[0];
_profile = bits[1]; _profile = bits[1];
string[] userParts = bits[2].Split('@'); string[] userParts = bits[2].Split('@');
if (userParts.Length == 2) if (userParts.Length == 2)
{ {
m_address = userParts[0]; _address = userParts[0];
HostName = userParts[1]; HostName = userParts[1];
} }
else else
m_address = bits[2]; _address = bits[2];
} }
} }
...@@ -133,8 +133,8 @@ namespace FreeSwitch.EventSocket ...@@ -133,8 +133,8 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public string Address public string Address
{ {
get { return m_address; } get { return _address; }
set { m_address = value; } set { _address = value; }
} }
/// <summary> /// <summary>
...@@ -165,7 +165,7 @@ namespace FreeSwitch.EventSocket ...@@ -165,7 +165,7 @@ namespace FreeSwitch.EventSocket
/// </summary> /// </summary>
public string Protocol public string Protocol
{ {
get { return m_protocol; } get { return _protocol; }
} }
public bool Parse(string name, string value) public bool Parse(string name, string value)
...@@ -173,25 +173,25 @@ namespace FreeSwitch.EventSocket ...@@ -173,25 +173,25 @@ namespace FreeSwitch.EventSocket
switch (name) switch (name)
{ {
case "channel-state": case "channel-state":
m_state = StateFromString(value); _state = StateFromString(value);
break; break;
case "channel-state-number": case "channel-state-number":
int.TryParse(value, out m_stateNumber); int.TryParse(value, out _stateNumber);
break; break;
case "channel-name": case "channel-name":
Name = value; Name = value;
break; break;
case "channel-read-codec-name": case "channel-read-codec-name":
m_readCodecName = value; _readCodecName = value;
break; break;
case "channel-read-codec-rate": case "channel-read-codec-rate":
int.TryParse(value, out m_readCodecRate); int.TryParse(value, out _readCodecRate);
break; break;
case "channel-write-codec-name": case "channel-write-codec-name":
m_writeCodecName = value; _writeCodecName = value;
break; break;
case "channel-write-codec-rate": case "channel-write-codec-rate":
int.TryParse(value, out m_writeCodecRate); int.TryParse(value, out _writeCodecRate);
break; break;
default: default:
return false; return false;
......
using System;
namespace FreeSwitch.EventSocket.Commands
{
public class DeflectCmd : SendMsg
{
private readonly string _uri;
/// <summary>
///
/// </summary>
/// <param name="uuid">session id</param>
/// <param name="sipUri">complete sip uri, with or whithout "sip:"</param>
public DeflectCmd(string uuid, string sipUri)
: base(uuid, "execute")
{
if (string.IsNullOrEmpty(sipUri))
throw new ArgumentNullException("sipUri");
_uri = sipUri;
}
public DeflectCmd(string uuid) : base(uuid)
{
}
public override string Command
{
get { return "deflect"; }
}
public override string Arguments
{
get { return _uri; }
}
}
}
using System;
namespace FreeSwitch.EventSocket.Commands namespace FreeSwitch.EventSocket.Commands
{ {
public abstract class SendMsg : CmdBase public abstract class SendMsg : CmdBase
...@@ -7,11 +9,18 @@ namespace FreeSwitch.EventSocket.Commands ...@@ -7,11 +9,18 @@ namespace FreeSwitch.EventSocket.Commands
public SendMsg(string uuid) public SendMsg(string uuid)
{ {
if (string.IsNullOrEmpty(uuid))
throw new ArgumentNullException("uuid");
_uuid = uuid; _uuid = uuid;
} }
public SendMsg(string uuid, string callCommand) public SendMsg(string uuid, string callCommand)
{ {
if (string.IsNullOrEmpty(uuid))
throw new ArgumentNullException("uuid");
if (string.IsNullOrEmpty(callCommand))
throw new ArgumentNullException("callCommand");
_callCommand = callCommand; _callCommand = callCommand;
_uuid = uuid; _uuid = uuid;
} }
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<Compile Include="Commands\AuthCommand.cs" /> <Compile Include="Commands\AuthCommand.cs" />
<Compile Include="Commands\CmdBase.cs" /> <Compile Include="Commands\CmdBase.cs" />
<Compile Include="Commands\CommandReply.cs" /> <Compile Include="Commands\CommandReply.cs" />
<Compile Include="Commands\DeflectCmd.cs" />
<Compile Include="Commands\ExecuteJavascript.cs" /> <Compile Include="Commands\ExecuteJavascript.cs" />
<Compile Include="Commands\GetVariable.cs" /> <Compile Include="Commands\GetVariable.cs" />
<Compile Include="Commands\HoldCmd.cs" /> <Compile Include="Commands\HoldCmd.cs" />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论