• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 #ifndef BASE_STARTUP_INIT_CMDS_H
16 #define BASE_STARTUP_INIT_CMDS_H
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include "cJSON.h"
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 #define DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH) // mkdir, default mode
29 #define SPACES_CNT_IN_CMD_MAX 10                                           // mount, max number of spaces in cmdline
30 #define SPACES_CNT_IN_CMD_MIN 2                                            // mount, min number of spaces in cmdline
31 
32 #define LOADCFG_BUF_SIZE 128       // loadcfg, max buffer for one cmdline
33 #define LOADCFG_MAX_FILE_LEN 51200 // loadcfg, max file size is 50K
34 #define LOADCFG_MAX_LOOP 20        // loadcfg, to prevent to be trapped in infite loop
35 #define OCTAL_TYPE 8               // 8 means octal to decimal
36 #define MAX_BUFFER 256UL
37 #define AUTHORITY_MAX_SIZE 128
38 
39 #define MAX_CMD_NAME_LEN 32
40 #define MAX_CMD_CONTENT_LEN 256
41 #define MAX_CMD_CNT_IN_ONE_JOB 200
42 #define MAX_COPY_BUF_SIZE 256
43 #define DEFAULT_COPY_ARGS_CNT 2
44 
45 #define OPTIONS_SIZE 128
46 
47 #define SUPPORT_MAX_ARG_FOR_EXEC 10
48 // one cmd line
49 typedef struct {
50     int cmdIndex;
51     char cmdContent[MAX_CMD_CONTENT_LEN + 1];
52 } CmdLine;
53 
54 typedef struct {
55     int cmdNum;
56     CmdLine cmds[0];
57 } CmdLines;
58 
59 struct CmdArgs {
60     int argc;
61     char *argv[0];
62 };
63 
64 struct CmdTable {
65     char name[MAX_CMD_NAME_LEN];
66     unsigned char minArg;
67     unsigned char maxArg;
68     void (*DoFuncion)(const struct CmdArgs *ctx);
69 };
70 
71 int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen);
72 const struct CmdArgs *GetCmdArg(const char *cmdContent, const char *delim, int argsCount);
73 void FreeCmdArg(struct CmdArgs *cmd);
74 void DoCmdByName(const char *name, const char *cmdContent);
75 void DoCmdByIndex(int index, const char *cmdContent);
76 const char *GetMatchCmd(const char *cmdStr, int *index);
77 const char *GetCmdKey(int index);
78 const struct CmdTable *GetCmdTable(int *number);
79 int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines);
80 const struct CmdTable *GetCmdByName(const char *name);
81 void ExecReboot(const char *value);
82 char *BuildStringFromCmdArg(const struct CmdArgs *ctx, int startIndex);
83 void ExecCmd(const struct CmdTable *cmd, const char *cmdContent);
84 int FileCryptEnable(char *fileCryptOption);
85 #ifdef __cplusplus
86 #if __cplusplus
87 }
88 #endif
89 #endif
90 
91 #endif // BASE_STARTUP_INITLITE_CMDS_H
92