Exemplo n.º 1
0
        public void getBusStats(XmlRpcValue stats)
        {
            XmlRpcValue publish_stats   = new XmlRpcValue(),
                        subscribe_stats = new XmlRpcValue(),
                        service_stats   = new XmlRpcValue();

            publish_stats.SetArray(0);   //.Size = 0;
            subscribe_stats.SetArray(0); //subscribe_stats.Size = 0;
            service_stats.SetArray(0);   //service_stats.Size = 0;
            int pidx = 0;

            lock (advertised_topics_mutex)
            {
                foreach (Publication t in advertised_topics)
                {
                    publish_stats.Set(pidx++, t.GetStats());
                }
            }
            int sidx = 0;

            lock (subs_mutex)
            {
                foreach (Subscription t in subscriptions)
                {
                    subscribe_stats.Set(sidx++, t.getStats());
                }
            }

            //TODO: fix for services

            stats.Set(0, publish_stats);
            stats.Set(1, subscribe_stats);
            stats.Set(2, service_stats);
        }
Exemplo n.º 2
0
        private static async Task <bool> GetParamAsync(string key, XmlRpcValue resultValue, bool useCache)
        {
            string mappepKey = Names.Resolve(key);

            if (useCache)
            {
                lock (gate)
                {
                    if (cachedValues.TryGetValue(mappepKey, out var cachedValue) && !cachedValue.IsEmpty)
                    {
                        resultValue.Copy(cachedValue);
                        return(true);
                    }
                }
            }

            var parm   = new XmlRpcValue();
            var result = new XmlRpcValue();

            parm.Set(0, ThisNode.Name);
            parm.Set(1, mappepKey);
            resultValue.SetArray(0);

            bool ret = await Master.ExecuteAsync("getParam", parm, result, resultValue, false).ConfigureAwait(false);

            if (ret && useCache)
            {
                lock (gate)
                {
                    cachedValues[mappepKey] = resultValue.Clone();
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
        public XmlRpcValue GetStats()
        {
            var stats = new XmlRpcValue();

            stats.Set(0, Name);
            var conn_data = new XmlRpcValue();

            conn_data.SetArray(0);

            lock (gate)
            {
                int cidx = 0;
                foreach (SubscriberLink sub_link in subscriberLinks)
                {
                    var s      = sub_link.Stats;
                    var inside = new XmlRpcValue();
                    inside.Set(0, sub_link.connectionId);
                    inside.Set(1, s.BytesSent);
                    inside.Set(2, s.MessageDataSent);
                    inside.Set(3, s.MessagesSent);
                    inside.Set(4, 0);
                    conn_data.Set(cidx++, inside);
                }
            }

            stats.Set(1, conn_data);
            return(stats);
        }
Exemplo n.º 4
0
        public XmlRpcValue getStats()
        {
            var stats = new XmlRpcValue();

            stats.Set(0, name);
            var conn_data = new XmlRpcValue();

            conn_data.SetArray(0);
            lock ( publisher_links_mutex )
            {
                int cidx = 0;
                foreach (PublisherLink link in publisher_links)
                {
                    XmlRpcValue v = new XmlRpcValue();
                    var         s = link.stats;
                    v.Set(0, link.ConnectionID);
                    v.Set(1, s.bytesReceived);
                    v.Set(2, s.messagesReceived);
                    v.Set(3, s.drops);
                    v.Set(4, 0);
                    conn_data.Set(cidx++, v);
                }
            }
            stats.Set(1, conn_data);
            return(stats);
        }
Exemplo n.º 5
0
        public XmlRpcValue GetBusStats()
        {
            var publishStats   = new XmlRpcValue();
            var subscribeStats = new XmlRpcValue();
            var serviceStats   = new XmlRpcValue();

            lock (gate)
            {
                int pidx = 0;
                publishStats.SetArray(advertisedTopics.Count);
                foreach (Publication p in advertisedTopics)
                {
                    publishStats.Set(pidx++, p.GetStats());
                }

                int sidx = 0;
                subscribeStats.SetArray(subscriptions.Count);
                foreach (Subscription s in subscriptions)
                {
                    subscribeStats.Set(sidx++, s.GetStats());
                }
            }

            // TODO: fix for services
            serviceStats.SetArray(0); //service_stats.Size = 0;

            var stats = new XmlRpcValue();

            stats.Set(0, publishStats);
            stats.Set(1, subscribeStats);
            stats.Set(2, serviceStats);
            return(stats);
        }
Exemplo n.º 6
0
        public XmlRpcValue GetStats()
        {
            XmlRpcValue stats = new XmlRpcValue();

            stats.Set(0, Name);
            XmlRpcValue conn_data = new XmlRpcValue();

            conn_data.SetArray(0);
            lock (subscriber_links_mutex)
            {
                int cidx = 0;
                foreach (SubscriberLink sub_link in subscriber_links)
                {
                    SubscriberLink.Stats s      = sub_link.stats;
                    XmlRpcValue          inside = new XmlRpcValue();
                    inside.Set(0, sub_link.connection_id);
                    inside.Set(1, s.bytes_sent);
                    inside.Set(2, s.message_data_sent);
                    inside.Set(3, s.messages_sent);
                    inside.Set(4, 0);
                    conn_data.Set(cidx++, inside);
                }
            }
            stats.Set(1, conn_data);
            return(stats);
        }
Exemplo n.º 7
0
        public XmlRpcValue GetStats()
        {
            var stats = new XmlRpcValue();

            stats.Set(0, Name);
            var conn_data = new XmlRpcValue();

            conn_data.SetArray(0);
            lock (gate)
            {
                int cidx = 0;
                foreach (PublisherLink link in publisherLinks)
                {
                    XmlRpcValue v = new XmlRpcValue();
                    var         s = link.Stats;
                    v.Set(0, link.ConnectionId);
                    v.Set(1, s.BytesReceived);
                    v.Set(2, s.MessagesReceived);
                    v.Set(3, s.Drops);
                    v.Set(4, 0);
                    conn_data.Set(cidx++, v);
                }
            }
            stats.Set(1, conn_data);
            return(stats);
        }
Exemplo n.º 8
0
        public bool ValidateXmlRpcResponse(string method, XmlRpcValue response, XmlRpcValue payload)
        {
            if (response.Type != XmlRpcType.Array)
            {
                return(ValidateFailed(method, "didn't return an array -- {0}", response));
            }
            if (response.Count != 3)
            {
                return(ValidateFailed(method, "didn't return a 3-element array -- {0}", response));
            }
            if (response[0].Type != XmlRpcType.Int)
            {
                return(ValidateFailed(method, "didn't return an int as the 1st element -- {0}", response));
            }
            int status_code = response[0].GetInt();

            if (response[1].Type != XmlRpcType.String)
            {
                return(ValidateFailed(method, "didn't return a string as the 2nd element -- {0}", response));
            }

            string status_string = response[1].GetString();

            if (status_code != 1)
            {
                return(ValidateFailed(method, "returned an error ({0}): [{1}] -- {2}", status_code, status_string, response));
            }

            switch (response[2].Type)
            {
            case XmlRpcType.Array:
            {
                payload.SetArray(0);
                for (int i = 0; i < response[2].Count; i++)
                {
                    payload.Set(i, response[2][i]);
                }
            }
            break;

            case XmlRpcType.Int:
            case XmlRpcType.Double:
            case XmlRpcType.String:
            case XmlRpcType.Boolean:
                payload.Copy(response[2]);
                break;

            case XmlRpcType.Empty:
                break;

            default:
                throw new ArgumentException("Unhandled valid XML-RPC payload type: " + response[2].Type, nameof(response));
            }
            return(true);
        }
Exemplo n.º 9
0
        public static bool getImpl(string key, ref XmlRpcValue v, bool use_cache)
        {
            string mapped_key = names.resolve(key);

            if (use_cache)
            {
                lock (parms_mutex)
                {
                    if (subscribed_params.Contains(mapped_key))
                    {
                        if (parms.ContainsKey(mapped_key))
                        {
                            if (parms[mapped_key].Valid)
                            {
                                v = parms[mapped_key];
                                return(true);
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        subscribed_params.Add(mapped_key);
                        XmlRpcValue parm = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue();
                        parm.Set(0, this_node.Name);
                        parm.Set(1, XmlRpcManager.Instance.uri);
                        parm.Set(2, mapped_key);
                        if (!master.execute("subscribeParam", parm, result, payload, false))
                        {
                            subscribed_params.Remove(mapped_key);
                            use_cache = false;
                        }
                    }
                }
            }

            XmlRpcValue parm2 = new XmlRpcValue(), result2 = new XmlRpcValue();

            parm2.Set(0, this_node.Name);
            parm2.Set(1, mapped_key);
            v.SetArray(0);

            bool ret = master.execute("getParam", parm2, result2, v, false);

            if (use_cache)
            {
                lock (parms_mutex)
                {
                    parms.Add(mapped_key, v);
                }
            }

            return(ret);
        }
Exemplo n.º 10
0
 public void GetSubscriptions(XmlRpcValue subs)
 {
     subs.SetArray(0);
     lock (gate)
     {
         int i = 0;
         foreach (Subscription t in subscriptions)
         {
             subs.Set(i++, new XmlRpcValue(t.Name, t.DataType));
         }
     }
 }
Exemplo n.º 11
0
 public void getSubscriptions(ref XmlRpcValue subs)
 {
     subs.SetArray(0);
     lock ( subcriptionsMutex )
     {
         int sidx = 0;
         foreach (Subscription t in subscriptions)
         {
             subs.Set(sidx++, new XmlRpcValue(t.name, t.datatype));
         }
     }
 }
Exemplo n.º 12
0
 public void GetPublications(XmlRpcValue pubs)
 {
     pubs.SetArray(0);
     lock (gate)
     {
         int i = 0;
         foreach (Publication t in advertisedTopics)
         {
             XmlRpcValue pub = new XmlRpcValue();
             pub.Set(0, t.Name);
             pub.Set(1, t.DataType);
             pubs.Set(i++, pub);
         }
     }
 }
Exemplo n.º 13
0
 public void getPublications(ref XmlRpcValue pubs)
 {
     pubs.SetArray(0);
     lock ( advertisedTopicsMutex )
     {
         int sidx = 0;
         foreach (Publication t in advertisedTopics)
         {
             XmlRpcValue pub = new XmlRpcValue();
             pub.Set(0, t.Name);
             pub.Set(1, t.DataType);
             pubs.Set(sidx++, pub);
         }
     }
 }
Exemplo n.º 14
0
 public void getBusInfo(XmlRpcValue info)
 {
     info.SetArray(0);
     lock (advertised_topics_mutex)
     {
         foreach (Publication t in advertised_topics)
         {
             t.getInfo(info);
         }
     }
     lock (subs_mutex)
     {
         foreach (Subscription t in subscriptions)
         {
             t.getInfo(info);
         }
     }
 }
Exemplo n.º 15
0
        public XmlRpcValue GetBusInfo()
        {
            var info = new XmlRpcValue();

            info.SetArray(0);
            lock (gate)
            {
                foreach (Publication t in advertisedTopics)
                {
                    t.GetInfo(info);
                }

                foreach (Subscription t in subscriptions)
                {
                    t.GetInfo(info);
                }
            }
            return(info);
        }
Exemplo n.º 16
0
        public XmlRpcValue getBusInfo()
        {
            var info = new XmlRpcValue();

            info.SetArray(0);
            lock ( advertisedTopicsMutex )
            {
                foreach (Publication t in advertisedTopics)
                {
                    t.getInfo(info);
                }
            }
            lock ( subcriptionsMutex )
            {
                foreach (Subscription t in subscriptions)
                {
                    t.getInfo(info);
                }
            }
            return(info);
        }
Exemplo n.º 17
0
        public XmlRpcValue getBusStats()
        {
            var publish_stats   = new XmlRpcValue();
            var subscribe_stats = new XmlRpcValue();
            var service_stats   = new XmlRpcValue();

            int pidx = 0;

            lock ( advertisedTopicsMutex )
            {
                publish_stats.SetArray(advertisedTopics.Count);
                foreach (Publication t in advertisedTopics)
                {
                    publish_stats.Set(pidx++, t.GetStats());
                }
            }

            int sidx = 0;

            lock ( subcriptionsMutex )
            {
                subscribe_stats.SetArray(subscriptions.Count);
                foreach (Subscription t in subscriptions)
                {
                    subscribe_stats.Set(sidx++, t.getStats());
                }
            }

            // TODO: fix for services
            service_stats.SetArray(0); //service_stats.Size = 0;

            var stats = new XmlRpcValue();

            stats.Set(0, publish_stats);
            stats.Set(1, subscribe_stats);
            stats.Set(2, service_stats);
            return(stats);
        }
Exemplo n.º 18
0
        public static bool GetImpl(string key, out XmlRpcValue value, bool useCache)
        {
            string mappepKey = Names.Resolve(key);

            value = new XmlRpcValue();

            if (useCache)
            {
                lock (gate)
                {
                    if (cachedValues.TryGetValue(mappepKey, out var cachedValue) && !cachedValue.IsEmpty)
                    {
                        value = cachedValue;
                        return(true);
                    }
                }
            }

            XmlRpcValue parm2 = new XmlRpcValue(), result2 = new XmlRpcValue();

            parm2.Set(0, ThisNode.Name);
            parm2.Set(1, mappepKey);
            value.SetArray(0);

            bool ret = Master.Execute("getParam", parm2, result2, value, false);

            if (ret && useCache)
            {
                lock (gate)
                {
                    cachedValues[mappepKey] = value;
                }
            }

            return(ret);
        }
Exemplo n.º 19
0
 public bool validateXmlrpcResponse(string method, XmlRpcValue response, XmlRpcValue payload)
 {
     if (response.Type != XmlRpcValue.ValueType.TypeArray)
         return validateFailed(method, "didn't return an array -- {0}", response);
     if (response.Size != 3)
         return validateFailed(method, "didn't return a 3-element array -- {0}", response);
     if (response[0].Type != XmlRpcValue.ValueType.TypeInt)
         return validateFailed(method, "didn't return an int as the 1st element -- {0}", response);
     int status_code = response[0].Get<int>();
     if (response[1].Type != XmlRpcValue.ValueType.TypeString)
         return validateFailed(method, "didn't return a string as the 2nd element -- {0}", response);
     string status_string = response[1].Get<string>();
     if (status_code != 1)
         return validateFailed(method, "returned an error ({0}): [{1}] -- {2}", status_code, status_string,
             response);
     switch (response[2].Type)
     {
         case XmlRpcValue.ValueType.TypeArray:
             {
                 payload.SetArray(0);
                 for (int i = 0; i < response[2].Length; i++)
                 {
                     payload.Set(i, response[2][i]);
                 }
             }
             break;
         case XmlRpcValue.ValueType.TypeInt:
             payload.asInt = response[2].asInt;
             break;
         case XmlRpcValue.ValueType.TypeDouble:
             payload.asDouble = response[2].asDouble;
             break;
         case XmlRpcValue.ValueType.TypeString:
             payload.asString = response[2].asString;
             break;
         case XmlRpcValue.ValueType.TypeBoolean:
             payload.asBool = response[2].asBool;
             break;
         case XmlRpcValue.ValueType.TypeInvalid:
             break;
         default:
             throw new Exception("Unhandled valid xmlrpc payload type: " + response[2].Type);
     }
     return true;
 }
Exemplo n.º 20
0
        public bool validateXmlrpcResponse(string method, XmlRpcValue response, XmlRpcValue payload)
        {
            if (response.Type != XmlRpcValue.ValueType.TypeArray)
            {
                return(validateFailed(method, "didn't return an array -- {0}", response));
            }
            if (response.Size != 3)
            {
                return(validateFailed(method, "didn't return a 3-element array -- {0}", response));
            }
            if (response[0].Type != XmlRpcValue.ValueType.TypeInt)
            {
                return(validateFailed(method, "didn't return an int as the 1st element -- {0}", response));
            }
            int status_code = response[0].Get <int>();

            if (response[1].Type != XmlRpcValue.ValueType.TypeString)
            {
                return(validateFailed(method, "didn't return a string as the 2nd element -- {0}", response));
            }
            string status_string = response[1].Get <string>();

            if (status_code != 1)
            {
                return(validateFailed(method, "returned an error ({0}): [{1}] -- {2}", status_code, status_string,
                                      response));
            }
            switch (response[2].Type)
            {
            case XmlRpcValue.ValueType.TypeArray:
            {
                payload.SetArray(0);
                for (int i = 0; i < response[2].Length; i++)
                {
                    payload.Set(i, response[2][i]);
                }
            }
            break;

            case XmlRpcValue.ValueType.TypeInt:
                payload.asInt = response[2].asInt;
                break;

            case XmlRpcValue.ValueType.TypeDouble:
                payload.asDouble = response[2].asDouble;
                break;

            case XmlRpcValue.ValueType.TypeString:
                payload.asString = response[2].asString;
                break;

            case XmlRpcValue.ValueType.TypeBoolean:
                payload.asBool = response[2].asBool;
                break;

            case XmlRpcValue.ValueType.TypeInvalid:
                break;

            default:
                throw new Exception("Unhandled valid xmlrpc payload type: " + response[2].Type);
            }
            return(true);
        }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
        // Execute multiple calls and return the results in an array.
        public bool executeMulticall(string methodNameRoot, XmlRpcValue parms, XmlRpcValue result)
        {
            if (methodNameRoot != SYSTEM_MULTICALL) return false;

            // There ought to be 1 parameter, an array of structs
            if (parms.Length != 1 || parms[0].Type != XmlRpcValue.ValueType.TypeArray)
                throw new XmlRpcException(SYSTEM_MULTICALL + ": Invalid argument (expected an array)");

            int nc = parms[0].Length;
            result.SetArray(nc);

            for (int i = 0; i < nc; ++i)
            {
                if (!parms[0][i].hasMember(METHODNAME) ||
                    !parms[0][i].hasMember(PARAMS))
                {
                    result[i].Set(FAULTCODE, -1);
                    result[i].Set(FAULTSTRING, SYSTEM_MULTICALL + ": Invalid argument (expected a struct with members methodName and params)");
                    continue;
                }

                string methodName = parms[0][i][METHODNAME].GetString();
                XmlRpcValue methodParams = parms[0][i][PARAMS];

                XmlRpcValue resultValue = new XmlRpcValue();
                resultValue.SetArray(1);
                try
                {
                    if (!executeMethod(methodName, methodParams, resultValue[0]) &&
                        !executeMulticall(methodName, parms, resultValue[0]))
                    {
                        result[i].Set(FAULTCODE, -1);
                        result[i].Set(FAULTSTRING, methodName + ": unknown method name");
                    }
                    else
                        result[i] = resultValue;
                }
                catch (XmlRpcException fault)
                {
                    result[i].Set(FAULTCODE, 0);
                    result[i].Set(FAULTSTRING, fault.Message);
                }
            }

            return true;
        }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
        private void listMethods(XmlRpcValue result)
        {
            int i = 0;
            result.SetArray(_methods.Count + 1);

            foreach (var rec in _methods)
            {
                result.Set(i++, rec.Key);
            }

            // Multicall support is built into XmlRpcServerConnection
            result.Set(i, MULTICALL);
        }
Exemplo n.º 25
0
 public XmlRpcValue GetStats()
 {
     XmlRpcValue stats = new XmlRpcValue();
     stats.Set(0, Name);
     XmlRpcValue conn_data = new XmlRpcValue();
     conn_data.SetArray(0);
     lock (subscriber_links_mutex)
     {
         int cidx = 0;
         foreach (SubscriberLink sub_link in subscriber_links)
         {
             SubscriberLink.Stats s = sub_link.stats;
             XmlRpcValue inside = new XmlRpcValue();
             inside.Set(0, sub_link.connection_id);
             inside.Set(1, s.bytes_sent);
             inside.Set(2, s.message_data_sent);
             inside.Set(3, s.messages_sent);
             inside.Set(4, 0);
             conn_data.Set(cidx++, inside);
         }
     }
     stats.Set(1, conn_data);
     return stats;
 }