Add setting to debug IRC traffic. Refs #91.

After this setting has been enabled all IRC traffic will be written
to the verbose log (only for new connections).
This commit is contained in:
Sebastian Kaspari 2013-01-29 21:35:44 +01:00
parent f9ef1c65ec
commit a39a4259ea
5 changed files with 55 additions and 13 deletions

View File

@ -65,4 +65,7 @@
<string name="key_history_size" translatable="false">history_size</string>
<string name="default_history_size" translatable="false">50</string>
<string name="key_debug_traffic" translatable="false">debug_traffic</string>
<string name="default_debug_traffic" translatable="false">false</string>
</resources>

View File

@ -234,6 +234,8 @@
<string name="settings_ime_extract_desc">Use fullscreen keyboard when in landscape mode</string>
<string name="settings_history_size_title">History size</string>
<string name="settings_history_size_desc">Number of lines of conversation history to keep</string>
<string name="settings_debug_traffic_title">Debug IRC traffic</string>
<string name="settings_debug_traffic_desc">Log IRC traffic to the verbose log. This may be a security risk!</string>
<string name="minute_1">1 minute</string>
<string name="minutes_5">5 minutes</string>

View File

@ -154,5 +154,10 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:defaultValue="@string/default_quitmessage"
android:dialogTitle="@string/settings_quitmessage_dialog_title"
android:dialogMessage="@string/settings_quitmessage_dialog_desc" />
<CheckBoxPreference
android:title="@string/settings_debug_traffic_title"
android:summary="@string/settings_debug_traffic_desc"
android:key="@string/key_debug_traffic"
android:defaultValue="@string/default_debug_traffic" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -21,11 +21,13 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
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 <sebastian@yaaic.org>
*/
public class IRCConnection extends PircBot
{
private static final String TAG = "Yaaic/IRCConnection";
private final IRCService service;
private final Server server;
private ArrayList<String> 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<String> 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
*/

View File

@ -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.
*/