예제 #1
0
        public static void version_handshake(Stream stream, thinCLIProtocol tCLIprotocol)
        {
            /* Check for the initial magic string */
            byte[] magic = Types.unmarshal_n(stream, (uint)tCLIprotocol.magic_string.Length);
            for (int i = 0; i < tCLIprotocol.magic_string.Length; i++)
            {
                if (magic[i] != tCLIprotocol.magic_string[i])
                {
                    tCLIprotocol.dGlobalError("Failed to find a server on " + tCLIprotocol.conf.hostname + ":" + tCLIprotocol.conf.port);
                    tCLIprotocol.dGlobalUsage();
                    tCLIprotocol.dExit(1);
                }
            }
            /* Read the remote version numbers */
            int remote_major = Types.unmarshal_int(stream);
            int remote_minor = Types.unmarshal_int(stream);

            tCLIprotocol.dGlobalDebug("Remote host has version " + remote_major + "." + remote_minor, tCLIprotocol);
            tCLIprotocol.dGlobalDebug("Client has version " + tCLIprotocol.major + "." + tCLIprotocol.minor, tCLIprotocol);
            if (tCLIprotocol.major != remote_major)
            {
                tCLIprotocol.dGlobalError("Protocol version mismatch talking to server on " + tCLIprotocol.conf.hostname + ":" + tCLIprotocol.conf.port);
                tCLIprotocol.dGlobalUsage();
                tCLIprotocol.dExit(1);
            }
            /* Tell the server our version numbers */
            for (int i = 0; i < tCLIprotocol.magic_string.Length; i++)
            {
                stream.WriteByte((byte)tCLIprotocol.magic_string[i]);
            }
            Types.marshal_int(stream, tCLIprotocol.major);
            Types.marshal_int(stream, tCLIprotocol.minor);
        }
예제 #2
0
        public static void CheckPermitFiles(String filename, thinCLIProtocol tCLIprotocol, bool includeCurrentDir = false)
        {
            string fullpath = "";

            try
            {
                fullpath = Path.GetFullPath(filename);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Failed to retrieve full path of file '{0}', '{1}'", filename, ex.Message));
            }

            if (includeCurrentDir)
            {
                tCLIprotocol.EnteredParamValues.Add(Directory.GetCurrentDirectory());
            }

            foreach (string value in tCLIprotocol.EnteredParamValues)
            {
                try
                {
                    String valueFullPath = Path.GetFullPath(value);

                    if (fullpath.StartsWith(valueFullPath))
                    {
                        tCLIprotocol.dGlobalDebug("Passed permit files check", tCLIprotocol);
                        return;
                    }
                }
                catch
                {
                }
            }

            throw new Exception(string.Format("The file with name '{0}' is not present at the command line.", filename));
        }
예제 #3
0
        public static void interpreter(Stream stream, thinCLIProtocol tCLIprotocol)
        {
            string filename = "";
            string path     = "";
            string msg      = "";

            while (!tCLIprotocol.dropOut)
            {
                Types.unmarshal_int32(stream); // total message length (unused here)
                Messages.tag t = Messages.unmarshal_tag(stream);
                switch (t)
                {
                case Messages.tag.Command:
                    t = Messages.unmarshal_tag(stream);
                    switch (t)
                    {
                    case Messages.tag.Print:
                        msg = Types.unmarshal_string(stream);
                        tCLIprotocol.dGlobalDebug("Read: Print: " + msg, tCLIprotocol);
                        tCLIprotocol.dConsoleWriteLine(msg);
                        break;

                    case Messages.tag.PrintStderr:
                        msg = Types.unmarshal_string(stream);
                        tCLIprotocol.dGlobalDebug("Read: PrintStderr: " + msg, tCLIprotocol);
                        tCLIprotocol.dConsoleWriteLine(msg);
                        break;

                    case Messages.tag.Debug:
                        msg = Types.unmarshal_string(stream);
                        tCLIprotocol.dGlobalDebug("Read: Debug: " + msg, tCLIprotocol);
                        tCLIprotocol.dConsoleWriteLine(msg);
                        break;

                    case Messages.tag.Exit:
                        int code = Types.unmarshal_int(stream);
                        tCLIprotocol.dGlobalDebug("Read: Command Exit " + code, tCLIprotocol);
                        tCLIprotocol.dExit(code);
                        break;

                    case Messages.tag.Error:
                        tCLIprotocol.dGlobalDebug("Read: Command Error", tCLIprotocol);
                        string err_code = Types.unmarshal_string(stream);
                        tCLIprotocol.dConsoleWriteLine("Error code: " + err_code);
                        tCLIprotocol.dConsoleWrite("Error params: ");
                        int length = Types.unmarshal_int(stream);
                        for (int i = 0; i < length; i++)
                        {
                            string param = Types.unmarshal_string(stream);
                            tCLIprotocol.dConsoleWrite(param);
                            if (i != (length - 1))
                            {
                                tCLIprotocol.dConsoleWrite(", ");
                            }
                        }
                        tCLIprotocol.dConsoleWriteLine("");
                        break;

                    case Messages.tag.Prompt:
                        tCLIprotocol.dGlobalDebug("Read: Command Prompt", tCLIprotocol);
                        string response = tCLIprotocol.dConsoleReadLine();
                        tCLIprotocol.dConsoleWriteLine("Read " + response);

                        /* NB, 4+4+4 here for the blob, chunk and string length, put in by the marshal_string
                         * function. A franken-marshal. */
                        Types.marshal_int(stream, 4 + 4 + 4);         // length
                        Messages.marshal_tag(stream, Messages.tag.Blob);
                        Messages.marshal_tag(stream, Messages.tag.Chunk);
                        Types.marshal_string(stream, response);
                        Types.marshal_int(stream, 4 + 4);         // length
                        Messages.marshal_tag(stream, Messages.tag.Blob);
                        Messages.marshal_tag(stream, Messages.tag.End);
                        break;

                    case Messages.tag.Load:
                        filename = Types.unmarshal_string(stream);
                        CheckPermitFiles(filename, tCLIprotocol);
                        tCLIprotocol.dGlobalDebug("Read: Load " + filename, tCLIprotocol);
                        Messages.load(stream, filename, tCLIprotocol);
                        break;

                    case Messages.tag.HttpPut:
                        filename = Types.unmarshal_string(stream);
                        CheckPermitFiles(filename, tCLIprotocol);
                        path = Types.unmarshal_string(stream);
                        Uri uri = ParseUri(path, tCLIprotocol);
                        tCLIprotocol.dGlobalDebug("Read: HttpPut " + filename + " -> " + uri, tCLIprotocol);
                        Messages.http_put(stream, filename, uri, tCLIprotocol);
                        break;

                    case Messages.tag.HttpGet:
                        filename = Types.unmarshal_string(stream);
                        CheckPermitFiles(filename, tCLIprotocol, true);
                        path = Types.unmarshal_string(stream);
                        uri  = ParseUri(path, tCLIprotocol);
                        tCLIprotocol.dGlobalDebug("Read: HttpGet " + filename + " -> " + uri, tCLIprotocol);
                        Messages.http_get(stream, filename, uri, tCLIprotocol);
                        break;

                    default:
                        Messages.protocol_failure("Command", t, tCLIprotocol);
                        break;
                    }
                    break;

                default:
                    Messages.protocol_failure("Message", t, tCLIprotocol);
                    break;
                }
            }
        }
예제 #4
0
        public static void interpreter(Stream stream, thinCLIProtocol tCLIprotocol)
        {
            string filename = "";
            string path = "";
            string msg = "";
            while (!tCLIprotocol.dropOut)
            {
                Types.unmarshal_int32(stream); // total message length (unused here)	
                Messages.tag t = Messages.unmarshal_tag(stream);
                switch (t)
                {
                    case Messages.tag.Command:
                        t = Messages.unmarshal_tag(stream);
                        switch (t)
                        {
                            case Messages.tag.Print:
                                msg = Types.unmarshal_string(stream);
                                tCLIprotocol.dGlobalDebug("Read: Print: " + msg, tCLIprotocol);
                                tCLIprotocol.dConsoleWriteLine(msg);
                                break;
                            case Messages.tag.PrintStderr:
                                msg = Types.unmarshal_string(stream);
                                tCLIprotocol.dGlobalDebug("Read: PrintStderr: " + msg, tCLIprotocol);
                                tCLIprotocol.dConsoleWriteLine(msg); 
                                break;
                            case Messages.tag.Debug:
                                msg = Types.unmarshal_string(stream);
                                tCLIprotocol.dGlobalDebug("Read: Debug: " + msg, tCLIprotocol);
                                tCLIprotocol.dConsoleWriteLine(msg);
                                break;
                            case Messages.tag.Exit:
                                int code = Types.unmarshal_int(stream);
                                tCLIprotocol.dGlobalDebug("Read: Command Exit " + code, tCLIprotocol);
                                tCLIprotocol.dExit(code);
                                break;
                            case Messages.tag.Error:
                                tCLIprotocol.dGlobalDebug("Read: Command Error", tCLIprotocol);
                                string err_code = Types.unmarshal_string(stream);
                                tCLIprotocol.dConsoleWriteLine("Error code: " + err_code);
                                tCLIprotocol.dConsoleWrite("Error params: ");
                                int length = Types.unmarshal_int(stream);
                                for (int i = 0; i < length; i++)
                                {
                                    string param = Types.unmarshal_string(stream);
                                    tCLIprotocol.dConsoleWrite(param);
                                    if (i != (length - 1)) tCLIprotocol.dConsoleWrite(", ");
                                }
                                tCLIprotocol.dConsoleWriteLine("");
                                break;
                            case Messages.tag.Prompt:
                                tCLIprotocol.dGlobalDebug("Read: Command Prompt", tCLIprotocol);
                                string response = tCLIprotocol.dConsoleReadLine();
				tCLIprotocol.dConsoleWriteLine("Read "+response);
				/* NB, 4+4+4 here for the blob, chunk and string length, put in by the marshal_string
				function. A franken-marshal. */
                                Types.marshal_int(stream, 4 + 4 + 4); // length
                                Messages.marshal_tag(stream, Messages.tag.Blob);
                                Messages.marshal_tag(stream, Messages.tag.Chunk);
                                Types.marshal_string(stream, response);
                                Types.marshal_int(stream, 4 + 4); // length
                                Messages.marshal_tag(stream, Messages.tag.Blob);
                                Messages.marshal_tag(stream, Messages.tag.End);
                                break;
                            case Messages.tag.Load:
                                filename = Types.unmarshal_string(stream);
                                tCLIprotocol.dGlobalDebug("Read: Load " + filename, tCLIprotocol);
                                Messages.load(stream, filename, tCLIprotocol);
                                break;
                            case Messages.tag.HttpPut:
                                filename = Types.unmarshal_string(stream);
                                path = Types.unmarshal_string(stream);
                                Uri uri = ParseUri(path, tCLIprotocol);
                                tCLIprotocol.dGlobalDebug("Read: HttpPut " + filename + " -> " + uri, tCLIprotocol);
                                Messages.http_put(stream, filename, uri, tCLIprotocol);
                                break;
                            case Messages.tag.HttpGet:
                                filename = Types.unmarshal_string(stream);
                                path = Types.unmarshal_string(stream);
                                uri = ParseUri(path, tCLIprotocol);
                                tCLIprotocol.dGlobalDebug("Read: HttpGet " + filename + " -> " + uri, tCLIprotocol);
                                Messages.http_get(stream, filename, uri, tCLIprotocol);
                                break;
                            default:
                                Messages.protocol_failure("Command", t, tCLIprotocol);
                                break;
                        }
                        break;
                    default:
                        Messages.protocol_failure("Message", t, tCLIprotocol);
                        break;
                }
            }
        }
예제 #5
0
 public static void version_handshake(Stream stream, thinCLIProtocol tCLIprotocol)
 {
     /* Check for the initial magic string */
     byte[] magic = Types.unmarshal_n(stream, (uint)tCLIprotocol.magic_string.Length);
     for (int i = 0; i < tCLIprotocol.magic_string.Length; i++)
     {
         if (magic[i] != tCLIprotocol.magic_string[i])
         {
             tCLIprotocol.dGlobalError("Failed to find a server on " + tCLIprotocol.conf.hostname + ":" + tCLIprotocol.conf.port);
             tCLIprotocol.dGlobalUsage();
             tCLIprotocol.dExit(1);
         }
     }
     /* Read the remote version numbers */
     int remote_major = Types.unmarshal_int(stream);
     int remote_minor = Types.unmarshal_int(stream);
     tCLIprotocol.dGlobalDebug("Remote host has version " + remote_major + "." + remote_minor, tCLIprotocol);
     tCLIprotocol.dGlobalDebug("Client has version " + tCLIprotocol.major + "." + tCLIprotocol.minor, tCLIprotocol);
     if (tCLIprotocol.major != remote_major)
     {
         tCLIprotocol.dGlobalError("Protocol version mismatch talking to server on " + tCLIprotocol.conf.hostname + ":" + tCLIprotocol.conf.port);
         tCLIprotocol.dGlobalUsage();
         tCLIprotocol.dExit(1);
     }
     /* Tell the server our version numbers */
     for (int i = 0; i < tCLIprotocol.magic_string.Length; i++)
     {
         stream.WriteByte((byte)tCLIprotocol.magic_string[i]);
     }
     Types.marshal_int(stream, tCLIprotocol.major);
     Types.marshal_int(stream, tCLIprotocol.minor);
 }