You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/29 18:22:55 UTC

svn commit: r1097868 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/windows/RegistryValueType.java native/Makefile.msc.in native/os/win32/arch_defs.h native/os/win32/registry.c

Author: mturk
Date: Fri Apr 29 16:22:54 2011
New Revision: 1097868

URL: http://svn.apache.org/viewvc?rev=1097868&view=rev
Log:
Add basic win32 registry

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java?rev=1097868&r1=1097867&r2=1097868&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java Fri Apr 29 16:22:54 2011
@@ -34,38 +34,43 @@ public enum RegistryValueType
     /**
      * Unknown or unsupported Registry value type.
      */
-    UNKNOWN(    0),
+    UNKNOWN(    0x00000000),
+
+    /**
+     * Unknown or unsupported Registry value type.
+     */
+    NONE(       0x00000001),
 
     /**
      * Binary data in any form.
      */
-    BINARY(     1),
+    BINARY(     0x00000008),
 
     /**
      * A 32-bit number.
      */
-    DWORD(      2),
+    DWORD(      0x00000010),
 
     /**
      * Null-terminated string that contains unexpanded references to
      * environment variables (for example, {@code %PATH%"}).
      */
-    EXPAND_SZ(  3),
+    EXPAND_SZ(  0x00000004),
 
     /**
      * Array of null-terminated strings, terminated by two null characters.
      */
-    MULTI_SZ(   4),
+    MULTI_SZ(   0x00000020),
 
     /**
      * A 64-bit number.
      */
-    QWORD(      5),
+    QWORD(      0x00000040),
 
     /**
      * Null-terminated string
      */
-    SZ(         6);
+    SZ(         0x00000002);
 
     private int value;
     private RegistryValueType(int v)

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1097868&r1=1097867&r2=1097868&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Apr 29 16:22:54 2011
@@ -84,6 +84,7 @@ WIN32_SOURCES=\
 	$(TOPDIR)\os\win32\platform.c \
 	$(TOPDIR)\os\win32\posix.c \
 	$(TOPDIR)\os\win32\procmutex.c \
+	$(TOPDIR)\os\win32\registry.c \
 	$(TOPDIR)\os\win32\security.c \
 	$(TOPDIR)\os\win32\semaphore.c \
 	$(TOPDIR)\os\win32\shmem.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h?rev=1097868&r1=1097867&r2=1097868&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_defs.h Fri Apr 29 16:22:54 2011
@@ -168,4 +168,20 @@ static __inline int isblank(int c)
 #define WAIT_OBJECT_3          (WAIT_OBJECT_0 + 3)
 #define WAIT_OBJECT_4          (WAIT_OBJECT_0 + 4)
 
+/**
+ * Definitions matching the KeyAccessRights Java enum
+ */
+#define ACR_KEY_ALL_ACCESS          0x0001
+#define ACR_KEY_CREATE_LINK         0x0002
+#define ACR_KEY_CREATE_SUB_KEY      0x0004
+#define ACR_KEY_ENUMERATE_SUB_KEYS  0x0008
+#define ACR_KEY_EXECUTE             0x0010
+#define ACR_KEY_NOTIFY              0x0020
+#define ACR_KEY_QUERY_VALUE         0x0040
+#define ACR_KEY_READ                0x0080
+#define ACR_KEY_SET_VALUE           0x0100
+#define ACR_KEY_WOW64_64KEY         0x0200
+#define ACR_KEY_WOW64_32KEY         0x0400
+#define ACR_KEY_WRITE               0x0800
+
 #endif /* _ACR_ARCH_DEFS_H_ */

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=1097868&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Fri Apr 29 16:22:54 2011
@@ -0,0 +1,146 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/error.h"
+#include "acr/memory.h"
+#include "acr/iodefs.h"
+#include "acr/port.h"
+#include "acr/clazz.h"
+#include "acr/string.h"
+#include "arch_opts.h"
+
+
+static REGSAM regsam_translate(int nsam)
+{
+    REGSAM rsam = 0;
+    if (nsam & ACR_KEY_ALL_ACCESS)
+        rsam |= KEY_ALL_ACCESS;
+    if (nsam & ACR_KEY_CREATE_LINK)
+        rsam |= KEY_CREATE_LINK;
+    if (nsam & ACR_KEY_CREATE_SUB_KEY)
+        rsam |= KEY_CREATE_SUB_KEY;
+    if (nsam & ACR_KEY_ENUMERATE_SUB_KEYS)
+        rsam |= KEY_ENUMERATE_SUB_KEYS;
+    if (nsam & ACR_KEY_EXECUTE)
+        rsam |= KEY_EXECUTE;
+    if (nsam & ACR_KEY_NOTIFY)
+        rsam |= KEY_NOTIFY;
+    if (nsam & ACR_KEY_QUERY_VALUE)
+        rsam |= KEY_QUERY_VALUE;
+    if (nsam & ACR_KEY_READ)
+        rsam |= KEY_READ;
+    if (nsam & ACR_KEY_SET_VALUE)
+        rsam |= KEY_SET_VALUE;
+    if (nsam & ACR_KEY_WOW64_64KEY)
+        rsam |= KEY_WOW64_64KEY;
+    if (nsam & ACR_KEY_WOW64_32KEY)
+        rsam |= KEY_WOW64_32KEY;
+    if (nsam & ACR_KEY_WRITE)
+        rsam |= KEY_WRITE;
+    return rsam;
+}
+
+ACR_WIN_EXPORT(jint, RegistryKey, close0)(JNI_STDARGS, jlong key)
+{
+    int rc    = ACR_EBADF;
+    HKEY hkey = J2P(key, HKEY);
+
+    if (IS_VALID_HANDLE(hkey)) {
+        if (hkey == HKEY_CLASSES_ROOT ||
+            hkey == HKEY_CURRENT_CONFIG ||
+            hkey == HKEY_CURRENT_USER ||
+            hkey == HKEY_LOCAL_MACHINE ||
+            hkey == HKEY_USERS ||
+            hkey == HKEY_PERFORMANCE_DATA)
+            rc = 0;
+        else
+            rc = (int)RegCloseKey(hkey);
+    }
+    return rc;
+}
+
+ACR_WIN_EXPORT(jint, RegistryKey, flush0)(JNI_STDARGS, jlong key)
+{
+    return (int)RegFlushKey(J2P(key, HKEY));
+}
+
+ACR_WIN_EXPORT(jlong, RegistryKey, open0)(JNI_STDARGS, jlong key,
+                                          jstring name, jint sam)
+{
+    int  rc     = ACR_EINVAL;
+    HKEY skey   = 0;
+    HKEY hkey   = J2P(key, HKEY);
+    REGSAM rsam = regsam_translate(sam);
+
+    WITH_WSTR(name) {
+        rc = RegOpenKeyExW(hkey,
+                           J2S(name),
+                           0,
+                           rsam,
+                           &skey);
+    } DONE_WITH_STR(name);
+
+    if (rc) {
+        skey = NULL;
+        AcrThrowByStatus(env, rc, 0);
+    }
+    return P2J(skey);
+}
+
+ACR_WIN_EXPORT(jlong, RegistryKey, create0)(JNI_STDARGS, jlong key,
+                                            jstring name, jint sam)
+{
+    int  rc     = ACR_EINVAL;
+    HKEY skey   = 0;
+    HKEY hkey   = J2P(key, HKEY);
+    REGSAM rsam = regsam_translate(sam);
+
+    WITH_WSTR(name) {
+        rc = RegCreateKeyExW(hkey,
+                             J2S(name),
+                             0,
+                             NULL,
+                             0,
+                             rsam,
+                             NULL,
+                             &skey,
+                             NULL);
+    } DONE_WITH_STR(name);
+
+    if (rc) {
+        skey = 0;
+        AcrThrowByStatus(env, rc, 0);
+    }
+    return P2J(skey);
+}
+
+ACR_WIN_EXPORT(jint, RegistryKey, info0)(JNI_STDARGS, jlong key, jstring name,
+                                         jintArray info)
+{
+    DWORD i[2]  = { 0, 0};
+    int  rc     = ACR_EINVAL;
+    HKEY skey   = 0;
+    HKEY hkey   = J2P(key, HKEY);
+
+    WITH_WSTR(name) {
+        rc = RegQueryValueExW(hkey, J2S(name), 0, &i[0], 0, &i[1]);
+    } DONE_WITH_STR(name);
+
+    if (rc == 0)
+        (*env)->SetIntArrayRegion(env, info, 0, 2, i);
+    return rc;
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
------------------------------------------------------------------------------
    svn:eol-style = native