Request.h 4.3 KB

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