예제 #1
0
PHP_METHOD(MIME, load) {
	zval *array, *arg, retval;

	/* Fetch allowHEAD */
	MAKE_STD_ZVAL(array);
	array_init_size(array, 2);
	add_next_index_stringl(array, "Pancake\\Config", sizeof("Pancake\\Config") - 1, 1);
	add_next_index_stringl(array, "get", 3, 1);

	MAKE_STD_ZVAL(arg);
	Z_TYPE_P(arg) = IS_STRING;
	Z_STRLEN_P(arg) = 4;
	Z_STRVAL_P(arg) = estrndup("mime", 4);

	call_user_function(CG(function_table), NULL, array, &retval, 1, &arg TSRMLS_CC);

	if(Z_TYPE(retval) != IS_ARRAY) {
		zend_error(E_ERROR, "Bad MIME type array - Please check Pancake MIME type configuration");
	}

	ALLOC_HASHTABLE(PANCAKE_GLOBALS(mimeTable));
	zend_hash_init(PANCAKE_GLOBALS(mimeTable), 0, NULL, ZVAL_PTR_DTOR, 0);

	zval **data, **ext;
	char *key;

	for(zend_hash_internal_pointer_reset(Z_ARRVAL(retval));
		zend_hash_get_current_data(Z_ARRVAL(retval), (void**) &data) == SUCCESS &&
		zend_hash_get_current_key(Z_ARRVAL(retval), &key, NULL, 0) == HASH_KEY_IS_STRING;
		zend_hash_move_forward(Z_ARRVAL(retval))) {

		for(zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
			zend_hash_get_current_data(Z_ARRVAL_PP(data), (void**) &ext) == SUCCESS;
			zend_hash_move_forward(Z_ARRVAL_PP(data))) {

			zval *zkey;
			MAKE_STD_ZVAL(zkey);
			Z_TYPE_P(zkey) = IS_STRING;
			Z_STRLEN_P(zkey) = strlen(key);
			Z_STRVAL_P(zkey) = estrndup(key, Z_STRLEN_P(zkey));

			zend_hash_add(PANCAKE_GLOBALS(mimeTable), Z_STRVAL_PP(ext), Z_STRLEN_PP(ext), (void*) &zkey, sizeof(zval*), NULL);
		}
	}

	MAKE_STD_ZVAL(PANCAKE_GLOBALS(defaultMimeType));
	Z_TYPE_P(PANCAKE_GLOBALS(defaultMimeType)) = IS_STRING;
	Z_STRLEN_P(PANCAKE_GLOBALS(defaultMimeType)) = sizeof("application/octet-stream") - 1;
	Z_STRVAL_P(PANCAKE_GLOBALS(defaultMimeType)) = estrndup("application/octet-stream", sizeof("application/octet-stream") - 1);

	free:
	zval_dtor(&retval);
	zval_ptr_dtor(&array);
	zval_ptr_dtor(&arg);
}
예제 #2
0
/**
 * Rewinds resultset to its beginning
 *
 */
PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){

	zval *type, *z_zero, *rows;

	z_zero = &PHALCON_GLOBAL(z_zero);

	type = phalcon_read_property(getThis(), SL("_type"), PH_NOISY);
	if (zend_is_true(type)) {

		/** 
		 * Here, the resultset act as a result that is fetched one by one
		 */
		zval *result = phalcon_read_property(getThis(), SL("_result"), PH_NOISY);
		if (PHALCON_IS_NOT_FALSE(result)) {

			zval *active_row = phalcon_read_property(getThis(), SL("_activeRow"), PH_NOISY);
			if (Z_TYPE_P(active_row) != IS_NULL) {
				PHALCON_MM_GROW();
				PHALCON_CALL_METHOD(NULL, result, "dataseek", z_zero);
				PHALCON_MM_RESTORE();
			}
		}
	} else {
		/** 
		 * Here, the resultset act as an array
		 */
		rows = phalcon_read_property(getThis(), SL("_rows"), PH_NOISY);
		if (Z_TYPE_P(rows) == IS_NULL) {

			zval *result = phalcon_read_property(getThis(), SL("_result"), PH_NOISY);
			if (Z_TYPE_P(result) == IS_OBJECT) {
				zval *r = NULL;
				PHALCON_CALL_METHODW(&r, result, "fetchall");
				if (likely(Z_TYPE_P(r) == IS_ARRAY)) {
					zend_hash_internal_pointer_reset(Z_ARRVAL_P(r));
				}

				phalcon_update_property_this(getThis(), SL("_rows"), r);
				zval_ptr_dtor(r);
			}
		}
		else if (Z_TYPE_P(rows) == IS_ARRAY) {
			zend_hash_internal_pointer_reset(Z_ARRVAL_P(rows));
		}
	}

	phalcon_update_property_this(getThis(), SL("_pointer"), z_zero);
}
예제 #3
0
파일: pip_convert.c 프로젝트: demos/Motif
/* {{{ pip_hash_to_list(zval **hash)
   Convert a PHP hash to a Python list */
PyObject *
pip_hash_to_list(zval **hash)
{
	PyObject *list, *item;
	zval **entry;
	long pos = 0;

	/* Make sure we were given a PHP hash */
	if (Z_TYPE_PP(hash) != IS_ARRAY) {
		return NULL;
	}

	/* Create a list with the same number of elements as the hash */
	list = PyList_New(zend_hash_num_elements(Z_ARRVAL_PP(hash)));

	/* Let's start at the very beginning, a very good place to start. */
	zend_hash_internal_pointer_reset(Z_ARRVAL_PP(hash));

	/* Iterate over the hash's elements */
	while (zend_hash_get_current_data(Z_ARRVAL_PP(hash),
									  (void **)&entry) == SUCCESS) {

		/* Convert the PHP value to its Python equivalent */
		item = pip_zval_to_pyobject(entry);

		/* Add this item to the list and increment the position */
		PyList_SetItem(list, pos++, item);

		/* Advance to the next entry */
		zend_hash_move_forward(Z_ARRVAL_PP(hash));
	}

	return list;
}
예제 #4
0
/**
 * @brief void Phalcon\Registry::rewind()
 */
PHP_METHOD(Phalcon_Registry, rewind){

	zval data = {};

	phalcon_read_property(&data, getThis(), SL("_data"), PH_NOISY);
	zend_hash_internal_pointer_reset(Z_ARRVAL(data));
}
예제 #5
0
파일: air_router.c 프로젝트: jaykizhou/air
zval* air_arr_del_index_el(zval *arr) {
	HashTable *ht = Z_ARRVAL_P(arr);
	zval *tmp;
	MAKE_STD_ZVAL(tmp);
	array_init(tmp);
	for(
		zend_hash_internal_pointer_reset(ht);
		zend_hash_has_more_elements(ht) == SUCCESS;
		zend_hash_move_forward(ht)
	){
		int type;
		ulong idx;
		char *key;
		uint key_len;
		zval **tmp_data;

		type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL);
		if(type == HASH_KEY_IS_STRING){
			if(zend_hash_get_current_data(ht, (void**)&tmp_data) != FAILURE) {
				add_assoc_stringl_ex(tmp, key, key_len, Z_STRVAL_PP(tmp_data), Z_STRLEN_PP(tmp_data), 1);
			}
		}
	}
	return tmp;
}
예제 #6
0
/* {{{ static zval* array_to_hash */
static zval *array_to_hash(zval *array)
{
	zval *hash, **entry;
	char *name_lc;

	/*
	 * Well, this just transposes the array, popularly known as flipping it, or
	 * giving it the finger.
	 */
	MAKE_STD_ZVAL(hash);
	array_init(hash);
	for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array));
		 zend_hash_get_current_data(Z_ARRVAL_P(array), (void**)&entry) == SUCCESS;
		 zend_hash_move_forward(Z_ARRVAL_P(array))) {
		if (Z_TYPE_PP(entry) == IS_STRING) {
			/*
			 * I hate case-insensitivity. Die, die, die.
			 */
			name_lc = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
			zend_str_tolower(name_lc, Z_STRLEN_PP(entry));
			add_assoc_bool_ex(hash, name_lc, Z_STRLEN_PP(entry)+1, 1);
			efree(name_lc);
		}
	}

	return hash;
}
/** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC)
 *	判断名称是否是已经注册了的module的名称
*/
int yaf_application_is_module_name(char *name, int len TSRMLS_DC) {
	zval 				*modules, **ppzval;
	HashTable 			*ht;
	yaf_application_t 	*app;
	/* 获取类的实例,$app = self::$_app */
	app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC);
	if (!app || Z_TYPE_P(app) != IS_OBJECT) {
		return 0;
	}
	/* $modules = $this->_modules */
	modules = zend_read_property(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_MODULES), 1 TSRMLS_CC);
	if (!modules || Z_TYPE_P(modules) != IS_ARRAY) {
		return 0;
	}
	/* 检测name是否在$this->_modules数组中,在就返回1,不在返回0 */
	ht = Z_ARRVAL_P(modules);
	zend_hash_internal_pointer_reset(ht);
	while (zend_hash_get_current_data(ht, (void **)&ppzval) == SUCCESS) {
		if (Z_TYPE_PP(ppzval) == IS_STRING && Z_STRLEN_PP(ppzval) == len
				&& strncasecmp(Z_STRVAL_PP(ppzval), name, len) == 0) {
			return 1;
		}
		zend_hash_move_forward(ht);
	}
	return 0;
}
예제 #8
0
/** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC)
*/
int yaf_application_is_module_name(char *name, int len TSRMLS_DC) {
	zval 			*modules, **ppzval;
	HashTable 		*ht;
	yaf_application_t 	*app;

	app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC);
	if (Z_TYPE_P(app) != IS_OBJECT) {
		return 0;
	}

	modules = zend_read_property(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_MODULES), 1 TSRMLS_CC);
	if (Z_TYPE_P(modules) != IS_ARRAY) {
		return 0;
	}

	ht = Z_ARRVAL_P(modules);
	zend_hash_internal_pointer_reset(ht);
	while (zend_hash_get_current_data(ht, (void **)&ppzval) == SUCCESS) {
		if (Z_STRLEN_PP(ppzval) == len && strncasecmp(Z_STRVAL_PP(ppzval), name, len) == 0) {
			return 1;
		}
		zend_hash_move_forward(ht);
	}
	return 0;
}
예제 #9
0
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
{
	php_conf_rec *d = base_conf, *e = new_conf, *n = NULL;
	php_dir_entry *pe;
	php_dir_entry *data;
	char *str;
	uint str_len;
	ulong num_index;

	n = create_php_config(p, "merge_php_config");
	zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry));

	phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n));
	for (zend_hash_internal_pointer_reset(&d->config);
			zend_hash_get_current_key_ex(&d->config, &str, &str_len, 
				&num_index, 0, NULL) == HASH_KEY_IS_STRING;
			zend_hash_move_forward(&d->config)) {
		pe = NULL;
		zend_hash_get_current_data(&d->config, (void **) &data);
		if (zend_hash_find(&n->config, str, str_len, (void **) &pe) == SUCCESS) {
			if (pe->status >= data->status) continue;
		}
		zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL);
		phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
	}

	return n;
}
zval * activerecord_extract_validate_options( zval * arr )
{
    zval * retval;

    MAKE_STD_ZVAL( retval );
    array_init( retval );

    if( Z_TYPE_P(arr) == IS_ARRAY && zend_hash_num_elements( Z_ARRVAL_P(arr) ) > 0 )
    {
        zval **last;
        char *key;
        int key_len, j;

        zend_hash_internal_pointer_end(Z_ARRVAL_P(arr));
        zend_hash_get_current_data(Z_ARRVAL_P(arr), (void **)&last);

        if( activerecord_is_options_hash(last, 0) )
        {
            retval = last;
            zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &key, &key_len, &j, 0, NULL);
            zend_hash_del_key_or_index(Z_ARRVAL_P(arr), key, key_len, j, (key) ? HASH_DEL_KEY : HASH_DEL_INDEX);
            if( !key_len && j >= Z_ARRVAL_P(arr)->nNextFreeElement - 1 )
                Z_ARRVAL_P(arr)->nNextFreeElement = Z_ARRVAL_P(arr)->nNextFreeElement - 1;
            zend_hash_internal_pointer_reset(Z_ARRVAL_P(arr));
        }
        else
        {
            if( !activerecord_is_hash(last) )
                /* throw exception */;
            zend_hash_add( Z_ARRVAL_P(retval), "conditions", 10, last, sizeof(zval*), NULL );
        }
    }

    return retval;
}
예제 #11
0
/**
 * Used for seeking on a phar directory handle
 */
static int phar_dir_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) /* {{{ */
{
	HashTable *data = (HashTable *)stream->abstract;

	if (!data) {
		return -1;
	}

	if (whence == SEEK_END) {
		whence = SEEK_SET;
		offset = zend_hash_num_elements(data) + offset;
	}

	if (whence == SEEK_SET) {
		zend_hash_internal_pointer_reset(data);
	}

	if (offset < 0) {
		return -1;
	} else {
		*newoffset = 0;
		while (*newoffset < offset && zend_hash_move_forward(data) == SUCCESS) {
			++(*newoffset);
		}
		return 0;
	}
}
예제 #12
0
파일: air_router.c 프로젝트: jaykizhou/air
PHP_METHOD(air_router, reset) {
	AIR_INIT_THIS;

	zval *original_rules = zend_read_property(air_router_ce, self, ZEND_STRL("_original_rules"), 1 TSRMLS_CC);
	HashTable *ro = Z_ARRVAL_P(original_rules);
	zend_hash_internal_pointer_reset(ro);
	php_error(E_NOTICE, "router cursor has been reset");
	AIR_RET_THIS;
}
예제 #13
0
/* {{{ proto int symbol.setpoints(array points)
   Set the points of the symbol ) */ 
PHP_METHOD(symbolObj, setPoints)
{
    zval *zpoints, **ppzval;
    HashTable *points_hash = NULL;
    zval *zobj = getThis();
    int index = 0, flag = 0, numelements = 0;
    php_symbol_object *php_symbol;

    PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",
                              &zpoints) == FAILURE) {
        PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
        return;
    }
    PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
    
    php_symbol = (php_symbol_object *) zend_object_store_get_object(zobj TSRMLS_CC);
    points_hash = Z_ARRVAL_P(zpoints);

    numelements = zend_hash_num_elements(points_hash);
    if ((numelements == 0) || (numelements % 2 != 0))
    {
        mapscript_report_php_error(E_WARNING, 
                                   "symbol->setpoints : invalid array of %d element(s) as parameter." TSRMLS_CC, numelements);
        RETURN_LONG(MS_FAILURE);
        
    }

    for(zend_hash_internal_pointer_reset(points_hash); 
        zend_hash_has_more_elements(points_hash) == SUCCESS; 
        zend_hash_move_forward(points_hash))
    { 
        
        zend_hash_get_current_data(points_hash, (void **)&ppzval);
        if (Z_TYPE_PP(ppzval) != IS_DOUBLE)
            convert_to_double(*ppzval);
	     
        if (!flag)
        {
            php_symbol->symbol->points[index].x = Z_DVAL_PP(ppzval);
            php_symbol->symbol->sizex = MS_MAX(php_symbol->symbol->sizex, php_symbol->symbol->points[index].x);
        }
        else
        {
            php_symbol->symbol->points[index].y = Z_DVAL_PP(ppzval);
            php_symbol->symbol->sizey = MS_MAX(php_symbol->symbol->sizey, php_symbol->symbol->points[index].y);
            index++;
        }    
        flag = !flag;
    }

    php_symbol->symbol->numpoints = (numelements/2);

    RETURN_LONG(MS_SUCCESS);
}
예제 #14
0
/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql) */
MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA * mysql)
{
	MYSQLI_WARNING	*w, *first = NULL, *prev = NULL;
	MYSQL_RES		*result;
	zval			row;

	if (mysql->m->query(mysql, "SHOW WARNINGS", 13)) {
		return NULL;
	}

	result = mysql->m->use_result(mysql, 0);

	for (;;) {
		zval *entry;
		int errno;

		mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, &row, MYSQLND_MYSQLI);
		if (Z_TYPE(row) != IS_ARRAY) {
			zval_ptr_dtor(&row);
			break;
		}
		zend_hash_internal_pointer_reset(Z_ARRVAL(row));
		/* 0. we don't care about the first */
		zend_hash_move_forward(Z_ARRVAL(row));

		/* 1. Here comes the error no */
		entry = zend_hash_get_current_data(Z_ARRVAL(row));
		convert_to_long_ex(entry);
		errno = Z_LVAL_P(entry);
		zend_hash_move_forward(Z_ARRVAL(row));

		/* 2. Here comes the reason */
		entry = zend_hash_get_current_data(Z_ARRVAL(row));

		w = php_new_warning(entry, errno);
		/*
		  Don't destroy entry, because the row destroy will decrease
		  the refcounter. Decreased twice then mysqlnd_free_result()
		  will crash, because it will try to access already freed memory.
		*/
		if (!first) {
			first = w;
		}
		if (prev) {
			prev->next = (void *)w;
		}
		prev = w;

		zval_ptr_dtor(&row);
	}

	mysql_free_result(result);
	return first;
}
예제 #15
0
/**
 * Convert a php Array to a map
 *
 * @param t the php Array to convert
 * @return the created map
 */
map* php_map_from_HasTable(HashTable* t){
#ifdef DEBUG
  fprintf(stderr,"mapsFromPHPArray start\n");
#endif
  map* final_res=(map*)malloc(MAP_SIZE);
  final_res=NULL;
  char key[1024];
  for(zend_hash_internal_pointer_reset(t);
      zend_hash_has_more_elements(t) == SUCCESS;
      zend_hash_move_forward(t)) {
    char *key;
    uint keylen;
    ulong idx;
    int type;
    int len;
    zval **ppzval, tmpcopy;
    type = zend_hash_get_current_key_ex(t, &key, &keylen, &idx, 0, NULL); 
    if (zend_hash_get_current_data(t, (void**)&ppzval) == FAILURE) { 
      /* Should never actually fail * since the key is known to exist. */ 
      continue; 
    }
    /**
     * Duplicate the zval so that * the orignal’s contents are not destroyed 
     */ 
    tmpcopy = **ppzval; 
    zval_copy_ctor(&tmpcopy); 
    /**
     * Reset refcount & Convert 
     */ 
    INIT_PZVAL(&tmpcopy); 
    convert_to_string(&tmpcopy);
    if(strncmp(key,"value",5)==0){
      len=Z_STRLEN_P(&tmpcopy);      
	  final_res = addToMapWithSize(final_res,key,Z_STRVAL_P(&tmpcopy),len);
    }
    else{
      if(final_res==NULL){
#ifdef DEBUG
	fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
#endif
	final_res=createMap(key,Z_STRVAL(tmpcopy));
      }
      else{
#ifdef DEBUG
	fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
#endif
	addToMap(final_res,key,Z_STRVAL(tmpcopy));
      }
    }
    /* Toss out old copy */ 
    zval_dtor(&tmpcopy); 
  }
  return final_res;
}
예제 #16
0
파일: Rows.c 프로젝트: NSRagu/php-driver
PHP_METHOD(Rows, rewind)
{
  cassandra_rows* self = NULL;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  zend_hash_internal_pointer_reset(Z_ARRVAL_P(self->rows));
}
예제 #17
0
파일: request.c 프로젝트: Lucups/Skyray
void skyray_http_request_resolve_cookies_if_needed(skyray_http_request_t *self)
{
    if (!ZVAL_IS_NULL(&self->cookie_params)) {
        return;
    }
    zval *lines = skyray_http_message_get_header(&self->message, intern_str_cookie, 0);
    if (!lines) {
        return;
    }
    array_init(&self->cookie_params);

    zend_array *ht = Z_ARR_P(lines);
    zend_array *ht2;
    zval tmp, *data;;

    zend_hash_internal_pointer_reset(ht);
    while(zend_hash_has_more_elements(ht) == SUCCESS) {

        array_init(&tmp);
        data = zend_hash_get_current_data(ht);
        php_explode(intern_str_param_delimiter, Z_STR_P(data), &tmp, ZEND_LONG_MAX);

        ht2 = Z_ARR_P(&tmp);

        zend_hash_internal_pointer_reset(ht2);
        while (zend_hash_has_more_elements(ht2) == SUCCESS) {
            data = zend_hash_get_current_data(ht2);

            char *c = strchr(Z_STR_P(data)->val, '=');
            int len = c - Z_STR_P(data)->val;
            add_assoc_str_ex(&self->cookie_params, Z_STR_P(data)->val, len, zend_string_init(c + 1, Z_STR_P(data)->len - len - 1, 0));

            zend_hash_move_forward(ht2);
        }

        zval_ptr_dtor(&tmp);

        zend_hash_move_forward(ht);
    }
}
예제 #18
0
파일: air_router.c 프로젝트: jaykizhou/air
PHP_METHOD(air_router, set_rules) {
	AIR_INIT_THIS;

	zval *rules;
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &rules) == FAILURE) {
	}else{
		zend_update_property(air_router_ce, self, ZEND_STRL("_original_rules"), rules TSRMLS_CC);
		zval *original_rules = zend_read_property(air_router_ce, self, ZEND_STRL("_original_rules"), 1 TSRMLS_CC);
		zend_hash_internal_pointer_reset(Z_ARRVAL_P(original_rules));
	}

	AIR_RET_THIS;
}
static PHP_METHOD(php_midgard_reflection_class, getMethods)
{
	zval *filter = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &filter) == FAILURE)
		return;

	zval *this = getThis();

	zval *class_name = NULL;
	zend_call_method_with_0_params(&this, zend_reflection_class_class, NULL, "getname", &class_name);

	zval *result = NULL;

	if (filter) {
		zend_call_method_with_1_params(&this, zend_reflection_class_class, NULL, "getmethods", &result, filter);
	} else {
		zend_call_method_with_0_params(&this, zend_reflection_class_class, NULL, "getmethods", &result);
	}

	array_init(return_value);

	HashTable *parent_ht = Z_ARRVAL_P(result);
	for(
		zend_hash_internal_pointer_reset(parent_ht);
		zend_hash_has_more_elements(parent_ht) == SUCCESS;
		zend_hash_move_forward(parent_ht)
	) {
		zval **ppzval = NULL;
		zend_hash_get_current_data(parent_ht, (void**)&ppzval);

		zval *method_name = NULL;
		zend_call_method_with_0_params(ppzval, zend_reflection_function_class, NULL, "getname", &method_name);

		zval *new_obj = NULL;
		MAKE_STD_ZVAL(new_obj);
		object_init_ex(new_obj, php_midgard_reflection_method_class);
		zend_call_method_with_2_params(&new_obj,
		                               php_midgard_reflection_method_class,
		                               &php_midgard_reflection_method_class->constructor, "__construct",
		                               NULL, class_name, method_name
		);
		zval_ptr_dtor(&method_name);

		add_next_index_zval(return_value, new_obj);
	}

	zval_ptr_dtor(&result);
	zval_ptr_dtor(&class_name);
}
예제 #20
0
파일: php_ini.c 프로젝트: Tyrael/php-src
/* {{{ php_ini_activate_config
 */
PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage)
{
	zend_string *str;
	zval *data;
	zend_ulong num_index;

	/* Walk through config hash and alter matching ini entries using the values found in the hash */
	for (zend_hash_internal_pointer_reset(source_hash);
		zend_hash_get_current_key(source_hash, &str, &num_index) == HASH_KEY_IS_STRING;
		zend_hash_move_forward(source_hash)
	) {
		data = zend_hash_get_current_data(source_hash);
		zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0);
	}
}
예제 #21
0
파일: alinq.c 프로젝트: wosiwo/clinq
//迭代函数
void php_alinq_iterator_key(HashTable *arrht)
{

    for(zend_hash_internal_pointer_reset(arrht);
        zend_hash_has_more_elements(arrht) == SUCCESS;
        zend_hash_move_forward(arrht))
    {
        if(zend_hash_has_more_elements(arrht) == SUCCESS){
            php_printf("aaaa");
        }else{
            php_printf("bbbb");
        }
       
    }
}
예제 #22
0
파일: pip_convert.c 프로젝트: demos/Motif
/* {{{ pip_zobject_to_pyobject(zval **obj)
   Convert a PHP (Zend) object to a Python object */
PyObject *
pip_zobject_to_pyobject(zval **obj)
{
	PyObject *dict, *item, *str;
	zval **entry;
	char *string_key;
	long num_key;

	/*
	 * At this point, we represent a PHP object as a dictionary of
	 * its properties.  In the future, we may provide a true object
	 * conversion (which is entirely possible, but it's more work
	 * that I plan on doing right now).
	 */
	dict = PyDict_New();

	/* Start at the beginning of the object properties hash */
	zend_hash_internal_pointer_reset(Z_OBJPROP_PP(obj));

	/* Iterate over the hash's elements */
	while (zend_hash_get_current_data(Z_OBJPROP_PP(obj),
									  (void **)&entry) == SUCCESS) {

		/* Convert the PHP value to its Python equivalent (recursion) */
		item = pip_zval_to_pyobject(entry);

		switch (zend_hash_get_current_key(Z_OBJPROP_PP(obj),
										  &string_key, &num_key, 0)) {
			case HASH_KEY_IS_STRING:
				PyDict_SetItemString(dict, string_key, item);
				break;
			case HASH_KEY_IS_LONG:
				str = PyString_FromFormat("%d", num_key);
				PyObject_SetItem(dict, str, item);
				Py_DECREF(str);
				break;
			case HASH_KEY_NON_EXISTANT:
				php_error(E_ERROR, "No array key");
				break;
		}

		/* Advance to the next entry */
		zend_hash_move_forward(Z_OBJPROP_PP(obj));
	}

	return dict;
}
예제 #23
0
void apply_config(void *dummy)
{
	php_conf_rec *d = dummy;
	char *str;
	uint str_len;
	php_dir_entry *data;
	
	for (zend_hash_internal_pointer_reset(&d->config);
			zend_hash_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING;
			zend_hash_move_forward(&d->config)) {
		zend_hash_get_current_data(&d->config, (void **) &data);
		phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
		if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) {
			phpapdebug((stderr, "..FAILED\n"));
		}	
	}
}
예제 #24
0
파일: pip_convert.c 프로젝트: demos/Motif
/* {{{ pip_hash_to_dict(zval **hash)
   Convert a PHP hash to a Python dictionary */
PyObject *
pip_hash_to_dict(zval **hash)
{
	PyObject *dict, *item, *integer;
	zval **entry;
	char *string_key;
	long num_key = 0;

	/* Make sure we were given a PHP hash */
	if (Z_TYPE_PP(hash) != IS_ARRAY) {
		return NULL;
	}

	/* Create a new empty dictionary */
	dict = PyDict_New();

	/* Let's start at the very beginning, a very good place to start. */
	zend_hash_internal_pointer_reset(Z_ARRVAL_PP(hash));

	/* Iterate over the hash's elements */
	while (zend_hash_get_current_data(Z_ARRVAL_PP(hash),
									  (void **)&entry) == SUCCESS) {

		/* Convert the PHP value to its Python equivalent (recursion) */
		item = pip_zval_to_pyobject(entry);

		/* Assign the item with the appropriate key type (string or integer) */
		switch (zend_hash_get_current_key(Z_ARRVAL_PP(hash), &string_key,
										  &num_key, 0)) {
			case HASH_KEY_IS_STRING:
				PyDict_SetItemString(dict, string_key, item);
				break;
			case HASH_KEY_IS_LONG:
				integer = PyInt_FromLong(num_key);
				PyDict_SetItem(dict, integer, item);
				Py_DECREF(integer);
				break;
		}

		/* Advance to the next entry */
		zend_hash_move_forward(Z_ARRVAL_PP(hash));
	}

	return dict;
}
예제 #25
0
char *owsrequest_getenv(const char *name, void *thread_context)
{
    zval **val, **ppzval;
    zval *cookie_result, *key;
    HashTable *cookies;
    char *string_key = NULL, *cookie_tmp;
    ulong num_key;
    int numElements, i = 0;
    TSRMLS_FETCH_FROM_CTX(thread_context);

    if  (STRING_EQUAL(name, "HTTP_COOKIE"))
    {
        cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht;
        numElements = zend_hash_num_elements(cookies);
        MAKE_STD_ZVAL(cookie_result);
        ZVAL_STRING(cookie_result, "",1);
        for(zend_hash_internal_pointer_reset(cookies); 
            zend_hash_has_more_elements(cookies) == SUCCESS; 
            zend_hash_move_forward(cookies), ++i)
        { 
            zend_hash_get_current_data(cookies, (void **)&ppzval);
            zend_hash_get_current_key(cookies, &string_key, &num_key, 1);
            cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char));
            sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval));
            MAKE_STD_ZVAL(key);
            ZVAL_STRING(key, cookie_tmp,1);
            add_string_to_string(cookie_result,cookie_result, key);
            zval_dtor(key);
            free(cookie_tmp);
        }
        return Z_STRVAL_P(cookie_result);
    }
    else 
    {
        zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
        if ( PG(http_globals)[TRACK_VARS_SERVER] &&
             (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) &&
             (Z_TYPE_PP(val) == IS_STRING))
        {
            return Z_STRVAL_PP(val);
        }
    }
    
    return NULL;
}
예제 #26
0
파일: behavior.c 프로젝트: bixuehujin/yee
void yee_behavior_attach(zval *self, zval *owner) {
	zend_class_entry *ce = Z_OBJCE_P(self);
	zval *events = NULL, **handler_ptr;
	char *event;
	int event_size;
	
	zend_update_property(ce, self, ZEND_STRL("owner"), owner);
	
	zend_call_method(&self, ce, NULL, ZEND_STRL("events"), &events, 0, NULL, NULL);
	
	if (events && Z_TYPE_P(events) == IS_ARRAY) {
		HashTable *ht = Z_ARRVAL_P(events);
		zend_hash_internal_pointer_reset(ht);
		while(zend_hash_has_more_elements(ht) == SUCCESS) {
			zend_hash_get_current_key_ex(ht, &event, &event_size, NULL, 0, NULL);
			zend_hash_get_current_data(ht, (void **)&handler_ptr);
			
			zval *zv_event, *zv_handler;
			
			MAKE_STD_ZVAL(zv_event);
			ZVAL_STRINGL(zv_event, event, event_size - 1, 0);
			
			if (Z_TYPE_PP(handler_ptr) == IS_STRING) {
				MAKE_STD_ZVAL(zv_handler);
				array_init(zv_handler);
				add_next_index_zval(zv_handler, self);
				add_next_index_zval(zv_handler, *handler_ptr);

				zval_addref_p(self);
			}else {
				zv_handler = *handler_ptr;
			}
			
			zend_call_method(&owner, Z_OBJCE_P(owner), NULL, ZEND_STRL("on"), NULL, 2, zv_event, zv_handler);
			
			efree(zv_event);
			if (zv_handler != *handler_ptr) {
				zval_ptr_dtor(&zv_handler);
			}
			zend_hash_move_forward(ht);
		}
		
	}
	zval_ptr_dtor(&events);
}
예제 #27
0
/* {{{ proto Util::array_first(array $arr)
   Return the first value from an array. */
ZEND_METHOD(util, array_first)
{
	zval *arr, **zvalue;
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) {
		RETURN_NULL();
	}
	if (Z_TYPE_P(arr) != IS_ARRAY) {
		RETURN_NULL();
	}
	zend_hash_internal_pointer_reset(Z_ARRVAL_P(arr));
	if (zend_hash_get_current_data(Z_ARRVAL_P(arr), (void**)&zvalue) == FAILURE) {
		RETURN_NULL();
	}

	*return_value = **zvalue;
	zval_copy_ctor(return_value);
	return;
}
예제 #28
0
파일: params.c 프로젝트: Leon2012/php-ext
static PHP_FUNCTION(params_array) {
    HashTable *options = NULL;
    zval *v;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &v) == FAILURE) {
        RETURN_FALSE;
    }

    options = Z_ARRVAL_P(v);//读取array类型的值

    //zend_hash_internal_pointer_reset 
    //zend_hash_has_more_elements 判断HashTable是否有元素
    //zend_hash_move_forward 移动HashTable到顶端
    //zend_hash_get_current_key_ex 读取HashTable当前的key,HashTable的key有两种,一种是指定字符串,另一种是顺序的0-n下标
    //zend_hash_get_current_data 读取HashTable当前的值到zval
    //zend_hash_get_current_key_type 获取当前key的类型

    for(zend_hash_internal_pointer_reset(options); SUCCESS == zend_hash_has_more_elements(options); zend_hash_move_forward(options)) {
        char *k1;
        ulong nkey = -1, keylen;
        zval **z;
        zend_hash_get_current_key_ex(options, &k1, &keylen, &nkey, 0, NULL);
        zend_hash_get_current_data(options, (void **)&z);
        php_printf(" key: ");

        if (HASH_KEY_IS_STRING == zend_hash_get_current_key_type(options)) {
            PHPWRITE(k1, keylen);
        }else{
            php_printf("%ld", nkey);
        }

        php_printf("  value: ");
        if (Z_TYPE_P(*z) == IS_STRING) {
            //php_printf("string(%d)\n", Z_STRLEN_P(*z));
            PHPWRITE(Z_STRVAL_P(*z), Z_STRLEN_P(*z));
        }else{
            zend_print_zval_r((*z), 0 TSRMLS_CC); 
        }
        php_printf("\n");
    }

    RETURN_TRUE;
}
예제 #29
0
파일: readline.c 프로젝트: AzerTyQsdF/osx
static char *_readline_command_generator(const char *text, int state)
{
	HashTable  *myht = Z_ARRVAL(_readline_array);
	zval **entry;
	
	if (!state) {
		zend_hash_internal_pointer_reset(myht);
	}
	
	while (zend_hash_get_current_data(myht, (void **)&entry) == SUCCESS) {
		zend_hash_move_forward(myht);

		convert_to_string_ex(entry);
		if (strncmp (Z_STRVAL_PP(entry), text, strlen(text)) == 0) {
			return (strdup(Z_STRVAL_PP(entry)));
		}
	}

	return NULL;
}
예제 #30
0
파일: Rows.c 프로젝트: NSRagu/php-driver
PHP_METHOD(Rows, first)
{
  HashPointer ptr;
  zval **entry;
  cassandra_rows* self = NULL;

  if (zend_parse_parameters_none() == FAILURE) {
    return;
  }

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  zend_hash_get_pointer(Z_ARRVAL_P(self->rows), &ptr);
  zend_hash_internal_pointer_reset(Z_ARRVAL_P(self->rows));

  if (zend_hash_get_current_data(Z_ARRVAL_P(self->rows), (void **) &entry) == SUCCESS)
    RETVAL_ZVAL(*entry, 1, 0);

  zend_hash_set_pointer(Z_ARRVAL_P(self->rows), &ptr);
}