• 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 #ifndef APPSPAWN_CLIENT_MSG_H
17 #define APPSPAWN_CLIENT_MSG_H
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 
23 #include "appspawn.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define NWEBSPAWN_SOCKET_NAME "NWebSpawn"
30 #define APPSPAWN_SOCKET_NAME "AppSpawn"
31 #define CJAPPSPAWN_SOCKET_NAME "CJAppSpawn"
32 #define KEEPALIVE_NAME "keepalive"
33 #define NATIVESPAWN_SOCKET_NAME "NativeSpawn"
34 #define SPAWN_LISTEN_FD_NAME "SpawnListenFd"
35 
36 #define APPSPAWN_ALIGN(len) (((len) + 0x03) & (~0x03))
37 #define APPSPAWN_TLV_NAME_LEN 32
38 #define MAX_MSG_BLOCK_LEN (4 * 1024)
39 #define RECV_BLOCK_LEN 1024
40 #define MAX_MSG_TOTAL_LENGTH (64 * 1024)
41 #define EXTRAINFO_TOTAL_LENGTH_MAX (32 * 1024)
42 #define MAX_TLV_COUNT 128
43 #define APPSPAWN_MSG_MAGIC 0xEF201234
44 
45 #define APP_LEN_PROC_NAME 256    // process name length
46 #define APP_LEN_BUNDLE_NAME 256  // bundle name length
47 #define APP_LEN_SO_PATH 256      // load so lib
48 #define APP_APL_MAX_LEN 32
49 #define APP_RENDER_CMD_MAX_LEN 2048
50 #define APP_OWNER_ID_LEN 64
51 
52 typedef enum {
53     TLV_BUNDLE_INFO = 0,
54     TLV_MSG_FLAGS,
55     TLV_DAC_INFO,
56     TLV_DOMAIN_INFO,
57     TLV_OWNER_INFO,
58     TLV_ACCESS_TOKEN_INFO,
59     TLV_PERMISSION,
60     TLV_INTERNET_INFO,
61     TLV_RENDER_TERMINATION_INFO,
62     TLV_MAX
63 } AppSpawnMsgTlvType;
64 
65 #define DATA_TYPE_STRING 1
66 
67 #if defined(__clang__)
68 #    pragma clang diagnostic push
69 #    pragma clang diagnostic ignored "-Wextern-c-compat"
70 #elif defined(__GNUC__)
71 #    pragma GCC diagnostic push
72 #    pragma GCC diagnostic ignored "-Wextern-c-compat"
73 #elif defined(_MSC_VER)
74 #    pragma warning(push)
75 #endif
76 
77 #pragma pack(4)
78 typedef AppDacInfo AppSpawnMsgDacInfo;
79 
80 typedef struct {
81     uint16_t tlvLen;
82     uint16_t tlvType;
83 } AppSpawnTlv;
84 
85 typedef struct {
86     uint16_t tlvLen;  // 对齐后的长度
87     uint16_t tlvType;
88     uint16_t dataLen;  // 数据的长度
89     uint16_t dataType;
90     char tlvName[APPSPAWN_TLV_NAME_LEN];
91 } AppSpawnTlvExt;
92 
93 typedef struct {
94     uint32_t count;
95     uint32_t flags[0];
96 } AppSpawnMsgFlags;
97 
98 typedef struct {
99     uint64_t accessTokenIdEx;
100 } AppSpawnMsgAccessToken;
101 
102 typedef struct {
103     char ownerId[0];  // app identifier id
104 } AppSpawnMsgOwnerId;
105 
106 typedef struct {
107     uint8_t setAllowInternet;
108     uint8_t allowInternet;  // hap sockect allowed
109     uint8_t res[2];
110 } AppSpawnMsgInternetInfo;
111 
112 typedef struct {
113     uint32_t hapFlags;
114     char apl[0];
115 } AppSpawnMsgDomainInfo;
116 
117 typedef struct {
118     uint32_t bundleIndex;
119     char bundleName[0];  // process name
120 } AppSpawnMsgBundleInfo;
121 
122 typedef struct TagAppSpawnMsg {
123     uint32_t magic;
124     uint32_t msgType;
125     uint32_t msgLen;
126     uint32_t msgId;
127     uint32_t tlvCount;
128     char processName[APP_LEN_PROC_NAME];
129 } AppSpawnMsg;
130 
131 typedef struct {
132     AppSpawnMsg msgHdr;
133     AppSpawnResult result;
134 } AppSpawnResponseMsg;
135 #pragma pack()
136 
137 #if defined(__clang__)
138 #    pragma clang diagnostic pop
139 #elif defined(__GNUC__)
140 #    pragma GCC diagnostic pop
141 #elif defined(_MSC_VER)
142 #    pragma warning(pop)
143 #endif
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 #endif  // APPSPAWN_CLIENT_MSG_H
149