private void SendNotify(Dialog dialog, int expires, PresenceDocument document) { int transactionId = GetTransactionId(Methods.Notifym); var writer = new SipMessageWriter(); writer.WriteRequestLine(Methods.Notifym, dialog.RemoteUri); writer.WriteVia(dialog.Transport, dialog.LocalEndPoint, transactionId); writer.WriteFrom(dialog.LocalUri, dialog.LocalTag); writer.WriteTo(dialog.RemoteUri, dialog.RemoteTag); writer.WriteCallId(dialog.CallId); writer.WriteEventPresence(); writer.WriteSubscriptionState(expires); writer.WriteMaxForwards(70); writer.WriteCseq(dialog.GetNextLocalCseq(), Methods.Notifym); writer.WriteContact(dialog.LocalEndPoint, dialog.Transport); if (document != null) { writer.WriteContentType(application, pidfXml); //writer.WriteContentLength(); //writer.WriteCRLF(); //writer.RewriteContentLength( // document.CopyTo((length) => writer.GetBytesForCustomWrite(length))); document.WriteLenghtAndContent(writer); } else { writer.WriteContentLength(0); writer.WriteCRLF(); } notifyProducer.SendRequest(dialog.Transport, dialog.LocalEndPoint, dialog.RemoteEndPoint, ServerAsyncEventArgs.AnyConnectionId, writer, transactionId); }
public void GenerateForwardedResponse(SipMessageWriter writer, SipMessageReader response, ArraySegment<byte> content, ConnectionAddresses ca) { //if (response.StatusCode.Is2xx && response.To.Tag.IsValid) // trunk.AddDialogs(tag, new Dialog(response, ca), dialog2); if (response.CSeq.Method == Methods.Byem) { trunk.RemoveDialog1(tag); trunk.RemoveDialog2(tag); } else { if (response.StatusCode.Is2xx && response.To.Tag.IsValid) trunk.AddDialog1(tag, new Dialog(response, binding.ConnectionAddresses)); //ca)); if (response.StatusCode.Is2xx == false && response.StatusCode.Is1xx == false) trunk.RemoveDialog2(tag); } writer.WriteStatusLine(response.StatusCode); for (int i = 0; i < response.Count.HeaderCount; i++) { switch (response.Headers[i].HeaderName) { case HeaderNames.Via: writer.Write(SipMessageWriter.C.Via, SipMessageWriter.C.HCOLON, via); writer.WriteCRLF(); break; case HeaderNames.WwwAuthenticate: case HeaderNames.ProxyAuthenticate: break; case HeaderNames.To: writer.WriteTo(dialog2.LocalUri, dialog2.LocalTag); break; case HeaderNames.From: writer.WriteFrom(dialog2.RemoteUri, dialog2.RemoteTag); break; case HeaderNames.CSeq: writer.WriteCseq(dialog2.RemoteCseq, response.CSeq.Method); break; case HeaderNames.Contact: writer.WriteContact(ca.LocalEndPoint, ca.Transport); break; default: writer.WriteHeader(response, i); break; } } if (response.ContentLength == int.MinValue) writer.WriteContentLength(content.Count); writer.WriteCustomHeaders(); writer.WriteCRLF(); writer.Write(content); }
private void GenerateRequest(SipMessageWriter writer, SipMessageReader reader, Methods method) { writer.WriteRequestLine(method, trunk.ForwardCallToUri); writer.WriteVia(ToConnectionAddresses.Transport, ToConnectionAddresses.LocalEndPoint, TransactionId); for (int i = 0; i < reader.Count.HeaderCount; i++) { switch (reader.Headers[i].HeaderName) { case HeaderNames.From: case HeaderNames.To: case HeaderNames.CallId: writer.WriteHeader(reader, i); break; } } writer.WriteMaxForwards(70); writer.WriteCseq(reader.CSeq.Value, method); writer.WriteContentLength(0); writer.WriteCustomHeaders(); writer.WriteCRLF(); }
public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId) { //int? tag = HexEncoding.ParseHex8(reader.To.Tag); //var dialog2 = trunk.GetExternalDialog(tag); //if (dialog2 != null) //{ // this.tag = tag.Value; // //this.dialog1 = dialog1; // this.dialog2 = dialog2; //} Dialog dialog2 = null; if (HexEncoding.TryParseHex8(reader.To.Tag, out tag)) dialog2 = trunk.GetDialog2(tag); else tag = DialogManager.NewLocalTag(); dialog1 = new Dialog(reader, tag, fromConnectionAddress); trunk.AddDialog1(tag, dialog1); writer.WriteRequestLine(reader.Method, trunk.Transport.ToScheme(), reader.To.AddrSpec.User, trunk.Domain); //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId); //writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid); writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId); for (int i = 0; i < reader.Count.HeaderCount; i++) { switch (reader.Headers[i].HeaderName) { case HeaderNames.MaxForwards: writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1); break; case HeaderNames.Contact: writer.WriteContact(trunk.LocalEndPoint, trunk.Transport, reader.Contact[0].SipInstance); break; case HeaderNames.Via: via = reader.Headers[i].Value.DeepCopy(); break; case HeaderNames.To: writer.WriteTo2(reader.To.AddrSpec.User, trunk.Domain, (dialog2 != null) ? dialog2.RemoteTag : ByteArrayPart.Invalid); break; case HeaderNames.From: writer.WriteFrom(trunk.Uri, tag); break; case HeaderNames.CSeq: writer.WriteCseq(trunk.GetCSeq(reader.CSeq.Method, reader.CallId, reader.CSeq.Value), reader.CSeq.Method); break; case HeaderNames.Authorization: case HeaderNames.ContentLength: case HeaderNames.Extension: break; default: writer.WriteHeader(reader, i); break; } } WriteAuthorization(writer, reader.Method, content); if (reader.Method == Methods.Invitem && reader.ContentType.Subtype.Equals(sdp)) // temp content = Sip.Sdp.Helpers.CutCandidates(content); writer.WriteContentLength(content.Count); writer.WriteCRLF(); writer.Write(content); }