Trans2FindFirst2.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using SharpCifs.Util;
  18. namespace SharpCifs.Smb
  19. {
  20. internal class Trans2FindFirst2 : SmbComTransaction
  21. {
  22. private const int FlagsCloseAfterThisRequest = unchecked(0x01);
  23. private const int FlagsCloseIfEndReached = unchecked(0x02);
  24. private const int FlagsReturnResumeKeys = unchecked(0x04);
  25. private const int FlagsResumeFromPreviousEnd = unchecked(0x08);
  26. private const int FlagsFindWithBackupIntent = unchecked(0x10);
  27. private const int DefaultListSize = 65535;
  28. private const int DefaultListCount = 200;
  29. private int _searchAttributes;
  30. private int _flags;
  31. private int _informationLevel;
  32. private int _searchStorageType = 0;
  33. private string _wildcard;
  34. internal const int SmbInfoStandard = 1;
  35. internal const int SmbInfoQueryEaSize = 2;
  36. internal const int SmbInfoQueryEasFromList = 3;
  37. internal const int SmbFindFileDirectoryInfo = unchecked(0x101);
  38. internal const int SmbFindFileFullDirectoryInfo = unchecked(0x102);
  39. internal const int SmbFileNamesInfo = unchecked(0x103);
  40. internal const int SmbFileBothDirectoryInfo = unchecked(0x104);
  41. internal static readonly int ListSize = Config.GetInt("jcifs.smb.client.listSize"
  42. , DefaultListSize);
  43. internal static readonly int ListCount = Config.GetInt("jcifs.smb.client.listCount"
  44. , DefaultListCount);
  45. internal Trans2FindFirst2(string filename, string wildcard, int searchAttributes)
  46. {
  47. // flags
  48. // information levels
  49. if (filename.Equals("\\"))
  50. {
  51. Path = filename;
  52. }
  53. else
  54. {
  55. Path = filename + "\\";
  56. }
  57. this._wildcard = wildcard;
  58. this._searchAttributes = searchAttributes & unchecked(0x37);
  59. Command = SmbComTransaction2;
  60. SubCommand = Trans2FindFirst2;
  61. _flags = unchecked(0x00);
  62. _informationLevel = SmbFileBothDirectoryInfo;
  63. TotalDataCount = 0;
  64. MaxParameterCount = 10;
  65. MaxDataCount = ListSize;
  66. MaxSetupCount = 0;
  67. }
  68. internal override int WriteSetupWireFormat(byte[] dst, int dstIndex)
  69. {
  70. dst[dstIndex++] = SubCommand;
  71. dst[dstIndex++] = unchecked(unchecked(0x00));
  72. return 2;
  73. }
  74. internal override int WriteParametersWireFormat(byte[] dst, int dstIndex)
  75. {
  76. int start = dstIndex;
  77. WriteInt2(_searchAttributes, dst, dstIndex);
  78. dstIndex += 2;
  79. WriteInt2(ListCount, dst, dstIndex);
  80. dstIndex += 2;
  81. WriteInt2(_flags, dst, dstIndex);
  82. dstIndex += 2;
  83. WriteInt2(_informationLevel, dst, dstIndex);
  84. dstIndex += 2;
  85. WriteInt4(_searchStorageType, dst, dstIndex);
  86. dstIndex += 4;
  87. dstIndex += WriteString(Path + _wildcard, dst, dstIndex);
  88. return dstIndex - start;
  89. }
  90. internal override int WriteDataWireFormat(byte[] dst, int dstIndex)
  91. {
  92. return 0;
  93. }
  94. internal override int ReadSetupWireFormat(byte[] buffer, int bufferIndex, int len
  95. )
  96. {
  97. return 0;
  98. }
  99. internal override int ReadParametersWireFormat(byte[] buffer, int bufferIndex, int
  100. len)
  101. {
  102. return 0;
  103. }
  104. internal override int ReadDataWireFormat(byte[] buffer, int bufferIndex, int len)
  105. {
  106. return 0;
  107. }
  108. public override string ToString()
  109. {
  110. return "Trans2FindFirst2[" + base.ToString() + ",searchAttributes=0x"
  111. + Hexdump.ToHexString(_searchAttributes, 2) + ",searchCount=" + ListCount + ",flags=0x"
  112. + Hexdump.ToHexString(_flags, 2) + ",informationLevel=0x" + Hexdump.ToHexString(
  113. _informationLevel, 3) + ",searchStorageType=" + _searchStorageType + ",filename="
  114. + Path + "]";
  115. }
  116. }
  117. }