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 "web_data_base_ffi.h"
17
18 #include "nweb_helper.h"
19 #include "nweb_init_params.h"
20 #include "web_data_base.h"
21 #include "web_errors.h"
22 #include "webview_log.h"
23 #include "webview_utils.h"
24
25 using namespace OHOS::FFI;
26 using namespace OHOS::NWeb;
27
28 namespace OHOS {
29 namespace Webview {
30 extern "C" {
31 // web data base;
FfiOHOSDBGetHttpAuthCredentials(const char * host,const char * realm)32 RetDataCArrString FfiOHOSDBGetHttpAuthCredentials(const char* host, const char* realm)
33 {
34 std::string host_s = std::string(host);
35 std::string realm_s = std::string(realm);
36
37 CArrString result = OHOS::NWeb::WebDataBase::CJGetHttpAuthCredentials(host_s, realm_s);
38 RetDataCArrString ret;
39
40 if (result.size == -1) {
41 ret.code = NWebError::HTTP_AUTH_MALLOC_FAILED;
42 } else {
43 ret.code = NWebError::NO_ERROR;
44 }
45
46 ret.data = result;
47 return ret;
48 }
49
FfiOHOSDBSaveHttpAuthCredentials(const char * host,const char * realm,const char * username,const char * password)50 void FfiOHOSDBSaveHttpAuthCredentials(const char* host, const char* realm, const char* username, const char* password)
51 {
52 std::string host_s = std::string(host);
53 std::string realm_s = std::string(realm);
54 std::string username_s = std::string(username);
55 std::string password_s = std::string(password);
56
57 OHOS::NWeb::WebDataBase::CJSaveHttpAuthCredentials(host_s, realm_s, username_s, password_s);
58 }
59
FfiOHOSDBExistHttpAuthCredentials()60 bool FfiOHOSDBExistHttpAuthCredentials()
61 {
62 return OHOS::NWeb::WebDataBase::CJExistHttpAuthCredentials();
63 }
64
FfiOHOSDBDeleteHttpAuthCredentials()65 void FfiOHOSDBDeleteHttpAuthCredentials()
66 {
67 OHOS::NWeb::WebDataBase::CJDeleteHttpAuthCredentials();
68 }
69 }
70 } // namespace Webview
71 } // namespace OHOS