gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash/cygnal ChangeLog http.cpp http.h


From: Rob Savoye
Subject: [Gnash-commit] gnash/cygnal ChangeLog http.cpp http.h
Date: Thu, 20 Mar 2008 22:19:07 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    08/03/20 22:19:07

Modified files:
        cygnal         : ChangeLog http.cpp http.h 

Log message:
                * http.{h.cpp}: Add support for RTMPT, which is an extension to
                HTTP 1.0. Parse the RTMPT commands from the header.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/ChangeLog?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.cpp?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/http.h?cvsroot=gnash&r1=1.17&r2=1.18

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/cygnal/ChangeLog,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- ChangeLog   20 Mar 2008 18:14:55 -0000      1.12
+++ ChangeLog   20 Mar 2008 22:19:06 -0000      1.13
@@ -1,5 +1,8 @@
 2008-03-20  Rob Savoye  <address@hidden>
 
+       * http.{h.cpp}: Add support for RTMPT, which is an extension to
+       HTTP 1.0. Parse the RTMPT commands from the header.
+
        * http.{h,cpp}: Add support for more header fields, Accept-Range,
        Last-Modified, Keep-Alive. Use "\r\n" instead of endl for header
        fileds, as the two byte sequence is required by HTTP.

Index: http.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- http.cpp    20 Mar 2008 18:14:56 -0000      1.23
+++ http.cpp    20 Mar 2008 22:19:06 -0000      1.24
@@ -34,6 +34,7 @@
 #include <cstring>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <algorithm>
 
 #include "http.h"
 #include "log.h"
@@ -52,7 +53,12 @@
 static const int readsize = 1024;
 
 HTTP::HTTP() 
-    : _filesize(0), _port(80), _keepalive(true), _handler(0)
+    : _filesize(0),
+      _port(80),
+      _keepalive(true),
+      _handler(0),
+      _clientid(0),
+      _index(0)
 {
 //    GNASH_REPORT_FUNCTION;
 //    struct status_codes *status = new struct status_codes;
@@ -84,6 +90,8 @@
     _te.clear();
     _accept.clear();
     _filesize = 0;
+    _clientid = 0;
+    _index = 0;
     return true;
 }
 
@@ -120,14 +128,8 @@
        return "";
     }
     
-//    const char *ptr = reinterpret_cast<const char *>(buf->reference());
-//     if (readNet(buffer, readsize) > 0) {
-//         log_debug (_("Read initial GET Request"));
-//     } else {
-//         log_error (_("Couldn't read initial GET Request"));
-//     }
-
     clearHeader();
+    extractCommand(buf);    
     extractAccept(buf);
     extractMethod(buf);
     extractReferer(buf);
@@ -141,13 +143,6 @@
     extractTE(buf);
 //    dump();
 
-//     // See if we got a legit GET request
-//     if (strncmp(ptr, "GET ", 4) == 0) {
-//         log_debug (_("Got legit GET request"));
-//     } else {
-//         log_error (_("Got bogus GET request"));
-//     }
-
     _filespec = _url;
     return _url;
 }
@@ -317,6 +312,9 @@
       case MP3:
          _header << "Content-Type: audio/mpeg" << "\r\n";
          break;
+      case FCS:
+         _header << "Content-Type: application/x-fcs" << "\r\n";
+         break;
       default:
          _header << "Content-Type: text/html" << "\r\n";
 //       _header << "Content-Type: text/html; charset=UTF-8" << "\r\n";
@@ -460,6 +458,38 @@
 }
 
 bool
+HTTP::sendPostReply(rtmpt_cmd_e code)
+{
+    GNASH_REPORT_FUNCTION;
+
+    _header << "HTTP/1.1 200 OK" << "\r\n";
+    formatDate();
+    formatServer();
+    formatContentType(HTTP::FCS);
+    // All HTTP messages are followed by a blank line.
+    terminateHeader();
+    return true;
+
+#if 0
+    formatHeader(_filesize, code);
+    Buffer *buf = new Buffer;
+    if (_header.str().size()) {
+       buf->resize(_header.str().size());
+       string str = _header.str();
+       buf->copy(str);
+       _handler->pushout(buf);
+       _handler->notifyout();
+        log_debug (_("Sent GET Reply"));
+       return true; // Default to true
+    } else {
+       clearHeader();
+       log_debug (_("Couldn't send POST Reply, no header data"));
+    }
+#endif
+    return false;
+}
+
+bool
 HTTP::formatRequest(const string &url, http_method_e req)
 {
 //    GNASH_REPORT_FUNCTION;
@@ -537,6 +567,123 @@
     return _accept.size();
 }
 
+/// These methods extract data from an RTMPT message. RTMP is an
+/// extension to HTTP that adds commands to manipulate the
+/// connection's persistance.
+//
+/// The URL to be opened has the following form:
+/// http://server/<comand>/[<client>/]<index>
+/// <command>
+///    denotes the RTMPT request type, "OPEN", "SEND", "IDLE", "CLOSE")
+/// <client>
+///    specifies the id of the client that performs the requests
+///    (only sent for established sessions)
+/// <index>
+///    is a consecutive number that seems to be used to detect missing packages
+HTTP::rtmpt_cmd_e
+HTTP::extractRTMPT(gnash::Network::byte_t *data)
+{
+    GNASH_REPORT_FUNCTION;
+
+    string body = reinterpret_cast<const char *>(data);
+    string tmp, cid, indx;
+    HTTP::rtmpt_cmd_e cmd;
+
+    // force the case to make comparisons easier
+    std::transform(body.begin(), body.end(), body.begin(), 
+               (int(*)(int)) toupper);
+    string::size_type start, end;
+
+    // Extract the command first
+    start = body.find("OPEN", 0);
+    if (start != string::npos) {
+        cmd = HTTP::OPEN;
+    }
+    start = body.find("SEND", 0);
+    if (start != string::npos) {
+        cmd = HTTP::SEND;
+    }
+    start = body.find("IDLE", 0);
+    if (start != string::npos) {
+        cmd = HTTP::IDLE;
+    }
+    start = body.find("CLOSE", 0);
+    if (start != string::npos) {
+        cmd = HTTP::CLOSE;
+    }
+
+    // Extract the optional client id
+    start = body.find("/", start+1);
+    if (start != string::npos) {
+       end = body.find("/", start+1);
+       if (end != string::npos) {
+           indx = body.substr(end, body.size());
+           cid = body.substr(start, (end-start));
+       } else {
+           cid = body.substr(start, body.size());
+       }
+    }
+
+    _index = strtol(indx.c_str(), NULL, 0);
+    _clientid = strtol(cid.c_str(), NULL, 0);
+    end =  body.find("\r\n", start);
+//     if (end != string::npos) {
+//         cmd = HTTP::CLOSE;
+//     }
+
+    return cmd;
+}
+
+HTTP::http_method_e
+HTTP::extractCommand(gnash::Network::byte_t *data)
+{
+    GNASH_REPORT_FUNCTION;
+
+    string body = reinterpret_cast<const char *>(data);
+    HTTP::http_method_e cmd;
+
+    // force the case to make comparisons easier
+//     std::transform(body.begin(), body.end(), body.begin(), 
+//                (int(*)(int)) toupper);
+    string::size_type start, end;
+
+    // Extract the command
+    start = body.find("GET", 0);
+    if (start != string::npos) {
+        cmd = HTTP::GET;
+    }
+    start = body.find("POST", 0);
+    if (start != string::npos) {
+        cmd = HTTP::POST;
+    }
+    start = body.find("HEAD", 0);
+    if (start != string::npos) {
+        cmd = HTTP::HEAD;
+    }
+    start = body.find("CONNECT", 0);
+    if (start != string::npos) {
+        cmd = HTTP::CONNECT;
+    }
+    start = body.find("TRACE", 0);
+    if (start != string::npos) {
+        cmd = HTTP::TRACE;
+    }
+    start = body.find("OPTIONS", 0);
+    if (start != string::npos) {
+        cmd = HTTP::OPTIONS;
+    }
+    start = body.find("PUT", 0);
+    if (start != string::npos) {
+        cmd = HTTP::PUT;
+    }
+    start = body.find("DELETE", 0);
+    if (start != string::npos) {
+        cmd = HTTP::DELETE;
+    }
+
+    return cmd;
+}
+
 string
 HTTP::extractAcceptRanges(Network::byte_t *data) {
 //    GNASH_REPORT_FUNCTION;
@@ -553,7 +700,7 @@
         return "error";
     }
     
-    _referer = body.substr(start+pattern.size(), end-start-1);
+    _acceptranges = body.substr(start+pattern.size(), end-start-1);
     return _acceptranges;    
 }
 
@@ -1006,6 +1153,10 @@
     for (it = _te.begin(); it != _te.end(); it++) {
         log_debug("TE param: \"%s\"", (*(it)).c_str());
     }
+
+    // Dump the RTMPT fields
+    log_debug("RTMPT optional index is: ", _index);
+    log_debug("RTMPT optional client ID is: ", _clientid);
     log_debug (_("==== ==== ===="));
 }
 

Index: http.h
===================================================================
RCS file: /sources/gnash/gnash/cygnal/http.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- http.h      20 Mar 2008 18:14:56 -0000      1.17
+++ http.h      20 Mar 2008 22:19:07 -0000      1.18
@@ -99,6 +99,12 @@
         TRACE,
         CONNECT
     } http_method_e;
+    typedef enum {
+       OPEN,
+       SEND,
+       IDLE,
+       CLOSE
+    } rtmpt_cmd_e;
     struct status_codes {
         const char *code;
         const char *msg;
@@ -111,6 +117,7 @@
        VIDEO,
        AUDIO,
        MP3,
+       FCS,
        OSCP
     } filetype_e;
     HTTP();
@@ -121,13 +128,24 @@
     
     // Handle the GET request response
     bool sendGetReply(http_status_e code);
+    bool sendPostReply(rtmpt_cmd_e code);
 //    bool sendGetReply(Network &net);
 
     // Make copies of ourself
     HTTP &operator = (HTTP &obj);
 
+    // These methods extract data from an RTMPT message. RTMP is an
+    // extension to HTTP that adds commands to manipulate the
+    // connection's persistance.
+    rtmpt_cmd_e extractRTMPT(gnash::Network::byte_t *data);
+    rtmpt_cmd_e extractRTMPT(Buffer *data)
+       { return extractRTMPT(data->reference()); };
+
     // These methods extract the fields in the HTTP header.
     // These all return the number of items found, or 0
+    http_method_e extractCommand(gnash::Network::byte_t *data);
+    http_method_e extractCommand(Buffer *data)
+       { return extractCommand(data->reference()); };
     int extractAccept(gnash::Network::byte_t *data);
     int extractAccept(Buffer *data)
        { return extractAccept(data->reference()); };
@@ -259,6 +277,9 @@
     // Connection parameters we care about
     bool       _keepalive;
     Handler     *_handler;
+    // These two field hold the data from an RTMPT message
+    int                _clientid;
+    int                _index;
 //    bool     _te;
 };  
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]