Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _AMF_H_
00028 #define _AMF_H_
00029
00030 #include <string>
00031 #include <cstring>
00032 #include <boost/cstdint.hpp>
00033 #include <boost/shared_ptr.hpp>
00034
00035 #include "element.h"
00036 #include "dsodefs.h"
00037
00039 namespace cygnal
00040 {
00041
00042
00043 class Buffer;
00044
00046 const size_t AMF0_NUMBER_SIZE = 0x08;
00047
00051 const boost::uint8_t AMF_HEADER_SIZE = 3;
00052
00059 const boost::uint8_t AMF_PROP_HEADER_SIZE = 5;
00060
00062 const boost::uint8_t AMF_VERSION = 0;
00063
00065 const boost::uint8_t TERMINATOR = 0x09;
00066
00072 const boost::uint16_t SANE_STR_SIZE = 65535;
00073
00075
00080 class DSOEXPORT AMF {
00081 public:
00082
00084 typedef enum {
00085 CONNECT = 0x01,
00086 DISCONNECT = 0x02,
00087 SET_ATTRIBUTE = 0x03,
00088 UPDATE_DATA = 0x04,
00089 UPDATE_ATTRIBUTE = 0x05,
00090 SEND_MESSAGE = 0x06,
00091 STATUS = 0x07,
00092 CLEAR_DATA = 0x08,
00093 DELETE_DATA = 0x09,
00094 DELETE_ATTRIBYTE = 0x0a,
00095 INITIAL_DATA = 0x0b
00096 } shared_obj_types_e;
00097
00099 typedef enum {
00100 FILETYPE_ERROR = -1,
00101 FILETYPE_NONE = 0,
00102 FILETYPE_HTML,
00103 FILETYPE_SWF,
00104 FILETYPE_VIDEO,
00105 FILETYPE_AUDIO,
00106 FILETYPE_MP3,
00107 FILETYPE_FCS,
00108 FILETYPE_OSCP
00109 } filetype_e;
00110
00112
00117 AMF();
00118
00120 ~AMF();
00121
00131
00133
00138 static boost::shared_ptr<Buffer> encodeString(const std::string &str);
00139
00141
00148 static boost::shared_ptr<Buffer> encodeString(boost::uint8_t *data,
00149 size_t size);
00150
00152
00157 static boost::shared_ptr<Buffer> encodeNullString();
00158
00160
00165 static boost::shared_ptr<Buffer> encodeBoolean(bool flag);
00166
00168
00171 static boost::shared_ptr<Buffer> encodeUndefined();
00172
00174
00179 static boost::shared_ptr<Buffer> encodeNull();
00180
00182
00185 static boost::shared_ptr<Buffer> encodeUnsupported();
00186
00188
00195 static boost::shared_ptr<Buffer> encodeXMLObject(const boost::uint8_t *data,
00196 size_t nbytes);
00197
00199
00206 static boost::shared_ptr<Buffer> encodeTypedObject(const cygnal::Element &data);
00207
00209
00216 static boost::shared_ptr<Buffer> encodeReference(boost::uint16_t index);
00217
00219
00226 static boost::shared_ptr<Buffer> encodeMovieClip(const boost::uint8_t *data,
00227 size_t size);
00228
00230
00240 static boost::shared_ptr<Buffer> encodeECMAArray(const cygnal::Element &data);
00241
00243
00250 static boost::shared_ptr<Buffer> encodeLongString(const boost::uint8_t *data,
00251 size_t size);
00252
00254
00261 static boost::shared_ptr<Buffer> encodeRecordSet(const boost::uint8_t *data,
00262 size_t size);
00263
00265
00270 static boost::shared_ptr<Buffer> encodeDate(const boost::uint8_t *data);
00271
00273
00283 static boost::shared_ptr<Buffer> encodeStrictArray(const cygnal::Element &data);
00284
00286
00291 static boost::shared_ptr<Buffer> encodeObject(const cygnal::Element &data);
00292
00294
00297 static boost::shared_ptr<Buffer> encodeObjectEnd();
00298
00300
00305 static boost::shared_ptr<Buffer> encodeNumber(double num);
00306
00308
00313 static boost::shared_ptr<Buffer> encodeElement(boost::shared_ptr<cygnal::Element> el);
00314
00316
00321 static boost::shared_ptr<Buffer> encodeElement(const cygnal::Element& el);
00322
00324
00329 boost::shared_ptr<Buffer> encodeProperty(boost::shared_ptr<cygnal::Element> el);
00330
00332
00338
00340
00345 static Element::amf0_type_e extractElementHeader(boost::uint8_t *in)
00346 { return *(reinterpret_cast<Element::amf0_type_e *>(in)); };
00347
00349
00361 boost::shared_ptr<cygnal::Element> extractAMF(boost::uint8_t *in, boost::uint8_t* tooFar);
00362
00364
00371 boost::shared_ptr<cygnal::Element> extractAMF(boost::shared_ptr<Buffer> buf);
00372
00374
00388 boost::shared_ptr<cygnal::Element> extractProperty(boost::uint8_t *in, boost::uint8_t* tooFar);
00389
00391
00402 boost::shared_ptr<cygnal::Element> extractProperty(boost::shared_ptr<Buffer> buf);
00403
00405
00407
00410 size_t totalsize() { return _totalsize; }
00411
00412 private:
00413
00415 size_t _totalsize;
00416
00417 };
00418
00420
00429 DSOEXPORT void *swapBytes(void *word, size_t size);
00430
00431
00432 }
00433
00434
00435 #endif
00436
00437
00438
00439
00440