public static CreateRequest ( string method, |
||
method | string | The SIP method to use. |
uri | The destination URI used in the first line. | |
headers | Dictionary |
The SIP headers. |
content | string | The SIP body content. |
return |
/// <summary> /// Creates a SIP ACK message based on the transaction and SIP response. /// </summary> /// <param name="response">The response.</param> /// <returns>Message.</returns> public Message CreateAck(Message response) { if (Request == null) { Debug.Assert(false, String.Format("Error creating Ack message when request is null")); return(null); } Message m = Message.CreateRequest("ACK", Request.Uri); m.Headers["Call-ID"] = Request.Headers["Call-ID"]; m.Headers["From"] = Request.Headers["From"]; if (response != null) { m.Headers["To"] = response.Headers["To"]; } else { m.Headers["To"] = Request.Headers["To"]; } m.Headers["Via"] = new List <Header> { Request.First("Via") }; m.Headers["CSeq"] = new List <Header> { new Header(Request.First("CSeq").Number + " ACK", "CSeq") }; if (Request.Headers.ContainsKey("Route")) { m.Headers["Route"] = Request.Headers["Route"]; } return(m); }
/// <summary> /// Creates a SIP ACK message. /// </summary> /// <returns>Message if possible, else null</returns> public virtual Message CreateAck() { if (Request != null && !Server) { return(Message.CreateRequest("ACK", Request.Uri, Headers)); } return(null); }
/// <summary> /// Creates a SIP CANCEL request. /// </summary> /// <returns>Message.</returns> public virtual Message CreateCancel() { Message m = null; if (Request != null && !Server) { m = Message.CreateRequest("CANCEL", Request.Uri, Headers); if (m != null && Request.Headers.ContainsKey("Route")) { m.Headers["Route"] = Request.Headers["Route"]; } if (m != null && Request.Headers.ContainsKey("Via")) { m.Headers["Via"] = new List <Header> { Request.First("Route") }; } } return(m); }
/// <summary> /// Creates a SIP request. /// </summary> /// <param name="method">The SIP method (invite etc.)</param> /// <param name="content">The SIP body contents.</param> /// <param name="contentType">The type of the SIP body.</param> /// <returns>Message.</returns> public virtual Message CreateRequest(string method, string content = "", string contentType = "") { Server = false; if (RemoteParty == null) { Debug.Assert(false, String.Format("No remoteParty for UAC\n")); } if (LocalParty == null) { LocalParty = new Address("\"Anonymous\" <sip:[email protected]>"); } //TODO: Use Remote Party instead of Remote Target? SIPURI uri; if (RemoteTarget != null) { uri = new SIPURI(RemoteTarget.ToString()); } else { uri = new SIPURI(RemoteParty.ToString()); } if (method == "REGISTER") { //TODO: Is this right ? //uri.User = ""; } if ((method != "ACK") && (method != "CANCEL")) { LocalSeq = ++LocalSeq; } //TODO: Use Remote Party instead of Remote Target? Header to; if (RemoteTarget != null) { to = new Header(RemoteTarget.ToString(), "To"); } else { to = new Header(RemoteParty.ToString(), "To"); } Header from = new Header(LocalParty.ToString(), "From"); from.Attributes["tag"] = LocalTag; Header cSeq = new Header(LocalSeq + " " + method, "CSeq"); Header callId = new Header(CallID, "Call-ID"); Header maxForwards = new Header(MaxForwards.ToString(), "Max-Forwards"); Header via = Stack.CreateVia(); Dictionary <string, object> branchParams = new Dictionary <string, object> { { "To", to.Value }, { "From", @from.Value }, { "CallId", callId.Value }, { "CSeq", cSeq.Number } }; via.Attributes["branch"] = Transaction.CreateBranch(branchParams, false); if (LocalTarget == null) { LocalTarget = Stack.Uri.Dup(); LocalTarget.User = LocalParty.Uri.User; } Header contact = new Header(LocalTarget.ToString(), "Contact"); Header[] headerList = { to, from, cSeq, callId, maxForwards, via, contact }; List <Header> headers = headerList.ToList(); // Check this TODO // if (RouteSet.Count != 0) { headers.AddRange(RouteSet); } //app adds other headers such as Supported, Require and Proxy-Require if (!string.IsNullOrEmpty(contentType)) { headers.Add(new Header(contentType, "Content-Type")); } Dictionary <string, List <Header> > headerDict = new Dictionary <string, List <Header> >(); foreach (Header h in headers) { if (headerDict.ContainsKey(h.Name)) { headerDict[h.Name].Add(h); } else { List <Header> temp = new List <Header> { h }; headerDict.Add(h.Name, temp); } } Request = Message.CreateRequest(method, uri, headerDict, content); return(Request); }