Ejemplo n.º 1
0
		public void It_should_replace_tuples_with_same_id()
		{
			var doc = new PresenceDocument("*****@*****.**");
			doc.Modify(0, GetPresenceBytes("<tuple id='1'></tuple>"));
			doc.Modify(1, GetPresenceBytes("<tuple id='1'><new/></tuple>"));

			AreEqual("<tuple id='1' xmlns='urn:ietf:params:xml:ns:pidf'><new /></tuple>", doc);
		}
Ejemplo n.º 2
0
		public void It_should_remove_tuples_if_it_absent_in_new_request()
		{
			var doc = new PresenceDocument("*****@*****.**");
			doc.Modify(0, GetPresenceBytes("<tuple id='1'></tuple>"));
			doc.Modify(0, GetPresenceBytes("<tuple id='2'></tuple>"));

			AreEqual("<tuple id='2' xmlns='urn:ietf:params:xml:ns:pidf'></tuple>", doc);
		}
Ejemplo n.º 3
0
		public void It_should_remove_tuples_by_sipIfMatch()
		{
			var doc = new PresenceDocument("*****@*****.**");
			doc.Modify(0, GetPresenceBytes("<tuple id='1'></tuple><tuple id='2'></tuple>"));
			doc.Modify(1, GetPresenceBytes("<tuple id='2'></tuple>"));
			doc.Remove(0);

			AreEqual("<tuple id='2' xmlns='urn:ietf:params:xml:ns:pidf'></tuple>", doc);
		}
Ejemplo n.º 4
0
		private void AreEqual(string expected, PresenceDocument doc)
		{
			var writer = new SipMessageWriter();

			expected = expected.Replace('\'', '"');

			//byte[] actualBytes = null;
			//int copied = doc.CopyTo(
			//    (length) => { return new ArraySegment<byte>(actualBytes = new byte[length], 0, length); });
			doc.WriteContent(writer);

			//string actual = Encoding.UTF8.GetString(actualBytes);

			var actual = Encoding.UTF8.GetString(writer.Buffer, writer.Offset, writer.Count);

			Assert.AreEqual(openPresence + expected + closePresence, actual);
		}
Ejemplo n.º 5
0
		private void SendNotify(Dialog dialog, int expires, PresenceDocument document)
		{
			int transactionId = GetTransactionId(Methods.Notifym);

			var writer = new SipMessageWriter();

			writer.WriteRequestLine(Methods.Notifym, dialog.RemoteUri);
			writer.WriteVia(dialog.Transport, dialog.LocalEndPoint, transactionId);
			writer.WriteFrom(dialog.LocalUri, dialog.LocalTag);
			writer.WriteTo(dialog.RemoteUri, dialog.RemoteTag);
			writer.WriteCallId(dialog.CallId);
			writer.WriteEventPresence();
			writer.WriteSubscriptionState(expires);
			writer.WriteMaxForwards(70);
			writer.WriteCseq(dialog.GetNextLocalCseq(), Methods.Notifym);
			writer.WriteContact(dialog.LocalEndPoint, dialog.Transport);

			if (document != null)
			{
				writer.WriteContentType(application, pidfXml);
				//writer.WriteContentLength();
				//writer.WriteCRLF();

				//writer.RewriteContentLength(
				//    document.CopyTo((length) => writer.GetBytesForCustomWrite(length)));

				document.WriteLenghtAndContent(writer);
			}
			else
			{
				writer.WriteContentLength(0);
				writer.WriteCRLF();
			}

			notifyProducer.SendRequest(dialog.Transport, dialog.LocalEndPoint,
				dialog.RemoteEndPoint, ServerAsyncEventArgs.AnyConnectionId, writer, transactionId);
		}
Ejemplo n.º 6
0
		private void SimpleModule_NotifyEvent(string publisherId, string subscriptionId, int expires, PresenceDocument document)
		{
			var dialog = dialogManager.Get(new ByteArrayPart(subscriptionId));

			if (dialog != null)
				SendNotify(dialog, expires, document);
		}
Ejemplo n.º 7
0
 public Publication(string aor)
 {
     document      = new PresenceDocument(aor);
     subscriptions = new ThreadSafe.List <Subscription>(
         new List <Subscription>());
 }
Ejemplo n.º 8
0
		public Publication(string aor)
		{
			document = new PresenceDocument(aor);
			subscriptions = new ThreadSafe.List<Subscription>(
				new List<Subscription>());
		}