gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/rtmp r9765: Don't pass shared_ptrs as a pa


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9765: Don't pass shared_ptrs as a parameter, pass by reference.
Date: Fri, 21 Nov 2008 17:28:11 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9765
committer: address@hidden
branch nick: rtmp
timestamp: Fri 2008-11-21 17:28:11 -0700
message:
  Don't pass shared_ptrs as a parameter, pass by reference.
  Extract the actual version number and convert to a number so we can use it.
  Extract the various versions of the Keep-Alive field to set max requests
  or toggle the Keep-Alive state for network persistance.
  Add more tests to test all this stuff.
  toggle the Keep-Alive state based on the HTTP version number.
modified:
  libnet/http.cpp
  libnet/http.h
  testsuite/libnet.all/test_http.cpp
=== modified file 'libnet/http.cpp'
--- a/libnet/http.cpp   2008-11-21 16:43:51 +0000
+++ b/libnet/http.cpp   2008-11-22 00:28:11 +0000
@@ -77,7 +77,8 @@
       _keepalive(false),
       _handler(0),
       _clientid(0),
-      _index(0)
+      _index(0),
+      _max_requests(0)
 {
 //    GNASH_REPORT_FUNCTION;
 //    struct status_codes *status = new struct status_codes;
@@ -91,7 +92,8 @@
       _port(80),
       _keepalive(false),
       _clientid(0),
-      _index(0)
+      _index(0),
+      _max_requests(0)
 {
 //    GNASH_REPORT_FUNCTION;
     _handler = hand;
@@ -116,6 +118,8 @@
     _filesize = 0;
     _clientid = 0;
     _index = 0;
+    _max_requests = 0;
+    
     return true;
 }
 
@@ -189,18 +193,18 @@
     }
     
     clearHeader();
-    extractCommand(buf);    
-    extractConnection(buf);
-    extractAccept(buf);
-    extractMethod(buf);
-    extractReferer(buf);
-    extractHost(buf);
-    extractAgent(buf);
-    extractLanguage(buf);
-    extractCharset(buf);
-    extractKeepAlive(buf);
-    extractEncoding(buf);
-    extractTE(buf);
+    extractCommand(*buf);
+    extractConnection(*buf);
+    extractAccept(*buf);
+    extractMethod(*buf);
+    extractReferer(*buf);
+    extractHost(*buf);
+    extractAgent(*buf);
+    extractLanguage(*buf);
+    extractCharset(*buf);
+    extractKeepAlive(*buf);
+    extractEncoding(*buf);
+    extractTE(*buf);
 //    dump();
 
     _filespec = _url;
@@ -229,18 +233,18 @@
     }
     
     clearHeader();
-    extractCommand(buf);    
-    extractAccept(buf);
-    extractMethod(buf);
-    extractReferer(buf);
-    extractHost(buf);
-    extractAgent(buf);
-    extractLanguage(buf);
-    extractCharset(buf);
-    extractConnection(buf);
-    extractKeepAlive(buf);
-    extractEncoding(buf);
-    extractTE(buf);
+    extractCommand(*buf);
+    extractAccept(*buf);
+    extractMethod(*buf);
+    extractReferer(*buf);
+    extractHost(*buf);
+    extractAgent(*buf);
+    extractLanguage(*buf);
+    extractCharset(*buf);
+    extractConnection(*buf);
+    extractKeepAlive(*buf);
+    extractEncoding(*buf);
+    extractTE(*buf);
 
     _filespec = _url;
 
@@ -874,9 +878,21 @@
         return _method;
     }
     _url = body.substr(start+1, end-start-1);
-    _version = body.substr(end+1, length);
-
-    cerr << "HTTP version is: " << _version << endl;
+
+    // HTTP 1.0 doesn't support persistant connections by default.
+    if (body.substr(end+6, 3) == "1.0") {
+       log_debug("Disbling Keep Alive for default");
+       _version = 1.0;
+       _keepalive = false;
+    }
+    // HTTP 1.1 does support persistant connections by default.
+    if (body.substr(end+6, 3) == "1.1") {
+       log_debug("Enabling Keep Alive for default");
+       _version = 1.1;
+       _keepalive = true;
+    }    
+
+    log_debug("HTTP version is: HTTP %g", _version);
     end = _url.find("?", 0);
 //    _filespec = _url.substr(start+1, end);
     return _method;
@@ -943,6 +959,7 @@
        _connections.push_back(substr);
        // Opera uses upper case first letters, Firefox doesn't.
        if ((substr == "Keep-Alive") || (substr == "keep-alive")) {
+           log_debug("Got a Keep Alive in field!");
            _keepalive = true;
        }
        start = pos;
@@ -974,7 +991,7 @@
     }
     end =  body.find("\r\n", start);
     if (end == string::npos) {
-       end = body.find("\n", start);
+       end = body.size();
 //         return "error";
     }
 
@@ -1009,7 +1026,15 @@
     return _connections.size();
 }
 
-int
+// KeepAlive directive
+// Syntax: (Apache 1.1) KeepAlive max-requests
+// Default: (Apache 1.1) KeepAlive 5
+// Syntax: (Apache 1.2) KeepAlive on|off
+// Default: (Apache 1.2) KeepAlive On
+// Context: server config
+// Status: Core
+// Compatibility: KeepAlive is only available in Apache 1.1 and later. 
+bool
 HTTP::extractKeepAlive(Network::byte_t *data)
 {
     GNASH_REPORT_FUNCTION;
@@ -1022,33 +1047,32 @@
     if (start == string::npos) {
         return -1;
     }
+
+    log_debug("Got a Keep Alive!");
     end =  body.find("\r\n", start);
     if (end == string::npos) {
-       end = body.find("\n", start);
+       end = body.size();
 //         return "error";
     }
 
     length = end-start-pattern.size();
     start = start+pattern.size();
-    string _connection = body.substr(start, length);
-    pos = start;
-    while (pos <= end) {
-       pos = (body.find(",", start) + 2);
-       if (pos <= start) {
-           return _encoding.size();
-       }
-       if ((pos == string::npos) || (pos > end)) {
-           length = end - start;
-       } else {
-           length = pos - start - 2;
-       }
-       string substr = body.substr(start, length);
-       _kalive.push_back(substr);
-       _keepalive = true;      // if we get this header setting, we want to 
keep alive
-       start = pos;
-    }
+    string tmp = body.substr(start, length);
 
-    return _connections.size();
+    std::transform(tmp.begin(), tmp.end(), tmp.begin(), 
+               (int(*)(int)) toupper);
+    if ((tmp[0] >= '0') && (tmp[0] <= '9')) {
+       _max_requests = strtol(tmp.c_str(), NULL, 0);
+       _keepalive = true;      // if we get this header setting, we want to 
keep alive 
+    }    
+    if (tmp == "ON") {
+       _keepalive = true;      // if we get this header setting, we want to 
keep alive 
+    }
+    if (tmp == "OFF") {
+       _keepalive = false;     // if we get this header setting, we want to 
not keep alive     
+    }
+    
+    return _keepalive;
 }
 
 string &
@@ -1442,7 +1466,7 @@
     log_debug (_("==== The HTTP header breaks down as follows: ===="));
     log_debug (_("Filespec: %s"), _filespec.c_str());
     log_debug (_("URL: %s"), _url.c_str());
-    log_debug (_("Version: %s"), _version.c_str());
+    log_debug (_("Version: %g"), _version);
     for (it = _accept.begin(); it != _accept.end(); it++) {
         log_debug("Accept param: \"%s\"", (*(it)).c_str());
     }

=== modified file 'libnet/http.h'
--- a/libnet/http.h     2008-11-19 17:42:19 +0000
+++ b/libnet/http.h     2008-11-22 00:28:11 +0000
@@ -138,58 +138,54 @@
     // 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(boost::shared_ptr<amf::Buffer> data)
-       { return extractRTMPT(data->reference()); };
+    rtmpt_cmd_e extractRTMPT(amf::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(boost::shared_ptr<amf::Buffer> data)
-       { return extractCommand(data->reference()); };
+    http_method_e extractCommand(amf::Buffer &data)
+       { return extractCommand(data.reference()); };
     int extractAccept(gnash::Network::byte_t *data);
-    int extractAccept(boost::shared_ptr<amf::Buffer> data)
-       { return extractAccept(data->reference()); };
+    int extractAccept(amf::Buffer &data)
+       { return extractAccept(data.reference()); };
     std::string &extractAcceptRanges(gnash::Network::byte_t *data);
-    std::string &extractAcceptRanges(boost::shared_ptr<amf::Buffer> data)
-       { return extractAcceptRanges(data->reference()); };
-
-    
+    std::string &extractAcceptRanges(amf::Buffer &data)
+       { return extractAcceptRanges(data.reference()); };
     int extractField(const std::string &name, gnash::Network::byte_t *data);
     int extractField(const std::string &name, amf::Buffer *data);
-
-    
     int extractLanguage(gnash::Network::byte_t *data);
-    int extractLanguage(boost::shared_ptr<amf::Buffer> data)
-       { return extractLanguage(data->reference()); };
+    int extractLanguage(amf::Buffer &data)
+       { return extractLanguage(data.reference()); };
     int extractCharset(gnash::Network::byte_t *data);
-    int extractCharset(boost::shared_ptr<amf::Buffer> data)
-       { return extractCharset(data->reference()); };
+    int extractCharset(amf::Buffer &data)
+       { return extractCharset(data.reference()); };
     int extractEncoding(gnash::Network::byte_t *data);
-    int extractEncoding(boost::shared_ptr<amf::Buffer> data)
-       { return extractEncoding(data->reference()); };
+    int extractEncoding(amf::Buffer &data)
+       { return extractEncoding(data.reference()); };
     int extractTE(gnash::Network::byte_t *data);
-    int extractTE(boost::shared_ptr<amf::Buffer> data)
-       { return extractTE(data->reference()); };
+    int extractTE(amf::Buffer &data)
+       { return extractTE(data.reference()); };
     int extractConnection(gnash::Network::byte_t *data);
-    int extractConnection(boost::shared_ptr<amf::Buffer> data)
-       { return extractConnection(data->reference()); };
-    int extractKeepAlive(gnash::Network::byte_t *data);
-    int extractKeepAlive(boost::shared_ptr<amf::Buffer> data)
-       { return extractKeepAlive(data->reference()); };
+    int extractConnection(amf::Buffer &data)
+       { return extractConnection(data.reference()); };
+    bool extractKeepAlive(gnash::Network::byte_t *data);
+    bool extractKeepAlive(amf::Buffer &data)
+       { return extractKeepAlive(data.reference()); };
 
     // These return the string that was found for this field.
     std::string &extractMethod(gnash::Network::byte_t *data);
-    std::string &extractMethod(boost::shared_ptr<amf::Buffer> data)
-       { return extractMethod(data->reference()); };
+    std::string &extractMethod(amf::Buffer &data)
+       { return extractMethod(data.reference()); };
     std::string &extractReferer(gnash::Network::byte_t *data);
-    std::string &extractReferer(boost::shared_ptr<amf::Buffer> data)
-       { return extractReferer(data->reference()); };
+    std::string &extractReferer(amf::Buffer &data)
+       { return extractReferer(data.reference()); };
     std::string &extractHost(gnash::Network::byte_t *data);
-    std::string &extractHost(boost::shared_ptr<amf::Buffer> data)
-       { return extractHost(data->reference()); };
+    std::string &extractHost(amf::Buffer &data)
+       { return extractHost(data.reference()); };
     std::string &extractAgent(gnash::Network::byte_t *data);
-    std::string &extractAgent(boost::shared_ptr<amf::Buffer> data)
-       { return extractAgent(data->reference()); };
+    std::string &extractAgent(amf::Buffer &data)
+       { return extractAgent(data.reference()); };
 
     /// @note These methods add data to the fields in the HTTP header.
     /// \brief clear the data in the stored header
@@ -290,12 +286,13 @@
     
     // These accessors are used mostly just for debugging.
     bool keepAlive() { return _keepalive; }
+    int getMaxRequests() { return _max_requests; }
     int getFileSize() { return _filesize; }
     std::string &getFilespec() { return _filespec; }
     std::string &getURL() { return _url; }
     std::map<int, struct status_codes *> getStatusCodes()
        { return _status_codes; }
-    std::string getVersion() { return _version; }
+    double getVersion() { return _version; }
     std::string getMethod() { return _method; }
     std::string getReferer() { return _referer; }
 
@@ -306,7 +303,7 @@
     std::vector<std::string> getCharset() { return _charset; }
     std::vector<std::string> getEncoding() { return _encoding; }
 
-    int         getHostPort(){ return _port; }
+    int getHostPort(){ return _port; }
     std::string getHost() { return _host; }
     std::string getUserAgent() { return _agent; }
 
@@ -323,7 +320,7 @@
     std::string                _url;
     std::map<int, struct status_codes *> _status_codes;
 //    std::map<std::string, std::string> DSOEXPORT _datafields;  
-    std::string                _version;
+    double             _version;
     std::string                _method;
     std::string                _referer;
     std::string                _host;
@@ -345,6 +342,7 @@
     // These two field hold the data from an RTMPT message
     int                _clientid;
     int                _index;
+    int                _max_requests;
 //    bool     _te;
 };  
 

=== modified file 'testsuite/libnet.all/test_http.cpp'
--- a/testsuite/libnet.all/test_http.cpp        2008-04-02 01:06:57 +0000
+++ b/testsuite/libnet.all/test_http.cpp        2008-11-22 00:28:11 +0000
@@ -273,7 +273,7 @@
     http.clearHeader();
     http.formatHeader(HTTP::LIFE_IS_GOOD);
 //    cerr << "FIXME: " << http.getHeader() << endl;
-    regcomp (&regex_pat, "HTTP/1.1 200 
OK.*Date:.*Server:.*:.*-Length.*-Type:.*$",
+    regcomp (&regex_pat, "HTTP/1.* 200 
OK.*Date:.*Server:.*:.*-Length.*-Type:.*$",
              REG_NOSUB);        // note that we do want to look for NL
     if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) 
{
         runtest.fail ("HTTP::formatHeader(port)");
@@ -333,7 +333,52 @@
 // Connection: keep-alive
 
 // User Agent: Lynx/2.8.6rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8b
-    
+
+    Network::byte_t *field1 = (Network::byte_t *)"GET /index.html HTTP/1.1";
+    HTTP http1;
+    http1.extractMethod(field1);
+    if ((http1.keepAlive() == true) && (http1.getVersion() == 1.1)) {
+        runtest.pass ("HTTP::extractMethod(HTTP/1.1)");
+    } else {
+        runtest.fail ("HTTP::extractMethod(HTTP/1.1)");
+    }
+
+    Network::byte_t *field2 = (Network::byte_t *)"GET /index.html HTTP/1.0";
+    HTTP http2;
+    http2.extractMethod(field2);
+    if ((http2.keepAlive() == false) && (http2.getVersion() == 1.0)) {
+        runtest.pass ("HTTP::extractMethod(HTTP/1.0)");
+    } else {
+        runtest.fail ("HTTP::extractMethod(HTTP/1.0)");
+    }
+
+    Network::byte_t *field3 = (Network::byte_t *) "Keep-Alive: 300";
+    HTTP http3;
+    http3.extractKeepAlive(field3);
+    if ((http3.keepAlive() == true) && (http3.getMaxRequests() == 300)) {
+        runtest.pass ("HTTP::extractKeepAlive(300)");
+    } else {
+        runtest.fail ("HTTP::extractKeepAlive(300)");
+    }
+    
+    Network::byte_t *field4 = (Network::byte_t *) "Keep-Alive: On";
+    HTTP http4;
+    http4.extractKeepAlive(field4);
+    if (http4.keepAlive() == true) {
+        runtest.pass ("HTTP::extractKeepAlive(On)");
+    } else {
+        runtest.fail ("HTTP::extractKeepAlive(On)");
+    }
+    
+    Network::byte_t *field5 = (Network::byte_t *) "Keep-Alive: Off";
+    HTTP http5;
+    http5.extractKeepAlive(field5);
+    if (http5.keepAlive() == false) {
+        runtest.pass ("HTTP::extractKeepAlive(Off)");
+    } else {
+        runtest.fail ("HTTP::extractKeepAlive(Off)");
+    }
+
 // Some browsers have a different synatax, of course, to keep things
 // interesting.
     Network::byte_t *buffer2 = (Network::byte_t *)"GET 
/software/gnash/tests/flvplayer.swf?file=http://localhost/software/gnash/tests/Ouray_Ice_Festival_Climbing_Competition.flv
 HTTP/1.1\r\n)"


reply via email to

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