blob: 9431195c14559ff2da2c6c9b28ef48121f6d3195 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2004 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
36namespace rfb {
37
38 class HTTPServer : public network::SocketServer {
39 public:
40 // -=- Constructors
41
42 // - HTTPServer(files)
43 // Create an HTTP server which will use the getFile method
44 // to satisfy HTTP GET requests.
45 HTTPServer();
46
47 virtual ~HTTPServer();
48
49 // -=- Client management
50
51 // - Run a client connection on the supplied socket
52 // This causes the server to perform HTTP protocol on the
53 // supplied socket.
54 // The socket will be closed if protocol initialisation
55 // fails.
56 virtual void addClient(network::Socket* sock);
57
58 // -=- Event processing methods
59
60 // - Process an input event on a particular Socket
61 // The platform-specific side of the server implementation calls
62 // this method whenever data arrives on one of the active
63 // network sockets.
64 // The method returns true if the Socket is still in use by the
65 // server, or false if it is no longer required and should be
66 // deleted.
67 // NB: If false is returned then the Socket is deleted and must
68 // not be accessed again!
69
70 virtual bool processSocketEvent(network::Socket* sock);
71
72 // - Check for socket timeouts
73 virtual int checkTimeouts();
74
75 // getSockets() gets a list of sockets. This can be used to generate an
76 // fd_set for calling select().
77
78 virtual void getSockets(std::list<network::Socket*>* sockets);
79
80
81 // -=- File interface
82
83 // - getFile is passed the path portion of a URL and returns an
84 // InStream containing the data to return. If the requested
85 // file is available then the contentType should be set to the
86 // type of the file, or left untouched if the file type is to
87 // be determined automatically by HTTPServer.
88 // If the file is not available then null is returned.
89 // Overridden getFile functions should call the default version
90 // if they do not recognise a path name.
91 // NB: The caller assumes ownership of the returned InStream.
92 // NB: The contentType is statically allocated by the getFile impl.
93 // NB: contentType is *guaranteed* to be valid when getFile is called.
94
95 virtual rdr::InStream* getFile(const char* name, const char** contentType);
96
97 // - guessContentType is passed the name of a file and returns the
98 // name of an HTTP content type, based on the file's extension. If
99 // the extension isn't recognised then defType is returned. This can
100 // be used from getFile to easily default to the supplied contentType,
101 // or by passing zero in to determine whether a type is recognised or not.
102
103 static const char* guessContentType(const char* name, const char* defType);
104
105 protected:
106 class Session;
107 std::list<Session*> sessions;
108 };
109}
110
111#endif
112