提交 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.Collections.Generic;
using System.Text;
namespace FreeSwitch.EventSocket
{
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; }
set { m_hangupCause = value; }
get { return _hangupCause; }
set { _hangupCause = value; }
}
public override bool ParseCommand(string name, string value)
......@@ -79,7 +18,14 @@ namespace FreeSwitch.EventSocket
if (name == "hangupcause" || name == "hangup-cause")
{
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
return base.ParseCommand(name, value);
......@@ -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
public class ChannelInfo
{
private ChannelState m_state;
private int m_stateNumber;
private ChannelState _state;
private int _stateNumber;
private string _profile;
private string m_address;
private string _address;
private string _hostName;
private string m_protocol = string.Empty;
private string m_readCodecName;
private int m_readCodecRate;
private string m_writeCodecName;
private int m_writeCodecRate;
private string _protocol = string.Empty;
private string _readCodecName;
private int _readCodecRate;
private string _writeCodecName;
private int _writeCodecRate;
/// <summary>
/// Coded used to read information from the channel.
......@@ -36,8 +36,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public string ReadCodecName
{
get { return m_readCodecName; }
set { m_readCodecName = value; }
get { return _readCodecName; }
set { _readCodecName = value; }
}
/// <summary>
......@@ -46,8 +46,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public int ReadCodecRate
{
get { return m_readCodecRate; }
set { m_readCodecRate = value; }
get { return _readCodecRate; }
set { _readCodecRate = value; }
}
/// <summary>
......@@ -56,8 +56,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public string WriteCodecName
{
get { return m_writeCodecName; }
set { m_writeCodecName = value; }
get { return _writeCodecName; }
set { _writeCodecName = value; }
}
/// <summary>
......@@ -66,8 +66,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public int WriteCodecRate
{
get { return m_writeCodecRate; }
set { m_writeCodecRate = value; }
get { return _writeCodecRate; }
set { _writeCodecRate = value; }
}
/// <summary>
......@@ -75,8 +75,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public ChannelState State
{
get { return m_state; }
set { m_state = value; }
get { return _state; }
set { _state = value; }
}
/// <summary>
......@@ -84,8 +84,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public int StateNumber
{
get { return m_stateNumber; }
set { m_stateNumber = value; }
get { return _stateNumber; }
set { _stateNumber = value; }
}
/// <summary>
......@@ -98,22 +98,22 @@ namespace FreeSwitch.EventSocket
/// <seealso cref="HostName"/>
public string Name
{
get { return m_protocol + "/" + _profile + "/" + m_address + "@" + _hostName; }
get { return _protocol + "/" + _profile + "/" + _address + "@" + _hostName; }
set
{
string[] bits = value.Split('/');
if (bits.Length == 3)
{
m_protocol = bits[0];
_protocol = bits[0];
_profile = bits[1];
string[] userParts = bits[2].Split('@');
if (userParts.Length == 2)
{
m_address = userParts[0];
_address = userParts[0];
HostName = userParts[1];
}
else
m_address = bits[2];
_address = bits[2];
}
}
......@@ -133,8 +133,8 @@ namespace FreeSwitch.EventSocket
/// </summary>
public string Address
{
get { return m_address; }
set { m_address = value; }
get { return _address; }
set { _address = value; }
}
/// <summary>
......@@ -165,7 +165,7 @@ namespace FreeSwitch.EventSocket
/// </summary>
public string Protocol
{
get { return m_protocol; }
get { return _protocol; }
}
public bool Parse(string name, string value)
......@@ -173,25 +173,25 @@ namespace FreeSwitch.EventSocket
switch (name)
{
case "channel-state":
m_state = StateFromString(value);
_state = StateFromString(value);
break;
case "channel-state-number":
int.TryParse(value, out m_stateNumber);
int.TryParse(value, out _stateNumber);
break;
case "channel-name":
Name = value;
break;
case "channel-read-codec-name":
m_readCodecName = value;
_readCodecName = value;
break;
case "channel-read-codec-rate":
int.TryParse(value, out m_readCodecRate);
int.TryParse(value, out _readCodecRate);
break;
case "channel-write-codec-name":
m_writeCodecName = value;
_writeCodecName = value;
break;
case "channel-write-codec-rate":
int.TryParse(value, out m_writeCodecRate);
int.TryParse(value, out _writeCodecRate);
break;
default:
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
{
public abstract class SendMsg : CmdBase
......@@ -7,11 +9,18 @@ namespace FreeSwitch.EventSocket.Commands
public SendMsg(string uuid)
{
if (string.IsNullOrEmpty(uuid))
throw new ArgumentNullException("uuid");
_uuid = uuid;
}
public SendMsg(string uuid, string callCommand)
{
if (string.IsNullOrEmpty(uuid))
throw new ArgumentNullException("uuid");
if (string.IsNullOrEmpty(callCommand))
throw new ArgumentNullException("callCommand");
_callCommand = callCommand;
_uuid = uuid;
}
......
......@@ -54,6 +54,7 @@
<Compile Include="Commands\AuthCommand.cs" />
<Compile Include="Commands\CmdBase.cs" />
<Compile Include="Commands\CommandReply.cs" />
<Compile Include="Commands\DeflectCmd.cs" />
<Compile Include="Commands\ExecuteJavascript.cs" />
<Compile Include="Commands\GetVariable.cs" />
<Compile Include="Commands\HoldCmd.cs" />
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论