diff --git a/application/res/values/settings.xml b/application/res/values/settings.xml
index 53e5ce7..ad9ed75 100644
--- a/application/res/values/settings.xml
+++ b/application/res/values/settings.xml
@@ -65,4 +65,7 @@
history_size
50
+
+ debug_traffic
+ false
diff --git a/application/res/values/strings.xml b/application/res/values/strings.xml
index 4ef60f5..467ab93 100644
--- a/application/res/values/strings.xml
+++ b/application/res/values/strings.xml
@@ -234,6 +234,8 @@
Use fullscreen keyboard when in landscape mode
History size
Number of lines of conversation history to keep
+ Debug IRC traffic
+ Log IRC traffic to the verbose log. This may be a security risk!
1 minute
5 minutes
diff --git a/application/res/xml/preferences.xml b/application/res/xml/preferences.xml
index ff0797e..19c961a 100644
--- a/application/res/xml/preferences.xml
+++ b/application/res/xml/preferences.xml
@@ -154,5 +154,10 @@ along with Yaaic. If not, see .
android:defaultValue="@string/default_quitmessage"
android:dialogTitle="@string/settings_quitmessage_dialog_title"
android:dialogMessage="@string/settings_quitmessage_dialog_desc" />
+
diff --git a/application/src/org/yaaic/irc/IRCConnection.java b/application/src/org/yaaic/irc/IRCConnection.java
index 1efbaa1..27c7c30 100644
--- a/application/src/org/yaaic/irc/IRCConnection.java
+++ b/application/src/org/yaaic/irc/IRCConnection.java
@@ -21,11 +21,13 @@ along with Yaaic. If not, see .
*/
package org.yaaic.irc;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import java.util.regex.Pattern;
+import org.jibble.pircbot.NickAlreadyInUseException;
import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User;
import org.yaaic.R;
@@ -41,28 +43,30 @@ import org.yaaic.model.ServerInfo;
import org.yaaic.model.Status;
import android.content.Intent;
+import android.util.Log;
/**
* The class that actually handles the connection to an IRC server
- *
+ *
* @author Sebastian Kaspari
*/
public class IRCConnection extends PircBot
{
+ private static final String TAG = "Yaaic/IRCConnection";
private final IRCService service;
private final Server server;
private ArrayList autojoinChannels;
private Pattern mNickMatch;
private boolean ignoreMOTD = true;
-
+ private boolean debugTraffic = false;
private boolean isQuitting = false;
private boolean disposeRequested = false;
private final Object isQuittingLock = new Object();
/**
* Create a new connection
- *
+ *
* @param service
* @param serverId
*/
@@ -71,6 +75,8 @@ public class IRCConnection extends PircBot
this.server = Yaaic.getInstance().getServerById(serverId);
this.service = service;
+ this.debugTraffic = service.getSettings().debugTraffic();
+
// XXX: Should be configurable via settings
this.setAutoNickChange(true);
@@ -78,9 +84,24 @@ public class IRCConnection extends PircBot
this.updateNickMatchPattern();
}
+ /**
+ * This method handles events when any line of text arrives from the server.
+ *
+ * We are intercepting this method call for logging the IRC traffic if
+ * this debug option is set.
+ */
+ @Override
+ protected void handleLine(String line) throws NickAlreadyInUseException, IOException {
+ if (debugTraffic) {
+ Log.v(TAG, server.getTitle() + " :: " + line);
+ }
+
+ super.handleLine(line);
+ }
+
/**
* Set the nickname of the user
- *
+ *
* @param nickname The nickname to use
*/
public void setNickname(String nickname)
@@ -91,7 +112,7 @@ public class IRCConnection extends PircBot
/**
* Set the real name of the user
- *
+ *
* @param realname The realname to use
*/
public void setRealName(String realname)
@@ -103,7 +124,7 @@ public class IRCConnection extends PircBot
/**
* Set channels to autojoin after connect
- *
+ *
* @param channels
*/
public void setAutojoinChannels(ArrayList channels)
@@ -113,7 +134,7 @@ public class IRCConnection extends PircBot
/**
* On version (CTCP version)
- *
+ *
* This is a fix for pircbot as pircbot uses the version as "real name" and as "version"
*/
@Override
@@ -128,7 +149,7 @@ public class IRCConnection extends PircBot
/**
* Set the ident of the user
- *
+ *
* @param ident The ident to use
*/
public void setIdent(String ident)
@@ -143,7 +164,7 @@ public class IRCConnection extends PircBot
public void onConnect()
{
server.setStatus(Status.CONNECTED);
-
+
server.setMayReconnect(true);
ignoreMOTD = service.getSettings().isIgnoreMOTDEnabled();
@@ -1187,7 +1208,7 @@ public class IRCConnection extends PircBot
/**
* Get all channels where the user with the given nickname is online
- *
+ *
* @param nickname
* @return Array of channel names
*/
@@ -1211,7 +1232,7 @@ public class IRCConnection extends PircBot
/**
* Get list of users in a channel as array of strings
- *
+ *
* @param channel Name of the channel
*/
public String[] getUsersAsStringArray(String channel)
@@ -1229,7 +1250,7 @@ public class IRCConnection extends PircBot
/**
* Get a user by channel and nickname
- *
+ *
* @param channel The channel the user is in
* @param nickname The nickname of the user (with or without prefix)
* @return the User object or null if user was not found
@@ -1282,7 +1303,7 @@ public class IRCConnection extends PircBot
/**
* Check whether the nickname has been mentioned.
- *
+ *
* @param text The text to check for the nickname
* @return true if nickname was found, otherwise false
*/
diff --git a/application/src/org/yaaic/model/Settings.java b/application/src/org/yaaic/model/Settings.java
index d208b9f..bc63902 100644
--- a/application/src/org/yaaic/model/Settings.java
+++ b/application/src/org/yaaic/model/Settings.java
@@ -299,6 +299,17 @@ public class Settings
);
}
+ /**
+ * Should IRC traffic be logged to the verbose log?
+ * @return
+ */
+ public boolean debugTraffic() {
+ return preferences.getBoolean(
+ resources.getString(R.string.key_debug_traffic),
+ Boolean.parseBoolean(resources.getString(R.string.default_debug_traffic))
+ );
+ }
+
/**
* Whether sentences in messages should be automatically capitalized.
*/