/* * ChannelAddRequest * 0..3 UInt32 Channel ID * 4 byte Channel Class (0 = unspecified, 1 = ProcessChannel, ...) * 5 byte Channel Type (0 = unspecified, 1 = BIDIRECTIONAL, 2 = OUT, 3 = IN) Note: channel type has to be reversed on other endpoit IN becomes OUT, OUT becomes in * 6 byte Channel Encoding (0 = unspecified, 1 = BYTEARRAY, 2 = UTF8) * 7..10 UInt32 Channel parent ID (0= unspecified, in case of process channel process ID) * 11..14 UInt32 Channel subtype (in case of process: 0=STDIN, 1=STDOUT, 2=STDERR) */ /* * private void sendChannelAddRequest(Channel ch) * { * * if (ch is ProcessChannel) * { * ProcessChannel p_ch = (ProcessChannel)ch; * * List<byte> chAddRequest = Struct.packUInt32(p_ch.ID); * * chAddRequest = Struct.packByte(1, chAddRequest); * * if (p_ch.type == Channel.Types.BIDIRECTIONAL) chAddRequest = Struct.packByte(1, chAddRequest); * else if (p_ch.type == Channel.Types.IN) chAddRequest = Struct.packByte(2, chAddRequest); //set to out on other end * else if (p_ch.type == Channel.Types.OUT) chAddRequest = Struct.packByte(3, chAddRequest); //set to in on other end * else chAddRequest = Struct.packByte(0, chAddRequest); //unspecified * * if (p_ch.encoding == Channel.Encodings.BYTEARRAY) chAddRequest = Struct.packByte(1, chAddRequest); //set to BYTEARRAY encoding * else if (p_ch.encoding == Channel.Encodings.UTF8) chAddRequest = Struct.packByte(2, chAddRequest); //set to UTF-8 encoding * else chAddRequest = Struct.packByte(0, chAddRequest); //set to unspecified encoding * * * * } * else * { * Console.WriteLine("undefined channel"); * } * * } */ private byte[] core_call_fs_command(byte[] args) { List <byte> argbytes = new List <byte>(args); String command = Struct.extractNullTerminatedString(argbytes); String resstr = ""; if (command == "pwd") { resstr = FileSystem.pwd(); } else if (command == "ls") { String target = Struct.extractNullTerminatedString(argbytes); String[] entries = FileSystem.ls(target); foreach (String entry in entries) { resstr += entry + "\n"; } } else if (command == "cd") { String target = Struct.extractNullTerminatedString(argbytes); resstr = FileSystem.cd(target); } else { throw new ClientMethodException(String.Format("Unknown command {0}", command)); } return(Struct.packNullTerminatedString(resstr).ToArray()); }
private byte[] core_create_proc(byte[] args) { List <byte> data = new List <byte>(args); // first byte indicates if STDIN, STDOUT and STDERR should be streamed to channels bool use_channels = (Struct.extractByte(data) != 0); string proc_filename = Struct.extractNullTerminatedString(data); string proc_args = Struct.extractNullTerminatedString(data); ClientProcess proc = new ClientProcess(proc_filename, proc_args, use_channels, this.callbackChannelOutputPresent, this.triggerProcessingNeeded); //starts the process already proc.registerOnExitCallback(this.onProcessExit); if (use_channels) { this.AddChannel(proc.Ch_stdin); this.AddChannel(proc.Ch_stdout); this.AddChannel(proc.Ch_stderr); /* * proc.Ch_stdin = this.tl.CreateChannel(Channel.Types.IN, Channel.Encodings.UTF8); * proc.Ch_stdout = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8); * proc.Ch_stderr = this.tl.CreateChannel(Channel.Types.OUT, Channel.Encodings.UTF8); */ } //generate method response List <byte> resp = Struct.packUInt32((UInt32)proc.Id); if (use_channels) { resp = Struct.packByte(1, resp); resp = Struct.packUInt32(proc.Ch_stdin.ID, resp); resp = Struct.packUInt32(proc.Ch_stdout.ID, resp); resp = Struct.packUInt32(proc.Ch_stderr.ID, resp); } else { resp = Struct.packByte(0, resp); resp = Struct.packUInt32(0, resp); resp = Struct.packUInt32(0, resp); resp = Struct.packUInt32(0, resp); } Monitor.Enter(this.pendingClientProcessesLock); this.pending_client_processes.Add(proc.Id, proc); Monitor.Exit(this.pendingClientProcessesLock); //throw new ClientMethodException(String.Format("Not implemented: Trying to start proc '{0}' with args: {1}", proc_filename, proc_args)); return(resp.ToArray()); }
public ClientMethod(List <byte> data) { // generate client object based on data received in a run_method control message this.id = Struct.extractUInt32(data); this.name = Struct.extractNullTerminatedString(data); this.args = data.ToArray(); this.finished = false; this.error = false; this.started = false; }
/* * //REMOVE, obsolete * private byte[] core_create_filechannel(byte[] args) * { * List<byte> request = new List<byte>(args); * String local_filename = Struct.extractNullTerminatedString(request); * String local_file_access_mode = Struct.extractNullTerminatedString(request); * Byte local_file_target = Struct.extractByte(request); //0 = disc, 1 = in memory * Byte local_file_force = Struct.extractByte(request); //0 = don't force, 1= force (if force is set, non existing file get overwritten on WRITE, and non existing files are created on READWRITE * * * //create the file channel, on error an exception will be thrown and handled by the caller * FileChannel fc = new FileChannel(this.tl.setOutputProcessingNeeded, local_filename, local_file_access_mode, local_file_target, (local_file_force == 1)); * * //String response = String.Format("Created file channel for '{0}', access '{1}', mode: {2}, force {3}", local_filename, local_file_access_mode, local_file_target, local_file_force); * * //if we are here, channel creation succeded and we return the channel ID as response * List<byte> response = Struct.packUInt32(fc.ID); * return response.ToArray(); * } */ private byte[] core_fs_open_file(byte[] args) { List <byte> request = new List <byte>(args); String filename = Struct.extractNullTerminatedString(request); FileMode fm = (FileMode)Struct.extractByte(request); FileAccess fa = (FileAccess)Struct.extractByte(request); FileStream fs = File.Open(filename, fm, fa); this.addStream(fs); //store this in global list of opened streams int result = fs.GetHashCode(); //return stream id //if we are here, channel creation succeded and we return the channel ID as response List <byte> response = Struct.packInt32(result); return(response.ToArray()); }