001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.shared.asn1.ber; 021 022 023 import org.apache.directory.shared.asn1.ber.grammar.IGrammar; 024 import org.apache.directory.shared.asn1.ber.grammar.IStates; 025 import org.apache.directory.shared.asn1.ber.tlv.TLV; 026 027 028 /** 029 * Every ASN1 container must implement this interface. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 * @version $Rev: 725712 $, $Date: 2008-12-11 16:32:04 +0100 (Thu, 11 Dec 2008) $ 033 */ 034 public interface IAsn1Container 035 { 036 // ~ Methods 037 // ------------------------------------------------------------------------------------ 038 039 // State accessors 040 /** 041 * Get the current grammar state 042 * 043 * @return Returns the current grammar state 044 */ 045 int getState(); 046 047 048 /** 049 * Set the new current state 050 * 051 * @param state The new state 052 */ 053 void setState( int state ); 054 055 056 /** 057 * Set the current TLV 058 * 059 * @param tlv The current TLV 060 */ 061 void setCurrentTLV( TLV tlv ); 062 063 064 /** 065 * Get the currentTLV 066 * 067 * @return Returns the current TLV being decoded 068 */ 069 TLV getCurrentTLV(); 070 071 072 /** 073 * Get the grammar 074 * 075 * @return Returns the grammar used to decode a LdapMessage. 076 */ 077 IGrammar getGrammar(); 078 079 080 /** 081 * Get the transition 082 * 083 * @return Returns the transition from the previous state to the new state 084 */ 085 int getTransition(); 086 087 088 /** 089 * Update the transition from a state to another 090 * 091 * @param transition The transition to set 092 */ 093 void setTransition( int transition ); 094 095 /** 096 * @return Returns the states. 097 */ 098 IStates getStates(); 099 100 101 /** 102 * @return get the parent TLV. 103 */ 104 TLV getParentTLV(); 105 106 107 /** 108 * Set the parent TLV 109 * 110 * @param parentTLV The new parent TLV 111 */ 112 void setParentTLV( TLV parentTLV ); 113 114 115 /** 116 * Check that we can have a end state after this transition 117 * 118 * @return true if this can be the last transition 119 */ 120 boolean isGrammarEndAllowed(); 121 122 123 /** 124 * Set the flag to allow a end transition 125 * 126 * @param grammarEndAllowed true or false, depending on the next transition 127 * being an end or not. 128 */ 129 void grammarEndAllowed( boolean grammarEndAllowed ); 130 131 /** 132 * Get a new TLV id 133 * @return a unique value representing the current TLV id 134 */ 135 int getNewTlvId(); 136 137 /** 138 * Get the current TLV id 139 * @return a unique value representing the current TLV id 140 */ 141 int getTlvId(); 142 143 144 /** 145 * @return The number of decoded bytes for this message. This is used 146 * to control the PDU size and avoid PDU exceeding the maximum allowed 147 * size to break the server. 148 */ 149 int getDecodeBytes(); 150 151 152 /** 153 * Increment the decodedBytes by the latest received buffer's size. 154 * @param nb The buffer size. 155 */ 156 void incrementDecodeBytes( int nb ); 157 158 159 /** 160 * @return The maximum PDU size. 161 */ 162 int getMaxPDUSize(); 163 164 165 /** 166 * Set the maximum PDU size. 167 * @param maxPDUSize The maximum PDU size (if negative or null, will be 168 * replaced by the max integer value) 169 */ 170 void setMaxPDUSize( int maxPDUSize ); 171 }