PHP_METHOD(MongoDB, drop) { zval *data; if (zend_parse_parameters_none() == FAILURE) { return; } MAKE_STD_ZVAL(data); array_init(data); add_assoc_long(data, "dropDatabase", 1); MONGO_CMD(return_value, getThis()); zval_ptr_dtor(&data); }
/* ****************************************************************************************************** Lists the UDF modules registered with the server. * * @param aerospike_obj_p The C client's aerospike object. * @param error_p The C client's as_error to be set to the encountered error. * @param array_of_modules_p An array of registered UDF modules * against the Aerospike DB to be populated by * this function. * @param language Optionally filters a subset of modules * matching the given type. * @options_p The optional parameters to the * Aerospike::listRegistered(). * * @return AEROSPIKE_OK if success. Otherwise AEROSPIKE_x. ****************************************************************************************************** */ extern as_status aerospike_list_registered_udf_modules(Aerospike_object* aerospike_obj_p, as_error* error_p, zval* array_of_modules_p, long language, zval* options_p) { as_udf_files udf_files; uint32_t init_udf_files = 0; uint32_t i = 0; as_policy_info info_policy; TSRMLS_FETCH_FROM_CTX(aerospike_obj_p->ts); set_policy(&aerospike_obj_p->as_ref_p->as_p->config, NULL, NULL, NULL, NULL, &info_policy, NULL, NULL, NULL, options_p, error_p TSRMLS_CC); if (AEROSPIKE_OK != (error_p->code)) { DEBUG_PHP_EXT_DEBUG("Unable to set policy"); goto exit; } as_udf_files_init(&udf_files, 0); init_udf_files = 1; if (AEROSPIKE_OK != aerospike_udf_list(aerospike_obj_p->as_ref_p->as_p, error_p, &info_policy, &udf_files)) { DEBUG_PHP_EXT_ERROR("%s", error_p->message); goto exit; } for (i = 0; i < udf_files.size; i++) { if ((language != -1) && (udf_files.entries[i].type != language)) { continue; } zval* module_p = NULL; MAKE_STD_ZVAL(module_p); array_init(module_p); add_assoc_stringl(module_p, UDF_MODULE_NAME, udf_files.entries[i].name, strlen(udf_files.entries[i].name), 1); add_assoc_long(module_p, UDF_MODULE_TYPE, (udf_files.entries[i].type)); add_next_index_zval(array_of_modules_p, module_p); } exit: if (init_udf_files) { as_udf_files_destroy(&udf_files); } return error_p->code; }
PHP_METHOD(Edge_Controller, result) { zval *data; char *msg; int mlen; long code; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|zs", &code, &data, &msg, &mlen) == FAILURE) { RETURN_FALSE; } Z_ADDREF_P(data); array_init(return_value); add_assoc_long(return_value, "code", code); add_assoc_string(return_value, "msg", msg, 1); add_assoc_zval(return_value, "data", data); }
PHP_METHOD(MongoDB, repair) { zend_bool cloned=0, original=0; zval *data; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &cloned, &original) == FAILURE) { return; } MAKE_STD_ZVAL(data); array_init(data); add_assoc_long(data, "repairDatabase", 1); add_assoc_bool(data, "preserveClonedFilesOnFailure", cloned); add_assoc_bool(data, "backupOriginalFiles", original); MONGO_CMD(return_value, getThis()); zval_ptr_dtor(&data); }
//返回array类型 static PHP_FUNCTION(return_array) { zval *sub; //zval *return_value ,此参数已经被定义在zif函数声明里了,要操作返回值时只需要操作此值函数会自动返回这个结果出去 array_init(return_value); // $ret = array(); add_next_index_bool(return_value, 1); // $ret[] = true; add_index_string(return_value, 5, "Hello", 1); // $ret[5] = "Hello"; add_assoc_long(return_value, "a", 42); //$ret["a"] = 42; add_assoc_string(return_value, "c", "d", 1); //$ret["c"] = "d"; //$sub = array() MAKE_STD_ZVAL(sub); array_init(sub); add_assoc_double(sub, "pi", 3.1415926535); //$sub["pi"] = 3.1415926535 add_next_index_zval(return_value, sub); //$ret[] = $sub; }
ZEND_METHOD(YConsistent,find_server){ char *key; char *return_key; int key_len; zval *object = getThis(); zval **conhash_prop; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s",&key,&key_len) == FAILURE){ return; } if(zend_hash_find(Z_OBJPROP_P(object),"conhash",sizeof("conhash"),(void **)&conhash_prop) == FAILURE){ RETURN_NULL(); } conhash *con = zend_list_find(Z_LVAL_PP(conhash_prop),&le_conhash); cnode *node = conhash_find_server(key,key_len,con); array_init(return_value); add_assoc_string(return_value,"host",node->server.host,1); add_assoc_long(return_value,"port",node->server.port); }
void beast_cache_info(zval *retval) { char key[128]; int i; cache_item_t *item; beast_locker_lock(beast_cache_locker); for (i = 0; i < BUCKETS_DEFAULT_SIZE; i++) { item = beast_cache_buckets[i]; while (item) { sprintf(key, "{device(%d)#inode(%d)}", item->key.device, item->key.inode); add_assoc_long(retval, key, item->key.fsize); item = item->next; } } beast_locker_unlock(beast_cache_locker); }
static void php_mongo_db_profiling_level(INTERNAL_FUNCTION_PARAMETERS, int get) { long level; zval *cmd, *cmd_return; zval **ok; mongo_db *db; if (get) { if (zend_parse_parameters_none() == FAILURE) { return; } level = -1; } else { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &level) == FAILURE) { return; } } PHP_MONGO_GET_DB(getThis()); MAKE_STD_ZVAL(cmd); array_init(cmd); add_assoc_long(cmd, "profile", level); cmd_return = php_mongo_runcommand(db->link, &db->read_pref, Z_STRVAL_P(db->name), Z_STRLEN_P(db->name), cmd, NULL, 0, NULL TSRMLS_CC); zval_ptr_dtor(&cmd); if (!cmd_return) { return; } if ( zend_hash_find(HASH_P(cmd_return), "ok", 3, (void**)&ok) == SUCCESS && ((Z_TYPE_PP(ok) == IS_BOOL && Z_BVAL_PP(ok)) || Z_DVAL_PP(ok) == 1) ) { zend_hash_find(HASH_P(cmd_return), "was", 4, (void**)&ok); RETVAL_ZVAL(*ok, 1, 0); } else { RETVAL_NULL(); } zval_ptr_dtor(&cmd_return); }
static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) { pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; PGresult *res; char *q=NULL; ExecStatusType status; if (!S->result) { return FAILURE; } if (colno >= stmt->column_count) { return FAILURE; } array_init(return_value); add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type); /* Fetch metadata from Postgres system catalogue */ spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%u", S->cols[colno].pgsql_type); res = PQexec(S->H->server, q); efree(q); status = PQresultStatus(res); if (status != PGRES_TUPLES_OK) { /* Failed to get system catalogue, but return success * with the data we have collected so far */ goto done; } /* We want exactly one row returned */ if (1 != PQntuples(res)) { goto done; } add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0)); done: PQclear(res); return 1; }
/* {{{ proto array parse_url(string url) Parse a URL and return its components */ void php3_parse_url(INTERNAL_FUNCTION_PARAMETERS) { pval *string; url *resource; TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &string) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(string); resource = url_parse(string->value.str.val); if (resource == NULL) { php3_error(E_WARNING, "unable to parse url (%s)", string->value.str.val); RETURN_FALSE; } /* allocate an array for return */ if (array_init(return_value) == FAILURE) { free_url(resource); RETURN_FALSE; } /* add the various elements to the array */ if (resource->scheme != NULL) add_assoc_string(return_value, "scheme", resource->scheme, 1); if (resource->host != NULL) add_assoc_string(return_value, "host", resource->host, 1); if (resource->port != 0) add_assoc_long(return_value, "port", resource->port); if (resource->user != NULL) add_assoc_string(return_value, "user", resource->user, 1); if (resource->pass != NULL) add_assoc_string(return_value, "pass", resource->pass, 1); if (resource->path != NULL) add_assoc_string(return_value, "path", resource->path, 1); if (resource->query != NULL) add_assoc_string(return_value, "query", resource->query, 1); if (resource->fragment != NULL) add_assoc_string(return_value, "fragment", resource->fragment, 1); free_url(resource); }
static void add_expr_to_array(zval *expressions, uri_template_expr *expr) { uri_template_var *next; zval *result; zval *vars; char op[2] = {expr->op, 0}; char sep[2] = {expr->sep, 0}; char ifemp[2] = {expr->ifemp, 0}; MAKE_STD_ZVAL(result); array_init(result); add_assoc_string(result, "op", op, 1); add_assoc_string(result, "sep", sep, 1); add_assoc_string(result, "ifemp", ifemp, 1); add_assoc_bool(result, "allow", expr->allow); add_assoc_bool(result, "named", expr->named); add_assoc_bool(result, "error", expr->error); MAKE_STD_ZVAL(vars); array_init_size(vars, expr->vars->count); next = expr->vars->first; while (next != NULL) { zval *var; MAKE_STD_ZVAL(var); array_init(var); add_assoc_string(var, "name", next->name, 1); add_assoc_long(var, "length", next->length); add_assoc_bool(var, "explode", next->explode); add_next_index_zval(vars, var); next = next->next; } add_assoc_zval(result, "vars", vars); add_next_index_zval(expressions, result); }
void CACHE_SESSION::serialize_php(zval *result, bool everything) { CACHE_BASE *cb; CACHE_COLL *cc; bool basereg; zval *zbaselist; array_init(result); add_assoc_long(result, (char *)"session_id", this->session_id); MAKE_STD_ZVAL(zbaselist); array_init(zbaselist); for(cb = this->firstbase; cb; cb = cb->nextbase) { basereg = everything; for(cc=cb->firstcoll; !basereg && cc; cc=cc->nextcoll) basereg = cc->registered; if(everything || (cb->online && basereg)) // on ne retourne pas les bases offline cb->serialize_php(zbaselist, everything); } add_assoc_zval(result, (char *)"bases", zbaselist); }
/* {{{ apc_cache_link_info */ static zval apc_cache_link_info(apc_cache_t *cache, apc_cache_slot_t* p) { zval link; array_init(&link); add_assoc_str(&link, "info", p->key.str); add_assoc_long(&link, "ttl", p->value->ttl); add_assoc_double(&link, "num_hits", (double)p->nhits); add_assoc_long(&link, "mtime", p->key.mtime); add_assoc_long(&link, "creation_time", p->ctime); add_assoc_long(&link, "deletion_time", p->dtime); add_assoc_long(&link, "access_time", p->atime); add_assoc_long(&link, "ref_count", p->value->ref_count); add_assoc_long(&link, "mem_size", p->value->mem_size); return link; }
void CACHE_SESSION::serialize_php(zval *result) //, bool everything) { CACHE_BASE *cb; // CACHE_COLL *cc; // bool basereg; zval *zbaselist; array_init(result); add_assoc_long(result, (char *)"session_id", this->session_id); MAKE_STD_ZVAL(zbaselist); array_init(zbaselist); for(cb = this->firstbase; cb; cb = cb->nextbase) { // basereg = everything; // for(cc=cb->firstcoll; !basereg && cc; cc=cc->nextcoll) // basereg = cc->registered; // // if(everything || (cb->online && basereg)) // don't return offline bases cb->serialize_php(zbaselist); // , everything); } add_assoc_zval(result, (char *)"bases", zbaselist); }
/* {{{ PHP METHODS */ PHP_METHOD(air_async_waiter, __construct) { AIR_INIT_THIS; zval *services; MAKE_STD_ZVAL(services); array_init(services); zend_update_property(air_async_waiter_ce, self, ZEND_STRL("_services"), services TSRMLS_CC); zval_ptr_dtor(&services); zval *responses; MAKE_STD_ZVAL(responses); array_init(responses); zend_update_property(air_async_waiter_ce, self, ZEND_STRL("_responses"), responses TSRMLS_CC); zval_ptr_dtor(&responses); zval *context; MAKE_STD_ZVAL(context); array_init(context); add_assoc_long(context, "step", 0); zend_update_property(air_async_waiter_ce, self, ZEND_STRL("_context"), context TSRMLS_CC); zval_ptr_dtor(&context); }
/* Takes a pointer to posix group and a pointer to an already initialized ZVAL * array container and fills the array with the posix group member data. */ int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */ { zval array_members; int count; if (NULL == g) return 0; if (array_group == NULL || Z_TYPE_P(array_group) != IS_ARRAY) return 0; array_init(&array_members); add_assoc_string(array_group, "name", g->gr_name); add_assoc_string(array_group, "passwd", g->gr_passwd); for (count=0; g->gr_mem[count] != NULL; count++) { add_next_index_string(&array_members, g->gr_mem[count]); } zend_hash_str_update(Z_ARRVAL_P(array_group), "members", sizeof("members")-1, &array_members); add_assoc_long(array_group, "gid", g->gr_gid); return 1; }
static int pdo_dblib_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) { pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data; pdo_dblib_db_handle *H = S->H; DBTYPEINFO* dbtypeinfo; int coltype; if(colno >= stmt->column_count || colno < 0) { return FAILURE; } array_init(return_value); dbtypeinfo = dbcoltypeinfo(H->link, colno+1); if(!dbtypeinfo) return FAILURE; coltype = dbcoltype(H->link, colno+1); add_assoc_long(return_value, "max_length", dbcollen(H->link, colno+1) ); add_assoc_long(return_value, "precision", (int) dbtypeinfo->precision ); add_assoc_long(return_value, "scale", (int) dbtypeinfo->scale ); add_assoc_string(return_value, "column_source", dbcolsource(H->link, colno+1)); add_assoc_string(return_value, "native_type", pdo_dblib_get_field_name(coltype)); add_assoc_long(return_value, "native_type_id", coltype); add_assoc_long(return_value, "native_usertype_id", dbcolutype(H->link, colno+1)); switch (coltype) { case SQLBIT: case SQLINT1: case SQLINT2: case SQLINT4: add_assoc_long(return_value, "pdo_type", PDO_PARAM_INT); break; default: add_assoc_long(return_value, "pdo_type", PDO_PARAM_STR); break; } return 1; }
PHP_METHOD(MongoDB, drop) { zval *cmd, *retval; mongo_db *db; if (zend_parse_parameters_none() == FAILURE) { return; } PHP_MONGO_GET_DB(getThis()); MAKE_STD_ZVAL(cmd); array_init(cmd); add_assoc_long(cmd, "dropDatabase", 1); retval = php_mongo_runcommand(db->link, &db->read_pref, Z_STRVAL_P(db->name), Z_STRLEN_P(db->name), cmd, NULL, 0, NULL TSRMLS_CC); zval_ptr_dtor(&cmd); if (retval) { RETURN_ZVAL(retval, 0, 1); } }
/* {{{ * Internal function which calls the udat_parseCalendar */ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse, int32_t text_len, int32_t *parse_pos, zval *return_value) { UCalendar *parsed_calendar = NULL; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; zend_long isInDST = 0; /* Convert timezone to UTF-16. */ intl_convert_utf8_to_utf16(&text_utf16, &text_utf16_len, text_to_parse, text_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); parsed_calendar = (UCalendar *)udat_getCalendar(DATE_FORMAT_OBJECT(dfo)); udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar, text_utf16, text_utf16_len, parse_pos, &INTL_DATA_ERROR_CODE(dfo)); if (text_utf16) { efree(text_utf16); } INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); array_init( return_value ); /* Add entries from various fields of the obtained parsed_calendar */ add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_SECOND, CALENDAR_SEC); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MINUTE, CALENDAR_MIN); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_HOUR_OF_DAY, CALENDAR_HOUR); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_YEAR, CALENDAR_YEAR); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_MONTH, CALENDAR_MDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_WEEK, CALENDAR_WDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_DAY_OF_YEAR, CALENDAR_YDAY); add_to_localtime_arr( dfo, return_value, parsed_calendar, UCAL_MONTH, CALENDAR_MON); /* Is in DST? */ isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." ); add_assoc_long( return_value, CALENDAR_ISDST,(isInDST==1?1:0)); }
long tw_span_create(char *category, size_t category_len TSRMLS_DC) { zval span, starts, stops, annotations; int idx; long parent = 0; if (TWG(spans) == NULL) { return -1; } idx = zend_hash_num_elements(Z_ARRVAL_P(TWG(spans))); // Hardcode a limit of 1500 spans for now, Daemon will re-filter again to 1000. // We assume web-requests and non-spammy worker/crons here, need a way to support // very long running scripts at some point. if (idx >= 1500) { return -1; } array_init(&span); array_init(&starts); array_init(&stops); array_init(&annotations); add_assoc_stringl(&span, "n", category, category_len); add_assoc_zval(&span, "b", &starts); add_assoc_zval(&span, "e", &stops); if (parent > 0) { add_assoc_long(&span, "p", parent); } zend_hash_index_update(Z_ARRVAL_P(TWG(spans)), idx, &span); return idx; }
static void _php_cal_info(int cal, zval *ret) { zval months, smonths; int i; struct cal_entry_t *calendar; calendar = &cal_conversion_table[cal]; array_init(ret); array_init(&months); array_init(&smonths); for (i = 1; i <= calendar->num_months; i++) { add_index_string(&months, i, calendar->month_name_long[i]); add_index_string(&smonths, i, calendar->month_name_short[i]); } add_assoc_zval(ret, "months", &months); add_assoc_zval(ret, "abbrevmonths", &smonths); add_assoc_long(ret, "maxdaysinmonth", calendar->max_days_in_month); add_assoc_string(ret, "calname", calendar->name); add_assoc_string(ret, "calsymbol", calendar->symbol); }
/* fetches information about the key provided */ PHP_APCU_API zval* apc_cache_stat(apc_cache_t* cache, zend_string *key, zval *stat) { apc_cache_slot_t** slot; zend_ulong h, s; /* calculate hash and slot */ apc_cache_hash_slot(cache, key, &h, &s); /* read lock header */ APC_RLOCK(cache->header); /* find head */ slot = &cache->slots[s]; while (*slot) { /* check for a matching key by has and identifier */ if ((h == ZSTR_HASH((*slot)->key.str)) && memcmp(ZSTR_VAL((*slot)->key.str), ZSTR_VAL(key), ZSTR_LEN(key)) == SUCCESS) { array_init(stat); add_assoc_long(stat, "hits", (*slot)->nhits); add_assoc_long(stat, "access_time", (*slot)->atime); add_assoc_long(stat, "mtime", (*slot)->key.mtime); add_assoc_long(stat, "creation_time", (*slot)->ctime); add_assoc_long(stat, "deletion_time", (*slot)->dtime); add_assoc_long(stat, "ttl", (*slot)->value->ttl); add_assoc_long(stat, "refs", (*slot)->value->ref_count); break; } /* next */ slot = &(*slot)->next; } APC_RUNLOCK(cache->header); return stat; }
/** * Populates key-details for an oks structure */ static void oks_to_zvarray(struct observe_keystate *oks, zval *arry) { add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_RESPONSES, oks->got.resp); add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_REPLICAS, oks->got.replicate); add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_PERSISTS, oks->got.persist); add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_TTR, oks->got.ttr); add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_TTP, oks->got.ttp); if (oks->got.errstr) { zval *zvtmp; ALLOC_INIT_ZVAL(zvtmp); ZVAL_STRING(zvtmp, oks->got.errstr, 0); add_assoc_zval(arry, COUCHBASE_OBSERVE_RESKEY_ERRSTR, zvtmp); oks->got.errstr = NULL; /* zend takes ownership */ } else { add_assoc_null(arry, COUCHBASE_OBSERVE_RESKEY_ERRSTR); } if (oks->got.errcode) { add_assoc_long(arry, COUCHBASE_OBSERVE_RESKEY_ERRNUM, oks->got.errcode); } }
/* {{{ proto array ImagickPixel::getColor([int normalization]) Returns the color of the pixel in an array normalization - 0 - values returned in the range 0,255 and will be ints, except for legacy reasons alpha which is 0-1 normalization - 1 - values returned in the range 0,1 and will be floats normalization - 2 - values returned in the range 0,255 and will be ints including alpha values i.e. float if ImageMagick was compiled with HDRI, or integers normally. */ PHP_METHOD(imagickpixel, getcolor) { php_imagickpixel_object *internp; im_long normalization = 0; double red, green, blue, alpha; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &normalization) == FAILURE) { return; } internp = Z_IMAGICKPIXEL_P(getThis()); array_init(return_value); red = PixelGetRed(internp->pixel_wand); green = PixelGetGreen(internp->pixel_wand); blue = PixelGetBlue(internp->pixel_wand); alpha = PixelGetAlpha(internp->pixel_wand); switch (normalization) { //values returned in the range 0,255 and will be ints case(0): { //Leave like this for legacy code //TODO fix the alpha not being normalised at next major/minor verysion red *= 255; green *= 255; blue *= 255; //values are always >=0, so the rounding below may not be necessary add_assoc_long(return_value, "r", (long) (red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (long) (blue > 0.0 ? blue + 0.5 : blue - 0.5)); add_assoc_long(return_value, "a", alpha); break; } //values returned in the range 0,1 and will be floats case(1): { add_assoc_double(return_value, "r", red); add_assoc_double(return_value, "g", green); add_assoc_double(return_value, "b", blue); add_assoc_double(return_value, "a", alpha); break; } case(2): { red *= 255; green *= 255; blue *= 255; alpha *= 255; //values are always >=0, so the rounding below may not be necessary add_assoc_long(return_value, "r", (long) (red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (long) (green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (long) (blue > 0.0 ? blue + 0.5 : blue - 0.5)); add_assoc_long(return_value, "a", (long) (alpha > 0.0 ? alpha + 0.5 : alpha - 0.5)); break; } } return; }
/* {{{ proto array accelerator_get_status([bool fetch_scripts]) Obtain statistics information regarding code acceleration */ static ZEND_FUNCTION(opcache_get_status) { long reqs; zval *memory_usage,*statistics,*scripts; zend_bool fetch_scripts = 1; /* keep the compiler happy */ (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &fetch_scripts) == FAILURE) { return; } if (!accel_startup_ok) { RETURN_FALSE; } array_init(return_value); /* Trivia */ add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled))); add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted)); add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending)); add_assoc_bool(return_value, "restart_in_progress", ZCSG(restart_in_progress)); /* Memory usage statistics */ MAKE_STD_ZVAL(memory_usage); array_init(memory_usage); add_assoc_long(memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory)); add_assoc_long(memory_usage, "free_memory", zend_shared_alloc_get_free_memory()); add_assoc_long(memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory)); add_assoc_double(memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0); add_assoc_zval(return_value, "memory_usage", memory_usage); /* Accelerator statistics */ MAKE_STD_ZVAL(statistics); array_init(statistics); add_assoc_long(statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries); add_assoc_long(statistics, "num_cached_keys", ZCSG(hash).num_entries); add_assoc_long(statistics, "max_cached_keys", ZCSG(hash).max_num_entries); add_assoc_long(statistics, "hits", ZCSG(hits)); add_assoc_long(statistics, "start_time", ZCSG(start_time)); add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time)); add_assoc_long(statistics, "oom_restarts", ZCSG(oom_restarts)); add_assoc_long(statistics, "hash_restarts", ZCSG(hash_restarts)); add_assoc_long(statistics, "manual_restarts", ZCSG(manual_restarts)); add_assoc_long(statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses)); add_assoc_long(statistics, "blacklist_misses", ZCSG(blacklist_misses)); reqs = ZCSG(hits)+ZCSG(misses); add_assoc_double(statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0); add_assoc_double(statistics, "opcache_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0); add_assoc_zval(return_value, "opcache_statistics", statistics); if (fetch_scripts) { /* accelerated scripts */ scripts = accelerator_get_scripts(TSRMLS_C); if (scripts) { add_assoc_zval(return_value, "scripts", scripts); } } }
static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value) { struct stat *stat_sb; int rmask=S_IROTH,wmask=S_IWOTH,xmask=S_IXOTH; /* access rights defaults to other */ BLS_FETCH(); stat_sb = &BG(sb); if (!BG(CurrentStatFile) || strcmp(filename, BG(CurrentStatFile))) { if (!BG(CurrentStatFile) || filename_length > BG(CurrentStatLength)) { if (BG(CurrentStatFile)) { efree(BG(CurrentStatFile)); } BG(CurrentStatLength) = filename_length; BG(CurrentStatFile) = estrndup(filename, filename_length); } else { memcpy(BG(CurrentStatFile), filename, filename_length+1); } #if HAVE_SYMLINK BG(lsb).st_mode = 0; /* mark lstat buf invalid */ #endif if (VCWD_STAT(BG(CurrentStatFile), &BG(sb)) == -1) { if (!IS_LINK_OPERATION() && (type != 15 || errno != ENOENT)) { /* fileexists() test must print no error */ php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); } efree(BG(CurrentStatFile)); BG(CurrentStatFile) = NULL; if (!IS_LINK_OPERATION()) { /* Don't require success for link operation */ RETURN_FALSE; } } } #if HAVE_SYMLINK if (IS_LINK_OPERATION() && !BG(lsb).st_mode) { /* do lstat if the buffer is empty */ if (VCWD_LSTAT(filename, &BG(lsb)) == -1) { php_error(E_NOTICE, "lstat failed for %s (errno=%d - %s)", filename, errno, strerror(errno)); RETURN_FALSE; } } #endif if (type >= 9 && type <= 11) { if(BG(sb).st_uid==getuid()) { rmask=S_IRUSR; wmask=S_IWUSR; xmask=S_IXUSR; } else if(BG(sb).st_gid==getgid()) { rmask=S_IRGRP; wmask=S_IWGRP; xmask=S_IXGRP; } else { int groups,n,i; gid_t *gids; groups = getgroups(0,NULL); if(groups) { gids=(gid_t *)emalloc(groups*sizeof(gid_t)); n=getgroups(groups,gids); for(i=0;i<n;i++){ if(BG(sb).st_gid==gids[i]) { rmask=S_IRGRP; wmask=S_IWGRP; xmask=S_IXGRP; break; } } efree(gids); } } } switch (type) { case 0: /* fileperms */ RETURN_LONG((long)BG(sb).st_mode); case 1: /* fileinode */ RETURN_LONG((long)BG(sb).st_ino); case 2: /* filesize */ RETURN_LONG((long)BG(sb).st_size); case 3: /* fileowner */ RETURN_LONG((long)BG(sb).st_uid); case 4: /* filegroup */ RETURN_LONG((long)BG(sb).st_gid); case 5: /* fileatime */ RETURN_LONG((long)BG(sb).st_atime); case 6: /* filemtime */ RETURN_LONG((long)BG(sb).st_mtime); case 7: /* filectime */ RETURN_LONG((long)BG(sb).st_ctime); case 8: /* filetype */ #if HAVE_SYMLINK if (S_ISLNK(BG(lsb).st_mode)) { RETURN_STRING("link",1); } #endif switch(BG(sb).st_mode&S_IFMT) { case S_IFIFO: RETURN_STRING("fifo",1); case S_IFCHR: RETURN_STRING("char",1); case S_IFDIR: RETURN_STRING("dir",1); case S_IFBLK: RETURN_STRING("block",1); case S_IFREG: RETURN_STRING("file",1); #if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__) case S_IFSOCK: RETURN_STRING("socket",1); #endif } php_error(E_WARNING,"Unknown file type (%d)",BG(sb).st_mode&S_IFMT); RETURN_STRING("unknown", 1); case 9: /*is writable*/ if (getuid()==0) { RETURN_LONG(1); /* root */ } RETURN_LONG((BG(sb).st_mode & wmask) != 0); case 10: /*is readable*/ if (getuid()==0) { RETURN_LONG(1); /* root */ } RETURN_LONG((BG(sb).st_mode&rmask)!=0); case 11: /*is executable*/ if (getuid()==0) { xmask = S_IXROOT; /* root */ } RETURN_LONG((BG(sb).st_mode&xmask)!=0 && !S_ISDIR(BG(sb).st_mode)); case 12: /*is file*/ RETURN_LONG(S_ISREG(BG(sb).st_mode)); case 13: /*is dir*/ RETURN_LONG(S_ISDIR(BG(sb).st_mode)); case 14: /*is link*/ #if HAVE_SYMLINK RETURN_LONG(S_ISLNK(BG(lsb).st_mode)); #else RETURN_FALSE; #endif case 15: /*file exists*/ RETURN_TRUE; /* the false case was done earlier */ case 16: /* lstat */ #if HAVE_SYMLINK stat_sb = &BG(lsb); #endif /* FALLTHROUGH */ case 17: /* stat */ if (array_init(return_value) == FAILURE) { RETURN_FALSE; } add_next_index_long(return_value, stat_sb->st_dev); add_next_index_long(return_value, stat_sb->st_ino); add_next_index_long(return_value, stat_sb->st_mode); add_next_index_long(return_value, stat_sb->st_nlink); add_next_index_long(return_value, stat_sb->st_uid); add_next_index_long(return_value, stat_sb->st_gid); #ifdef HAVE_ST_RDEV add_next_index_long(return_value, stat_sb->st_rdev); #else add_next_index_long(return_value, -1); #endif add_next_index_long(return_value, stat_sb->st_size); add_next_index_long(return_value, stat_sb->st_atime); add_next_index_long(return_value, stat_sb->st_mtime); add_next_index_long(return_value, stat_sb->st_ctime); #ifdef HAVE_ST_BLKSIZE add_next_index_long(return_value, stat_sb->st_blksize); #else add_next_index_long(return_value, -1); #endif #ifdef HAVE_ST_BLOCKS add_next_index_long(return_value, stat_sb->st_blocks); #else add_next_index_long(return_value, -1); #endif /* Support string references as well as numerical*/ add_assoc_long ( return_value , "dev" , stat_sb->st_dev ); add_assoc_long ( return_value , "ino" , stat_sb->st_ino ); add_assoc_long ( return_value , "mode" , stat_sb->st_mode ); add_assoc_long ( return_value , "nlink" , stat_sb->st_nlink ); add_assoc_long ( return_value , "uid" , stat_sb->st_uid ); add_assoc_long ( return_value , "gid" , stat_sb->st_gid ); #ifdef HAVE_ST_RDEV add_assoc_long ( return_value, "rdev" , stat_sb->st_rdev ); #endif #ifdef HAVE_ST_BLKSIZE add_assoc_long ( return_value , "blksize" , stat_sb->st_blksize ); #endif add_assoc_long ( return_value , "size" , stat_sb->st_size ); add_assoc_long ( return_value , "atime" , stat_sb->st_atime ); add_assoc_long ( return_value , "mtime" , stat_sb->st_mtime ); add_assoc_long ( return_value , "ctime" , stat_sb->st_ctime ); #ifdef HAVE_ST_BLOCKS add_assoc_long ( return_value , "blocks" , stat_sb->st_blocks ); #endif return; } php_error(E_WARNING, "didn't understand stat call"); RETURN_FALSE; }
PHP_METHOD(jsonrpc_server, execute) { zval *object; zval *func; zval **func_params, **exec_params; zval *data, *payload, *error, *response; zval **payload_method, **payload_params; zval **id = NULL; sapi_header_line ctr = {0}; smart_str buf = {0}; zend_bool response_type = 0; // type:0 =>json type:1 => array object = getThis(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &response_type) == FAILURE) { return ; } payload = zend_read_property( php_jsonrpc_server_entry, getThis(), "payload", sizeof("payload")-1, 0 TSRMLS_CC ); MAKE_STD_ZVAL(error); array_init(error); MAKE_STD_ZVAL(func); ZVAL_STRINGL(func, "jsonformat", sizeof("jsonformat") - 1, 0); if (call_user_function(NULL, &object, func, return_value, 0, NULL TSRMLS_CC) == FAILURE){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::jsonformat()"); return ; } if (!Z_BVAL_P(return_value)){ add_assoc_long(error, "code", -32700); add_assoc_string(error, "message", "Parse error", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; } ZVAL_STRINGL(func, "rpcformat", sizeof("rpcformat") - 1, 0); if (call_user_function(NULL, &object, func, return_value, 0, NULL TSRMLS_CC) == FAILURE){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::rpcformat()"); return ; } if (Z_LVAL_P(return_value) == -32600){ add_assoc_long(error, "code", -32600); add_assoc_string(error, "message", "Invalid Request", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; }else if (Z_LVAL_P(return_value) == -32601){ add_assoc_long(error, "code", -32601); add_assoc_string(error, "message", "Method not found", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; }else if (Z_LVAL_P(return_value) == -32602){ add_assoc_long(error, "code", -32602); add_assoc_string(error, "message", "Invalid params", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; }else if (Z_LVAL_P(return_value) == -32603){ add_assoc_long(error, "code", -32603); add_assoc_string(error, "message", "Internal error", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; } exec_params = emalloc(sizeof(zval *) * 2); payload = zend_read_property( php_jsonrpc_server_entry, getThis(), "payload", sizeof("payload")-1, 0 TSRMLS_CC ); if (zend_hash_find(Z_ARRVAL_P(payload), "method", strlen("method")+1, (void **)&payload_method) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "method is not find"); return ; } //jsr_dump_zval(*payload_method); exec_params[0] = *payload_method; if (zend_hash_find(Z_ARRVAL_P(payload), "params", strlen("params")+1, (void **)&payload_params) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "params is not find"); return ; } //shurrik_dump_zval(*payload_params); exec_params[1] = *payload_params; MAKE_STD_ZVAL(data); ZVAL_STRINGL(func, "executeprocedure", sizeof("executeprocedure") - 1, 0); if (call_user_function(NULL, &object, func, data, 2, exec_params TSRMLS_CC) == FAILURE){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Server::executeprocedure()"); return ; } efree(exec_params); if (Z_LVAL_P(data) == -32601){ add_assoc_long(error, "code", -32601); add_assoc_string(error, "message", "Method not found", 1); zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "error", error); goto getresponse; } zval_dtor(return_value); array_init(return_value); add_assoc_string(return_value, "jsonrpc", "2.0", 1); add_assoc_zval(return_value, "result", data); goto getresponse; return ; getresponse: if (Z_TYPE_P(payload) == IS_ARRAY){ if (!zend_symtable_exists(Z_ARRVAL_P(payload), "id", strlen("id")+1)) { }else { if (zend_hash_find(Z_ARRVAL_P(payload), "id", strlen("id")+1, (void **)&id ) == FAILURE) { //php_error_docref(NULL TSRMLS_CC, E_WARNING, "closeure is not expected to be a valid callback"); //return ; } if (Z_TYPE_PP(id) == IS_NULL){ add_assoc_null(return_value, "id"); }else if(Z_TYPE_PP(id) == IS_STRING){ convert_to_string(*id); add_assoc_string(return_value, "id", Z_STRVAL_PP(id), 0); }else if (Z_TYPE_PP(id) == IS_LONG){ convert_to_long(*id); add_assoc_long(return_value, "id", Z_LVAL_PP(id)); } } }else { add_assoc_null(return_value, "id"); } ctr.line = "Content-Type: application/json"; ctr.line_len = strlen(ctr.line); sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); /*if (!response_type){ php_json_encode(&buf, return_value, 0 TSRMLS_CC); zval_dtor(return_value); zval_dtor(error); ZVAL_STRINGL(return_value, buf.c, buf.len, 1); smart_str_free(&buf); }*/ if (!response_type){ exec_params = emalloc(sizeof(zval *) * 1); exec_params[0] = return_value; ZVAL_STRINGL(func, "Jsonrpc_Yajl::generate", sizeof("Jsonrpc_Yajl::generate") - 1, 0); if (call_user_function(EG(function_table), NULL, func, return_value, 1, exec_params TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed calling Jsonrpc_Yajl::generate()"); return ; } //ZVAL_STRINGL(return_value, Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), 1); zval_dtor(error); efree(exec_params); } efree(func); return ; }
/* {{{ proto array accelerator_get_configuration() Obtain configuration information */ static ZEND_FUNCTION(opcache_get_configuration) { zval directives, version, blacklist; if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } if (!validate_api_restriction()) { RETURN_FALSE; } array_init(return_value); /* directives */ array_init(&directives); add_assoc_bool(&directives, "opcache.enable", ZCG(enabled)); add_assoc_bool(&directives, "opcache.enable_cli", ZCG(accel_directives).enable_cli); add_assoc_bool(&directives, "opcache.use_cwd", ZCG(accel_directives).use_cwd); add_assoc_bool(&directives, "opcache.validate_timestamps", ZCG(accel_directives).validate_timestamps); add_assoc_bool(&directives, "opcache.validate_permission", ZCG(accel_directives).validate_permission); #ifndef ZEND_WIN32 add_assoc_bool(&directives, "opcache.validate_root", ZCG(accel_directives).validate_root); #endif add_assoc_bool(&directives, "opcache.inherited_hack", ZCG(accel_directives).inherited_hack); add_assoc_bool(&directives, "opcache.dups_fix", ZCG(accel_directives).ignore_dups); add_assoc_bool(&directives, "opcache.revalidate_path", ZCG(accel_directives).revalidate_path); add_assoc_long(&directives, "opcache.log_verbosity_level", ZCG(accel_directives).log_verbosity_level); add_assoc_long(&directives, "opcache.memory_consumption", ZCG(accel_directives).memory_consumption); add_assoc_long(&directives, "opcache.interned_strings_buffer",ZCG(accel_directives).interned_strings_buffer); add_assoc_long(&directives, "opcache.max_accelerated_files", ZCG(accel_directives).max_accelerated_files); add_assoc_double(&directives, "opcache.max_wasted_percentage", ZCG(accel_directives).max_wasted_percentage); add_assoc_long(&directives, "opcache.consistency_checks", ZCG(accel_directives).consistency_checks); add_assoc_long(&directives, "opcache.force_restart_timeout", ZCG(accel_directives).force_restart_timeout); add_assoc_long(&directives, "opcache.revalidate_freq", ZCG(accel_directives).revalidate_freq); add_assoc_string(&directives, "opcache.preferred_memory_model", STRING_NOT_NULL(ZCG(accel_directives).memory_model)); add_assoc_string(&directives, "opcache.blacklist_filename", STRING_NOT_NULL(ZCG(accel_directives).user_blacklist_filename)); add_assoc_long(&directives, "opcache.max_file_size", ZCG(accel_directives).max_file_size); add_assoc_string(&directives, "opcache.error_log", STRING_NOT_NULL(ZCG(accel_directives).error_log)); add_assoc_bool(&directives, "opcache.protect_memory", ZCG(accel_directives).protect_memory); add_assoc_bool(&directives, "opcache.save_comments", ZCG(accel_directives).save_comments); add_assoc_bool(&directives, "opcache.fast_shutdown", ZCG(accel_directives).fast_shutdown); add_assoc_bool(&directives, "opcache.enable_file_override", ZCG(accel_directives).file_override_enabled); add_assoc_long(&directives, "opcache.optimization_level", ZCG(accel_directives).optimization_level); #ifndef ZEND_WIN32 add_assoc_string(&directives, "opcache.lockfile_path", STRING_NOT_NULL(ZCG(accel_directives).lockfile_path)); #endif #ifdef HAVE_OPCACHE_FILE_CACHE add_assoc_string(&directives, "opcache.file_cache", ZCG(accel_directives).file_cache ? ZCG(accel_directives).file_cache : ""); add_assoc_bool(&directives, "opcache.file_cache_only", ZCG(accel_directives).file_cache_only); add_assoc_bool(&directives, "opcache.file_cache_consistency_checks", ZCG(accel_directives).file_cache_consistency_checks); #endif add_assoc_zval(return_value, "directives", &directives); /*version */ array_init(&version); add_assoc_string(&version, "version", PHP_VERSION); add_assoc_string(&version, "opcache_product_name", ACCELERATOR_PRODUCT_NAME); add_assoc_zval(return_value, "version", &version); /* blacklist */ array_init(&blacklist); zend_accel_blacklist_apply(&accel_blacklist, add_blacklist_path, &blacklist); add_assoc_zval(return_value, "blacklist", &blacklist); }
/* {{{ proto array accelerator_get_status([bool fetch_scripts]) Obtain statistics information regarding code acceleration */ static ZEND_FUNCTION(opcache_get_status) { zend_long reqs; zval memory_usage, statistics, scripts; zend_bool fetch_scripts = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &fetch_scripts) == FAILURE) { return; } if (!validate_api_restriction()) { RETURN_FALSE; } if (!accel_startup_ok) { RETURN_FALSE; } array_init(return_value); /* Trivia */ add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled))); #ifdef HAVE_OPCACHE_FILE_CACHE if (ZCG(accel_directives).file_cache) { add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache); } if (ZCG(accel_directives).file_cache_only) { add_assoc_bool(return_value, "file_cache_only", 1); return; } #endif add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted)); add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending)); add_assoc_bool(return_value, "restart_in_progress", ZCSG(restart_in_progress)); /* Memory usage statistics */ array_init(&memory_usage); add_assoc_long(&memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory)); add_assoc_long(&memory_usage, "free_memory", zend_shared_alloc_get_free_memory()); add_assoc_long(&memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory)); add_assoc_double(&memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0); add_assoc_zval(return_value, "memory_usage", &memory_usage); if (ZCSG(interned_strings_start) && ZCSG(interned_strings_end) && ZCSG(interned_strings_top)) { zval interned_strings_usage; array_init(&interned_strings_usage); add_assoc_long(&interned_strings_usage, "buffer_size", ZCSG(interned_strings_end) - ZCSG(interned_strings_start)); add_assoc_long(&interned_strings_usage, "used_memory", ZCSG(interned_strings_top) - ZCSG(interned_strings_start)); add_assoc_long(&interned_strings_usage, "free_memory", ZCSG(interned_strings_end) - ZCSG(interned_strings_top)); add_assoc_long(&interned_strings_usage, "number_of_strings", ZCSG(interned_strings).nNumOfElements); add_assoc_zval(return_value, "interned_strings_usage", &interned_strings_usage); } /* Accelerator statistics */ array_init(&statistics); add_assoc_long(&statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries); add_assoc_long(&statistics, "num_cached_keys", ZCSG(hash).num_entries); add_assoc_long(&statistics, "max_cached_keys", ZCSG(hash).max_num_entries); add_assoc_long(&statistics, "hits", (zend_long)ZCSG(hits)); add_assoc_long(&statistics, "start_time", ZCSG(start_time)); add_assoc_long(&statistics, "last_restart_time", ZCSG(last_restart_time)); add_assoc_long(&statistics, "oom_restarts", ZCSG(oom_restarts)); add_assoc_long(&statistics, "hash_restarts", ZCSG(hash_restarts)); add_assoc_long(&statistics, "manual_restarts", ZCSG(manual_restarts)); add_assoc_long(&statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses)); add_assoc_long(&statistics, "blacklist_misses", ZCSG(blacklist_misses)); reqs = ZCSG(hits)+ZCSG(misses); add_assoc_double(&statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0); add_assoc_double(&statistics, "opcache_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0); add_assoc_zval(return_value, "opcache_statistics", &statistics); if (fetch_scripts) { /* accelerated scripts */ if (accelerator_get_scripts(&scripts)) { add_assoc_zval(return_value, "scripts", &scripts); } } }
/* {{{ php_parserr */ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int raw, zval *subarray) { int type; u_long ttl; type = pRec->wType; ttl = pRec->dwTtl; if (type_to_fetch != DNS_TYPE_ANY && type != type_to_fetch) { return; } if (!store) { return; } array_init(subarray); add_assoc_string(subarray, "host", pRec->pName); add_assoc_string(subarray, "class", "IN"); add_assoc_long(subarray, "ttl", ttl); if (raw) { add_assoc_long(subarray, "type", type); add_assoc_stringl(subarray, "data", (char*) &pRec->Data, (uint) pRec->wDataLength); return; } switch (type) { case DNS_TYPE_A: { IN_ADDR ipaddr; ipaddr.S_un.S_addr = (pRec->Data.A.IpAddress); add_assoc_string(subarray, "type", "A"); add_assoc_string(subarray, "ip", inet_ntoa(ipaddr)); break; } case DNS_TYPE_MX: add_assoc_string(subarray, "type", "MX"); add_assoc_long(subarray, "pri", pRec->Data.Srv.wPriority); /* no break; */ case DNS_TYPE_CNAME: if (type == DNS_TYPE_CNAME) { add_assoc_string(subarray, "type", "CNAME"); } /* no break; */ case DNS_TYPE_NS: if (type == DNS_TYPE_NS) { add_assoc_string(subarray, "type", "NS"); } /* no break; */ case DNS_TYPE_PTR: if (type == DNS_TYPE_PTR) { add_assoc_string(subarray, "type", "PTR"); } add_assoc_string(subarray, "target", pRec->Data.MX.pNameExchange); break; /* Not available on windows, the query is possible but there is no DNS_HINFO_DATA structure */ case DNS_TYPE_HINFO: case DNS_TYPE_TEXT: { DWORD i = 0; DNS_TXT_DATA *data_txt = &pRec->Data.TXT; DWORD count = data_txt->dwStringCount; zend_string *txt; char *txt_dst; long txt_len = 0; zval entries; add_assoc_string(subarray, "type", "TXT"); array_init(&entries); for (i = 0; i < count; i++) { txt_len += strlen(data_txt->pStringArray[i]) + 1; } txt = zend_string_safe_alloc(txt_len, 2, 0, 0); txt_dst = txt->val; for (i = 0; i < count; i++) { int len = strlen(data_txt->pStringArray[i]); memcpy(txt_dst, data_txt->pStringArray[i], len); add_next_index_stringl(&entries, data_txt->pStringArray[i], len); txt_dst += len; } txt->len = txt_dst - txt->val; add_assoc_str(subarray, "txt", txt); add_assoc_zval(subarray, "entries", &entries); } break; case DNS_TYPE_SOA: { DNS_SOA_DATA *data_soa = &pRec->Data.Soa; add_assoc_string(subarray, "type", "SOA"); add_assoc_string(subarray, "mname", data_soa->pNamePrimaryServer); add_assoc_string(subarray, "rname", data_soa->pNameAdministrator); add_assoc_long(subarray, "serial", data_soa->dwSerialNo); add_assoc_long(subarray, "refresh", data_soa->dwRefresh); add_assoc_long(subarray, "retry", data_soa->dwRetry); add_assoc_long(subarray, "expire", data_soa->dwExpire); add_assoc_long(subarray, "minimum-ttl", data_soa->dwDefaultTtl); } break; case DNS_TYPE_AAAA: { DNS_AAAA_DATA *data_aaaa = &pRec->Data.AAAA; char buf[sizeof("AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA")]; char *tp = buf; int i; unsigned short out[8]; int have_v6_break = 0, in_v6_break = 0; for (i = 0; i < 4; ++i) { DWORD chunk = data_aaaa->Ip6Address.IP6Dword[i]; out[i * 2] = htons(LOWORD(chunk)); out[i * 2 + 1] = htons(HIWORD(chunk)); } for(i=0; i < 8; i++) { if (out[i] != 0) { if (tp > (u_char *)buf) { in_v6_break = 0; tp[0] = ':'; tp++; } tp += sprintf((char*)tp,"%x", out[i]); } else { if (!have_v6_break) { have_v6_break = 1; in_v6_break = 1; tp[0] = ':'; tp++; } else if (!in_v6_break) { tp[0] = ':'; tp++; tp[0] = '0'; tp++; } } } if (have_v6_break && in_v6_break) { tp[0] = ':'; tp++; } tp[0] = '\0'; add_assoc_string(subarray, "type", "AAAA"); add_assoc_string(subarray, "ipv6", buf); } break; #if 0 /* Won't be implemented. A6 is deprecated. (Pierre) */ case DNS_TYPE_A6: break; #endif case DNS_TYPE_SRV: { DNS_SRV_DATA *data_srv = &pRec->Data.Srv; add_assoc_string(subarray, "type", "SRV"); add_assoc_long(subarray, "pri", data_srv->wPriority); add_assoc_long(subarray, "weight", data_srv->wWeight); add_assoc_long(subarray, "port", data_srv->wPort); add_assoc_string(subarray, "target", data_srv->pNameTarget); } break; #if _MSC_VER >= 1500 case DNS_TYPE_NAPTR: { DNS_NAPTR_DATA * data_naptr = &pRec->Data.Naptr; add_assoc_string(subarray, "type", "NAPTR"); add_assoc_long(subarray, "order", data_naptr->wOrder); add_assoc_long(subarray, "pref", data_naptr->wPreference); add_assoc_string(subarray, "flags", data_naptr->pFlags); add_assoc_string(subarray, "services", data_naptr->pService); add_assoc_string(subarray, "regex", data_naptr->pRegularExpression); add_assoc_string(subarray, "replacement", data_naptr->pReplacement); } break; #endif default: /* unknown type */ ZVAL_UNDEF(subarray); return; } }