2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VARIABLE_UNSERIALIZER_H_
18 #define incl_HPHP_VARIABLE_UNSERIALIZER_H_
20 #include "hphp/runtime/base/req-containers.h"
21 #include "hphp/runtime/base/type-variant.h"
22 #include "hphp/runtime/base/types.h"
26 ///////////////////////////////////////////////////////////////////////////////
28 enum class UnserializeMode
{
35 struct VariableUnserializer
{
38 * Supported unserialization formats.
47 * Construct an unserializer, with an optional whitelist of classes to
48 * allow. In the whitelist, empty_array means "allow no classes", while
49 * null_array means allow any classes. We default to null_array since
50 * serialization is not limited inside the VM.
56 bool allowUnknownSerializableClass
= false,
57 const Array
& classWhitelist
= null_array
);
60 * Main API; unserialize the buffer and return as a Variant.
62 Variant
unserialize();
65 * Read the appropriate data type from buffer.
70 void read(char* buf
, unsigned n
);
73 * Read a character and throw if it differs from expected.
75 void expectChar(char expected
);
76 void throwUnexpected(char expected
, char got
);
82 bool allowUnknownSerializableClass() const;
83 const char* head() const;
85 char peekBack() const;
86 bool endOfBuffer() const;
89 * True if clsName is allowed to be unserialized.
91 bool isWhitelistedClass(const String
& clsName
) const;
94 * Set the beginning and end of internal buffer.
96 void set(const char* buf
, const char* end
);
99 * Push v onto the vector of refs for future reference.
101 void add(Variant
* v
, UnserializeMode mode
);
104 * Used by the 'r' encoding to get a reference.
106 Variant
* getByVal(int id
);
109 * Used by the 'R' encoding to get a reference.
111 Variant
* getByRef(int id
);
114 * Store properties/array elements that get overwritten incase they are
115 * referenced later during unserialization
117 void putInOverwrittenList(const Variant
& v
);
121 * Hold references to previously-unserialized data, along with bits telling
122 * whether it is legal to reference them later.
125 explicit RefInfo(Variant
* v
);
126 static RefInfo
makeNonRefable(Variant
* v
);
127 Variant
* var() const;
128 bool canBeReferenced() const;
133 Array m_overwrittenList
;
140 req::vector
<RefInfo
> m_refs
;
141 bool m_unknownSerializable
;
142 const Array
& m_classWhiteList
; // classes allowed to be unserialized
145 ///////////////////////////////////////////////////////////////////////////////
147 void unserializeVariant(Variant
&, VariableUnserializer
*unserializer
,
148 UnserializeMode mode
= UnserializeMode::Value
);
152 #include "hphp/runtime/base/variable-unserializer-inl.h"
154 #endif // incl_HPHP_VARIABLE_UNSERIALIZER_H_