void OnInputDataReceived (Request sender, DataReceivedArgs args) { // If the data is completed, call the worker and return. if (args.DataCompleted) { DataNeeded = false; if (input_data != null && write_index < input_data.Length) { Abort (Strings.ResponderRequest_IncompleteInput, write_index, input_data.Length); } else if (Server.MultiplexConnections) ThreadPool.QueueUserWorkItem (Worker); else Worker (null); return; } // If input_data is null, create the new array by // reading the length from the CONTENT_LENGTH parameter. if (input_data == null) { string length_text = GetParameter ("CONTENT_LENGTH"); // If the field is missing we can't continue. if (length_text == null) { Abort (Strings.ResponderRequest_NoContentLength); return; } // If the length isn't a number, we can't // continue. int length; if(!Int32.TryParse (length_text, NumberStyles.Integer, CultureInfo.InvariantCulture, out length)){ Abort (Strings.ResponderRequest_NoContentLengthNotNumber); return; } input_data = new byte [length]; } if (write_index + args.DataLength > input_data.Length) { Abort (Strings.ResponderRequest_ContentExceedsLength); return; } args.CopyTo (input_data, write_index); write_index += args.DataLength; }
void HandleBeginRequest (Request request, NRecord record) { // If a request with the given ID // already exists, there's a bug in the // client. Abort. if (request != null) { StopRun (Strings.Connection_RequestAlreadyExists); return; } // If there are unfinished requests // and multiplexing is disabled, inform // the client and don't begin the // request. if (!server.MultiplexConnections && UnfinishedRequests) { EndRequest (record.RequestID, 0, ProtocolStatus.CantMultiplexConnections); return; } // If the maximum number of requests is // reached, inform the client and don't // begin the request. if (!server.CanRequest) { EndRequest (record.RequestID, 0, ProtocolStatus.Overloaded); return; } var body = new BeginRequestBody (record); // If the role is "Responder", and it is // supported, create a ResponderRequest. if (body.Role == Role.Responder && server.SupportsResponder) request = new ResponderRequest(record.RequestID, this); else { // If the role is not supported inform the client // and don't begin the request. Logger.Write (LogLevel.Warning, Strings.Connection_RoleNotSupported, body.Role); EndRequest (record.RequestID, 0, ProtocolStatus.UnknownRole); return; } lock (request_lock) { requests.Add (request); } keep_alive = (body.Flags & BeginRequestFlags.KeepAlive) != 0; }
void HandleParams (Request request, NRecord record) { if (request == null) { StopRun (Strings.Connection_RequestDoesNotExist, record.RequestID); return; } IReadOnlyList<byte> body = record.GetBody (); request.AddParameterData (body); }
void HandleStandardInput (Request request, NRecord record) { if (request == null) { StopRun (Strings.Connection_RequestDoesNotExist, record.RequestID); return; } request.AddInputData (record); }
static void HandleAbortRequest (Request request) { if (request == null) return; request.Abort (Strings.Connection_AbortRecordReceived); }
void HandleRequest (NRecord record, Request request) { switch (record.Type) { // Creates a new request. case RecordType.BeginRequest: HandleBeginRequest (request, record); break; // Gets server values. case RecordType.GetValues: HandleGetValues (record); break; // Sends params to the request. case RecordType.Params: HandleParams (request, record); break; // Sends standard input to the request. case RecordType.StandardInput: HandleStandardInput (request, record); break; // Sends file data to the request. case RecordType.Data: HandleData (request, record); break; // Aborts a request when the server aborts. case RecordType.AbortRequest: HandleAbortRequest (request); break; // Informs the client that the record type is // unknown. default: HandleUnknown (record); break; } }
void HandleParams(Request request, Record record) { if (request == null) { StopRun (Strings.Connection_RequestDoesNotExist, record.RequestID); return; } request.AddParameterData (record.GetBody ()); }
void HandleData(Request request, Record record) { if (request == null) { StopRun (Strings.Connection_RequestDoesNotExist, record.RequestID); return; } request.AddFileData (record); }