gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/rtmp r9776: Process Header fields into an


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9776: Process Header fields into an array, not seperate variables.
Date: Sun, 23 Nov 2008 19:32:35 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9776
committer: address@hidden
branch nick: rtmp
timestamp: Sun 2008-11-23 19:32:35 -0700
message:
  Process Header fields into an array, not seperate variables.
  Add method to extract list of values in header field.
modified:
  libnet/http.cpp
  libnet/http.h
=== modified file 'libnet/http.cpp'
--- a/libnet/http.cpp   2008-11-22 05:12:52 +0000
+++ b/libnet/http.cpp   2008-11-24 02:32:35 +0000
@@ -25,6 +25,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/shared_array.hpp>
 #include <boost/scoped_array.hpp>
+#include <boost/tokenizer.hpp>
 //#include <boost/date_time/local_time/local_time.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/date_time/gregorian/gregorian.hpp>
@@ -231,20 +232,30 @@
        log_debug("Que empty, net connection dropped for fd #%d", getFileFd());
        return false;
     }
-    
+    return processPostRequest();
+}
+
+// The order in which header fields with differing field names are
+// received is not significant. However, it is "good practice" to send
+// general-header fields first, followed by request-header or
+// response- header fields, and ending with the entity-header fields.
+bool
+HTTP::processPostRequest(amf::Buffer &buf)
+{
+    GNASH_REPORT_FUNCTION;
     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;
 
@@ -254,6 +265,116 @@
     return false;
 }
 
+// http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5 (5.3 Request 
Header Fields)
+bool
+HTTP::processRequestFields(amf::Buffer &buf)
+{
+//    GNASH_REPORT_FUNCTION;
+
+    const char *foo[] = {
+       "Accept",
+       "Accept-Charset",
+       "Accept-Encoding",
+       "Accept-Language",
+       "Authorization",
+       "Expect",
+       "From",
+       "Host",
+       "If-Match",
+       "If-Modified-Since",
+       "If-None-Match",
+       "If-Range",
+       "If-Unmodified-Since",
+       "Max-Forwards",
+       "Proxy-Authorization",
+       "Range",
+       "Referer",
+       "TE",
+       "User-Agent",
+       0
+       };
+}
+
+// http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec7 (7.1 Entity 
Header Fields)
+bool
+HTTP::processEntityFields(amf::Buffer &buf)
+{
+//    GNASH_REPORT_FUNCTION;
+
+    const char *foo[] = {
+       "Accept",
+       "Allow",
+       "Content-Encoding",
+       "Content-Language",
+       "Content-Length",       // Must be used when sending a Response
+       "Content-Location",
+       "Content-MD5",
+       "Content-Range",
+       "Content-Type",         // Must be used when sending non text/html files
+       "Expires",
+       "Last-Modified",
+       0
+       };
+    
+    return true;
+
+}
+
+bool
+HTTP::processHeaderFields(amf::Buffer &buf)
+{
+//    GNASH_REPORT_FUNCTION;
+    string head(reinterpret_cast<const char *>(buf.reference()));
+    Tok t(head, Sep("\r\n"));
+    for (Tok::iterator i = t.begin(), e = t.end(); i != e; ++i) {
+       string::size_type pos = i->find(":", 0);
+       if (pos != string::npos) {
+           string name = i->substr(0, pos);
+           string value = i->substr(pos+2, i->size());
+           std::transform(name.begin(), name.end(), name.begin(), 
+                          (int(*)(int)) tolower);
+           std::transform(value.begin(), value.end(), value.begin(), 
+                          (int(*)(int)) tolower);
+           _fields[name] = value;          
+       }
+    }
+    
+    return true;
+}
+
+boost::shared_ptr<std::vector<std::string> >
+HTTP::getFieldItem(const std::string &name)
+{
+//    GNASH_REPORT_FUNCTION;
+    boost::shared_ptr<std::vector<std::string> > ptr(new 
std::vector<std::string>);
+    Tok t(_fields[name], Sep(", "));
+    for (Tok::iterator i = t.begin(), e = t.end(); i != e; ++i) {
+       ptr->push_back(*i);
+    }
+
+    return ptr;
+}
+
+// http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec4 (4.5 General 
Header Fields)
+bool
+HTTP::processGeneralFields(amf::Buffer &buf)
+{
+//    GNASH_REPORT_FUNCTION;
+
+    const char *foo[] = {
+       "Cache-Control"
+       "Connection",           // Must look for Keep-Alive and close
+       "Date",
+       "Pragma",
+       "Trailer",
+       "Transfer-Encoding",    // Must look for Chunked-Body too
+       "Upgrade",
+       "Via",
+       "Warning",
+       0
+       };
+}
+
 bool
 HTTP::startHeader()
 {
@@ -882,17 +1003,19 @@
     // 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;
+       _version.major = 1;
+       _version.minor = 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;
+       _version.major = 1;
+       _version.minor = 1;
        _keepalive = true;
     }    
 
-    log_debug("HTTP version is: HTTP %g", _version);
+    log_debug("HTTP version is: HTTP %d.%d", _version.major, _version.minor);
     end = _url.find("?", 0);
 //    _filespec = _url.substr(start+1, end);
     return _method;
@@ -1466,7 +1589,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: %g"), _version);
+    log_debug (_("Version: %d.%d"), _version.major, _version.minor);
     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-22 00:28:11 +0000
+++ b/libnet/http.h     2008-11-24 02:32:35 +0000
@@ -114,6 +114,10 @@
         const char *code;
         const char *msg;
     };
+    typedef struct {
+       int major;
+       int minor;
+    } http_version_t;
     HTTP();
     HTTP(Handler *hand);
     ~HTTP();
@@ -122,7 +126,17 @@
     bool processClientRequest();
     bool processGetRequest();
     bool processPostRequest();
+    bool processPostRequest(amf::Buffer &buf);
+
+    bool processRequestFields(amf::Buffer &buf);
+    bool processEntityFields(amf::Buffer &buf);
+    bool processGeneralFields(amf::Buffer &buf);
+    bool processHeaderFields(amf::Buffer &buf);
+    
 //    bool processPostRequest(gnash::Network &net);
+
+    std::string &getField(const std::string &name) { return _fields[name]; };
+    boost::shared_ptr<std::vector<std::string> > getFieldItem(const 
std::string &name);
     
     // Handle the GET request response
     boost::shared_ptr<amf::Buffer> formatServerReply(http_status_e code);
@@ -292,9 +306,10 @@
     std::string &getURL() { return _url; }
     std::map<int, struct status_codes *> getStatusCodes()
        { return _status_codes; }
-    double getVersion() { return _version; }
+    http_version_t &getVersion() { return _version; }
     std::string getMethod() { return _method; }
     std::string getReferer() { return _referer; }
+    std::string getCommand() { return _command; }
 
     std::vector<std::string> getLanguage() { return _language;  }
     std::vector<std::string> getConnection() { return _connections; }
@@ -310,6 +325,9 @@
     void setHandler(Handler *hand) { _handler = hand; };
     
 private:
+    typedef boost::char_separator<char> Sep;
+    typedef boost::tokenizer<Sep> Tok;
+
     CQue               _que;
     std::stringstream  _header;
     std::stringstream  _body;
@@ -319,15 +337,17 @@
     int                        _filesize;
     std::string                _url;
     std::map<int, struct status_codes *> _status_codes;
-//    std::map<std::string, std::string> DSOEXPORT _datafields;  
-    double             _version;
+    
+    std::map<std::string, std::string> DSOEXPORT _fields;
+    http_version_t     _version;
+    
     std::string                _method;
     std::string                _referer;
     std::string                _host;
     int                        _port;
     std::string                _agent;
     std::string                _acceptranges;
-    std::map<std::string, std::vector<std::string> > _fields;  
+    
     std::vector<std::string> _connections;
     std::vector<std::string> _language;
     std::vector<std::string> _charset;


reply via email to

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