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"
51 SG_USING_STD(istrstream);
54 bool FGJpegHttpd::open() {
56 SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
57 << "is already in use, ignoring" );
61 imageServer = new HttpdImageServer( port );
63 set_hz( 5 ); // default to processing requests @ 5Hz
70 bool FGJpegHttpd::process() {
77 bool FGJpegHttpd::close() {
84 // Handle http GET requests
85 void HttpdImageChannel::foundTerminator (void) {
91 const string s = buffer.getData();
92 if ( s.find( "GET " ) == 0 ) {
94 printf("echo: %s\n", s.c_str());
96 int ImageLen = JpgFactory->render();
99 response = "HTTP/1.1 200 OK";
100 response += getTerminator();
101 response += "Content-Type: image/jpeg";
102 response += getTerminator();
103 push( response.c_str() );
106 printf( "info->numbytes = %d\n", ImageLen );
107 sprintf( ctmp, "Content-Length: %d", ImageLen );
110 response = getTerminator();
111 response += "Connection: close";
112 response += getTerminator();
113 response += getTerminator();
114 push( response.c_str() );
116 /* can't use strlen on binary data */
117 bufferSend ( (char *)JpgFactory->data(), ImageLen ) ;
119 printf("!!! NO IMAGE !!!\n\tinfo->numbytes = %d\n", ImageLen );