You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HTTPServer.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- HTTPServer.h
  19. // Single-threaded HTTP server implementation.
  20. // All I/O is handled by the processSocketEvent routine,
  21. // which is called by the main-loop of the VNC server whenever
  22. // there is an event on an HTTP socket.
  23. #ifndef __RFB_HTTP_SERVER_H__
  24. #define __RFB_HTTP_SERVER_H__
  25. #include <list>
  26. #include <rdr/MemInStream.h>
  27. #include <rfb/UpdateTracker.h>
  28. #include <rfb/Configuration.h>
  29. #include <network/Socket.h>
  30. #include <time.h>
  31. namespace rfb {
  32. class HTTPServer : public network::SocketServer {
  33. public:
  34. // -=- Constructors
  35. // - HTTPServer(files)
  36. // Create an HTTP server which will use the getFile method
  37. // to satisfy HTTP GET requests.
  38. HTTPServer();
  39. virtual ~HTTPServer();
  40. // SocketServer interface
  41. // addSocket()
  42. // This causes the server to perform HTTP protocol on the
  43. // supplied socket.
  44. virtual void addSocket(network::Socket* sock, bool outgoing=false);
  45. // removeSocket()
  46. // Could clean up socket-specific resources here.
  47. virtual void removeSocket(network::Socket* sock);
  48. // processSocketEvent()
  49. // The platform-specific side of the server implementation calls
  50. // this method whenever data arrives on one of the active
  51. // network sockets.
  52. virtual void processSocketEvent(network::Socket* sock);
  53. // Check for socket timeouts
  54. virtual int checkTimeouts();
  55. // getSockets() gets a list of sockets. This can be used to generate an
  56. // fd_set for calling select().
  57. virtual void getSockets(std::list<network::Socket*>* sockets);
  58. // -=- File interface
  59. // - getFile is passed the path portion of a URL and returns an
  60. // InStream containing the data to return. If the requested
  61. // file is available then the contentType should be set to the
  62. // type of the file, or left untouched if the file type is to
  63. // be determined automatically by HTTPServer.
  64. // If the file is not available then null is returned.
  65. // Overridden getFile functions should call the default version
  66. // if they do not recognise a path name.
  67. // NB: The caller assumes ownership of the returned InStream.
  68. // NB: The contentType is statically allocated by the getFile impl.
  69. // NB: contentType is *guaranteed* to be valid when getFile is called.
  70. virtual rdr::InStream* getFile(const char* name, const char** contentType,
  71. int* contentLength, time_t* lastModified);
  72. // - guessContentType is passed the name of a file and returns the
  73. // name of an HTTP content type, based on the file's extension. If
  74. // the extension isn't recognised then defType is returned. This can
  75. // be used from getFile to easily default to the supplied contentType,
  76. // or by passing zero in to determine whether a type is recognised or
  77. // not.
  78. static const char* guessContentType(const char* name, const char* defType);
  79. protected:
  80. class Session;
  81. std::list<Session*> sessions;
  82. };
  83. }
  84. #endif