public override int OnEvent(MsrpEvent e) { MsrpSession session = e.getSipSession(); MsrpMessage message = e.getMessage(); if (session != null && message != null) { uint id = session.getId(); //Console.WriteLine("Msrp Event {0} {1}", id, message.getMsrpHeaderValue("Byte-Range")); long start, end, total; //message.getByteRange(out start, out end, out total); //Console.WriteLine("Byte-Range {0}-{1}/{2}", start, end, total); //if (message.isRequest()) // { // uint size = message.getMsrpContentLength(); // byte[] bytes = new byte[(int)size]; // message.getMsrpContent(bytes, (uint)bytes.Length); // } if (!message.isRequest() && message.getCode() == 200) { if (message.isLastChunck()) { session.hangup(); } } } return(0); }
private void ProcessResponse(MsrpMessage message) { short code = message.getCode(); if (code >= 200 && code <= 299) { // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; message.getByteRange(out start, out end, out total); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.SUCCESS_2XX); eargs.AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_START, start) .AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_END, end) .AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_TOTAL, total) .AddExtra(MsrpEventArgs.EXTRA_RESPONSE_CODE, code) .AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); } } else if (code >= 300) { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.ERROR); eargs.AddExtra(MsrpEventArgs.EXTRA_RESPONSE_CODE, code) .AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); } }
private void ProcessResponse(MsrpMessage message) { short code = message.getCode(); if (code >= 200 && code <= 299) { if (this.session.MediaType == MediaType.FileTransfer) { long start = -1L; long end = -1L; long total = -1L; message.getByteRange(out start, out end, out total); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.SUCCESS_2XX); eargs.AddExtra("byte-start", start).AddExtra("byte-end", end).AddExtra("byte-total", total).AddExtra("response-code", code).AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } } else if (code >= 300) { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.ERROR); eargs.AddExtra("response-code", code).AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } }
public override int OnEvent(MsrpEvent e) { tmsrp_event_type_t type = e.getType(); SipSession session = e.getSipSession(); int result; if (session == null || (ulong)session.getId() != (ulong)this.session.Id) { MyMsrpSession.LOG.Error("Invalid session"); result = -1; } else { switch (type) { case tmsrp_event_type_t.tmsrp_event_type_connected: { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.CONNECTED); eargs.AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); if (this.session.mPendingMessages != null && this.session.mPendingMessages.Count > 0) { if (this.session.IsConnected) { foreach (MyMsrpSession.PendingMessage pendingMsg in this.session.mPendingMessages) { MyMsrpSession.LOG.Info("Sending pending message..."); this.session.SendMessage(pendingMsg.Message, pendingMsg.ContentType, pendingMsg.WContentType); } this.session.mPendingMessages.Clear(); } else { MyMsrpSession.LOG.Warn("There are pending messages but we are not connected"); } } break; } case tmsrp_event_type_t.tmsrp_event_type_disconnected: { if (this.session.mOutFileStream != null) { lock (this.session.mOutFileStream) { if (this.session.mOutFileStream != null) { this.session.mOutFileStream.Close(); this.session.mOutFileStream = null; } } } MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DISCONNECTED); eargs.AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); break; } case tmsrp_event_type_t.tmsrp_event_type_message: { MsrpMessage message = e.getMessage(); if (message == null) { MyMsrpSession.LOG.Error("Invalid MSRP content"); result = -1; return(result); } if (message.isRequest()) { this.ProcessRequest(message); } else { this.ProcessResponse(message); } break; } } result = 0; } return(result); }
private void ProcessRequest(MsrpMessage message) { switch (message.getRequestType()) { case tmsrp_request_type_t.tmsrp_SEND: { uint clen = message.getMsrpContentLength(); if (clen == 0u) { MyMsrpSession.LOG.Info("Empty MSRP message"); } else { if (this.tempBuffer == null || this.tempBufferPtr == System.IntPtr.Zero || (long)this.tempBuffer.Length < (long)((ulong)clen)) { this.tempBuffer = new byte[clen]; if (this.tempBufferPtr != System.IntPtr.Zero) { System.Runtime.InteropServices.Marshal.FreeHGlobal(this.tempBufferPtr); } this.tempBufferPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal((int)clen); } uint read = message.getMsrpContent(this.tempBufferPtr, (uint)this.tempBuffer.Length); System.Runtime.InteropServices.Marshal.Copy(this.tempBufferPtr, this.tempBuffer, 0, this.tempBuffer.Length); if (message.isFirstChunck()) { this.contentType = message.getMsrpHeaderValue("Content-Type"); if (!string.IsNullOrEmpty(this.contentType) && this.contentType.StartsWith("Message/CPIM", System.StringComparison.InvariantCultureIgnoreCase)) { MediaContentCPIM mediaContent = MediaContent.parse(this.tempBufferPtr, read); System.Runtime.InteropServices.Marshal.Copy(this.tempBufferPtr, this.tempBuffer, 0, this.tempBuffer.Length); if (mediaContent != null) { this.wContentType = mediaContent.getHeaderValue("Content-Type"); this.tempBuffer = mediaContent.getPayload(); read = (uint)this.tempBuffer.Length; mediaContent.Dispose(); } } } this.AppenData(this.tempBuffer, read); if (this.session.MediaType == MediaType.FileTransfer) { long start = -1L; long end = -1L; long total = -1L; message.getByteRange(out start, out end, out total); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DATA); eargs.AddExtra("byte-start", start).AddExtra("byte-end", end).AddExtra("byte-total", total).AddExtra("request-type", "SEND").AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } if (message.isLastChunck()) { if (this.session.MediaType == MediaType.Chat && this.chatStream != null) { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DATA); eargs.AddExtra("content-type", this.contentType).AddExtra("w-content-type", this.wContentType).AddExtra("data", this.chatStream.ToArray()).AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); this.chatStream.SetLength(0L); } else if (this.session.MediaType == MediaType.FileTransfer) { if (this.session.mOutFileStream != null) { lock (this.session.mOutFileStream) { this.session.mOutFileStream.Close(); this.session.mOutFileStream = null; } } } } } break; } case tmsrp_request_type_t.tmsrp_REPORT: if (this.session.MediaType == MediaType.FileTransfer) { long start = -1L; long end = -1L; long total = -1L; message.getByteRange(out start, out end, out total); bool isSuccessReport = message.isSuccessReport(); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, isSuccessReport ? MsrpEventTypes.SUCCESS_REPORT : MsrpEventTypes.FAILURE_REPORT); eargs.AddExtra("byte-start", start).AddExtra("byte-end", end).AddExtra("byte-total", total).AddExtra("session", this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } break; } }
private void ProcessRequest(MsrpMessage message) { tmsrp_request_type_t type = message.getRequestType(); switch (type) { case tmsrp_request_type_t.tmsrp_SEND: { uint clen = message.getMsrpContentLength(); uint read = 0; if (clen == 0) { LOG.Info("Empty MSRP message"); return; } if (this.tempBuffer == null || this.tempBuffer.Length < clen) { this.tempBuffer = new byte[(int)clen]; } read = message.getMsrpContent(this.tempBuffer, (uint)this.tempBuffer.Length); if (message.isFirstChunck()) { this.contentType = message.getMsrpHeaderValue("Content-Type"); if (!String.IsNullOrEmpty(contentType) && contentType.StartsWith(ContentType.CPIM, StringComparison.InvariantCultureIgnoreCase)) { MediaContentCPIM mediaContent = MediaContent.parse(this.tempBuffer, read); if (mediaContent != null) { this.wContentType = mediaContent.getHeaderValue("Content-Type"); this.tempBuffer = mediaContent.getPayload(); read = (uint)this.tempBuffer.Length; mediaContent.Dispose(); // Hi GC, I want my memory right now } } } this.AppenData(this.tempBuffer, read); // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; message.getByteRange(out start, out end, out total); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DATA); eargs.AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_START, start) .AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_END, end) .AddExtra(MsrpEventArgs.EXTRA_BYTE_RANGE_TOTAL, total) .AddExtra(MsrpEventArgs.EXTRA_REQUEST_TYPE, "SEND") .AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); } if (message.isLastChunck()) { if (this.session.MediaType == MediaType.Chat && this.chatStream != null) { MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, MsrpEventTypes.DATA); eargs.AddExtra(MsrpEventArgs.EXTRA_CONTENT_TYPE, this.contentType) .AddExtra(MsrpEventArgs.EXTRA_WRAPPED_CONTENT_TYPE, this.wContentType) .AddExtra(MsrpEventArgs.EXTRA_DATA, this.chatStream.ToArray()) .AddExtra(MsrpEventArgs.EXTRA_SESSION, this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.onMsrpEvent, this.session, eargs); this.chatStream.SetLength(0); } else if (this.session.MediaType == MediaType.FileTransfer) { if (this.session.outFileStream != null) { lock (this.session.outFileStream) { this.session.outFileStream.Close(); this.session.outFileStream = null; } } } } break; } case tmsrp_request_type_t.tmsrp_REPORT: { break; } case tmsrp_request_type_t.tmsrp_NONE: case tmsrp_request_type_t.tmsrp_AUTH: default: break; } }