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