gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash utilities/dumpshm.cpp testsuite/libamf.al...


From: Rob Savoye
Subject: [Gnash-commit] gnash utilities/dumpshm.cpp testsuite/libamf.al...
Date: Fri, 25 Jan 2008 18:08:00 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    08/01/25 18:08:00

Modified files:
        utilities      : dumpshm.cpp 
        testsuite/libamf.all: test_lc.cpp 
        .              : ChangeLog 
        libbase        : shm.cpp shm.h 
        libamf         : amf.cpp element.cpp element.h lcshm.cpp lcshm.h 

Log message:
                * libamf/amf.cpp: Make extractElement() only process a single
                element instead of looping.
                * libamf/element.{h,cpp}: Convert the element in common data
                types. Add methods for creating special AMF objects.
                * libamf/lcshm.{cpp,h}: Add better support for SYSV style memory
                segments. Tweak parseHeader() to only grab the header, and not
                any of the AMF elements in the body. Also parse the header and 
the
                body of the memory segment when connecting. Add dump() method.
                * libbase/shm.{cpp,h}: Move SYSV style memory support to it's 
own
                method to reduce ifdef spagetti.
                * utilities/dumpshm.cpp: Use rewritten LcShm class instead of
                handling the segment directly.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/dumpshm.cpp?cvsroot=gnash&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libamf.all/test_lc.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5494&r2=1.5495
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/shm.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/shm.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.cpp?cvsroot=gnash&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/lcshm.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/lcshm.h?cvsroot=gnash&r1=1.4&r2=1.5

Patches:
Index: utilities/dumpshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/utilities/dumpshm.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- utilities/dumpshm.cpp       21 Jan 2008 23:29:46 -0000      1.20
+++ utilities/dumpshm.cpp       25 Jan 2008 18:07:58 -0000      1.21
@@ -336,54 +336,32 @@
        cerr << "No shared memory segments found!" << endl;
        return;
     }
-    log_msg("SHM Key 0x%x", key);
+//    log_msg("SHM Key 0x%x", key);
   
     int size = 64528;                  // 1007 bytes less than unsigned
     int flags = 0660 | IPC_CREAT;
     int total = 0;
     
-    id = shmget(key, size, flags);
-    if (id < 0) {
-       cerr << "shmget() failed!: " <<  strerror(errno) << endl;
-       return;
-    }
-
-    shmaddr = (char *)shmat (id, 0, SHM_RDONLY); // attach segment for reading
-    if (shmaddr == (char *)-1) {
-       cerr << "shmat() failed!: " <<  strerror(errno) << endl;
-       return;
-    }
-
-    Listener list(reinterpret_cast<boost::uint8_t *>(shmaddr));
-    vector<string>::const_iterator it;
-    vector<string> *listeners = list.listListeners();
-    if (listeners->size() == 0) {
-        cout << "Nobody is listening" << endl;
-    } else {
-        for (it=listeners->begin(); it!=listeners->end(); it++) {
-            string str = *it;
-           if ((str[0] != ':') || (verbosity > 0)) {
-               cout << " Listeners: " << str << endl;
-               total++;
-           }
-        }
-    }
+    LcShm lc;
+    lc.connect(key);
+    vector<string> *listeners = lc.listListeners();
+    cout << "There are " << listeners->size() << " Listeners listening" << 
endl; 
+    lc.dump();
     
-    cout << "There are " << total << " Listeners listening" << endl; 
     // If the -c convert options was specified, dump the memory segment to 
disk.
     // This makes it easy to store them as well as to examine them in great 
detail.
     if (convert) {
-       //char buf[size+1];
        int fd = open("segment.raw",O_WRONLY|O_CREAT, S_IRWXU);
        if (fd == -1) {
            perror("open");
        }
+       cout << "Writing memory segment to disk: \"segment.raw\"" << endl;
        write(fd, shmaddr, size);
        close(fd);
     }
     
-    shmdt (shmaddr);           // detach segment
-    exit (0);                  // quit leaving resource allocated
+    delete listeners;
+    exit (0);
 }
 
 key_t

Index: testsuite/libamf.all/test_lc.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libamf.all/test_lc.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- testsuite/libamf.all/test_lc.cpp    21 Jan 2008 23:26:49 -0000      1.2
+++ testsuite/libamf.all/test_lc.cpp    25 Jan 2008 18:07:58 -0000      1.3
@@ -123,11 +123,13 @@
     srcdir += "/segment.raw";
     int fd = ::open(srcdir.c_str(), O_RDONLY);
     void *dataptr = static_cast<unsigned char *>(mmap(0, 64528, PROT_READ, 
MAP_SHARED, fd, 0));
+#if 0
     if (dataptr != (void *)0xffffffff) {
         memcpy(shmaddr, dataptr, 64528);
     } else {
         cerr << "ERROR: couldn't map input file!" << endl;
     }
+#endif
     ::close(fd);
     
     Listener list(reinterpret_cast<uint8_t *>(shmaddr));
@@ -153,7 +155,7 @@
     }
     
     
-    list.addListener(filespec);
+//    list.addListener(filespec);
     listeners = list.listListeners();
     if (listeners->size() == 0) {
         cout << "Nobody is listening" << endl;
@@ -168,7 +170,9 @@
     }
 
     boost::uint8_t *ptr = lc.parseHeader(reinterpret_cast<boost::uint8_t 
*>(shmaddr));
-    lc.parseBody(ptr);
+    vector<amf::Element *> ellist = lc.parseBody(ptr);
+//    cout << "# of AMF Elements in file: " << ellist.size() << endl;
+//    lc.dump();
 }
 
 bool
@@ -382,3 +386,41 @@
 }
 
 #endif
+
+#if 0 // { // what are these Listeners ?
+
+    Listener::setBaseAddress(Shm::getAddr());
+        
+    string str1 = "HelloWorld";
+    addListener(str1);
+    str1 = "GutenTag";
+    addListener(str1);
+    str1 = "Aloha";
+    addListener(str1);
+    
+    vector<string>::const_iterator it;
+    vector<string> *listeners = listListeners();
+    if (listeners->size() == 0) {
+        log_msg("Nobody is listening");
+    } else {
+        log_msg("There are %d", listeners->size());
+        for (it=listeners->begin(); it!=listeners->end(); it++) {
+            string str = *it;
+            log_debug("Listeners: %s", str.c_str());
+        }
+    }
+
+    delete listeners;
+    
+    str1 = "HelloWorld";
+    removeListener(str1);
+    listeners = listListeners();  
+    log_msg("There are %d", listeners->size());
+    for (it=listeners->begin(); it != listeners->end(); it++) {
+        string str = *it;
+        log_debug("Listeners: %s", str.c_str());
+    }
+    
+    delete listeners;
+#endif // }
+

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5494
retrieving revision 1.5495
diff -u -b -r1.5494 -r1.5495
--- ChangeLog   25 Jan 2008 17:51:27 -0000      1.5494
+++ ChangeLog   25 Jan 2008 18:07:58 -0000      1.5495
@@ -1,3 +1,19 @@
+2008-01-25  Rob Savoye  <address@hidden>
+
+       * libamf/amf.cpp: Make extractElement() only process a single
+       element instead of looping.
+       * libamf/element.{h,cpp}: Convert the element in common data
+       types. Add methods for creating special AMF objects.
+       * libamf/lcshm.{cpp,h}: Add better support for SYSV style memory
+       segments. Tweak parseHeader() to only grab the header, and not
+       any of the AMF elements in the body. Also parse the header and the
+       body of the memory segment when connecting. Add dump() method.
+       * libbase/shm.{cpp,h}: Move SYSV style memory support to it's own
+       method to reduce ifdef spagetti.
+       * utilities/dumpshm.cpp: Use rewritten LcShm class instead of
+       handling the segment directly.
+       * testsuite/libamf.all/test_lc.cpp: 
+
 2008-01-25 Sandro Santilli <address@hidden>
 
        * testsuite/misc-ming.all/place_object_test.c: add more tests (and 

Index: libbase/shm.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/shm.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libbase/shm.cpp     21 Jan 2008 20:55:45 -0000      1.2
+++ libbase/shm.cpp     25 Jan 2008 18:07:59 -0000      1.3
@@ -67,19 +67,69 @@
 
   Shm::Shm() :_addr(0), _alloced(0), _size(0), _shmkey(0), _shmfd(0)
 {
+//    GNASH_REPORT_FUNCTION;
     memset(_filespec, 0, MAX_SHM_NAME_SIZE);
 }
 
 Shm::~Shm()
 {
+//    GNASH_REPORT_FUNCTION;
 }
     
-/// \brief Initialize the shared memory segment
+bool
+Shm::attach()
+{
+//    GNASH_REPORT_FUNCTION;
+    return attach(0, false);
+}
+
+bool
+Shm::attach(key_t key, bool nuke)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+#if defined(USE_SYSV_SHM) && defined(HAVE_SHMGET)
+    const int shmflg = 0660 | IPC_CREAT;
+    // this is the magic size of shared memory segments used by the other 
flash player;
+    _size = 64528;
+    // this is the magic shared memory key used by the other player.
+    if (key != 0) {
+       _shmkey = key;
+    }
+    
+    // If there is no SYSV style shared memory key in the users ~/.gnashrc 
file, warn them
+    // that compatibility will be broken, and then just pick our own key so 
things still work
+    // finer when using just Gnash.
+    if (_shmkey == 0) {
+       log_error("No Shared Memory key specified in ~/.gnashrc! Please run 
\"dumpshm -i\" to find your key if you want to be conpatible with the other swf 
player.");
+       _shmkey = 0xdd3adabd;
+    }
+    
+    _shmfd = shmget(_shmkey, _size, shmflg);
+    if (_shmfd < 0 && errno == EEXIST) {
+       // Get the shared memory id for this segment
+       _shmfd = shmget(_shmkey, _size, 0);
+    }
+    _addr = (char *)shmat(_shmfd, 0, 0);
+    if (_addr <= 0) {
+       log_msg("WARNING: shmat() failed: %s\n", strerror(errno));
+       return false;
+    }
+
+    return true;
+#else
+#error "You need SYSV Shared memory support to use this option"
+#endif  // end of USE_SYSV_SHM
+}      
+
+// \brief Initialize the shared memory segment
 ///
 /// This creates or attaches to an existing shared memory segment.
 bool
 Shm::attach(char const *filespec, bool nuke)
 {
+//    GNASH_REPORT_FUNCTION;
+    
     bool exists = false;
     long addr;
     // #ifdef FLAT_ADDR_SPACE
@@ -352,6 +402,7 @@
 Shm *
 Shm::cloneSelf(void)
 {
+//    GNASH_REPORT_FUNCTION;
 
     if (_addr > 0) {
 //         log_msg("Cloning ShmControl, %d bytes to %p\n",
@@ -372,6 +423,7 @@
 bool
 Shm::resize()
 {
+//    GNASH_REPORT_FUNCTION;
     // Increase the size by 10 %
     return resize(DEFAULT_SHM_SIZE + (DEFAULT_SHM_SIZE/10)); 
 }
@@ -380,6 +432,7 @@
 Shm::resize(int bytes)
     
 {
+//    GNASH_REPORT_FUNCTION;
 #ifdef HAVE_MREMAP
     _addr = mremap(_shmAddr, _shmSize, _shmSize + bytes, MREMAP_MAYMOVE);
     if (_addr != 0) {
@@ -398,6 +451,7 @@
 void *
 Shm::brk(int bytes)
 {
+//    GNASH_REPORT_FUNCTION;
     int wordsize = sizeof(long);
     
     // Adjust the allocated amount of memory to be on a word boundary.
@@ -444,6 +498,7 @@
 bool
 Shm::closeMem()
 {
+//    GNASH_REPORT_FUNCTION;
     // Only nuke the shared memory segement if we're the last one.
 #ifdef USE_POSIX_SHM
 #ifdef HAVE_SHM_UNLINK
@@ -478,6 +533,7 @@
 bool
 Shm::exists()
 {
+//    GNASH_REPORT_FUNCTION;
     struct stat           stats;
     struct dirent         *entry;
     vector<const char *>  dirlist;

Index: libbase/shm.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/shm.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libbase/shm.h       21 Jan 2008 20:55:45 -0000      1.2
+++ libbase/shm.h       25 Jan 2008 18:07:59 -0000      1.3
@@ -61,7 +61,9 @@
     DSOEXPORT ~Shm();
     
     // Initialize the shared memory segment
+    bool attach();
     bool attach(char const *filespec, bool nuke);
+    bool attach(key_t key, bool nuke);
     
     // Resize the allocated memory segment
     bool resize(int bytes);

Index: libamf/amf.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- libamf/amf.cpp      21 Jan 2008 22:55:26 -0000      1.56
+++ libamf/amf.cpp      25 Jan 2008 18:07:59 -0000      1.57
@@ -1368,8 +1368,9 @@
 
 //    return parseBody(_amf_data, _total_size);
 }
+#endif
 
-uint8_t *
+boost::uint8_t *
 AMF::extractElement(Element *el, boost::uint8_t *in)
 {
 //    GNASH_REPORT_FUNCTION;
@@ -1394,6 +1395,7 @@
     hexint =  (boost::uint8_t*) malloc((bytes * 3) + 12);
     hexify((boost::uint8_t *)hexint, (boost::uint8_t *)in, bytes, true);
     log_msg(_("The packet body is: 0x%s"), hexint);
+    free(hexint);
 #endif
 
     tmpptr = in;
@@ -1404,36 +1406,38 @@
 // After the element name there is a type byte. If it's a Number type, then 8 
bytes are read
 // If it's a String type, then there is a count of characters, then the string 
value    
     
-    while (tmpptr  <= (in + bytes)) {
-        memset(buffer, 0, sizeof(buffer));     //FIXME, slow
         // Check the type of the element data
         char type = *(Element::astype_e *)tmpptr;
         tmpptr++;                        // skip the header byte
 
         switch ((Element::astype_e)type) {
           case Element::NUMBER:
-//              memcpy(buffer, tmpptr, 8);
+         el->makeNumber(tmpptr);
               tmpptr += 8;
-              continue;
               break;
           case Element::BOOLEAN:
+         el->makeBoolean(tmpptr);
+         tmpptr += 2;
+         break;
           case Element::STRING:
               // get the length of the name
               length = ntohs((*(short *)tmpptr) & 0xffff);
               tmpptr += 2;
-              log_msg(_("AMF String length is: %d"), length);
+//       log_msg(_("AMF String length is: %d"), length);
+         if (length > 0) {
               // get the name of the element
-              if (length) {
-                  memcpy(buffer, tmpptr, length);
-              }
+             el->makeString(tmpptr, length);
+//           log_msg(_("AMF String is: %s"), el->to_string());
               tmpptr += length;
-              log_msg(_("AMF String is: %s"), buffer);              
-              el.name = buffer;
+         } else {
+             el->setType(Element::STRING);
+             el->setData(0);
+         };
               break;
           case Element::OBJECT:
               do {
-                  tmpptr = extractVariable(&el, tmpptr);
-              } while (el.type != Element::OBJECT_END);
+             tmpptr = extractVariable(el, tmpptr);
+         } while (el->getType() != Element::OBJECT_END);
               break;
           case Element::MOVIECLIP:
           case Element::NULL_VALUE: 
@@ -1452,13 +1456,9 @@
            log_unimpl("%s: type %d", __PRETTY_FUNCTION__, (int)type);
               return 0;
         }
-    }
-
-    free(hexint);
 
-    return 0;
+    return tmpptr;
 }
-#endif
 
 boost::uint8_t *
 AMF::extractVariable(Element *el, boost::uint8_t *in)

Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libamf/element.cpp  21 Jan 2008 22:55:26 -0000      1.6
+++ libamf/element.cpp  25 Jan 2008 18:08:00 -0000      1.7
@@ -191,6 +191,36 @@
     
 }
 
+double
+Element::to_number()
+{
+    if (_data) {
+       return *(reinterpret_cast<double *>(_data));
+    }
+    return nan("NaN");
+}
+
+const char *
+Element::to_string()
+{
+    return reinterpret_cast<const char *>(_data);
+};
+
+bool
+Element::to_bool()
+{
+    if (_data) {
+       return *(reinterpret_cast<bool *>(_data));
+    }
+    return false;
+};
+
+void *
+Element::to_reference()
+{
+    return reinterpret_cast<void *>(_data);
+};
+
 Element &
 Element::operator=(Element &el)
 {
@@ -232,6 +262,44 @@
 }
 
 Element &
+Element::makeString(boost::uint8_t *data, int size)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+    _type = Element::STRING;
+    _length = size;
+    _data = new boost::uint8_t[size+1];
+    memset(_data, 0, size+1);
+    memcpy(_data, data, size);
+    return *this;
+}
+
+Element &
+Element::makeNumber(boost::uint8_t *data)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+    _type = Element::NUMBER;
+    _length = amf::AMF_NUMBER_SIZE;
+    _data = new boost::uint8_t[amf::AMF_NUMBER_SIZE];
+    memcpy(_data, data, amf::AMF_NUMBER_SIZE);
+    return *this;
+}
+
+Element &
+Element::makeBoolean(boost::uint8_t *data)
+{
+//    GNASH_REPORT_FUNCTION;
+    
+    _type = Element::BOOLEAN;
+    _length = 1;
+    _data = new boost::uint8_t[2];
+    memset(_data, 0, 2);
+    memcpy(_data, data+1, 1);
+    return *this;
+}
+
+Element &
 Element::makeUndefined()
 {
     return makeUndefined("");
@@ -417,17 +485,53 @@
 void
 Element::dump()
 {
-    log_debug("AMF Type is: %s", astype_str[_type]);
-    log_debug("AMF Length is: %d", _length);
+//    GNASH_REPORT_FUNCTION;
+    
     if (_name.size()) {
-       log_debug("AMF Name is: %s", _name.c_str());
+       cerr << "Dumping AMF Varible: " << _name << endl;
     }
-#if 0
+
+    cerr << astype_str[_type] << ": ";
+
+    switch (_type) {
+      case Element::NUMBER:
+         cerr << "AMF Numeric value: " << to_number() << endl;
+         break;
+      case Element::BOOLEAN:
+         cerr << "AMF Boolean value: " << (to_bool() ? "true" : "false") << 
endl;
+         break;
+      case Element::STRING:
+         cerr << "(" << _length << " bytes): ";
+         if (_length > 0) {
+             cerr << "\t\"" << to_string() << "\"" << endl;
+         } else {
+             cerr << endl;
+         }
+         break;
+      case Element::OBJECT:
+         break;
+      case Element::MOVIECLIP:
+      case Element::NULL_VALUE: 
+      case Element::UNDEFINED:
+      case Element::REFERENCE:
+      case Element::ECMA_ARRAY:
+      case Element::OBJECT_END:
+      case Element::STRICT_ARRAY:
+      case Element::DATE:
+      case Element::LONG_STRING:
+      case Element::UNSUPPORTED:
+      case Element::RECORD_SET:
+      case Element::XML_OBJECT:
+      case Element::TYPED_OBJECT:
     boost::uint8_t *hexint;
     hexint = new boost::uint8_t[(_length + 3) * 3];
     hexify((boost::uint8_t *)hexint, _data, _length, false);
-    log_debug("AMF data is: 0x%s", hexint);
-#endif
+         cerr << "AMF data is: 0x%s" << hexint << endl;
+         break;
+      default:
+         log_unimpl("%s: type %d", __PRETTY_FUNCTION__, (int)_type);
+    }
+    
 }
 
 } // end of amf namespace

Index: libamf/element.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libamf/element.h    21 Jan 2008 22:55:26 -0000      1.6
+++ libamf/element.h    25 Jan 2008 18:08:00 -0000      1.7
@@ -76,6 +76,9 @@
     Element &init(bool data);
 
     // These create the other "special" AMF types.
+    Element &makeString(boost::uint8_t *data, int size); 
+    Element &makeNumber(boost::uint8_t *data); 
+    Element &makeBoolean(boost::uint8_t *data); 
     Element &makeUndefined();
     Element &makeUndefined(const std::string &name);
     Element &makeNull();
@@ -105,10 +108,10 @@
     void setData(boost::uint8_t *x) { _data = x; };
 
     // These accessors convert the raw data to a standard data type we can use.
-    double to_number() { return *(reinterpret_cast<double *>(_data)); };
-    const char *to_string() { return reinterpret_cast<const char *>(_data); };
-    bool to_bool() { return *(reinterpret_cast<bool *>(_data)); };
-    void *to_reference() { return reinterpret_cast<void *>(_data); };
+    double to_number();
+    const char *to_string();
+    bool to_bool();
+    void *to_reference();
     
     boost::uint16_t getLength() { return _length; };
     void setLength(boost::uint16_t x) { _length = x; };

Index: libamf/lcshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/lcshm.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libamf/lcshm.cpp    21 Jan 2008 22:55:26 -0000      1.4
+++ libamf/lcshm.cpp    25 Jan 2008 18:08:00 -0000      1.5
@@ -22,11 +22,15 @@
 
 #include <unistd.h>
 #include <cerrno>
+#include <vector>
+#include <string>
 #include <cstring>
 #include <boost/cstdint.hpp>
 
 #include "log.h"
 #include "amf.h"
+#include "shm.h"
+#include "element.h"
 #include "lcshm.h"
 
 using namespace std;
@@ -55,43 +59,59 @@
 /// each other Flash Objects to be executed.
 ///
 LcShm::LcShm()
+    : _baseaddr(0)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
+}
+
+LcShm::LcShm(boost::uint8_t *addr)
+{
+//    GNASH_REPORT_FUNCTION;
+    _baseaddr = addr;
+}
+
+LcShm::LcShm(key_t key)
+{
+//    GNASH_REPORT_FUNCTION;
+    _shmkey = key;
 }
 
 LcShm::~LcShm()
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
     
     vector<amf::Element *>::iterator it;
     for (it = _amfobjs.begin(); it != _amfobjs.end(); it++) {
        amf::Element *el = (*(it));
+         if (el) {
+//             el->dump();
        delete el;
     }
+    }
 }
 
 Listener::Listener()
     : _baseaddr(0)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
 }
 
 Listener::Listener(boost::uint8_t *x)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
     _baseaddr = x;
 }
 
 Listener::~Listener()
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
 }
 
 // see if a connection name exists in our list of listeners
 bool
 Listener::findListener(std::string &name)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
 
     boost::uint8_t *addr = _baseaddr + LC_LISTENERS_START;
     char *item = reinterpret_cast<char *>(addr);
@@ -166,19 +186,22 @@
     return false;
 }
 
-std::vector<std::string> *
+vector<string> *
 Listener::listListeners()
 {
-    GNASH_REPORT_FUNCTION;
-
+//    GNASH_REPORT_FUNCTION;    
+    vector<string> *listeners = new vector<string>;
+    if (_baseaddr != 0) {
     boost::uint8_t *addr = _baseaddr + LC_LISTENERS_START;
 
-    vector<string> *listeners = new vector<string>;
     const char *item = reinterpret_cast<const char *>(addr);
     while (*item != 0) {
+            if (item[0] != ':') {
         listeners->push_back(item);
+            }
         item += strlen(item) + 1;
     }    
+    }
 
     return listeners;
 }
@@ -213,35 +236,23 @@
 #endif
 
 vector<amf::Element *> 
-LcShm::parseBody(boost::uint8_t * /*data*/)
+LcShm::parseBody(boost::uint8_t *data)
 {
-    GNASH_REPORT_FUNCTION;
-
-    //boost::uint8_t *ptr = reinterpret_cast<uint8_t *>(data);
-    //Element::astype_e type = (Element::astype_e)*ptr;
-//    log_msg(_("Type is %s"), astype_str[type]);
-    amf::Element el;
+//    GNASH_REPORT_FUNCTION;
+    boost::uint8_t *ptr = reinterpret_cast<uint8_t *>(data);
     AMF amf;
 
-#if 0
-    while ((*(ptr) != 0) || (*(ptr) != 0) || (*(ptr) != 0)) {
-        switch (type) {
-          case AMF::NUMBER:
-              double dub = 50.0;
-              amf_obj.createElement(&el, "gain", dub);
-              break;
-          case AMF::STRING:
-              amf_obj.createElement(&el, name, data);
-              break;
-          default:
-              break;
-        };
-        
+    while (ptr) {
+        amf::Element *el = new Element;
+        ptr = amf.extractElement(el, ptr);
+        if (el->getType() == Element::NUMBER) {
+            if (el->to_number() == 0.0) {
+                ptr = 0;
+                continue;
+            }
+        }
         addObject(el);
-//        ptr = amf.readElement(ptr);
-        printf("FIXME:");
     };
-#endif
     
     return _amfobjs;
 }
@@ -265,41 +276,59 @@
 boost::uint8_t *
 LcShm::parseHeader(boost::uint8_t *data)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
     boost::uint8_t *ptr = data;
     
     memcpy(&_header, ptr, LC_HEADER_SIZE);
 //     memcpy(&_object, data + LC_HEADER_SIZE, _header.length);
-    log_debug("Timestamp: %ud", _header.timestamp);
-    log_debug("Length: %ud", _header.length);
+//    log_debug("Timestamp: %d", _header.timestamp);
+//    log_debug("Length: %d", _header.length);
 //     log_debug("Connection: %s", _object.connection_name);
 //     log_debug("name: %s", _object.hostname);
     ptr += LC_HEADER_SIZE;
+
+    
+    Element *el = new amf::Element;
     AMF amf;
-#if 0
-    _object.connection_name = amf.extractString(ptr);
-    ptr += _object.connection_name.size() + 3;
-    _object.hostname = amf.extractString(ptr);
-    ptr += _object.hostname.size() + 3;
-    _object.domain = ptr + 2;
-    ptr += 3;
-    _object.unknown_num1 = amf.extractNumber(ptr);
-    ptr += AMF_NUMBER_SIZE + 1;
-    _object.unknown_num1 = amf.extractNumber(ptr);
-    ptr += AMF_NUMBER_SIZE + 2;
-#endif
+    ptr = amf.extractElement(el, ptr);
+    _object.connection_name = el->to_string();
+    delete el;
+    
+    el = new amf::Element;
+    ptr = amf.extractElement(el, ptr);
+    _object.hostname = el->to_string();
+    delete el;
+    
+//     el = new amf::Element;
+//     ptr = amf.extractElement(el, ptr);
+//     _object.domain = el->to_bool();
+//     delete el;
+    
+//     el = new amf::Element;
+//     ptr = amf.extractElement(el, ptr);
+//     _object.unknown_num1 = el->to_number();
+//     delete el;
+    
+//     el = new amf::Element;
+//     ptr = amf.extractElement(el, ptr);
+//     _object.unknown_num2 = el->to_number();
+//     delete el;
     
 //    memcpy(&_object, data + LC_HEADER_SIZE, _header.length);
-    log_debug("Connection: %s", _object.connection_name.c_str());
-    log_debug("name: %s", _object.hostname.c_str());
+//     log_debug("Connection: %s", _object.connection_name.c_str());
+//     log_debug("name: %s", _object.hostname.c_str());
+//     log_debug("domain: %s", (_object.domain) ? "true" : "false");
+//     log_debug("unknown_num1: %f", _object.unknown_num1);
+//     log_debug("unknown_num2: %f", _object.unknown_num2);
 
+//    ptr += 3;                   // skip past the NULL terminator
     return ptr;
 }
 
 boost::uint8_t *
 LcShm::formatHeader(boost::uint8_t * /*data*/)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
     return NULL;
 }
 
@@ -312,7 +341,7 @@
 bool
 LcShm::connect(string &name)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
     
     _name = name;
     
@@ -326,17 +355,31 @@
     }
     
     Listener::setBaseAddress(reinterpret_cast<uint8_t *>(Shm::getAddr()));
+    boost::uint8_t *ptr = parseHeader(Listener::getBaseAddress());
+    vector<amf::Element *> ellist = parseBody(ptr);
     
     return true;
 }
 
 bool
-LcShm::addObject(amf::Element * /* el */)
+LcShm::connect(key_t key)
 {
-    GNASH_REPORT_FUNCTION;
+//    GNASH_REPORT_FUNCTION;
+    
+    if (Shm::attach(key, true) == false) {
+        return false;
+    }
 
+    if (Shm::getAddr() <= 0) {
+        log_error("Failed to open shared memory segment: 0x%x", key);
     return false;
+    }
 
+    Listener::setBaseAddress(reinterpret_cast<uint8_t *>(Shm::getAddr()));
+    boost::uint8_t *ptr = parseHeader(Listener::getBaseAddress());
+    vector<amf::Element *> ellist = parseBody(ptr);
+    
+    return true;
 }
 
 /// \brief Invokes a method on a specified LcShm object.
@@ -347,4 +390,34 @@
     log_unimpl (__FUNCTION__);
 }
 
+void
+LcShm::dump()
+{
+//    GNASH_REPORT_FUNCTION;
+
+//     cerr <<"Timestamp: " << _header.timestamp << endl;
+//     cerr << "Length: " << _header.length << endl;
+
+    cerr << "Connection Name:\t" << _object.connection_name << endl;
+    cerr << "Hostname Name:\t\t" << _object.hostname << endl;
+    cerr << "Domain Allowed:\t\t" << ((_object.domain) ? "true" : "false") << 
endl;
+    vector<amf::Element *>::iterator ait;
+//    cerr << "# of Elements in file: " << _amfobjs.size() << endl;
+    for (ait = _amfobjs.begin(); ait != _amfobjs.end(); ait++) {
+       amf::Element *el = (*(ait));
+        el->dump();
+    }
+
+    vector<string>::const_iterator lit;
+    vector<string> *listeners = listListeners();
+    for (lit=listeners->begin(); lit!=listeners->end(); lit++) {
+        string str = *lit;
+        if (str[0] != ':') {
+            cerr << "Listeners:\t" << str << endl;
+//             total++;
+        }
+    }
+    delete listeners;
+}
+
 } // end of gnash namespace

Index: libamf/lcshm.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/lcshm.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libamf/lcshm.h      21 Jan 2008 22:55:27 -0000      1.4
+++ libamf/lcshm.h      25 Jan 2008 18:08:00 -0000      1.5
@@ -45,9 +45,11 @@
     bool removeListener(std::string &name);
     std::vector<std::string> *listListeners();
     void setBaseAddress(boost::uint8_t *addr) { _baseaddr = addr; };
+    boost::uint8_t *getBaseAddress() { return _baseaddr; };
 protected:
     std::string _name;
     boost::uint8_t *_baseaddr;
+//    std::vector<std::string> _listeners;
 };
 
 class LcShm : public Listener, public Shm {
@@ -72,19 +74,25 @@
         double unknown_num2;
     } lc_object_t;
     LcShm();
+    LcShm(boost::uint8_t *baseaddr);
+    LcShm(key_t key);
     ~LcShm();
     bool connect(std::string &name);
+    bool connect(key_t key);
     void close(void);
     void send(const std::string &name, const std::string &dataname, 
amf::Element *data);
     void recv(std::string &name, std::string &dataname, amf::Element *data);
     std::vector<amf::Element *> parseBody(boost::uint8_t *data);
     boost::uint8_t *parseHeader(boost::uint8_t *data);
     boost::uint8_t *formatHeader(boost::uint8_t *data);
-    bool addObject(amf::Element *el);
+    void addObject(amf::Element *el) { _amfobjs.push_back(el); };
     size_t size() { return _amfobjs.size(); };
     std::vector<amf::Element *> getElements() { return _amfobjs; };
+
+    void setBaseAddr(boost::uint8_t *x) { _baseaddr = x; };
+    void dump();
 private:
-    uint8_t *_baseaddr;
+    boost::uint8_t *_baseaddr;
     lc_header_t _header;
     lc_object_t _object;
     std::vector<amf::Element *> _amfobjs;




reply via email to

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