Request.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_REQUEST_H_
  36. #define _D_REQUEST_H_
  37. #include "common.h"
  38. #include "SharedHandle.h"
  39. #include <string>
  40. #include <deque>
  41. #define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\
  42. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
  43. "0123456789"\
  44. ":/?[]@"\
  45. "!$&'()*+,;="\
  46. "-._~"\
  47. "%"\
  48. "#"
  49. namespace aria2 {
  50. class CookieBox;
  51. class Request {
  52. public:
  53. enum TRACKER_EVENT {
  54. AUTO,
  55. STARTED,
  56. STOPPED,
  57. COMPLETED,
  58. AFTER_COMPLETED
  59. };
  60. private:
  61. std::string url;
  62. std::string currentUrl;
  63. /**
  64. * URL previously requested to the server. This is used as Referer
  65. */
  66. std::string previousUrl;
  67. /**
  68. * URL used as Referer in the initial request
  69. */
  70. std::string referer;
  71. std::string protocol;
  72. std::string host;
  73. int32_t port;
  74. std::string dir;
  75. std::string file;
  76. int32_t tryCount;
  77. TRACKER_EVENT trackerEvent;
  78. bool keepAlive;
  79. std::string method;
  80. std::string _username;
  81. std::string _password;
  82. bool parseUrl(const std::string& url);
  83. bool isHexNumber(const char c) const;
  84. std::string urlencode(const std::string& src) const;
  85. public:
  86. SharedHandle<CookieBox> cookieBox;
  87. public:
  88. Request();
  89. virtual ~Request();
  90. // Parses URL and sets url, host, port, dir, file fields.
  91. // Returns true if parsing goes successful, otherwise returns false.
  92. bool setUrl(const std::string& url);
  93. // Parses URL and sets host, port, dir, file fields.
  94. // url field are not altered by this method.
  95. // Returns true if parsing goes successful, otherwise returns false.
  96. bool redirectUrl(const std::string& url);
  97. bool resetUrl();
  98. void resetTryCount() { tryCount = 0; }
  99. void addTryCount() { tryCount++; }
  100. int32_t getTryCount() const { return tryCount; }
  101. //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
  102. std::string getUrl() const { return url; }
  103. std::string getCurrentUrl() const { return currentUrl; }
  104. std::string getPreviousUrl() const { return previousUrl; }
  105. std::string getReferer() const { return referer; }
  106. void setReferer(const std::string& url) { referer = previousUrl = url; }
  107. std::string getProtocol() const { return protocol; }
  108. std::string getHost() const { return host; }
  109. int32_t getPort() const { return port; }
  110. std::string getDir() const { return dir; }
  111. std::string getFile() const { return file;}
  112. bool isKeepAlive() const { return keepAlive; }
  113. void setKeepAlive(bool keepAlive) { this->keepAlive = keepAlive; }
  114. void setTrackerEvent(TRACKER_EVENT event) { trackerEvent = event; }
  115. TRACKER_EVENT getTrackerEvent() const { return trackerEvent; }
  116. void setMethod(const std::string& method) {
  117. this->method = method;
  118. }
  119. const std::string& getUsername() const
  120. {
  121. return _username;
  122. }
  123. const std::string& getPassword() const
  124. {
  125. return _password;
  126. }
  127. const std::string& getMethod() const {
  128. return method;
  129. }
  130. static const std::string METHOD_GET;
  131. static const std::string METHOD_HEAD;
  132. };
  133. typedef SharedHandle<Request> RequestHandle;
  134. typedef WeakHandle<Request> RequestWeakHandle;
  135. typedef std::deque<RequestHandle> Requests;
  136. } // namespace aria2
  137. #endif // _D_REQUEST_H_