示例#1
0
文件: debug.c 项目: Myleft/cphalcon
/**
 * Escapes a string with htmlentities
 *
 * @param string $value
 * @return string
 */
PHP_METHOD(Phalcon_Debug, _escapeString){

	zval *value, *charset, *replaced_value;

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

	if (Z_TYPE_P(value) == IS_STRING) {
		zval line_break;
		zval escaped_line_break;

		charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC);

		INIT_ZVAL(line_break);
		ZVAL_STRING(&line_break, "\n", 0);

		INIT_ZVAL(escaped_line_break);
		ZVAL_STRING(&escaped_line_break, "\\n", 0);

		ALLOC_INIT_ZVAL(replaced_value);
		phalcon_fast_str_replace(replaced_value, &line_break, &escaped_line_break, value);
		phalcon_htmlentities(return_value, replaced_value, NULL, charset TSRMLS_CC);
		phalcon_ptr_dtor(&replaced_value);
		return;
	}

	RETURN_ZVAL(value, 1, 0);
}
示例#2
0
/* {{{ mlfi_body()
*/
static sfsistat mlfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
{
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_body", 0);
	ZVAL_STRINGL(param[0], (char*)bodyp, len, 1); /*alex*/
	
	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_BODY;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	
	zval_ptr_dtor(param);	

	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
示例#3
0
/* {{{ mlfi_header()
*/
static sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
{
	zval function_name, retval, *param[2];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	ALLOC_ZVAL(param[1]);
	INIT_PZVAL(param[0]);
	INIT_PZVAL(param[1]);
	
	ZVAL_STRING(&function_name, "milter_header", 0);
	ZVAL_STRING(param[0], headerf, 1);
	ZVAL_STRING(param[1], headerv, 1);

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_HEADER;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 2, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	
	zval_ptr_dtor(&param[0]);
	zval_ptr_dtor(&param[1]);	
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}
	
	return SMFIS_CONTINUE;
}
示例#4
0
/* {{{ mlfi_connect()
*/
static sfsistat	mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
{
	zend_file_handle file_handle;
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* request startup */
	if (php_request_startup(TSRMLS_C)==FAILURE) {
		SG(headers_sent) = 1;
		SG(request_info).no_headers = 1;
		php_request_shutdown((void *) 0);

		return SMFIS_TEMPFAIL;
	}
	
	/* disable headers */
	SG(headers_sent) = 1;
	SG(request_info).no_headers = 1;
	
	if (filename == NULL) {
		php_printf("No input file specified");
		return SMFIS_TEMPFAIL;
	}
	
	if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) {
		php_printf("Could not open input file: %s\n", filename);
		return SMFIS_TEMPFAIL;
	}

	file_handle.type = ZEND_HANDLE_FP;
	file_handle.filename = filename;
	file_handle.free_filename = 0;
	file_handle.opened_path = NULL;

	php_execute_script(&file_handle TSRMLS_CC);
	
	/* call userland */
	INIT_ZVAL(function_name);

	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_connect", 0);
	ZVAL_STRING(param[0], hostname, 1);

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_CONNECT;

	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	zval_ptr_dtor(param);
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}
	
	return SMFIS_CONTINUE;
}
示例#5
0
/* {{{ mlfi_envform()
*/
static sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv)
{
	zval function_name, retval, *param[1];
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	
	ALLOC_ZVAL(param[0]);
	INIT_PZVAL(param[0]);

	ZVAL_STRING(&function_name, "milter_envfrom", 0);
	array_init(param[0]);

	while (*argv) {
		add_next_index_string(param[0], *argv, 1);
		argv++;
	}

	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_ENVFROM;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 1, param TSRMLS_CC);

	MG(state) = MLFI_NONE;
	zval_ptr_dtor(param);
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
示例#6
0
static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(phalcon)
{
	TSRMLS_FETCH();

#ifndef PHALCON_RELEASE
	if (!CG(unclean_shutdown)) {
		//phalcon_verify_permanent_zvals(1 TSRMLS_CC);
	}
#endif

	if (CG(unclean_shutdown)) {
		zend_phalcon_globals *pg = PHALCON_VGLOBAL;

		INIT_ZVAL(*pg->z_null);
		Z_ADDREF_P(pg->z_null);

		INIT_PZVAL(pg->z_false);
		Z_ADDREF_P(pg->z_false);
		ZVAL_FALSE(pg->z_false);

		INIT_PZVAL(pg->z_true);
		Z_ADDREF_P(pg->z_true);
		ZVAL_TRUE(pg->z_true);

		INIT_PZVAL(pg->z_zero);
		Z_ADDREF_P(pg->z_zero);
		ZVAL_LONG(pg->z_zero, 0);

		INIT_PZVAL(pg->z_one);
		Z_ADDREF_P(pg->z_one);
		ZVAL_LONG(pg->z_one, 1);
	}

	return SUCCESS;
}
示例#7
0
/* {{{ mlfi_close()
*/
static sfsistat mlfi_close(SMFICTX *ctx)
{
	int ret = SMFIS_CONTINUE;
	zval function_name, retval;
	int status;
	TSRMLS_FETCH();

	/* call userland */
	INIT_ZVAL(function_name);
	ZVAL_STRING(&function_name, "milter_close", 0);
	
	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_CLOSE;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

	MG(state) = MLFI_NONE;
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		ret = Z_LVAL(retval);
	}
	
	php_request_shutdown((void *) 0);

	return ret;
}
示例#8
0
/* {{{ Init Milter
*/
static int mlfi_init()
{
	int ret = 0;
	zend_file_handle file_handle;
	zval function_name, retval;
	int status;
	TSRMLS_FETCH();

	/* request startup */
	if (php_request_startup(TSRMLS_C)==FAILURE) {
		SG(headers_sent) = 1;
		SG(request_info).no_headers = 1;
		php_request_shutdown((void *) 0);

		return -1;
	}
	
	/* disable headers */
	SG(headers_sent) = 1;
	SG(request_info).no_headers = 1;
	 
	if (filename == NULL) {
		php_printf("No input file specified");
		return SMFIS_TEMPFAIL;
	}

	if (!(file_handle.handle.fp = VCWD_FOPEN(filename, "rb"))) {
		php_printf("Could not open input file: %s\n", filename);
		return SMFIS_TEMPFAIL;
	}

	file_handle.type = ZEND_HANDLE_FP;
	file_handle.filename = filename;
	file_handle.free_filename = 0;
	file_handle.opened_path = NULL;

	php_execute_script(&file_handle TSRMLS_CC);
	
	/* call userland */
	INIT_ZVAL(function_name);

	ZVAL_STRING(&function_name, "milter_init", 0);

	/* set the milter context for possible use in API functions */
	MG(state) = MLFI_INIT;

	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL TSRMLS_CC);

	MG(state) = MLFI_NONE;
	MG(initialized) = 1;

	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		ret = Z_LVAL(retval);
	}
	
	php_request_shutdown((void *) 0);
	
	return ret;
}
示例#9
0
文件: zend_closures.c 项目: 0/php-src
/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ] )
   Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind) /* {{{ */
{
	zval *newthis, *zclosure, *scope_arg = NULL;
	zend_closure *closure;
	zend_class_entry *ce, **ce_p;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
		RETURN_NULL();
	}

	closure = (zend_closure *)zend_object_store_get_object(zclosure TSRMLS_CC);	

	if ((newthis != NULL) && (closure->func.common.fn_flags & ZEND_ACC_STATIC)) {
		zend_error(E_WARNING, "Cannot bind an instance to a static closure");
	}

	if (scope_arg != NULL) { /* scope argument was given */
		if (IS_ZEND_STD_OBJECT(*scope_arg)) {
			ce = Z_OBJCE_P(scope_arg);
		} else if (Z_TYPE_P(scope_arg) == IS_NULL) {
			ce = NULL;
		} else {
			char *class_name;
			int class_name_len;
			zval tmp_zval;
			INIT_ZVAL(tmp_zval);

			if (Z_TYPE_P(scope_arg) == IS_STRING) {
				class_name = Z_STRVAL_P(scope_arg);
				class_name_len = Z_STRLEN_P(scope_arg);
			} else {
				tmp_zval = *scope_arg;
				zval_copy_ctor(&tmp_zval);
				convert_to_string(&tmp_zval);
				class_name = Z_STRVAL(tmp_zval);
				class_name_len = Z_STRLEN(tmp_zval);
			}

			if ((class_name_len == sizeof("static") - 1) &&
				(memcmp("static", class_name, sizeof("static") - 1) == 0)) {
				ce = closure->func.common.scope;
			}
			else if (zend_lookup_class_ex(class_name, class_name_len, NULL, 1, &ce_p TSRMLS_CC) == FAILURE) {
				zend_error(E_WARNING, "Class '%s' not found", class_name);
				zval_dtor(&tmp_zval);
				RETURN_NULL();
			} else {
				ce = *ce_p;
			}
			zval_dtor(&tmp_zval);
		}
	} else { /* scope argument not given; do not change the scope by default */
		ce = closure->func.common.scope;
	}

	zend_create_closure(return_value, &closure->func, ce, newthis TSRMLS_CC);
}
示例#10
0
/**
 * Escapes a HTML attribute string
 *
 * @param string $attribute
 * @return string
 */
PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){

	zval *attribute, *encoding;

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

	if (Z_TYPE_P(attribute) == IS_STRING && zend_is_true(attribute)) {
		zval quoting;

		INIT_ZVAL(quoting);
		ZVAL_LONG(&quoting, ENT_QUOTES);

		encoding = phalcon_fetch_nproperty_this(this_ptr, SL("_encoding"), PH_NOISY TSRMLS_CC);

		phalcon_htmlspecialchars(return_value, attribute, &quoting, encoding TSRMLS_CC);
		return;
	}

	RETURN_ZVAL(attribute, 1, 0);
}
示例#11
0
static const char* phalcon_http_request_getmethod_helper(TSRMLS_D)
{
	zval **value;
	const char *method = SG(request_info).request_method;
	if (unlikely(!method)) {
		zval *_SERVER, key;

		INIT_ZVAL(key);
		ZVAL_STRING(&key, "REQUEST_METHOD", 0);

		phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC);
		value = phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_NA);
		if (value && Z_TYPE_PP(value) == IS_STRING) {
			return Z_STRVAL_PP(value);
		}

		return "";
	}

	return method;
}
示例#12
0
/* {{{ mlfi_abort()
*/
static sfsistat mlfi_abort(SMFICTX *ctx)
{
	zval function_name, retval;
	int status;

	/* call userland */
	INIT_ZVAL(function_name);
	ZVAL_STRING(&function_name, "milter_abort", 0);
	
	/* set the milter context for possible use in API functions */
	MG(ctx) = ctx;
	MG(state) = MLFI_ABORT;
	
	status = call_user_function(CG(function_table), NULL, &function_name, &retval, 0, NULL);

	MG(state) = MLFI_NONE;
	
	if (status == SUCCESS && Z_TYPE(retval) == IS_LONG) {
		return Z_LVAL(retval);
	}

	return SMFIS_CONTINUE;
}
示例#13
0
int main(int argc, char ** argv)
{
	zval t1, * pt2, ** ppt3;

	INIT_ZVAL(t1);
	Z_TYPE(t1) = IS_LONG;
	Z_LVAL(t1) = 54321;
	zval_print(&t1);

	ALLOC_INIT_ZVAL(pt2);
	ZVAL_STRING(pt2, "this is string val.", 1);
	zval_print(pt2);

	*ppt3 = pt2;
	ZVAL_ADDREF(*ppt3);
	zval_print(*ppt3);

	//zval_copy_ctor(*ppt3);
	SEPARATE_ZVAL(ppt3);
	zval_print(*ppt3);
	zval_print(pt2);

	Z_TYPE(t1) = IS_BOOL;
	Z_LVAL(t1) = 1;
	zval_print(&t1);
	Z_TYPE(t1) = IS_DOUBLE;
	Z_DVAL(t1) = 20.12;
	zval_print(&t1);

	/*
	zval_dtor(pt2);
	FREE_ZVAL(pt2);
	zval_dtor(*ppt3);
	FREE_ZVAL(*ppt3);
	*/
}
示例#14
0
/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ] )
   Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
	zval *newthis, *zclosure, *scope_arg = NULL;
	zend_closure *closure;
	zend_class_entry *ce, **ce_p;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
		RETURN_NULL();
	}

	closure = (zend_closure *)zend_object_store_get_object(zclosure TSRMLS_CC);

	if ((newthis != NULL) && (closure->func.common.fn_flags & ZEND_ACC_STATIC)) {
		zend_error(E_WARNING, "Cannot bind an instance to a static closure");
	}

	if (newthis == NULL && !(closure->func.common.fn_flags & ZEND_ACC_STATIC)
			&& closure->func.common.scope && closure->func.type == ZEND_INTERNAL_FUNCTION) {
		zend_error(E_WARNING, "Cannot unbind $this of internal method");
		return;
	}

	if (scope_arg != NULL) { /* scope argument was given */
		if (IS_ZEND_STD_OBJECT(*scope_arg)) {
			ce = Z_OBJCE_P(scope_arg);
		} else if (Z_TYPE_P(scope_arg) == IS_NULL) {
			ce = NULL;
		} else {
			char *class_name;
			int class_name_len;
			zval tmp_zval;
			INIT_ZVAL(tmp_zval);

			if (Z_TYPE_P(scope_arg) == IS_STRING) {
				class_name = Z_STRVAL_P(scope_arg);
				class_name_len = Z_STRLEN_P(scope_arg);
			} else {
				tmp_zval = *scope_arg;
				zval_copy_ctor(&tmp_zval);
				convert_to_string(&tmp_zval);
				class_name = Z_STRVAL(tmp_zval);
				class_name_len = Z_STRLEN(tmp_zval);
			}

			if ((class_name_len == sizeof("static") - 1) &&
				(memcmp("static", class_name, sizeof("static") - 1) == 0)) {
				ce = closure->func.common.scope;
			}
			else if (zend_lookup_class_ex(class_name, class_name_len, NULL, 1, &ce_p TSRMLS_CC) == FAILURE) {
				zend_error(E_WARNING, "Class '%s' not found", class_name);
				zval_dtor(&tmp_zval);
				RETURN_NULL();
			} else {
				ce = *ce_p;
			}
			zval_dtor(&tmp_zval);
		}
	} else { /* scope argument not given; do not change the scope by default */
		ce = closure->func.common.scope;
	}

	/* verify that we aren't binding internal function to a wrong scope */
	if (closure->func.type == ZEND_INTERNAL_FUNCTION && closure->func.common.scope != NULL) {
		if (ce && !instanceof_function(ce, closure->func.common.scope TSRMLS_CC)) {
			zend_error(E_WARNING, "Cannot bind function %s::%s to scope class %s", closure->func.common.scope->name, closure->func.common.function_name, ce->name);
			return;
		}
		if (ce && newthis && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0 &&
				!instanceof_function(Z_OBJCE_P(newthis), closure->func.common.scope TSRMLS_CC)) {
			zend_error(E_WARNING, "Cannot bind internal method %s::%s() to object of class %s", closure->func.common.scope->name, closure->func.common.function_name, Z_OBJCE_P(newthis)->name);
			return;
		}
	}

	zend_create_closure(return_value, &closure->func, ce, newthis TSRMLS_CC);
}
示例#15
0
文件: money.c 项目: Peekmo/money
static int money_handler_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2)
{
	zval *currency1 = NULL, *currency2 = NULL, *currency_result = NULL;

	long amount1, amount2, amount_result;

	switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
		case TYPE_PAIR(IS_OBJECT, IS_OBJECT):
			if (!instanceof_function(Z_OBJCE_P(op1), money_ce) || !instanceof_function(Z_OBJCE_P(op2), money_ce)) {
				return FAILURE;
			}
			currency1 = zend_read_property(Z_OBJCE_P(op1), op1, MONEY_PROP_CURRENCY_WS, 0);
			currency2 = zend_read_property(Z_OBJCE_P(op2), op2, MONEY_PROP_CURRENCY_WS, 0);

			if (Z_OBJ_HANDLER_P(currency1, compare_objects)(currency1, currency2) != 0) {
				zend_throw_exception(CurrencyMismatchException_ce, "Currencies don't match", 0);
				ZVAL_NULL(result);
				return SUCCESS;
			}
			amount1         = Z_LVAL_P(zend_read_property(Z_OBJCE_P(op1), op1, MONEY_PROP_AMOUNT_WS, 0));
			amount2         = Z_LVAL_P(zend_read_property(Z_OBJCE_P(op2), op2, MONEY_PROP_AMOUNT_WS, 0));
			currency_result = currency1;
		break;

		case TYPE_PAIR(IS_LONG, IS_OBJECT): /* negate */
			if (!instanceof_function(Z_OBJCE_P(op2), money_ce)) {
				return FAILURE;
			}
			if (Z_LVAL_P(op1) != 0) {
				return FAILURE; /* I said negate */
			}
			amount1         = 0;
			amount2         = Z_LVAL_P(zend_read_property(Z_OBJCE_P(op2), op2, MONEY_PROP_AMOUNT_WS, 0));
			currency_result = zend_read_property(Z_OBJCE_P(op2), op2, MONEY_PROP_CURRENCY_WS, 0);
		break;
		default :
			return FAILURE;
	}

	INIT_ZVAL(*result);

	switch (opcode) {
		case ZEND_ADD:
			if (UNEXPECTED((amount1 & LONG_SIGN_MASK) == (amount2 & LONG_SIGN_MASK)
				   && (amount1 & LONG_SIGN_MASK) != ((amount1 + amount2) & LONG_SIGN_MASK))) {
					zend_throw_exception(spl_ce_OverflowException, "Integer overflow", 0);
					return FAILURE;
			}
			amount_result = amount1 + amount2;
			goto success;
		break;
		case ZEND_SUB:
			{
				amount_result = amount1 - amount2;
				if (amount_result == LONG_MIN) {
					zend_throw_exception(spl_ce_OverflowException, "Integer negative overflow", 0);
					return FAILURE;
				}
				goto success;
			}
		break;
		default:
			return FAILURE;
		break;
	}

success:
	CREATE_NEW_MONEY_OBJ(result, amount_result, currency_result);
	return SUCCESS;
}
示例#16
0
文件: adapter.c 项目: 9466/cphalcon
/**
 * Set the background color of an image. This is only useful for images
 * with alpha transparency.
 *
 * @param string $color hexadecimal color value
 * @param int $opacity background opacity: 0-100
 * @return Phalcon\Image\Adapter
 */
PHP_METHOD(Phalcon_Image_Adapter, background) {

    zval *color, *opacity = NULL;
    zval *tmp_color = NULL, *r = NULL, *g = NULL, *b = NULL;
    long i;
    char *c;
    zval tmp;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 1, 1, &color, &opacity);

    if (Z_TYPE_P(color) != IS_STRING) {
        PHALCON_SEPARATE_PARAM(color);
        convert_to_string(color);
    }

    c = Z_STRVAL_P(color);

    if (Z_STRLEN_P(color) > 0 && c[0] == '#') {
        PHALCON_INIT_NVAR(tmp_color);
        phalcon_substr(tmp_color, color, 1, 0);
    } else {
        PHALCON_CPY_WRT_CTOR(tmp_color, color);
    }

    if (Z_STRLEN_P(tmp_color) == 3) {
        /* Convert RGB to RRGGBB */
        c = Z_STRVAL_P(tmp_color);
        if (!IS_INTERNED(c)) {
            STR_REALLOC(c, 7);
        }
        else {
            char* tmp = ecalloc(7, 1);
            memcpy(tmp, c, Z_STRLEN_P(tmp_color));
            c = tmp;
        }

        c[6] = '\0';
        c[5] = c[2];
        c[4] = c[2];
        c[3] = c[1];
        c[2] = c[1];
        c[1] = c[0];
        ZVAL_STRING(tmp_color, c, 0);
    }

    if (Z_STRLEN_P(tmp_color) < 6) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "Color is not valid");
        return;
    }

    INIT_ZVAL(tmp);

    Z_TYPE(tmp) = IS_STRING;
    ZVAL_STRINGL(&tmp, Z_STRVAL_P(tmp_color), 2, 0);

    PHALCON_INIT_NVAR(r);
    _php_math_basetozval(&tmp, 16, r);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_NVAR(g);
    _php_math_basetozval(&tmp, 16, g);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_NVAR(b);
    _php_math_basetozval(&tmp, 16, b);

    if (!opacity) {
        PHALCON_INIT_NVAR(opacity);
        ZVAL_LONG(opacity, 100);
    } else {
        PHALCON_SEPARATE_PARAM(opacity);

        i = phalcon_get_intval(opacity);

        if (i < 1) {
            PHALCON_INIT_NVAR(opacity);
            ZVAL_LONG(opacity, 1);
        } else if (i > 100) {
            PHALCON_INIT_NVAR(opacity);
            ZVAL_LONG(opacity, 100);
        }
    }

    PHALCON_CALL_METHOD(NULL, this_ptr, "_background", r, g, b, opacity);

    RETURN_THIS();
}
示例#17
0
文件: route.c 项目: 11mariom/cphalcon
/**
 * Replaces placeholders from pattern returning a valid PCRE regular expression
 *
 * @param string $pattern
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){

	zval *pattern, *compiled_pattern = NULL, *id_pattern;
	zval wildcard, *pattern_copy = NULL, *params_pattern;
	zval *int_pattern;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &pattern);
	
	PHALCON_CPY_WRT(compiled_pattern, pattern);
	
	/** 
	 * If a pattern contains ':', maybe there are placeholders to replace
	 */
	if (phalcon_memnstr_str(pattern, SL(":"))) {
	
		/** 
		 * This is a pattern for valid identifiers
		 */
		PHALCON_INIT_VAR(id_pattern);
		ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_\\-]+)", 1);
	
		/** 
		 * Replace the module part
		 */
		if (phalcon_memnstr_str(pattern, SL("/:module"))) {
			INIT_ZVAL(wildcard);
			ZVAL_STRING(&wildcard, "/:module", 0);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy);
		}
	
		/** 
		 * Replace the controller placeholder
		 */
		if (phalcon_memnstr_str(pattern, SL("/:controller"))) {
			INIT_ZVAL(wildcard);
			ZVAL_STRING(&wildcard, "/:controller", 0);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy);
		}
	
		/** 
		 * Replace the namespace placeholder
		 */
		if (phalcon_memnstr_str(pattern, SL("/:namespace"))) {
			INIT_ZVAL(wildcard)
			ZVAL_STRING(&wildcard, "/:namespace", 0);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy);
		}
	
		/** 
		 * Replace the action placeholder
		 */
		if (phalcon_memnstr_str(pattern, SL("/:action"))) {
			INIT_ZVAL(wildcard);
			ZVAL_STRING(&wildcard, "/:action", 0);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, id_pattern, pattern_copy);
		}
	
		/** 
		 * Replace the params placeholder
		 */
		if (phalcon_memnstr_str(pattern, SL("/:params"))) {
			INIT_ZVAL(wildcard);
			ZVAL_STRING(&wildcard, "/:params", 0);
	
			PHALCON_INIT_VAR(params_pattern);
			ZVAL_STRING(params_pattern, "(/.*)*", 1);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, params_pattern, pattern_copy);
		}
	
		/** 
		 * Replace the int placeholder
		 */
		if (phalcon_memnstr_str(pattern, SL("/:int"))) {
			INIT_ZVAL(wildcard);
			ZVAL_STRING(&wildcard, "/:int", 0);
	
			PHALCON_INIT_VAR(int_pattern);
			ZVAL_STRING(int_pattern, "/([0-9]+)", 1);
			PHALCON_CPY_WRT(pattern_copy, compiled_pattern);
	
			PHALCON_INIT_NVAR(compiled_pattern);
			phalcon_fast_str_replace(compiled_pattern, &wildcard, int_pattern, pattern_copy);
		}
	}
	
	/** 
	 * Check if the pattern has parantheses in order to add the regex delimiters
	 */
	if (phalcon_memnstr_str(compiled_pattern, SL("("))) {
		PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#");
		RETURN_MM();
	}
	
	/** 
	 * Square brackets are also checked
	 */
	if (phalcon_memnstr_str(compiled_pattern, SL("["))) {
		PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#");
		RETURN_MM();
	}
	
	RETURN_CCTOR(compiled_pattern);
}
示例#18
0
static void call_php(char *name, PARAMDSC *r, int argc, PARAMDSC **argv)
{
	do {
		zval callback, args[4], *argp[4], return_value;
		PARAMVARY *res = (PARAMVARY*)r->dsc_address;
		int i;

		INIT_ZVAL(callback);
		ZVAL_STRING(&callback,name,0);

		LOCK();
		
		/* check if the requested function exists */
		if (!zend_is_callable(&callback, 0, NULL TSRMLS_CC)) {
			break;
		}
		
		UNLOCK();
	
		/* create the argument array */
		for (i = 0; i < argc; ++i) {

			INIT_ZVAL(args[i]);
			argp[i] = &args[i];
			
			/* test arg for null */
			if (argv[i]->dsc_flags & DSC_null) {
				ZVAL_NULL(argp[i]);
				continue;
			}

			switch (argv[i]->dsc_dtype) {
				ISC_INT64 l;
				struct tm t;
				char const *fmt;
				char d[64];

				case dtype_cstring:
					ZVAL_STRING(argp[i], (char*)argv[i]->dsc_address,0);
					break;

				case dtype_text:
					ZVAL_STRINGL(argp[i], (char*)argv[i]->dsc_address, argv[i]->dsc_length,0);
					break;

				case dtype_varying:
					ZVAL_STRINGL(argp[i], ((PARAMVARY*)argv[i]->dsc_address)->vary_string,
						((PARAMVARY*)argv[i]->dsc_address)->vary_length,0);
					break;

				case dtype_short:
					if (argv[i]->dsc_scale == 0) {
						ZVAL_LONG(argp[i], *(short*)argv[i]->dsc_address);
					} else {
						ZVAL_DOUBLE(argp[i],
							((double)*(short*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
					}
					break;

				case dtype_long:
					if (argv[i]->dsc_scale == 0) {
						ZVAL_LONG(argp[i], *(ISC_LONG*)argv[i]->dsc_address);
					} else {
						ZVAL_DOUBLE(argp[i],
							((double)*(ISC_LONG*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
					}
					break;

				case dtype_int64:
					l = *(ISC_INT64*)argv[i]->dsc_address;

					if (argv[i]->dsc_scale == 0 && l <= LONG_MAX && l >= LONG_MIN) {
						ZVAL_LONG(argp[i], (long)l);
					} else {
						ZVAL_DOUBLE(argp[i], ((double)l)/scales[-argv[i]->dsc_scale]);
					}
					break;

				case dtype_real:
					ZVAL_DOUBLE(argp[i], *(float*)argv[i]->dsc_address);
					break;

				case dtype_double:
					ZVAL_DOUBLE(argp[i], *(double*)argv[i]->dsc_address);
					break;

				case dtype_sql_date:
					isc_decode_sql_date((ISC_DATE*)argv[i]->dsc_address, &t);
					ZVAL_STRINGL(argp[i], d, strftime(d, sizeof(d), INI_STR("ibase.dateformat"), &t),1); 
					break;

				case dtype_sql_time:
					isc_decode_sql_time((ISC_TIME*)argv[i]->dsc_address, &t);
					ZVAL_STRINGL(argp[i], d, strftime(d, sizeof(d), INI_STR("ibase.timeformat"), &t),1); 
					break;

				case dtype_timestamp:
					isc_decode_timestamp((ISC_TIMESTAMP*)argv[i]->dsc_address, &t);
					ZVAL_STRINGL(argp[i], d, strftime(d, sizeof(d), INI_STR("ibase.timestampformat"), &t),1); 
					break;
			}
		}

		LOCK();

		/* now call the function */
		if (FAILURE == call_user_function(EG(function_table), NULL,
				&callback, &return_value, argc, argp TSRMLS_CC)) {
			UNLOCK();
			break;
		}
		
		UNLOCK();

		for (i = 0; i < argc; ++i) {
			switch (argv[i]->dsc_dtype) {
				case dtype_sql_date:
				case dtype_sql_time:
				case dtype_timestamp:
					zval_dtor(argp[i]);
					
			}
		}

		/* return whatever type we got back from the callback: let DB handle conversion */
		switch (Z_TYPE(return_value)) {

			case IS_LONG:
				r->dsc_dtype = dtype_long;
				*(long*)r->dsc_address = Z_LVAL(return_value);
				r->dsc_length = sizeof(long);
				break;

			case IS_DOUBLE:
				r->dsc_dtype = dtype_double;
				*(double*)r->dsc_address = Z_DVAL(return_value);
				r->dsc_length = sizeof(double);
				break;

			case IS_NULL:
				r->dsc_flags |= DSC_null;
				break;

			default:
				convert_to_string(&return_value);

			case IS_STRING:
				r->dsc_dtype = dtype_varying;
				memcpy(res->vary_string, Z_STRVAL(return_value),
					(res->vary_length = min(r->dsc_length-2,Z_STRLEN(return_value))));
				r->dsc_length = res->vary_length+2;
				break;
		}
				
		zval_dtor(&return_value);

		return;

	} while (0);
	
	/**
	* If we end up here, we should report an error back to the DB engine, but
	* that's not possible. We can however report it back to PHP.
	*/
	LOCK();
	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error calling function '%s' from database", name);
	UNLOCK();
}
示例#19
0
文件: adapter.c 项目: 9466/cphalcon
/**
 * Add a text to an image with a specified opacity.
 *
 * @param string text
 * @param int $offset_x offset from the left, If less than 0 offset from the right, If true right the x offset
 * @param int $offset_y offset from the top, If less than 0 offset from the bottom, If true bottom the Y offset
 * @param int $opacity opacity of text: 1-100
 * @param string $color hexadecimal color value
 * @param int $size font pointsize
 * @param string $fontfile font path
 * @return Phalcon\Image\Adapter
 */
PHP_METHOD(Phalcon_Image_Adapter, text) {

    zval **text, **ofs_x = NULL, **ofs_y = NULL, **op = NULL, **fontcolor = NULL, **fontsize = NULL, **fontfile = NULL;
    zval *offset_x = NULL, *offset_y = NULL, *opacity, *color, *size;
    zval *r, *g, *b;
    char *c;
    zval tmp;

    phalcon_fetch_params_ex(1, 6, &text, &ofs_x, &ofs_y, &op, &fontcolor, &fontsize, &fontfile);

    PHALCON_MM_GROW();

    if (!ofs_x || Z_TYPE_PP(ofs_x) == IS_NULL) {
        PHALCON_INIT_VAR(offset_x);
        ZVAL_FALSE(offset_x);
    }
    else {
        PHALCON_CPY_WRT_CTOR(offset_x, *ofs_x);
    }

    if (!ofs_y || Z_TYPE_PP(ofs_y) == IS_NULL) {
        PHALCON_INIT_VAR(offset_y);
        ZVAL_FALSE(offset_y);
    }
    else {
        PHALCON_CPY_WRT_CTOR(offset_y, *ofs_y);
    }

    PHALCON_INIT_VAR(opacity);
    if (!op || Z_TYPE_PP(op) == IS_NULL) {
        ZVAL_LONG(opacity, 100);
    } else {
        PHALCON_ENSURE_IS_LONG(op);
        if (Z_LVAL_PP(op) < 1) {
            ZVAL_LONG(opacity, 1);
        } else if (Z_LVAL_PP(op) > 100) {
            ZVAL_LONG(opacity, 100);
        } else {
            ZVAL_LONG(opacity, Z_LVAL_PP(op));
        }
    }

    PHALCON_INIT_VAR(color);
    if (!fontcolor || Z_TYPE_PP(fontcolor) == IS_NULL) {
        ZVAL_STRING(color, "000000", 1);
    }
    else {
        PHALCON_ENSURE_IS_STRING(fontcolor);
        if (Z_STRLEN_PP(fontcolor) > 1 && Z_STRVAL_PP(fontcolor)[0] == '#') {
            phalcon_substr(color, *fontcolor, 1, 0);
        }
        else {
            ZVAL_STRINGL(color, Z_STRVAL_PP(fontcolor), Z_STRLEN_PP(fontcolor), 1);
        }
    }

    PHALCON_INIT_VAR(size);
    if (!fontsize || Z_TYPE_PP(fontsize) == IS_NULL) {
        ZVAL_LONG(size, 12);
    }
    else {
        PHALCON_ENSURE_IS_LONG(fontsize);
        ZVAL_LONG(size, Z_LVAL_PP(fontsize));
    }

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

    if (Z_STRLEN_P(color) == 3) {
        /* Convert RGB to RRGGBB */
        c = Z_STRVAL_P(color);
        assert(!IS_INTERNED(c));
        STR_REALLOC(c, 7);
        c[6] = '\0';
        c[5] = c[2];
        c[4] = c[2];
        c[3] = c[1];
        c[2] = c[1];
        c[1] = c[0];
        ZVAL_STRING(color, c, 0);
    }

    if (Z_STRLEN_P(color) < 6) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
        return;
    }

    INIT_ZVAL(tmp);

    Z_TYPE(tmp) = IS_STRING;
    ZVAL_STRINGL(&tmp, Z_STRVAL_P(color), 2, 0);

    PHALCON_INIT_VAR(r);
    _php_math_basetozval(&tmp, 16, r);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_VAR(g);
    _php_math_basetozval(&tmp, 16, g);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_VAR(b);
    _php_math_basetozval(&tmp, 16, b);

    PHALCON_CALL_METHOD(NULL, this_ptr, "_text", *text, offset_x, offset_y, opacity, r, g, b, size, *fontfile);

    RETURN_THIS();
}