[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libamf/amf.cpp libamf/amf.h lib...
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash ChangeLog libamf/amf.cpp libamf/amf.h lib... |
Date: |
Sat, 05 Apr 2008 20:39:39 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 08/04/05 20:39:39
Modified files:
. : ChangeLog
libamf : amf.cpp amf.h buffer.cpp element.cpp element.h
sol.cpp
Log message:
* libamf/amf.{h,cpp}: Keep track of the total size of data read
from each packet to make it easier to calculate the byte
offset. Don't have extractVariable as a static so it can
calculate
the pointer offset.
* libamf/buffer.cpp: Set private data at constructor time.
* libamf/element.cpp: Set private data. Don't calculate the
total
data size here. Add makeNull() for zero length strings.
* libamf/sol.cpp: Remove smart pointer for file reading.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6188&r2=1.6189
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.cpp?cvsroot=gnash&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.h?cvsroot=gnash&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/buffer.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.h?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.cpp?cvsroot=gnash&r1=1.30&r2=1.31
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6188
retrieving revision 1.6189
diff -u -b -r1.6188 -r1.6189
--- ChangeLog 5 Apr 2008 11:08:18 -0000 1.6188
+++ ChangeLog 5 Apr 2008 20:39:38 -0000 1.6189
@@ -1,3 +1,14 @@
+2008-04-05 Rob Savoye <address@hidden>
+
+ * libamf/amf.{h,cpp}: Keep track of the total size of data read
+ from each packet to make it easier to calculate the byte
+ offset. Don't have extractVariable as a static so it can calculate
+ the pointer offset.
+ * libamf/buffer.cpp: Set private data at constructor time.
+ * libamf/element.cpp: Set private data. Don't calculate the total
+ data size here. Add makeNull() for zero length strings.
+ * libamf/sol.cpp: Remove smart pointer for file reading.
+
2008-04-05 Benjamin Wolsey <address@hidden>
* gui/Player.cpp: minor cleanups.
Index: libamf/amf.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.cpp,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- libamf/amf.cpp 4 Apr 2008 23:29:46 -0000 1.67
+++ libamf/amf.cpp 5 Apr 2008 20:39:39 -0000 1.68
@@ -66,14 +66,7 @@
};
AMF::AMF()
-#if 0
- _amf_index(0),
- _header_size(0),
- _total_size(0),
- _packet_size(0),
- _amf_data(0),
- _seekptr(0),
-#endif
+ : _totalsize(0)
{
// GNASH_REPORT_FUNCTION;
}
@@ -738,10 +731,10 @@
switch (type) {
case Element::NUMBER: // a 64 bit numeric value
- return 8;
+ return AMF_NUMBER_SIZE;
break;
case Element::BOOLEAN: // a single byte
- return 1;
+ return sizeof(bool);
break;
case Element::STRING: // the length is a 2 byte value
//FIXME, there are all kinds of byte order problems in this
code.
@@ -1133,22 +1126,6 @@
// return out;
// }
-// Network::byte_t *
-// AMF::addPacketData(Network::byte_t *data, int bytes)
-// {
-// // GNASH_REPORT_FUNCTION;
-// memcpy(_seekptr, data, bytes);
-// _seekptr+=bytes;
-// return _seekptr;
-// }
-
-// int
-// AMF::parseBody()
-// {
-// // GNASH_REPORT_FUNCTION;
-
-// // return parseBody(_amf_data, _total_size);
-// }
// #endif
Element *
@@ -1164,23 +1141,21 @@
log_error(_("AMF body input data is NULL"));
return 0;
}
-// if (reinterpret_cast<int>(el) == 0)) {
-// log_error(_("Got NULL instead of amf_element_t!"));
-// return 0;
-// }
tmpptr = in;
-// All elements look like this:
-// the first two bytes is the length of name of the element
-// Then the next bytes are the element name
-// 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
+ // All elements look like this:
+ // the first two bytes is the length of name of the element
+ // Then the next bytes are the element name
+ // 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
// Check the type of the element data
Element::amf_type_e type = *(Element::amf_type_e *)tmpptr;
tmpptr++; // skip the header byte
+ AMF amf_obj;
switch (type) {
case Element::NUMBER:
el->makeNumber(tmpptr);
@@ -1206,8 +1181,8 @@
break;
case Element::OBJECT:
do {
- el = extractVariable(tmpptr);
- tmpptr += el->totalsize();
+ el = amf_obj.extractVariable(tmpptr);
+ tmpptr += amf_obj.totalsize();
} while (el->getType() != Element::OBJECT_END);
break;
case Element::MOVIECLIP:
@@ -1239,39 +1214,42 @@
boost::uint16_t length;
Network::byte_t *tmpptr = in;
- length = *(reinterpret_cast<boost::uint16_t *>(in));
- tmpptr += sizeof(boost::uint16_t);
+// std::copy(in, in + sizeof(boost::uint16_t), &length);
+ length = *reinterpret_cast<boost::uint16_t *>(in);
swapBytes(&length, sizeof(boost::uint16_t));
-
+ tmpptr += sizeof(boost::uint16_t);
if (length <= 0) {
if (*(in+2) == Element::OBJECT_END) {
log_debug(_("End of Object definition"));
el->setType(Element::OBJECT_END);
return el;
}
+ delete el;
return 0;
}
// get the name of the element, the length of which we just decoded
if (length > 0) {
log_debug(_("AMF element length is: %d"), length);
el->setName(tmpptr, length);
-// el->setName("fixme");
- tmpptr += length;
log_debug(_("AMF element name is: %s"), el->getName());
+ tmpptr += length;
}
- // get the type of the element, which is a single byte
- Element::amf_type_e type = (Element::amf_type_e)(*(tmpptr) & 0xff);
+ // get the type of the element, which is a single byte.
+ char c = *(reinterpret_cast<char *>(tmpptr));
+ Element::amf_type_e type = static_cast<Element::amf_type_e>(c);
tmpptr++;
- if (type <= Element::TYPED_OBJECT) {
+ if (type != Element::TYPED_OBJECT) {
log_debug(_("AMF type is: %s"), amftype_str[(int)type]);
el->setType(type);
}
switch (type) {
- case Element::NUMBER: {
- swapBytes(tmpptr, AMF_NUMBER_SIZE);
- el->makeNumber(tmpptr);
+ case Element::NUMBER:
+ {
+ double num = *reinterpret_cast<const double*>(tmpptr);
+ swapBytes(&num, AMF_NUMBER_SIZE);
+ el->makeNumber(num);
tmpptr += AMF_NUMBER_SIZE;
break;
}
@@ -1283,19 +1261,26 @@
break;
}
case Element::STRING:
- // extractString returns a printable char *
- length = ntohs((*(const boost::uint16_t *)tmpptr) & 0xffff);
+ // extractString returns a printable char *. First 2 bytes for the
length,
+ // and then read the string, which is NOT NULL terminated.
+ length = *reinterpret_cast<boost::uint16_t *>(tmpptr);
+ swapBytes(&length, sizeof(boost::uint16_t));
tmpptr += sizeof(boost::uint16_t);
+ if (length > 0) {
el->makeString(tmpptr, length);
-// string v(reinterpret_cast<const char *>(str) + 3, (int)length);
-// log_debug(_("Variable \"%s\" is: %s"), el->getName().c_str(),
v.c_str());
tmpptr += length;
+ }
+ if (length == 0) {
+ el->makeNullString();
+// tmpptr++;
+ }
+// string v(reinterpret_cast<const char *>(tmpptr) + 3, (int)length);
+ log_debug(_("Variable \"%s\" is: %s"), el->getName(),
el->to_string());
break;
case Element::OBJECT:
while (*(tmpptr++) != Element::OBJECT_END) {
log_debug("Look for end of object...");
}
-
break;
case Element::MOVIECLIP:
case Element::NULL_VALUE:
@@ -1324,9 +1309,14 @@
case Element::XML_OBJECT:
default:
log_unimpl(_("amf_type_e of value: %x"), (int)type);
- break;
+ delete el;
+ return 0;
}
+ // Calculate the offset for the next read
+ _totalsize = (tmpptr - in) + 1;
+ log_debug("Total number of bytes read from byte stream is: %d",
_totalsize);
+
return el;
}
Index: libamf/amf.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- libamf/amf.h 1 Apr 2008 22:20:40 -0000 1.36
+++ libamf/amf.h 5 Apr 2008 20:39:39 -0000 1.37
@@ -258,9 +258,12 @@
static amf::Element *extractAMF(gnash::Network::byte_t *in);
// Extract an AMF "variable", which is a standard AMF object preceeded by
// just a length and a name field.
- static amf::Element *extractVariable(gnash::Network::byte_t *in);
+ amf::Element *extractVariable(gnash::Network::byte_t *in);
+
+ size_t totalsize() { return _totalsize; }
+
private:
-// no data, all the methods are static
+ size_t _totalsize;
};
DSOEXPORT void *swapBytes(void *word, int size);
Index: libamf/buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/buffer.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- libamf/buffer.cpp 1 Apr 2008 22:19:54 -0000 1.1
+++ libamf/buffer.cpp 5 Apr 2008 20:39:39 -0000 1.2
@@ -47,20 +47,20 @@
}
Buffer::Buffer()
+ : _seekptr(0),
+ _ptr(0)
{
// GNASH_REPORT_FUNCTION;
- _ptr = 0;
- _seekptr = 0;
_nbytes = gnash::NETBUFSIZE;
init(gnash::NETBUFSIZE);
}
// Create with a size other than the default
Buffer::Buffer(size_t nbytes)
+ : _seekptr(0),
+ _ptr(0)
{
// GNASH_REPORT_FUNCTION;
- _ptr = 0;
- _seekptr = 0;
_nbytes = nbytes;
init(nbytes);
}
Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- libamf/element.cpp 5 Apr 2008 16:51:04 -0000 1.14
+++ libamf/element.cpp 5 Apr 2008 20:39:39 -0000 1.15
@@ -63,11 +63,9 @@
};
Element::Element()
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
-// _length(0),
-// _data(0)
+ _type(Element::NOTYPE)
{
// GNASH_REPORT_FUNCTION;
}
@@ -87,18 +85,18 @@
}
Element::Element(Network::byte_t *indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(indata);
}
Element::Element(double indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(indata);
@@ -111,36 +109,36 @@
// }
Element::Element(const string &indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(indata);
}
Element::Element(const string &name, const string &indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(name, indata);
}
Element::Element(const string &name, bool indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(name, indata);
}
Element::Element(bool indata)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(indata);
@@ -149,30 +147,14 @@
// Create a function block for AMF
Element::Element(bool flag, double unknown1, double unknown2,
const string &methodname)
- : _type(Element::NOTYPE),
+ : _name(0),
_buffer(0),
- _name(0)
+ _type(Element::NOTYPE)
{
GNASH_REPORT_FUNCTION;
init(flag, unknown1, unknown2, methodname);
}
-// Return the total size of the data plus the headers for byte math
-size_t
-Element::totalsize()
-{
-// GNASH_REPORT_FUNCTION;
- size_t size = 0;
-
- if (_name == 0) {
- size = _buffer->size() + AMF_HEADER_SIZE;
- } else {
- size = _buffer->size() + AMF_VAR_HEADER_SIZE + strlen(_name);
- }
-
- return size;
-}
-
Element &
Element::init(bool flag, double unknown1, double unknown2,
const string &methodname)
@@ -391,7 +373,19 @@
// a NULL terminator to the string. When encoding, we are careful to
// to adjust the byte count down by one, as the NULL terminator doesn't
// get written.
- *(_buffer->end()) = 0;
+ *(_buffer->end() - 1) = 0;
+ return *this;
+}
+
+// A Null string is a string with no length. The data is only one byte, which
+// always has the value of zero of course.
+Element &
+Element::makeNullString()
+{
+// GNASH_REPORT_FUNCTION;
+ _type = Element::STRING;
+ _buffer = new Buffer(sizeof(Network::byte_t));
+ *(_buffer->reference()) = 0;
return *this;
}
@@ -424,24 +418,22 @@
Element &
Element::makeNumber(Network::byte_t *data)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
double num = *reinterpret_cast<const double*>(data);
_type = Element::NUMBER;
_buffer = new Buffer(AMF_NUMBER_SIZE);
_buffer->append(num);
-
return *this;
}
Element &
-Element::makeNumber(const string &name, double innum)
+Element::makeNumber(double num)
{
-// GNASH_REPORT_FUNCTION;
- if (name.size()) {
- setName(name);
- }
- Network::byte_t *num = reinterpret_cast<Network::byte_t *>(&innum);
- return makeNumber(num);
+ _type = Element::NUMBER;
+ _buffer = new Buffer(AMF_NUMBER_SIZE);
+ _buffer->append(num);
+
+ return *this;
}
Element &
@@ -630,6 +622,7 @@
size_t
Element::getNameSize()
{
+// GNASH_REPORT_FUNCTION;
if (_name) {
return strlen(_name);
}
@@ -639,19 +632,19 @@
void
Element::setName(const string &str)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
_name = new char[str.size() + 1];
std::copy(str.begin(), str.end(), _name);
*(_name + str.size()) = 0;
}
void
-Element::setName(Network::byte_t *name, size_t x)
+Element::setName(Network::byte_t *name, size_t size)
{
- GNASH_REPORT_FUNCTION;
- _name = new char[x+1];
- std::copy(name, name+x, _name);
- *(_name + x) = 0;
+// GNASH_REPORT_FUNCTION;
+ _name = new char[size+1];
+ std::copy(name, name+size, _name);
+ *(_name + size) = 0;
}
void
@@ -669,6 +662,7 @@
case Element::NOTYPE:
break;
case Element::NUMBER:
+
cerr << to_number() << endl;
break;
case Element::BOOLEAN:
Index: libamf/element.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- libamf/element.h 3 Apr 2008 11:05:01 -0000 1.13
+++ libamf/element.h 5 Apr 2008 20:39:39 -0000 1.14
@@ -81,13 +81,15 @@
Element &init(bool, double, double, const std::string &str);
// These create the other "special" AMF types.
+ Element &makeNullString();
Element &makeString(const char *str, size_t size);
Element &makeString(gnash::Network::byte_t *data, size_t size);
Element &makeString(const std::string &data);
Element &makeString(const std::string &name, const std::string &data);
+ Element &makeNumber(double num);
Element &makeNumber(gnash::Network::byte_t *data);
- Element &makeNumber(const std::string &name, double);
+ Element &makeNumber(const std::string &name, double num);
Element &makeBoolean(gnash::Network::byte_t *data);
Element &makeBoolean(bool data);
@@ -117,9 +119,6 @@
bool operator==(bool x);
gnash::Network::byte_t operator[](int x);
- // Return the total size of the data plus the headers for byte math
- size_t totalsize();
-
gnash::Network::byte_t *getData();
boost::uint16_t getLength();
Buffer *getBuffer() { return _buffer; };
@@ -145,10 +144,10 @@
void dump();
private:
- amf_type_e _type;
- Buffer *_buffer;
char *_name;
+ Buffer *_buffer;
std::vector<Element *> _children;
+ amf_type_e _type;
}; // end of class definition
Index: libamf/sol.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- libamf/sol.cpp 1 Apr 2008 23:45:55 -0000 1.30
+++ libamf/sol.cpp 5 Apr 2008 20:39:39 -0000 1.31
@@ -248,7 +248,7 @@
size_t outsize = 0;
switch (el->getType()) {
case Element::BOOLEAN:
- outsize = el->getNameSize() + 5;
+ outsize = el->getNameSize() + AMF_VAR_HEADER_SIZE;
memcpy(ptr, var, outsize);
ptr += outsize;
break;
@@ -323,7 +323,7 @@
// GNASH_REPORT_FUNCTION;
struct stat st;
boost::uint16_t size;
- boost::scoped_array<Network::byte_t> buf;
+ Network::byte_t *buf;
Network::byte_t *ptr;
int bodysize;
@@ -333,15 +333,15 @@
_filesize = st.st_size;
bodysize = st.st_size - 6;
_filespec = filespec;
- buf.reset( new Network::byte_t[_filesize+1] );
- ptr = buf.get();
- ifs.read(reinterpret_cast<char *>(buf.get()), _filesize);
+ buf = new Network::byte_t[_filesize+1];
+ ptr = buf;
+ ifs.read(reinterpret_cast<char *>(buf), _filesize);
// skip the magic number (will check later)
ptr += 2;
// extract the file size
- int length = *(reinterpret_cast<boost::uint32_t *>(ptr));
+ boost::uint32_t length = *(reinterpret_cast<boost::uint32_t *>(ptr));
length = ntohl(length);
ptr += 4;
@@ -376,8 +376,8 @@
while (size <= bodysize) {
amf::Element *el = amf_obj.extractVariable(ptr);
if (el != 0) {
- ptr += el->getLength() + AMF_HEADER_SIZE;
- size += el->getNameSize() + AMF_HEADER_SIZE;
+ size += amf_obj.totalsize();
+ ptr += amf_obj.totalsize();
_amfobjs.push_back(el);
} else {
break;
- [Gnash-commit] gnash ChangeLog libamf/amf.cpp libamf/amf.h lib...,
Rob Savoye <=