⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scapi.cxx

📁 Windows CE 6.0 Server 源码
💻 CXX
📖 第 1 页 / 共 5 页
字号:
				else
					pQueueProps->aPropVar[i].bVal = MQ_JOURNAL_NONE;

				break;

			case PROPID_Q_JOURNAL_QUOTA:
				if (pQueueProps->aPropVar[i].vt != VT_UI4)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
				else
					pQueueProps->aPropVar[i].ulVal = pq->pJournal ? pq->pJournal->qp.uiQuotaK : 0;
				break;

			case PROPID_Q_PRIV_LEVEL:
				if (pQueueProps->aPropVar[i].vt != VT_UI4)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else
					pQueueProps->aPropVar[i].ulVal = pq->qp.uiPrivacyLevel;
				break;

			case PROPID_Q_QUOTA:
				if (pQueueProps->aPropVar[i].vt != VT_UI4)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else
					pQueueProps->aPropVar[i].ulVal = pq->qp.uiQuotaK;
				break;

			case PROPID_Q_TRANSACTION:
				if (pQueueProps->aPropVar[i].vt != VT_UI1)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else
					pQueueProps->aPropVar[i].bVal = pq->qp.bTransactional ? MQ_TRANSACTIONAL :
													MQ_TRANSACTIONAL_NONE;
				break;

			case PROPID_Q_TYPE:
				if (pQueueProps->aPropVar[i].vt != VT_CLSID)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else if (! pQueueProps->aPropVar[i].puuid)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
				else {
					CMarshallDataToProcess copyData((HANDLE)GetCallerVMProcessId());
					copyData.WriteGUIDToProc(pQueueProps->aPropVar[i].puuid, &pq->qp.guidQueueType, &hRes);
				}
				break;

			case PROPID_Q_LABEL:
				if (pQueueProps->aPropVar[i].vt != VT_NULL)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else {
					pQueueProps->aPropVar[i].vt = VT_LPWSTR;
					pQueueProps->aPropVar[i].pwszVal = scutil_OutOfProcDup (pq->lpszQueueLabel ? pq->lpszQueueLabel : L"");
				}
				break;

			case PROPID_Q_PATHNAME:
				if (pQueueProps->aPropVar[i].vt != VT_NULL)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else {
					pQueueProps->aPropVar[i].vt = VT_LPWSTR;
					WCHAR *lpsz = scutil_MakePathName (pq->lpszQueueHost, pq->lpszQueueName, &pq->qp);

					pQueueProps->aPropVar[i].pwszVal = scutil_OutOfProcDup (lpsz);
					g_funcFree (lpsz, g_pvFreeData);
				}
				break;

			default:
				hRes = MQ_ERROR_ILLEGAL_PROPID;
			}

			if (pQueueProps->aStatus)
				pQueueProps->aStatus[i] = hRes;
		}
	}
	__except(ReportFault(GetExceptionInformation(),0), EXCEPTION_EXECUTE_HANDLER) {
		hRes = MQ_ERROR_INVALID_PARAMETER;
	}

	gMem->Unlock ();

	return hRes;
}

HRESULT scapi_MQSetQueueProperties (WCHAR *lpszFormatName, SCPROPVAR *pQueueProps) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQSetQueueProperties\n");
#endif

	if (! lpszFormatName)
		return MQ_ERROR_ILLEGAL_FORMATNAME;

	if (! pQueueProps)
		return MQ_ERROR_ILLEGAL_MQQUEUEPROPS;

	HANDLE			hCallerProc = (HANDLE)GetCallerProcess();

	if ((NULL == pQueueProps->aPropID) || (NULL == pQueueProps->aPropVar)) {
		return MQ_ERROR_ILLEGAL_MQQUEUEPROPS;
	}

	if (! fApiInitialized)
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;

	gMem->Lock ();

	if (! fApiInitialized) {
		gMem->Unlock ();
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;
	}

	ScQueue *pq = gQueueMan->FindIncomingByFormat (lpszFormatName);

	if (! pq) {
		gMem->Unlock ();
		return MQ_ERROR_QUEUE_NOT_FOUND;
	}

	HRESULT hRes = MQ_OK;

	if (pQueueProps->aStatus && pQueueProps->cProp > 0)
		memset (pQueueProps->aStatus, 0, sizeof (HRESULT) * pQueueProps->cProp);

	for (int i = 0 ; (! FAILED(hRes)) && i < (int)pQueueProps->cProp; ++i) {
		hRes = MQ_OK;
		switch (pQueueProps->aPropID[i]) {
		case PROPID_Q_AUTHENTICATE:
			if (pQueueProps->aPropVar[i].vt != VT_UI1)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else if (pQueueProps->aPropVar[i].bVal == MQ_AUTHENTICATE_NONE)
				pq->qp.bAuthenticate = FALSE;
			else
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
			break;

		case PROPID_Q_BASEPRIORITY:
			if (pQueueProps->aPropVar[i].vt != VT_I2)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
			else
				pq->qp.iBasePriority = pQueueProps->aPropVar[i].iVal;
			break;

		case PROPID_Q_JOURNAL:
			if (! pq->pJournal)
				hRes = MQ_ERROR_PROPERTY;
			else if (pQueueProps->aPropVar[i].bVal == MQ_JOURNAL)
				pq->qp.bIsJournalOn = TRUE;
			else if (pQueueProps->aPropVar[i].bVal == MQ_JOURNAL_NONE)
				pq->qp.bIsJournalOn = FALSE;
			else
				hRes = MQ_ERROR_PROPERTY;
			break;

		case PROPID_Q_JOURNAL_QUOTA:
			if (! pq->pJournal)
				hRes = MQ_ERROR_PROPERTY;
			else
				pq->pJournal->qp.uiQuotaK = pQueueProps->aPropVar[i].ulVal;
			break;

		case PROPID_Q_CREATE_TIME:
		case PROPID_Q_INSTANCE:
		case PROPID_Q_MODIFY_TIME:
		case PROPID_Q_PATHNAME:
		case PROPID_Q_TRANSACTION:
			hRes = MQ_ERROR_WRITE_NOT_ALLOWED;
			break;

		case PROPID_Q_LABEL:
			if (pQueueProps->aPropVar[i].vt != VT_LPWSTR)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else {
				if (pq->lpszQueueLabel) {
					g_funcFree (pq->lpszQueueLabel, g_pvFreeData);
					pq->lpszQueueLabel = NULL;
				}

				WCHAR *lpszNewLabel = pQueueProps->aPropVar[i].pwszVal;

				if (lpszNewLabel && (lpszNewLabel[0] != L'\0'))
					pq->lpszQueueLabel = svsutil_wcsdup (lpszNewLabel);
				else
					pq->lpszQueueLabel = NULL;
			}
			break;

		case PROPID_Q_PRIV_LEVEL:
			if (pQueueProps->aPropVar[i].vt != VT_UI4)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				pq->qp.uiPrivacyLevel = pQueueProps->aPropVar[i].ulVal;
			break;

		case PROPID_Q_QUOTA:
			if (pQueueProps->aPropVar[i].vt != VT_UI4)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				pq->qp.uiQuotaK = pQueueProps->aPropVar[i].ulVal;
			break;

		case PROPID_Q_TYPE:
			if ((pQueueProps->aPropVar[i].vt != VT_CLSID) || (! pQueueProps->aPropVar[i].puuid))
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				pq->qp.guidQueueType = *pQueueProps->aPropVar[i].puuid;
			break;

		default:
			hRes = MQ_ERROR_ILLEGAL_PROPID;
		}
		if (pQueueProps->aStatus)
			pQueueProps->aStatus[i] = hRes;
	}

	if (! FAILED(hRes))
		pq->UpdateFile ();

	gMem->Unlock ();
	return hRes;
}

HRESULT	scapi_MQOpenQueue (WCHAR *lpszFormatName, DWORD dwAccess, DWORD dwShareMode, SCHANDLE *phQueue) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQOpenQueue\n");
#endif

	if (! phQueue)
		return MQ_ERROR;

	if (! lpszFormatName)
		return MQ_ERROR_ILLEGAL_FORMATNAME;

	if ((dwAccess != MQ_PEEK_ACCESS) && (dwAccess != MQ_SEND_ACCESS) && (dwAccess != MQ_RECEIVE_ACCESS))
		return MQ_ERROR_UNSUPPORTED_ACCESS_MODE;

	if ((dwAccess == MQ_SEND_ACCESS) && (dwShareMode != MQ_DENY_NONE))
		return MQ_ERROR_INVALID_PARAMETER;

	if (dwShareMode != MQ_DENY_NONE && dwShareMode != MQ_DENY_RECEIVE_SHARE)
		return MQ_ERROR_INVALID_PARAMETER;

	if (! fApiInitialized)
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;	

	gMem->Lock ();

	if (! fApiInitialized) {
		gMem->Unlock ();
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;
	}

	WCHAR *p = wcschr (lpszFormatName, L';');
	if (p && (wcsicmp (p, L";XACTONLY") != 0))
		p = NULL;

	if (p)
		*p = L'\0';

	int uiQueueType;
	ScQueue *pq = gQueueMan->FindIncomingByFormat(lpszFormatName,&uiQueueType);

	if ((! pq) && (dwAccess == MQ_SEND_ACCESS)) {
		pq = gQueueMan->FindOutgoingByFormat (lpszFormatName);

		if (! pq) {
			ScQueueParms qp;
			memset (&qp, 0, sizeof(qp));
			qp.uiQuotaK = gMachine->uiDefaultOutQuotaK;
			qp.bTransactional = p != NULL;
			pq = gQueueMan->MakeOutgoingQueue (lpszFormatName, &qp, NULL);
		}
	}

	if (p)
		*p = L';';

	if (! pq) {
		gMem->Unlock ();

		return MQ_ERROR_QUEUE_NOT_FOUND;
	}

	if (((pq->fDenyAll) && (dwAccess == MQ_RECEIVE_ACCESS)) ||
		((pq->uiOpenRecv) && (dwShareMode == MQ_DENY_RECEIVE_SHARE)) || pq->qp.bIsInternal) {
		gMem->Unlock ();

		return MQ_ERROR_ACCESS_DENIED;
	}

	if (dwAccess == MQ_SEND_ACCESS) {
		if (pq->qp.bIsDeadLetter || pq->qp.bIsJournal || pq->qp.bIsMachineJournal || pq->qp.bIsOrderAck) {
			gMem->Unlock ();

			return MQ_ERROR_UNSUPPORTED_FORMATNAME_OPERATION;
		}

		if (! pq->qp.bIsIncoming) {
			if ( (pq->IsHttpOrHttps () && (! gMachine->fUseSRMP)) ||
				((! pq->IsHttpOrHttps ()) && (! gMachine->fUseBinary)) ) {
				gMem->Unlock ();
				return MQ_ERROR_QUEUE_NOT_AVAILABLE;
			}
		}
	}

	ScHandleInfo sHInfo;

	sHInfo.uiHandleType       = SCQMAN_HANDLE_QUEUE;
	sHInfo.pQueue             = pq;
	sHInfo.pProcId            = scapi_GetOwnerProcId ();
	sHInfo.q.uiShareMode      = dwShareMode;
	sHInfo.q.uiAccess         = dwAccess;
	sHInfo.q.uiQueueType      = uiQueueType;

	SCHANDLE hQueue = (SCHANDLE)gQueueMan->AllocHandle (&sHInfo);

	HRESULT hr = MQ_ERROR_INSUFFICIENT_RESOURCES;
	if ((SVSHandle)hQueue != SVSUTIL_HANDLE_INVALID) {
		hr = MQ_OK;

		ScHandleInfo *pHInfo = gQueueMan->QueryHandle ((SVSHandle)hQueue);
		SVSUTIL_ASSERT (pHInfo && (pHInfo->pQueue == pq) && (pHInfo->uiHandleType == SCQMAN_HANDLE_QUEUE));

		if (dwShareMode == MQ_DENY_RECEIVE_SHARE)
			pq->fDenyAll = TRUE;

		if (dwAccess != MQ_SEND_ACCESS)
			++pq->uiOpenRecv;

		pq->uiOpen++;

		if (pq->qp.bIsIncoming) {
			sHInfo.uiHandleType  = SCQMAN_HANDLE_CURSOR;
			sHInfo.pQueue        = pq;
			sHInfo.pProcId       = scapi_GetOwnerProcId ();
			sHInfo.c.hQueue      = (SVSHandle)hQueue;
			sHInfo.c.pNode		 = NULL;
			sHInfo.c.fPosValid   = FALSE;

			pHInfo->q.hDefaultCursor = gQueueMan->AllocHandle (&sHInfo);

			if (pHInfo->q.hDefaultCursor == SVSUTIL_HANDLE_INVALID) {
				gQueueMan->CloseHandle ((SVSHandle)hQueue);
				hr = MQ_ERROR_INSUFFICIENT_RESOURCES;
			}
		} else
			pHInfo->q.hDefaultCursor = SVSUTIL_HANDLE_INVALID;

		if (hr == MQ_OK) {
			// This assignment does not require a try/except because 
			// the phQueue is a local stack variable of the caller, not 
			// direct ptr from PSL.
			*phQueue = hQueue;
		}
	}

	gMem->Unlock ();

	return hr;
}

HRESULT scapi_MQCloseQueue (SCHANDLE hQueue) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQCloseQueue\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)) {
		gQueueMan->CloseAllHandles ((SVSHandle)hQueue);
		gQueueMan->CloseHandle ((SVSHandle)hQueue);
	} else
		hr = MQ_ERROR_INVALID_HANDLE;

	gMem->Unlock ();
	return hr;
}

HRESULT scapi_MQCreateCursor (SCHANDLE hQueue, SCHANDLE *phCursor) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQCreateCursor\n");
#endif

	if (! phCursor)
		return MQ_ERROR_INVALID_PARAMETER;

	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) &&
									pHInfo->pQueue->qp.bIsIncoming) {
		ScHandleInfo sHInfo;
		sHInfo.uiHandleType = SCQMAN_HANDLE_CURSOR;
		sHInfo.pQueue       = pHInfo->pQueue;
		sHInfo.pProcId      = scapi_GetOwnerProcId ();
		sHInfo.c.hQueue     = (SVSHandle)hQueue;
		sHInfo.c.pNode		= NULL;
		sHInfo.c.fPosValid  = FALSE;

		SVSHandle hCursor = gQueueMan->AllocHandle (&sHInfo);

		if (hCursor == SVSUTIL_HANDLE_INVALID)
			hr = MQ_ERROR_INSUFFICIENT_RESOURCES;
		else
		{
			*phCursor = hCursor;
		}
	} else
		hr = MQ_ERROR_INVALID_HANDLE;


	gMem->Unlock ();

	return hr;
}

HRESULT scapi_MQCloseCursor (SCHANDLE hCursor) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQCloseCursor\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)hCursor);

	if (pHInfo && (pHInfo->uiHandleType == SCQMAN_HANDLE_CURSOR))
		gQueueMan->CloseHandle ((SVSHandle)hCursor);
	else
		hr = MQ_ERROR_INVALID_HANDLE;

	gMem->Unlock ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -