Commit 7c248ff4 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

wtsapi32: Implement WTSEnumerateSessionsA() on top of WTSEnumerateSessionsW().

parent 6c3399a9
......@@ -310,14 +310,19 @@ static void test_WTSEnumerateSessions(void)
{
BOOL console_found = FALSE, services_found = FALSE;
WTS_SESSION_INFOW *info;
WTS_SESSION_INFOA *infoA;
DWORD count, count2;
unsigned int i;
DWORD count;
BOOL bret;
bret = WTSEnumerateSessionsW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &info, &count);
ok(bret, "got error %lu.\n", GetLastError());
todo_wine_if(count == 1) ok(count >= 2, "got %lu.\n", count);
bret = WTSEnumerateSessionsA(WTS_CURRENT_SERVER_HANDLE, 0, 1, &infoA, &count2);
ok(bret, "got error %lu.\n", GetLastError());
ok(count2 == count, "got %lu.\n", count2);
for (i = 0; i < count; ++i)
{
trace("SessionId %lu, name %s, State %d.\n", info[i].SessionId, debugstr_w(info[i].pWinStationName), info[i].State);
......@@ -325,17 +330,20 @@ static void test_WTSEnumerateSessions(void)
{
console_found = TRUE;
ok(info[i].State == WTSActive, "got State %d.\n", info[i].State);
ok(!strcmp(infoA[i].pWinStationName, "Console"), "got %s.\n", debugstr_a(infoA[i].pWinStationName));
}
else if (!wcscmp(info[i].pWinStationName, L"Services"))
{
services_found = TRUE;
ok(info[i].State == WTSDisconnected, "got State %d.\n", info[i].State);
ok(!strcmp(infoA[i].pWinStationName, "Services"), "got %s.\n", debugstr_a(infoA[i].pWinStationName));
}
}
ok(console_found, "Console session not found.\n");
todo_wine ok(services_found, "Services session not found.\n");
WTSFreeMemory(info);
WTSFreeMemory(infoA);
}
START_TEST (wtsapi)
......
......@@ -266,7 +266,6 @@ BOOL WINAPI WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Versi
return FALSE;
}
/************************************************************
* WTSEnumerateEnumerateSessionsExW (WTSAPI32.@)
*/
......@@ -290,19 +289,57 @@ BOOL WINAPI WTSEnumerateSessionsExA(HANDLE server, DWORD *level, DWORD filter, W
/************************************************************
* WTSEnumerateEnumerateSessionsA (WTSAPI32.@)
*/
BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
BOOL WINAPI WTSEnumerateSessionsA(HANDLE server, DWORD reserved, DWORD version,
PWTS_SESSION_INFOA *session_info, DWORD *count)
{
static int once;
PWTS_SESSION_INFOW infoW;
DWORD size, offset;
unsigned int i;
int len;
if (!once++) FIXME("Stub %p 0x%08lx 0x%08lx %p %p\n", hServer, Reserved, Version,
ppSessionInfo, pCount);
TRACE("%p 0x%08lx 0x%08lx %p %p.\n", server, reserved, version, session_info, count);
if (!ppSessionInfo || !pCount) return FALSE;
if (!session_info || !count) return FALSE;
*pCount = 0;
*ppSessionInfo = NULL;
if (!WTSEnumerateSessionsW(server, reserved, version, &infoW, count)) return FALSE;
size = 0;
for (i = 0; i < *count; ++i)
{
if (!(len = WideCharToMultiByte(CP_ACP, 0, infoW[i].pWinStationName, -1, NULL, 0, NULL, NULL)))
{
ERR("WideCharToMultiByte failed.\n");
WTSFreeMemory(infoW);
return FALSE;
}
size += sizeof(**session_info) + len;
}
if (!(*session_info = heap_alloc(size)))
{
WTSFreeMemory(infoW);
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
offset = *count * sizeof(**session_info);
for (i = 0; i < *count; ++i)
{
(*session_info)[i].State = infoW[i].State;
(*session_info)[i].SessionId = infoW[i].SessionId;
(*session_info)[i].pWinStationName = (char *)(*session_info) + offset;
len = WideCharToMultiByte(CP_ACP, 0, infoW[i].pWinStationName, -1, (*session_info)[i].pWinStationName,
size - offset, NULL, NULL);
if (!len)
{
ERR("WideCharToMultiByte failed.\n");
WTSFreeMemory(*session_info);
WTSFreeMemory(infoW);
}
offset += len;
}
WTSFreeMemory(infoW);
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment