virtualFileMountHTTP.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Filename: virtualFileMountHTTP.h
  2. // Created by: drose (30Oct08)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef VIRTUALFILEMOUNTHTTP_H
  15. #define VIRTUALFILEMOUNTHTTP_H
  16. #include "pandabase.h"
  17. #ifdef HAVE_OPENSSL
  18. #include "virtualFileMount.h"
  19. #include "httpClient.h"
  20. #include "httpChannel.h"
  21. #include "urlSpec.h"
  22. #include "pointerTo.h"
  23. #include "mutexImpl.h"
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : VirtualFileMountHTTP
  26. // Description : Maps a web page (URL root) into the
  27. // VirtualFileSystem.
  28. ////////////////////////////////////////////////////////////////////
  29. class EXPCL_PANDAEXPRESS VirtualFileMountHTTP : public VirtualFileMount {
  30. PUBLISHED:
  31. VirtualFileMountHTTP(const URLSpec &root, HTTPClient *http = HTTPClient::get_global_ptr());
  32. virtual ~VirtualFileMountHTTP();
  33. INLINE HTTPClient *get_http_client() const;
  34. INLINE const URLSpec &get_root() const;
  35. static void reload_vfs_mount_url();
  36. public:
  37. virtual PT(VirtualFile) make_virtual_file(const Filename &local_filename,
  38. const Filename &original_filename,
  39. bool implicit_pz_file,
  40. int open_flags);
  41. virtual bool has_file(const Filename &file) const;
  42. virtual bool is_directory(const Filename &file) const;
  43. virtual bool is_regular_file(const Filename &file) const;
  44. virtual istream *open_read_file(const Filename &file) const;
  45. virtual streamsize get_file_size(const Filename &file, istream *stream) const;
  46. virtual streamsize get_file_size(const Filename &file) const;
  47. virtual time_t get_timestamp(const Filename &file) const;
  48. virtual bool scan_directory(vector_string &contents,
  49. const Filename &dir) const;
  50. virtual void output(ostream &out) const;
  51. PT(HTTPChannel) get_channel();
  52. void recycle_channel(HTTPChannel *channel);
  53. private:
  54. PT(HTTPClient) _http;
  55. URLSpec _root;
  56. MutexImpl _channels_lock;
  57. typedef pvector< PT(HTTPChannel) > Channels;
  58. Channels _channels;
  59. public:
  60. virtual TypeHandle get_type() const {
  61. return get_class_type();
  62. }
  63. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  64. static TypeHandle get_class_type() {
  65. return _type_handle;
  66. }
  67. static void init_type() {
  68. VirtualFileMount::init_type();
  69. register_type(_type_handle, "VirtualFileMountHTTP",
  70. VirtualFileMount::get_class_type());
  71. }
  72. private:
  73. static TypeHandle _type_handle;
  74. };
  75. #include "virtualFileMountHTTP.I"
  76. #endif // HAVE_OPENSSL
  77. #endif