Request.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. class Request {
  38. private:
  39. string url;
  40. string currentUrl;
  41. /**
  42. * URL previously requested to the server. This is used as Referer
  43. */
  44. string previousUrl;
  45. /**
  46. * URL used as Referer in the initial request
  47. */
  48. string referer;
  49. string protocol;
  50. string host;
  51. int port;
  52. string dir;
  53. string file;
  54. map<string, int> defaultPorts;
  55. int tryCount;
  56. int trackerEvent;
  57. bool parseUrl(string url);
  58. public:
  59. Segment seg;
  60. CookieBox* cookieBox;
  61. bool isTorrent;
  62. public:
  63. Request();
  64. virtual ~Request();
  65. // Parses URL and sets url, host, port, dir, file fields.
  66. // Returns true if parsing goes successful, otherwise returns false.
  67. bool setUrl(string url);
  68. // Parses URL and sets host, port, dir, file fields.
  69. // url field are not altered by this method.
  70. // Returns true if parsing goes successful, otherwise returns false.
  71. bool redirectUrl(string url);
  72. bool resetUrl();
  73. void resetTryCount() { tryCount = 0; }
  74. void addTryCount() { tryCount++; }
  75. int getTryCount() const { return tryCount; }
  76. //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
  77. string getUrl() const { return url; }
  78. string getCurrentUrl() const { return currentUrl; }
  79. string getPreviousUrl() const { return previousUrl; }
  80. string getReferer() const { return referer; }
  81. void setReferer(string url) { referer = previousUrl = url; }
  82. string getProtocol() const { return protocol; }
  83. string getHost() const { return host; }
  84. int getPort() const { return port; }
  85. string getDir() const { return dir; }
  86. string getFile() const { return file;}
  87. void setTrackerEvent(int event) { trackerEvent = event; }
  88. int getTrackerEvent() const { return trackerEvent; }
  89. enum TRACKER_EVENT {
  90. AUTO,
  91. STARTED,
  92. STOPPED,
  93. COMPLETED
  94. };
  95. };
  96. #endif // _D_REQUEST_H_