1 // httpd.hxx -- FGFS http property manager interface / external script
4 // Written by Curtis Olson, started June 2001.
6 // Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
8 // Jpeg Image Support added August 2001
9 // by Norman Vine - nhv@cape.com
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <simgear/compiler.h>
34 #include <stdlib.h> // atoi() atof()
37 #include STL_STRSTREAM
39 #include <simgear/debug/logstream.hxx>
40 #include <simgear/io/iochannel.hxx>
41 #include <simgear/math/sg_types.hxx>
42 #include <simgear/misc/props.hxx>
44 #include <Main/fg_props.hxx>
45 #include <Main/globals.hxx>
47 #include "jpg-httpd.hxx"
50 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
52 SG_USING_STD(istrstream);
56 bool FGJpegHttpd::open() {
58 SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
59 << "is already in use, ignoring" );
63 imageServer = new HttpdImageServer( port );
65 set_hz( 5 ); // default to processing requests @ 5Hz
72 bool FGJpegHttpd::process() {
79 bool FGJpegHttpd::close() {
86 // Handle http GET requests
87 void HttpdImageChannel::foundTerminator (void) {
93 const string s = buffer.getData();
94 if ( s.find( "GET " ) == 0 ) {
96 printf("echo: %s\n", s.c_str());
98 int ImageLen = JpgFactory->render();
101 response = "HTTP/1.1 200 OK";
102 response += getTerminator();
103 response += "Content-Type: image/jpeg";
104 response += getTerminator();
105 push( response.c_str() );
108 printf( "info->numbytes = %d\n", ImageLen );
109 sprintf( ctmp, "Content-Length: %d", ImageLen );
112 response = getTerminator();
113 response += "Connection: close";
114 response += getTerminator();
115 response += getTerminator();
116 push( response.c_str() );
118 /* can't use strlen on binary data */
119 bufferSend ( (char *)JpgFactory->data(), ImageLen ) ;
121 printf("!!! NO IMAGE !!!\n\tinfo->numbytes = %d\n", ImageLen );