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 - http://www.flightgear.org/~curt
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()
38 #include <simgear/debug/logstream.hxx>
39 #include <simgear/io/iochannel.hxx>
40 #include <simgear/math/sg_types.hxx>
41 #include <simgear/props/props.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Main/globals.hxx>
46 #include "jpg-httpd.hxx"
51 bool FGJpegHttpd::open() {
53 SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
54 << "is already in use, ignoring" );
58 imageServer = new HttpdImageServer( port );
60 set_hz( 5 ); // default to processing requests @ 5Hz
67 bool FGJpegHttpd::process() {
74 bool FGJpegHttpd::close() {
81 // Handle http GET requests
82 void HttpdImageChannel::foundTerminator (void) {
88 const string s = buffer.getData();
89 if ( s.find( "GET " ) == 0 ) {
91 printf("echo: %s\n", s.c_str());
93 int ImageLen = JpgFactory->render();
96 response = "HTTP/1.1 200 OK";
97 response += getTerminator();
98 response += "Content-Type: image/jpeg";
99 response += getTerminator();
100 push( response.c_str() );
103 printf( "info->numbytes = %d\n", ImageLen );
104 sprintf( ctmp, "Content-Length: %d", ImageLen );
107 response = getTerminator();
108 response += "Connection: close";
109 response += getTerminator();
110 response += getTerminator();
111 push( response.c_str() );
113 /* can't use strlen on binary data */
114 bufferSend ( (char *)JpgFactory->data(), ImageLen ) ;
116 printf("!!! NO IMAGE !!!\n\tinfo->numbytes = %d\n", ImageLen );