xmlDocPtr soap_xmlParseFile(const char *filename) { String cache_key("HPHP.SOAP.WSDL."); cache_key += filename; Variant content = f_apc_fetch(cache_key); if (same(content, false)) { Variant stream = File::Open(filename, "rb", 0, f_stream_context_create( make_map_array(s_http, make_map_array(s_timeout, 1000)))); if (!same(stream, false)) { content = f_stream_get_contents(stream.toResource()); if (!same(content, false)) { f_apc_store(cache_key, content); } } } if (!same(content, false)) { String scontent = content.toString(); xmlDocPtr ret = soap_xmlParseMemory(scontent.data(), scontent.size(), false); if (ret) { ret->URL = xmlCharStrdup(filename); } return ret; } return NULL; }
xmlDocPtr soap_xmlParseFile(const char *filename) { String cache_key("HPHP.SOAP.WSDL."); cache_key += filename; Variant content = HHVM_FN(apc_fetch)(cache_key); if (same(content, false)) { Variant cxt = HHVM_FN(stream_context_create)(make_map_array( s_http, make_map_array(s_timeout, 1000))); auto file = File::Open(filename, "rb", 0, cast_or_null<StreamContext>(cxt)); if (file) { content = HHVM_FN(stream_get_contents)(Resource(file)); if (!same(content, false)) { HHVM_FN(apc_store)(cache_key, content); } } } if (!same(content, false)) { String scontent = content.toString(); xmlDocPtr ret = soap_xmlParseMemory(scontent.data(), scontent.size(), false); if (ret) { ret->URL = xmlCharStrdup(filename); } return ret; } return nullptr; }
Variant HHVM_FUNCTION(socket_get_option, const Resource& socket, int level, int optname) { auto sock = cast<Socket>(socket); socklen_t optlen; switch (optname) { case SO_LINGER: { struct linger linger_val; optlen = sizeof(linger_val); if (getsockopt(sock->fd(), level, optname, (char*)&linger_val, &optlen) != 0) { SOCKET_ERROR(sock, "unable to retrieve socket option", errno); return false; } return make_map_array( s_l_onoff, linger_val.l_onoff, s_l_linger, linger_val.l_linger ); } break; case SO_RCVTIMEO: case SO_SNDTIMEO: { struct timeval tv; optlen = sizeof(tv); if (getsockopt(sock->fd(), level, optname, (char*)&tv, &optlen) != 0) { SOCKET_ERROR(sock, "unable to retrieve socket option", errno); return false; } return make_map_array( s_sec, (int)tv.tv_sec, s_usec, (int)tv.tv_usec ); } break; default: { int other_val; optlen = sizeof(other_val); if (getsockopt(sock->fd(), level, optname, (char*)&other_val, &optlen)) { SOCKET_ERROR(sock, "unable to retrieve socket option", errno); return false; } return other_val; } } not_reached(); }
Array TimeZone::transitions(int64_t timestamp_begin, /* = k_PHP_INT_MIN */ int64_t timestamp_end /* = k_PHP_INT_MAX */) const { Array ret; if (m_tzi) { uint32_t timecnt; timecnt = m_tzi->bit32.timecnt; uint32_t lastBefore = 0; for (uint32_t i = 0; i < timecnt && m_tzi->trans && m_tzi->trans[i] <= timestamp_begin; ++i) { lastBefore = i; } // If explicitly provided a timestamp to the ret array // and always make sure there is at least one returned value if (!m_tzi->trans || timestamp_begin >= timestamp_end || ( (timestamp_begin != k_PHP_INT_MIN || timestamp_end != k_PHP_INT_MAX) && timestamp_begin != m_tzi->trans[lastBefore])) { auto dt = req::make<DateTime>( timestamp_begin, req::make<TimeZone>("UTC")); int index = m_tzi->trans ? m_tzi->trans_idx[lastBefore] : 0; ttinfo &offset = m_tzi->type[index]; const char *abbr = m_tzi->timezone_abbr + offset.abbr_idx; ret.append(make_map_array( s_ts, timestamp_begin, s_time, dt->toString(DateTime::DateFormat::ISO8601), s_offset, offset.offset, s_isdst, (bool)offset.isdst, s_abbr, String(abbr, CopyString) )); } for (uint32_t i = lastBefore; i < timecnt && m_tzi->trans && m_tzi->trans[i] < timestamp_end; ++i) { int timestamp = m_tzi->trans[i]; if (timestamp_begin <= timestamp) { int index = m_tzi->trans_idx[i]; auto dt = req::make<DateTime>(timestamp, req::make<TimeZone>("UTC")); ttinfo &offset = m_tzi->type[index]; const char *abbr = m_tzi->timezone_abbr + offset.abbr_idx; ret.append(make_map_array( s_ts, timestamp, s_time, dt->toString(DateTime::DateFormat::ISO8601), s_offset, offset.offset, s_isdst, (bool)offset.isdst, s_abbr, String(abbr, CopyString) )); } } } return ret; }
Variant BZ2File::error() { assert(m_bzFile); int errnum; const char * errstr; errstr = BZ2_bzerror(m_bzFile, &errnum); return make_map_array(s_errno, errnum, s_errstr, String(errstr)); }
Array c_DateTime::t___debuginfo() { return make_map_array( s_date, t_format(s_ISOformat), s_timezone_type, m_dt->zoneType(), s_timezone, m_dt->timezone()->name() ); }
void ExecutionContext::registerShutdownFunction(const Variant& function, Array arguments, ShutdownType type) { Array callback = make_map_array(s_name, function, s_args, arguments); Variant& funcs = m_shutdowns.lvalAt(type); forceToArray(funcs).append(callback); }
Variant HHVM_FUNCTION(time_nanosleep, int seconds, int nanoseconds) { if (seconds < 0) { throw_invalid_argument("seconds: cannot be negative"); return false; } if (nanoseconds < 0 || nanoseconds > 999999999) { throw_invalid_argument("nanoseconds: has to be 0 to 999999999"); return false; } struct timespec req, rem; req.tv_sec = (time_t)seconds; req.tv_nsec = nanoseconds; IOStatusHelper io("nanosleep"); if (!nanosleep(&req, &rem)) { recordNanosleepTime(req, nullptr); return true; } recordNanosleepTime(req, &rem); if (errno == EINTR) { return make_map_array(s_seconds, (int64_t)rem.tv_sec, s_nanoseconds, (int64_t)rem.tv_nsec); } return false; }
Array DateTimeData::getDebugInfo() const { return make_map_array( s_date, format(s_ISOformat), s_timezone_type, m_dt->zoneType(), s_timezone, zone_type_to_string(m_dt->zoneType(), m_dt) ); }
TEST(Backtrace, LongFunctionNames) { StructuredLogEntry sample; { auto bt = Array::Create(); bt.append( make_map_array( s_file, "filenameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", s_line, "42---------------------------------------------------------------------------------", s_function, "function_name--------------------------------------------------------------------", s_type, s_arrow, s_object, "this-------------------------------------------------------------------------------", s_class, "Class-----------------------------------------------------------------------------------------" ) ); addBacktraceToStructLog(bt, sample); } auto const expectedDescription = "{\"vecs\":{\"php_lines\":[\"42-------------" "--------------------------------------------------------------------\"]," "\"php_functions\":[\"Class------------------------------------------------" "------------------------------------------>function_name------------------" "--------------------------------------------------\"],\"php_files\":[\"fil" "enameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "eeeeeee\"]}" ",\"sets\":{},\"ints\":{}}"; EXPECT_EQ(show(sample), expectedDescription); }
TEST(Type, Specialized) { auto packed = Type::Arr.specialize(ArrayData::kPackedKind); EXPECT_LE(packed, Type::Arr); EXPECT_LT(packed, Type::Arr); EXPECT_FALSE(Type::Arr <= packed); EXPECT_LT(packed, Type::Arr | Type::Obj); EXPECT_EQ(packed, packed & (Type::Arr | Type::Counted)); EXPECT_GE(packed, Type::Bottom); EXPECT_GT(packed, Type::Bottom); EXPECT_TRUE(Type::Int <= (packed | Type::Int)); EXPECT_EQ(Type::Bottom, packed - Type::Arr); auto const array = make_packed_array(1, 2, 3, 4); auto const mixed = make_map_array(1, 1, 2, 2); auto const arrData = ArrayData::GetScalarArray(array.get()); auto const arrDataMixed = ArrayData::GetScalarArray(mixed.get()); auto constArray = Type::cns(arrData); auto constArrayMixed = Type::cns(arrDataMixed); auto const spacked = Type::StaticArr.specialize(ArrayData::kPackedKind); EXPECT_EQ(spacked, spacked - constArray); // conservative EXPECT_EQ(constArray, constArray - spacked); // conservative (could be // bottom if we did better) // Implemented conservatively right now, but the following better not return // bottom: EXPECT_EQ(constArrayMixed, constArrayMixed - spacked); // Checking specialization dropping. EXPECT_EQ(Type::Arr | Type::BoxedInitCell, packed | Type::BoxedInitCell); auto specializedObj = Type::Obj.specialize(SystemLib::s_IteratorClass); EXPECT_EQ(Type::Arr | Type::Obj, packed | specializedObj); }
Array f_error_get_last() { String lastError = g_context->getLastError(); if (lastError.isNull()) { return (ArrayData *)NULL; } return make_map_array(s_message, g_context->getLastError(), s_type, g_context->getLastErrorNumber()); }
Array TimeZone::transitions(int64_t timestamp_begin, /* = k_PHP_INT_MIN */ int64_t timestamp_end /* = k_PHP_INT_MAX */) const { Array ret; if (m_tzi) { // If explicitly provided add the beginning timestamp to the ret array if (timestamp_begin > k_PHP_INT_MIN) { auto dt = req::make<DateTime>(timestamp_begin); auto idx = m_tzi->trans_idx[0]; ret.append(make_map_array( s_ts, timestamp_begin, s_time, dt->toString(DateTime::DateFormat::ISO8601), s_offset, m_tzi->type[idx].offset, s_isdst, (bool)m_tzi->type[idx].isdst, s_abbr, String(m_tzi->timezone_abbr + m_tzi->type[idx].abbr_idx, CopyString) )); } uint32_t timecnt; #ifdef FACEBOOK // Internal builds embed tzdata into HHVM by keeping timelib updated timecnt = m_tzi->bit32.timecnt; #else // OSS builds read tzdata from the system location (eg /usr/share/zoneinfo) // as this format must be stable, we're keeping timelib stable too timecnt = m_tzi->timecnt; #endif for (uint32_t i = 0; i < timecnt; ++i) { int timestamp = m_tzi->trans[i]; if (timestamp > timestamp_begin && timestamp <= timestamp_end) { int index = m_tzi->trans_idx[i]; auto dt = req::make<DateTime>(timestamp); ttinfo &offset = m_tzi->type[index]; const char *abbr = m_tzi->timezone_abbr + offset.abbr_idx; ret.append(make_map_array( s_ts, timestamp, s_time, dt->toString(DateTime::DateFormat::ISO8601), s_offset, offset.offset, s_isdst, (bool)offset.isdst, s_abbr, String(abbr, CopyString) )); } } } return ret; }
bool f_stream_set_timeout(const Resource& stream, int seconds, int microseconds /* = 0 */) { if (stream.getTyped<Socket>(false, true)) { return f_socket_set_option (stream, SOL_SOCKET, SO_RCVTIMEO, make_map_array(s_sec, seconds, s_usec, microseconds)); } return false; }
static Array HHVM_METHOD(ImagickPixel, getHSL) { auto wand = getPixelWandResource(this_); double hue, saturation, luminosity; PixelGetHSL(wand->getWand(), &hue, &saturation, &luminosity); return make_map_array( s_hue, hue, s_saturation, saturation, s_luminosity, luminosity); }
bool TestExtMemcached::test_Memcached_get_set() { CREATE_MEMCACHED(); const char *key = "foo"; Array value = make_map_array("foo", "bar"); memc->t_set(key, value, EXPIRATION); VS(memc->t_get(key), value); return Count(true); }
Array HHVM_FUNCTION(heapgraph_stats, const Resource& resource) { auto hgptr = get_valid_heapgraph_context_resource(resource, __FUNCTION__); if (!hgptr) return empty_array(); auto result = make_map_array( s_nodes, Variant(hgptr->hg.nodes.size()), s_edges, Variant(hgptr->hg.ptrs.size()), s_roots, Variant(hgptr->hg.roots.size()) ); return result; }
Array HHVM_FUNCTION(error_get_last) { String lastError = g_context->getLastError(); if (lastError.isNull()) { return Array(); } return make_map_array(s_type, g_context->getLastErrorNumber(), s_message, g_context->getLastError(), s_file, g_context->getLastErrorPath(), s_line, g_context->getLastErrorLine()); }
bool TestExtCurl::test_curl_setopt_array() { Variant c = HHVM_FN(curl_init)(); HHVM_FN(curl_setopt_array) (c.toResource(), make_map_array(k_CURLOPT_URL, String(get_request_uri()), k_CURLOPT_RETURNTRANSFER, true)); Variant res = HHVM_FN(curl_exec)(c.toResource()); VS(res, "OK"); return Count(true); }
void CmdMachine::UpdateIntercept(DebuggerClient &client, const std::string &host, int port) { CmdMachine cmd; cmd.m_body = "rpc"; cmd.m_rpcConfig = make_map_array (s_host, String(host), s_port, port ? port : RuntimeOption::DebuggerDefaultRpcPort, s_auth, String(RuntimeOption::DebuggerDefaultRpcAuth), s_timeout, RuntimeOption::DebuggerDefaultRpcTimeout); client.xend<CmdMachine>(&cmd); }
Array mockBacktrace() { auto bt = Array::Create(); bt.append( make_map_array( s_file, "filename", s_line, "42", s_function, "function_name", s_type, s_double_colon, s_class, "Class" ) ); return bt; }
// Creates an array to respond to the Xenon PHP extension; // builds the data into the format neeeded. Array XenonRequestLocalData::createResponse() { PackedArrayInit stacks(m_stackSnapshots.size()); for (ArrayIter it(m_stackSnapshots); it; ++it) { const auto& frame = it.second().toArray(); stacks.append(make_map_array( s_time, frame[s_time], s_stack, frame[s_stack].toArray(), s_phpStack, parsePhpStack(frame[s_stack].toArray()), s_isWait, frame[s_isWait] )); } return stacks.toArray(); }
void XenonRequestLocalData::log(Xenon::SampleType t, c_WaitableWaitHandle* wh) { TRACE(1, "XenonRequestLocalData::log\n"); time_t now = time(nullptr); auto bt = createBacktrace(BacktraceArgs() .skipTop(t == Xenon::EnterSample) .fromWaitHandle(wh) .withMetadata() .ignoreArgs()); m_stackSnapshots.append(make_map_array( s_time, now, s_stack, bt, s_isWait, (t == Xenon::IOWaitSample) )); }
Array createPhpEdge(HeapGraphContextPtr hgptr, int index) { auto ptr = hgptr->hg.ptrs[index]; auto cptr = hgptr->cptrs[index]; auto ptr_arr = make_map_array( s_index, Variant(index), s_kind, Variant(getEdgeKindName(ptr.kind)), s_from, Variant(ptr.from), s_to, Variant(ptr.to), s_seat, (ptr.seat == nullptr ? init_null() : Variant(ptr.seat)), s_name, Variant(cptr.edgename) ); return ptr_arr; }
Array createPhpNode(HeapGraphContextPtr hgptr , int index) { auto cnode = hgptr->cnodes[index]; auto node_arr = make_map_array( s_index, Variant(index), s_kind, Variant(header_names[int(cnode.kind)]), s_size, Variant(cnode.size) ); if (cnode.classname != nullptr) { node_arr.set(s_class, Variant(cnode.classname)); } return node_arr; }
Variant HHVM_FUNCTION(posix_times) { struct tms t; clock_t ticks = times(&t); if (ticks == -1) { return false; } return make_map_array( s_ticks, (int)ticks, /* clock ticks */ s_utime, (int)t.tms_utime, /* user time */ s_stime, (int)t.tms_stime, /* system time */ s_cutime, (int)t.tms_cutime, /* user time of children */ s_cstime, (int)t.tms_cstime /* system time of children */ ); }
Array createPhpEdge(HeapGraphContextPtr hgptr, int index) { auto ptr = hgptr->hg.ptrs[index]; auto cptr = hgptr->cptrs[index]; auto ptr_arr = make_map_array( s_index, Variant(index), s_kind, Variant(getEdgeKindName(ptr.ptr_kind)), s_from, Variant(ptr.from), s_to, Variant(ptr.to), s_seat, Variant(root_kind_names[(unsigned)ptr.root_kind]), s_name, Variant(cptr.edgename) ); return ptr_arr; }
Array HHVM_FUNCTION(proc_get_status, const Resource& process) { auto proc = cast<ChildProcess>(process); errno = 0; bool running = true, signaled = false, stopped = false; int exitcode = -1, termsig = 0, stopsig = 0; #ifdef _WIN32 DWORD wstatus; GetExitCodeProcess(proc->childHandle, &wstatus); running = wstatus == STILL_ACTIVE; exitcode = running ? -1 : wstatus; #else int wstatus; pid_t wait_pid = LightProcess::waitpid(proc->child, &wstatus, WNOHANG|WUNTRACED); if (wait_pid == proc->child) { if (WIFEXITED(wstatus)) { running = false; exitcode = WEXITSTATUS(wstatus); } if (WIFSIGNALED(wstatus)) { running = false; signaled = true; termsig = WTERMSIG(wstatus); } if (WIFSTOPPED(wstatus)) { stopped = true; stopsig = WSTOPSIG(wstatus); } } else if (wait_pid == -1) { running = false; } #endif return make_map_array( s_command, proc->command, s_pid, (int)proc->child, s_running, running, s_signaled, signaled, s_stopped, stopped, s_exitcode, exitcode, s_termsig, termsig, s_stopsig, stopsig ); }
Array HHVM_FUNCTION(apache_get_config) { int workers = 0, queued = 0, health_level = 0; if (HttpServer::Server) { workers = HttpServer::Server->getPageServer()->getActiveWorker(); queued = HttpServer::Server->getPageServer()->getQueuedJobs(); health_level = (int)(ApacheExtension::GetHealthLevel()); } return make_map_array( s_restart_time, HttpServer::StartTime, s_max_clients, RuntimeOption::ServerThreadCount, s_active_clients, workers, s_queued_requests, queued, s_health_level, health_level ); }
Array TimeStamp::CurrentTime() { struct timeval tp; gettimeofday(&tp, nullptr); timelib_time_offset *offset = timelib_get_time_zone_info(tp.tv_sec, TimeZone::Current()->getTZInfo()); auto const ret = make_map_array( s_sec, (int)tp.tv_sec, s_usec, (int)tp.tv_usec, s_minuteswest, (int)(-offset->offset / 60), s_dsttime, (int)offset->is_dst ); timelib_time_offset_dtor(offset); return ret; }