Exemplo n.º 1
0
		public static MessageContainer FromMessage (Message message)
		{
			MessageContainer container = new MessageContainer (message) {
				Path = (ObjectPath)message.Header[FieldCode.Path],
				Interface = (string)message.Header[FieldCode.Interface],
				Member = (string)message.Header[FieldCode.Member],
				Destination = (string)message.Header[FieldCode.Destination],
				//TODO: filled by the bus so reliable, but not the case for p2p
				//so we make it optional here, but this needs some more thought
				//if (message.Header.Fields.ContainsKey (FieldCode.Sender))
				Sender = (string)message.Header[FieldCode.Sender],
				ErrorName = (string)message.Header[FieldCode.ErrorName],
				ReplySerial = (uint?)message.Header[FieldCode.ReplySerial],
				Signature = message.Signature,
				Serial = message.Header.Serial,
				Type = message.Header.MessageType,
			};
#if PROTO_REPLY_SIGNATURE
			//TODO: note that an empty ReplySignature should really be treated differently to the field not existing!
			if (message.Header.Fields.ContainsKey (FieldCode.ReplySignature))
				container.ReplySignature = (Signature)message.Header[FieldCode.ReplySignature];
			else
				container.ReplySignature = Signature.Empty;
#endif

			return container;
		}
Exemplo n.º 2
0
		public static Message FromReceivedBytes (Connection connection, byte[] header, byte[] body)
		{
			Message message = new Message ();
			message.connection = connection;
			message.body = body;
			message.SetHeaderData (header);

			return message;
		}
Exemplo n.º 3
0
 public static void WriteMessage(Message msg, TextWriter w)
 {
     w.WriteLine("# Message");
     w.WriteLine("# Header");
     MessageDumper.WriteBlock(msg.GetHeaderData(), w);
     w.WriteLine("# Body");
     MessageDumper.WriteBlock(msg.Body, w);
     w.WriteLine();
     w.Flush();
 }
Exemplo n.º 4
0
		Message ExportToMessage () {
			var message = new Message ();
			message.Header.MessageType = Type;
			if (Type == MessageType.MethodCall)
				message.ReplyExpected = true;
			else
				message.Header.Flags = HeaderFlag.NoReplyExpected | HeaderFlag.NoAutoStart;
			message.Header[FieldCode.Path] = Path;
			message.Header[FieldCode.Interface] = Interface;
			message.Header[FieldCode.Member] = Member;
			message.Header[FieldCode.Destination] = Destination;
			message.Header[FieldCode.ErrorName] = ErrorName;
#if PROTO_REPLY_SIGNATURE
			//TODO
#endif
			message.Signature = Signature;
			if (ReplySerial != null)
				message.Header[FieldCode.ReplySerial] = (uint)ReplySerial;
			if (Serial != null)
				message.Header.Serial = (uint)Serial;

			return message;
		}
Exemplo n.º 5
0
		public bool MatchesHeader (Message msg)
		{
			if (MessageType != MessageType.All)
				if (msg.Header.MessageType != MessageType)
					return false;

			foreach (KeyValuePair<FieldCode,MatchTest> pair in Fields) {
				object value;
				if (!msg.Header.TryGetField (pair.Key, out value))
					return false;
				if (!pair.Value.Value.Equals (value))
					return false;
			}

			return true;
		}
Exemplo n.º 6
0
		public static void Test (HashSet<ArgMatchTest> a, Message msg)
		{
			List<Signature> sigs = new List<Signature> ();
			sigs.AddRange (msg.Signature.GetParts ());

			if (sigs.Count == 0) {
				a.Clear ();
				return;
			}

			a.RemoveWhere ( delegate (ArgMatchTest t) { return t.ArgNum >= sigs.Count || t.Signature != sigs[t.ArgNum]; } );

			// Sorting the list here is not ideal
			List<ArgMatchTest> tests = new List<ArgMatchTest> (a);
			tests.Sort ( delegate (ArgMatchTest aa, ArgMatchTest bb) { return aa.ArgNum - bb.ArgNum; } );

			if (tests.Count == 0) {
				a.Clear ();
				return;
			}

			MessageReader reader = new MessageReader (msg);

			int argNum = 0;
			foreach (ArgMatchTest test in tests) {
				if (argNum > test.ArgNum) {
					// This test cannot pass because a previous test already did.
					// So we already know it will fail without even trying.
					// This logic will need to be changed to support wildcards.
					a.Remove (test);
					continue;
				}

				while (argNum != test.ArgNum) {
					Signature sig = sigs[argNum];
					if (!reader.StepOver (sig))
						throw new Exception ();
					argNum++;
				}

				// TODO: Avoid re-reading values
				if (!reader.PeekValue (test.Signature[0]).Equals (test.Value)) {
					a.Remove (test);
					continue;
				}

				argNum++;
			}
		}
Exemplo n.º 7
0
 MessageContainer(Message originalMessage)
 {
     this.resultMessage = originalMessage;
 }
Exemplo n.º 8
0
 internal virtual void WriteMessage(Message msg)
 {
     lock (writeLock) {
         msg.Header.GetHeaderDataToStream (stream);
         if (msg.Body != null && msg.Body.Length != 0)
             stream.Write (msg.Body, 0, msg.Body.Length);
         stream.Flush ();
     }
 }
Exemplo n.º 9
0
		internal virtual void WriteMessage (Message msg)
		{
			lock (writeLock) {
				msg.Header.GetHeaderDataToStream (stream);
				//TODO: extract file descriptors from msg and write them to the stream similiar to how we
				//read them
				if (msg.Body != null && msg.Body.Length != 0)
					stream.Write (msg.Body, 0, msg.Body.Length);
				stream.Flush ();
			}
		}