public override void GetRoute (TransportRequest req, string vhost, int vport, string vpath)
		{
			IApplicationHost host = Listener.Server.GetRoute (vhost, vport, vpath);

			if (host != null) {
				req.Transport = host.AppHostTransport;
			}
		}
Exemple #2
0
        public override void GetRoute(TransportRequest req, string vhost, int vport, string vpath)
        {
            IApplicationHost host = Listener.Server.GetRoute(vhost, vport, vpath);

            if (host != null)
            {
                req.Transport = host.AppHostTransport;
            }
        }
        public virtual void SendOutput(ulong hash, int requestNumber, byte[] data, int length)
        {
            if (debugEnabled)
            {
                Logger.Write(LogLevel.Debug, "lt={0:X} SendOutput reqN={1}", hash, requestNumber);
            }
            TransportRequest req = GetRequest(hash);

            if (req != null && req.RequestNumber == requestNumber)
            {
                SendStreamData(req.fd, RecordType.StandardOutput, req.RequestId, data, length);
            }
        }
        public virtual void EndRequest(ulong hash, int requestNumber, int appStatus)
        {
            if (debugEnabled)
            {
                Logger.Write(LogLevel.Debug, "lt={0:X} EndRequest reqN={1}", hash, requestNumber);
            }
            TransportRequest req = GetRequest(hash);

            if (req != null && req.RequestNumber == requestNumber)
            {
                RemoveRequest(req.Hash);
                EndRequestBody body = new EndRequestBody(appStatus, ProtocolStatus.RequestComplete);

                byte[] bodyData = body.GetData();

                SendRecord(req.fd, RecordType.EndRequest, req.RequestId,
                           bodyData, 0, bodyData.Length);
            }
            else
            {
                Logger.Write(LogLevel.Error, "Wrong EndRequest");
            }
        }
		public override void HeadersSent (TransportRequest req)
		{
			req.Transport.HeadersSent (req.Hash, req.RequestNumber);
		}
		public override void Process (TransportRequest req)
		{
			req.Transport.Process (req.Hash, req.RequestNumber);
		}
		private void AddRequest (TransportRequest request)
		{
			lock (requestsLock) {
				requests.Add (request.Hash, request);
			}
		}
		public override void AddHeader (TransportRequest req, string name, string value)
		{
			req.Transport.AddHeader (req.Hash, req.RequestNumber, name, value);
		}
		public override void HeadersSent (TransportRequest req)
		{
			AppHostTransportHeadersSent (req.Host, req.Hash, req.RequestNumber);
		}
		public abstract bool IsHostFound(TransportRequest req);
Exemple #11
0
 public override void GetRoute(TransportRequest req, string vhost, int vport, string vpath)
 {
     req.Host = GetRoute(vhost, vport, vpath);
 }
Exemple #12
0
 public override void HeadersSent(TransportRequest req)
 {
     req.Transport.HeadersSent(req.Hash, req.RequestNumber);
 }
		public override void CreateRequest (TransportRequest req)
		{
			AppHostTransportCreateRequest (req.Host, req.Hash, req.RequestNumber);
		}
 public abstract void CreateRequest(TransportRequest req);
		public override void GetRoute (TransportRequest req, string vhost, int vport, string vpath)
		{
			req.Host = GetRoute (vhost, vport, vpath);
		}
		public override bool IsHostFound (TransportRequest req)
		{
			return req.Host != IntPtr.Zero;
		}
		public override void Process (TransportRequest req)
		{
			AppHostTransportProcess (req.Host, req.Hash, req.RequestNumber);
		}
Exemple #18
0
 public override bool IsHostFound(TransportRequest req)
 {
     return(req.Host != IntPtr.Zero);
 }
		public abstract void AddServerVariable(TransportRequest req, string name, string value);
Exemple #20
0
 public override void AddHeader(TransportRequest req, string name, string value)
 {
     req.Transport.AddHeader(req.Hash, req.RequestNumber, name, value);
 }
		public abstract void AddBodyPart(TransportRequest req, byte[] body, bool final);
Exemple #22
0
 public override void Process(TransportRequest req)
 {
     req.Transport.Process(req.Hash, req.RequestNumber);
 }
Exemple #23
0
 public override void CreateRequest(TransportRequest req)
 {
     AppHostTransportCreateRequest(req.Host, req.Hash, req.RequestNumber);
 }
Exemple #24
0
 public override void Process(TransportRequest req)
 {
     AppHostTransportProcess(req.Host, req.Hash, req.RequestNumber);
 }
 public abstract void AddHeader(TransportRequest req, string name, string value);
		public abstract void HeadersSent(TransportRequest req);
 public abstract void AddServerVariable(TransportRequest req, string name, string value);
		public abstract void Process(TransportRequest req);
        private bool AddHeader(string name, string value, bool isHeader, object userData)
        {
            TransportRequest req = userData as TransportRequest;

            //if we did not find a route yet
            if (!IsHostFound(req))
            {
                req.tempKeys.Add(new KeyValuePair()
                {
                    Key      = name,
                    Value    = value,
                    IsHeader = isHeader
                });

                if (req.VHost == null && name == "SERVER_NAME")
                {
                    req.VHost = value;
                }
                if (req.VPort == -1 && name == "SERVER_PORT")
                {
                    int.TryParse(value, out req.VPort);
                }
                if (req.VPath == null && name == "SCRIPT_NAME")
                {
                    req.VPath = value;
                }

                if (req.VHost != null && req.VPort != -1 && req.VPath != null)
                {
                    GetRoute(req, req.VHost, req.VPort, req.VPath);

                    if (IsHostFound(req))
                    {
                        CreateRequest(req);

                        foreach (KeyValuePair pair in req.tempKeys)
                        {
                            if (pair.IsHeader)
                            {
                                AddHeader(req, pair.Key, pair.Value);
                            }
                            else
                            {
                                AddServerVariable(req, pair.Key, pair.Value);
                            }
                        }
                    }
                    else
                    {
                        Logger.Write(LogLevel.Error, "Can't find app {0}:{1} {2}", req.VHost, req.VPort, req.VPath);
                        //TODO: Send EndRequest with error message
                        //SendError (request.Hash, req.RequestNumber, Strings.Connection_AbortRecordReceived);
                        byte[] notFound = HttpErrors.NotFound(req.VPath);
                        SendOutput(req.Hash, req.RequestNumber, notFound, notFound.Length);
                        EndRequest(req.Hash, req.RequestNumber, 0);
                        return(false);
                    }
                }
            }
            else
            {
                if (isHeader)
                {
                    AddHeader(req, name, value);
                }
                else
                {
                    AddServerVariable(req, name, value);
                }
            }

            return(true);
        }
		public abstract void GetRoute(TransportRequest req, string vhost, int vport, string vpath);
 public abstract void HeadersSent(TransportRequest req);
		public virtual bool Process (ulong listenerTag, int requestNumber, byte[] header, byte[] recordBody)
		{
			bool stopReceive = false;

			Record record = new Record ();
			record.Version = header [0];
			record.Type = (RecordType)header [1];
			record.RequestId = (ushort)((header [2] << 8) + header [3]);
			record.BodyLength = (ushort)((header [4] << 8) + header [5]);
			record.PaddingLength = header [6];
			record.Body = recordBody;
			if (debugEnabled) {
				Logger.Write (LogLevel.Debug, "lt={0} LT::ProcessRecord0 header={1} reqId={2}", listenerTag,
					record.Type, (ushort)((header [2] << 8) + header [3]));
			}
			ulong hash = ((ulong)record.RequestId << 32) ^ listenerTag;  

			TransportRequest request = GetRequest (hash);

			if (request == null && record.Type == RecordType.BeginRequest) {
				BeginRequestBody brb = new BeginRequestBody (recordBody);
				TransportRequest req = new TransportRequest (record.RequestId);
				req.Hash = ((ulong)record.RequestId << 32) ^ listenerTag;
				req.fd = (uint)listenerTag;
				req.KeepAlive = (brb.Flags & BeginRequestFlags.KeepAlive) == BeginRequestFlags.KeepAlive;
				AddRequest (req);

				//try to find single app route
				GetRoute (req, null, -1, null);
				if (IsHostFound(req)) {
					CreateRequest (req);
				}

				FastCgiNetworkConnector connector = FastCgiNetworkConnector.GetConnector (req.fd);
				if (connector != null) {
					connector.KeepAlive = req.KeepAlive;
				}
				return stopReceive;
			}

			if (request != null) {
				switch (record.Type) {
				case RecordType.BeginRequest:
					break;
				case RecordType.Params:
					if (header != null) {
						if (debugEnabled) {
							Logger.Write (LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
								header [1], (ushort)((header [2] << 8) + header [3]));
						}
					}

					if (recordBody != null) {
						FcgiUtils.ParseParameters (recordBody, AddHeader, request);
					} else {
						//FIXME: request.Host can be null
						HeadersSent (request);
					}

					if (debugEnabled) {
						Logger.Write (LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
							header [1], (ushort)((header [2] << 8) + header [3]));
					}
					break;
				case RecordType.StandardInput:
						//Ready to process
					if (debugEnabled) {
						Logger.Write (LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
							header [1], (ushort)((header [2] << 8) + header [3]));
					}
					bool final = record.BodyLength == 0;
					AddBodyPart (request, recordBody, final);
					if (final) {
						stopReceive = true;
						Process (request);
					}
					break;
				case RecordType.Data:
					break;
				case RecordType.GetValues:
					//TODO: return server values
					break;
				// Aborts a request when the server aborts.
				//TODO: make Thread.Abort for request
				case RecordType.AbortRequest:
					//FIXME: send it to the HostTransport as is
					//TODO: send error to Connector
					//TODO: send EndRequest to Connector
					//					SendError (request.RequestId, Strings.Connection_AbortRecordReceived);
					//					EndRequest (request.RequestId, -1, ProtocolStatus.RequestComplete);
					break;

				default:
				//TODO: CgiConnector.SendRecord
				//				SendRecord (new Record (Record.ProtocolVersion,
				//					RecordType.UnknownType,
				//					request.RequestId,
				//					new UnknownTypeBody (record.Type).GetData ()));
					break;
				}
			}

			return stopReceive;

		}
 public abstract void AddBodyPart(TransportRequest req, byte[] body, bool final);
		public override void AddServerVariable (TransportRequest req, string name, string value)
		{
			req.Transport.AddServerVariable (req.Hash, req.RequestNumber, name, value);
		}
 public abstract void Process(TransportRequest req);
		public override void AddBodyPart (TransportRequest req, byte[] body, bool final)
		{
			req.Transport.AddBodyPart (req.Hash, req.RequestNumber, body, final);
		}
 public abstract bool IsHostFound(TransportRequest req);
		public override bool IsHostFound (TransportRequest req)
		{
			return req.Transport != null;
		}
 public abstract void GetRoute(TransportRequest req, string vhost, int vport, string vpath);
		public override void CreateRequest (TransportRequest req)
		{
			req.Transport.CreateRequest (req.Hash, req.RequestNumber);
		}
 private void AddRequest(TransportRequest request)
 {
     lock (requestsLock) {
         requests.Add(request.Hash, request);
     }
 }
Exemple #42
0
 public override void AddServerVariable(TransportRequest req, string name, string value)
 {
     req.Transport.AddServerVariable(req.Hash, req.RequestNumber, name, value);
 }
        public virtual bool Process(ulong listenerTag, int requestNumber, byte[] header, byte[] recordBody)
        {
            bool stopReceive = false;

            Record record = new Record();

            record.Version       = header [0];
            record.Type          = (RecordType)header [1];
            record.RequestId     = (ushort)((header [2] << 8) + header [3]);
            record.BodyLength    = (ushort)((header [4] << 8) + header [5]);
            record.PaddingLength = header [6];
            record.Body          = recordBody;
            if (debugEnabled)
            {
                Logger.Write(LogLevel.Debug, "lt={0} LT::ProcessRecord0 header={1} reqId={2}", listenerTag,
                             record.Type, (ushort)((header [2] << 8) + header [3]));
            }
            ulong hash = ((ulong)record.RequestId << 32) ^ listenerTag;

            TransportRequest request = GetRequest(hash);

            if (request == null && record.Type == RecordType.BeginRequest)
            {
                BeginRequestBody brb = new BeginRequestBody(recordBody);
                TransportRequest req = new TransportRequest(record.RequestId);
                req.Hash      = ((ulong)record.RequestId << 32) ^ listenerTag;
                req.fd        = (uint)listenerTag;
                req.KeepAlive = (brb.Flags & BeginRequestFlags.KeepAlive) == BeginRequestFlags.KeepAlive;
                AddRequest(req);

                //try to find single app route
                GetRoute(req, null, -1, null);
                if (IsHostFound(req))
                {
                    CreateRequest(req);
                }

                FastCgiNetworkConnector connector = FastCgiNetworkConnector.GetConnector(req.fd);
                if (connector != null)
                {
                    connector.KeepAlive = req.KeepAlive;
                }
                return(stopReceive);
            }

            if (request != null)
            {
                switch (record.Type)
                {
                case RecordType.BeginRequest:
                    break;

                case RecordType.Params:
                    if (header != null)
                    {
                        if (debugEnabled)
                        {
                            Logger.Write(LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
                                         header [1], (ushort)((header [2] << 8) + header [3]));
                        }
                    }

                    if (recordBody != null)
                    {
                        FcgiUtils.ParseParameters(recordBody, AddHeader, request);
                    }
                    else
                    {
                        //FIXME: request.Host can be null
                        HeadersSent(request);
                    }

                    if (debugEnabled)
                    {
                        Logger.Write(LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
                                     header [1], (ushort)((header [2] << 8) + header [3]));
                    }
                    break;

                case RecordType.StandardInput:
                    //Ready to process
                    if (debugEnabled)
                    {
                        Logger.Write(LogLevel.Debug, "lt={0} LT::ProcessRecord header={1} reqId={2}", listenerTag,
                                     header [1], (ushort)((header [2] << 8) + header [3]));
                    }
                    bool final = record.BodyLength == 0;
                    AddBodyPart(request, recordBody, final);
                    if (final)
                    {
                        stopReceive = true;
                        Process(request);
                    }
                    break;

                case RecordType.Data:
                    break;

                case RecordType.GetValues:
                    //TODO: return server values
                    break;

                // Aborts a request when the server aborts.
                //TODO: make Thread.Abort for request
                case RecordType.AbortRequest:
                    //FIXME: send it to the HostTransport as is
                    //TODO: send error to Connector
                    //TODO: send EndRequest to Connector
                    //					SendError (request.RequestId, Strings.Connection_AbortRecordReceived);
                    //					EndRequest (request.RequestId, -1, ProtocolStatus.RequestComplete);
                    break;

                default:
                    //TODO: CgiConnector.SendRecord
                    //				SendRecord (new Record (Record.ProtocolVersion,
                    //					RecordType.UnknownType,
                    //					request.RequestId,
                    //					new UnknownTypeBody (record.Type).GetData ()));
                    break;
                }
            }

            return(stopReceive);
        }
Exemple #44
0
 public override void AddBodyPart(TransportRequest req, byte[] body, bool final)
 {
     req.Transport.AddBodyPart(req.Hash, req.RequestNumber, body, final);
 }
		public abstract void CreateRequest(TransportRequest req);
Exemple #46
0
 public override bool IsHostFound(TransportRequest req)
 {
     return(req.Transport != null);
 }
		public abstract void AddHeader(TransportRequest req, string name, string value);
Exemple #48
0
 public override void CreateRequest(TransportRequest req)
 {
     req.Transport.CreateRequest(req.Hash, req.RequestNumber);
 }
Exemple #49
0
 public override void HeadersSent(TransportRequest req)
 {
     AppHostTransportHeadersSent(req.Host, req.Hash, req.RequestNumber);
 }