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; } }