Re: cvs: pecl /sam SAM_Connection.c SAM_Connection.h SAM_Message.c SAM_Message.h SAM_Utils.c SAM_Utils.h config.m4 config.w32 package.xml php_sam.c
php_sam.h sam.dsp

From: Date: Wed, 22 Nov 2006 19:15:40 +0000
Subject: Re: cvs: pecl /sam SAM_Connection.c SAM_Connection.h SAM_Message.c SAM_Message.h SAM_Utils.c SAM_Utils.h config.m4 config.w32 package.xml php_sam.c
php_sam.h sam.dsp
References: 1  Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6675@lists.php.net to get a copy of this message
Dave Renshaw wrote: > dsr Wed Nov 22 17:06:57 2006 UTC > > Added files: > /pecl/sam SAM_Utils.c SAM_Utils.h > > Modified files: > /pecl/sam SAM_Connection.c SAM_Connection.h SAM_Message.c > SAM_Message.h config.m4 config.w32 package.xml php_sam.c > php_sam.h sam.dsp > Log: > > > > > ------------------------------------------------------------------------ > > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Connection.c?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/SAM_Connection.c > diff -u pecl/sam/SAM_Connection.c:1.1 pecl/sam/SAM_Connection.c:1.2 > --- pecl/sam/SAM_Connection.c:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/SAM_Connection.c Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,7 +18,7 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: SAM_Connection.c,v 1.1 2006/11/08 12:02:08 dsr Exp $ > +$Id: SAM_Connection.c,v 1.2 2006/11/22 17:06:57 dsr Exp $ > > */ > > @@ -59,6 +59,7 @@ > PHP_NAMED_FE(disconnect, PHP_FN(SAM_Connection_disconnect) , NULL) > PHP_NAMED_FE(isconnected, PHP_FN(SAM_Connection_isConnected) , NULL) > PHP_NAMED_FE(peek, PHP_FN(SAM_Connection_peek), NULL) > + PHP_NAMED_FE(peekAll, PHP_FN(SAM_Connection_peekAll), NULL) > PHP_NAMED_FE(receive, PHP_FN(SAM_Connection_receive), NULL) > PHP_NAMED_FE(remove, PHP_FN(SAM_Connection_remove), NULL) > PHP_NAMED_FE(rollback, PHP_FN(SAM_Connection_rollback), NULL) > @@ -377,10 +378,10 @@ > if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> Caller > specified target chain of <b>%s</b><br/>", szTargetChain); > } > > - } // zend_hash_num_elements(optionsHT) > 0 > + } /* zend_hash_num_elements(optionsHT) > 0 */ > } else { > if (SAM_DEBUG) zend_printf("<b>SAMConnection->connect()</b> No options > array specified.<br/>"); > - } // zvOptions > + } /* zvOptions */ > > /* Create an error block for capturing any error information from XMS... */ > if (XMS_OK != xmsErrorCreate(&errorBlock)) { > @@ -517,7 +518,7 @@ > } > } > > - /* create the connection factory... */ > + /* create the XMS connection */ > rc = xmsConnFactCreateConnection(connFactory, &connection, errorBlock); > if (XMS_OK != rc) { > if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->connect()</b> > Connection create failed!\n"); > @@ -540,7 +541,12 @@ > /* Create a resource to represent this XMS connection */ > MAKE_STD_ZVAL(zConnection); > connResource = emalloc(sizeof(php_sam_connection)); > + connResource->connFact = connFactory; > connResource->conn = connection; > + > + /* copy the protocol type into the connection resource (so we can validate the target client > option in the send) */ > + strcpy(connResource->protocol, szProtocol); > + > ZEND_REGISTER_RESOURCE(zConnection, connResource, le_sam_connection); > > /* Store the connection property in this object's hash table */ > @@ -564,6 +570,8 @@ > > php_sam_connection *connResource; > zval **zConnection; > + xmsHErrorBlock errorBlock; > + int rc; > > if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->disconnect()</b> > enter<br/>"); > > @@ -575,13 +583,61 @@ > ZEND_FETCH_RESOURCE(connResource, php_sam_connection*, zConnection, -1, > PHP_SAM_CONNECTION_RES_NAME, le_sam_connection); > > if (connResource) { > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> closing > connection %d<br/>", connResource->conn); > - /* Free the resource memory and this will cause the resource cleanerupperer to close the > connection */ > - efree(connResource); > - /* Having removed the resource we must make sure we remove the hashtable entry that points > to it... */ > + > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_FALSE; > + } > + > + > + 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); > + 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); > + rc = xmsConnClose(&connResource->conn, errorBlock); > + if (XMS_OK != rc) { > + if (SAM_DEBUG) > zend_printf("<br/><b>SAMConnection->disconnect()</b> Connection close > failed!\n"); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CONNECTION_CLOSE, > SAM_CONNECTION_CONNECTION_CLOSE_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + > + } > + > + /* Set the connection to NULL to eliminate the possibility of attempting to disconnect > again */ > + 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)); > - } > > + /* Dispose of the error block */ > + xmsErrorDispose(&errorBlock); > + } > if (SAM_DEBUG) zend_printf("<b>SAMConnection->disconnect()</b> > exit<br/>"); > RETURN_TRUE; > } > @@ -615,30 +671,1192 @@ > Please add prototype, so the docs tools can generate doc skeletongs. > PHP_FUNCTION(SAM_Connection_peek) > { > + int rc; > + > + char *destString = NULL; /* Destination string parsed in via the argument list */ > + int destLength=0; /* Length of the destination given in the arg list */ > + > + zval *zvOptions = NULL; > + HashTable *optionsHT; > + zval **zTemp; > + > + char *szCorrelID = NULL; > + char *szMessageID = NULL; > + xmsCHAR *szSelector = NULL; > + > + xmsHErrorBlock errorBlock; > + xmsHSess session = XMS_NULL_HANDLE; > + xmsHDest dest = XMS_NULL_HANDLE; > + xmsHQueueBrowser qbrowser = XMS_NULL_HANDLE; > + xmsHIterator browserIterator; > + xmsHMsg message; > + > + xmsMESSAGE_TYPE messageType; > + > + int transacted = xmsFALSE; > + xmsCHAR *text = NULL; > + xmsINT receivedLength; > + > + xmsHIterator props; > + xmsHProperty prop; > + xmsBOOL messagesReturned; > + > + php_sam_connection *connResource; > + zval **zConnection; > + > + zval* msg; > + zval* func; > + zval* zBody; > + zval* parms[1]; > + zval* zVal; > + zval* zMsgHdr; > + > + xmsCHAR *msgID; > + xmsINT length; Please use tabs :) > + > + xmsCHAR *propName=NULL, *propValue = NULL; > + xmsINT pnLength, pvLength; > + > + > if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->peek()</b> > enter<br/>"); > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> > exit<br/>"); > - RETURN_FALSE; > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > + "s|a", &destString, &destLength, &zvOptions) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_PEEK, > SAM_CONNECTION_WRONG_PARAMETERS_PEEK_MSG); > + WRONG_PARAM_COUNT; AFAIK, WRONG_PARAM_COUNT is not used. zend_parse_parameters should take care of it. > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Target > destination is: %s.<br/>", destString); > + > + > + /* 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->peek()</b> connection is > %d<br/>", connResource->conn); > + > + /* Take a look in the options array if we have one... */ > + if (zvOptions) { > + optionsHT = Z_ARRVAL_P(zvOptions); > + if (zend_hash_num_elements(optionsHT) > 0) { > + optionsHT = HASH_OF(zvOptions); > + > + /* Has a correlID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_CORRELID, sizeof(SAM_CONSTANT_CORRELID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szCorrelID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CORRELID_ALLOC_FAILED, > SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szCorrelID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > + } > + > + /* Has a messageID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_MESSAGEID, sizeof(SAM_CONSTANT_MESSAGEID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szMessageID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGEID_ALLOC_FAILED, > SAM_CONNECTION_MESSAGEID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szMessageID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szMessageID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Caller > specified messageID of <b>%s</b><br/>", szMessageID); > + } > + } /* zend_hash_num_elements(optionsHT) > 0 */ > + } else { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> No options > array specified.<br/>"); > + } /* zvOptions */ > + > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsDestCreate(destString, &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + if (SAM_DEBUG) check(errorBlock); > + 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; > + } > + > + /* 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); > + } 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); > + > + /* Free any correlId & message id buffers */ > + if (NULL != szCorrelID) efree(szCorrelID); > + if (NULL != szMessageID) efree(szMessageID); Please follow the PECL Coding Standards. This should look like if (NULL != szMessageID) { efree (szMessageID); } > + > + /* Free the selector string */ > + if (NULL != szSelector) efree(szSelector); > + } > + > + if (XMS_OK != rc) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_QBROWSER, SAM_CONNECTION_NO_QBROWSER_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> About to browse > messages<br/>"); > + if (XMS_OK != xmsQueueBrowserGetEnumeration(qbrowser, &browserIterator, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_QBROWSE_FAILED, > SAM_CONNECTION_QBROWSE_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsIteratorHasNext(browserIterator, &messagesReturned, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HASNEXT_FAILED, > SAM_CONNECTION_HASNEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (!messagesReturned) > + { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> No matching > messages<br/>"); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsIteratorGetNext(browserIterator, (xmsHObj*)&message, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_GETNEXT_FAILED, > SAM_CONNECTION_GETNEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* Finished with the iterator so throw it away */ > + xmsIteratorDispose(&browserIterator, errorBlock); > + > + /* get the message type... */ > + if (XMS_OK != xmsMsgGetTypeId(message, &messageType, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_TYPE_GET_FAILED, > SAM_CONNECTION_TYPE_GET_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now attempt to allocate the buffer */ > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> allocating %d > bytes for rcvd bytes msg<br/>", receivedLength); > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsTextMsgGetText(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now attempt to allocate the buffer */ > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> allocating %d > bytes for rcvd text msg<br/>", receivedLength); > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + > + } > + > + if (XMS_OK != xmsTextMsgGetText(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_GETTEXT_FAILED, > SAM_CONNECTION_GETTEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + } > + > + /* create a new SAM_Message object to hold the results... */ > + MAKE_STD_ZVAL(msg); > + Z_TYPE_P(msg) = IS_OBJECT; This is redundant, object_init_ex() will set it. > + object_init_ex(msg, php_sam_SAM_Message_entry); > + > + /* call the constructor */ > + MAKE_STD_ZVAL(func); > + ZVAL_STRING(func, "sammessage", 1); > + > + MAKE_STD_ZVAL(zBody); > + ZVAL_STRINGL(zBody, text, receivedLength, 1); > + parms[0] = zBody; > + call_user_function(&php_sam_SAM_Message_entry->function_table, &msg, func, > return_value, 1, parms TSRMLS_CC); > + > + return_value->value.obj = msg->value.obj; > + return_value->type = msg->type; > + > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Message of %ld > bytes peeked<br/>", receivedLength); > + > + /* Create the SAM message header property... */ > + MAKE_STD_ZVAL(zMsgHdr); > + object_init(zMsgHdr); > + > + if (add_property_zval(msg, SAM_MESSAGE_HEADER, zMsgHdr) == FAILURE) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Unable to > create header property in message!<br/>", receivedLength); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HEADER_CREATE_FAILED, > SAM_CONNECTION_HEADER_CREATE_FAILED_MSG); > + return; > + } > + > + /* find the message id... */ > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, XMSC_QUERY_SIZE, &length, > errorBlock)) { > + msgID = emalloc(length); > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, length, NULL, errorBlock)) { > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, msgID, length, 1); > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_MESSAGEID, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + } > + } No spaces please ;) > + > + /* see what properties we have in the XMS message that we can reflect in the SAM message... > */ > + if (XMS_OK != xmsMsgGetProperties(message, &props, errorBlock)) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Unable to > retrieve message properties!<br/>", receivedLength); > + } else { > + /* Walk through the properties... */ > + while(XMS_OK == xmsIteratorGetNext(props, (xmsHObj*)&prop, errorBlock)) { > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, XMSC_QUERY_SIZE, > &pnLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propName = emalloc(pnLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPNAME_ALLOC_FAILED, > SAM_CONNECTION_PROPNAME_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, pnLength, &pnLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, XMSC_QUERY_SIZE, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propValue = emalloc(pvLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPVAL_ALLOC_FAILED, > SAM_CONNECTION_PROPVAL_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, pvLength, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> Retrieved > message property '%s' value=%s<br/>", propName, propValue); > + > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, propValue, pvLength, 1); > + if (add_property_zval(zMsgHdr, propName, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + > + if (NULL != propName) efree(propName); > + if (NULL != propValue) efree(propValue); > + } /*while*/ > + > + /* Finished with the iterator so throw it away... */ > + xmsIteratorDispose(&props, errorBlock); > + } > + > + /* if we understood then set the message type as a header property... */ > + MAKE_STD_ZVAL(zVal); > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + ZVAL_STRING(zVal, SAM_CONSTANT_BYTES, 1); > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + ZVAL_STRING(zVal, SAM_CONSTANT_TEXT, 1); > + } else { > + ZVAL_STRING(zVal, SAM_CONSTANT_UNKNOWN, 1); > + } ZVAL_STRING is a macro, three times using it, will make the code explode a bit. Probably better is to put the whole thing in a block, have a temporary char* variable to be initialized in the if() and then have one ZVAL_STRING. Even better, is to add an long variable for the length. I suppose these three texts are const strings, so you can use sizeof() to get the size at compile time and then use ZVAL_STRINGL. > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_TYPE, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + > + /* Free the buffer we allocated for the data retrieved from the message */ > + if (NULL != text) efree(text); > + > + xmsMsgDispose(&message, errorBlock); > + xmsQueueBrowserClose(&qbrowser, errorBlock); > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> > exit<br/>"); > + return; This return is redundant. One more question, if an error happens, how do you do the clean, you do few lines above? Or you leak? > } > > -/* ******************************************************************************** > -| RECEIVE | > -| ------- | > -| | > -******************************************************************************** */ > +PHP_FUNCTION(SAM_Connection_peekAll) > +{ > + int rc; > + > + char *destString = NULL; /* Destination string parsed in via the argument list */ > + int destLength=0; /* Length of the destination given in the arg list */ > + > + zval *zvOptions = NULL; > + HashTable *optionsHT; > + zval **zTemp; > + > + char *szCorrelID = NULL; > + char *szMessageID = NULL; > + xmsCHAR *szSelector = NULL; > + > + xmsHErrorBlock errorBlock; > + xmsHSess session = XMS_NULL_HANDLE; > + xmsHDest dest = XMS_NULL_HANDLE; > + xmsHQueueBrowser qbrowser = XMS_NULL_HANDLE; > + xmsHIterator browserIterator; > + xmsHMsg message; > + > + xmsMESSAGE_TYPE messageType; > + > + int transacted = xmsFALSE; > + xmsCHAR *text = NULL; > + xmsINT receivedLength; > + > + > + xmsHIterator props; > + xmsHProperty prop; > + xmsBOOL messagesReturned; > + > + php_sam_connection *connResource; > + zval **zConnection; > + > + zval* func; > + zval* zBody; > + zval* parms[1]; > + zval* zVal; > + zval* zMsgHdr; > + > + xmsCHAR *msgID; > + xmsINT length; > + > + xmsCHAR *propName = NULL; > + xmsCHAR *propValue = NULL; > + xmsINT pnLength, pvLength; > + > + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->peekAll()</b> > enter<br/>"); > + > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > + "s|a", &destString, &destLength, &zvOptions) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_PEEKALL, > SAM_CONNECTION_WRONG_PARAMETERS_PEEKALL_MSG); > + WRONG_PARAM_COUNT; > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Target > destination is: %s.<br/>", destString); > + > + > + /* 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->peekAll()</b> connection > is %d<br/>", connResource->conn); > + > + /* Take a look in the options array if we have one... */ > + if (zvOptions) { > + optionsHT = Z_ARRVAL_P(zvOptions); > + if (zend_hash_num_elements(optionsHT) > 0) { > + optionsHT = HASH_OF(zvOptions); > + > + /* Has a correlID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_CORRELID, sizeof(SAM_CONSTANT_CORRELID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szCorrelID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CORRELID_ALLOC_FAILED, > SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szCorrelID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > + } > + > + /* Has a messageID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_MESSAGEID, sizeof(SAM_CONSTANT_MESSAGEID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szMessageID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGEID_ALLOC_FAILED, > SAM_CONNECTION_MESSAGEID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szMessageID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szMessageID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Caller > specified messageID of <b>%s</b><br/>", szMessageID); > + } > + > + } /* zend_hash_num_elements(optionsHT) > 0 */ > + } else { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> No options > array specified.<br/>"); > + } /* zvOptions */ > + > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsDestCreate(destString, &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + if (SAM_DEBUG) check(errorBlock); > + 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; > + } > + > + /* 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); > + } 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); > + > + /* Free any correlId & message id buffers */ > + if (NULL != szCorrelID) efree(szCorrelID); > + if (NULL != szMessageID) efree(szMessageID); > + > + /* Free any selector string */ > + if (NULL != szSelector) efree(szSelector); > + } > + > + > + if (XMS_OK != rc) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_QBROWSER, SAM_CONNECTION_NO_QBROWSER_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> About to > browse messages<br/>"); > + if (XMS_OK != xmsQueueBrowserGetEnumeration(qbrowser, &browserIterator, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_QBROWSE_FAILED, > SAM_CONNECTION_QBROWSE_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsIteratorHasNext(browserIterator, &messagesReturned, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HASNEXT_FAILED, > SAM_CONNECTION_HASNEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (!messagesReturned) > + { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> No matching > messages<br/>"); > + RETURN_FALSE; > + } > + > + /* Initialise the array of messages to be returned */ > + array_init(return_value); > + > + while (XMS_OK == xmsIteratorGetNext(browserIterator, (xmsHObj*)&message, errorBlock)) > + { > + /* get the message type... */ > + if (XMS_OK != xmsMsgGetTypeId(message, &messageType, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_TYPE_GET_FAILED, > SAM_CONNECTION_TYPE_GET_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now attempt to allocate the buffer */ > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> allocating %d > bytes for rcvd bytes msg<br/>", receivedLength); > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsTextMsgGetText(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now attempt to allocate the buffer */ > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peek()</b> allocating %d > bytes for rcvd bytes msg<br/>", receivedLength); > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + > + } > + > + if (XMS_OK != xmsTextMsgGetText(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_GETTEXT_FAILED, > SAM_CONNECTION_GETTEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + } > + > + /* create a new SAM_Message object to hold the results... */ > + { > + zval* msg; > + zval* cnstrRetVal; > + MAKE_STD_ZVAL(msg); > + Z_TYPE_P(msg) = IS_OBJECT; > + object_init_ex(msg, php_sam_SAM_Message_entry); > + > + /* call the constructor */ > + MAKE_STD_ZVAL(func); > + ZVAL_STRING(func, "sammessage", 1); Use ZVAL_STRINGL with sizeof() > + > + MAKE_STD_ZVAL(zBody); > + ZVAL_STRINGL(zBody, text, receivedLength, 1); > + parms[0] = zBody; > + > + /* This is a (dummy) ZVAL for the constructor return value */ > + MAKE_STD_ZVAL(cnstrRetVal); > + > + call_user_function(&php_sam_SAM_Message_entry->function_table, &msg, func, > cnstrRetVal, 1, parms TSRMLS_CC); > + > + /* return_value->value.obj = msg->value.obj; > + return_value->type = msg->type; */ > + > + /* Add this message to the array of messages to be returned */ > + add_next_index_zval(return_value, msg); > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Message of > %ld bytes peeked<br/>", receivedLength); > + > + /* Create the SAM message header property... */ > + MAKE_STD_ZVAL(zMsgHdr); > + object_init(zMsgHdr); > + > + if (add_property_zval(msg, SAM_MESSAGE_HEADER, zMsgHdr) == FAILURE) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Unable to > create header property in message!<br/>", receivedLength); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HEADER_CREATE_FAILED, > SAM_CONNECTION_HEADER_CREATE_FAILED_MSG); > + return; > + } > + > + > + /* find the message id... */ > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, XMSC_QUERY_SIZE, > &length, errorBlock)) { > + msgID = emalloc(length); > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, length, NULL, > errorBlock)) { > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, msgID, length, 1); > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_MESSAGEID, zVal) == > FAILURE) { > + setError(this_ptr TSRMLS_CC, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + } > + } Please use tabs > + /* see what properties we have in the XMS message that we can reflect in the SAM > message... */ > + if (XMS_OK != xmsMsgGetProperties(message, &props, errorBlock)) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> Unable to > retrieve message properties!<br/>", receivedLength); > + } else { > + /* Walk through the properties... */ > + while(XMS_OK == xmsIteratorGetNext(props, (xmsHObj*)&prop, errorBlock)) { > + > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, XMSC_QUERY_SIZE, > &pnLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propName = emalloc(pnLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPNAME_ALLOC_FAILED, > SAM_CONNECTION_PROPNAME_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, pnLength, &pnLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, XMSC_QUERY_SIZE, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propValue = emalloc(pvLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPVAL_ALLOC_FAILED, > SAM_CONNECTION_PROPVAL_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, pvLength, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> > Retrieved message property '%s' value=%s<br/>", propName, propValue); > + > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, propValue, pvLength, 1); > + if (add_property_zval(zMsgHdr, propName, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + > + if (NULL != propName) efree(propName); > + if (NULL != propValue) efree(propValue); > + } /*while*/ > + > + /* Finished with the iterator so throw it away... */ > + xmsIteratorDispose(&props, errorBlock); > + } > + > + /* if we understood then set the message type as a header property... */ > + MAKE_STD_ZVAL(zVal); > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + ZVAL_STRING(zVal, SAM_CONSTANT_BYTES, 1); > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + ZVAL_STRING(zVal, SAM_CONSTANT_TEXT, 1); > + } else { > + ZVAL_STRING(zVal, SAM_CONSTANT_UNKNOWN, 1); > + } > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_TYPE, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + } > + > + /* Free the buffer we allocated for the data retrieved from the message */ > + if (NULL != text) efree(text); > + } > + > + /* Finished with the iterator so throw it away */ > + xmsIteratorDispose(&browserIterator, errorBlock); > + > + xmsMsgDispose(&message, errorBlock); > + xmsQueueBrowserClose(&qbrowser, errorBlock); > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->peekAll()</b> > exit<br/>"); > + return; redundant > +} > + > + > + > +/* ******************************************************************************** > +| RECEIVE | > +| ------- | > +| | > +******************************************************************************** */ > + > +PHP_FUNCTION(SAM_Connection_receive) { > + > + int rc; > + > + char *destString = NULL; /* Destination string parsed in via the argument list */ > + int destLength=0; /* Length of the destination given in the arg list */ > + > + char destPrefix[128] = { '\0' }; /* The destination prefix - topic, queue or sub > */ > + char aDestination[128] = { '\0' }; /* The destination parsed out of the > destination given in the argument list */ > + char *tempString; > + > + char aSubscriptionName[128] ={ '\0' }; > + int subNameLength = 0; > + > + xmsBOOL noLocal = xmsFALSE; > + > + zval *zvOptions = NULL; > + > + HashTable *optionsHT; > + zval **zTemp; > + > + char *szCorrelID = NULL; > + char *szMessageID = NULL; > + xmsCHAR *szSelector = NULL; > + > + xmsINT waitTimeout = 0; > + > + xmsHErrorBlock errorBlock; > + xmsHSess session = XMS_NULL_HANDLE; > + xmsHDest dest = XMS_NULL_HANDLE; > + xmsHMsgConsumer consumer = XMS_NULL_HANDLE; > + xmsHMsg message; > + int transacted = xmsFALSE; > + xmsCHAR *text = NULL; > + xmsINT receivedLength; > + > + > + xmsHIterator props; > + xmsHProperty prop; > + xmsMESSAGE_TYPE messageType; > + > + php_sam_connection *connResource; > + zval **zConnection; > + > + zval* msg; > + zval* func; > + zval* zBody; > + zval* parms[1]; > + zval* zVal; > + zval* zMsgHdr; > + int i,j; > + > + xmsCHAR *msgID; > + xmsINT length; No spaces > + > + xmsCHAR *propName = NULL; > + xmsCHAR *propValue = NULL; > + xmsINT pnLength, pvLength; > + > + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->receive()</b> > enter<br/>"); > + > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > + "s|a", &destString, &destLength, &zvOptions) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_RECEIVE, > SAM_CONNECTION_WRONG_PARAMETERS_RECEIVE_MSG); > + WRONG_PARAM_COUNT; WRONG_PARAM_COUNT is redunant > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Target > destination is: %s.<br/>", destString); > + > + > + /* Extract the prefix from the destination string, this should be "queue", > "topic" or "sub" */ > + for (i = 0, j = 0; j >= 0 && i < destLength && j < > sizeof(destPrefix); i++, j++) { > + switch (destString[i]) { Indented after the case?! > + case '\0': > + case SAM_CONNECTION_PROTOCOL_SEPERATOR: > + destPrefix[j] = '\0'; > + j = -2; > + break; > + > + default: > + destPrefix[j] = destString[i]; > + break; > + } > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Destination > prefix: %s.<br/>", destPrefix); > + > + /* Parse the destination in the argument list > + For destinations not prefixed with "sub:" we just use the whole argument as the > destination > + Otherwise the destination string is expected to be in the form: > + sub://....subscription name...._topic://....... > + so we then parse out the destination from the end of the string */ > + if (0 != strcmp(destPrefix, SAM_CONSTANT_SUB)) { > + /* We do not have a destination with a subscription name so just use the input parameter > + as the destination string */ > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> No > subscription name provided.<br/>"); > + > + strncpy(aDestination, destString, destLength); > + } else { > + /* We have a destination with a subscription name. The topic should be at the end. Parse > out > + the topic and subscription name */ > + if ((destString == strstr(destString, SAM_CONSTANT_SUBPREFIX)) && > + (NULL != (tempString = strstr(destString, SAM_CONSTANT_TOPICPREFIX)))) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> > Subscription name type destination provided.<br/>"); > + > + /* Extract the trailing destination from the supplied subscription name URL */ > + strcpy(aDestination, tempString); > + > + /* Take out the real subscription name from the subscription name URL */ > + strncpy(aSubscriptionName, destString + strlen(SAM_CONSTANT_SUBPREFIX), > + strlen(destString+strlen(SAM_CONSTANT_SUBPREFIX)) - strlen(tempString)); > + > + subNameLength = strlen(aSubscriptionName); > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Parsed > subscription name: %s<br/>", aSubscriptionName); > + } One tab too much? > + else { > + /* We have a subscription type destination with no topic, this is invalid */ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + RETURN_FALSE; > + } > + } > + > + /* 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->receive()</b> connection > is %d<br/>", connResource->conn); > + > + /* Take a look in the options array if we have one... */ > + if (zvOptions) { > + optionsHT = Z_ARRVAL_P(zvOptions); > + if (zend_hash_num_elements(optionsHT) > 0) { > + optionsHT = HASH_OF(zvOptions); > + > + /* Has a correlID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_CORRELID, sizeof(SAM_CONSTANT_CORRELID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szCorrelID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CORRELID_ALLOC_FAILED, > SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szCorrelID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > + } > + > + /* Has a messageID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_MESSAGEID, sizeof(SAM_CONSTANT_MESSAGEID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > + > + if (NULL == (szMessageID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGEID_ALLOC_FAILED, > SAM_CONNECTION_MESSAGEID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szMessageID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szMessageID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Caller > specified messageID of <b>%s</b><br/>", szMessageID); > + } > + > + /* Has a timeout value been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_WAIT, sizeof(SAM_CONSTANT_WAIT), > (void**)&zTemp) == SUCCESS) { > + convert_to_long(*zTemp); > + waitTimeout = Z_LVAL_PP(zTemp); > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Caller > specified wait timeout of <b>%ld</b><br/>", waitTimeout); > + } > + } /* zend_hash_num_elements(optionsHT) > 0 */ > + } else { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> No options > array specified.<br/>"); > + } /* zvOptions */ > + > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsDestCreate(aDestination, &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + if (SAM_DEBUG) check(errorBlock); > + 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; > + } > + > + /* 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); > + } > + else > + { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Creating > durable subscriber<br/>"); > + rc = xmsSessCreateDurableSubscriber(session, dest, aSubscriptionName, &consumer, > errorBlock); > + } > + } else { > + /* Yes, so build a selector string accordingly */ > + szSelector = SAMBuildSelectorString(szCorrelID, szMessageID); > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Using > selector string - %s<br/>", szSelector); > + 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); > + } > + 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); > + } > + > + /* Free any correlId or message id buffers */ > + if (NULL != szCorrelID) efree(szCorrelID); > + if (NULL != szMessageID) efree(szMessageID); > + > + /* Free the selector string */ > + if (NULL != szSelector) efree(szSelector); > + } > + > + if (XMS_OK != rc) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_CONSUMER, SAM_CONNECTION_NO_CONSUMER_MSG); > + if (SAM_DEBUG) check(errorBlock); > + 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); > + RETURN_FALSE; > + } > + > + /* get the message type... */ > + if (XMS_OK != xmsMsgGetTypeId(message, &messageType, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_TYPE_GET_FAILED, > SAM_CONNECTION_TYPE_GET_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + > + > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now allocate the buffer */ > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsBytesMsgReadBytes(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + > + /* Allocate a buffer for the message */ > + /* -- First determine the length of the message */ > + if (XMS_OK != xmsTextMsgGetText(message, text, XMSC_QUERY_SIZE, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + /* -- Now attempt to allocate the buffer */ > + if (NULL == (text = emalloc(receivedLength))){ > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED, > SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + > + } > + > + if (XMS_OK != xmsTextMsgGetText(message, text, receivedLength, &receivedLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_GETTEXT_FAILED, > SAM_CONNECTION_GETTEXT_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + } > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Message of > %ld bytes received<br/>", receivedLength); > + > + /* create a new SAM_Message object to hold the results... */ > + MAKE_STD_ZVAL(msg); > + Z_TYPE_P(msg) = IS_OBJECT; > + object_init_ex(msg, php_sam_SAM_Message_entry); > + > + /* call the constructor */ > + MAKE_STD_ZVAL(func); > + ZVAL_STRING(func, "sammessage", 1); ZVAL_STRINGL > + > + MAKE_STD_ZVAL(zBody); > + ZVAL_STRINGL(zBody, text, receivedLength, 1); > + parms[0] = zBody; > + call_user_function(&php_sam_SAM_Message_entry->function_table, &msg, func, > return_value, 1, parms TSRMLS_CC); > + > + return_value->value.obj = msg->value.obj; > + return_value->type = msg->type; > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Message > received OK. '%.*s'<br/>", receivedLength, text); > + > + /* Create the SAM message header property... */ > + MAKE_STD_ZVAL(zMsgHdr); > + object_init(zMsgHdr); > + > + if (add_property_zval(msg, SAM_MESSAGE_HEADER, zMsgHdr) == FAILURE) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Unable to > create header property in message!<br/>", receivedLength); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HEADER_CREATE_FAILED, > SAM_CONNECTION_HEADER_CREATE_FAILED_MSG); > + return; > + } > + > + /* find the message id... */ > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, XMSC_QUERY_SIZE, &length, > errorBlock)) { > + msgID = emalloc(length); > + if (XMS_OK == xmsMsgGetJMSMessageID(message, msgID, length, NULL, errorBlock)) > { > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, msgID, length, 1); > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_MESSAGEID, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + } > + } > + > + /* see what properties we have in the XMS message that we can reflect in the SAM message... > */ > + if (XMS_OK != xmsMsgGetProperties(message, &props, errorBlock)) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Unable to > retrieve message properties!<br/>", receivedLength); > + } else { > + /* Walk through the properties... */ > + while(XMS_OK == xmsIteratorGetNext(props, (xmsHObj*)&prop, errorBlock)) { > + > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, XMSC_QUERY_SIZE, > &pnLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propName = emalloc(pnLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPNAME_ALLOC_FAILED, > SAM_CONNECTION_PROPNAME_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propName, pnLength, &pnLength, > errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, XMSC_QUERY_SIZE, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (NULL == (propValue = emalloc(pvLength))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPVAL_ALLOC_FAILED, > SAM_CONNECTION_PROPVAL_ALLOC_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, propValue, pvLength, > &pvLength, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Retrieved > message property '%s' value=%s<br/>", propName, propValue); > + > + MAKE_STD_ZVAL(zVal); > + ZVAL_STRINGL(zVal, propValue, pvLength, 1); > + if (add_property_zval(zMsgHdr, propName, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + > + if (NULL != propName) efree(propName); > + if (NULL != propValue) efree(propValue); > + } /*while*/ > + > + /* Finished with the iterator so throw it away... */ > + xmsIteratorDispose(&props, errorBlock); > + } > + > + /* if we understood then set the message type as a header property... */ > + MAKE_STD_ZVAL(zVal); > + if (messageType == XMS_MESSAGE_TYPE_BYTES) { > + ZVAL_STRING(zVal, SAM_CONSTANT_BYTES, 1); > + } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > + ZVAL_STRING(zVal, SAM_CONSTANT_TEXT, 1); > + } else { > + ZVAL_STRING(zVal, SAM_CONSTANT_UNKNOWN, 1); > + } Again as above, use a block, temp variables and one time ZVAL_STRING > + if (add_property_zval(zMsgHdr, SAM_CONSTANT_TYPE, zVal) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + RETURN_FALSE; > + } > + > + /* Free the buffer we allocated for the data retrieved from the message */ > + if (NULL != text) efree(text); > + > + xmsMsgDispose(&message, errorBlock); > + xmsMsgConsumerClose(&consumer, errorBlock); > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > > -PHP_FUNCTION(SAM_Connection_receive) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> > exit<br/>"); > + return; > +} > > +PHP_FUNCTION(SAM_Connection_remove) > +{ > int rc; > > - char *aDestination=NULL; > - int destLength=0; > + char *destString = NULL; /* Destination string parsed in via the argument list */ > + int destLength=0; /* Length of the destination given in the arg list */ > + > zval *zvOptions = NULL; > > HashTable *optionsHT; > zval **zTemp; > > - char szCorrelID[512] = { '\0' }; > + char *szCorrelID = NULL; > + char *szMessageID = NULL; > + xmsCHAR *szSelector = NULL; > + > xmsINT waitTimeout = 0; > > xmsHErrorBlock errorBlock; > @@ -647,223 +1865,133 @@ > xmsHMsgConsumer consumer = XMS_NULL_HANDLE; > xmsHMsg message; > int transacted = xmsFALSE; > - xmsCHAR text[500] = { '\0'}; > - xmsINT receivedLength; > - > - xmsCHAR szSelector[256] = { '\0'}; > > - xmsHIterator props; > - xmsHProperty prop; > - xmsCHAR propertyName[256] = { '\0'}; > - xmsINT nameLength; > - xmsMESSAGE_TYPE messageType; > > php_sam_connection *connResource; > zval **zConnection; > > - zval* msg; > - zval* func; > - zval* zBody; > - zval* parms[1]; > - zval* zVal; > - zval* zMsgHdr; > - > - if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->receive()</b> > enter<br/>"); > + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->remove()</b> > enter<br/>"); > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > - "s|a", &aDestination, &destLength, &zvOptions) == FAILURE) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_RECEIVE, > SAM_CONNECTION_WRONG_PARAMETERS_RECEIVE_MSG); > - WRONG_PARAM_COUNT; > - RETURN_FALSE; > - } > + "sa", &destString, &destLength, &zvOptions) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_REMOVE, > SAM_CONNECTION_WRONG_PARAMETERS_REMOVE_MSG); > + WRONG_PARAM_COUNT; > + RETURN_FALSE; > + } > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Target > destination is: %s.<br/>", aDestination); > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Target > destination is: %s.<br/>", destString); > > - /* 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->receive()</b> connection is > %d<br/>", connResource->conn); > + /* 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->remove()</b> connection is > %d<br/>", connResource->conn); > > - /* Take a look in the options array if we have one... */ > - if (zvOptions) { > - optionsHT = Z_ARRVAL_P(zvOptions); > - if (zend_hash_num_elements(optionsHT) > 0) { > - optionsHT = HASH_OF(zvOptions); > - > - /* Has a correlID been specified? */ > - if (zend_hash_find(optionsHT, SAM_CONSTANT_SELECT, sizeof(SAM_CONSTANT_SELECT), > (void**)&zTemp) == SUCCESS) { > - convert_to_string(*zTemp); > - strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > - } > - > - /* Has a timeout value been specified? */ > - if (zend_hash_find(optionsHT, SAM_CONSTANT_WAIT, sizeof(SAM_CONSTANT_WAIT), > (void**)&zTemp) == SUCCESS) { > - convert_to_long(*zTemp); > - waitTimeout = Z_LVAL_PP(zTemp); > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Caller > specified wait timeout of <b>%ld</b><br/>", waitTimeout); > - } > - } /* zend_hash_num_elements(optionsHT) > 0 */ > - } else { > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> No options > array specified.<br/>"); > - } /* zvOptions */ > + /* Take a look in the options array if we have one... */ > + if (zvOptions) { > + optionsHT = Z_ARRVAL_P(zvOptions); > + if (zend_hash_num_elements(optionsHT) > 0) { > + optionsHT = HASH_OF(zvOptions); > > - if (XMS_OK != xmsErrorCreate(&errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > - RETURN_FALSE; > - } > + /* Has a correlID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_CORRELID, sizeof(SAM_CONSTANT_CORRELID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > > - if (XMS_OK != xmsDestCreate(aDestination, &dest, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > - if (SAM_DEBUG) check(errorBlock); > - RETURN_FALSE; > - } > + if (NULL == (szCorrelID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CORRELID_ALLOC_FAILED, > SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG); > + 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; > - } > + strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szCorrelID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > + } > > - /* Do we have a correlation ID string? */ > - if (strlen(szCorrelID) == 0) { > - /* No, so create a consumer without specifying a selector */ > - rc = xmsSessCreateConsumer(session, dest, &consumer, errorBlock); > - } else { > - /* Yes, so build a selector string to filter the JMSCorrelationID */ > - strcpy(szSelector, "JMSCorrelationID = '"); > - strcat(szSelector, szCorrelID); > - strcat(szSelector, "'"); > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Using > selector string - %s<br/>", szSelector); > - rc = xmsSessCreateConsumerSelector(session, dest, szSelector, XMSC_CALCULATE_STRING_SIZE, > &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); > - RETURN_FALSE; > - } > + /* Has a messageID been specified? */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_MESSAGEID, sizeof(SAM_CONSTANT_MESSAGEID), > (void**)&zTemp) == SUCCESS) { > + convert_to_string(*zTemp); > > - 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); > - RETURN_FALSE; > - } > + if (NULL == (szMessageID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGEID_ALLOC_FAILED, > SAM_CONNECTION_MESSAGEID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > > - /* get the message type... */ > - if (XMS_OK != xmsMsgGetTypeId(message, &messageType, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_TYPE_GET_FAILED, > SAM_CONNECTION_TYPE_GET_FAILED_MSG); > - if (SAM_DEBUG) check(errorBlock); > - RETURN_FALSE; > - } > + strncpy(szMessageID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szMessageID[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Caller > specified messageID of <b>%s</b><br/>", szMessageID); > + } > > - if (messageType == XMS_MESSAGE_TYPE_BYTES) { > - if (XMS_OK != xmsBytesMsgReadBytes(message, text, sizeof(text), &receivedLength, > errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_READBYTES_FAILED, > SAM_CONNECTION_READBYTES_FAILED_MSG); > - if (SAM_DEBUG) check(errorBlock); > - RETURN_FALSE; > - } > - } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > - if (XMS_OK != xmsTextMsgGetText(message, text, sizeof(text), &receivedLength, > errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_GETTEXT_FAILED, > SAM_CONNECTION_GETTEXT_FAILED_MSG); > - if (SAM_DEBUG) check(errorBlock); > + } /* zend_hash_num_elements(optionsHT) > 0 */ > + } else { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> No options > array specified.<br/>"); > RETURN_FALSE; > - } > - } > - > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Message of > %ld bytes received<br/>", receivedLength); > + } /* zvOptions */ > > - /* create a new SAM_Message object to hold the results... */ > - MAKE_STD_ZVAL(msg); > - Z_TYPE_P(msg) = IS_OBJECT; > - object_init_ex(msg, php_sam_SAM_Message_entry); > - > - /* call the constructor */ > - MAKE_STD_ZVAL(func); > - ZVAL_STRING(func, "sammessage", 1); > - > - MAKE_STD_ZVAL(zBody); > - ZVAL_STRINGL(zBody, text, receivedLength, 1); > - parms[0] = zBody; > - call_user_function(&php_sam_SAM_Message_entry->function_table, &msg, func, > return_value, 1, parms TSRMLS_CC); > - > - return_value->value.obj = msg->value.obj; > - return_value->type = msg->type; > - > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Message > received OK. '%s'<br/>", text); > - > - /* Create the SAM message header property... */ > - MAKE_STD_ZVAL(zMsgHdr); > - object_init(zMsgHdr); > + if ( ( (NULL == szCorrelID) || (0 == strlen(szCorrelID) ) ) && > + ( (NULL == szMessageID) || (0 == strlen(szMessageID) ) ) ) { > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> No > correlation id or message id specified.<br/>"); > + RETURN_FALSE; > + } > > - if (add_property_zval(msg, SAM_MESSAGE_HEADER, zMsgHdr) == FAILURE) { > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Unable to > create header property in message!<br/>", receivedLength); > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HEADER_CREATE_FAILED, > SAM_CONNECTION_HEADER_CREATE_FAILED_MSG); > - return; > - } > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_FALSE; > + } > > - /* see what properties we have in the XMS message that we can reflect in the SAM message... > */ > - if (XMS_OK != xmsMsgGetProperties(message, &props, errorBlock)) { > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Unable to > retrieve message properties!<br/>", receivedLength); > - } else { > - /* Walk through the properties... */ > - while(XMS_OK == xmsIteratorGetNext(props, (xmsHObj*)&prop, errorBlock)) { > - if (XMS_OK != xmsPropertyGetName((xmsHProperty) prop, propertyName, sizeof(propertyName), > &nameLength, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_NAME_FAILED, > SAM_CONNECTION_PROPERTY_GET_NAME_FAILED_MSG); > + if (XMS_OK != xmsDestCreate(destString, &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > if (SAM_DEBUG) check(errorBlock); > RETURN_FALSE; > } > - if (XMS_OK != xmsPropertyGetString((xmsHProperty) prop, text, sizeof(text), > &receivedLength, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_PROPERTY_GET_STRING_FAILED, > SAM_CONNECTION_PROPERTY_GET_STRING_FAILED_MSG); > + > + 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 (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> Retrieved > message property '%s' value=%s<br/>", propertyName, text); > > - MAKE_STD_ZVAL(zVal); > - ZVAL_STRINGL(zVal, text, receivedLength, 1); > - if (add_property_zval(zMsgHdr, propertyName, zVal) == FAILURE) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > + /* Build a selector string from the message id or correlid */ > + szSelector = SAMBuildSelectorString(szCorrelID, szMessageID); > + > + /* Free the correlId and messageid buffers */ > + if (NULL != szCorrelID) efree(szCorrelID); > + if (NULL != szMessageID) efree(szMessageID); > + > + 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); > + > + /* Free the selector buffer */ > + if (NULL != szSelector) efree(szSelector); > + > + if (XMS_OK != rc) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_CONSUMER, SAM_CONNECTION_NO_CONSUMER_MSG); > + if (SAM_DEBUG) check(errorBlock); > RETURN_FALSE; > } > - } /*while*/ > - > - /* Finished with the iterator so throw it away... */ > - xmsIteratorDispose(&props, errorBlock); > - } > > - /* if we understood then set the message type as a header property... */ > - MAKE_STD_ZVAL(zVal); > - if (messageType == XMS_MESSAGE_TYPE_BYTES) { > - ZVAL_STRING(zVal, SAM_CONSTANT_BYTES, 1); > - } else if (messageType == XMS_MESSAGE_TYPE_TEXT) { > - ZVAL_STRING(zVal, SAM_CONSTANT_TEXT, 1); > - } else { > - ZVAL_STRING(zVal, SAM_CONSTANT_UNKNOWN, 1); > - } > - if (add_property_zval(zMsgHdr, SAM_CONSTANT_TYPE, zVal) == FAILURE) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED, > SAM_CONNECTION_MESSAGE_PROPERTY_SET_FAILED_MSG); > - RETURN_FALSE; > - } > + /* Here we just set the waitTimeout to a very low value */ > + waitTimeout = 1; > > - xmsMsgDispose(&message, errorBlock); > - xmsMsgConsumerClose(&consumer, errorBlock); > - xmsSessClose(&session, errorBlock); > - xmsErrorDispose(&errorBlock); > + if (XMS_OK != xmsMsgConsumerReceiveWithWait(consumer, waitTimeout, &message, > errorBlock) > + || (message == XMS_NULL_HANDLE)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_REMOVE_FAILED, > SAM_CONNECTION_REMOVE_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->receive()</b> > exit<br/>"); > - return; > -} > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> Message > removed<br/>"); > > -PHP_FUNCTION(SAM_Connection_remove) > -{ > - if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->remove()</b> > enter<br/>"); > + xmsMsgDispose(&message, errorBlock); > + xmsMsgConsumerClose(&consumer, errorBlock); > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> > exit<br/>"); > - RETURN_FALSE; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->remove()</b> > exit<br/>"); > + RETURN_TRUE; > } > > PHP_FUNCTION(SAM_Connection_rollback) > @@ -888,8 +2016,9 @@ > HashTable *optionsHT; > zval **zTemp; > > - char szCorrelID[512] = {'\0'}; > + char *szCorrelID = NULL; > char szDeliveryMode[512] = {'\0'}; > + char *szHeaders = NULL; /* Used to store any SAM_HEADER option (which must be > "none" or "jms") */ > xmsINT priority = -1; > xmsLONG timeToLive = -1; > > @@ -920,7 +2049,7 @@ > int key_len; > long index; > > - char *msgType = SAM_CONSTANT_BYTES; > + int msgType = SAM_MSGTYPE_BYTES; > > if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->send()</b> > enter<br/>"); > > @@ -963,9 +2092,16 @@ > optionsHT = HASH_OF(zvOptions); > > /* Has a correlID been specified? */ > - if (zend_hash_find(optionsHT, SAM_CONSTANT_SELECT, sizeof(SAM_CONSTANT_SELECT), > (void**)&zTemp) == SUCCESS) { > + if (zend_hash_find(optionsHT, SAM_CONSTANT_CORRELID, sizeof(SAM_CONSTANT_CORRELID), > (void**)&zTemp) == SUCCESS) { > convert_to_string(*zTemp); > + > + if (NULL == (szCorrelID = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_CORRELID_ALLOC_FAILED, > SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > strncpy(szCorrelID, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szCorrelID[Z_STRLEN_PP(zTemp)]=0; > if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> Caller > specified correlID of <b>%s</b><br/>", szCorrelID); > } > > @@ -1008,10 +2144,31 @@ > } > } > > - } // zend_hash_num_elements(optionsHT) > 0 > + /* Was the SAM_HEADERS option specified */ > + if (zend_hash_find(optionsHT, SAM_CONSTANT_HEADERS, sizeof(SAM_CONSTANT_HEADERS), > (void**)&zTemp) == SUCCESS) { > + > + if (NULL == (szHeaders = emalloc(Z_STRLEN_PP(zTemp)+1))) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_HEADERS_ALLOC_FAILED, > SAM_CONNECTION_HEADERS_ALLOC_FAILED_MSG); > + RETURN_FALSE; > + } > + > + strncpy(szHeaders, Z_STRVAL_PP(zTemp), Z_STRLEN_PP(zTemp)); > + szHeaders[Z_STRLEN_PP(zTemp)]=0; > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> Caller > specified headers of <b>%s</b><br/>", szHeaders); > + > + /* This option should be set to jms or none */ > + if ( (0 != strcmp(szHeaders, SAM_CONSTANT_HEADERS_JMS)) && > + (0 != strcmp(szHeaders, SAM_CONSTANT_HEADERS_NONE)) ) > + { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_ILLEGAL_HEADERS, > SAM_CONNECTION_ILLEGAL_HEADERS_MSG); > + RETURN_FALSE; > + } > + } > + > + } /* zend_hash_num_elements(optionsHT) > 0 */ > } else { > if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> No options > array specified.<br/>"); > - } // zvOptions > + } /* zvOptions */ > > /* 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) { > @@ -1021,6 +2178,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); > > + /* 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_HEADERS_MODE, > SAM_CONNECTION_ILLEGAL_HEADERS_MODE_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); > @@ -1034,6 +2197,16 @@ > RETURN_FALSE; > } > > + /* If we are not setting up the RFH2 for MQ then set the XMSC_WMQ_TARGET_CLIENT property to > XMSC_WMQ_TARGET_DEST_MQ */ > + if ( (NULL != szHeaders) && (0 == strcmp(szHeaders, SAM_CONSTANT_HEADERS_NONE))) { > + if (XMS_OK != xmsSetIntProperty( (xmsHObj) dest, XMSC_WMQ_TARGET_CLIENT, > XMSC_WMQ_TARGET_DEST_MQ, errorBlock)) { > + if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->send()</b> > xmsSetIntProperty (XMSC_WMQ_TARGET_CLIENT) failed!<br/>"); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_SET_TARGET_CLIENT, > SAM_CONNECTION_SET_TARGET_CLIENT_MSG); > + RETURN_FALSE; > + } > + 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); > @@ -1049,7 +2222,7 @@ > } > > /* Set the deliveryMode if one was specified */ > - if (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)) { > @@ -1096,46 +2269,44 @@ > } > > /* Do we have any header properties to reflect into the message? Here we are looking for > msgType only before > - we create the actual message > + we create the actual message > */ > if (zHeader) { > - /* Do we have a message type specified? */ > - if (zend_hash_find(Z_OBJPROP_PP(zHeader), SAM_CONSTANT_TYPE, > sizeof(SAM_CONSTANT_TYPE), (void**)&data) != FAILURE) { > + /* Do we have a message type specified? */ > + if (zend_hash_find(Z_OBJPROP_PP(zHeader), SAM_CONSTANT_TYPE, sizeof(SAM_CONSTANT_TYPE), > (void**)&data) != FAILURE) { > /* Is the message type specified something we understand? */ > if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> TYPE > =%s<br/>", Z_STRVAL_PP(data)); > - if (strncmp(key, SAM_CONSTANT_TYPE, key_len) == 0) { > - if ( (0 == strcmp(Z_STRVAL_PP(data), SAM_CONSTANT_TEXT)) || > - (0 == strcmp(Z_STRVAL_PP(data), SAM_CONSTANT_BYTES))) { > - msgType = Z_STRVAL_PP(data); > - } else { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_TYPE_INVALID, > SAM_CONNECTION_MSG_TYPE_INVALID_MSG); > - RETURN_FALSE; > - } > + if ( 0 == strncmp(Z_STRVAL_PP(data), SAM_CONSTANT_TEXT, Z_STRLEN_PP(data))) { > + msgType = SAM_MSGTYPE_TEXT; > + if (SAM_DEBUG) > zend_printf("<b>SAMConnection->send()</b> msgType=%s<br/>", > SAM_CONSTANT_TEXT); > + } else if (0 == strncmp(Z_STRVAL_PP(data), SAM_CONSTANT_BYTES, > Z_STRLEN_PP(data))) { > + msgType = SAM_MSGTYPE_BYTES; > + if (SAM_DEBUG) > zend_printf("<b>SAMConnection->send()</b> msgType=%s<br/>", > SAM_CONSTANT_BYTES); > + } else { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_MSG_TYPE_INVALID, > SAM_CONNECTION_MSG_TYPE_INVALID_MSG); > + RETURN_FALSE; > } > } else { > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> no TYPE > specified<br/>"); > - } > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> no TYPE > specified<br/>"); > + } > } > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> > msgType=%s<br/>", msgType); > - > - if (SAM_CONSTANT_BYTES == msgType) { > - /* Bytes message format - create xn XMS bytes message object that can take any arbitrary > data */ > - if (XMS_OK != xmsSessCreateBytesMessage(session, &message, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_BYTES_MESSAGE, > SAM_CONNECTION_NO_BYTES_MESSAGE_MSG); > - if (SAM_DEBUG) check(errorBlock); > - RETURN_FALSE; > - } > - > + 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)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_BYTES_MESSAGE, > SAM_CONNECTION_NO_BYTES_MESSAGE_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > } else { > - /* Text mesage format - create an XMS text message */ > - if (XMS_OK != xmsSessCreateTextMessage(session, &message, errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_TEXT_MESSAGE, > SAM_CONNECTION_NO_TEXT_MESSAGE_MSG); > - if (SAM_DEBUG) check(errorBlock); > - RETURN_FALSE; > - } > + /* Text message format - create an XMS text message */ > + if (XMS_OK != xmsSessCreateTextMessage(session, &message, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_TEXT_MESSAGE, > SAM_CONNECTION_NO_TEXT_MESSAGE_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > > - } > + } > > > /* Scan the rest of the header properties to reflect into the message */ > @@ -1162,7 +2333,7 @@ > RETURN_FALSE; > } > } else if (strncmp(key, SAM_CONSTANT_TYPE, key_len) == 0) { > - /* Ignore type as we have already dealt with it... */ > + /* Ignore type as we have already dealt with it... */ > } else { > if (SAM_DEBUG) zend_printf("<b>SAMConnection->send()</b> property > key =%s<br/>", key); > /* Doesn't look like anything we recognise so set it as a user property on the > message... */ > @@ -1265,10 +2436,10 @@ > } > > /* Move the message body into the message... */ > - if (SAM_CONSTANT_BYTES == msgType) { > - /* In this case we write the message as raw bytes with no character conversion */ > + if (SAM_MSGTYPE_BYTES == msgType) { > + /* In this case we write the message as raw bytes with no character conversion */ > if (XMS_OK != xmsBytesMsgWriteBytes(message, Z_STRVAL_PP(zMsg), Z_STRLEN_PP(zMsg), > errorBlock)) { > - setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRITE_BYTES_FAILED, > SAM_CONNECTION_WRITE_BYTES_FAILED_MSG); > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRITE_BYTES_FAILED, > SAM_CONNECTION_WRITE_BYTES_FAILED_MSG); > if (SAM_DEBUG) check(errorBlock); > RETURN_FALSE; > } > @@ -1281,13 +2452,13 @@ > } > > /* Do we have a correlation ID to set? */ > - if (strlen(szCorrelID) > 0) { > + if ((NULL != szCorrelID) && (strlen(szCorrelID) > 0)) { > if (XMS_OK != xmsMsgSetJMSCorrelationID(message, szCorrelID, strlen(szCorrelID), > errorBlock)) { > setError(this_ptr TSRMLS_CC, SAM_CONNECTION_SET_CORRELID_FAILED, > SAM_CONNECTION_SET_CORRELID_FAILED_MSG); > if (SAM_DEBUG) check(errorBlock); > RETURN_FALSE; > } > - } // strlen(szCorrelID) > 0 > + } > > /* Finally we can try and send the message... */ > if (XMS_OK != xmsMsgProducerSend(producer, message, errorBlock)) { > @@ -1296,6 +2467,9 @@ > RETURN_FALSE; > } > > + /* Free the correlId buffer */ > + if (NULL != szCorrelID) efree(szCorrelID); > + > /* retrieve the id of the message so we can use this as a correlation id */ > if (XMS_OK != xmsMsgGetJMSMessageID(message, NULL, XMSC_QUERY_SIZE, &length, > errorBlock)) { > setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_MSG_ID, SAM_CONNECTION_NO_MSG_ID_MSG); > @@ -1340,19 +2514,163 @@ > > PHP_FUNCTION(SAM_Connection_subscribe) > { > + int rc; > + > + char *aDestination=NULL; > + int destLength=0; > + > + xmsHErrorBlock errorBlock; > + xmsHSess session = XMS_NULL_HANDLE; > + xmsHDest dest = XMS_NULL_HANDLE; > + xmsHMsgConsumer consumer = XMS_NULL_HANDLE; > + int transacted = xmsFALSE; > + > + php_sam_connection *connResource; > + zval **zConnection; > + > + char subscriptionName[128]; > + > if (SAM_DEBUG) zend_printf("<br/><b>SAMConnection->subscribe()</b> > enter<br/>"); > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->subscribe()</b> > exit<br/>"); > - RETURN_FALSE; > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > + "s", &aDestination, &destLength) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_SUBSCRIBE, > SAM_CONNECTION_WRONG_PARAMETERS_SUBSCRIBE_MSG); > + WRONG_PARAM_COUNT; redundant > + RETURN_NULL(); actually just "return;" will suffice as the return_value wasn't initialized and defaults to PHP's NULL > + } > + > + if (SAM_DEBUG) { > + zend_printf("<b>SAMConnection->subscribe()</b> Target destination is: > %s.<br/>", aDestination); > + } > + > + /* 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_NULL(); redundant > + } > + > + 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); > + > + if (XMS_OK != xmsErrorCreate(&errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_ERROR_BLOCK, > SAM_CONNECTION_NO_ERROR_BLOCK_MSG); > + RETURN_NULL(); The brackets are redundant; > + } > + > + if (XMS_OK != xmsDestCreate(aDestination, &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_NULL(); > + } > + > + 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_NULL(); > + } > + > + if (0 == SAMGetSignature(subscriptionName)) { > + rc = xmsSessCreateDurableSubscriber(session, dest, subscriptionName, &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); > + RETURN_NULL(); > + } > + else { > + char urlString[128]; > + sprintf(urlString, "%s%s%s", SAM_CONSTANT_SUBPREFIX, subscriptionName, > aDestination); > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->subscribe()</b> > subscription url is %s<br/>", urlString); > + RETURN_STRING(urlString, 1); > + } > + } > + > + xmsMsgConsumerClose(&consumer, errorBlock); > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > + > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->subscribe()</b> > exit<br/>"); > + RETURN_NULL(); > } > > > PHP_FUNCTION(SAM_Connection_unsubscribe) > { > + xmsINT rc; > + xmsHSess session; > + xmsHDest dest; > + xmsHMsgConsumer consumer = XMS_NULL_HANDLE; > + int transacted = xmsFALSE; > + xmsHErrorBlock errorBlock; > + php_sam_connection *connResource; > + zval **zConnection; > + > + char *aSubscriptionName = NULL; > + int subNameLength; > + > if (SAM_DEBUG) > zend_printf("<br/><b>SAMConnection->unsubscribe()</b> > enter<br/>"); > > - if (SAM_DEBUG) zend_printf("<b>SAMConnection->unsubscribe()</b> > exit<br/>"); > - RETURN_FALSE; > -} > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, > + "s", &aSubscriptionName, &subNameLength) == FAILURE) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_WRONG_PARAMETERS_UNSUBSCRIBE, > SAM_CONNECTION_WRONG_PARAMETERS_UNSUBSCRIBE_MSG); > + WRONG_PARAM_COUNT; > + RETURN_FALSE; > + } > + > + if (SAM_DEBUG) { > + zend_printf("<b>SAMConnection->unsubscribe()</b> Subscription Name is: > %s.<br/>", aSubscriptionName); > + } > + > + > + /* 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_FALSE; > + } > + > + 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); > + > + /* 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); > + RETURN_FALSE; > + } > + > + /* NB: We have to create a subscriber and close it against this session otherwise the > unsubscribe fails with > + a 2019 error - defect raised 104864 - otherwise we would not need destination and create > subscriber code */ > + > + if (XMS_OK != xmsDestCreate("topic://dummyDest", &dest, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_NO_DESTINATION, > SAM_CONNECTION_NO_DESTINATION_MSG); > + if (SAM_DEBUG) check(errorBlock); > + 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; > + } > > + rc = xmsSessCreateDurableSubscriber(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); > + RETURN_FALSE; > + } > + > + xmsMsgConsumerClose(&consumer, errorBlock); > + > + if (XMS_OK != xmsSessUnsubscribe(session, aSubscriptionName, errorBlock)) { > + setError(this_ptr TSRMLS_CC, SAM_CONNECTION_UNSUBSCRIBE_FAILED, > SAM_CONNECTION_UNSUBSCRIBE_FAILED_MSG); > + if (SAM_DEBUG) check(errorBlock); > + RETURN_FALSE; > + } > + > + > + /* clean up the XMS structures we have finished with... */ > + xmsSessClose(&session, errorBlock); > + xmsErrorDispose(&errorBlock); > > + if (SAM_DEBUG) zend_printf("<b>SAMConnection->unsubscribe()</b> > exit<br/>"); > + RETURN_TRUE; > +} > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Connection.h?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/SAM_Connection.h > diff -u pecl/sam/SAM_Connection.h:1.1 pecl/sam/SAM_Connection.h:1.2 > --- pecl/sam/SAM_Connection.h:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/SAM_Connection.h Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,7 +18,7 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: SAM_Connection.h,v 1.1 2006/11/08 12:02:08 dsr Exp $ > + $Id: SAM_Connection.h,v 1.2 2006/11/22 17:06:57 dsr Exp $ > > */ > > @@ -31,7 +31,9 @@ > > /* Resource struct... */ > typedef struct _php_sam_connection { > + xmsHConnFact connFact; > xmsHConn conn; > + char protocol[128]; > } php_sam_connection; > > > @@ -43,6 +45,7 @@ > PHP_FUNCTION(SAM_Connection_disconnect); > PHP_FUNCTION(SAM_Connection_isConnected); > PHP_FUNCTION(SAM_Connection_peek); > +PHP_FUNCTION(SAM_Connection_peekAll); > PHP_FUNCTION(SAM_Connection_receive); > PHP_FUNCTION(SAM_Connection_remove); > PHP_FUNCTION(SAM_Connection_rollback); > @@ -160,7 +163,56 @@ > #define SAM_CONNECTION_TYPE_GET_FAILED_MSG "Unable to get message type!" > #define SAM_CONNECTION_GETTEXT_FAILED 255 > #define SAM_CONNECTION_GETTEXT_FAILED_MSG "XMS get of text from message > failed!" > - > +#define SAM_CONNECTION_WRONG_PARAMETERS_UNSUBSCRIBE 256 > +#define SAM_CONNECTION_WRONG_PARAMETERS_UNSUBSCRIBE_MSG "Incorrect number of parameters > on unsubscribe call!" > +#define SAM_CONNECTION_UNSUBSCRIBE_FAILED 257 > +#define SAM_CONNECTION_UNSUBSCRIBE_FAILED_MSG "Unable to unsubscribe from > specified subscription!" > +#define SAM_CONNECTION_WRONG_PARAMETERS_SUBSCRIBE 258 > +#define SAM_CONNECTION_WRONG_PARAMETERS_SUBSCRIBE_MSG "Incorrect number of parameters > on send call!" > +#define SAM_CONNECTION_WRONG_PARAMETERS_PEEK 259 > +#define SAM_CONNECTION_WRONG_PARAMETERS_PEEK_MSG "Incorrect number of parameters > on peek call!" > +#define SAM_CONNECTION_WRONG_PARAMETERS_REMOVE 260 > +#define SAM_CONNECTION_WRONG_PARAMETERS_REMOVE_MSG "Incorrect number of parameters > on remove call!" > +#define SAM_CONNECTION_NO_QBROWSER 261 > +#define SAM_CONNECTION_NO_QBROWSER_MSG "Unable to create XMS Queue > Browser!" > +#define SAM_CONNECTION_QBROWSE_FAILED 262 > +#define SAM_CONNECTION_QBROWSE_FAILED_MSG "XMS queue browse failed!" > +#define SAM_CONNECTION_HASNEXT_FAILED 263 > +#define SAM_CONNECTION_HASNEXT_FAILED_MSG "XMS queue browse failed!" > +#define SAM_CONNECTION_GETNEXT_FAILED 264 > +#define SAM_CONNECTION_GETNEXT_FAILED_MSG "XMS queue browse failed!" > +#define SAM_CONNECTION_REMOVE_FAILED 265 > +#define SAM_CONNECTION_REMOVE_FAILED_MSG "XMS receive to remove message > failed!" > +#define SAM_CONNECTION_ILLEGAL_HEADERS 266 > +#define SAM_CONNECTION_ILLEGAL_HEADERS_MSG "Illegal value for > SAM_HEADERS!" > +#define SAM_CONNECTION_ILLEGAL_HEADERS_MODE 267 > +#define SAM_CONNECTION_ILLEGAL_HEADERS_MODE_MSG "SAM_HEADERS can only be used > with WebSphere MQ!" > +#define SAM_CONNECTION_SET_TARGET_CLIENT 268 > +#define SAM_CONNECTION_SET_TARGET_CLIENT_MSG "Unable to set XMS target client > property!" > +#define SAM_CONNECTION_WRONG_PARAMETERS_PEEKALL 269 > +#define SAM_CONNECTION_WRONG_PARAMETERS_PEEKALL_MSG "Incorrect number of parameters > on peekAll call!" > +#define SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED 270 > +#define SAM_CONNECTION_MSG_BUFFER_ALLOC_FAILED_MSG "Unable to allocate buffer for > message to be retrieved!" > +#define SAM_CONNECTION_CORRELID_ALLOC_FAILED 271 > +#define SAM_CONNECTION_CORRELID_ALLOC_FAILED_MSG "Unable to allocate buffer for > correlation id!" > +#define SAM_CONNECTION_PROPVAL_ALLOC_FAILED 272 > +#define SAM_CONNECTION_PROPVAL_ALLOC_FAILED_MSG "Unable to allocate buffer for > property value!" > +#define SAM_CONNECTION_MESSAGEID_ALLOC_FAILED 273 > +#define SAM_CONNECTION_MESSAGEID_ALLOC_FAILED_MSG "Unable to allocate buffer for > message id!" > +#define SAM_CONNECTION_PROPNAME_ALLOC_FAILED 274 > +#define SAM_CONNECTION_PROPNAME_ALLOC_FAILED_MSG "Unable to allocate buffer for > property name!" > +#define SAM_CONNECTION_HEADERS_ALLOC_FAILED 275 > +#define SAM_CONNECTION_HEADERS_ALLOC_FAILED_MSG "Unable to allocate buffer for > SAM headers buffer!" > +#define SAM_CONNECTION_CONNECTION_STOP 276 > +#define SAM_CONNECTION_CONNECTION_STOP_MSG "Unable to stop XMS > connection!" > +#define SAM_CONNECTION_CONNECTION_CLOSE 277 > +#define SAM_CONNECTION_CONNECTION_CLOSE_MSG "Unable to close XMS > connection!" > +#define SAM_CONNECTION_CONNFACT_DELETE 278 > +#define SAM_CONNECTION_CONNFACT_DELETE_MSG "Unable to delete XMS connection > factory!" > + > +/* internal constants */ > +#define SAM_MSGTYPE_TEXT 1 > +#define SAM_MSGTYPE_BYTES 2 > > #endif /*__SAMPHPCONN_H__) */ > > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Message.c?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/SAM_Message.c > diff -u pecl/sam/SAM_Message.c:1.1 pecl/sam/SAM_Message.c:1.2 > --- pecl/sam/SAM_Message.c:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/SAM_Message.c Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,7 +18,7 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: SAM_Message.c,v 1.1 2006/11/08 12:02:08 dsr Exp $ > + $Id: SAM_Message.c,v 1.2 2006/11/22 17:06:57 dsr Exp $ > > */ > > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Message.h?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/SAM_Message.h > diff -u pecl/sam/SAM_Message.h:1.1 pecl/sam/SAM_Message.h:1.2 > --- pecl/sam/SAM_Message.h:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/SAM_Message.h Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,7 +18,7 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: SAM_Message.h,v 1.1 2006/11/08 12:02:08 dsr Exp $ > + $Id: SAM_Message.h,v 1.2 2006/11/22 17:06:57 dsr Exp $ > > */ > > > http://cvs.php.net/viewvc.cgi/pecl/sam/config.m4?r1=1.2&r2=1.3&diff_format=u > Index: pecl/sam/config.m4 > diff -u pecl/sam/config.m4:1.2 pecl/sam/config.m4:1.3 > --- pecl/sam/config.m4:1.2 Wed Nov 15 16:40:22 2006 > +++ pecl/sam/config.m4 Wed Nov 22 17:06:57 2006 > @@ -1,4 +1,4 @@ > -dnl $Id: config.m4,v 1.2 2006/11/15 16:40:22 dsr Exp $ > +dnl $Id: config.m4,v 1.3 2006/11/22 17:06:57 dsr Exp $ > dnl config.m4 for extension sam > > dnl Comments in this file start with the string 'dnl'. > @@ -12,7 +12,7 @@ > > dnl # --with-sam -> check with-path > SEARCH_PATH="/opt" > - SEARCH_FOR="/IBM/XMS/tools/c/include/xms.h" > + SEARCH_FOR="/IBM/XMS/tools/c/include/xms.h" > if test -r $PHP_SAM/; then # path given as parameter > SAM_DIR=$PHP_SAM > else # search default path list > @@ -24,7 +24,7 @@ > fi > done > fi > - > + > if test -z "$SAM_DIR"; then > AC_MSG_RESULT([not found]) > AC_MSG_ERROR([Please reinstall the XMS distribution]) > @@ -46,8 +46,8 @@ > ],[ > -L$SAM_DIR/IBM/XMS/lib -lm -ldl > ]) > - > + > PHP_SUBST(SAM_SHARED_LIBADD) > > - PHP_NEW_EXTENSION(sam, php_sam.c SAM_Connection.c SAM_Message.c, $ext_shared) > + PHP_NEW_EXTENSION(sam, php_sam.c SAM_Connection.c SAM_Message.c SAM_Utils.c, $ext_shared, , > -DLINUX) > fi > > http://cvs.php.net/viewvc.cgi/pecl/sam/config.w32?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/config.w32 > diff -u pecl/sam/config.w32:1.1 pecl/sam/config.w32:1.2 > --- pecl/sam/config.w32:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/config.w32 Wed Nov 22 17:06:57 2006 > @@ -9,7 +9,7 @@ > if ( CHECK_LIB("gxi.lib", "sam", PHP_SAM + "\\tools\\lib") > && > CHECK_HEADER_ADD_INCLUDE("xms.h", "CFLAGS_SAM", PHP_SAM + > "\\tools\\c\\include;")) { > > - EXTENSION("sam", "php_sam.c SAM_Connection.c SAM_Message.c", > "shared"); > + EXTENSION("sam", "php_sam.c SAM_Connection.c SAM_Message.c > SAM_Utils.c", "shared"); > AC_DEFINE('HAVE_SAM', 1); > } else { > WARNING("sam not enabled; libraries and headers not found"); > > http://cvs.php.net/viewvc.cgi/pecl/sam/package.xml?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/package.xml > diff -u pecl/sam/package.xml:1.1 pecl/sam/package.xml:1.2 > --- pecl/sam/package.xml:1.1 Tue Nov 14 12:46:23 2006 > +++ pecl/sam/package.xml Wed Nov 22 17:06:57 2006 > @@ -15,11 +15,11 @@ > </maintainer> > </maintainers> > <release> > - <version>0.1.0</version> > - <date>2006-11-14</date> > + <version>0.2.0</version> > + <date>2006-11-22</date> > <license>Apache 2.0</license> > <state>beta</state> > - <notes>Initial release of the SAM extension. > + <notes>Update release to add peek, peekAll and remove functionality. > </notes> > <deps> > <dep type="php" rel="ge" version="4.4.2" > optional="no"/> > @@ -37,10 +37,24 @@ > <file role="src" name="SAM_Connection.h"/> > <file role="src" name="SAM_Message.c"/> > <file role="src" name="SAM_Message.h"/> > + <file role="src" name="SAM_Utils.c"/> > + <file role="src" name="SAM_Utils.h"/> > <file role="src" name="sam.dsp"/> > + <dir name="tests"> > + <file role="src" name="sam_test1_wmq_p2p.php"/> > + <file role="src" name="sam_test2_wpm_p2p.php"/> > + </dir> <!-- tests --> > </dir> <!-- / --> > </filelist> > </release> > <changelog> > + <release> > + <version>0.1.0</version> > + <date>2006-11-14</date> > + <license>Apache 2.0</license> > + <state>beta</state> > + <notes>Initial release of the SAM extension. > + </notes> > + </release> > </changelog> > </package> > > http://cvs.php.net/viewvc.cgi/pecl/sam/php_sam.c?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/php_sam.c > diff -u pecl/sam/php_sam.c:1.1 pecl/sam/php_sam.c:1.2 > --- pecl/sam/php_sam.c:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/php_sam.c Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,8 +18,8 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: php_sam.c,v 1.1 2006/11/08 12:02:08 dsr Exp $ > - > +$Id: php_sam.c,v 1.2 2006/11/22 17:06:57 dsr Exp $ > + > */ > > #ifdef HAVE_CONFIG_H > @@ -49,12 +49,12 @@ > /* ZEND_DECLARE_MODULE_GLOBALS(sam) */ > > /* > - * > - * Every user visible function must have an entry in xms_functions[]. > - */ > +* > +* Every user visible function must have an entry in xms_functions[]. > +*/ > static function_entry sam_functions[] = { > - PHP_FE(sam_debug_off, NULL) > - PHP_FE(sam_debug_on, NULL) > + PHP_FE(sam_debug_off, NULL) > + PHP_FE(sam_debug_on, NULL) > {NULL, NULL, NULL} /* Must be the last line in xms_functions[] */ > }; > > @@ -62,20 +62,20 @@ > */ > zend_module_entry sam_module_entry = { > STANDARD_MODULE_HEADER, > - SAM__MODULE_NAME, /* Name by which this module is known in PHP */ > - sam_functions, /* Global variable containing module entry points */ > - PHP_MINIT(sam), /* Function to execute at module initialise */ > - NULL, /* Function to execute at module shutdown */ > - NULL, /* Replace with NULL if there's nothing to do at request > start */ > - NULL, /* Replace with NULL if there's nothing to do at request > end */ > - PHP_MINFO(sam), /* Used to dump out module information */ > - SAM__MODULE_VERSION, /* Version number of this extension */ > - STANDARD_MODULE_PROPERTIES > + SAM__MODULE_NAME, /* Name by which this module is known in PHP */ > + sam_functions, /* Global variable containing module entry points */ > + PHP_MINIT(sam), /* Function to execute at module initialise */ > + NULL, /* Function to execute at module shutdown */ > + NULL, /* Replace with NULL if there's nothing to do at request start > */ > + NULL, /* Replace with NULL if there's nothing to do at request end */ > + PHP_MINFO(sam), /* Used to dump out module information */ > + SAM__MODULE_VERSION, /* Version number of this extension */ > + STANDARD_MODULE_PROPERTIES > }; > /* }}} */ > > #ifdef COMPILE_DL_SAM > - ZEND_GET_MODULE(sam) > +ZEND_GET_MODULE(sam) > #endif > > /***************************************************************************/ > @@ -87,48 +87,49 @@ > */ > PHP_MINIT_FUNCTION(sam) > { > - zend_class_entry ce; > + zend_class_entry ce; > > - if (SAM_DEBUG) zend_printf("<br/><b>sam PHP_MINIT_FUNCTION</b> > enter<br/>"); > + if (SAM_DEBUG) zend_printf("<br/><b>sam PHP_MINIT_FUNCTION</b> > enter<br/>"); > > - /* Register the XMS connection resource */ > - le_sam_connection = zend_register_list_destructors_ex(php_sam_connection_dtor, NULL, > - PHP_SAM_CONNECTION_RES_NAME, > module_number); > + /* Register the XMS connection resource */ > + le_sam_connection = zend_register_list_destructors_ex(php_sam_connection_dtor, NULL, > + PHP_SAM_CONNECTION_RES_NAME, module_number); > > - /* define some constants... */ > + /* define some constants... */ > > - /* property types */ > + /* property types */ > REGISTER_STRING_CONSTANT("SAM_BOOL", SAM_CONSTANT_BOOLEAN, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_BYTE", SAM_CONSTANT_BYTE, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_DOUBLE", SAM_CONSTANT_DOUBLE, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_FLOAT", SAM_CONSTANT_FLOAT, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_INT", SAM_CONSTANT_INTEGER, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_LONG", SAM_CONSTANT_LONG, CONST_CS | > CONST_PERSISTENT); > - REGISTER_STRING_CONSTANT("SAM_STRING", SAM_CONSTANT_SELECT, CONST_CS | > CONST_PERSISTENT); > + REGISTER_STRING_CONSTANT("SAM_STRING", SAM_CONSTANT_STRING, CONST_CS | > CONST_PERSISTENT); > > - /* property names */ > - /* These constants are defeined with the value the same as the name to */ > - /* get round some unexpected behaviour in the PHP parsing of certain */ > - /* statements. In particular $msg->header->SAM_XXX will always pass in */ > - /* a property name of SAM_XXX rather than the value of the constant named */ > - /* SAM_XXX! */ > + /* property names */ > + /* These constants are defeined with the value the same as the name to */ > + /* get round some unexpected behaviour in the PHP parsing of certain */ > + /* statements. In particular $msg->header->SAM_XXX will always pass in */ > + /* a property name of SAM_XXX rather than the value of the constant named */ > + /* SAM_XXX! */ > REGISTER_STRING_CONSTANT(SAM_CONSTANT_BROKER, SAM_CONSTANT_BROKER, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_BUS, SAM_CONSTANT_BUS, CONST_CS | CONST_PERSISTENT); > + REGISTER_STRING_CONSTANT(SAM_CONSTANT_CORRELID, SAM_CONSTANT_CORRELID, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_DELIVERYMODE, SAM_CONSTANT_DELIVERYMODE, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_ENDPOINTS, SAM_CONSTANT_ENDPOINTS, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_HOST, SAM_CONSTANT_HOST, CONST_CS | CONST_PERSISTENT); > + REGISTER_STRING_CONSTANT(SAM_CONSTANT_MESSAGEID, SAM_CONSTANT_MESSAGEID, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_MSGPRIORITY, SAM_CONSTANT_MSGPRIORITY, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_PASSWORD, SAM_CONSTANT_PASSWORD, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_PORT, SAM_CONSTANT_PORT, CONST_CS | CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_REPLY_TO, SAM_CONSTANT_REPLY_TO, CONST_CS | > CONST_PERSISTENT); > - REGISTER_STRING_CONSTANT(SAM_CONSTANT_SELECT, SAM_CONSTANT_SELECT, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_TARGETCHAIN, SAM_CONSTANT_TARGETCHAIN, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_TRANSACTIONS, SAM_CONSTANT_TRANSACTIONS, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_TYPE, SAM_CONSTANT_TYPE, CONST_CS | CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_USERID, SAM_CONSTANT_USERID, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_WAIT, SAM_CONSTANT_WAIT, CONST_CS | CONST_PERSISTENT); > > - /* property values */ > + /* property values */ > REGISTER_STRING_CONSTANT("SAM_AUTO", SAM_CONSTANT_AUTO, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_BYTES, SAM_CONSTANT_BYTES, CONST_CS | > CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_MANUAL", SAM_CONSTANT_MANUAL, CONST_CS | > CONST_PERSISTENT); > @@ -137,23 +138,23 @@ > REGISTER_STRING_CONSTANT(SAM_CONSTANT_TEXT, SAM_CONSTANT_TEXT, CONST_CS | CONST_PERSISTENT); > REGISTER_STRING_CONSTANT(SAM_CONSTANT_UNKNOWN, SAM_CONSTANT_UNKNOWN, CONST_CS | > CONST_PERSISTENT); > > - /* protocols */ > + /* protocols */ > REGISTER_STRING_CONSTANT("SAM_RTT", SAM_CONSTANT_RTT, CONST_CS | CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_WMQ", SAM_CONSTANT_WMQ, CONST_CS | CONST_PERSISTENT); > REGISTER_STRING_CONSTANT("SAM_WMQ_CLIENT", SAM_CONSTANT_WMQ_CLIENT, CONST_CS | > CONST_PERSISTENT); > 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); > > - /* Register the connection class */ > - INIT_CLASS_ENTRY(ce, "SAMConnection", sam_conn_functions); > - php_sam_SAM_Connection_entry = zend_register_internal_class(&ce TSRMLS_CC); > + /* Register the connection class */ > + INIT_CLASS_ENTRY(ce, "SAMConnection", sam_conn_functions); > + php_sam_SAM_Connection_entry = zend_register_internal_class(&ce TSRMLS_CC); > > - INIT_CLASS_ENTRY(ce, "SAMMessage", sam_message_functions); > - php_sam_SAM_Message_entry = zend_register_internal_class(&ce TSRMLS_CC); > + INIT_CLASS_ENTRY(ce, "SAMMessage", sam_message_functions); > + php_sam_SAM_Message_entry = zend_register_internal_class(&ce TSRMLS_CC); > > - if (SAM_DEBUG) zend_printf("<b>sam PHP_MINIT_FUNCTION</b> > exit<br/>"); > + if (SAM_DEBUG) zend_printf("<b>sam PHP_MINIT_FUNCTION</b> > exit<br/>"); > > - return SUCCESS; > + return SUCCESS; > } > /* }}} */ > > @@ -163,48 +164,75 @@ > */ > PHP_MINFO_FUNCTION(sam) > { > - if (SAM_DEBUG) zend_printf("<br/><b>sam PHP_MINFO_FUNCTION</b> > enter<br/>"); > + if (SAM_DEBUG) zend_printf("<br/><b>sam PHP_MINFO_FUNCTION</b> > enter<br/>"); > php_info_print_table_start(); > php_info_print_table_header(2, "SAM - Simple Asynchronous Messaging support", > "enabled"); > php_info_print_table_row(2, "SAM extension version", SAM__MODULE_VERSION); > php_info_print_table_end(); > - if (SAM_DEBUG) zend_printf("<b>sam PHP_MINFO_FUNCTION</b> > exit<br/>"); > + if (SAM_DEBUG) zend_printf("<b>sam PHP_MINFO_FUNCTION</b> > exit<br/>"); > } > /* }}} */ > > /* {{{ proto void sam_debug_off() > - * Turn debug output off > - */ > +* Turn debug output off > +*/ > PHP_FUNCTION(sam_debug_off) { > - SAM_DEBUG = 0; > - RETURN_TRUE; > + SAM_DEBUG = 0; > + RETURN_TRUE; > } > /* }}} */ > > /* {{{ proto void sam_debug_off() > - * Turn debug output on > - */ > +* Turn debug output on > +*/ > PHP_FUNCTION(sam_debug_on) { > - SAM_DEBUG = 1; > - RETURN_TRUE; > + SAM_DEBUG = 1; > + RETURN_TRUE; > } > /* }}} */ > > /* {{{ proto void php_sam_connection_dtor(zend_rsrc_list_entry) > - * routine to close off any open XMS connections at module exit > - */ > +* routine to close off any open XMS connections at module exit > +*/ > static void php_sam_connection_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) { > - php_sam_connection *connResource = (php_sam_connection*)rsrc->ptr; > - if (SAM_DEBUG) zend_printf("<br/><b>php_sam_connection_dtor</b> > enter<br/>"); > + php_sam_connection *connResource = (php_sam_connection*)rsrc->ptr; > + xmsHErrorBlock errorBlock; > + > + if (SAM_DEBUG) zend_printf("<br/><b>php_sam_connection_dtor</b> > enter<br/>"); > + > + if (connResource) { > > - 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 */ > - if (XMS_OK != xmsConnClose(&connResource->conn, NULL)) { > - if (SAM_DEBUG) > zend_printf("<br/><b>php_sam_connection_dtor</b> close > failed!<br/>"); > - } > - efree(connResource); > - } > - if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> > exit<br/>"); > + 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 */ > + if (connResource->conn) { > + if (XMS_OK != xmsConnClose(&connResource->conn, NULL)) { > + if (SAM_DEBUG) zend_printf("<br/><b>php_sam_connection_dtor</b> > close failed!<br/>"); > + } > + > + /* Set the connection to NULL to eliminate the possibility of attempting to disconnect > again */ > + 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); > + } > + if (SAM_DEBUG) zend_printf("<b>php_sam_connection_dtor</b> > exit<br/>"); > } > /* }}} */ > > http://cvs.php.net/viewvc.cgi/pecl/sam/php_sam.h?r1=1.1&r2=1.2&diff_format=u > Index: pecl/sam/php_sam.h > diff -u pecl/sam/php_sam.h:1.1 pecl/sam/php_sam.h:1.2 > --- pecl/sam/php_sam.h:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/php_sam.h Wed Nov 22 17:06:57 2006 > @@ -1,6 +1,6 @@ > /* > +----------------------------------------------------------------------+ > -| (c) Copyright IBM Corporation 2006. | > +| Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > @@ -18,7 +18,7 @@ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > - $Id: php_sam.h,v 1.1 2006/11/08 12:02:08 dsr Exp $ > + $Id: php_sam.h,v 1.2 2006/11/22 17:06:57 dsr Exp $ > > */ > > @@ -71,15 +71,17 @@ > /* property names */ > #define SAM_CONSTANT_BROKER "SAM_BROKER" > #define SAM_CONSTANT_BUS "SAM_BUS" > +#define SAM_CONSTANT_CORRELID "SAM_CORRELID" > #define SAM_CONSTANT_DELIVERYMODE "SAM_DELIVERYMODE" > #define SAM_CONSTANT_ENDPOINTS "SAM_ENDPOINTS" > +#define SAM_CONSTANT_HEADERS "SAM_HEADERS" > #define SAM_CONSTANT_HOST "SAM_HOST" > +#define SAM_CONSTANT_MESSAGEID "SAM_MESSAGEID" > #define SAM_CONSTANT_MSGPRIORITY "SAM_MSGPRIORITY" > #define SAM_CONSTANT_PASSWORD "SAM_PASSWORD" > #define SAM_CONSTANT_PORT "SAM_PORT" > #define SAM_CONSTANT_PRIORITY "SAM_PRIORITY" > #define SAM_CONSTANT_REPLY_TO "SAM_REPLY_TO" > -#define SAM_CONSTANT_SELECT "SAM_SELECT" > #define SAM_CONSTANT_TARGETCHAIN "SAM_TARGETCHAIN" > #define SAM_CONSTANT_TIMETOLIVE "SAM_TIMETOLIVE" > #define SAM_CONSTANT_TRANSACTIONS "SAM_TRANSACTIONS" > @@ -90,6 +92,8 @@ > /* property values */ > #define SAM_CONSTANT_AUTO "auto" > #define SAM_CONSTANT_BYTES "SAM_BYTES" > +#define SAM_CONSTANT_HEADERS_JMS "jms" > +#define SAM_CONSTANT_HEADERS_NONE "none" > #define SAM_CONSTANT_MANUAL "manual" > #define SAM_CONSTANT_NONPERSISTENT "nonpersistent" > #define SAM_CONSTANT_PERSISTENT "persistent" > @@ -102,6 +106,9 @@ > #define SAM_CONSTANT_WMQ_CLIENT "wmq:client" > #define SAM_CONSTANT_WMQ_BINDINGS "wmq:bindings" > #define SAM_CONSTANT_WPM "wpm" > +#define SAM_CONSTANT_SUB "sub" > +#define SAM_CONSTANT_SUBPREFIX "sub://" > +#define SAM_CONSTANT_TOPICPREFIX "topic://" > > #define SAM_CONSTANT_OPTION_CLIENT "client" > #define SAM_CONSTANT_OPTION_BINDINGS "bindings" > @@ -114,6 +121,8 @@ > > #include "SAM_Connection.h" > #include "SAM_Message.h" > +#include "SAM_Utils.h" > + > > PHP_FUNCTION(sam_debug_off); > PHP_FUNCTION(sam_debug_on); > @@ -130,27 +139,8 @@ > /* */ > /***************************************************************************/ > > -/* > - * Module initialisation function > - */ > PHP_MINIT_FUNCTION(sam); > > -/* > - * Module shutdown funciton > - */ > -PHP_MSHUTDOWN_FUNCTION(sam); > - > - > -/* > - * Module request initialisation function > - */ > -PHP_RINIT_FUNCTION(sam); > - > -/* > - * Module request shutdown function > - */ > -PHP_RSHUTDOWN_FUNCTION(sam); > - > PHP_MINFO_FUNCTION(sam); > > > > http://cvs.php.net/viewvc.cgi/pecl/sam/sam.dsp?r1=1.1&r2=1.2&diff_format=u^ðT0 > ^#Ø?«9tc¥ > Index: pecl/sam/sam.dsp > diff -u pecl/sam/sam.dsp:1.1 pecl/sam/sam.dsp:1.2 > --- pecl/sam/sam.dsp:1.1 Wed Nov 8 12:02:08 2006 > +++ pecl/sam/sam.dsp Wed Nov 22 17:06:57 2006 > @@ -51,8 +51,8 @@ > # ADD BASE BSC32 /nologo > # ADD BSC32 /nologo > LINK32=link.exe > -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts.lib gxi.lib /nologo /dll /out:"..\..\Release_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" > /pdb:".\Release_TS\sam.pdb" /pdbtype:sept /subsystem:windows > /implib:".\Release_TS/php_sam.lib" /machine:ix86 > -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts.lib gxi.lib /nologo /dll /out:"..\..\Release_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" > /pdb:".\Release_TS\sam.pdb" /pdbtype:sept /subsystem:windows > /implib:".\Release_TS/php_sam.lib" /machine:ix86 > +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts.lib gxi.lib /nologo /dll /out:"..\..\Release_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" > /pdb:".\Release_TS\sam.pdb" /pdbtype:sept /subsystem:windows > /implib:".\Release_TS/sam.lib" /machine:ix86 > +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts.lib gxi.lib /nologo /dll /out:"..\..\Release_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" > /pdb:".\Release_TS\sam.pdb" /pdbtype:sept /subsystem:windows > /implib:".\Release_TS/sam.lib" /machine:ix86 > > !ELSEIF "$(CFG)" == "sam - Win32 Debug_TS" > > @@ -76,8 +76,8 @@ > # ADD BASE BSC32 /nologo > # ADD BSC32 /nologo > LINK32=link.exe > -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts_debug.lib /nologo /dll /out:"..\..\Debug_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Debug_TS" /pdb:".\Debug_TS\sam.pdb" /pdbtype:sept > /subsystem:windows /implib:".\Debug_TS/php_sam.lib" /machine:ix86 > -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts_debug.lib /nologo /dll /out:"..\..\Debug_TS\php_sam.dll" /incremental:no > /libpath:"..\..\Debug_TS" /pdb:".\Debug_TS\sam.pdb" /pdbtype:sept > /subsystem:windows /implib:".\Debug_TS/php_sam.lib" /machine:ix86 > +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts_debug.lib /nologo /dll /out:"..\..\Debug_TS\sam.dll" /incremental:no > /libpath:"..\..\Debug_TS" /pdb:".\Debug_TS\sam.pdb" /pdbtype:sept > /subsystem:windows /implib:".\Debug_TS/sam.lib" /machine:ix86 > +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib > shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib odbc32.lib odbccp32.lib > php4ts_debug.lib /nologo /dll /out:"..\..\Debug_TS\sam.dll" /incremental:no > /libpath:"..\..\Debug_TS" /pdb:".\Debug_TS\sam.pdb" /pdbtype:sept > /subsystem:windows /implib:".\Debug_TS/sam.lib" /machine:ix86 > > !ENDIF > > > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Utils.c?view=markup&rev=1.1 > Index: pecl/sam/SAM_Utils.c > +++ pecl/sam/SAM_Utils.c > /* > +----------------------------------------------------------------------+ > | Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > | Licensed under the Apache License, Version 2.0 (the "License"); you | > | may not use this file except in compliance with the License. You may | > | obtain a copy of the License at | > | http://www.apache.org/licenses/LICENSE-2.0 > | > | | > | Unless required by applicable law or agreed to in writing, software | > | distributed under the License is distributed on an "AS IS" BASIS, | > | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | > | implied. See the License for the specific language governing | > | permissions and limitations under the License. | > +----------------------------------------------------------------------+ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > $Id: SAM_Utils.c,v 1.1 2006/11/22 17:06:57 dsr Exp $ > > */ > > #ifdef LINUX > #include <stdlib.h> /* for random */ > #include <sys/types.h> /* for getpid */ > #include <linux/unistd.h> /* for gettid */ > #include <unistd.h> /* for getpid */ > #include <time.h> /* for time() call */ > > #include <netdb.h> /* For gethostbyname */ > #include <sys/socket.h> /* For inet_ntoa */ > #include <netinet/in.h> /* For inet_ntoa */ > #include <arpa/inet.h> /* For inet_ntoa */ > #include <string.h> /* For memcpy */ > #include <stdio.h> > > /* Includes for the Zend PHP API */ > #include <php.h> > #include <php_ini.h> > #include <ext/standard/info.h> > > /* Includes for our implementation */ > #include "php_sam.h" > > extern int SAM_DEBUG; > > char *SAMGetMyIPAddress() > { > char *myIPAddress = NULL; > char hostName[128]; > struct hostent *h; > > if (0 == gethostname(hostName, sizeof(hostName))) > { > if (NULL != (h = gethostbyname(hostName))) > { > struct in_addr sinAddr; > > memcpy(&sinAddr, h->h_addr_list[0], h->h_length); > myIPAddress = inet_ntoa(sinAddr); > } > } > return(myIPAddress); > } > > int SAMGetSignature(char *aSig) > { > pid_t myPid; > int aRand; > time_t thisTime = 0; > char *myIPAddress; > > if (NULL != aSig) { > myIPAddress = SAMGetMyIPAddress(); > if (myIPAddress != NULL) > { > /* On Linux the process id returned by getpid() is actually unique per thread */ > myPid = getpid(); > > time(&thisTime); > > /* Seed the random number generator from the time of day */ > srand(thisTime); > > aRand = rand(); > > sprintf(aSig, "%s_%d_%d_%d", myIPAddress, myPid, thisTime, aRand); > > return 0; > } > else > return 1; > } > return 1; > } > > #else > > /* Includes for the Zend PHP API */ > #include <php.h> > #include <php_ini.h> > #include <ext/standard/info.h> > > /* Includes for our implementation */ > #include "php_sam.h" > > extern int SAM_DEBUG; > > char *SAMGetMyIPAddress() > { > WSADATA wsd; > char *myIPAddress = NULL; > char hostName[128]; > > if ((0 == WSAStartup( MAKEWORD( 2, 2 ), &wsd )) && > (0 == gethostname(hostName, sizeof(hostName)))) { > struct hostent* FAR h; > > if (NULL != (h = gethostbyname(hostName))) > { > struct in_addr sinAddr; > > memcpy( &sinAddr, h->h_addr_list[0], h->h_length ); > myIPAddress = inet_ntoa( sinAddr ); > } > } > > WSACleanup(); > return myIPAddress; > } > > int SAMGetSignature(char *aSig) > { > int myPid; > int myTid; > unsigned int myRand; > FILETIME ft; > char *myIPAddress; > > if (NULL != aSig) { > myIPAddress = SAMGetMyIPAddress(); > if (myIPAddress != NULL) > { > srand( (unsigned) time(NULL) ); > myPid = GetCurrentProcessId(); > myTid = GetCurrentThreadId(); > > /* rand_s is a better function on VS2005 */ > myRand = rand(); > > GetSystemTimeAsFileTime(&ft); > > sprintf(aSig, "%s_%d_%d_%u_%u_%d", myIPAddress, myPid, myTid, ft.dwHighDateTime, > ft.dwLowDateTime, myRand); > return 0; > } > else > return 1; > } > return 1; > } > #endif > > xmsCHAR *SAMBuildSelectorString(char *correlId, char *messageId) > { > xmsCHAR *mySelector = NULL; > > /* Add any correlid part of the selector */ > if ( (NULL != correlId) && (*correlId != '\0')) { > mySelector = emalloc(22 + strlen(correlId)); > sprintf(mySelector, "JMSCorrelationID = '%s'", correlId); > } > > /* Add any message id part of the selector */ > if ( ( NULL != messageId) && (*messageId != '\0')) > { > if ( ( NULL != mySelector) && (0 != strlen(mySelector)) ) > { > mySelector = erealloc(mySelector, strlen(mySelector) + 22 + strlen(messageId)); > strcat(mySelector, " AND "); > strcat(mySelector, "JMSMessageID = '"); > } > else > { > mySelector = emalloc(18 + strlen(messageId)); > strcpy(mySelector, "JMSMessageID = '"); > } > > strcat(mySelector, messageId); > strcat(mySelector, "'"); > } > > return mySelector; > } > > > http://cvs.php.net/viewvc.cgi/pecl/sam/SAM_Utils.h?view=markup&rev=1.1 > Index: pecl/sam/SAM_Utils.h > +++ pecl/sam/SAM_Utils.h > /* > +----------------------------------------------------------------------+ > | Copyright IBM Corporation 2006. | > | All Rights Reserved. | > +----------------------------------------------------------------------+ > | | > | Licensed under the Apache License, Version 2.0 (the "License"); you | > | may not use this file except in compliance with the License. You may | > | obtain a copy of the License at | > | http://www.apache.org/licenses/LICENSE-2.0 > | > | | > | Unless required by applicable law or agreed to in writing, software | > | distributed under the License is distributed on an "AS IS" BASIS, | > | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | > | implied. See the License for the specific language governing | > | permissions and limitations under the License. | > +----------------------------------------------------------------------+ > | Authors: Dave Renshaw, Jerry Stevens | > +----------------------------------------------------------------------+ > > $Id: SAM_Utils.h,v 1.1 2006/11/22 17:06:57 dsr Exp $ > > */ > > #if !defined(__SAMPHPUTILS_H__) > #define __SAMPHPUTILS_H__ > > int SAMGetSignature(char *s); > xmsCHAR *SAMBuildSelectorString(char *correlId, char *messageId); > > #endif /*__SAMPHPUTILS_H__) */ > > >

« previous php.pecl.cvs (#6675) next »