FtpNegotiationCommand.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef _D_FTP_NEGOTIATION_COMMAND_H_
  36. #define _D_FTP_NEGOTIATION_COMMAND_H_
  37. #include "AbstractCommand.h"
  38. namespace aria2 {
  39. class FtpConnection;
  40. class SocketCore;
  41. class HttpConnection;
  42. class FtpNegotiationCommand : public AbstractCommand {
  43. public:
  44. enum Seq {
  45. SEQ_RECV_GREETING,
  46. SEQ_SEND_USER,
  47. SEQ_RECV_USER,
  48. SEQ_SEND_PASS,
  49. SEQ_RECV_PASS,
  50. SEQ_SEND_TYPE,
  51. SEQ_RECV_TYPE,
  52. SEQ_SEND_PWD,
  53. SEQ_RECV_PWD,
  54. SEQ_SEND_CWD_PREP,
  55. SEQ_SEND_CWD,
  56. SEQ_RECV_CWD,
  57. SEQ_SEND_MDTM,
  58. SEQ_RECV_MDTM,
  59. SEQ_SEND_SIZE,
  60. SEQ_RECV_SIZE,
  61. SEQ_PREPARE_PORT,
  62. SEQ_PREPARE_SERVER_SOCKET_EPRT,
  63. SEQ_SEND_EPRT,
  64. SEQ_RECV_EPRT,
  65. SEQ_PREPARE_SERVER_SOCKET,
  66. SEQ_SEND_PORT,
  67. SEQ_RECV_PORT,
  68. SEQ_PREPARE_PASV,
  69. SEQ_SEND_EPSV,
  70. SEQ_RECV_EPSV,
  71. SEQ_SEND_PASV,
  72. SEQ_RECV_PASV,
  73. SEQ_RESOLVE_PROXY,
  74. SEQ_SEND_TUNNEL_REQUEST,
  75. SEQ_RECV_TUNNEL_RESPONSE,
  76. SEQ_SEND_REST_PASV,
  77. SEQ_SEND_REST,
  78. SEQ_RECV_REST,
  79. SEQ_SEND_RETR,
  80. SEQ_RECV_RETR,
  81. SEQ_WAIT_CONNECTION,
  82. SEQ_NEGOTIATION_COMPLETED,
  83. SEQ_RETRY,
  84. SEQ_HEAD_OK,
  85. SEQ_DOWNLOAD_ALREADY_COMPLETED,
  86. SEQ_FILE_PREPARATION, // File allocation after SIZE command
  87. SEQ_EXIT
  88. };
  89. private:
  90. bool recvGreeting();
  91. bool sendUser();
  92. bool recvUser();
  93. bool sendPass();
  94. bool recvPass();
  95. bool sendType();
  96. bool recvType();
  97. bool sendPwd();
  98. bool recvPwd();
  99. bool sendCwdPrep();
  100. bool sendCwd();
  101. bool recvCwd();
  102. bool sendMdtm();
  103. bool recvMdtm();
  104. bool sendSize();
  105. bool recvSize();
  106. bool preparePort();
  107. bool prepareServerSocketEprt();
  108. bool sendEprt();
  109. bool recvEprt();
  110. bool prepareServerSocket();
  111. bool sendPort();
  112. bool recvPort();
  113. bool preparePasv();
  114. bool sendEpsv();
  115. bool recvEpsv();
  116. bool sendPasv();
  117. bool recvPasv();
  118. bool preparePasvConnect();
  119. bool resolveProxy();
  120. bool sendTunnelRequest();
  121. bool recvTunnelResponse();
  122. bool sendRest(const SharedHandle<Segment>& segment);
  123. bool sendRestPasv(const SharedHandle<Segment>& segment);
  124. bool recvRest(const SharedHandle<Segment>& segment);
  125. bool sendRetr();
  126. bool recvRetr();
  127. bool waitConnection();
  128. bool processSequence(const SharedHandle<Segment>& segment);
  129. void afterFileAllocation();
  130. void poolConnection() const;
  131. bool onFileSizeDetermined(uint64_t totalLength);
  132. void onDryRunFileFound();
  133. SharedHandle<SocketCore> dataSocket_;
  134. SharedHandle<SocketCore> serverSocket_;
  135. Seq sequence_;
  136. SharedHandle<FtpConnection> ftp_;
  137. // For tunneling
  138. SharedHandle<HttpConnection> http_;
  139. // IP, Port pair in pasv response
  140. std::pair<std::string, uint16_t> dataConnAddr_;
  141. // Resolved address for proxy
  142. std::string proxyAddr_;
  143. std::deque<std::string> cwdDirs_;
  144. protected:
  145. virtual bool executeInternal();
  146. public:
  147. FtpNegotiationCommand(cuid_t cuid,
  148. const SharedHandle<Request>& req,
  149. const SharedHandle<FileEntry>& fileEntry,
  150. RequestGroup* requestGroup,
  151. DownloadEngine* e,
  152. const SharedHandle<SocketCore>& s,
  153. Seq seq = SEQ_RECV_GREETING,
  154. const std::string& baseWorkingDir = "/");
  155. virtual ~FtpNegotiationCommand();
  156. };
  157. } // namespace aria2
  158. #endif // _D_FTP_NEGOTIATION_COMMAND_H_