Skip to content

Commit

Permalink
Generate an error if there's no queue/topic name provided (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet authored Dec 11, 2024
1 parent b68a107 commit b9489df
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions C/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static void dumpConfig(char *filename) {
printf(" Cipher : %s\n", N(ep->cipher));
printf(" CipherSuite : %s\n", N(ep->cipherSuite));
printf(" KeyRepository : %s\n", N(ep->keyRepository));
printf(" WaitInterval : %s\n",N(ep->waitInterval));
}

printf("JWT Endpoint:\n");
Expand Down Expand Up @@ -352,6 +353,7 @@ void freeConfig() {
cfFree(ep->cipher);
cfFree(ep->cipherSuite);
cfFree(ep->keyRepository);
cfFree(ep->waitInterval);
}

cfFree(pJwt->tokenEndpoint);
Expand Down
5 changes: 5 additions & 0 deletions C/sampleget.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ static int openQueue(MQHCONN hConn, PMQHOBJ pHObj) {
MQOD mqod = {MQOD_DEFAULT};
MQLONG options = MQOO_INPUT_EXCLUSIVE;

if (!mqEndpoints[0].queueName) {
printf("Error: No queue name supplied\n");
return -1;
}

strncpy(mqod.ObjectName, mqEndpoints[0].queueName, MQ_Q_NAME_LENGTH);
mqod.ObjectType = MQOT_Q;

Expand Down
4 changes: 4 additions & 0 deletions C/samplepublish.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ static int openTopic(MQHCONN hConn, PMQHOBJ pHObj) {
// The objectString contains the full topic string that we
// want to use. Alternatives allow a combination of administered object
// names and the objectString value, but that's more advanced.
if (!mqEndpoints[0].topicName) {
printf("Error: No topic name supplied\n");
return -1;
}
topic = mqEndpoints[0].topicName;
objectString.VSPtr = topic;
objectString.VSLength = (MQLONG)strlen(topic);
Expand Down
9 changes: 7 additions & 2 deletions C/sampleput.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ static int openQueue(MQHCONN hConn, PMQHOBJ pHObj) {
MQOD mqod = {MQOD_DEFAULT};
MQLONG options = MQOO_OUTPUT;

if (!mqEndpoints[0].queueName) {
printf("Error: No queue name supplied\n");
return -1;
}

strncpy(mqod.ObjectName, mqEndpoints[0].queueName, MQ_Q_NAME_LENGTH);
mqod.ObjectType = MQOT_Q;

Expand Down Expand Up @@ -127,15 +132,15 @@ static int putMessage(MQHCONN hConn, MQHOBJ hObj, char *msg) {

// We are sending a character string. Set the format to indicate
// that, so that the recipient can convert the codepage if necessary
memcpy(mqmd.Format,MQFMT_STRING,MQ_FORMAT_LENGTH);
memcpy(mqmd.Format, MQFMT_STRING, MQ_FORMAT_LENGTH);

// Now put the message to the queue
MQPUT(hConn, hObj, &mqmd, &mqpmo, strlen(msg), msg, &compCode, &reason);
if (reason != MQRC_NONE) {
printError("MQPUT", compCode, reason);
rc = -1;
} else {
printf("Sent Message: %s\n",msg);
printf("Sent Message: %s\n", msg);
}

return rc;
Expand Down
11 changes: 10 additions & 1 deletion C/samplerequest.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ static int openRequestQueue(MQHCONN hConn, PMQHOBJ pHObj) {
MQOD mqod = {MQOD_DEFAULT};
MQLONG options = MQOO_OUTPUT;

if (!mqEndpoints[0].queueName) {
printf("Error: No queue name supplied\n");
return -1;
}
strncpy(mqod.ObjectName, mqEndpoints[0].queueName, MQ_Q_NAME_LENGTH);

mqod.ObjectType = MQOT_Q;
Expand Down Expand Up @@ -150,6 +154,12 @@ static int openReplyQueue(MQHCONN hConn, PMQHOBJ pHObj) {
MQLONG options = MQOO_INPUT_EXCLUSIVE;

mqEndpoint_t ep = mqEndpoints[0];

if (!mqEndpoints[0].modelQueueName) {
printf("Error: No model queue name supplied\n");
return -1;
}

strncpy(mqod.ObjectName, ep.modelQueueName, MQ_Q_NAME_LENGTH);
if (ep.dynamicQueuePrefix) {
// The dynamic queue has its name start with this prefix
Expand Down Expand Up @@ -228,7 +238,6 @@ static int getReplyMessage(MQHCONN hConn, MQHOBJ hObj) {
MQLONG datalength;
MQLONG waitInterval = DEFAULT_WAIT_INTERVAL;


// Structure version must be high enough to recognise the MatchOptions field
mqgmo.Version = MQGMO_VERSION_2;

Expand Down
4 changes: 4 additions & 0 deletions C/sampleresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ static int openQueue(MQHCONN hConn, PMQHOBJ pHObj) {
MQOD mqod = {MQOD_DEFAULT};
MQLONG options = MQOO_INPUT_EXCLUSIVE;

if (!mqEndpoints[0].queueName) {
printf("Error: No queue name supplied\n");
return -1;
}
strncpy(mqod.ObjectName, mqEndpoints[0].queueName, MQ_Q_NAME_LENGTH);
mqod.ObjectType = MQOT_Q;

Expand Down
6 changes: 5 additions & 1 deletion C/samplesubscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ static int subscribeTopic(MQHCONN hConn, PMQHOBJ pTopicHObj, PMQHOBJ pQueueHObj)
// The objectString contains the full topic string that we
// want to use. Alternatives allow a combination of administered object
// names and the objectString value, but that's more advanced.
if (!mqEndpoints[0].topicName) {
printf("Error: No topic name supplied\n");
return -1;
}
strncpy(topic, mqEndpoints[0].topicName, sizeof(topic) - 1);
printf("Subscribing to %s\n", topic);

Expand Down Expand Up @@ -156,7 +160,7 @@ static int getMessages(MQHCONN hConn, MQHOBJ hObj) {
if (mqEndpoints[0].waitInterval) {
waitInterval = atoi(mqEndpoints[0].waitInterval);
}
printf("waitInterval: %d\n",waitInterval);
printf("waitInterval: %d\n", waitInterval);
mqgmo.WaitInterval = waitInterval * 1000; // Convert seconds to milliseconds

// Not going to try to match on MsgId or CorrelId
Expand Down

0 comments on commit b9489df

Please sign in to comment.