コード例 #1
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static Variant HHVM_STATIC_METHOD(Locale, composeLocale, CArrRef subtags) {
  s_intl_error->clearError();

  if (subtags.exists(s_GRANDFATHERED)) {
    auto val = subtags[s_GRANDFATHERED];
    if (val.isString()) {
      return val;
    }
  }

  if (!subtags.exists(s_LOC_LANG)) {
    s_intl_error->setError(U_ILLEGAL_ARGUMENT_ERROR, "locale_compose: "
                           "parameter array does not contain 'language' tag.");
    return false;
  }
  String ret(subtags[s_LOC_LANG].toString());
  if (!append_multiple_key_values(ret, subtags, LOC_EXTLANG) ||
      !append_key_value(ret, subtags, LOC_SCRIPT) ||
      !append_key_value(ret, subtags, LOC_REGION) ||
      !append_multiple_key_values(ret, subtags, LOC_VARIANT) ||
      !append_multiple_key_values(ret, subtags, LOC_PRIVATE)) {
    return false;
  }
  return ret;
}
コード例 #2
0
ファイル: ext_stream.cpp プロジェクト: Bluarggag/hhvm
void StreamContext::mergeParams(CArrRef params) {
  if (m_params.isNull()) {
    m_params = Array::Create();
  }
  const String& notification_key = String::FromCStr("notification");
  if (params.exists(notification_key)) {
    m_params.set(notification_key, params[notification_key]);
  }
  const String& options_key = String::FromCStr("options");
  if (params.exists(options_key)) {
    assert(params[options_key].isArray());
    mergeOptions(params[options_key].toArray());
  }
}
コード例 #3
0
ファイル: pdo_sqlite.cpp プロジェクト: Dx3webs/hhvm
bool PDOSqliteConnection::create(CArrRef options) {
  String filename = data_source.substr(0,1) == ":" ? String(data_source) :
                    File::TranslatePath(data_source);
  if (filename.empty()) {
    throw_pdo_exception(0, Array(),
                        "safe_mode/open_basedir prohibits opening %s",
                        data_source.c_str());
    return false;
  }

  if (sqlite3_open(filename.data(), &m_db) != SQLITE_OK) {
    handleError(__FILE__, __LINE__);
    return false;
  }

  sqlite3_set_authorizer(m_db, authorizer, NULL);

  long timeout = 60;
  if (options.exists(PDO_ATTR_TIMEOUT)) {
    timeout = options[PDO_ATTR_TIMEOUT].toInt64();
  }
  sqlite3_busy_timeout(m_db, timeout * 1000);

  return true;
}
コード例 #4
0
ファイル: pdo_pgsql.cpp プロジェクト: kastermester/hhvm-pgsql
	String pdo_attr_strval(const CArrRef& options, int opt, const char *def){
		if(options.exists(opt)){
			return options[opt].toString();
		}
		if(def){
			return def;
		}
		return String();
	}
コード例 #5
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static bool append_key_value(String& ret,
                             CArrRef subtags,
                             LocaleTag tag) {
  auto name = LocaleName(tag);
  if (!subtags.exists(name)) return true;
  auto val = subtags[name];
  if (!val.isString()) {
    element_not_string();
    return false;
  }
  ret += s_SEPARATOR + val.toString();
  return true;
}
コード例 #6
0
std::string ExtendedLogger::StringOfFrame(CArrRef frame, int i, bool escape) {
  std::ostringstream ss;

  if (i > 0) {
    ss << (escape ? "\\n" : "\n");
  }
  ss << "    #" << i << " ";
  if (frame.exists(s_function)) {
    if (frame.exists(s_class)) {
      ss << frame[s_class].toString().c_str()
         << frame[s_type].toString().c_str()
         << frame[s_function].toString().c_str()
         << "(), called ";
    } else {
      ss << frame[s_function].toString().c_str()
         << "(), called ";
    }
  }
  ss << "at [" << frame[s_file].toString().c_str()
     << ":" << frame[s_line].toInt64() << "]";

  return ss.str();
}
コード例 #7
0
ファイル: ext_server.cpp プロジェクト: ArPharazon/hiphop-php
Object f_pagelet_server_task_start(CStrRef url,
                                   CArrRef headers /* = null_array */,
                                   CStrRef post_data /* = null_string */,
                                   CArrRef files /* = null_array */) {
  String remote_host;
  Transport *transport = g_context->getTransport();
  if (transport) {
    remote_host = transport->getRemoteHost();
    if (!headers.exists("Host") && RuntimeOption::SandboxMode) {
      Array tmp = headers;
      tmp.set("Host", transport->getHeader("Host"));
      return PageletServer::TaskStart(url, tmp, remote_host, post_data, files);
    }
  }
  return PageletServer::TaskStart(url, headers, remote_host, post_data);
}
コード例 #8
0
Resource f_pagelet_server_task_start(CStrRef url,
                                     CArrRef headers /* = null_array */,
                                     CStrRef post_data /* = null_string */,
                                     CArrRef files /* = null_array */) {
  String remote_host;
  Transport *transport = g_context->getTransport();
  int timeout = ThreadInfo::s_threadInfo->m_reqInjectionData.getRemainingTime();
  if (transport) {
    remote_host = transport->getRemoteHost();
    if (!headers.exists(s_Host) && RuntimeOption::SandboxMode) {
      Array tmp = headers;
      tmp.set(s_Host, transport->getHeader("Host"));
      return PageletServer::TaskStart(url, tmp, remote_host,
                                      post_data, files, timeout);
    }
  }
  return PageletServer::TaskStart(url, headers, remote_host,
                                  post_data, files, timeout);
}
コード例 #9
0
ファイル: type_array.cpp プロジェクト: jmedrano/hiphop-php
Array Array::diffImpl(CArrRef array, bool by_key, bool by_value, bool match,
                      PFUNC_CMP key_cmp_function,
                      const void *key_data,
                      PFUNC_CMP value_cmp_function,
                      const void *value_data) const {
  ASSERT(by_key || by_value);
  ASSERT(by_key || key_cmp_function == NULL);
  ASSERT(by_value || value_cmp_function == NULL);
  PFUNC_CMP value_cmp_as_string_function = value_cmp_function;
  if (!value_cmp_function) {
    value_cmp_function = SortStringAscending;
    value_cmp_as_string_function = CompareAsStrings;
  }

  Array ret = Array::Create();
  if (by_key && !key_cmp_function) {
    // Fast case
    for (ArrayIter iter(*this); iter; ++iter) {
      Variant key(iter.first());
      CVarRef value(iter.secondRef());
      bool found = false;
      if (array->exists(key)) {
        if (by_value) {
          found = value_cmp_as_string_function(
            value, array.rvalAt(key, AccessFlags::Key), value_data) == 0;
        } else {
          found = true;
        }
      }
      if (found == match) {
        ret.addLval(key, true).setWithRef(value);
      }
    }
    return ret;
  }

  if (!key_cmp_function) {
    key_cmp_function = SortRegularAscending;
  }

  vector<int> perm1;
  SortData opaque1;
  int bottom = 0;
  int top = array.size();
  PFUNC_CMP cmp;
  const void *cmp_data;
  if (by_key) {
    cmp = key_cmp_function;
    cmp_data = key_data;
  } else {
    cmp = value_cmp_function;
    cmp_data = value_data;
  }
  SortImpl(perm1, array, opaque1, cmp, by_key, cmp_data);

  for (ArrayIter iter(*this); iter; ++iter) {
    Variant target;
    if (by_key) {
      target = iter.first();
    } else {
      target = iter.second();
    }

    int mid = -1;
    int min = bottom;
    int max = top;
    while (min < max) {
      mid = (max + min) / 2;
      ssize_t pos = opaque1.positions[perm1[mid]];
      int cmp_res =  cmp(target,
                         by_key ? array->getKey(pos)
                                : array->getValueRef(pos),
                         cmp_data);
      if (cmp_res > 0) { // outer is bigger
        min = mid + 1;
      } else if (cmp_res == 0) {
        break;
      } else {
        max = mid;
      }
    }
    bool found = false;
    if (min < max) { // found
      // if checking both, check value
      if (by_key && by_value) {
        CVarRef val(iter.secondRef());
        // Have to look up and down for matches
        for (int i = mid; i < max; i++) {
          ssize_t pos = opaque1.positions[perm1[i]];
          if (key_cmp_function(target, array->getKey(pos), key_data) != 0) {
            break;
          }
          if (value_cmp_as_string_function(val, array->getValueRef(pos),
                                           value_data) == 0) {
            found = true;
            break;
          }
        }
        if (!found) {
          for (int i = mid-1; i >= min; i--) {
            ssize_t pos = opaque1.positions[perm1[i]];
            if (key_cmp_function(target, array->getKey(pos), key_data) != 0) {
              break;
            }
            if (value_cmp_as_string_function(val, array->getValueRef(pos),
                                             value_data) == 0) {
              found = true;
              break;
            }
          }
        }
      } else {
        // found at mid
        found = true;
      }
    }

    if (found == match) {
      ret.addLval(iter.first(), true).setWithRef(iter.secondRef());
    }
  }
  return ret;
}
コード例 #10
0
ファイル: ext_icu_locale.cpp プロジェクト: RdeWilde/hhvm
static bool append_multiple_key_values(String& ret,
                                       CArrRef subtags,
                                       LocaleTag tag) {
  auto name = LocaleName(tag);
  if (subtags.exists(name)) {
    // Sane version: [tag] => string, [tag] => array<tring>
    auto val = subtags[name];
    if (val.isString()) {
      if (tag == LOC_PRIVATE) {
        ret += s_SEPARATOR_x;
      }
      ret += s_SEPARATOR + val.toString();
      return true;
    }
    if (!val.isArray()) {
      return false;
    }
    bool first = true;
    for (ArrayIter it(val.toArray()); it; ++it) {
      auto v = it.second();
      if (!v.isString()) {
        element_not_string();
        return false;
      }
      if (first) {
        if (tag == LOC_PRIVATE) {
          ret += s_SEPARATOR + "x";
        }
        first = false;
      }
      ret += s_SEPARATOR + v.toString();
    }
    return true;
  }

  // clowny version [tag$n] => string
  // Only extlang, variant, and private
  if (tag != LOC_EXTLANG &&
      tag != LOC_VARIANT &&
      tag != LOC_PRIVATE) {
    return true;
  }

  int max = (tag == LOC_EXTLANG) ? 3 : 15;
  bool first = true;
  for (int i = 0; i < max; ++i) {
    auto namenum = name + String(i, CopyString);
    if (!subtags.exists(namenum)) continue;
    auto val = subtags[namenum];
    if (!val.isString()) {
      element_not_string();
      return false;
    }
    if (first) {
      if (tag == LOC_PRIVATE) {
        ret += s_SEPARATOR + "x";
      }
      first = false;
    }
    ret += s_SEPARATOR + val.toString();
  }
  return true;
}
コード例 #11
0
ファイル: pdo_pgsql.cpp プロジェクト: kastermester/hhvm-pgsql
	long pdo_attr_lval(const CArrRef& options, int opt, long defaultValue){
		if(options.exists(opt)){
			return options[opt].toInt64();
		}
		return defaultValue;
	}