• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "DataProtectionKit/dlp_permission_api.h"
17 #include "napi/native_api.h"
18 #include <cstdint>
19 #include <cstdlib>
20 
OsGetDlpPermissionInfo0100(napi_env env,napi_callback_info info)21 static napi_value OsGetDlpPermissionInfo0100(napi_env env, napi_callback_info info)
22 {
23     DLP_FileAccess *dlpFileAccess = NULL;
24     uint32_t flags = NULL;
25     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(dlpFileAccess, &flags);
26     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
27         napi_value result = nullptr;
28         napi_create_int32(env, ret, &result);
29         return result;
30     }
31     napi_value result = nullptr;
32     napi_create_int32(env, ret, &result);
33     return result;
34 }
OsGetDlpPermissionInfo0101(napi_env env,napi_callback_info info)35 static napi_value OsGetDlpPermissionInfo0101(napi_env env, napi_callback_info info)
36 {
37     DLP_FileAccess dlpFileAccess = NO_PERMISSION;
38     uint32_t flags = 0;
39     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(&dlpFileAccess, &flags);
40     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
41         napi_value result = nullptr;
42         napi_create_int32(env, ret, &result);
43         return result;
44     }
45     napi_value result = nullptr;
46     napi_create_int32(env, ret, &result);
47     return result;
48 }
OsGetDlpPermissionInfo0102(napi_env env,napi_callback_info info)49 static napi_value OsGetDlpPermissionInfo0102(napi_env env, napi_callback_info info)
50 {
51     DLP_FileAccess dlpFileAccess = READ_ONLY;
52     uint32_t flags = 0x00000001;
53     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(&dlpFileAccess, &flags);
54     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
55         napi_value result = nullptr;
56         napi_create_int32(env, ret, &result);
57         return result;
58     }
59     napi_value result = nullptr;
60     napi_create_int32(env, ret, &result);
61     return result;
62 }
OsGetDlpPermissionInfo0103(napi_env env,napi_callback_info info)63 static napi_value OsGetDlpPermissionInfo0103(napi_env env, napi_callback_info info)
64 {
65     DLP_FileAccess dlpFileAccess = CONTENT_EDIT;
66     uint32_t flags = 0;
67     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(&dlpFileAccess, &flags);
68     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
69         napi_value result = nullptr;
70         napi_create_int32(env, ret, &result);
71         return result;
72     }
73     napi_value result = nullptr;
74     napi_create_int32(env, ret, &result);
75     return result;
76 }
OsGetDlpPermissionInfo0104(napi_env env,napi_callback_info info)77 static napi_value OsGetDlpPermissionInfo0104(napi_env env, napi_callback_info info)
78 {
79     DLP_FileAccess dlpFileAccess = FULL_CONTROL;
80     uint32_t flags = 0;
81     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(&dlpFileAccess, &flags);
82     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
83         napi_value result = nullptr;
84         napi_create_int32(env, ret, &result);
85         return result;
86     }
87     napi_value result = nullptr;
88     napi_create_int32(env, ret, &result);
89     return result;
90 }
OsGetDlpPermissionInfo0105(napi_env env,napi_callback_info info)91 static napi_value OsGetDlpPermissionInfo0105(napi_env env, napi_callback_info info)
92 {
93     DLP_FileAccess *dlpFileAccess = NULL;
94     uint32_t flags = NULL;
95     DLP_ErrCode ret = OH_DLP_GetDlpPermissionInfo(dlpFileAccess, &flags);
96     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
97         napi_value result = nullptr;
98         napi_create_int32(env, ret, &result);
99         return result;
100     }
101     napi_value result = nullptr;
102     napi_create_int32(env, ret, &result);
103     return result;
104 }
OsGetOriginalFileName0100(napi_env env,napi_callback_info info)105 static napi_value OsGetOriginalFileName0100(napi_env env, napi_callback_info info)
106 {
107     const char *fileName = "test.txt";
108     char *originalFileName = nullptr;
109     DLP_ErrCode ret = OH_DLP_GetOriginalFileName(fileName, &originalFileName);
110     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
111         napi_value result = nullptr;
112         napi_create_string_utf8(env, originalFileName, NAPI_AUTO_LENGTH, &result);
113         return result;
114     }
115     napi_value result = nullptr;
116     napi_create_int32(env, ret, &result);
117     free(originalFileName);
118     return result;
119 }
OsSetSandboxAppConfig0100(napi_env env,napi_callback_info info)120 static napi_value OsSetSandboxAppConfig0100(napi_env env, napi_callback_info info)
121 {
122     const char *configInfo = nullptr;
123     DLP_ErrCode ret = OH_DLP_SetSandboxAppConfig(configInfo);
124     if (ret == DLP_ErrCode::ERR_OH_SUCCESS) {
125         napi_value result = nullptr;
126         napi_get_boolean(env, ret, &result);
127         return result;
128     }
129     napi_value result = nullptr;
130     napi_create_int32(env, ret, &result);
131     return result;
132 }
133 EXTERN_C_START
Init(napi_env env,napi_value exports)134 static napi_value Init(napi_env env, napi_value exports)
135 {
136     napi_property_descriptor desc[] = {
137         {"OsGetDlpPermissionInfo0100", nullptr, OsGetDlpPermissionInfo0100, nullptr, nullptr, nullptr, napi_default,
138          nullptr},
139         {"OsGetDlpPermissionInfo0101", nullptr, OsGetDlpPermissionInfo0101, nullptr, nullptr, nullptr, napi_default,
140          nullptr},
141         {"OsGetDlpPermissionInfo0102", nullptr, OsGetDlpPermissionInfo0102, nullptr, nullptr, nullptr, napi_default,
142          nullptr},
143         {"OsGetDlpPermissionInfo0103", nullptr, OsGetDlpPermissionInfo0103, nullptr, nullptr, nullptr, napi_default,
144          nullptr},
145         {"OsGetDlpPermissionInfo0104", nullptr, OsGetDlpPermissionInfo0104, nullptr, nullptr, nullptr, napi_default,
146          nullptr},
147         {"OsGetDlpPermissionInfo0105", nullptr, OsGetDlpPermissionInfo0105, nullptr, nullptr, nullptr, napi_default,
148          nullptr},
149         {"OsGetOriginalFileName0100", nullptr, OsGetOriginalFileName0100, nullptr, nullptr, nullptr, napi_default,
150          nullptr},
151         {"OsSetSandboxAppConfig0100", nullptr, OsSetSandboxAppConfig0100, nullptr, nullptr, nullptr, napi_default,
152          nullptr},
153     };
154 
155     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
156     return exports;
157 }
158 EXTERN_C_END
159 
160 static napi_module demoModule = {
161     .nm_version = 1,
162     .nm_flags = 0,
163     .nm_filename = nullptr,
164     .nm_register_func = Init,
165     .nm_modname = "osaccountndk",
166     .nm_priv = ((void *)0),
167     .reserved = {0},
168 };
169 
RegisterModule(void)170 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
171