url.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: url.h
  3. // Purpose: interface of wxURL
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Error types returned from wxURL::GetError().
  9. */
  10. typedef enum {
  11. wxURL_NOERR = 0, ///< No error.
  12. wxURL_SNTXERR, ///< Syntax error in the URL string.
  13. wxURL_NOPROTO, ///< Found no protocol which can get this URL.
  14. wxURL_NOHOST, ///< A host name is required for this protocol.
  15. wxURL_NOPATH, ///< A path is required for this protocol.
  16. wxURL_CONNERR, ///< Connection error.
  17. wxURL_PROTOERR ///< An error occurred during negotiation.
  18. } wxURLError;
  19. /**
  20. @class wxURL
  21. wxURL is a specialization of wxURI for parsing URLs. Please look at wxURI
  22. documentation for more info about the functions you can use to retrieve the
  23. various parts of the URL (scheme, server, port, etc).
  24. Supports standard assignment operators, copy constructors, and comparison
  25. operators.
  26. @library{wxnet}
  27. @category{net}
  28. @see wxSocketBase, wxProtocol
  29. */
  30. class wxURL : public wxURI
  31. {
  32. public:
  33. /**
  34. Constructs a URL object from the string. The URL must be valid
  35. according to RFC 1738. In particular, file URLs must be of the format
  36. @c "file://hostname/path/to/file", otherwise GetError() will return a
  37. value different from ::wxURL_NOERR.
  38. It is valid to leave out the hostname but slashes must remain in place,
  39. in other words, a file URL without a hostname must contain three
  40. consecutive slashes (e.g. @c "file:///somepath/myfile").
  41. @param url
  42. Url string to parse.
  43. */
  44. wxURL(const wxString& url = wxEmptyString);
  45. /**
  46. Destroys the URL object.
  47. */
  48. virtual ~wxURL();
  49. /**
  50. Returns the last error. This error refers to the URL parsing or to the
  51. protocol. It can be one of ::wxURLError.
  52. */
  53. wxURLError GetError() const;
  54. /**
  55. Creates a new input stream on the specified URL. You can use all but
  56. seek functionality of wxStream. Seek isn't available on all streams.
  57. For example, HTTP or FTP streams don't deal with it.
  58. Note that this method is somewhat deprecated, all future wxWidgets
  59. applications should use wxFileSystem instead.
  60. Example:
  61. @code
  62. wxURL url("http://a.host/a.dir/a.file");
  63. if (url.GetError() == wxURL_NOERR)
  64. {
  65. wxInputStream *in_stream;
  66. in_stream = url.GetInputStream();
  67. // Then, you can use all IO calls of in_stream (See wxStream)
  68. }
  69. @endcode
  70. @return Returns the initialized stream. You will have to delete it
  71. yourself.
  72. @see wxInputStream
  73. */
  74. wxInputStream* GetInputStream();
  75. /**
  76. Returns a reference to the protocol which will be used to get the URL.
  77. */
  78. wxProtocol& GetProtocol();
  79. /**
  80. Returns @true if this object is correctly initialized, i.e.\ if
  81. GetError() returns ::wxURL_NOERR.
  82. */
  83. bool IsOk() const;
  84. /**
  85. Sets the default proxy server to use to get the URL. The string
  86. specifies the proxy like this: @c "<hostname>:<port number>".
  87. @param url_proxy
  88. Specifies the proxy to use.
  89. @see SetProxy()
  90. */
  91. static void SetDefaultProxy(const wxString& url_proxy);
  92. /**
  93. Sets the proxy to use for this URL.
  94. @see SetDefaultProxy()
  95. */
  96. void SetProxy(const wxString& url_proxy);
  97. /**
  98. Initializes this object with the given URL and returns ::wxURL_NOERR if
  99. it's valid (see GetError() for more info).
  100. */
  101. wxURLError SetURL(const wxString& url);
  102. };