本文整理汇总了C#中Transaction.SendResponse方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.SendResponse方法的具体用法?C# Transaction.SendResponse怎么用?C# Transaction.SendResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.SendResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceivedRequest
public override void ReceivedRequest(Transaction transaction, Message request)
{
//try
//{
if ((transaction != null) && Transaction != null && Transaction != transaction &&
request.Method.ToUpper() != "CANCEL")
{
Debug.Assert(false, "Invalid transaction for received request");
}
Server = true;
if (!request.Uri.Scheme.ToLower().Equals("sip"))
{
SendResponse(416, "Unsupported URI scheme");
return;
}
if (request.First("Max-Forwards") != null &&
int.Parse(request.First("Max-Forwards").Value.ToString()) < 0)
{
SendResponse(483, "Too many hops");
return;
}
if (!request.Headers["To"][0].Attributes.ContainsKey("tag") && transaction != null)
{
if (Stack.FindOtherTransactions(request, transaction) != null)
{
//SendResponse(482, "Loop detected - found another transaction");
return;
}
}
if (request.First("Proxy-Require") != null)
{
if (!request.Method.ToUpper().Contains("CANCEL") && !request.Method.ToUpper().Contains("ACK"))
{
Message response = CreateResponse(420, "Bad extension");
Header unsupported = request.First("Proxy-Require");
unsupported.Name = "Unsupported";
response.InsertHeader(unsupported);
SendResponse(unsupported);
return;
}
}
if (transaction != null)
{
Transaction = transaction;
}
if (request.Method.ToUpper() == "CANCEL")
{
string branch;
if (request.First("Via") != null && request.First("Via").Attributes.ContainsKey("branch"))
{
branch = request.First("Via").Attributes["branch"];
}
else
{
branch = Transaction.CreateBranch(request, true);
}
Transaction original = Stack.FindTransaction(Transaction.CreateId(branch, "INVITE"));
if (original != null)
{
if (original.State == "proceeding" || original.State == "trying")
{
original.SendResponse(original.CreateResponse(487, "Request terminated"));
}
transaction = Transaction.CreateServer(Stack, this, request, Stack.Transport,
Stack.Tag, false);
transaction.SendResponse(transaction.CreateResponse(200, "OK"));
}
SendCancel();
return;
}
if (string.IsNullOrEmpty(request.Uri.User) && IsLocal(request.Uri) && request.Uri.Parameters != null &&
request.First("Route") != null)
{
Header lastRoute = request.Headers["Route"].Last();
request.Headers["Route"].RemoveAt(request.Headers["Route"].Count - 1);
request.Uri = ((Address)(lastRoute.Value)).Uri;
}
if (request.First("Route") != null && IsLocal(((Address)(request.First("Route").Value)).Uri))
{
request.Headers["Route"].RemoveAt(0);
request.had_lr = true;
}
Stack.ReceivedRequest(this, request);
//}
//catch (Exception)
//{
// throw;
//}
}
示例2: ReceivedRequest
/// <summary>
/// Virtual function to receive a request.
/// </summary>
/// <param name="transaction">The transaction.</param>
/// <param name="request">The request.</param>
public virtual void ReceivedRequest(Transaction transaction, Message request)
{
if ((transaction != null) && (Transaction != null) && (transaction != Transaction) &&
(request.Method != "CANCEL"))
{
Transaction t = Transaction;
Transaction t2 = transaction;
bool test = Transaction.TEquals(t, request, t2);
Console.WriteLine("Invalid transaction for received request {0} != {1}, {2}", transaction, Transaction,
test);
// TODO: Re-enable this
Debug.Assert(false,
String.Format("Invalid transaction for received request {0} != {1}", transaction,
Transaction));
return;
}
Server = true;
//if request.method == 'REGISTER':
//response = transaction.createResponse(405, 'Method not allowed')
//response.Allow = Header('INVITE, ACK, CANCEL, BYE', 'Allow') # TODO make this configurable
//transaction.sendResponse(response)
//return;
if (request.Uri.Scheme != "sip")
{
transaction.SendResponse(transaction.CreateResponse(416, "Unsupported URI scheme"));
return;
}
if (!request.Headers["To"][0].ToString().Contains("tag"))
{
if (Stack.FindOtherTransactions(request, transaction) != null)
{
transaction.SendResponse(transaction.CreateResponse(482, "Loop Detected - found another transaction"));
}
}
// TODO Fix support of Require Header
//if (request.headers.ContainsKey("Require"))
//{
// if ((request.method != "CANCEL") && (request.method != "ACK"))
// {
// Message response = transaction.createResponse(420, "Bad extension");
// response.insertHeader(new Header(request.headers["Require"][0].value.ToString(), "Unsupported"));
// transaction.sendResponse(response);
// return;
// }
//}
if (Transaction != null)
{
Transaction = transaction;
}
if (request.Method == "CANCEL")
{
Transaction original = Stack.FindTransaction(Transaction.CreateId(transaction.Branch, "Invite"));
if (original == null)
{
transaction.SendResponse(transaction.CreateResponse(481, "Cannot find transaction??"));
return;
}
if (original.State == "proceeding" || original.State == "trying")
{
original.SendResponse(original.CreateResponse(487, "Request terminated"));
}
transaction.SendResponse(transaction.CreateResponse(200, "OK"));
// TODO: The To tag must be the same in the two responses
}
Stack.ReceivedRequest(this, request);
}