static void php_memc_store_impl()

in php_memcached.c [1977:2062]


static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool by_key)
{
	zend_string *key;
	zend_string *server_key = NULL;
	zend_string *s_value;
	zval s_zvalue;
	zval *value = NULL;
	zend_long expiration = 0;
	MEMC_METHOD_INIT_VARS;

	if (by_key) {
		if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
			/* "SSS" */
			ZEND_PARSE_PARAMETERS_START(3, 3)
			        Z_PARAM_STR(server_key)
			        Z_PARAM_STR(key)
			        Z_PARAM_STR(s_value)
			ZEND_PARSE_PARAMETERS_END();
			value = &s_zvalue;
			ZVAL_STR(value, s_value);
		} else if (op == MEMC_OP_TOUCH) {
			/* "SS|l" */
			ZEND_PARSE_PARAMETERS_START(2, 3)
			        Z_PARAM_STR(server_key)
			        Z_PARAM_STR(key)
				Z_PARAM_OPTIONAL
				Z_PARAM_LONG(expiration)
			ZEND_PARSE_PARAMETERS_END();
		} else {
			/* "SSz|l" */
			ZEND_PARSE_PARAMETERS_START(3, 4)
			        Z_PARAM_STR(server_key)
			        Z_PARAM_STR(key)
			        Z_PARAM_ZVAL(value)
				Z_PARAM_OPTIONAL
				Z_PARAM_LONG(expiration)
			ZEND_PARSE_PARAMETERS_END();
		}
	} else {
		if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
			/* "SS" */
			ZEND_PARSE_PARAMETERS_START(2, 2)
			        Z_PARAM_STR(key)
			        Z_PARAM_STR(s_value)
			ZEND_PARSE_PARAMETERS_END();
			value = &s_zvalue;
			ZVAL_STR(value, s_value);
		} else if (op == MEMC_OP_TOUCH) {
			/* "S|l */
			ZEND_PARSE_PARAMETERS_START(1, 2)
			        Z_PARAM_STR(key)
			        Z_PARAM_OPTIONAL
			        Z_PARAM_LONG(expiration)
			ZEND_PARSE_PARAMETERS_END();
		} else {
			/* "Sz|l" */
			ZEND_PARSE_PARAMETERS_START(2, 3)
			        Z_PARAM_STR(key)
			        Z_PARAM_ZVAL(value)
			        Z_PARAM_OPTIONAL
			        Z_PARAM_LONG(expiration)
			ZEND_PARSE_PARAMETERS_END();
		}
	}

	MEMC_METHOD_FETCH_OBJECT;
	s_memc_set_status(intern, MEMCACHED_SUCCESS, 0);
	MEMC_CHECK_KEY(intern, key);

	if (memc_user_data->compression_enabled) {
		/*
		 * When compression is enabled, we cannot do appends/prepends because that would
		 * corrupt the compressed values. It is up to the user to fetch the value,
		 * append/prepend new data, and store it again.
		 */
		if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
			php_error_docref(NULL, E_WARNING, "cannot append/prepend with compression turned on");
			RETURN_NULL();
		}
	}

	if (!s_memc_write_zval (intern, op, server_key, key, value, expiration)) {
		RETURN_FALSE;
	}
	RETURN_TRUE;
}