]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/ident/IdentWrapper.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / ident / IdentWrapper.java
1 /*****************************************************/
2 /*          This java file is a part of the          */
3 /*                                                   */
4 /*           -  Plouf's Java IRC Client  -           */
5 /*                                                   */
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */
7 /*                                                   */
8 /*         All contacts : theplouf@yahoo.com         */
9 /*                                                   */
10 /*  PJIRC is free software; you can redistribute     */
11 /*  it and/or modify it under the terms of the GNU   */
12 /*  General Public License as published by the       */
13 /*  Free Software Foundation; version 2 or later of  */
14 /*  the License.                                     */
15 /*                                                   */
16 /*  PJIRC is distributed in the hope that it will    */
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */
18 /*  even the implied warranty of MERCHANTABILITY or  */
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */
20 /*  General Public License for more details.         */
21 /*                                                   */
22 /*  You should have received a copy of the GNU       */
23 /*  General Public License along with PJIRC; if      */
24 /*  not, write to the Free Software Foundation,      */
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */
26 /*  MA  02111-1307  USA                              */
27 /*                                                   */
28 /*****************************************************/
29
30 package irc.ident;
31
32 import irc.IRCConfiguration;
33 import irc.IRCObject;
34 import irc.ident.prv.IdentServer;
35
36 /**
37  * Ident wrapper.
38  */
39 public class IdentWrapper extends IRCObject {
40         private IdentServer _ident;
41         private IdentListener _lis;
42
43         /**
44          * Create a new IdentWrapper.
45          * 
46          * @param config
47          *          the global configuration.
48          */
49         public IdentWrapper(IRCConfiguration config) {
50                 super(config);
51         }
52
53         /**
54          * Start the execution of the ident server, using default configuration.
55          * 
56          * @param userName
57          *          ident user name.
58          * @param lis
59          *          the listener to use.
60          * @return any occured exception if failed, or null if everything went well.
61          */
62         public Exception start(String userName, IdentListener lis) {
63                 _lis = lis;
64                 _ident = new IdentServer(_ircConfiguration);
65                 _ident.addIdentListener(lis);
66                 String name = _ircConfiguration.getS("userid");
67                 if (name.length() == 0)
68                         name = userName;
69                 _ident.setDefaultUser("JAVA", name);
70                 try {
71                         int port = 113;
72                         _ident.start(port);
73                         return null;
74                 } catch (Exception e) {
75                         return e;
76                 }
77         }
78
79         /**
80          * Stop the execution of the ident server.
81          */
82         public void stop() {
83                 _ident.removeIdentListener(_lis);
84                 _ident.stop();
85                 _lis = null;
86         }
87 }