Esempio n. 1
0
void pdo_sqlsrv_retrieve_context_error( sqlsrv_error const* last_error, zval* pdo_zval )
{
    if( last_error ) {

        // SQLSTATE is already present in the zval.
        add_next_index_long( pdo_zval, last_error->native_code );
        add_next_index_string( pdo_zval, reinterpret_cast<char*>( last_error->native_message ), 1 /*dup*/ );
    }
    else {
        add_next_index_null( pdo_zval ); /* native code */
        add_next_index_null( pdo_zval ); /* native message */
    }

}
/* {{{ Mosquitto\Message::tokeniseTopic() */
PHP_METHOD(Mosquitto_Message, tokeniseTopic)
{
	char *topic = NULL, **topics = NULL;
	int topic_len = 0, retval = 0, count = 0, i = 0;

	PHP_MOSQUITTO_ERROR_HANDLING();
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &topic, &topic_len) == FAILURE) {
		PHP_MOSQUITTO_RESTORE_ERRORS();
		return;
	}
	PHP_MOSQUITTO_RESTORE_ERRORS();

	retval = mosquitto_sub_topic_tokenise(topic, &topics, &count);

	if (retval == MOSQ_ERR_NOMEM) {
		zend_throw_exception_ex(mosquitto_ce_exception, 0 TSRMLS_CC, "Failed to tokenise topic");
		return;
	}

	array_init(return_value);
	for (i = 0; i < count; i++) {
		if (topics[i] == NULL) {
			add_next_index_null(return_value);
		} else {
			add_next_index_string(return_value, topics[i], 1);
		}
	}

	mosquitto_sub_topic_tokens_free(&topics, count);
}
Esempio n. 3
0
    void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray)
    {
        if (value->IsNull() || value->IsUndefined())
        {
            add_next_index_null(phpArray);
        }
        else if (value->IsBool())
        {
            if (value->ToBool())
                add_next_index_bool(phpArray, 1);
            else
                add_next_index_bool(phpArray, 0);
        }
        else if (value->IsNumber())
        {
            /* No way to check whether the number is an
               integer or a double here. All Kroll numbers
               are doubles, so return a double. This could
               cause some PHP to function incorrectly if it's
               doing strict type checking. */
            add_next_index_double(phpArray, value->ToNumber());
        }
        else if (value->IsString())
        {
            add_next_index_stringl(phpArray, (char *) value->ToString(), strlen(value->ToString()), 1);
        }
        else if (value->IsObject())
        {
            /*TODO: Implement*/
        }
        else if (value->IsMethod())
        {
            /*TODO: Implement*/
        }
        else if (value->IsList())
        {
            zval *phpValue;
            AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>();
            if (!pl.isNull())
                phpValue = pl->ToPHP();
            else
                phpValue = PHPUtils::ToPHPValue(value);

            add_next_index_zval(phpArray, phpValue);
        }
    }
Esempio n. 4
0
ZEND_METHOD(Vedis, eval)
{
    char *cmd;
    int cmd_len;
    int rc;
    php_vedis_object_t *intern;
    vedis_value *result = NULL;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
                              &cmd, &cmd_len) == FAILURE) {
        return;
    }

    VEDIS_SELF(intern);

    if (vedis_exec(intern->vedis->store, cmd, cmd_len) != VEDIS_OK) {
        php_vedis_error(intern, E_WARNING TSRMLS_CC);
        RETURN_FALSE;
    }

    vedis_exec_result(intern->vedis->store, &result);
    if (!result) {
        php_vedis_error(intern, E_WARNING TSRMLS_CC);
        RETURN_FALSE;
    }

    if (vedis_value_is_array(result)) {
        vedis_value *entry;
        array_init(return_value);
        while ((entry = vedis_array_next_elem(result)) != 0) {
            if (vedis_value_is_null(entry)) {
                add_next_index_null(return_value);
            } else {
                int len = 0;
                const char *str = vedis_value_to_string(entry, &len);
                add_next_index_stringl(return_value, str, len, 1);
            }
        }
    } else if (vedis_value_is_int(result)) {
        RETURN_LONG(vedis_value_to_int64(result));
    } else {
        int len = 0;
        const char *str = vedis_value_to_string(result, &len);
        RETURN_STRINGL(str, len, 1);
    }
}
Esempio n. 5
0
ONPHP_METHOD(QuerySkeleton, where)
{
	zval
		*exp,
		*logic,
		*where = ONPHP_READ_PROPERTY(getThis(), "where");
	
	if (Z_TYPE_P(where) != IS_ARRAY) {
		ONPHP_THROW(WrongStateException, NULL);
	}
	
	zend_bool where_not_empty = (
		(Z_TYPE_P(where) == IS_ARRAY)
		&& (zend_hash_num_elements(Z_ARRVAL_P(where)) > 0)
	);
	
	ONPHP_GET_ARGS("O|z", &exp, onphp_ce_LogicalObject, &logic);
	
	if (
		(ZEND_NUM_ARGS() == 1)
		&& where_not_empty
	) {
		ONPHP_THROW(
			WrongArgumentException,
			"you have to specify expression logic"
		);
	} else {
		zval *whereLogic = ONPHP_READ_PROPERTY(getThis(), "whereLogic");
		
		if (Z_TYPE_P(whereLogic) != IS_ARRAY) {
			ONPHP_THROW(WrongStateException, NULL);
		}
		
		if (!where_not_empty || (ZEND_NUM_ARGS() == 1)) {
			add_next_index_null(whereLogic);
		} else {
			ONPHP_ARRAY_ADD(whereLogic, logic);
		}
		
		ONPHP_ARRAY_ADD(where, exp);
	}
	
	RETURN_THIS;
}
Esempio n. 6
0
File: arrr.c Progetto: tony2001/arrr
/* {{{ proto mixed R::__call(string function_name, array arguments)
 
 */
static PHP_METHOD(R, __call)
{ 
	char *func;
	int func_len, error_occurred = 0, num_args;
	zval *args;
	SEXP e, fun, val, arg, next;
	HashPosition pos;
	zval **element;
	SEXPTYPE type;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &func, &func_len, &args) == FAILURE) {
		return;
	}

	fun = Rf_install(func);
	if (!fun) {
		RETURN_FALSE;
	}

	num_args = zend_hash_num_elements(Z_ARRVAL_P(args));

	PROTECT(fun);
	PROTECT(e = allocVector(LANGSXP, num_args + 1));
	SETCAR(e, fun);

	next = CDR(e);

	for(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
		zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **)&element, &pos) == SUCCESS;
		zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos)
		) {

		arg = php_zval_to_r(element);

		SETCAR(next, arg);
		next = CDR(next);
	}

	val = R_tryEval(e, R_GlobalEnv, &error_occurred);

	if (error_occurred) {
		UNPROTECT(2);
		RETURN_FALSE;
	}

	/* okay, the call succeeded */
	PROTECT(val);

	if (val == NULL_USER_OBJECT || GET_LENGTH(val) == 0) {
		/* ignore the return value */
	} else if (php_is_r_primitive(val, &type)) {
		int i;
		array_init(return_value);
		for (i = 0; i < GET_LENGTH(val); i++) {
			switch (type) {
				case STRSXP:
					add_next_index_string(return_value, CHAR(STRING_ELT(val, 0)), 1);
					break;
				case LGLSXP:
					add_next_index_bool(return_value, LOGICAL_DATA(val)[0] ? 1 : 0);
					break;
				case INTSXP:
					add_next_index_long(return_value, INTEGER_DATA(val)[0]);
					break;
				case REALSXP:
					add_next_index_double(return_value, NUMERIC_DATA(val)[0]);
					break;
				default:
					add_next_index_null(return_value);
					break;
			}
		}
		UNPROTECT(3);
		return;
	}

	UNPROTECT(3);
	RETURN_TRUE;
}