1 /*
2 * Copyright (C) 2022-2025 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 "hidump_adapter.h"
17 #include "hc_log.h"
18 #include "string.h"
19 #include "string_util.h"
20
21 static DumpCallBack g_dumpCallBack = NULL;
22 static CredDumpCallBack g_credDumpCallBack = NULL;
23 static PerformanceDumpCallBack g_performDumpCallback = NULL;
24
DumpByArgs(int fd,StringVector * strArgVec)25 static void DumpByArgs(int fd, StringVector *strArgVec)
26 {
27 HcString strArg = strArgVec->get(strArgVec, 0);
28 if (IsStrEqual(StringGet(&strArg), PERFORM_DUMP_ARG)) {
29 if (g_performDumpCallback != NULL) {
30 g_performDumpCallback(fd, strArgVec);
31 }
32 } else {
33 LOGE("Invalid dumper command!");
34 }
35 }
36
DevAuthDump(int fd,StringVector * strArgVec)37 void DevAuthDump(int fd, StringVector *strArgVec)
38 {
39 if (strArgVec == NULL) {
40 LOGE("Dumper arguments vector is null!");
41 return;
42 }
43 if (strArgVec->size(strArgVec) == 0) {
44 if (g_dumpCallBack != NULL) {
45 g_dumpCallBack(fd);
46 }
47 if (g_credDumpCallBack != NULL) {
48 g_credDumpCallBack(fd);
49 }
50 } else {
51 DumpByArgs(fd, strArgVec);
52 }
53 }
54
RegisterDumpFunc(DumpCallBack func)55 void RegisterDumpFunc(DumpCallBack func)
56 {
57 g_dumpCallBack = func;
58 }
59
RegisterCredDumpFunc(CredDumpCallBack func)60 void RegisterCredDumpFunc(CredDumpCallBack func)
61 {
62 g_credDumpCallBack = func;
63 }
64
RegisterPerformDumpFunc(PerformanceDumpCallBack func)65 void RegisterPerformDumpFunc(PerformanceDumpCallBack func)
66 {
67 g_performDumpCallback = func;
68 }