Gnash  0.8.11dev
AMFConverter.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 
20 #ifndef GNASH_AMFCONVERTER_H
21 #define GNASH_AMFCONVERTER_H
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 #include "dsodefs.h"
28 #include "AMF.h"
29 
30 namespace gnash {
31  class as_object;
32  class as_value;
33  class SimpleBuffer;
34  class Global_as;
35 }
36 
37 namespace gnash {
38 
40 //
44 namespace amf {
45 
47 //
50 //
55 class Writer
56 {
57 public:
58 
59  typedef std::map<as_object*, size_t> OffsetTable;
60 
61  Writer(SimpleBuffer& buf, bool strictArray = false)
62  :
63  _buf(buf),
64  _strictArray(strictArray)
65  {}
66 
68  //
70  bool writeObject(as_object* obj);
71 
73  //
75  bool writeString(const std::string& str);
76 
78  bool writeNull();
79 
81  bool writeUndefined();
82 
84  bool writeNumber(double d);
85 
87  bool writeBoolean(bool b);
88 
90  //
92  bool writePropertyName(const std::string& name);
93 
95  void writeData(const std::uint8_t* data, size_t length);
96 
97 private:
98 
99  OffsetTable _offsets;
100  SimpleBuffer& _buf;
101  bool _strictArray;
102 
103 };
104 
105 
107 //
111 //
115 //
121 class Reader
122 {
123 public:
124 
126  //
129  //
135  Reader(const std::uint8_t*& pos, const std::uint8_t* end, Global_as& gl)
136  :
137  _pos(pos),
138  _end(end),
139  _global(gl)
140  {}
141 
143  //
149  bool operator()(as_value& val, Type t = NOTYPE);
150 
151 private:
152 
154  as_value readXML();
155 
157  as_value readDate();
158 
160  as_value readObject();
161 
163  as_value readReference();
164 
166  as_value readArray();
167 
169  as_value readStrictArray();
170 
172  std::vector<as_object*> _objectRefs;
173 
175  const std::uint8_t*& _pos;
176 
178  const std::uint8_t* const _end;
179 
181  Global_as& _global;
182 
183 };
184 
185 } // namespace amf
186 } // namespace gnash
187 
188 #endif
AMF.h
gnash::Date_as
Definition: Date_as.h:34
gnash::XML_as::toString
void toString(std::ostream &o, bool encode) const
Convert the XML object to a string.
Definition: XML_as.cpp:129
gnash::isNativeType
bool isNativeType(const as_object *obj, T *&relay)
Check whether the object is an instance of a known type.
Definition: as_object.h:875
gnash::amf::AMFException
Exception for handling malformed buffers.
Definition: AMF.h:71
gnash::arrayKey
ObjectURI arrayKey(VM &vm, size_t i)
Convert an integral value into an ObjectURI.
Definition: Array_as.cpp:995
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::as_object::visitProperties
void visitProperties(PropertyVisitor &visitor) const
Visit the properties of this object by key/as_value pairs.
Definition: as_object.h:547
gnash::key::d
@ d
Definition: GnashKey.h:150
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::amf::readBoolean
bool readBoolean(const std::uint8_t *&pos, const std::uint8_t *_end)
Read a boolean value from the buffer.
Definition: AMF.cpp:50
gnash::SimpleBuffer::appendNetworkLong
void appendNetworkLong(const std::uint32_t l)
Append 4 bytes to the buffer.
Definition: SimpleBuffer.h:169
as_object.h
SimpleBuffer.h
gnash::amf::Writer
A class to compose AMF buffers.
Definition: AMFConverter.h:56
ObjectURI.h
gnash::amf::readLongString
std::string readLongString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a long string value from the buffer.
Definition: AMF.cpp:109
AMFConverter.h
gnash::getName
string_table::key getName(const ObjectURI &o)
Get the name element of an ObjectURI.
Definition: ObjectURI.h:116
dsodefs.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::amf::Reader::Reader
Reader(const std::uint8_t *&pos, const std::uint8_t *end, Global_as &gl)
Construct a Reader with pointers into an AMF buffer.
Definition: AMFConverter.h:135
gnash::NSV::PROP_LENGTH
@ PROP_LENGTH
Definition: namedStrings.h:83
_
#define _(String)
Definition: log.h:44
gnash::as_environment
Provides information about timeline context.
Definition: as_environment.h:51
gnash::amf::XML_OBJECT_AMF0
@ XML_OBJECT_AMF0
Definition: AMF.h:62
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
gnash::SimpleBuffer::appendByte
void appendByte(const std::uint8_t b)
Append a byte to the buffer.
Definition: SimpleBuffer.h:140
gnash::as_object::to_function
virtual as_function * to_function()
Cast to a as_function, or return NULL.
Definition: as_object.h:471
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::amf::STRICT_ARRAY_AMF0
@ STRICT_ARRAY_AMF0
Definition: AMF.h:57
PropertyList.h
gnash::arrayLength
size_t arrayLength(as_object &array)
Get the length of an object as though it were an array.
Definition: Array_as.cpp:942
gnash::amf::NOTYPE
@ NOTYPE
Definition: AMF.h:46
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::amf::Writer::writeString
bool writeString(const std::string &str)
Write a string.
Definition: AMFConverter.cpp:251
gnash::amf::LONG_STRING_AMF0
@ LONG_STRING_AMF0
Definition: AMF.h:59
as_value.h
gnash::amf::NULL_AMF0
@ NULL_AMF0
Definition: AMF.h:52
Global_as.h
gnash::amf::readNetworkShort
std::uint16_t readNetworkShort(const std::uint8_t *buf)
Read an unsigned 16-bit value in network byte order.
Definition: AMF.h:119
gnash::amf::Writer::Writer
Writer(SimpleBuffer &buf, bool strictArray=false)
Definition: AMFConverter.h:61
gnash::NSV::PROP_CONSTRUCTOR
@ PROP_CONSTRUCTOR
Definition: namedStrings.h:68
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
as_function.h
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::getMember
as_value getMember(as_object &o, const ObjectURI &uri)
Get a member of an object using AS lookup rules.
Definition: as_object.h:756
gnash::as_object::array
bool array() const
Return true if this object should be treated as an array.
Definition: as_object.h:625
gnash::amf::Writer::writeData
void writeData(const std::uint8_t *data, size_t length)
Write custom data for special cases.
Definition: AMFConverter.cpp:293
gnash::createObject
as_object * createObject(const Global_as &gl)
Definition: Global_as.cpp:303
gnash::NSV::PROP_PUSH
@ PROP_PUSH
Definition: namedStrings.h:88
gnash::amf::readNetworkLong
std::uint32_t readNetworkLong(const std::uint8_t *buf)
Read an unsigned 32-bit value in network byte order.
Definition: AMF.h:129
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::callMethod
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
gnash::amf::OBJECT_END_AMF0
@ OBJECT_END_AMF0
Definition: AMF.h:56
gnash::amf::write
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
gnash::fn_call::Args
FunctionArgs< as_value > Args
Definition: fn_call.h:121
gnash::amf::Type
Type
Definition: AMF.h:45
gnash::as_value::to_function
as_function * to_function() const
Return the value as a function only if it is a function.
Definition: as_value.cpp:499
gnash::FunctionArgs
A class to contain transferable arguments for a fn_call.
Definition: fn_call.h:57
gnash::amf::readString
std::string readString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a string value from the buffer.
Definition: AMF.cpp:87
gnash::NSV::CLASS_DATE
@ CLASS_DATE
Definition: namedStrings.h:208
gnash::as_value::writeAMF0
bool writeAMF0(amf::Writer &w) const
Serialize value in AMF0 format.
Definition: as_value.cpp:759
gnash::amf::DATE_AMF0
@ DATE_AMF0
Definition: AMF.h:58
length
@ length
Definition: klash_part.cpp:329
gnash::amf::Writer::writeNumber
bool writeNumber(double d)
Write a double.
Definition: AMFConverter.cpp:258
gnash::constructInstance
as_object * constructInstance(as_function &ctor, const as_environment &env, fn_call::Args &args)
Definition: as_function.cpp:47
gnash::amf::OBJECT_AMF0
@ OBJECT_AMF0
Definition: AMF.h:50
gnash::amf::writePlainString
void writePlainString(SimpleBuffer &buf, const std::string &str, Type t)
Encode a plain short string to an AMF buffer.
Definition: AMF.cpp:133
gnash::amf::ECMA_ARRAY_AMF0
@ ECMA_ARRAY_AMF0
Definition: AMF.h:55
gnash::IsEnumerable
Definition: as_object.h:805
test.w
w
Definition: test.py:8
gnash::amf::NUMBER_AMF0
@ NUMBER_AMF0
Definition: AMF.h:47
gnash::amf::Writer::OffsetTable
std::map< as_object *, size_t > OffsetTable
Definition: AMFConverter.h:59
gnash::NSV::CLASS_XML
@ CLASS_XML
Definition: namedStrings.h:257
gnash::amf::Writer::writeBoolean
bool writeBoolean(bool b)
Write a boolean.
Definition: AMFConverter.cpp:265
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::Global_as::createArray
as_object * createArray()
Construct an Array.
Definition: Global_as.cpp:207
VM.h
gnash::amf::REFERENCE_AMF0
@ REFERENCE_AMF0
Definition: AMF.h:54
XML_as.h
gnash::as_object::relay
Relay * relay() const
Access the as_object's Relay object.
Definition: as_object.h:620
fn_call.h
gnash::amf::Reader
Deserialize an AMF buffer to as_values.
Definition: AMFConverter.h:122
gnash::amf::Writer::writePropertyName
bool writePropertyName(const std::string &name)
Encode the name of an object's property.
Definition: AMFConverter.cpp:115
gnash::image::end
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
namedStrings.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
test.uri
uri
Definition: test.py:12
gnash::getStringTable
string_table & getStringTable(const as_environment &env)
Definition: as_environment.cpp:639
gnash::Date_as::getTimeValue
double getTimeValue() const
Definition: Date_as.h:41
gnash::amf::UNDEFINED_AMF0
@ UNDEFINED_AMF0
Definition: AMF.h:53
gnash::XML_as
Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
Definition: XML_as.h:45
gnash::amf::STRING_AMF0
@ STRING_AMF0
Definition: AMF.h:49
gnash::NSV::PROP_uuPROTOuu
@ PROP_uuPROTOuu
Definition: namedStrings.h:118
gnash::getURI
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
gnash::amf::Reader::operator()
bool operator()(as_value &val, Type t=NOTYPE)
Create a type from current position in the AMF buffer.
Definition: AMFConverter.cpp:299
Array_as.h
gnash::amf::UNSUPPORTED_AMF0
@ UNSUPPORTED_AMF0
Definition: AMF.h:60
gnash::SimpleBuffer::append
void append(const void *inData, size_t size)
Append data to the buffer.
Definition: SimpleBuffer.h:123
gnash::amf::Writer::writeUndefined
bool writeUndefined()
Write an undefined value.
Definition: AMFConverter.cpp:273
gnash::string_table::key
std::size_t key
Definition: string_table.h:83
gnash::amf::readNumber
double readNumber(const std::uint8_t *&pos, const std::uint8_t *end)
Read a number from an AMF buffer.
Definition: AMF.cpp:65
gnash::amf::Writer::writeObject
bool writeObject(as_object *obj)
Write any simple Object type: not DisplayObjects.
Definition: AMFConverter.cpp:122
gnash::IsStrictArray
A visitor to check whether an array is strict or not.
Definition: Array_as.h:55
Date_as.h
gnash::amf::BOOLEAN_AMF0
@ BOOLEAN_AMF0
Definition: AMF.h:48
gnash::amf::writePlainNumber
void writePlainNumber(SimpleBuffer &buf, double d)
Write a number to an AMF buffer.
Definition: AMF.cpp:154
gnash::SimpleBuffer::appendNetworkShort
void appendNetworkShort(const std::uint16_t s)
Append 2 bytes to the buffer.
Definition: SimpleBuffer.h:154
gnash::key::b
@ b
Definition: GnashKey.h:148
data
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::SimpleBuffer
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
gnash::as_function
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:63
gnash::amf::Writer::writeNull
bool writeNull()
Write a null value.
Definition: AMFConverter.cpp:283