Esempio n. 1
0
static void _php_ibase_free_trans(zend_resource *rsrc) /* {{{ */
{
	ibase_trans *trans = (ibase_trans *)rsrc->ptr;
	unsigned short i;

	IBDEBUG("Cleaning up transaction resource...");
	if (trans->handle != 0) {
		IBDEBUG("Rolling back unhandled transaction...");
		if (isc_rollback_transaction(IB_STATUS, &trans->handle)) {
			_php_ibase_error();
		}
	}

	/* now remove this transaction from all the connection-transaction lists */
	for (i = 0; i < trans->link_cnt; ++i) {
		if (trans->db_link[i] != NULL) {
			ibase_tr_list **l;
			for (l = &trans->db_link[i]->tr_list; *l != NULL; l = &(*l)->next) {
				if ( (*l)->trans == trans) {
					ibase_tr_list *p = *l;
					*l = p->next;
					efree(p);
					break;
				}
			}
		}
	}
	efree(trans);
}
Esempio n. 2
0
void _php_ibase_free_event(ibase_event *event) /* {{{ */
{
	unsigned short i;

	event->state = DEAD;

	if (event->link != NULL) {
		ibase_event **node;

		if (event->link->handle != NULL &&
				isc_cancel_events(IB_STATUS, &event->link->handle, &event->event_id)) {
			_php_ibase_error();
		}

		/* delete this event from the link struct */
		for (node = &event->link->event_head; *node != event; node = &(*node)->event_next);
		*node = event->event_next;
	}

	if (Z_TYPE(event->callback) != IS_UNDEF) {
		zval_dtor(&event->callback);
		ZVAL_UNDEF(&event->callback);

		_php_ibase_event_free(event->event_buffer,event->result_buffer);

		for (i = 0; i < event->event_count; ++i) {
			efree(event->events[i]);
		}
		efree(event->events);
	}
}
Esempio n. 3
0
static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
	unsigned short buffer_size, char *result_buf)
{
	zval *res;

	/* this function is called asynchronously by the Interbase client library. */
	TSRMLS_FETCH_FROM_CTX(event->thread_ctx);

	/**
	 * The callback function is called when the event is first registered and when the event
	 * is cancelled. I consider this is a bug. By clearing event->callback first and setting
	 * it to -1 later, we make sure nothing happens if no event was actually posted.
	 */
	switch (event->state) {
		unsigned short i;
		unsigned long occurred_event[15];
		zval return_value, args[2];

		default: /* == DEAD */
			break;
		case ACTIVE:
			/* copy the updated results into the result buffer */
			memcpy(event->result_buffer, result_buf, buffer_size);

			res = zend_hash_index_find(&EG(regular_list), event->link_res_id);
			ZVAL_RES(&args[1], Z_RES_P(res));

			/* find out which event occurred */
			isc_event_counts(occurred_event, buffer_size, event->event_buffer, event->result_buffer);
			for (i = 0; i < event->event_count; ++i) {
				if (occurred_event[i]) {
					ZVAL_STRING(&args[0], event->events[i]);
					efree(event->events[i]);
					break;
				}
			}

			/* call the callback provided by the user */
			if (SUCCESS != call_user_function(EG(function_table), NULL,
					&event->callback, &return_value, 2, args)) {
				_php_ibase_module_error("Error calling callback %s", Z_STRVAL(event->callback));
				break;
			}

			if (Z_TYPE(return_value) == IS_FALSE) {
				event->state = DEAD;
				break;
			}
		case NEW:
			/* re-register the event */
			if (isc_que_events(IB_STATUS, &event->link->handle, &event->event_id, buffer_size,
				event->event_buffer,(isc_callback)_php_ibase_callback, (void *)event)) {

				_php_ibase_error();
			}
			event->state = ACTIVE;
	}
	return 0;
}
Esempio n. 4
0
static void _php_ibase_commit_link(ibase_db_link *link) /* {{{ */
{
	unsigned short i = 0, j;
	ibase_tr_list *l;
	ibase_event *e;
	IBDEBUG("Checking transactions to close...");

	for (l = link->tr_list; l != NULL; ++i) {
		ibase_tr_list *p = l;
		if (p->trans != 0) {
			if (i == 0) {
				if (p->trans->handle != 0) {
					IBDEBUG("Committing default transaction...");
					if (isc_commit_transaction(IB_STATUS, &p->trans->handle)) {
						_php_ibase_error();
					}
				}
				efree(p->trans); /* default transaction is not a registered resource: clean up */
			} else {
				if (p->trans->handle != 0) {
					/* non-default trans might have been rolled back by other call of this dtor */
					IBDEBUG("Rolling back other transactions...");
					if (isc_rollback_transaction(IB_STATUS, &p->trans->handle)) {
						_php_ibase_error();
					}
				}
				/* set this link pointer to NULL in the transaction */
				for (j = 0; j < p->trans->link_cnt; ++j) {
					if (p->trans->db_link[j] == link) {
						p->trans->db_link[j] = NULL;
						break;
					}
				}
			}
		}
		l = l->next;
		efree(p);
	}
	link->tr_list = NULL;

	for (e = link->event_head; e; e = e->event_next) {
		_php_ibase_free_event(e);
		e->link = NULL;
	}
}
Esempio n. 5
0
static void _php_ibase_free_service(zend_resource *rsrc) /* {{{ */
{
    ibase_service *sv = (ibase_service *) rsrc->ptr;

    if (isc_service_detach(IB_STATUS, &sv->handle)) {
        _php_ibase_error();
    }

    if (sv->hostname) {
        efree(sv->hostname);
    }
    if (sv->username) {
        efree(sv->username);
    }

    efree(sv);
}