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; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif 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.mOnMsrpEvent, 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.mOnMsrpEvent, this.session, eargs); } }
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; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif 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.mOnMsrpEvent, 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.mOnMsrpEvent, this.session, eargs); } }
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.tempBufferPtr == IntPtr.Zero || this.tempBuffer.Length < clen) { #if !WINDOWS_PHONE this.tempBuffer = new byte[(int)clen]; #endif if (this.tempBufferPtr != IntPtr.Zero) { Marshal.FreeHGlobal(this.tempBufferPtr); } this.tempBufferPtr = Marshal.AllocHGlobal((int)clen); } #if WINDOWS_PHONE this.tempBuffer = Encoding.UTF8.GetBytes(message.getMsrpContent(clen)); read = (uint)this.tempBuffer.Length; #else read = message.getMsrpContent(this.tempBufferPtr, (uint)this.tempBuffer.Length); Marshal.Copy(this.tempBufferPtr, this.tempBuffer, 0, this.tempBuffer.Length); #endif if (message.isFirstChunck()) { this.contentType = message.getMsrpHeaderValue("Content-Type"); if (!String.IsNullOrEmpty(contentType) && contentType.StartsWith(ContentType.CPIM, StringComparison.InvariantCultureIgnoreCase)) { #if !WINRT MediaContentCPIM mediaContent = MediaContent.parse(this.tempBufferPtr, read); 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(); // Hi GC, I want my memory right now } #endif } } this.AppenData(this.tempBuffer, read); // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif 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.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(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.mOnMsrpEvent, this.session, eargs); this.chatStream.SetLength(0); } 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: { // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif bool isSuccessReport = message.isSuccessReport(); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, isSuccessReport ? MsrpEventTypes.SUCCESS_REPORT : MsrpEventTypes.FAILURE_REPORT); 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_SESSION, this.session); EventHandlerTrigger.TriggerEvent<MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } break; } case tmsrp_request_type_t.tmsrp_NONE: case tmsrp_request_type_t.tmsrp_AUTH: default: 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.tempBufferPtr == IntPtr.Zero || this.tempBuffer.Length < clen) { #if !WINDOWS_PHONE this.tempBuffer = new byte[(int)clen]; #endif if (this.tempBufferPtr != IntPtr.Zero) { Marshal.FreeHGlobal(this.tempBufferPtr); } this.tempBufferPtr = Marshal.AllocHGlobal((int)clen); } #if WINDOWS_PHONE this.tempBuffer = Encoding.UTF8.GetBytes(message.getMsrpContent(clen)); read = (uint)this.tempBuffer.Length; #else read = message.getMsrpContent(this.tempBufferPtr, (uint)this.tempBuffer.Length); Marshal.Copy(this.tempBufferPtr, this.tempBuffer, 0, this.tempBuffer.Length); #endif if (message.isFirstChunck()) { this.contentType = message.getMsrpHeaderValue("Content-Type"); if (!String.IsNullOrEmpty(contentType) && contentType.StartsWith(ContentType.CPIM, StringComparison.InvariantCultureIgnoreCase)) { #if !WINRT MediaContentCPIM mediaContent = MediaContent.parse(this.tempBufferPtr, read); 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(); // Hi GC, I want my memory right now } #endif } } this.AppenData(this.tempBuffer, read); // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif 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.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(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.mOnMsrpEvent, this.session, eargs); this.chatStream.SetLength(0); } 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: { // File Transfer => ProgressBar if (this.session.MediaType == MediaType.FileTransfer) { long start = -1, end = -1, total = -1; #if WINRT #if WINDOWS_PHONE doubango_rt.BackEnd.rtMsrpByteRange byteRange = message.getByteRange(); start = byteRange.Start; end = byteRange.End; total = byteRange.Total; #else message.getByteRange(mStart, mEnd, mTotal); start = Marshal.ReadInt64(mStart); end = Marshal.ReadInt64(mEnd); total = Marshal.ReadInt64(mTotal); #endif #else message.getByteRange(out start, out end, out total); #endif bool isSuccessReport = message.isSuccessReport(); MsrpEventArgs eargs = new MsrpEventArgs(this.session.Id, isSuccessReport ? MsrpEventTypes.SUCCESS_REPORT : MsrpEventTypes.FAILURE_REPORT); 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_SESSION, this.session); EventHandlerTrigger.TriggerEvent <MsrpEventArgs>(this.session.mOnMsrpEvent, this.session, eargs); } break; } case tmsrp_request_type_t.tmsrp_NONE: case tmsrp_request_type_t.tmsrp_AUTH: default: break; } }