[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libnet/Makefile.am libnet/cque....
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash ChangeLog libnet/Makefile.am libnet/cque.... |
Date: |
Tue, 01 Apr 2008 22:20:43 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 08/04/01 22:20:42
Modified files:
. : ChangeLog
libnet : Makefile.am cque.cpp cque.h handler.cpp
handler.h http.cpp http.h network.cpp network.h
rtmp.cpp rtmp.h rtmp_server.cpp rtmp_server.h
libamf : Makefile.am amf.cpp amf.h element.cpp element.h
lcshm.cpp protocol.h sol.cpp
Log message:
* libamf/Makefile.am: Build buffer class here instead of
libnet.
* libamf/amf.cpp: All encode* methods return a Buffer now with
the
encoded data.
* libamf/amf.h: Add more comments about the constants. All
encode*
methods return a Buffer now.
* libamf/element.{h,cpp}: Use a Buffer to store data instead of
duplicating the functionality here. Add additional methods for
appending data. Use a char * for the name instead of a string to
reduce copying of data.
* libamf/lcshm.cpp: AMF:encode* methods return an Element now.
* libamf/protocol.h: Add a suffix to the enum names for protocol
types.
* libamf/sol.cpp: Work with modified Element class. All encoding
classs use a Buffer now, extract classes return an Element.
* libnet/Makefile.am: Don't build buffer class here.
* libnet/cque.{h,cpp}: Buffer class now in amf namespace.
* libnet/handler.{h,cpp}: Buffer class now in amf namespace.
* libnet/http.{h,cpp}: Buffer class now in amf namespace.
* libnet/network.{h,cpp}: Buffer class now in amf namespace. Add
suffix to port names in enum.
* libnet/rtmp.{h,cpp}: Buffer class now in amf namespace. Rename
RTMPproto to just RTMP.
* libnet/rtmp_server.{h,cpp}: Buffer class now in amf namespace.
* testsuite/libnet.all/Makefile.am: Move test_buffer to
libamf.all.
* testsuite/libamf.all/Makefile.am: Test_buffer moved to here as
it's on libamf now.
* testsuite/libamf.all/test_el.cpp: Use MakeString instead of
init().
* testsuite/libamf.all/test_sol.cpp: Element name is now a
char*,
so use strcmp() for string compares.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6143&r2=1.6144
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/Makefile.am?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/cque.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/cque.h?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/handler.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/handler.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/http.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/http.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/network.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/network.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/rtmp.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/rtmp.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/rtmp_server.cpp?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/libnet/rtmp_server.h?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/Makefile.am?cvsroot=gnash&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.cpp?cvsroot=gnash&r1=1.65&r2=1.66
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/amf.h?cvsroot=gnash&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.h?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/lcshm.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/protocol.h?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.cpp?cvsroot=gnash&r1=1.28&r2=1.29
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6143
retrieving revision 1.6144
diff -u -b -r1.6143 -r1.6144
--- ChangeLog 1 Apr 2008 21:10:26 -0000 1.6143
+++ ChangeLog 1 Apr 2008 22:20:34 -0000 1.6144
@@ -1,3 +1,36 @@
+2008-04-01 Rob Savoye <address@hidden>
+
+ * libamf/Makefile.am: Build buffer class here instead of libnet.
+ * libamf/amf.cpp: All encode* methods return a Buffer now with the
+ encoded data.
+ * libamf/amf.h: Add more comments about the constants. All encode*
+ methods return a Buffer now.
+ * libamf/element.{h,cpp}: Use a Buffer to store data instead of
+ duplicating the functionality here. Add additional methods for
+ appending data. Use a char * for the name instead of a string to
+ reduce copying of data.
+ * libamf/lcshm.cpp: AMF:encode* methods return an Element now.
+ * libamf/protocol.h: Add a suffix to the enum names for protocol
+ types.
+ * libamf/sol.cpp: Work with modified Element class. All encoding
+ classs use a Buffer now, extract classes return an Element.
+ * libnet/Makefile.am: Don't build buffer class here.
+ * libnet/cque.{h,cpp}: Buffer class now in amf namespace.
+ * libnet/handler.{h,cpp}: Buffer class now in amf namespace.
+ * libnet/http.{h,cpp}: Buffer class now in amf namespace.
+ * libnet/network.{h,cpp}: Buffer class now in amf namespace. Add
+ suffix to port names in enum.
+ * libnet/rtmp.{h,cpp}: Buffer class now in amf namespace. Rename
+ RTMPproto to just RTMP.
+ * libnet/rtmp_server.{h,cpp}: Buffer class now in amf namespace.
+ * testsuite/libnet.all/Makefile.am: Move test_buffer to libamf.all.
+ * testsuite/libamf.all/Makefile.am: Test_buffer moved to here as
+ it's on libamf now.
+ * testsuite/libamf.all/test_el.cpp: Use MakeString instead of
+ init().
+ * testsuite/libamf.all/test_sol.cpp: Element name is now a char*,
+ so use strcmp() for string compares.
+
2008-04-01 Sandro Santilli <address@hidden>
* server/vm/ASHandlers.cpp (ActionLogicalNot): swf < 5 return 0
Index: libnet/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libnet/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libnet/Makefile.am 29 Mar 2008 19:35:53 -0000 1.3
+++ libnet/Makefile.am 1 Apr 2008 22:20:36 -0000 1.4
@@ -47,7 +47,6 @@
$(PTHREAD_CFLAGS)
noinst_HEADERS = \
- buffer.h \
cque.h \
lirc.h \
handler.h \
@@ -59,7 +58,6 @@
statistics.h
libgnashnet_la_SOURCES = \
- buffer.cpp \
cque.cpp \
handler.cpp \
lirc.cpp \
Index: libnet/cque.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/cque.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libnet/cque.cpp 31 Mar 2008 02:47:48 -0000 1.7
+++ libnet/cque.cpp 1 Apr 2008 22:20:36 -0000 1.8
@@ -54,10 +54,10 @@
// GNASH_REPORT_FUNCTION;
// clear();
#if 0
- deque<Buffer *>::iterator it;
+ deque<amf::Buffer *>::iterator it;
boost::mutex::scoped_lock lock(_mutex);
for (it = _que.begin(); it != _que.end(); it++) {
- Buffer *ptr = *(it);
+ amf::Buffer *ptr = *(it);
delete ptr;
}
#endif
@@ -91,7 +91,7 @@
}
bool
-CQue::push(Buffer *data)
+CQue::push(amf::Buffer *data)
{
// GNASH_REPORT_FUNCTION;
boost::mutex::scoped_lock lock(_mutex);
@@ -108,18 +108,18 @@
CQue::push(gnash::Network::byte_t *data, int nbytes)
{
// GNASH_REPORT_FUNCTION;
- Buffer *buf = new Buffer;
+ amf::Buffer *buf = new amf::Buffer;
std::copy(data, data + nbytes, buf->reference());
return push(buf);
}
// Pop the first date element off the FIFO
-Buffer *
+amf::Buffer *
CQue::pop()
{
// GNASH_REPORT_FUNCTION;
- Buffer *buf = 0;
+ amf::Buffer *buf = 0;
boost::mutex::scoped_lock lock(_mutex);
if (_que.size()) {
buf = _que.front();
@@ -132,7 +132,7 @@
}
// Peek at the first data element without removing it
-Buffer *
+amf::Buffer *
CQue::peek()
{
// GNASH_REPORT_FUNCTION;
@@ -154,14 +154,14 @@
// Remove a range of elements
void
-CQue::remove(Buffer *begin, Buffer *end)
+CQue::remove(amf::Buffer *begin, amf::Buffer *end)
{
GNASH_REPORT_FUNCTION;
- deque<Buffer *>::iterator it;
- deque<Buffer *>::iterator start;
- deque<Buffer *>::iterator stop;
+ deque<amf::Buffer *>::iterator it;
+ deque<amf::Buffer *>::iterator start;
+ deque<amf::Buffer *>::iterator stop;
boost::mutex::scoped_lock lock(_mutex);
- Buffer *ptr;
+ amf::Buffer *ptr;
for (it = _que.begin(); it != _que.end(); it++) {
ptr = *(it);
if (ptr->reference() == begin->reference()) {
@@ -177,13 +177,13 @@
// Remove an element
void
-CQue::remove(Buffer *element)
+CQue::remove(amf::Buffer *element)
{
GNASH_REPORT_FUNCTION;
- deque<Buffer *>::iterator it;
+ deque<amf::Buffer *>::iterator it;
boost::mutex::scoped_lock lock(_mutex);
for (it = _que.begin(); it != _que.end(); it++) {
- Buffer *ptr = *(it);
+ amf::Buffer *ptr = *(it);
if (ptr->reference() == element->reference()) {
_que.erase(it);
}
@@ -192,27 +192,27 @@
// Merge sucessive buffers into one single larger buffer. This is for some
// protocols, than have very long headers.
-Buffer *
-CQue::merge(Buffer *begin)
+amf::Buffer *
+CQue::merge(amf::Buffer *begin)
{
GNASH_REPORT_FUNCTION;
int totalsize = 0;
- deque<Buffer *>::iterator it;
- vector<deque<Buffer *>::iterator> elements;
- vector<deque<Buffer *>::iterator>::iterator eit;
+ deque<amf::Buffer *>::iterator it;
+ vector<deque<amf::Buffer *>::iterator> elements;
+ vector<deque<amf::Buffer *>::iterator>::iterator eit;
boost::mutex::scoped_lock lock(_mutex);
for (it = _que.begin(); it != _que.end(); it++) {
- Buffer *ptr = *(it);
+ amf::Buffer *ptr = *(it);
if (totalsize > 0) {
totalsize += ptr->size();
elements.push_back(it);
if (ptr->size() < gnash::NETBUFSIZE) {
- Buffer *newbuf = new Buffer(totalsize);
+ amf::Buffer *newbuf = new amf::Buffer(totalsize);
Network::byte_t *tmp = newbuf->reference();
- Buffer *buf;
+ amf::Buffer *buf;
// _que.insert(elements.begin(), newbuf);
for (eit = elements.begin(); eit != elements.end(); eit++) {
- deque<Buffer *>::iterator ita = *(eit);
+ deque<amf::Buffer *>::iterator ita = *(eit);
buf = *(ita);
std::copy(buf->reference(), buf->reference() + buf->size(),
tmp);
tmp += buf->size();
@@ -236,11 +236,11 @@
CQue::dump()
{
// GNASH_REPORT_FUNCTION;
- deque<Buffer *>::iterator it;
+ deque<amf::Buffer *>::iterator it;
boost::mutex::scoped_lock lock(_mutex);
cerr << endl << "CQue \"" << _name << "\" has "<< _que.size() << "
buffers." << endl;
for (it = _que.begin(); it != _que.end(); it++) {
- Buffer *ptr = *(it);
+ amf::Buffer *ptr = *(it);
ptr->dump();
}
#ifdef USE_STATS_QUEUE
Index: libnet/cque.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/cque.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- libnet/cque.h 31 Mar 2008 02:47:48 -0000 1.5
+++ libnet/cque.h 1 Apr 2008 22:20:36 -0000 1.6
@@ -47,11 +47,11 @@
~CQue();
// Push data onto the que
bool push(gnash::Network::byte_t *data, int nbytes);
- bool push(Buffer *data);
+ bool push(amf::Buffer *data);
// Pop the first date element off the que
- Buffer *pop();
+ amf::Buffer *pop();
// Peek at the first date element witjhout removing it from the que
- Buffer *peek();
+ amf::Buffer *peek();
// Get the number of elements in the que
size_t size();
// Wait for a condition variable to trigger
@@ -61,13 +61,13 @@
// Empty the que of all data.
void clear();
// Remove a range of elements
- void remove(Buffer *begin, Buffer *end);
+ void remove(amf::Buffer *begin, amf::Buffer *end);
// // Remove an element
-// void remove(Buffer *it);
- void remove(Buffer *it);
+// void remove(amf::Buffer *it);
+ void remove(amf::Buffer *it);
// Merge sucessive buffers into one single larger buffer. This is for some
// protocols, than have very long headers.
- Buffer *merge(Buffer *begin);
+ amf::Buffer *merge(amf::Buffer *begin);
// Dump the data to the terminal
void dump();
@@ -79,7 +79,7 @@
// an optional name for the queue, only used for debugging messages to
make them unique
std::string _name;
// The queue itself
- std::deque<Buffer *> _que;
+ std::deque<amf::Buffer *> _que;
// A condition variable used to signal the other thread when the que has
data
boost::condition _cond;
// This is the mutex used by the condition variable. It needs to be
separate from the
Index: libnet/handler.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/handler.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libnet/handler.cpp 29 Mar 2008 19:35:53 -0000 1.4
+++ libnet/handler.cpp 1 Apr 2008 22:20:37 -0000 1.5
@@ -63,7 +63,7 @@
}
bool
-Handler::push(Buffer *data, fifo_e direction)
+Handler::push(amf::Buffer *data, fifo_e direction)
{
// GNASH_REPORT_FUNCTION;
if (direction == Handler::OUTGOING) {
@@ -83,17 +83,17 @@
Handler::push(gnash::Network::byte_t *data, int nbytes, fifo_e direction)
{
// GNASH_REPORT_FUNCTION;
- Buffer *ptr = new Buffer;
+ amf::Buffer *ptr = new amf::Buffer;
ptr->copy(data, nbytes);
return push(ptr, direction);
}
// Pop the first date element off the FIFO
-Buffer *
+amf::Buffer *
Handler::pop(fifo_e direction)
{
// GNASH_REPORT_FUNCTION;
- Buffer *buf;
+ amf::Buffer *buf;
if (direction == Handler::OUTGOING) {
if (_outgoing.size()) {
@@ -112,7 +112,7 @@
}
// Peek at the first data element without removing it
-Buffer *
+amf::Buffer *
Handler::peek(fifo_e direction)
{
// GNASH_REPORT_FUNCTION;
@@ -182,7 +182,7 @@
if (args->port == 4080) { // FIXME: hack alert!
boost::thread handler(boost::bind(&httphandler, args));
}
- if (args->port == RTMP) {
+ if (args->port == RTMP_PORT) {
boost::thread handler(boost::bind(&rtmp_handler, args));
}
@@ -211,7 +211,7 @@
log_debug("Starting to wait for data in net for fd #%d", args->netfd);
do {
- Buffer *buf = new Buffer;
+ amf::Buffer *buf = new amf::Buffer;
size_t ret = hand->readNet(args->netfd, buf->reference(), buf->size(),
1);
// the read timed out as there was no data, but the socket is still
open.
if (ret == 0) {
@@ -258,7 +258,7 @@
}
hand->waitout();
while (hand->outsize()) {
- Buffer *buf = hand->popout();
+ amf::Buffer *buf = hand->popout();
// log_debug("FIXME: got data in Outgoing que");
// buf->dump();
// ret = hand->writeNet(buf->reference(), buf->size(), 15);
Index: libnet/handler.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/handler.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libnet/handler.h 29 Mar 2008 19:35:53 -0000 1.3
+++ libnet/handler.h 1 Apr 2008 22:20:37 -0000 1.4
@@ -61,45 +61,45 @@
typedef enum { INCOMING, OUTGOING } fifo_e;
// Push bytes on the incoming FIFO, which is the default
- bool push(Buffer *data)
+ bool push(amf::Buffer *data)
{ return _incoming.push(data); };
- bool push(Buffer *data, fifo_e direction);
+ bool push(amf::Buffer *data, fifo_e direction);
bool push(gnash::Network::byte_t *data, int nbytes, fifo_e direction);
bool push(gnash::Network::byte_t *data, int nbytes)
{ return _incoming.push(data, nbytes); };
bool pushin(gnash::Network::byte_t *data, int nbytes)
{ return _incoming.push(data, nbytes); };
- bool pushin(Buffer *data)
+ bool pushin(amf::Buffer *data)
{ return _incoming.push(data); };
// Push bytes on the incoming FIFO, which must be specified
bool pushout(gnash::Network::byte_t *data, int nbytes)
{ return _outgoing.push(data, nbytes); };
- bool pushout(Buffer *data)
+ bool pushout(amf::Buffer *data)
{ return _outgoing.push(data); };
// Pop the first date element off the incoming FIFO
- Buffer *pop() { return _incoming.pop(); };
- Buffer *pop(fifo_e direction);
- Buffer *popin()
+ amf::Buffer *pop() { return _incoming.pop(); };
+ amf::Buffer *pop(fifo_e direction);
+ amf::Buffer *popin()
{ return _incoming.pop(); };
// Pop the first date element off the outgoing FIFO
- Buffer *popout()
+ amf::Buffer *popout()
{ return _outgoing.pop(); };
// Peek at the first data element without removing it
- Buffer *peek() { return _incoming.peek(); };
- Buffer *peek(fifo_e direction);
- Buffer *peekin()
+ amf::Buffer *peek() { return _incoming.peek(); };
+ amf::Buffer *peek(fifo_e direction);
+ amf::Buffer *peekin()
{ return _incoming.peek(); };
// Pop the first date element off the outgoing FIFO
- Buffer *peekout()
+ amf::Buffer *peekout()
{ return _outgoing.peek(); };
// Removes all the buffers from the queues
- Buffer *merge(Buffer *begin) { return _incoming.merge(begin); };
- Buffer *mergein(Buffer *begin) { return _incoming.merge(begin); };
- Buffer *mergeout(Buffer *begin) { return _outgoing.merge(begin); };
+ amf::Buffer *merge(amf::Buffer *begin) { return _incoming.merge(begin); };
+ amf::Buffer *mergein(amf::Buffer *begin) { return _incoming.merge(begin);
};
+ amf::Buffer *mergeout(amf::Buffer *begin) { return _outgoing.merge(begin);
};
// Removes all the buffers from the queues
void clear() { _incoming.clear(); };
@@ -128,10 +128,10 @@
bool start(thread_params_t *args);
// Take a buffer and write it to the network
- int writeNet(int fd, Buffer *buf)
+ int writeNet(int fd, amf::Buffer *buf)
{ return Network::writeNet(fd, buf->reference(), buf->size()); };
- int writeNet(Buffer *buf)
+ int writeNet(amf::Buffer *buf)
{ return Network::writeNet(buf->reference(), buf->size()); };
// Dump internal data.
Index: libnet/http.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/http.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- libnet/http.cpp 29 Mar 2008 19:35:53 -0000 1.5
+++ libnet/http.cpp 1 Apr 2008 22:20:37 -0000 1.6
@@ -42,6 +42,7 @@
#include "network.h"
#include "handler.h"
#include "utility.h"
+#include "buffer.h"
using namespace gnash;
using namespace std;
@@ -125,7 +126,7 @@
// memset(buffer, 0, readsize+1);
// _handler->wait();
- Buffer *buf = _handler->pop();
+ amf::Buffer *buf = _handler->pop();
if (buf == 0) {
log_debug("Que empty, net connection dropped for fd #%d",
_handler->getFileFd());
@@ -446,7 +447,7 @@
formatHeader(_filesize, code);
// int ret = Network::writeNet(_header.str());
- Buffer *buf = new Buffer;
+ amf::Buffer *buf = new amf::Buffer;
// Network::byte_t *ptr = (Network::byte_t *)_body.str().c_str();
// buf->copy(ptr, _body.str().size());
// _handler->dump();
@@ -481,7 +482,7 @@
#if 0
formatHeader(_filesize, code);
- Buffer *buf = new Buffer;
+ amf::Buffer *buf = new amf::Buffer;
if (_header.str().size()) {
buf->resize(_header.str().size());
string str = _header.str();
@@ -1270,7 +1271,7 @@
log_debug (_("File \"%s\" is %lld bytes in size, disk fd #%d"),
filespec,
st.st_size, filefd);
do {
- Buffer *buf = new Buffer;
+ amf::Buffer *buf = new amf::Buffer;
ret = read(filefd, buf->reference(), buf->size());
if (ret == 0) { // the file is done
delete buf;
Index: libnet/http.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/http.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libnet/http.h 29 Mar 2008 19:35:53 -0000 1.4
+++ libnet/http.h 1 Apr 2008 22:20:37 -0000 1.5
@@ -27,6 +27,7 @@
#include "rtmp.h"
#include "handler.h"
#include "network.h"
+#include "buffer.h"
namespace gnash
{
@@ -126,51 +127,51 @@
// 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(Buffer *data)
+ 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(Buffer *data)
+ http_method_e extractCommand(amf::Buffer *data)
{ return extractCommand(data->reference()); };
int extractAccept(gnash::Network::byte_t *data);
- int extractAccept(Buffer *data)
+ int extractAccept(amf::Buffer *data)
{ return extractAccept(data->reference()); };
std::string &extractAcceptRanges(gnash::Network::byte_t *data);
- std::string &extractAcceptRanges(Buffer *data)
+ std::string &extractAcceptRanges(amf::Buffer *data)
{ return extractAcceptRanges(data->reference()); };
int extractLanguage(gnash::Network::byte_t *data);
- int extractLanguage(Buffer *data)
+ int extractLanguage(amf::Buffer *data)
{ return extractLanguage(data->reference()); };
int extractCharset(gnash::Network::byte_t *data);
- int extractCharset(Buffer *data)
+ int extractCharset(amf::Buffer *data)
{ return extractCharset(data->reference()); };
int extractEncoding(gnash::Network::byte_t *data);
- int extractEncoding(Buffer *data)
+ int extractEncoding(amf::Buffer *data)
{ return extractEncoding(data->reference()); };
int extractTE(gnash::Network::byte_t *data);
- int extractTE(Buffer *data)
+ int extractTE(amf::Buffer *data)
{ return extractTE(data->reference()); };
int extractConnection(gnash::Network::byte_t *data);
- int extractConnection(Buffer *data)
+ int extractConnection(amf::Buffer *data)
{ return extractConnection(data->reference()); };
int extractKeepAlive(gnash::Network::byte_t *data);
- int extractKeepAlive(Buffer *data)
+ int extractKeepAlive(amf::Buffer *data)
{ return extractConnection(data->reference()); };
// These return the string that was found for this field.
std::string &extractMethod(gnash::Network::byte_t *data);
- std::string &extractMethod(Buffer *data)
+ std::string &extractMethod(amf::Buffer *data)
{ return extractMethod(data->reference()); };
std::string &extractReferer(gnash::Network::byte_t *data);
- std::string &extractReferer(Buffer *data)
+ std::string &extractReferer(amf::Buffer *data)
{ return extractReferer(data->reference()); };
std::string &extractHost(gnash::Network::byte_t *data);
- std::string &extractHost(Buffer *data)
+ std::string &extractHost(amf::Buffer *data)
{ return extractHost(data->reference()); };
std::string &extractAgent(gnash::Network::byte_t *data);
- std::string &extractAgent(Buffer *data)
+ std::string &extractAgent(amf::Buffer *data)
{ return extractAgent(data->reference()); };
// These methods add data to the fields in the HTTP header.
Index: libnet/network.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/network.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- libnet/network.cpp 28 Mar 2008 03:30:23 -0000 1.1
+++ libnet/network.cpp 1 Apr 2008 22:20:38 -0000 1.2
@@ -57,7 +57,7 @@
namespace gnash {
static const char *DEFAULTPROTO = "tcp";
-static const short DEFAULTPORT = RTMP;
+static const short DEFAULTPORT = RTMP_PORT;
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
@@ -434,7 +434,7 @@
{
// GNASH_REPORT_FUNCTION;
- return createClient("localhost", RTMP);
+ return createClient("localhost", RTMP_PORT);
}
bool
Network::createClient(short /* port */)
@@ -449,7 +449,7 @@
{
// GNASH_REPORT_FUNCTION;
- return createClient(hostname, RTMP);
+ return createClient(hostname, RTMP_PORT);
}
bool
Index: libnet/network.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/network.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- libnet/network.h 28 Mar 2008 03:30:23 -0000 1.1
+++ libnet/network.h 1 Apr 2008 22:20:38 -0000 1.2
@@ -41,10 +41,12 @@
namespace gnash {
// Define the ports for the RTMP protocols
-const short ADMIN = 1111;
-const short RTMP = 1935;
-const short RTMPT = 80;
-const short RTMPTS = 443;
+const short ADMIN_PORT = 1111;
+const short RTMP_PORT = 1935;
+const short RTMPE_PORT = 1935;
+const short RTMPT_PORT = 80;
+const short RTMPTE_PORT = 80;
+const short RTMPTS_PORT = 443;
#ifdef __OS2__
typedef int socklen_t;
@@ -88,12 +90,14 @@
DSOEXPORT bool createClient(const std::string &hostname, short port);
// Read from the connection
+// int readNet(Buffer &buffer);
int readNet(byte_t *buffer, int nbytes);
DSOEXPORT int readNet(byte_t *buffer, int nbytes, int timeout);
int readNet(int fd, byte_t *buffer, int nbytes);
int readNet(int fd, byte_t *buffer, int nbytes, int timeout);
// Write to the connection
+// int writeNet(gnash::Buffer &buffer);
int writeNet(const std::string &buffer);
DSOEXPORT int writeNet(const byte_t *buffer, int nbytes);
// int writeNet(int fd, const byte_t *buffer);
Index: libnet/rtmp.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/rtmp.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libnet/rtmp.cpp 29 Mar 2008 19:35:53 -0000 1.4
+++ libnet/rtmp.cpp 1 Apr 2008 22:20:38 -0000 1.5
@@ -36,10 +36,11 @@
#include "element.h"
#include "handler.h"
#include "utility.h"
+#include "buffer.h"
-using namespace amf;
using namespace gnash;
using namespace std;
+using namespace amf;
namespace gnash
{
@@ -78,13 +79,13 @@
};
int
-RTMPproto::headerSize(Network::byte_t header)
+RTMP::headerSize(Network::byte_t header)
{
// GNASH_REPORT_FUNCTION;
int headersize = -1;
- switch (header & AMF_HEADSIZE_MASK) {
+ switch (header & RTMP_HEADSIZE_MASK) {
case HEADER_12:
headersize = 12;
break;
@@ -99,7 +100,7 @@
break;
default:
log_error(_("AMF Header size bits (0x%X) out of range"),
- header & AMF_HEADSIZE_MASK);
+ header & RTMP_HEADSIZE_MASK);
headersize = 1;
break;
};
@@ -107,7 +108,7 @@
return headersize;
}
-RTMPproto::RTMPproto()
+RTMP::RTMP()
: _handshake(0), _handler(0)
{
// GNASH_REPORT_FUNCTION;
@@ -118,7 +119,7 @@
// memset(_body, 0, RTMP_BODY_SIZE+1);
}
-RTMPproto::~RTMPproto()
+RTMP::~RTMP()
{
// GNASH_REPORT_FUNCTION;
_variables.clear();
@@ -126,28 +127,28 @@
}
void
-RTMPproto::addVariable(amf::Element *el)
+RTMP::addVariable(amf::Element *el)
{
// GNASH_REPORT_FUNCTION;
- _variables[el->getName().c_str()] = el;
+ _variables[el->getName()] = el;
}
void
-RTMPproto::addVariable(char *name, Element *el)
+RTMP::addVariable(char *name, amf::Element *el)
{
// GNASH_REPORT_FUNCTION;
_variables[name] = el;
}
amf::Element *
-RTMPproto::getVariable(const std::string &name)
+RTMP::getVariable(const std::string &name)
{
// GNASH_REPORT_FUNCTION;
// return _variables[name.c_str()];
map<const char *, amf::Element *>::iterator it;
for (it = _variables.begin(); it != _variables.end(); it++) {
const char *title = it->first;
- Element *el = it->second;
+ amf::Element *el = it->second;
if (name == title) {
// log_debug("found variable in RTMP packet: %s", name);
return el;
@@ -158,7 +159,7 @@
// A request for a handshake is initiated by sending a byte with a
// value of 0x3, followed by a message body of unknown format.
bool
-RTMPproto::handShakeRequest()
+RTMP::handShakeRequest()
{
GNASH_REPORT_FUNCTION;
@@ -191,7 +192,7 @@
// The client finished the handshake process by sending the second
// data block we get from the server as the response
bool
-RTMPproto::clientFinish()
+RTMP::clientFinish()
{
GNASH_REPORT_FUNCTION;
@@ -224,7 +225,7 @@
}
bool
-RTMPproto::packetRequest()
+RTMP::packetRequest()
{
GNASH_REPORT_FUNCTION;
return false;
@@ -232,14 +233,65 @@
#if 0
bool
-RTMPproto::packetSend(Buffer * /* buf */)
+RTMP::packetSend(amf::Buffer * /* buf */)
{
GNASH_REPORT_FUNCTION;
return false;
}
+#endif
+
+/// \brief \ Each RTMP header consists of the following:
+///
+/// * Index & header size - The header size and amf channel index.
+/// * Total size - The total size of the message
+/// * Type - The type of the message
+/// * Routing - The source/destination of the message
+Network::byte_t *
+RTMP::encodeRTMPHeader(int amf_index, rtmp_headersize_e head_size,
+ size_t total_size, content_types_e type,
+ rtmp_source_e routing)
+{
+// GNASH_REPORT_FUNCTION;
+ Network::byte_t *out = new Network::byte_t[total_size + 12 + 4];
+ memset(out, 0, total_size + 12 + 4);
+ char *tmpptr = reinterpret_cast<char *>(out);
+ // Make the index & header size byte
+ *tmpptr = head_size & RTMP_HEADSIZE_MASK;
+ *tmpptr += amf_index & RTMP_INDEX_MASK;
+ tmpptr++;
+
+ // Add the unknown bytes. These seem to be used by video and
+ // audio, and only when the header size is 4 or more.
+ if (head_size <= HEADER_4) {
+ memset(tmpptr, 0, 3);
+ tmpptr += 3;
+ }
+
+ // Add the size of the message if the header size is 8 or more.
+ if (head_size <= HEADER_8) {
+ int length = total_size;
+ swapBytes(&length, 4);
+ memcpy(tmpptr, ((char *)&length +1), 3);
+ tmpptr += 3;
+ }
+
+ // Add the type of the objectif the header size is 8 or more.
+ if (head_size <= HEADER_8) {
+ *tmpptr = type;
+ tmpptr++;
+ }
+
+ // Add the routing of the message if the header size is 12 or more.
+ if (head_size == HEADER_12) {
+ memcpy(tmpptr, &routing, 4);
+ tmpptr += 4;
+ }
+
+ return out;
+}
bool
-RTMPproto::packetRead(Buffer *buf)
+RTMP::packetRead(amf::Buffer *buf)
{
GNASH_REPORT_FUNCTION;
@@ -249,7 +301,7 @@
AMF amf;
//
address@hidden@\000\000\000\000\000\000\003\000\003app\002\000#software/gnash/tests/1153948634.flv\000\bflashVer\002\000\fLNX
6,0,82,0\000\006swfUrl\002\000\035file:///file|address@hidden://localhost/software/gnash/tests/1153948634
- amf_index = *buf->reference() & AMF_INDEX_MASK;
+ amf_index = *buf->reference() & RTMP_INDEX_MASK;
headersize = headerSize(*buf->reference());
log_debug (_("The Header size is: %d"), headersize);
log_debug (_("The AMF index is: 0x%x"), amf_index);
@@ -274,16 +326,14 @@
ptr = parseHeader(ptr);
// ptr += headersize;
- Element el;
- ptr = amf.extractElement(&el, ptr);
- el.dump();
- ptr = amf.extractElement(&el, ptr) + 1;
- el.dump();
+ amf::Element *el = amf.extractAMF(ptr);
+ el->dump();
+ el = amf.extractAMF(ptr) + 1;
+ el->dump();
log_debug (_("Reading AMF packets till we're done..."));
buf->dump();
while (ptr < end) {
- amf::Element *el = new amf::Element;
- ptr = amf.extractVariable(el, ptr);
+ amf::Element *el = amf.extractVariable(ptr);
addVariable(el);
el->dump();
}
@@ -296,21 +346,16 @@
buf = _handler->merge(buf);
}
while ((ptr - buf->begin()) < actual_size) {
- amf::Element *el = new amf::Element;
- if (ptr) {
- ptr = amf.extractVariable(el, ptr);
+ amf::Element *el = amf.extractVariable(ptr);
addVariable(el);
- } else {
- return true;
- }
el->dump(); // FIXME: dump the AMF objects as they are read
in
}
dump();
- Element *url = getVariable("tcUrl");
- Element *file = getVariable("swfUrl");
- Element *app = getVariable("app");
+ amf::Element *url = getVariable("tcUrl");
+ amf::Element *file = getVariable("swfUrl");
+ amf::Element *app = getVariable("app");
if (file) {
log_debug("SWF file %s", file->getData());
@@ -324,32 +369,31 @@
return true;
}
-#endif
void
-RTMPproto::dump()
+RTMP::dump()
{
cerr << "RTMP packet contains " << _variables.size() << " variables." <<
endl;
map<const char *, amf::Element *>::iterator it;
for (it = _variables.begin(); it != _variables.end(); it++) {
// const char *name = it->first;
- Element *el = it->second;
+ amf::Element *el = it->second;
el->dump();
}
}
Network::byte_t *
-RTMPproto::parseHeader(Network::byte_t *in)
+RTMP::parseHeader(Network::byte_t *in)
{
// GNASH_REPORT_FUNCTION;
Network::byte_t *tmpptr = in;
- _amf_index = *tmpptr & AMF_INDEX_MASK;
+ _amf_index = *tmpptr & RTMP_INDEX_MASK;
log_debug (_("The AMF channel index is %d"), _amf_index);
_header_size = headerSize(*tmpptr++);
- log_debug (_("The header size is %d"), _header_size);
+ printf (_("The header size is %d"), _header_size);
if (_header_size >= 4) {
_mystery_word = *tmpptr++;
@@ -363,9 +407,6 @@
_total_size = (_total_size << 12) + *tmpptr++;
_total_size = (_total_size << 8) + *tmpptr++;
_total_size = _total_size & 0xffffff;
-// _amf_data = new uint8_t(_total_size+1);
-// _seekptr = _amf_data;
-// memset(_amf_data, 0, _total_size+1);
log_debug(_("The body size is: %d"), _total_size);
}
@@ -385,10 +426,10 @@
// case NOTIFY:
// case SHARED_OBJ:
// case INVOKE:
-// _packet_size = AMF_VIDEO_PACKET_SIZE;
+// _packet_size = RTMP_VIDEO_PACKET_SIZE;
// break;
// case AUDIO_DATA:
-// _packet_size = AMF_AUDIO_PACKET_SIZE;
+// _packet_size = RTMP_AUDIO_PACKET_SIZE;
// break;
// default:
// log_error (_("ERROR: Unidentified AMF header data type 0x%x"),
_type);
@@ -396,7 +437,6 @@
// };
if (_header_size == 12) {
-// hexify((Network::byte_t *)hexint, (Network::byte_t *)tmpptr, 3,
false);
_src_dest = *(reinterpret_cast<rtmp_source_e *>(tmpptr));
tmpptr += sizeof(unsigned int);
log_debug(_("The source/destination is: %x"), _src_dest);
Index: libnet/rtmp.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/rtmp.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libnet/rtmp.h 29 Mar 2008 19:35:53 -0000 1.3
+++ libnet/rtmp.h 1 Apr 2008 22:20:38 -0000 1.4
@@ -26,17 +26,55 @@
#include "element.h"
#include "handler.h"
#include "network.h"
+#include "buffer.h"
+#include "amfutf8.h"
namespace gnash
{
-#define RTMP_HANDSHAKE 0x3
-#define RTMP_BODY_SIZE 1536
-#define MAX_AMF_INDEXES 64
+const int RTMP_HANDSHAKE = 0x3;
+const int RTMP_BODY_SIZE = 1536;
+const int MAX_AMF_INDEXES = 64;
+
+const int RTMP_HEADSIZE_MASK = 0xc0;
+const char RTMP_INDEX_MASK = 0x3f;
+const int RTMP_VIDEO_PACKET_SIZE = 128;
+const int RTMP_AUDIO_PACKET_SIZE = 64;
-class DSOEXPORT RTMPproto
+// For terminating sequences, a byte with value 0x09 is used.
+const char TERMINATOR = 0x09;
+
+// Each packet consists of the following:
+//
+// The first byte of the AMF file/stream is believed to be a version
+// indicator. So far the only valid value for this field that has been
+// found is 0x00. If it is anything other than 0x00 (zero), your
+// system should consider the AMF file/stream to be
+// 'malformed'd. This can happen in the IDE if AMF calls are put
+// on the stack but never executed and the user exits the movie from the
+// IDE; the two top bytes will be random and the number of headers will
+// be unreliable.
+
+// The third and fourth bytes form an integer value that specifies the
+// number of headers.
+typedef struct {
+ gnash::Network::byte_t version;
+ gnash::Network::byte_t source;
+ boost::uint32_t count;
+} amfpacket_t;
+
+typedef enum {
+ onStatus,
+ onResult,
+ onDebugEvents
+} amfresponse_e;
+
+class DSOEXPORT RTMP
{
public:
+ // The second byte of the AMF file/stream is appears to be 0x00 if the
+ // client is the Flash Player and 0x01 if the client is the FlashCom
+ // server.
typedef enum {
FROM_CLIENT, // Flash player
FROM_SERVER // Flash com server
@@ -125,16 +163,19 @@
void *data;
} rtmp_body_t;
- RTMPproto();
- ~RTMPproto();
+ RTMP();
+ ~RTMP();
+ gnash::Network::byte_t *encodeRTMPHeader(int amf_index, rtmp_headersize_e
head_size,
+ size_t total_size, content_types_e type,
rtmp_source_e routing);
+
// bool handShakeWait();
bool handShakeRequest();
// bool handShakeResponse();
bool clientFinish();
// bool serverFinish();
bool packetRequest();
- bool packetSend(Buffer *buf);
- bool packetRead(Buffer *buf);
+ bool packetSend(amf::Buffer *buf);
+ bool packetRead(amf::Buffer *buf);
void addVariable(amf::Element *el);
void addVariable(char *name, amf::Element *el);
@@ -165,7 +206,7 @@
void dump();
protected:
std::map<const char *, amf::Element *> _variables;
- Buffer *_handshake;
+ amf::Buffer *_handshake;
Handler *_handler;
int _amf_index;
int _header_size;
Index: libnet/rtmp_server.cpp
===================================================================
RCS file: /sources/gnash/gnash/libnet/rtmp_server.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libnet/rtmp_server.cpp 31 Mar 2008 00:36:34 -0000 1.2
+++ libnet/rtmp_server.cpp 1 Apr 2008 22:20:39 -0000 1.3
@@ -37,10 +37,11 @@
#include "element.h"
#include "handler.h"
#include "utility.h"
+#include "buffer.h"
-using namespace amf;
using namespace gnash;
using namespace std;
+using namespace amf;
namespace gnash
{
@@ -73,7 +74,7 @@
// char buffer[RTMP_BODY_SIZE+16];
// memset(buffer, 0, RTMP_BODY_SIZE+16);
- Buffer *buf = _handler->pop();
+ amf::Buffer *buf = _handler->pop();
if (buf == 0) {
log_debug("Que empty, net connection dropped for fd #%d",
_handler->getFileFd());
@@ -99,7 +100,7 @@
// }
if (buf->size() >= RTMP_BODY_SIZE) {
- _handshake = new Buffer(RTMP_BODY_SIZE);
+ _handshake = new amf::Buffer(RTMP_BODY_SIZE);
_handshake->copy(buf->reference() + 1, RTMP_BODY_SIZE);
log_debug (_("Handshake Data matched"));
delete buf; // we're done with the buffer
@@ -120,7 +121,7 @@
{
GNASH_REPORT_FUNCTION;
- Buffer *buf = new Buffer((RTMP_BODY_SIZE * 2) + 1);
+ amf::Buffer *buf = new amf::Buffer((RTMP_BODY_SIZE * 2) + 1);
Network::byte_t *ptr = buf->reference();
*ptr = 0x3;
@@ -139,8 +140,8 @@
{
GNASH_REPORT_FUNCTION;
- Buffer *buf = _handler->pop();
- Buffer *obj = buf;
+ amf::Buffer *buf = _handler->pop();
+ amf::Buffer *obj = buf;
if (buf == 0) {
log_debug("Que empty, net connection dropped for fd #%d",
_handler->getFileFd());
@@ -152,7 +153,7 @@
// the remainder for processing.
if (buf->size() > RTMP_BODY_SIZE) {
int size = buf->size() - RTMP_BODY_SIZE;
- obj = new Buffer[size];
+ obj = new amf::Buffer[size];
obj->copy(buf->begin()+RTMP_BODY_SIZE, size);
} else {
_handler->wait();
@@ -174,14 +175,14 @@
}
bool
-RTMPServer::packetSend(Buffer * /* buf */)
+RTMPServer::packetSend(amf::Buffer * /* buf */)
{
GNASH_REPORT_FUNCTION;
return false;
}
bool
-RTMPServer::packetRead(Buffer *buf)
+RTMPServer::packetRead(amf::Buffer *buf)
{
GNASH_REPORT_FUNCTION;
@@ -192,7 +193,7 @@
AMF amf;
//
address@hidden@\000\000\000\000\000\000\003\000\003app\002\000#software/gnash/tests/1153948634.flv\000\bflashVer\002\000\fLNX
6,0,82,0\000\006swfUrl\002\000\035file:///file|address@hidden://localhost/software/gnash/tests/1153948634
- amf_index = *buf->reference() & AMF_INDEX_MASK;
+ amf_index = *buf->reference() & RTMP_INDEX_MASK;
headersize = headerSize(*buf->reference());
log_debug (_("The Header size is: %d"), headersize);
log_debug (_("The AMF index is: 0x%x"), amf_index);
@@ -232,7 +233,7 @@
el->dump();
}
ptr += 1;
- size_t actual_size = _total_size - AMF_HEADER_SIZE;
+ size_t actual_size = _total_size - RTMP_HEADER_SIZE;
log_debug("Total size in header is %d, buffer size is: %d", _total_size,
buf->size());
// buf->dump();
if (buf->size() < actual_size) {
Index: libnet/rtmp_server.h
===================================================================
RCS file: /sources/gnash/gnash/libnet/rtmp_server.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- libnet/rtmp_server.h 29 Mar 2008 18:48:32 -0000 1.1
+++ libnet/rtmp_server.h 1 Apr 2008 22:20:39 -0000 1.2
@@ -24,14 +24,14 @@
#include "rtmp.h"
#include "amf.h"
-#include "element.h"
#include "handler.h"
#include "network.h"
+#include "buffer.h"
namespace gnash
{
- class DSOEXPORT RTMPServer : public RTMPproto
+class DSOEXPORT RTMPServer : public RTMP
{
public:
RTMPServer();
@@ -39,8 +39,8 @@
bool handShakeWait();
bool handShakeResponse();
bool serverFinish();
- bool packetSend(Buffer *buf);
- bool packetRead(Buffer *buf);
+ bool packetSend(amf::Buffer *buf);
+ bool packetRead(amf::Buffer *buf);
// These process the incoming RTMP message content types from the header
gnash::Network::byte_t *decodeChunkSize(gnash::Network::byte_t *buf);
Index: libamf/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libamf/Makefile.am,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- libamf/Makefile.am 29 Mar 2008 19:35:53 -0000 1.34
+++ libamf/Makefile.am 1 Apr 2008 22:20:39 -0000 1.35
@@ -21,6 +21,7 @@
pkglib_LTLIBRARIES = libgnashamf.la
libgnashamf_la_SOURCES = \
amf.cpp \
+ buffer.cpp \
element.cpp \
lcshm.cpp \
sol.cpp
@@ -45,6 +46,7 @@
noinst_HEADERS = \
amfutf8.h \
amf.h \
+ buffer.h \
element.h \
lcshm.h \
protocol.h \
Index: libamf/amf.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- libamf/amf.cpp 31 Mar 2008 00:21:24 -0000 1.65
+++ libamf/amf.cpp 1 Apr 2008 22:20:40 -0000 1.66
@@ -31,6 +31,7 @@
#endif
#include "log.h"
+#include "buffer.h"
#include "amf.h"
#include "network.h"
#include "element.h"
@@ -289,23 +290,19 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeNumber(double indata)
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_NUMBER_SIZE + AMF_HEADER_SIZE;
double num;
// Encode the data as a 64 bit, big-endian, numeric value
- Network::byte_t *ptr = new Network::byte_t[pktsize + 1];
- Network::byte_t *x = ptr;
- memset(x, 0, pktsize);
- *x++ = (char)Element::NUMBER;
- memcpy(&num, &indata, AMF_NUMBER_SIZE);
+ Buffer *buf = new Buffer(AMF_NUMBER_SIZE + AMF_HEADER_SIZE);
+ buf->append(Element::NUMBER);
+ num = indata;
swapBytes(&num, AMF_NUMBER_SIZE);
- memcpy(x, &num, AMF_NUMBER_SIZE);
-// x += pktsize - AMF_HEADER_SIZE;
+ buf->append(num);
- return ptr;
+ return buf;
}
/// Encode a Boolean object
@@ -315,23 +312,18 @@
///
/// Although a boolean is one byte in size, swf uses 16bit short integers
/// heavily, so this value is also a short.
-Network::byte_t *
+Buffer *
AMF::encodeBoolean(bool flag)
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_HEADER_SIZE;
-
- Network::byte_t*ptr = new Network::byte_t[pktsize + 1];
- Network::byte_t* x = ptr;
- memset(x, 0, pktsize);
// Encode a boolean value. 0 for false, 1 for true
- *x++ = (char)Element::BOOLEAN;
- x++;
- *x = flag;
-// swapBytes(x, 2);
-// x += sizeof(boost::uint16_t);
+ Buffer *buf = new Buffer(AMF_HEADER_SIZE);
+ buf->append(Element::BOOLEAN);
+ bool x = flag;
+ swapBytes(&x, 2);
+ buf->append(x);
- return ptr;
+ return buf;
}
/// Encode an object
@@ -339,22 +331,20 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
-AMF::encodeObject(const Network::byte_t *data, int size)
+Buffer *
+AMF::encodeObject(Network::byte_t *data, int size)
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_HEADER_SIZE + size;
-
// Encode an XML object. The data follows a 4 byte length
// field. (which must be big-endian)
- Network::byte_t *x = new Network::byte_t[pktsize + 1];
- memset(x, 0, pktsize);
- *x++ = Element::OBJECT;
- uint32_t num = size;
+ Buffer *buf = new Buffer(AMF_HEADER_SIZE + size);
+ buf->append(Element::OBJECT);
+ boost::uint32_t num = size;
swapBytes(&num, 4);
- memcpy(x, data, size);
+ buf->append(num);
+ buf->append(data, size);
- return x;
+ return buf;
}
/// Encode an "Undefined" object
@@ -362,18 +352,14 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeUndefined()
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_HEADER_SIZE;;
- Network::byte_t* x = new Network::byte_t[pktsize + 1];
- memset(x, 0, pktsize);
- *x++ = (char)Element::UNDEFINED;
-// *x = *static_cast<const char *>(flag);
- x += pktsize - AMF_HEADER_SIZE;
+ Buffer *buf = new Buffer(AMF_HEADER_SIZE);
+ buf->append(Element::UNDEFINED);
- return x;
+ return buf;
}
/// Encode an "Undefined" object
@@ -381,18 +367,14 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeUnsupported()
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_HEADER_SIZE;;
- Network::byte_t* x = new Network::byte_t[pktsize + 1];
- memset(x, 0, pktsize);
- *x++ = (char)Element::UNSUPPORTED;
-// *x = *static_cast<const char *>(flag);
- x += pktsize - AMF_HEADER_SIZE;
+ Buffer *buf = new Buffer(AMF_HEADER_SIZE);
+ buf->append(Element::UNSUPPORTED);
- return x;
+ return buf;
}
/// Encode a Date
@@ -400,25 +382,23 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *encodeDate(Network::byte_t *data)
+Buffer *encodeDate(Network::byte_t *data)
{
// GNASH_REPORT_FUNCTION;
- int pktsize = AMF_HEADER_SIZE;;
- Network::byte_t *x = new Network::byte_t[pktsize + 1];
- memset(x, 0, pktsize);
- *x++ = Element::DATE;
+ Buffer *buf = new Buffer(AMF_HEADER_SIZE);
+ buf->append(Element::DATE);
double num = *reinterpret_cast<const double*>(data);
swapBytes(&num, 8);
- memcpy(x, &num, 8);
+ buf->append(num);
- return x;
+ return buf;
}
/// Encode a "NULL" object
///
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeNull()
{
// GNASH_REPORT_FUNCTION;
@@ -432,7 +412,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeXMLObject(Network::byte_t * /*data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -446,7 +426,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeTypedObject(Network::byte_t * /* data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -460,7 +440,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeReference(Network::byte_t * /* data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -474,7 +454,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeMovieClip(Network::byte_t * /*data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -488,7 +468,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeECMAArray(Network::byte_t * /*data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -502,7 +482,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeLongString(Network::byte_t * /* data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -516,7 +496,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeRecordSet(Network::byte_t * /* data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -531,7 +511,7 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
+Buffer *
AMF::encodeStrictArray(Network::byte_t * /* data */, int /* size */)
{
// GNASH_REPORT_FUNCTION;
@@ -545,28 +525,25 @@
/// @return a binary AMF packet in big endian format (header,data) which
/// needs to be deleted[] after being used.
///
-Network::byte_t *
-AMF::encodeElement(const char *str)
+Buffer *
+AMF::encodeString(const string &str)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
boost::uint16_t length;
- int pktsize = strlen(str) + AMF_HEADER_SIZE;
- // Encode a string value. The data follows a 2 byte length
- // field. (which must be big-endian)
- Network::byte_t *ptr = new Network::byte_t[pktsize + 1];
- Network::byte_t *x = ptr;
- memset(x, 0, pktsize);
- *x++ = Element::STRING;
- length = strlen(str);
+ Buffer *buf = new Buffer(str.size() + AMF_HEADER_SIZE);
+ buf->append(Element::STRING);
+ // when a string is stored in an element, we add a NULL terminator so
+ // it can be printed by to_string() efficiently. The NULL terminator
+ // doesn't get written when encoding a string as it has a byte count
+ // instead.
+ length = str.size() - 1;
log_debug("Encoded data size is going to be %d", length);
swapBytes(&length, 2);
- memcpy(x, &length, 2);
- x += 2;
- memcpy(x, str, pktsize - AMF_HEADER_SIZE);
- x += pktsize - AMF_HEADER_SIZE;
+ buf->append(length);
+ buf->append(str);
- return ptr;
+ return buf;
}
/// \brief Write an AMF element
@@ -586,7 +563,7 @@
/// normal ASCII. It may be that these need to be converted to wide
/// characters, but for now we just leave them as standard multibyte
/// characters.
-Network::byte_t *
+Buffer *
AMF::encodeElement(Element *el)
{
// GNASH_REPORT_FUNCTION;
@@ -602,7 +579,7 @@
return encodeBoolean(el->to_bool());
break;
case Element::STRING:
- return encodeElement(el->to_string());
+ return encodeString(el->to_string());
break;
case Element::OBJECT:
return encodeObject(el->getData(), el->getLength());
@@ -661,6 +638,7 @@
return 0;
}
+#if 0
/// Encode an array of elements.
///
/// @return a binary AMF packet in big endian format (header,data)
@@ -668,7 +646,7 @@
/// @return a newly allocated byte array.
/// to be deleted by caller using delete [] operator, or NULL
///
-vector<Network::byte_t> *
+vector<Buffer> *
AMF::encodeElement(vector<amf::Element *> &data)
{
GNASH_REPORT_FUNCTION;
@@ -738,6 +716,7 @@
}
return vec;
}
+#endif
#if 0
AMF::astype_e
@@ -980,241 +959,206 @@
return el;
}
-
-// AMF::amf_element_t *
-// createElement(AMF::amf_element_t *el, std::string &name,
-// boost::intrusive_ptr<gnash::as_object> &data)
-// {
-// GNASH_REPORT_FUNCTION;
-// log_debug("Creating element %s", name.c_str());
-
-// el->type = AMF::OBJECT;
-// el->name = name;
-// el->length = sizeof(data);
-// el->data = new uint8_t[sizeof(uint16_t)];
-// memset(el->data, 0, sizeof(uint16_t));
-// memcpy(el->data, (char *)&data, el->length);
-// return el;
-// }
-
-// AMF::amf_element_t *
-// createElement(AMF::amf_element_t *el, const char *name,
-// boost::intrusive_ptr<gnash::as_object> &data)
-// {
-// GNASH_REPORT_FUNCTION;
-// string str = name;
-// return createElement(el, str, data);
-// }
#endif
-boost::uint8_t *
+Buffer *
AMF::encodeVariable(amf::Element *el)
{
GNASH_REPORT_FUNCTION;
- size_t outsize = el->getName().size() + el->getLength() + 5; // why +5
here ?
- Network::byte_t *out = new Network::byte_t[outsize + 4]; // why +4 here ?
- Network::byte_t *end = out + outsize+4; // why +4 ?
+ size_t outsize = el->getNameSize() + el->getLength() + AMF_VAR_HEADER_SIZE;
+
+ Buffer *buf = new Buffer(outsize);
+// Network::byte_t *out = new Network::byte_t[outsize + 4]; // why +4 here
?
+// Network::byte_t *end = out + outsize+4; // why +4 ?
- memset(out, 0, outsize + 2); // why +2 here ?
- Network::byte_t *tmpptr = out;
+// memset(out, 0, outsize + 2); // why +2 here ?
+// Network::byte_t *tmpptr = out;
// Add the length of the string for the name of the variable
- size_t length = el->getName().size();
+ size_t length = el->getNameSize();
boost::uint16_t enclength = length;
swapBytes(&enclength, 2);
- assert(tmpptr+2 < end);
- memcpy(tmpptr, &enclength, 2);
+ buf->copy(enclength);
- // Add the actual name
- tmpptr += sizeof(uint16_t);
- assert(tmpptr+length < end);
- memcpy(tmpptr, el->getName().c_str(), length);
- tmpptr += length;
+ buf->append(el->getName());
// Add the type of the variable's data
- *tmpptr++ = el->getType();
+ buf->append(el->getType());
// Booleans appear to be encoded weird. Just a short after
// the type byte that's the value.
switch (el->getType()) {
case Element::BOOLEAN:
enclength = el->to_bool();
- assert(tmpptr+2 < end);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += sizeof(uint16_t);
+ buf->append(enclength);
break;
case Element::NUMBER:
if (el->getData()) {
swapBytes(el->getData(), AMF_NUMBER_SIZE);
- assert(tmpptr+AMF_NUMBER_SIZE < end);
- memcpy(tmpptr, el->getData(), AMF_NUMBER_SIZE);
+ buf->append(el->getData(), AMF_NUMBER_SIZE);
}
break;
default:
enclength = el->getLength();
swapBytes(&enclength, 2);
- assert(tmpptr+2 < end);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += sizeof(uint16_t);
+ buf->append(enclength);
// Now the data for the variable
- assert(tmpptr+el->getLength() < end);
- memcpy(tmpptr, el->getData(), el->getLength());
+ buf->append(el->getData(), el->getLength());
}
- return reinterpret_cast<boost::uint8_t *>(out);
+ return buf;
}
-#if 0
-Network::byte_t *
-AMF::encodeVariable(const char *name, bool flag)
-{
-// GNASH_REPORT_FUNCTION;
-
- int outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
- Network::byte_t *out = new uint8_t[outsize];
- Network::byte_t *tmpptr = out;
-
- size_t length = strlen(name);
- short enclength = length;
- swapBytes(&enclength, 2);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += 2;
- memcpy(tmpptr, name, length);
- tmpptr += length;
- *tmpptr = Element::BOOLEAN;
- tmpptr++;
- *tmpptr = flag;
-
- return out;
-}
-
-Network::byte_t *
-AMF::encodeVariable(const char *name)
-{
-// GNASH_REPORT_FUNCTION;
- size_t outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
- Network::byte_t *out = new Network::byte_t[outsize];
- Network::byte_t *tmpptr = out;
-
- size_t length = strlen(name);
- short enclength = length;
- swapBytes(&enclength, 2);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += 2;
- memcpy(tmpptr, name, length);
- tmpptr += length;
- *tmpptr = Element::UNDEFINED;
- tmpptr++;
+// #if 0
+// Network::byte_t *
+// AMF::encodeVariable(const char *name, bool flag)
+// {
+// // GNASH_REPORT_FUNCTION;
- return out;
-}
+// int outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
+// Network::byte_t *out = new uint8_t[outsize];
+// Network::byte_t *tmpptr = out;
+
+// size_t length = strlen(name);
+// short enclength = length;
+// swapBytes(&enclength, 2);
+// memcpy(tmpptr, &enclength, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, name, length);
+// tmpptr += length;
+// *tmpptr = Element::BOOLEAN;
+// tmpptr++;
+// *tmpptr = flag;
-Network::byte_t *
-AMF::encodeVariable(const char *name, double bignum)
-{
-// GNASH_REPORT_FUNCTION;
- int outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
- Network::byte_t *out = new Network::byte_t[outsize];
- Network::byte_t *tmpptr = out;
- double newnum = bignum;
- char *numptr = (char *)&newnum;
+// return out;
+// }
- size_t length = strlen(name);
- short enclength = length;
- swapBytes(&enclength, 2);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += 2;
- memcpy(tmpptr, name, length);
- tmpptr += length;
- *tmpptr = Element::NUMBER;
- tmpptr++;
-// swapBytes(numptr, AMF_NUMBER_SIZE);
- memcpy(tmpptr, numptr, AMF_NUMBER_SIZE);
+// Network::byte_t *
+// AMF::encodeVariable(const char *name)
+// {
+// // GNASH_REPORT_FUNCTION;
+// size_t outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
+// Network::byte_t *out = new Network::byte_t[outsize];
+// Network::byte_t *tmpptr = out;
+
+// size_t length = strlen(name);
+// short enclength = length;
+// swapBytes(&enclength, 2);
+// memcpy(tmpptr, &enclength, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, name, length);
+// tmpptr += length;
+// *tmpptr = Element::UNDEFINED;
+// tmpptr++;
- return out;
-}
+// return out;
+// }
-uint8_t *
-AMF::encodeVariable(const char *name, const char *val)
-{
-// GNASH_REPORT_FUNCTION;
+// Network::byte_t *
+// AMF::encodeVariable(const char *name, double bignum)
+// {
+// // GNASH_REPORT_FUNCTION;
+// int outsize = strlen(name) + AMF_NUMBER_SIZE + 5;
+// Network::byte_t *out = new Network::byte_t[outsize];
+// Network::byte_t *tmpptr = out;
+// double newnum = bignum;
+// char *numptr = (char *)&newnum;
+
+// size_t length = strlen(name);
+// short enclength = length;
+// swapBytes(&enclength, 2);
+// memcpy(tmpptr, &enclength, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, name, length);
+// tmpptr += length;
+// *tmpptr = Element::NUMBER;
+// tmpptr++;
+// // swapBytes(numptr, AMF_NUMBER_SIZE);
+// memcpy(tmpptr, numptr, AMF_NUMBER_SIZE);
- int outsize = strlen(name) + strlen(val) + 5;
- Network::byte_t *out = new Network::byte_t[outsize];
- Network::byte_t *tmpptr = out;
+// return out;
+// }
- size_t length = strlen(name);
- short enclength = length;
- swapBytes(&enclength, 2);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += 2;
- memcpy(tmpptr, name, length);
- tmpptr += length;
- *tmpptr = Element::STRING;
- tmpptr++;
- length = strlen(val);
- enclength = length;
- swapBytes(&enclength, 2);
- memcpy(tmpptr, &enclength, 2);
- tmpptr += 2;
- memcpy(tmpptr, val, length);
+// uint8_t *
+// AMF::encodeVariable(const char *name, const char *val)
+// {
+// // GNASH_REPORT_FUNCTION;
- return out;
-}
+// int outsize = strlen(name) + strlen(val) + 5;
+// Network::byte_t *out = new Network::byte_t[outsize];
+// Network::byte_t *tmpptr = out;
+
+// size_t length = strlen(name);
+// short enclength = length;
+// swapBytes(&enclength, 2);
+// memcpy(tmpptr, &enclength, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, name, length);
+// tmpptr += length;
+// *tmpptr = Element::STRING;
+// tmpptr++;
+// length = strlen(val);
+// enclength = length;
+// swapBytes(&enclength, 2);
+// memcpy(tmpptr, &enclength, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, val, length);
-Network::byte_t *
-AMF::encodeVariable(std::string &name, std::string &val)
-{
-// GNASH_REPORT_FUNCTION;
+// return out;
+// }
- int outsize = name.size() + val.size() + 5;
- Network::byte_t *out = new Network::byte_t[outsize];
- Network::byte_t *tmpptr = out;
- short length;
+// Network::byte_t *
+// AMF::encodeVariable(std::string &name, std::string &val)
+// {
+// // GNASH_REPORT_FUNCTION;
- length = name.size() && 0xffff;
- swapBytes(&length, 2);
- memcpy(tmpptr, &length, 2);
- tmpptr += 2;
- memcpy(tmpptr, name.c_str(), name.size());
- tmpptr += name.size();
- *tmpptr = Element::STRING;
- tmpptr++;
- length = val.size() && 0xffff;
- swapBytes(&length, 2);
- memcpy(tmpptr, &length, 2);
- tmpptr += 2;
- memcpy(tmpptr, val.c_str(), name.size());
+// int outsize = name.size() + val.size() + 5;
+// Network::byte_t *out = new Network::byte_t[outsize];
+// Network::byte_t *tmpptr = out;
+// short length;
+
+// length = name.size() && 0xffff;
+// swapBytes(&length, 2);
+// memcpy(tmpptr, &length, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, name.c_str(), name.size());
+// tmpptr += name.size();
+// *tmpptr = Element::STRING;
+// tmpptr++;
+// length = val.size() && 0xffff;
+// swapBytes(&length, 2);
+// memcpy(tmpptr, &length, 2);
+// tmpptr += 2;
+// memcpy(tmpptr, val.c_str(), name.size());
- return out;
-}
+// return out;
+// }
-Network::byte_t *
-AMF::addPacketData(Network::byte_t *data, int bytes)
-{
-// GNASH_REPORT_FUNCTION;
- memcpy(_seekptr, data, bytes);
- _seekptr+=bytes;
- return _seekptr;
-}
+// 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;
+// int
+// AMF::parseBody()
+// {
+// // GNASH_REPORT_FUNCTION;
-// return parseBody(_amf_data, _total_size);
-}
-#endif
+// // return parseBody(_amf_data, _total_size);
+// }
+// #endif
-Network::byte_t *
-AMF::extractElement(Element *el, Network::byte_t *in)
+Element *
+AMF::extractAMF(Network::byte_t *in)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
+ Element *el = new Element;
Network::byte_t *tmpptr;
-
-// uint8_t hexint[(bytes*2)+1];
- short length;
+ boost::uint16_t length;
if (in == 0) {
log_error(_("AMF body input data is NULL"));
@@ -1234,36 +1178,36 @@
// If it's a String type, then there is a count of characters, then the string
value
// Check the type of the element data
- char type = *(Element::astype_e *)tmpptr;
+ Element::amf_type_e type = *(Element::amf_type_e *)tmpptr;
tmpptr++; // skip the header byte
- switch ((Element::astype_e)type) {
+ switch (type) {
case Element::NUMBER:
el->makeNumber(tmpptr);
- tmpptr += 8;
+ tmpptr += AMF_NUMBER_SIZE; // all numbers are 8 bit big endian
break;
case Element::BOOLEAN:
el->makeBoolean(tmpptr);
- tmpptr += 2;
+ tmpptr += sizeof(boost::uint16_t); // although a bool is one byte,
it's stored as a short
break;
case Element::STRING:
// get the length of the name
- length = ntohs((*(short *)tmpptr) & 0xffff);
- tmpptr += 2;
-// log_debug(_("AMF String length is: %d"), length);
+ length = ntohs((*(boost::uint16_t *)tmpptr) & 0xffff);
+ tmpptr += sizeof(boost::uint16_t);
+ log_debug(_("AMF String length is: %d"), length);
if (length > 0) {
// get the name of the element
el->makeString(tmpptr, length);
-// log_debug(_("AMF String is: %s"), el->to_string());
+ log_debug(_("AMF String is: %s"), el->to_string());
tmpptr += length;
} else {
el->setType(Element::STRING);
- el->setData(0);
};
break;
case Element::OBJECT:
do {
- tmpptr = extractVariable(el, tmpptr);
+ el = extractVariable(tmpptr);
+ tmpptr += el->totalsize();
} while (el->getType() != Element::OBJECT_END);
break;
case Element::MOVIECLIP:
@@ -1284,101 +1228,65 @@
return 0;
}
- return tmpptr;
+ return el;
}
-Network::byte_t *
-AMF::extractVariable(Element *el, Network::byte_t *in)
+Element *
+AMF::extractVariable(Network::byte_t *in)
{
// GNASH_REPORT_FUNCTION;
+ Element *el;
+ boost::uint16_t length;
- char *buffer[AMF_PACKET_SIZE];
Network::byte_t *tmpptr = in;
- boost::int16_t length;
-
-// if (el == 0) {
-// return 0;
-// }
-
- el->clear();
-
- memset(buffer, 0, AMF_PACKET_SIZE);
- // @@ casting generic pointers to bigger types may be dangerous
- // due to memory alignment constraints
- length = *((short *)tmpptr);
- swapBytes(&length, 2);
-// length = ntohs((*(const short *)tmpptr) & 0xffff);
- el->setLength(length);
- if (length == 0) {
- if (*(tmpptr+2) == Element::OBJECT_END) {
-// log_debug(_("End of Object definition"));
- el->setLength(0);
+ length = *(reinterpret_cast<boost::uint16_t *>(in));
+ tmpptr += sizeof(boost::uint16_t);
+ swapBytes(&length, sizeof(boost::uint16_t));
+
+ if (length <= 0) {
+ if (*(in+2) == Element::OBJECT_END) {
+ log_debug(_("End of Object definition"));
el->setType(Element::OBJECT_END);
- tmpptr+=3;
- return tmpptr;
+ return el;
}
return 0;
}
-
- tmpptr += 2;
- // get the name of the element
+ // get the name of the element, the length of which we just decoded
if (length > 0) {
- if (length > 20000) {
- log_error("Length field corrupted! parsed value is: %hd", length);
- return 0;
- }
-
-// log_debug(_("AMF element length is: %d"), length);
- memcpy(buffer, tmpptr, length);
+ 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());
}
-// log_debug(_("AMF element name is: %s"), buffer);
- Element::astype_e type = (Element::astype_e)((*tmpptr++) & 0xff);
-
+ // get the type of the element, which is a single byte
+ Element::amf_type_e type = (Element::amf_type_e)(*(tmpptr) & 0xff);
+ tmpptr++;
if (type <= Element::TYPED_OBJECT) {
-// log_debug(_("AMF type is: %s"), Element::astype_str[(int)type]);
+ log_debug(_("AMF type is: %s"), amftype_str[(int)type]);
el->setType(type);
}
switch (type) {
- case Element::NUMBER:
- {
- memcpy(buffer, tmpptr, AMF_NUMBER_SIZE);
- swapBytes(buffer, AMF_NUMBER_SIZE);
- uint8_t* tmp = new uint8_t[AMF_NUMBER_SIZE+1];
- memset(tmp, 0, AMF_NUMBER_SIZE+1);
- memcpy(tmp, buffer, AMF_NUMBER_SIZE);
- el->setData(tmp);
-#if 0
- uint8_t hexint[AMF_NUMBER_SIZE*3];
- hexify((uint8_t *)hexint, (uint8_t *)buffer,
- AMF_NUMBER_SIZE, false);
- log_debug(_("Number \"%s\" is: 0x%s"), el->getName().c_str(),
hexint);
-// double *num = extractNumber(tmpptr);
-#endif
- tmpptr += 8;
- el->setLength(AMF_NUMBER_SIZE);
+ case Element::NUMBER: {
+ swapBytes(tmpptr, AMF_NUMBER_SIZE);
+ el->makeNumber(tmpptr);
+ tmpptr += AMF_NUMBER_SIZE;
break;
}
case Element::BOOLEAN:
{
- bool sheet = *tmpptr;
- el->init(sheet);
+ bool sheet = *(reinterpret_cast<bool *>(tmpptr));
+ el->makeBoolean(sheet);
tmpptr += 1;
break;
}
case Element::STRING:
// extractString returns a printable char *
- length = ntohs((*(const short *)tmpptr) & 0xffff);
- tmpptr += sizeof(short);
- el->setLength(length);
- Network::byte_t *str;
- str = new Network::byte_t[length + 1];
- memset(str, 0, length + 1);
- memcpy(str, tmpptr, length);
- el->setData(str);
+ length = ntohs((*(const boost::uint16_t *)tmpptr) & 0xffff);
+ tmpptr += sizeof(boost::uint16_t);
+ 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;
@@ -1415,11 +1323,11 @@
case Element::RECORD_SET:
case Element::XML_OBJECT:
default:
- log_unimpl(_("astype_e of value: %x"), (int)type);
+ log_unimpl(_("amf_type_e of value: %x"), (int)type);
break;
}
- return tmpptr; // we're dropping const specification
+ return el;
}
} // end of amf namespace
Index: libamf/amf.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/amf.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- libamf/amf.h 30 Mar 2008 22:08:53 -0000 1.35
+++ libamf/amf.h 1 Apr 2008 22:20:40 -0000 1.36
@@ -15,6 +15,14 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+// This file is for the low level support for encoding and decoding AMF
objects.
+// As this class has no data associated with it, all the methods are static as
+// they are for convenience only.
+// All the encoding methods return a Buffer class, which is simply an array on
+// of unsigned bytes, and a byte count.
+// The only extraction classes parse either a raw AMF object or the larger
+// "variable"
+
#ifndef _AMF_H_
#define _AMF_H_
@@ -30,56 +38,39 @@
#include "network.h"
#include "element.h"
-#include "amfutf8.h"
#include "dsodefs.h"
namespace amf
{
-const char AMF_NUMBER_SIZE = 0x08;
+// forward declaration
+class Buffer;
+
+// All numbers in AMF format are 8 byte doubles.
+const size_t AMF_NUMBER_SIZE = 0x08;
+
+// The header of an AMF object is a type filed (1 byte), followed by a
+// length field. (short)
+const char AMF_HEADER_SIZE = 3;
+
+// A variable is a little different. It always assumes the the first field is
+// a string that's the variable name, then the type byte like a regular AMF
+// object and length is used for the data. So a variable object header is
+// then only 5 bytes instead of the 6 that one assumes would be used.
+const char AMF_VAR_HEADER_SIZE = 5;
+
+// FIXME: this should go away
+const int AMF_PACKET_SIZE = 128;
+// Use a zero version till now till we know what this should be.
const char AMF_VERSION = 0;
-const int AMF_HEADSIZE_MASK = 0xc0;
-const char AMF_HEADER_SIZE = 0x03;
-const char AMF_INDEX_MASK = 0x3f;
-const int AMF_VIDEO_PACKET_SIZE = 128;
-const int AMF_AUDIO_PACKET_SIZE = 64;
-// This is the sized used when reading from the network to
-// be the most efficient
-const int AMF_PACKET_SIZE = 7096;
// For terminating sequences, a byte with value 0x09 is used.
const char TERMINATOR = 0x09;
-// Each packet consists of the following:
-//
-// The first byte of the AMF file/stream is believed to be a version
-// indicator. So far the only valid value for this field that has been
-// found is 0x00. If it is anything other than 0x00 (zero), your
-// system should consider the AMF file/stream to be
-// 'malformed'd. This can happen in the IDE if AMF calls are put
-// on the stack but never executed and the user exits the movie from the
-// IDE; the two top bytes will be random and the number of headers will
-// be unreliable.
-
-// The second byte of the AMF file/stream is appears to be 0x00 if the
-// client is the Flash Player and 0x01 if the client is the FlashCom
-// server.
-
-// The third and fourth bytes form an integer value that specifies the
-// number of headers.
-typedef struct {
- gnash::Network::byte_t version;
- gnash::Network::byte_t source;
- boost::uint32_t count;
-} amfpacket_t;
-
-typedef enum {
- onStatus,
- onResult,
- onDebugEvents
-} amfresponse_e;
-
+// An AMF object is the binary representation of an ActionScript object. AMF
+// is used to send objects, wheather to a SharedObject .sol file, a memory
based
+// LocalConnection segment, or over an RTMP connection for streaming.
class DSOEXPORT AMF {
public:
// typedef enum {
@@ -122,103 +113,106 @@
//
// Methods for encoding data into big endian formatted raw AMF data.
- //
+ // Note that while we could have had a single overloaded encode method,
+ // this is more explicit, which when it comes to manipulating binary
+ // protocols make the code much more readable.
/// Encode a string object
///
+
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeElement(const char *str);
+ static Buffer *encodeString(const std::string &str);
/// Encode a Boolean object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeBoolean(bool flag);
+ static Buffer *encodeBoolean(bool flag);
/// Encode an "Undefined" object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeUndefined();
+ static Buffer *encodeUndefined();
/// Encode a "NULL" object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeNull();
+ static Buffer *encodeNull();
/// Encode a "Unsupported" object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeUnsupported();
+ static Buffer *encodeUnsupported();
/// Encode an XML object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeXMLObject(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeXMLObject(gnash::Network::byte_t *data, int size);
/// Encode a Typed Object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeTypedObject(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeTypedObject(gnash::Network::byte_t *data, int size);
/// Encode a Reference to an object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeReference(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeReference(gnash::Network::byte_t *data, int size);
/// Encode a Movie Clip
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeMovieClip(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeMovieClip(gnash::Network::byte_t *data, int size);
/// Encode an ECMA Array
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeECMAArray(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeECMAArray(gnash::Network::byte_t *data, int size);
/// Encode a long string
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeLongString(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeLongString(gnash::Network::byte_t *data, int size);
/// Encode a Record Set
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeRecordSet(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeRecordSet(gnash::Network::byte_t *data, int size);
/// Encode a Date
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeDate(gnash::Network::byte_t *data);
+ static Buffer *encodeDate(gnash::Network::byte_t *data);
/// Encode a Strict Array
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeStrictArray(gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeStrictArray(gnash::Network::byte_t *data, int size);
/// Encode an object
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeObject(const gnash::Network::byte_t
*data, int size);
+ static Buffer *encodeObject(gnash::Network::byte_t *data, int size);
/// Encode a 64 bit number
///
/// @return a binary AMF packet in big endian format (header,data)
///
- static gnash::Network::byte_t *encodeNumber(double num);
+ static Buffer *encodeNumber(double num);
/// Encode a element.
///
@@ -227,8 +221,9 @@
/// @return a newly allocated byte array.
/// to be deleted by caller using delete [] operator, or NULL
///
- static gnash::Network::byte_t *encodeElement(amf::Element *el);
+ static Buffer *encodeElement(amf::Element *el);
+#if 0
/// Encode an array of elements.
///
/// @return a binary AMF packet in big endian format (header,data)
@@ -237,6 +232,7 @@
/// to be deleted by caller using delete [] operator, or NULL
///
static std::vector<gnash::Network::byte_t>
*encodeElement(std::vector<amf::Element *> &els);
+#endif
/// Encode a variable.
//
@@ -248,122 +244,23 @@
/// in form of a newly allocated byte array.
/// to be deleted by caller using delete [] operator, or NULL
///
- gnash::Network::byte_t *encodeVariable(amf::Element *el);
-
-#if 0
- /// Encode an element
- //
- /// @param type
- /// Type of element
- ///
- /// @param in
- /// Input stream
- ///
- /// @param nbytes
- /// Lenght of data packet (not including header).
- ///
- /// @return an amf packet (header,data)
- ///
- static gnash::Network::byte_t* encodeElement(Element::astype_e type, const
void *in, int nbytes);
-
- /// @return a newly allocated byte array,
- /// to be deleted by caller using delete [] operator, or NULL
- ///
- static gnash::Network::byte_t* encodeVariable(const char *name);
-
- /// Encode a boolean variable. This is a name followed by a boolean value.
- //
- /// @return a newly allocated byte array,
- /// to be deleted by caller using delete [] operator, or NULL
- ///
- static gnash::Network::byte_t* encodeVariable(const char *name, bool flag);
-
- /// Encode a variable.
- //
- /// @return a newly allocated byte array,
- /// to be deleted by caller using delete [] operator, or NULL
- ///
- static gnash::Network::byte_t* encodeVariable(const char *name, double
num);
-
- /// Encode a variable.
- //
- /// @return a newly allocated byte array,
- /// to be deleted by caller using delete [] operator, or NULL
- ///
- static gnash::Network::byte_t* encodeVariable(std::string &name,
std::string &val);
-
- /// Encode a variable.
- //
- /// @return a newly allocated byte array,
- /// to be deleted by caller using delete [] operator, or NULL
- ///
- static gnash::Network::byte_t* encodeVariable(const char *name, const char
*val);
-
- void *encodeRTMPHeader(int amf_index, amf_headersize_e head_size, int
total_size,
- content_types_e type, amfsource_e routing);
-// amfhead_t *encodeHeader(amfutf8_t *name, bool required, int nbytes, void
*data);
-// amfbody_t *encodeBody(amfutf8_t *target, amfutf8_t *response, int
nbytes, void *data);
-// amfpacket_t *encodePacket(std::vector<amfhead_t *> messages);
-
-// std::vector<amf_element_t> *readElements(gnash::Network::byte_t *in);
-
- /// Extract the string from a string-type AMF packet
- //
- /// Return a newly allocated char[],
- /// or NULL if the given AMF packet is not a string type
- ///
- /// Caller is responsible for deletion using delete [] operator.
- ///
-#endif
+ static Buffer *encodeVariable(amf::Element *el);
//
// Methods for extracting data from big endian formatted raw AMF data.
//
- amf::Element::astype_e extractElementHeader(gnash::Network::byte_t *in)
- { return *(reinterpret_cast<amf::Element::astype_e *>(in)); };
-
- gnash::Network::byte_t *extractElement(amf::Element *el,
gnash::Network::byte_t *in);
- gnash::Network::byte_t *extractVariable(amf::Element *el,
gnash::Network::byte_t *in);
-
-#if 0
- // FIXME: these should return an Element, and then use to_*() to convert.
- char *extractString(const gnash::Network::byte_t* in);
-
- double extractNumber(const gnash::Network::byte_t *in);
- Element &extractObject(const gnash::Network::byte_t *in);
-
- // FIXME: these are all for RTMP, and should be moved
- bool parseAMF(gnash::Network::byte_t *in);
- int packetReadAMF(int bytes);
-
- int parseBody();
- gnash::Network::byte_t *addPacketData(gnash::Network::byte_t *data, int
bytes);
-#endif
-
-// content_types_e getType() { return _type; };
-// std::map<std::string, Element> *getElements() { return &_elements; };
- gnash::Network::byte_t *appendPtr(gnash::Network::byte_t *data,
gnash::Network::byte_t *var,
- int bytes) {
- memcpy(data, var, bytes);
- return data += bytes;
- }
-
- private:
-#if 0
- Element::astype_e extractElementHeader(void *in);
- int extractElementLength(void *in);
-// std::map<std::string, Element &> _elements;
- int _amf_index;
- int _header_size;
- int _total_size;
- int _packet_size;
- gnash::Network::byte_t *_amf_data;
- gnash::Network::byte_t *_seekptr;
- amfsource_e _src_dest;
-#endif
-// content_types_e _type;
- int _mystery_word;
+ // Extract the object type from the first byte of the header.
+ static amf::Element::amf_type_e
extractElementHeader(gnash::Network::byte_t *in)
+ { return *(reinterpret_cast<amf::Element::amf_type_e
*>(in)); };
+
+ // Extract an AMF object. These have no name like the variables do.
+ 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);
+private:
+// no data, all the methods are static
};
DSOEXPORT void *swapBytes(void *word, int size);
Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libamf/element.cpp 30 Mar 2008 22:08:53 -0000 1.12
+++ libamf/element.cpp 1 Apr 2008 22:20:41 -0000 1.13
@@ -26,6 +26,7 @@
#include <cmath>
#include <climits>
+#include "buffer.h"
#include "log.h"
#include "amf.h"
#include "amfutf8.h"
@@ -63,8 +64,10 @@
Element::Element()
: _type(Element::NOTYPE),
- _length(0),
- _data(0)
+ _buffer(0),
+ _name(0)
+// _length(0),
+// _data(0)
{
// GNASH_REPORT_FUNCTION;
}
@@ -73,21 +76,29 @@
Element::~Element()
{
// GNASH_REPORT_FUNCTION;
- if (_data) {
- delete [] _data;
- }
+// if (_buffer) {
+// if (_buffer->size() > 0) {
+// delete _buffer;
+// }
+// }
for (size_t i=0; i< _children.size(); i++) {
delete _children[i];
}
}
Element::Element(Network::byte_t *indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(indata);
}
Element::Element(double indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(indata);
@@ -100,24 +111,36 @@
// }
Element::Element(const string &indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(indata);
}
Element::Element(const string &name, const string &indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(name, indata);
}
Element::Element(const string &name, bool indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(name, indata);
}
Element::Element(bool indata)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
GNASH_REPORT_FUNCTION;
init(indata);
@@ -126,11 +149,30 @@
// Create a function block for AMF
Element::Element(bool flag, double unknown1, double unknown2,
const string &methodname)
+ : _type(Element::NOTYPE),
+ _buffer(0),
+ _name(0)
{
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)
@@ -138,7 +180,7 @@
GNASH_REPORT_FUNCTION;
_type = Element::FUNCTION;
if (methodname.size()) {
- _name = methodname;
+ setName(methodname);
}
// Build up the children for the function block
@@ -154,9 +196,9 @@
el = new Element(methodname);
_children.push_back(el);
- _length = 3
+ _buffer = new Buffer(3
+ ((AMF_HEADER_SIZE + AMF_NUMBER_SIZE) * 2)
- + methodname.size() + AMF_HEADER_SIZE;
+ + methodname.size() + AMF_HEADER_SIZE);
// memcpy(_data, &indata, _length);
return *this;
}
@@ -169,16 +211,18 @@
}
Element &
-Element::init(const string &name, double indata)
+Element::init(const string &name, double num)
{
// GNASH_REPORT_FUNCTION;
_type = Element::NUMBER;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = AMF_NUMBER_SIZE;
- _data = reinterpret_cast<Network::byte_t *>(new char[sizeof(double)]);
- memcpy(_data, &indata, _length);
+ _buffer = new Buffer(AMF_NUMBER_SIZE);
+// _data = reinterpret_cast<Network::byte_t *>(new char[sizeof(double)]);
+// Network::byte_t *ptr = reinterpret_cast<Network::byte_t *>(&indata);
+
+ _buffer->append(num);
return *this;
}
@@ -190,18 +234,16 @@
}
Element &
-Element::init(const string &name, const string &indata)
+Element::init(const string &name, const string &str)
{
GNASH_REPORT_FUNCTION;
_type = Element::STRING;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = indata.size();
- // add a byte for a NULL string terminator byte.
- _data = new Network::byte_t[indata.size() + 1];
- memset(_data, 0, indata.size() + 1);
- memcpy(_data, indata.c_str(), indata.size());
+ _buffer = new Buffer(str.size());
+ _buffer->append(str);
+
return *this;
}
@@ -213,16 +255,16 @@
}
Element &
-Element::init(const string &name, bool indata)
+Element::init(const string &name, bool flag)
{
// GNASH_REPORT_FUNCTION;
_type = Element::BOOLEAN;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = 1;
- _data = new Network::byte_t[1];
- *_data = indata;
+ _buffer = new Buffer(sizeof(bool));
+ _buffer->append(flag);
+
return *this;
}
@@ -230,23 +272,39 @@
Element::clear()
{
// GNASH_REPORT_FUNCTION;
- if (_data) {
- delete[] _data;
- _data = 0;
+ if (_name) {
+ delete [] _name;
}
- if (_name.size()) {
- _name.clear();
+ if (_buffer) {
+ delete _buffer;
}
- _length = 0;
- _type = Element::NOTYPE;
-
}
+Network::byte_t *
+Element::getData()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_buffer) {
+ return _buffer->reference();
+ }
+ return 0;
+};
+
+boost::uint16_t
+Element::getLength()
+{
+// GNASH_REPORT_FUNCTION;
+ if (_buffer) {
+ return _buffer->size();
+ }
+ return 0;
+};
+
double
Element::to_number()
{
- if (_data) {
- return *(reinterpret_cast<double *>(_data));
+ if (_buffer) {
+ return *(reinterpret_cast<double *>(_buffer->reference()));
}
// return ::nan("NaN");
return -1.0;
@@ -255,14 +313,20 @@
const char *
Element::to_string()
{
- return reinterpret_cast<const char *>(_data);
+ if (_buffer) {
+ if (_buffer->size() > 0) {
+ return reinterpret_cast<const char *>(_buffer->reference());
+ }
+ return "NULL";
+ }
+ return 0;
};
bool
Element::to_bool()
{
- if (_data) {
- return *(reinterpret_cast<bool *>(_data));
+ if (_buffer) {
+ return *(reinterpret_cast<bool *>(_buffer->reference()));
}
return false;
};
@@ -270,24 +334,44 @@
void *
Element::to_reference()
{
- return reinterpret_cast<void *>(_data);
+ if (_buffer) {
+ return reinterpret_cast<void *>(_buffer->reference());
+ }
+ return 0;
};
+bool
+Element::operator==(bool x)
+{
+ if (_buffer) {
+ _buffer->append(x);
+ }
+ return false;
+};
+Network::byte_t
+Element::operator[](int x)
+{
+ if (_buffer) {
+ return *_buffer->at(x);
+ }
+ return 0;
+};
+
+
Element &
Element::operator=(Element &el)
{
// GNASH_REPORT_FUNCTION;
_type = el.getType();
- _length = el.getLength();
- if (el.getName().size()) {
+ if (el.getNameSize()) {
_name = el.getName();
}
- _data = new Network::byte_t[_length + 1];
- memcpy(_data, el.getData(), _length);
-
+ _buffer = new Buffer(el.getLength());
+ _buffer = el.getBuffer();
return *this;
}
-/// \brief Extract an AMF element from the byte stream
+
+/// \brief Fill an element with data
///
/// All Numbers are 64 bit, big-endian (network byte order) entities.
///
@@ -295,313 +379,279 @@
/// normal ASCII. It may be that these need to be converted to wide
/// characters, but for now we just leave them as standard multibyte
/// characters.
-Network::byte_t *
-Element::init(Network::byte_t *indata)
+Element &
+Element::makeString(Network::byte_t *data, size_t size)
{
// GNASH_REPORT_FUNCTION;
-
- Network::byte_t *ptr = indata;
- // Extract the type
- _type = (Element::astype_e)((*ptr++) & 0xff);
- // For doubles, the length value is never set, but we might as
- // well put in a legit value anyway.
- _length = AMF_NUMBER_SIZE;
- _data = new Network::byte_t[AMF_NUMBER_SIZE + 1];
- memset(_data, 0, AMF_NUMBER_SIZE + 1);
- memcpy(_data, &indata, AMF_NUMBER_SIZE);
-
- return indata + AMF_NUMBER_SIZE;
+ _type = Element::STRING;
+ // Make room for an additional NULL terminator
+ _buffer = new Buffer(size+1);
+ _buffer->copy(data, size);
+ // Unlike other buffers, people like to print strings, so we must add
+ // 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;
+ return *this;
}
Element &
-Element::makeString(Network::byte_t *data, int size)
+Element::makeString(const char *str, size_t size)
{
// GNASH_REPORT_FUNCTION;
-
_type = Element::STRING;
- _length = size;
- _data = new Network::byte_t[size+1];
- memset(_data, 0, size+1);
- memcpy(_data, data, size);
- return *this;
+ Network::byte_t *ptr = reinterpret_cast<Network::byte_t *>(const_cast<char
*>(str));
+ return makeString(ptr, size);
}
Element &
-Element::makeString(const string &name, const string &indata)
+Element::makeString(const string &str)
{
- GNASH_REPORT_FUNCTION;
- _type = Element::STRING;
+// GNASH_REPORT_FUNCTION;
+ return makeString(str.c_str(), str.size());
+}
+
+Element &
+Element::makeString(const string &name, const string &str)
+{
+// GNASH_REPORT_FUNCTION;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = indata.size();
- // add a byte for a NULL string terminator byte.
- _data = new Network::byte_t[indata.size() + 1];
- memcpy(_data, indata.c_str(),_length);
- *(_data + _length) = 0; // terminate the string for printing
- return *this;
+ return makeString(str.c_str(), str.size());
}
Element &
Element::makeNumber(Network::byte_t *data)
{
// GNASH_REPORT_FUNCTION;
-
+ double num = *reinterpret_cast<const double*>(data);
_type = Element::NUMBER;
- _length = amf::AMF_NUMBER_SIZE;
- _data = new Network::byte_t[amf::AMF_NUMBER_SIZE];
- memcpy(_data, data, amf::AMF_NUMBER_SIZE);
+ _buffer = new Buffer(AMF_NUMBER_SIZE);
+ _buffer->append(num);
+
return *this;
}
Element &
-Element::makeNumber(const string &name, double data)
+Element::makeNumber(const string &name, double innum)
{
// GNASH_REPORT_FUNCTION;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _type = Element::NUMBER;
- _length = amf::AMF_NUMBER_SIZE;
- _data = new Network::byte_t[amf::AMF_NUMBER_SIZE];
- memcpy(_data, &data, amf::AMF_NUMBER_SIZE);
-// std::copy(&data, &data + amf::AMF_NUMBER_SIZE, _data);
- return *this;
+ Network::byte_t *num = reinterpret_cast<Network::byte_t *>(&innum);
+ return makeNumber(num);
}
Element &
-Element::makeBoolean(bool data)
+Element::makeBoolean(bool flag)
{
// GNASH_REPORT_FUNCTION;
-
_type = Element::BOOLEAN;
- _length = 1;
- _data = new Network::byte_t[2];
- memset(_data, 0, 2);
- _data[1]= data;
+ _buffer = new Buffer(sizeof(bool));
+ _buffer->append(flag);
return *this;
}
Element &
-Element::makeBoolean(const string &name, bool data)
+Element::makeBoolean(const string &name, bool flag)
{
// GNASH_REPORT_FUNCTION;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _type = Element::BOOLEAN;
- _length = 1;
- _data = new Network::byte_t[2];
- memset(_data, 0, 2);
- _data[1]= data;
- return *this;
+ return makeBoolean(flag);
}
Element &
Element::makeBoolean(Network::byte_t *data)
{
// GNASH_REPORT_FUNCTION;
+ bool flag = *reinterpret_cast<const bool*>(data);
- _type = Element::BOOLEAN;
- _length = 1;
- _data = new Network::byte_t[2];
- memset(_data, 0, 2);
- memcpy(_data, data+1, 1);
- return *this;
+ return makeBoolean(flag);
}
Element &
Element::makeUndefined()
{
- return makeUndefined("");
+ _type = Element::UNDEFINED;
+ return *this;
}
Element &
Element::makeUndefined(const std::string &name)
{
// GNASH_REPORT_FUNCTION;
-
- _type = Element::UNDEFINED;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = 0;
- _data = 0;
- return *this;
+ return makeUndefined();
}
Element &
Element::makeNull()
{
// GNASH_REPORT_FUNCTION;
- return makeNull("");
+ _type = Element::NULL_VALUE;
+ Network::byte_t val = 0;
+ _buffer = new Buffer(sizeof(Network::byte_t));
+ _buffer->append(val);
+ return *this;
}
Element &
Element::makeNull(const std::string &name)
{
// GNASH_REPORT_FUNCTION;
-
- _type = Element::NULL_VALUE;
if (name.size()) {
- _name = name;
+ setName(name);
}
- _length = 0;
- _data = 0;
- return *this;
+ return makeNull();
}
Element &
-Element::makeObject(Network::byte_t *indata, int size)
+Element::makeObject(const std::string &name)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
+ setName(name);
+ _type = OBJECT;
+ return *this;
+}
+Element &
+Element::makeObject(Network::byte_t *indata, size_t size)
+{
+ GNASH_REPORT_FUNCTION;
_type = Element::OBJECT;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
Element::makeObjectEnd()
{
-// GNASH_REPORT_FUNCTION;
-
+ GNASH_REPORT_FUNCTION;
_type = Element::OBJECT_END;
- _length = 0;
- _data = 0;
return *this;
}
Element &
-Element::makeXMLObject(Network::byte_t *indata, int size)
+Element::makeXMLObject(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
-
+ GNASH_REPORT_FUNCTION;
_type = Element::XML_OBJECT;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeTypedObject(Network::byte_t *indata, int size)
+Element::makeTypedObject(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
-
+ GNASH_REPORT_FUNCTION;
_type = Element::TYPED_OBJECT;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeReference(Network::byte_t *indata, int size)
+Element::makeReference(Network::byte_t *indata, size_t size)
{
// GNASH_REPORT_FUNCTION;
- _type = Element::TYPED_OBJECT;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _type = Element::REFERENCE;
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeMovieClip(Network::byte_t *indata, int size)
+Element::makeMovieClip(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
_type = Element::MOVIECLIP;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeECMAArray(Network::byte_t *indata, int size)
+Element::makeECMAArray(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
_type = Element::ECMA_ARRAY;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeLongString(Network::byte_t *indata, int size)
+Element::makeLongString(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
-
+ GNASH_REPORT_FUNCTION;
_type = Element::LONG_STRING;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
-
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeRecordSet(Network::byte_t *indata, int size)
+Element::makeRecordSet(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
_type = Element::RECORD_SET;
-
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
-
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
Element &
-Element::makeDate(Network::byte_t *indata)
+Element::makeDate(Network::byte_t *date)
{
-// GNASH_REPORT_FUNCTION;
-
+ GNASH_REPORT_FUNCTION;
_type = Element::DATE;
- _length = AMF_NUMBER_SIZE;
- _data = new Network::byte_t[AMF_NUMBER_SIZE + 1];
- memset(_data, 0, AMF_NUMBER_SIZE + 1);
- memcpy(_data, indata, AMF_NUMBER_SIZE);
-
- return *this;
+ return makeNumber(date);
}
Element &
-Element::makeStrictArray(Network::byte_t *indata, int size)
+Element::makeStrictArray(Network::byte_t *indata, size_t size)
{
-// GNASH_REPORT_FUNCTION;
+ GNASH_REPORT_FUNCTION;
_type = Element::STRICT_ARRAY;
- _length = size;
- _data = new Network::byte_t[size + 1];
- memset(_data, 0, size + 1);
- memcpy(_data, indata, size);
-
+ _buffer = new Buffer(size);
+ _buffer->copy(indata, size);
return *this;
}
+size_t
+Element::getNameSize()
+{
+ if (_name) {
+ return strlen(_name);
+ }
+ return 0;
+}
+
void
-Element::setName(Network::byte_t *name, int x)
+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;
+}
- char *buf = new char[x+1];
- *(buf+x) = 0; // terminate the string, we don't need
to memcpy the whole thing
- std::copy(name, name+x, buf);
- _name = buf;
+void
+Element::setName(Network::byte_t *name, size_t x)
+{
+ GNASH_REPORT_FUNCTION;
+ char *_name = new char[x+1];
+ std::copy(name, name+x, _name);
+ *(_name + x) = 0;
}
void
@@ -609,8 +659,8 @@
{
// GNASH_REPORT_FUNCTION;
- if (_name.size()) {
- cerr << "AMF object name: " << _name << ", length is " << _length <<
endl;
+ if (_name) {
+ cerr << "AMF object name: " << _name << ", length is " << getLength()
<< endl;
}
cerr << astype_str[_type] << ": ";
@@ -625,8 +675,8 @@
cerr << (to_bool() ? "true" : "false") << endl;
break;
case Element::STRING:
- cerr << "(" << _length << " bytes): ";
- if (_length > 0) {
+ cerr << "(" << getLength() << " bytes): ";
+ if (getLength() > 0) {
cerr << "\t\"" << to_string() << "\"" << endl;
} else {
cerr << endl;
Index: libamf/element.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- libamf/element.h 30 Mar 2008 22:08:53 -0000 1.11
+++ libamf/element.h 1 Apr 2008 22:20:41 -0000 1.12
@@ -18,26 +18,21 @@
#ifndef _ELEMENT_H_
#define _ELEMENT_H_
-#ifdef HAVE_CONFIG_H
-#include "gnashconfig.h"
-#endif
-
#include <vector>
#include <string>
#include <cstring>
-
#include <boost/cstdint.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
+//#include "buffer.h"
#include "network.h"
-#include "amfutf8.h"
-#include "amf.h"
#include "dsodefs.h" // DSOEXPORT
namespace amf
{
-class DSOEXPORT Element {
+class Buffer;
+
+class Element {
public:
// The following elements are defined within AMF:
typedef enum {
@@ -62,7 +57,7 @@
// these aren't part of the AMF spec, they're used internally
VARIABLE=0x11,
FUNCTION=0x12
- } astype_e;
+ } amf_type_e;
Element();
Element(gnash::Network::byte_t *data);
Element(double data);
@@ -75,7 +70,6 @@
Element(bool, double, double, const std::string &str);
~Element();
void clear();
- gnash::Network::byte_t *init(gnash::Network::byte_t *data);
Element &init(const std::string &name, double data);
Element &init(double data);
Element &init(std::vector<double> &data);
@@ -87,7 +81,8 @@
Element &init(bool, double, double, const std::string &str);
// These create the other "special" AMF types.
- Element &makeString(gnash::Network::byte_t *data, int size);
+ 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);
@@ -102,29 +97,37 @@
Element &makeUndefined(const std::string &name);
Element &makeNull();
Element &makeNull(const std::string &name);
+
Element &makeObjectEnd();
- Element &makeObject(gnash::Network::byte_t *data, int size);
- Element &makeXMLObject(gnash::Network::byte_t *data, int size);
- Element &makeTypedObject(gnash::Network::byte_t *data, int size);
- Element &makeReference(gnash::Network::byte_t *data, int size);
- Element &makeMovieClip(gnash::Network::byte_t *data, int size);
- Element &makeECMAArray(gnash::Network::byte_t *data, int size);
- Element &makeLongString(gnash::Network::byte_t *data, int size);
- Element &makeRecordSet(gnash::Network::byte_t *data, int size);
+ Element &makeObject(const std::string &name);
+ Element &makeObject(gnash::Network::byte_t *data, size_t size);
+
+ Element &makeXMLObject(gnash::Network::byte_t *data, size_t size);
+ Element &makeTypedObject(gnash::Network::byte_t *data, size_t size);
+ Element &makeReference(gnash::Network::byte_t *data, size_t size);
+ Element &makeMovieClip(gnash::Network::byte_t *data, size_t size);
+ Element &makeECMAArray(gnash::Network::byte_t *data, size_t size);
+ Element &makeLongString(gnash::Network::byte_t *data, size_t size);
+ Element &makeRecordSet(gnash::Network::byte_t *data, size_t size);
Element &makeDate(gnash::Network::byte_t *data);
- Element &makeStrictArray(gnash::Network::byte_t *data, int size);
+ Element &makeStrictArray(gnash::Network::byte_t *data, size_t size);
// Element &makeArray();
Element &operator=(Element &);
+ bool operator==(bool x);
+ gnash::Network::byte_t operator[](int x);
- bool operator==(bool x) { if (_data) return _data[0] == x; return false; };
- uint8_t operator[](int x) { if (_data) return _data[x]; return 0; };
+ // 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; };
// These are all accessors for the various output formats
- astype_e getType() { return _type; };
- void setType(astype_e x) { _type = x; };
- gnash::Network::byte_t *getData() { return _data; };
- void setData(gnash::Network::byte_t *x) { _data = x; };
+ amf_type_e getType() { return _type; };
+ void setType(amf_type_e x) { _type = x; };
+// void setData(Buffer *buf) { _buffer = buf; };
// These accessors convert the raw data to a standard data type we can use.
double to_number();
@@ -132,19 +135,19 @@
bool to_bool();
void *to_reference();
- boost::uint16_t getLength() { return _length; };
- void setLength(boost::uint16_t x) { _length = x; };
- const std::string &getName() const { return _name; };
- void setName(const std::string &name) { _name = name; };
- void setName(gnash::Network::byte_t *name, int x);
-// boost::posix_time::ptime to_date();
+ char *getName() const { return _name; };
+ size_t getNameSize();
+ void setName(const std::string &name);
+ void setName(gnash::Network::byte_t *name, size_t x);
+
+ void addChild(Element *el) { _children.push_back(el); };
+ Element *popChild() { return _children.front(); };
void dump();
private:
- astype_e _type;
- boost::int16_t _length;
- std::string _name;
- gnash::Network::byte_t *_data;
+ amf_type_e _type;
+ Buffer *_buffer;
+ char *_name;
std::vector<Element *> _children;
}; // end of class definition
Index: libamf/lcshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/lcshm.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- libamf/lcshm.cpp 30 Mar 2008 22:08:53 -0000 1.10
+++ libamf/lcshm.cpp 1 Apr 2008 22:20:41 -0000 1.11
@@ -28,6 +28,7 @@
#include <boost/cstdint.hpp>
#include "log.h"
+#include "buffer.h"
#include "network.h"
#include "amf.h"
#include "shm.h"
@@ -255,16 +256,17 @@
AMF amf;
while (ptr) {
- amf::Element *el = new Element;
- ptr = amf.extractElement(el, ptr);
+ amf::Element *el = amf.extractAMF(ptr);
if (el->getType() == Element::NUMBER) {
if (el->to_number() == 0.0) {
- ptr = 0;
- continue;
+ break;
}
}
if (el->getType() != Element::NOTYPE) {
- addObject(el);
+ _amfobjs.push_back(el);
+ ptr += el->getLength();
+ } else {
+ break;
}
};
@@ -302,19 +304,17 @@
ptr += LC_HEADER_SIZE;
- Element *el = new amf::Element;
AMF amf;
- ptr = amf.extractElement(el, ptr);
- if (ptr == 0) {
- log_error("Didn't extract element from byte stream!");
+ Element *el = AMF::extractAMF(ptr);
+ if (el == 0) {
+ log_debug("Didn't extract an element from the byte stream!");
return 0;
}
_object.connection_name = el->to_string();
delete el;
- el = new amf::Element;
- ptr = amf.extractElement(el, ptr);
+ el = AMF::extractAMF(ptr);
if (ptr != 0) {
_object.hostname = el->to_string();
}
@@ -353,6 +353,8 @@
// Network::byte_t *ptr = data + LC_HEADER_SIZE;
int size = con.size() + host.size() + 9;
+ Buffer *buf;
+
Network::byte_t *header = new Network::byte_t[size + 1];
Network::byte_t *ptr = header;
@@ -364,16 +366,13 @@
ptr = header + LC_HEADER_SIZE;
// Which is then always followed by 3 AMF objects.
- Network::byte_t *tmp = AMF::encodeElement(con.c_str());
- memcpy(ptr, tmp, con.size());
- ptr += con.size();
- delete[] tmp;
-
- tmp = AMF::encodeElement(host.c_str());
- memcpy(ptr, tmp, host.size());
- ptr += host.size();
-
- delete[] tmp;
+ Buffer *buf1 = AMF::encodeString(con);
+ memcpy(ptr, buf1->begin(), buf1->size());
+ ptr += buf->size();
+
+ Buffer *buf2 = AMF::encodeString(host);
+ memcpy(ptr, buf2->begin(), buf2->size());
+ ptr += buf->size();
return ptr;
}
@@ -458,6 +457,7 @@
log_error("base address not set!");
}
+#if 0
// Network::byte_t *tmp = AMF::encodeElement(name.c_str());
// memcpy(ptr, tmp, name.size());
// ptr += name.size() + AMF_HEADER_SIZE;
@@ -468,18 +468,19 @@
// ptr += domainname.size() + AMF_HEADER_SIZE;
// ptr += LC_HEADER_SIZE;
- Network::byte_t *x = ptr; // just for debugging from gdb. temporary
+// Network::byte_t *x = ptr; // just for debugging from gdb. temporary
// This is the initial 16 bytes of the header
memset(ptr, 0, LC_HEADER_SIZE + 200);
- *ptr = 1;
+ *buf->at(0) = 1;
+// *ptr = 1;
ptr += 4;
- *ptr = 1;
+ *buf->at(4) = 1;
+// *ptr = 1;
ptr += LC_HEADER_SIZE - 4;
-
// Which is then always followed by 3 AMF objects.
- Network::byte_t *tmp = AMF::encodeElement(name.c_str());
+ Buffer *tmp = AMF::encodeElement(name.c_str());
memcpy(ptr, tmp, name.size() + AMF_HEADER_SIZE);
delete[] tmp;
@@ -516,6 +517,7 @@
}
// delete[] tmp;
+#endif
}
Index: libamf/protocol.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/protocol.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- libamf/protocol.h 29 Mar 2008 19:35:53 -0000 1.8
+++ libamf/protocol.h 1 Apr 2008 22:20:41 -0000 1.9
@@ -26,7 +26,7 @@
#include "network.h"
class Protocol : public gnash::Network {
- typedef enum { RTMP, RTMPT, RTMPS, HTTP, HTTPS } protocol_type_e;
+ typedef enum { RTMP_PROTO, RTMPT_PROTO, RTMPS_PROTO, HTTP_PROTO, HTTPS_PROTO
} protocol_type_e;
public:
Protocol() { };
virtual ~Protocol() { };
Index: libamf/sol.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- libamf/sol.cpp 31 Mar 2008 04:31:02 -0000 1.28
+++ libamf/sol.cpp 1 Apr 2008 22:20:42 -0000 1.29
@@ -31,6 +31,7 @@
#include "network.h"
#include "amf.h"
+#include "buffer.h"
#include "sol.h"
#include "log.h"
@@ -47,6 +48,7 @@
#include <boost/scoped_array.hpp>
using namespace std;
+using namespace amf;
using namespace gnash;
// It comprises of a magic number, followed by the file length, a
@@ -78,12 +80,15 @@
{
// GNASH_REPORT_FUNCTION;
+#if 0
vector<amf::Element *>::iterator it;
- for (it = _amfobjs.begin(); it != _amfobjs.end(); it++)
- {
+ for (it = _amfobjs.begin(); it != _amfobjs.end(); it++) {
amf::Element *el = (*(it));
+ if (el) {
delete el;
}
+ }
+#endif
}
bool
@@ -224,7 +229,7 @@
for (ita = _amfobjs.begin(); ita != _amfobjs.end(); ita++) {
amf::Element *el = (*(ita));
- size += el->getName().size() + el->getLength() + 7;
+ size += el->getNameSize() + el->getLength() + 7;
}
_filesize = size;
@@ -235,7 +240,7 @@
for (ita = _amfobjs.begin(); ita != _amfobjs.end(); ita++) {
amf::Element *el = (*(ita));
- Network::byte_t *var = amf_obj.encodeVariable(el);
+ Buffer *var = amf_obj.encodeVariable(el);
// Network::byte_t *var = amf_obj.encodeVariable(el, outsize);
if (!var) {
continue;
@@ -243,22 +248,21 @@
size_t outsize = 0;
switch (el->getType()) {
case Element::BOOLEAN:
- outsize = el->getName().size() + 5;
- assert(ptr+outsize < endPtr);
- memcpy(ptr, var, outsize);
+ outsize = el->getNameSize() + 5;
+ var->append(el->getNameSize());
ptr += outsize;
break;
case Element::OBJECT:
- outsize = el->getName().size() + 5;
+ outsize = el->getNameSize() + 5;
assert(ptr+outsize < endPtr);
- outsize = el->getName().size() + 5;
+ outsize = el->getNameSize() + 5;
memcpy(ptr, var, outsize);
ptr += outsize;
*ptr++ = Element::OBJECT_END;
*ptr++ = 0; // objects are terminated too!
break;
case Element::NUMBER:
- outsize = el->getName().size() + AMF_NUMBER_SIZE + 2;
+ outsize = el->getNameSize() + AMF_NUMBER_SIZE + 2;
assert(ptr+outsize < endPtr);
memcpy(ptr, var, outsize);
ptr += outsize;
@@ -282,7 +286,7 @@
memcpy(ptr, var, outsize);
ptr += outsize;
}
- delete[] var;
+ delete var;
}
_filesize = ptr - body.get();
@@ -368,12 +372,13 @@
ptr += 4;
AMF amf_obj;
- while ((ptr - buf.get()) < bodysize) {
- amf::Element *el = new amf::Element;
- ptr = amf_obj.extractVariable(el, ptr);
- if (ptr != 0) {
- ptr += 1;
- addObj(el);
+ int size = 0;
+ 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;
+ _amfobjs.push_back(el);
} else {
break;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libnet/Makefile.am libnet/cque....,
Rob Savoye <=