FtpNegotiationCommand.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 FtpNegotiationCommand : public AbstractCommand {
  42. public:
  43. enum Seq {
  44. SEQ_RECV_GREETING,
  45. SEQ_SEND_USER,
  46. SEQ_RECV_USER,
  47. SEQ_SEND_PASS,
  48. SEQ_RECV_PASS,
  49. SEQ_SEND_TYPE,
  50. SEQ_RECV_TYPE,
  51. SEQ_SEND_PWD,
  52. SEQ_RECV_PWD,
  53. SEQ_SEND_CWD,
  54. SEQ_RECV_CWD,
  55. SEQ_SEND_MDTM,
  56. SEQ_RECV_MDTM,
  57. SEQ_SEND_SIZE,
  58. SEQ_RECV_SIZE,
  59. SEQ_PREPARE_SERVER_SOCKET,
  60. SEQ_SEND_PORT,
  61. SEQ_RECV_PORT,
  62. SEQ_SEND_PASV,
  63. SEQ_RECV_PASV,
  64. SEQ_SEND_REST_PASV,
  65. SEQ_SEND_REST,
  66. SEQ_RECV_REST,
  67. SEQ_SEND_RETR,
  68. SEQ_RECV_RETR,
  69. SEQ_WAIT_CONNECTION,
  70. SEQ_NEGOTIATION_COMPLETED,
  71. SEQ_RETRY,
  72. SEQ_HEAD_OK,
  73. SEQ_DOWNLOAD_ALREADY_COMPLETED,
  74. SEQ_FILE_PREPARATION, // File allocation after SIZE command
  75. };
  76. private:
  77. bool recvGreeting();
  78. bool sendUser();
  79. bool recvUser();
  80. bool sendPass();
  81. bool recvPass();
  82. bool sendType();
  83. bool recvType();
  84. bool sendPwd();
  85. bool recvPwd();
  86. bool sendCwd();
  87. bool recvCwd();
  88. bool sendMdtm();
  89. bool recvMdtm();
  90. bool sendSize();
  91. bool recvSize();
  92. bool prepareServerSocket();
  93. bool sendPort();
  94. bool recvPort();
  95. bool sendPasv();
  96. bool recvPasv();
  97. bool sendRest(const SharedHandle<Segment>& segment);
  98. bool sendRestPasv(const SharedHandle<Segment>& segment);
  99. bool recvRest(const SharedHandle<Segment>& segment);
  100. bool sendRetr();
  101. bool recvRetr();
  102. bool waitConnection();
  103. bool processSequence(const SharedHandle<Segment>& segment);
  104. void afterFileAllocation();
  105. void poolConnection() const;
  106. bool onFileSizeDetermined(uint64_t totalLength);
  107. SharedHandle<SocketCore> dataSocket;
  108. SharedHandle<SocketCore> serverSocket;
  109. Seq sequence;
  110. SharedHandle<FtpConnection> ftp;
  111. protected:
  112. virtual bool executeInternal();
  113. public:
  114. FtpNegotiationCommand(int32_t cuid,
  115. const SharedHandle<Request>& req,
  116. RequestGroup* requestGroup,
  117. DownloadEngine* e,
  118. const SharedHandle<SocketCore>& s,
  119. Seq seq = SEQ_RECV_GREETING,
  120. const std::string& baseWorkingDir = "/");
  121. virtual ~FtpNegotiationCommand();
  122. };
  123. } // namespace aria2
  124. #endif // _D_FTP_NEGOTIATION_COMMAND_H_