public static byte[] BuildInvalidResponse(InvalidCommand command) { BinaryResponseStatus status; if (command!=null && command.Opcode == Opcode.unknown_command) status = BinaryResponseStatus.unknown_commnad; else status = BinaryResponseStatus.invalid_arguments; return BuildResposne(command.Opcode, status, command.Opaque, 0, null, null, null); }
public void CreateInvalidCommand() { _command = new InvalidCommand(); }
private void CreateInvalidCommand() { _command = new InvalidCommand(null); this.State = ParserState.ReadyToDispatch; return; }
private void CreateInvalidCommand(string error) { _command = new InvalidCommand(error); this.State = ParserState.ReadyToDispatch; return; }
private void CreateRetrievalCommand(string arguments, Opcode cmdType) { if (arguments == null) { CreateInvalidCommand(); return; } string[] argumentsArray = arguments.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (argumentsArray.Length == 0) { _command = new InvalidCommand(); } else { GetCommand getCommand = new GetCommand(cmdType); getCommand.Keys = argumentsArray; _command = getCommand; } this.State = ParserState.ReadyToDispatch; }
/// <summary> /// Parses an <see cref="Alachisoft.NCache.Integrations.Memcached.ProxyServer.Commands.AbstractCommand"/> from string /// </summary> /// <param name="command">string command to pe parsed</param> public void Parse(string command) { string[] commandParts = command.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (commandParts == null || commandParts.Length == 0) { _command = new InvalidCommand(); this.State = ParserState.ReadyToDispatch; return; } string arguments = null; if (commandParts.Length > 1) arguments = commandParts[1]; switch (commandParts[0]) { case "get": CreateRetrievalCommand(arguments, Opcode.Get); break; case "gets": CreateRetrievalCommand(arguments, Opcode.Gets); break; case "set": CreateStorageCommand(arguments, Opcode.Set); break; case "add": CreateStorageCommand(arguments, Opcode.Add); break; case "replace": CreateStorageCommand(arguments, Opcode.Replace); break; case "append": CreateStorageCommand(arguments, Opcode.Append); break; case "prepend": CreateStorageCommand(arguments, Opcode.Prepend); break; case "cas": CreateStorageCommand(arguments, Opcode.CAS); break; case "delete": CreateDeleteCommand(arguments); break; case "incr": CreateCounterCommand(arguments, Opcode.Increment); break; case "decr": CreateCounterCommand(arguments, Opcode.Decrement); break; case "touch": CreateTouchCommand(arguments); break; case "flush_all": CreateFlushCommand(arguments); break; case "stats": CreateStatsCommand(arguments); break; case "slabs": break; case "version": CreateVersionCommand(arguments); break; case "verbosity": CreateVerbosityCommand(arguments); break; case "quit": CreateQuitCommand(); break; default: CreateInvalidCommand(); break; } }
private void CreateSlabsCommand(string arguments) { if (string.IsNullOrEmpty(arguments)) { CreateInvalidCommand(); return; } string[] argumentsArray; argumentsArray = arguments.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (argumentsArray.Length > 3 || argumentsArray.Length < 2) { CreateInvalidCommand(); return; } try { bool noreply = false; switch (argumentsArray[0]) { case "reasign": int sourceClass = int.Parse(argumentsArray[1]); int destClass = int.Parse(argumentsArray[2]); noreply = argumentsArray.Length > 2 && argumentsArray[3] == "noreply"; _command = new SlabsReassignCommand(sourceClass, destClass); _command.NoReply = noreply; break; case "automove": int option = int.Parse(argumentsArray[1]); noreply = argumentsArray.Length > 2 && argumentsArray[2] == "noreply"; _command = new SlabsAuomoveCommand(option); _command.NoReply = noreply; break; default: _command = new InvalidCommand(); break; } this.State = ParserState.ReadyToDispatch; } catch (Exception) { CreateInvalidCommand(); } }