ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » MQ Exit AgentBufferLength

Post new topic  Reply to topic
 MQ Exit AgentBufferLength « View previous topic :: View next topic » 
Author Message
kschindl
PostPosted: Mon Apr 04, 2005 1:48 am    Post subject: MQ Exit AgentBufferLength Reply with quote

Newbie

Joined: 04 Apr 2005
Posts: 5

We are trying to use the receiver exit by adding certain information into the message.
As long as the total message length is below 4000 Bytes there is no problem, as the AgentBufferLength is always 4000 Bytes minimum.
i tried to use the ExitBufferAddress and setting the correct the datasize (the value i use is correct).
As soon as the message size is > 4000 Bytes we got a problem.
I asume that there should be a parameter in the exit configuration. is this so?
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Mon Apr 04, 2005 7:16 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

FYI,

http://www.mqseries.net/phpBB2/viewtopic.php?t=20523

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
kschindl
PostPosted: Mon Apr 04, 2005 11:51 pm    Post subject: thx, but does not solve the problem Reply with quote

Newbie

Joined: 04 Apr 2005
Posts: 5

thx, but this is just simple

my receiver exit gets a message and adds some data to the RFH2 header and puts it back into the ExitBufferAddresse with the ExitBufferLength set to the size of the changed message:

// memory allocation
PMQLONG *outAgentBuffer = malloc(agentBufferLength + strlen(insertString) + reserve);
PMQBYTE pOutAgentBuffer = (PMQBYTE)outAgentBuffer;

// setting the exit buffer
*pExitBufferLength = *pAgentBufferLength + insertStringLength;
*pExitBufferAddr = pOutAgentBuffer;

// channel exit parameters
pMQCXP->ExitResponse = MQXCC_OK;
pMQCXP->ExitResponse2 = MQXR2_USE_EXIT_BUFFER;
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Apr 05, 2005 7:36 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,

By no means is it simple, MQ Exits are most definitely an 'advanced' topic. There is far more than what you have listed. I would do more research before you start having shared memory problems or plain old memory leaks.

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
kschindl
PostPosted: Tue Apr 05, 2005 9:55 pm    Post subject: leaks Reply with quote

Newbie

Joined: 04 Apr 2005
Posts: 5

hi

of course there is far more than i listed. i cannot post the complete code here out of security reasons.

but to say about leaks: unlikely.
as the logs show that the message is complete
the problem is when i put the message back in the channel and when the message is bigger than 4000 Bytes then the message is not processed anymoare in the queue.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Apr 05, 2005 10:11 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Exactly!!! And the reason is....

Since you think it is simple then I will let you answer the question.

By the way, hiding the source code is not a means to security.

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
kschindl
PostPosted: Tue Apr 05, 2005 10:23 pm    Post subject: simple Reply with quote

Newbie

Joined: 04 Apr 2005
Posts: 5

i did not say it is simple

the sample is just simple. the sample does not manipulate the message and change its length. but my exit does change the length of the message by inserting information into the RFH2 header.

and u are wrong. since this list is public and there are certain information in the code which are not supposed to be public it would be a security breach to post the complete code here.

but since this is hidden in some methods i can post the the exit call without the method here.

void MQStart() {;}
void MQENTRY ZEKEXIT(PMQCXP pMQCXP,
PMQCD pMQCD,
PMQLONG pDataLength,
PMQLONG pAgentBufferLength,
PMQBYTE pAgentBuffer,
PMQLONG pExitBufferLength,
PMQPTR pExitBufferAddr)
{

PMQXQH pMQXQH; /* =pAgentBuffer */
PMQRFH2 pMQRFH2; /* RFH2 Header structure */
/* initial MQRFH2 values */
MQRFH2 myRFH2 = {MQRFH2_DEFAULT};
pMQRFH2 = malloc(sizeof(myRFH2));
pMQRFH2 = &myRFH2;

int inDataLength;
int outDataLength;
int agentBufferLength;
int count = 0;
int reserve = 100;
int* pUsrLength = malloc(sizeof(int));
int insertStringLength = 0;

/* this is for debugging without tool
* set this to true to get printouts to file
* else set it too false and recompile
*/

inDataLength = *pDataLength;
agentBufferLength = *pAgentBufferLength;

/* variable to hold the mitglied nummer from MQCD->ChannelName */
char mitgliedNummer[] = "00000";
char* ptrMitgliedNummer = mitgliedNummer;
char mitgliedNummerM[] ="M00000";
char* ptrMitgliedNummerM = mitgliedNummerM;

/* tag constant to be insertet */
const char beginTag[] = "<MitgliedNummer>";
const char endTag[] = "</MitgliedNummer>";

/* string to be used in RFH2 Header */
char insertString[41] = "";
char* pInsertString = insertString;
char* channelName;

/* memory for the changed message */
PMQLONG *outAgentBuffer = malloc(agentBufferLength + strlen(insertString) + reserve);
PMQBYTE pOutAgentBuffer = (PMQBYTE)outAgentBuffer;

/* Free the ExitBuffer */
FreeExitBuffer( pExitBufferAddr, pExitBufferLength );

switch(pMQCXP -> ExitId)
{
case MQXT_CHANNEL_MSG_EXIT:
break;
case MQXT_CHANNEL_SEND_EXIT:
break;
case MQXT_CHANNEL_RCV_EXIT:
{
if (debugFlag)
{
#ifdef WIN32
filePointer=fopen("C:\\tmp\\zekrcvexit.log","a");
#else
filePointer=fopen("/tmp/zekrcvexit.log","a");
#endif

print_timestamp();
fprintf(filePointer,"Msgexit msg invoked\n");
}

pMQXQH = (PMQXQH)pAgentBuffer; /* begin mapping message data */

if (debugFlag)
{
print_timestamp();
if (!pMQCD) fprintf(filePointer, "pMQCD is NULL!");
}

/* get the channel name Channel Definition is Mxxxxx.
where xxx is the Mitliednummer */
channelName = pMQCD->ChannelName;
/* get the part before the . */
strncpy(mitgliedNummerM, channelName, 6);

/* shift string */
ptrMitgliedNummer = ++ptrMitgliedNummerM;

/* calculate the checksum of MitgliederNummer */
char checksum = getModulo11CheckSum(ptrMitgliedNummer);
/* the following is cause the *%&@# MQ does not want to bind with
* &checksum in strcat
*/
char* pChecksum = (char*)malloc(sizeof(char));
pChecksum = &checksum;

if (debugFlag)
{
fprintf(filePointer, "checksum: %c\n", checksum);
fprintf(filePointer, "checksum from pointer: %s\n", pChecksum);
}

/* put the stringtogether with the channelname */
strcat(pInsertString, beginTag);
strcat(pInsertString, ptrMitgliedNummer);
strcat(pInsertString, ".");
strcat(pInsertString, pChecksum);
strcat(pInsertString, endTag);

insertStringLength = strlen(insertString);

free(pChecksum);

if (debugFlag)
{
fprintf(filePointer, "Insert string: %s\n", pInsertString);
fprintf(filePointer, "Insert string length: %i\n", insertStringLength);
fprintf(filePointer, "DataLength: %i\n", inDataLength);
fprintf(filePointer, "AgentBufferLength: %i\n", agentBufferLength);
fflush(filePointer);

fprintf(filePointer, "***Agentbuffer***\n");
dump_message(pAgentBuffer, pDataLength);
fflush(filePointer);
}

/***** searching ******/
/* using memmemPos */
int pos = memmemPos(pAgentBuffer, inDataLength, "<usr>", 5);

/* did not find <usr> */
if (pos <= 0) break;
/* if we found the <usr> we move this part to the exit */
else
{
/* first me must set the new usr length, this is an integer (4 bytes)
* before the <usr> tag we found above
*/
memcpy(pUsrLength, pAgentBuffer + pos - 5, sizeof(int));
if (debugFlag)
{
fprintf(filePointer, "pos usrLength: %i\n", pAgentBuffer + pos - 5);
fprintf(filePointer, "usrLength before: %i\n", *pUsrLength);
}

/* new length of usr */
*pUsrLength = *pUsrLength + insertStringLength;
if (debugFlag)
{
fprintf(filePointer, "usrLength after: %i\n", *pUsrLength);
fflush(filePointer);
}

/* filling the RFH2 Header structure
* RFH2 headers starts at HEX 1DD hence 477-1 (address starts with 0 not 1 in dec
* size is of sizeof the default structure initialized above
*/
memcpy(pMQRFH2, pAgentBuffer + 476, sizeof(myRFH2));
if (debugFlag)
{
fprintf(filePointer, "Testing RFH2 Header output\n");
fprintf(filePointer, "==========================\n");
fprintf(filePointer, "StrucId: %s\n", pMQRFH2->StrucId);
fprintf(filePointer, "Version: %i\n", pMQRFH2->Version);
fprintf(filePointer, "StrucLength: %i\n", pMQRFH2->StrucLength);
fflush(filePointer);
}

/* now change the length of StrucLength to new Length */
pMQRFH2->StrucLength = pMQRFH2->StrucLength + insertStringLength;
if (debugFlag)
{
fprintf(filePointer, "new StrucLength: %i\n", pMQRFH2->StrucLength);
fflush(filePointer);
}

/* move the first part of the buffer without <usr> & without the usrLegth*/
memcpy(pOutAgentBuffer, pAgentBuffer, pos - sizeof(pUsrLength) - 1);

/* copy the new usrLength */
memcpy(pOutAgentBuffer + pos - sizeof(pUsrLength) -1,
pUsrLength,
sizeof(pUsrLength));

/* we also want to move the <usr> before inserting */
memcpy(pOutAgentBuffer + pos - 1, pAgentBuffer + pos - 1, sizeof("<usr>") );

/* now add the insertstring */
/* the pointer of the outAgentBuffer is pointing to the end */
count = pos + 4;
memcpy(pOutAgentBuffer + count, pInsertString, insertStringLength);

/* now add the the rest of the AgentBuffer */
/* the pointer of the outAgentBuffer is pointing to the end */
memcpy(pOutAgentBuffer + count + insertStringLength,
pAgentBuffer + count,
inDataLength - count);

/* write the new MQRFH2 structure back */
memmove(pOutAgentBuffer + 476, pMQRFH2, sizeof(*pMQRFH2));

/* now change the datalenght */
outDataLength = inDataLength + insertStringLength;

/* set the exit buffer length to new length */
*pExitBufferLength = *pAgentBufferLength + insertStringLength;
*pExitBufferAddr = pOutAgentBuffer;
*pDataLength = outDataLength;
}

/* the data to the exit buffer */
if (debugFlag)
{
PMQLONG pCount = malloc(outDataLength);
pCount = (PMQLONG)&outDataLength;
fprintf(filePointer, "***EXITBUFFER using pAgentBuffer***\n");
fprintf(filePointer, "pCount: %i\n", outDataLength);
dump_message(*pExitBufferAddr, pCount);

fflush(filePointer);
fclose(filePointer);

/* free the pCount memory */
free(pCount);
}

/* tell the exit what the response is
* and to use the agentbuffer
*/
pMQCXP->ExitResponse = MQXCC_OK;
pMQCXP->ExitResponse2 = MQXR2_USE_EXIT_BUFFER;
}
break;
case MQXT_CHANNEL_SEC_EXIT:
break;
default:
break;
}

/* free the used memory */
free(pMQRFH2);
free(outAgentBuffer);
free(pUsrLength);
}
Back to top
View user's profile Send private message
Nigelg
PostPosted: Wed Apr 06, 2005 3:04 am    Post subject: Reply with quote

Grand Master

Joined: 02 Aug 2004
Posts: 1046

You are setting the pointer to the data:
Quote:

/* memory for the changed message */
PMQLONG *outAgentBuffer = malloc(agentBufferLength + strlen(insertString) + reserve);
PMQBYTE pOutAgentBuffer = (PMQBYTE)outAgentBuffer;
...
*pExitBufferAddr = pOutAgentBuffer;


Why is outAgentBuffer a PMQLONG * ?
Should it not be a PMQCHAR or PMQBYTE?

and then freeing the memory before ending the function
Quote:

free(outAgentBuffer);
Back to top
View user's profile Send private message
kschindl
PostPosted: Wed Apr 06, 2005 11:13 pm    Post subject: Reply with quote

Newbie

Joined: 04 Apr 2005
Posts: 5

outAgentBuffer is a pointer and same type as pAgentBuffer which is PMQLONG
the content of the Buffer (data type) is PMQBYTE same as the AgentBuffer

the memory freeing is done at the end of the library call where it must be placed, there is no main as this is a shared libray. furthermore as i pointed out earlier, the message is going out of the exit. and ends back in the channel.
the problem is that if the message gets bigger than 4000 Bytes it gets stuck in the channel / queue.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » MQ Exit AgentBufferLength
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.