Beispiel #1
0
/* {{{ php_runkit_import_functions
 */
static int php_runkit_import_functions(HashTable *function_table, long flags TSRMLS_DC)
{
	HashPosition pos;
	int i, func_count = zend_hash_num_elements(function_table);

	zend_hash_internal_pointer_reset_ex(function_table, &pos);
	for(i = 0; i < func_count; i++) {
		zend_function *fe = NULL;
		char *key, *new_key;
		int key_len, new_key_len, type;
		long idx;
		zend_bool add_function = 1;
		zend_bool exists = 0;

		zend_hash_get_current_data_ex(function_table, (void**)&fe, &pos);

		new_key = fe->common.function_name;
		new_key_len = strlen(new_key) + 1;

		if (((type = zend_hash_get_current_key_ex(function_table, &key, &key_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT) &&
			fe && fe->type == ZEND_USER_FUNCTION) {

			if (type == HASH_KEY_IS_STRING) {
				new_key = key;
				new_key_len = key_len;
				exists = zend_hash_exists(EG(function_table), new_key, new_key_len);
			} else {
				exists = zend_hash_index_exists(EG(function_table), idx);
			}

			if (exists) {
				if (flags & PHP_RUNKIT_IMPORT_OVERRIDE) {
					if (type == HASH_KEY_IS_STRING) {
						if (zend_hash_del(EG(function_table), new_key, new_key_len) == FAILURE) {
							php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
							return FAILURE;
						}
					} else {
						if (zend_hash_index_del(EG(function_table), idx) == FAILURE) {
							php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
							return FAILURE;
						}
					}
				} else {
					add_function = 0;
				}
			}
		}

		if (add_function) {
			if (zend_hash_add(EG(function_table), new_key, new_key_len, fe, sizeof(zend_function), NULL) == FAILURE) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure importing %s()", fe->common.function_name);
#ifdef ZEND_ENGINE_2
				destroy_zend_function(fe TSRMLS_CC);
#else
				destroy_end_function(fe);
#endif
				return FAILURE;
			} else {
				fe->op_array.static_variables = NULL;
				(*fe->op_array.refcount)++;
			}
		}
		zend_hash_move_forward_ex(function_table, &pos);
	}

	return SUCCESS;
}
Beispiel #2
0
/* {{{ php_runkit_import_functions
 */
static int php_runkit_import_functions(HashTable *function_table, long flags TSRMLS_DC)
{
	HashPosition pos;
	int i, func_count = zend_hash_num_elements(function_table);

	zend_hash_internal_pointer_reset_ex(function_table, &pos);
	for(i = 0; i < func_count; i++) {
		zend_function *fe = NULL;
		char *key;
		uint key_len;
		int type;
		ulong idx;
		zend_bool add_function = 1;

		zend_hash_get_current_data_ex(function_table, (void**)&fe, &pos);

		if (((type = zend_hash_get_current_key_ex(EG(function_table), &key, &key_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT) && 
			fe && fe->type == ZEND_USER_FUNCTION) {
		
			if (flags & PHP_RUNKIT_IMPORT_OVERRIDE) {
				if (type == HASH_KEY_IS_STRING) {
					if (zend_hash_del(EG(function_table), key, key_len) == FAILURE) {
						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
						return FAILURE;
					}
				} else {
					if (zend_hash_index_del(EG(function_table), idx) == FAILURE) {
						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
						return FAILURE;
					}
				}
			} else {
				add_function = 0;
			}
		}

		if (add_function) {
			PHP_RUNKIT_FUNCTION_ADD_REF(fe);


			char *lcase = estrdup(fe->common.function_name);
			int lcase_len = strlen(lcase);

			php_strtolower(lcase, lcase_len);
			if (zend_hash_add(EG(function_table), lcase, lcase_len + 1, fe, sizeof(zend_function), NULL) == FAILURE) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure importing %s()", fe->common.function_name);
#ifdef ZEND_ENGINE_2
				destroy_zend_function(fe TSRMLS_CC);
#else
				destroy_end_function(fe);
#endif
				efree(lcase);
				return FAILURE;
			}
			efree(lcase);
		}
		zend_hash_move_forward_ex(function_table, &pos);
	}

	return SUCCESS;
}