1 /* |
1 /* |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
69 static void throwOutOfMemoryError(JNIEnv *env, const char *msg) |
69 static void throwOutOfMemoryError(JNIEnv *env, const char *msg) |
70 { |
70 { |
71 static jclass exceptionClass = NULL; |
71 static jclass exceptionClass = NULL; |
72 jclass c; |
72 jclass c; |
73 |
73 |
|
74 (*env)->ExceptionClear(env); // If an exception is pending, clear it before |
|
75 // calling FindClass() and/or ThrowNew(). |
74 if (exceptionClass) { |
76 if (exceptionClass) { |
75 c = exceptionClass; |
77 c = exceptionClass; |
76 } else { |
78 } else { |
77 c = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); |
79 c = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); |
78 if ((*env)->ExceptionOccurred(env)) return; |
80 if ((*env)->ExceptionOccurred(env)) return; |
532 JNIEXPORT jboolean JNICALL |
534 JNIEXPORT jboolean JNICALL |
533 Java_java_util_prefs_MacOSXPreferencesFile_addNode |
535 Java_java_util_prefs_MacOSXPreferencesFile_addNode |
534 (JNIEnv *env, jobject klass, jobject jpath, |
536 (JNIEnv *env, jobject klass, jobject jpath, |
535 jobject jname, jlong juser, jlong jhost) |
537 jobject jname, jlong juser, jlong jhost) |
536 { |
538 { |
537 CFStringRef path = toCF(env, jpath); |
539 CFStringRef path = NULL; |
538 CFStringRef name = toCF(env, jname); |
540 CFStringRef name = NULL; |
|
541 |
|
542 path = toCF(env, jpath); |
|
543 if (path != NULL) { |
|
544 name = toCF(env, jname); |
|
545 } |
539 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
546 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
540 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
547 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
541 CFDictionaryRef node = NULL; |
548 CFDictionaryRef node = NULL; |
542 jboolean neededNewNode = false; |
549 jboolean neededNewNode = false; |
543 |
550 |
577 JNIEXPORT void JNICALL |
584 JNIEXPORT void JNICALL |
578 Java_java_util_prefs_MacOSXPreferencesFile_removeNode |
585 Java_java_util_prefs_MacOSXPreferencesFile_removeNode |
579 (JNIEnv *env, jobject klass, jobject jpath, |
586 (JNIEnv *env, jobject klass, jobject jpath, |
580 jobject jname, jlong juser, jlong jhost) |
587 jobject jname, jlong juser, jlong jhost) |
581 { |
588 { |
582 CFStringRef path = toCF(env, jpath); |
589 CFStringRef path = NULL; |
583 CFStringRef name = toCF(env, jname); |
590 CFStringRef name = NULL; |
|
591 |
|
592 path = toCF(env, jpath); |
|
593 if (path != NULL) { |
|
594 name = toCF(env, jname); |
|
595 } |
584 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
596 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
585 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
597 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
586 CFStringRef parentName; |
598 CFStringRef parentName; |
587 CFStringRef childName; |
599 CFStringRef childName; |
588 CFDictionaryRef constParent; |
600 CFDictionaryRef constParent; |
645 Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode |
657 Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode |
646 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild, |
658 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild, |
647 jobject jname, jlong juser, jlong jhost) |
659 jobject jname, jlong juser, jlong jhost) |
648 { |
660 { |
649 // like addNode, but can put a three-level-deep dict into the root file |
661 // like addNode, but can put a three-level-deep dict into the root file |
650 CFStringRef path = toCF(env, jpath); |
662 CFStringRef path = NULL; |
651 CFStringRef child = toCF(env, jchild); |
663 CFStringRef child = NULL; |
652 CFStringRef name = toCF(env, jname); |
664 CFStringRef name = NULL; |
|
665 |
|
666 path = toCF(env, jpath); |
|
667 if (path != NULL) { |
|
668 child = toCF(env, jchild); |
|
669 } |
|
670 if (child != NULL) { |
|
671 name = toCF(env, jname); |
|
672 } |
653 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
673 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
654 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
674 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
655 CFMutableDictionaryRef parent; |
675 CFMutableDictionaryRef parent; |
656 CFDictionaryRef node; |
676 CFDictionaryRef node; |
657 CFStringRef topKey; |
677 CFStringRef topKey; |
691 JNIEXPORT void JNICALL |
711 JNIEXPORT void JNICALL |
692 Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode |
712 Java_java_util_prefs_MacOSXPreferencesFile_removeChildFromNode |
693 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild, |
713 (JNIEnv *env, jobject klass, jobject jpath, jobject jchild, |
694 jobject jname, jlong juser, jlong jhost) |
714 jobject jname, jlong juser, jlong jhost) |
695 { |
715 { |
696 CFStringRef path = toCF(env, jpath); |
716 CFStringRef path = NULL; |
697 CFStringRef child = toCF(env, jchild); |
717 CFStringRef child = NULL; |
698 CFStringRef name = toCF(env, jname); |
718 CFStringRef name = NULL; |
|
719 |
|
720 path = toCF(env, jpath); |
|
721 if (path != NULL) { |
|
722 child = toCF(env, jchild); |
|
723 } |
|
724 if (child != NULL) { |
|
725 name = toCF(env, jname); |
|
726 } |
699 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
727 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
700 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
728 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
701 CFDictionaryRef constParent; |
729 CFDictionaryRef constParent; |
702 |
730 |
703 if (!path || !child || !name) goto badparams; |
731 if (!path || !child || !name) goto badparams; |
732 JNIEXPORT void JNICALL |
760 JNIEXPORT void JNICALL |
733 Java_java_util_prefs_MacOSXPreferencesFile_addKeyToNode |
761 Java_java_util_prefs_MacOSXPreferencesFile_addKeyToNode |
734 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, jobject jvalue, |
762 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, jobject jvalue, |
735 jobject jname, jlong juser, jlong jhost) |
763 jobject jname, jlong juser, jlong jhost) |
736 { |
764 { |
737 CFStringRef path = toCF(env, jpath); |
765 CFStringRef path = NULL; |
738 CFStringRef key = toCF(env, jkey); |
766 CFStringRef key = NULL; |
739 CFStringRef value = toCF(env, jvalue); |
767 CFStringRef value = NULL; |
740 CFStringRef name = toCF(env, jname); |
768 CFStringRef name = NULL; |
|
769 |
|
770 path = toCF(env, jpath); |
|
771 if (path != NULL) { |
|
772 key = toCF(env, jkey); |
|
773 } |
|
774 if (key != NULL) { |
|
775 value = toCF(env, jvalue); |
|
776 } |
|
777 if (value != NULL) { |
|
778 name = toCF(env, jname); |
|
779 } |
741 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
780 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
742 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
781 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
743 CFMutableDictionaryRef node = NULL; |
782 CFMutableDictionaryRef node = NULL; |
744 CFStringRef topKey; |
783 CFStringRef topKey; |
745 CFMutableDictionaryRef topValue; |
784 CFMutableDictionaryRef topValue; |
769 JNIEXPORT void JNICALL |
808 JNIEXPORT void JNICALL |
770 Java_java_util_prefs_MacOSXPreferencesFile_removeKeyFromNode |
809 Java_java_util_prefs_MacOSXPreferencesFile_removeKeyFromNode |
771 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, |
810 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, |
772 jobject jname, jlong juser, jlong jhost) |
811 jobject jname, jlong juser, jlong jhost) |
773 { |
812 { |
774 CFStringRef path = toCF(env, jpath); |
813 CFStringRef path = NULL; |
775 CFStringRef key = toCF(env, jkey); |
814 CFStringRef key = NULL; |
776 CFStringRef name = toCF(env, jname); |
815 CFStringRef name = NULL; |
|
816 |
|
817 path = toCF(env, jpath); |
|
818 if (path != NULL) { |
|
819 key = toCF(env, jkey); |
|
820 } |
|
821 if (key != NULL) { |
|
822 name = toCF(env, jname); |
|
823 } |
777 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
824 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
778 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
825 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
779 CFDictionaryRef constNode; |
826 CFDictionaryRef constNode; |
780 |
827 |
781 if (!path || !key || !name) goto badparams; |
828 if (!path || !key || !name) goto badparams; |
810 JNIEXPORT jstring JNICALL |
857 JNIEXPORT jstring JNICALL |
811 Java_java_util_prefs_MacOSXPreferencesFile_getKeyFromNode |
858 Java_java_util_prefs_MacOSXPreferencesFile_getKeyFromNode |
812 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, |
859 (JNIEnv *env, jobject klass, jobject jpath, jobject jkey, |
813 jobject jname, jlong juser, jlong jhost) |
860 jobject jname, jlong juser, jlong jhost) |
814 { |
861 { |
815 CFStringRef path = toCF(env, jpath); |
862 CFStringRef path = NULL; |
816 CFStringRef key = toCF(env, jkey); |
863 CFStringRef key = NULL; |
817 CFStringRef name = toCF(env, jname); |
864 CFStringRef name = NULL; |
|
865 |
|
866 path = toCF(env, jpath); |
|
867 if (path != NULL) { |
|
868 key = toCF(env, jkey); |
|
869 } |
|
870 if (key != NULL) { |
|
871 name = toCF(env, jname); |
|
872 } |
818 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
873 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
819 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
874 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
820 CFPropertyListRef value; |
875 CFPropertyListRef value; |
821 CFDictionaryRef node; |
876 CFDictionaryRef node; |
822 jstring result = NULL; |
877 jstring result = NULL; |
912 |
967 |
913 static jarray getStringsForNode(JNIEnv *env, jobject klass, jobject jpath, |
968 static jarray getStringsForNode(JNIEnv *env, jobject klass, jobject jpath, |
914 jobject jname, jlong juser, jlong jhost, |
969 jobject jname, jlong juser, jlong jhost, |
915 Boolean allowSlash) |
970 Boolean allowSlash) |
916 { |
971 { |
917 CFStringRef path = toCF(env, jpath); |
972 CFStringRef path = NULL; |
918 CFStringRef name = toCF(env, jname); |
973 CFStringRef name = NULL; |
|
974 |
|
975 path = toCF(env, jpath); |
|
976 if (path != NULL) { |
|
977 name = toCF(env, jname); |
|
978 } |
919 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
979 CFStringRef user = (CFStringRef)jlong_to_ptr(juser); |
920 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
980 CFStringRef host = (CFStringRef)jlong_to_ptr(jhost); |
921 CFDictionaryRef node; |
981 CFDictionaryRef node; |
922 jarray result = NULL; |
982 jarray result = NULL; |
923 CFIndex count; |
983 CFIndex count; |