File Source: Process004005.java
/*
P/P * Method: com.dmdirc.parser.irc.Process004005__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 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.parser.irc;
24
25 /**
26 * Process ISUPPORT lines.
27 */
28 public class Process004005 extends IRCProcessor {
29 /**
30 * Process ISUPPORT lines.
31 *
32 * @param sParam Type of line to process ("005", "004")
33 * @param token IRCTokenised line to process
34 */
35 @Override
36 public void process(final String sParam, final String[] token) {
/*
P/P * Method: void process(String, String[])
*
* Preconditions:
* sParam != null
* (soft) this.myParser.sNetworkName != null
* (soft) init'ed(this.myParser.stringConverter)
* (soft) this.myParser != null
* (soft) this.myParser...myCallbackManager != null
* (soft) this.myParser...myCallbackManager.callbackHash != null
* (soft) this.myParser.cMyself != null
* (soft) this.myParser.cMyself.sNickname != null
* (soft) this.myParser.h005Info != null
* (soft) this.myParser.hChanModesBool != null
* ...
*
* Presumptions:
* java.lang.Integer:parseInt(...)@96 <= 232-2
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == 0
* possibly_updated(this.myParser.nNextKeyCMBool)
* possibly_updated(this.myParser.nNextKeyPrefix)
* possibly_updated(this.myParser.nNextKeyUser)
* this.myParser.sNetworkName != null
* init'ed(this.myParser.stringConverter)
* init'ed(new IRCStringConverter(getIRCStringConverter#1) num objects)
* new IRCStringConverter(getIRCStringConverter#1) num objects == 0
* init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
* init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
* ...
*
* Test Vectors:
* token.length: {4}, {7..232-1}
* java.lang.String:equals(...)@37: {0}, {1}
* java.lang.String:equals(...)@39: {0}, {1}
* java.lang.String:equals(...)@52: {0}, {1}
* java.lang.String:equals(...)@62: {0}, {1}
* java.lang.String:equals(...)@65: {0}, {1}
* java.lang.String:equals(...)@83: {0}, {1}
* java.lang.String:equals(...)@85: {0}, {1}
* java.lang.String:equals(...)@87: {0}, {1}
* java.lang.String:equals(...)@89: {0}, {1}
* ...
*/
37 if (sParam.equals("003")) {
38 myParser.h005Info.put("003IRCD",token[token.length-1]);
39 } else if (sParam.equals("004")) {
40 // 004
41 if (token.length > 4) {
42 myParser.h005Info.put("004IRCD",token[4]);
43 myParser.h005Info.put("USERMODES",token[5]);
44 myParser.h005Info.put("USERCHANMODES",token[6]);
45 } else {
46 final String[] bits = token[3].split(" ");
47 myParser.h005Info.put("004IRCD",bits[1]);
48 myParser.h005Info.put("USERMODES",bits[2]);
49 myParser.h005Info.put("USERCHANMODES",bits[3]);
50 }
51 myParser.parseUserModes();
52 } else if (sParam.equals("005")) {
53 // 005
54 String[] Bits = null;
55 String sKey = null, sValue = null;
56 for (int i = 3; i < token.length ; i++) {
57 Bits = token[i].split("=",2);
58 sKey = Bits[0].toUpperCase();
59 if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
60 callDebugInfo(IRCParser.DEBUG_INFO, "%s => %s",sKey,sValue);
61 myParser.h005Info.put(sKey,sValue);
62 if (sKey.equals("NETWORK")) {
63 myParser.sNetworkName = sValue;
64 callGotNetwork();
65 } else if (sKey.equals("CASEMAPPING")) {
66 byte limit = (byte)4;
67 if (sValue.equalsIgnoreCase("strict-rfc1459")) {
68 limit = (byte)3;
69 } else if (sValue.equalsIgnoreCase("ascii")) {
70 limit = (byte)0;
71 } else if (!sValue.equalsIgnoreCase("rfc1459")) {
72 myParser.callErrorInfo(new ParserError(ParserError.ERROR_WARNING, "Unknown casemapping: '"+sValue+"' - assuming rfc1459", myParser.getLastLine()));
73 }
74 final boolean limitChanged = (myParser.getIRCStringConverter().getLimit() != limit);
75 myParser.updateCharArrays(limit);
76 if (limitChanged && myParser.knownClients() == 1) {
77 // This means that the casemapping is not rfc1459
78 // We have only added ourselves so far (from 001)
79 // We can fix the hashtable easily.
80 myParser.removeClient(myParser.getMyself());
81 myParser.addClient(myParser.getMyself());
82 }
83 } else if (sKey.equals("CHANTYPES")) {
84 myParser.parseChanPrefix();
85 } else if (sKey.equals("PREFIX")) {
86 myParser.parsePrefixModes();
87 } else if (sKey.equals("CHANMODES")) {
88 myParser.parseChanModes();
89 } else if (sKey.equals("LISTMODE")) {
90 // Support for potential future decent mode listing in the protocol
91 //
92 // See my proposal: http://shane.dmdirc.com/listmodes.php
93 // Add listmode handler
94 String[] handles = new String[2];
95 handles[0] = sValue; // List mode item
96 sValue = ""+(Integer.parseInt(sValue) + 1);
97 myParser.h005Info.put("LISTMODEEND", sValue);
98 handles[1] = sValue; // List mode end
99 // Add listmode handlers
100 try {
101 myParser.getProcessingManager().addProcessor(handles, myParser.getProcessingManager().getProcessor("__LISTMODE__"));
102 } catch (ProcessorNotFoundException e) { }
103 }
104 }
105 }
106 }
107
108 /**
109 * What does this IRCProcessor handle.
110 *
111 * @return String[] with the names of the tokens we handle.
112 */
113 @Override
114 public String[] handles() {
/*
P/P * Method: String[] handles()
*
* Postconditions:
* return_value == &new String[](handles#1)
* new String[](handles#1) num objects == 1
* return_value.length == 3
* return_value[0] == &"003"
* return_value[1] == &"004"
* return_value[2] == &"005"
*/
115 return new String[]{"003", "004", "005"};
116 }
117
118 /**
119 * Callback to all objects implementing the GotNetwork Callback.
120 * This takes no params of its own, but works them out itself.
121 *
122 * @see IGotNetwork
123 * @return true if a method was called, false otherwise
124 */
125 protected boolean callGotNetwork() {
/*
P/P * Method: bool callGotNetwork()
*
* Preconditions:
* this.myParser != null
* this.myParser.h005Info != null
* this.myParser.myCallbackManager != null
* this.myParser.myCallbackManager.callbackHash != null
* (soft) this.myParser.sNetworkName != null
*
* Presumptions:
* getCallbackManager(...)@130 init'ed
*
* Postconditions:
* init'ed(return_value)
*/
126 final String networkName = myParser.sNetworkName;
127 final String ircdVersion = myParser.getIRCD(false);
128 final String ircdType = myParser.getIRCD(true);
129
130 return getCallbackManager().getCallbackType("OnGotNetwork").call(networkName, ircdVersion, ircdType);
131 }
132
133 /**
134 * Create a new instance of the IRCProcessor Object.
135 *
136 * @param parser IRCParser That owns this IRCProcessor
137 * @param manager ProcessingManager that is in charge of this IRCProcessor
138 */
/*
P/P * Method: void com.dmdirc.parser.irc.Process004005(IRCParser, ProcessingManager)
*
* Postconditions:
* this.myManager == manager
* init'ed(this.myManager)
* this.myParser == parser
* init'ed(this.myParser)
*/
139 protected Process004005 (final IRCParser parser, final ProcessingManager manager) { super(parser, manager); }
140
141 }
SofCheck Inspector Build Version : 2.17854
| Process004005.java |
2009-Jun-25 01:54:24 |
| Process004005.class |
2009-Sep-02 17:04:16 |