Request.h 4.7 KB

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