Rename runtime/base/zend_* to zend-
[hiphop-php.git] / hphp / runtime / base / variable_unserializer.cpp
blobfcbec5fc910af356bf24ce60728abf559361abc1
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1998-2010 Zend Technologies Ltd. (http://www.zend.com) |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 2.00 of the Zend license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.zend.com/license/2_00.txt. |
12 | If you did not receive a copy of the Zend license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@zend.com so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #include "hphp/runtime/base/variable_unserializer.h"
19 #include "hphp/runtime/base/complex_types.h"
20 #include "hphp/runtime/base/zend-strtod.h"
21 #include "hphp/runtime/base/array_iterator.h"
22 #include "hphp/runtime/ext/ext_class.h"
24 namespace HPHP {
25 ///////////////////////////////////////////////////////////////////////////////
27 Variant VariableUnserializer::unserialize() {
28 Variant v;
29 v.unserialize(this);
30 return v;
33 Variant VariableUnserializer::unserializeKey() {
34 Variant v;
35 v.unserialize(this, Uns::Mode::Key);
36 return v;
39 int64_t VariableUnserializer::readInt() {
40 check();
41 char *newBuf;
42 int64_t r = strtoll(m_buf, &newBuf, 10);
43 m_buf = newBuf;
44 return r;
47 double VariableUnserializer::readDouble() {
48 check();
49 char *newBuf;
50 double r = zend_strtod(m_buf, &newBuf);
51 m_buf = newBuf;
52 return r;
55 void VariableUnserializer::read(char *buf, uint n) {
56 check();
58 /* compute copy boundaries in a more efficient manner,
59 by using min(...) operation rather than complex conditional
60 in a loop guard */
61 const size_t BUFFER_SIZE = m_end - m_buf;
62 const size_t BUFFER_LIMIT = std::min(BUFFER_SIZE, size_t(n));
64 memcpy(buf, m_buf, BUFFER_LIMIT);
65 m_buf += BUFFER_LIMIT;
68 Variant &VariableUnserializer::addVar() {
69 m_vars.push_back(uninit_null());
70 return m_vars.back();
73 bool VariableUnserializer::isWhitelistedClass(CStrRef cls_name) const {
74 if (m_type != Type::Serialize || m_classWhiteList.isNull()) {
75 return true;
77 if (!m_classWhiteList.isNull() && !m_classWhiteList.empty()) {
78 for (ArrayIter iter(m_classWhiteList); iter; ++iter) {
79 CVarRef value(iter.secondRef());
80 if (f_is_subclass_of(cls_name, value.toString()) ||
81 same(value, cls_name)) {
82 return true;
86 return false;
89 ///////////////////////////////////////////////////////////////////////////////