[PATCH 4/5] Use getTempCopy in DQPublisher


Ian Bell <IBell@...>
 

From 5d0782498dcfc187b9cbdafdb0bf126edc24d55f Mon Sep 17 00:00:00 2001

Message-Id: <5d0782498dcfc187b9cbdafdb0bf126edc24d55f.1348577193.git.ibell@...>

In-Reply-To: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

References: <c6056d16f347a98054cb70348d5fbcc988abbf60.1348577193.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Tue, 25 Sep 2012 13:42:38 +0100

Subject: [PATCH 4/5] Use getTempCopy in DQPublisher

 

Changed the msg modification to use the new getTempCopy API.  This means

that an app can send on messages it doesnt own and change the seqnum and

senderid on the fly

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/c/dqpublisher.c |   26 +++++++++++++++++---------

1 file changed, 17 insertions(+), 9 deletions(-)

 

diff --git a/mama/c_cpp/src/c/dqpublisher.c b/mama/c_cpp/src/c/dqpublisher.c

index c2780aa..e100330 100644

--- a/mama/c_cpp/src/c/dqpublisher.c

+++ b/mama/c_cpp/src/c/dqpublisher.c

@@ -24,6 +24,8 @@

 #include "mama/dqpublisher.h"

#include "mama/publisher.h"

+#include "mama/msg.h"

+#include "mama/msgfield.h"

 

 

@@ -74,10 +76,12 @@ mama_status mamaDQPublisher_create (mamaDQPublisher pub, mamaTransport transport

mama_status mamaDQPublisher_send (mamaDQPublisher pub, mamaMsg msg)

{    

     mamaDQPublisherImpl* impl = (mamaDQPublisherImpl*) (pub);

+    mamaMsg modifableMsg = NULL;

     if (impl->mSeqNum != 0)

     {

-        switch (mamaMsgType_typeForMsg (msg))

+        mamaMsg_getTempCopy (msg, &modifableMsg);

+        switch (mamaMsgType_typeForMsg (modifableMsg))

         {

             case MAMA_MSG_TYPE_REFRESH :

             case MAMA_MSG_TYPE_SYNC_REQUEST :

@@ -90,33 +94,34 @@ mama_status mamaDQPublisher_send (mamaDQPublisher pub, mamaMsg msg)

             case MAMA_MSG_TYPE_RECAP        :

             case MAMA_MSG_TYPE_BOOK_RECAP   :

                 if(MAMA_STATUS_OK !=

-                        mamaMsg_updateU8(msg,MamaFieldMsgStatus.mName,

+                        mamaMsg_updateU8(modifableMsg,MamaFieldMsgStatus.mName,

                             MamaFieldMsgStatus.mFid, impl->mStatus))

                 {

-                    mamaMsg_updateI16(msg,MamaFieldMsgStatus.mName,

+                    mamaMsg_updateI16(modifableMsg,MamaFieldMsgStatus.mName,

                             MamaFieldMsgStatus.mFid, impl->mStatus);

                 }

                 break;

             default:

                 if(MAMA_STATUS_OK !=

-                        mamaMsg_updateU8(msg,MamaFieldMsgStatus.mName,

+                        mamaMsg_updateU8(modifableMsg,MamaFieldMsgStatus.mName,

                             MamaFieldMsgStatus.mFid, impl->mStatus))

                 {

-                   mamaMsg_updateI16(msg,MamaFieldMsgStatus.mName,

+                   mamaMsg_updateI16(modifableMsg,MamaFieldMsgStatus.mName,

                            MamaFieldMsgStatus.mFid, impl->mStatus);

                 }

                 impl->mSeqNum++;

                 break;

         }

-        mamaMsg_updateU32(msg, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

+        mamaMsg_updateU32(modifableMsg, MamaFieldSeqNum.mName, MamaFieldSeqNum.mFid,

                 impl->mSeqNum);

     }

    

     if (impl->mSenderId != 0)

     {

         mamaMsgField senderIdField = NULL;

-        if (MAMA_STATUS_OK == mamaMsg_getField(msg, MamaFieldSenderId.mName,

+        mamaMsg_getTempCopy (msg, &modifableMsg);

+        if (MAMA_STATUS_OK == mamaMsg_getField(modifableMsg, MamaFieldSenderId.mName,

                     MamaFieldSenderId.mFid, &senderIdField))

         {

             mamaFieldType senderIdType = MAMA_FIELD_TYPE_UNKNOWN;

@@ -143,11 +148,14 @@ mama_status mamaDQPublisher_send (mamaDQPublisher pub, mamaMsg msg)

             }

         }

         else

-            mamaMsg_addU64(msg, MamaFieldSenderId.mName,

+            mamaMsg_addU64(modifableMsg, MamaFieldSenderId.mName,

                     MamaFieldSenderId.mFid, impl->mSenderId);

     }

-    return (mamaPublisher_send (impl->mPublisher, msg));

+    if (modifableMsg)

+        return (mamaPublisher_send (impl->mPublisher, modifableMsg));

+    else

+        return (mamaPublisher_send (impl->mPublisher, msg));

}

 

 mama_status mamaDQPublisher_sendReply (mamaDQPublisher pub,

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.