2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef _HTTP_SERVER_H_
20 #define _HTTP_SERVER_H_
24 #include <boost/shared_ptr.hpp>
25 #include <boost/shared_array.hpp>
26 #include <boost/scoped_array.hpp>
36 #include "diskstream.h"
41 class DSOEXPORT HTTPServer
: public gnash::HTTP
47 // These are for the protocol itself
48 http_method_e
processClientRequest(int fd
);
49 http_method_e
processClientRequest(Handler
*hand
, int fd
, cygnal::Buffer
*buf
);
50 cygnal::Buffer
&processGetRequest(Handler
*hand
, int fd
, cygnal::Buffer
*buf
);
51 boost::shared_ptr
<cygnal::Buffer
> processPostRequest(int fd
, cygnal::Buffer
*buf
);
52 boost::shared_ptr
<cygnal::Buffer
> processPutRequest(int fd
, cygnal::Buffer
*buf
);
53 boost::shared_ptr
<cygnal::Buffer
> processDeleteRequest(int fd
, cygnal::Buffer
*buf
);
54 boost::shared_ptr
<cygnal::Buffer
> processConnectRequest(int fd
, cygnal::Buffer
*buf
);
55 boost::shared_ptr
<cygnal::Buffer
> processOptionsRequest(int fd
, cygnal::Buffer
*buf
);
56 boost::shared_ptr
<cygnal::Buffer
> processHeadRequest(int fd
, cygnal::Buffer
*buf
);
57 boost::shared_ptr
<cygnal::Buffer
> processTraceRequest(int fd
, cygnal::Buffer
*buf
);
59 // Handle the response for the request.
60 boost::shared_ptr
<cygnal::Buffer
> formatServerReply(http_status_e code
);
61 cygnal::Buffer
&formatGetReply(gnash::DiskStream::filetype_e type
, size_t size
, http_status_e code
);
62 cygnal::Buffer
&formatGetReply(size_t size
, http_status_e code
);
63 cygnal::Buffer
&formatGetReply(http_status_e code
);
64 cygnal::Buffer
&formatPostReply(rtmpt_cmd_e code
);
65 cygnal::Buffer
&formatErrorResponse(http_status_e err
);
67 // These methods extract data from an RTMPT message. RTMP is an
68 // extension to HTTP that adds commands to manipulate the
69 // connection's persistance.
70 rtmpt_cmd_e
extractRTMPT(boost::uint8_t *data
);
71 rtmpt_cmd_e
extractRTMPT(cygnal::Buffer
&data
)
72 { return extractRTMPT(data
.reference()); };
75 // Examine the beginning of the data for an HTTP request command
76 // like GET or POST, etc...
77 http_method_e
extractCommand(boost::uint8_t *data
);
78 http_method_e
extractCommand(cygnal::Buffer
&data
)
79 { return extractCommand(data
.reference()); };
81 // process all the header fields in the Buffer, storing them internally
82 // in _fields. The address returned is the address where the Content data
83 // starts, and is "Content-Length" bytes long, of "Content-Type" data.
84 boost::uint8_t *processHeaderFields(cygnal::Buffer
&buf
);
88 // Parse an Echo Request message coming from the Red5 echo_test.
89 std::vector
<boost::shared_ptr
<cygnal::Element
> > parseEchoRequest(gnash::cygnal::Buffer
&buf
) { return parseEchoRequest(buf
.reference(), buf
.size()); };
90 std::vector
<boost::shared_ptr
<cygnal::Element
> > parseEchoRequest(boost::uint8_t *buf
, size_t size
);
92 // format a response to the 'echo' test used for testing Gnash.
93 gnash::cygnal::Buffer
&formatEchoResponse(const std::string
&num
, cygnal::Element
&el
);
94 gnash::cygnal::Buffer
&formatEchoResponse(const std::string
&num
, cygnal::Buffer
&data
);
95 gnash::cygnal::Buffer
&formatEchoResponse(const std::string
&num
, uint8_t *data
, size_t size
);
98 bool http_handler(Handler
*hand
, int netfd
, cygnal::Buffer
*buf
);
99 boost::shared_ptr
<gnash::DiskStream
> getDiskStream() { return _diskstream
; };
103 boost::shared_ptr
<gnash::DiskStream
> _diskstream
;
106 } // end of gnash namespace
108 // end of _HTTP_SERVER_H_
114 // indent-tabs-mode: t