📄 scapi.cxx
字号:
return hr;
}
HRESULT scapi_MQHandleToFormatName (SCHANDLE hQueue, WCHAR *lpszFormatName, DWORD *dwNameLen) {
#if defined (SC_VERBOSE)
scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQHandleToFormatName\n");
#endif
if (! fApiInitialized)
return MQ_ERROR_SERVICE_NOT_AVAILABLE;
gMem->Lock ();
if (! fApiInitialized) {
gMem->Unlock ();
return MQ_ERROR_SERVICE_NOT_AVAILABLE;
}
HRESULT hr = MQ_OK;
ScHandleInfo *pHInfo = gQueueMan->QueryHandle ((SVSHandle)hQueue);
if (pHInfo && (pHInfo->uiHandleType == SCQMAN_HANDLE_QUEUE)) {
__try {
ScQueue *pQueue = pHInfo->pQueue;
int ccFormatChars = wcslen (pQueue->lpszFormatName) + 1;
int ccAddTransact = (! pQueue->qp.bIsIncoming) && pQueue->qp.bTransactional ? SVSUTIL_CONSTSTRLEN(L";XACTONLY") : 0;
if ((int)*dwNameLen < ccFormatChars) {
memcpy (lpszFormatName, pQueue->lpszFormatName, (*dwNameLen - 1) * sizeof(WCHAR));
lpszFormatName[*dwNameLen - 1] = L'\0';
hr = MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL;
} else if ((int)*dwNameLen < ccFormatChars + ccAddTransact) {
memcpy (lpszFormatName, pQueue->lpszFormatName, ccFormatChars * sizeof(WCHAR));
PREFAST_SUPPRESS(12008,"ccFormatChars and ccAddTransact are always lengths of strings in memory, so they are relatively small and an integer overflow can never occur");
memcpy (&lpszFormatName[ccFormatChars], L";XACTONLY", (*dwNameLen - ccFormatChars - 1) * sizeof(WCHAR));
lpszFormatName[*dwNameLen - 1] = L'\0';
*dwNameLen = ccFormatChars + ccAddTransact;
hr = MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL;
} else {
memcpy (lpszFormatName, pQueue->lpszFormatName, ccFormatChars * sizeof(WCHAR));
if (ccAddTransact)
memcpy (&lpszFormatName[ccFormatChars - 1], L";XACTONLY", (ccAddTransact + 1) * sizeof(WCHAR));
*dwNameLen = ccFormatChars + ccAddTransact;
}
}
__except (ReportFault(GetExceptionInformation(),0), EXCEPTION_EXECUTE_HANDLER) {
hr = MQ_ERROR_INVALID_PARAMETER;
}
} else
hr = MQ_ERROR_INVALID_HANDLE;
gMem->Unlock ();
return hr;
}
HRESULT scapi_MQPathNameToFormatName (const WCHAR *lpszPathName, WCHAR *lpszFormatName, DWORD *pdwCount) {
#if defined (SC_VERBOSE)
scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQPathNameToFormatName\n");
#endif
if (! fApiInitialized)
return MQ_ERROR_SERVICE_NOT_AVAILABLE;
__try {
ScQueueParms qp;
memset (&qp, 0, sizeof (qp));
qp.bIsIncoming = TRUE;
WCHAR *szFormatName = scutil_MakeFormatName ((WCHAR *)lpszPathName, &qp);
if (! szFormatName)
return MQ_ERROR_ILLEGAL_QUEUE_PATHNAME;
unsigned int uiFormatChars = wcslen (szFormatName) + 1;
if (*pdwCount < uiFormatChars) {
if (lpszFormatName && *pdwCount > 0) {
memcpy (lpszFormatName, szFormatName, (*pdwCount - 1) * sizeof(WCHAR));
lpszFormatName[*pdwCount - 1] = L'\0';
}
g_funcFree (szFormatName, g_pvFreeData);
return MQ_ERROR_FORMATNAME_BUFFER_TOO_SMALL;
}
if (lpszFormatName)
memcpy (lpszFormatName, szFormatName, uiFormatChars * sizeof(WCHAR));
*pdwCount = uiFormatChars;
g_funcFree (szFormatName, g_pvFreeData);
}
__except (ReportFault(GetExceptionInformation(),0), EXCEPTION_EXECUTE_HANDLER) {
return MQ_ERROR_INVALID_PARAMETER;
}
return MQ_OK;
}
// This function is called with global lock held.
static HRESULT scapi_MQSendMessage(SCHANDLE hQueue, SCPROPVAR *pMsgProps, int iTransaction) {
#if defined (SC_VERBOSE)
scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQSendMessage\n");
#endif
SVSUTIL_ASSERT(gMem->IsLocked());
if (! pMsgProps)
return MQ_ERROR_INSUFFICIENT_PROPERTIES;
if ((NULL == pMsgProps->aPropID) || (NULL == pMsgProps->aPropVar)) {
return MQ_ERROR_ILLEGAL_MQQUEUEPROPS;
}
//
// Construct a packet
//
HRESULT hRes = MQ_OK;
if (pMsgProps->aStatus && pMsgProps->cProp > 0)
memset (pMsgProps->aStatus, 0, sizeof (HRESULT) * pMsgProps->cProp);
unsigned int uiAckType = MQMSG_ACKNOWLEDGMENT_NONE;
unsigned int uiAppSpecific = 0;
unsigned int uiBodyType = 0;
unsigned int uiMsgClass = MQMSG_CLASS_NORMAL;
unsigned int uiDelivery = MQMSG_DELIVERY_EXPRESS;
unsigned int uiJournalType = MQMSG_JOURNAL_NONE;
unsigned int uiPriority = (iTransaction == (int)MQ_SINGLE_MESSAGE) ? 0 : 3;
unsigned int uiTrace = MQMSG_TRACE_NONE;
unsigned int tTTR = INFINITE;
unsigned int tTRQ = INFINITE;
CAUB *pcaubBody = NULL;
CAUB *pcaubCorrId = NULL;
CAUB *pcaubExt = NULL;
CAPROPVARIANT *pFwdVia = NULL;
CAPROPVARIANT *pRevVia = NULL;
int iSoapFwdVia = 0;
int iSoapRevVia = 0;
WCHAR *lpszAdminQueue = NULL;
WCHAR *lpszLabel = NULL;
WCHAR *lpszResponseQueue = NULL;
WCHAR *lpszDestQueue = NULL;
WCHAR *lpszSoapBody = NULL;
WCHAR *lpszSoapHeader = NULL;
WCHAR *lpszSoapEnvelope = NULL;
WCHAR *lpszSoapRelatesTo = NULL;
WCHAR *lpszSoapFrom = NULL;
int iMsgNdx = -1;
for (int i = 0 ; (! FAILED (hRes)) && (i < (int)pMsgProps->cProp) ; ++i) {
hRes = MQ_OK;
switch (pMsgProps->aPropID[i]) {
case PROPID_M_ACKNOWLEDGE:
if (pMsgProps->aPropVar[i].vt != VT_UI1)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiAckType = pMsgProps->aPropVar[i].bVal;
break;
case PROPID_M_ADMIN_QUEUE:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR) || (! pMsgProps->aPropVar[i].pwszVal))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszAdminQueue = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_APPSPECIFIC:
if (pMsgProps->aPropVar[i].vt != VT_UI4)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiAppSpecific = pMsgProps->aPropVar[i].ulVal;
break;
case PROPID_M_AUTH_LEVEL:
if (pMsgProps->aPropVar[i].vt != VT_UI4)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else if (pMsgProps->aPropVar[i].ulVal != MQMSG_AUTH_LEVEL_NONE)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
break;
case PROPID_M_BODY:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_UI1)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else if (pMsgProps->aPropVar[i].caub.cElems && pMsgProps->aPropVar[i].caub.pElems)
pcaubBody = &pMsgProps->aPropVar[i].caub;
break;
case PROPID_M_BODY_TYPE:
if (pMsgProps->aPropVar[i].vt != VT_UI4)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiBodyType = pMsgProps->aPropVar[i].ulVal;
break;
case PROPID_M_CLASS:
if (pMsgProps->aPropVar[i].vt != VT_UI2)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiMsgClass = pMsgProps->aPropVar[i].uiVal;
break;
case PROPID_M_CORRELATIONID:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_UI1)) ||
(pMsgProps->aPropVar[i].caub.cElems <= 0) ||
(pMsgProps->aPropVar[i].caub.cElems > 20) ||
(! pMsgProps->aPropVar[i].caub.pElems))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
pcaubCorrId = &pMsgProps->aPropVar[i].caub;
break;
case PROPID_M_DELIVERY:
if ((pMsgProps->aPropVar[i].vt != VT_UI1) ||
((pMsgProps->aPropVar[i].bVal != MQMSG_DELIVERY_EXPRESS) &&
(pMsgProps->aPropVar[i].bVal != MQMSG_DELIVERY_RECOVERABLE)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiDelivery = pMsgProps->aPropVar[i].bVal;
break;
case PROPID_M_DEST_QUEUE:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR) || (! pMsgProps->aPropVar[i].pwszVal))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszDestQueue = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_EXTENSION:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_UI1)) ||
(pMsgProps->aPropVar[i].caub.cElems <= 0) ||
(! pMsgProps->aPropVar[i].caub.pElems))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
pcaubExt = &pMsgProps->aPropVar[i].caub;
break;
case PROPID_M_JOURNAL:
if ((pMsgProps->aPropVar[i].vt != VT_UI1) ||
(pMsgProps->aPropVar[i].bVal & (~(MQMSG_DEADLETTER | MQMSG_JOURNAL | MQMSG_JOURNAL_NONE))))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiJournalType = pMsgProps->aPropVar[i].bVal;
break;
case PROPID_M_LABEL:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR) || (! pMsgProps->aPropVar[i].pwszVal))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszLabel = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_PRIORITY:
if ((pMsgProps->aPropVar[i].vt != VT_UI1) || (pMsgProps->aPropVar[i].bVal > 7))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiPriority = pMsgProps->aPropVar[i].bVal;
break;
case PROPID_M_RESP_QUEUE:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR) || (! pMsgProps->aPropVar[i].pwszVal))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszResponseQueue = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_TIME_TO_BE_RECEIVED:
if (pMsgProps->aPropVar[i].vt != VT_UI4)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
tTTR = pMsgProps->aPropVar[i].ulVal;
break;
case PROPID_M_TIME_TO_REACH_QUEUE:
if (pMsgProps->aPropVar[i].vt != VT_UI4)
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
tTRQ = pMsgProps->aPropVar[i].ulVal;
break;
case PROPID_M_TRACE:
if ((pMsgProps->aPropVar[i].vt != VT_UI1) ||
((pMsgProps->aPropVar[i].bVal != MQMSG_SEND_ROUTE_TO_REPORT_QUEUE) &&
(pMsgProps->aPropVar[i].bVal != MQMSG_TRACE_NONE)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
uiTrace = pMsgProps->aPropVar[i].bVal;
break;
case PROPID_M_MSGID:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_UI1)) ||
(pMsgProps->aPropVar[i].caub.cElems <= 0) ||
(pMsgProps->aPropVar[i].caub.cElems > 20) ||
(! pMsgProps->aPropVar[i].caub.pElems))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else {
iMsgNdx = i;
}
break;
case PROPID_M_BODY_SIZE:
case PROPID_M_EXTENSION_LEN:
case PROPID_M_SENDERID_LEN:
case PROPID_M_SENDERID_TYPE:
case PROPID_M_SENDERID:
hRes = MQ_INFORMATION_PROPERTY_IGNORED;
break;
case PROPID_M_SOAP_HEADER:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszSoapHeader = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_SOAP_BODY:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszSoapBody = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_SOAP_FWD_VIA:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_VARIANT)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
if (hRes != MQ_OK)
break;
pFwdVia = &pMsgProps->aPropVar[i].capropvar;
if (hRes == ERROR_SUCCESS) {
if (0 == (iSoapFwdVia = CalcFwdRevViaSectionSize(pFwdVia)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
}
break;
case PROPID_M_SOAP_REV_VIA:
if ((pMsgProps->aPropVar[i].vt != (VT_VECTOR | VT_VARIANT)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
if (hRes != MQ_OK)
break;
pRevVia = &pMsgProps->aPropVar[i].capropvar;
if (hRes == ERROR_SUCCESS) {
if (0 == (iSoapRevVia = CalcFwdRevViaSectionSize(pRevVia)))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
}
break;
case PROPID_M_SOAP_FROM:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszSoapFrom = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_SOAP_RELATES_TO:
if ((pMsgProps->aPropVar[i].vt != VT_LPWSTR))
hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
else
lpszSoapRelatesTo = pMsgProps->aPropVar[i].pwszVal;
break;
case PROPID_M_LABEL_LEN:
case PROPID_M_RESP_QUEUE_LEN:
case PROPID_M_DEST_QUEUE_LEN:
case PROPID_M_ADMIN_QUEUE_LEN:
// In case a user wants to forward on a message they have received
// that may have these values set, silently ignore them.
break;
case PROPID_M_XACT_STATUS_QUEUE:
case PROPID_M_XACT_STATUS_QUEUE_LEN:
case PROPID_M_VERSION:
case PROPID_M_SRC_MACHINE_ID:
case PROPID_M_SIGNATURE:
case PROPID_M_SIGNATURE_LEN:
case PROPID_M_SENTTIME:
case PROPID_M_SENDER_CERT_LEN:
case PROPID_M_SENDER_CERT:
case PROPID_M_SECURITY_CONTEXT:
case PROPID_M_PROV_TYPE:
case PROPID_M_PROV_NAME_LEN:
case PROPID_M_PROV_NAME:
case PROPID_M_PRIV_LEVEL:
case PROPID_M_HASH_ALG:
case PROPID_M_ENCRYPTION_ALG:
case PROPID_M_DEST_SYMM_KEY:
case PROPID_M_DEST_SYMM_KEY_LEN:
case PROPID_M_CONNECTOR_TYPE:
case PROPID_M_AUTHENTICATED:
case PROPID_M_ARRIVEDTIME:
default:
hRes = MQ_ERROR_PROPERTY;
}
if (pMsgProps->aStatus)
pMsgProps->aStatus[i] = hRes;
}
if (FAILED(hRes))
return hRes;
if (lpszLabel && (wcslen (lpszLabel) > MQ_MAX_MSG_LABEL_LEN))
return MQ_ERROR_LABEL_TOO_LONG;
if (tTTR < tTRQ)
tTRQ = tTTR;
if ((tTRQ != INFINITE) && (tTTR != INFINITE))
tTTR -= tTRQ;
//
// Parameters parsed. Check the validity...
//
if (! fApiInitialized)
return MQ_ERROR_SERVICE_NOT_AVAILABLE;
if ((! gMachine->fUseSRMP) &&
(lpszSoapHeader || lpszSoapBody || pFwdVia || pRevVia || lpszSoapFrom || lpszSoapRelatesTo)) {
return MQ_INFORMATION_UNSUPPORTED_PROPERTY;
}
ScHandleInfo *pHInfo = gQueueMan->QueryHandle ((SVSHandle)hQueue);
if ((! pHInfo) || (pHInfo->uiHandleType != SCQMAN_HANDLE_QUEUE)) {
return MQ_ERROR_INVALID_HANDLE;
}
if (pHInfo->q.uiAccess != MQ_SEND_ACCESS) {
return MQ_ERROR_INVALID_HANDLE;
}
ScQueue *pQueue = pHInfo->pQueue;
int fHttp = pQueue->IsHttpOrHttps();
int fUseSoap = (lpszSoapHeader || lpszSoapBody);
if (pQueue->qp.bTransactional) {
uiDelivery = MQMSG_DELIVERY_RECOVERABLE;
if (iTransaction != (int)MQ_SINGLE_MESSAGE)
hRes = M
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -