gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/rtmp r9778: Return the location of the dat


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9778: Return the location of the data when processing header fields.
Date: Sun, 23 Nov 2008 21:11:30 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9778
committer: address@hidden
branch nick: rtmp
timestamp: Sun 2008-11-23 21:11:30 -0700
message:
  Return the location of the data when processing header fields.
  Tweak the test case to have "\r\n" at the end of each header line.
  Process the data in a field.
modified:
  libnet/http.cpp
  libnet/http.h
  testsuite/libnet.all/test_http.cpp
=== modified file 'libnet/http.cpp'
--- a/libnet/http.cpp   2008-11-24 02:32:35 +0000
+++ b/libnet/http.cpp   2008-11-24 04:11:30 +0000
@@ -320,13 +320,16 @@
 
 }
 
-bool
+gnash::Network::byte_t *
 HTTP::processHeaderFields(amf::Buffer &buf)
 {
 //    GNASH_REPORT_FUNCTION;
     string head(reinterpret_cast<const char *>(buf.reference()));
+    // The end of the header block is always followed by a blank line
+    string::size_type end = head.find("\r\n\r\n", 0);
+    head.erase(end, buf.size()-end);
     Tok t(head, Sep("\r\n"));
-    for (Tok::iterator i = t.begin(), e = t.end(); i != e; ++i) {
+    for (Tok::iterator i = t.begin(); i != t.end(); ++i) {
        string::size_type pos = i->find(":", 0);
        if (pos != string::npos) {
            string name = i->substr(0, pos);
@@ -335,11 +338,16 @@
                           (int(*)(int)) tolower);
            std::transform(value.begin(), value.end(), value.begin(), 
                           (int(*)(int)) tolower);
-           _fields[name] = value;          
+           _fields[name] = value;
+       } else {
+           const gnash::Network::byte_t *cmd = reinterpret_cast<const 
gnash::Network::byte_t *>(i->c_str());
+           if (extractCommand(const_cast<gnash::Network::byte_t *>(cmd)) == 
HTTP::HTTP_NONE) {
+               break;
+           }
        }
     }
     
-    return true;
+    return buf.reference() + end + 4;
 }
 
 boost::shared_ptr<std::vector<std::string> >
@@ -919,38 +927,46 @@
     start = body.find("GET", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_GET;
+       return cmd;
     }
     start = body.find("POST", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_POST;
+       return cmd;
     }
     start = body.find("HEAD", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_HEAD;
+       return cmd;
     }
     start = body.find("CONNECT", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_CONNECT;
+       return cmd;
     }
     start = body.find("TRACE", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_TRACE;
+       return cmd;
     }
     start = body.find("OPTIONS", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_OPTIONS;
+       return cmd;
     }
     start = body.find("PUT", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_PUT;
+       return cmd;
     }
     start = body.find("DELETE", 0);
     if (start != string::npos) {
         cmd = HTTP::HTTP_DELETE;
+       return cmd;
     }
 
-    _command = cmd;
-    return cmd;
+//    _command = cmd;
+    return HTTP::HTTP_NONE;
 }
 
 string &

=== modified file 'libnet/http.h'
--- a/libnet/http.h     2008-11-24 02:32:35 +0000
+++ b/libnet/http.h     2008-11-24 04:11:30 +0000
@@ -95,6 +95,7 @@
        CLOSEPIPE = 1235
     } http_status_e;
     typedef enum {
+       HTTP_NONE,
         HTTP_OPTIONS,
         HTTP_GET,
         HTTP_HEAD,
@@ -131,7 +132,7 @@
     bool processRequestFields(amf::Buffer &buf);
     bool processEntityFields(amf::Buffer &buf);
     bool processGeneralFields(amf::Buffer &buf);
-    bool processHeaderFields(amf::Buffer &buf);
+    gnash::Network::byte_t *processHeaderFields(amf::Buffer &buf);
     
 //    bool processPostRequest(gnash::Network &net);
 
@@ -160,6 +161,7 @@
     http_method_e extractCommand(gnash::Network::byte_t *data);
     http_method_e extractCommand(amf::Buffer &data)
        { return extractCommand(data.reference()); };
+    
     int extractAccept(gnash::Network::byte_t *data);
     int extractAccept(amf::Buffer &data)
        { return extractAccept(data.reference()); };

=== modified file 'testsuite/libnet.all/test_http.cpp'
--- a/testsuite/libnet.all/test_http.cpp        2008-11-24 02:33:51 +0000
+++ b/testsuite/libnet.all/test_http.cpp        2008-11-24 04:11:30 +0000
@@ -525,18 +525,21 @@
 
     HTTP http;
     amf::Buffer ptr1;
-    ptr1 = "POST /echo/gateway HTTP/1.1";
-    ptr1 += "User-Agent: Opera/9.62 (X11; Linux i686; U; en) Presto/2.1.1";
-    ptr1 += "Host: localhost:4080";
-    ptr1 += "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, 
image/png, image/jpeg, image/gif, image/x-xbitmap;q=0.1";
-    ptr1 += "Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0";
-    ptr1 += "Referer: http://localhost:5080/demos/echo_test.swf";;
-    ptr1 += "Connection: Keep-Alive, TE";
-    ptr1 += "Content-Length: 26";
-    ptr1 += "Content-Type: application/x-amf";
+    ptr1 = "POST /echo/gateway HTTP/1.1\r\n";
+    ptr1 += "User-Agent: Opera/9.62 (X11; Linux i686; U; en) Presto/2.1.1\r\n";
+    ptr1 += "Host: localhost:4080\r\n";
+    ptr1 += "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, 
image/png, image/jpeg, image/gif, image/x-xbitmap;q=0.1\r\n";
+    ptr1 += "Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\r\n";
+    ptr1 += "Referer: http://localhost:5080/demos/echo_test.swf\r\n";;
+    ptr1 += "Connection: Keep-Alive, TE\r\n";
+    ptr1 += "Content-Length: 26\r\n";
+    ptr1 += "Content-Type: application/x-amf\r\n";
+    ptr1 += "\r\n";
+    ptr1 += "foobar";
+    ptr1.resize();
     
     amf::Buffer ptr2;
-    ptr2 += "POST./echo/gateway.HTTP/1.1\r\n";
+    ptr2 += "POST /echo/gateway HTTP/1.1\r\n";
     ptr2 += "User-Agent: Opera/9.62.(X11;.Linux.i686;.U;.en) Presto/2.1.1\r\n";
     ptr2 += "Host: localhost:5080\r\n";
     ptr2 += "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, 
image/png, image/jpeg, image/gif, image/x-xbitmap\r\n";
@@ -547,6 +550,9 @@
     ptr2 += "Connection: Keep-Alive, TE. TE: deflate, gzip, chunked, identity, 
trailers\r\n";
     ptr2 += "Content-Length:.35\r\n";
     ptr2 += "Content-Type: application/x-amf\r\n";
+    ptr2 += "\r\n";
+    ptr2 += "foobar";
+    ptr2.resize();
 
 #if 0
 2...........echo../2............ Hello.world!
@@ -559,9 +565,9 @@
    02 00 0c 48 65 6c 6c 6f 20 77 6f 72 6c 64 21
 #endif
         
-    http.processHeaderFields(ptr2);
+    gnash::Network::byte_t *data2 = http.processHeaderFields(ptr2);
     if ((http.getField("host") == "localhost:5080")
-        && (http.getField("content-type") == "application/x-amf")
+        && (memcmp(data2, "foobar", 6) == 0)
         && (http.getField("content-length") == "35")) {
         runtest.pass("HTTP::processHeaderFields(POST)");
     } else {


reply via email to

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