Exemplo n.º 1
0
/* {{{ */
zend_string* pthreads_globals_string(zend_string *str) {
	/*
	 This is sourcery of the darkest kind ...
	
	 We don't need all threads to have a copy of every string used as the name for a threaded objects property.
	 
	 In addition, Zend has troubles with persistent strings in non-persistent hashes and vice versa, to avoid these
	 we have a global table of strings that is used when writing to threaded objects properties, this table is detroyed
	 on shutdown of the process, so will show as leaked, but we don't care, we want stable !
	*/
	zend_string* p = NULL;
	if (pthreads_globals_lock()) {
		if (!(p = zend_hash_find_ptr(&PTHREADS_G(gstrings), str)) && 
			(p = (zend_string*) malloc(ZEND_MM_ALIGNED_SIZE(_ZSTR_STRUCT_SIZE(ZSTR_LEN(str)))))) {
			memset(p, 0, sizeof(zend_string));

			GC_REFCOUNT(p) = 2;
			GC_TYPE_INFO(p) = IS_STR_PERSISTENT;

			memcpy(ZSTR_VAL(p), ZSTR_VAL(str), ZSTR_LEN(str));
			p->len = ZSTR_LEN(str);
			ZSTR_VAL(p)[ZSTR_LEN(p)] = '\0';
			zend_string_forget_hash_val(p);
			zend_hash_update_ptr(
				&PTHREADS_G(gstrings), p, p);
		}

		pthreads_globals_unlock();
	}

	return p;
} /* }}} */
Exemplo n.º 2
0
PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory)
{
	zend_string *str = zend_string_init_interned(protocol, strlen(protocol), 1);

	zend_hash_update_ptr(&xport_hash, str, factory);
	zend_string_release_ex(str, 1);
	return SUCCESS;
}
Exemplo n.º 3
0
PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory)
{
	int ret;
	zend_string *str = zend_string_init_interned(protocol, strlen(protocol), 1);

	ret = zend_hash_update_ptr(&xport_hash, str, factory) ? SUCCESS : FAILURE;
	zend_string_release(str);
	return ret;
}
static int move_user_function(zval *zv, int num_args, va_list args, zend_hash_key *hash_key)
{
	zend_function *function = Z_PTR_P(zv);
	HashTable *function_table = va_arg(args, HashTable *);
	(void)num_args; /* keep the compiler happy */

	if (function->type == ZEND_USER_FUNCTION) {
		zend_hash_update_ptr(function_table, hash_key->key, function);
		return 1;
	} else {
		return 0;
	}
}
Exemplo n.º 5
0
static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg) /* {{{ */
{
	browscap_parser_ctx *ctx = arg;
	browser_data *bdata = ctx->bdata;
	int persistent = bdata->htab->u.flags & HASH_FLAG_PERSISTENT;

	if (!arg1) {
		return;
	}

	switch (callback_type) {
		case ZEND_INI_PARSER_ENTRY:
			if (ctx->current_entry != NULL && arg2) {
				zend_string *new_key, *new_value;

				/* Set proper value for true/false settings */
				if ((Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "on", sizeof("on") - 1)) ||
					(Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "yes", sizeof("yes") - 1)) ||
					(Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "true", sizeof("true") - 1))
				) {
					new_value = zend_string_copy(ctx->str_one);
				} else if (
					(Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "no", sizeof("no") - 1)) ||
					(Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "off", sizeof("off") - 1)) ||
					(Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "none", sizeof("none") - 1)) ||
					(Z_STRLEN_P(arg2) == 5 && !strncasecmp(Z_STRVAL_P(arg2), "false", sizeof("false") - 1))
				) {
					new_value = zend_string_copy(ctx->str_empty);
				} else { /* Other than true/false setting */
					new_value = browscap_intern_str(ctx, Z_STR_P(arg2));
				}

				if (!strcasecmp(Z_STRVAL_P(arg1), "parent")) {
					/* parent entry can not be same as current section -> causes infinite loop! */
					if (ctx->current_section_name != NULL &&
						!strcasecmp(ZSTR_VAL(ctx->current_section_name), Z_STRVAL_P(arg2))
					) {
						zend_error(E_CORE_ERROR, "Invalid browscap ini file: "
							"'Parent' value cannot be same as the section name: %s "
							"(in file %s)", ZSTR_VAL(ctx->current_section_name), INI_STR("browscap"));
						return;
					}

					if (ctx->current_entry->parent) {
						zend_string_release(ctx->current_entry->parent);
					}
					ctx->current_entry->parent = new_value;
				} else {
					new_key = browscap_intern_str_ci(ctx, Z_STR_P(arg1), persistent);
					browscap_add_kv(bdata, new_key, new_value, persistent);
					ctx->current_entry->kv_end = bdata->kv_used;
				}
			}
			break;
		case ZEND_INI_PARSER_SECTION:
		{
			browscap_entry *entry;
			zend_string *pattern = Z_STR_P(arg1);
			size_t pos;
			int i;

			if (ZSTR_LEN(pattern) > UINT16_MAX) {
				php_error_docref(NULL, E_WARNING,
					"Skipping excessively long pattern of length %zd", ZSTR_LEN(pattern));
				break;
			}
			
			entry = ctx->current_entry
				= pemalloc(sizeof(browscap_entry), persistent);
			zend_hash_update_ptr(bdata->htab, pattern, entry);

			if (ctx->current_section_name) {
				zend_string_release(ctx->current_section_name);
			}
			ctx->current_section_name = zend_string_copy(pattern);

			entry->pattern = zend_string_copy(pattern);
			entry->kv_end = entry->kv_start = bdata->kv_used;
			entry->parent = NULL;

			pos = entry->prefix_len = browscap_compute_prefix_len(pattern);
			for (i = 0; i < BROWSCAP_NUM_CONTAINS; i++) {
				pos = browscap_compute_contains(pattern, pos,
					&entry->contains_start[i], &entry->contains_len[i]);
			}
			break;
		}
	}
}