1 18 19 package jcifs.smb; 20 21 import java.io.UnsupportedEncodingException ; 22 import java.util.Date ; 23 24 class Trans2FindFirst2Response extends SmbComTransactionResponse { 25 26 28 static final int SMB_INFO_STANDARD = 1; 29 static final int SMB_INFO_QUERY_EA_SIZE = 2; 30 static final int SMB_INFO_QUERY_EAS_FROM_LIST = 3; 31 static final int SMB_FIND_FILE_DIRECTORY_INFO = 0x101; 32 static final int SMB_FIND_FILE_FULL_DIRECTORY_INFO = 0x102; 33 static final int SMB_FILE_NAMES_INFO = 0x103; 34 static final int SMB_FILE_BOTH_DIRECTORY_INFO = 0x104; 35 36 class SmbFindFileBothDirectoryInfo implements FileEntry { 37 int nextEntryOffset; 38 int fileIndex; 39 long creationTime; 40 long lastAccessTime; 41 long lastWriteTime; 42 long changeTime; 43 long endOfFile; 44 long allocationSize; 45 int extFileAttributes; 46 int fileNameLength; 47 int eaSize; 48 int shortNameLength; 49 String shortName; 50 String filename; 51 52 public String getName() { 53 return filename; 54 } 55 public int getType() { 56 return SmbFile.TYPE_FILESYSTEM; 57 } 58 public int getAttributes() { 59 return extFileAttributes; 60 } 61 public long createTime() { 62 return creationTime; 63 } 64 public long lastModified() { 65 return lastWriteTime; 66 } 67 public long length() { 68 return endOfFile; 69 } 70 71 public String toString() { 72 return new String ( "SmbFindFileBothDirectoryInfo[" + 73 "nextEntryOffset=" + nextEntryOffset + 74 ",fileIndex=" + fileIndex + 75 ",creationTime=" + new Date ( creationTime ) + 76 ",lastAccessTime=" + new Date ( lastAccessTime ) + 77 ",lastWriteTime=" + new Date ( lastWriteTime ) + 78 ",changeTime=" + new Date ( changeTime ) + 79 ",endOfFile=" + endOfFile + 80 ",allocationSize=" + allocationSize + 81 ",extFileAttributes=" + extFileAttributes + 82 ",fileNameLength=" + fileNameLength + 83 ",eaSize=" + eaSize + 84 ",shortNameLength=" + shortNameLength + 85 ",shortName=" + shortName + 86 ",filename=" + filename + "]" ); 87 } 88 } 89 90 int sid; 91 boolean isEndOfSearch; 92 int eaErrorOffset; 93 int lastNameOffset, lastNameBufferIndex; 94 String lastName; 95 int resumeKey; 96 97 98 Trans2FindFirst2Response() { 99 command = SMB_COM_TRANSACTION2; 100 subCommand = SmbComTransaction.TRANS2_FIND_FIRST2; 101 } 102 103 String readString( byte[] src, int srcIndex, int len ) { 104 String str = null; 105 try { 106 if( useUnicode ) { 107 str = new String ( src, srcIndex, len, "UnicodeLittle" ); 109 } else { 110 111 116 117 122 123 if( len > 0 && src[srcIndex + len - 1] == '\0' ) { 124 len--; 125 } 126 str = new String ( src, srcIndex, len, ServerMessageBlock.OEM_ENCODING ); 127 } 128 } catch( UnsupportedEncodingException uee ) { 129 if( log.level > 1 ) 130 uee.printStackTrace( log ); 131 } 132 return str; 133 } 134 int writeSetupWireFormat( byte[] dst, int dstIndex ) { 135 return 0; 136 } 137 int writeParametersWireFormat( byte[] dst, int dstIndex ) { 138 return 0; 139 } 140 int writeDataWireFormat( byte[] dst, int dstIndex ) { 141 return 0; 142 } 143 int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) { 144 return 0; 145 } 146 int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) { 147 int start = bufferIndex; 148 149 if( subCommand == SmbComTransaction.TRANS2_FIND_FIRST2 ) { 150 sid = readInt2( buffer, bufferIndex ); 151 bufferIndex += 2; 152 } 153 numEntries = readInt2( buffer, bufferIndex ); 154 bufferIndex += 2; 155 isEndOfSearch = ( buffer[bufferIndex] & 0x01 ) == 0x01 ? true : false; 156 bufferIndex += 2; 157 eaErrorOffset = readInt2( buffer, bufferIndex ); 158 bufferIndex += 2; 159 lastNameOffset = readInt2( buffer, bufferIndex ); 160 bufferIndex += 2; 161 162 return bufferIndex - start; 163 } 164 int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) { 165 int start = bufferIndex; 166 SmbFindFileBothDirectoryInfo e; 167 168 lastNameBufferIndex = bufferIndex + lastNameOffset; 169 170 results = new SmbFindFileBothDirectoryInfo[numEntries]; 171 for( int i = 0; i < numEntries; i++ ) { 172 results[i] = e = new SmbFindFileBothDirectoryInfo(); 173 174 e.nextEntryOffset = readInt4( buffer, bufferIndex ); 175 e.fileIndex = readInt4( buffer, bufferIndex + 4 ); 176 e.creationTime = readTime( buffer, bufferIndex + 8 ); 177 e.lastWriteTime = readTime( buffer, bufferIndex + 24 ); 179 e.endOfFile = readInt8( buffer, bufferIndex + 40 ); 181 e.extFileAttributes = readInt4( buffer, bufferIndex + 56 ); 183 e.fileNameLength = readInt4( buffer, bufferIndex + 60 ); 184 187 189 190 e.filename = readString( buffer, bufferIndex + 94, e.fileNameLength ); 192 193 200 201 if( lastNameBufferIndex >= bufferIndex && ( e.nextEntryOffset == 0 || 202 lastNameBufferIndex < ( bufferIndex + e.nextEntryOffset ))) { 203 lastName = e.filename; 204 resumeKey = e.fileIndex; 205 } 206 207 bufferIndex += e.nextEntryOffset; 208 } 209 210 213 214 216 return dataCount; 217 } 218 public String toString() { 219 String c; 220 if( subCommand == SmbComTransaction.TRANS2_FIND_FIRST2 ) { 221 c = "Trans2FindFirst2Response["; 222 } else { 223 c = "Trans2FindNext2Response["; 224 } 225 return new String ( c + super.toString() + 226 ",sid=" + sid + 227 ",searchCount=" + numEntries + 228 ",isEndOfSearch=" + isEndOfSearch + 229 ",eaErrorOffset=" + eaErrorOffset + 230 ",lastNameOffset=" + lastNameOffset + 231 ",lastName=" + lastName + "]" ); 232 } 233 } 234 | Popular Tags |