• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

amf.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 // This file is for the low level support for encoding and decoding AMF objects.
00020 // As this class has no data associated with it, all the methods are static as
00021 // they are for convenience only.
00022 // All the encoding methods return a Buffer class, which is simply an array on
00023 // of unsigned bytes, and a byte count.
00024 // The only extraction classes parse either a raw AMF object or the larger
00025 // "variable"
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 // forward declaration
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 } // end of amf namespace
00433 
00434 // end of _AMF_H_
00435 #endif
00436 
00437 // local Variables:
00438 // mode: C++
00439 // indent-tabs-mode: t
00440 // End:

Generated on Fri Mar 16 2012 15:46:08 for Gnash by  doxygen 1.7.1