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