/* */ #ifndef _D_REQUEST_H_ #define _D_REQUEST_H_ #include "common.h" #include "CookieBox.h" #define SAFE_CHARS "abcdefghijklmnopqrstuvwxyz"\ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\ "0123456789"\ ":/?[]@"\ "!$&'()*+,;="\ "-._~"\ "%"\ "#" #define METALINK_MARK "#!metalink3!" class Request { public: enum TRACKER_EVENT { AUTO, STARTED, STOPPED, COMPLETED, AFTER_COMPLETED }; private: string url; string currentUrl; /** * URL previously requested to the server. This is used as Referer */ string previousUrl; /** * URL used as Referer in the initial request */ string referer; string protocol; string host; int32_t port; string dir; string file; int32_t tryCount; TRACKER_EVENT trackerEvent; bool keepAlive; string method; string _username; string _password; bool parseUrl(const string& url); public: CookieBoxHandle cookieBox; public: Request(); virtual ~Request(); // Parses URL and sets url, host, port, dir, file fields. // Returns true if parsing goes successful, otherwise returns false. bool setUrl(const string& url); // Parses URL and sets host, port, dir, file fields. // url field are not altered by this method. // Returns true if parsing goes successful, otherwise returns false. bool redirectUrl(const string& url); bool resetUrl(); void resetTryCount() { tryCount = 0; } void addTryCount() { tryCount++; } int32_t getTryCount() const { return tryCount; } //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; } string getUrl() const { return url; } string getCurrentUrl() const { return currentUrl; } string getPreviousUrl() const { return previousUrl; } string getReferer() const { return referer; } void setReferer(const string& url) { referer = previousUrl = url; } string getProtocol() const { return protocol; } string getHost() const { return host; } int32_t getPort() const { return port; } string getDir() const { return dir; } string getFile() const { return file;} bool isKeepAlive() const { return keepAlive; } void setKeepAlive(bool keepAlive) { this->keepAlive = keepAlive; } void setTrackerEvent(TRACKER_EVENT event) { trackerEvent = event; } TRACKER_EVENT getTrackerEvent() const { return trackerEvent; } void setMethod(const string& method) { this->method = method; } const string& getUsername() const { return _username; } const string& getPassword() const { return _password; } const string& getMethod() const { return method; } static const string METHOD_GET; static const string METHOD_HEAD; }; typedef SharedHandle RequestHandle; typedef deque Requests; typedef WeakHandle RequestWeakHandle; #endif // _D_REQUEST_H_