Skip to content

Commit

Permalink
Cleanup _VERSION setting for structures
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Sep 4, 2023
1 parent 02c1807 commit dd85424
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
8 changes: 5 additions & 3 deletions lib/mqcsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ var MQC = require('./mqidefs.js');
* for more details on the usage of each field.
* Not all of the underlying fields may be exposed in this object. For example,
* unlike the regular MQI, we don't bother exposing the authenticationType
* attribute, as there's currently only one value other than none - and setting
* the userid and password implies you want to use it.
* attribute and setting
* the userid and password or token implies the value you need.
*/
exports.MQCSP = function() {
/** @member {String} */
this.UserId = null;
/** @member {String} */
this.Password = null;
this._authenticationType = MQC.MQCSP_AUTH_USER_ID_AND_PWD;
this._authenticationType = MQC.MQCSP_NONE;
/** @member {String} */
this.InitialKey = null;
/** @member {String} */
this.Token = null;
Object.seal(this);
};
2 changes: 1 addition & 1 deletion samples/typescript/amqssub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function cleanup(hConn: mq.MQQueueManager, hObjPubQ: mq.MQObject, hObjSubscripti
console.log("MQCLOSE (Subscription) successful");
} catch (err) {
const mqerr = err as mq.MQError;
console.log("MQCLOSE (Subscription) ended with reason " + mqerr.toString());
console.log("MQCLOSE (Subscription) ended with reason " + mqerr.message);
}

mq.Close(hObjPubQ, 0, function (closeErr) {
Expand Down
24 changes: 12 additions & 12 deletions src/mqconndisc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Object CONNX(const CallbackInfo &info) {
w->jscd = v.As<Object>();
w->cno.ClientConnPtr = &w->cd;
copyCDtoC(env, w->jscd, &w->cd);
if (w->cno.Version < 2) {
w->cno.Version = 2;
if (w->cno.Version < MQCNO_VERSION_2) {
w->cno.Version = MQCNO_VERSION_2;
}
}

Expand All @@ -164,8 +164,8 @@ Object CONNX(const CallbackInfo &info) {
w->jssco = v.As<Object>();
w->cno.SSLConfigPtr = &w->sco;
copySCOtoC(env, w->jssco, &w->sco);
if (w->cno.Version < 4) {
w->cno.Version = 4;
if (w->cno.Version < MQCNO_VERSION_4) {
w->cno.Version = MQCNO_VERSION_4;
}
}

Expand All @@ -174,8 +174,8 @@ Object CONNX(const CallbackInfo &info) {
w->jscsp = v.As<Object>();
w->cno.SecurityParmsPtr = &w->csp;
copyCSPtoC(env, w->jscsp, &w->csp);
if (w->cno.Version < 5) {
w->cno.Version = 5;
if (w->cno.Version < MQCNO_VERSION_5) {
w->cno.Version = MQCNO_VERSION_5;
}
}

Expand All @@ -184,16 +184,16 @@ Object CONNX(const CallbackInfo &info) {
w->cno.CCDTUrlPtr = mqnStrdup(env, w->jscno.Get("CCDTUrl").As<String>().Utf8Value().c_str());
w->cno.CCDTUrlOffset = 0;
w->cno.CCDTUrlLength = strlen(w->cno.CCDTUrlPtr);
if (w->cno.Version < 6) {
w->cno.Version = 6;
if (w->cno.Version < MQCNO_VERSION_6) {
w->cno.Version = MQCNO_VERSION_6;
}
}

v = w->jscno.Get("ApplName");
if (v.IsString()) {
setMQIString(env, w->cno.ApplName, w->jscno, "ApplName", MQ_APPL_NAME_LENGTH);
if (w->cno.Version < 7) {
w->cno.Version = 7;
if (w->cno.Version < MQCNO_VERSION_7) {
w->cno.Version = MQCNO_VERSION_7;
}
}

Expand All @@ -202,8 +202,8 @@ Object CONNX(const CallbackInfo &info) {
w->jsbno = v.As<Object>();
w->cno.BalanceParmsPtr = &w->bno;
copyBNOtoC(env, w->jsbno, &w->bno);
if (w->cno.Version < 8) {
w->cno.Version = 8;
if (w->cno.Version < MQCNO_VERSION_8) {
w->cno.Version = MQCNO_VERSION_8;
}
}
}
Expand Down
27 changes: 23 additions & 4 deletions src/mqcsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ void copyCSPtoC(Env env, Object jscsp, PMQCSP pmqcsp) {
char *cUserId = NULL;
char *cPassword = NULL;
char *cInitialKey = NULL;
char *cToken = NULL;

// Set the Authentication type if there's a non-empty Userid specified.
// There's only one non-default option for now. We don't copy it into the
// C structure if the userid is empty because the CSP might be being used
// only for the InitialKey setting.
String UserId = jscsp.Get("UserId").As<String>();
if (!UserId.IsNull() && !UserId.IsUndefined()) {
cUserId = mqnStrdup(env,UserId.Utf8Value().c_str());
Expand All @@ -43,6 +41,10 @@ void copyCSPtoC(Env env, Object jscsp, PMQCSP pmqcsp) {
pmqcsp->CSPUserIdLength = strlen(cUserId);

pmqcsp->AuthenticationType = getMQLong(jscsp,"_authenticationType");
// If you've set a non-blank userid, then you MUST be asking for userid/pwd checking.
if (pmqcsp->AuthenticationType == MQCSP_AUTH_NONE) {
pmqcsp->AuthenticationType = MQCSP_AUTH_USER_ID_AND_PWD;
}
}

Object Password = jscsp.Get("Password").As<Object>();
Expand All @@ -59,6 +61,22 @@ void copyCSPtoC(Env env, Object jscsp, PMQCSP pmqcsp) {
pmqcsp->InitialKeyPtr = cInitialKey;
pmqcsp->InitialKeyOffset = 0;
pmqcsp->InitialKeyLength = strlen(cInitialKey);
if (pmqcsp->Version < MQCSP_VERSION_2) {
pmqcsp->Version = MQCSP_VERSION_2;
}
}

Object Token = jscsp.Get("Token").As<Object>();
if (!Token.IsNull() && !Token.IsUndefined()) {
cToken = mqnStrdup(env,Token.As<String>().Utf8Value().c_str());
pmqcsp->TokenPtr = cToken;
pmqcsp->TokenOffset = 0;
pmqcsp->TokenLength = strlen(cToken);
// Using a token overrides userid/password checking
pmqcsp->AuthenticationType = MQCSP_AUTH_ID_TOKEN;
if (pmqcsp->Version < MQCSP_VERSION_3) {
pmqcsp->Version = MQCSP_VERSION_3;
}
}
}

Expand All @@ -67,5 +85,6 @@ void cleanupCSP(PMQCSP pCsp) {
mqnFreeString(pCsp->CSPUserIdPtr);
mqnFreeString(pCsp->CSPPasswordPtr);
mqnFreeString(pCsp->InitialKeyPtr);
mqnFreeString(pCsp->TokenPtr);
}
}
}
11 changes: 9 additions & 2 deletions src/mqsco.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

void copySCOtoC(Env env, Object jssco, PMQSCO pmqsco) {

pmqsco->Version = MQSCO_VERSION_4; // Assume this base level

setMQIString(env,pmqsco->KeyRepository, jssco, "KeyRepository",MQ_SSL_KEY_REPOSITORY_LENGTH);
setMQIString(env,pmqsco->CryptoHardware,jssco, "CryptoHardware", MQ_SSL_CRYPTO_HARDWARE_LENGTH);
pmqsco->KeyResetCount = getMQLong(jssco,"KeyResetCount");
Expand All @@ -35,14 +37,19 @@ void copySCOtoC(Env env, Object jssco, PMQSCO pmqsco) {
}
pmqsco->CertificateValPolicy = getMQLong(jssco,"CertificateValPolicy");
setMQIString(env, pmqsco->CertificateLabel , jssco,"CertificateLabel",MQ_CERT_LABEL_LENGTH);
if (pmqsco->CertificateLabel[0] != ' ' && pmqsco->CertificateLabel[0] != 0) {
if (pmqsco->Version < MQSCO_VERSION_5) {
pmqsco->Version = MQSCO_VERSION_5;
}
}

Value v = jssco.Get("KeyRepoPassword");
if (v.IsString()) {
pmqsco->KeyRepoPasswordPtr = mqnStrdup(env,jssco.Get("KeyRepoPassword").As<String>().Utf8Value().c_str());
pmqsco->KeyRepoPasswordOffset = 0;
pmqsco->KeyRepoPasswordLength = strlen((char *)pmqsco->KeyRepoPasswordPtr);
if (pmqsco->Version < 6) {
pmqsco->Version = 6;
if (pmqsco->Version < MQSCO_VERSION_6) {
pmqsco->Version = MQSCO_VERSION_6;
}
}

Expand Down

0 comments on commit dd85424

Please sign in to comment.