Esempio n. 1
0
        // Parse the method name and the argument values from the request.
        private string parseRequest(XmlRpcValue parms, string _request)
        {
            bool   success    = true;
            string methodName = "unknown";

            //XmlRpcValue result = null;
            using (XmlReader reader = XmlReader.Create(new StringReader(_request)))
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(reader);

                // Parse response xml into result
                //int offset = 0;
                XmlNodeList xmlMethodNameList = xmldoc.GetElementsByTagName("methodName");
                if (xmlMethodNameList.Count > 0)
                {
                    XmlNode xmlMethodName = xmlMethodNameList[0];
                    methodName = xmlMethodName.InnerText;
                }

                XmlNodeList xmlParameters = xmldoc.GetElementsByTagName("param");
                XmlNodeList xmlFault      = xmldoc.GetElementsByTagName("fault");
                if (xmlParameters.Count == 0)
                {
                    XmlRpcUtil.error("Error in XmlRpcServer::parseRequest: Invalid request - no methodResponse. Request:\n{0}", _request);
                    return(null);
                }

                parms.SetArray(xmlParameters.Count);

                for (int i = 0; i < xmlParameters.Count; i++)
                {
                    var value = new XmlRpcValue();
                    value.fromXml(xmlParameters[i]["value"]);
                    parms.asArray[i] = value;
                }

                if (xmlFault.Count > 0 && parms.fromXml(xmlFault[0]))
                {
                    XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.WARNING, "Read fault on response for request:\n{0}\nFAULT: {1}", _request, parms.ToString());
                }
            }

            return(methodName);
        }
Esempio n. 2
0
        public bool fromXml(XmlNode value)
        {
            //int val = offset;
            //offset = 0;
            try
            {
                //XmlElement value = node["value"];
                if (value == null)
                {
                    return(false);
                }

                string     tex = value.InnerText;
                XmlElement val;
                if ((val = value[BOOLEAN_TAG]) != null)
                {
                    _type = ValueType.TypeBoolean;
                    int tmp = 0;
                    if (!int.TryParse(tex, out tmp))
                    {
                        return(false);
                    }
                    if (tmp != 0 && tmp != 1)
                    {
                        return(false);
                    }
                    asBool = (tmp == 0 ? false : true);
                }
                else if ((val = value[I4_TAG]) != null)
                {
                    _type = ValueType.TypeInt;
                    return(int.TryParse(tex, out asInt));
                }
                else if ((val = value[INT_TAG]) != null)
                {
                    _type = ValueType.TypeInt;
                    return(int.TryParse(tex, out asInt));
                }
                else if ((val = value[DOUBLE_TAG]) != null)
                {
                    _type = ValueType.TypeDouble;
                    return(double.TryParse(tex, out asDouble));
                }
                else if ((val = value[DATETIME_TAG]) != null)
                {
                    // TODO: implement
                }
                else if ((val = value[BASE64_TAG]) != null)
                {
                    // TODO: implement
                }
                else if ((val = value[STRING_TAG]) != null)
                {
                    _type    = ValueType.TypeString;
                    asString = tex;
                }
                else if ((val = value[ARRAY_TAG]) != null)
                {
                    var data = val[DATA_TAG];
                    if (data == null)
                    {
                        return(false);
                    }
                    var selection = data.SelectNodes(VALUE_TAG);
                    SetArray(selection.Count);
                    for (int i = 0; i < selection.Count; i++)
                    {
                        var xmlValue = new XmlRpcValue();
                        if (!xmlValue.fromXml(selection[i]))
                        {
                            return(false);
                        }
                        asArray[i] = xmlValue;
                    }
                }
                else if ((val = value[STRUCT_TAG]) != null)
                {
                    // TODO: implement
                }
                else
                {
                    _type    = ValueType.TypeString;
                    asString = tex;
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        // Convert the response xml into a result value
        private bool parseResponse(XmlRpcValue result, string _response)
        {
            bool success = true;

            //XmlRpcValue result = null;
            using (XmlReader reader = XmlReader.Create(new StringReader(_response)))
            {
                XmlDocument response = new XmlDocument();
                response.Load(reader);
                // Parse response xml into result
                //int offset = 0;
                XmlNodeList resp         = response.GetElementsByTagName("methodResponse");
                XmlNode     responseNode = resp[0];

                //if (!XmlRpcUtil.findTag(METHODRESPONSE_TAG, _response, out offset))
                if (resp.Count == 0)
                {
                    XmlRpcUtil.error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n{0}", _response);
                    return(false);
                }

                XmlElement pars  = responseNode["params"];
                XmlElement fault = responseNode["fault"];

                //result = new XmlRpcValue();
                if (pars != null)
                {
                    bool isArray   = false;
                    var  selection = pars.SelectNodes("param");
                    if (selection.Count > 1)
                    {
                        result.SetArray(selection.Count);
                        int i = 0;
                        foreach (XmlNode par in selection)
                        {
                            var value = new XmlRpcValue();
                            value.fromXml(par["value"]);
                            result[i++] = value;
                        }
                    }
                    else if (selection.Count == 1)
                    {
                        result.fromXml(selection[0]["value"]);
                    }
                    else
                    {
                        success = false;
                    }
                }
                else if (fault != null && result.fromXml(fault))
                {
                    success = false;
                }
                else
                {
                    XmlRpcUtil.error("Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n{0}", _response);
                }
                _response = "";
            }
            return(success);
        }