Beispiel #1
0
        //very messy
        internal void MaybeSendUnknownMethodError(MethodCall method_call)
        {
            Message msg = MessageHelper.CreateUnknownMethodError(method_call);

            if (msg != null)
            {
                Send(msg);
            }
        }
Beispiel #2
0
        internal void HandleMessage(Message msg)
        {
            if (msg == null)
            {
                return;
            }

            //List<Connection> recipients = new List<Connection> ();
            HashSet <Connection> recipients = new HashSet <Connection> ();
            //HashSet<Connection> recipientsAll = new HashSet<Connection> (Connections);

            object fieldValue = msg.Header[FieldCode.Destination];

            if (fieldValue != null)
            {
                string     destination = (string)fieldValue;
                Connection destConn;
                if (Names.TryGetValue(destination, out destConn))
                {
                    recipients.Add(destConn);
                }
                else if (destination != DBusBusName && !destination.StartsWith(":") && (msg.Header.Flags & HeaderFlag.NoAutoStart) != HeaderFlag.NoAutoStart)
                {
                    // Attempt activation
                    StartProcessNamed(destination);
                    //Thread.Sleep (5000);
                    // TODO: Route the message to the newly activated service!
                    activationMessages[destination] = msg;
                    //if (Names.TryGetValue (destination, out destConn))
                    //	recipients.Add (destConn);
                    //else
                    //	Console.Error.WriteLine ("Couldn't route message to activated service");
                }
                else if (destination != DBusBusName)
                {
                    // Send an error when there's no hope of getting the requested reply
                    if (msg.ReplyExpected)
                    {
                        // Error org.freedesktop.DBus.Error.ServiceUnknown: The name {0} was not provided by any .service files
                        Message rmsg = MessageHelper.CreateUnknownMethodError(new MethodCall(msg));
                        if (rmsg != null)
                        {
                            //Caller.Send (rmsg);
                            Caller.SendReal(rmsg);
                            return;
                        }
                    }
                }
            }

            HashSet <Connection> recipientsMatchingHeader = new HashSet <Connection> ();

            HashSet <ArgMatchTest> a = new HashSet <ArgMatchTest> ();

            foreach (KeyValuePair <MatchRule, List <Connection> > pair in Rules)
            {
                if (recipients.IsSupersetOf(pair.Value))
                {
                    continue;
                }
                if (pair.Key.MatchesHeader(msg))
                {
                    a.UnionWith(pair.Key.Args);
                    recipientsMatchingHeader.UnionWith(pair.Value);
                }
            }

            MatchRule.Test(a, msg);

            foreach (KeyValuePair <MatchRule, List <Connection> > pair in Rules)
            {
                if (recipients.IsSupersetOf(pair.Value))
                {
                    continue;
                }
                if (!recipientsMatchingHeader.IsSupersetOf(pair.Value))
                {
                    continue;
                }
                if (a.IsSupersetOf(pair.Key.Args))
                {
                    recipients.UnionWith(pair.Value);
                }
            }

            foreach (Connection conn in recipients)
            {
                // TODO: rewrite/don't header fields
                //conn.Send (msg);
                // TODO: Zero the Serial or not?
                //msg.Header.Serial = 0;
                ((ServerConnection)conn).SendReal(msg);
            }
        }