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