Request.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - a simple utility for downloading files faster
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* copyright --> */
  22. #ifndef _D_REQUEST_H_
  23. #define _D_REQUEST_H_
  24. #include <string>
  25. #include <map>
  26. #include <Segment.h>
  27. #include "CookieBox.h"
  28. #include "common.h"
  29. using namespace std;
  30. #define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\
  31. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\
  32. "0123456789"\
  33. ":/?[]@"\
  34. "!$&'()*+,;="\
  35. "-._~"\
  36. "%"\
  37. "#"
  38. #define METALINK_MARK "#!metalink3!"
  39. class Request {
  40. private:
  41. string url;
  42. string currentUrl;
  43. /**
  44. * URL previously requested to the server. This is used as Referer
  45. */
  46. string previousUrl;
  47. /**
  48. * URL used as Referer in the initial request
  49. */
  50. string referer;
  51. string protocol;
  52. string host;
  53. int port;
  54. string dir;
  55. string file;
  56. map<string, int> defaultPorts;
  57. int tryCount;
  58. int trackerEvent;
  59. bool parseUrl(const string& url);
  60. public:
  61. Segment seg;
  62. CookieBox* cookieBox;
  63. bool isTorrent;
  64. public:
  65. Request();
  66. virtual ~Request();
  67. // Parses URL and sets url, host, port, dir, file fields.
  68. // Returns true if parsing goes successful, otherwise returns false.
  69. bool setUrl(const string& url);
  70. // Parses URL and sets host, port, dir, file fields.
  71. // url field are not altered by this method.
  72. // Returns true if parsing goes successful, otherwise returns false.
  73. bool redirectUrl(const string& url);
  74. bool resetUrl();
  75. void resetTryCount() { tryCount = 0; }
  76. void addTryCount() { tryCount++; }
  77. int getTryCount() const { return tryCount; }
  78. //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
  79. string getUrl() const { return url; }
  80. string getCurrentUrl() const { return currentUrl; }
  81. string getPreviousUrl() const { return previousUrl; }
  82. string getReferer() const { return referer; }
  83. void setReferer(const string& url) { referer = previousUrl = url; }
  84. string getProtocol() const { return protocol; }
  85. string getHost() const { return host; }
  86. int getPort() const { return port; }
  87. string getDir() const { return dir; }
  88. string getFile() const { return file;}
  89. void setTrackerEvent(int event) { trackerEvent = event; }
  90. int getTrackerEvent() const { return trackerEvent; }
  91. enum TRACKER_EVENT {
  92. AUTO,
  93. STARTED,
  94. STOPPED,
  95. COMPLETED,
  96. AFTER_COMPLETED
  97. };
  98. };
  99. typedef deque<Request*> Requests;
  100. #endif // _D_REQUEST_H_