示例#1
0
        public void OnResponse(ref HTTPRequestStruct hTTPRequestStruct, ref HTTPResponseStruct responseStruct)
        {
            char[] base64chars = Encoding.UTF8.GetChars(hTTPRequestStruct.BodyData);

            WriteLog("Base64Chars: " + new String(base64chars));

            byte[] encBytes = Convert.FromBase64CharArray(base64chars, 0, base64chars.Length);

            XmlRpcRequest xmlRequest = XmlRpcRequest.ParseXmlRpcRequest(encryptor.Decrypt(encBytes));

            WriteLog("\n\n MethodCall: " + xmlRequest.ObjectName + "." + xmlRequest.MethodName);
            WriteLog("\n\n Params ");
            foreach (Object o in xmlRequest.Params)
                WriteLog("\n " + o);

            Object handler = null;

            if(handlers.ContainsKey(xmlRequest.ObjectName))
                handler = handlers[xmlRequest.ObjectName];

            if (handler == null)
                throw new XmlRpcException(String.Format("No handler registered for \"{0}\"", xmlRequest.ObjectName));

            Type handlerType = handler.GetType();
            MethodInfo methodInfo = handlerType.GetMethod(xmlRequest.MethodName);

            if (methodInfo == null)
                throw new MissingMethodException("Method " + xmlRequest.MethodName + " not found.");

            Object returnValue = null;

            lock (this)
            {
                returnValue = methodInfo.Invoke(handler, xmlRequest.Params.ToArray());
            }

            if (returnValue == null)
                throw new XmlRpcException("Method returned NULL.");

            XmlRpcResponse response = new XmlRpcResponse(returnValue);
            MemoryStream ms = new MemoryStream();
            response.WriteXml(new XmlTextWriter(ms, UTF8Encoding.UTF8));

            responseStruct.BodyData = UTF8Encoding.UTF8.GetBytes(Convert.ToBase64String(encryptor.Encrypt(ms.ToArray())));
            responseStruct.BodySize = responseStruct.BodyData.Length;
        }
示例#2
0
        private void ProcessRequest(MemoryStream inputStream, MemoryStream outputStream)
        {
            XmlRpcResponse response = null;

            try
            {
                XmlRpcRequest request = XmlRpcRequest.ParseXmlRpcRequest(inputStream);
                response = InvokeMethod(request);
            }
            catch (Exception e)
            {
                response = new XmlRpcResponse(e.Message, e.GetHashCode());
            }

            try
            {
                response.WriteXml(outputStream);
            }
            catch (Exception e)
            {
                WriteLog(e.Message);
            }
        }
示例#3
0
 private void PrepareFaultResponse(ref HTTPResponseStruct responseStruct, string faultMessage, int faultCode)
 {
     XmlRpcResponse response = new XmlRpcResponse(faultMessage, faultCode);
     MemoryStream ms = new MemoryStream();
     response.WriteXml(new XmlTextWriter(ms, UTF8Encoding.UTF8));
     responseStruct.BodyData = UTF8Encoding.UTF8.GetBytes(Convert.ToBase64String(this.Parent.encryptor.Encrypt(ms.ToArray())));
     responseStruct.BodySize = responseStruct.BodyData.Length;
 }
示例#4
0
        private void ProcessLoginRequest(MemoryStream inputStream, MemoryStream outputStream, IPEndPoint endPoint)
        {
            XmlRpcResponse response = null;

            try
            {
                XmlRpcRequest request = XmlRpcRequest.ParseXmlRpcRequest(inputStream);
                if (request.ObjectName == "Server" && request.MethodName == "Login")
                {
                    if (request.Params.Count == 2 && request.Params[0] is String && request.Params[1] is String)
                    {
                        bool loggedIn;
                        lock (this)
                        {
                            loggedIn = (String)request.Params[0] == this.userName && (String)request.Params[1] == this.passWord;
                        }

                        if (loggedIn)
                        {
                            DateTime now = DateTime.Now;

                            if (connections.ContainsKey(endPoint.Address))
                                connections[endPoint.Address] = now;
                            else
                                connections.Add(endPoint.Address, DateTime.Now);

                            response = new XmlRpcResponse(true);
                        }
                        else
                            throw new LoginException("Invalid Username or Password");
                    }
                    else
                        throw new LoginException("Invalid parameter list for the login method");
                }
                else
                    throw new LoginException("You must be logged in to perform this action.");
            }
            catch (LoginException le)
            {
                response = new XmlRpcResponse(le.Message, le.GetHashCode());
            }
            catch (Exception e)
            {
                response = new XmlRpcResponse("Error", 0);
            }

            try
            {
                response.WriteXml(outputStream);
            }
            catch(Exception e)
            {
                WriteLog(e.Message);
            }
        }