blob: d7ca69ade47b66c7fde8b6d21ed8feaa8406b6d9 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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
19// -=- HTTPServer.h
20
21// Single-threaded HTTP server implementation.
22// All I/O is handled by the processSocketEvent routine,
23// which is called by the main-loop of the VNC server whenever
24// there is an event on an HTTP socket.
25
26#ifndef __RFB_HTTP_SERVER_H__
27#define __RFB_HTTP_SERVER_H__
28
29#include <list>
30
31#include <rdr/MemInStream.h>
32#include <rfb/UpdateTracker.h>
33#include <rfb/Configuration.h>
34#include <network/Socket.h>
35#include <time.h>
36
37namespace rfb {
38
39 class HTTPServer : public network::SocketServer {
40 public:
41 // -=- Constructors
42
43 // - HTTPServer(files)
44 // Create an HTTP server which will use the getFile method
45 // to satisfy HTTP GET requests.
46 HTTPServer();
47
48 virtual ~HTTPServer();
49
50 // SocketServer interface
51
52 // addSocket()
53 // This causes the server to perform HTTP protocol on the
54 // supplied socket.
55 virtual void addSocket(network::Socket* sock, bool outgoing=false);
56
57 // removeSocket()
58 // Could clean up socket-specific resources here.
59 virtual void removeSocket(network::Socket* sock);
60
Pierre Ossmand408ca52016-04-29 14:26:05 +020061 // processSocketReadEvent()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062 // The platform-specific side of the server implementation calls
63 // this method whenever data arrives on one of the active
64 // network sockets.
Pierre Ossmand408ca52016-04-29 14:26:05 +020065 virtual void processSocketReadEvent(network::Socket* sock);
66
67 // processSocketWriteEvent()
68 // Similar to processSocketReadEvent(), but called when it is
69 // possible to write more data to a socket.
70 virtual void processSocketWriteEvent(network::Socket* sock);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071
72 // Check for socket timeouts
73 virtual int checkTimeouts();
74
75
76 // getSockets() gets a list of sockets. This can be used to generate an
77 // fd_set for calling select().
78
79 virtual void getSockets(std::list<network::Socket*>* sockets);
80
81
82 // -=- File interface
83
84 // - getFile is passed the path portion of a URL and returns an
85 // InStream containing the data to return. If the requested
86 // file is available then the contentType should be set to the
87 // type of the file, or left untouched if the file type is to
88 // be determined automatically by HTTPServer.
89 // If the file is not available then null is returned.
90 // Overridden getFile functions should call the default version
91 // if they do not recognise a path name.
92 // NB: The caller assumes ownership of the returned InStream.
93 // NB: The contentType is statically allocated by the getFile impl.
94 // NB: contentType is *guaranteed* to be valid when getFile is called.
95
96 virtual rdr::InStream* getFile(const char* name, const char** contentType,
97 int* contentLength, time_t* lastModified);
98
99 // - guessContentType is passed the name of a file and returns the
100 // name of an HTTP content type, based on the file's extension. If
101 // the extension isn't recognised then defType is returned. This can
102 // be used from getFile to easily default to the supplied contentType,
103 // or by passing zero in to determine whether a type is recognised or
104 // not.
105
106 static const char* guessContentType(const char* name, const char* defType);
107
108 protected:
109 class Session;
110 std::list<Session*> sessions;
111 };
112}
113
114#endif
115