Move group-list related code to a separate file and keep the group name in the group...
authorEric Kohl <eric.kohl@reactos.org>
Sat, 31 Dec 2005 18:56:34 +0000 (18:56 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 31 Dec 2005 18:56:34 +0000 (18:56 +0000)
svn path=/trunk/; revision=20491

reactos/subsys/system/services/config.c
reactos/subsys/system/services/database.c
reactos/subsys/system/services/groupdb.c [new file with mode: 0644]
reactos/subsys/system/services/services.h
reactos/subsys/system/services/services.xml

index 24c0138..4c1143f 100644 (file)
@@ -233,7 +233,7 @@ ScmReadString(HKEY hServiceKey,
     DWORD dwType;\r
     DWORD dwSizeNeeded;\r
     LPWSTR expanded = NULL;\r
-    LPBYTE ptr = NULL;\r
+    LPWSTR ptr = NULL;\r
 \r
     *lpValue = NULL;\r
 \r
@@ -255,7 +255,7 @@ ScmReadString(HKEY hServiceKey,
                                lpValueName,\r
                                0,\r
                                &dwType,\r
-                               ptr,\r
+                               (LPBYTE)ptr,\r
                                &dwSize);\r
     if (dwError != ERROR_SUCCESS)\r
         goto done;\r
@@ -281,7 +281,7 @@ ScmReadString(HKEY hServiceKey,
     }\r
     else\r
     {\r
-        *lpValue = (LPWSTR)ptr;\r
+        *lpValue = ptr;\r
     }\r
 \r
 done:;\r
index efbe3d6..34bf1eb 100644 (file)
 #include <debug.h>
 
 
-/* TYPES *********************************************************************/
-
-typedef struct _SERVICE_GROUP
-{
-  LIST_ENTRY GroupListEntry;
-  UNICODE_STRING GroupName;
-
-  BOOLEAN ServicesRunning;
-  ULONG TagCount;
-  PULONG TagArray;
-
-} SERVICE_GROUP, *PSERVICE_GROUP;
-
-
 /* GLOBALS *******************************************************************/
 
-LIST_ENTRY GroupListHead;
 LIST_ENTRY ServiceListHead;
 
 static RTL_RESOURCE DatabaseLock;
@@ -143,104 +128,6 @@ ScmGetServiceEntryByResumeCount(DWORD dwResumeCount)
 }
 
 
-static NTSTATUS STDCALL
-CreateGroupOrderListRoutine(PWSTR ValueName,
-                            ULONG ValueType,
-                            PVOID ValueData,
-                            ULONG ValueLength,
-                            PVOID Context,
-                            PVOID EntryContext)
-{
-    PSERVICE_GROUP Group;
-
-    DPRINT("CreateGroupOrderListRoutine(%S, %x, %x, %x, %x, %x)\n",
-           ValueName, ValueType, ValueData, ValueLength, Context, EntryContext);
-
-    if (ValueType == REG_BINARY &&
-        ValueData != NULL &&
-        ValueLength >= sizeof(DWORD) &&
-        ValueLength >= (*(PULONG)ValueData + 1) * sizeof(DWORD))
-    {
-        Group = (PSERVICE_GROUP)Context;
-        Group->TagCount = ((PULONG)ValueData)[0];
-        if (Group->TagCount > 0)
-        {
-            if (ValueLength >= (Group->TagCount + 1) * sizeof(DWORD))
-            {
-                Group->TagArray = (PULONG)HeapAlloc(GetProcessHeap(),
-                                                    HEAP_ZERO_MEMORY,
-                                                    Group->TagCount * sizeof(DWORD));
-                if (Group->TagArray == NULL)
-                {
-                    Group->TagCount = 0;
-                    return STATUS_INSUFFICIENT_RESOURCES;
-                }
-
-                RtlCopyMemory(Group->TagArray,
-                              (PULONG)ValueData + 1,
-                              Group->TagCount * sizeof(DWORD));
-            }
-            else
-            {
-                Group->TagCount = 0;
-                return STATUS_UNSUCCESSFUL;
-            }
-        }
-    }
-
-    return STATUS_SUCCESS;
-}
-
-
-static NTSTATUS STDCALL
-CreateGroupListRoutine(PWSTR ValueName,
-                       ULONG ValueType,
-                       PVOID ValueData,
-                       ULONG ValueLength,
-                       PVOID Context,
-                       PVOID EntryContext)
-{
-    PSERVICE_GROUP Group;
-    RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-    NTSTATUS Status;
-
-    if (ValueType == REG_SZ)
-    {
-        DPRINT("Data: '%S'\n", (PWCHAR)ValueData);
-
-        Group = (PSERVICE_GROUP)HeapAlloc(GetProcessHeap(),
-                                          HEAP_ZERO_MEMORY,
-                                          sizeof(SERVICE_GROUP));
-        if (Group == NULL)
-        {
-            return STATUS_INSUFFICIENT_RESOURCES;
-        }
-
-        if (!RtlCreateUnicodeString(&Group->GroupName,
-                                    (PWSTR)ValueData))
-        {
-            return STATUS_INSUFFICIENT_RESOURCES;
-        }
-
-        RtlZeroMemory(&QueryTable, sizeof(QueryTable));
-        QueryTable[0].Name = (PWSTR)ValueData;
-        QueryTable[0].QueryRoutine = CreateGroupOrderListRoutine;
-
-        Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                        L"GroupOrderList",
-                                        QueryTable,
-                                        (PVOID)Group,
-                                        NULL);
-        DPRINT("%x %d %S\n", Status, Group->TagCount, (PWSTR)ValueData);
-
-        InsertTailList(&GroupListHead,
-                       &Group->GroupListEntry);
-    }
-
-    return STATUS_SUCCESS;
-}
-
-
 DWORD
 ScmCreateNewServiceRecord(LPWSTR lpServiceName,
                           PSERVICE *lpServiceRecord)
@@ -412,31 +299,6 @@ done:;
 }
 
 
-DWORD
-ScmReadGroupList(VOID)
-{
-    RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-    NTSTATUS Status;
-
-    InitializeListHead(&GroupListHead);
-
-    /* Build group order list */
-    RtlZeroMemory(&QueryTable,
-                  sizeof(QueryTable));
-
-    QueryTable[0].Name = L"List";
-    QueryTable[0].QueryRoutine = CreateGroupListRoutine;
-
-    Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                    L"ServiceGroupOrder",
-                                    QueryTable,
-                                    NULL,
-                                    NULL);
-
-    return RtlNtStatusToDosError(Status);
-}
-
-
 VOID
 ScmDeleteMarkedServices(VOID)
 {
@@ -476,7 +338,7 @@ ScmCreateServiceDatabase(VOID)
 
     DPRINT("ScmCreateServiceDatabase() called\n");
 
-    dwError = ScmReadGroupList();
+    dwError = ScmCreateGroupList();
     if (dwError != ERROR_SUCCESS)
         return dwError;
 
@@ -627,9 +489,9 @@ ScmCheckDriver(PSERVICE Service)
                 {
                     CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
 
-                    DPRINT("Checking group '%wZ'\n", &CurrentGroup->GroupName);
+                    DPRINT("Checking group '%S'\n", &CurrentGroup->lpGroupName);
                     if (Service->lpServiceGroup != NULL &&
-                        _wcsicmp(Service->lpServiceGroup, CurrentGroup->GroupName.Buffer) == 0)
+                        _wcsicmp(Service->lpServiceGroup, CurrentGroup->lpGroupName) == 0)
                     {
                         CurrentGroup->ServicesRunning = TRUE;
                     }
@@ -984,7 +846,7 @@ ScmAutoStartServices(VOID)
     {
         CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
 
-        DPRINT("Group '%wZ'\n", &CurrentGroup->GroupName);
+        DPRINT("Group '%S'\n", CurrentGroup->lpGroupName);
 
         /* Start all services witch have a valid tag */
         for (i = 0; i < CurrentGroup->TagCount; i++)
@@ -995,7 +857,7 @@ ScmAutoStartServices(VOID)
                 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
 
                 if ((CurrentService->lpServiceGroup != NULL) &&
-                    (_wcsicmp(CurrentGroup->GroupName.Buffer, CurrentService->lpServiceGroup) == 0) &&
+                    (_wcsicmp(CurrentGroup->lpGroupName, CurrentService->lpServiceGroup) == 0) &&
                     (CurrentService->dwStartType == SERVICE_AUTO_START) &&
                     (CurrentService->ServiceVisited == FALSE) &&
                     (CurrentService->dwTag == CurrentGroup->TagArray[i]))
@@ -1016,7 +878,7 @@ ScmAutoStartServices(VOID)
             CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
 
             if ((CurrentService->lpServiceGroup != NULL) &&
-                (_wcsicmp(CurrentGroup->GroupName.Buffer, CurrentService->lpServiceGroup) == 0) &&
+                (_wcsicmp(CurrentGroup->lpGroupName, CurrentService->lpServiceGroup) == 0) &&
                 (CurrentService->dwStartType == SERVICE_AUTO_START) &&
                 (CurrentService->ServiceVisited == FALSE))
             {
diff --git a/reactos/subsys/system/services/groupdb.c b/reactos/subsys/system/services/groupdb.c
new file mode 100644 (file)
index 0000000..a5cfbc0
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+ * groupdb.c\r
+ */\r
+\r
+/* INCLUDES *****************************************************************/\r
+\r
+#include "services.h"\r
+\r
+#define NDEBUG\r
+#include <debug.h>\r
+\r
+\r
+/* GLOBALS *******************************************************************/\r
+\r
+LIST_ENTRY GroupListHead;\r
+\r
+\r
+/* FUNCTIONS *****************************************************************/\r
+\r
+static NTSTATUS STDCALL\r
+CreateGroupOrderListRoutine(PWSTR ValueName,\r
+                            ULONG ValueType,\r
+                            PVOID ValueData,\r
+                            ULONG ValueLength,\r
+                            PVOID Context,\r
+                            PVOID EntryContext)\r
+{\r
+    PSERVICE_GROUP Group;\r
+\r
+    DPRINT("CreateGroupOrderListRoutine(%S, %x, %x, %x, %x, %x)\n",\r
+           ValueName, ValueType, ValueData, ValueLength, Context, EntryContext);\r
+\r
+    if (ValueType == REG_BINARY &&\r
+        ValueData != NULL &&\r
+        ValueLength >= sizeof(DWORD) &&\r
+        ValueLength >= (*(PULONG)ValueData + 1) * sizeof(DWORD))\r
+    {\r
+        Group = (PSERVICE_GROUP)Context;\r
+        Group->TagCount = ((PULONG)ValueData)[0];\r
+        if (Group->TagCount > 0)\r
+        {\r
+            if (ValueLength >= (Group->TagCount + 1) * sizeof(DWORD))\r
+            {\r
+                Group->TagArray = (PULONG)HeapAlloc(GetProcessHeap(),\r
+                                                    HEAP_ZERO_MEMORY,\r
+                                                    Group->TagCount * sizeof(DWORD));\r
+                if (Group->TagArray == NULL)\r
+                {\r
+                    Group->TagCount = 0;\r
+                    return STATUS_INSUFFICIENT_RESOURCES;\r
+                }\r
+\r
+                RtlCopyMemory(Group->TagArray,\r
+                              (PULONG)ValueData + 1,\r
+                              Group->TagCount * sizeof(DWORD));\r
+            }\r
+            else\r
+            {\r
+                Group->TagCount = 0;\r
+                return STATUS_UNSUCCESSFUL;\r
+            }\r
+        }\r
+    }\r
+\r
+    return STATUS_SUCCESS;\r
+}\r
+\r
+\r
+static NTSTATUS STDCALL\r
+CreateGroupListRoutine(PWSTR ValueName,\r
+                       ULONG ValueType,\r
+                       PVOID ValueData,\r
+                       ULONG ValueLength,\r
+                       PVOID Context,\r
+                       PVOID EntryContext)\r
+{\r
+    PSERVICE_GROUP Group;\r
+    RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+    NTSTATUS Status;\r
+\r
+    if (ValueType == REG_SZ)\r
+    {\r
+        DPRINT("Data: '%S'\n", (PWCHAR)ValueData);\r
+\r
+        Group = (PSERVICE_GROUP)HeapAlloc(GetProcessHeap(),\r
+                                          HEAP_ZERO_MEMORY,\r
+                                          sizeof(SERVICE_GROUP) + (wcslen(ValueData) * sizeof(WCHAR)));\r
+        if (Group == NULL)\r
+        {\r
+            return STATUS_INSUFFICIENT_RESOURCES;\r
+        }\r
+\r
+        wcscpy(Group->szGroupName, ValueData);\r
+        Group->lpGroupName = Group->szGroupName;\r
+        Group->dwRefCount = (DWORD)-1;\r
+\r
+        RtlZeroMemory(&QueryTable, sizeof(QueryTable));\r
+        QueryTable[0].Name = (PWSTR)ValueData;\r
+        QueryTable[0].QueryRoutine = CreateGroupOrderListRoutine;\r
+\r
+        Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                        L"GroupOrderList",\r
+                                        QueryTable,\r
+                                        (PVOID)Group,\r
+                                        NULL);\r
+        DPRINT("%x %d %S\n", Status, Group->TagCount, (PWSTR)ValueData);\r
+\r
+        InsertTailList(&GroupListHead,\r
+                       &Group->GroupListEntry);\r
+    }\r
+\r
+    return STATUS_SUCCESS;\r
+}\r
+\r
+\r
+DWORD\r
+ScmCreateGroupList(VOID)\r
+{\r
+    RTL_QUERY_REGISTRY_TABLE QueryTable[2];\r
+    NTSTATUS Status;\r
+\r
+    InitializeListHead(&GroupListHead);\r
+\r
+    /* Build group order list */\r
+    RtlZeroMemory(&QueryTable,\r
+                  sizeof(QueryTable));\r
+\r
+    QueryTable[0].Name = L"List";\r
+    QueryTable[0].QueryRoutine = CreateGroupListRoutine;\r
+\r
+    Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,\r
+                                    L"ServiceGroupOrder",\r
+                                    QueryTable,\r
+                                    NULL,\r
+                                    NULL);\r
+\r
+    return RtlNtStatusToDosError(Status);\r
+}\r
+\r
+/* EOF */\r
index b3e4c14..31f739c 100644 (file)
@@ -9,6 +9,21 @@
 #include <ndk/ntndk.h>
 #include <services/services.h>
 
+
+typedef struct _SERVICE_GROUP
+{
+    LIST_ENTRY GroupListEntry;
+    LPWSTR lpGroupName;
+
+    DWORD dwRefCount;
+    BOOLEAN ServicesRunning;
+    ULONG TagCount;
+    PULONG TagArray;
+
+    WCHAR szGroupName[1];
+} SERVICE_GROUP, *PSERVICE_GROUP;
+
+
 typedef struct _SERVICE
 {
     LIST_ENTRY ServiceListEntry;
@@ -40,6 +55,7 @@ typedef struct _SERVICE
 /* VARIABLES ***************************************************************/
 
 extern LIST_ENTRY ServiceListHead;
+extern LIST_ENTRY GroupListHead;
 extern BOOL ScmShutdown;
 
 
@@ -90,6 +106,11 @@ DWORD ScmControlDriver(PSERVICE lpService,
                        LPSERVICE_STATUS lpServiceStatus);
 
 
+/* groupdb.c */
+
+DWORD ScmCreateGroupList(VOID);
+
+
 /* rpcserver.c */
 
 VOID ScmStartRpcServer(VOID);
index d8f3409..b64b025 100644 (file)
@@ -13,6 +13,7 @@
        <file>config.c</file>
        <file>database.c</file>
        <file>driver.c</file>
+       <file>groupdb.c</file>
        <file>rpcserver.c</file>
        <file>services.c</file>
        <file>services.rc</file>