public void GenerateCancel(SipMessageWriter writer, SipMessageReader reader) { trunk.RemoveDialog1(tag); trunk.RemoveDialog2(tag); GenerateRequest(writer, reader, Methods.Cancelm); }
public bool IsAccepted(SipMessageReader reader) { return (reader.ContentType.Type.Equals(type) && reader.ContentType.Subtype.Equals(subtype) && reader.To.AddrSpec.User.StartsWith(userPrefix)); }
public int ProccessTransport(SipMessageReader reader, out T transaction) { var key = new BadServerTransactionKey(reader, (reader.IsAck || reader.IsCancel) ? Methods.Invitem : reader.Method); lock (sync) { if (TryGet(key, out transaction) == false) { int transactionId = Transaction.InvalidKId; if (reader.Method == Methods.Cancelm) { transactionId = Transaction.ChangeKind( inviteStorage.GetRelaytedTransactionId(key), Transaction.Kind.CancelServer); } if (transactionId == Transaction.InvalidKId) { transactionId = GenerateKId(); } transaction = Add(key, GetAcceptedRequestIndex(reader), transactionId); } int action = transaction.ProccessTransport(reader.Method == Methods.Ackm); UpdateOrRemove(transaction); return(action); } }
private void CancelClients(RequestProxy requestProxy, SipMessageReader message) { lock (requestProxy) { var proxies = requestProxy.GetAllProxie(); for (int i = 0; i < proxies.Count; i++) { if (proxies[i].IsFinalReceived == false && proxies[i].IsCancelSent == false) { proxies[i].IsCancelSent = true; if (Transaction.GetTransactionKind(proxies[i].TransactionId) == Transaction.Kind.InviteClient) { var writer = GetWriter(); proxies[i].GenerateCancel(writer, message); int transactionKId = Transaction.GetRelaytedCancelClientKId(proxies[i].TransactionId); requestProducer.SendRequest(proxies[i].ToConnectionAddresses, writer, transactionKId); } } } } }
private static StatusCodes Validate(SipMessageReader reader) { if (reader.RequestUri.UriScheme != UriSchemes.Sip && reader.RequestUri.UriScheme != UriSchemes.Sips) { return(StatusCodes.UnsupportedURIScheme); } if (reader.MaxForwards == 0) { return(StatusCodes.TooManyHops); } if (reader.To.AddrSpec.User.IsInvalid) { return(StatusCodes.BadRequest); } if (reader.To.AddrSpec.Hostport.Host.IsInvalid) { return(StatusCodes.BadRequest); } // validate ProxyRequire & Require return(StatusCodes.OK); }
private static ByteArrayPart GetDialogId(SipMessageReader message) { if (Dialog.HasValidId(message) == false) { return(ByteArrayPart.Invalid); } int length = Dialog.GetIdLength(message); if (dialogIdBytes == null || dialogIdBytes.Length < length) { dialogIdBytes = new byte[length]; } var part = new ByteArrayPart() { Bytes = dialogIdBytes, Begin = 0, End = length, }; Dialog.GenerateId(message, part.Bytes); return(part); }
private void GenerateRequest(SipMessageWriter writer, SipMessageReader reader, Methods method) { writer.WriteRequestLine(method, trunk.Uri); 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(); }
private void ForwardRequest(IProxie proxie, RequestProxy requestProxy, SipMessageReader reader) { #region vars... var serverConnectionAddresses = requestProxy.ConnectionAddresses; var clientConnectionAddresses = proxie.ToConnectionAddresses; int serverTransactionId = requestProxy.ServerTransactionId; int clientTransactionId = proxie.TransactionId; var method = reader.Method; var content = requestProxy.Content; #endregion clientTransactionIds.Add(clientTransactionId, serverTransactionId); if (method == Methods.Ackm) { proxie.IsFinalReceived = true; } requestProxy.AddProxie(proxie); var writer = GetWriter(); proxie.GenerateForwardedRequest(writer, reader, content, serverConnectionAddresses, serverTransactionId); requestProducer.SendRequest(clientConnectionAddresses, writer, clientTransactionId, serverTransactionId); proxie.TimerC = (method == Methods.Invitem) ? timerC.Add(new ServerClientId(serverTransactionId, clientTransactionId)) : timerC.InvalidTimerIndex; }
public Dialog Get(SipMessageReader message) { if (Dialog.HasValidId(message)) { return(dictionary.TryGetValue(GetDialogId(message))); } return(null); }
public bool IsChanged(SipMessageReader reader, int contactIndex) { return (AddrSpec != reader.Contact[contactIndex].AddrSpec.Value || SipInstance != reader.Contact[contactIndex].SipInstance || Epid != reader.From.Epid || CallId != reader.CallId); }
public void Load() { var dfa = new SipMessageReader(); dfa.LoadTables(@"..\..\..\Sip.Message\Sip.Message.dfa"); dfa.SetDefaultValue(); dfa.Parse(new byte[] { 0 }, 0, 1); }
public IncomingMessage(ConnectionAddresses connectionAddresses, Connection connection) { ConnectionAddresses = connectionAddresses; Reader = connection.Reader; Header = connection.Header; Content = connection.Content; }
public IncomingMessage(Transports transport, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, int connectionId, SipMessageReader reader, ArraySegment <byte> readerData, ArraySegment <byte> contentData) { ConnectionAddresses = new ConnectionAddresses(transport, localEndPoint, remoteEndPoint, connectionId); Reader = reader; Header = readerData; Content = contentData; }
protected SipMessageWriter GenerateResponse(SipMessageReader reader, StatusCodes statusCode) { var writer = GetWriter(); writer.WriteResponse(reader, statusCode); return(writer); }
public Dialog Create(SipMessageReader message, int localTag, ConnectionAddresses connectionAddresses) { var dialog = new Dialog(message, localTag, connectionAddresses); dictionary.Add(dialog.Id, dialog); return(dialog); }
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); } 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); }
/// <summary> /// DEPRECATED!!! Не удобно читать код, не видно откуда CallLegTransactionDoesNotExist /// </summary> public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses, out StatusCodes statusCode) { var dialog = GetOrCreate(reader, connectionAddresses); statusCode = (dialog == null) ? StatusCodes.CallLegTransactionDoesNotExist : StatusCodes.OK; return(dialog); }
public IncomingMessage(Connection connection) { ConnectionAddresses = new ConnectionAddresses(GetTransport(connection), connection.LocalEndPoint, new IPEndPoint(connection.RemoteEndPoint.Address, connection.RemoteEndPoint.Port), connection.Id); Reader = connection.Reader; Header = connection.Header; Content = connection.Content; }
public bool CanFork(SipMessageReader response) { if (response.StatusCode.Value != 407 && response.StatusCode.Value != 401) { return(false); } return(trunk.UpdateChallenge(response.GetAnyChallenge())); }
public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment <byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId) { dialog2 = new Dialog(reader, tag, fromConnectionAddress); //trunk.AddDialog2(tag, dialog2); ///////////////////////////////////////////////////////////////////////////////// writer.WriteRequestLine(reader.Method, dialog1.RemoteUri); //var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId); //writer.WriteVia(dialog1.Transport, dialog1.LocalEndPoint, TransactionId, msReceivedCid); writer.WriteVia(dialog1.Transport, dialog1.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(dialog1.LocalEndPoint, dialog1.Transport); break; case HeaderNames.To: writer.WriteTo(dialog1.RemoteUri, dialog1.RemoteTag); break; case HeaderNames.From: writer.WriteFrom(reader.From.AddrSpec.Value, tag); break; case HeaderNames.Authorization: break; default: writer.WriteHeader(reader, i); break; case HeaderNames.Via: via = reader.Headers[i].Value.DeepCopy(); break; } } if (reader.ContentLength == int.MinValue) { writer.WriteContentLength(content.Count); } writer.WriteCustomHeaders(); writer.WriteCRLF(); writer.Write(content); }
private static SipMessageReader Parse(string message) { var messageBytes = Encoding.UTF8.GetBytes(message); var reader = new SipMessageReader(); reader.SetDefaultValue(); reader.Parse(messageBytes, 0, messageBytes.Length); reader.SetArray(messageBytes); return(reader); }
public static SipMessageReader GetEmpty() { connectionId = -1; if (Value == null) { Value = new SipMessageReader(); } Value.SetDefaultValue(); return(Value); }
private bool HasStarContact(SipMessageReader reader) { for (int i = 0; i < reader.Count.ContactCount; i++) { if (reader.Contact[i].IsStar) { return(true); } } return(false); }
public static void Update(int currentConnectionId, ArraySegment <byte> header) { connectionId = currentConnectionId; if (Value == null) { Value = new SipMessageReader(); } Value.SetDefaultValue(); Value.Parse(header.Array, header.Offset, header.Count); Value.SetArray(header.Array); }
private SipMessageReader ParseHeaders(RequestProxy requestProxy) { if (readerInternal == null) { readerInternal = new SipMessageReader(); } readerInternal.SetDefaultValue(); readerInternal.Parse(requestProxy.Headers.Array, requestProxy.Headers.Offset, requestProxy.Headers.Count); readerInternal.SetArray(requestProxy.Headers.Array); return(readerInternal); }
public IncomingMessage(ServerAsyncEventArgs e, SipMessageReader reader, ArraySegment <byte> content) { if (e.LocalEndPoint.Protocol != ServerProtocol.Udp) { throw new ArgumentException(); } ConnectionAddresses = new ConnectionAddresses(Transports.Udp, e.LocalEndPoint, new IPEndPoint(e.RemoteEndPoint.Address, e.RemoteEndPoint.Port), ServerAsyncEventArgs.AnyNewConnectionId); Reader = reader; Content = content; Header = new ArraySegment <byte>(e.Buffer, e.Offset, e.BytesTransferred - content.Count); }
public BadServerTransactionKey(SipMessageReader reader, Methods method) { this.transactionId = null; int offset; if (reader.Via[0].Branch.StartsWith(SipMessage.MagicCookie)) { int count = reader.Via[0].Branch.Length + 1 + reader.Via[0].SentBy.Host.Length + 16; bytes = new byte[count]; offset = bytes.CopyFrom(reader.Via[0].Branch, 0) + 1; offset = bytes.CopyFrom(reader.Via[0].SentBy.Host, offset); } else { bool useToTag = reader.To.Tag.IsValid && method != Methods.Invitem; int count = reader.RequestUri.Value.Length + 1 + reader.From.Tag.Length + 1 + reader.CallId.Length + 1 + reader.Via[0].SentBy.Host.Length + 1 + (useToTag ? reader.To.Tag.Length : 0) + 16; bytes = new byte[count]; offset = bytes.CopyFrom(reader.RequestUri.Value, 0) + 1; offset = bytes.CopyFrom(reader.From.Tag, offset) + 1; offset = bytes.CopyFrom(reader.CallId, offset) + 1; offset = bytes.CopyFrom(reader.Via[0].SentBy.Host, offset) + 1; if (useToTag) { offset = bytes.CopyFrom(reader.To.Tag, offset); } } offset = bytes.CopyFrom((int)method, offset); offset = bytes.CopyFrom((int)reader.Via[0].Transport, offset); offset = bytes.CopyFrom(reader.Via[0].SentBy.Port, offset); offset = bytes.CopyFrom(reader.CSeq.Value, offset); hashCode = bytes.GetValueHashCode(); }
public Dialog GetOrCreate(SipMessageReader reader, ConnectionAddresses connectionAddresses) { Dialog dialog = null; if (reader.To.Tag.IsInvalid) { dialog = Create(reader, NewLocalTag(), connectionAddresses); } else { dialog = Get(reader); } return(dialog); }
private StatusCodes Filter(SipMessageReader reader) { if (IsOfficeSIPFiletransferEnabled == false) { if (reader.Method == Methods.Messagem) { if (reader.ContentType.Type.Equals(contentTypeFile) && reader.ContentType.Subtype.Equals(contentSubtypeData)) { return(StatusCodes.Forbidden); } } } return(StatusCodes.OK); }
private static void GetReader(string messageText, out SipMessageReader reader, out ArraySegment <byte> headers) { reader = new SipMessageReader(); var message = Encoding.UTF8.GetBytes(messageText); headers = new ArraySegment <byte>(message); reader.SetDefaultValue(); int parsed = reader.Parse(message, 0, message.Length); if (reader.IsFinal == false || reader.IsError || parsed < message.Length) { throw new InvalidProgramException(@"Invalid message: " + messageText); } reader.SetArray(message); }