blob: 6412946a494dc11c983b4468e082bcd276a6740d [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
61 // processSocketEvent()
62 // The platform-specific side of the server implementation calls
63 // this method whenever data arrives on one of the active
64 // network sockets.
65 virtual void processSocketEvent(network::Socket* sock);
66
67 // Check for socket timeouts
68 virtual int checkTimeouts();
69
70
71 // getSockets() gets a list of sockets. This can be used to generate an
72 // fd_set for calling select().
73
74 virtual void getSockets(std::list<network::Socket*>* sockets);
75
76
77 // -=- File interface
78
79 // - getFile is passed the path portion of a URL and returns an
80 // InStream containing the data to return. If the requested
81 // file is available then the contentType should be set to the
82 // type of the file, or left untouched if the file type is to
83 // be determined automatically by HTTPServer.
84 // If the file is not available then null is returned.
85 // Overridden getFile functions should call the default version
86 // if they do not recognise a path name.
87 // NB: The caller assumes ownership of the returned InStream.
88 // NB: The contentType is statically allocated by the getFile impl.
89 // NB: contentType is *guaranteed* to be valid when getFile is called.
90
91 virtual rdr::InStream* getFile(const char* name, const char** contentType,
92 int* contentLength, time_t* lastModified);
93
94 // - guessContentType is passed the name of a file and returns the
95 // name of an HTTP content type, based on the file's extension. If
96 // the extension isn't recognised then defType is returned. This can
97 // be used from getFile to easily default to the supplied contentType,
98 // or by passing zero in to determine whether a type is recognised or
99 // not.
100
101 static const char* guessContentType(const char* name, const char* defType);
102
103 protected:
104 class Session;
105 std::list<Session*> sessions;
106 };
107}
108
109#endif
110