cvs: pecl /sam SAM_Connection.c SAM_Connection.h package.xml php_sam.c php_sam.h

From: Date: Mon, 18 Dec 2006 12:27:58 +0000
Subject: cvs: pecl /sam SAM_Connection.c SAM_Connection.h package.xml php_sam.c php_sam.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6804@lists.php.net to get a copy of this message
dsr Mon Dec 18 12:27:58 2006 UTC Modified files: /pecl/sam SAM_Connection.c SAM_Connection.h package.xml php_sam.c php_sam.h Log:

http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Connection.c?r1=1.3&r2=1.4&diff_format=u Index: pecl/sam/SAM_Connection.c diff -u pecl/sam/SAM_Connection.c:1.3 pecl/sam/SAM_Connection.c:1.4 --- pecl/sam/SAM_Connection.c:1.3 Fri Dec 8 17:39:54 2006 +++ pecl/sam/SAM_Connection.c Mon Dec 18 12:27:58 2006 @@ -18,7 +18,7 @@ | Authors: Dave Renshaw, Jerry Stevens | +----------------------------------------------------------------------+ -$Id: SAM_Connection.c,v 1.3 2006/12/08 17:39:54 dsr Exp $ +$Id: SAM_Connection.c,v 1.4 2006/12/18 12:27:58 dsr Exp $ */ @@ -224,10 +224,45 @@ /* {{{ proto PHP_NAMED_FUNCTION(SAM_Connection_commit) Commit any outstanding unit of work on the connection */ PHP_FUNCTION(SAM_Connection_commit) { + + php_sam_connection *connResource; + zval **zConnection; + xmsHErrorBlock errorBlock; + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->commit()</b> enter<br/>"); + /* Retrieve the connection resource from this object's hash table */ + if (zend_hash_find(Z_OBJPROP_P(this_ptr), SAM_CONNECTION_CONNECTION_INDEX, sizeof(SAM_CONNECTION_CONNECTION_INDEX), (void**)&zConnection) == FAILURE) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_CONNECTION, SAM_CONNECTION_NO_CONNECTION_MSG); + return; + } + ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); + if (SAM_DEBUG) zend_printf("<b>SAMConnection->commit()</b> connection is %d<br/>", connResource->conn); + + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + + /* Create an XMS error block that we will need to issue a commit */ + if (XMS_OK != xmsErrorCreate(&errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, SAM_CONNECTION_NO_ERROR_BLOCK_MSG); + RETURN_FALSE; + } + + /* Issue the XMS commit */ + if (XMS_OK != xmsSessCommit(connResource->session, errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_COMMIT_FAILED, SAM_CONNECTION_COMMIT_FAILED_MSG); + if (SAM_DEBUG) check(errorBlock); + RETURN_FALSE; + } + + /* Finished with the error block */ + xmsErrorDispose(&errorBlock); + if (SAM_DEBUG) zend_printf("<b>SAMConnection->commit()</b> exit<br/>"); - RETURN_FALSE; + RETURN_TRUE; } /* }}} */ @@ -261,10 +296,15 @@ char szBusName[128] = { '\0' }; char *szWpmDurSubHome = NULL; + char *szTransactions = NULL; + char *szUserId = NULL; + char *szPassword =NULL; php_sam_connection *connResource; zval* zConnection; + int transacted = xmsFALSE; + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->connect()</b> enter<br/>"); resetError(this_ptr TSRMLS_CC); @@ -398,6 +438,59 @@ if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller specified target chain of <b>%s</b><br/>", szTargetChain); } + /* Has a transaction option been specified? */ + if (zend_hash_find(optionsHT, SAM_CONSTANT_TRANSACTIONS, sizeof(SAM_CONSTANT_TRANSACTIONS), (void**)&zTemp) == SUCCESS) { + convert_to_string(*zTemp); + + if (NULL == (szTransactions = emalloc(Z_STRLEN_PP(zTemp)+1))) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_TRANSACTIONS_ALLOC_FAILED, SAM_CONNECTION_TRANSACTIONS_ALLOC_FAILED_MSG); + RETURN_FALSE; + } + + strncpy(szTransactions, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); + szTransactions[Z_STRLEN_PP(zTemp)]=0; + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller specified transactions options <b>%s</b><br/>", szTransactions); + + i = strcmp(SAM_CONSTANT_MANUAL, szTransactions); + efree(szTransactions); + if (0 == i) { + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller specified manual transaction control<br/>"); + transacted = xmsTRUE; + } else if (0 != strcmp(SAM_CONSTANT_AUTO, szTransactions)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_ILLEGAL_TRANSACTION_MODE, SAM_CONNECTION_ILLEGAL_TRANSACTION_MODE_MSG); + RETURN_FALSE; + } + + } + + /* Has a user identifier been specified? */ + if (zend_hash_find(optionsHT, SAM_CONSTANT_USERID, sizeof(SAM_CONSTANT_USERID), (void**)&zTemp) == SUCCESS) { + convert_to_string(*zTemp); + + if (NULL == (szUserId = emalloc(Z_STRLEN_PP(zTemp)+1))) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_USERID_ALLOC_FAILED, SAM_CONNECTION_USERID_ALLOC_FAILED_MSG); + RETURN_FALSE; + } + + strncpy(szUserId, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); + szUserId[Z_STRLEN_PP(zTemp)]=0; + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller specified UserId of <b>%s</b><br/>", szUserId); + } + + /* Has a password been specified? */ + if (zend_hash_find(optionsHT, SAM_CONSTANT_PASSWORD, sizeof(SAM_CONSTANT_PASSWORD), (void**)&zTemp) == SUCCESS) { + convert_to_string(*zTemp); + + if (NULL == (szPassword = emalloc(Z_STRLEN_PP(zTemp)+1))) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PASSWORD_ALLOC_FAILED, SAM_CONNECTION_PASSWORD_ALLOC_FAILED_MSG); + RETURN_FALSE; + } + + strncpy(szPassword, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); + szPassword[Z_STRLEN_PP(zTemp)]=0; + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller specified password of <b>%s</b><br/>", szPassword); + } + } /* zend_hash_num_elements(optionsHT) > 0 */ } else { if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> No options array specified.<br/>"); @@ -434,6 +527,40 @@ RETURN_FALSE; } + /* Set up any protocol independent properties */ + if (NULL != szUserId) { + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> userid %s<br/>", szUserId); + + /* Set the XMSC_USERID connection factory property */ + rc = xmsSetStringProperty( (xmsHObj) connFactory, XMSC_USERID, szUserId, strlen(szUserId), errorBlock); + + /* We can now free szUserId */ + efree(szUserId); + + if (XMS_OK != rc) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->connect()</b> xmsSetStringProperty (XMSC_USERID) failed!<br/>"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_SET_USERID, SAM_CONNECTION_SET_USERID_MSG); + RETURN_FALSE; + } + + } + + if (NULL != szPassword) { + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> password %s<br/>", szPassword); + + /* Set the XMSC_PASSWORD connection factory property */ + rc = xmsSetStringProperty( (xmsHObj) connFactory, XMSC_PASSWORD, szPassword, strlen(szPassword), errorBlock); + + /* We can now free szPassword */ + efree(szPassword); + + if (XMS_OK != rc) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->connect()</b> xmsSetStringProperty (XMSC_PASSWORD) failed!<br/>"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_SET_PASSWORD, SAM_CONNECTION_SET_PASSWORD_MSG); + RETURN_FALSE; + } + } + /* set up any other properties we need dependant on the protocol we are using... */ if (strcmp(szProtocol, SAM_CONSTANT_WMQ) == 0) { /* @@ -595,8 +722,17 @@ /* Create a resource to represent this XMS connection */ MAKE_STD_ZVAL(zConnection); connResource = emalloc(sizeof(php_sam_connection)); - connResource->connFact = connFactory; connResource->conn = connection; + connResource->session = XMS_NULL_HANDLE; + connResource->transacted = transacted; + + /* Create the XMS session. The session handle is stored in the connection resource so it can be used without + creating and closing further sessions in each api call. */ + if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &(connResource->session), errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); + if (SAM_DEBUG) check(errorBlock); + RETURN_FALSE; + } /* copy the protocol type into the connection resource (so we can validate the target client option in the send) */ strcpy(connResource->protocol, szProtocol); @@ -609,6 +745,17 @@ if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> new connection %d<br/>", connResource->conn); /* clean up any XMS resources we no longer need... */ + /* We have finished with the connection factory */ + if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Deleting connection factory<br/>"); + rc = xmsConnFactDispose(&connFactory, errorBlock); + if (XMS_OK != rc) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->connect()</b> Delete of connection factory failed!\n"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CONNFACT_DELETE, SAM_CONNECTION_CONNFACT_DELETE_MSG); + if (SAM_DEBUG) check(errorBlock); + RETURN_FALSE; + } + + /* And we have finished with the error block */ xmsErrorDispose(&errorBlock); if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> exit<br/>"); @@ -637,22 +784,46 @@ if (connResource) { + /* Create an error block */ if (XMS_OK != xmsErrorCreate(&errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, SAM_CONNECTION_NO_ERROR_BLOCK_MSG); RETURN_FALSE; } + /* Close the session */ + if (XMS_NULL_HANDLE != connResource->session) { - if (connResource->conn) { - /* stop the connection */ - if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Stopping connection\n"); - rc = xmsConnStop(connResource->conn, errorBlock); - if (XMS_OK != rc) { - if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Connection stop failed!\n"); - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CONNECTION_STOP, SAM_CONNECTION_CONNECTION_STOP_MSG); + /* Issue an explicit rollback before closing the session if the session was manually transacted */ + if (connResource->transacted) { + if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> Issuing rollback<br/>"); + if (XMS_OK != xmsSessRollback(connResource->session, errorBlock)) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Session rollback failed!\n"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_ROLLBACK_FAILED, SAM_CONNECTION_ROLLBACK_FAILED_MSG); + RETURN_FALSE; + } + } + + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Closing session\n"); + if (XMS_OK != xmsSessClose(&connResource->session, errorBlock)) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Session close failed!\n"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_SESSION_CLOSE, SAM_CONNECTION_SESSION_CLOSE_MSG); if (SAM_DEBUG) check(errorBlock); RETURN_FALSE; } + } + + + /* stop the connection */ + if (connResource->conn) { + + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Stopping connection\n"); + rc = xmsConnStop(connResource->conn, errorBlock); + if (XMS_OK != rc) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Connection stop failed!\n"); + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CONNECTION_STOP, SAM_CONNECTION_CONNECTION_STOP_MSG); + if (SAM_DEBUG) check(errorBlock); + RETURN_FALSE; + } /* close the connection */ if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> closing connection %d<br/>", connResource->conn); @@ -669,22 +840,6 @@ connResource->conn=NULL; } - if (connResource->connFact) - { - - /* Delete the connection factory */ - if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> Deleting connection factory<br/>"); - rc = xmsConnFactDispose(&connResource->connFact, errorBlock); - if (XMS_OK != rc) { - if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> Delete of connection factory failed!\n"); - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CONNFACT_DELETE, SAM_CONNECTION_CONNFACT_DELETE_MSG); - if (SAM_DEBUG) check(errorBlock); - RETURN_FALSE; - } - /* Set the connectionFactory to NULL to eliminate the possibiliy of attempting to dispose of it again */ - connResource->connFact = NULL; - } - /* Remove the hashtable entry that points to the resource we have now finished with */ zend_hash_del(Z_OBJPROP_P(this_ptr), SAM_CONNECTION_CONNECTION_INDEX, sizeof(SAM_CONNECTION_CONNECTION_INDEX)); @@ -715,6 +870,12 @@ if (connResource) { if (SAM_DEBUG) zend_printf("<b>SAMConnection->isConnected()</b> connection is %d<br/>", connResource->conn); + + if (XMS_NULL_HANDLE == connResource->session) { + if (SAM_DEBUG) zend_printf("<b>SAMConnection->isConnected()</b> exit (no session)<br/>"); + RETURN_FALSE; + } + if (SAM_DEBUG) zend_printf("<b>SAMConnection->isConnected()</b> exit<br/>"); RETURN_TRUE; } @@ -744,7 +905,6 @@ xmsCHAR *szSelector = NULL; xmsHErrorBlock errorBlock; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHQueueBrowser qbrowser = XMS_NULL_HANDLE; xmsHIterator browserIterator = XMS_NULL_HANDLE; @@ -797,6 +957,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS connection */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* Take a look in the options array if we have one... */ if (zvOptions) { optionsHT = Z_ARRVAL_P(zvOptions); @@ -847,23 +1013,16 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_PEEK(); - RETURN_FALSE; - } - - /* Do we have any selection criteria? (I.e. a correlation id or message id string) */ + /* Do we have any selection criteria? (I.e. a correlation id or message id string) */ if ( (NULL == szCorrelID) && (NULL == szMessageID) ) { /* No, so we can use a queue browser without a select */ if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Creating queue browser<br/>"); - rc = xmsSessCreateBrowser(session, dest, &qbrowser, errorBlock); + rc = xmsSessCreateBrowser(connResource->session, dest, &qbrowser, errorBlock); } else { /* Yes, so build a selector string accordingly */ szSelector = SAMBuildSelectorString(szCorrelID, szMessageID); if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Creating queue browser with selector - %s<br/>", szSelector); - rc = xmsSessCreateBrowserSelector(session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &qbrowser, errorBlock); + rc = xmsSessCreateBrowserSelector(connResource->session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &qbrowser, errorBlock); /* Free any correlId & message id buffers */ if (NULL != szCorrelID) efree(szCorrelID); @@ -1131,7 +1290,6 @@ xmsCHAR *szSelector = NULL; xmsHErrorBlock errorBlock; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHQueueBrowser qbrowser = XMS_NULL_HANDLE; xmsHIterator browserIterator = XMS_NULL_HANDLE; @@ -1184,6 +1342,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* Take a look in the options array if we have one... */ if (zvOptions) { optionsHT = Z_ARRVAL_P(zvOptions); @@ -1235,23 +1399,16 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_PEEKALL(); - RETURN_FALSE; - } - /* Do we have any selection criteria? (I.e. a correlation id or message id string) */ if ( (NULL == szCorrelID) && (NULL == szMessageID) ) { /* No, so we can use a queue browser without a select */ if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Creating queue browser<br/>"); - rc = xmsSessCreateBrowser(session, dest, &qbrowser, errorBlock); + rc = xmsSessCreateBrowser(connResource->session, dest, &qbrowser, errorBlock); } else { /* Yes, so build a selector string accordingly */ szSelector = SAMBuildSelectorString(szCorrelID, szMessageID); if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Creating queue browser with selector - %s<br/>", szSelector); - rc = xmsSessCreateBrowserSelector(session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &qbrowser, errorBlock); + rc = xmsSessCreateBrowserSelector(connResource->session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &qbrowser, errorBlock); /* Free any correlId & message id buffers */ if (NULL != szCorrelID) efree(szCorrelID); @@ -1547,7 +1704,6 @@ xmsINT waitTimeout = 0; xmsHErrorBlock errorBlock; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHMsgConsumer consumer = XMS_NULL_HANDLE; xmsHMsg message; @@ -1653,6 +1809,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* Take a look in the options array if we have one... */ if (zvOptions) { optionsHT = Z_ARRVAL_P(zvOptions); @@ -1710,25 +1872,18 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_RECEIVE(); - RETURN_FALSE; - } - /* Do we have any selection criteria? (I.e. a correlation id or message id string) */ if ( (NULL == szCorrelID) && (NULL == szMessageID) ) { /* No, so create a consumer without specifying a selector */ if (subNameLength == 0) { if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Creating non-durable consumer<br/>"); - rc = xmsSessCreateConsumer(session, dest, &consumer, errorBlock); + rc = xmsSessCreateConsumer(connResource->session, dest, &consumer, errorBlock); } else { if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Creating durable subscriber<br/>"); - rc = xmsSessCreateDurableSubscriber(session, dest, aSubscriptionName, &consumer, errorBlock); + rc = xmsSessCreateDurableSubscriber(connResource->session, dest, aSubscriptionName, &consumer, errorBlock); } } else { /* Yes, so build a selector string accordingly */ @@ -1738,12 +1893,12 @@ if (subNameLength == 0) { if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Creating non-durable consumer with selector<br/>"); - rc = xmsSessCreateConsumerSelector(session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &consumer, errorBlock); + rc = xmsSessCreateConsumerSelector(connResource->session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &consumer, errorBlock); } else { if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Creating durable subscriber with selector<br/>"); - rc = xmsSessCreateDurableSubscriberSelector(session, dest, aSubscriptionName, szSelector, XMSC_CALCULATE_STRING_SIZE, noLocal, &consumer, errorBlock); + rc = xmsSessCreateDurableSubscriberSelector(connResource->session, dest, aSubscriptionName, szSelector, XMSC_CALCULATE_STRING_SIZE, noLocal, &consumer, errorBlock); } /* Free any correlId or message id buffers */ @@ -1761,13 +1916,20 @@ RETURN_FALSE; } - if (XMS_OK != xmsMsgConsumerReceiveWithWait(consumer, waitTimeout, &message, errorBlock) - || (message == XMS_NULL_HANDLE)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_RECEIVE_FAILED, SAM_CONNECTION_RECEIVE_FAILED_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_RECEIVE(); - RETURN_FALSE; - } + if (XMS_OK != xmsMsgConsumerReceiveWithWait(consumer, waitTimeout, &message, errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_RECEIVE_FAILED, SAM_CONNECTION_RECEIVE_FAILED_MSG); + if (SAM_DEBUG) check(errorBlock); + SAM_CLEANUP_RECEIVE(); + RETURN_FALSE; + } + + /* If there was no error but a null message handle was returned then no message was received + during the wait interval */ + if (message == XMS_NULL_HANDLE) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_RECEIVE_TIMEDOUT, SAM_CONNECTION_RECEIVE_TIMEDOUT_MSG); + SAM_CLEANUP_RECEIVE(); + RETURN_FALSE; + } /* get the message type... */ if (XMS_OK != xmsMsgGetTypeId(message, &messageType, errorBlock)) { @@ -1995,7 +2157,6 @@ xmsINT waitTimeout = 0; xmsHErrorBlock errorBlock; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHMsgConsumer consumer = XMS_NULL_HANDLE; xmsHMsg message; @@ -2024,6 +2185,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* Take a look in the options array if we have one... */ if (zvOptions) { optionsHT = Z_ARRVAL_P(zvOptions); @@ -2082,13 +2249,6 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_REMOVE(); - RETURN_FALSE; - } - /* Build a selector string from the message id or correlid */ szSelector = SAMBuildSelectorString(szCorrelID, szMessageID); @@ -2099,7 +2259,7 @@ if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Using selector string - %s<br/>", szSelector); if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Creating non-durable consumer with selector<br/>"); - rc = xmsSessCreateConsumerSelector(session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &consumer, errorBlock); + rc = xmsSessCreateConsumerSelector(connResource->session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, &consumer, errorBlock); /* Free the selector buffer */ if (NULL != szSelector) efree(szSelector); @@ -2137,10 +2297,43 @@ PHP_FUNCTION(SAM_Connection_rollback) { + php_sam_connection *connResource; + zval **zConnection; + xmsHErrorBlock errorBlock; + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->rollback()</b> enter<br/>"); + /* Retrieve the connection resource from this object's hash table */ + if (zend_hash_find(Z_OBJPROP_P(this_ptr), SAM_CONNECTION_CONNECTION_INDEX, sizeof(SAM_CONNECTION_CONNECTION_INDEX), (void**)&zConnection) == FAILURE) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_CONNECTION, SAM_CONNECTION_NO_CONNECTION_MSG); + return; + } + ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); + if (SAM_DEBUG) zend_printf("<b>SAMConnection->rollback()</b> connection is %d<br/>", connResource->conn); + + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + + /* Create an XMS error block that we will need to issue a rollback */ + if (XMS_OK != xmsErrorCreate(&errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, SAM_CONNECTION_NO_ERROR_BLOCK_MSG); + RETURN_FALSE; + } + + /* Issue the XMS rollback */ + if (XMS_OK != xmsSessRollback(connResource->session, errorBlock)) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_ROLLBACK_FAILED, SAM_CONNECTION_ROLLBACK_FAILED_MSG); + RETURN_FALSE; + } + + /* Finished with the error block */ + xmsErrorDispose(&errorBlock); + if (SAM_DEBUG) zend_printf("<b>SAMConnection->rollback()</b> exit<br/>"); - RETURN_FALSE; + RETURN_TRUE; } /* }}} */ @@ -2163,7 +2356,6 @@ xmsLONG timeToLive = -1; zend_class_entry *objce; - xmsHSess session; xmsHDest dest; xmsHDest replyDest; xmsHErrorBlock errorBlock; @@ -2318,6 +2510,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* The SAM_HEADERS option is only supported with MQ */ if ((NULL != szHeaders) && (0 != strcmp(SAM_CONSTANT_WMQ, connResource->protocol))) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_ILLEGAL_TARGETCLIENT_MODE, SAM_CONNECTION_ILLEGAL_TARGETCLIENT_MODE_MSG); @@ -2349,16 +2547,8 @@ efree(szHeaders); } - /* Create a session on this connection for our send... */ - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_SEND(); - RETURN_FALSE; - } - /* Create an XMS producer with which to do our send... */ - if (XMS_OK != xmsSessCreateProducer(session, dest, &producer, errorBlock)) { + if (XMS_OK != xmsSessCreateProducer(connResource->session, dest, &producer, errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_PRODUCER, SAM_CONNECTION_NO_PRODUCER_MSG); if (SAM_DEBUG) check(errorBlock); SAM_CLEANUP_SEND(); @@ -2366,7 +2556,7 @@ } /* Set the deliveryMode if one was specified */ - if (NULL == szDeliveryMode && strlen(szDeliveryMode) > 0) { + if (NULL != szDeliveryMode && strlen(szDeliveryMode) > 0) { /* Non persistent delivery mode was requested */ if (0 == strcmp(szDeliveryMode, SAM_CONSTANT_NONPERSISTENT)) { if (XMS_OK != xmsMsgProducerSetDeliveryMode(producer, XMSC_DELIVERY_NOT_PERSISTENT, errorBlock)) { @@ -2442,7 +2632,7 @@ if (SAM_MSGTYPE_BYTES == msgType) { /* Bytes message format - create an XMS bytes message object that can take any arbitrary data */ - if (XMS_OK != xmsSessCreateBytesMessage(session, &message, errorBlock)) { + if (XMS_OK != xmsSessCreateBytesMessage(connResource->session, &message, errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_BYTES_MESSAGE, SAM_CONNECTION_NO_BYTES_MESSAGE_MSG); if (SAM_DEBUG) check(errorBlock); SAM_CLEANUP_SEND(); @@ -2450,7 +2640,7 @@ } } else { /* Text message format - create an XMS text message */ - if (XMS_OK != xmsSessCreateTextMessage(session, &message, errorBlock)) { + if (XMS_OK != xmsSessCreateTextMessage(connResource->session, &message, errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_TEXT_MESSAGE, SAM_CONNECTION_NO_TEXT_MESSAGE_MSG); if (SAM_DEBUG) check(errorBlock); SAM_CLEANUP_SEND(); @@ -2691,7 +2881,6 @@ int destLength=0; xmsHErrorBlock errorBlock; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHMsgConsumer consumer = XMS_NULL_HANDLE; int transacted = xmsFALSE; @@ -2723,6 +2912,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->subscribe()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + if (XMS_OK != xmsErrorCreate(&errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, SAM_CONNECTION_NO_ERROR_BLOCK_MSG); RETURN_FALSE; @@ -2734,14 +2929,8 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - RETURN_FALSE; - } - if (0 == SAMGetSignature(&subscriptionName, aDestination)) { - rc = xmsSessCreateDurableSubscriber(session, dest, subscriptionName, &consumer, errorBlock); + rc = xmsSessCreateDurableSubscriber(connResource->session, dest, subscriptionName, &consumer, errorBlock); if (XMS_OK != rc) { /* Have a look at the error and see if we are using WPM check for whether the DUR_SUB_HOME option was missing*/ @@ -2768,7 +2957,6 @@ if (NULL != subscriptionName) efree(subscriptionName); xmsMsgConsumerClose(&consumer, errorBlock); - xmsSessClose(&session, errorBlock); xmsErrorDispose(&errorBlock); if (SAM_DEBUG) zend_printf("<b>SAMConnection->subscribe()</b> exit<br/>"); @@ -2786,7 +2974,6 @@ PHP_FUNCTION(SAM_Connection_unsubscribe) { xmsINT rc; - xmsHSess session = XMS_NULL_HANDLE; xmsHDest dest = XMS_NULL_HANDLE; xmsHMsgConsumer consumer = XMS_NULL_HANDLE; int transacted = xmsFALSE; @@ -2820,6 +3007,12 @@ ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); if (SAM_DEBUG) zend_printf("<b>SAMConnection->unsubscribe()</b> connection is %d<br/>", connResource->conn); + /* Check we have a valid XMS session handle */ + if (XMS_NULL_HANDLE == connResource->session) { + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NULL_SESSION, SAM_CONNECTION_NULL_SESSION_MSG); + RETURN_FALSE; + } + /* create an XMS error block to capture error info... */ if (XMS_OK != xmsErrorCreate(&errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, SAM_CONNECTION_NO_ERROR_BLOCK_MSG); @@ -2836,14 +3029,7 @@ RETURN_FALSE; } - if (XMS_OK != xmsConnCreateSession(connResource->conn, transacted, XMSC_AUTO_ACKNOWLEDGE, &session, errorBlock)) { - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_SESSION, SAM_CONNECTION_NO_SESSION_MSG); - if (SAM_DEBUG) check(errorBlock); - SAM_CLEANUP_UNSUBSCRIBE(); - RETURN_FALSE; - } - - rc = xmsSessCreateDurableSubscriber(session, dest, aSubscriptionName, &consumer, errorBlock); + rc = xmsSessCreateDurableSubscriber(connResource->session, dest, aSubscriptionName, &consumer, errorBlock); if (XMS_OK != rc) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_CONSUMER, SAM_CONNECTION_NO_CONSUMER_MSG); if (SAM_DEBUG) check(errorBlock); @@ -2853,7 +3039,7 @@ xmsMsgConsumerClose(&consumer, errorBlock); - if (XMS_OK != xmsSessUnsubscribe(session, aSubscriptionName, errorBlock)) { + if (XMS_OK != xmsSessUnsubscribe(connResource->session, aSubscriptionName, errorBlock)) { setError(this_ptr TSRMLS_CC, SAM_CONNECTION_UNSUBSCRIBE_FAILED, SAM_CONNECTION_UNSUBSCRIBE_FAILED_MSG); if (SAM_DEBUG) check(errorBlock); SAM_CLEANUP_UNSUBSCRIBE(); http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Connection.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sam/SAM_Connection.h diff -u pecl/sam/SAM_Connection.h:1.3 pecl/sam/SAM_Connection.h:1.4 --- pecl/sam/SAM_Connection.h:1.3 Fri Dec 8 17:39:54 2006 +++ pecl/sam/SAM_Connection.h Mon Dec 18 12:27:58 2006 @@ -18,7 +18,7 @@ | Authors: Dave Renshaw, Jerry Stevens | +----------------------------------------------------------------------+ -$Id: SAM_Connection.h,v 1.3 2006/12/08 17:39:54 dsr Exp $ +$Id: SAM_Connection.h,v 1.4 2006/12/18 12:27:58 dsr Exp $ */ @@ -31,9 +31,10 @@ /* Resource struct... */ typedef struct _php_sam_connection { - xmsHConnFact connFact; - xmsHConn conn; char protocol[128]; + xmsHConn conn; + xmsHSess session; + xmsINT transacted; } php_sam_connection; @@ -219,6 +220,30 @@ #define SAM_CONNECTION_NO_WPMDURSUBHOME_MSG "SAM_WPM_DUR_SUB_HOME must be set as a connect option when using WPM!" #define SAM_CONNECTION_SET_WPMDURSUBHOME 283 #define SAM_CONNECTION_SET_WPMDURSUBHOME_MSG "Unable to set XMS WPM durable subscription home property!" +#define SAM_CONNECTION_NULL_SESSION 284 +#define SAM_CONNECTION_NULL_SESSION_MSG "XMS Session handle is NULL!" +#define SAM_CONNECTION_SESSION_CLOSE 285 +#define SAM_CONNECTION_SESSION_CLOSE_MSG "Unable to close XMS session!" +#define SAM_CONNECTION_TRANSACTIONS_ALLOC_FAILED 286 +#define SAM_CONNECTION_TRANSACTIONS_ALLOC_FAILED_MSG "Unable to allocate buffer for transaction options!" +#define SAM_CONNECTION_ILLEGAL_TRANSACTION_MODE 287 +#define SAM_CONNECTION_ILLEGAL_TRANSACTION_MODE_MSG "Illegal value for SAM_TRANSACTIONS|" +#define SAM_CONNECTION_ROLLBACK_FAILED 288 +#define SAM_CONNECTION_ROLLBACK_FAILED_MSG "XMS Session rollback failed!" +#define SAM_CONNECTION_COMMIT_FAILED 289 +#define SAM_CONNECTION_COMMIT_FAILED_MSG "XMS Session commit failed!" +#define SAM_CONNECTION_USERID_ALLOC_FAILED 290 +#define SAM_CONNECTION_USERID_ALLOC_FAILED_MSG "Unable to allocate buffer for userid" +#define SAM_CONNECTION_PASSWORD_ALLOC_FAILED 291 +#define SAM_CONNECTION_PASSWORD_ALLOC_FAILED_MSG "Unable to allocate buffer for password!" +#define SAM_CONNECTION_SET_USERID 292 +#define SAM_CONNECTION_SET_USERID_MSG "Unable to set XMS userid property!" +#define SAM_CONNECTION_SET_PASSWORD 293 +#define SAM_CONNECTION_SET_PASSWORD_MSG "Unable to set XMS password property!" + +/* We make available a constant SAM_RECEIVE_TIMEDOUT in php_sam.h and php_sam.c which maps to the following value. */ +#define SAM_CONNECTION_RECEIVE_TIMEDOUT 500 +#define SAM_CONNECTION_RECEIVE_TIMEDOUT_MSG "No message available to receive!" /* internal constants */ #define SAM_MSGTYPE_TEXT 1 @@ -233,7 +258,6 @@ \ xmsMsgDispose(&message, errorBlock); \ xmsQueueBrowserClose(&qbrowser, errorBlock); \ - xmsSessClose(&session, errorBlock); \ xmsErrorDispose(&errorBlock); #define SAM_CLEANUP_PEEKALL() SAM_CLEANUP_PEEK() @@ -241,7 +265,6 @@ #define SAM_CLEANUP_RECEIVE() \ xmsMsgDispose(&message, errorBlock); \ xmsMsgConsumerClose(&consumer, errorBlock); \ - xmsSessClose(&session, errorBlock); \ xmsErrorDispose(&errorBlock); #define SAM_CLEANUP_REMOVE() SAM_CLEANUP_RECEIVE() @@ -249,12 +272,10 @@ #define SAM_CLEANUP_SEND() \ xmsMsgDispose(&message, errorBlock); \ xmsMsgProducerClose(&producer, errorBlock); \ - xmsSessClose(&session, errorBlock); \ xmsErrorDispose(&errorBlock); #define SAM_CLEANUP_UNSUBSCRIBE() \ xmsMsgConsumerClose(&consumer, errorBlock); \ - xmsSessClose(&session, errorBlock); \ xmsErrorDispose(&errorBlock); #endif /*__SAMPHPCONN_H__) */ http://cvs.php.net/viewvc.cgi/pecl/sam/package.xml?r1=1.3&r2=1.4&diff_format=u Index: pecl/sam/package.xml diff -u pecl/sam/package.xml:1.3 pecl/sam/package.xml:1.4 --- pecl/sam/package.xml:1.3 Fri Dec 8 17:39:54 2006 +++ pecl/sam/package.xml Mon Dec 18 12:27:58 2006 @@ -15,11 +15,13 @@ </maintainer> </maintainers> <release> - <version>0.3.0</version> - <date>2006-12-08</date> + <version>1.0.0</version> + <date>2006-12-18</date> <license>Apache 2.0</license> - <state>beta</state> - <notes>Update release to add publish/subscribe functionality. + <state>stable</state> + <notes>Moved from beta to stable release state. + Added auto/manual transaction control functionality. + Added support for userid and password connect() options. </notes> <deps> <dep type="php" rel="ge" version="4.4.2" optional="no"/> @@ -45,6 +47,8 @@ <file role="src" name="sam_test2_wpm_p2p.php"/> <file role="src" name="sam_test3_wmq_pubsub.php"/> <file role="src" name="sam_test4_wpm_pubsub.php"/> + <file role="src" name="sam_test5_wmq_candr.php"/> + <file role="src" name="sam_test6_wpm_candr.php"/> </dir> <!-- tests --> </dir> <!-- / --> </filelist> @@ -66,5 +70,13 @@ <notes>Update release to add peek, peekAll and remove functionality. </notes> </release> + <release> + <version>0.3.0</version> + <date>2006-12-08</date> + <license>Apache 2.0</license> + <state>beta</state> + <notes>Update release to add publish/subscribe functionality. + </notes> + </release> </changelog> </package> http://cvs.php.net/viewvc.cgi/pecl/sam/php_sam.c?r1=1.3&r2=1.4&diff_format=u Index: pecl/sam/php_sam.c diff -u pecl/sam/php_sam.c:1.3 pecl/sam/php_sam.c:1.4 --- pecl/sam/php_sam.c:1.3 Fri Dec 8 17:39:54 2006 +++ pecl/sam/php_sam.c Mon Dec 18 12:27:58 2006 @@ -18,7 +18,7 @@ | Authors: Dave Renshaw, Jerry Stevens | +----------------------------------------------------------------------+ -$Id: php_sam.c,v 1.3 2006/12/08 17:39:54 dsr Exp $ +$Id: php_sam.c,v 1.4 2006/12/18 12:27:58 dsr Exp $ */ @@ -145,6 +145,9 @@ REGISTER_STRING_CONSTANT("SAM_WMQ_BINDINGS", SAM_CONSTANT_WMQ_BINDINGS, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("SAM_WPM", SAM_CONSTANT_WPM, CONST_CS | CONST_PERSISTENT); + /* Error constants */ + REGISTER_LONG_CONSTANT(SAM_CONSTANT_RECEIVE_TIMEDOUT, SAM_CONNECTION_RECEIVE_TIMEDOUT, CONST_CS | CONST_PERSISTENT); + /* Register the connection class */ INIT_CLASS_ENTRY(ce, "SAMConnection", sam_conn_functions); php_sam_SAM_Connection_entry = zend_register_internal_class(&ce TSRMLS_CC); @@ -200,11 +203,35 @@ if (SAM_DEBUG) zend_printf("<br/><b>php_sam_connection_dtor</b> enter<br/>"); + /* Close the session and connection and free the resource memory */ if (connResource) { - if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> closing connection %d<br/>", connResource->conn); - /* Close the connection and free the resource memory */ + /* Close the session */ + if (XMS_NULL_HANDLE != connResource->session) { + + /* Create an error block for xmsSessClose */ + if (XMS_OK != xmsErrorCreate(&errorBlock)) { + if (SAM_DEBUG) zend_printf("<br/><b>php_sam_dtor()</b> Error creating error block\n"); + } else { + /* Issue an explicit rollback before closing the session if the session was manually transacted */ + if (connResource->transacted) { + if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> Issuing rollback<br/>"); + if (XMS_OK != xmsSessRollback(connResource->session, errorBlock)) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->php_sam_connection_dtor</b> Session rollback failed!\n"); + } + } + + if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> Closing session<br/>"); + if (XMS_OK != xmsSessClose(&(connResource->session), errorBlock)) { + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->php_sam_connection_dtor</b> Session close failed!\n"); + } + /* Finished with the error block now */ + xmsErrorDispose(&errorBlock); + } + } + if (connResource->conn) { + if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> closing connection %d<br/>", connResource->conn); if (XMS_OK != xmsConnClose(&connResource->conn, NULL)) { if (SAM_DEBUG) zend_printf("<br/><b>php_sam_connection_dtor</b> close failed!<br/>"); } @@ -213,22 +240,6 @@ connResource->conn=NULL; } - /* Dispose of the connection factory */ - if (connResource->connFact) { - - /* Delete the connection factory */ - if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> Deleting connection factory<br/>"); - - if ( (XMS_OK != xmsErrorCreate(&errorBlock)) || - (XMS_OK != xmsConnFactDispose(&connResource->connFact, errorBlock))) { - if (SAM_DEBUG) zend_printf("<br/><b>php_sam_dtor()</b> Delete of connection factory failed!\n"); - } - else - xmsErrorDispose(&errorBlock); - - /* Set the connectionFactory to NULL to eliminate the possibiliy of attempting to dispose of it again */ - connResource->connFact = NULL; - } /* Free the resource */ efree(connResource); http://cvs.php.net/viewvc.cgi/pecl/sam/php_sam.h?r1=1.3&r2=1.4&diff_format=u Index: pecl/sam/php_sam.h diff -u pecl/sam/php_sam.h:1.3 pecl/sam/php_sam.h:1.4 --- pecl/sam/php_sam.h:1.3 Fri Dec 8 17:39:54 2006 +++ pecl/sam/php_sam.h Mon Dec 18 12:27:58 2006 @@ -18,7 +18,7 @@ | Authors: Dave Renshaw, Jerry Stevens | +----------------------------------------------------------------------+ - $Id: php_sam.h,v 1.3 2006/12/08 17:39:54 dsr Exp $ + $Id: php_sam.h,v 1.4 2006/12/18 12:27:58 dsr Exp $ */ @@ -54,7 +54,7 @@ */ #define SAM__MODULE_NAME "sam" -#define SAM__MODULE_VERSION "0.3" +#define SAM__MODULE_VERSION "1.0" #define PHP_SAM_CONNECTION_RES_NAME "__SAM_XMS_Connection_pointer" @@ -91,13 +91,13 @@ #define SAM_CONSTANT_WPM_DUR_SUB_HOME "SAM_WPM_DUR_SUB_HOME" /* property values */ -#define SAM_CONSTANT_AUTO "auto" +#define SAM_CONSTANT_AUTO "SAM_AUTO" #define SAM_CONSTANT_BYTES "SAM_BYTES" #define SAM_CONSTANT_WMQTARGETCLIENT_JMS "jms" #define SAM_CONSTANT_WMQTARGETCLIENT_MQ "mq" -#define SAM_CONSTANT_MANUAL "manual" -#define SAM_CONSTANT_NONPERSISTENT "nonpersistent" -#define SAM_CONSTANT_PERSISTENT "persistent" +#define SAM_CONSTANT_MANUAL "SAM_MANUAL" +#define SAM_CONSTANT_NONPERSISTENT "SAM_NON_PERSISTENT" +#define SAM_CONSTANT_PERSISTENT "SAM_PERSISTENT" #define SAM_CONSTANT_TEXT "SAM_TEXT" #define SAM_CONSTANT_UNKNOWN "SAM_UNKNOWN" @@ -117,6 +117,10 @@ #define SAM_CONSTANT_OPTION_CLIENT "client" #define SAM_CONSTANT_OPTION_BINDINGS "bindings" +/* Error constants */ +#define SAM_CONSTANT_RECEIVE_TIMEDOUT "SAM_RECEIVE_TIMEDOUT" + + /***************************************************************************/ /* */ /* Individual include files for each PHP class */
« previous php.pecl.cvs (#6804) next »