/// <summary> /// Publish a stream on the server. /// </summary> private void rtmpPublish() { outputBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x8); header.EndPoint = 0x1; header.TimeStamp = 0x25; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; AMFString func = new AMFString("publish"); func.write(outputBuff); byte[] n_reserved = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; outputBuff.Write(n_reserved, 0, n_reserved.Length); new AMFNull().write(outputBuff); new AMFString(sParams.PublishName).write(outputBuff); AMFString live = new AMFString(sParams.Record ? "record" : "live"); live.write(outputBuff); header.BodySize = (int)outputBuff.Position; //send the information chunkBufferAndSend(header); int l = connectionSocket.Receive(dataBuffer); }
/// <summary> /// Create a Live Stream on the server /// </summary> private void rtmpCreateStream() { outputBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x3); header.EndPoint = 0; header.TimeStamp = 1; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; AMFString func = new AMFString("createStream"); func.write(outputBuff); outputBuff.Write(c_reserved, 0, c_reserved.Length); new AMFNull().write(outputBuff); header.BodySize = (int)outputBuff.Position; //send the information chunkBufferAndSend(header); int l = connectionSocket.Receive(dataBuffer); }
public override void call(string methodName, fMethodCallback callbackFunc, params object[] pobject) { outputBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x3); header.EndPoint = 0; header.TimeStamp = 1; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; AMFString func = new AMFString(methodName); func.write(outputBuff); outputBuff.Write(c_reserved, 0, c_reserved.Length); new AMFNull().write(outputBuff); foreach (object o in pobject) { AMFDataType dObj = AMFDataType.findDataHandler(o); dObj.write(outputBuff); } header.BodySize = (int)outputBuff.Position; chunkBufferAndSend(header); }
public override bool disconnect() { isConnected = false; outputBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x8); header.EndPoint = 0x00000001; header.TimeStamp = 0; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; AMFString func = new AMFString("publish"); func.write(outputBuff); byte[] n_reserved = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; outputBuff.Write(n_reserved, 0, n_reserved.Length); new AMFNull().write(outputBuff); new AMFString(sParams.PublishName).write(outputBuff); new AMFBoolean(false).write(outputBuff); header.BodySize = (int)outputBuff.Position; //send the information chunkBufferAndSend(header); connectionSocket.Disconnect(true); return(true); }
public override void ClearPrincipal() { HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(GetFormsAuthCookieName()); if (cookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); if (((ticket != null) && (ticket.UserData != null)) && ticket.UserData.StartsWith("fluorineauthticket")) { HttpRuntime.Cache.Remove(ticket.UserData); } } FormsAuthentication.SignOut(); if (AMFContext.Current != null) { AMFContext current = AMFContext.Current; if (current.AMFMessage.GetHeader("CredentialsId") != null) { current.AMFMessage.RemoveHeader("CredentialsId"); ASObject content = new ASObject(); content["name"] = "CredentialsId"; content["mustUnderstand"] = false; content["data"] = null; AMFHeader header = new AMFHeader("RequestPersistentHeader", true, content); current.MessageOutput.AddHeader(header); } } }
/// <summary> /// Sends the flv tag to the RTMP server. /// </summary> /// <param name="tagData"></param> /// <param name="tag"></param> public override bool sendFLVTag(byte[] tagData, FLVTag tag) { if (!isConnected) { return(false); } outputBuff.Position = 0; chunkBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x8); header.RTMPType = AMFHeader.RTMP_TYPE_VIDEO; header.TimeStamp = tag.TimeStamp; header.EndPoint = 0x00000001; header.BodySize = tag.getTagSizeInBytes() - 11; //write the header to teh chunkbuffer header.writeHeader(chunkBuff); //the size remaining in the data buffer int size = tag.getTagSizeInBytes() - 11; //the position in the data buffer (from which to start sending bytes) int position = 0; //write the header to the chunk buffer header.writeHeader(chunkBuff); //copy <= 128 bytes from the tagData into the chunk buffer to send. Array.Copy(tagData, 11, chunk_buffer, header.getHeaderSize(), size > 128 ? 128 : size); //send the first packet of information connectionSocket.Send(chunk_buffer, (header.getHeaderSize() + (size > 128 ? 128 : size)), SocketFlags.None); size -= 128; position += 128 + 11; //while there is still bytes while (size > 0) { //add a header byte byte t = tagData[position - 1]; tagData[position - 1] = header.get_1_HeaderByte(); //send out the data connectionSocket.Send(tagData, position - 1, size > 128 ? 129 : size + 1, SocketFlags.None); //restore where the header was tagData[position - 1] = t; position += 128; size -= 128; } return(true); }
public void SpecialConstructorInitializesProperties() { ASString content = new ASString("abc"); AMFHeader header = new AMFHeader("header", true, content); Assert.AreEqual("header", header.Name); Assert.IsTrue(header.MustUnderstand); Assert.AreEqual(content, header.Content); }
public void rtmptConnect(string[] c_params) { PersistantHTTPConnection connection = new PersistantHTTPConnection(sParams.ServerURL, sParams.Port); req = (HttpWebRequest)WebRequest.Create( "http://" + sParams.ServerURL + ":" + sParams.Port + "/send/" + clientIndex + "/" + pollCount ); req.ContentType = "application/x-fcs"; req.Method = "POST"; req.KeepAlive = true; //using the client index connect to the application AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x3); header.EndPoint = 0; header.TimeStamp = 1; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; requestStream = req.GetRequestStream(); //write the method name (connect); AMFString aString = new AMFString("connect"); aString.write(buffer); buffer.Write(reserved1, 0, reserved1.Length); AMFObject aConnParams = new AMFObject(); aConnParams.addParameter("app", new AMFString(sParams.ApplicationName)); aConnParams.addParameter("flashVer", new AMFString("WIN 8,0,24,0")); aConnParams.addParameter("swfUrl", new AMFString("xfile://c:\\swfurl.swf")); aConnParams.addParameter("tcUrl", new AMFString("rtmp://" + sParams.ServerURL + "/" + sParams.ApplicationName)); aConnParams.addParameter("fpad", new AMFBoolean(false)); aConnParams.addParameter("name", new AMFString("ePresence")); aConnParams.write(buffer); foreach (string s in c_params) { new AMFString(s).write(buffer); } header.BodySize = (int)buffer.Position; Console.Write(header.BodySize); header.writeHeader(requestStream); requestStream.Write(buffer.GetBuffer(), 0, (int)buffer.Position); resp = (HttpWebResponse)req.GetResponse(); responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8); Console.WriteLine(responseReader.ReadToEnd()); }
public override void Invoke(AMFContext context) { AMFMessage amfMessage = context.AMFMessage; AMFHeader amfHeader = amfMessage.GetHeader(AMFHeader.ServiceBrowserHeader); if (amfHeader != null) { AMFBody amfBody = amfMessage.GetBodyAt(0); amfBody.IsDescribeService = true; } }
public override void Invoke(AMFContext context) { AMFMessage amfMessage = context.AMFMessage; AMFHeader amfHeader = amfMessage.GetHeader(AMFHeader.DebugHeader); if (amfHeader != null) { //The value of the header ASObject asObject = amfHeader.Content as ASObject; //["error"]: {true} //["trace"]: {true} //["httpheaders"]: {false} //["coldfusion"]: {true} //["amf"]: {false} //["m_debug"]: {true} //["amfheaders"]: {false} //["recordset"]: {true} AMFBody amfBody = amfMessage.GetBodyAt(amfMessage.BodyCount - 1); //last body ResponseBody amfBodyOut = new ResponseBody(); amfBodyOut.Target = amfBody.Response + AMFBody.OnDebugEvents; amfBodyOut.Response = null; amfBodyOut.IsDebug = true; ArrayList headerResults = new ArrayList(); ArrayList result = new ArrayList(); headerResults.Add(result); if ((bool)asObject["httpheaders"] == true) { //If the client wants http headers result.Add(new HttpHeader( )); } if ((bool)asObject["amfheaders"] == true) { result.Add(new AMFRequestHeaders(amfMessage)); } ArrayList traceStack = NetDebug.GetTraceStack(); if ((bool)asObject["trace"] == true && traceStack != null && traceStack.Count > 0) { ArrayList tmp = new ArrayList(traceStack); result.Add(new TraceHeader(tmp)); NetDebug.Clear(); } //http://osflash.org/amf/envelopes/remoting/debuginfo amfBodyOut.Content = headerResults; context.MessageOutput.AddBody(amfBodyOut); } NetDebug.Clear(); }
private void BeginResponseFlashCall(IAsyncResult ar) { try { RequestData asyncState = ar.AsyncState as RequestData; if (asyncState != null) { HttpWebResponse response = (HttpWebResponse)asyncState.Request.EndGetResponse(ar); if (response != null) { Stream responseStream = response.GetResponseStream(); if (responseStream != null) { AMFMessage message = new AMFDeserializer(responseStream).ReadAMFMessage(); AMFBody bodyAt = message.GetBodyAt(0); for (int i = 0; i < message.HeaderCount; i++) { AMFHeader headerAt = message.GetHeaderAt(i); if (headerAt.Name == "RequestPersistentHeader") { this._netConnection.AddHeader(headerAt.Name, headerAt.MustUnderstand, headerAt.Content); } } PendingCall call = asyncState.Call; call.Result = bodyAt.Content; if (bodyAt.Target.EndsWith("/onStatus")) { call.Status = 0x13; } else { call.Status = 2; } asyncState.Callback.ResultReceived(call); } else { this._netConnection.RaiseNetStatus("Could not aquire ResponseStream"); } } else { this._netConnection.RaiseNetStatus("Could not aquire HttpWebResponse"); } } } catch (Exception exception) { this._netConnection.RaiseNetStatus(exception); } }
/// <summary> /// Performs the "connect" method on the server. /// </summary> private void rtmpConnect(string[] c_params) { //reset the output buffer position outputBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x3); header.EndPoint = 0; header.TimeStamp = 1; header.RTMPType = AMFHeader.RTMP_TYPE_FUNCTION; header.BodySize = 0; //write the method name (connect); AMFString aString = new AMFString("connect"); aString.write(outputBuff); outputBuff.Write(reserved1, 0, reserved1.Length); AMFObject aConnParams = new AMFObject(); aConnParams.addParameter("app", new AMFString(sParams.ApplicationName)); aConnParams.addParameter("flashVer", new AMFString("WIN 8,0,24,0")); aConnParams.addParameter("swfUrl", new AMFString("xfile://c:\\swfurl.swf")); aConnParams.addParameter("tcUrl", new AMFString("rtmp://" + sParams.ServerURL + "/" + sParams.ApplicationName)); aConnParams.addParameter("fpad", new AMFBoolean(false)); aConnParams.addParameter("name", new AMFString("ePresence")); aConnParams.write(outputBuff); foreach (string s in c_params) { new AMFString(s).write(outputBuff); } //since we only wrote the body, the body size is the positiin //in the buffer header.BodySize = (int)outputBuff.Position; //send the information chunkBufferAndSend(header); //receive the connection information int l = connectionSocket.Receive(dataBuffer); //receive the connection information l = connectionSocket.Receive(dataBuffer); }
/// <summary> /// Adds a context header to the Action Message Format (AMF) packet structure. /// This header is sent with every future AMF packet. /// To remove a header call AddHeader with the name of the header to remove an undefined object. /// </summary> /// <param name="operation">Identifies the header and the ActionScript object data associated with it.</param> /// <param name="mustUnderstand">A value of true indicates that the server must understand and process this header before it handles any of the following headers or messages.</param> /// <param name="param">Any ActionScript object or null.</param> /// <remarks>Not implemented.</remarks> public void AddHeader(string operation, bool mustUnderstand, object param) { if (param == null) { if (_headers.ContainsKey(operation)) { _headers.Remove(operation); } return; } AMFHeader header = new AMFHeader(operation, mustUnderstand, param); _headers[operation] = header; }
public AMFRequestHeaders(AMFMessage amfMessage) { this["EventType"] = "AmfHeaders"; Hashtable hashtable = new Hashtable(); for (int i = 0; i < amfMessage.HeaderCount; i++) { AMFHeader amfHeader = amfMessage.GetHeaderAt(i); if (amfHeader != null && amfHeader.Name != null) { hashtable[amfHeader.Name] = amfHeader.Content; } } this["AmfHeaders"] = hashtable; }
public void AddHeader(string operation, bool mustUnderstand, object param) { if (param == null) { if (this._headers.ContainsKey(operation)) { this._headers.Remove(operation); } } else { AMFHeader header = new AMFHeader(operation, mustUnderstand, param); this._headers[operation] = header; } }
public AMFRequestHeaders(AMFMessage amfMessage) { this["EventType"] = "AmfHeaders"; Hashtable hashtable = new Hashtable(); for (int i = 0; i < amfMessage.HeaderCount; i++) { AMFHeader headerAt = amfMessage.GetHeaderAt(i); if ((headerAt != null) && (headerAt.Name != null)) { hashtable[headerAt.Name] = headerAt.Content; } } this["AmfHeaders"] = hashtable; }
public void CanGetAndSetProperties() { ASString content = new ASString("abc"); AMFHeader header = new AMFHeader(); Assert.IsNull(header.Content); header.Content = content; Assert.AreSame(content, header.Content); Assert.IsFalse(header.MustUnderstand); header.MustUnderstand = true; Assert.IsTrue(header.MustUnderstand); Assert.IsNull(header.Name); header.Name = "abc"; Assert.AreEqual("abc", header.Name); }
public LinkedList <AMFDataType> getParameters(byte[] data, int length) { AMFHeader headerResponse = AMFHeader.readHeader(0, data); MemoryStream inStream = new MemoryStream(data); inStream.Position = headerResponse.getHeaderSize(); //since we are only dealing with function calls... //the first information is going to be A Function name. (AMF String) AMFString function = new AMFString(""); function.read(inStream); inStream.Close(); return(null); }
/// <summary> /// Sends the current buffer using data_buffer as the source of data. The size /// is determined from the position in outputBuff. /// </summary> /// <param name="header">The header to prepend to the amf packet.</param> private void chunkBufferAndSend(AMFHeader header) { //the size remaining in the data buffer int size = (int)outputBuff.Position; //the position in the data buffer (from which to start sending bytes) int position = 0; //reset the chunkBuff position chunkBuff.Position = 0; //write the header to the chunk buffer header.writeHeader(chunkBuff); //copy <= 128 bytes from the data buffer into the chunk buffer to send. Array.Copy(dataBuffer, 0, chunk_buffer, header.getHeaderSize(), size > 128 ? 128 : size); //send the first packet of information connectionSocket.Send(chunk_buffer, (header.getHeaderSize() + (size > 128 ? 128 : size)), SocketFlags.None); size -= 128; position += 128; while (size > 0) { //add a header byte dataBuffer[position - 1] = header.get_1_HeaderByte(); //send out the data connectionSocket.Send(dataBuffer, position - 1, size > 128 ? 129 : size + 1, SocketFlags.None); position += 128; size -= 128; } }
public override void Invoke(AMFContext context) { AMFMessage aMFMessage = context.AMFMessage; AMFHeader header = aMFMessage.GetHeader("amf_server_debug"); if (header != null) { ASObject content = header.Content as ASObject; AMFBody bodyAt = aMFMessage.GetBodyAt(aMFMessage.BodyCount - 1); ResponseBody body = new ResponseBody { Target = bodyAt.Response + "/onDebugEvents", Response = null, IsDebug = true }; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); list.Add(list2); if ((bool)content["httpheaders"]) { list2.Add(new HttpHeader()); } if ((bool)content["amfheaders"]) { list2.Add(new AMFRequestHeaders(aMFMessage)); } ArrayList traceStack = NetDebug.GetTraceStack(); if ((((bool)content["trace"]) && (traceStack != null)) && (traceStack.Count > 0)) { ArrayList list4 = new ArrayList(traceStack); list2.Add(new TraceHeader(list4)); NetDebug.Clear(); } body.Content = list; context.MessageOutput.AddBody(body); } NetDebug.Clear(); }
public bool Logout() { bool result = false; if (_loginCommand != null) { result = _loginCommand.Logout(this.Principal); if (this.IsPerClientAuthentication) { if (FluorineContext.Current.Client != null) { FluorineContext.Current.Client.Principal = null; } } else { if (FluorineContext.Current.Session != null) { FluorineContext.Current.Session.Invalidate(); } } } else { if (FluorineContext.Current.Session != null) { FluorineContext.Current.Session.Invalidate(); } if (log.IsErrorEnabled) { log.Error(__Res.GetString(__Res.Security_LoginMissing)); } //FluorineFx.Messaging.SecurityException se = new FluorineFx.Messaging.SecurityException(NoLoginCommand, FluorineFx.Messaging.SecurityException.ServerAuthorizationCode); //throw se; throw new UnauthorizedAccessException(__Res.GetString(__Res.Security_LoginMissing)); } if (HttpContext.Current != null) { /* * HttpCookie authCookie = HttpContext.Current.Request.Cookies.Get(FormsAuthCookieName); * if (authCookie != null) * { * FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); * if (ticket != null && ticket.UserData != null && ticket.UserData.StartsWith(FluorineContext.FluorineTicket)) * { * HttpRuntime.Cache.Remove(ticket.UserData); * } * } */ FormsAuthentication.SignOut(); } if (AMFContext.Current != null) { AMFContext amfContext = AMFContext.Current; AMFHeader amfHeader = amfContext.AMFMessage.GetHeader(AMFHeader.CredentialsIdHeader); if (amfHeader != null) { amfContext.AMFMessage.RemoveHeader(AMFHeader.CredentialsIdHeader); ASObject asoObjectCredentialsId = new ASObject(); asoObjectCredentialsId["name"] = AMFHeader.CredentialsIdHeader; asoObjectCredentialsId["mustUnderstand"] = false; asoObjectCredentialsId["data"] = null;//clear AMFHeader headerCredentialsId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectCredentialsId); amfContext.MessageOutput.AddHeader(headerCredentialsId); } } return(result); }
public override void Invoke(AMFContext context) { MessageOutput messageOutput = context.MessageOutput; for (int i = 0; i < context.AMFMessage.BodyCount; i++) { AMFBody amfBody = context.AMFMessage.GetBodyAt(i); //Check for Flex2 messages if (amfBody.IsEmptyTarget) { object content = amfBody.Content; if (content is IList) { content = (content as IList)[0]; } IMessage message = content as IMessage; if (message != null) { Client client = null; HttpSession session = null; if (FluorineContext.Current.Client == null) { IClientRegistry clientRegistry = _endpoint.GetMessageBroker().ClientRegistry; string clientId = message.GetFlexClientId(); if (!clientRegistry.HasClient(clientId)) { lock (clientRegistry.SyncRoot) { if (!clientRegistry.HasClient(clientId)) { client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client; } } } if (client == null) { client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client; } FluorineContext.Current.SetClient(client); } session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current); FluorineContext.Current.SetSession(session); //Context initialized, notify listeners. if (session != null && session.IsNew) { session.NotifyCreated(); } if (client != null) { if (session != null) { client.RegisterSession(session); } if (client.IsNew) { client.Renew(_endpoint.ClientLeaseTime); client.NotifyCreated(); } } /* * RemotingConnection remotingConnection = null; * foreach (IConnection connection in client.Connections) * { * if (connection is RemotingConnection) * { * remotingConnection = connection as RemotingConnection; * break; * } * } * if (remotingConnection == null) * { * remotingConnection = new RemotingConnection(_endpoint, null, client.Id, null); * remotingConnection.Initialize(client, session); * } * FluorineContext.Current.SetConnection(remotingConnection); */ } } else { //Flash remoting AMFHeader amfHeader = context.AMFMessage.GetHeader(AMFHeader.AMFDSIdHeader); string amfDSId = null; if (amfHeader == null) { amfDSId = Guid.NewGuid().ToString("D"); ASObject asoObjectDSId = new ASObject(); asoObjectDSId["name"] = AMFHeader.AMFDSIdHeader; asoObjectDSId["mustUnderstand"] = false; asoObjectDSId["data"] = amfDSId;//set AMFHeader headerDSId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectDSId); context.MessageOutput.AddHeader(headerDSId); } else { amfDSId = amfHeader.Content as string; } Client client = null; HttpSession session = null; if (FluorineContext.Current.Client == null) { IClientRegistry clientRegistry = _endpoint.GetMessageBroker().ClientRegistry; string clientId = amfDSId; if (!clientRegistry.HasClient(clientId)) { lock (clientRegistry.SyncRoot) { if (!clientRegistry.HasClient(clientId)) { client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client; } } } if (client == null) { client = _endpoint.GetMessageBroker().ClientRegistry.GetClient(clientId) as Client; } } FluorineContext.Current.SetClient(client); session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current); FluorineContext.Current.SetSession(session); //Context initialized, notify listeners. if (session != null && session.IsNew) { session.NotifyCreated(); } if (client != null) { if (session != null) { client.RegisterSession(session); } if (client.IsNew) { client.Renew(_endpoint.ClientLeaseTime); client.NotifyCreated(); } } } } }
private void BeginResponseFlexCall(IAsyncResult ar) { try { AmfRequestData amfRequestData = ar.AsyncState as AmfRequestData; if (amfRequestData != null) { HttpWebResponse response = (HttpWebResponse)amfRequestData.Request.EndGetResponse(ar); if (response != null) { //Get response and deserialize Stream responseStream = response.GetResponseStream(); if (responseStream != null) { AMFDeserializer amfDeserializer = new AMFDeserializer(responseStream); AMFMessage responseMessage = amfDeserializer.ReadAMFMessage(); AMFBody responseBody = responseMessage.GetBodyAt(0); for (int i = 0; i < responseMessage.HeaderCount; i++) { AMFHeader header = responseMessage.GetHeaderAt(i); if (header.Name == AMFHeader.RequestPersistentHeader) _netConnection.AddHeader(header.Name, header.MustUnderstand, header.Content); } object message = responseBody.Content; if (message is ErrorMessage) { /* ASObject status = new ASObject(); status["level"] = "error"; status["code"] = "NetConnection.Call.Failed"; status["description"] = (result as ErrorMessage).faultString; status["details"] = result; _netConnection.RaiseNetStatus(status); */ if (amfRequestData.Call != null) { PendingCall call = amfRequestData.Call; call.Result = message; call.Status = Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION; amfRequestData.Callback.ResultReceived(call); } if (amfRequestData.Responder != null) { StatusFunction statusFunction = amfRequestData.Responder.GetType().GetProperty("Status").GetValue(amfRequestData.Responder, null) as StatusFunction; if (statusFunction != null) statusFunction(new Fault(message as ErrorMessage)); } } else if (message is AcknowledgeMessage) { AcknowledgeMessage ack = message as AcknowledgeMessage; if (_netConnection.ClientId == null && ack.HeaderExists(MessageBase.FlexClientIdHeader)) _netConnection.SetClientId(ack.GetHeader(MessageBase.FlexClientIdHeader) as string); if (amfRequestData.Call != null) { PendingCall call = amfRequestData.Call; call.Result = ack.body; call.Status = Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT; amfRequestData.Callback.ResultReceived(call); } if (amfRequestData.Responder != null) { Delegate resultFunction = amfRequestData.Responder.GetType().GetProperty("Result").GetValue(amfRequestData.Responder, null) as Delegate; if (resultFunction != null) { ParameterInfo[] arguments = resultFunction.Method.GetParameters(); object result = TypeHelper.ChangeType(ack.body, arguments[0].ParameterType); resultFunction.DynamicInvoke(result); } } } } else _netConnection.RaiseNetStatus("Could not aquire ResponseStream"); } else _netConnection.RaiseNetStatus("Could not aquire HttpWebResponse"); } } catch (Exception ex) { _netConnection.RaiseNetStatus(ex); } }
private void BeginResponseFlashCall(IAsyncResult ar) { try { AmfRequestData amfRequestData = ar.AsyncState as AmfRequestData; if (amfRequestData != null) { HttpWebResponse response = (HttpWebResponse)amfRequestData.Request.EndGetResponse(ar); if (response != null) { //Get response and deserialize Stream responseStream = response.GetResponseStream(); if (responseStream != null) { AMFDeserializer amfDeserializer = new AMFDeserializer(responseStream); AMFMessage responseMessage = amfDeserializer.ReadAMFMessage(); AMFBody responseBody = responseMessage.GetBodyAt(0); for (int i = 0; i < responseMessage.HeaderCount; i++) { AMFHeader header = responseMessage.GetHeaderAt(i); if (header.Name == AMFHeader.RequestPersistentHeader) _netConnection.AddHeader(header.Name, header.MustUnderstand, header.Content); } if (amfRequestData.Call != null) { PendingCall call = amfRequestData.Call; call.Result = responseBody.Content; call.Status = responseBody.Target.EndsWith(AMFBody.OnStatus) ? Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION : Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT; amfRequestData.Callback.ResultReceived(call); } if (amfRequestData.Responder != null) { if (responseBody.Target.EndsWith(AMFBody.OnStatus)) { StatusFunction statusFunction = amfRequestData.Responder.GetType().GetProperty("Status").GetValue(amfRequestData.Responder, null) as StatusFunction; if (statusFunction != null) statusFunction(new Fault(responseBody.Content)); } else { Delegate resultFunction = amfRequestData.Responder.GetType().GetProperty("Result").GetValue(amfRequestData.Responder, null) as Delegate; if (resultFunction != null) { ParameterInfo[] arguments = resultFunction.Method.GetParameters(); object result = TypeHelper.ChangeType(responseBody.Content, arguments[0].ParameterType); resultFunction.DynamicInvoke(result); } } } } else _netConnection.RaiseNetStatus("Could not aquire ResponseStream"); } else _netConnection.RaiseNetStatus("Could not aquire HttpWebResponse"); } } catch (Exception ex) { _netConnection.RaiseNetStatus(ex); } }
private void BeginResponseFlexCall(IAsyncResult ar) { try { RequestData asyncState = ar.AsyncState as RequestData; if (asyncState != null) { HttpWebResponse response = (HttpWebResponse)asyncState.Request.EndGetResponse(ar); if (response != null) { Stream responseStream = response.GetResponseStream(); if (responseStream != null) { PendingCall call; AMFMessage message = new AMFDeserializer(responseStream).ReadAMFMessage(); AMFBody bodyAt = message.GetBodyAt(0); for (int i = 0; i < message.HeaderCount; i++) { AMFHeader headerAt = message.GetHeaderAt(i); if (headerAt.Name == "RequestPersistentHeader") { this._netConnection.AddHeader(headerAt.Name, headerAt.MustUnderstand, headerAt.Content); } } object content = bodyAt.Content; if (content is ErrorMessage) { call = asyncState.Call; call.Result = content; call.Status = 0x13; asyncState.Callback.ResultReceived(call); } if (content is AcknowledgeMessage) { AcknowledgeMessage message2 = content as AcknowledgeMessage; if ((this._netConnection.ClientId == null) && message2.HeaderExists("DSId")) { this._netConnection.SetClientId(message2.GetHeader("DSId") as string); } call = asyncState.Call; call.Result = message2.body; call.Status = 2; asyncState.Callback.ResultReceived(call); } } else { this._netConnection.RaiseNetStatus("Could not aquire ResponseStream"); } } else { this._netConnection.RaiseNetStatus("Could not aquire HttpWebResponse"); } } } catch (Exception exception) { this._netConnection.RaiseNetStatus(exception); } }
public override void Invoke(AMFContext context) { IPrincipal principal = null; int num; ErrorResponseBody body2; MessageBroker messageBroker = this._endpoint.GetMessageBroker(); try { string str3; AMFHeader header = context.AMFMessage.GetHeader("Credentials"); if ((header != null) && (header.Content != null)) { string username = ((ASObject)header.Content)["userid"] as string; string password = ((ASObject)header.Content)["password"] as string; ASObject content = new ASObject(); content["name"] = "Credentials"; content["mustUnderstand"] = false; content["data"] = null; AMFHeader header2 = new AMFHeader("RequestPersistentHeader", true, content); context.MessageOutput.AddHeader(header2); ILoginCommand loginCommand = this._endpoint.GetMessageBroker().LoginCommand; if (loginCommand == null) { throw new UnauthorizedAccessException(__Res.GetString("Security_LoginMissing")); } Hashtable credentials = new Hashtable(1); credentials["password"] = password; principal = loginCommand.DoAuthentication(username, credentials); if (principal == null) { throw new UnauthorizedAccessException(__Res.GetString("Security_AccessNotAllowed")); } FluorineContext.Current.StorePrincipal(principal, username, password); str3 = FluorineContext.Current.EncryptCredentials(this._endpoint, principal, username, password); FluorineContext.Current.StorePrincipal(principal, str3); ASObject obj3 = new ASObject(); obj3["name"] = "CredentialsId"; obj3["mustUnderstand"] = false; obj3["data"] = str3; AMFHeader header3 = new AMFHeader("RequestPersistentHeader", true, obj3); context.MessageOutput.AddHeader(header3); } else { header = context.AMFMessage.GetHeader("CredentialsId"); if (header != null) { str3 = header.Content as string; if (str3 != null) { FluorineContext.Current.RestorePrincipal(messageBroker.LoginCommand, str3); } } else { principal = FluorineContext.Current.RestorePrincipal(messageBroker.LoginCommand); } } } catch (UnauthorizedAccessException exception) { for (num = 0; num < context.AMFMessage.BodyCount; num++) { body2 = new ErrorResponseBody(context.AMFMessage.GetBodyAt(num), exception); context.MessageOutput.AddBody(body2); } } catch (Exception exception2) { if ((log != null) && log.get_IsErrorEnabled()) { log.Error(exception2.Message, exception2); } for (num = 0; num < context.AMFMessage.BodyCount; num++) { body2 = new ErrorResponseBody(context.AMFMessage.GetBodyAt(num), exception2); context.MessageOutput.AddBody(body2); } } FluorineContext.Current.User = principal; Thread.CurrentPrincipal = principal; }
public override void Invoke(AMFContext context) { MessageBroker messageBroker = _endpoint.GetMessageBroker(); try { AMFHeader amfHeader = context.AMFMessage.GetHeader(AMFHeader.CredentialsHeader); if (amfHeader != null && amfHeader.Content != null) { string userId = ((ASObject)amfHeader.Content)["userid"] as string; string password = ((ASObject)amfHeader.Content)["password"] as string; //Clear credentials header, further requests will not send the credentials ASObject asoObject = new ASObject(); asoObject["name"] = AMFHeader.CredentialsHeader; asoObject["mustUnderstand"] = false; asoObject["data"] = null;//clear AMFHeader header = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObject); context.MessageOutput.AddHeader(header); IPrincipal principal = _endpoint.GetMessageBroker().LoginManager.Login(userId, amfHeader.Content as IDictionary); string key = EncryptCredentials(_endpoint, principal, userId, password); ASObject asoObjectCredentialsId = new ASObject(); asoObjectCredentialsId["name"] = AMFHeader.CredentialsIdHeader; asoObjectCredentialsId["mustUnderstand"] = false; asoObjectCredentialsId["data"] = key;//set AMFHeader headerCredentialsId = new AMFHeader(AMFHeader.RequestPersistentHeader, true, asoObjectCredentialsId); context.MessageOutput.AddHeader(headerCredentialsId); } else { amfHeader = context.AMFMessage.GetHeader(AMFHeader.CredentialsIdHeader); if (amfHeader != null) { string key = amfHeader.Content as string; if (key != null) { _endpoint.GetMessageBroker().LoginManager.RestorePrincipal(key); } } else { _endpoint.GetMessageBroker().LoginManager.RestorePrincipal(); } } } catch (UnauthorizedAccessException exception) { for (int i = 0; i < context.AMFMessage.BodyCount; i++) { AMFBody amfBody = context.AMFMessage.GetBodyAt(i); ErrorResponseBody errorResponseBody = new ErrorResponseBody(amfBody, exception); context.MessageOutput.AddBody(errorResponseBody); } } catch (Exception exception) { if (log != null && log.IsErrorEnabled) { log.Error(exception.Message, exception); } for (int i = 0; i < context.AMFMessage.BodyCount; i++) { AMFBody amfBody = context.AMFMessage.GetBodyAt(i); ErrorResponseBody errorResponseBody = new ErrorResponseBody(amfBody, exception); context.MessageOutput.AddBody(errorResponseBody); } } }