]> git.mxchange.org Git - flightgear.git/blob - src/Network/httpd.hxx
new FSF address
[flightgear.git] / src / Network / httpd.hxx
1 // httpd.hxx -- FGFS http property manager interface / external script
2 //              and control class
3 //
4 // Written by Curtis Olson, started June 2001.
5 //
6 // Copyright (C) 2001  Curtis L. Olson - http://www.flightgear.org/~curt
7 //
8 // Jpeg Image Support added August 2001
9 //  by Norman Vine - nhv@cape.com
10 //
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 //
25 // $Id$
26
27
28 #ifndef _FG_HTTPD_HXX
29 #define _FG_HTTPD_HXX
30
31 #ifdef HAVE_CONFIG_H
32 #  include <config.h>
33 #endif
34
35 #include <plib/netChat.h>
36
37 #include "protocol.hxx"
38
39
40 /* simple httpd server that makes an hasty stab at following the http
41    1.1 rfc.  */
42
43 class HttpdChannel : public netChat
44 {
45
46     netBuffer buffer ;
47
48     string urlEncode(string);
49     string urlDecode(string);
50
51 public:
52
53     HttpdChannel() : buffer(512) { setTerminator("\r\n"); }
54
55     virtual void collectIncomingData (const char* s, int n) {
56         buffer.append(s,n);
57     }
58
59     // Handle the actual http request
60     virtual void foundTerminator (void);
61 } ;
62
63
64 class HttpdServer : private netChannel
65 {
66     virtual bool writable (void) { return false ; }
67
68     virtual void handleAccept (void) {
69         netAddress addr ;
70         int handle = accept ( &addr ) ;
71         printf("Client %s:%d connected\n", addr.getHost(), addr.getPort());
72
73         HttpdChannel *hc = new HttpdChannel;
74         hc->setHandle ( handle ) ;
75     }
76
77 public:
78
79     HttpdServer ( int port ) {
80         open() ;
81         bind( "", port );
82         listen( 5 );
83
84         printf( "Httpd server started on port %d\n", port ) ;
85     }
86 };
87
88
89 class FGHttpd : public FGProtocol {
90
91     int port;
92     HttpdServer *server;
93     
94 public:
95
96     inline FGHttpd( int p ) { port = p; }
97
98     inline ~FGHttpd() { }
99
100     bool open();
101
102     bool process();
103
104     bool close();
105 };
106
107
108 #endif // _FG_HTTPD_HXX