summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-26 07:47:40 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-08-17 13:21:01 (GMT)
commitf56f245c1f7e768caf356a0e7b57f428cf8cc6da (patch)
treef0935ab00c73e86163abe72fc9c20098121fff4f /src/com/isode/stroke/client/ClientXMLTracer.java
parent2533374644704040ca67aba4e1240a9d6ea450c8 (diff)
downloadstroke-f56f245c1f7e768caf356a0e7b57f428cf8cc6da.zip
stroke-f56f245c1f7e768caf356a0e7b57f428cf8cc6da.tar.bz2
Update Client.
Updates all bits of Client to be in parity with Swiften. Some part of code which depends on Network is commented. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for: ClientBlockListManager, ClientSession and NickResolver. All tests pass. Change-Id: I5b9b0e5ae5b2df58202e2349ba24e4544d9a4614
Diffstat (limited to 'src/com/isode/stroke/client/ClientXMLTracer.java')
-rw-r--r--src/com/isode/stroke/client/ClientXMLTracer.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/isode/stroke/client/ClientXMLTracer.java b/src/com/isode/stroke/client/ClientXMLTracer.java
new file mode 100644
index 0000000..e3a65a6
--- /dev/null
+++ b/src/com/isode/stroke/client/ClientXMLTracer.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010-2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.client;
+
+import com.isode.stroke.client.CoreClient;
+import com.isode.stroke.client.XMLBeautifier;
+import com.isode.stroke.base.SafeByteArray;
+import com.isode.stroke.signals.SignalConnection;
+import com.isode.stroke.signals.Slot1;
+
+public class ClientXMLTracer {
+
+ private XMLBeautifier beautifier;
+ private boolean bosh;
+ private SignalConnection onDataReadConnection;
+ private SignalConnection onDataWrittenConnection;
+
+ public ClientXMLTracer(CoreClient client) {
+ this(client, false);
+ }
+
+ public ClientXMLTracer(CoreClient client, boolean bosh) {
+ this.bosh = bosh;
+ beautifier = new XMLBeautifier(true, true);
+ onDataReadConnection = client.onDataRead.connect(new Slot1<SafeByteArray>() {
+ @Override
+ public void call(SafeByteArray s) {
+ printData('<', s);
+ }
+ });
+ onDataWrittenConnection = client.onDataWritten.connect(new Slot1<SafeByteArray>() {
+ @Override
+ public void call(SafeByteArray s) {
+ printData('>', s);
+ }
+ });
+ }
+
+ private void printData(char direction, final SafeByteArray data) {
+ printLine(direction);
+ if (bosh) {
+ String line = data.toString();
+ // Disabled because it swallows bits of XML (namespaces, if I recall)
+ // size_t endOfHTTP = line.find("\r\n\r\n");
+ // if (false && endOfHTTP != std::string::npos) {
+ // std::cerr << line.substr(0, endOfHTTP) << std::endl << beautifier->beautify(line.substr(endOfHTTP)) << std::endl;
+ // }
+ // else {
+ System.err.println(line);
+ // }
+ }
+ else {
+ System.err.println(beautifier.beautify(data.toString()));
+ }
+ }
+
+ private void printLine(char c) {
+ for (int i = 0; i < 80; ++i) {
+ System.err.println(c);
+ }
+ System.err.println();
+ }
+}