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

📄 scmgmt.cxx

📁 Windows CE 6.0 Server 源码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++


Module Name:

    scmgmt.cxx

Abstract:

    Small client driver


--*/
#include <windows.h>
#include <mq.h>

#include <scapi.h>

#include <sc.hxx>
#include <scqman.hxx>
#include <scqueue.hxx>
#include <scpacket.hxx>
#include <scfile.hxx>
#include <scsman.hxx>
#include <scorder.hxx>

#include <mqmgmt.h>

// Called with lock held and in __try/__except block.
static HRESULT scmgmt_MQMgmtGetInfo2
(
LPCWSTR			pMachineName,
LPCWSTR			pObjectName,
DWORD			cp,
PROPID			aPropID[],
PROPVARIANT		aPropVar[]
) {
	SVSUTIL_ASSERT(gMem->IsLocked());

	if (pMachineName)
		return MQ_ERROR_MACHINE_NOT_FOUND;

	if (! pObjectName || (! cp) || (! aPropID) || (! aPropVar))
		return MQ_ERROR_INVALID_PARAMETER;

	if (! fApiInitialized)
		return MQ_ERROR_SERVICE_NOT_AVAILABLE;

	if (wcsicmp (pObjectName, MO_MACHINE_TOKEN) == 0) {
		//
		//	Validate parameters first
		//
		for (int i = 0 ; i < (int)cp ; ++i) {
			switch (aPropID[i]) {
			case PROPID_MGMT_MSMQ_ACTIVEQUEUES:
			case PROPID_MGMT_MSMQ_PRIVATEQ:
			case PROPID_MGMT_MSMQ_DSSERVER:
			case PROPID_MGMT_MSMQ_CONNECTED:
			case PROPID_MGMT_MSMQ_TYPE:
				if (aPropVar[i].vt != VT_NULL)
					return MQ_ERROR_PROPERTY;
				break;
			default:
				return MQ_ERROR_PROPERTY;
			}
		}

		//
		//	Do the work
		//
		if (! fApiInitialized) {
			return MQ_ERROR_SERVICE_NOT_AVAILABLE;
		}

		for (i = 0 ; i < (int)cp ; ++i) {
			switch (aPropID[i]) {
			case PROPID_MGMT_MSMQ_ACTIVEQUEUES:
				{
					//
					//	Active are all queues
					//
					int iQueues = 0;
					ScQueueList *pql = gQueueMan->pqlIncoming;

					while (pql) {
						++iQueues;

						pql = pql->pqlNext;
					}

					pql = gQueueMan->pqlOutgoing;

					while (pql) {
						++iQueues;

						pql = pql->pqlNext;
					}

					if (! iQueues)
						break;

					// Allocate data to hold the pointers.  Translate
					// to user address space only once we've written everything
					// out in servicesd.exe address space.
					WCHAR **ppsz = (WCHAR **)gMem->remoteAlloc.AllocOnCallerHeap(iQueues * sizeof(WCHAR*));
					if (! ppsz)
						break;

					aPropVar[i].vt = VT_VECTOR | VT_LPWSTR;
					aPropVar[i].calpwstr.cElems = iQueues;
					pql = gQueueMan->pqlIncoming;

					int iQueues2 = 0;

					while (pql) {
						ppsz[iQueues2++] = scutil_OutOfProcDup (pql->pQueue->lpszFormatName);

						pql = pql->pqlNext;
					}

					pql = gQueueMan->pqlOutgoing;

					while (pql) {
						ppsz[iQueues2++] = scutil_OutOfProcDup (pql->pQueue->lpszFormatName);

						pql = pql->pqlNext;
					}

					aPropVar[i].calpwstr.pElems = (WCHAR **)gMem->remoteAlloc.TranslateData((BYTE*)ppsz);

					SVSUTIL_ASSERT (iQueues == iQueues2);
				}
				break;

			case PROPID_MGMT_MSMQ_PRIVATEQ:
				{
					//
					//	Only local (they are all private)
					//
					int iQueues = 0;
					ScQueueList *pql = gQueueMan->pqlIncoming;

					while (pql) {
						if (! (pql->pQueue->qp.bIsDeadLetter || pql->pQueue->qp.bIsInternal ||
							pql->pQueue->qp.bIsJournal || pql->pQueue->qp.bIsMachineJournal ||
							pql->pQueue->qp.bIsOrderAck || pql->pQueue->qp.bIsProtected))
							++iQueues;

						pql = pql->pqlNext;
					}

					if (! iQueues)
						break;

					// Allocate data to hold the pointers.  Translate
					// to user address space only once we've written everything
					// out in servicesd.exe address space.
					WCHAR **ppsz = (WCHAR **)gMem->remoteAlloc.AllocOnCallerHeap(iQueues * sizeof(WCHAR*));
					if (! ppsz)
						break;

					aPropVar[i].vt = VT_VECTOR | VT_LPWSTR;
					aPropVar[i].calpwstr.cElems = iQueues;
					pql = gQueueMan->pqlIncoming;

					int iQueues2 = 0;

					while (pql) {
						if (! (pql->pQueue->qp.bIsDeadLetter || pql->pQueue->qp.bIsInternal ||
							pql->pQueue->qp.bIsJournal || pql->pQueue->qp.bIsMachineJournal ||
							pql->pQueue->qp.bIsOrderAck || pql->pQueue->qp.bIsProtected))
							ppsz[iQueues2++] = scutil_OutOfProcDup (pql->pQueue->lpszFormatName);

						pql = pql->pqlNext;
					}

					aPropVar[i].calpwstr.pElems = (WCHAR **)gMem->remoteAlloc.TranslateData((BYTE*)ppsz);

					SVSUTIL_ASSERT (iQueues == iQueues2);
				}
				break;

			case PROPID_MGMT_MSMQ_DSSERVER:
				break;

			case PROPID_MGMT_MSMQ_CONNECTED:
				{
					int fConnected = FALSE;

					ScSession *pSess = gSessionMan->pSessList;

					while (pSess) {
						if (pSess->fSessionState == SCSESSION_STATE_OPERATING) {
							fConnected = TRUE;
							break;
						}

						pSess = pSess->pNext;
					}

					aPropVar[i].vt = VT_LPWSTR;
					aPropVar[i].pwszVal = (WCHAR *)scutil_OutOfProcDup (fConnected ? MSMQ_CONNECTED : MSMQ_DISCONNECTED);
				}
				break;

			case PROPID_MGMT_MSMQ_TYPE:
				{
					OSVERSIONINFO v;

					v.dwOSVersionInfoSize = sizeof (v);

					GetVersionEx (&v);

					WCHAR szBuffer[MSMQ_SC_BIGBUFFER];
					StringCchPrintfW(szBuffer, MSMQ_SC_BIGBUFFER, L"Windows CE %d.%02d (Build %d, %d) - MSMQ %d.%d (Build %d), MSMQ_CE",
							v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber, v.dwPlatformId,
							SC_VERSION_MAJOR, SC_VERSION_MINOR, SC_VERSION_BUILD_NUMBER);

					aPropVar[i].vt = VT_LPWSTR;
					aPropVar[i].pwszVal = (WCHAR *)scutil_OutOfProcDup (szBuffer);
				}
				break;

			default:
				SVSUTIL_ASSERT (0);
			}
		}
	} else {
		if (wcsnicmp (pObjectName, MO_QUEUE_TOKEN, SVSUTIL_CONSTSTRLEN(MO_QUEUE_TOKEN)) != 0)
			return MQ_ERROR_INVALID_PARAMETER;

		WCHAR *lpszFormatName = (WCHAR *)pObjectName + SVSUTIL_CONSTSTRLEN(MO_QUEUE_TOKEN) + 1;

		//
		//	Validate parameters first
		//
		for (int i = 0 ; i < (int)cp ; ++i) {
			switch (aPropID[i]) {
			case PROPID_MGMT_QUEUE_BASE:
				break;

			case PROPID_MGMT_QUEUE_PATHNAME:
			case PROPID_MGMT_QUEUE_FORMATNAME:
			case PROPID_MGMT_QUEUE_TYPE:
			case PROPID_MGMT_QUEUE_LOCATION:
			case PROPID_MGMT_QUEUE_XACT:
			case PROPID_MGMT_QUEUE_FOREIGN:
			case PROPID_MGMT_QUEUE_MESSAGE_COUNT:
			case PROPID_MGMT_QUEUE_USED_QUOTA:
			case PROPID_MGMT_QUEUE_JOURNAL_MESSAGE_COUNT:
			case PROPID_MGMT_QUEUE_JOURNAL_USED_QUOTA:
			case PROPID_MGMT_QUEUE_STATE:
			case PROPID_MGMT_QUEUE_NEXTHOPS:
			case PROPID_MGMT_QUEUE_EOD_LAST_ACK:
			case PROPID_MGMT_QUEUE_EOD_LAST_ACK_TIME:
			case PROPID_MGMT_QUEUE_EOD_LAST_ACK_COUNT:
			case PROPID_MGMT_QUEUE_EOD_FIRST_NON_ACK:
			case PROPID_MGMT_QUEUE_EOD_LAST_NON_ACK:
			case PROPID_MGMT_QUEUE_EOD_NEXT_SEQ:
			case PROPID_MGMT_QUEUE_EOD_NO_READ_COUNT:
			case PROPID_MGMT_QUEUE_EOD_NO_ACK_COUNT:
			case PROPID_MGMT_QUEUE_EOD_RESEND_TIME:
			case PROPID_MGMT_QUEUE_EOD_RESEND_INTERVAL:
			case PROPID_MGMT_QUEUE_EOD_RESEND_COUNT:
			case PROPID_MGMT_QUEUE_EOD_SOURCE_INFO:
				if (aPropVar[i].vt != VT_NULL)
					return MQ_ERROR_PROPERTY;
				break;
			default:
				return MQ_ERROR_PROPERTY;
			}
		}

		if (! fApiInitialized)
			return MQ_ERROR_SERVICE_NOT_AVAILABLE;

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

		if (! pQueue) {
			return MQ_ERROR_QUEUE_NOT_FOUND;
		}

		//
		//	Do the work...
		//
		for (i = 0 ; i < (int)cp ; ++i) {
			switch (aPropID[i]) {
			case PROPID_MGMT_QUEUE_BASE:
				break;

			case PROPID_MGMT_QUEUE_PATHNAME:
				if (pQueue->qp.bIsDeadLetter || pQueue->qp.bIsMachineJournal ||
					pQueue->qp.bIsInternal || pQueue->qp.bIsOrderAck || pQueue->qp.bIsProtected)
					break;

⌨️ 快捷键说明

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