protocol.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/protocol/protocol.h
  3. // Purpose: interface of wxProtocol
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Error values returned by wxProtocol.
  9. */
  10. enum wxProtocolError
  11. {
  12. wxPROTO_NOERR = 0, //!< No error.
  13. wxPROTO_NETERR, //!< A generic network error occurred.
  14. wxPROTO_PROTERR, //!< An error occurred during negotiation.
  15. wxPROTO_CONNERR, //!< The client failed to connect the server.
  16. wxPROTO_INVVAL, //!< Invalid value.
  17. wxPROTO_NOHNDLR, //!< Not currently used.
  18. wxPROTO_NOFILE, //!< The remote file doesn't exist.
  19. wxPROTO_ABRT, //!< Last action aborted.
  20. wxPROTO_RCNCT, //!< An error occurred during reconnection.
  21. wxPROTO_STREAMING //!< Someone tried to send a command during a transfer.
  22. };
  23. /**
  24. @class wxProtocol
  25. Represents a protocol for use with wxURL.
  26. Note that you may want to change the default time-out for HTTP/FTP connections
  27. and network operations (using SetDefaultTimeout()) since the default time-out
  28. value is quite long (60 seconds).
  29. @library{wxnet}
  30. @category{net}
  31. @see wxSocketBase, wxURL
  32. */
  33. class wxProtocol : public wxSocketClient
  34. {
  35. public:
  36. /**
  37. Abort the current stream.
  38. @warning
  39. It is advised to destroy the input stream instead of aborting the stream
  40. this way.
  41. @return Returns @true, if successful, else @false.
  42. */
  43. virtual bool Abort() = 0;
  44. /**
  45. Returns the type of the content of the last opened stream. It is a mime-type.
  46. May be an empty string if the content-type is unknown.
  47. */
  48. virtual wxString GetContentType() const;
  49. /**
  50. Returns the last occurred error.
  51. @see wxProtocolError
  52. */
  53. virtual wxProtocolError GetError() const;
  54. /**
  55. Creates a new input stream on the specified path.
  56. You can use all but seek() functionality of wxStream.
  57. Seek() isn't available on all streams. For example, HTTP or FTP streams
  58. don't deal with it. Other functions like StreamSize() and Tell() aren't
  59. available for the moment for this sort of stream.
  60. You will be notified when the EOF is reached by an error.
  61. @return Returns the initialized stream. You will have to delete it
  62. yourself once you don't use it anymore. The destructor
  63. closes the network connection.
  64. @see wxInputStream
  65. */
  66. virtual wxInputStream* GetInputStream(const wxString& path) = 0;
  67. /**
  68. Tries to reestablish a previous opened connection (close and renegotiate
  69. connection).
  70. @return @true, if the connection is established, else @false.
  71. */
  72. bool Reconnect();
  73. /**
  74. Sets the authentication password.
  75. */
  76. virtual void SetPassword(const wxString& user);
  77. /**
  78. Sets the authentication user.
  79. */
  80. virtual void SetUser(const wxString& user);
  81. /**
  82. Sets a new default timeout for the network operations.
  83. The default timeout is 60 seconds.
  84. @see wxSocketBase::SetTimeout
  85. */
  86. void SetDefaultTimeout(wxUint32 Value);
  87. /**
  88. @name Logging support.
  89. Each wxProtocol object may have the associated logger (by default there
  90. is none) which is used to log network requests and responses.
  91. @see wxProtocolLog
  92. */
  93. //@{
  94. /**
  95. Set the logger, deleting the old one and taking ownership of this one.
  96. @param log
  97. New logger allocated on the heap or @NULL.
  98. */
  99. void SetLog(wxProtocolLog *log);
  100. /**
  101. Return the current logger, may be @NULL.
  102. */
  103. wxProtocolLog *GetLog() const { return m_log; }
  104. /**
  105. Detach the existing logger without deleting it.
  106. The caller is responsible for deleting the returned pointer if it's
  107. non-@c NULL.
  108. */
  109. wxProtocolLog *DetachLog();
  110. /**
  111. Call wxProtocolLog::LogRequest() if we have a valid logger or do
  112. nothing otherwise.
  113. */
  114. void LogRequest(const wxString& str);
  115. /**
  116. Call wxProtocolLog::LogResponse() if we have a valid logger or do
  117. nothing otherwise.
  118. */
  119. void LogResponse(const wxString& str);
  120. //@}
  121. };