コード例 #1
0
ファイル: oci8_failover.c プロジェクト: dzuelke/php-src
/* {{{ php_oci_register_taf_callback()
   Register a callback function for Oracle TAF */
int php_oci_register_taf_callback(php_oci_connection *connection, zval *callback)
{
	sword errstatus;
	int registered = 0;

	/* temporary failover callback structure */
	OCIFocbkStruct failover;

	if (!callback) {
		/* Unregister callback */
		if (Z_ISUNDEF(connection->taf_callback) || Z_ISNULL(connection->taf_callback)) {
			return 0; // Nothing to unregister 
		}

		registered = 1;
		zval_ptr_dtor(&connection->taf_callback);
		ZVAL_NULL(&connection->taf_callback);
	} else {
		if (!Z_ISUNDEF(connection->taf_callback)) {
			registered = 1;
			if (!Z_ISNULL(connection->taf_callback)) {
				zval_ptr_dtor(&connection->taf_callback);
				ZVAL_NULL(&connection->taf_callback);
			}
		}

		/* Set userspace callback function */
		ZVAL_COPY(&connection->taf_callback, callback);
	}

	/* OCI callback function already registered */
	if (registered) {
		return 0;
	}

	/* set context */
	failover.fo_ctx = connection;

	/* set callback function */
	failover.callback_function = &callback_fn;

	/* do the registration */
	PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, (connection->server, (ub4) OCI_HTYPE_SERVER, (void *) &failover, (ub4) 0, (ub4) OCI_ATTR_FOCBK, connection->err));

	if (errstatus  != OCI_SUCCESS) {
		zval_ptr_dtor(&connection->taf_callback);
		ZVAL_UNDEF(&connection->taf_callback);
		connection->errcode = php_oci_error(connection->err, errstatus);
		return 1;
	}

	/* successful conclusion */
	return 0;
}
コード例 #2
0
ファイル: source.c プロジェクト: gtkforphp/glib
/* Custom Object Destruction - calls g_source_destroy() */
void glib_source_free_obj(zend_object *object)
{
	glib_source_object *intern = glib_source_fetch_object(object);

	if(!intern) {
		return;
	}

	GSource *source = (GSource *)intern->source;

	/* this will make finalize call, we MUST do this before freeing the source zval */
	if(intern->source != NULL) {
		g_source_destroy(source);
		g_source_unref(source);

		if(intern->is_php_source) {
			GPhpSource *psource = (GPhpSource *)intern->source;
			if(!Z_ISNULL(psource->source_zval) &&
				!Z_ISUNDEF(psource->source_zval)) {

				Z_TRY_DELREF_P(&psource->source_zval);
				ZVAL_UNDEF(&psource->source_zval);
			}
		}
	}

	zend_object_std_dtor(&intern->std);
}
コード例 #3
0
ファイル: oci8_failover.c プロジェクト: dzuelke/php-src
/* {{{ callback_fn() 
   OCI TAF callback function, calling userspace function */
sb4 callback_fn(void *svchp, void *envhp, void *fo_ctx, ub4 fo_type, ub4 fo_event)
{
	/* Create zval */
	zval retval, params[3];
    php_oci_connection *connection = (php_oci_connection*)fo_ctx;

	/* Default return value */
	sb4 returnValue = 0;

	/* Check if userspace callback function was unregistered */
	if (Z_ISUNDEF(connection->taf_callback) || Z_ISNULL(connection->taf_callback)) {
		return 0;
	}

	/* Initialize zval */
	ZVAL_RES(&params[0], connection->id);
	ZVAL_LONG(&params[1], fo_event);
	ZVAL_LONG(&params[2], fo_type);

	/* Call user function (if possible) */
	if (call_user_function(EG(function_table), NULL, &connection->taf_callback, &retval, 3, params) == FAILURE) {
		php_error_docref(NULL, E_WARNING, "Unable to call Oracle TAF callback function");
	}

	/* Set return value */
	if (Z_TYPE(retval) == IS_LONG) {
		returnValue = (sb4) Z_LVAL(retval);
	}

	/* Setting params[0] to null so ressource isn't destroyed on zval_dtor */
	ZVAL_NULL(&params[0]);

	/* Cleanup */
	zval_ptr_dtor(&retval);
	zval_ptr_dtor(&params[0]);
	zval_ptr_dtor(&params[1]);
	zval_ptr_dtor(&params[2]);

	return returnValue;
}
コード例 #4
0
/**
 *  Set a std::function as a php exception handler
 */
Value set_exception_handler(const std::function<Value(Parameters &params)> &handler)
{
    // we need the tsrm_ls variable
    TSRMLS_FETCH();

    // create a functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_exception_handler into a Value so we can return the original one later on
    if (!Z_ISNULL(EG(user_exception_handler))) output = &EG(user_exception_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // copy our zval into the user_exception_handler
    ZVAL_COPY(value, &EG(user_exception_handler));

    // return the original handler
    return output;
}
コード例 #5
0
/**
 *  Set a std::function as a php error handler
 */
Value set_error_handler(const std::function<Value(Parameters &params)> &handler, Error error)
{
    // we need the tsrm_ls variable
    TSRMLS_FETCH();

    // create the functor which wraps our callback
    Function functor(handler);

    // initialize our output value
    Value output;

    // turn our user_error_handler into a Value if we have one, just so we can return it later on
    if (!Z_ISNULL(EG(user_error_handler))) output = &EG(user_error_handler);

    // detach so we have the zval
    auto value = functor.detach(true);

    // copy our zval into the user_error_handler
    ZVAL_COPY_VALUE(&EG(user_error_handler), value);
    EG(user_error_handler_error_reporting) = (int) error;

    // return the original handler
    return output;
}