/// <summary>
/// Parses SIP_Uri from SIP-URI string.
/// </summary>
/// <param name="value">SIP-URI string.</param>
/// <returns>Returns parsed SIP_Uri object.</returns>
/// <exception cref="ArgumentNullException">Raised when <b>reader</b> is null.</exception>
/// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
protected override void ParseInternal(string value)
{
// Syntax: sip:/sips: username@host:port *[;parameter] [?header *[&header]]
if (value == null)
{
throw new ArgumentNullException("value");
}
value = Uri.UnescapeDataString(value);
if (!(value.ToLower().StartsWith("sip:") || value.ToLower().StartsWith("sips:")))
{
throw new SIP_ParseException("Specified value is invalid SIP-URI !");
}
StringReader r = new StringReader(value);
// IsSecure
this.IsSecure = r.QuotedReadToDelimiter(':').ToLower() == "sips";
// Get username
if (r.SourceString.IndexOf('@') > -1)
{
this.User = r.QuotedReadToDelimiter('@');
}
// Gets host[:port]
string[] host_port = r.QuotedReadToDelimiter(new char[] { ';', '?' }, false).Split(':');
this.Host = host_port[0];
// Optional port specified
if (host_port.Length == 2)
{
this.Port = Convert.ToInt32(host_port[1]);
}
// We have parameters and/or header
if (r.Available > 0)
{
// Get parameters
string[] parameters = TextUtils.SplitQuotedString(r.QuotedReadToDelimiter('?'), ';');
foreach (string parameter in parameters)
{
if (parameter.Trim() != "")
{
string[] name_value = parameter.Trim().Split(new char[] { '=' }, 2);
if (name_value.Length == 2)
{
this.Parameters.Add(name_value[0], TextUtils.UnQuoteString(name_value[1]));
}
else
{
this.Parameters.Add(name_value[0], null);
}
}
}
// We have header
if (r.Available > 0)
{
this.m_Header = r.ReadToEnd();
}
}
}