1 /*
2 * Copyright (c) 2023 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 "gethttpproxy_context.h"
17
18 #include <set>
19 #include <string>
20
21 #include "napi_constant.h"
22 #include "napi_utils.h"
23 #include "netmanager_base_log.h"
24
25 namespace OHOS {
26 namespace NetManagerStandard {
27 namespace {
28
CheckParamsType(napi_env env,napi_value * params,size_t paramsCount)29 bool CheckParamsType(napi_env env, napi_value *params, size_t paramsCount)
30 {
31 if (paramsCount == PARAM_NONE) {
32 return true;
33 }
34 if (paramsCount == PARAM_JUST_CALLBACK) {
35 return NapiUtils::GetValueType(env, params[ARG_INDEX_0]) == napi_function;
36 }
37 return false;
38 }
39 } // namespace
40
GetHttpProxyContext(napi_env env,EventManager * manager)41 GetHttpProxyContext::GetHttpProxyContext(napi_env env, EventManager *manager) : BaseContext(env, manager) {}
42
ParseParams(napi_value * params,size_t paramsCount)43 void GetHttpProxyContext::ParseParams(napi_value *params, size_t paramsCount)
44 {
45 if (!CheckParamsType(GetEnv(), params, paramsCount)) {
46 NETMANAGER_BASE_LOGE("check params type failed");
47 SetNeedThrowException(true);
48 SetErrorCode(NETMANAGER_ERR_PARAMETER_ERROR);
49 return;
50 }
51
52 if (paramsCount == PARAM_JUST_CALLBACK) {
53 SetParseOK(SetCallback(params[ARG_INDEX_0]) == napi_ok);
54 return;
55 }
56
57 SetParseOK(true);
58 }
59 } // namespace NetManagerStandard
60 } // namespace OHOS