Example #1
0
        private byte[] core_inform_channel_added(byte[] args)
        {
            UInt32 ch_id = Struct.extractUInt32(new List <byte>(args));

            ((Channel)this.GetChannel(ch_id)).isLinked = true;
            return(Struct.packNullTerminatedString(String.Format("Channel with ID {0} set to 'hasLink'", ch_id)).ToArray());
        }
Example #2
0
        /*
         * 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());
        }
        public byte[] createResponse()
        {
            // this function should only be called when the method has finished (finished member == $true), but anyway, this isn't checked here

            // first response field is uint32 method id
            List <byte> response = Struct.packUInt32(this.id);

            // next field is a ubyte indicating success or error (0 success, everything else error)
            if (this.error)
            {
                response = Struct.packByte((byte)1, response);                            // indicating an error
                response = Struct.packNullTerminatedString(this.error_message, response); //append error message
                return(response.ToArray());                                               // hand back error response
            }

            response = Struct.packByte((byte)0, response); // add success field
            response = Struct.packByteArray(this.result, response);

            return(response.ToArray()); // return result
        }