Request.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. bool parseUrl(string url);
  57. public:
  58. Segment seg;
  59. CookieBox* cookieBox;
  60. public:
  61. Request();
  62. virtual ~Request();
  63. // Parses URL and sets url, host, port, dir, file fields.
  64. // Returns true if parsing goes successful, otherwise returns false.
  65. bool setUrl(string url);
  66. // Parses URL and sets host, port, dir, file fields.
  67. // url field are not altered by this method.
  68. // Returns true if parsing goes successful, otherwise returns false.
  69. bool redirectUrl(string url);
  70. bool resetUrl();
  71. void resetTryCount() { tryCount = 0; }
  72. void addTryCount() { tryCount++; }
  73. int getTryCount() const { return tryCount; }
  74. //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
  75. string getUrl() const { return url; }
  76. string getCurrentUrl() const { return currentUrl; }
  77. string getPreviousUrl() const { return previousUrl; }
  78. string getReferer() const { return referer; }
  79. void setReferer(string url) { referer = previousUrl = url; }
  80. string getProtocol() const { return protocol; }
  81. string getHost() const { return host; }
  82. int getPort() const { return port; }
  83. string getDir() const { return dir; }
  84. string getFile() const { return file;}
  85. };
  86. #endif // _D_REQUEST_H_