Merge pull request #252 from AsterNET/AsterNET-1.x_merge_to_Master

Merge AsterNET 1.x changes to master
This commit is contained in:
Deantwo 2021-04-23 11:58:00 +02:00 committed by GitHub
commit c23d932609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 148 additions and 94 deletions

View file

@ -18,7 +18,7 @@ namespace AsterNET
/// <summary>Line separator</summary> /// <summary>Line separator</summary>
public const string LINE_SEPARATOR = "\r\n"; public const string LINE_SEPARATOR = "\r\n";
public static Regex ASTERISK_VERSION = new Regex( "^Asterisk\\s+\\D*([0-9]+.[0-9]+.[0-9]+|[1-9][0-9]-r[0-9]+|[0-9]+.[0-9]+-cert[0-9]).*$", public static Regex ASTERISK_VERSION = new Regex( "^Asterisk\\s+\\D*([0-9]+\\.[0-9]+\\.[0-9]+|[1-9][0-9]-r[0-9]+|[0-9]+\\.[0-9]+-cert[0-9]).*$",
RegexOptions.Compiled | RegexOptions.IgnoreCase ); RegexOptions.Compiled | RegexOptions.IgnoreCase );
public static Regex SHOW_VERSION_FILES_PATTERN = new Regex("^([\\S]+)\\s+Revision: ([0-9\\.]+)"); public static Regex SHOW_VERSION_FILES_PATTERN = new Regex("^([\\S]+)\\s+Revision: ([0-9\\.]+)");

View file

@ -5,6 +5,7 @@ namespace AsterNET.Manager
/// </summary> /// </summary>
public enum AsteriskVersion public enum AsteriskVersion
{ {
Unknown = 0,
ASTERISK_1_0 = 10, ASTERISK_1_0 = 10,
ASTERISK_1_2 = 12, ASTERISK_1_2 = 12,
ASTERISK_1_4 = 14, ASTERISK_1_4 = 14,
@ -13,6 +14,11 @@ namespace AsterNET.Manager
ASTERISK_10 = 100, ASTERISK_10 = 100,
ASTERISK_11 = 110, ASTERISK_11 = 110,
ASTERISK_12 = 120, ASTERISK_12 = 120,
ASTERISK_13 = 130 ASTERISK_13 = 130,
ASTERISK_14 = 140,
ASTERISK_15 = 150,
ASTERISK_16 = 160,
ASTERISK_17 = 170,
ASTERISK_Newer = 999
} }
} }

View file

@ -71,7 +71,7 @@ namespace AsterNET.Manager
/// <summary> Default Slow Reconnect interval in milliseconds.</summary> /// <summary> Default Slow Reconnect interval in milliseconds.</summary>
private int reconnectIntervalMax = 10000; private int reconnectIntervalMax = 10000;
public char[] VAR_DELIMITER = { '|' }; public char[] VAR_DELIMITER = { '|' };
#endregion #endregion
@ -1012,102 +1012,130 @@ namespace AsterNET.Manager
#if LOGGER #if LOGGER
logger.Info("Determined Asterisk version: " + asteriskVersion); logger.Info("Determined Asterisk version: " + asteriskVersion);
#endif #endif
enableEvents = true; enableEvents = true;
ConnectEvent ce = new ConnectEvent(this); ConnectEvent ce = new ConnectEvent(this);
ce.ProtocolIdentifier = this.protocolIdentifier; ce.ProtocolIdentifier = this.protocolIdentifier;
DispatchEvent(ce); DispatchEvent(ce);
} }
else if (response is ManagerError) else if (response is ManagerError)
throw new ManagerException("Unable login to Asterisk - " + response.Message); throw new ManagerException("Unable login to Asterisk - " + response.Message);
else else
throw new ManagerException("Unknown response during login to Asterisk - " + response.GetType().Name + " with message " + response.Message); throw new ManagerException("Unknown response during login to Asterisk - " + response.GetType().Name + " with message " + response.Message);
} }
#endregion #endregion
#region determineVersion() #region determineVersion()
protected internal AsteriskVersion determineVersion() protected internal AsteriskVersion determineVersion()
{ {
Response.ManagerResponse response; Response.ManagerResponse response;
response = SendAction(new Action.CommandAction("core show version"), defaultResponseTimeout * 2); response = SendAction(new Action.CommandAction("core show version"), defaultResponseTimeout * 2);
if (response is Response.CommandResponse) if (response is Response.CommandResponse)
{ {
foreach (string line in ((Response.CommandResponse)response).Result) foreach (string line in ((Response.CommandResponse)response).Result)
{ {
foreach (Match m in Common.ASTERISK_VERSION.Matches(line)) foreach (Match m in Common.ASTERISK_VERSION.Matches(line))
{ {
if (m.Groups.Count >= 2) if (m.Groups.Count >= 2)
{ {
version = m.Groups[1].Value; version = m.Groups[1].Value;
if (version.StartsWith("1.4.")) if (version.StartsWith("1.4."))
{ {
VAR_DELIMITER = new char[] { '|' }; VAR_DELIMITER = new char[] { '|' };
return AsteriskVersion.ASTERISK_1_4; return AsteriskVersion.ASTERISK_1_4;
} }
else if (version.StartsWith("1.6.")) else if (version.StartsWith("1.6."))
{ {
VAR_DELIMITER = new char[] { '|' }; VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_1_6; return Manager.AsteriskVersion.ASTERISK_1_6;
} }
else if (version.StartsWith("1.8.")) else if (version.StartsWith("1.8."))
{ {
VAR_DELIMITER = new char[] { '|' }; VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_1_8; return Manager.AsteriskVersion.ASTERISK_1_8;
} }
else if (version.StartsWith("10.")) else if (version.StartsWith("10."))
{ {
VAR_DELIMITER = new char[] { '|' }; VAR_DELIMITER = new char[] { '|' };
return Manager.AsteriskVersion.ASTERISK_10; return Manager.AsteriskVersion.ASTERISK_10;
} }
else if (version.StartsWith("11.")) else if (version.StartsWith("11."))
{ {
VAR_DELIMITER = new char[] { ',' }; VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_11; return Manager.AsteriskVersion.ASTERISK_11;
} }
else if (version.StartsWith("12.")) else if (version.StartsWith("12."))
{ {
VAR_DELIMITER = new char[] { ',' }; VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_12; return Manager.AsteriskVersion.ASTERISK_12;
} }
else if (version.StartsWith("13.")) else if (version.StartsWith("13."))
{ {
VAR_DELIMITER = new char[] { ',' }; VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_13; return Manager.AsteriskVersion.ASTERISK_13;
} }
else else if (version.StartsWith("14."))
throw new ManagerException("Unknown Asterisk version " + version); {
} VAR_DELIMITER = new char[] { ',' };
} return Manager.AsteriskVersion.ASTERISK_14;
} }
} else if (version.StartsWith("15."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_15;
}
else if (version.StartsWith("16."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_16;
}
else if (version.StartsWith("17."))
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_17;
}
else if (version.IndexOf('.') >= 2)
{
VAR_DELIMITER = new char[] { ',' };
return Manager.AsteriskVersion.ASTERISK_Newer;
}
else
throw new ManagerException("Unknown Asterisk version " + version);
}
}
}
}
Response.ManagerResponse showVersionFilesResponse = SendAction(new Action.CommandAction("show version files"), defaultResponseTimeout * 2); Response.ManagerResponse showVersionFilesResponse = SendAction(new Action.CommandAction("show version files"), defaultResponseTimeout * 2);
if (showVersionFilesResponse is Response.CommandResponse) if (showVersionFilesResponse is Response.CommandResponse)
{ {
IList showVersionFilesResult = ((Response.CommandResponse)showVersionFilesResponse).Result; IList showVersionFilesResult = ((Response.CommandResponse)showVersionFilesResponse).Result;
if (showVersionFilesResult != null && showVersionFilesResult.Count > 0) if (showVersionFilesResult != null && showVersionFilesResult.Count > 0)
{ {
string line1; string line1;
line1 = (string)showVersionFilesResult[0]; line1 = (string)showVersionFilesResult[0];
if (line1 != null && line1.StartsWith("File")) if (line1 != null && line1.StartsWith("File"))
return AsteriskVersion.ASTERISK_1_2; {
} VAR_DELIMITER = new char[] { '|' };
} return AsteriskVersion.ASTERISK_1_2;
return AsteriskVersion.ASTERISK_1_0; }
} }
}
return AsteriskVersion.ASTERISK_1_0;
}
#endregion #endregion
#region connect() #region connect()
protected internal bool connect() protected internal bool connect()
{ {
bool result = false; bool result = false;
bool startReader = false; bool startReader = false;
lock (lockSocket) lock (lockSocket)
{ {
if (mrSocket == null) if (mrSocket == null)
{ {
#if LOGGER #if LOGGER
logger.Info("Connecting to {0}:{1}", hostname, port); logger.Info("Connecting to {0}:{1}", hostname, port);
#endif #endif

View file

@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("AsterNET")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AsterNET")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: Guid("abe98502-ea83-4b04-98c3-ffe3eabe06b0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]