/// <summary> /// This method receives requests from the HTTP agent and passes the request to the Site Controller. /// </summary> /// <param name="httpContext">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request data.</param> /// <returns>Returns true if the connection should be reset.</returns> public override bool Receive(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { context.ChangeState("ProcessData"); return context.Receive(job, Data); }
/// <summary> /// This method sets the transport context server connection parameters. /// </summary> /// <param name="context">The transport context.</param> /// <param name="job">The current job.</param> /// <param name="Data">The data.</param> /// <returns>Returns false as this context should be accepted.</returns> public override bool ListenRequest(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.Location = Data.ContractRequest.TransportUri; context.ServerContextID = Data.ContractRequest.ServerContextID; Data.ContractResponse.ConnectionType = TransportConnectionType.Connectionful; Data.Response.Status = CH.HTTPCodes.OK_200; return false; }
/// <summary> /// This close method is initiated by the remote server. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public override bool Close(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { TransportContextTCPIP tcpContext = context as TransportContextTCPIP; tcpContext.ClosePending = true; tcpContext.SocketClose(); return true; }
/// <summary> /// This state manages connection requests from HTTP browsers. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The current job.</param> /// <param name="Data">The data in the request.</param> /// <returns>Returns false if the connection is successful, true if the connection should be reset.</returns> public override bool ConnectionRequest(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { RQCallbackServer Request = Data.ContractRequest; RSCallbackServer Response = Data.ContractResponse; Response.ServerContextID = context.SignatureID; Response.Status = CH.HTTPCodes.OK_200; Response.MessageResponse = null; Response.MessageRequestType = typeof(HTTPRequestMessage); context.URILocal = Request.LocalUri; context.URIRemote = Request.RemoteUri; context.ProtocolCommandID = Data.Sender; context.ProtocolContextID = Request.ProtocolContextID; context.ExpiryTimeSet(); context.ChangeState("AwaitRequest"); return false; }
public override bool Transmit(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { return base.Transmit(context, job, Data); }
/// <summary> /// This method swaps to the open state and calls the corresponding method. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public override bool OpenRequest(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.ChangeState("Open"); return context.OpenRequest(job, Data); }
/// <summary> /// This method is called after the transport-server handshake is confirmed. This method starts the listening process. /// </summary> /// <param name="context">The transport context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns>Returns false is the listening process has started successfully.</returns> public override bool ListenConfirm(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { TransportContextTCPIP tcpContext = context as TransportContextTCPIP; if (tcpContext == null) { Data.Response.Status = CH.HTTPCodes.ServiceUnavailable_503; return true; } Uri location = tcpContext.Location; //Ok, validate the IP address IPAddress address; if (!IPAddress.TryParse(location.Host, out address)) { if (location.Host.ToLowerInvariant() != "localhost") { Data.Response.Status = CH.HTTPCodes.BadRequest_400; Data.Response.Substatus = string.Format("Location '{0}' is not a valid listening address.", location.Host); return true; } address = IPAddress.Loopback; } IPEndPoint EndPoint = new IPEndPoint(address, location.Port); try { Socket listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //We need to start listening on the appropriate ports and IP addresses listeningSocket.Bind(EndPoint); //Start the socket listening, the cnLISTENQUEUE is the number of items we allow //in the connection queue listeningSocket.Listen(tcpContext.ListenerQueueLength); //tcpContext.LocalEndPoint = EndPoint; tcpContext.ActiveSocket = listeningSocket; //Ok, we need to shunt off the listening duties to another thread so that we can returns to //the server on this thread. AsyncCallback startListening = new AsyncCallback(tcpContext.ListenerStart); startListening.BeginInvoke(null, null, null); Data.Response.Status = CH.HTTPCodes.OK_200; return false; } catch (SocketException socex) { Data.Response.Status = CH.HTTPCodes.BadRequest_400; Data.Response.Substatus = string.Format("The socket threw an exception {0}:{1} ({2})", socex.ErrorCode, socex.SocketErrorCode, socex.Message); return true; } catch (ObjectDisposedException obex) { Data.Response.Status = CH.HTTPCodes.InternalServerError_500; Data.Response.Substatus = string.Format("The socket threw an object disposed exception {0}", obex.Message); return true; } catch (Exception ex) { Data.Response.Status = CH.HTTPCodes.InternalServerError_500; Data.Response.Substatus = string.Format("An unhandeled exception was caught {0}/{1}", ex.GetType().ToString(), ex.Message); return true; } }
/// <summary> /// This method receives requests from the HTTP agent and passes the request to the Site Controller. /// </summary> /// <param name="httpContext">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request data.</param> /// <returns>Returns true if the connection should be reset.</returns> public override bool Receive(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { RQCallbackServer Request = Data.ContractRequest; RSCallbackServer Response = Data.ContractResponse; HTTPRequestMessage httpRQ = null; RQRSContract<SiteControllerRequest, SiteControllerResponse> Env = null; try { httpRQ = Request.Message as HTTPRequestMessage; Env = context.EnvelopeHelper.Get(mSiteManager) as RQRSContract<SiteControllerRequest, SiteControllerResponse>; context.SenderIdentitySet((IXimuraRQRSEnvelope)Env); Env.DestinationAddress = new EnvelopeAddress(mSiteManager, "Receive"); //HTTPServerContext httpContext = context as HTTPServerContext; Env.ContractRequest.MessageMethod = httpRQ.Instruction.Verb; Env.ContractRequest.Message = httpRQ; Env.ContractRequest.MessageUri = ExtractUri(httpRQ, context.URILocal); Env.ContractRequest.MessageUserAgent = ExtractUserAgent(httpRQ); Env.ContractRequest.ServerType = "http"; Env.ContractRequest.URILocal = context.URILocal; Env.ContractRequest.URIRemote = context.URIRemote; context.ExpiryTime = null; Guid signatureID = context.SignatureID.Value; //Send the request synchronously to the server using the current job, //so that it is processed on the current thread. job.ProcessRequest((IXimuraRQRSEnvelope)Env); //Check whether the context has been reset during the call to the Site Controller. if (context == null || !context.SignatureID.HasValue || context.SignatureID.Value != signatureID) { Response.Status = CH.HTTPCodes.InternalServerError_500; Response.CloseNotify = true; return false; } context.ExpiryTimeSet(); Response.MessageResponse = Env.ContractResponse.Message; Response.MessageRequestType = typeof(HTTPRequestMessage); Response.MaxLength = 2000000; Response.Status = CH.HTTPCodes.OK_200; } catch (Exception ex) { Response.Status = CH.HTTPCodes.InternalServerError_500; Response.Substatus = ex.Message; } finally { Response.ProtocolContextID = Request.ProtocolContextID; Response.ServerContextID = context.SignatureID; if (httpRQ != null || httpRQ.ObjectPoolCanReturn) { httpRQ.ObjectPoolReturn(); } if (Env != null || Env.ObjectPoolCanReturn) { Env.ObjectPoolReturn(); } context.ChangeState("AwaitRequest"); } return false; }
public override bool Close(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { return base.Close(context, job, Data); }
public virtual bool Transmit(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { throw new NotImplementedException("Transmit is not implemented."); }
/// <summary> /// This base method switches any close request to the Close State. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public virtual bool Close(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.ChangeState("Close"); return context.Close(job, Data); }