Browse Source

Add initial work on MSN parser

Change-Id: Ie684811c98597cabdfa608786763675b491444fc
Depends-On: Icaa1cebfd34ddc1a278d00468d9d1da3048eb869
Reviewed-on: http://gerrit.dmdirc.com/1990
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.7rc1
Greg Holmes 13 years ago
parent
commit
c51d08c6d7

BIN
lib/httpcore.jar View File


BIN
lib/jml-1.0b4-full.jar View File


+ 76
- 0
src/com/dmdirc/addons/parser_msn/MSNChannelClientInfo.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.BaseChannelClientInfo;
26
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
27
+import com.dmdirc.parser.interfaces.ChannelInfo;
28
+import com.dmdirc.parser.interfaces.ClientInfo;
29
+
30
+/**
31
+ * An MSN-specific channel client info object.
32
+ */
33
+public class MSNChannelClientInfo extends BaseChannelClientInfo {
34
+
35
+    /**
36
+     * Creates a new client info object for the specified channel and client.
37
+     *
38
+     * @param channel The channel the association is with
39
+     * @param client The user that holds the association
40
+     */
41
+    public MSNChannelClientInfo(final ChannelInfo channel,
42
+            final ClientInfo client) {
43
+        super(channel, client);
44
+    }
45
+
46
+    /** {@inheritDoc} */
47
+    @Override
48
+    public String getImportantModePrefix() {
49
+        return "";
50
+    }
51
+
52
+    /** {@inheritDoc} */
53
+    @Override
54
+    public String getImportantMode() {
55
+        return "";
56
+    }
57
+
58
+    /** {@inheritDoc} */
59
+    @Override
60
+    public String getAllModes() {
61
+        return "";
62
+    }
63
+
64
+    /** {@inheritDoc} */
65
+    @Override
66
+    public void kick(final String message) {
67
+        //Ignore
68
+    }
69
+
70
+    /** {@inheritDoc} */
71
+    @Override
72
+    public int compareTo(final ChannelClientInfo o) {
73
+        return 0;
74
+    }
75
+
76
+}

+ 91
- 0
src/com/dmdirc/addons/parser_msn/MSNClientInfo.java View File

@@ -0,0 +1,91 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.AwayState;
26
+import com.dmdirc.parser.common.BaseClientInfo;
27
+
28
+import net.sf.jml.MsnUser;
29
+import net.sf.jml.MsnUserStatus;
30
+
31
+/**
32
+ * An MSN-specific client info object.
33
+ */
34
+public class MSNClientInfo extends BaseClientInfo {
35
+
36
+    /** MSN contact. */
37
+    private final MsnUser contact;
38
+
39
+    /**
40
+     * Creates a new client info object with the specified details.
41
+     *
42
+     * @param contact The contact this object represents
43
+     * @param parser The parser that owns this client info object
44
+     * @param nick The nickname of the user this object represents
45
+     * @param user The username of the user this object represents
46
+     * @param host The hostname of the user this object represents
47
+     */
48
+    public MSNClientInfo(final MsnUser contact, final MSNParser parser,
49
+            final String nick, final String user, final String host) {
50
+        super(parser, nick, user, host);
51
+
52
+        this.contact = contact;
53
+    }
54
+
55
+    /** {@inheritDoc} */
56
+    @Override
57
+    public int getChannelCount() {
58
+        return 0;
59
+    }
60
+
61
+    /** {@inheritDoc} */
62
+    @Override
63
+    public AwayState getAwayState() {
64
+        if (contact.getStatus() == MsnUserStatus.ONLINE) {
65
+            return AwayState.HERE;
66
+        }
67
+        return AwayState.AWAY;
68
+    }
69
+
70
+    /** {@inheritDoc} */
71
+    @Override
72
+    public MSNParser getParser() {
73
+        return (MSNParser) super.getParser();
74
+    }
75
+
76
+    /** {@inheritDoc} */
77
+    @Override
78
+    public String getRealname() {
79
+        return contact.getDisplayName();
80
+    }
81
+
82
+    /**
83
+     * Returns the contact for this client info object
84
+     *
85
+     * @return MSN contact for this client
86
+     */
87
+    public MsnUser getContact() {
88
+        return contact;
89
+    }
90
+
91
+}

+ 188
- 0
src/com/dmdirc/addons/parser_msn/MSNFakeChannel.java View File

@@ -0,0 +1,188 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.BaseChannelInfo;
26
+import com.dmdirc.parser.common.ChannelListModeItem;
27
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+import com.dmdirc.parser.interfaces.ClientInfo;
29
+import com.dmdirc.parser.interfaces.Parser;
30
+import com.dmdirc.parser.interfaces.callbacks.ChannelNamesListener;
31
+
32
+import java.util.Collection;
33
+import java.util.Collections;
34
+
35
+/**
36
+ * A 'fake' local channel used to display contact lists.
37
+ */
38
+public class MSNFakeChannel extends BaseChannelInfo {
39
+
40
+    /**
41
+     * Creates a new fake channel belonging to the specified parser and
42
+     * with the given name.
43
+     *
44
+     * @param parser The parser that owns this channel
45
+     * @param name The name of the channel
46
+     */
47
+    public MSNFakeChannel(final Parser parser, final String name) {
48
+        super(parser, name);
49
+    }
50
+
51
+    /** {@inheritDoc} */
52
+    @Override
53
+    public void setTopic(final String topic) {
54
+        //Ignore
55
+    }
56
+
57
+    /** {@inheritDoc} */
58
+    @Override
59
+    public String getTopic() {
60
+        return "";
61
+    }
62
+
63
+    /** {@inheritDoc} */
64
+    @Override
65
+    public long getTopicTime() {
66
+        return 0;
67
+    }
68
+
69
+    /** {@inheritDoc} */
70
+    @Override
71
+    public String getTopicSetter() {
72
+        return "";
73
+    }
74
+
75
+    /** {@inheritDoc} */
76
+    @Override
77
+    public String getModes() {
78
+        return "";
79
+    }
80
+
81
+    /** {@inheritDoc} */
82
+    @Override
83
+    public String getMode(final char mode) {
84
+        return "";
85
+    }
86
+
87
+    /** {@inheritDoc} */
88
+    @Override
89
+    public Collection<ChannelListModeItem> getListMode(final char mode) {
90
+        return Collections.<ChannelListModeItem>emptyList();
91
+    }
92
+
93
+    /** {@inheritDoc} */
94
+    @Override
95
+    public void part(final String reason) {
96
+        throw new UnsupportedOperationException("Not supported yet.");
97
+    }
98
+
99
+    /** {@inheritDoc} */
100
+    @Override
101
+    public void sendWho() {
102
+        //Ignore
103
+    }
104
+
105
+    /** {@inheritDoc} */
106
+    @Override
107
+    public void alterMode(final boolean add,
108
+            final Character mode, final String parameter) {
109
+        //Ignore
110
+    }
111
+
112
+    /** {@inheritDoc} */
113
+    @Override
114
+    public void flushModes() {
115
+        //Ignore
116
+    }
117
+
118
+    /** {@inheritDoc} */
119
+    @Override
120
+    public void requestListModes() {
121
+        //Ignore
122
+    }
123
+
124
+    /** {@inheritDoc} */
125
+    @Override
126
+    public ChannelClientInfo getChannelClient(final ClientInfo client) {
127
+        return getClient(client.getNickname());
128
+    }
129
+
130
+    /** {@inheritDoc} */
131
+    @Override
132
+    public ChannelClientInfo getChannelClient(final String client,
133
+            final boolean create) {
134
+        final String[] parts = getParser().parseHostmask(client);
135
+        if (create && getClient(parts[0]) == null) {
136
+            return new MSNChannelClientInfo(this, getParser().getClient(client));
137
+        }
138
+        return getClient(parts[0]);
139
+    }
140
+
141
+    /**
142
+     * Replaces the clients in this channel with a the new list of clients.
143
+     *
144
+     * @param clients client list
145
+     */
146
+    public void replaceContacts(final Collection<ClientInfo> clients) {
147
+        for (ChannelClientInfo client : getChannelClients()) {
148
+            removeClient(client.getClient().getNickname());
149
+        }
150
+        for (ClientInfo client : clients) {
151
+            addClient(client.getNickname(), new MSNChannelClientInfo(this,
152
+                    client));
153
+        }
154
+
155
+        getParser().getCallbackManager().getCallbackType(
156
+                ChannelNamesListener.class).call(this);
157
+    }
158
+
159
+    /**
160
+     * Adds the specified clients to this channel
161
+     *
162
+     * @param clients client list
163
+     */
164
+    public void addContacts(final Collection<ClientInfo> clients) {
165
+        for (ClientInfo client : clients) {
166
+            addClient(client.getNickname(), new MSNChannelClientInfo(this,
167
+                    client));
168
+        }
169
+
170
+        getParser().getCallbackManager().getCallbackType(
171
+                ChannelNamesListener.class).call(this);
172
+    }
173
+
174
+    /**
175
+     * Removes the specified clients from this channel
176
+     *
177
+     * @param clients client list
178
+     */
179
+    public void removeContacts(final Collection<ClientInfo> clients) {
180
+        for (ClientInfo client : clients) {
181
+            removeClient(client.getNickname());
182
+        }
183
+
184
+        getParser().getCallbackManager().getCallbackType(
185
+                ChannelNamesListener.class).call(this);
186
+    }
187
+
188
+}

+ 187
- 0
src/com/dmdirc/addons/parser_msn/MSNListener.java View File

@@ -0,0 +1,187 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.AwayState;
26
+import com.dmdirc.parser.common.ParserError;
27
+import com.dmdirc.parser.interfaces.ChannelInfo;
28
+import com.dmdirc.parser.interfaces.ClientInfo;
29
+import com.dmdirc.parser.interfaces.callbacks.ChannelSelfJoinListener;
30
+import com.dmdirc.parser.interfaces.callbacks.ConnectErrorListener;
31
+import com.dmdirc.parser.interfaces.callbacks.OtherAwayStateListener;
32
+import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
33
+import com.dmdirc.parser.interfaces.callbacks.ServerNoticeListener;
34
+import com.dmdirc.parser.interfaces.callbacks.ServerReadyListener;
35
+import com.dmdirc.parser.interfaces.callbacks.SocketCloseListener;
36
+
37
+import java.util.ArrayList;
38
+import java.util.Arrays;
39
+import java.util.Collection;
40
+import java.util.List;
41
+
42
+import net.sf.jml.MsnContact;
43
+import net.sf.jml.MsnList;
44
+import net.sf.jml.MsnMessenger;
45
+import net.sf.jml.MsnSwitchboard;
46
+import net.sf.jml.MsnUserStatus;
47
+import net.sf.jml.event.MsnAdapter;
48
+import net.sf.jml.message.MsnInstantMessage;
49
+import net.sf.jml.message.MsnSystemMessage;
50
+import net.sf.jml.message.MsnUnknownMessage;
51
+
52
+/**
53
+ * Listener object acting on events from the MSN connection.
54
+ */
55
+public class MSNListener extends MsnAdapter {
56
+
57
+    /** MSN Parser. */
58
+    private final MSNParser parser;
59
+    /** Switchboard ID. */
60
+    private final Object object = new Object();
61
+
62
+    /**
63
+     * Creates a new MSN listener.
64
+     *
65
+     * @param parser Parent parser
66
+     */
67
+    public MSNListener(final MSNParser parser) {
68
+        this.parser = parser;
69
+    }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public void contactAddCompleted(final MsnMessenger mm, final MsnContact mc,
74
+            final MsnList ml) {
75
+        parser.addClient(mc);
76
+        parser.addClients(parser.getFakeChannel(), Arrays.asList(
77
+                new ClientInfo[]{ parser.getClient(mc), }));
78
+    }
79
+
80
+    /** {@inheritDoc} */
81
+    @Override
82
+    public void contactListSyncCompleted(final MsnMessenger mm) {
83
+        final Collection<MsnContact> contacts = Arrays.asList(
84
+                mm.getContactList().getContacts());
85
+        final List<ClientInfo> clients = new ArrayList<ClientInfo>();
86
+        for (MsnContact contact : contacts) {
87
+            parser.addClient(contact);
88
+            clients.add(parser.getClient(contact));
89
+        }
90
+    }
91
+
92
+    /** {@inheritDoc} */
93
+    @Override
94
+    public void contactStatusChanged(final MsnMessenger mm,
95
+            final MsnContact mc) {
96
+        if (mc.getStatus() != MsnUserStatus.OFFLINE) {
97
+            parser.addClients(parser.getFakeChannel(), Arrays.asList(
98
+                    new ClientInfo[]{ parser.getClient(mc), }));
99
+        } else if (mc.getStatus() == MsnUserStatus.OFFLINE) {
100
+            parser.removeClients(parser.getFakeChannel(), Arrays.asList(
101
+                    new ClientInfo[]{ parser.getClient(mc), }));
102
+        }
103
+        final boolean isBack = mc.getStatus().equals(MsnUserStatus.ONLINE);
104
+        parser.getCallbackManager().getCallbackType(
105
+                OtherAwayStateListener.class).call(parser.getClient(mc),
106
+                isBack ? AwayState.AWAY : AwayState.HERE,
107
+                isBack ? AwayState.HERE : AwayState.AWAY);
108
+    }
109
+
110
+    /** {@inheritDoc} */
111
+    @Override
112
+    public void exceptionCaught(final MsnMessenger mm, final Throwable thrwbl) {
113
+        final ParserError error = new ParserError(ParserError.ERROR_ERROR,
114
+                thrwbl.getMessage(), "");
115
+        error.setException(new Exception(thrwbl)); //NOPMD
116
+        parser.getCallbackManager().getCallbackType(ConnectErrorListener.class)
117
+                .call(error);
118
+    }
119
+
120
+    /** {@inheritDoc} */
121
+    @Override
122
+    public void instantMessageReceived(final MsnSwitchboard ms,
123
+            final MsnInstantMessage mim, final MsnContact mc) {
124
+        parser.getCallbackManager().getCallbackType(
125
+                PrivateMessageListener.class).call(mim.getContent(),
126
+                mc.getEmail().getEmailAddress());
127
+    }
128
+
129
+    /** {@inheritDoc} */
130
+    @Override
131
+    public void loginCompleted(final MsnMessenger mm) {
132
+        mm.newSwitchboard(object);
133
+        parser.getCallbackManager().getCallbackType(ServerReadyListener.class)
134
+                .call();
135
+        final ChannelInfo channel = parser.getFakeChannel();
136
+        if (channel != null) {
137
+            parser.getCallbackManager().getCallbackType(
138
+                    ChannelSelfJoinListener.class).call(channel);
139
+        }
140
+    }
141
+
142
+    /** {@inheritDoc} */
143
+    @Override
144
+    public void logout(final MsnMessenger mm) {
145
+        parser.getCallbackManager().getCallbackType(SocketCloseListener.class)
146
+                .call();
147
+    }
148
+
149
+    /** {@inheritDoc} */
150
+    @Override
151
+    public void offlineMessageReceived(final String body,
152
+            final String contentType, final String encoding,
153
+            final MsnContact mc) {
154
+        parser.getCallbackManager().getCallbackType(
155
+                PrivateMessageListener.class).call(body,
156
+                mc.getEmail().getEmailAddress());
157
+    }
158
+
159
+    /** {@inheritDoc} */
160
+    @Override
161
+    public void ownerStatusChanged(final MsnMessenger mm) {
162
+        if (mm.getOwner().getStatus() == MsnUserStatus.ONLINE) {
163
+            parser.getLocalClient().setBack();
164
+        }
165
+        parser.getLocalClient().setAway(mm.getOwner().getStatus()
166
+                .getDisplayStatus());
167
+    }
168
+
169
+    /** {@inheritDoc} */
170
+    @Override
171
+    public void systemMessageReceived(final MsnMessenger mm,
172
+            final MsnSystemMessage msm) {
173
+        if (msm.getContent() != null) {
174
+            parser.getCallbackManager().getCallbackType(
175
+                    ServerNoticeListener.class).call(msm.getContent(), "MSN");
176
+        }
177
+    }
178
+
179
+    /** {@inheritDoc} */
180
+    @Override
181
+    public void unknownMessageReceived(final MsnSwitchboard ms,
182
+            final MsnUnknownMessage mum, final MsnContact mc) {
183
+        parser.getCallbackManager().getCallbackType(
184
+                ServerNoticeListener.class).call("Unknown message: "
185
+                + mum.getContent(), "MSN");
186
+    }
187
+}

+ 100
- 0
src/com/dmdirc/addons/parser_msn/MSNLocalClientInfo.java View File

@@ -0,0 +1,100 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.AwayState;
26
+import com.dmdirc.parser.interfaces.LocalClientInfo;
27
+import com.dmdirc.parser.interfaces.callbacks.AwayStateListener;
28
+
29
+import net.sf.jml.MsnOwner;
30
+import net.sf.jml.MsnUserStatus;
31
+
32
+/**
33
+ * A representation of the local MSN client.
34
+ */
35
+public class MSNLocalClientInfo extends MSNClientInfo implements LocalClientInfo {
36
+
37
+    /** MSN user. */
38
+    private final MsnOwner owner;
39
+
40
+    /**
41
+     * Creates a new local client info object with the specified details.
42
+     *
43
+     * @param owner The client this object represents
44
+     * @param parser The parser that owns this client info object
45
+     * @param nick The nickname of the user this object represents
46
+     * @param user The username of the user this object represents
47
+     * @param host The hostname of the user this object represents
48
+     */
49
+    public MSNLocalClientInfo(final MsnOwner owner, final MSNParser parser,
50
+            final String nick, final String user, final String host) {
51
+        super(owner, parser, nick, user, host);
52
+
53
+        this.owner = owner;
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public void setNickname(final String name) {
59
+        owner.setDisplayName(name);
60
+    }
61
+
62
+    /** {@inheritDoc} */
63
+    @Override
64
+    public String getModes() {
65
+        return "";
66
+    }
67
+
68
+    /** {@inheritDoc} */
69
+    @Override
70
+    public void setAway(final String reason) {
71
+        owner.setStatus(MsnUserStatus.AWAY);
72
+
73
+        getParser().getCallbackManager().getCallbackType(
74
+                AwayStateListener.class).call(AwayState.HERE, AwayState.AWAY,
75
+                reason);
76
+    }
77
+
78
+    /** {@inheritDoc} */
79
+    @Override
80
+    public void setBack() {
81
+        owner.setStatus(MsnUserStatus.ONLINE);
82
+
83
+        getParser().getCallbackManager().getCallbackType(
84
+                AwayStateListener.class).call(AwayState.AWAY, AwayState.HERE,
85
+                null);
86
+    }
87
+
88
+    /** {@inheritDoc} */
89
+    @Override
90
+    public void alterMode(final boolean add, final Character mode) {
91
+        //Ignore
92
+    }
93
+
94
+    /** {@inheritDoc} */
95
+    @Override
96
+    public void flushModes() {
97
+        //Ignore
98
+    }
99
+
100
+}

+ 442
- 0
src/com/dmdirc/addons/parser_msn/MSNParser.java View File

@@ -0,0 +1,442 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.BaseParser;
26
+import com.dmdirc.parser.common.ChannelJoinRequest;
27
+import com.dmdirc.parser.common.DefaultStringConverter;
28
+import com.dmdirc.parser.common.QueuePriority;
29
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
30
+import com.dmdirc.parser.interfaces.ChannelInfo;
31
+import com.dmdirc.parser.interfaces.ClientInfo;
32
+import com.dmdirc.parser.interfaces.LocalClientInfo;
33
+import com.dmdirc.parser.interfaces.StringConverter;
34
+
35
+import java.net.URI;
36
+import java.util.Collection;
37
+import java.util.Collections;
38
+import java.util.HashMap;
39
+import java.util.List;
40
+import java.util.Map;
41
+
42
+import net.sf.jml.MsnContact;
43
+import net.sf.jml.MsnMessenger;
44
+import net.sf.jml.impl.MsnMessengerFactory;
45
+
46
+/**
47
+ * A parser which can understand the MSN protocol.
48
+ */
49
+public class MSNParser extends BaseParser {
50
+
51
+    /** A map of this parser's implementations of common interfaces. */
52
+    private static final Map<Class<?>, Class<?>> IMPL_MAP
53
+            = new HashMap<Class<?>, Class<?>>();
54
+    /** MSN Connection. */
55
+    private MsnMessenger msn;
56
+    /** A cache of known clients. */
57
+    private final Map<String, MSNClientInfo> clients
58
+            = new HashMap<String, MSNClientInfo>();
59
+    /** Whether or not to use a channel for contact lists. */
60
+    private final boolean useFakeChannel;
61
+    /** The fake channel to use is useFakeChannel is enabled. */
62
+    private MSNFakeChannel fakeChannel;
63
+
64
+    /** Creates map of this parser's implementations of common interfaces. */
65
+    static {
66
+        IMPL_MAP.put(ClientInfo.class, MSNClientInfo.class);
67
+        IMPL_MAP.put(LocalClientInfo.class, MSNLocalClientInfo.class);
68
+        IMPL_MAP.put(ChannelInfo.class, MSNFakeChannel.class);
69
+        IMPL_MAP.put(ChannelClientInfo.class, MSNChannelClientInfo.class);
70
+    }
71
+
72
+    /**
73
+     * Creates a new parser for the specified address.
74
+     *
75
+     * @param address The address to connect to
76
+     */
77
+    public MSNParser(final URI address) {
78
+        super(address, IMPL_MAP);
79
+
80
+        useFakeChannel = address.getQuery().matches(
81
+                "(?i).*(^|&)showchannel($|&).*");
82
+    }
83
+
84
+    /** {@inheritDoc} */
85
+    @Override
86
+    public void disconnect(final String message) {
87
+        msn.logout();
88
+    }
89
+
90
+    /** {@inheritDoc} */
91
+    @Override
92
+    public void joinChannels(final ChannelJoinRequest... channels) {
93
+        //Ignore
94
+    }
95
+
96
+    /** {@inheritDoc} */
97
+    @Override
98
+    public ChannelInfo getChannel(final String channel) {
99
+        if ("&contacts".equalsIgnoreCase(channel)) {
100
+            return fakeChannel;
101
+        }
102
+        return null;
103
+    }
104
+
105
+    /** {@inheritDoc} */
106
+    @Override
107
+    public Collection<? extends ChannelInfo> getChannels() {
108
+        return Collections.<ChannelInfo>emptyList();
109
+    }
110
+
111
+    /** {@inheritDoc} */
112
+    @Override
113
+    public int getMaxLength(final String type, final String target) {
114
+        return -1;
115
+    }
116
+
117
+    /** {@inheritDoc} */
118
+    @Override
119
+    public int getMaxLength() {
120
+        return -1;
121
+    }
122
+
123
+    /** {@inheritDoc} */
124
+    @Override
125
+    public LocalClientInfo getLocalClient() {
126
+        final String[] parts = parseHostmask(msn.getOwner().getEmail()
127
+                .getEmailAddress());
128
+        return new MSNLocalClientInfo(msn.getOwner(), this, parts[0], parts[2],
129
+                parts[1]);
130
+    }
131
+
132
+    /** {@inheritDoc} */
133
+    @Override
134
+    public MSNClientInfo getClient(final String details) {
135
+        final String[] parts = parseHostmask(details);
136
+        return clients.get(parts[0]);
137
+    }
138
+
139
+    /**
140
+     * Retrieves a {@link ClientInfo} object which corresponds to the specified
141
+     * contact. If the client wasn't previously known, it will be created.
142
+     *
143
+     * @param contact The contact to look up
144
+     *
145
+     * @return A corresponding client info object
146
+     */
147
+    public MSNClientInfo getClient(final MsnContact contact) {
148
+        return getClient(contact.getEmail().getEmailAddress());
149
+    }
150
+
151
+    /** {@inheritDoc} */
152
+    @Override
153
+    public void sendRawMessage(final String message) {
154
+        //Ignore
155
+    }
156
+
157
+    /** {@inheritDoc} */
158
+    @Override
159
+    public void sendRawMessage(final String message,
160
+            final QueuePriority priority) {
161
+        //Ignore
162
+    }
163
+
164
+    /** {@inheritDoc} */
165
+    @Override
166
+    public StringConverter getStringConverter() {
167
+        return new DefaultStringConverter();
168
+    }
169
+
170
+    /** {@inheritDoc} */
171
+    @Override
172
+    public boolean isValidChannelName(final String name) {
173
+        return false;
174
+    }
175
+
176
+    /** {@inheritDoc} */
177
+    @Override
178
+    public boolean compareURI(final URI uri) {
179
+        throw new UnsupportedOperationException("Not supported yet.");
180
+    }
181
+
182
+    /** {@inheritDoc} */
183
+    @Override
184
+    public Collection<? extends ChannelJoinRequest> extractChannels(
185
+            final URI uri) {
186
+        return Collections.<ChannelJoinRequest>emptyList();
187
+    }
188
+
189
+    /** {@inheritDoc} */
190
+    @Override
191
+    public String getServerName() {
192
+        return "MSN";
193
+    }
194
+
195
+    /** {@inheritDoc} */
196
+    @Override
197
+    public String getNetworkName() {
198
+        return "MSN";
199
+    }
200
+
201
+    /** {@inheritDoc} */
202
+    @Override
203
+    public String getServerSoftware() {
204
+        return "MSN";
205
+    }
206
+
207
+    /** {@inheritDoc} */
208
+    @Override
209
+    public String getServerSoftwareType() {
210
+        return "MSN";
211
+    }
212
+
213
+    /** {@inheritDoc} */
214
+    @Override
215
+    public List<String> getServerInformationLines() {
216
+        return Collections.<String>emptyList();
217
+    }
218
+
219
+    /** {@inheritDoc} */
220
+    @Override
221
+    public int getMaxTopicLength() {
222
+        return 0;
223
+    }
224
+
225
+    /** {@inheritDoc} */
226
+    @Override
227
+    public String getBooleanChannelModes() {
228
+        return "";
229
+    }
230
+
231
+    /** {@inheritDoc} */
232
+    @Override
233
+    public String getListChannelModes() {
234
+        return "";
235
+    }
236
+
237
+    /** {@inheritDoc} */
238
+    @Override
239
+    public int getMaxListModes(final char mode) {
240
+        return 0;
241
+    }
242
+
243
+    /** {@inheritDoc} */
244
+    @Override
245
+    public boolean isUserSettable(final char mode) {
246
+        return false;
247
+    }
248
+
249
+    /** {@inheritDoc} */
250
+    @Override
251
+    public String getParameterChannelModes() {
252
+        return "";
253
+    }
254
+
255
+    /** {@inheritDoc} */
256
+    @Override
257
+    public String getDoubleParameterChannelModes() {
258
+        return "";
259
+    }
260
+
261
+    /** {@inheritDoc} */
262
+    @Override
263
+    public String getUserModes() {
264
+        return "";
265
+    }
266
+
267
+    /** {@inheritDoc} */
268
+    @Override
269
+    public String getChannelUserModes() {
270
+        return "";
271
+    }
272
+
273
+    /** {@inheritDoc} */
274
+    @Override
275
+    public String getChannelPrefixes() {
276
+        return "#";
277
+    }
278
+
279
+    /** {@inheritDoc} */
280
+    @Override
281
+    public long getServerLatency() {
282
+        return 0;
283
+    }
284
+
285
+    /** {@inheritDoc} */
286
+    @Override
287
+    public void sendCTCP(final String target, final String type,
288
+            final String message) {
289
+        throw new UnsupportedOperationException("Not supported yet.");
290
+    }
291
+
292
+    /** {@inheritDoc} */
293
+    @Override
294
+    public void sendCTCPReply(final String target, final String type,
295
+            final String message) {
296
+        throw new UnsupportedOperationException("Not supported yet.");
297
+    }
298
+
299
+    /** {@inheritDoc} */
300
+    @Override
301
+    public void sendMessage(final String target, final String message) {
302
+        msn.sendText(getClient(target).getContact().getEmail(), message);
303
+
304
+    }
305
+
306
+    /** {@inheritDoc} */
307
+    @Override
308
+    public void sendNotice(final String target, final String message) {
309
+        throw new UnsupportedOperationException("Not supported yet.");
310
+    }
311
+
312
+    /** {@inheritDoc} */
313
+    @Override
314
+    public void sendAction(final String target, final String message) {
315
+        throw new UnsupportedOperationException("Not supported yet.");
316
+    }
317
+
318
+    /** {@inheritDoc} */
319
+    @Override
320
+    public void sendInvite(final String channel, final String user) {
321
+        throw new UnsupportedOperationException("Not supported yet.");
322
+    }
323
+
324
+    /** {@inheritDoc} */
325
+    @Override
326
+    public String getLastLine() {
327
+        return "";
328
+    }
329
+
330
+    /** {@inheritDoc} */
331
+    @Override
332
+    public String[] parseHostmask(final String hostmask) {
333
+        return new MSNProtocolDescription().parseHostmask(hostmask);
334
+    }
335
+
336
+    /** {@inheritDoc} */
337
+    @Override
338
+    public long getPingTime() {
339
+        return 0;
340
+    }
341
+
342
+    /** {@inheritDoc} */
343
+    @Override
344
+    public void run() {
345
+        final String[] userInfoParts = getURI().getUserInfo().split(":", 2);
346
+        msn = MsnMessengerFactory.createMsnMessenger(
347
+                userInfoParts[0], userInfoParts[1]);
348
+        msn.addListener(new MSNListener(this));
349
+        msn.login();
350
+        if (useFakeChannel) {
351
+            fakeChannel = new MSNFakeChannel(this, "&contacts");
352
+        }
353
+    }
354
+
355
+    /**
356
+     * Updates the clients in the specified channel.
357
+     *
358
+     * @param channel Channel to update
359
+     * @param clients Clients to use in the channel
360
+     */
361
+    public void updateClients(final ChannelInfo channel,
362
+            final Collection<ClientInfo> clients) {
363
+        if (channel == fakeChannel) {
364
+            fakeChannel.replaceContacts(clients);
365
+        }
366
+    }
367
+
368
+    /**
369
+     * Adds the clients in the specified channel.
370
+     *
371
+     * @param channel Channel to update
372
+     * @param clients Clients to add in the channel
373
+     */
374
+    public void addClients(final ChannelInfo channel,
375
+            final Collection<ClientInfo> clients) {
376
+        if (channel == fakeChannel) {
377
+            fakeChannel.addContacts(clients);
378
+        }
379
+    }
380
+
381
+    /**
382
+     * Removes the clients in the specified channel.
383
+     *
384
+     * @param channel Channel to update
385
+     * @param clients Clients to add in the channel
386
+     */
387
+    public void removeClients(final ChannelInfo channel,
388
+            final Collection<ClientInfo> clients) {
389
+        if (channel == fakeChannel) {
390
+            fakeChannel.removeContacts(clients);
391
+        }
392
+    }
393
+
394
+    /**
395
+     * Returns the fake channel for this parser, this will be null if the
396
+     * user has opted not to use the fake channel.
397
+     *
398
+     * @return Fake channel or null
399
+     */
400
+    public ChannelInfo getFakeChannel() {
401
+        return fakeChannel;
402
+    }
403
+
404
+    /** {@inheritDoc} */
405
+    @Override
406
+    public String getBindIP() {
407
+        return msn.getConnection().getInternalIP();
408
+    }
409
+
410
+    /** {@inheritDoc} */
411
+    @Override
412
+    public void setBindIP(final String ip) {
413
+        //Ignore
414
+    }
415
+
416
+    /** {@inheritDoc} */
417
+    @Override
418
+    public int getLocalPort() {
419
+        return msn.getConnection().getInternalPort();
420
+    }
421
+
422
+    /**
423
+     * Adds a contact to the list of known clients.
424
+     *
425
+     * @param contact Contact to add
426
+     */
427
+    public void addClient(final MsnContact contact) {
428
+        final String email = contact.getEmail().getEmailAddress();
429
+        final String[] parts = parseHostmask(email);
430
+        clients.put(email, new MSNClientInfo(contact, this, parts[0], parts[1],
431
+                parts[2]));
432
+    }
433
+
434
+    /**
435
+     * Removes a contact from the list of known clients.
436
+     *
437
+     * @param contact Contact to remove
438
+     */
439
+    public void removeClient(final MsnContact contact) {
440
+        clients.remove(contact.getEmail().getEmailAddress());
441
+    }
442
+}

+ 73
- 0
src/com/dmdirc/addons/parser_msn/MSNPlugin.java View File

@@ -0,0 +1,73 @@
1
+/*
2
+ * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.common.MyInfo;
26
+import com.dmdirc.parser.interfaces.Parser;
27
+import com.dmdirc.parser.interfaces.ProtocolDescription;
28
+import com.dmdirc.plugins.BasePlugin;
29
+
30
+import java.net.URI;
31
+
32
+/**
33
+ * Plugin that provides a parser to connect to MSN services.
34
+ */
35
+public class MSNPlugin extends BasePlugin {
36
+
37
+    /** Protocol descriptor. */
38
+    private final MSNProtocolDescription protocol
39
+            = new MSNProtocolDescription();
40
+
41
+    /** {@inheritDoc} */
42
+    @Override
43
+    public void onLoad() {
44
+        // Do nothing
45
+    }
46
+
47
+    /** {@inheritDoc} */
48
+    @Override
49
+    public void onUnload() {
50
+        // Do nothing
51
+    }
52
+
53
+    /**
54
+     * Creates a new MSN parser for the specified client info and address.
55
+     *
56
+     * @param myInfo The settings for the local client
57
+     * @param address The address to connect to
58
+     *
59
+     * @return An appropriately configured parser
60
+     */
61
+    public Parser getParser(final MyInfo myInfo, final URI address) {
62
+        return new MSNParser(address);
63
+    }
64
+
65
+    /**
66
+     * Retrieves an object describing the properties of the MSN  protocol.
67
+     *
68
+     * @return A relevant protocol description object
69
+     */
70
+    public ProtocolDescription getDescription() {
71
+        return protocol;
72
+    }
73
+}

+ 44
- 0
src/com/dmdirc/addons/parser_msn/MSNProtocolDescription.java View File

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.parser_msn;
24
+
25
+import com.dmdirc.parser.interfaces.ProtocolDescription;
26
+
27
+/**
28
+ * A description of the MSN protocol.
29
+ */
30
+class MSNProtocolDescription implements ProtocolDescription {
31
+
32
+    /** {@inheritDoc} */
33
+    @Override
34
+    public int getDefaultPort() {
35
+        return 1863;
36
+    }
37
+
38
+    /** {@inheritDoc} */
39
+    @Override
40
+    public String[] parseHostmask(final String hostmask) {
41
+        return new String[] { hostmask, hostmask, hostmask, };
42
+    }
43
+
44
+}

+ 34
- 0
src/com/dmdirc/addons/parser_msn/plugin.config View File

@@ -0,0 +1,34 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+  version
10
+  defaults
11
+  icons
12
+
13
+metadata:
14
+  author=Greg <greg@dmdirc.com>
15
+  mainclass=com.dmdirc.addons.parser_msn.MSNPlugin
16
+  description=Provides MSN access for DMDirc.
17
+  name=msn
18
+  nicename=MSN Plugin
19
+
20
+updates:
21
+  id=68
22
+
23
+version:
24
+  number=1
25
+  friendly=0.1
26
+
27
+provides:
28
+  msn parser
29
+  msns parser
30
+
31
+
32
+exports:
33
+  getParser in com.dmdirc.addons.parser_msn.MSNPlugin as getParser
34
+  getDescription in com.dmdirc.addons.parser_msn.MSNPlugin as getProtocolDescription

Loading…
Cancel
Save