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

📄 scapi.cxx

📁 Windows CE 6.0 Server 源码
💻 CXX
📖 第 1 页 / 共 5 页
字号:
		gQueueMan->ForwardTransactionalResponse (pPacket->pImage, MQMSG_CLASS_ACK_RECEIVE, NULL, NULL);
		gQueueMan->AcceptPacket (pPacket, MQMSG_CLASS_ACK_RECEIVE, pQueue);
		pQueue->DisposeOfPacket (pPacket);
	}

	return hRes;
}


static HRESULT scapi_MQReceiveMessageI
(
ScIoRequest *pReq
) {
	gMem->Lock ();

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

	ScPacket	 *pPacket    = NULL;
	ScQueue		 *pQueue     = NULL;
	ScHandleInfo *pHInfo     = NULL;

	HRESULT hr = scapi_GetPacket (pReq->hQueue, pReq->hCursor, pReq->dwAction, pPacket, pQueue, pHInfo);

	if (hr != MQ_OK) {
		SVSUTIL_ASSERT ((! pHInfo));
		SVSUTIL_ASSERT ((! pPacket));
		SVSUTIL_ASSERT ((! pQueue));
		gMem->Unlock ();
		return hr;
	}

	SVSUTIL_ASSERT (pQueue);

	HANDLE hCallerProc = pReq->hCallerProc;

	if (pPacket) {
		SVSUTIL_ASSERT (pHInfo);

		__try {
			hr = scapi_RetrievePacketInfo (pPacket, pQueue, pHInfo, pReq->dwAction, pReq->pMsgProps, hCallerProc);
		} __except (1) {
			hr = MQ_ERROR_PROPERTY;
		}
		gMem->Unlock ();

		return hr;
	}

#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_IO, L"Waiting (again) for message in the queue %s until %d ms.\n", pQueue->lpszFormatName, pReq->tExpirationTicks);
#endif

	HANDLE hQueueEvent = pQueue->hUpdateEvent;

	gMem->Unlock ();

	if (did_expire (pReq->tExpirationTicks, GetTickCount()))
		return MQ_ERROR_IO_TIMEOUT;

	return gOverlappedSupport->EnterOverlappedReceive (hQueueEvent, pReq);
}

//////////////////////////////////////////////////////////////////////
//
//
//	API code section
//
//
//////////////////////////////////////////////////////////////////////
HRESULT	scapi_MQCreateQueue
(
SCPROPVAR		*pQueueProps,
WCHAR			*lpszFormatName,
DWORD			*dwNameLen
) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQCreateQueue\n");
#endif

	if (! pQueueProps)
		return MQ_ERROR_ILLEGAL_MQQUEUEPROPS;

	if (dwNameLen == NULL)
		return MQ_ERROR_INVALID_PARAMETER;

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

	WCHAR			*szLabel = NULL;
	WCHAR			*szPathName = NULL;

	unsigned int	uiJournalQuota = (unsigned int)-1;

	ScQueueParms	qp;

	memset (&qp, 0, sizeof(qp));
	qp.uiPrivacyLevel = MQ_PRIV_LEVEL_NONE;
	qp.bIsIncoming = TRUE;

	gMem->Lock ();

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

	qp.uiQuotaK = gMachine->uiDefaultInQuotaK;

	gMem->Unlock ();

	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)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
			break;

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

		case PROPID_Q_CREATE_TIME:
		case PROPID_Q_INSTANCE:
		case PROPID_Q_MODIFY_TIME:
			hRes = MQ_ERROR_PROPERTY_NOTALLOWED;
			break;

		case PROPID_Q_JOURNAL:
			if (pQueueProps->aPropVar[i].vt != VT_UI1)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else if (pQueueProps->aPropVar[i].bVal == MQ_JOURNAL)
				qp.bIsJournalOn = qp.bHasJournal = TRUE;
			else if (pQueueProps->aPropVar[i].bVal != MQ_JOURNAL_NONE)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VALUE;
			break;

		case PROPID_Q_JOURNAL_QUOTA:
			if (pQueueProps->aPropVar[i].vt != VT_UI4)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				uiJournalQuota = pQueueProps->aPropVar[i].ulVal;
			break;

		case PROPID_Q_LABEL:
			if (pQueueProps->aPropVar[i].vt != VT_LPWSTR)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				szLabel = pQueueProps->aPropVar[i].pwszVal;
			break;

		case PROPID_Q_PATHNAME:
			if (pQueueProps->aPropVar[i].vt != VT_LPWSTR)
				hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
			else
				szPathName = pQueueProps->aPropVar[i].pwszVal;
			break;

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

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

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

			break;

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

		default:
			hRes = MQ_ERROR_ILLEGAL_PROPID;
		}

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

	if (FAILED(hRes))
		return hRes;

	if (szPathName == NULL)
		return MQ_ERROR_INSUFFICIENT_PROPERTIES;

	if (! fApiInitialized)
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;

	gMem->Lock ();

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

	ScQueue *pQueue = gQueueMan->MakeIncomingQueue (szPathName, szLabel ? szLabel : NULL, &qp, uiJournalQuota, &hRes);

	if (! pQueue) {
		gMem->Unlock ();
		return hRes;
	}

	int iFormatChars = wcslen (pQueue->lpszFormatName) + 1;

	if ((int)*dwNameLen < iFormatChars) {
		if (lpszFormatName && (*dwNameLen > 0)) {
			memcpy (lpszFormatName, pQueue->lpszFormatName, (*dwNameLen - 1) * sizeof(WCHAR));
			lpszFormatName[*dwNameLen - 1] = L'\0';
		}

		hRes = MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL;
	}
	else {
		if (lpszFormatName)
			memcpy (lpszFormatName, pQueue->lpszFormatName, iFormatChars * sizeof(WCHAR));

		hRes = MQ_OK;
	}

	*dwNameLen = iFormatChars;

	gMem->Unlock ();
	return hRes;
}

HRESULT	scapi_MQDeleteQueue
(
WCHAR *lpszFormatName
) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQDeleteQueue\n");
#endif

	if (! lpszFormatName)
		return MQ_ERROR_ILLEGAL_FORMATNAME;

	if (! fApiInitialized)
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;

	gMem->Lock ();

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

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

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

		return MQ_ERROR_QUEUE_NOT_FOUND;
	}

	if (pQueue->qp.bIsProtected || pQueue->qp.bIsJournal) {
		gMem->Unlock ();

		return MQ_ERROR_ACCESS_DENIED;
	}

	if (pQueue->pJournal)
		gQueueMan->DeleteQueue (pQueue->pJournal, TRUE);

	gQueueMan->DeleteQueue (pQueue, TRUE);

	gMem->Unlock ();

	return MQ_OK;
}

HRESULT	scapi_MQGetMachineProperties
(
const WCHAR	    *lpszMachineName,
const GUID      *pGUID,
SCPROPVAR       *pMachineProps
) {
#if defined (SC_VERBOSE)
	scerror_DebugOut (VERBOSE_MASK_API, L"Entered MQGetMachineProperties\n");
#endif

	if ((! pMachineProps) || (pMachineProps->cProp < 1))
		return MQ_ERROR_ILLEGAL_MQQMPROPS;

	if (lpszMachineName && pGUID)
		return MQ_ERROR_INVALID_PARAMETER;

	if ((! pMachineProps->aPropID) || (! pMachineProps->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;
	}

	HRESULT hRes = MQ_OK;
		
	__try {
		if (lpszMachineName && (wcsicmp (lpszMachineName, gMachine->lpszHostName) != 0)) {
			gMem->Unlock ();
			return MQ_ERROR_SERVICE_NOT_AVAILABLE;
		}

		if (pGUID && (*pGUID != gMachine->guid)) {
			gMem->Unlock ();
			return MQ_ERROR_SERVICE_NOT_AVAILABLE;
		}

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

		for (int i = 0 ; (! FAILED(hRes)) && i < (int)pMachineProps->cProp; ++i) {
			hRes = MQ_OK;
			switch (pMachineProps->aPropID[i]) {
			case PROPID_QM_MACHINE_ID:
				{
					if (pMachineProps->aPropVar[i].vt == VT_NULL) {
 						pMachineProps->aPropVar[i].puuid = (CLSID*)gMem->remoteAlloc.DuplicateBufferAndTranslate((BYTE*)&gMachine->guid,sizeof(GUID));
						pMachineProps->aPropVar[i].vt = VT_CLSID;
                        break;
					}

					if (pMachineProps->aPropVar[i].vt == VT_CLSID) {
						CMarshallDataToProcess copyOut((HANDLE)GetCallerVMProcessId());
						copyOut.WriteGUIDToProc(pMachineProps->aPropVar[i].puuid, &gMachine->guid, &hRes);
					}
					else
						hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				}
				break;

			default:
				hRes = MQ_ERROR_ILLEGAL_PROPID;
			}

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

	gMem->Unlock ();

	return hRes;
}

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

	if (! lpszFormatName)
		return MQ_ERROR_ILLEGAL_FORMATNAME;

	if (! pQueueProps)
		return MQ_ERROR_ILLEGAL_MQQUEUEPROPS;

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

	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;

	__try {
		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 (pq->qp.bAuthenticate)
					pQueueProps->aPropVar[i].bVal = MQ_AUTHENTICATE;
				else
					pQueueProps->aPropVar[i].bVal = MQ_AUTHENTICATE_NONE;
				break;

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

			case PROPID_Q_CREATE_TIME:
				if (pQueueProps->aPropVar[i].vt != VT_I4)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else
					pQueueProps->aPropVar[i].lVal = (int)pq->tCreation;
				break;

			case PROPID_Q_INSTANCE:
				hRes = MQ_INFORMATION_PROPERTY_IGNORED;
				break;

			case PROPID_Q_MODIFY_TIME:
				if (pQueueProps->aPropVar[i].vt != VT_I4)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else
					pQueueProps->aPropVar[i].lVal = (int)pq->tModification;
				break;

			case PROPID_Q_JOURNAL:
				if (pQueueProps->aPropVar[i].vt != VT_UI1)
					hRes = MQ_ERROR_ILLEGAL_PROPERTY_VT;
				else if (pq->qp.bIsJournalOn)
					pQueueProps->aPropVar[i].bVal = MQ_JOURNAL;

⌨️ 快捷键说明

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