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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <rdr/MemInStream.h>
  26. #include <rfb/UpdateTracker.h>
  27. #include <rfb/Configuration.h>
  28. #include <network/Socket.h>
  29. #include <time.h>
  30. namespace rfb {
  31. class HTTPServer : public network::SocketServer {
  32. public:
  33. // -=- Constructors
  34. // - HTTPServer(files)
  35. // Create an HTTP server which will use the getFile method
  36. // to satisfy HTTP GET requests.
  37. HTTPServer();
  38. virtual ~HTTPServer();
  39. // SocketServer interface
  40. // addSocket()
  41. // This causes the server to perform HTTP protocol on the
  42. // supplied socket.
  43. virtual void addSocket(network::Socket* sock, bool outgoing=false);
  44. // removeSocket()
  45. // Could clean up socket-specific resources here.
  46. virtual void removeSocket(network::Socket* sock);
  47. // getSockets() gets a list of sockets. This can be used to generate an
  48. // fd_set for calling select().
  49. virtual void getSockets(std::list<network::Socket*>* sockets);
  50. // processSocketReadEvent()
  51. // The platform-specific side of the server implementation calls
  52. // this method whenever data arrives on one of the active
  53. // network sockets.
  54. virtual void processSocketReadEvent(network::Socket* sock);
  55. // processSocketWriteEvent()
  56. // Similar to processSocketReadEvent(), but called when it is
  57. // possible to write more data to a socket.
  58. virtual void processSocketWriteEvent(network::Socket* sock);
  59. // Check for socket timeouts
  60. virtual int checkTimeouts();
  61. // -=- File interface
  62. // - getFile is passed the path portion of a URL and returns an
  63. // InStream containing the data to return. If the requested
  64. // file is available then the contentType should be set to the
  65. // type of the file, or left untouched if the file type is to
  66. // be determined automatically by HTTPServer.
  67. // If the file is not available then null is returned.
  68. // Overridden getFile functions should call the default version
  69. // if they do not recognise a path name.
  70. // NB: The caller assumes ownership of the returned InStream.
  71. // NB: The contentType is statically allocated by the getFile impl.
  72. // NB: contentType is *guaranteed* to be valid when getFile is called.
  73. virtual rdr::InStream* getFile(const char* name, const char** contentType,
  74. int* contentLength, time_t* lastModified);
  75. // - guessContentType is passed the name of a file and returns the
  76. // name of an HTTP content type, based on the file's extension. If
  77. // the extension isn't recognised then defType is returned. This can
  78. // be used from getFile to easily default to the supplied contentType,
  79. // or by passing zero in to determine whether a type is recognised or
  80. // not.
  81. static const char* guessContentType(const char* name, const char* defType);
  82. protected:
  83. class Session;
  84. std::list<Session*> sessions;
  85. };
  86. }
  87. #endif