1 /** 2 * Copyright (c) 2012, University of Konstanz, Distributed Systems Group All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 5 * following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of 6 * conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, 7 * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the 8 * distribution. * Neither the name of the University of Konstanz nor the names of its contributors may be used to 9 * endorse or promote products derived from this software without specific prior written permission. 10 * 11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 12 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 13 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 14 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 15 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 17 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 */ 19 package org.jscsi.initiator.connection.state; 20 21 22 import org.jscsi.exception.InternetSCSIException; 23 import org.jscsi.initiator.connection.Connection; 24 import org.jscsi.parser.ProtocolDataUnit; 25 import org.jscsi.parser.datasegment.DataSegmentFactory; 26 import org.jscsi.parser.datasegment.DataSegmentFactory.DataSegmentFormat; 27 import org.jscsi.parser.datasegment.IDataSegment; 28 import org.jscsi.parser.datasegment.OperationalTextKey; 29 import org.jscsi.parser.text.TextResponseParser; 30 31 32 /** 33 * <h1>GetConnectionsResponseState</h1> 34 * <p/> 35 * This state handles the response of a TextRequest PDU. So, there can be opened more connections to these targets 36 * listed in this response. 37 * 38 * @author Volker Wildi 39 */ 40 final class GetConnectionsResponseState extends AbstractState { 41 42 // -------------------------------------------------------------------------- 43 // -------------------------------------------------------------------------- 44 45 /** 46 * Constructor to create a <code>GetConnectionsResponseState</code> instance, which uses the given connection for 47 * transmission. 48 * 49 * @param initConnection The context connection, which is used for the network transmission. 50 */ 51 protected GetConnectionsResponseState (final Connection initConnection) { 52 53 super(initConnection); 54 } 55 56 // -------------------------------------------------------------------------- 57 // -------------------------------------------------------------------------- 58 59 /** {@inheritDoc} */ 60 public void execute () throws InternetSCSIException { 61 62 ProtocolDataUnit protocolDataUnit; 63 final IDataSegment textResponse = DataSegmentFactory.create(DataSegmentFormat.TEXT, connection.getSettingAsInt(OperationalTextKey.MAX_RECV_DATA_SEGMENT_LENGTH)); 64 65 do { 66 protocolDataUnit = connection.receive(); 67 68 if (!(protocolDataUnit.getBasicHeaderSegment().getParser() instanceof TextResponseParser)) { 69 break; 70 } 71 72 textResponse.append(protocolDataUnit.getDataSegment(), protocolDataUnit.getBasicHeaderSegment().getDataSegmentLength()); 73 } while (!protocolDataUnit.getBasicHeaderSegment().isFinalFlag()); 74 75 // extract Target Session Handle Identifying Handle 76 // final TextResponseParser parser = (TextResponseParser) 77 // protocolDataUnit.getBasicHeaderSegment().getParser(); 78 // final ByteBuffer textDataSegment = ByteBuffer 79 // .allocate(AbstractDataSegment.getTotalLength(textResponse.getLength())); 80 // textResponse.serialize(textDataSegment, 0); 81 // 82 // try { 83 // final String response = new String(textDataSegment.array(), "UTF-8"); 84 // final String[] lines = response.split("\0"); 85 // } catch (UnsupportedEncodingException e) { 86 // if (LOGGER.isErrorEnabled()) { 87 // LOGGER.error("Unsupported Encoding Exception: " + 88 // e.getLocalizedMessage()); 89 // } 90 // } 91 92 // return false; 93 } 94 95 // -------------------------------------------------------------------------- 96 // -------------------------------------------------------------------------- 97 98 // /** {@inheritDoc} */ 99 // @Override 100 // public final boolean isCorrect(final ProtocolDataUnit protocolDataUnit) 101 // throws InternetSCSIException { 102 // 103 // // FIXME: Reject must also be supported. 104 // return protocolDataUnit.getBasicHeaderSegment().getParser() instanceof 105 // TextResponseParser; 106 // } 107 108 // -------------------------------------------------------------------------- 109 // -------------------------------------------------------------------------- 110 // -------------------------------------------------------------------------- 111 // -------------------------------------------------------------------------- 112 113 }