Example #1
0
/**
 * Gets variable from $_GET superglobal applying filters if needed
 * If no parameters are given the $_GET superglobal is returned
 *
 *<code>
 *	//Returns value from $_GET["id"] without sanitizing
 *	$id = $request->getQuery("id");
 *
 *	//Returns value from $_GET["id"] with sanitizing
 *	$id = $request->getQuery("id", "int");
 *
 *	//Returns value from $_GET["id"] with a default value
 *	$id = $request->getQuery("id", null, 150);
 *</code>
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, getQuery){

	zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, *get;

	phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, &not_allow_empty, &norecursive);

	if (!name) {
		name = &PHALCON_GLOBAL(z_null);
	}

	if (!filters) {
		filters = &PHALCON_GLOBAL(z_null);
	}

	if (!default_value) {
		default_value = &PHALCON_GLOBAL(z_null);
	}

	if (!not_allow_empty) {
		not_allow_empty = &PHALCON_GLOBAL(z_false);
	}

	if (!norecursive) {
		norecursive = &PHALCON_GLOBAL(z_false);
	}

	get = phalcon_get_global_str(SL("_GET"));

	PHALCON_RETURN_CALL_SELFW("_get", get, name, filters, default_value, not_allow_empty, norecursive);
}
Example #2
0
/**
 * Gets a variable from the $_REQUEST superglobal applying filters if needed.
 * If no parameters are given the $_REQUEST superglobal is returned
 *
 *<code>
 *	//Returns value from $_REQUEST["user_email"] without sanitizing
 *	$userEmail = $request->get("user_email");
 *
 *	//Returns value from $_REQUEST["user_email"] with sanitizing
 *	$userEmail = $request->get("user_email", "email");
 *</code>
 *
 * @param string $name
 * @param string|array $filters
 * @param mixed $defaultValue
 * @param boolean $notAllowEmpty
 * @param boolean $noRecursive
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, get)
{
	zval *name = NULL, *filters = NULL, *default_value = NULL, *not_allow_empty = NULL, *norecursive = NULL, *request;
	zval put = {}, merged = {};

	phalcon_fetch_params(0, 0, 5, &name, &filters, &default_value, &not_allow_empty, &norecursive);

	if (!name) {
		name = &PHALCON_GLOBAL(z_null);
	}

	if (!filters) {
		filters = &PHALCON_GLOBAL(z_null);
	}

	if (!default_value) {
		default_value = &PHALCON_GLOBAL(z_null);
	}

	if (!not_allow_empty) {
		not_allow_empty = &PHALCON_GLOBAL(z_false);
	}

	if (!norecursive) {
		norecursive = &PHALCON_GLOBAL(z_false);
	}

	request = phalcon_get_global_str(SL("_REQUEST"));

	PHALCON_CALL_METHODW(&put, getThis(), "getput");

	phalcon_fast_array_merge(&merged, request, &put);

	PHALCON_RETURN_CALL_SELFW("_get", &merged, name, filters, default_value, not_allow_empty, norecursive);
}
Example #3
0
/**
 * Checks whether $_SERVER superglobal has certain index
 *
 * @param string $name
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, hasServer){

	zval *name, *_SERVER;

	phalcon_fetch_params(0, 1, 0, &name);

	_SERVER = phalcon_get_global_str(SL("_SERVER"));
	RETURN_BOOL(phalcon_array_isset(_SERVER, name));
}
Example #4
0
/**
 * Checks whether $_POST superglobal has certain index
 *
 * @param string $name
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, hasPost){

	zval *name, *_POST;

	phalcon_fetch_params(0, 1, 0, &name);

	_POST = phalcon_get_global_str(SL("_POST"));
	RETURN_BOOL(phalcon_array_isset(_POST, name));
}
Example #5
0
/**
 * Checks whether $_GET superglobal has certain index
 *
 * @param string $name
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, hasQuery){

	zval *name, *_GET;

	phalcon_fetch_params(0, 1, 0, &name);

	_GET = phalcon_get_global_str(SL("_GET"));
	RETURN_BOOL(phalcon_array_isset(_GET, name));
}
Example #6
0
/**
 * Gets active server address IP
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getServerAddress){

	zval *server, server_addr = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&server_addr, server, SL("SERVER_ADDR"))) {
		RETURN_CTORW(&server_addr);
	}

	RETURN_STRING("127.0.0.1");
}
Example #7
0
/**
 * Gets variable from $_SERVER superglobal
 *
 * @param string $name
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Request, getServer){

	zval *name, *_SERVER;

	phalcon_fetch_params(0, 1, 0, &name);

	_SERVER = phalcon_get_global_str(SL("_SERVER"));
	if (!phalcon_array_isset_fetch(return_value, _SERVER, name, 0)) {
		RETURN_NULL();
	}
}
Example #8
0
/**
 * Gets HTTP user agent used to made the request
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getUserAgent){

	zval *server, user_agent = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&user_agent, server, SL("HTTP_USER_AGENT"))) {
		RETURN_CTORW(&user_agent);
	}

	RETURN_EMPTY_STRING();
}
Example #9
0
/**
 * Gets active server name
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getServerName){

	zval *server, server_name = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_fetch_str(&server_name, server, SL("SERVER_NAME"))) {
		RETURN_CTORW(&server_name);
	}

	RETURN_STRING("localhost");
}
Example #10
0
/**
 * Gets HTTP URI which request has been made
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getURI){

	zval *value, *_SERVER, key = {};

	PHALCON_STR(&key, "REQUEST_URI");

	_SERVER = phalcon_get_global_str(SL("_SERVER"));
	value = (Z_TYPE_P(_SERVER) == IS_ARRAY) ? phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_UNSET) : NULL;
	if (value && Z_TYPE_P(value) == IS_STRING) {
		RETURN_ZVAL(value, 1, 0);
	}

	RETURN_EMPTY_STRING();
}
Example #11
0
/**
 * Gets query string which request has been made
 *
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getQueryString){

	zval *value, *_SERVER, key = {};

	PHALCON_STR(&key, "QUERY_STRING");

	_SERVER = phalcon_get_global_str(SS("_SERVER") TSRMLS_CC);
	value = (Z_TYPE_P(_SERVER) == IS_ARRAY) ? phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_UNSET) : NULL;
	if (value && Z_TYPE_P(value) == IS_STRING) {
		RETURN_ZVAL(value, 1, 0);
	}

	RETURN_EMPTY_STRING();
}
Example #12
0
/**
 * Gets HTTP header from request data
 *
 * @param string $header
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getHeader)
{
	zval *header, *_SERVER, key = {};

	phalcon_fetch_params(0, 1, 0, &header);

	_SERVER = phalcon_get_global_str(SL("_SERVER"));
	if (!phalcon_array_isset_fetch(return_value, _SERVER, header, 0)) {
		PHALCON_CONCAT_SV(&key, "HTTP_", header);
		if (phalcon_array_isset_fetch(return_value, _SERVER, &key, 0)) {
			return;
		}
	}

	RETURN_EMPTY_STRING();
}
Example #13
0
/**
 * Checks whether request has been made using SOAP
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, isSoapRequested)
{
	zval *server, content_type = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_str(server, SL("HTTP_SOAPACTION"))) {
		RETURN_TRUE;
	}

	if (phalcon_array_isset_fetch_str(&content_type, server, SL("CONTENT_TYPE"))) {
		if (phalcon_memnstr_str(&content_type, SL("application/soap+xml"))) {
			RETURN_TRUE;
		}
	}

	RETURN_FALSE;
}
Example #14
0
/**
 * Checks whether $_SERVER superglobal has certain index
 *
 * @param string $header
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, hasHeader){

	zval *header, *_SERVER, key = {};

	phalcon_fetch_params(0, 1, 0, &header);

	_SERVER = phalcon_get_global_str(SS("_SERVER") TSRMLS_CC);
	if (phalcon_array_isset(_SERVER, header)) {
		RETURN_TRUE;
	}

	PHALCON_CONCAT_SV(&key, "HTTP_", header);
	if (phalcon_array_isset(_SERVER, &key)) {
		RETURN_TRUE;
	}

	RETURN_FALSE;
}
Example #15
0
static const char* phalcon_http_request_getmethod_helper()
{
	zval *value, *_SERVER, key = {};
	const char *method = SG(request_info).request_method;
	if (unlikely(!method)) {
		PHALCON_STR(&key, "REQUEST_METHOD");

		_SERVER = phalcon_get_global_str(SL("_SERVER"));
		if (Z_TYPE_P(_SERVER) == IS_ARRAY) {
			value = phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_UNSET);
			if (value && Z_TYPE_P(value) == IS_STRING) {
				return Z_STRVAL_P(value);
			}
		}

		return "";
	}

	return method;
}
Example #16
0
/**
 * Gets most possible client IPv4 Address. This method search in $_SERVER['REMOTE_ADDR'] and optionally in $_SERVER['HTTP_X_FORWARDED_FOR']
 *
 * @param boolean $trustForwardedHeader
 * @return string
 */
PHP_METHOD(Phalcon_Http_Request, getClientAddress){

	zval *trust_forwarded_header = NULL, *_SERVER, address = {}, addresses = {}, first = {};

	phalcon_fetch_params(0, 0, 1, &trust_forwarded_header);

	if (!trust_forwarded_header) {
		trust_forwarded_header = &PHALCON_GLOBAL(z_false);
	}

	_SERVER = phalcon_get_global_str(SL("_SERVER"));

	/**
	 * Proxies use this IP
	 */
	if (zend_is_true(trust_forwarded_header)) {
		if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("HTTP_X_FORWARDED_FOR"))) {
			if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"))) {
				phalcon_array_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"), PH_NOISY);
			}
		}
	} else if (!phalcon_array_isset_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"))) {
		phalcon_array_fetch_str(&address, _SERVER, SL("REMOTE_ADDR"), PH_NOISY);
	}

	if (Z_TYPE(address) == IS_STRING) {
		if (phalcon_memnstr_str(&address, SL(","))) {
			/**
			 * The client address has multiples parts, only return the first part
			 */
			phalcon_fast_explode_str(&addresses, SL(","), &address);

			phalcon_array_fetch_long(&first, &addresses, 0, PH_NOISY);
			RETURN_CTORW(&first);
		}

		RETURN_CTORW(&address);
	}

	RETURN_FALSE;
}
Example #17
0
/**
 * Returns the cookie's value
 *
 * @param string|array $filters
 * @param string $defaultValue
 * @return mixed
 */
PHP_METHOD(Phalcon_Http_Cookie, getValue)
{
	zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL, *readed, *name, *_COOKIE, value = {}, *encryption;
	zval service = {}, crypt = {}, decrypted_value = {}, filter = {};

	phalcon_fetch_params(0, 0, 2, &filters, &default_value);

	if (!filters) {
		filters = &PHALCON_GLOBAL(z_null);
	}

	if (!default_value) {
		default_value = &PHALCON_GLOBAL(z_null);
	}

	restored = phalcon_read_property(getThis(), SL("_restored"), PH_NOISY);
	if (!zend_is_true(restored)) {
		PHALCON_CALL_METHODW(NULL, getThis(), "restore");
	}

	dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'filter' service");
		return;
	}

	readed = phalcon_read_property(getThis(), SL("_readed"), PH_NOISY);
	if (PHALCON_IS_FALSE(readed)) {
		name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY);

		_COOKIE = phalcon_get_global_str(SL("_COOKIE"));
		if (phalcon_array_isset_fetch(&value, _COOKIE, name)) {
			encryption = phalcon_read_property(getThis(), SL("_useEncryption"), PH_NOISY);
			if (zend_is_true(encryption) && PHALCON_IS_NOT_EMPTY(&value)) {
				ZVAL_STRING(&service, "crypt");

				PHALCON_CALL_METHODW(&crypt, dependency_injector, "getshared", &service);
				PHALCON_VERIFY_INTERFACEW(&crypt, phalcon_cryptinterface_ce);

				/** 
				 * Decrypt the value also decoding it with base64
				 */
				PHALCON_CALL_METHODW(&decrypted_value, &crypt, "decryptbase64", &value);
			} else {
				PHALCON_CPY_WRT_CTOR(&decrypted_value, &value);
			}

			/** 
			 * Update the decrypted value
			 */
			phalcon_update_property_this(getThis(), SL("_value"), &decrypted_value);
			if (Z_TYPE_P(filters) != IS_NULL) {
				phalcon_return_property(&filter, getThis(), SL("_filter"));
				if (Z_TYPE(filter) != IS_OBJECT) {
					ZVAL_STRING(&service, ISV(filter));

					PHALCON_CALL_METHODW(&filter, dependency_injector, "getshared", &service);
					PHALCON_VERIFY_INTERFACEW(&filter, phalcon_filterinterface_ce);
					phalcon_update_property_this(getThis(), SL("_filter"), &filter);
				}

				PHALCON_RETURN_CALL_METHOD(&filter, "sanitize", &decrypted_value, filters);
				return;
			}

			/** 
			 * Return the value without filtering
			 */

			RETURN_CTORW(&decrypted_value);
		}

		RETURN_CTORW(default_value);
	}

	phalcon_return_property(&value, getThis(), SL("_value"));

	RETURN_CTORW(&value);
}